/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  /* Dark is the primary identity — serious, editorial, precision-tool mood */
  --bg: #15181c;
  --surface: #1d2126;
  --surface-2: #262b32;
  --border: #363c46;
  --text: #f5f6f8;
  --text-muted: #a8adb8;
  --text-faint: #6f7580;
  --accent: #34d399;
  --accent-dark: #22b881;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --ink-on-accent: #0d1310;
  --ok: #3ddc97;
  --warn: #ffb020;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Manrope", var(--sans);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fb;
    --surface: #ffffff;
    --surface-2: #f0f2f7;
    --border: #e1e5ee;
    --text: #171a21;
    --text-muted: #5b6272;
    --text-faint: #8890a0;
    --accent: #047857;
    --accent-dark: #036249;
    --accent-soft: #e3f6ee;
    --ink-on-accent: #0d1310;
    --ok: #17845a;
    --warn: #b45309;
    --shadow: 0 2px 10px rgba(20, 25, 40, 0.06), 0 1px 2px rgba(20,25,40,.04);
    --shadow-lg: 0 20px 50px rgba(20, 25, 40, 0.16);
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
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(--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;
}
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.15; font-family: var(--display); letter-spacing: -0.01em; }
::selection { background: var(--accent); color: var(--ink-on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.container { width: 100%; max-width: 1080px; margin-inline: auto; padding-inline: 1.25rem; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--text); color: var(--bg);
  z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* =============================================================
   3. Header
   ============================================================= */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 40; }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding-block: .9rem; }
.logo { display: flex; align-items: center; gap: .5rem; font-family: var(--display); font-weight: 800; font-size: 1.05rem; }
.header-nav { display: none; gap: 1.5rem; font-size: .92rem; font-weight: 600; color: var(--text-muted); }
.header-nav a:hover { color: var(--accent); }
@media (min-width: 720px) { .header-nav { display: flex; } }

/* =============================================================
   4. Hero + tool card
   ============================================================= */
.hero {
  padding-block: 2.2rem 1.6rem;
  position: relative;
}
.hero::before {
  content: "";
  position: absolute;
  top: -6%; left: 50%;
  width: min(900px, 140%);
  height: 420px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--accent) 20%, transparent) 0%, transparent 70%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
}
.hero > * { position: relative; z-index: 1; }

.eyebrow {
  display: inline-flex; align-items: center; gap: .55rem;
  font-size: .78rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent); margin-bottom: .9rem;
}
.eyebrow::before { content: ""; width: 18px; height: 2px; background: var(--accent); display: inline-block; border-radius: 2px; }

.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 800; max-width: 24ch; }
.hero h1 .hl {
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, white));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub { margin-top: .8rem; color: var(--text-muted); max-width: 62ch; font-size: 1.02rem; text-align: justify; text-justify: inter-word; }

.tool-card {
  margin-top: 1.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mode-tabs {
  display: flex; flex-wrap: wrap; gap: .25rem;
  padding: .6rem .6rem 0;
  border-bottom: 1px solid var(--border);
}
.mode-tab {
  padding: .65rem 1rem;
  font-size: .88rem; font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color .15s var(--ease-out), background .15s var(--ease-out);
}
.mode-tab:hover { color: var(--text); background: var(--surface-2); }
.mode-tab.is-active { color: var(--accent); background: var(--accent-soft); }

.js-warning { margin: 1.2rem; padding: .9rem 1rem; background: var(--accent-soft); border-radius: var(--radius-sm); color: var(--text); }

.mode-panel { padding: 1.4rem; }
.mode-panel[hidden] { display: none; }

.panel-grid { display: grid; gap: 1.6rem; grid-template-columns: minmax(0, 1fr); min-width: 0; }
@media (min-width: 720px) { .panel-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.panel-col { min-width: 0; }
.panel-controls { display: flex; flex-direction: column; gap: .95rem; min-width: 0; }

.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .8rem; min-width: 0; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field-inline { display: flex; gap: .4rem; min-width: 0; }
.field-inline input[type="number"] { flex: 1; min-width: 0; }

input[type="number"], input[type="text"], select {
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .95rem;
  width: 100%;
}
input[type="color"] {
  width: 46px; height: 38px; padding: 2px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface);
}
select { flex: 0 0 auto; width: auto; min-width: 4.5rem; }
.unit-echo { display: flex; align-items: center; padding: 0 .6rem; color: var(--text-faint); font-size: .88rem; }

.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text-muted); }
.checkbox-row input { width: 16px; height: 16px; }

.tiles-info {
  font-size: .85rem; color: var(--accent-dark); font-weight: 600;
  background: var(--accent-soft); padding: .55rem .75rem; border-radius: var(--radius-sm);
}
.hint-note { font-size: .8rem; color: var(--text-faint); }

