/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #faf9fc;
  --surface: #ffffff;
  --surface-alt: #f4f1fb;
  --border: #e5e1f0;
  --text: #1c1a24;
  --text-soft: #3b3646;
  --text-muted: #6b6678;
  --accent: #7c3aed;
  --accent-dark: #6023d9;
  --accent-2: #ec4899;
  --accent-soft: #f5edff;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --warn-bg: #fff4e5;
  --warn-text: #92400e;
  --warn-border: #fcd9a8;
  --ad-bg: #f6f4fb;
  --ad-border: #c9c3de;
  --ad-text: #9089a8;
  --canvas-bg: #15121c;
  --radius-lg: 20px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(24, 12, 48, 0.08);
  --shadow-md: 0 10px 30px rgba(24, 12, 48, 0.12);
  --shadow-lg: 0 20px 60px rgba(24, 12, 48, 0.18);
  --gradient: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Poppins", var(--font-sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --container-w: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15121e;
    --surface: #1e1a2b;
    --surface-alt: #241f36;
    --border: #332c49;
    --text: #f1eef9;
    --text-soft: #cfc9e6;
    --text-muted: #aba2c6;
    --accent: #a78bfa;
    --accent-dark: #d8b4fe;
    --accent-2: #f472b6;
    --accent-soft: #2a2140;
    --danger: #f87171;
    --danger-bg: #3a1a1a;
    --warn-bg: #3a2a12;
    --warn-text: #fbbf24;
    --warn-border: #5a4420;
    --ad-bg: #251f38;
    --ad-border: #4a4166;
    --ad-text: #9084ab;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #15121e;
  --surface: #1e1a2b;
  --surface-alt: #241f36;
  --border: #332c49;
  --text: #f1eef9;
  --text-soft: #cfc9e6;
    --text-muted: #aba2c6;
  --accent: #a78bfa;
  --accent-dark: #d8b4fe;
  --accent-2: #f472b6;
  --accent-soft: #2a2140;
  --danger: #f87171;
  --danger-bg: #3a1a1a;
  --warn-bg: #3a2a12;
  --warn-text: #fbbf24;
  --warn-border: #5a4420;
  --ad-bg: #251f38;
  --ad-border: #4a4166;
  --ad-text: #9084ab;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; overflow-x: clip; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.12; letter-spacing: -0.01em; font-family: var(--font-display); }
ul, ol { list-style: none; padding: 0; }
::selection { background: var(--accent); color: #fff; }
input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* =============================================================
   3. Utilities
   ============================================================= */
.container { max-width: var(--container-w); margin-inline: auto; padding-inline: 1.25rem; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .7rem 1.1rem; background: var(--text); color: #fff;
  z-index: 9999; border-radius: 8px; font-weight: 600;
  transition: top .2s var(--ease-out);
}
.skip-link:focus { top: 1rem; }

.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;
}

/* =============================================================
   4. Typography
   ============================================================= */
h1 { font-size: clamp(1.7rem, 4.4vw, 2.7rem); }
h2 { font-size: clamp(1.4rem, 3vw, 2rem); margin-bottom: 1.1rem; }
h3 { font-size: 1.05rem; margin-bottom: .4rem; }
.hero-subtitle { color: var(--text-muted); font-size: clamp(1rem, 2vw, 1.15rem); max-width: 56ch; }
.seo-copy p { margin-bottom: 1rem; color: var(--text-soft); max-width: 74ch; }
.seo-copy p:last-child { margin-bottom: 0; }

/* =============================================================
   5. Components
   ============================================================= */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .85rem 1.4rem; border-radius: 999px; font-weight: 600; font-size: .96rem;
  transition: transform .15s var(--ease-out), box-shadow .15s var(--ease-out), background-color .15s var(--ease-out);
  white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.btn-primary { background: var(--gradient); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--surface-alt); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger-ghost { background: var(--danger-bg); color: var(--danger); }
.btn-danger-ghost:hover { filter: brightness(0.92); }
.btn-block { width: 100%; }
.btn-small { padding: .55rem 1rem; font-size: .85rem; }
.btn-download { margin-top: 1.4rem; font-size: 1.05rem; padding: 1.05rem 1.6rem; }
.btn-download.is-success { background: linear-gradient(135deg, #16a34a, #22c55e); }

/* Tool section wrapper */
.tool-section { padding-block: 1.5rem 0; }
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
}
@media (min-width: 720px) { .tool-card { padding: 1.75rem; } }

.js-required {
  background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm); padding: .9rem 1.1rem; font-weight: 600; margin-bottom: 1rem;
}

