/* ==========================================================================
   SPEEDLAB — base.css
   Design tokens, self-hosted fonts, reset, typography, layout, content
   components, ad slots. Arcade-specific components live in arcade.css.
   ========================================================================== */

/* ---- Self-hosted fonts (no external requests) --------------------------- */
@font-face {
  font-family: "Archivo";
  src: url("/assets/fonts/archivo-var.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 100%;
  font-display: swap;
  font-style: normal;
}
@font-face {
  /* Seven-segment display face — used ONLY for live numeric readouts. */
  font-family: "DSEG7";
  src: url("/assets/fonts/dseg7-bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
  font-style: normal;
}

/* ---- Design tokens ------------------------------------------------------ */
:root {
  /* Palette — each colour has one job (see design plan) */
  --c-bg:        #1A1030; /* Cabinet Aubergine — backdrop / bezel        */
  --c-panel:     #241640; /* raised cabinet panel                         */
  --c-panel-2:   #150C28; /* recessed cabinet panel                       */
  --c-screen:    #0B0716; /* CRT screen interior                          */
  --c-ink:       #F6F1FF; /* Marquee White — primary text                 */
  --c-ink-dim:   #A99FC7; /* secondary text                               */
  --c-p1:        #FF3D7F; /* Player-1 Pink — act / primary buttons        */
  --c-p2:        #00C2FF; /* Player-2 Blue — navigate / focus             */
  --c-amber:     #FFC531; /* Scoreboard Amber — live readout ONLY         */
  --c-go:        #2BE86B; /* Go Green — success / new best ONLY           */
  --c-line:      #000000; /* hard keyline on everything                   */

  /* Hard-edged shadows (no blur, ever) */
  --shadow-hard:   4px 4px 0 var(--c-line);
  --shadow-hard-lg: 6px 6px 0 var(--c-line);

  /* Border weights — chunky */
  --bd:   3px;
  --bd-2: 5px;

  /* Spacing scale */
  --sp-1: 0.5rem;
  --sp-2: 0.75rem;
  --sp-3: 1rem;
  --sp-4: 1.5rem;
  --sp-5: 2rem;
  --sp-6: 3rem;

  --radius: 6px; /* small only — chunky, not soft */
  --wrap: 960px;

  --font-ui: "Archivo", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-seg: "DSEG7", "Archivo", monospace;
}

/* ---- Reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
/* The [hidden] attribute must win over component display rules (flex/grid),
   otherwise toggling .hidden on a flex element does nothing. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.6;
  /* subtle cabinet texture: two hard dot rows, not a gradient wash */
  background-image:
    radial-gradient(var(--c-panel) 1.5px, transparent 1.5px);
  background-size: 22px 22px;
  background-position: 0 0;
}
img, svg, canvas { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }
a { color: var(--c-p2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.05; margin: 0 0 var(--sp-3); }
p { margin: 0 0 var(--sp-3); }
ul { margin: 0 0 var(--sp-3); padding-left: 1.25rem; }
:target { scroll-margin-top: 90px; }

/* ---- Typography --------------------------------------------------------- */
h1 {
  font-weight: 900;
  font-size: clamp(1.9rem, 6vw, 3rem);
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
h2 {
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  letter-spacing: -0.01em;
}
h3 { font-weight: 800; font-size: 1.15rem; }
.lead { color: var(--c-ink-dim); font-size: 1.05rem; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- Accessibility ------------------------------------------------------ */
:focus-visible {
  outline: var(--bd) solid var(--c-p2);
  outline-offset: 2px;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--c-amber); color: var(--c-line);
  padding: var(--sp-2) var(--sp-3); font-weight: 800;
  border: var(--bd) solid var(--c-line);
}
.skip-link:focus { left: var(--sp-2); top: var(--sp-2); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---- Layout ------------------------------------------------------------- */
.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--sp-3); }

/* Desktop sidebar layout: content column + sticky right rail */
.layout { display: block; }
@media (min-width: 1024px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--sp-5);
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 var(--sp-3);
  }
  .wrap.layout { padding: 0 var(--sp-3); }
}