.btn-primary {
  margin-top: .3rem;
  padding: .85rem 1.2rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 85%, white), var(--accent-dark));
  color: var(--ink-on-accent);
  font-weight: 700;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
  transition: filter .15s var(--ease-out), transform .1s var(--ease-out);
}
.btn-primary:hover:not(:disabled) { filter: brightness(0.94); }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary.is-loading { position: relative; color: transparent; }
.btn-primary.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  border: 2.5px solid rgba(24,19,10,.35); border-top-color: var(--ink-on-accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-text { align-self: flex-start; font-size: .85rem; font-weight: 600; color: var(--accent); }
.btn-text:hover { text-decoration: underline; }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  padding: 2.2rem 1.2rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s var(--ease-out), background .15s var(--ease-out);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.dz-text { font-weight: 600; color: var(--text); }
.dropzone.is-dragover .dz-text, .dropzone:hover .dz-text { color: inherit; }
.dz-sub { font-size: .8rem; color: var(--text-faint); }

.preview-box { margin-top: 1rem; display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.preview-box img { max-height: 240px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* Shape / letter / ruler / grid previews */
.shape-preview, .letter-preview, .ruler-preview, .grid-preview {
  min-height: 220px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-faint);
}
.letter-preview { font-family: Arial, sans-serif; font-weight: 800; font-size: 5rem; color: var(--text); }
.shape-preview .shape-el { background: var(--accent); }
.ruler-preview { background-image: repeating-linear-gradient(90deg, var(--border) 0 1px, transparent 1px 20px); }
.grid-preview { background-image: repeating-linear-gradient(0deg, var(--border) 0 1px, transparent 1px 16px), repeating-linear-gradient(90deg, var(--border) 0 1px, transparent 1px 16px); }

.sub-tabs { display: flex; gap: .4rem; padding: 1.2rem 1.4rem 0; }
.sub-tab { padding: .5rem .9rem; font-size: .85rem; font-weight: 600; color: var(--text-muted); background: var(--surface-2); border-radius: 999px; }
.sub-tab.is-active { background: var(--accent); color: var(--ink-on-accent); }
.sub-panel { padding: 1.2rem 1.4rem 1.4rem; }
.sub-panel[hidden] { display: none; }

.calib-box { padding: .4rem 0 1rem; display: flex; flex-direction: column; gap: 1rem; max-width: 46rem; }
.calib-list { padding-left: 1.2rem; color: var(--text-muted); display: flex; flex-direction: column; gap: .3rem; }

.tool-footer { padding: 1rem 1.4rem 1.4rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .4rem; }
.privacy-badge { font-size: .85rem; color: var(--ok); font-weight: 600; }
.limits-note { font-size: .78rem; color: var(--text-faint); }

/* =============================================================
   5. Ad slots (placeholders only)
   ============================================================= */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-faint);
  position: relative;
}
.ad-label {
  font-size: .72rem; letter-spacing: .12em; font-weight: 700;
  color: var(--text-faint);
  border: 1px solid var(--border);
  padding: .2rem .5rem; border-radius: 4px; text-transform: uppercase;
}
.ad-leaderboard { min-height: 90px; margin-block: 1.6rem; }
.ad-incontent { min-height: 250px; margin-block: 1.6rem; max-width: 336px; margin-inline: auto; }
.ad-popup { min-height: 200px; width: 100%; }

.corner-toast {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 60;
  display: flex; align-items: center; gap: .6rem;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); border-radius: var(--radius-sm);
  padding: .7rem 2.2rem .7rem .9rem; min-width: 160px; min-height: 56px;
}
.corner-toast[hidden] { display: none; }
.corner-toast-close {
  position: absolute; top: .3rem; right: .4rem;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 1.1rem; line-height: 1;
}
.corner-toast-close:hover { background: var(--surface-2); color: var(--text); }

.download-dialog {
  border: none; border-radius: var(--radius); padding: 1.4rem;
  box-shadow: var(--shadow-lg); background: var(--surface); color: var(--text);
  width: min(360px, 90vw);
}
.download-dialog::backdrop { background: rgba(10, 12, 18, .55); }
.btn-dialog-close { width: 100%; margin-top: 1rem; }

/* =============================================================
   6. Sections
   ============================================================= */
.section { padding-block: 2.4rem; }
.section h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 800; }
.section-sub { color: var(--text-muted); margin-top: .4rem; }

.steps-grid { list-style: none; display: grid; gap: 1.1rem; margin-top: 1.4rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .steps-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.step-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.3rem; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 800; margin-bottom: .7rem;
}
.step-card h3 { font-size: 1.02rem; margin-bottom: .35rem; }
.step-card p { color: var(--text-muted); font-size: .92rem; }

.seo-text { margin-top: 2.2rem; display: flex; flex-direction: column; gap: 1rem; max-width: 74ch; }
.seo-text h3 { font-size: 1.15rem; }
.seo-text p { color: var(--text-muted); text-align: justify; text-justify: inter-word; }

.usos-grid { display: grid; gap: 1rem; margin-top: 1.4rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 540px) { .usos-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) { .usos-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.uso-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.uso-card h3 { font-size: .98rem; margin-bottom: .3rem; }
.uso-card p { color: var(--text-muted); font-size: .88rem; }

.faq-list { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.4rem; max-width: 74ch; }
.faq-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .9rem 1.1rem; }
.faq-item summary { cursor: pointer; font-weight: 700; font-size: .96rem; list-style: none; display: flex; justify-content: space-between; gap: 1rem; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; color: var(--accent); font-weight: 800; }
.faq-item[open] summary::after { content: "–"; }
.faq-item p { margin-top: .6rem; color: var(--text-muted); font-size: .92rem; text-align: justify; text-justify: inter-word; }

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

/* =============================================================
   8. Legal page skeletons
   ============================================================= */
.legal-page { max-width: 74ch; margin-inline: auto; padding: 2.4rem 1.25rem 4rem; display: flex; flex-direction: column; gap: 1rem; }
.legal-page h1 { font-size: 1.8rem; }
.legal-page h2 { font-size: 1.15rem; margin-top: .6rem; }
.legal-page p, .legal-page li { color: var(--text-muted); }
