/* PyForge styles ---------------------------------------------------------
   Palette: cool slate neutrals with a slate-blue accent and a mustard "spark"
   (a nod to Python's colours without copying them). Difficulty colours are
   semantic and independent of the accent. */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #e2e7ee;
  --line: #d8dee6;
  --line-strong: #c2cad5;
  --ink: #131a24;
  --ink-2: #3a4556;
  --muted: #677386;
  --accent: #2c5a88;
  --accent-hover: #234a71;
  --accent-ink: #ffffff;
  --accent-soft: #e1eaf4;
  --spark: #d99c12;
  --spark-soft: #fbf1d8;
  --easy: #0f8f77;
  --medium: #b97705;
  --hard: #cc3653;
  --practice: #5a6b85;
  --ok: #1d8548;
  --ok-hover: #176b3a;
  --ok-soft: #e2f3e9;
  --bad: #c3352f;
  --bad-soft: #fbe8e6;
  --warn-soft: #fcf3dc;
  --code-bg: #f6f8fb;
  --syn-kw: #8a3fb8;
  --syn-def: #1f5fa8;
  --syn-str: #1a7a4c;
  --syn-num: #b4570b;
  --syn-com: #7c8797;
  --syn-builtin: #0f7a8a;
  --syn-op: #4a5566;
  --shadow: 0 1px 2px rgba(19, 26, 36, 0.06), 0 4px 16px rgba(19, 26, 36, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-display: "Schibsted Grotesk", "Helvetica Neue", Arial, sans-serif;
  --font-body: "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --topbar-h: 52px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1219;
    --surface: #141b25;
    --surface-2: #1a2330;
    --surface-3: #222d3b;
    --line: #283343;
    --line-strong: #364457;
    --ink: #e4e9f0;
    --ink-2: #b8c2cf;
    --muted: #8290a3;
    --accent: #80b1e6;
    --accent-hover: #a3c7ee;
    --accent-ink: #0d1219;
    --accent-soft: #1b2b3e;
    --spark: #f0c24b;
    --spark-soft: #2e2713;
    --easy: #2cc3a2;
    --medium: #f0b240;
    --hard: #ff6c86;
    --practice: #93a3bb;
    --ok: #46c27a;
    --ok-hover: #62d391;
    --ok-soft: #14281c;
    --bad: #ff6f66;
    --bad-soft: #2e1715;
    --warn-soft: #2b2412;
    --code-bg: #10161f;
    --syn-kw: #cf8ef5;
    --syn-def: #7fb6f2;
    --syn-str: #8fd19e;
    --syn-num: #f2a86b;
    --syn-com: #6d7a8c;
    --syn-builtin: #6fd0dc;
    --syn-op: #aab4c2;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1219;
  --surface: #141b25;
  --surface-2: #1a2330;
  --surface-3: #222d3b;
  --line: #283343;
  --line-strong: #364457;
  --ink: #e4e9f0;
  --ink-2: #b8c2cf;
  --muted: #8290a3;
  --accent: #80b1e6;
  --accent-hover: #a3c7ee;
  --accent-ink: #0d1219;
  --accent-soft: #1b2b3e;
  --spark: #f0c24b;
  --spark-soft: #2e2713;
  --easy: #2cc3a2;
  --medium: #f0b240;
  --hard: #ff6c86;
  --practice: #93a3bb;
  --ok: #46c27a;
  --ok-hover: #62d391;
  --ok-soft: #14281c;
  --bad: #ff6f66;
  --bad-soft: #2e1715;
  --warn-soft: #2b2412;
  --code-bg: #10161f;
  --syn-kw: #cf8ef5;
  --syn-def: #7fb6f2;
  --syn-str: #8fd19e;
  --syn-num: #f2a86b;
  --syn-com: #6d7a8c;
  --syn-builtin: #6fd0dc;
  --syn-op: #aab4c2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

/* Base ------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; text-wrap: balance; margin: 0; }
code, pre, kbd { font-family: var(--font-mono); }
img { max-width: 100%; }

.shell { display: flex; flex-direction: column; height: 100%; }
#app { flex: 1; min-height: 0; overflow: auto; outline: none; }
#app.app-fixed { overflow: hidden; }

/* Top bar ---------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--topbar-h);
  padding: 0 20px;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand { display: flex; align-items: baseline; gap: 8px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-prompt { font: 700 13px var(--font-mono); color: var(--spark); letter-spacing: -0.02em; }
.brand-name { font: 800 19px var(--font-display); letter-spacing: -0.02em; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.runtime-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  white-space: nowrap;
}
.runtime-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.runtime-pill[data-state="loading"] .dot { background: var(--spark); animation: pulse 1s ease-in-out infinite; }
.runtime-pill[data-state="busy"] .dot { background: var(--accent); animation: pulse 0.8s ease-in-out infinite; }
.runtime-pill[data-state="ready"] .dot { background: var(--ok); }
.runtime-pill[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.3; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Buttons ---------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-submit { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-submit:hover { background: var(--ok-hover); border-color: var(--ok-hover); }
:root[data-theme="dark"] .btn-submit { color: #0d1219; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-submit { color: #0d1219; } }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn kbd { font-size: 11px; opacity: 0.7; }

/* Shared bits ------------------------------------------------------------ */

.page { max-width: 1120px; margin: 0 auto; padding: 32px 20px 64px; }
.eyebrow {
  font: 600 12px var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); }
