:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e2e5ee;
  --border-strong: #cdd2e0;
  --text: #141726;
  --muted: #586075;
  --faint: #8a90a3;
  --accent: #5048e5;
  --accent-bg: #ecebff;
  --accent-border: #c5c1ff;
  --ok: #10855a;
  --ok-bg: #e2f5eb;
  --ok-border: #9fdcbf;
  --bad: #c93636;
  --bad-bg: #fde9e9;
  --bad-border: #f1b5b5;
  --t-kw: #b02a86;
  --t-str: #237a37;
  --t-num: #b45f00;
  --t-fn: #2563c9;
  --t-com: #8a90a3;
  --t-op: #586075;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme="dark"] {
    --bg: #0c0e16;
    --surface: #141724;
    --surface-2: #1b1f30;
    --border: #262a3d;
    --border-strong: #353a52;
    --text: #e9ebf4;
    --muted: #a3a9bd;
    --faint: #6d7389;
    --accent: #8e88ff;
    --accent-bg: #222048;
    --accent-border: #3f3a85;
    --ok: #4fd69a;
    --ok-bg: #0f2e20;
    --ok-border: #1f6a46;
    --bad: #ff7b7b;
    --bad-bg: #371416;
    --bad-border: #7a2b2e;
    --t-kw: #ff7ccc;
    --t-str: #8fe39a;
    --t-num: #ffb86b;
    --t-fn: #7fb6ff;
    --t-com: #6d7389;
    --t-op: #a3a9bd;
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
code, .ln, .box, .cell, .console, .tok, .eq, .cond, .vname, .ptr { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.6; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.92em; background: var(--accent-bg); color: var(--accent); padding: 1px 6px; border-radius: 6px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- top bar ---------- */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar .wrap, .topbar .wide { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.logo svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.crumb { color: var(--muted); font-size: 14px; display: flex; gap: 8px; align-items: center; min-width: 0; }
.crumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- player ---------- */
.player { --line-h: 34px; }
.stage { position: relative; perspective: 1400px; }
.world { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; transform-style: preserve-3d; }
.pane { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 0 14px; position: relative; min-width: 0; }
.pane-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-size: 13px; color: var(--muted); }
.pane-h-out { padding-top: 6px; }
.pane-t { font-weight: 600; color: var(--text); }
.pane-h .hint { color: var(--faint); }
.pill { margin-left: auto; font-size: 12px; padding: 2px 10px; border-radius: 99px; background: var(--accent-bg); color: var(--accent); }
.lights { display: flex; gap: 6px; }
.lights i { width: 10px; height: 10px; border-radius: 50%; background: var(--border-strong); }

.code { position: relative; margin: 0 12px; padding: 4px 0; }
.ln { position: relative; display: flex; gap: 14px; height: var(--line-h); line-height: var(--line-h); padding: 0 10px; font-family: var(--mono); font-size: 15px; white-space: pre; transition: color 0.3s, opacity 0.3s; }
.ln .no { width: 18px; flex: none; text-align: right; color: var(--faint); user-select: none; }
.ln .src { position: relative; }
.c { display: inline-block; white-space: pre; }
.t-kw { color: var(--t-kw); } .t-str { color: var(--t-str); } .t-num { color: var(--t-num); }
.t-fn { color: var(--t-fn); } .t-com { color: var(--t-com); font-style: italic; } .t-op { color: var(--t-op); }
.ln.on .no { color: var(--accent); font-weight: 700; }
.ln.skip { opacity: 0.38; text-decoration: line-through; text-decoration-color: var(--bad); }
.bar { position: absolute; left: 0; right: 0; top: 0; height: var(--line-h); border-radius: 8px; background: var(--accent-bg); border: 1px solid var(--accent-border); opacity: 0; transform-origin: 50% 0; transition: background 0.3s, border-color 0.3s; }
.bar::before { content: ""; position: absolute; left: -7px; top: 50%; margin-top: -6px; border: 6px solid transparent; border-left-color: var(--accent); }
.bar.is-true { background: var(--ok-bg); border-color: var(--ok-border); }
.bar.is-true::before { border-left-color: var(--ok); }
.bar.is-false { background: var(--bad-bg); border-color: var(--bad-border); }
.bar.is-false::before { border-left-color: var(--bad); }
.reader { position: absolute; width: 7px; height: 7px; margin-left: -3px; border-radius: 50%; background: var(--accent); opacity: 0; }
.jump { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.jp, .jh { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.jt { fill: var(--accent); font: 600 11px var(--font); opacity: 0; paint-order: stroke; stroke: var(--surface, #fff); stroke-width: 4px; stroke-linejoin: round; }

.mem { position: relative; padding: 4px 16px 6px; min-height: 120px; perspective: 600px; }
.empty { color: var(--faint); font-size: 14px; margin: 10px 0; }
.row { display: flex; align-items: flex-start; gap: 12px; margin: 0 0 12px; transform-origin: 50% 0; }
.vname { font-family: var(--mono); font-size: 14px; width: 58px; flex: none; display: flex; flex-direction: column; justify-content: center; min-height: 42px; line-height: 1.25; overflow: hidden; }
.vname span { overflow: hidden; text-overflow: ellipsis; }
.vname small { font-size: 11px; color: var(--faint); }
.vbody { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.addr { font: 11px var(--mono); color: var(--faint); padding-left: 2px; }
.box.is-ptr { border-style: dashed; border-color: var(--accent-border); color: var(--accent); background: var(--accent-bg); }
.row.chg .box.is-ptr { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }
.links { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 3; }
.lk { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; opacity: 0.85; transition: stroke 0.25s, stroke-width 0.25s; }
.lkh { fill: var(--accent); transition: fill 0.25s; }
.lkd { fill: var(--accent); }
.lk.hot { stroke: var(--ok); stroke-width: 3.2; opacity: 1; }
.lkh.hot { fill: var(--ok); }
.runner { fill: var(--ok); stroke: var(--surface); stroke-width: 2; }
.frame { position: relative; border: 1px solid var(--border-strong); border-radius: 12px; padding: 4px 12px 2px; margin: 0 0 12px; background: var(--surface); transform-origin: 50% 0; }
.frame + .frame { border-color: var(--accent-border); }
.frame-h { display: flex; align-items: baseline; gap: 8px; font: 600 13px var(--mono); color: var(--accent); padding: 4px 0 8px; }
.frame-h small { font: 11px var(--font); color: var(--faint); }
.t-pre { color: var(--t-kw); opacity: 0.85; }
.is-c .cell { height: 54px; width: 58px; align-items: flex-start; padding-top: 8px; }
.caddr { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font: 9.5px var(--mono); color: var(--faint); }
.is-c .list { padding-bottom: 8px; }
.box { min-width: 60px; height: 42px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 16px; perspective: 200px; transition: background 0.3s, border-color 0.3s, color 0.3s; }
.val, .cv { display: inline-block; }
.row.chg .box { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok); }
.list { position: relative; padding-bottom: 26px; perspective: 500px; }
.cells { display: flex; gap: 6px; transform-style: preserve-3d; flex-wrap: nowrap; }
.cell { position: relative; width: 50px; height: 42px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 16px; transition: background 0.3s, border-color 0.3s, color 0.3s; }
.cell .idx { position: absolute; top: 2px; right: 5px; font-size: 9px; color: var(--faint); line-height: 1; }
.cell.hit { background: var(--accent-bg); border-color: var(--accent-border); color: var(--accent); }
.ptr { position: absolute; top: 46px; left: 0; display: flex; align-items: center; gap: 2px; font: 600 12px var(--mono); color: var(--accent); white-space: nowrap; }
.ptr svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.console { margin: 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 15px; min-height: 52px; }
.oline { min-height: 24px; white-space: pre-wrap; }
.oline.fresh { color: var(--ok); }
.prompt { display: flex; align-items: center; color: var(--faint); height: 24px; }
.caret { margin-right: 8px; }
.cur { width: 8px; height: 16px; background: var(--muted); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 20; overflow: visible; }
.tok, .eq, .cond { position: absolute; left: 0; top: 0; white-space: nowrap; font-family: var(--mono); font-size: 15px; border-radius: 9px; padding: 5px 12px; }
.tok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-border); box-shadow: 0 6px 18px rgba(16, 133, 90, 0.18); }
.eq { background: var(--surface); color: var(--text); border: 1px solid var(--accent-border); box-shadow: 0 8px 24px rgba(80, 72, 229, 0.16); }
.eq b { color: var(--ok); font-weight: 700; }
.cond { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--accent-border); box-shadow: 0 8px 24px rgba(80, 72, 229, 0.16); perspective: 300px; }
.cr { display: inline-block; padding: 1px 9px; border-radius: 6px; font-weight: 700; font-size: 13px; }
.cr.yes { background: var(--ok-bg); color: var(--ok); }
.cr.no { background: var(--bad-bg); color: var(--bad); }
.pt { position: absolute; left: 0; top: 0; width: 6px; height: 6px; border-radius: 1.5px; background: var(--ok); }
.pt.bad { background: var(--bad); }

.say { margin: 18px 0 0; padding: 12px 18px; min-height: 76px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0; font-size: 17px; line-height: 1.7; perspective: 500px; }
.say .w { display: inline-block; }

.controls { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 600 15px var(--font); cursor: pointer; transition: background 0.15s, transform 0.1s, border-color 0.15s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.96); }
.btn:focus-visible, .scrub:focus-visible, .speed:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.icon { width: 44px; padding: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; min-width: 112px; }
.btn.primary svg { fill: currentColor; }
.btn.primary.on svg { fill: none; }
.btn.primary:hover { filter: brightness(1.08); }
.scrub { flex: 1; min-width: 140px; accent-color: var(--accent); height: 44px; }
.speed { height: 44px; border-radius: 11px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 600 14px var(--font); padding: 0 10px; }
.count { font-size: 14px; color: var(--muted); min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- lesson page ---------- */
.lesson-head { padding: 28px 0 18px; }
.lesson-head h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.02em; line-height: 1.25; }
.lesson-head p { margin: 0; color: var(--muted); }
.lesson-main { padding-bottom: 60px; }
.done-card { margin-top: 22px; padding: 20px 22px; border-radius: var(--radius); background: var(--ok-bg); border: 1px solid var(--ok-border); display: none; align-items: center; gap: 16px; flex-wrap: wrap; }
.done-card.show { display: flex; }
.done-card h2 { margin: 0; font-size: 18px; color: var(--ok); }
.done-card p { margin: 0; color: var(--muted); font-size: 15px; }
.done-card .btn { margin-left: auto; text-decoration: none; }
.err { padding: 40px 0; color: var(--muted); }

/* ---------- home ---------- */
.hero { padding: 48px 0 24px; display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 40px; align-items: center; }
.hero h1 { font-size: clamp(32px, 4.4vw, 52px); line-height: 1.08; letter-spacing: -0.03em; margin: 0 0 16px; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero-copy p { color: var(--muted); font-size: 18px; margin: 0 0 24px; max-width: 34ch; }
.hero .btn { text-decoration: none; }
.hero-demo .player { --line-h: 30px; }
.hero-demo .ln { font-size: 13.5px; }
.hero-demo .say { font-size: 15px; min-height: 64px; }
.hero-demo .controls .scrub, .hero-demo .controls .speed { display: none; }
.course { padding-bottom: 28px; }
.course-h { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-top: 28px; }
.section-h { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
.course-meta { font-size: 14px; color: var(--muted); }
.course-blurb { margin: 4px 0 16px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 8px; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); transition: transform 0.25s cubic-bezier(.2,.8,.2,1), border-color 0.2s; }
.card:hover { transform: translateY(-4px) rotateX(4deg); border-color: var(--accent-border); }
.card .meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.card .num { width: 28px; height: 28px; border-radius: 8px; background: var(--accent-bg); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.card h3 { margin: 4px 0 0; font-size: 18px; letter-spacing: -0.01em; }
.card p { margin: 0; color: var(--muted); font-size: 15px; }
.card .state { margin-top: auto; padding-top: 8px; font-size: 13px; font-weight: 600; color: var(--accent); }
.card .state.done { color: var(--ok); }

@media (max-width: 860px) {
  .world { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); padding-top: 28px; }
}
@media (max-width: 520px) {
  .wrap { padding: 0 16px; }
  .ln { font-size: 13.5px; gap: 10px; padding: 0 6px; }
  .say { font-size: 16px; }
  .scrub { order: 10; flex-basis: 100%; }
  .count { margin-left: auto; }
  .btn.primary { min-width: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .btn { transition: none; }
}

/* ---------- printed values: slot + matching colour on %spec, argument and variable ---------- */
.hue1 { --hc: #2F80ED; } .hue2 { --hc: #E8505B; } .hue3 { --hc: #8B5CF6; } .hue4 { --hc: #D98E04; }
:root[data-theme="dark"] .hue1 { --hc: #6AA8FF; }
:root[data-theme="dark"] .hue2 { --hc: #FF7A84; }
:root[data-theme="dark"] .hue3 { --hc: #B69CFF; }
:root[data-theme="dark"] .hue4 { --hc: #FFC24A; }
.c.arg-hot { color: var(--hc) !important; background: color-mix(in srgb, var(--hc) 20%, transparent); font-weight: 800; transition: background 0.2s; }
.src-hot { outline: 3px solid var(--hc); outline-offset: 3px; border-radius: 10px; box-shadow: 0 0 0 7px color-mix(in srgb, var(--hc) 18%, transparent); transition: outline-color 0.2s, box-shadow 0.2s; }
.oline .slot { display: inline-block; min-width: calc(var(--n, 1) * 1ch + 12px); padding: 0 3px; margin: 0 1px; text-align: center; color: var(--hc); font-weight: 800; border-bottom: 2px dashed var(--hc); border-radius: 2px; vertical-align: baseline; transform-origin: 50% 70%; }
.oline .slot.filled { border-bottom-color: transparent; background: color-mix(in srgb, var(--hc) 14%, transparent); }
.oline.fresh .slot { color: var(--hc); }
.tok.hue1, .tok.hue2, .tok.hue3, .tok.hue4 { background: color-mix(in srgb, var(--hc) 16%, var(--surface, #fff)); color: var(--hc); border-color: color-mix(in srgb, var(--hc) 55%, transparent); font-weight: 800; box-shadow: 0 6px 18px color-mix(in srgb, var(--hc) 30%, transparent); }
/* condition bubble: names that turn into values */
.cond .term { display: inline-block; color: var(--hc); font-weight: 800; border-bottom: 2px dashed var(--hc); padding: 0 2px; border-radius: 3px; }
.cond .term.filled { border-bottom-color: transparent; background: color-mix(in srgb, var(--hc) 15%, transparent); }
