/* =====================================================================
   site.css: shared styles for every page.
   WHY one file: every tool page loads the same small stylesheet, so the
   browser caches it once and later pages open instantly.
   ===================================================================== */

/* ---------------------------------------------------------------------
   Design tokens.
   WHY CSS variables: one place to change brand colours; dark mode is a
   second set of values instead of duplicated rules.
   --------------------------------------------------------------------- */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #141824;
  --muted: #5b6475;
  --border: #dde2ea;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --brand-soft: #eceafd;
  --ok: #15803d;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 36, .06), 0 8px 24px rgba(20, 24, 36, .06);
  --max: 1180px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117; --surface: #161a22; --surface-2: #1e2430; --text: #e8ebf1;
    --muted: #9aa3b5; --border: #2a3140; --brand: #8b85ff; --brand-ink: #0e1117;
    --brand-soft: #24224a; --ok: #4ade80; --danger: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

/* ---------------------------------------------------------------------
   Base / reset.
   WHY system fonts: zero font downloads = faster first paint on phones.
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
img, canvas { max-width: 100%; display: block; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.8rem, 4.5vw, 2.7rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.7rem); letter-spacing: -.01em; }
h3, .h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------------
   Header + "All tools" mega menu.
   WHY <details>/<summary>: opens without JavaScript, and all tool links
   are plain HTML that search engines follow.
   --------------------------------------------------------------------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.hdr { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; color: var(--text); text-decoration: none; flex: none; }
.logo svg { width: 30px; height: 30px; color: var(--brand); }
.top-nav { display: flex; gap: 2px; margin-left: 12px; }
.top-nav a, .menu summary {
  white-space: nowrap; padding: 8px 10px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-size: .92rem; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
}
.top-nav a:hover, .menu summary:hover { background: var(--surface-2); }
.top-nav a[aria-current=page] { color: var(--brand); }
.menu { margin-left: auto; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.menu summary::-webkit-details-marker { display: none; }
.menu .burger { display: none; }
.mega {
  position: absolute; left: 0; right: 0; top: 100%; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow); max-height: calc(100vh - 60px); overflow: auto;
}
.mega-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; padding-top: 20px; padding-bottom: 20px; }
.menu-h { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; }
.mega ul, .site-footer ul { list-style: none; margin: 0; padding: 0; }
.mega a, .mega .soon { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem; }
.mega a:hover { background: var(--surface-2); }
.mega a[aria-current=page] { color: var(--brand); font-weight: 600; }
.mega .soon { color: var(--muted); }
.mega .ico { color: var(--brand); flex: none; }
@media (max-width: 960px) { .top-nav { display: none; } }
@media (max-width: 560px) { .menu .menu-label { display: none; } .menu .burger { display: block; } }

/* Breadcrumbs (also emitted as JSON-LD). */
.crumbs { font-size: .85rem; color: var(--muted); padding-top: 14px; }
.crumbs a { color: var(--muted); }

/* ---------------------------------------------------------------------
   Footer: every tool linked, grouped by category (internal linking).
   --------------------------------------------------------------------- */
.site-footer { margin-top: 64px; padding: 36px 0 24px; border-top: 1px solid var(--border); background: var(--surface); font-size: .92rem; }
.foot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 20px; }
.site-footer li { margin: 4px 0; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); text-decoration: underline; }
.copy { color: var(--muted); margin: 28px 0 0; font-size: .85rem; }

/* ---------------------------------------------------------------------
   Ad slots.
   WHY: ads live in <aside class="ad-slot"> OUTSIDE the tool, so they can
   never cover a button. min-height reserves space (no layout shift).
   Hidden while AdSense is off (html.ads-off, set by site.js).
   --------------------------------------------------------------------- */
.ad-slot { margin: 24px auto; min-height: 100px; text-align: center; max-width: var(--max); padding: 0 16px; }
.ad-slot[data-ad-format="rectangle"] { min-height: 250px; }
.ads-off .ad-slot { display: none; }
.ads-preview .ad-slot { display: grid; place-items: center; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); font-size: .85rem; }
.ads-preview .ad-slot::before { content: "Ad placeholder: " attr(data-ad-name); }

/* ---------------------------------------------------------------------
   Generic components.
   --------------------------------------------------------------------- */