/* Format tabs */
.format-tabs {
  display: flex; gap: .5rem; overflow-x: auto; overflow-y: visible;
  padding-bottom: .3rem; margin-bottom: 1.1rem; scrollbar-width: thin;
}
.format-tab {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .6rem 1rem; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: .88rem; color: var(--text-muted);
  transition: all .15s var(--ease-out);
}
.format-tab span { font-size: .72rem; font-weight: 500; color: var(--text-muted); opacity: .8; }
.format-tab.is-active { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.format-tab.is-active span { color: var(--accent); }
.format-tab:hover { border-color: var(--accent); }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
  text-align: center; padding: 3rem 1.5rem; border: 2px dashed var(--border); border-radius: var(--radius);
  cursor: pointer; color: var(--text-muted); background: var(--surface-alt);
  transition: border-color .15s var(--ease-out), background-color .15s var(--ease-out);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.dropzone-icon { width: 44px; height: 44px; color: var(--accent); }
.dropzone-title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.dropzone-hint { font-size: .85rem; }
.upload-error {
  margin-top: .8rem; padding: .7rem 1rem; border-radius: var(--radius-sm);
  background: var(--danger-bg); color: var(--danger); font-size: .9rem; font-weight: 600;
}

/* Editor layout */
.editor { display: grid; gap: 1.5rem; margin-top: .25rem; }
@media (min-width: 960px) {
  .editor { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
}

.editor-canvas-col { max-width: 460px; margin-inline: auto; width: 100%; }
.canvas-stage {
  position: relative; width: 100%; aspect-ratio: var(--ar, 9 / 16);
  border-radius: var(--radius); overflow: hidden; background: var(--canvas-bg); box-shadow: var(--shadow-sm);
  touch-action: none;
}
.canvas-stage canvas { width: 100%; height: 100%; display: block; }

.selection-box {
  position: absolute; border: 2px dashed #fff; box-shadow: 0 0 0 2px var(--accent);
  border-radius: 6px; pointer-events: none;
}
.selection-delete {
  position: absolute; top: -14px; right: -14px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 1.1rem; line-height: 1; display: flex;
  align-items: center; justify-content: center; box-shadow: var(--shadow-sm); pointer-events: auto;
}

.canvas-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: .9rem; flex-wrap: wrap;
}
.zoom-control { display: flex; align-items: center; gap: .5rem; font-size: .82rem; color: var(--text-muted); flex: 1 1 120px; }
.zoom-control input[type="range"] { flex: 1; accent-color: var(--accent); }

/* Editor panel */
.editor-panel { display: flex; flex-direction: column; gap: 1rem; }
.panel-tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--border); }
.panel-tab {
  padding: .6rem .9rem; font-weight: 600; font-size: .92rem; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.panel-tab.is-active { color: var(--accent-dark); border-color: var(--accent); }
.panel-pane { display: none; }
.panel-pane.is-active { display: block; }

/* Filter grid */
.filter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.filter-swatch { display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .3rem; border-radius: var(--radius-sm); }
.filter-swatch-thumb {
  width: 100%; aspect-ratio: 1; border-radius: 10px; background-size: cover; background-position: center;
  border: 2px solid var(--border); transition: border-color .15s var(--ease-out);
}
.filter-swatch.is-active .filter-swatch-thumb { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.filter-swatch-label { font-size: .74rem; color: var(--text-muted); font-weight: 600; text-align: center; }
.filter-swatch.is-active .filter-swatch-label { color: var(--accent-dark); }

/* Text layer list */
.text-layer-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .8rem; }
.text-chip {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .55rem .8rem; border-radius: var(--radius-sm); background: var(--surface-alt);
  border: 1.5px solid transparent; font-size: .88rem; font-weight: 600; color: var(--text-muted);
  text-align: left; width: 100%;
}
.text-chip.is-active { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.text-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.text-chip-remove { flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; color: var(--text-muted); font-size: 1rem; line-height: 1; }
.text-chip-remove:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.text-empty-hint { font-size: .85rem; color: var(--text-muted); margin-top: .6rem; }

/* Field controls */
.text-controls { display: flex; flex-direction: column; gap: .9rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.field textarea, .field select {
  font-weight: 500; color: var(--text); padding: .6rem .7rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface); resize: vertical;
}
.field textarea:focus, .field select:focus { border-color: var(--accent); }
.field input[type="range"] { accent-color: var(--accent); }
.field-color { flex-direction: row; align-items: center; justify-content: space-between; }
.field-color input[type="color"] { width: 44px; height: 34px; border-radius: 8px; border: 1.5px solid var(--border); padding: 2px; background: var(--surface); }

.button-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.toggle-btn {
  flex: 1 1 0; min-width: 64px; padding: .55rem .6rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface); font-size: .85rem; font-weight: 600;
  color: var(--text-muted); text-align: center;
}
.toggle-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.toggle-btn-wide { flex: 1 1 45%; }

.privacy-badge { margin-top: 1.2rem; font-size: .85rem; color: var(--text-muted); text-align: center; }
.tool-limits { margin-top: .8rem; font-size: .82rem; color: var(--text-muted); text-align: center; }

/* Ad slots */
.ad-slot {
  border: 1.5px dashed var(--ad-border); border-radius: var(--radius); background: var(--ad-bg);
  min-height: 100px; display: flex; align-items: center; justify-content: center;
  color: var(--ad-text); font-weight: 700; letter-spacing: .08em; font-size: .8rem; margin-block: 2rem;
}
.ad-slot-label::before { content: "· "; }
.ad-slot-label::after { content: " ·"; }
.ad-slot--leaderboard { min-height: 90px; }
@media (min-width: 720px) { .ad-slot--leaderboard { min-height: 120px; } }
.ad-slot--incontent { min-height: 250px; max-width: 336px; margin-inline: auto; }
.ad-slot--popup { min-height: 220px; margin-block: 1rem; }
.ad-slot--corner { min-height: 90px; width: 100%; }

/* Download popup dialog */
.ad-dialog { border: none; border-radius: var(--radius-lg); padding: 0; max-width: 380px; width: calc(100% - 2rem); box-shadow: var(--shadow-lg); }
.ad-dialog::backdrop { background: rgba(20, 12, 40, .55); }
.ad-dialog-card { position: relative; padding: 1.5rem; }
.ad-dialog-close {
  position: absolute; top: .7rem; right: .7rem; width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-alt); font-size: 1.2rem; line-height: 1; color: var(--text-muted);
}
.ad-dialog-close:hover { background: var(--border); }
.ad-dialog-kicker { font-weight: 700; text-align: center; margin-bottom: .4rem; padding-right: 1.5rem; }