/* ---- Site header -------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--c-panel);
  border-bottom: var(--bd-2) solid var(--c-line);
}
.site-header .bar {
  display: flex; align-items: center; gap: var(--sp-3);
  max-width: 1300px; margin: 0 auto; padding: var(--sp-2) var(--sp-3);
}
.brand {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-weight: 900; font-size: 1.35rem; letter-spacing: -0.03em;
  text-transform: uppercase; color: var(--c-ink);
}
.brand:hover { text-decoration: none; }
.brand .lab {
  color: var(--c-line); background: var(--c-amber);
  padding: 0 0.35rem; border: var(--bd) solid var(--c-line);
  box-shadow: 3px 3px 0 var(--c-line);
}
.site-header nav { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.site-header nav a { color: var(--c-ink); font-weight: 700; padding: 0.35rem 0.5rem; }
/* keep the header inside narrow phones (was overflowing ~8px) */
@media (max-width: 430px) {
  .brand { font-size: 1.15rem; }
  .site-header .bar { gap: var(--sp-2); padding: var(--sp-2); }
  .site-header nav { gap: 0.3rem; }
  .site-header nav a { padding: 0.35rem 0.4rem; }
  .sound-toggle { padding: 0.35rem 0.5rem; }
}

/* ---- Buttons (generic) -------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; cursor: pointer;
  font-weight: 800; font-size: 1rem;
  color: var(--c-line); background: var(--c-ink);
  border: var(--bd) solid var(--c-line);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  box-shadow: var(--shadow-hard);
  transition: transform .06s steps(2), box-shadow .06s steps(2);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--c-line); }
.btn-p1 { background: var(--c-p1); }
.btn-p2 { background: var(--c-p2); }
.btn-ghost {
  background: transparent; color: var(--c-ink);
  border-color: var(--c-ink); box-shadow: none;
}
.btn-ghost:active { transform: none; }
.btn-sm { font-size: 0.85rem; padding: 0.4rem 0.7rem; box-shadow: 3px 3px 0 var(--c-line); }

/* Sound toggle */
.sound-toggle {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--c-panel-2); color: var(--c-ink);
  border: var(--bd) solid var(--c-line); border-radius: var(--radius);
  padding: 0.35rem 0.6rem; font-weight: 800; cursor: pointer; font-size: 0.85rem;
}
.sound-toggle[aria-pressed="true"] { background: var(--c-go); color: var(--c-line); }

/* ---- Breadcrumbs -------------------------------------------------------- */
.crumbs { font-size: 0.85rem; color: var(--c-ink-dim); margin: var(--sp-4) 0 var(--sp-2); }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0; padding: 0; }
.crumbs li::after { content: "›"; margin-left: 0.35rem; color: var(--c-ink-dim); }
.crumbs li:last-child::after { content: ""; }
.crumbs a { color: var(--c-ink-dim); font-weight: 700; }

/* ---- Written content ---------------------------------------------------- */
.content { margin: var(--sp-5) 0; }
.content h2 { margin-top: var(--sp-5); }
.content h2:first-child { margin-top: 0; }

/* FAQ */
.faq details {
  border: var(--bd) solid var(--c-line);
  border-radius: var(--radius);
  background: var(--c-panel);
  box-shadow: var(--shadow-hard);
  margin-bottom: var(--sp-2);
}
.faq summary {
  cursor: pointer; font-weight: 800; padding: var(--sp-3);
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 1.4rem; line-height: 1; color: var(--c-amber); }
.faq details[open] summary::after { content: "\2013"; }
.faq details > p { padding: 0 var(--sp-3) var(--sp-3); margin: 0; color: var(--c-ink-dim); }

