/* Traceback. Layout concept: a transit strip-map. Each world is a coloured line, each lesson a stop.
   Paper-grey ground, navy ink, Lisbon-tram yellow for the one thing to do next. */
:root {
  --paper: #eef1f5;
  --card: #ffffff;
  --card-2: #f6f8fb;
  --ink: #14213d;
  --muted: #5b6677;
  --line: #d6dce5;
  --tram: #f2b705;
  --tram-ink: #2a2000;
  --go: #1d8a5a;
  --go-soft: #e3f4ec;
  --stop: #c8372d;
  --stop-soft: #fbe9e7;
  --info: #2f6feb;
  --info-soft: #e8effd;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 16px rgba(20, 33, 61, .06);
  --code-bg: #0f1828;
  --code-ink: #dfe6f1;
  --code-muted: #6c7a91;
  --code-line: #1c2840;
  --code-sel: #2a3b5c;
  --font-display: "Bricolage Grotesque", "Space Grotesk", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0a111f; --card: #111a2c; --card-2: #0d1526; --ink: #e6ebf3; --muted: #93a0b5; --line: #24314a;
    --tram: #f5c232; --tram-ink: #241b00; --go: #3cc48a; --go-soft: #10291f; --stop: #f0675b; --stop-soft: #2c1513;
    --info: #6b9bff; --info-soft: #14213d; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    --code-bg: #0b1322; --code-line: #1a2540; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0a111f; --card: #111a2c; --card-2: #0d1526; --ink: #e6ebf3; --muted: #93a0b5; --line: #24314a;
  --tram: #f5c232; --tram-ink: #241b00; --go: #3cc48a; --go-soft: #10291f; --stop: #f0675b; --stop-soft: #2c1513;
  --info: #6b9bff; --info-soft: #14213d; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --code-bg: #0b1322; --code-line: #1a2540; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.55; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--card); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--info); }
code, kbd, pre { font-family: var(--font-mono); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: #14213d; color: #fff; box-shadow: inset 0 -4px 0 #f2b705, 0 0 0 1px rgba(255,255,255,.12); display: grid; place-items: center; padding-bottom: 3px;
  font-family: var(--font-display); font-weight: 800; font-size: 15px; letter-spacing: -.02em; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: -.02em; }
.nav { display: flex; gap: 4px; margin-left: 8px; flex-wrap: wrap; }
.nav button { background: none; border: 0; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; position: relative; }
.nav button:hover { background: var(--card-2); color: var(--ink); }
.nav button[aria-current="page"] { background: var(--ink); color: var(--card); }
.badge-dot { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--stop); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; vertical-align: 1px; }
.hud { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip b { font-weight: 700; }
.py-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.py-status.ready .dot { background: var(--go); }
.py-status.busy .dot { background: var(--tram); animation: pulse 1s infinite; }
.py-status.err .dot { background: var(--stop); }
@keyframes pulse { 50% { opacity: .35; } }

main { max-width: 1280px; margin: 0 auto; padding-block: 22px 60px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(26px, 3.4vw, 38px); font-weight: 800; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--tram); border-color: var(--tram); color: var(--tram-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--card); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--card-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }
kbd { font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid currentColor; opacity: .7; }