.hero { padding: 28px 0 8px; text-align: center; }
.hero p { color: var(--muted); max-width: 680px; margin: 0 auto 1em; font-size: 1.08rem; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0; padding: 0; list-style: none; }
.badges li { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; color: var(--muted); }
.badges li::before { content: "✓"; color: var(--ok); font-weight: 700; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { padding: 44px 0 0; }
.section > h2 { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; /* WHY 44px: minimum comfortable tap target on phones */
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-lg { min-height: 52px; font-size: 1.08rem; width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.steps { counter-reset: step; display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding: 0; list-style: none; }
.steps li { counter-increment: step; padding: 20px; }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; margin-bottom: 10px; }
.steps.plain li::before { content: "✓"; }
.steps p { color: var(--muted); margin: 0; }

.faq { max-width: 780px; margin: 0 auto; display: grid; gap: 10px; }
.faq details { padding: 4px 18px; }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; float: right; color: var(--muted); }
.faq details[open] summary::after { content: "–"; }
.faq details p { color: var(--muted); }
.prose { max-width: 780px; margin: 0 auto; }
.prose p, .prose li { color: var(--muted); }

/* ---------------------------------------------------------------------
   Tool grid (home page + "Related tools").
   WHY cards are whole links: big tap targets and one clean link per tool.
   --------------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px auto 22px; }
.pill-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.pill-btn[aria-pressed=true] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tool-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tool-card { display: block; padding: 20px; color: var(--text); text-decoration: none; transition: transform .15s, border-color .15s; position: relative; }
.tool-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.tool-card .ico { color: var(--brand); margin-bottom: 10px; }
.tool-card h3 { margin-bottom: .3em; }
.tool-card p { color: var(--muted); font-size: .92rem; margin: 0; }
.tool-card.soon { opacity: .6; }
.pill { position: absolute; top: 14px; right: 14px; font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .tool-card { transition: none; } }

/* =====================================================================
   TOOL UI (shared by all tools, driven by toolkit.js)
   State classes on .tool: has-files, is-busy, has-result.
   WHY: CSS decides what is visible per state, JS only flips a class.
   ===================================================================== */
.tool { margin-top: 20px; padding: 16px; }
.dropzone {
  display: grid; place-items: center; gap: 8px; text-align: center; min-height: 260px; padding: 24px;
  border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-dragging { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .icon { width: 48px; height: 48px; color: var(--brand); }
.dropzone small { color: var(--muted); }
.privacy-note { display: flex; align-items: center; gap: 6px; justify-content: center; color: var(--ok); font-weight: 600; font-size: .92rem; margin: 12px 0 0; }

.status { display: none; text-align: center; padding: 40px 16px; }
.is-busy .status { display: block; }
.is-busy .dropzone, .is-busy .workspace, .is-busy .results, .is-busy .compare-wrap, .is-busy .editor { display: none !important; }
.spinner { width: 40px; height: 40px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.progress { height: 6px; max-width: 280px; margin: 10px auto 0; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.error { color: var(--danger); text-align: center; margin: 12px 0 0; }

/* Batch workspace: file thumbnails on the left, options on the right
   (stacked on phones). */
.workspace { display: none; gap: 16px; grid-template-columns: 1fr 320px; align-items: start; }
.has-files .workspace { display: grid; }
.has-files .dropzone, .has-result .dropzone, .has-result .workspace { display: none; }
.file-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.thumb { position: relative; background: var(--surface-2); border-radius: 12px; padding: 8px; text-align: center; font-size: .8rem; cursor: grab; }
.thumb .frame { height: 120px; display: grid; place-items: center; overflow: hidden; border-radius: 8px; }
.thumb img { max-height: 120px; object-fit: contain; transition: transform .2s; }
.thumb .name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 6px; }
.thumb small { color: var(--muted); }
.thumb .rm { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text); cursor: pointer; box-shadow: var(--shadow); font-size: 1rem; line-height: 1; }
.thumb.dragging { opacity: .4; }
.add-more { display: grid; place-items: center; min-height: 160px; border: 2px dashed var(--border); border-radius: 12px; color: var(--muted); cursor: pointer; background: none; font: inherit; }
.add-more:hover { border-color: var(--brand); color: var(--brand); }
.options { position: sticky; top: 76px; padding: 16px; background: var(--surface-2); border-radius: 12px; display: grid; gap: 14px; }
/* Tool-panel labels are <p>, not headings, so the page outline Google reads stays clean. */
.panel-title { font-size: 1.05rem; font-weight: 700; margin: 0; line-height: 1.2; }
.field { display: grid; gap: 6px; font-size: .92rem; }
.field > span, .field legend { font-weight: 600; }
.field input[type=number], .field input[type=text], .field select, .field textarea {
  width: 100%; min-height: 40px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.field input[type=range] { width: 100%; accent-color: var(--brand); }
.field input[type=color] { width: 48px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1 1 100px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
fieldset.field { border: 0; padding: 0; margin: 0; }
/* Segmented control built from radio buttons (accessible by default). */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; font-size: .9rem; font-weight: 600; }
.seg input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg input:focus-visible + span { outline: 3px solid var(--brand); outline-offset: 2px; }
.hint { color: var(--muted); font-size: .82rem; margin: 0; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; }
.pos-grid label span { height: 40px; padding: 0; display: grid; place-items: center; }

/* Results list. */
.results { display: none; }
.has-result .results { display: block; }
.results-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.results-head .panel-title { margin: 0; }
.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.result-list li { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 10px; background: var(--surface-2); }
.result-list img { width: 56px; height: 56px; object-fit: contain; border-radius: 6px; flex: none; }
.result-list .meta { flex: 1; min-width: 0; font-size: .9rem; }
.result-list .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-list .meta small { color: var(--muted); }
.saving { color: var(--ok); font-weight: 700; }

/* Single-image editors (crop, meme, photo editor, blur, upscale). */
.editor { display: none; gap: 16px; grid-template-columns: 1fr 320px; align-items: start; }
.has-files .editor { display: grid; }
.stage { background: var(--surface-2); border-radius: 12px; padding: 8px; display: grid; place-items: center; min-height: 300px; overflow: hidden; position: relative; }
.stage canvas, .stage img { max-height: 70vh; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.sticker-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.sticker-grid button { font-size: 1.4rem; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; padding: 8px 4px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button[aria-selected=true] { color: var(--brand); border-color: var(--brand); }

@media (max-width: 860px) {
  .workspace, .editor { grid-template-columns: 1fr; }
  .options { position: static; }
}

/* Checkerboard = universal "this area is transparent" signal. */
.checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #d9dde4 25%, transparent 25%), linear-gradient(-45deg, #d9dde4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9dde4 75%), linear-gradient(-45deg, transparent 75%, #d9dde4 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

/* ---------------------------------------------------------------------
   Before/after comparer (background remover + upscaler).
   WHY layered images + clip-path driven by a native range input: smooth,
   and keyboard/screen-reader accessible for free.
   --------------------------------------------------------------------- */
.compare-wrap { display: none; }
.has-result .compare-wrap { display: block; }
.has-result > .dropzone { display: none; }
.compare { position: relative; margin: 0 auto; width: fit-content; max-width: 100%; overflow: hidden; border-radius: 12px; user-select: none; touch-action: pan-y; }
.compare img { width: auto; height: auto; max-width: 100%; max-height: 70vh; }
.compare .after { position: relative; }
.compare .before { position: absolute; inset: 0; width: 100%; height: 100%; clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0); }
.compare .handle { position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); pointer-events: none; }
.compare .handle::after { content: "‹ ›"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #111; display: grid; place-items: center; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.3); }
.compare input[type=range] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.compare .tag { position: absolute; top: 10px; padding: 2px 8px; border-radius: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: .75rem; pointer-events: none; }
.compare .tag.l { left: 10px; } .compare .tag.r { right: 10px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-top: 14px; }
.bg-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; padding: 0; border: 0; }
.bg-picker legend { float: left; margin-right: 4px; color: var(--muted); font-size: .9rem; }
.swatch { position: relative; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; padding: 0; overflow: hidden; }
.swatch[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.swatch input[type=color] { position: absolute; inset: -8px; width: 52px; height: 52px; border: 0; padding: 0; cursor: pointer; opacity: 0; }
.swatch.custom { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (max-width: 560px) {
  .controls, .actions { flex-direction: column; align-items: stretch; }
  .actions .btn { width: 100%; }
  .bg-picker { justify-content: center; }
  .bg-picker legend { float: none; width: 100%; text-align: center; }
}
