/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --ink: #10131a;
  --ink-2: #4a5262;
  --ink-3: #767f91;
  --line: #e2e6ec;
  --line-2: #cfd5de;
  --accent: #2f6bff;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #128a4d;
  --ok-soft: #e2f6ea;
  --warn: #a25c00;
  --warn-soft: #fdf1dd;
  --danger: #c02626;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16,19,26,.05), 0 8px 24px -12px rgba(16,19,26,.16);
  --shadow-lg: 0 2px 4px rgba(16,19,26,.06), 0 24px 60px -20px rgba(16,19,26,.28);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --gutter: clamp(1rem, 4vw, 2rem);
  --maxw: 1120px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1016;
    --surface: #151a23;
    --surface-2: #1c222d;
    --ink: #eef1f6;
    --ink-2: #aab3c2;
    --ink-3: #7d8798;
    --line: #262e3b;
    --line-2: #333e4f;
    --accent: #5b8bff;
    --accent-ink: #0a0d13;
    --accent-soft: #1a2440;
    --ok: #45d18a;
    --ok-soft: #12301f;
    --warn: #e5a13a;
    --warn-soft: #33260f;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.5), 0 24px 60px -20px rgba(0,0,0,.8);
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.62;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.14; letter-spacing: -0.022em; font-weight: 700; }
h1 { font-size: clamp(1.75rem, 5.2vw, 2.65rem); letter-spacing: -0.032em; }
h2 { font-size: clamp(1.35rem, 3.4vw, 1.8rem); }
h3 { font-size: 1.06rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* =============================================================
   3. Utilities
   ============================================================= */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.narrow { max-width: 760px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -100px; left: 1rem; z-index: 999;
  padding: .6rem 1rem; background: var(--ink); color: var(--bg); border-radius: 8px;
}
.skip-link:focus { top: 1rem; }
[hidden] { display: none !important; }

/* =============================================================
   4. Header / footer
   ============================================================= */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 58px;
}
.logo {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; letter-spacing: -0.03em; color: var(--ink); font-size: 1.02rem;
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.header-nav { display: flex; gap: 1.1rem; font-size: .9rem; }
.header-nav a { color: var(--ink-2); }

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 3.5rem; padding-block: 2rem 2.5rem;
  color: var(--ink-3); font-size: .87rem; background: var(--surface);
}
.site-footer .wrap { display: grid; gap: .85rem; }
.footer-links { display: flex; flex-wrap: wrap; gap: 1rem 1.4rem; }
.footer-links a { color: var(--ink-2); }

/* =============================================================
   5. Hero + tool card
   ============================================================= */
.hero { padding-top: clamp(1.4rem, 4vw, 2.4rem); }
.eyebrow {
  display: inline-flex; align-items: center; gap: .45rem;
  font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: .55rem;
}
.eyebrow .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.hero p.lede { color: var(--ink-2); font-size: 1.03rem; margin-top: .7rem; max-width: 62ch; }

.spec-strip {
  display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.1rem;
}
.spec-chip {
  display: inline-flex; align-items: baseline; gap: .4rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .35rem .8rem; font-size: .84rem; color: var(--ink-2);
  box-shadow: var(--shadow);
}
.spec-chip b { color: var(--ink); font-variant-numeric: tabular-nums; }

.tool-card {
  margin-top: 1.3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.tool-body { padding: clamp(.9rem, 3vw, 1.4rem); }

/* Dropzone */
.dropzone {
  display: grid; place-items: center; gap: .55rem; text-align: center;
  min-height: 210px; padding: 1.8rem 1rem;
  border: 2px dashed var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface-2); cursor: pointer;
  transition: border-color .18s var(--ease-out), background .18s var(--ease-out);
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.005); }
.dropzone svg { width: 34px; height: 34px; color: var(--accent); }
.dropzone strong { font-size: 1.05rem; }
.dropzone small { color: var(--ink-3); font-size: .84rem; }
.dz-or { color: var(--ink-3); font-size: .84rem; }
.btn-pick {
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  padding: .6rem 1.2rem; border-radius: 999px; font-size: .92rem;
}

