/* ═══════════════════════════════════════════════════════════════════════
   Tokens

   Chart colours follow the project's data-viz palette. The single series
   hue was validated against both surfaces (lightness band, chroma floor,
   3:1 contrast) before use. Dark values are selected steps for the dark
   surface, not an automatic inversion.

   Dark is declared under both scopes: the media query follows the OS, the
   [data-theme] scope follows an explicit toggle and must win either way.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  /* Prose muted must clear 4.5:1 for small text; the palette's #898781 only
     reaches 3.5:1 on this surface, so it is reserved for chart chrome below. */
  --text-muted: #63625d;
  /* Graphical chrome — axis ticks, median rule. 3:1 is the applicable bar. */
  --chart-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --accent-ink: #184f95;
  --critical: #d03b3b;
  /* Button carries white label text, so it needs 4.5:1 against white — a bar
     the series hue misses in both modes. Step 500 of the same blue ramp is the
     only step that clears white text AND stays >=3:1 on both surfaces. */
  --btn-bg: #256abf;
  --btn-bg-hover: #1c5cab;

  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --wrap: 860px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #a8a79f;
    --chart-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --accent-ink: #86b6ef;
    --critical: #e66767;
    --btn-bg: #256abf;
    --btn-bg-hover: #2a78d6;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #a8a79f;
  --chart-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --accent-ink: #86b6ef;
  --critical: #e66767;
  --btn-bg: #256abf;
  --btn-bg-hover: #2a78d6;
}

/* ═══════════════════════════ base ═══════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }

/* The UA rule [hidden]{display:none} has specificity (0,1,0) — exactly the same
   as a class selector — and author styles win ties against the UA sheet. So any
   element carrying both `hidden` and a class that sets `display` (.field,
   .height-row, .unit-toggle, .feet-row) stays visible. This restores the
   attribute's meaning; !important is the documented fix for that collision. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 20px;
}

h1, h2, h3 { line-height: 1.25; font-weight: 600; }
h1 { font-size: 2rem; margin: 0 0 .5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.3rem; margin: 2.2rem 0 .6rem; }
p { margin: 0 0 1rem; }

a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

.skip-link {
  position: absolute; left: -9999px;
  background: var(--surface-1); padding: 10px 16px; border-radius: var(--radius);
}
.skip-link:focus { left: 12px; top: 12px; z-index: 100; }

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

/* ═══════════════════════════ chrome ═══════════════════════════ */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding-block: 14px;
}
.brand { font-weight: 650; font-size: 1.05rem; color: var(--text-primary); text-decoration: none; }
.site-header nav { display: flex; gap: 18px; font-size: .93rem; }

main { padding-bottom: 48px; }

.intro { padding-top: 36px; }
.lede { font-size: 1.1rem; color: var(--text-secondary); max-width: 62ch; }
.disclaimer { font-size: .9rem; color: var(--text-muted); }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  padding: 28px 0 40px;
  margin-top: 40px;
}
.site-footer nav { display: flex; gap: 20px; flex-wrap: wrap; font-size: .93rem; margin-bottom: 12px; }
.fine-print { font-size: .85rem; color: var(--text-muted); margin: 0; max-width: 68ch; }

/* ═══════════════════════════ form ═══════════════════════════ */

