/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #f0f2ec;
  --ink: #12161c;
  --muted: #5b6470;
  --line: #e1e5dd;
  --accent: #0d8a76;
  --accent-d: #0a6b5b;
  --accent-soft: #e2f3ef;
  --on-accent: #ffffff;
  --warn: #8a5200;
  --warn-bg: #fff3dc;
  --warn-line: #f0d9a8;
  --err: #a8231b;
  --err-bg: #fdecea;
  --err-line: #f3c4c0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(18, 22, 28, .05), 0 10px 34px rgba(18, 22, 28, .07);
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1215;
    --surface: #161b1f;
    --surface-2: #1c2227;
    --ink: #eef2f0;
    --muted: #9aa6a2;
    --line: #262e33;
    --accent: #2fc6a8;
    --accent-d: #5fe0c6;
    --accent-soft: #11302a;
    --on-accent: #06251f;
    --warn: #f1c26b;
    --warn-bg: #2a2110;
    --warn-line: #4a3a18;
    --err: #ff9b92;
    --err-bg: #2c1514;
    --err-line: #572624;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 34px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: var(--accent-d); }
p { text-wrap: pretty; }
h1, h2, h3 { text-wrap: balance; line-height: 1.15; letter-spacing: -0.02em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--on-accent); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 9999;
  padding: .6rem 1rem; background: var(--ink); color: var(--bg);
  border-radius: 8px; font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 1rem; }
.wrap { width: 100%; max-width: 1040px; margin-inline: auto; padding-inline: var(--gutter); }

/* =============================================================
   3. Header
   ============================================================= */
.site-header { border-bottom: 1px solid var(--line); background: var(--bg); }
.site-header .wrap { display: flex; flex-direction: column; gap: 10px; padding-block: 14px; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.25rem; letter-spacing: -0.03em;
  color: var(--ink); text-decoration: none;
}
.brand svg { width: 30px; height: 30px; flex: none; }
.brand small { font-weight: 500; color: var(--muted); font-size: .8rem; letter-spacing: 0; display: none; }
.main-nav {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
}
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  color: var(--muted); text-decoration: none; border: 1px solid transparent;
  transition: background .2s var(--ease-out), color .2s var(--ease-out);
}
.main-nav a:hover { background: var(--surface-2); color: var(--ink); }
.main-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-d); border-color: var(--accent); }

/* =============================================================
   4. Hero + tool card
   ============================================================= */
.hero { padding-block: 28px 8px; }
.hero h1 {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(1.9rem, 6.2vw, 3rem);
}
.hero .sub { margin-top: 8px; color: var(--muted); font-size: 1.05rem; max-width: 60ch; }

.tool-card {
  margin-top: 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px); box-shadow: var(--shadow);
  padding: 14px; display: flex; flex-direction: column; gap: 14px;
}
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 6px; min-height: 170px; padding: 22px 16px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface-2); transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.is-over, .dropzone:focus-within {
  border-color: var(--accent); background: var(--accent-soft);
}
.dropzone svg { width: 44px; height: 44px; color: var(--accent); margin-bottom: 4px; }
.dropzone strong { font-size: 1.15rem; }
.dropzone span { color: var(--muted); font-size: .92rem; }
.dropzone .pick {
  margin-top: 8px; display: inline-flex; padding: 12px 22px; border-radius: 12px;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 1rem;
}
.tool-card.compact .dropzone { min-height: 0; padding: 12px 14px; flex-direction: row; gap: 10px; }
.tool-card.compact .dropzone svg { width: 28px; height: 28px; margin: 0; }
.tool-card.compact .dropzone strong { font-size: 1rem; }
.tool-card.compact .dropzone span { display: none; }

.tool-card > [data-when="idle error"], .tool-card > [data-when="idle done error"] { display: flex; flex-direction: column; gap: 14px; }
.nojs { padding: 14px; border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); }

.privacy {
  display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; color: var(--muted);
  padding: 4px 2px 0;
}
.privacy svg { width: 18px; height: 18px; flex: none; margin-top: 3px; color: var(--accent); }
.limits { font-size: .85rem; color: var(--muted); }

