/* =============================================================================
   MTI Interactive Labs — design system

   Light palette is defined on bare :root. Dark redefines only the tokens, twice:
   once under prefers-color-scheme (guarded so an explicit light choice wins) and
   once under [data-theme="dark"] so the toggle beats the system in both
   directions. No colour is ever defined only inside a media query.
   ========================================================================== */

:root {
  /* neutrals ------------------------------------------------------------- */
  --bg:            #f6f6f8;
  --bg-sunken:     #ececed;
  --surface:       #ffffff;
  --surface-2:     #f4f4f6;
  --surface-glass: rgba(255, 255, 255, 0.72);
  --border:        #e0e0e4;
  --border-strong: #c8c8cf;

  --text:          #16161a;
  --text-2:        #55555f;
  --text-3:        #68686f;
  --text-invert:   #ffffff;
  /* Text drawn ON the accent fill. Light accents need dark text; this is what
     keeps a primary button legible when the palette flips. */
  --on-accent:     #ffffff;

  /* accents -------------------------------------------------------------- */
  --oop:           #c2410c;   /* C++ — warm */
  --oop-soft:      #fff1e8;
  --oop-line:      #f4c4a6;
  --dbms:          #1d4ed8;   /* SQL — cool */
  --dbms-soft:     #eaf0ff;
  --dbms-line:     #b6c9f5;

  --accent:        var(--oop);
  --accent-soft:   var(--oop-soft);
  --accent-line:   var(--oop-line);

  /* semantic ------------------------------------------------------------- */
  --ok:            #15803d;
  --ok-soft:       #e8f6ec;
  --warn:          #a16207;
  --warn-soft:     #fdf6e3;
  --err:           #b91c1c;
  --err-soft:      #fdeceb;
  --info:          #0369a1;
  --info-soft:     #e7f4fb;

  /* code ----------------------------------------------------------------- */
  --code-bg:       #1c1c21;
  --code-text:     #e6e6ea;
  --code-line:     #2b2b33;
  --code-gutter:   #6a6a77;
  --code-hl:       rgba(255, 214, 122, 0.13);

  /* shape and depth ------------------------------------------------------ */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --shadow-1: 0 1px 2px rgba(16, 16, 24, 0.05), 0 1px 3px rgba(16, 16, 24, 0.04);
  --shadow-2: 0 2px 6px rgba(16, 16, 24, 0.06), 0 8px 20px rgba(16, 16, 24, 0.07);
  --shadow-3: 0 8px 24px rgba(16, 16, 24, 0.10), 0 24px 56px rgba(16, 16, 24, 0.12);

  /* motion — critically damped by default; bounce is opt-in, and only where
     a gesture carried momentum (see --spring-bouncy). */
  --spring:        400ms cubic-bezier(0.32, 0.72, 0, 1);
  --spring-bouncy: 520ms cubic-bezier(0.18, 0.89, 0.32, 1.19);
  --quick:         140ms cubic-bezier(0.4, 0, 0.2, 1);

  --nav-h: 56px;
  --side-w: 268px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0e0e11;
    --bg-sunken:     #08080a;
    --surface:       #17171c;
    --surface-2:     #1f1f26;
    --surface-glass: rgba(23, 23, 28, 0.74);
    --border:        #2a2a33;
    --border-strong: #3d3d49;

    --text:          #f2f2f5;
    --text-2:        #a9a9b6;
    --text-3:        #8e8e99;
    --text-invert:   #0e0e11;
    --on-accent:     #0e0e11;

    --oop:           #fb923c;
    --oop-soft:      #2b1a10;
    --oop-line:      #5c3418;
    --dbms:          #7ba5fb;
    --dbms-soft:     #131c30;
    --dbms-line:     #2b3f68;

    --ok:            #4ade80;
    --ok-soft:       #10231a;
    --warn:          #fbbf24;
    --warn-soft:     #241d0c;
    --err:           #f87171;
    --err-soft:      #2a1414;
    --info:          #60c5f1;
    --info-soft:     #0d1f2a;

    --code-bg:       #0b0b0e;
    --code-text:     #e6e6ea;
    --code-line:     #1c1c22;
    --code-gutter:   #5b5b68;
    --code-hl:       rgba(255, 214, 122, 0.10);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.45), 0 10px 28px rgba(0, 0, 0, 0.35);
    --shadow-3: 0 10px 30px rgba(0, 0, 0, 0.55), 0 30px 70px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  --bg:            #0e0e11;
  --bg-sunken:     #08080a;
  --surface:       #17171c;
  --surface-2:     #1f1f26;
  --surface-glass: rgba(23, 23, 28, 0.74);
  --border:        #2a2a33;
  --border-strong: #3d3d49;

  --text:          #f2f2f5;
  --text-2:        #a9a9b6;
  --text-3:        #8e8e99;
  --text-invert:   #0e0e11;
  --on-accent:     #0e0e11;

  --oop:           #fb923c;
  --oop-soft:      #2b1a10;
  --oop-line:      #5c3418;
  --dbms:          #7ba5fb;
  --dbms-soft:     #131c30;
  --dbms-line:     #2b3f68;

  --ok:            #4ade80;
  --ok-soft:       #10231a;
  --warn:          #fbbf24;
  --warn-soft:     #241d0c;
  --err:           #f87171;
  --err-soft:      #2a1414;
  --info:          #60c5f1;
  --info-soft:     #0d1f2a;

  --code-bg:       #0b0b0e;
  --code-text:     #e6e6ea;
  --code-line:     #1c1c22;
  --code-gutter:   #5b5b68;
  --code-hl:       rgba(255, 214, 122, 0.10);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.45), 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-3: 0 10px 30px rgba(0, 0, 0, 0.55), 0 30px 70px rgba(0, 0, 0, 0.45);
}