/* ---- Related tests grid (chunky tiles, hard shadows — not soft cards) --- */
.related { margin: var(--sp-5) 0; }
.tile-grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px) { .tile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile {
  display: block; background: var(--c-panel);
  border: var(--bd) solid var(--c-line); border-radius: var(--radius);
  box-shadow: var(--shadow-hard); padding: var(--sp-3);
  color: var(--c-ink); transition: transform .06s steps(2), box-shadow .06s steps(2);
}
.tile:hover { text-decoration: none; transform: translate(-2px, -2px); box-shadow: var(--shadow-hard-lg); }
.tile:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--c-line); }
.tile .t-name { font-weight: 800; display: block; }
.tile .t-desc { font-size: 0.85rem; color: var(--c-ink-dim); }
.tile .t-kbd {
  display: inline-block; font-size: 0.7rem; font-weight: 800; text-transform: uppercase;
  background: var(--c-panel-2); border: 2px solid var(--c-line); padding: 0 0.3rem;
  border-radius: 3px; margin-bottom: 0.35rem;
}

/* ---- Ad slots (reserved now, filled later) ------------------------------
   Fixed height reserved in CSS so turning ads on causes zero layout shift.
   Dashed dev outline + label; delete the outline styles when ads go live.  */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  margin: var(--sp-5) auto;
  color: var(--c-ink-dim); font-weight: 800; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  border: 2px dashed rgba(169,159,199,0.4); border-radius: var(--radius);
  overflow: hidden;
}
.ad-slot::before { content: "Ad slot \00B7 " attr(data-slot); }
.ad-slot[data-slot="content-top"],
.ad-slot[data-slot="content-bottom"] { width: 336px; max-width: 100%; height: 250px; }
.ad-slot[data-slot="sidebar"] { width: 300px; height: 600px; position: sticky; top: 90px; }
.ad-slot[data-slot="footer"] { width: 100%; height: 100px; }
@media (min-width: 728px) {
  .ad-slot[data-slot="content-top"],
  .ad-slot[data-slot="content-bottom"] { height: 280px; }
  .ad-slot[data-slot="footer"] { height: 90px; }
}
.sidebar-rail { display: none; }
@media (min-width: 1024px) { .sidebar-rail { display: block; } }

/* ---- Footer ------------------------------------------------------------- */
.site-footer {
  border-top: var(--bd-2) solid var(--c-line);
  background: var(--c-panel-2);
  margin-top: var(--sp-6);
  padding: var(--sp-5) 0;
  font-size: 0.9rem;
}
.site-footer .cols { display: flex; flex-wrap: wrap; gap: var(--sp-4) var(--sp-5); }
.site-footer a { color: var(--c-ink-dim); }
.site-footer h3 { color: var(--c-ink); font-size: 0.9rem; text-transform: uppercase; }
.site-footer nav { display: flex; flex-direction: column; gap: 0.25rem; }
.site-footer .fine { color: var(--c-ink-dim); margin-top: var(--sp-4); }

/* ---- Page entrance (smooth load, not pop-in) ---------------------------
   Only under no-preference, so reduced-motion users and any environment
   without CSS animation see content fully visible right away. Uses only
   opacity/transform, so there is zero layout shift and the test stays
   clickable while it fades in. */
@media (prefers-reduced-motion: no-preference) {
  @keyframes sl-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
  @keyframes sl-drop { from { opacity: 0; transform: translateY(-100%); } to { opacity: 1; transform: none; } }

  .site-header { animation: sl-drop .4s ease-out both; }

  main.wrap:not(.layout) > *,
  main.layout > div > * { animation: sl-rise .5s ease-out both; }

  main.wrap:not(.layout) > *:nth-child(1), main.layout > div > *:nth-child(1) { animation-delay: .03s; }
  main.wrap:not(.layout) > *:nth-child(2), main.layout > div > *:nth-child(2) { animation-delay: .09s; }
  main.wrap:not(.layout) > *:nth-child(3), main.layout > div > *:nth-child(3) { animation-delay: .15s; }
  main.wrap:not(.layout) > *:nth-child(4), main.layout > div > *:nth-child(4) { animation-delay: .21s; }
  main.wrap:not(.layout) > *:nth-child(5), main.layout > div > *:nth-child(5) { animation-delay: .27s; }
  main.wrap:not(.layout) > *:nth-child(n+6), main.layout > div > *:nth-child(n+6) { animation-delay: .32s; }
}

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