/* =============================================================
   5. Buttons
   ============================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 12px; font-weight: 700; font-size: .98rem;
  text-decoration: none; transition: transform .15s var(--ease-out), background .2s, opacity .2s;
  border: 1px solid transparent; line-height: 1.2; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not([disabled]) { background: var(--accent-d); color: var(--on-accent); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-link { color: var(--muted); text-decoration: underline; padding: 8px 6px; font-weight: 600; }
.btn-link:hover { color: var(--ink); }
.btn-xl { font-size: 1.15rem; padding: 16px 26px; width: 100%; }
.btn-lg { font-size: 1.05rem; padding: 14px 24px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px;
  color: var(--muted); border: 1px solid var(--line); background: var(--surface);
}
.icon-btn:hover:not([disabled]) { color: var(--ink); background: var(--surface-2); }
.icon-btn[disabled] { opacity: .35; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions .btn-primary { flex: 1 1 220px; }

/* =============================================================
   6. File list (merge, images)
   ============================================================= */
.file-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: grid; grid-template-columns: 52px 1fr; grid-template-areas: "th meta" "th act";
  gap: 6px 12px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.file-row .thumb { grid-area: th; align-self: start; }
.file-row .meta { grid-area: meta; }
.file-row .row-actions { grid-area: act; justify-content: flex-start; }
.file-row .grip { display: none; }
.file-row.is-dragging { opacity: .4; }
.file-row.is-target { border-color: var(--accent); box-shadow: 0 -3px 0 var(--accent); }
.file-row .grip { color: var(--muted); cursor: grab; user-select: none; font-size: 1.2rem; line-height: 1; padding: 4px; touch-action: none; }
.file-row .thumb {
  width: 52px; height: 64px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--line); object-fit: cover; display: grid; place-items: center;
  color: var(--muted); font-size: .7rem; overflow: hidden;
}
.file-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-row .meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-row .meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.file-row .meta span { font-size: .82rem; color: var(--muted); }
.file-row .meta .ok { color: var(--accent-d); font-weight: 700; }
.file-row .meta .bad { color: var(--err); font-weight: 600; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.row-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.mini-btn {
  display: inline-flex; padding: 7px 12px; border-radius: 9px; font-size: .85rem; font-weight: 700;
  background: var(--accent-soft); color: var(--accent-d); text-decoration: none; border: 1px solid var(--accent);
}

/* =============================================================
   7. Options, thumbs, notices
   ============================================================= */
.options { display: grid; gap: 12px; }
.opt-group { border: 0; padding: 0; display: grid; gap: 8px; }
.opt-group legend { font-weight: 700; font-size: .95rem; margin-bottom: 6px; padding: 0; }
.choice {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: start;
  padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { grid-row: span 2; margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; }
.choice b { font-size: .96rem; }
.choice small { color: var(--muted); font-size: .84rem; grid-column: 2; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 700; font-size: .92rem; }
.field input[type="text"], .field input[type="number"], .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit;
}
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field .hint { font-size: .82rem; color: var(--muted); }
.opt-row { display: grid; gap: 14px 16px; align-items: start; }

.page-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px;
  max-height: 340px; overflow-y: auto; padding: 4px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2);
}
.page-thumb {
  position: relative; display: grid; place-items: center; min-height: 118px; padding: 6px;
  border: 2px solid transparent; border-radius: 10px; background: var(--surface); text-align: center;
}
.page-thumb canvas { max-width: 100%; height: auto; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.page-thumb .num { font-size: .75rem; font-weight: 700; color: var(--muted); margin-top: 4px; }
.page-grid.is-select .page-thumb { cursor: pointer; }
.page-grid.is-select .page-thumb:hover { border-color: var(--accent); }
.page-thumb[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.page-thumb[aria-pressed="true"] .num { color: var(--accent-d); }
.page-thumb.chip { min-height: 44px; }

.notice {
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: .92rem; border: 1px solid var(--line);
}
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.notice.error { background: var(--err-bg); color: var(--err); border-color: var(--err-line); }
.notice.info { background: var(--accent-soft); color: var(--accent-d); border-color: var(--accent); }
.notice label { display: flex; gap: 10px; align-items: flex-start; margin-top: 8px; font-weight: 700; cursor: pointer; }
.notice input[type="checkbox"] { margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }

.file-info {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.file-info .thumb { width: 52px; height: 64px; border-radius: 6px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.file-info .thumb canvas { width: 100%; height: 100%; object-fit: cover; }
.file-info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info span { color: var(--muted); font-size: .85rem; }
.file-info .meta { min-width: 0; }

/* =============================================================
   8. Progress + result
   ============================================================= */
.progress { display: grid; gap: 10px; padding: 8px 2px; }
.bar { height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s var(--ease-out); }
.bar.indeterminate span { width: 40%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.progress p { font-size: .95rem; color: var(--muted); }

.result { display: grid; gap: 14px; text-align: center; padding: 6px 0; }
.result .check {
  width: 54px; height: 54px; margin-inline: auto; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-d);
}
.result .check svg { width: 28px; height: 28px; }
.result h2 { font-size: 1.4rem; }
.stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px 26px; }
.stats div { display: grid; }
.stats span { font-size: .8rem; color: var(--muted); }
.stats b { font-size: 1.15rem; }
.stats .saved b { color: var(--accent-d); }
.result .btn-link { justify-self: center; }

/* =============================================================
   9. Ads
   ============================================================= */
.ad-slot {
  margin-block: 26px; min-height: 100px; display: grid; place-items: center;
  border: 1px dashed var(--line); border-radius: var(--radius-sm); color: var(--muted);
  font-size: .75rem; letter-spacing: .08em; text-transform: uppercase;
}

/* =============================================================
   10. Content sections
   ============================================================= */
.section { margin-top: 44px; }
.section h2 { font-size: clamp(1.4rem, 4.4vw, 1.9rem); margin-bottom: 16px; }
.steps { list-style: none; padding: 0; display: grid; gap: 12px; counter-reset: step; }
.steps li {
  counter-increment: step; display: grid; grid-template-columns: 44px 1fr; gap: 14px; align-items: start;
  padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.steps li::before {
  content: counter(step); display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-d); font-weight: 800; font-size: 1.15rem;
}
.steps b { display: block; margin-bottom: 2px; }
.steps span { color: var(--muted); font-size: .95rem; }
.prose { max-width: 70ch; }
.prose h2 { margin-top: 28px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 1.1rem; margin: 22px 0 8px; }
.prose p { margin-bottom: 14px; color: var(--ink); }
.prose ul { padding-left: 1.2rem; margin-bottom: 14px; }
.prose li { margin-bottom: 6px; }

.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; }
.faq summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700; display: flex; justify-content: space-between; gap: 12px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 1.3rem; line-height: 1; }
.faq details[open] summary::after { content: "–"; }
.faq details p { padding: 0 16px 16px; color: var(--muted); }

.more-tools { display: grid; gap: 10px; }
.tool-link {
  display: grid; grid-template-columns: 44px 1fr; gap: 14px; align-items: center; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); transition: border-color .2s, transform .2s var(--ease-out);
}
.tool-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-link .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-d); }
.tool-link .ico svg { width: 24px; height: 24px; }
.tool-link b { display: block; }
.tool-link span { color: var(--muted); font-size: .88rem; }