/* Editor */
.editor { display: grid; gap: 1rem; }
@media (min-width: 900px) {
  .editor { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}

.stage-wrap { display: grid; gap: .55rem; }
.stage {
  position: relative; overflow: hidden; border-radius: var(--radius-sm);
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 18px 18px;
  border: 1px solid var(--line);
  touch-action: none; cursor: grab; user-select: none;
  width: 100%;
}
.stage.is-dragging { cursor: grabbing; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage-frame {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: var(--radius-sm);
}
.stage-frame::before, .stage-frame::after {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(to right, rgba(255,255,255,.32) 1px, transparent 1px);
  background-size: 33.333% 100%; opacity: .55;
}
.stage-frame::after { background-image: linear-gradient(to bottom, rgba(255,255,255,.32) 1px, transparent 1px); background-size: 100% 33.333%; }
.stage-hint { font-size: .82rem; color: var(--ink-3); text-align: center; }

.zoom-row { display: flex; align-items: center; gap: .7rem; }
.zoom-row input[type=range] { flex: 1; accent-color: var(--accent); }
.zoom-row button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; font-size: 1rem; color: var(--ink-2);
}
.zoom-row button:hover { border-color: var(--accent); color: var(--accent); }

/* Controls panel */
.panel { display: grid; gap: 1rem; }
.field { display: grid; gap: .38rem; }
.field > label, .field-label {
  font-size: .78rem; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink-3);
}
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; padding: .42rem .3rem; border-radius: 7px; font-size: .85rem; font-weight: 600;
  color: var(--ink-2); transition: background .15s var(--ease-out), color .15s var(--ease-out);
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

select, input[type=text] {
  width: 100%; padding: .5rem .65rem; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); font-size: .92rem;
}
input[type=color] {
  width: 100%; height: 36px; padding: 2px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer;
}
.quality-row { display: flex; align-items: center; gap: .6rem; }
.quality-row input[type=range] { flex: 1; accent-color: var(--accent); }
.quality-row output { font-variant-numeric: tabular-nums; font-size: .86rem; color: var(--ink-2); min-width: 3ch; text-align: right; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .72rem 1.1rem; border-radius: 11px; font-weight: 650; font-size: .95rem;
  border: 1px solid transparent; text-align: center; width: 100%;
  transition: transform .12s var(--ease-out), filter .15s var(--ease-out);
}
.btn:hover { text-decoration: none; filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-ghost { background: none; color: var(--ink-2); font-weight: 500; font-size: .88rem; padding: .4rem; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn svg { width: 17px; height: 17px; flex: none; }

/* Size readout */
.size-readout {
  display: flex; align-items: center; gap: .5rem; padding: .55rem .7rem;
  border-radius: 10px; font-size: .87rem; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); min-height: 40px;
}
.size-readout[data-status="ok"] { background: var(--ok-soft); color: var(--ok); }
.size-readout[data-status="warn"] { background: var(--warn-soft); color: var(--warn); }
.size-readout svg { width: 16px; height: 16px; flex: none; }
.size-readout .spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.privacy-badge {
  display: flex; align-items: flex-start; gap: .55rem;
  margin-top: 1rem; padding: .7rem .85rem; border-radius: var(--radius-sm);
  background: var(--ok-soft); color: var(--ok); font-size: .87rem; font-weight: 500;
}
.privacy-badge svg { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.privacy-badge span { color: color-mix(in srgb, var(--ok) 85%, var(--ink)); }
.limits-note { margin-top: .5rem; font-size: .82rem; color: var(--ink-3); }

/* Batch list */
.batch-list { display: grid; gap: .4rem; margin-top: .8rem; max-height: 260px; overflow-y: auto; }
.batch-item {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .6rem;
  background: var(--surface-2); border-radius: 9px; font-size: .84rem;
}
.batch-item .thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; flex: none; background: var(--line); }
.batch-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item .st { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: .8rem; }
.batch-item .st.done { color: var(--ok); }

.tool-note { font-size: .84rem; color: var(--ink-3); margin-top: .55rem; }
.tool-error {
  margin-top: .8rem; padding: .7rem .85rem; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); font-size: .88rem; font-weight: 500;
}
.noscript-note {
  margin-top: 1rem; padding: .9rem 1rem; border-radius: var(--radius-sm);
  background: var(--warn-soft); color: var(--warn); font-size: .9rem;
}

/* =============================================================
   6. Content sections
   ============================================================= */
.section { padding-top: clamp(2.2rem, 6vw, 3.2rem); }
.section > .wrap > h2 { margin-bottom: .35rem; }
.section-sub { color: var(--ink-2); margin-bottom: 1.2rem; max-width: 65ch; }

.steps { display: grid; gap: .9rem; counter-reset: step; }
@media (min-width: 760px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.step {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; box-shadow: var(--shadow);
}
.step::before {
  counter-increment: step; content: counter(step);
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: .9rem;
  margin-bottom: .6rem;
}
.step h3 { margin-bottom: .25rem; }
.step p { font-size: .9rem; color: var(--ink-2); }

.prose p { margin-bottom: 1rem; color: var(--ink-2); }
.prose p:last-child { margin-bottom: 0; }

.table-wrap {
  overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  position: relative;   /* contains the sr-only <caption>, which would otherwise
                           widen the document and trip "content wider than screen" */
}
table.sizes { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 560px; }
table.sizes th, table.sizes td { padding: .72rem .9rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.sizes th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); background: var(--surface-2); font-weight: 700; }
table.sizes tr:last-child td { border-bottom: 0; }
table.sizes td.dim { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
table.sizes td.note { color: var(--ink-3); font-size: .85rem; }
table.sizes tr.is-primary td { background: var(--accent-soft); }
.src {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: .18rem .5rem; border-radius: 999px; white-space: nowrap;
}
.src-official { background: var(--ok-soft); color: var(--ok); }
.src-rec { background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--line); }
table.sizes .use-btn {
  font-size: .8rem; font-weight: 600; color: var(--accent);
  border: 1px solid var(--line-2); border-radius: 7px; padding: .25rem .6rem; white-space: nowrap;
  background: var(--surface);
}
table.sizes .use-btn:hover { border-color: var(--accent); }

