/* ============================================================================
   80in8 — stylesheet
   ----------------------------------------------------------------------------
   Contents
     1. Design tokens (light / dark, per the validated reference palette)
     2. Base & reset
     3. Utilities
     4. Header & nav
     5. Hero
     6. Buttons
     7. App panel & screens
     8. Screen: home (settings, history)
     9. Screen: test (meters, question, input, helpers)
    10. Screen: results (hero figure, tiles, table, review)
    11. Guide article & FAQ
    12. Footer
    13. Focus mode & responsive
    14. Reduced motion & forced colors
   ========================================================================== */

/* 1. Design tokens ---------------------------------------------------------- */

:root {
  color-scheme: light;
  /* chrome & ink */
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  /* marks & accents */
  --accent: #2a78d6;        /* meter fill, progress marks */
  --track: #cde2fb;         /* lighter step of the same ramp (meter track) */
  --action: #1c5cab;        /* primary button background (AA with white ink) */
  --action-ink: #ffffff;
  --link: #1c5cab;
  --focus: #2a78d6;
  /* status (always paired with a text label, never color alone) */
  --good: #006300;
  --warn: #fab219;
  --crit: #d03b3b;
  /* misc */
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.05);
  --radius: 10px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --track: #104281;       /* darker step of the same ramp on the dark surface */
    --action: #3987e5;
    --action-ink: #0b0b0b;
    --link: #5598e7;
    --focus: #3987e5;
    --good: #0ca30c;
    --warn: #fab219;
    --crit: #d03b3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hairline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --track: #104281;
  --action: #3987e5;
  --action-ink: #0b0b0b;
  --link: #5598e7;
  --focus: #3987e5;
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* 2. Base & reset ----------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
}

h1, h2, h3 { line-height: 1.25; overflow-wrap: break-word; }
h1 { font-size: clamp(2rem, 5.5vw, 3.25rem); font-weight: 750; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.375rem, 3vw, 1.75rem); font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 1.0625rem; font-weight: 650; }

p { overflow-wrap: break-word; }

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

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

input, select, button { font: inherit; color: inherit; }

/* 3. Utilities -------------------------------------------------------------- */

.container { max-width: 60rem; margin-inline: auto; padding-inline: 1.25rem; }

.hidden { display: none !important; }

/* The hidden attribute must always win, even over classes that set
   display (e.g. .btn's inline-flex) — otherwise buttons toggled via
   .hidden stay visible in real browsers. */
[hidden] { display: none !important; }

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

.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 100;
  background: var(--surface); color: var(--ink);
  padding: 0.5rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  text-decoration: none; transition: top 120ms ease;
}
.skip-link:focus { top: 1rem; }

/* 4. Header & nav ----------------------------------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--page);
  border-bottom: 1px solid var(--hairline);
}

.header-row {
  display: flex; align-items: center; gap: 1rem;
  min-height: 3.5rem;
}

.brand {
  font-weight: 800; font-size: 1.25rem; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.brand-slash { color: var(--accent); padding-inline: 1px; }

.site-nav { display: flex; gap: 0.25rem; margin-left: auto; }
.site-nav a {
  color: var(--ink-2); text-decoration: none;
  padding: 0.4rem 0.7rem; border-radius: 999px;
}
.site-nav a:hover { color: var(--ink); background: var(--surface); }

.theme-toggle {
  min-width: 3.5rem; min-height: 2.25rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-size: 0.8125rem; font-weight: 600;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--hairline); }

/* 5. Hero ------------------------------------------------------------------- */

.hero { padding: clamp(3rem, 8vw, 5.5rem) 0 clamp(2rem, 5vw, 3.5rem); }

.hero-tagline {
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  color: var(--ink-2); max-width: 38rem; margin: 0.75rem 0 1.75rem;
}

.hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 0 0 1.75rem; }

.hero-facts {
  list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin: 0; padding: 0;
}
.hero-facts li {
  font-size: 0.875rem; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.25rem 0.85rem;
}
.hero-facts strong { color: var(--ink); font-weight: 700; }

.hero-scoring {
  margin: 1rem 0 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
  max-width: 38rem;
}
.hero-scoring strong { color: var(--ink); }