/* Corner toast */
.corner-ad {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 500; width: min(260px, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .9rem; opacity: 0; transform: translateY(16px);
  transition: opacity .3s var(--ease-out), transform .3s var(--ease-out);
}
.corner-ad.is-visible { opacity: 1; transform: translateY(0); }
.corner-ad-close {
  position: absolute; top: -10px; right: -10px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--text); color: #fff; font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}

/* Step icons */
.step-icon { display: inline-flex; width: 52px; height: 52px; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); margin-bottom: .8rem; }
.step-icon svg { width: 26px; height: 26px; }

/* FAQ */
.faq-list { display: flex; flex-direction: column; gap: .7rem; max-width: 74ch; }
.faq-list details {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1.1rem; background: var(--surface);
}
.faq-list summary {
  font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center;
  justify-content: space-between; gap: 1rem;
}
.faq-list summary::-webkit-details-marker { display: none; }
.faq-list summary::after { content: "+"; font-size: 1.3rem; font-weight: 400; color: var(--accent); flex-shrink: 0; }
.faq-list details[open] summary::after { content: "–"; }
.faq-list details p { margin-top: .6rem; color: var(--text-muted); }

/* =============================================================
   6. Sections
   ============================================================= */
.site-header { padding-block: 1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.logo { display: flex; align-items: center; gap: .5rem; font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.logo-icon { width: 28px; height: 28px; color: var(--accent); }
.header-tagline { font-size: .85rem; color: var(--text-muted); display: none; }
@media (min-width: 720px) { .header-tagline { display: block; } }

.hero { padding-block: 2.2rem 1.4rem; text-align: center; }
.hero h1 { max-width: 22ch; margin-inline: auto; }
.hero-subtitle { margin-inline: auto; margin-top: .8rem; }

.how-it-works { padding-block: 2.5rem; }
.steps { display: grid; gap: 1.5rem; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.step p { color: var(--text-muted); font-size: .94rem; }

.seo-copy { padding-block: 1rem 2.5rem; }

.faq { padding-block: 1rem 3rem; }

.site-footer { border-top: 1px solid var(--border); padding-block: 1.6rem; margin-top: 1rem; }
.footer-inner { display: flex; flex-direction: column; gap: .6rem; align-items: center; text-align: center; color: var(--text-muted); font-size: .85rem; }
@media (min-width: 720px) { .footer-inner { flex-direction: row; justify-content: space-between; text-align: left; } }
.footer-links { display: flex; gap: 1rem; }
.footer-links a:hover { color: var(--accent-dark); }

/* Legal pages */
.legal-page { padding-block: 2.5rem 4rem; max-width: 74ch; }
.legal-page h1 { margin-bottom: 1rem; }
.legal-page h2 { font-size: 1.15rem; margin-top: 1.6rem; }
.legal-page p, .legal-page li { color: var(--text-soft); margin-bottom: .8rem; }
.legal-page ul { list-style: disc; padding-left: 1.3rem; }
.legal-page .todo { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 1.2rem; }

.cookie-consent {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 800;
  display: flex; justify-content: center; padding: 1rem;
}
.cookie-consent[hidden] { display: none; }
.cookie-consent-card {
  width: min(680px, 100%); display: flex; flex-wrap: wrap; align-items: center; gap: .9rem 1.2rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 1rem 1.2rem;
}
.cookie-consent-text { flex: 1 1 260px; margin: 0; font-size: .88rem; color: var(--text-muted); }
.cookie-consent-text a { color: inherit; text-decoration: underline; }
.cookie-consent-actions { display: flex; gap: .6rem; flex: 0 0 auto; }

@media (max-width: 560px) {
  .cookie-consent { padding: .7rem; }
  .cookie-consent-card { flex-direction: column; align-items: stretch; }
  .cookie-consent-actions { justify-content: flex-end; }
}

/* =============================================================
   9. Reduced motion — only intrusive effects
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  .corner-ad { transition: opacity .01s linear; }
}
