/* Tokens. The tape (array cells + sliding pointers) is the one loud element; everything else stays quiet. */
:root {
  --paper: #f5f6f8; --surface: #ffffff; --ink: #1b2333; --muted: #5b6577; --line: #d5dae3;
  --pointer: #2747d4; --pointer-soft: #e3e8fb; --found: #b97a00; --found-soft: #fbefcf;
  --good: #1f7a45; --bad: #b8332b; --code-bg: #eef1f5;
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121826; --surface: #1a2233; --ink: #e6eaf2; --muted: #9aa5b8; --line: #2e3950;
    --pointer: #8ea4ff; --pointer-soft: #232f55; --found: #f2c14e; --found-soft: #3d3215;
    --good: #5fcf8c; --bad: #ff8a80; --code-bg: #0f1522;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* .btn sets display, which would otherwise un-hide hidden buttons */
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 1.0625rem/1.65 var(--serif); }
main { max-width: 46rem; margin: 0 auto; padding: 1.5rem 1rem 4rem; outline: none; }
h1, h2, h3 { line-height: 1.2; margin: 2.2rem 0 .6rem; font-weight: 700; }
h1 { font-size: 2.1rem; letter-spacing: -.01em; margin-top: 1rem; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.1rem; }
p, ul, ol { margin: 0 0 1rem; }
a { color: var(--pointer); }
:focus-visible { outline: 3px solid var(--pointer); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--surface); padding: .5rem; z-index: 9; }
.muted { color: var(--muted); }
.small { font: .875rem/1.5 var(--sans); }

/* Top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; align-items: center;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); font-family: var(--sans); }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; margin-right: auto; }
.top nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.top nav a { color: var(--muted); text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
.top nav a[aria-current] { color: var(--ink); border-color: var(--pointer); }
.badge { background: var(--pointer); color: var(--surface); border-radius: 999px; padding: 0 .45rem; font-size: .75rem; font-weight: 700; }
.foot { max-width: 46rem; margin: 0 auto; padding: 1rem; color: var(--muted); font: .875rem/1.5 var(--sans); border-top: 1px solid var(--line); }
button, input, textarea, select { font: inherit; color: inherit; }
.link { background: none; border: 0; padding: 0; color: var(--pointer); text-decoration: underline; cursor: pointer; }
.btn { font-family: var(--sans); font-size: .95rem; background: var(--pointer); color: var(--surface); border: 0; border-radius: 6px; padding: .5rem .9rem; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.quiet { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* Course map */
.hero p.lede { font-size: 1.2rem; max-width: 34rem; }
.week { border-top: 1px solid var(--line); padding: .9rem 0; display: grid; grid-template-columns: 4.5rem 1fr; gap: .25rem 1rem; }
.week.now { border-top: 3px solid var(--pointer); }
.week .when { font: .875rem/1.4 var(--sans); color: var(--muted); }
.week .when b { display: block; font-size: 1.05rem; color: var(--ink); }
.week ul { list-style: none; padding: 0; margin: 0; }
.week li { display: flex; gap: .5rem; align-items: baseline; padding: .15rem 0; }
.week li .track { font: .8rem var(--sans); color: var(--muted); min-width: 6.5rem; }
.tick { width: 1rem; display: inline-block; color: var(--good); font-family: var(--sans); }
details.phase { border-top: 1px solid var(--line); padding: .7rem 0; }
details.phase summary { cursor: pointer; font-weight: 700; }
details.phase table { margin-top: .6rem; }

/* Lesson */
.crumbs { font: .875rem var(--sans); color: var(--muted); }
.sections { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font: .9rem var(--sans); padding: .5rem 0; border-bottom: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font: .92rem/1.45 var(--sans); margin-bottom: 1rem; display: block; overflow-x: auto; }
th, td { text-align: left; padding: .4rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
code, pre, textarea.code { font-family: var(--mono); font-size: .875rem; }
code { background: var(--code-bg); padding: .1em .3em; border-radius: 4px; }
pre { background: var(--code-bg); padding: .8rem 1rem; border-radius: 8px; overflow-x: auto; line-height: 1.5; margin: 0 0 1rem; }
pre code { background: none; padding: 0; }
.steps { list-style: none; padding: 0; }
.steps li { display: flex; gap: .6rem; align-items: baseline; padding: .3rem 0; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font: .9rem var(--sans); margin: 0 0 .6rem; }
.flow span { border: 1.5px solid var(--line); border-radius: 6px; padding: .35rem .6rem; background: var(--surface); }
.flow i { font-style: normal; color: var(--muted); }
.flow span.key { border-color: var(--pointer); background: var(--pointer-soft); }

/* The tape */
.player { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin: 0 0 1.2rem; font-family: var(--sans); }
.tape { position: relative; display: flex; gap: 4px; padding: .25rem 0 4.4rem; overflow-x: auto; }
.cell { flex: 0 0 2.75rem; height: 2.75rem; display: grid; place-items: center; font: 600 1rem var(--mono);
  background: var(--surface); border: 1.5px solid var(--ink); border-radius: 4px; transition: background .25s, opacity .25s, border-color .25s; }
.cell.hi { background: var(--pointer-soft); border-color: var(--pointer); }
.cell.hit { background: var(--found-soft); border-color: var(--found); }
.cell.dim { opacity: .3; }
.cell small { position: absolute; }
.ptr { position: absolute; top: 3.1rem; left: 0; width: 2.75rem; text-align: center; font: 700 .8rem var(--mono); color: var(--pointer);
  transition: transform .35s cubic-bezier(.3,.7,.2,1); }
.ptr::before { content: "▲"; display: block; font-size: .7rem; line-height: 1; }
.ptr.low::before { content: ""; }
.side { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; font: .9rem var(--mono); margin: .2rem 0 .6rem; }
.side b { color: var(--muted); font-weight: 600; }
.note { min-height: 3.2em; font: 1rem/1.5 var(--serif); margin: 0 0 .6rem; }
.controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.controls input[type=text] { flex: 1 1 12rem; min-width: 0; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); font-family: var(--mono); font-size: .875rem; }
.controls .count { font-size: .85rem; color: var(--muted); min-width: 4.5rem; text-align: right; }
.err { color: var(--bad); font: .9rem var(--sans); }

/* Exercises */
.ex { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 1rem; margin: 0 0 1.2rem; }
.ex h3 { margin-top: 0; }
textarea.code { width: 100%; min-height: 11rem; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--code-bg); line-height: 1.5; tab-size: 4; resize: vertical; white-space: pre; overflow-wrap: normal; overflow-x: auto; }
.results { font: .9rem/1.5 var(--sans); margin-top: .7rem; }
.results ul { list-style: none; padding: 0; margin: 0 0 .5rem; }
.results li { padding: .15rem 0; }
.pass { color: var(--good); } .fail { color: var(--bad); }
.results pre { margin-top: .4rem; }

/* Cards */
.card { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 1.2rem; margin: 0 0 1rem; }
.card .q { font-size: 1.15rem; margin-bottom: .8rem; }
.card .a { border-top: 1px dashed var(--line); padding-top: .8rem; margin-bottom: .8rem; }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .6rem 1rem; font: .9rem var(--sans); }
.calc label { display: grid; gap: .2rem; }
.calc input { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.calc output { font: 600 1.05rem var(--mono); }

@media (max-width: 30rem) { .week { grid-template-columns: 1fr; } h1 { font-size: 1.7rem; } .cell, .ptr { flex-basis: 2.2rem; width: 2.2rem; } }
@media (prefers-reduced-motion: reduce) { .ptr, .cell { transition: none; } html { scroll-behavior: auto; } }