/* course accent is swapped by a data attribute on <body> */
body[data-course="dbms2"] {
  --accent:      var(--dbms);
  --accent-soft: var(--dbms-soft);
  --accent-line: var(--dbms-line);
}

/* =========================== base =========================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Without this, native controls (the <select>, focus rings, scrollbars) stay
   light-themed in dark mode and their default text colour is near-black. */
:root { color-scheme: light; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Tracking is size-specific: large text reads too loose as it grows, small text
   too tight. One global letter-spacing would be wrong somewhere. */
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 640; line-height: 1.18; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); letter-spacing: -0.022em; line-height: 1.08; }
h2 { font-size: 1.32rem; letter-spacing: -0.014em; }
h3 { font-size: 1.06rem; letter-spacing: -0.008em; }
h4 { font-size: 0.95rem; letter-spacing: 0; }
p  { margin: 0 0 .85em; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.875em; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Inline code inside prose */
.prose code, .note code, .walkthrough code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.08em 0.34em;
  font-size: 0.86em;
  white-space: nowrap;
}

.prose strong { font-weight: 650; }

/* =========================== chrome =========================== */

.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  /* No hard rule. The separation appears only where content actually slides
     under the bar — a scroll edge effect rather than a permanent divider. */
  border-bottom: 1px solid transparent;
  transition: border-color 220ms ease-out, box-shadow 220ms ease-out;
}
.topbar.scrolled {
  border-bottom-color: var(--border);
  box-shadow: 0 1px 12px rgba(16, 16, 24, .05);
}
:root[data-theme="dark"] .topbar.scrolled,
:root:not([data-theme="light"]) .topbar.scrolled {
  box-shadow: 0 1px 14px rgba(0, 0, 0, .45);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 660; letter-spacing: -0.015em; color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  /* A solid colour under the gradient, not just the gradient: it is the
     fallback wherever gradients do not paint, and it is what a contrast
     checker can actually measure. Both stops clear AA against --on-accent. */
  background-color: var(--oop);
  background-image: linear-gradient(140deg, var(--oop), var(--dbms));
  /* Not #fff. In dark mode the accents are light, so white-on-accent falls to
     2.3:1; --on-accent is the token that pairs with them and gives 7.9:1. */
  color: var(--on-accent); font-size: 13px; font-weight: 700;
}

.topbar-spacer { flex: 1; }

.xp-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px;
  color: var(--text);
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px; font-weight: 560;
  cursor: pointer;
  transition: transform var(--quick), background var(--quick);
}
.xp-pill:hover { background: var(--surface); }
.xp-pill:active { transform: scale(0.97); }
.xp-pill .lvl {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  color: var(--on-accent); background: var(--accent);
  border-radius: 999px; padding: 2px 7px;
}
.xp-pill .streak { color: var(--warn); }