.hero-scoring-note {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* Net-score rating bands (labels carry the meaning; dots are decoration) */
.hero-bands {
  list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem;
  margin: 0.75rem 0 0; padding: 0;
  font-size: 0.875rem; color: var(--ink-2);
}
.hero-bands li { display: inline-flex; align-items: center; gap: 0.4rem; }
.hero-bands strong { color: var(--ink); font-weight: 650; }
.band-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.d-cracked { background: #008300; }
.d-excellent { background: #1c5cab; }
.d-strong { background: #0369a1; }
.d-solid { background: #b45309; }
.d-practice { background: #d03b3b; }
:root[data-theme="dark"] .d-cracked { background: #0ca30c; }
:root[data-theme="dark"] .d-excellent { background: #5598e7; }
:root[data-theme="dark"] .d-strong { background: #38bdf8; }
:root[data-theme="dark"] .d-solid { background: #fab219; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .d-cracked { background: #0ca30c; }
  :root:where(:not([data-theme="light"])) .d-excellent { background: #5598e7; }
  :root:where(:not([data-theme="light"])) .d-strong { background: #38bdf8; }
  :root:where(:not([data-theme="light"])) .d-solid { background: #fab219; }
}

/* 6. Buttons ------------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0.55rem 1.1rem;
  font-weight: 650; font-size: 0.9375rem;
  text-decoration: none; cursor: pointer;
  min-height: 44px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--action); color: var(--action-ink);
}
.btn-primary:not(:disabled):hover { filter: brightness(1.08); }

.btn-ghost {
  background: var(--surface); color: var(--ink);
  border-color: var(--border);
}
.btn-ghost:not(:disabled):hover { border-color: var(--muted); }

.btn-lg { font-size: 1.0625rem; padding: 0.75rem 1.5rem; }
.btn-sm { min-height: 36px; font-size: 0.875rem; padding: 0.35rem 0.85rem; }

/* 7. App panel & screens ------------------------------------------------------ */

.app-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 3.5vw, 2.5rem);
  margin-bottom: 3rem;
}

.app-heading { margin: 0 0 1.25rem; }

/* 8. Screen: home ------------------------------------------------------------- */

.settings { margin: 0; }

.seg-fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }

.segmented { display: inline-flex; background: var(--page); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  padding: 0.45rem 1.4rem; border-radius: 7px;
  font-weight: 650; font-size: 0.9375rem; color: var(--ink-2);
  cursor: pointer; min-height: 38px; display: inline-flex; align-items: center;
  transition: background 120ms ease, color 120ms ease;
}
.segmented input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(11, 11, 11, 0.12); }
.segmented input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }

.settings-grid {
  display: flex; flex-wrap: wrap; gap: 1rem 1.5rem;
  margin-bottom: 1rem;
}

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 8.5rem; }
.field label { font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }

.field input[type="number"], .field select {
  background: var(--page);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.5rem 0.7rem; min-height: 44px;
  font-size: 1rem; color: var(--ink);
}
.field input[type="number"]:focus-visible, .field select:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px;
}

.field-check { flex-direction: row; align-items: center; gap: 0.55rem; min-height: 44px; padding-top: 1.3rem; }
.field-check input { width: 1.15rem; height: 1.15rem; accent-color: var(--action); }
.field-check label { font-size: 1rem; font-weight: 500; color: var(--ink); }

.mode-note {
  font-size: 0.9375rem; color: var(--ink-2);
  background: var(--page); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem; margin: 0.5rem 0 1.5rem;
  max-width: 42rem;
}

.btn-start { width: 100%; max-width: 24rem; }

.home-secondary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  margin-top: 1.5rem;
}
.best-line { margin: 0; color: var(--ink-2); font-size: 0.9375rem; }
.best-line strong { color: var(--ink); }

.history { margin-top: 2rem; border-top: 1px solid var(--hairline); padding-top: 1.25rem; }
.history h3 { margin: 0 0 0.75rem; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li {
  display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; align-items: baseline;
  padding: 0.5rem 0; border-bottom: 1px solid var(--hairline);
  font-size: 0.9375rem; color: var(--ink-2);
}
.recent-list li:last-child { border-bottom: 0; }
.recent-list .r-date { min-width: 9.5rem; color: var(--muted); font-size: 0.875rem; }
.recent-list .r-score { color: var(--ink); font-weight: 650; }
.recent-list .r-detail { margin-left: auto; }

.noscript-note { color: var(--crit); font-weight: 600; }

/* 9. Screen: test ----------------------------------------------------------------
   Meters: the fill carries severity (accent -> warning -> critical); the
   unfilled track is a lighter step of the same ramp so state reads across
   the whole bar. Text labels always sit next to the bars — never color alone. */

.test-top {
  display: flex; gap: 1.5rem; margin-bottom: 1.25rem;
}
.test-meter { flex: 1; min-width: 0; }
.test-clock-meter { flex: 0 0 11rem; }

.meter-label {
  margin: 0 0 0.35rem; font-size: 0.875rem; font-weight: 600; color: var(--ink-2);
}
.clock {
  font-size: 1.25rem; font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.clock.warn { color: var(--warn); }
.clock.crit { color: var(--crit); }
.test-clock-meter .meter-label { text-align: right; }

.meter {
  height: 8px; border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 160ms linear, background-color 160ms linear;
}
.meter-fill.warn { background: var(--warn); }
.meter-fill.crit { background: var(--crit); }

.question {
  margin: clamp(1.5rem, 5vw, 3rem) 0;
  text-align: center;
  font-size: clamp(2.4rem, 9vw, 4.25rem);
  font-weight: 680;
  letter-spacing: -0.01em;
  min-height: 1.4em;
  color: var(--ink);
  font-variant-numeric: proportional-nums;
}
.question sup { font-size: 0.55em; }

/* Multiple-choice options (the real test's answer format) */
.options {
  display: grid; gap: 0.7rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 30rem; margin: 0 auto;
}
.options[hidden] { display: none; }
.opt {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 56px;
  background: var(--page);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 1.25rem; font-weight: 650;
  cursor: pointer;
  font-variant-numeric: proportional-nums;
}
.opt:hover { border-color: var(--muted); }
.opt:active { background: var(--track); }
.opt-key {
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--hairline); border-radius: 4px;
  padding: 0 0.4rem; line-height: 1.4;
}
@media (pointer: coarse) { .opt-key { display: none; } }

.answer-actions {
  display: flex; justify-content: center; gap: 0.6rem;
  margin-top: 0.9rem;
}

.res-rating {
  text-align: center; font-weight: 650; font-size: 1.0625rem;
  margin: 0 auto 1.75rem; max-width: 34rem;
}
.res-rating.good { color: var(--good); }
.res-rating.info { color: var(--link); }
.res-rating.strong { color: #0369a1; }
.res-rating.warn { color: #8a6100; }
.res-rating.bad { color: var(--crit); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .res-rating.warn { color: var(--warn); }
  :root:where(:not([data-theme="light"])) .res-rating.strong { color: #38bdf8; }
}
:root[data-theme="dark"] .res-rating.strong { color: #38bdf8; }
:root[data-theme="dark"] .res-rating.warn { color: var(--warn); }

.res-bar {
  text-align: center; color: var(--ink-2); font-size: 0.9375rem;
  margin: -0.75rem 0 2rem;
}

.answer-form {
  display: flex; justify-content: center; gap: 0.6rem;
  max-width: 30rem; margin: 0 auto;
}
.answer-form[hidden] { display: none; }
#answer-input {
  flex: 1; min-width: 0;
  background: var(--page);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 1.25rem; font-weight: 600;
  text-align: center;
  font-variant-numeric: proportional-nums;
}
#answer-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
#answer-input:disabled { opacity: 0.5; }

.helper-keys {
  display: none;
  justify-content: center; gap: 0.6rem;
  margin-top: 0.9rem;
}
.helper-keys .key {
  min-width: 56px; min-height: 44px;
  background: var(--page); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.15rem; font-weight: 600; color: var(--ink-2);
  cursor: pointer;
}
.helper-keys .key:active { background: var(--track); }

@media (pointer: coarse) {
  .helper-keys { display: flex; }
}

.feedback {
  text-align: center; margin: 1.25rem auto 0;
  font-size: 1.0625rem; font-weight: 650;
  min-height: 1.6em;
}
.feedback.ok { color: var(--good); }
.feedback.bad { color: var(--crit); }

.test-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 1.5rem; min-height: 2.5rem;
}
.score-chip {
  margin: 0; font-size: 0.9375rem; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.score-chip strong { color: var(--ink); }

/* 10. Screen: results ---------------------------------------------------------
   Stat tiles: label (sentence case) + value (semibold, proportional figures).
   One hero figure per view; tabular figures only inside table columns. */

.res-sub { color: var(--ink-2); margin: -0.5rem 0 1.5rem; }

.hero-figure { text-align: center; margin: 0.5rem 0 1.75rem; }
.hero-value {
  margin: 0;
  font-size: clamp(3.25rem, 9vw, 4.5rem);
  font-weight: 750; letter-spacing: -0.02em;
  font-variant-numeric: proportional-nums;
}
.hero-denom { color: var(--muted); font-weight: 600; font-size: 0.55em; }
.hero-label { margin: 0.1rem 0 0; color: var(--ink-2); font-weight: 600; }

.tiles {
  display: grid; gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  margin-bottom: 2rem;
}
.tile {
  background: var(--page);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.tile-label { margin: 0; font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); }
.tile-value { margin: 0.15rem 0 0; font-size: 1.5rem; font-weight: 700; }

.res-section { margin: 0 0 2rem; }
.res-section h3 { margin: 0 0 0.75rem; font-size: 1rem; }

.table-wrap { overflow-x: auto; }
#res-table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
#res-table th, #res-table td {
  text-align: left; padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
}
#res-table th { color: var(--ink-2); font-size: 0.8125rem; font-weight: 600; }
#res-table td.num, #res-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
#res-table tbody tr:last-child td { border-bottom: 0; }

.review-list { list-style: none; margin: 0; padding: 0; }
.review-list li {
  padding: 0.65rem 0; border-bottom: 1px solid var(--hairline);
}
.review-list li:last-child { border-bottom: 0; }
.rev-q { margin: 0; font-weight: 650; font-size: 1.0625rem; }
.rev-answers { margin: 0.2rem 0 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; font-size: 0.9375rem; color: var(--ink-2); }
.rev-answers .rev-yours.wrong { color: var(--crit); font-weight: 600; }
.rev-answers .rev-correct { color: var(--good); font-weight: 600; }

.res-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.5rem; }

/* 11. Guide article & FAQ ------------------------------------------------------ */

.guide { max-width: 44rem; padding-bottom: 3rem; }

.guide section { margin-bottom: 2.5rem; }
.guide h2 { margin: 0 0 0.9rem; }
.guide h3 { margin: 1.6rem 0 0.5rem; font-size: 1.0625rem; }
.guide p { color: var(--ink-2); }
.guide p strong, .guide li strong { color: var(--ink); }
.guide ul, .guide ol { color: var(--ink-2); padding-left: 1.4rem; }
.guide li { margin: 0.3rem 0; }

#faq details {
  border-bottom: 1px solid var(--hairline);
}
#faq details:last-child { border-bottom: 0; }
#faq summary {
  cursor: pointer; padding: 0.85rem 0;
  font-weight: 650; color: var(--ink);
  list-style-position: outside;
}
#faq details[open] summary { color: var(--link); }
#faq details p { margin: 0 0 0.9rem; }

/* 12. Footer --------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--hairline);
  padding: 1.75rem 0 2.25rem;
  color: var(--muted); font-size: 0.875rem;
}
.site-footer p { margin: 0.25rem 0; }

/* 13. Focus mode & responsive ----------------------------------------------------- */

@media (max-width: 720px) {
  .test-top { flex-direction: column-reverse; gap: 0.9rem; }
  .test-clock-meter { flex: 1 1 auto; }
  .test-clock-meter .meter-label, .clock { text-align: left; }
  .site-nav { gap: 0; }
  .site-nav a { padding: 0.4rem 0.55rem; }
  .answer-form { flex-wrap: wrap; }
  #answer-input { flex: 1 1 100%; font-size: 1.25rem; }
  .answer-form .btn { flex: 1; }
}

@media (max-width: 480px) {
  .field { min-width: 100%; }
  .test-foot { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
}

/* Very narrow phones (<= 359px): the header row cannot fit on one line */
@media (max-width: 359px) {
  .header-row { flex-wrap: wrap; row-gap: 0.25rem; padding-block: 0.3rem; }
  .site-nav { margin-left: auto; }
  .theme-toggle { min-width: 2.75rem; }
}

/* 14. Reduced motion & forced colors ------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .btn { border: 1px solid ButtonText; }
  .meter { border: 1px solid ButtonText; }
  .tile { border: 1px solid ButtonText; }
}
