/* ============================================================================
   LexiFocus — landing site
   Plain CSS, no build step. Tokens live on :root and are swapped wholesale by
   [data-theme], so the demo's colour picker re-skins the entire page.
   ========================================================================== */

/* --- Fonts. Self-hosted; zero third-party requests. ----------------------- */
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/assets/fonts/atkinson-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/assets/fonts/atkinson-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
/* Lexend and OpenDyslexic are only fetched if a visitor picks them. */
@font-face {
  font-family: 'Lexend';
  src: url('/assets/fonts/lexend-var.woff2') format('woff2-variations');
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('/assets/fonts/opendyslexic-400.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('/assets/fonts/opendyslexic-700.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}

/* --- Tokens --------------------------------------------------------------- */
:root,
:root[data-theme='cream'] {
  --bg:         #FDF8F0;
  --surface:    #FFFBF4;
  --ink:        #2A2622;  /* 14.2:1 on --bg */
  --ink-muted:  #4A4238;  /*  9.3:1 on --bg */
  --accent:     #0E5A54;  /*  7.6:1 on --bg */
  --accent-ink: #FDF8F0;
  --warm:       #B4472A;  /*  5.1:1 on --bg */
  --line:       #E3D9C9;
  --shadow:     0 2px 12px rgb(74 66 56 / 0.08);
  --grain-op:   0.03;
}
:root[data-theme='blue'] {
  --bg: #EAF2F8; --surface: #F4F9FC; --ink: #21303B; --ink-muted: #3C4E5C;
  --accent: #10505E; --accent-ink: #F4F9FC; --warm: #A63F22; --line: #CBDDE9;
  --shadow: 0 2px 12px rgb(33 48 59 / 0.10); --grain-op: 0.02;
}
:root[data-theme='contrast'] {
  --bg: #FFFFFF; --surface: #FFFFFF; --ink: #0B0B0B; --ink-muted: #1F1F1F;
  --accent: #10403C; --accent-ink: #FFFFFF; --warm: #8C2E12; --line: #6B6B6B;
  --shadow: none; --grain-op: 0;
}
:root[data-theme='dark'] {
  --bg: #171E26; --surface: #1F2833; --ink: #E8EDF2; --ink-muted: #BCC7D2;
  --accent: #7FD6C8; --accent-ink: #10201E; --warm: #F0A183; --line: #33404E;
  --shadow: 0 2px 12px rgb(0 0 0 / 0.35); --grain-op: 0;
}

:root {
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* 8px rhythm */
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 40px; --s5: 64px; --s6: 96px; --s7: 128px;

  /* fluid type scale */
  --t-xs:  0.875rem;
  --t-sm:  1rem;
  --t-md:  1.0625rem;                              /* 17px body */
  --t-lg:  clamp(1.125rem, 0.4vw + 1.05rem, 1.25rem);
  --t-xl:  clamp(1.35rem, 0.8vw + 1.15rem, 1.5625rem);
  --t-2xl: clamp(1.6rem, 1.4vw + 1.25rem, 2.0625rem);
  --t-3xl: clamp(2rem, 2.4vw + 1.4rem, 2.75rem);
  --t-4xl: clamp(2.4rem, 4vw + 1.4rem, 3.625rem);

  --r-sm: 6px; --r-md: 14px; --r-pill: 999px;
  --measure: 66ch;
  --dur: 180ms;
}

/* Honour the OS flag *and* the in-page toggle. */
@media (prefers-reduced-motion: reduce) {
  :root { --dur: 0ms; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
:root[data-motion='reduce'] { --dur: 0ms; }
:root[data-motion='reduce'] *,
:root[data-motion='reduce'] *::before,
:root[data-motion='reduce'] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

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

html {
  scroll-behavior: smooth;
  /* Sticky header must not obscure a focused/anchored target (WCAG 2.4.11). */
  scroll-padding-top: 88px;
}
:root[data-motion='reduce'] html { scroll-behavior: auto; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--t-md);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  transition: background-color var(--dur) ease, color var(--dur) ease;
}

/* Paper grain. Static, decorative, and off in the high-contrast and dark themes. */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0;
  opacity: var(--grain-op);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}
body > * { position: relative; z-index: 1; }

h1, h2, h3 {
  line-height: 1.15;
  text-wrap: balance;
  margin: 0 0 var(--s2);
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: var(--t-4xl); }
h2 { font-size: var(--t-3xl); }
h3 { font-size: var(--t-xl); letter-spacing: 0; }

p { margin: 0 0 var(--s2); max-width: var(--measure); }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

img, svg { max-width: 100%; }

/* One focus style, everywhere, verified in all four themes. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--warm);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute; left: var(--s2); top: -100px; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: var(--s1) var(--s2); border-radius: var(--r-sm);
  text-decoration: none; font-weight: 700;
}
.skip-link:focus { top: var(--s2); }

.wrap { width: min(1120px, 100% - 2 * var(--s3)); margin-inline: auto; }
.wrap.narrow { width: min(760px, 100% - 2 * var(--s3)); }

/* --- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 var(--s3);
  background: var(--accent); color: var(--accent-ink);
  border: 2px solid var(--accent); border-radius: var(--r-pill);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  transition: opacity var(--dur) ease;
}
.btn:hover { opacity: 0.88; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.btn-sm { min-height: 38px; padding: 0 var(--s2); font-size: var(--t-xs); }

.linkish {
  background: none; border: 0; padding: var(--s1);
  min-height: 38px;
  font: inherit; font-size: var(--t-xs); color: var(--ink-muted);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* --- Header / footer ------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner, .footer-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s2); flex-wrap: wrap; min-height: 64px;
}
.wordmark {
  display: inline-flex; align-items: center; gap: var(--s1);
  color: var(--ink); text-decoration: none;
  font-size: var(--t-lg); letter-spacing: -0.01em;
  min-height: 44px;
}
.wordmark b { font-weight: 700; color: var(--accent); }
.wordmark span { font-weight: 400; }
.mark {
  width: 28px; height: 28px; flex: none;
  fill: none; stroke: var(--accent); stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.mark .mark-rule { stroke: var(--warm); }
.nav-list {
  display: flex; align-items: center; gap: var(--s3);
  list-style: none; margin: 0; padding: 0; flex-wrap: wrap;
}
.nav-list a:not(.btn) {
  color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; min-height: 44px;
}
.nav-list a:not(.btn):hover { text-decoration: underline; }

.site-footer {
  border-top: 1px solid var(--line);
  padding-block: var(--s4);
  color: var(--ink-muted); font-size: var(--t-sm);
}
.site-footer p { margin: 0; }

/* --- Sections ------------------------------------------------------------- */
.hero { padding-block: clamp(48px, 7vw, 96px) 0; }
.band { padding-block: clamp(64px, 9vw, 128px); }
.band-alt { background: var(--surface); border-block: 1px solid var(--line); }
.band-cta { background: var(--surface); border-top: 1px solid var(--line); }

.eyebrow {
  font-size: var(--t-xs); font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: var(--s2);
}
.lede { font-size: var(--t-lg); color: var(--ink-muted); }
.cta-row { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }

/* --- Demo ----------------------------------------------------------------- */
.demo {
  margin-block: var(--s4) 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3vw, 40px);
}
.demo-title { font-size: var(--t-lg); margin-bottom: var(--s3); }
.demo-grid {
  display: grid; gap: var(--s4);
  grid-template-columns: minmax(240px, 300px) 1fr;
  align-items: start;
}
@media (max-width: 780px) {
  .demo-grid { grid-template-columns: 1fr; gap: var(--s3); }
}

