/* ============================================================================
   Cursivia base styles — reset, typography, shell (nav / wrap / footer).
   Depends on tokens.css. Version-string when it changes (base.css?v=N).
   ========================================================================== */

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

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---- Typography ------------------------------------------------------------ */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  margin: 0;
  text-wrap: balance;
}

p { margin: 0 0 var(--sp-4); }

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

small { font-size: var(--text-sm); }

::selection { background: var(--accent-soft-border); }

/* ---- Focus visibility (keyboard) -------------------------------------------- */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

/* Skip link for keyboard/screen-reader users */
.skip-link {
  position: absolute;
  left: -9999px;
  top: var(--sp-2);
  z-index: 100;
  background: var(--surface);
  color: var(--accent);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}
.skip-link:focus { left: var(--sp-2); }

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

/* ---- Layout: page wrap -------------------------------------------------------- */
.wrap {
  max-width: var(--wrap);
  margin: var(--sp-8) auto var(--sp-16);
  padding: 0 var(--sp-6);
}
.wrap-narrow { max-width: var(--wrap-narrow); }
.wrap-wide   { max-width: var(--wrap-wide); }

/* ---- Shell: top navigation band ----------------------------------------------------
   The nav is a centred container, but the band behind it runs edge to edge. The
   band is painted by a spread box-shadow clipped to the element's own height: no
   wrapper element, so every template that overrides {% block nav %} (nine of them,
   plus the Compass and Clinic pages) gets the band for free. A spread shadow never
   adds scrollable overflow, which a 100vw pseudo-element would on Windows. */
.site-nav {
  position: relative;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: 60px;
  background: var(--nav-bg);
  color: var(--nav-fg);
  box-shadow: 0 0 0 100vmax var(--nav-bg);
  clip-path: inset(0 -100vmax);
}
.site-nav.site-nav-wide { max-width: var(--wrap-wide); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  font-size: 1.25rem;
  letter-spacing: var(--tracking-tight);
  color: var(--nav-fg);
  text-decoration: none;
  white-space: nowrap;
}
.brand::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18);
  flex: none;
}
.brand:hover { color: var(--nav-fg); }
.brand .brand-suffix { color: var(--nav-faint); font-weight: var(--weight-medium); font-family: var(--font-sans); font-size: var(--text-md); letter-spacing: 0; }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px var(--sp-3);
  border-radius: var(--r-md);
  color: var(--nav-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  background: none;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-link:hover { color: var(--nav-fg); background: var(--nav-hover); }
.nav-link[aria-current="page"] { color: var(--nav-fg); background: rgba(255, 255, 255, 0.14); }
.nav-link:focus-visible { box-shadow: 0 0 0 3px rgba(91, 134, 255, 0.6); }

/* Small screens: tighten the shell so brand + 4 links hold one row at ~360px
   (no hamburger — intentional; wrap is the graceful fallback below that). */
@media (max-width: 480px) {
  .site-nav { padding: var(--sp-2) var(--sp-4); gap: var(--sp-2); }
  .brand { font-size: var(--text-lg); }
  .brand::before { width: 18px; height: 18px; border-radius: 5px; }
  .nav-links { gap: 0; }
  .nav-link { font-size: var(--text-xs); padding: 6px var(--sp-2); }
}
/* The signed-in nav carries the brand plus five links; below ~420px the mark gives way so
   they keep one row instead of dropping "Log out" onto a second one. */
@media (max-width: 420px) {
  .brand::before { display: none; }
  .nav-link { padding: 6px 6px; }
}

/* Focused-flow nav (Compass session, diagnostic): quiet meta text on the right.
   It also carries the way out (Exit, Log out), so it wraps rather than overflow on a phone. */
.nav-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--sp-3);
  color: var(--nav-muted);
  font-size: var(--text-sm);
}
.nav-meta .counter { font-variant-numeric: tabular-nums; color: var(--nav-fg); font-weight: var(--weight-semibold); }
/* The per-question clock and its toggle are the player's, but they sit on the band,
   so their colours are set here where the band's palette is known. */