.icon-btn {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-2);
  cursor: pointer; font-size: 15px;
  transition: transform var(--quick), background var(--quick), color var(--quick);
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

/* =========================== layout =========================== */

.shell { display: flex; min-height: calc(100vh - var(--nav-h)); }

.sidebar {
  width: var(--side-w); flex: none;
  border-right: 1px solid var(--border);
  background: var(--bg-sunken);
  padding: 16px 10px 40px;
  position: sticky; top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.main { flex: 1; min-width: 0; padding: 26px 30px 80px; }
.wrap { max-width: 1080px; margin: 0 auto; }
.wrap-narrow { max-width: 760px; margin: 0 auto; }

.side-group { margin-bottom: 20px; }
.side-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 10px; margin-bottom: 6px;
}

.side-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; margin-bottom: 1px;
  border-radius: 8px;
  color: var(--text-2); font-size: 13.5px;
  cursor: pointer; position: relative;
  transition: background var(--quick), color var(--quick), transform 90ms ease-out;
}
.side-link:hover { background: var(--surface); color: var(--text); text-decoration: none; }
/* Feedback belongs on the press, not the release — without this the sidebar is
   the one navigation surface in the app that feels dead to the touch. */
.side-link:active { background: var(--accent-soft); transform: scale(0.985); }
.side-link[aria-current="page"] {
  background: var(--accent-soft); color: var(--accent); font-weight: 590;
}
.side-link .dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--border-strong);
}
.side-link .dot.run  { background: var(--ok); }
.side-link .dot.open { background: var(--warn); }
.side-link .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* =========================== cards =========================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 18px 20px; }

.lab-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
}

.lab-card {
  display: flex; flex-direction: column; gap: 9px;
  padding: 16px 17px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  cursor: pointer; color: inherit;
  transition: transform var(--spring), box-shadow var(--spring), border-color var(--quick);
}
.lab-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--border-strong);
  text-decoration: none;
}
.lab-card:active { transform: translateY(0) scale(0.993); }

/* A card title is an h2 for document structure, but visually it is a card
   title — size and tracking come from the role, not the tag. */
.lab-card h2 { margin: 0; font-size: 1rem; letter-spacing: -0.008em; }
.lab-card .blurb { color: var(--text-2); font-size: 13.2px; line-height: 1.5; flex: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11px; font-weight: 550;
  padding: 2px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
}
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }

.meta-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--text-3);
}

/* progress ring */
.ring { width: 26px; height: 26px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.4; }
.ring .track { stroke: var(--border); }
.ring .value {
  stroke: var(--accent); stroke-linecap: round;
  transition: stroke-dashoffset var(--spring);
}