.demo-controls { border: 0; margin: 0; padding: 0; min-width: 0; }
.field { margin: 0 0 var(--s3); max-width: none; }
.field > label,
.field > legend,
fieldset.field > legend {
  display: block; font-size: var(--t-xs); font-weight: 700;
  margin-bottom: var(--s1); padding: 0;
}
fieldset.field { border: 0; margin: 0 0 var(--s3); padding: 0; min-width: 0; }
.field output { font-weight: 400; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.control {
  width: 100%; min-height: 44px; padding: var(--s1) var(--s2);
  font: inherit; font-size: var(--t-sm);
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-sm);
}
input[type='range'].control {
  padding: 0; background: transparent; border: 0;
  accent-color: var(--accent);
}
select.control { cursor: pointer; }
/* Render each font option in its own face so the choice is visible before picking. */
select.control option[value='atkinson'] { font-family: 'Atkinson Hyperlegible', sans-serif; }
select.control option[value='lexend']   { font-family: 'Lexend', sans-serif; }
select.control option[value='odys']     { font-family: 'OpenDyslexic', sans-serif; }
select.control option[value='system']   { font-family: system-ui, sans-serif; }

/* Colour swatch chips */
.swatch-row, .radio-row { display: flex; flex-wrap: wrap; gap: var(--s1); }
/* Clipped rather than merely transparent: full-size absolute inputs stack at the
   container origin and swallow clicks meant for the first chip's label. */
