/* Speed Maths Lab: shared tokens, notebook layout, ruled prose, bench components.
   Layout: 1032px content (43 x 24px), 24px gutters, a 120px left rail; spacing in multiples of 24px. */
:root {
  --paper: #f6f8fb; --sheet: #ffffff; --ink: #0f172a; --ink-soft: #475569; --rule: #e2e8f0; --ruled: rgba(37, 99, 235, 0.16);
  --blue: #2563eb; --blue-ink: #ffffff; --exam-bg: #f5f8fc;
  /* physics palette (the lab text names these hues: keep them) */
  --pos: #dc2626; --neg: #2563eb; --efield: #0f766e; --bfield: #2557c9; --current: #b45309; --force: #6d28d9;
  --vel: #b45309; --acc: #dc2626; --body: #2563eb; --heat: #0b7d62; --maths: #6d28d9; --probe: #7c3aed;
  --field: var(--bfield); /* alias used by the ported legend swatches */
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --text: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b1017; --sheet: #111824; --ink: #e8eef6; --ink-soft: #94a3b8; --rule: #1f2a3a; --ruled: rgba(96, 165, 250, 0.14);
    --blue: #60a5fa; --blue-ink: #0b1017; --exam-bg: #0f1621;
    --pos: #f87171; --neg: #60a5fa; --efield: #2dd4bf; --bfield: #7ea4ff; --current: #fbbf24; --force: #b79bff;
    --vel: #fbbf24; --acc: #f87171; --body: #7ea4ff; --heat: #3fd1a6; --maths: #b79bff; --probe: #c4b5fd;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--text); font-size: 17px; line-height: 1.6; }
a { color: var(--blue); }
.wrap { max-width: 1032px; margin: 0 auto; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); }
h1, h2, h3 { font-family: var(--display); font-weight: 400; letter-spacing: -0.015em; text-wrap: balance; margin: 0; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ruled prose: a rule under every line, sized by the line height so it scales with the text */
@supports (height: 1lh) {
  main :is(h1, h2, .lede, p.prose, .entry h3, .entry .clicked) {
    background-image: linear-gradient(transparent calc(1lh - 1px), var(--ruled) calc(1lh - 1px));
    background-size: 100% 1lh;
  }
}

/* top bar */
.top { border-bottom: 1px solid var(--rule); background: var(--sheet); background: color-mix(in srgb, var(--sheet) 90%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5; }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; min-height: 48px; flex-wrap: wrap; }
.mark { display: flex; align-items: baseline; gap: 8px; font-weight: 600; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.mark .badge { font-family: var(--mono); font-size: 12px; font-weight: 600; background: var(--blue); color: var(--blue-ink); padding: 2px 7px; border-radius: 4px; letter-spacing: 0.04em; }
.top nav { display: flex; gap: 18px; flex-wrap: wrap; font-size: 15px; }
.top nav a { color: var(--ink-soft); text-decoration: none; }
.top nav a:hover { color: var(--ink); }
.top nav svg.ext { vertical-align: 0.05em; margin-left: 2px; }

/* notebook rows: rail + content */
.row { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 24px; padding-block: 48px; border-top: 1px solid var(--rule); }
.row:first-child { border-top: 0; }
.rail { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em; text-transform: uppercase; padding-top: 10px; border-top: 2px solid var(--ink); align-self: start; line-height: 1.7; }
.kicker { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em; text-transform: uppercase; }

/* KaTeX display maths: left-aligned inside the equation box, scrolls if wide */
.eq .katex-display { margin: 0; text-align: left; }
.eq .katex-display > .katex { text-align: left; }
.eq .katex { font-size: 1.08em; }

/* legend, parts, trainer */
.key { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; font-size: 14px; color: var(--ink-soft); }
.key span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.row.part { padding-block: 32px 0; border-top: 0; }
.row.part h2 { font-size: 22px; color: var(--ink-soft); }
.answers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.answers .btn { width: 100%; }
.feedback { min-height: 3em; }
em.f { font-style: normal; color: var(--bfield); font-weight: 600; }
em.c { font-style: normal; color: var(--current); font-weight: 600; }
em.m { font-style: normal; color: var(--force); font-weight: 600; }

/* 'Would this score?' trainer */
.traps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 14px; }
.trap-item q { font-style: italic; }
.trap-item .vote { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.trap-fb { margin-top: 6px; font-size: 15px; }
.trap-fb .src { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); display: block; margin-top: 2px; }

/* hub */
.hero { padding-block: 72px 48px; }
.hero h1 { font-size: clamp(36px, 6.4vw, 64px); line-height: 1.04; max-width: 15ch; }
.lede { color: var(--ink-soft); max-width: 58ch; margin: 18px 0 0; font-size: 18px; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 20px; font-family: var(--mono); font-size: 13px; color: var(--ink-soft); }
.meta b { color: var(--ink); font-weight: 600; }
.entries { display: flex; flex-direction: column; }
.entry { display: grid; grid-template-columns: 144px minmax(0, 1fr) auto; gap: 24px; align-items: center; padding: 24px 0; border-bottom: 1px solid var(--rule); text-decoration: none; color: inherit; }
.entry:first-child { padding-top: 0; }
.entry canvas { width: 144px; height: 96px; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); display: block; }
.entry .id { font-family: var(--mono); font-size: 12px; color: var(--blue); letter-spacing: 0.06em; }
.entry h3 { font-size: 26px; margin: 2px 0 4px; line-height: 1.2; }
.entry .clicked { margin: 0; color: var(--ink-soft); font-size: 15px; padding: 0; border: 0; }
.entry .clicked em { font-style: normal; color: var(--ink); }
.entry .side { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); text-align: right; line-height: 1.7; white-space: nowrap; }
.entry:hover h3 { color: var(--blue); }