.diff { font-weight: 600; font-size: 13px; }
.diff-Easy { color: var(--easy); }
.diff-Medium { color: var(--medium); }
.diff-Hard { color: var(--hard); }
.diff-Practice { color: var(--practice); }
.pill {
  display: inline-flex; align-items: center; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2);
}
.pill.diff-Easy { background: color-mix(in srgb, var(--easy) 14%, transparent); }
.pill.diff-Medium { background: color-mix(in srgb, var(--medium) 16%, transparent); }
.pill.diff-Hard { background: color-mix(in srgb, var(--hard) 14%, transparent); }
.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: var(--radius-sm); font-size: 12px; background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap;
}
.status-icon { display: inline-flex; width: 18px; height: 18px; flex-shrink: 0; }
.status-icon svg { width: 18px; height: 18px; }
.st-solved { color: var(--ok); }
.st-attempted { color: var(--spark); }
.st-todo { color: var(--line-strong); }
.bar { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.ok > span { background: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px);
}

/* Learn (home) ----------------------------------------------------------- */

.welcome {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; margin-bottom: 40px;
}
.welcome-main h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 800; letter-spacing: -0.03em; margin: 8px 0 12px; }
.welcome-main p { color: var(--ink-2); max-width: 60ch; margin: 0 0 20px; }
.continue-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.continue-card h2 { font-size: 20px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font: 700 22px var(--font-display); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.path { display: flex; flex-direction: column; gap: 28px; }
.module {
  display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 20px;
}
.module-num {
  font: 800 34px/1 var(--font-display); color: var(--line-strong); letter-spacing: -0.04em;
  padding-top: 4px; font-variant-numeric: tabular-nums;
}
.module.done .module-num { color: var(--ok); }
.module-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.module-head h2 { font-size: 22px; letter-spacing: -0.01em; }
.module-head .muted { font-size: 13px; font-variant-numeric: tabular-nums; }
.module-blurb { color: var(--ink-2); margin: 4px 0 14px; max-width: 70ch; }
.lesson-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.lesson-row {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 16px; color: var(--ink);
}
.lesson-list li + li .lesson-row { border-top: 1px solid var(--line); }
.lesson-row:hover { background: var(--surface-2); text-decoration: none; }
.lesson-row .title { font-weight: 500; }
.lesson-row .summary { font-size: 13px; color: var(--muted); display: block; }
.ex-dots { display: flex; gap: 4px; align-items: center; }
.ex-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--line-strong); }
.ex-dots i.on { background: var(--ok); border-color: var(--ok); }
.ex-dots small { font-size: 12px; color: var(--muted); margin-left: 6px; font-variant-numeric: tabular-nums; }