/* =========================== buttons =========================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 13.5px; font-weight: 560;
  cursor: pointer; white-space: nowrap;
  /* Feedback lands on pointer-down, not on release. */
  transition: transform 100ms ease-out, background var(--quick), border-color var(--quick), opacity var(--quick);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent); border-color: transparent; color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-lg { height: 40px; padding: 0 18px; font-size: 14.5px; border-radius: 11px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* =========================== tabs =========================== */

.tabs {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; width: fit-content; max-width: 100%;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 5px 12px; border-radius: 7px; border: none; background: transparent;
  color: var(--text-2); font-family: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: transform 100ms ease-out, background var(--quick), color var(--quick);
}
.tab:hover { color: var(--text); }
/* Feedback on pointer-down, matching .btn and .side-link. Without it a tab is
   the only control here that gives nothing back until the pane swaps. */
.tab:active { transform: scale(0.97); }
.tab[aria-selected="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-1);
}

/* =========================== code =========================== */

.code-shell {
  background: var(--code-bg); color: var(--code-text);
  border-radius: var(--r); overflow: hidden;
  border: 1px solid var(--code-line);
}
.code-head {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  background: rgba(255,255,255,.03);
  border-bottom: 1px solid var(--code-line);
  font-size: 11.5px; color: var(--code-gutter);
  font-family: var(--mono);
}
.code-head .name { color: #c9c9d4; }
.code-head .spacer { flex: 1; }

/* The header sits on the dark code surface, so its buttons need the inverse
   palette — the page tokens would put dark text on a dark ground. */
.code-head .btn {
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .14);
  color: #d7d7e0;
}
.code-head .btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.code-head .btn-ghost { background: transparent; border-color: transparent; color: #9c9caa; }
.code-head .btn-ghost:hover { background: rgba(255, 255, 255, .09); color: #fff; }

.code-body { max-height: 62vh; overflow: auto; }

pre.code {
  margin: 0; padding: 12px 0;
  font-family: var(--mono); font-size: 12.6px; line-height: 1.62;
  tab-size: 4;
}
/* Simulators render a pre.code on its own rather than inside .code-body, which
   is the element that normally does the scrolling. Standalone blocks have to
   carry their own, or a long line pushes the whole page sideways on a phone. */
pre.code.code-block {
  overflow-x: auto;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--code-line);
  border-radius: var(--r-sm);
  background: var(--code-bg);
  color: var(--code-text);
}

pre.code .ln {
  display: block; padding: 0 14px 0 0; white-space: pre;
}
pre.code .ln::before {
  content: attr(data-n);
  display: inline-block; width: 3.2em; margin-right: 14px;
  padding-right: 8px; text-align: right;
  color: var(--code-gutter); user-select: none;
  border-right: 1px solid var(--code-line);
}
pre.code .ln.hl { background: var(--code-hl); }
pre.code .ln.note-anchor { cursor: pointer; }
pre.code .ln.note-anchor:hover { background: rgba(255,255,255,.05); }

/* minimal C++/SQL tokens, applied by app/ui/highlight.js */
.tok-key   { color: #ff9ec4; }
.tok-type  { color: #7fd6ff; }
.tok-str   { color: #b7e88a; }
.tok-num   { color: #ffd67a; }
.tok-com   { color: #8b8b9e; font-style: italic; }
.tok-pre   { color: #c9a6ff; }
.tok-fn    { color: #ffd67a; }

/* CodeMirror sits inside .code-shell, which already supplies the frame. */
.code-shell .CodeMirror {
  border: 0;
  border-radius: 0;
  background: var(--code-bg);
}

/* =========================== console =========================== */

.console {
  background: var(--code-bg); color: var(--code-text);
  border: 1px solid var(--code-line); border-radius: var(--r);
  font-family: var(--mono); font-size: 12.6px; line-height: 1.6;
  padding: 12px 14px;
  min-height: 90px; max-height: 44vh; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
.console:empty::before {
  content: "Output appears here once you press Run.";
  color: var(--code-gutter); font-style: italic;
}
.console .err { color: #ff9b9b; }
.console .ok  { color: #8ee6a8; }
.console .dim { color: var(--code-gutter); }

.stdin-box {
  width: 100%; min-height: 60px; resize: vertical;
  font-family: var(--mono); font-size: 12.6px; line-height: 1.55;
  padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text);
}

/* =========================== notes and callouts =========================== */

.note {
  border-radius: var(--r); padding: 11px 13px;
  font-size: 13.2px; line-height: 1.55;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2);
}
.note + .note { margin-top: 7px; }
.note strong, .note b { color: var(--text); }
.note-info  { background: var(--info-soft);  border-color: color-mix(in srgb, var(--info) 26%, transparent); }
.note-warn  { background: var(--warn-soft);  border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.note-ok    { background: var(--ok-soft);    border-color: color-mix(in srgb, var(--ok)   30%, transparent); }
.note-err   { background: var(--err-soft);   border-color: color-mix(in srgb, var(--err)  30%, transparent); }

.note-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 620; font-size: 12px; letter-spacing: .02em;
  text-transform: uppercase; margin-bottom: 4px;
  color: var(--text-3);
}

/* =========================== tables =========================== */

.table-scroll { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); }

table.grid {
  border-collapse: collapse; width: 100%;
  font-size: 12.8px; font-family: var(--mono);
  background: var(--surface);
}
table.grid th, table.grid td {
  padding: 6px 11px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
table.grid th {
  background: var(--surface-2); color: var(--text-2);
  font-weight: 620; font-size: 11.5px; letter-spacing: .02em;
  position: sticky; top: 0; z-index: 1;
}
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid td.null { color: var(--text-3); font-style: italic; }
table.grid td.num { text-align: right; }

/* rows highlighted by the pipeline lesson */
table.grid tr.dropped td { opacity: .3; text-decoration: line-through; }
table.grid tr.kept td { background: var(--ok-soft); }

/* =========================== challenges =========================== */

.challenge {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); overflow: hidden;
}
.challenge + .challenge { margin-top: 12px; }
.challenge.solved { border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }

.challenge-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; cursor: pointer;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.challenge-head .kind {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent);
}
.challenge-head .xp {
  font-size: 11.5px; font-weight: 620; color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.challenge-head .status { font-size: 15px; }
.challenge-body { padding: 15px 16px; }

.opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface); cursor: pointer; font-size: 13.6px; line-height: 1.5;
  transition: transform 100ms ease-out, border-color var(--quick), background var(--quick);
  text-align: left; width: 100%; font-family: inherit; color: inherit;
}
.opt:hover { border-color: var(--border-strong); background: var(--surface-2); }
.opt:active { transform: scale(0.995); }
.opt .mark {
  width: 19px; height: 19px; flex: none; margin-top: 1px;
  border-radius: 50%; border: 1.6px solid var(--border-strong);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  color: var(--text-3);
}
.opt.chosen { border-color: var(--accent); background: var(--accent-soft); }
.opt.chosen .mark { border-color: var(--accent); background: var(--accent); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .mark { border-color: var(--ok); background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--err); background: var(--err-soft); }
.opt.wrong .mark { border-color: var(--err); background: var(--err); color: #fff; }
.opt:disabled { cursor: default; }

.answer-input {
  width: 100%; height: 36px; padding: 0 11px;
  font-family: var(--mono); font-size: 13.5px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
}

/* =========================== badges =========================== */

.badge-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px 10px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface);
}
.badge .icon { font-size: 26px; line-height: 1; }
.badge .name { font-size: 12.5px; font-weight: 620; }
.badge .hint { font-size: 11px; color: var(--text-3); line-height: 1.4; }
.badge.locked { opacity: .5; }
.badge.locked .icon { filter: grayscale(1); }
.badge.earned { border-color: var(--accent-line); background: var(--accent-soft); }

/* =========================== toasts =========================== */

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none; max-width: min(340px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px;
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow-3);
  font-size: 13.4px;
  pointer-events: auto;
  /* Materialise rather than fade: blur and scale together read as a real
     surface arriving. */
  animation: toast-in var(--spring-bouncy) both;
}
.toast.leaving { animation: toast-out 220ms cubic-bezier(0.4, 0, 1, 1) both; }
.toast .icon { font-size: 20px; line-height: 1; flex: none; }
.toast .title { font-weight: 620; }
.toast .sub { color: var(--text-2); font-size: 12.2px; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px) scale(.97); }
}

/* =========================== modal =========================== */

.scrim {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(8, 8, 12, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  animation: fade-in 180ms ease-out both;
}
.modal {
  /* transform-origin is set per-instance from the trigger's position, so the
     panel grows out of the control that summoned it rather than from nowhere. */
  transform-origin: center center;
  width: min(560px, 100%); max-height: 86vh; overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: 22px 24px;
  animation: modal-in var(--spring) both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* =========================== progress bars =========================== */

.bar {
  height: 7px; border-radius: 999px; overflow: hidden;
  background: var(--border);
}
.bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--accent);
  transition: width var(--spring);
}
.bar.thick { height: 10px; }

/* =========================== misc =========================== */

.stack   { display: flex; flex-direction: column; }
.gap-4   { gap: 4px; }  .gap-6 { gap: 6px; }   .gap-8  { gap: 8px; }
.gap-10  { gap: 10px; } .gap-14 { gap: 14px; } .gap-20 { gap: 20px; } .gap-28 { gap: 28px; }
.row     { display: flex; align-items: center; }
.between { justify-content: space-between; }
.wrapx   { flex-wrap: wrap; }
.muted   { color: var(--text-2); }
.dim     { color: var(--text-3); }
.small   { font-size: 12.5px; }
.tnum    { font-variant-numeric: tabular-nums; }
.hr      { height: 1px; background: var(--border); border: 0; margin: 18px 0; }
.hidden  { display: none !important; }

.section-title {
  display: flex; align-items: center; gap: 9px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
  margin: 26px 0 10px;
}
.section-title::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* For headings that quote SQL: shouting a statement back at the reader makes it
   harder to recognise, not easier. */
.section-title.plain {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12.5px;
  font-family: var(--mono);
  color: var(--text-2);
}

.split {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 640ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================== responsive =========================== */

.menu-btn { display: none; }
.drawer-scrim { display: none; }

/* ── touch sizing ──────────────────────────────────────────────────────────
   Apple's 44pt minimum. Rather than inflating every control visually — which
   would wreck the density this UI depends on — controls grow moderately and
   the *hit area* is extended past the paint with a transparent ::after. The
   button still looks 28px tall; the finger gets 44.
   Applied by pointer capability, not width, so a touch laptop benefits too. */
@media (pointer: coarse), (max-width: 900px) {
  .btn { height: 44px; padding: 0 16px; }
  .btn-lg { height: 46px; }
  .btn-sm { height: 34px; padding: 0 12px; }
  .icon-btn { width: 42px; height: 42px; }
  .xp-pill { height: 40px; padding: 0 14px; }
  .tab { padding: 9px 15px; }
  .side-link { padding: 12px; min-height: 44px; }
  .brand { min-height: 44px; }
  .opt { padding: 13px 14px; }
  .answer-input { height: 44px; }

  /* Anything still under 44 gets the invisible margin. */
  .btn-sm, button.chip, .icon-btn, button.tab, .xp-pill {
    position: relative;
  }
  .btn-sm::after, button.chip::after, .icon-btn::after,
  button.tab::after, .xp-pill::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    min-width: 44px; min-height: 44px;
    width: 100%; height: 100%;
  }
  /* Chips are laid out tightly; the expanded areas must not overlap or the
     wrong one wins the tap. */
  .chip-row { gap: 10px 8px; }
  button.chip { padding: 6px 11px; }

  /* Inline links inside a sentence keep their painted size — padding them
     would break the line — but the finger still gets 44px, via the same
     transparent ::after used above. Height only, so two links on one line
     cannot fight over a tap. */
  .prose a:not(.btn), .note a:not(.btn) {
    position: relative;
  }
  .prose a:not(.btn)::after, .note a:not(.btn)::after {
    content: "";
    position: absolute;
    top: 50%; left: 0;
    transform: translateY(-50%);
    width: 100%; height: 100%;
    min-height: 44px;
  }

  /* Links in a table cell are the only way out of the progress table, so they
     need a real target. */
  table.grid td a {
    display: inline-block;
    padding: 12px 0;
    min-height: 44px;
  }
}

@media (max-width: 900px) {
  .menu-btn { display: grid; }
  .drawer-scrim { display: block; }
  .sidebar {
    position: fixed; top: var(--nav-h); left: 0; z-index: 70;
    box-shadow: var(--shadow-3);
    width: min(300px, 84vw);
    /* Position comes from app/ui/drawer.js, one frame at a time. A CSS
       transition here would fight the gesture and could not be grabbed
       mid-flight. */
    will-change: transform;
    touch-action: pan-y;
  }
  .drawer-scrim {
    position: fixed; inset: var(--nav-h) 0 0 0; z-index: 65;
    background: rgba(8, 8, 12, .36);
    opacity: 0; pointer-events: none;
  }
  /* While a finger is down, text selection and scroll chaining get in the way. */
  body.drawer-dragging { user-select: none; -webkit-user-select: none; }
  body.drawer-dragging .sidebar { cursor: grabbing; }
  .main { padding: 20px 16px 70px; }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .main { padding: 16px 12px 60px; }
  .lab-grid { grid-template-columns: 1fr; }
  .xp-pill .xp-text { display: none; }
  .badge-grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }
}

/* =========================== accessibility =========================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 120ms !important;
    scroll-behavior: auto !important;
  }
  /* Reduced motion means a gentler equivalent, not no feedback: opacity and
     colour changes stay, movement goes. */
  .lab-card:hover, .btn:active, .opt:active, .xp-pill:active, .icon-btn:active,
  .tab:active, .side-link:active {
    transform: none !important;
  }
  .toast { animation: fade-in 140ms ease-out both; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar, .toast { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .scrim { backdrop-filter: none; -webkit-backdrop-filter: none; }
}

@media (prefers-contrast: more) {
  :root { --border: var(--border-strong); }
  .card, .lab-card, .challenge, .note { border-width: 1.5px; }
}

@media print {
  .topbar, .sidebar, .toasts, .btn-row { display: none !important; }
  .main { padding: 0; }
}
