/* ── Visuco design tokens ─────────────────────────────────
   Hacker green on green-biased neutrals. Light + dark via
   prefers-color-scheme; dark is the primary look. */
:root {
  --bg: #f3f5ef;
  --panel: #ffffff;
  --border: #dfe5d6;
  --text: #1c2117;
  --muted: #5c6750;
  --accent: #55841f;
  --accent-soft: rgba(85, 132, 31, 0.12);
  --btn-text: #ffffff;
  --pass: #55841f;
  --fail: #c02a4d;
  --fail-soft: rgba(192, 42, 77, 0.09);
  /* Form controls: a distinct fill and a clearly visible border so an input
     never blends into the page behind it */
  --field-bg: #ffffff;
  --field-border: #b7c3a6;
  --editor-bg: #1E1E1E;
  --shadow: 0 1px 2px rgba(20, 28, 12, 0.06), 0 4px 16px rgba(20, 28, 12, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --panel: #0b0b0b;
    --border: #1A1A1A;
    --text: #E8E8E6;
    --muted: #8A8A8A;
    --accent: #7cb442;
    --accent-soft: rgba(124, 180, 66, 0.16);
    --btn-text: #10190a;
    --pass: #7cb442;
    --fail: #e25368;
    --fail-soft: rgba(226, 83, 104, 0.13);
    --field-bg: #1c1c1c;
    --field-border: #3d3d3d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace; }
a { color: var(--accent); }

button { font: inherit; cursor: pointer; color: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; font-size: 13.5px; color: var(--muted);
  text-decoration: none; display: inline-block;
}
.btn-mini { padding: 3px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; }
.btn-mini:hover { color: var(--text); border-color: var(--muted); }
/* Grid button: "Grid" reads as the button, the value as a tinted chip */
#gridBtn { display: inline-flex; align-items: stretch; padding: 0; overflow: hidden; }
#gridBtn[aria-pressed="true"] { background: none; border-color: var(--border); color: var(--muted); }
#gridBtn .grid-lab { padding: 7px 12px; }
#gridBtn .grid-val {
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; padding: 0 11px;
  border-left: 1px solid var(--border);
  background: var(--bg); color: var(--muted);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
#gridBtn[aria-pressed="true"] .grid-val { background: var(--accent-soft); color: var(--accent); }
.btn-ghost[aria-pressed="true"] {
  color: var(--accent); border-color: var(--accent); background: var(--accent-soft);
}
/* Try goes solid green while a try run is live, like the Run button */
#tryBtn[aria-pressed="true"] {
  background: var(--accent); color: var(--btn-text); border-color: var(--accent);
  font-weight: 600;
}
.btn-run {
  background: var(--accent); color: var(--btn-text); border: none; border-radius: 8px;
  padding: 7px 18px 7px 14px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 7px; text-decoration: none;
}
.btn-run:hover { filter: brightness(1.08); }
.btn-run svg { display: block; }

/* ── Top bar ── */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
/* Wordmark: lowercase, in the code font, with a terminal cursor — the name
   reads like something you'd type. The mark is the logo image. */
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-weight: 600; font-size: 16.5px; letter-spacing: -0.02em;
  text-transform: lowercase;
  color: var(--text); text-decoration: none;
}
.brand::after {
  content: "_";
  margin-left: -6px; /* pull back the flex gap so the cursor hugs the word */
  color: var(--accent); font-weight: 700;
  animation: brand-blink 1.1s steps(1) infinite;
}
@keyframes brand-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .brand::after { animation: none; }
}
.brand-mark {
  width: 26px; height: 18px; flex: none;
  background: url(/images/logo.png) center / contain no-repeat;
}
.crumbs { color: var(--muted); font-size: 13.5px; display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.5; }
.crumbs .here { color: var(--text); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Course links sit inline on desktop (display:contents lets the <a>s flow into
   .topbar-actions) and collapse behind a single "Courses" toggle under 900px. */
.course-nav { display: contents; }
.course-nav-toggle { display: none; }
.course-nav-links { display: contents; }
@media (max-width: 900px) {
  .course-nav { position: relative; display: inline-block; }
  .course-nav-toggle { display: inline-block; }
  .course-nav-links {
    display: none; position: absolute; right: 0; top: calc(100% + 8px);
    flex-direction: column; gap: 4px; min-width: 190px; padding: 6px; z-index: 20;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  }
  .course-nav-cb:checked ~ .course-nav-links { display: flex; }
  .course-nav-links .btn-ghost { border: none; text-align: left; width: 100%; }
}

/* ── Workbench layout ── */
.workbench {
  display: grid;
  grid-template-columns: minmax(360px, 5fr) minmax(0, 6fr);
  grid-template-areas: "editor stage" "editor results";
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 16px 20px 28px;
  max-width: 1280px;
  margin: 0 auto;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.panel-head .meta { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12.5px; }

/* ── Editor ── */
.editor-panel { grid-area: editor; display: flex; flex-direction: column; min-height: 420px; }
.editor-panel .editor-host { flex: 1; min-height: 0; background: var(--editor-bg); }
.editor-panel .CodeMirror { height: 100%; font-size: 13.5px; line-height: 1.7; }

/* ── Stage ── */
.stage-panel { grid-area: stage; }
.seg {
  display: inline-flex; background: var(--bg);
  border: 1px solid var(--border); border-radius: 9px; padding: 2px;
}
.seg button {
  border: none; background: none; border-radius: 7px; white-space: nowrap;
  padding: 4px 14px; font-size: 13px; color: var(--muted); font-weight: 550;
}
.seg button[aria-pressed="true"] {
  background: var(--panel); color: var(--text); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 3px 13px;
}
.stage {
  display: flex; gap: 20px; justify-content: center; align-items: flex-start;
  padding: 20px;
}
@media (max-width: 900px) {
  .stage { flex-wrap: wrap; }
}
/* Viewports display at the sketch's natural pixel size (width set by JS),
   shrinking as flex items only when the stage is too narrow */
.viewport { text-align: center; margin: 0; flex: 0 1 auto; min-width: 0; max-width: 100%; }
.viewport .screen {
  background: var(--editor-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  box-shadow: var(--shadow);
}
.viewport canvas {
  /* the ratio follows the sketch's own dimensions (set by main.js) — a hardcoded
     1 here squashed any canvas that wasn't square, turning circles into ovals */
  width: 100%; aspect-ratio: var(--vp-ratio, 1); display: block;
  border-radius: 5px;
}
.viewport .cap { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* Replay controls under the canvases */
.try-note {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 20px 14px; padding: 9px 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 8px; font-size: 13px; line-height: 1.45;
}
.try-note[hidden] { display: none; }
.try-note b { color: var(--accent); font-weight: 650; white-space: nowrap; }
.playbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px 16px;
}
.playbar[hidden] { display: none; }
.pb-btn {
  min-width: 40px; min-height: 32px;
  border: 1px solid var(--border); border-radius: 8px; background: none;
  color: var(--muted); font-size: 13px; line-height: 1;
}
.pb-btn:hover { color: var(--accent); border-color: var(--accent); }
/* the playbar is always on screen; while there's nothing recorded to replay
   its controls sit there greyed out rather than vanishing */
.pb-btn:disabled { opacity: 0.4; cursor: default; }
.pb-btn:disabled:hover { color: var(--muted); border-color: var(--border); }
#scrub:disabled { opacity: 0.4; }
.scrub-wrap { position: relative; flex: 1; display: flex; align-items: center; min-width: 0; }
#scrub { width: 100%; accent-color: var(--accent); min-width: 0; }
/* interaction-event markers on the scrub track */
#evmarks { position: absolute; left: 0; right: 0; top: -8px; height: 12px; pointer-events: none; }
.ev-mark {
  position: absolute; transform: translateX(-50%);
  width: 11px; height: 11px; border-radius: 50%; padding: 0;
  background: var(--accent); border: 2px solid var(--panel);
  pointer-events: auto; cursor: pointer;
}
.ev-mark:hover { transform: translateX(-50%) scale(1.3); }

/* "what just happened" pill over the canvases when an event fires */
.stage-panel { position: relative; }
.event-flash {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%);
  background: #10140c; border: 1px solid var(--accent); color: #e7ece1;
  padding: 6px 14px; border-radius: 999px; font-size: 12.5px;
  white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
  z-index: 4; pointer-events: none;
}
.event-flash[hidden] { display: none; }
.frame-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.coords { color: var(--accent); }
.coords:not(:empty)::after { content: " · "; color: var(--muted); }
.stage-panel .panel-head { flex-wrap: wrap; }

/* ── Results ── */
.results-panel { grid-area: results; }
.results-body { padding: 16px 18px 18px; display: grid; gap: 18px; }
.score-row { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.score-num { font-size: 40px; font-weight: 650; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.score-num small { font-size: 22px; font-weight: 550; color: var(--muted); }
.score-sub { color: var(--muted); font-size: 13.5px; }
.meter { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.25s ease; }

.cats { display: grid; gap: 9px; }
.cats:empty { display: none; }
.cat { display: grid; grid-template-columns: 110px 1fr 74px 20px; gap: 12px; align-items: center; }
.cat .name { font-size: 12px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.cat .frac { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.cat .mark { font-size: 14px; text-align: center; line-height: 1; }
.cat .mark.ok { color: var(--pass); }
.cat .mark.no { color: var(--fail); }
.cat.clickable { cursor: pointer; }
.cat.clickable:hover .name { color: var(--accent); }

/* Inline colour swatches in hints */
.swatch {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid var(--border); vertical-align: -1.5px;
}

.hints { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.hints[hidden] { display: none; }
.hints-head {
  padding: 9px 14px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--border); background: var(--fail-soft);
  display: flex; gap: 8px; align-items: center;
}
.hints ul { margin: 0; padding: 10px 14px 12px 30px; display: grid; gap: 6px; font-size: 13.5px; color: var(--text); }
.hints li::marker { color: var(--fail); }
.hints .cat-tag { font-weight: 600; }
.error-msg { padding: 10px 14px; font-size: 13px; color: var(--fail); overflow-x: auto; }
.error-plain { padding: 0 14px 12px; font-size: 13px; color: var(--text); line-height: 1.5; }
.error-plain::before { content: '💡 '; }

.status-line { font-size: 13px; color: var(--muted); }
.status-line b { color: var(--text); font-weight: 550; }

.desc { border-top: 1px dashed var(--border); padding-top: 12px; font-size: 13.5px; color: var(--muted); max-width: 62ch; }
.desc b { color: var(--text); }

/* The task, in a band above the workbench — the first thing read, and aligned
   to the same max-width and gutters as the panels below it. */
.task {
  /* line up with the panels below: the workbench is max-width 1280 with 20px
     side padding, so its content is 1240 wide with 20px gutters */
  max-width: 1240px; width: calc(100% - 40px);
  margin: 16px auto 0; padding: 14px 18px 16px;
  /* Reads as content, not as an alert: panel background and a plain border, the
     same grammar as the editor and stage panels. The old tinted band with an
     accent rule down its left edge looked like a dismissible notice, and got
     treated as one. */
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow);
}
.task-step {
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 6px;
}
/* the explaining half: present, but clearly not the sentence to act on */
.task-why {
  margin: 0; font-size: 14px; line-height: 1.55; color: var(--muted);
}
/* the doing half — the loudest text on the page bar the score */
.task-do {
  margin: 8px 0 0; font-size: 17px; line-height: 1.45; font-weight: 600;
  color: var(--text);
}
.task-do::before {
  content: '\25B8'; flex: none; color: var(--accent); font-weight: 400;margin-right:0.3em;
}
/* The same instruction repeated where it's needed: above line 1 of the code,
   and above the hints after a run that didn't pass. */
.task-pin {
  margin: 0; padding: 9px 14px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  font-size: 14px; line-height: 1.4; font-weight: 600; color: var(--text);
  display: flex; gap: 8px; align-items: baseline;
}
.task-pin::before { content: '\25B8'; flex: none; color: var(--accent); font-weight: 400; }
/* the third copy is a safety net, not a third shout: quiet, so the loud one
   stays the instruction above the code */
.task-pin-hint {
  border: 0; background: none; padding: 0 0 9px;
  font-size: 13.5px; font-weight: 500; color: var(--muted);
}
/* solved: the instruction stops asking and starts confirming */
.task-done .task-do::before, .task-done .task-pin::before { content: '\2713'; font-weight: 700; }
.task-done .task-do, .task-done .task-pin { color: var(--muted); }
@media (max-width: 900px) {
  /* the workbench becomes a tabbed, full-height column and goes full-bleed
     here, so the task follows it edge to edge — still above the tabs */
  .task {
    width: 100%; max-width: none; margin: 0; padding: 12px 14px 14px;
    border-radius: 0; border-top: 0; border-left: 0; border-right: 0;
    box-shadow: none;
  }
  .task-do { font-size: 16px; }
}

/* Prev/next challenge links */
.chal-nav { display: flex; justify-content: space-between; gap: 16px; border-top: 1px dashed var(--border); padding-top: 12px; font-size: 13.5px; }
.chal-nav a {
  text-decoration: none; font-weight: 550; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chal-nav a:hover { text-decoration: underline; }
.chal-nav .next { margin-left: auto; }

/* Comfortable touch targets */
@media (pointer: coarse) {
  .seg button { padding-top: 10px; padding-bottom: 10px; }
  .seg button[aria-pressed="true"] { padding-top: 9px; padding-bottom: 9px; }
}

/* Symbol toolbar: shown on touch devices, where phone keyboards bury the
   punctuation JavaScript needs behind symbol layers */
.kbar { display: none; }
@media (pointer: coarse) {
  .kbar {
    display: flex; gap: 4px; overflow-x: auto;
    padding: 5px 8px; border-bottom: 1px solid var(--border);
    background: var(--panel);
    -webkit-overflow-scrolling: touch;
  }
  .kbar button {
    flex: 1 0 36px; min-height: 38px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
    font-size: 16px; color: var(--text); padding: 0;
  }
  .kbar button:active { background: var(--accent-soft); border-color: var(--accent); }
}

/* Console strip under the editor for print() output */
.console { border-top: 1px solid var(--border); background: var(--editor-bg); }
.console[hidden] { display: none; }
.console-head {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 14px 0; font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.console-head .meta { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 11.5px; }
.console-out {
  margin: 0; padding: 6px 14px 10px; max-height: 110px; overflow-y: auto;
  font-size: 12.5px; line-height: 1.6; color: #b8e086; white-space: pre-wrap;
}

/* CodeMirror 6: the editor node also carries the .CodeMirror class (the shim
   adds it) so the height/font rules above still apply; these fill the scroller
   and quiet the focus outline. The editor is dark in both site themes. */
.cm-editor { height: 100%; }
.cm-editor .cm-scroller { flex: 1 1 auto; overflow: auto; }
.cm-editor.cm-focused { outline: none; }

/* Error line highlight (line decoration class on .cm-line) */
.cm-editor .cm-line.cm-error-line { background: rgba(226, 83, 104, 0.25); }

/* Locked scaffold: editable slots read as small green input fields (matching
   the walkthrough's .tut-slot), so it's obvious what the student may change;
   everything else is fixed. The slot is one mark span wrapping the
   syntax-highlight spans; `outline` (not `border`) gives the green frame
   without reflowing the glyphs inside the line. */
.cm-editor .cm-slot {
  background: var(--accent-soft);
  outline: 1px solid var(--accent);
  border-radius: 5px;
  padding: 2px 4px;
}
.editor-host { position: relative; }
.lock-hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: #10140c; border: 1px solid var(--border); color: #e7ece1;
  padding: 6px 14px; border-radius: 999px; font-size: 12px;
  white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
  z-index: 4; pointer-events: none;
}
.lock-hint[hidden] { display: none; }

/* Autocomplete popup, matched to the dark editor (CM6 autocompletion tooltip) */
.cm-tooltip.cm-tooltip-autocomplete {
  background: #10140c; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.cm-tooltip-autocomplete > ul {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 13px; max-height: 16em;
}
.cm-tooltip-autocomplete > ul > li {
  color: #d8dee9; padding: 3px 10px; border-radius: 5px;
}
.cm-tooltip-autocomplete > ul > li[aria-selected] {
  background: rgba(124, 180, 66, 0.25); color: #e7ece1;
}
.cm-tooltip-autocomplete .cm-completionIcon { display: none; }

/* The topic crumb is the first thing to go when the top bar tightens */
@media (max-width: 1000px) {
  .challenge .crumb-topic { display: none; }
}

/* Compact top bar: logo mark + challenge title + actions */
@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .challenge .brand { font-size: 0; gap: 0; }
  .challenge .crumbs { flex: 1; }
  .challenge .crumbs a, .challenge .crumbs .sep { display: none; }
  .challenge .crumbs .here { font-size: 13.5px; }
}

/* ── Small-screen layout: full-height tabs (Preview / Results / Code) ──
   Covers phones and portrait tablets; must match mqMobile in main.js */
.mtabs { display: none; }
@media (max-width: 900px) {
  /* One panel at a time, filling the space between top bar and tab bar */
  .challenge { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .challenge .workbench {
    display: block; flex: 1; min-height: 0;
    padding: 0; margin: 0; max-width: none; overflow: hidden;
  }
  .challenge .panel {
    display: none; height: 100%;
    border-radius: 0; border-left: 0; border-right: 0; box-shadow: none;
  }
  .challenge .panel.m-active { display: flex; flex-direction: column; }
  .challenge .editor-panel { min-height: 0; }
  .challenge .stage { flex: 1; overflow-y: auto; align-content: flex-start; }
  .challenge .results-body { flex: 1; overflow-y: auto; align-content: start; }

  .challenge .mtabs {
    display: flex; gap: 6px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: var(--panel);
  }
  .mtabs button {
    flex: 1; min-height: 44px;
    display: flex; align-items: center; justify-content: center; gap: 7px;
    border: none; background: none; border-radius: 9px;
    font-size: 13.5px; font-weight: 600; color: var(--muted);
  }
  .mtabs button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
  .tab-score {
    font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
    background: var(--bg); color: var(--muted); font-variant-numeric: tabular-nums;
  }
  .tab-score:empty { display: none; }
  .mtabs button[aria-pressed="true"] .tab-score { background: var(--panel); color: var(--accent); }
}

/* ── Landing page ─────────────────────────────────────── */
.landing main { max-width: 1080px; margin: 0 auto; padding: 0 20px 60px; }
.hero {
  display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
  gap: 48px; align-items: center;
  padding: 64px 0 48px;
}
.hero h1 {
  font-size: clamp(30px, 4.5vw, 44px); line-height: 1.12; margin: 0 0 16px;
  letter-spacing: -0.02em; text-wrap: balance;
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero .lede { font-size: 17px; color: var(--muted); max-width: 46ch; margin: 0 0 26px; }
.hero-ctas { display: flex; gap: 12px; align-items: center; }
.hero-ctas .btn-run { font-size: 15px; padding: 10px 22px 10px 18px; }
.hero-ctas .btn-ghost { padding: 9px 16px; font-size: 14px; }

.hero-demo { display: grid; gap: 10px; justify-items: center; }
.hero-demo .screen {
  width: min(100%, 320px);
  background: var(--editor-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.hero-demo canvas {
  width: 100%; aspect-ratio: 1; display: block;
  border-radius: 6px;
}
.hero-demo .demo-code {
  width: min(100%, 320px);
  background: var(--editor-bg); color: #d8dee9;
  border-radius: 10px; padding: 12px 16px;
  font-size: 12.5px; line-height: 1.65; overflow-x: auto;
  text-align: left; margin: 0;
}
.demo-code .kw { color: #b48ead; }
.demo-code .fn { color: #88c0d0; }
.demo-code .lit { color: #d08770; }
.hero-demo .demo-cap { font-size: 12.5px; color: var(--muted); }

.section { padding: 36px 0; }
.section > h2 {
  font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em;
}
.section > .section-sub { color: var(--muted); margin: 0 0 24px; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.step {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; box-shadow: var(--shadow);
}
.step .step-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 650; font-size: 13px; margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.step h3 { margin: 0 0 6px; font-size: 15.5px; }
.step p { margin: 0; font-size: 13.5px; color: var(--muted); }

.challenge-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.challenge-card {
  display: block; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px; text-decoration: none;
  color: var(--text); box-shadow: var(--shadow);
}
.challenge-card:hover { border-color: var(--accent); }
.challenge-card .cc-id { font-size: 12px; color: var(--muted); letter-spacing: 0.07em; text-transform: uppercase; font-weight: 600; }
.challenge-card .cc-done { color: var(--pass); margin-left: 8px; letter-spacing: 0.04em; }
.challenge-card .cc-title { font-weight: 600; margin-top: 4px; }
.challenge-card .cc-go { font-size: 13px; color: var(--accent); margin-top: 10px; font-weight: 550; }

/* ── Courses & topics ── */
.landing .crumbs { flex: 1; }
.page-head { padding-bottom: 8px; }
.page-head h2 { font-size: clamp(24px, 3.5vw, 32px); margin: 6px 0; letter-spacing: -0.015em; }

.topic-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; margin: 0 0 4px; letter-spacing: -0.01em;
}
.topic-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 650; font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.topic-sub { margin: 0 0 14px 34px; font-size: 13.5px; color: var(--muted); max-width: 60ch; }
.topic .challenge-list { margin-left: 34px; }
/* a topic shown on its own, with no number badge to align under (the landing
   page's single "get started" topic) — so nothing is indented */
.topic-plain .topic-sub, .topic-plain .challenge-list { margin-left: 0; }
.topic-lesson { margin: 0 0 14px 34px; max-width: 70ch; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.topic-lesson > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--accent); list-style: none; }
.topic-lesson > summary::-webkit-details-marker { display: none; }
.topic-lesson > summary::before { content: '\25B8\00a0'; }
.topic-lesson[open] > summary::before { content: '\25BE\00a0'; }
.topic-lesson .lesson-body { padding: 0 14px 14px; color: var(--text); line-height: 1.6; font-size: 14.5px; }
@media (max-width: 640px) {
  .topic-sub, .topic .challenge-list, .topic-lesson { margin-left: 0; }
}

.course-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.course-card {
  display: block; position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 20px; text-decoration: none;
  color: var(--text); box-shadow: var(--shadow);
}
.course-card:hover { border-color: var(--accent); }
/* whole-card click without nesting anchors: the cover link stretches over
   the card; action buttons sit above it */
.card-cover { color: inherit; text-decoration: none; }
.card-cover::after { content: ""; position: absolute; inset: 0; }
.card-actions { position: relative; z-index: 1; display: flex; gap: 8px; margin-top: 14px; }
.course-byline { font-size: 12px; color: var(--muted); letter-spacing: 0.07em; text-transform: uppercase; font-weight: 600; }
.course-title { font-weight: 650; font-size: 17px; margin-top: 4px; }
.course-desc { margin: 8px 0 0; font-size: 13.5px; color: var(--muted); }
.course-meta {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; font-size: 12px; color: var(--muted);
}
.course-progress:empty { display: none; }
.course-progress.has-progress { color: var(--pass); font-weight: 600; }
p.course-progress { font-size: 13px; margin: 6px 0 0; }
.badge-official {
  display: inline-block; margin-left: 8px; padding: 1px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 650; letter-spacing: 0.05em;
}
.challenge-card.done { border-color: var(--pass); }

/* ── Creator studio ── */
.tree-course {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 14px;
}
.tree-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; min-width: 0; }
.tree-title { color: var(--text); text-decoration: none; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.tree-title:hover { color: var(--accent); }
.tree-course-row .tree-title { font-size: 17px; font-weight: 650; display: block; }
.tree-actions { display: flex; gap: 6px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.tree-topic { margin: 8px 0 4px 14px; padding-left: 14px; border-left: 2px solid var(--border); }
.tree-challenge { margin-left: 14px; padding-left: 14px; border-left: 2px solid var(--border); }
.tree-challenge .tree-title { font-weight: 450; font-size: 14px; }
.tree-empty { color: var(--muted); font-size: 13px; }
.tree-warn { color: var(--fail); font-size: 12px; font-weight: 600; align-self: center; }

/* Friendly 404 (not_found_page in inc/auth.php) — centred column, oversized
   ghosted status code, a couple of ways back. */
.notfound { text-align: center; max-width: 460px; margin: 0 auto; padding: 72px 20px 60px; }
.notfound-code {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: clamp(64px, 14vw, 108px); font-weight: 700; line-height: 1;
  letter-spacing: -0.04em; color: var(--accent); opacity: 0.16; margin-bottom: 4px;
}
.notfound h2 { font-size: clamp(22px, 3.5vw, 30px); margin: 0 0 8px; letter-spacing: -0.015em; }
.notfound .section-sub { margin: 0 auto 24px; }
.notfound-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.notfound-actions .btn-run { display: inline-flex; }

.studio-search { display: flex; gap: 8px; margin-bottom: 18px; }
.studio-search input[type="search"] {
  font: inherit; color: var(--text);
  background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 8px;
  padding: 8px 12px; flex: 1;
}
.studio-search input[type="search"]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

/* complexity tags — catalogue filter buttons, card chips, and form checkboxes */
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tag-btn {
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--muted); background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 13px; text-decoration: none; cursor: pointer;
}
.tag-btn:hover { border-color: var(--accent); color: var(--text); }
.tag-btn.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
/* On the course head the chips sit just under the description, so tighten its
   gap (the general .section-sub margin is roomier for other pages) */
.page-head > .section-sub { margin-bottom: 12px; }
.tag-chip {
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: 999px; padding: 2px 9px;
}
.tag-field { border: 0; padding: 0; margin: 0; }
.tag-field > span { display: block; margin-bottom: 8px; }
.tag-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px 12px; }
/* radios & checkboxes as selectable cards: the whole label is the target,
   the checked one lights up in the accent */
.tag-check {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); cursor: pointer;
  font-weight: 400; font-size: 13px; line-height: 1.45; color: var(--muted);
}
.tag-check:hover { border-color: var(--accent); }
/* .field input's width:100% must not stretch the tick itself */
.std-form .tag-check input, .tag-check input { width: 15px; height: 15px; flex: none; margin: 2px 0 0; accent-color: var(--accent); cursor: pointer; }
.tag-check:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  color: var(--text);
}
.tag-check b { color: var(--text); font-weight: 650; }

/* course visibility badge — studio list + workspace */
.status-chip {
  display: inline-block; vertical-align: middle;
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  border-radius: 999px; padding: 2px 9px; border: 1px solid var(--border);
  color: var(--muted); background: var(--bg);
}
.status-chip.status-draft { color: var(--fail); border-color: var(--fail); }
.status-chip.status-unlisted { color: var(--accent); border-color: var(--accent); }
.status-chip.status-published { color: var(--accent); border-color: var(--accent); }

/* topic scheduling — unlock/due chips and locked topics (organisation courses) */
.sched-chip {
  display: inline-block; vertical-align: middle; align-self: center;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
  color: var(--muted); background: var(--bg); white-space: nowrap;
}
.sched-chip.sched-late { color: var(--fail); border-color: var(--fail); }
.topic-locked { opacity: 0.55; }

/* the organisation hub (/organisation/) */
.org-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.org-sub { margin: 22px 0 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

/* roster / members / marks tables (organisation pages) */
.roster-table-wrap { overflow-x: auto; }
.roster-table { border-collapse: collapse; font-size: 13.5px; width: 100%; min-width: 480px; }
.roster-table td:last-child, .roster-table th:last-child { padding-right: 0; }
.roster-table th, .roster-table td {
  text-align: left; padding: 7px 14px 7px 0;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.roster-table th { font-size: 11.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.roster-table .meta { color: var(--muted); font-weight: 400; }

/* the reports grid: roster × challenges */
.marks-table th.ch-col, .marks-table td.mark { text-align: center; padding: 7px 8px; min-width: 34px; }
.marks-table th.topic-col { border-left: 1px solid var(--border); padding-left: 10px; }
.marks-table td.m-done { color: var(--accent); font-weight: 700; }
.marks-table td.m-part { color: var(--text); }
.marks-table td.m-none { color: var(--muted); }
.marks-table td.m-late { color: var(--fail); font-weight: 600; }
.marks-table .health-row td { border-bottom: 0; font-size: 11.5px; line-height: 1.5; }
.m-late-key { color: var(--fail); font-weight: 600; }

/* drill-in: one student's graded runs */
.attempt-list { display: grid; gap: 8px; max-width: 760px; }
.attempt { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.attempt summary {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 14px; cursor: pointer; list-style: none;
}
.attempt summary::-webkit-details-marker { display: none; }
.attempt[open] summary { border-bottom: 1px solid var(--border); }
.attempt-score { font-weight: 700; min-width: 46px; }
.attempt-score.is-done { color: var(--accent); }
.attempt-title { font-weight: 600; flex: 1; }
.attempt-code { margin: 0; padding: 12px 14px; font-size: 12.5px; overflow-x: auto; white-space: pre; }

/* forms span the content width: short fields pair up two per row, while
   textareas, choice groups and the action row take the full line */
.std-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 28px; }
.std-form > .field:has(textarea), .std-form > .field-wide, .std-form > .tag-field, .std-form > .check-field, .std-form > .form-actions { grid-column: 1 / -1; }
.field-row { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 28px; }
.field-row[hidden] { display: none; }
@media (max-width: 720px) {
  .std-form, .field-row { grid-template-columns: 1fr; }
}
.field { display: grid; gap: 6px; font-size: 13.5px; font-weight: 550; }
.field small { color: var(--muted); font-weight: 400; }
.field input, .field select, .field textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--field-bg); border: 1px solid var(--field-border); border-radius: 8px;
  padding: 9px 11px; width: 100%;
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--muted); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent);
}
.check-field { display: flex; align-items: center; gap: 10px; font-weight: 450; }
.check-field input { width: auto; accent-color: var(--accent); }
/* Tabbed forms (e.g. the studio course settings: Details / Teachers / Class code) */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; color: var(--muted);
  border-radius: 8px 8px 0 0;
}
.tab-btn:hover { color: var(--text); background: var(--accent-soft); }
.tab-btn[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel[hidden] { display: none; }
.join-code { font-size: 1.7em; letter-spacing: 3px; margin: 4px 0 16px; }

/* positive actions (save / add / cancel) sit right; destructive ones left */
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.form-actions .btn-danger { order: -1; margin-right: auto; }
.btn-danger { color: var(--fail); }
.btn-danger:hover { border-color: var(--fail); }
/* Solid destructive-confirm button, for modal actions */
.btn-danger-solid { background: var(--fail); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); }

/* ── Modal dialog (native <dialog>) ── */
.modal { border: none; padding: 0; background: transparent; color: var(--text); }
.modal::backdrop { background: rgba(0, 0, 0, 0.5); }
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 22px 22px 18px; width: 420px; max-width: 92vw; margin: 0;
}
.modal-title { margin: 0 0 8px; font-size: 18px; }
.modal-body { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* 100% completion notice — a modal over everything, because on mobile the
   results panel is behind a tab the student isn't on when a run finishes */
.done-modal:not([open]) { display: none; } /* belt and braces where <dialog> isn't native */
.done-card { border-color: var(--pass); text-align: center; }
.done-mark {
  width: 42px; height: 42px; margin: 0 auto 12px; border-radius: 50%;
  background: var(--accent-soft); color: var(--pass);
  font-size: 22px; font-weight: 700; line-height: 42px;
}
.done-title { color: var(--pass); }
.done-actions { justify-content: center; flex-wrap: wrap; }
.done-actions .btn-run { text-decoration: none; }

/* ── Walkthrough (/tutorial) ── */
.tut-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tut-panel { display: flex; flex-direction: column; }
.tut-code { padding: 16px 18px; font-size: 14px; line-height: 2.1; background: var(--editor-bg); }
.tut-cline { color: var(--muted); white-space: pre; }
#tutCodeLine { color: var(--text); }
.tut-slot {
  width: 3.4em; text-align: center; font: inherit;
  background: var(--accent-soft); color: var(--text);
  border: 1px solid var(--accent); border-radius: 6px; padding: 1px 4px;
}
.tut-slot:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.tut-hint { margin: 0; padding: 10px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.tut-stage { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; padding: 18px; }
.tut-vp { margin: 0; text-align: center; }
.tut-vp .screen { background: var(--editor-bg); border: 1px solid var(--border); border-radius: 12px; padding: 10px; box-shadow: var(--shadow); display: inline-block; }
.tut-vp canvas { display: block; border-radius: 5px; width: 220px; height: 220px; max-width: 100%; }
.tut-vp .cap { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.tut-score { text-align: center; padding: 0 18px 16px; color: var(--muted); font-size: 13.5px; }
.tut-score-num { font-size: 22px; font-weight: 700; color: var(--fail); }
.tut-score-num.is-done { color: var(--pass); }
/* Spotlight overlay: dim everything but the element that needs action. The
   overlay is click-through (pointer-events:none) so the learner can still type
   and press Run; only the tooltip takes clicks. */
.tut-overlay { position: fixed; inset: 0; z-index: 1000; pointer-events: none; }
.tut-spot {
  position: fixed; border-radius: 8px; pointer-events: none;
  /* a light dim — the learner should still see the animation playing behind it */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4); outline: 2px solid var(--accent);
  transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
}
.tut-tip {
  position: fixed; z-index: 1001; width: 300px; max-width: 92vw; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 16px 16px 12px;
}
.tut-title { margin: 0 0 6px; font-size: 16px; }
.tut-body { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.tut-nav { display: flex; justify-content: flex-end; }

/* "Try the walkthrough" CTA: accent-framed and gently pulsing so it reads as a
   real invitation next to the solid green "Start the course" button */
.tut-cta {
  color: var(--accent); border-color: var(--accent); background: var(--accent-soft);
  font-weight: 600; animation: tut-pulse 2.4s ease-in-out infinite;
}
.tut-cta:hover { filter: brightness(1.08); }
@keyframes tut-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(124, 180, 66, 0.45); }
  70%  { box-shadow: 0 0 0 12px rgba(124, 180, 66, 0); }
  100% { box-shadow: 0 0 0 0 rgba(124, 180, 66, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .tut-spot { transition: none; }
  .tut-cta { animation: none; }
}
@media (max-width: 820px) { .tut-grid { grid-template-columns: 1fr; } }
.form-error {
  background: var(--fail-soft); color: var(--fail); border: 1px solid var(--fail);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; max-width: 720px;
}
.form-ok {
  background: var(--accent-soft); color: var(--pass); border: 1px solid var(--pass);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 550;
}

.studio-main { max-width: 1280px; margin: 0 auto; padding: 16px 20px 40px; }
.studio-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(280px, 5fr); gap: 16px; align-items: start; }
.studio-left { display: grid; gap: 16px; }
.studio .panel-body { padding: 14px 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .span2 { grid-column: span 2; }
.wgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.wgrid-head { margin: 14px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.wgrid-head small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.wfield { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.wfield input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; width: 100%;
}
.ev-row {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13px;
}
.ev-row select, .ev-row input {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 4px 8px;
}
.ev-row input[type="number"] { width: 62px; }
.ev-row input.ev-key { width: 110px; }
.ev-row label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); white-space: nowrap; }
.ev-row .ev-p[hidden] { display: none; }
.ev-label { color: var(--muted); flex: 1; min-width: 200px; }
.ev-w { margin-left: auto; }
.ev-del { line-height: 1; padding: 3px 8px; }
.ev-actions { padding-top: 10px; }

.studio .editor-host .CodeMirror { height: 300px; font-size: 13px; line-height: 1.6; }
.studio .editor-host-short .CodeMirror { height: 200px; }
.kbar-author { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.starter-help { padding: 8px 14px 10px; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--border); }
.studio-right { position: sticky; top: 66px; }
.preview-body { padding: 14px 16px; display: grid; gap: 10px; }
.preview-body .screen {
  background: var(--editor-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px;
}
.preview-body canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 5px; }
.preview-body .score-num { font-size: 30px; }
.preview-body .score-num small { font-size: 17px; }
.preview-body .error-msg { padding: 0; }
@media (max-width: 980px) {
  .studio-grid { grid-template-columns: 1fr; }
  .studio-right { position: static; order: -1; }
}

/* ── Reference panel: a drawer over the right edge; full-width on phones ── */
.refpanel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 20;
  width: min(400px, 100%);
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column;
}
.refpanel[hidden] { display: none; }
.ref-head {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.ref-title { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
#refSearch {
  flex: 1; min-width: 0; font: inherit; font-size: 13.5px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px;
}
#refSearch:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.ref-body { flex: 1; overflow-y: auto; padding: 6px 14px 20px; }
.ref-group {
  margin: 16px 0 2px; font-size: 12px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent);
}
.ref-note { font-size: 12.5px; color: var(--muted); margin: 4px 0 6px; }
.ref-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; border-radius: 8px;
  padding: 7px 8px; margin: 0 -8px;
}
.ref-item:hover { background: var(--accent-soft); }
.ref-sig { display: block; font-size: 13px; color: var(--text); }
.ref-desc { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }

/* The lesson drawer shares .refpanel's frame; only the prose differs. Set for
   reading rather than scanning: longer measure, looser lines. */
.lesson-topic {
  flex: 1; min-width: 0; font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lesson-text {
  font-size: 14.5px; line-height: 1.65; color: var(--text);
  padding-top: 14px; max-width: 62ch;
}

/* ── Read aloud ──
   The button and the clickable words are injected by js/speak.js, and only on
   a machine that actually has voices — so none of this is ever an affordance
   that does nothing. */
.say-group { display: inline-flex; gap: 4px; align-items: center; }
.say-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  background: none; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted);
}
.say-cog { width: 20px; }
.say-btn:hover { color: var(--text); border-color: var(--muted); }
.say-btn[aria-pressed="true"] {
  color: var(--accent); border-color: var(--accent); background: var(--accent-soft);
}
/* Every word is its own target. The tint is the only hint that it is — a
   permanent underline across a whole lesson would read as a page of links. */
.say-words .say-w { cursor: pointer; border-radius: 3px; }
.say-words .say-w:hover { background: var(--accent-soft); }
/* the word being spoken, tracked from the utterance's boundary events */
.say-words .say-w.say-on {
  background: var(--accent-soft); box-shadow: 0 1px 0 var(--accent);
}

/* Hosts for the injected button, where it can't simply be prepended. */
.task { position: relative; }
.task-tools { position: absolute; top: 12px; right: 14px; }
.hints-tools { margin-left: auto; display: flex; }
.hints-tools[hidden] { display: none; }
.ref-tools { display: flex; }
/* on the course page the buttons have no head to sit in, so they float out of
   the first line of the lesson rather than shunting the text sideways */
.lesson-body > .say-group:first-child { float: right; margin: 0 0 6px 10px; }

/* Voice and speed, chosen once per machine and remembered. Positioned in JS,
   under whichever button opened it. */
.say-menu {
  position: absolute; z-index: 60; width: 260px; padding: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.28); font-size: 13px;
}
.say-menu[hidden] { display: none; }
.say-menu-row {
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 10px; color: var(--muted);
}
.say-menu select, .say-menu input[type="range"] { width: 100%; font: inherit; }
.say-menu select {
  color: var(--text); background: var(--field-bg);
  border: 1px solid var(--field-border); border-radius: 8px; padding: 5px 6px;
}
.say-menu input[type="range"] { accent-color: var(--accent); }
.say-test {
  width: 100%; background: none; border: 1px solid var(--border);
  border-radius: 8px; padding: 5px; color: var(--muted); font-size: 12.5px;
}
.say-test:hover { color: var(--text); border-color: var(--muted); }
@media (max-width: 900px) {
  .task-tools { top: 10px; right: 12px; }
}

/* ── Accounts ── */
.account-link { white-space: nowrap; }
.account-name { display: inline-block; max-width: 130px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

/* Account dropdown — a native <details> disclosure in the top bar */
.account-menu { position: relative; }
.account-menu > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu > summary .caret { font-size: 10px; color: var(--muted); transition: transform 0.15s ease; }
.account-menu[open] > summary { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.account-menu[open] > summary .caret { transform: rotate(180deg); color: var(--accent); }
.account-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  display: flex; flex-direction: column; min-width: 190px; padding: 6px; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
}
.account-dropdown a, .account-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border-radius: 7px; border: none; background: none;
  color: var(--text); text-decoration: none; font: inherit; font-size: 13.5px; cursor: pointer;
}
.account-dropdown a:hover, .account-dropdown button:hover { background: var(--accent-soft); color: var(--accent); }
.account-dropdown form { margin: 0; }
.account-dropdown .menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* the compact phone topbar keeps only Grid/Try/Run */
@media (max-width: 720px) {
  .challenge .account-menu, .challenge .account-link { display: none; }
}
.attempt-list { max-width: 640px; }
.attempt-row {
  display: flex; gap: 14px; align-items: baseline; padding: 8px 2px;
  border-bottom: 1px dashed var(--border);
  text-decoration: none; color: var(--text); font-size: 14px;
}
.attempt-row:hover .attempt-title { color: var(--accent); }
.attempt-score { min-width: 52px; font-weight: 650; color: var(--muted); font-variant-numeric: tabular-nums; }
.attempt-score.pass { color: var(--pass); }
.attempt-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attempt-when { font-size: 12px; color: var(--muted); }

.landing footer {
  border-top: 1px solid var(--border);
  padding: 20px; text-align: center;
  font-size: 13px; color: var(--muted);
}

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 32px; padding-top: 40px; }
  .steps { grid-template-columns: 1fr; }
}