.swatches input[type='radio'] {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  pointer-events: none;
}
.swatches label {
  display: inline-flex; align-items: center; gap: var(--s1);
  min-height: 44px; padding: 0 var(--s2);
  border: 2px solid var(--line); border-radius: var(--r-pill);
  font-size: var(--t-xs); cursor: pointer;
}
.swatches label::before {
  content: ''; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--ink-muted); flex: none;
}
.swatches label[data-swatch='cream']::before    { background: #FDF8F0; }
.swatches label[data-swatch='blue']::before     { background: #EAF2F8; }
.swatches label[data-swatch='contrast']::before { background: linear-gradient(90deg,#FFF 50%,#0B0B0B 50%); }
.swatches label[data-swatch='dark']::before     { background: #171E26; }
.swatches input:checked + label { border-color: var(--accent); font-weight: 700; }
.swatches input:focus-visible + label { outline: 3px solid var(--warm); outline-offset: 2px; }

.toggles, .actions { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; }

.hint {
  display: block;
  font-size: var(--t-xs); color: var(--ink-muted); margin: var(--s1) 0 0;
  max-width: var(--measure);
}

/* Passage */
.demo-stage { min-width: 0; }
.passage-label { font-size: var(--t-xs); color: var(--ink-muted); margin-bottom: var(--s1); }
.passage {
  position: relative; overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--s3);
  font-family: var(--demo-font, var(--font-body));
  font-size: clamp(1.125rem, 1vw + 1rem, 1.375rem);
  letter-spacing: var(--demo-letter, 0.06em);
  line-height: var(--demo-line, 1.6);
  word-spacing: var(--demo-word, normal);
}
.passage p { margin: 0; max-width: 46ch; position: relative; z-index: 1; }

.ruler {
  position: absolute; left: 0; right: 0; top: 0;
  height: var(--ruler-h, 0);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-bottom: 2px solid var(--accent);
  transform: translateY(var(--ruler-y, 0));
  transition: transform 90ms ease;
  pointer-events: none;
  display: none;
}
.passage[data-ruler='on'] .ruler { display: block; }
:root[data-motion='reduce'] .ruler { transition: none; }
@media (prefers-reduced-motion: reduce) { .ruler { transition: none; } }

.demo-payoff {
  margin: var(--s3) 0 0; font-size: var(--t-sm);
  color: var(--ink-muted); max-width: none;
}

/* --- Cards ---------------------------------------------------------------- */
.cards {
  list-style: none; margin: var(--s4) 0 0; padding: 0;
  display: grid; gap: var(--s3);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3); box-shadow: var(--shadow);
}
.card p { max-width: 34ch; margin-bottom: 0; color: var(--ink-muted); }
.ico {
  width: 44px; height: 44px; margin-bottom: var(--s2);
  fill: none; stroke: var(--accent); stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

/* --- Two-column blocks ---------------------------------------------------- */
.two-col {
  display: grid; gap: var(--s4); margin-top: var(--s4);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.two-col h3 { margin-bottom: var(--s2); }

.ticks { list-style: none; margin: 0; padding: 0; }
.ticks li {
  position: relative; padding-left: var(--s3); margin-bottom: var(--s1);
  color: var(--ink-muted);
}
.ticks li::before {
  content: '✓'; position: absolute; left: 0; color: var(--accent); font-weight: 700;
}
.ticks-no li::before { content: '✕'; color: var(--warm); }

.callout {
  margin-top: var(--s4); padding: var(--s3);
  background: var(--bg); border-left: 4px solid var(--warm);
  border-radius: var(--r-sm); font-size: var(--t-sm); color: var(--ink-muted);
  max-width: none;
}

.fork .panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: flex-start;
}
.fork .panel p { flex: 1; color: var(--ink-muted); }

/* --- Signup form ---------------------------------------------------------- */
.signup { margin-top: var(--s4); max-width: 34rem; }
.signup .control { max-width: 26rem; }
.radio-row label {
  display: inline-flex; align-items: center; gap: var(--s1);
  min-height: 44px; padding-right: var(--s2); cursor: pointer;
  font-size: var(--t-sm);
}
.radio-row input[type='radio'] { width: 20px; height: 20px; accent-color: var(--accent); }

.error {
  display: block; margin-top: var(--s1);
  font-size: var(--t-xs); font-weight: 700; color: var(--warm);
}
/* display:block would otherwise beat the [hidden] UA rule. */
.error[hidden] { display: none; }
.error::before { content: '⚠ '; }
.control[aria-invalid='true'] { border-color: var(--warm); border-width: 2px; }
.status { margin-top: var(--s2); font-weight: 700; color: var(--accent); }

/* --- Reflow --------------------------------------------------------------- */
@media (max-width: 560px) {
  .header-inner { min-height: 56px; flex-wrap: nowrap; }
  .nav-list { gap: var(--s2); }
  /* The section links wrap the sticky header onto three rows on a phone, which
     costs a fifth of the viewport. Keep the wordmark and the CTA; the page is
     short enough to scroll, and the footer still links everything. */
  .site-header .nav-list li:not(:last-child) { display: none; }
  .cta-row .btn { width: 100%; }
}