/* =============================================================
   11. Footer
   ============================================================= */
.site-footer { margin-top: 64px; border-top: 1px solid var(--line); padding-block: 28px 40px; color: var(--muted); font-size: .9rem; }
.site-footer .wrap { display: grid; gap: 14px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--ink); }

/* =============================================================
   12. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .tool-card { padding: 20px; }
  .opt-row { grid-template-columns: repeat(2, 1fr); }
  .btn-xl { width: auto; justify-self: center; min-width: 320px; }
  .more-tools { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 720px) {
  :root { --gutter: 24px; }
  .site-header .wrap { flex-direction: row; align-items: center; justify-content: space-between; }
  .brand small { display: inline; }
  .main-nav { margin-inline: 0; padding-inline: 0; overflow: visible; }
  .hero { padding-top: 44px; }
  .file-row { grid-template-columns: auto 56px 1fr auto; grid-template-areas: none; }
  .file-row .grip { display: block; }
  .file-row .thumb, .file-row .meta, .file-row .row-actions { grid-area: auto; align-self: center; }
  .file-row .row-actions { justify-content: flex-end; }
  .file-row.is-image { grid-template-columns: 56px 1fr auto; }
}
@media (min-width: 960px) {
  .steps { grid-template-columns: repeat(3, 1fr); }
  .steps li { grid-template-columns: 1fr; }
  .more-tools { grid-template-columns: repeat(3, 1fr); }
}

/* =============================================================
   13. Reduced motion — only the intrusive loops
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .bar.indeterminate span { animation: none; width: 100%; opacity: .5; }
  html { scroll-behavior: auto; }
}
