/* 1. Tokens */
:root {
  color-scheme: light dark;
  --bg: #f4f4f1; --card: #ffffff; --ink: #17171b; --muted: #5d5d66; --line: #dcdcd6;
  --soft: #ececE7; --accent: #c8390b; --accent-soft: #fbe7df; --on-accent: #ffffff;
  --warn-bg: #fff4d6; --warn-ink: #6b4b00; --ok: #17794a; --bad: #b3261e;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121215; --card: #1c1c21; --ink: #f1f1ee; --muted: #a8a8b0; --line: #34343b;
    --soft: #2a2a30; --accent: #ff7f50; --accent-soft: #3a2118; --on-accent: #1b0d07;
    --warn-bg: #3a2e0c; --warn-ink: #f6dc94; --ok: #58d199; --bad: #ff8a80;
  }
}

/* 2. Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--sans); font-size: 16px; line-height: 1.55; color: var(--ink); background: var(--bg); overflow-x: clip; -webkit-font-smoothing: antialiased; }
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.12; letter-spacing: -.02em; text-wrap: balance; }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* 3. Utilities */
.wrap { width: min(1120px, 100% - 32px); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: fixed; top: -100px; left: 1rem; padding: .6rem 1rem; background: var(--card); z-index: 99; border-radius: 8px; }
.skip-link:focus { top: 1rem; }
.hint { color: var(--muted); font-size: .84rem; }
.label, .field label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 4px; }
.note-warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }

/* 4. Header */
.site-header { background: var(--card); border-bottom: 1px solid var(--line); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -.02em; font-size: 1.1rem; text-decoration: none; color: var(--accent); }
.logo span { color: var(--ink); }
.intro { padding: 16px 0 10px; }
h1 { font-size: clamp(1.3rem, 3.6vw, 2rem); font-weight: 800; }
.sub { color: var(--muted); font-size: .94rem; margin-top: 3px; }

/* 5. Tabs */
.tabs-outer { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; width: min(1120px, 100% - 32px); margin-inline: auto; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 10px 11px; font-size: .9rem; font-weight: 600; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); }