.tips { display: grid; gap: .8rem; }
@media (min-width: 760px) { .tips { grid-template-columns: 1fr 1fr; } }
.tip {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.tip h3 { margin-bottom: .25rem; display: flex; gap: .5rem; align-items: baseline; }
.tip h3::before { content: "→"; color: var(--accent); font-weight: 800; }
.tip p { font-size: .9rem; color: var(--ink-2); }

.faq { display: grid; gap: .5rem; }
.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .85rem 1rem; box-shadow: var(--shadow);
}
.faq summary {
  cursor: pointer; font-weight: 650; list-style: none; display: flex;
  justify-content: space-between; gap: 1rem; align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 1.25rem; font-weight: 400; line-height: 1; flex: none; }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin-top: .6rem; color: var(--ink-2); font-size: .93rem; }

.tool-grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tool-link {
  display: block; padding: .9rem 1rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--ink); transition: transform .15s var(--ease-out), border-color .15s var(--ease-out);
}
.tool-link:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.tool-link strong { display: block; font-size: .95rem; }
.tool-link span { font-size: .84rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tool-link[aria-current="page"] { border-color: var(--accent); background: var(--accent-soft); }

/* =============================================================
   7. Ad slots (placeholders only)
   ============================================================= */
.ad-slot { display: grid; place-items: center; margin-inline: auto; }
/* A slot with nothing in it is not shown at all — no empty boxes, no reserved gaps.
   As soon as an ad is placed inside, the slot stops matching :empty and appears. */
.ad-slot:empty { display: none; }
.ad-leaderboard { margin-top: 1.6rem; width: 100%; max-width: 728px; }
.ad-incontent { margin-block: 2rem; width: 100%; max-width: 580px; }
.ad-footer { margin-top: 2rem; width: 100%; max-width: 728px; }
.ad-dialog-slot { width: 100%; max-width: 336px; margin-top: .9rem; }
.ad-toast-slot { width: 100%; }

dialog.ad-dialog {
  border: 0; border-radius: var(--radius); padding: 0; max-width: 380px; width: calc(100% - 2rem);
  margin: auto;   /* the global margin reset removes the UA centering */
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.ad-dialog::backdrop { background: rgba(10,13,19,.55); backdrop-filter: blur(2px); }
.ad-dialog-inner { padding: 1.1rem; display: grid; place-items: center; text-align: center; }
.ad-dialog-head { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 1rem; }
.ad-dialog-head strong { font-size: .95rem; }
.ad-close {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  color: var(--ink-3); font-size: 1.15rem; line-height: 1; background: var(--surface-2);
}
.ad-close:hover { color: var(--ink); }
.ad-dialog .btn { margin-top: .9rem; }

aside.ad-toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60; width: 260px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .7rem; display: grid; gap: .5rem;
  animation: toast-in .45s var(--ease-out) both;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(14px); } }
.ad-toast-head { display: flex; align-items: center; justify-content: space-between; font-size: .72rem; letter-spacing: .16em; font-weight: 700; color: var(--ink-3); }
@media (max-width: 560px) { aside.ad-toast { left: 1rem; right: 1rem; width: auto; } }

/* =============================================================
   8. Home page
   ============================================================= */
.home-hero { padding-block: clamp(2rem, 7vw, 3.6rem) 0; text-align: center; }
.home-hero p.lede { margin-inline: auto; }
.home-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); margin-top: 1.6rem; }
.home-card {
  display: grid; gap: .3rem; padding: 1.05rem 1.15rem; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  color: var(--ink); transition: transform .15s var(--ease-out), border-color .15s var(--ease-out);
  border-left: 3px solid var(--pf, var(--accent));
}
.home-card:hover { text-decoration: none; transform: translateY(-3px); border-color: var(--accent); }
.home-card .pf { font-size: .74rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--pf, var(--accent)); }
.home-card strong { font-size: 1.02rem; }
.home-card .dim { font-size: .87rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.feature-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* =============================================================
   9. Reduced motion — only intrusive effects
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  aside.ad-toast { animation: none; }
  .size-readout .spinner { animation-duration: 2s; }
}