.tool {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-top: 8px;
}
.tool h2 { margin-top: 0; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 18px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field legend, .value-head label, .height-row > label {
  font-size: .88rem; font-weight: 600; color: var(--text-secondary);
}
.field-hint { font-size: .82rem; color: var(--text-muted); margin: 2px 0 0; line-height: 1.45; }

input[type="number"], select {
  font: inherit;
  font-size: .97rem;
  padding: 10px 12px;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  min-width: 0;
}

/* Explains a field's absence, so it is quieter than a real field: no control,
   no border, and the title carries label weight without pretending to be one. */
.field--note { justify-content: flex-start; gap: 4px; }
.field-note-title {
  font-size: .88rem; font-weight: 600; color: var(--text-secondary);
}
.field--note .field-hint { margin-top: 0; }

.field--radio { border: 0; margin: 0; padding: 0; min-width: 0; }
.field--radio legend { padding: 0; margin-bottom: 6px; }
.radio {
  display: flex; align-items: center; gap: 8px;
  font-size: .95rem; font-weight: 400; color: var(--text-primary);
  padding: 3px 0; cursor: pointer;
}
.radio input { accent-color: var(--series-1); width: 17px; height: 17px; margin: 0; }

.value-block {
  margin-top: 22px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.value-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 8px;
}
.value-inputs { display: flex; gap: 12px; flex-wrap: wrap; }
.input-with-unit { position: relative; flex: 1 1 190px; min-width: 130px; }
.input-with-unit input { padding-right: 52px; }
.unit {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: .85rem; color: var(--text-muted); pointer-events: none;
}
.feet-row { display: flex; gap: 12px; flex: 1 1 100%; }

.unit-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  background: var(--page);
}
.unit-toggle button {
  font: inherit; font-size: .82rem; font-weight: 600;
  padding: 5px 14px; border: 0; border-radius: 999px;
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.unit-toggle button.is-active { background: var(--btn-bg); color: #fff; }
.unit-toggle button:hover:not(.is-active):not(:disabled) { color: var(--text-primary); }
/* A disabled option must read as unavailable rather than merely unselected —
   without this it is pixel-identical to an enabled one and looks broken. */
.unit-toggle button:disabled {
  opacity: .45;
  cursor: not-allowed;
  text-decoration: line-through;
}

.height-row { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; max-width: 320px; }

.btn-primary {
  font: inherit; font-weight: 600; font-size: 1rem;
  margin-top: 20px; padding: 12px 22px;
  color: #fff; background: var(--btn-bg);
  border: 0; border-radius: var(--radius); cursor: pointer;
}
.btn-primary:hover { background: var(--btn-bg-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.form-error {
  margin-top: 16px; padding: 11px 14px;
  font-size: .92rem; color: var(--critical);
  border: 1px solid currentColor; border-radius: var(--radius);
  background: color-mix(in srgb, var(--critical) 8%, transparent);
}

/* ═══════════════════════════ results ═══════════════════════════ */

.results { margin-top: 32px; padding-top: 26px; border-top: 1px solid var(--border); }

.hero { text-align: center; margin-bottom: 6px; }
/* Proportional figures — tabular-nums makes a large number look loose. */
.hero-figure {
  font-family: var(--sans);
  font-size: clamp(3rem, 11vw, 4.6rem);
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}
.hero-label { font-size: .95rem; color: var(--text-secondary); margin-top: 6px; }

.result-summary {
  text-align: center; max-width: 56ch; margin: 14px auto 26px;
  color: var(--text-secondary);
}
.result-summary strong { color: var(--text-primary); }

.chart-figure { margin: 0; }
.chart-figure figcaption {
  font-size: .85rem; color: var(--text-muted);
  margin-top: 10px; max-width: 64ch;
}

/* ── chart marks ── */

.dist-chart { width: 100%; height: auto; display: block; overflow: visible; }

.chart-grid line { stroke: var(--gridline); stroke-width: 1; }
.chart-axis { stroke: var(--axis); stroke-width: 1; }

/* Area wash, never a saturated block. */
.chart-area { fill: var(--series-1); fill-opacity: .10; }
/* Same hue, more presence — emphasis, not a second category. */
.chart-area-below { fill: var(--series-1); fill-opacity: .26; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }

.chart-median { stroke: var(--axis); stroke-width: 1; }
.chart-median-label { fill: var(--chart-muted); font-size: 11px; font-family: var(--sans); }

.chart-you-line { stroke: var(--text-primary); stroke-width: 2; }
/* 2px surface ring keeps the dot legible where it crosses the curve. */
.chart-you-dot { fill: var(--text-primary); stroke: var(--surface-1); stroke-width: 2; }
.chart-you-label { fill: var(--text-primary); font-size: 12px; font-weight: 650; font-family: var(--sans); }

.chart-tick-labels text {
  fill: var(--chart-muted); font-size: 11px; font-family: var(--sans);
  font-variant-numeric: tabular-nums;
}
.chart-axis-label { fill: var(--text-secondary); font-size: 12px; font-family: var(--sans); }

.chart-hover { pointer-events: none; }
.chart-hover-line { stroke: var(--chart-muted); stroke-width: 1; }
.chart-hover-box { fill: var(--surface-1); stroke: var(--border); stroke-width: 1; }
.chart-hover-value { fill: var(--text-primary); font-size: 12px; font-weight: 650; font-family: var(--sans); }
.chart-hover-pct { fill: var(--text-secondary); font-size: 11px; font-family: var(--sans); }

/* ── table view ── */

.table-view { margin-top: 22px; }
.table-view summary {
  cursor: pointer; font-size: .9rem; font-weight: 600; color: var(--text-secondary);
  padding: 6px 0;
}
.table-view table {
  width: 100%; max-width: 440px; margin-top: 10px;
  border-collapse: collapse; font-size: .92rem;
  font-variant-numeric: tabular-nums;
}
.table-view caption { text-align: left; font-size: .85rem; color: var(--text-muted); padding-bottom: 8px; }
.table-view th, .table-view td {
  text-align: left; padding: 7px 12px 7px 0;
  border-bottom: 1px solid var(--border);
}
.table-view th { font-weight: 600; color: var(--text-secondary); }
.table-view .is-you td { font-weight: 650; color: var(--text-primary); }

.provenance { margin-top: 24px; font-size: .85rem; color: var(--text-muted); }
.provenance p { margin: 0 0 8px; }
.provenance .caveat { line-height: 1.55; max-width: 68ch; }
.badge {
  display: inline-block; margin-left: 6px; padding: 1px 8px;
  font-size: .72rem; font-weight: 650; letter-spacing: .02em;
  border-radius: 999px; color: #fff; background: var(--btn-bg);
}
/* Muted badge also carries white text, so it needs a dark enough ground. */
.badge-muted { background: #5c5b56; }

.explainer { margin-top: 40px; max-width: 68ch; }
.explainer p { color: var(--text-secondary); }

/* ═══════════════════════════ ad slots ═══════════════════════════

   Deliberately distinct from content: own surface, dashed hairline, and a
   persistent "Advertisement" label. AdSense policy forbids ads that could be
   mistaken for site content — do not restyle these to blend in.
   Heights are reserved so switching ads on causes no layout shift.
   ═══════════════════════════════════════════════════════════════ */

.ad-slot {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  margin: 28px 0;
  padding: 12px;
  background: var(--surface-1);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.ad-slot--leaderboard { min-height: 100px; }
.ad-slot--rectangle { min-height: 260px; }
.ad-slot--footer { min-height: 100px; margin-top: 0; }

.ad-slot-label {
  position: absolute; top: 4px; left: 10px;
  font-size: .64rem; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-muted);
}
.ad-slot-note { font-size: .8rem; color: var(--text-muted); text-align: center; }
.ad-slot .adsbygoogle { width: 100%; }

/* ═══════════════════════════ prose pages ═══════════════════════════ */

.prose { max-width: 68ch; padding-top: 32px; }
.prose p, .prose li { color: var(--text-secondary); }
.prose li { margin-bottom: .4rem; }
.prose table {
  width: 100%; border-collapse: collapse; font-size: .9rem; margin: 16px 0 24px;
}
.prose th, .prose td {
  text-align: left; padding: 9px 14px 9px 0;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.prose th { font-weight: 600; color: var(--text-primary); }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .88em; padding: 1px 5px;
  background: var(--page); border: 1px solid var(--border); border-radius: 4px;
}
.updated { font-size: .85rem; color: var(--text-muted); }

/* Wide content scrolls inside its own box; the page body never scrolls sideways. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .tool { padding: 18px; border-radius: 12px; }
  h1 { font-size: 1.65rem; }
  .site-header .wrap { padding-block: 12px; }
  .site-header nav { gap: 14px; font-size: .88rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
