/* Python Pathway - Clyst Vale Community College
   Layout: a Clyst Vale blue banner, then one column of content (max 1180px). Task pages put
   the editor full width with console + checks side by side underneath.
   Palette: the v6 tools' Clyst Vale blue for the banner and actions, house colours
   (Danes green, Clyst Vale blue, Hembury gold, Ashclyst red) for the four stages,
   Hembury yellow for XP. */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #e8edf5;
  --ink: #1d2433;
  --muted: #535d70;
  --line: #d3dae6;
  --band: #003b8e;
  --band-edge: #00255b;
  --band-ink: #ffffff;
  --accent: #003b8e;
  --accent-ink: #ffffff;
  --accent-soft: #dce7f8;
  --gold: #e6c800;
  --gold-ink: #2e2700;
  --ok: #1a7f37;
  --ok-soft: #e0f3e5;
  --bad: #c4161c;
  --bad-soft: #fbe5e5;
  --warn: #8f5c00;
  --warn-soft: #fdf0d6;
  --s1: #1f8a33; --s2: #003b8e; --s3: #8a7200; --s4: #c40d1b; --s5: #26255d;
  --code-bg: #f7f9fc;
  --code-ink: #1d2a3d;
  --tok-kw: #a3248f; --tok-str: #1a7f37; --tok-num: #b0520b; --tok-com: #6f7a8c;
  --tok-def: #003b8e; --tok-builtin: #0f7489; --tok-op: #44546a;
  --font-display: "Bricolage Grotesque", Arial, Helvetica, sans-serif;
  --font-body: "Atkinson Hyperlegible", Arial, Helvetica, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 20, 60, .06), 0 4px 14px rgba(0, 20, 60, .07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c121c; --surface: #151d2a; --surface-2: #1c2636; --ink: #e6ebf3; --muted: #9ba8ba;
    --line: #2a3648; --band: #0a2350; --band-edge: #13336d; --band-ink: #ffffff;
    --accent: #8db4f0; --accent-ink: #08142a; --accent-soft: #19304f;
    --gold: #e6c800; --gold-ink: #2e2700;
    --ok: #4fc46d; --ok-soft: #10301b; --bad: #ff7b7b; --bad-soft: #3b1618; --warn: #f0b04c; --warn-soft: #33260f;
    --s1: #4cc35e; --s2: #8db4f0; --s3: #e6c800; --s4: #ff6670; --s5: #b7b4ff; --s5: #b7b4ff;
    --code-bg: #101824; --code-ink: #dce4ee;
    --tok-kw: #e48fd6; --tok-str: #8fd6a4; --tok-num: #f5b06a; --tok-com: #7d8a9c;
    --tok-def: #9cc2ff; --tok-builtin: #6fd3e4; --tok-op: #b5c1d1;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c121c; --surface: #151d2a; --surface-2: #1c2636; --ink: #e6ebf3; --muted: #9ba8ba;
  --line: #2a3648; --band: #0a2350; --band-edge: #13336d; --band-ink: #ffffff;
  --accent: #8db4f0; --accent-ink: #08142a; --accent-soft: #19304f;
  --gold: #e6c800; --gold-ink: #2e2700;
  --ok: #4fc46d; --ok-soft: #10301b; --bad: #ff7b7b; --bad-soft: #3b1618; --warn: #f0b04c; --warn-soft: #33260f;
  --s1: #4cc35e; --s2: #8db4f0; --s3: #e6c800; --s4: #ff6670; --s5: #b7b4ff;
  --code-bg: #101824; --code-ink: #dce4ee;
  --tok-kw: #e48fd6; --tok-str: #8fd6a4; --tok-num: #f5b06a; --tok-com: #7d8a9c;
  --tok-def: #9cc2ff; --tok-builtin: #6fd3e4; --tok-op: #b5c1d1;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.55;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--surface);
}
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; margin: 0; }
code, pre, .cm { font-family: var(--font-mono); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar: the Clyst Vale banner */
body::before { background: var(--band); }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--band); color: var(--band-ink); border-bottom: 3px solid var(--band-edge);
}
.topbar-inner {
  max-width: 1680px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--band-ink); }