/* experiment page */
.exp-head { padding-block: 64px 32px; }
.exp-head h1 { font-size: clamp(34px, 5.6vw, 56px); line-height: 1.06; }
.clicked { border-left: 3px solid var(--blue); padding: 6px 0 6px 14px; margin-top: 20px; max-width: 62ch; }
.clicked .kicker { color: var(--blue); }
.clicked p { margin: 2px 0 0; }
.bench .card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.bench h2 { font-size: clamp(24px, 3.4vw, 32px); line-height: 1.15; }
.bench p, .bench-intro { margin: 0; max-width: 66ch; }
.bench ul { margin: 0; }
.fig { position: relative; width: 100%; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--paper); min-width: 0; }
.fig.drag { touch-action: none; } /* only figures you drag on block page scrolling */
.fig canvas { display: block; width: 100%; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.ctl { display: flex; flex-direction: column; gap: 2px; min-width: 150px; flex: 1 1 150px; }
.ctl label { font-size: 13px; color: var(--ink-soft); display: flex; justify-content: space-between; gap: 8px; }
.ctl output, .readout { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.ctl output { color: var(--ink); }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button, .btn { font: inherit; font-size: 14px; background: var(--sheet); color: var(--ink); border: 0; padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--blue); color: var(--blue-ink); }
.btn { border: 1px solid var(--rule); border-radius: 6px; }
.btn:hover, .seg button:hover { filter: brightness(0.97); }
.btn.right { background: var(--blue); color: var(--blue-ink); border-color: var(--blue); }
.btn.wrong { border-color: var(--pos); color: var(--pos); }
.readout { font-size: 13px; color: var(--ink-soft); border-left: 3px solid var(--rule); padding: 6px 0 6px 12px; overflow-x: auto; }
.exam { border-left: 3px solid var(--blue); background: var(--exam-bg); border-radius: 0 8px 8px 0; padding: 12px 16px; }
.exam ul { padding-left: 20px; }
.exam li { margin: 3px 0; }
details.maths { border: 1px solid var(--rule); border-left: 3px solid var(--maths); border-radius: 0 8px 8px 0; padding: 12px 16px; background: color-mix(in srgb, var(--maths) 5%, var(--sheet)); }
details.maths summary { cursor: pointer; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--maths); }
details.maths[open] summary { margin-bottom: 8px; }
details.maths p + p { margin-top: 8px; }
.eq { font-size: 16px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 12px; margin: 8px 0; overflow-x: auto; white-space: nowrap; }
table.steps { border-collapse: collapse; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
table.steps td, table.steps th { padding: 4px 12px; border-bottom: 1px solid var(--rule); text-align: right; }
table.steps th { color: var(--ink-soft); font-weight: 400; }
.scroll { overflow-x: auto; }
.prevnext { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-block: 32px 8px; font-family: var(--mono); font-size: 14px; }
.prevnext a { text-decoration: none; }

footer { border-top: 1px solid var(--rule); padding-block: 28px 48px; color: var(--ink-soft); font-size: 14px; margin-top: 24px; }
footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }

@media (max-width: 720px) {
  .row { grid-template-columns: minmax(0, 1fr); gap: 12px; padding-block: 32px; }
  .entry { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .entry canvas { width: 100%; height: 120px; }
  .entry .side { text-align: left; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .bench .card { padding: 16px; }
  body { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