/* ---------- map view ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; margin-bottom: 26px; }
.hero-main { padding: 26px; position: relative; overflow: hidden; }
.hero-main h1 { margin: 6px 0 10px; }
.hero-main p { margin: 0 0 18px; color: var(--muted); max-width: 60ch; }
.hero-stripe { position: absolute; right: -40px; top: 0; bottom: 0; width: 160px; background: repeating-linear-gradient(90deg, var(--tram) 0 10px, transparent 10px 22px); opacity: .18; transform: skewX(-12deg); pointer-events: none; }
.next-stop { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.next-stop .where { font-size: 14px; color: var(--muted); }
.next-stop .where b { color: var(--ink); }
.hero-side { padding: 20px; display: grid; gap: 14px; align-content: start; }
.rankline { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.rank-title { font-family: var(--font-display); font-weight: 800; font-size: 22px; }
.meter { height: 10px; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--tram); border-radius: 6px; }
.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mini-stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.mini-stat .v { font-family: var(--font-display); font-size: 22px; font-weight: 800; }
.mini-stat .k { font-size: 12px; color: var(--muted); }
.alert-row { display: flex; gap: 10px; flex-wrap: wrap; }
.alert { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); font-size: 14px; cursor: pointer; text-align: left; flex: 1 1 200px; }
.alert.warn { border-color: color-mix(in srgb, var(--stop) 40%, var(--line)); background: var(--stop-soft); }
.alert.due { border-color: color-mix(in srgb, var(--info) 40%, var(--line)); background: var(--info-soft); }

.worlds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.world { padding: 18px 18px 10px; }
.world.locked { opacity: .62; }
.world-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.line-badge { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 15px; flex: none; }
.world-head .t { min-width: 0; }
.world-head .sub { color: var(--muted); font-size: 13px; }
.world-head .prog { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.stops { list-style: none; margin: 0; padding: 0; position: relative; }
.stops::before { content: ""; position: absolute; left: 13px; top: 14px; bottom: 14px; width: 5px; border-radius: 3px; background: var(--wc); opacity: .9; }
.stop { position: relative; }
.stop button { width: 100%; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 7px 8px 7px 0; cursor: pointer; text-align: left; border-radius: 8px; }
.stop button:hover:not(:disabled) { background: var(--card-2); }
.stop button:disabled { cursor: not-allowed; }
.station { width: 31px; height: 31px; flex: none; display: grid; place-items: center; position: relative; z-index: 1; }
.station i { width: 17px; height: 17px; border-radius: 50%; background: var(--card); border: 4px solid var(--wc); display: block; }
.stop.done .station i { background: var(--wc); }
.stop.boss .station i { width: 23px; height: 23px; border-radius: 6px; transform: rotate(45deg); }
.stop.locked .station i { border-color: var(--line); background: var(--card-2); }
.stop.next .station::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid var(--tram); animation: ring 1.6s ease-out infinite; }
@keyframes ring { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }
.stop .ttl { flex: 1; min-width: 0; font-weight: 500; }
.stop.locked .ttl { color: var(--muted); }
.stop .meta { font-size: 12px; color: var(--muted); white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.tag-mini { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); background: var(--card-2); color: var(--muted); }
.tag-mini.boss { background: var(--ink); color: var(--card); border-color: var(--ink); }
.tag-mini.due { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag-mini.star { background: var(--go-soft); color: var(--go); border-color: transparent; }

/* ---------- lesson view ---------- */
.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.lesson-top .crumb { font-size: 13px; color: var(--muted); }
.lesson-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); grid-template-areas: "learn code" "coach code"; grid-template-rows: auto 1fr; gap: 18px; align-items: start; }
.pane-learn { grid-area: learn; } .pane-code { grid-area: code; } .pane-coach { grid-area: coach; }
.pane { min-width: 0; }
.learn { padding: 0; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--card-2); }
.tabs button { flex: 1; background: none; border: 0; padding: 12px 10px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--tram); background: var(--card); }
.tab-body { padding: 20px 22px 24px; }
.prose { max-width: 68ch; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 3px 0; }
.prose code { background: var(--card-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.prose pre { background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; line-height: 1.5; margin: 0 0 14px; }
.prose pre code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; }
.prose .tbl { overflow-x: auto; margin: 0 0 14px; }
.prose table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { font-weight: 600; background: var(--card-2); }
.headsup { margin: 0 0 16px; padding: 12px 14px; border-radius: 10px; background: var(--stop-soft); border: 1px solid color-mix(in srgb, var(--stop) 30%, var(--line)); font-size: 14px; }
.headsup b { color: var(--stop); }
.quiz { margin-top: 18px; padding: 16px; border-radius: 12px; border: 1px dashed var(--line); background: var(--card-2); }
.quiz pre { margin: 8px 0 12px; }
.quiz .opts { display: grid; gap: 8px; }
.quiz .opt { text-align: left; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-family: var(--font-mono); font-size: 13px; }
.quiz .opt:hover:not(:disabled) { border-color: var(--muted); }
.quiz .opt.right { border-color: var(--go); background: var(--go-soft); }
.quiz .opt.wrong { border-color: var(--stop); background: var(--stop-soft); }
.quiz .why { margin-top: 10px; font-size: 14px; }

.editor-card { overflow: hidden; }
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.editor-bar .grow { flex: 1; }
.editor-wrap { height: clamp(300px, 46vh, 560px); background: var(--code-bg); }
.editor-wrap textarea.fallback { width: 100%; height: 100%; background: var(--code-bg); color: var(--code-ink); border: 0; padding: 12px; font-family: var(--font-mono); font-size: 14px; resize: none; tab-size: 4; }
.stdin-note { padding: 8px 12px; font-size: 12.5px; background: var(--card-2); border-top: 1px solid var(--line); color: var(--muted); }
.stdin-note code { color: var(--ink); white-space: pre; }
.out { margin-top: 14px; }
.out-section { padding: 14px 16px; border-top: 1px solid var(--line); }
.out-section:first-child { border-top: 0; }
.term { background: var(--code-bg); color: var(--code-ink); border-radius: 9px; padding: 10px 12px; font-family: var(--font-mono); font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; margin: 0; }
.term.empty { color: var(--code-muted); }
.err-box { border-radius: 10px; border: 1px solid color-mix(in srgb, var(--stop) 45%, var(--line)); background: var(--stop-soft); padding: 12px 14px; }
.err-box .etype { font-family: var(--font-mono); font-weight: 700; color: var(--stop); }
.err-box .memory { margin-top: 8px; font-size: 13.5px; padding-top: 8px; border-top: 1px dashed color-mix(in srgb, var(--stop) 35%, var(--line)); }
.tests { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tests li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; font-size: 14px; align-items: start; }
.tests .ic { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; margin-top: 1px; }
.tests .ok .ic { background: var(--go); }
.tests .bad .ic { background: var(--stop); }
.tests .detail { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tests .detail code { font-size: 12px; background: var(--card-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; word-break: break-word; }
.tests .hidden-flag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; margin-left: 6px; }
.figs img { max-width: 100%; border-radius: 8px; background: #fff; border: 1px solid var(--line); margin-top: 8px; }
.win { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 12px; background: var(--go-soft); border: 1px solid color-mix(in srgb, var(--go) 40%, var(--line)); flex-wrap: wrap; }
.win .big { font-family: var(--font-display); font-size: 22px; font-weight: 800; color: var(--go); }
.hints { display: grid; gap: 8px; margin-top: 10px; }
.hint { padding: 10px 12px; border-radius: 9px; background: var(--info-soft); font-size: 14px; }
.coach { margin-top: 14px; }
.coach-head { display: flex; align-items: center; gap: 10px; }
.coach-avatar { width: 30px; height: 30px; border-radius: 8px; background: var(--ink); color: var(--tram); display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; }
.coach-log { position: relative; display: flex; flex-direction: column; gap: 10px; margin: 12px 0; max-height: clamp(200px, 42vh, 440px); overflow-y: auto; overscroll-behavior: contain; padding: 2px 4px 2px 0; }
.coach-log:empty { display: none; }
.coach-log .bubble { flex: none; }
.coach-log .bubble.old { opacity: .6; }
.bubble { padding: 10px 12px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; }
.bubble.me { background: var(--card-2); border: 1px solid var(--line); align-self: flex-end; max-width: 85%; }
.bubble.ai { background: var(--info-soft); }
.coach-form { display: flex; gap: 8px; }
.coach-form input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); }

/* ---------- gym ---------- */
.gym-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
.weak-list { display: grid; gap: 10px; }
.weak { padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.weak-top { display: flex; align-items: center; gap: 10px; }
.weak-top .nm { font-weight: 700; }
.weak-top .ct { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; }
.heat { height: 8px; border-radius: 4px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; margin: 8px 0; }
.heat > i { display: block; height: 100%; background: var(--stop); }
.weak p { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.drill { padding: 20px; }
.drill pre { background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 13px; margin: 10px 0 14px; white-space: pre; }
.log { display: grid; gap: 8px; }
.log-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 13.5px; }
.log-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.log-item code { font-size: 12px; }
.empty-state { padding: 26px; text-align: center; color: var(--muted); }

/* ---------- stats ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 36px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .track { height: 12px; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.bar-row .track i { display: block; height: 100%; border-radius: 6px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.bdg { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); }
.bdg.on { background: var(--card); border-color: var(--tram); box-shadow: inset 0 0 0 1px var(--tram); }
.bdg .bi { font-family: var(--font-display); font-weight: 800; font-size: 13px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: var(--muted); margin-bottom: 6px; }
.bdg.on .bi { background: var(--tram); color: var(--tram-ink); }
.bdg .bn { font-weight: 700; font-size: 14px; }
.bdg .bd { font-size: 12px; color: var(--muted); }

/* ---------- misc ---------- */
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; font-weight: 600; max-width: calc(100% - 32px); }
.modal-back { position: fixed; inset: 0; background: rgba(10, 17, 31, .55); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { max-width: 720px; width: 100%; max-height: 86vh; overflow: auto; padding: 22px; }
.modal pre { background: var(--code-bg); color: var(--code-ink); padding: 12px; border-radius: 10px; overflow-x: auto; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.spin { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { font-size: 13px; color: var(--muted); padding: 8px 12px; border-radius: 9px; background: var(--card-2); border: 1px solid var(--line); }

/* ---------- CodeMirror 5 core (inlined) + theme ---------- */
.CodeMirror { font-family: var(--font-mono); font-size: 14px; height: 100%; color: var(--code-ink); direction: ltr; position: relative; overflow: hidden; background: var(--code-bg); line-height: 1.55; }
.CodeMirror-lines { padding: 10px 0; cursor: text; min-height: 1px; }
.CodeMirror pre.CodeMirror-line, .CodeMirror pre.CodeMirror-line-like { padding: 0 10px; border-radius: 0; border-width: 0; background: transparent; font-family: inherit; font-size: inherit; margin: 0; white-space: pre; word-wrap: normal; line-height: inherit; color: inherit; z-index: 2; position: relative; overflow: visible; -webkit-tap-highlight-color: transparent; font-variant-ligatures: contextual; }
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { background-color: var(--code-bg); }
.CodeMirror-gutters { border-right: 1px solid var(--code-line); background-color: var(--code-bg); white-space: nowrap; position: absolute; left: 0; top: 0; min-height: 100%; z-index: 3; }
.CodeMirror-linenumber { padding: 0 8px 0 10px; min-width: 20px; text-align: right; color: var(--code-muted); white-space: nowrap; }
.CodeMirror-cursor { border-left: 2px solid var(--tram); border-right: none; width: 0; position: absolute; pointer-events: none; }
.CodeMirror-scroll { overflow: scroll !important; margin-bottom: -50px; margin-right: -50px; padding-bottom: 50px; height: 100%; outline: none; position: relative; z-index: 0; }
.CodeMirror-sizer { position: relative; border-right: 50px solid transparent; }
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler { position: absolute; z-index: 6; display: none; outline: none; }
.CodeMirror-vscrollbar { right: 0; top: 0; overflow-x: hidden; overflow-y: scroll; }
.CodeMirror-hscrollbar { bottom: 0; left: 0; overflow-y: hidden; overflow-x: scroll; }
.CodeMirror-scrollbar-filler { right: 0; bottom: 0; }
.CodeMirror-gutter-filler { left: 0; bottom: 0; }
.CodeMirror-gutter { white-space: normal; height: 100%; display: inline-block; vertical-align: top; margin-bottom: -50px; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: none !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0; bottom: 0; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-gutter-wrapper ::selection { background-color: transparent; }
.CodeMirror-linebackground { position: absolute; left: 0; right: 0; top: 0; bottom: 0; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; padding: .1px; }
.CodeMirror-code { outline: none; }
.CodeMirror-scroll, .CodeMirror-sizer, .CodeMirror-gutter, .CodeMirror-gutters, .CodeMirror-linenumber { box-sizing: content-box; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
div.CodeMirror-cursors { visibility: hidden; position: relative; z-index: 3; }
.CodeMirror-focused div.CodeMirror-cursors { visibility: visible; }
.CodeMirror-selected { background: var(--code-sel); }
.CodeMirror-focused .CodeMirror-selected { background: var(--code-sel); }
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: var(--code-sel); }
.cm-tab { display: inline-block; text-decoration: inherit; }
span.CodeMirror-selectedtext { background: none; }
.CodeMirror-matchingbracket { color: #fff !important; background: rgba(245, 194, 50, .25); }
.CodeMirror-activeline-background { background: rgba(255, 255, 255, .03); }
.cm-errline { background: rgba(240, 103, 91, .22); }
.cm-keyword { color: #c792ea; }
.cm-def { color: #82aaff; }
.cm-builtin { color: #ffcb6b; }
.cm-string, .cm-string-2 { color: #c3e88d; }
.cm-number { color: #f78c6c; }
.cm-comment { color: #6c7a91; font-style: italic; }
.cm-operator { color: #89ddff; }
.cm-variable-2 { color: #eeffff; }
.cm-property { color: #80cbc4; }
.cm-meta { color: #ffcb6b; }
.cm-atom { color: #f78c6c; }
.cm-error { color: #ff5370; }

@media (max-width: 980px) {
  .hero, .lesson-grid, .gym-grid { grid-template-columns: minmax(0, 1fr); }
  .lesson-grid { grid-template-areas: "learn" "code" "coach"; grid-template-rows: auto; }
  .worlds { grid-template-columns: minmax(0, 1fr); }
  .stats-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .hud .chip.hide-sm { display: none; }
  .nav { margin-left: 0; order: 3; width: 100%; }
  .nav button { flex: 1; padding: 7px 6px; }
  .nav .lg { display: none; }
  .tab-body { padding: 16px; }
  .mini-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 96px minmax(0, 1fr) 30px; }
  .log-item { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Traceback additions ---------- */
.account-chip { cursor: pointer; padding: 3px 10px 3px 4px; }
.account-chip img, .account-chip .initial { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.account-chip .initial { display: grid; place-items: center; background: var(--ink); color: var(--card); font-size: 12px; font-weight: 700; }
.account-chip .sync { font-size: 11px; color: var(--go); }
.account-chip .sync.syncing { color: var(--muted); }
.account-chip .sync.error { color: var(--stop); }
.coach-avatar { font-size: 13px; }
.coach-body { margin-top: 12px; display: grid; gap: 12px; max-height: clamp(220px, 44vh, 460px); overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; }
.coach-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; align-items: start; }
.coach-num { width: 24px; height: 24px; border-radius: 50%; background: var(--tram); color: var(--tram-ink); display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.coach-title { font-weight: 700; margin-bottom: 2px; }
.coach-text { font-size: 14px; }
.coach-text code { background: var(--card-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12.5px; word-break: break-word; }
.coach-line { background: var(--code-bg); color: var(--code-ink); padding: 6px 10px; border-radius: 8px; font-size: 12.5px; margin: 6px 0; overflow-x: auto; }
.coach-pattern { margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--stop-soft); font-size: 13.5px; }
.checklist { margin-top: 12px; font-size: 14px; }
.checklist summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.checklist ol { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 4px; }
.checklist code { font-size: 12.5px; }
.site-foot { max-width: 1280px; margin: 0 auto; padding-block: 0 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); font-size: 13px; display: grid; gap: 2px; color: var(--muted); }
