/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f2ede2;
  --ink: #211d17;
  --muted: #5c5544;
  --border: #e6ddcb;
  --accent: #c9822f;
  --accent-dark: #a1671f;
  --accent-ink: #2a1a08;
  --ok: #3f7a4d;
  --warn: #a15b1f;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-soft: 0 1px 2px rgba(33,29,23,.04), 0 8px 24px -12px rgba(33,29,23,.18);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Manrope", system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #201c15;
    --surface-2: #2a251c;
    --ink: #f1ece1;
    --muted: #b3a993;
    --border: #3a3326;
    --accent: #e0a052;
    --accent-dark: #f0b872;
    --accent-ink: #201200;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f;
  --surface: #201c15;
  --surface-2: #2a251c;
  --ink: #f1ece1;
  --muted: #b3a993;
  --border: #3a3326;
  --accent: #e0a052;
  --accent-dark: #f0b872;
  --accent-ink: #201200;
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3 { font-family: var(--serif); text-wrap: balance; line-height: 1.08; letter-spacing: -0.01em; font-weight: 600; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* =============================================================
   3. Utilities
   ============================================================= */
.wrap { max-width: 1160px; margin-inline: auto; padding-inline: 20px; }
.skip-link {
  position: fixed; top: -100px; left: 1rem; padding: .6rem 1rem;
  background: var(--ink); color: var(--bg); z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .4rem; }

/* =============================================================
   4. Header / footer
   ============================================================= */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.logo { font-family: var(--serif); font-size: 1.25rem; font-weight: 600; }
.logo span { color: var(--accent); }
.top-nav { display: none; gap: 1.5rem; font-weight: 600; font-size: .92rem; }
.top-nav a:hover { color: var(--accent-dark); }
@media (min-width: 720px) { .top-nav { display: flex; } }

.site-footer { border-top: 1px solid var(--border); padding: 2.2rem 0; color: var(--muted); font-size: .85rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; justify-content: space-between; }
.legal-links a { text-decoration: underline; text-underline-offset: 2px; }

/* =============================================================
   5. Hero
   ============================================================= */
.hero { padding: 2.6rem 0 1.6rem; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); max-width: 20ch; }
.hero-sub { margin-top: .8rem; max-width: 58ch; color: var(--muted); font-size: 1.05rem; }

/* =============================================================
   6. Tool card
   ============================================================= */
.tool-section { padding-bottom: 1.6rem; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-soft); padding: 1.2rem;
}
.tool-grid { display: grid; gap: 1.4rem; grid-template-columns: 1fr; }
@media (min-width: 960px) { .tool-grid { grid-template-columns: 1fr 1fr; align-items: start; } }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.2rem 1rem; text-align: center;
  cursor: pointer; color: var(--muted); transition: border-color .2s var(--ease-out), background .2s var(--ease-out);
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.dropzone svg { color: var(--accent); }
.dz-title { font-weight: 700; color: var(--ink); }
.dz-sub { font-size: .82rem; }

.crop-block { margin-top: 1rem; }
.crop-stage {
  position: relative; width: 100%; max-width: 360px; margin-inline: auto;
  border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border);
  touch-action: none; cursor: grab; background: var(--surface-2);
}
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { width: 100%; height: 100%; display: block; }
.range-row, .select-row, .check-row, .color-row {
  display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-top: .55rem; font-size: .88rem;
}
.range-row span, .select-row span, .color-row span { color: var(--muted); flex: 0 0 auto; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.range-row input[type="number"] { width: 5.5rem; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); }
.range-row output { width: 2.6rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.check-row { justify-content: flex-start; gap: .5rem; }
.check-row input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.select-row select { padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); }
.color-row input[type="color"] { width: 2.4rem; height: 1.8rem; border: 1px solid var(--border); border-radius: 6px; padding: 0; background: none; }