.checkpoint {
  margin-top: 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 14px 16px;
  background: linear-gradient(90deg, var(--spark-soft), transparent 60%);
}
.checkpoint-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.checkpoint-head h3 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.checkpoint-head h3::before { content: "◆"; color: var(--spark); font-size: 12px; }
.checkpoint p { margin: 4px 0 10px; font-size: 14px; color: var(--ink-2); }
.checkpoint-list { display: flex; flex-wrap: wrap; gap: 8px; }
.cp-item {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); font-size: 14px;
}
.cp-item:hover { border-color: var(--line-strong); text-decoration: none; }
.cp-item .diff { font-size: 12px; }
.cp-note { font-size: 12px; color: var(--muted); }

/* Lesson reader ---------------------------------------------------------- */

.lesson-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; max-width: 1080px; margin: 0 auto; padding: 32px 20px 80px; }
.lesson-side { position: sticky; top: 16px; align-self: start; font-size: 14px; }
.lesson-side h4 { font: 600 12px var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.lesson-side ol, .lesson-side ul { list-style: none; margin: 0 0 24px; padding: 0; }
.lesson-side li a { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-radius: var(--radius-sm); color: var(--ink-2); }
.lesson-side li a:hover { background: var(--surface-2); text-decoration: none; }
.lesson-side li a.current { background: var(--accent-soft); color: var(--ink); font-weight: 500; }
.lesson-side .toc a { font-size: 13px; color: var(--muted); }
.lesson-main { max-width: 740px; min-width: 0; }
.lesson-main > header h1 { font-size: clamp(28px, 4vw, 38px); font-weight: 800; letter-spacing: -0.025em; margin: 6px 0 8px; }
.lesson-main > header p { color: var(--ink-2); margin: 0; font-size: 17px; }
.lesson-main > header .meta { margin-top: 10px; font-size: 13px; color: var(--muted); }

.prose { margin-top: 28px; }
.prose > * + * { margin-top: 16px; }
.prose h2 { font-size: 22px; margin-top: 40px; letter-spacing: -0.01em; scroll-margin-top: 16px; }
.prose h3 { font-size: 17px; margin-top: 28px; }
.prose p, .prose li { max-width: 68ch; }
.prose p { margin: 0; }
.prose ul, .prose ol { padding-left: 22px; margin-bottom: 0; }
.prose li + li { margin-top: 4px; }
.prose code { font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; font-size: 13.5px; }
.md-pre {
  margin: 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow-x: auto; line-height: 1.55; font-size: 13.5px;
}
.md-text { color: var(--ink-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; }
.prose th, .prose td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.prose thead th { border-top: 0; background: var(--surface-2); font-weight: 600; font-size: 13px; }
.callout {
  border-left: 3px solid var(--spark); background: var(--spark-soft); padding: 12px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.callout p { margin: 0; }

.example {
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden;
}
.example-bar {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.example-bar .label { margin-right: auto; font-family: var(--font-mono); }
.example .CodeMirror { height: auto; background: var(--code-bg); font-size: 13.5px; }
.example .CodeMirror-scroll { max-height: 520px; }
.example-out {
  margin: 0; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--surface);
  font: 13px/1.5 var(--font-mono); white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
.example-out::before { content: "Output"; display: block; font: 600 11px var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.example-out .err { color: var(--bad); }
.example-out .empty { color: var(--muted); font-style: italic; }

.practice { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); }
.practice h2 { font-size: 22px; }
.practice > p { color: var(--ink-2); margin: 6px 0 16px; }
.practice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.practice-card {
  display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
.practice-card:hover { border-color: var(--accent); text-decoration: none; }
.practice-card .top { display: flex; justify-content: space-between; align-items: center; }
.practice-card h3 { font-size: 16px; }
.practice-card p { margin: 0; font-size: 13px; color: var(--muted); }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 32px; flex-wrap: wrap; }

/* Problems table --------------------------------------------------------- */

.problems-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.problems-head h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.025em; }
.solved-summary { display: flex; gap: 18px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.solved-summary b { color: var(--ink); font-weight: 600; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type="search"], .filters select {
  height: 34px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--ink); padding: 0 10px; font: inherit; font-size: 14px;
}
.filters input[type="search"] { flex: 1 1 220px; min-width: 0; }
.filters label.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--ink-2); }
.ptable-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow-x: auto; }
.ptable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ptable th {
  text-align: left; font: 600 12px var(--font-body); letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.ptable td { padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.ptable tbody tr:first-child td { border-top: 0; }
.ptable tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.ptable tbody tr { cursor: pointer; }
.ptable tbody tr:hover td { background: var(--surface-2); }
.ptable .title-cell a { color: var(--ink); font-weight: 500; }
.ptable .num { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.ptable .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.ptable .col-status { width: 44px; }
.ptable .col-diff { width: 96px; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* Progress --------------------------------------------------------------- */

.progress-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card h2 { font-size: 16px; margin-bottom: 14px; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-12 { grid-column: span 12; }
.ring-wrap { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.ring { position: relative; width: 132px; height: 132px; flex-shrink: 0; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .center b { font: 800 28px var(--font-display); font-variant-numeric: tabular-nums; }
.ring .center span { font-size: 12px; color: var(--muted); }
.diff-bars { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 12px; }
.diff-bar-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) 54px; gap: 10px; align-items: center; font-size: 13px; }
.diff-bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.bar.easy > span { background: var(--easy); }
.bar.medium > span { background: var(--medium); }
.bar.hard > span { background: var(--hard); }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 16px; }
.kv div b { display: block; font: 700 26px var(--font-display); font-variant-numeric: tabular-nums; }
.kv div span { font-size: 13px; color: var(--muted); }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-3); }
.heatmap i.l1 { background: color-mix(in srgb, var(--ok) 35%, var(--surface-3)); }
.heatmap i.l2 { background: color-mix(in srgb, var(--ok) 65%, var(--surface-3)); }
.heatmap i.l3 { background: var(--ok); }
.heatmap-legend { display: flex; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
.heatmap-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.module-progress { display: flex; flex-direction: column; gap: 12px; }
.module-progress-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 64px; gap: 12px; align-items: center; font-size: 14px; }
.module-progress-row .n { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; align-items: center; }
.recent li:first-child { border-top: 0; }
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.confirm-inline { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; color: var(--bad); }

/* Workspace -------------------------------------------------------------- */

.ws { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ws-toolbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--bg); flex-shrink: 0;
}
.ws-toolbar .left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ws-toolbar .left .crumb { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: 6px; }
.ws-toolbar .center { display: flex; gap: 8px; }
.ws-toolbar .right { display: flex; justify-content: flex-end; }
.ws-body { flex: 1; min-height: 0; display: flex; gap: 0; padding: 0 12px 12px; }
.pane {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
}
.pane-left { flex: 0 0 var(--left-basis, 44%); }
.pane-right { flex: 1 1 auto; display: flex; flex-direction: column; background: transparent; border: 0; border-radius: 0; overflow: visible; }
.gutter-x { flex: 0 0 10px; cursor: col-resize; position: relative; }
.gutter-y { flex: 0 0 10px; cursor: row-resize; position: relative; }
.gutter-x::after, .gutter-y::after { content: ""; position: absolute; background: var(--line-strong); border-radius: 2px; opacity: 0; transition: opacity 0.15s; }
.gutter-x::after { left: 4px; top: 50%; width: 2px; height: 32px; transform: translateY(-50%); }
.gutter-y::after { top: 4px; left: 50%; height: 2px; width: 32px; transform: translateX(-50%); }
.gutter-x:hover::after, .gutter-y:hover::after, .dragging::after { opacity: 1; background: var(--accent); }

.tabs { display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-shrink: 0; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--ink); background: var(--surface-3); }
.tab[aria-selected="true"] { color: var(--ink); background: var(--surface); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }
.tab .badge { font-size: 11px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); color: var(--ink-2); }
.pane-scroll { flex: 1; overflow: auto; padding: 18px 20px 28px; min-height: 0; }