.site-nav .timer { color: var(--nav-muted); }
.site-nav .q-timer {
  color: var(--nav-fg);
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  font-size: var(--text-md);
  background: rgba(36, 86, 228, 0.35);
  border: 1px solid rgba(91, 134, 255, 0.8);
  border-radius: var(--r-sm);
  padding: 2px 10px;
}
.site-nav .q-timer.warn { color: var(--nav-warn); border-color: var(--nav-warn); background: rgba(251, 191, 36, 0.14); }
.site-nav .q-timer.over { color: var(--nav-err); border-color: var(--nav-err); background: rgba(248, 113, 113, 0.14); }
.site-nav .timer-toggle { color: var(--nav-faint); }
.site-nav .timer-toggle:hover { color: var(--nav-fg); }
/* Question dots in the check-up, calibration and taster navs. */
.site-nav .dot { background: rgba(255, 255, 255, 0.22); }
.site-nav .dot.done, .site-nav .dot.now { background: var(--nav-accent); }

/* ---- Shell: session progress (Compass) ---------------------------------------------
   A thin track directly under the band, painted on the band's own colour so the two
   read as one piece of chrome. Same spread-shadow trick as the nav. */
.session-progress {
  position: relative;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 var(--sp-6);
  background: var(--nav-bg);
  box-shadow: 0 0 0 100vmax var(--nav-bg);
  clip-path: inset(0 -100vmax);
}
.session-progress .progress-track { background: var(--nav-line); border-radius: 0; height: 4px; }
.session-progress .progress-fill { background: var(--nav-accent); border-radius: 0; }

/* ---- Shell: footer ------------------------------------------------------------------ */
.site-footer {
  max-width: var(--wrap);
  margin: var(--sp-16) auto var(--sp-8);
  padding: var(--sp-6);
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: var(--text-xs);
  text-align: center;
}
.site-footer.site-footer-wide { max-width: var(--wrap-wide); }
.site-footer a { color: var(--faint); }
/* The EPSO disclaimer belongs where a visitor decides to sign up, so it lives in the
   landing footer rather than only inside /terms. */
.site-footer .seller-line { margin: var(--sp-2) 0 0; font-size: var(--text-sm); color: var(--faint); }
.site-footer .footer-note { margin: var(--sp-2) 0 0; font-size: var(--text-sm); color: var(--faint); }

/* Legal pages: long-form prose, so they get reading measure and breathing room rather than
   the app's dense card layout. */
.signup-legal { font-size: var(--text-sm); color: var(--muted); margin: var(--sp-2) 0 var(--sp-3); }

.legal { max-width: 44rem; line-height: 1.65; }
.legal h1 { margin-bottom: var(--sp-2); }
.legal h2 { margin-top: var(--sp-6); font-size: var(--text-xl); }
.legal h3 { margin-top: var(--sp-4); font-size: var(--text-lg); }
.legal ul, .legal ol { padding-left: 1.25rem; }
.legal li { margin-bottom: var(--sp-2); }
.legal code { font-size: 0.9em; }
.legal-table { border-collapse: collapse; width: 100%; margin: var(--sp-3) 0; font-size: var(--text-sm); }
.legal-table th, .legal-table td { text-align: left; padding: var(--sp-2); border-bottom: 1px solid var(--line); vertical-align: top; }

/* ---- Page header ----------------------------------------------------------------------- */
.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--weight-black);
  margin: 0 0 var(--sp-2);
}
.lede {
  color: var(--muted);
  margin: 0 0 var(--sp-6);
  max-width: 60ch;
  font-size: var(--text-lg);
}
/* Inside a card the lede is a section intro, not a page intro. */
.card .lede { font-size: var(--text-md); }

/* ---- Numerals: the one place the display face carries data --------------------------- */
.num-display {
  font-family: var(--font-display);
  font-weight: var(--weight-black);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}

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