.controls-block { margin-top: 1.4rem; display: flex; flex-direction: column; gap: 1.2rem; }
.control-group .group-label { font-family: var(--sans); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: .5rem; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.segmented button { flex: 1; padding: .5rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 600; color: var(--muted); text-align: center; }
.segmented button.is-active { background: var(--accent); color: var(--accent-ink); }
.sub-control { margin-top: .7rem; }

/* preview column */
.preview-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; height: 100%; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; }
.preview-title { font-weight: 700; font-size: .9rem; }
.light-toggle { border: 1px solid var(--border); border-radius: 999px; padding: .55rem .9rem; font-size: .8rem; font-weight: 600; background: var(--surface); }
.light-toggle[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.viewer { position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.viewer canvas { width: 100%; height: 100%; display: block; }
.viewer-empty, .viewer-nowebgl {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 1.2rem; color: var(--muted); font-size: .88rem; pointer-events: none;
}
.viewer-empty[hidden], .viewer-nowebgl[hidden] { display: none; }

.warnings { margin-top: .8rem; display: flex; flex-direction: column; gap: .35rem; }
.warnings p { font-size: .82rem; padding: .65rem .8rem; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.warnings p.warn { color: var(--warn); }
.warnings p.ok { color: var(--ok); }

.download-row { display: flex; flex-direction: column; gap: .6rem; margin-top: 1rem; }
.btn { padding: .85rem 1.2rem; border-radius: 999px; font-weight: 700; font-size: .95rem; text-align: center; transition: transform .15s var(--ease-out), opacity .15s; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.privacy-badge { margin-top: .8rem; font-size: .78rem; color: var(--muted); }

/* =============================================================
   7. Ad placeholders
   ============================================================= */
.ad-slot {
  min-height: 90px; margin: 1.6rem auto; border: 1px dashed var(--border); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
  font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; background: var(--surface-2);
}
.ad-slot--leaderboard { max-width: 1160px; }
.ad-slot--incontent { max-width: 720px; min-height: 250px; }

.corner-toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 40;
  display: flex; align-items: center; gap: .6rem; background: var(--surface); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); padding: .8rem 1.1rem; box-shadow: var(--shadow-soft);
  font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.corner-toast[hidden] { display: none; }
.corner-toast button { font-size: 1.1rem; line-height: 1; color: var(--muted); }

.download-dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; max-width: 360px; width: calc(100% - 2rem);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-soft);
}
.download-dialog::backdrop { background: rgba(20, 16, 8, .45); }
.dialog-close { position: absolute; top: .6rem; right: .8rem; font-size: 1.3rem; color: var(--muted); }
.dialog-ad-label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: center; }
.dialog-ad-slot { min-height: 200px; border: 1px dashed var(--border); border-radius: var(--radius-sm); margin: .6rem 0 1rem; background: var(--surface-2); }
.dialog-msg { text-align: center; margin-bottom: 1rem; font-size: .92rem; }
.download-dialog .btn { width: 100%; }

/* =============================================================
   8. Content sections
   ============================================================= */
.section { padding: 3rem 0; }
.section-alt { background: var(--surface-2); }
.section h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); margin-bottom: 1.6rem; }
.prose { max-width: 760px; }
.prose p { margin-bottom: 1rem; color: var(--ink); }
.prose p + p { color: var(--muted); }

.steps { list-style: none; display: grid; gap: 1.2rem; counter-reset: step; }
.steps li h3 { font-size: 1.05rem; margin-bottom: .4rem; }
.steps li p { color: var(--muted); font-size: .92rem; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(3, 1fr); } }

.cards { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cards { grid-template-columns: repeat(2, 1fr); } }
.idea-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1.1rem 1.2rem; }
.idea-card h3 { font-size: 1rem; margin-bottom: .35rem; font-family: var(--sans); }
.idea-card p { color: var(--muted); font-size: .9rem; }

details { border-bottom: 1px solid var(--border); padding: .9rem 0; }
details summary { cursor: pointer; font-weight: 700; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "+ "; color: var(--accent-dark); }
details[open] summary::before { content: "– "; }
details p { margin-top: .6rem; color: var(--muted); font-size: .92rem; }

/* =============================================================
   9. Reduced motion
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn, .dropzone { transition: none; }
}