.problem-title { font-size: 22px; font-weight: 700; letter-spacing: -0.015em; }
.problem-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 4px; }
.problem-meta .solved-flag { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-size: 13px; font-weight: 500; }
.problem-lesson-link { font-size: 13px; margin-top: 6px; }
.problem-desc { margin-top: 16px; }
.problem-desc.prose > * + * { margin-top: 12px; }
.ex-block { margin-top: 18px; }
.ex-block h4 { font: 600 14px var(--font-body); margin-bottom: 8px; }
.ex-io {
  border-left: 2px solid var(--line-strong); padding: 4px 0 4px 14px; font-size: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.ex-io .k { font-weight: 600; color: var(--ink); margin-right: 6px; }
.ex-io code { font-size: 13px; background: none; padding: 0; color: var(--ink-2); white-space: pre-wrap; word-break: break-word; }
.ex-io .why { color: var(--ink-2); }
.constraints { margin-top: 18px; }
.constraints h4 { font: 600 14px var(--font-body); margin-bottom: 6px; }
.constraints ul { margin: 0; padding-left: 20px; font-size: 14px; }
.constraints code { font-size: 12.5px; }

.hint { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface); }
.hint summary { cursor: pointer; padding: 10px 14px; font-weight: 500; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 8px; }
.hint summary::-webkit-details-marker { display: none; }
.hint summary::before { content: "›"; font-weight: 700; color: var(--muted); transition: transform 0.15s; display: inline-block; }
.hint[open] summary::before { transform: rotate(90deg); }
.hint .body { padding: 0 14px 12px 30px; font-size: 14px; color: var(--ink-2); }
.hint .body code { font-size: 12.5px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

.gate { text-align: center; padding: 36px 16px; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate svg { color: var(--muted); }
.gate p { margin: 0; max-width: 42ch; }
.solution-code { margin-top: 16px; }

.subs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.subs-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.subs-table td { padding: 8px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.subs-table tr { cursor: pointer; }
.subs-table tbody tr:hover td { background: var(--surface-2); }
.s-Accepted { color: var(--ok); font-weight: 600; }
.s-bad { color: var(--bad); font-weight: 600; }

.editor-pane { flex: 0 0 var(--editor-basis, 60%); min-height: 120px; }
.editor-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.editor-head .lang { font: 500 12px var(--font-mono); color: var(--ink-2); margin-right: auto; display: flex; align-items: center; gap: 8px; }
.editor-head .saved { font-size: 12px; color: var(--muted); }
.editor-host { flex: 1; min-height: 0; position: relative; }
.editor-host .CodeMirror { position: absolute; inset: 0; height: 100%; font-size: 14px; }
.console-pane { flex: 1 1 0; min-height: 90px; }

.case-tabs { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.case-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 0; background: var(--surface-2); color: var(--ink-2); cursor: pointer; font-size: 13px; font-weight: 500;
}
.case-tab[aria-selected="true"] { background: var(--surface-3); color: var(--ink); }
.case-tab .x { opacity: 0; font-size: 14px; line-height: 1; padding: 0 2px; border-radius: 3px; }
.case-tab:hover .x { opacity: 0.7; }
.case-tab .x:hover { opacity: 1; background: var(--line); }
.case-tab .dot { width: 7px; height: 7px; border-radius: 50%; }
.case-tab .dot.pass { background: var(--ok); }
.case-tab .dot.fail { background: var(--bad); }
.field { margin-bottom: 12px; }
.field label, .field .label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-family: var(--font-mono); }
.field textarea {
  width: 100%; resize: vertical; min-height: 38px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); font: 13px/1.5 var(--font-mono); padding: 8px 10px;
}
.field textarea:focus { outline: none; border-color: var(--accent); }
.value-box {
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; font: 13px/1.5 var(--font-mono);
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; border: 1px solid transparent;
}
.value-box.bad { border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.value-box.good { border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.console-note { font-size: 12px; color: var(--muted); margin-top: 8px; }
.result-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.result-head h3 { font-size: 20px; }
.result-head .sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.r-ok { color: var(--ok); }
.r-bad { color: var(--bad); }
.error-box {
  background: var(--bad-soft); color: var(--bad); border-radius: var(--radius-sm); padding: 12px 14px;
  font: 13px/1.55 var(--font-mono); white-space: pre-wrap; word-break: break-word; overflow-x: auto; margin-bottom: 14px;
}
.accepted-box { background: var(--ok-soft); border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.accepted-box p { margin: 0; color: var(--ink-2); font-size: 14px; }
.accepted-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.running { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 8px 0; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.placeholder { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* CodeMirror theme via tokens --------------------------------------------- */

.CodeMirror { font-family: var(--font-mono); font-variant-ligatures: none; background: var(--surface); color: var(--ink); line-height: 1.55; }
code, pre { font-variant-ligatures: none; }
.CodeMirror-gutters { background: var(--surface); border-right: 1px solid var(--line); }
.example .CodeMirror-gutters { background: var(--code-bg); }
.CodeMirror-linenumber { color: var(--muted); padding: 0 10px 0 6px; font-size: 12px; }
.CodeMirror-cursor { border-left: 2px solid var(--accent); }
.CodeMirror-selected { background: var(--accent-soft) !important; }
.CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--accent) 28%, transparent) !important; }
.CodeMirror-activeline-background { background: var(--surface-2); }
.CodeMirror-matchingbracket { color: var(--ink) !important; background: color-mix(in srgb, var(--spark) 30%, transparent); }
.CodeMirror-nonmatchingbracket { color: var(--bad) !important; }
/* Token colours. Each rule also targets .cm-s-default so it beats CodeMirror's
   built-in light theme (same specificity, and this file loads after it). The
   bare .cm-* selectors cover static code highlighted with runMode. */
.cm-keyword, .cm-s-default .cm-keyword { color: var(--syn-kw); font-weight: 500; }
.cm-def, .cm-s-default .cm-def { color: var(--syn-def); font-weight: 500; }
.cm-variable, .cm-s-default .cm-variable { color: var(--ink); }
.cm-variable-2, .cm-s-default .cm-variable-2, .cm-variable-3, .cm-s-default .cm-variable-3,
.cm-type, .cm-s-default .cm-type { color: var(--syn-builtin); }
.cm-builtin, .cm-s-default .cm-builtin { color: var(--syn-builtin); }
.cm-string, .cm-s-default .cm-string, .cm-string-2, .cm-s-default .cm-string-2 { color: var(--syn-str); }
.cm-number, .cm-s-default .cm-number { color: var(--syn-num); }
.cm-comment, .cm-s-default .cm-comment { color: var(--syn-com); font-style: italic; }
.cm-operator, .cm-s-default .cm-operator { color: var(--syn-op); }
.cm-meta, .cm-s-default .cm-meta { color: var(--syn-num); }
.cm-property, .cm-s-default .cm-property { color: var(--ink); }
.cm-atom, .cm-s-default .cm-atom { color: var(--syn-num); }
.cm-bracket, .cm-s-default .cm-bracket { color: var(--syn-op); }
.cm-error, .cm-s-default .cm-error { color: var(--bad); }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { font-variant-ligatures: none; }

/* Responsive ------------------------------------------------------------- */

@media (max-width: 900px) {
  .welcome { grid-template-columns: 1fr; }
  .lesson-layout { grid-template-columns: 1fr; gap: 16px; }
  .lesson-side { position: static; }
  .lesson-side .toc { display: none; }
  .span-5, .span-7 { grid-column: span 12; }
  #app.app-fixed { overflow: auto; }
  .ws { height: auto; }
  .ws-body { flex-direction: column; gap: 12px; }
  .pane-left { flex: none; max-height: none; }
  .pane-left .pane-scroll { max-height: 60vh; }
  .gutter-x, .gutter-y { display: none; }
  .pane-right { gap: 12px; }
  .editor-pane { flex: none; height: 420px; }
  .console-pane { flex: none; }
  .console-pane .pane-scroll { max-height: 60vh; }
  .ws-toolbar { grid-template-columns: 1fr auto; }
  .ws-toolbar .right { display: none; }
}

@media (max-width: 560px) {
  .topbar { gap: 10px; padding: 0 12px; }
  .brand-prompt { display: none; }
  .nav a { padding: 6px 8px; }
  .runtime-pill .label { display: none; }
  .page { padding: 24px 16px 48px; }
  .lesson-layout { padding: 24px 16px 64px; }
  .module { grid-template-columns: 1fr; gap: 6px; }
  .module-num { font-size: 22px; }
  .stat-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ptable .col-tags, .ptable .col-module { display: none; }
  .ws-toolbar .left .crumb { display: none; }
  .ws-body { padding: 0 8px 8px; }
  .module-progress-row { grid-template-columns: minmax(0, 1fr) 80px 56px; }
}

@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .brand-name { font-size: 17px; }
  .nav { gap: 0; }
  .nav a { padding: 6px 7px; font-size: 13.5px; }
  .runtime-pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