.school-logo { height: 42px; width: auto; display: block; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
.brand-text { display: grid; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 19px; }
.brand-sub { font-size: 12px; opacity: .85; letter-spacing: .04em; }
.topnav { display: flex; gap: 2px; flex-wrap: wrap; }
.topnav a {
  text-decoration: none; color: var(--band-ink); opacity: .85; padding: 6px 10px; border-radius: 6px; font-size: 15px;
}
.topnav a:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.topnav a.on { opacity: 1; background: rgba(255, 255, 255, .18); box-shadow: inset 0 -2px 0 var(--gold); }
.topnav a.ess-link { opacity: 1; font-weight: 700; border: 1.5px solid rgba(255, 255, 255, .6); }
.topnav a.ess-link.on { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); box-shadow: none; }
.top-status { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar .btn { background: transparent; color: var(--band-ink); border-color: rgba(255, 255, 255, .55); }
.topbar .btn:hover { background: rgba(255, 255, 255, .14); border-color: #fff; }
.topbar .file-status { color: rgba(255, 255, 255, .85); }
.topbar .file-status.warn { color: #ffd966; }
.topbar .file-status.warn::before { background: #ffd966; }
.topbar .file-status.ok::before { background: #6be38a; }
.py-status { font-size: 13px; color: rgba(255, 255, 255, .85); display: inline-flex; align-items: center; gap: 6px; }
.py-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #ffd966; }
.py-status.ready::before { background: #6be38a; }
.py-status.failed::before { background: #ff8a8a; }
.xp-chip {
  background: var(--gold); color: var(--gold-ink); border-radius: 999px; padding: 3px 11px;
  font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.xp-chip.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }
.theme-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px;
  background: rgba(255, 255, 255, .12); color: var(--band-ink); border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 999px; padding: 4px 11px; min-height: 30px;
}
.theme-btn:hover { background: rgba(255, 255, 255, .22); }
.topbar :focus-visible { outline-color: var(--gold); }
@media (max-width: 1100px) { .py-status { display: none; } }
@media (max-width: 640px) {
  .topnav { order: 3; width: 100%; }
  .brand-sub { display: none; }
  .school-logo { height: 34px; }
  .theme-btn #theme-label { display: none; }
}

/* ---------- footer */
.site-footer { border-top: 3px solid var(--band-edge); background: var(--band); color: var(--band-ink); }
.footer-inner {
  max-width: 1680px; margin: 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding-block: 14px calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  font-size: 14px;
}
.footer-inner img { height: 32px; width: auto; border-radius: 2px; }
.footer-values { margin-left: auto; font-weight: 700; letter-spacing: .12em; font-size: 13px; }
.footer-values i { font-style: normal; opacity: .55; margin: 0 4px; }

/* ---------- page */
.app {
  max-width: 1680px; margin: 0 auto; padding-block: 24px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  outline: none;
}
.boot { color: var(--muted); }
.eyebrow {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700;
}

/* ---------- home */
.hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; align-items: end; margin-bottom: 36px; }
.hero h1 { font-size: clamp(34px, 5.4vw, 58px); font-weight: 800; letter-spacing: -.02em; }
.hero h1 .prompt { font-family: var(--font-mono); color: var(--accent); font-weight: 600; font-size: .62em; vertical-align: .18em; margin-right: .2em; }
.hero p.lede { font-size: 18px; color: var(--muted); max-width: 58ch; margin: 14px 0 0; }
.hero-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); display: grid; gap: 12px;
}
.hero-card .big { font-family: var(--font-display); font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
  padding: 8px 14px; border-radius: 8px; font-size: 15px; line-height: 1.2; min-height: 38px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.go { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 700; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.stage { margin-top: 34px; }
.stage-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; border-bottom: 2px solid var(--stage-c, var(--line)); padding-bottom: 8px; margin-bottom: 14px; }
.stage-num {
  font-family: var(--font-display); font-weight: 800; color: var(--stage-c); font-size: 15px;
  border: 2px solid var(--stage-c); border-radius: 999px; padding: 1px 10px;
}
.stage-head h2 { font-size: 26px; }
.stage-head .grades { color: var(--muted); font-size: 15px; }
.stage-head .grades b { color: var(--stage-c); }
.stage-blurb { margin-left: auto; color: var(--muted); font-size: 15px; }
.unit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.unit-card {
  display: grid; grid-template-rows: auto 1fr auto; gap: 8px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  transition: border-color .15s, transform .15s;
}
.unit-card:hover { border-color: var(--stage-c); transform: translateY(-1px); }
.unit-card .u-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.unit-card .u-no { font-family: var(--font-mono); font-size: 13px; color: var(--stage-c); font-weight: 600; }
.unit-card h3 { font-size: 19px; }
.unit-card p { margin: 0; font-size: 14px; color: var(--muted); }
.unit-card .u-foot { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.unit-card .bar { flex: 1; height: 6px; }
.unit-card .bar > i { background: var(--stage-c); }
.done-badge { font-size: 12px; font-weight: 700; color: var(--ok); background: var(--ok-soft); padding: 2px 8px; border-radius: 999px; }

/* ---------- unit page */
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.unit-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.unit-head h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 800; }
.unit-head .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.pill { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.stage-pill { background: transparent; border: 1.5px solid var(--stage-c); color: var(--stage-c); font-weight: 700; }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 22px; }
.step {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; font-size: 14px;
}
.step .n { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.step.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.step.done { background: var(--ok-soft); border-color: transparent; }
.step.done .n::after { content: " ✓"; color: var(--ok); font-weight: 700; }
.step .t-type { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
@media (max-width: 640px) { .step .t-title { display: none; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.learn { max-width: 820px; }
.prose { min-width: 0; }
.prose > * + * { margin-top: 12px; }
.prose h3 { font-size: 22px; margin-top: 26px; }
.prose h4 { font-size: 18px; margin-top: 18px; }
.prose p, .prose li { max-width: 70ch; }
.prose ul, .prose ol { padding-left: 22px; margin-bottom: 0; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.prose pre code { background: none; padding: 0; font-size: inherit; }
.tablewrap { overflow-x: auto; }
.prose table { border-collapse: collapse; font-size: 15px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.prose th { background: var(--surface-2); }
pre.code {
  margin: 0; background: var(--code-bg); color: var(--code-ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; font-size: 14px; line-height: 1.5; position: relative;
}
pre.code[data-label]::before {
  content: attr(data-label); display: block; font-family: var(--font-body); font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
pre.code.erl { border-left: 4px solid var(--s3); }
pre.code.output { border-style: dashed; }
.callout { border-radius: 8px; padding: 10px 14px; background: var(--accent-soft); border-left: 4px solid var(--accent); }
.callout.warn { background: var(--warn-soft); border-left-color: var(--warn); }
.callout.exam { background: var(--ok-soft); border-left-color: var(--ok); }
.callout > * + * { margin-top: 6px; }
.callout p { margin: 0; }

.videos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.video {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 14px; background: var(--surface);
}
.video:hover { border-color: var(--bad); }
.video .play {
  width: 22px; height: 16px; border-radius: 4px; background: #e02a20; position: relative; flex: none;
}
.video .play::after {
  content: ""; position: absolute; left: 8px; top: 4px; border-left: 7px solid #fff;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
}
.video .alt { font-size: 12px; color: var(--muted); }

/* runnable examples */
.example { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.example .ex-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.example .ex-bar .lbl { font-size: 12px; color: var(--muted); }
.example .console { border: 0; border-top: 1px solid var(--line); border-radius: 0; min-height: 0; }

/* ---------- task */
.task-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 10px; }
.task-head h2 { font-size: 26px; }
.task-kind { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; color: var(--accent); }
.task-xp { font-size: 13px; color: var(--gold-ink); background: var(--gold); border-radius: 999px; padding: 1px 8px; }
.task-done { font-size: 13px; color: var(--ok); font-weight: 700; }
.erl-flag { font-size: 12px; font-weight: 700; color: var(--s3); border: 1.5px solid var(--s3); border-radius: 999px; padding: 1px 8px; }
.task-body { display: grid; gap: 16px; }
.intro { max-width: 860px; }
.erl-box { display: grid; gap: 8px; }

.editor-wrap { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.editor-wrap .CodeMirror { height: auto; min-height: 180px; font-size: 15px; line-height: 1.5; }
.editor-wrap .CodeMirror-scroll { min-height: 180px; max-height: 520px; }
.example .CodeMirror { height: auto; font-size: 14.5px; }
.example .CodeMirror-scroll { max-height: 360px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .spacer { flex: 1; }

.results { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 860px) { .results { grid-template-columns: minmax(0, 1fr); } }
.box-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.console {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  font-family: var(--font-mono); font-size: 14px; white-space: pre-wrap; word-break: break-word; min-height: 120px;
  max-height: 380px; overflow: auto;
}
.console .c-out { color: var(--code-ink); }
.console .c-prompt { color: var(--accent); }
.console .c-in { color: var(--ok); font-weight: 600; }
.console .c-err { color: var(--bad); }
.console .c-note { color: var(--muted); font-style: italic; }
.console .c-empty { color: var(--muted); font-family: var(--font-body); font-size: 14px; }
.console input.c-input {
  font: inherit; color: var(--ok); font-weight: 600; background: var(--accent-soft); border: 0; border-bottom: 2px solid var(--accent);
  outline: none; min-width: 8ch; width: 50%; padding: 0 4px;
}
.files-out { margin-top: 8px; display: grid; gap: 6px; }
.files-out .fname { font-size: 13px; font-weight: 700; }
.checks { display: grid; gap: 6px; align-content: start; }
.checks .empty { color: var(--muted); font-size: 14px; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; }
.check { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; padding: 7px 10px; border-radius: 8px; font-size: 15px; }
.check .ic { font-weight: 700; text-align: center; }
.check.ok { background: var(--ok-soft); }
.check.ok .ic { color: var(--ok); }
.check.bad { background: var(--bad-soft); }
.check.bad .ic { color: var(--bad); }
.check .hint { font-size: 13px; color: var(--muted); }
.score-line { font-weight: 700; font-size: 15px; }
.err-box { background: var(--bad-soft); border-radius: 8px; padding: 10px 12px; font-family: var(--font-mono); font-size: 13.5px; white-space: pre-wrap; color: var(--ink); }
.success {
  border: 2px solid var(--ok); background: var(--ok-soft); border-radius: var(--radius); padding: 14px 16px;
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.success .big { font-family: var(--font-display); font-weight: 800; font-size: 22px; color: var(--ok); }
.success .grow { flex: 1; min-width: 200px; }
.success.pop { animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { transform: scale(.96); opacity: .4; } }
.hint-box { background: var(--warn-soft); border-radius: 8px; padding: 10px 14px; }
.hint-box .prose > * + * { margin-top: 6px; }
.model { display: grid; gap: 8px; }

/* quiz */
.q { display: grid; gap: 10px; padding: 16px 0; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; padding-top: 0; }
.q-n { font-family: var(--font-mono); color: var(--muted); font-size: 13px; }
.opts { display: grid; gap: 8px; }
.opt {
  text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 12px;
  cursor: pointer; display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; align-items: start;
}
.opt:hover { border-color: var(--accent); }
.opt .k { font-family: var(--font-mono); color: var(--muted); }
.opt.right { background: var(--ok-soft); border-color: var(--ok); }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.opt[disabled] { cursor: default; }
.explain { font-size: 15px; color: var(--muted); }

/* predict + trace + classify + truth */
textarea.answer, .sql-input {
  width: 100%; font-family: var(--font-mono); font-size: 15px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--code-bg); color: var(--code-ink); min-height: 110px; resize: vertical;
}
.grid-table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid-table th, .grid-table td { border: 1px solid var(--line); padding: 0; text-align: center; }
.grid-table th { background: var(--surface-2); padding: 6px 12px; font-family: var(--font-mono); font-size: 14px; }
.grid-table td.rowno { padding: 4px 8px; color: var(--muted); font-size: 12px; background: var(--surface-2); }
.grid-table input {
  width: 100%; min-width: 70px; border: 0; padding: 7px 8px; font-family: var(--font-mono); font-size: 14px;
  background: var(--surface); color: var(--ink); text-align: center;
}
.grid-table td.ok input, .grid-table td.ok button { background: var(--ok-soft); }
.grid-table td.bad input, .grid-table td.bad button { background: var(--bad-soft); }
.grid-table td.fixed { padding: 7px 14px; font-family: var(--font-mono); }
.grid-table button.tt {
  width: 100%; min-width: 64px; border: 0; padding: 7px 8px; font-family: var(--font-mono); font-size: 15px; font-weight: 600;
  background: var(--surface); cursor: pointer; color: var(--ink);
}
.cls-list { display: grid; gap: 8px; }
.cls-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.cls-item.ok { background: var(--ok-soft); border-color: transparent; }
.cls-item.bad { background: var(--bad-soft); border-color: transparent; }
.cls-item .why { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 4px 9px; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* parsons */
.parsons { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 760px) { .parsons { grid-template-columns: minmax(0, 1fr); } }
.p-col { background: var(--surface-2); border-radius: 8px; padding: 8px; min-height: 120px; display: grid; gap: 6px; align-content: start; }
.p-line {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px 5px 10px; cursor: grab;
  font-family: var(--font-mono); font-size: 14px; white-space: pre; overflow-x: auto; touch-action: none;
}
.p-line.dragging { opacity: .4; }
.p-line.ok { border-color: var(--ok); }
.p-line.bad { border-color: var(--bad); background: var(--bad-soft); }
.p-line .mv { display: flex; gap: 2px; }
.p-line .mv button { border: 1px solid var(--line); background: var(--surface); border-radius: 4px; width: 26px; height: 24px; cursor: pointer; font-size: 12px; line-height: 1; }
.p-col.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* sql */
.db-preview { display: grid; gap: 10px; }
.db-preview table, .sql-result table { border-collapse: collapse; font-size: 13.5px; font-family: var(--font-mono); }
.db-preview th, .db-preview td, .sql-result th, .sql-result td { border: 1px solid var(--line); padding: 3px 8px; text-align: left; white-space: nowrap; }
.db-preview th, .sql-result th { background: var(--surface-2); }
.db-preview caption { text-align: left; font-weight: 700; font-size: 14px; padding-bottom: 4px; font-family: var(--font-body); }
.sql-result { overflow-x: auto; }

/* progress + teacher pages */
.cols-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 820px) { .cols-2 { grid-template-columns: minmax(0, 1fr); } }
.prog-table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.prog-table th, .prog-table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.prog-table td.num { text-align: right; }
.code-out { width: 100%; font-family: var(--font-mono); font-size: 12px; min-height: 90px; border-radius: 8px; border: 1px solid var(--line); background: var(--code-bg); color: var(--ink); padding: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 15px; z-index: 50; box-shadow: var(--shadow);
}

/* CodeMirror colours from our tokens, so one theme works in light and dark */
.CodeMirror { background: var(--code-bg); color: var(--code-ink); font-family: var(--font-mono); }
.CodeMirror-gutters { background: var(--surface-2); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--muted); }
.CodeMirror-cursor { border-left: 2px solid var(--ink); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--accent-soft) !important; }
.CodeMirror-matchingbracket { color: var(--ok) !important; text-decoration: underline; }
.CodeMirror .err-line { background: var(--bad-soft); }
.CodeMirror .cm-keyword, pre.code .cm-keyword, .p-line .cm-keyword { color: var(--tok-kw); font-weight: 600; }
.CodeMirror .cm-string, pre.code .cm-string, .p-line .cm-string, .CodeMirror .cm-string-2, pre.code .cm-string-2, .p-line .cm-string-2 { color: var(--tok-str); }
.CodeMirror .cm-number, pre.code .cm-number, .p-line .cm-number { color: var(--tok-num); }
.CodeMirror .cm-comment, pre.code .cm-comment, .p-line .cm-comment { color: var(--tok-com); font-style: italic; }
.CodeMirror .cm-def, pre.code .cm-def, .p-line .cm-def { color: var(--tok-def); font-weight: 600; }
.CodeMirror .cm-builtin, pre.code .cm-builtin, .p-line .cm-builtin { color: var(--tok-builtin); }
.CodeMirror .cm-operator, pre.code .cm-operator, .p-line .cm-operator { color: var(--tok-op); }
.CodeMirror .cm-variable, pre.code .cm-variable, .p-line .cm-variable, .CodeMirror .cm-variable-2, pre.code .cm-variable-2, .p-line .cm-variable-2, .CodeMirror .cm-property, pre.code .cm-property, .p-line .cm-property { color: var(--code-ink); }
.CodeMirror .cm-atom, pre.code .cm-atom, .p-line .cm-atom { color: var(--tok-num); }
.CodeMirror .cm-error, pre.code .cm-error, .p-line .cm-error { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (max-width: 760px) {
  .hero { grid-template-columns: minmax(0, 1fr); }
  .stage-blurb { margin-left: 0; width: 100%; }
  .panel { padding: 16px; }
}

/* diagrams in lessons */
.figure { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-end; color: var(--ink); }
.figure figure { margin: 0; display: grid; gap: 4px; justify-items: center; font-size: 14px; color: var(--muted); }
.figure svg { max-width: 100%; height: auto; }

/* Show >= == != exactly as typed: no font ligatures in code */
code, pre, .CodeMirror, .console, textarea.answer, .grid-table input, .p-line, .code-out {
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0;
}
.task-body > p, .task-body > .tablewrap + p { margin: 0; }

/* progress file: save / load */
.file-box { display: flex; align-items: center; gap: 6px; }
.file-box .btn.small { min-height: 30px; padding: 4px 10px; }
.file-status { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.file-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.file-status.ok::before { background: var(--ok); }
.file-status.warn { color: var(--warn); }
.file-status.warn::before { background: var(--warn); }
.top-status .file-status { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.name-input {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); width: 100%;
}
.save-panel { border-color: var(--accent); }
@media (max-width: 900px) { .top-status .file-status { font-size: 0; gap: 0; } }
@media (max-width: 640px) { .top-status { gap: 6px; } }
.spec-link { color: inherit; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 2px; }
.spec-link:hover { color: var(--accent); }

/* links between the two courses */
.mode-switch {
  display: block; margin: -18px 0 8px; padding: 12px 16px; border-radius: var(--radius); text-decoration: none;
  color: var(--ink); background: var(--accent-soft); border: 1.5px solid var(--accent);
}
.mode-switch.ess { background: var(--surface); border: 2px solid var(--gold); box-shadow: inset 6px 0 0 var(--gold); }
.mode-switch:hover { filter: brightness(1.03); }

/* read aloud */
.read-row { display: flex; justify-content: flex-end; }
.read-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.intro .read-row { margin-bottom: 6px; }

/* ---------- Python Essentials: bigger text, shorter lines, one idea per card */
body.essentials { font-size: 18px; line-height: 1.65; }
body.essentials .prose p, body.essentials .prose li { max-width: 58ch; }
body.essentials .learn { max-width: 760px; }
body.essentials .learn-card {
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--stage-c, var(--accent));
  border-radius: var(--radius); padding: 14px 18px; display: grid; gap: 12px;
}
body.essentials .learn .prose { display: grid; gap: 14px; }
body.essentials .learn .prose > * + * { margin-top: 0; }
body.essentials .learn-card h3 { margin-top: 0; font-size: 22px; }
body.essentials .panel.learn { background: transparent; border: 0; padding: 0; }
body.essentials .pyde-btn { display: none; }
body.essentials .intro { font-size: 19px; }
body.essentials .intro p { max-width: 52ch; }
body.essentials .editor-wrap .CodeMirror { font-size: 17px; }
body.essentials .console { font-size: 16px; }
body.essentials .check { font-size: 17px; }
body.essentials .callout { font-size: 17px; }
body.essentials .hero h1 .prompt { color: var(--s1); }
/* keep the footer at the bottom on short pages */
body { min-height: 100vh; display: flex; flex-direction: column; }
body > .app { flex: 1 0 auto; width: 100%; }
body.essentials .learn-card h4 { margin-top: 0; font-size: 22px; }
body.essentials .learn-card p, body.essentials .learn-card ul, body.essentials .learn-card ol { margin: 0; }
body.essentials .intro .prose > * + * { margin-top: 8px; }

/* ---------- wide screens: use the space */
.task-layout { display: grid; grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.6fr); gap: 28px; align-items: start; }
.task-side {
  position: sticky; top: calc(var(--bar-h, 72px) + 14px); display: grid; gap: 14px; align-content: start;
  max-height: calc(100vh - var(--bar-h, 72px) - 28px); overflow-y: auto; padding-right: 4px;
}
.task-side .intro { max-width: none; }
.task-layout .task-body { min-width: 0; }
.task-single .task-body { max-width: 1000px; }
@media (max-width: 1100px) {
  .task-layout { grid-template-columns: minmax(0, 1fr); }
  .task-side { position: static; max-height: none; overflow: visible; padding-right: 0; }
}
.learn-layout { display: grid; grid-template-columns: minmax(0, 940px) minmax(260px, 380px); gap: 28px; align-items: start; }
.learn-layout .learn { max-width: none; }
.learn-aside { position: sticky; top: calc(var(--bar-h, 72px) + 14px); display: grid; gap: 14px; }
.aside-card { display: grid; gap: 10px; padding: 16px 18px; }
.aside-tasks { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-size: 15px; }
.aside-tasks a { color: var(--ink); text-decoration: none; }
.aside-tasks a:hover { color: var(--accent); text-decoration: underline; }
.aside-tasks .t-type { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.aside-tasks li.done::marker { content: "✓  "; color: var(--ok); }
@media (max-width: 1000px) {
  .learn-layout { grid-template-columns: minmax(0, 1fr); }
  .learn-aside { position: static; }
}
body.essentials .learn { max-width: none; }

/* ---------- pupil's name */
.name-wrap { position: relative; }
.name-badge {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 16px; font-weight: 700;
  background: #fff; color: #00255b; border: 0; border-radius: 999px; padding: 3px 14px 3px 3px; min-height: 36px;
  max-width: 260px; box-shadow: 0 0 0 2px rgba(255,255,255,.35);
}
.name-badge .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--gold); color: var(--gold-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 800; flex: none;
}
.name-badge .name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-badge.empty { background: transparent; color: #fff; border: 1.5px dashed rgba(255,255,255,.75); font-weight: 600; }
.name-badge.empty .avatar { background: rgba(255,255,255,.2); color: #fff; }
.name-pop {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 40; width: min(320px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 14px; display: grid; gap: 8px;
}
.name-pop label { font-weight: 700; }
.name-pop input { font: inherit; font-size: 17px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--code-bg); color: var(--ink); }
.name-pop p { margin: 0; font-size: 13px; color: var(--muted); }
.name-pop .btn { color: var(--ink); border-color: var(--line); }
.name-pop .btn.primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.greet { font-family: var(--font-display); font-size: clamp(22px, 2.6vw, 30px); margin: 0 0 6px; color: var(--muted); font-weight: 600; }
.greet strong { color: var(--accent); }
.greet-add {
  font: inherit; font-size: 16px; cursor: pointer; margin-bottom: 10px; padding: 8px 14px; border-radius: 999px;
  border: 1.5px dashed var(--accent); background: var(--accent-soft); color: var(--ink);
}
@media (max-width: 640px) {
  .name-badge { max-width: 150px; font-size: 14px; }
  .name-pop { right: auto; left: 0; position: fixed; top: calc(var(--bar-h, 72px) + 6px); left: 16px; }
}

/* ---------- Python help drawer */
.help-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; font-weight: 700;
  background: var(--gold); color: var(--gold-ink); border: 0; border-radius: 999px; padding: 4px 12px 4px 4px; min-height: 32px;
}
.help-btn > span:first-child {
  width: 24px; height: 24px; border-radius: 50%; background: rgba(0,0,0,.12); display: grid; place-items: center; font-weight: 800;
}
.help-btn:hover { filter: brightness(1.06); }
@media (max-width: 640px) { .help-btn .help-label { display: none; } .help-btn { padding: 4px; } }
.drawer-scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(5, 15, 35, .45); opacity: 0; transition: opacity .2s ease;
}
.drawer-scrim.open { opacity: 1; }
.help-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61; width: min(480px, 100vw);
  background: var(--bg); color: var(--ink); border-left: 4px solid var(--band);
  box-shadow: -12px 0 40px rgba(0,0,0,.25); display: grid; grid-template-rows: auto auto auto 1fr;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  transform: translateX(100%); transition: transform .22s ease;
}
.help-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--band); color: #fff; }
.drawer-head h2 { font-size: 21px; }
.drawer-close { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; }
.drawer-search {
  margin: 12px 16px 6px; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.drawer-topics { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 10px; border-bottom: 1px solid var(--line); }
.chip { font: inherit; font-size: 13px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 3px 10px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.drawer-list { overflow-y: auto; padding: 8px 16px 24px; display: grid; gap: 10px; align-content: start; }
.ref-topic { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 10px 0 0; font-family: var(--font-body); }
.ref-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 6px; }
.ref-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ref-name { font-weight: 700; font-size: 15px; color: var(--accent); }
.ref-what { margin: 0; font-size: 15px; }
.ref-item pre.code { font-size: 13.5px; padding: 8px 10px; }
.ref-erl summary { cursor: pointer; font-size: 13px; color: var(--muted); }
body.essentials .ref-what { font-size: 17px; }
.help-drawer { grid-template-columns: minmax(0, 1fr); overflow: hidden; }
.help-drawer > * { min-width: 0; }
.drawer-list pre.code { white-space: pre; overflow-x: auto; }
/* small screens: the banner is tall when it wraps, so let it scroll away */
@media (max-width: 760px) { .topbar { position: static; } :root { --bar-h: 0px; } }

/* ---------- free coding */
.home-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin: -18px 0 8px; }
.home-links .mode-switch { margin: 0; }
.mode-switch.code-link { background: var(--surface); border: 2px solid var(--s1); box-shadow: inset 6px 0 0 var(--s1); }
.play-head { margin-bottom: 8px; }
.play-toolbar { margin-bottom: 12px; }
.play-name, .play-fname {
  font-family: var(--font-mono); font-size: 14px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 15em; max-width: 100%;
}
.play-examples { font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); min-height: 32px; }
.play-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 18px; align-items: start; }
.play-editor .CodeMirror, .play-editor .CodeMirror-scroll { min-height: min(68vh, 640px); }
.play-editor .CodeMirror-scroll { max-height: 78vh; }
.play-side { display: grid; gap: 14px; position: sticky; top: calc(var(--bar-h, 72px) + 14px); }
.play-console { min-height: 240px; max-height: 52vh; }
.play-data { display: grid; gap: 6px; padding: 12px 14px; }
.play-data summary { cursor: pointer; font-weight: 700; }
.play-data[open] summary { margin-bottom: 6px; }
.play-file { min-height: 120px; }
@media (max-width: 1000px) {
  .play-layout { grid-template-columns: minmax(0, 1fr); }
  .play-side { position: static; }
  .play-editor .CodeMirror, .play-editor .CodeMirror-scroll { min-height: 45vh; }
}

/* ---------- code text size (A- / A+) */
.editor-wrap .CodeMirror, .example .CodeMirror, body.essentials .editor-wrap .CodeMirror { font-size: var(--code-size, 15px); }
.console, body.essentials .console { font-size: calc(var(--code-size, 15px) - 1px); }
.text-size .btn { min-width: 38px; font-weight: 700; }

/* ---------- output tabs (Console | Graphics | Files) */
.out-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); }
.out-tab {
  font: inherit; font-size: 14px; cursor: pointer; padding: 6px 14px; border: 1px solid var(--line); border-bottom: 0;
  border-radius: 8px 8px 0 0; background: var(--surface-2); color: var(--muted); margin-bottom: -2px;
}
.out-tab.on { background: var(--surface); color: var(--ink); font-weight: 700; border-color: var(--line); border-bottom: 2px solid var(--surface); }
.tab-pane { padding-top: 10px; display: grid; gap: 10px; }

/* ---------- turtle graphics */
.turtle-box { display: grid; gap: 8px; margin-bottom: 10px; }
.turtle-stage {
  position: relative; width: 100%; background: #ffffff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  box-shadow: var(--shadow);
}
.turtle-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.turtle-bar { justify-content: flex-end; }

/* ---------- share / puzzle link */
.link-box {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: -4px 0 12px; padding: 10px 12px;
  border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent);
}
.link-field { flex: 1 1 260px; min-width: 0; font-family: var(--font-mono); font-size: 13px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.play-main { display: grid; gap: 12px; min-width: 0; }
.p-line { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- trace table drawer (slides in from the left) */
:root { --trace-w: clamp(320px, 34vw, 480px); }
.trace-drawer {
  position: fixed; left: 0; top: var(--bar-h, 72px); bottom: 0; z-index: 25; width: min(var(--trace-w), 100vw);
  background: var(--bg); color: var(--ink); border-right: 4px solid var(--band);
  box-shadow: 12px 0 40px rgba(0,0,0,.18); display: grid; grid-template-rows: auto auto auto 1fr auto;
  grid-template-columns: minmax(0, 1fr); padding-left: env(safe-area-inset-left, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateX(-100%); transition: transform .22s ease;
}
.trace-drawer.open { transform: translateX(0); }
.trace-drawer > * { min-width: 0; }
.trace-head { background: var(--band); color: #fff; }
.trace-controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; padding: 10px 14px 4px; }
.trace-status { margin: 0; padding: 4px 14px 8px; font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--line); }
.trace-status.wait { color: var(--warn); font-weight: 700; }
.trace-status.err { color: var(--bad); font-weight: 700; }
.trace-wrap { overflow: auto; padding: 8px 14px; }
.trace-table { border-collapse: collapse; font-family: var(--font-mono); font-size: 13.5px; font-variant-numeric: tabular-nums; min-width: 100%; }
.trace-table th, .trace-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; white-space: nowrap; }
.trace-table th { background: var(--surface-2); position: sticky; top: -8px; z-index: 1; }
.trace-table td { background: var(--surface); }
.trace-table td.ln { color: var(--muted); text-align: right; }
.trace-table td.chg { font-weight: 700; }
.trace-table td.same { color: var(--muted); }
.trace-table td.inp { color: var(--ok); font-weight: 700; }
.trace-table tr.cur td { background: var(--gold); color: var(--gold-ink); }
.trace-table tr.err td { background: var(--bad-soft); }
.trace-foot { display: flex; gap: 10px; align-items: center; padding: 8px 14px 12px; border-top: 1px solid var(--line); font-size: 13px; }
.CodeMirror .trace-cur { background: color-mix(in srgb, var(--gold) 45%, transparent); }
.CodeMirror .trace-cur-gutter { color: var(--gold-ink); background: var(--gold); }
.trace-toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.step-btn { font-weight: 700; }
@media (min-width: 900px) {
  body.trace-open > .app { margin-left: var(--trace-w); max-width: calc(100% - var(--trace-w)); }
  body.trace-open > .site-footer { margin-left: var(--trace-w); }
}
@media (max-width: 760px) { .trace-drawer { top: 0; z-index: 62; } }
@media (min-width: 900px) and (max-width: 1250px) {
  body.trace-open .play-layout { grid-template-columns: minmax(0, 1fr); }
  body.trace-open .play-side { position: static; }
}

/* ---------- exam practice */
.marks-pill { font-size: 13px; font-weight: 700; color: var(--s5); border: 1.5px solid var(--s5); border-radius: 999px; padding: 1px 9px; }
.score-line.marks { font-family: var(--font-display); font-size: 20px; color: var(--s5); }
.numbered { display: grid; grid-template-columns: auto minmax(0, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.numbered pre.code { border: 0; border-radius: 0; }
.numbered pre.code.erl { border-left: 0; }
.code-gutter {
  margin: 0; padding: 12px 8px; font-family: var(--font-mono); font-size: 14px; line-height: 1.5; color: var(--muted);
  background: var(--surface-2); text-align: right; user-select: none; border-right: 1px solid var(--line);
}
.numbered.labelled .code-gutter { padding-top: calc(12px + 6px + 1.5em * 0.75); }
.otrace-table input.ln-in { min-width: 56px; }
.answer-table td.fixed { text-align: left; }

/* ---------- hidden teacher tools (Ctrl + Alt + right-click the logo) */
.admin-scrim { position: fixed; inset: 0; z-index: 80; background: rgba(5, 15, 35, .55); display: grid; place-items: center; padding: 16px; }
.admin-box { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--bg); color: var(--ink); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.4); border-top: 5px solid var(--band); }
.admin-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--band); color: #fff; }
.admin-head h2 { font-size: 20px; }
.admin-body { padding: 16px; display: grid; gap: 10px; }
.admin-body h3 { font-size: 18px; margin-top: 4px; }
.admin-form { display: grid; gap: 8px; }
.admin-form label, .admin-body > label { font-weight: 700; font-size: 14px; }
.admin-input { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 100%; }
.admin-msg { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.admin-choices { display: grid; gap: 8px; }
.admin-choice { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.admin-choice:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.admin-choice span { display: grid; gap: 2px; }
.admin-choice small { color: var(--muted); font-size: 13px; }
.admin-check { font-weight: 400 !important; display: flex; gap: 8px; align-items: center; }
.admin-challenge { display: grid; gap: 2px; margin: 0 0 6px; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); }
.admin-challenge span { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.admin-challenge strong { font-family: var(--font-mono); font-size: 26px; letter-spacing: .06em; }

/* ---------- knowledge organisers and homework sheets */
.sheet-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sheet-btn { gap: 7px; font-weight: 700; }
.sheet-btn .sheet-ic { font-size: 15px; line-height: 1; }
.ko-btn { border-color: var(--stage-c, var(--accent)); color: var(--ink); }
.hw-btn { border-color: var(--gold); }
.sheet-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.sheet-tools .spacer { flex: 1; }
.sheet-help { margin: 0 0 12px; }
.sheet-wrap { background: var(--surface-2); border-radius: var(--radius); padding: clamp(8px, 3vw, 28px); overflow-x: auto; }
.sheet-wrap .sheet { width: 210mm; max-width: 100%; margin: 0 auto; padding: 9mm; box-shadow: 0 4px 24px rgba(0,0,0,.18); border-radius: 4px; }
@media (max-width: 760px) { .sheet-wrap .sheet { padding: 4mm; } }
@media print {
  @page { size: A4; margin: 9mm; }
  html, body { background: #fff !important; }
  .topbar, .site-footer, .sheet-tools, .sheet-help, .trace-drawer, .help-drawer, .drawer-scrim, .toast, .admin-scrim, body::before { display: none !important; }
  body > .app { margin: 0 !important; padding: 0 !important; max-width: none !important; }
  .sheet-wrap { background: none; padding: 0; border-radius: 0; }
  .sheet-wrap .sheet { width: auto; padding: 0; box-shadow: none; border-radius: 0; }
}

/* ---------- progress: rank, stage rings, medals, trophies */
.rank-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 18px 24px; align-items: center; margin-bottom: 18px;
  background: linear-gradient(120deg, var(--surface) 55%, var(--accent-soft)); border-width: 2px; border-color: var(--accent);
}
.rank-badge {
  width: 104px; height: 116px; display: grid; place-items: center; align-content: center; gap: 2px; color: #fff;
  background: linear-gradient(160deg, #0a4fb3, #26255d);
  clip-path: polygon(50% 0, 100% 22%, 100% 74%, 50% 100%, 0 74%, 0 22%);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .25));
}
.rank-ic { font-size: 40px; line-height: 1; }
.rank-lvl { font-family: var(--font-display); font-weight: 800; font-size: 14px; letter-spacing: .05em; background: rgba(255,255,255,.18); padding: 1px 9px; border-radius: 999px; }
.rank-kicker { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.rank-name { font-size: clamp(26px, 3.4vw, 38px); font-weight: 800; letter-spacing: -.01em; }
.rank-line { margin: 2px 0 10px; color: var(--muted); }
.rank-bar { height: 14px; max-width: 520px; }
.rank-bar > i { background: linear-gradient(90deg, var(--s1), var(--s3)); }
.rank-next { margin: 6px 0 0; font-weight: 700; font-size: 15px; }
.rank-tally { display: grid; grid-template-columns: repeat(2, minmax(70px, auto)); gap: 8px; }
.rank-tally div { display: grid; justify-items: center; padding: 8px 12px; border-radius: 12px; background: var(--surface-2); }
.rank-tally b { font-family: var(--font-display); font-size: 24px; font-weight: 800; line-height: 1.1; }
.rank-tally span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.rank-tally div:nth-child(1) b { color: #b8860b; } .rank-tally div:nth-child(2) b { color: #7b8794; } .rank-tally div:nth-child(3) b { color: #9a5b26; }
.rank-ladder { grid-column: 1 / -1; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.rank-ladder li { display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px; text-align: center; font-size: 11.5px; line-height: 1.15; border: 1.5px solid transparent; }
.rank-ladder .rl-ic { font-size: 20px; }
.rank-ladder li.past { background: var(--surface-2); }
.rank-ladder li.now { background: var(--accent-soft); border-color: var(--accent); font-weight: 700; }
.rank-ladder li.future { opacity: .5; }
@media (max-width: 900px) {
  .rank-card { grid-template-columns: auto 1fr; }
  .rank-tally { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); }
  .rank-ladder { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 520px) { .rank-badge { width: 80px; height: 90px; } .rank-ic { font-size: 30px; } }

.stage-rings { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 10px; }
.ring { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); border-left: 4px solid var(--stage-c); }
.ring-svg { color: var(--ink); line-height: 0; flex: none; }
.ring-txt { display: grid; line-height: 1.25; }
.ring-txt b { color: var(--stage-c); font-family: var(--font-display); }
.ring-txt small { color: var(--muted); }

.medal-key { margin: 4px 0 6px; }
.medal-cabinet { display: grid; gap: 14px; }
.medal-shelf h4 { margin: 0 0 6px; font-size: 14px; color: var(--stage-c); font-family: var(--font-display); border-bottom: 2px solid var(--stage-c); padding-bottom: 3px; }
.medal-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.medal { display: grid; justify-items: center; gap: 2px; padding: 6px 4px 8px; border-radius: 12px; text-decoration: none; color: var(--ink); text-align: center; border: 1.5px solid transparent; transition: transform .15s ease, border-color .15s ease; }
.medal:hover, .medal:focus-visible { border-color: var(--stage-c); transform: translateY(-2px); }
.medal.t0 { color: var(--muted); }
.medal.t3 { background: linear-gradient(180deg, rgba(255, 216, 77, .18), transparent); }
.medal .medal-svg { line-height: 0; }
.medal.t3 .medal-svg svg { filter: drop-shadow(0 0 6px rgba(255, 200, 0, .55)); }
.medal-name { font-size: 12px; line-height: 1.2; }
.medal-count { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }

.trophy-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.trophy { display: grid; justify-items: center; text-align: center; gap: 3px; padding: 12px 8px; border-radius: 12px; background: var(--surface-2); border: 1.5px dashed var(--line); }
.trophy .tr-ic { font-size: 30px; line-height: 1.1; filter: grayscale(1); opacity: .55; }
.trophy .tr-name { font-weight: 700; font-size: 14px; }
.trophy .tr-how { font-size: 12px; color: var(--muted); }
.trophy.got { border: 1.5px solid var(--s3); background: linear-gradient(180deg, var(--warn-soft, rgba(230,200,0,.15)), var(--surface-2)); }
.trophy.got .tr-ic { filter: none; opacity: 1; animation: trophy-pop .5s ease; }
.trophy.got .tr-how { color: var(--ok, #1a7f37); font-weight: 700; }
@keyframes trophy-pop { 0% { transform: scale(.6); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .trophy.got .tr-ic, .medal { animation: none; transition: none; } }