/* 6. Tool card */
.panels { padding-top: 14px; }
.tool-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.js .panel { display: none; }
.js .panel.active { display: block; }
.split { display: grid; gap: 18px; }
.stage-col { min-width: 0; }
.controls { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 3px; min-height: 150px; padding: 18px; border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone strong { font-size: 1.1rem; color: var(--accent); }
.dropzone span { font-size: .86rem; color: var(--muted); }
.dropzone:hover, .dropzone.over, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.small { min-height: 92px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.field-row.four { margin-top: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
input:not([type=range]):not([type=color]), select, textarea { width: 100%; font: inherit; font-size: 16px; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
textarea { resize: vertical; display: block; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=color] { width: 100%; height: 40px; padding: 3px; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.btn { display: inline-flex; justify-content: center; align-items: center; min-height: 42px; padding: 8px 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: .94rem; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-main { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-main:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.controls > .btn-main { min-height: 50px; font-size: 1rem; }
.link-btn { color: var(--muted); font-size: .86rem; text-decoration: underline; align-self: flex-start; padding: 4px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.seg { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; padding: 7px 8px; border-radius: 8px; font-size: .87rem; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .18); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; font-size: .82rem; background: var(--bg); }
.chip:hover { border-color: var(--ink); }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
details.mini summary { cursor: pointer; font-size: .87rem; color: var(--muted); margin-bottom: 8px; }
details.mini .field { margin-bottom: 8px; }

/* Themed dropdowns */
.csel { position: relative; }
.csel-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
.csel-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 42px; padding: 8px 11px; font-size: 16px; line-height: 1.3; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; cursor: pointer; transition: border-color .12s; }
.csel-btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csel-btn svg { flex: none; color: var(--muted); transition: transform .15s; }
.csel-btn:hover { border-color: var(--muted); }
.csel.open .csel-btn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.csel.open .csel-btn svg { transform: rotate(180deg); color: var(--accent); }
.csel-list { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 100%; width: max-content; max-width: min(320px, 86vw); max-height: 280px; overflow-y: auto; padding: 5px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 12px 30px rgb(0 0 0 / .32); scrollbar-width: thin; }
.csel.up .csel-list { top: auto; bottom: calc(100% + 6px); }
.csel-opt { display: block; width: 100%; padding: 8px 10px; font-size: .94rem; line-height: 1.3; text-align: left; border-radius: 7px; cursor: pointer; }
.csel-opt:hover, .csel-opt.active { background: var(--soft); }
.csel-opt.sel { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* AI blocks */
.ai-box { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); line-height: 1.45; }
.ai-title { font-size: 1rem; letter-spacing: -.01em; }
.ai-out { display: flex; flex-direction: column; gap: 8px; }
.ai-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-read { font-size: .86rem; color: var(--muted); }
.ai-list { padding-left: 18px; font-size: .88rem; color: var(--muted); }
#in-ai-out { margin-top: 12px; }
.thumb-row { display: flex; gap: 8px; }
.thumb { position: relative; width: 62px; height: 62px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb i { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgb(0 0 0 / .72); color: #fff; font: 700 13px/18px var(--sans); text-align: center; }

/* 7. Resize */
.crop-stage { display: grid; place-items: center; background: repeating-conic-gradient(var(--soft) 0 25%, transparent 0 50%) 0 0 / 18px 18px; border-radius: 10px; padding: 10px; min-height: 240px; }
#rz-canvas { max-height: min(62vh, 560px); width: auto; height: auto; cursor: grab; touch-action: none; box-shadow: 0 2px 14px rgb(0 0 0 / .25); }
#rz-canvas:active { cursor: grabbing; }

/* 8. Compress */
.file-list:not(:empty) { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.file-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; }
.file-row img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.file-row b { display: block; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row small { color: var(--muted); }
.file-row small.good { color: var(--ok); font-weight: 600; }
.file-row small.bad { color: var(--bad); }
.file-row > div { min-width: 0; }

/* 9. Thumbnails */
.yt-preview { --y-bg: #0f0f0f; --y-ink: #f1f1f1; --y-mut: #aaaaaa; background: var(--y-bg); color: var(--y-ink); border-radius: 12px; padding: 14px; min-width: 0; }
.yt-preview[data-theme=light] { --y-bg: #ffffff; --y-ink: #0f0f0f; --y-mut: #606060; border: 1px solid var(--line); }
.yt-label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--y-mut); margin-bottom: 6px; }
.yt-group { margin-bottom: 16px; }
.yt-two { display: grid; gap: 14px; }
.yt-disclaimer { font-size: .72rem; color: var(--y-mut); }
.yt-card[data-v=home] { max-width: 360px; }
.yt-card[data-v=mobile] { max-width: 300px; }
.yt-thumb { position: relative; aspect-ratio: 16/9; border-radius: 10px; overflow: hidden; background: linear-gradient(135deg, #4b4b57, #8d8d99); }
.yt-thumb img { width: 100%; height: 100%; object-fit: cover; }
.yt-thumb i { position: absolute; right: 4px; bottom: 4px; background: rgb(0 0 0 / .8); color: #fff; font: 600 .68rem/1 var(--sans); padding: 3px 4px; border-radius: 4px; }
.yt-meta { display: grid; grid-template-columns: 34px 1fr; gap: 10px; margin-top: 9px; }
.yt-ava { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: .85rem; }
.yt-title { font-weight: 600; font-size: .9rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.yt-sub { font-size: .76rem; color: var(--y-mut); margin-top: 2px; }
.yt-row { display: grid; grid-template-columns: 168px 1fr; gap: 8px; margin-bottom: 8px; }
.yt-row .yt-title { font-size: .84rem; }
.yt-tiny { grid-template-columns: 120px 1fr; }
.yt-tiny .yt-title { font-size: .78rem; }
.checks { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .86rem; }
.checks .good::before { content: "✓ "; color: var(--ok); font-weight: 800; }
.checks .warn::before { content: "! "; color: var(--bad); font-weight: 800; }

/* 10. Counter */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.stats div { background: var(--soft); border-radius: 9px; padding: 7px 9px; }
.stats b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stats span { font-size: .74rem; color: var(--muted); }
.limits { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.limit-top { display: flex; justify-content: space-between; gap: 8px; font-size: .84rem; }
.limit-top span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.limit-bar { height: 6px; background: var(--soft); border-radius: 6px; overflow: hidden; margin-top: 3px; }
.limit-bar i { display: block; height: 100%; background: var(--ok); }
.limit.over .limit-bar i { background: var(--bad); }
.limit.over .limit-top span:last-child { color: var(--bad); font-weight: 700; }
.limit.fold .limit-bar i { background: #d99a00; }

/* 11. Fonts */
.font-list { display: grid; gap: 6px; margin: 12px 0; }
.font-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px 7px 12px; }
.font-row small { display: block; color: var(--muted); font-size: .72rem; }
.font-row span { display: block; font-size: 1.08rem; overflow-wrap: anywhere; line-height: 1.35; }
.font-row .btn { min-height: 36px; padding: 5px 11px; font-size: .84rem; }

/* 12. QR */
.qr-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.qr-preview { display: grid; place-items: center; padding: 10px; background: var(--soft); border-radius: 12px; min-height: 260px; }
.qr-preview svg, .qr-preview canvas { width: min(100%, 260px); height: auto; border-radius: 6px; }
.output-link { display: flex; flex-direction: column; gap: 7px; }
.output-link code { display: block; font-size: .82rem; padding: 8px 10px; background: var(--soft); border-radius: 9px; overflow-wrap: anywhere; }
.file-btn { cursor: pointer; }

/* 13. Earnings */
.earn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 8px; }
.earn { min-height: 92px; background: var(--soft); border-radius: 12px; padding: 12px; }
.earn span { font-size: .78rem; color: var(--muted); }
.earn b { display: block; font-size: 1.5rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.earn small { color: var(--muted); }
.earn.mid { background: var(--accent-soft); }
.earn.mid b { color: var(--accent); }
#in-basis { margin: 10px 0; }

/* 15. Ads and content */
.privacy-line { font-size: .86rem; color: var(--muted); margin: 0 2px 14px; }
.ad-slot { display: grid; place-items: center; min-height: 100px; margin-bottom: 24px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.content { padding-bottom: 36px; max-width: 780px; }
.content h2 { font-size: 1.4rem; margin: 24px 0 12px; }
.content p { margin-bottom: 12px; color: var(--muted); }
.how { padding-left: 20px; margin-bottom: 14px; }
.how li { margin-bottom: 5px; }
.faq details { border-top: 1px solid var(--line); padding: 11px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: 7px 0 0; }
.site-footer { border-top: 1px solid var(--line); padding: 20px 0 28px; font-size: .84rem; color: var(--muted); }
.site-footer nav { display: flex; gap: 16px; margin-bottom: 8px; }
.credits { margin-top: 4px; font-size: .76rem; }
.legal { padding: 28px 0 48px; max-width: 760px; }
.legal h1 { margin-bottom: 14px; }
.legal h2 { margin: 22px 0 8px; font-size: 1.15rem; }
.legal p { margin-bottom: 10px; }
.todo { background: var(--warn-bg); color: var(--warn-ink); padding: 0 4px; border-radius: 4px; }

/* 16. Responsive */
@media (min-width: 720px) {
  .tool-card { padding: 20px; }
  .split { grid-template-columns: minmax(0, 1.45fr) minmax(280px, 1fr); }
  .thumbs { grid-template-columns: minmax(270px, .8fr) minmax(0, 1.6fr); }
  .yt-two { grid-template-columns: 300px minmax(0, 1fr); }
  #cp-zip, #cp-run { flex: none; }
}
