:root {
  --bg: #f5f7fb;
  --bg2: #eef2f8;
  --card: #ffffff;
  --card2: #f1f5fb;
  --line: #dfe5ef;
  --text: #1c1d1f;
  --muted: #5c6370;
  --accent: #1e5bd8;
  --accent-ink: #ffffff;
  --accent2: #1e5bd8;
  --gold: #e8900c;
  --danger: #d93025;
  --ok: #1a7f37;
  --code-bg: #0f1629;
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c111d; --bg2: #121a2b; --card: #161f33; --card2: #1c2740; --line: #2a3650;
    --text: #eef2ff; --muted: #9aa6c4; --accent: #5b8cff; --accent-ink: #ffffff; --accent2: #7aa2ff;
    --gold: #ffc857; --danger: #ff6b6b; --ok: #3ddc84;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c111d; --bg2: #121a2b; --card: #161f33; --card2: #1c2740; --line: #2a3650;
  --text: #eef2ff; --muted: #9aa6c4; --accent: #5b8cff; --accent-ink: #ffffff; --accent2: #7aa2ff;
  --gold: #ffc857; --danger: #ff6b6b; --ok: #3ddc84;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The page scrolls up and down only. Code blocks and the editor still scroll sideways inside themselves. */
html, body { margin: 0; padding: 0; overscroll-behavior-x: none; }
/* hidden on html goes to the viewport; clip on body stops sideways scroll without making body a scroll container,
   which would break every position: sticky element (the top bar and the 3D stage). */
html { overflow-x: hidden; }
body { overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent2); text-decoration: none; }
h1 { font-size: 1.55rem; line-height: 1.2; margin: 0.2em 0 0.3em; }
h2 { font-size: 1.2rem; }
h3 { margin: 0 0 0.4em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }

/* top bar + tab bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 800; letter-spacing: 0.2px; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.top-stats { display: flex; gap: 6px; align-items: center; }
.pill { background: var(--card2); border: 1px solid var(--line); padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.pill.level { color: var(--accent); }
.pill.dim { opacity: 0.55; }
.py-status { display: flex; align-items: center; gap: 5px; font-size: 0.75rem; color: var(--muted); }
.py-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: pulse 1.2s infinite; }
.py-status[data-state="ready"] i { background: var(--ok); animation: none; }
.py-status[data-state="error"] i { background: var(--danger); animation: none; }
@keyframes pulse { 50% { opacity: 0.3; } }
@media (max-width: 380px) { .py-status span { display: none; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b));
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; font-size: 0.72rem; color: var(--muted); padding: 4px 0; border-radius: 12px; }
.tabbar a span { font-size: 1.35rem; line-height: 1.2; }
.tabbar a.active { color: var(--accent); background: var(--card); }
body.editing .tabbar { display: none; }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px); outline: none; }
.view { animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* cards & buttons */
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; color: var(--text); }
a.card:active { transform: scale(0.99); }
.section-title { margin: 22px 0 6px; display: flex; gap: 8px; align-items: baseline; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card2); color: var(--text);
  font: inherit; font-weight: 650; font-size: 0.95rem; padding: 10px 14px; border-radius: 12px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.back { display: inline-block; margin: 4px 0 6px; font-weight: 600; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* path */
.hero { background: linear-gradient(135deg, var(--card2), var(--card)); }
.hero-top { display: flex; gap: 14px; align-items: center; }
.hero h1 { margin: 0; }
.avatar { width: 58px; height: 58px; flex: none; display: grid; place-items: center; font-size: 2rem; border-radius: 18px; background: var(--bg2); border: 1px solid var(--line); }
.rank { color: var(--accent); font-weight: 700; }
.xpbar { height: 12px; border-radius: 99px; background: var(--bg2); margin-top: 14px; overflow: hidden; border: 1px solid var(--line); }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 99px; transition: width 0.6s; }
.xpbar-label { display: flex; justify-content: space-between; margin-top: 4px; }
.done-all { margin-top: 12px; font-weight: 700; color: var(--gold); }
.review { display: flex; gap: 12px; align-items: center; border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.review.done { opacity: 0.7; }
.review-icon { font-size: 1.6rem; }
.install { position: relative; border-color: var(--accent2); padding-right: 40px; }
.install .x { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 1rem; padding: 6px; }
.module { display: flex; gap: 12px; align-items: center; }
.module.locked { opacity: 0.5; }
.module.complete { border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); }
.module-icon { font-size: 1.8rem; width: 46px; height: 46px; display: grid; place-items: center; background: var(--bg2); border-radius: 14px; flex: none; }
.module-body { flex: 1; min-width: 0; }
.module-title { font-weight: 700; }
.module-count { font-weight: 700; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.mini-bar { height: 6px; background: var(--bg2); border-radius: 9px; margin-top: 8px; overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: 9px; }
.mini-bar.wide { height: 8px; margin: 8px 0 12px; }

/* module */
.module-head { display: flex; gap: 14px; align-items: center; }
.big-icon { font-size: 2.6rem; }
.track-card { display: flex; align-items: center; gap: 14px; padding: 18px; color: var(--text); }
.track-card h2 { margin: 0 0 4px; font-size: 1.25rem; }
.track-card p { margin: 0; }
.soon { opacity: 0.6; }
.banner { border-left: 4px solid var(--gold); font-size: 0.9rem; }
.sandbox-3d { width: 100%; height: 300px; display: block; border-radius: var(--radius); touch-action: none; cursor: grab; background: #0b1020; }
/* The 3D stage: zoom buttons and a message strip over the canvas. The main stage stays in view while you scroll. */
.stage { position: relative; }
.sim-stage-col { position: sticky; top: calc(49px + var(--safe-t)); z-index: 15; }
.stage-main { margin: 10px 0; }
.stage-main .sandbox-3d { height: min(300px, 40vh); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.stage-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.stage-btn { min-width: 34px; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(11, 16, 32, 0.72); color: #e8ecff; font: inherit; font-size: 0.85rem; font-weight: 700; cursor: pointer; }
.stage-btn:hover { background: rgba(40, 52, 90, 0.9); }
/* At the top, under the zoom buttons, so it is on screen even when the bottom of a tall stage is below the fold. */
.stage-alert { position: absolute; left: 8px; right: 8px; top: 50px; padding: 8px 10px; border-radius: 8px; background: rgba(200, 30, 50, 0.92); color: #fff; font-size: 0.85rem; font-weight: 700; line-height: 1.35; }
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.readout span { display: block; font-size: 0.72rem; color: var(--muted); }
.readout b { font-size: 1rem; font-variant-numeric: tabular-nums; }
.health { grid-column: 1 / -1; font-weight: 700; }
.health.ok, .ik-result.ok { color: var(--ok); }
.health.warn { color: var(--gold); }
.health.bad, .ik-result.bad { color: var(--danger); }
.joint-row { display: grid; grid-template-columns: 34px 1fr 76px 74px; gap: 8px; align-items: center; padding: 4px 0; }
.joint-row.at-limit .j-slider { accent-color: var(--danger); }
.robotics-sandbox input[type=number], .robotics-sandbox select { width: 100%; padding: 6px 8px; background: var(--code-bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.target-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.target-grid label { display: grid; gap: 4px; }
.dh-wrap { overflow-x: auto; margin-top: 8px; }
.dh th, .dh td { padding: 3px; font-size: 0.8rem; text-align: left; }
.dh input { min-width: 58px; }
.mode-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mode-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.jog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.jog { min-height: 48px; font-weight: 700; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.jog-hint { margin: 8px 0 0; }
.io-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin: 6px 0; }
.io-btn:disabled { opacity: 0.85; cursor: default; }
.io-btn, .io-led { font-size: 0.68rem; padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); text-align: center; font-weight: 700; }
.io-btn.on, .io-led.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.program { width: 100%; font-family: var(--mono); background: var(--code-bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px; line-height: 1.5; resize: vertical; }
.status-card.is-error { border-color: var(--danger); }
.status-line { font-size: 1rem; margin-bottom: 8px; }
.log { margin-top: 10px; max-height: 220px; overflow-y: auto; font-family: var(--mono); font-size: 0.85rem; background: var(--code-bg); border-radius: 10px; padding: 8px 10px; }
.log > div { padding: 2px 0; }
.log-error { color: var(--danger); font-weight: 700; }
.log-info { color: var(--text); }
.log-fault { color: var(--gold); font-weight: 700; }
.shortcuts p { margin: 6px 0 0; color: var(--muted); }
.program-view { position: relative; margin: 8px 0 0; max-height: 240px; overflow: auto; font-family: var(--mono); font-size: 0.85rem; line-height: 1.5; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 0; }
.program-view[hidden] { display: none; }
.program-view > div { padding: 0 10px; white-space: pre; }
.program-view .current { background: color-mix(in srgb, var(--accent) 22%, transparent); font-weight: 700; }
.program-view .ln { display: inline-block; width: 28px; color: var(--muted); user-select: none; }
.sub { margin-top: 12px; font-size: 1rem; }
.io-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.io-list .io-led { display: block; text-align: left; padding: 6px 8px; font-size: 0.72rem; }
.ladder { margin-top: 10px; display: grid; gap: 8px; }
.rung { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.rung .line-no { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; }
.rung .branches { display: grid; gap: 6px; border-left: 3px solid var(--line); padding-left: 8px; }
.rung .branch { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.contact { font-family: var(--mono); font-size: 0.8rem; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); color: var(--muted); }
.contact.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.coil { font-family: var(--mono); font-size: 0.8rem; padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); white-space: nowrap; }
.coil.on { background: var(--gold); color: #1a1400; border-color: var(--gold); }
.scan-state { margin-top: 8px; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--code-bg); padding: 1px 5px; border-radius: 6px; }
.track-icon { font-size: 2.4rem; width: 64px; height: 64px; flex: none; display: grid; place-items: center; background: var(--bg2); border-radius: 18px; }
.lesson-row { display: flex; align-items: center; gap: 12px; margin: 8px 0; padding: 12px 14px; }
.lesson-num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--bg2); font-weight: 700; flex: none; }
.lesson-row.done .lesson-num { background: var(--accent); color: var(--accent-ink); }
.lesson-row.project { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); background: linear-gradient(135deg, color-mix(in srgb, var(--danger) 12%, var(--card)), var(--card)); }
.lesson-title { flex: 1; font-weight: 600; }
.xp-tag { font-size: 0.78rem; font-weight: 800; color: var(--gold); background: color-mix(in srgb, var(--gold) 14%, transparent); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }

/* exercise */
.ex-top { display: flex; justify-content: space-between; align-items: center; }
.ex-title { margin-top: 4px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700; padding: 8px; border-radius: 9px; min-height: 40px; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.prose h2 { font-size: 1.25rem; margin: 0.2em 0 0.5em; }
.prose h3 { font-size: 1.08rem; margin: 1em 0 0.3em; }
.prose h4 { margin: 1em 0 0.3em; }
.prose p, .prose li { color: var(--text); }
.prose code { white-space: pre-wrap; font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); padding: 1px 5px; border-radius: 6px; border: 1px solid var(--line); }
.prose ul, .prose ol { padding-left: 1.3em; }
.code-block { position: relative; margin: 10px 0; }
.code-block pre { margin: 0; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow-x: auto; font: 0.85rem/1.5 var(--mono); }
.code-block pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.try-it { position: absolute; top: 6px; right: 6px; font: 600 0.75rem/1 inherit; background: var(--card2); color: var(--accent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.tip { background: color-mix(in srgb, var(--accent2) 14%, transparent); border-left: 3px solid var(--accent2); padding: 8px 12px; border-radius: 8px; margin: 10px 0; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; margin: 8px 0; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 700; }
.hint-item { background: color-mix(in srgb, var(--gold) 12%, transparent); border-radius: 10px; padding: 8px 12px; margin-top: 8px; }
.hint-item p { display: inline; }

/* editor */
.editor { margin: 12px 0 0; }
.editor-cm { border: 1px solid var(--line); border-radius: 14px 14px 0 0; overflow: hidden; background: var(--code-bg); }
.editor .CodeMirror { height: auto; min-height: 180px; font-family: var(--mono); line-height: 1.55; background: var(--code-bg); color: var(--text); }
.editor .CodeMirror-scroll { min-height: 180px; }
.editor .CodeMirror-gutters { background: var(--code-bg); border-right: 1px solid var(--line); }
.editor .CodeMirror-linenumber { color: var(--muted); opacity: 0.6; }
.editor .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.editor .CodeMirror-activeline-background { background: color-mix(in srgb, var(--accent2) 8%, transparent); }
.editor .CodeMirror-selected, .editor .CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--accent2) 30%, transparent); }
.editor .CodeMirror-matchingbracket { color: var(--accent) !important; text-decoration: underline; }
.editor .error-line { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.keybar { background: var(--bg2); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 14px 14px; padding: 6px; transition: transform 0.12s; }
.editor.focused .keybar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; border-radius: 0; border-left: 0; border-right: 0; border-top: 1px solid var(--line); padding-bottom: 6px; }
.keybar .chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-height: 0; }
.keybar .chips:not(:empty) { margin-bottom: 6px; min-height: 34px; }
.keybar .chips::-webkit-scrollbar, .keybar .keys::-webkit-scrollbar { display: none; }
.keybar .chip { flex: none; font: 600 0.88rem var(--mono); padding: 6px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--accent); }
.keybar .chip.t-keyword { color: #c792ea; }
.keybar .chip.t-function, .keybar .chip.t-class { color: var(--accent2); }
.keybar .keys { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; }
.keybar .keys button { flex: none; min-width: 38px; height: 38px; font: 600 1rem var(--mono); border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 0 8px; }
.keybar .keys button:active, .keybar .chip:active { background: var(--accent); color: var(--accent-ink); }
.CodeMirror-hints { background: var(--card); border: 1px solid var(--line); font-family: var(--mono); z-index: 50; }
.CodeMirror-hint { color: var(--text); }
li.CodeMirror-hint-active { background: var(--accent); color: var(--accent-ink); }

/* syntax colors (editor + lesson code) */
.cm-s-typequest .cm-keyword, .cm-keyword { color: #c792ea; }
.cm-s-typequest .cm-def, .cm-def { color: #82aaff; }
.cm-s-typequest .cm-builtin, .cm-builtin { color: #ffcb6b; }
.cm-s-typequest .cm-string, .cm-string { color: #c3e88d; }
.cm-s-typequest .cm-number, .cm-number { color: #f78c6c; }
.cm-s-typequest .cm-comment, .cm-comment { color: #7f8bb8; font-style: italic; }
.cm-s-typequest .cm-operator, .cm-operator { color: #89ddff; }
.cm-s-typequest .cm-variable-2, .cm-variable-2 { color: #f07178; }
.cm-s-typequest .cm-property, .cm-property { color: #b2ccd6; }
.cm-s-typequest .cm-meta, .cm-meta { color: #ffcb6b; }

/* stdin, actions, output */
.stdin { margin: 10px 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.stdin summary { cursor: pointer; font-weight: 600; }
.stdin textarea { width: 100%; margin-top: 8px; background: var(--code-bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: 0.9rem var(--mono); padding: 8px; resize: vertical; }
.actions { display: grid; grid-template-columns: 1fr 1.2fr 1fr auto; gap: 8px; margin: 10px 0; }
.playground .actions { grid-template-columns: 1.4fr 1fr 1fr; }
.more-menu { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.output:empty { display: none; }
.output { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-top: 4px; }
.out-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 4px; }
.out-text, .out-error pre, .results pre, .doc-text { font: 0.85rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 0; }
.out-error { margin-top: 10px; border-left: 3px solid var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 8px 10px; border-radius: 8px; }
.out-error pre { color: var(--danger); }
.err-tip { margin-top: 8px; font-size: 0.9rem; }
.out-pass { font-weight: 800; color: var(--ok); font-size: 1.1rem; }
.out-fail { font-weight: 700; color: var(--gold); }
.out-status { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.results { list-style: none; margin: 8px 0 0; padding: 0; }
.results li { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.results li:last-child { border-bottom: 0; }
.results li > span { font-weight: 900; width: 1.2em; flex: none; }
.results li.ok > span { color: var(--ok); }
.results li.bad > span { color: var(--danger); }
.results pre { color: var(--muted); margin-top: 4px; }
.out-details { margin-top: 8px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* docs */
.search { display: flex; gap: 8px; }
.search input, .profile input:not([type=range]):not([type=checkbox]), .auth input {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chips-row .chip { font: 600 0.8rem var(--mono); padding: 6px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--accent2); cursor: pointer; }
.doc-card { overflow: hidden; }
.doc-title { margin-bottom: 8px; font-weight: 700; }
.doc-text { max-height: 70vh; overflow: auto; }
.guide { display: flex; justify-content: space-between; font-weight: 650; }

/* profile */
.profile-row { display: flex; gap: 12px; align-items: center; }
.profile-row .grow { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.big-avatar { cursor: pointer; font-size: 2.1rem; }
.avatar-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 12px; }
.avatar-picker button { font-size: 1.5rem; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 4px 0; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 480px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat { text-align: center; margin: 0; padding: 12px 6px; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.auth { display: flex; flex-direction: column; gap: 8px; }
.sync-line.ok { color: var(--ok); } .sync-line.error { color: var(--danger); } .sync-line.offline { color: var(--gold); }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.badge { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; opacity: 0.4; filter: grayscale(1); }
.badge.earned { opacity: 1; filter: none; border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); }
.badge-icon { font-size: 1.7rem; }
.badge-name { font-size: 0.78rem; font-weight: 700; margin-top: 2px; }
.badge-desc { font-size: 0.68rem; color: var(--muted); }
.setting { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.setting.toggle { flex-direction: row; justify-content: space-between; align-items: center; }
.setting.toggle input { width: 24px; height: 24px; accent-color: var(--accent); }
.setting input[type=range] { accent-color: var(--accent); }
.setting-buttons { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; }
.offline-state { margin-top: 4px; }

/* toasts, modals, confetti */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { pointer-events: auto; background: var(--card2); border: 1px solid var(--line); color: var(--text); padding: 10px 14px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); display: flex; gap: 12px; align-items: center; opacity: 0; transform: translateY(10px); transition: 0.25s; max-width: 520px; }
.toast.show { opacity: 1; transform: none; }
.toast button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 6px 10px; font-weight: 700; }
.modal-back { position: fixed; inset: 0; z-index: 70; background: rgba(3, 6, 18, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade 0.15s; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: 100%; max-width: 440px; max-height: 85vh; overflow: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }
.sheet { max-width: 680px; align-self: flex-end; border-radius: 20px 20px 0 0; margin-bottom: calc(-16px - var(--safe-b)); padding-bottom: calc(20px + var(--safe-b)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.celebrate { text-align: center; }
.celebrate .big { font-size: 3.4rem; }
.celebrate h2 { margin: 0.2em 0; }
.celebrate .gain { font-size: 1.8rem; font-weight: 900; color: var(--gold); margin: 6px 0; }
.levelup { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 12px; padding: 8px; margin: 8px 0; font-weight: 700; }
.new-badge { margin: 6px 0; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall 2.2s ease-in forwards; }
@keyframes fall { to { top: 105vh; transform: translateX(40px) rotate(720deg); } }

/* --- multi-language ------------------------------------------------------ */
.lang-switch { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 2px -16px 6px; padding: 2px 16px 4px; }
.lang-switch::-webkit-scrollbar { display: none; }
.lang-chip { flex: none; display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 650; font-size: 0.88rem; }
.lang-chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lang-chip .lang-pct { font-size: 0.72rem; opacity: 0.75; font-weight: 700; }
.lang-icon { font-size: 1.15rem; }
.lang-intro .section-title { margin-bottom: 0; }
.lang-intro p { margin: 2px 0 0; }
.track-title { margin: 18px 0 2px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.track-title .small { text-transform: none; letter-spacing: 0; }
.career { display: flex; gap: 12px; align-items: center; background: linear-gradient(135deg, color-mix(in srgb, var(--accent2) 12%, var(--card)), var(--card)); }
.career.locked { opacity: 0.6; }
.career-icon { font-size: 1.9rem; width: 50px; height: 50px; display: grid; place-items: center; background: var(--bg2); border-radius: 14px; flex: none; }
.career-body { flex: 1; min-width: 0; }
.career-head { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--card2), var(--card)); }
.career-head h1 { margin: 0; }
.skills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.skill { font-size: 0.78rem; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.locked-note { border-color: var(--gold); }
.pack { display: flex; gap: 12px; align-items: center; justify-content: space-between; border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.pack .btn { flex: none; }
.preview-wrap { margin: 10px 0; }
.preview { width: 100%; height: 280px; border: 1px solid var(--line); border-radius: 12px; background: #fff; display: block; }
.preview.tall { height: 380px; }
.grade-frame { position: fixed; left: -10000px; top: 0; width: 1024px; height: 768px; border: 0; visibility: hidden; pointer-events: none; }
.lang-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.lang-row:last-child { border-bottom: 0; }
.lang-row-main { display: flex; gap: 10px; align-items: center; color: var(--text); }
.lang-row-main .grow { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lang-row-main .mini-bar { margin-top: 2px; }
.pack-state { margin: 6px 0 0 34px; }
.pack-state .ok { color: var(--ok); font-weight: 600; }
.link { background: none; border: 0; color: var(--accent2); font: inherit; padding: 0 4px; cursor: pointer; text-decoration: underline; }
.small-btn { min-height: 34px; padding: 6px 10px; font-size: 0.82rem; }
.sheet-body { max-height: 65vh; overflow: auto; }
.sheet-body hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.cm-s-typequest .cm-tag, .cm-tag { color: #f07178; }
.cm-s-typequest .cm-attribute, .cm-attribute { color: #ffcb6b; }
.cm-s-typequest .cm-type, .cm-type, .cm-variable-3 { color: #ffcb6b; }
.cm-s-typequest .cm-atom, .cm-atom { color: #f78c6c; }
.cm-s-typequest .cm-qualifier, .cm-qualifier { color: #c3e88d; }
/* iPhone Safari zooms the page whenever a field with a font under 16px is focused, and it stays zoomed
   while you type. Every typing field uses 16px, so the page never zooms. The visible code keeps its size. */
input, textarea, select, .CodeMirror textarea { font-size: 16px !important; }
.state-badge { display: inline-block; font-weight: 800; padding: 4px 12px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); }
.state-badge.normal { background: var(--ok); color: #04241d; border-color: var(--ok); }
.state-badge.slowed { background: var(--gold); color: #1a1400; border-color: var(--gold); }
.state-badge.protective-stop, .state-badge.emergency-stop { background: var(--danger); color: #2a0008; border-color: var(--danger); }
.state-reason { margin: 8px 0 10px; }
.risk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.risk-grid label { display: grid; gap: 4px; font-size: 0.85rem; }
.risk-result { margin-top: 8px; }
.risk-low { color: var(--ok); }
.risk-medium { color: var(--gold); }
.risk-high { color: var(--danger); }
.quiz-item { border-top: 1px solid var(--line); padding: 10px 0; }
.quiz-item .btn { display: block; width: 100%; margin: 4px 0; text-align: left; white-space: normal; }
.quiz-why { margin-top: 6px; }
.quiz-why.ok { color: var(--ok); }
.quiz-why.bad { color: var(--danger); }


/* ===== Visual refresh: a clean, course-platform look (light by default, dark on request) ===== */
h1 { font-size: 1.75rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); backdrop-filter: none; -webkit-backdrop-filter: none; }
.brand { font-size: 1.05rem; font-weight: 800; color: var(--text); }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; color: var(--text); }
.pill.level { color: var(--accent); }
.tabbar { background: var(--card); border-top: 1px solid var(--line); backdrop-filter: none; -webkit-backdrop-filter: none; }
.tabbar a { font-weight: 600; color: var(--muted); }
.tabbar a span { font-size: 1.3rem; }
.tabbar a.active { color: var(--accent); background: transparent; }
main { max-width: 1040px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05); }
.btn { border-radius: 8px; font-weight: 600; background: var(--card); border: 1px solid var(--line); color: var(--text); }
.btn:hover { background: var(--card2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(0.95); background: var(--accent); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.hero { background: linear-gradient(120deg, #1e5bd8 0%, #3b82f6 100%); color: #fff; border: 0; box-shadow: 0 6px 20px rgba(30, 91, 216, 0.25); }
.hero h1, .hero .rank, .hero .muted, .hero .small { color: #fff; }
.hero .muted, .hero .small { opacity: 0.9; }
.hero .avatar { background: rgba(255, 255, 255, 0.18); border: 0; }
.hero .xpbar { background: rgba(255, 255, 255, 0.28); border: 0; }
.hero .xpbar i { background: #fff; }
.hero .btn.primary { background: #fff; color: var(--accent); border-color: #fff; }
.xpbar { background: var(--bg2); border: 0; }
.xpbar i { background: var(--accent); }
.mini-bar { background: var(--bg2); }
.mini-bar i { background: var(--accent); }
.track-card { padding: 18px; border-radius: var(--radius); }
.track-icon, .module-icon, .career-icon, .lesson-num, .avatar { background: var(--bg2); }
.module-count, .muted { color: var(--muted); }
.lang-chip { border-radius: 999px; font-weight: 600; }
.lang-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { background: var(--bg2); }
.install { border-color: var(--accent); }
.badge.earned { border-color: var(--accent); }
.tracks, .robotics { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) {
  .tracks, .robotics { grid-template-columns: 1fr 1fr; }
  .tracks .hero, .robotics .hero, .tracks .robo-progress, .robotics .robo-progress { grid-column: 1 / -1; }
  main { padding-top: 20px; }
}
/* Wide screens: navigation becomes a sidebar, like a course platform. */
@media (min-width: 1040px) {
  .tabbar {
    top: 0; bottom: 0; right: auto; width: 232px; z-index: 25;
    display: flex; flex-direction: column; gap: 2px; padding: 84px 12px 20px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tabbar a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; font-size: 0.98rem; border-radius: 10px; }
  .tabbar a .tab-icon { flex: none; margin: 0; }
  .tabbar a span { font-size: 1.2rem; }
  .tabbar a:hover { background: var(--card2); }
  .tabbar a.active { background: var(--card2); color: var(--accent); }
  .topbar { position: fixed; left: 0; right: 0; top: 0; z-index: 30; padding-left: 24px; padding-right: 24px; }
  main { max-width: 920px; margin: 0; padding-top: 84px; padding-left: 280px; padding-right: 32px; }
  #toasts { left: 232px; }
}
.lesson-row.locked { opacity: 0.55; pointer-events: none; }
.lesson-row.open { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent); }
.lesson-row.done .xp-tag { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.lesson-row.open .xp-tag { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.checks li.done { color: var(--ok); }
.checks .tick { width: 1.2em; font-weight: 800; }
.summary { width: 100%; font: inherit; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; background: transparent; border: 0; padding: 0; margin: 12px 0; }
.tabs button { flex: 1 1 auto; min-width: 120px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 600; min-height: 40px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool-card .tool-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.tool-card h3 { margin: 0; }
.tool-type { font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.tool-type.open-source { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.tool-type.free-proprietary { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.tool-type.trial-only { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.glossary dt { font-weight: 700; margin-top: 12px; }
.glossary dd { margin: 2px 0 0; color: var(--muted); }
.frames-table { width: 100%; }
.frames-table th { width: 30%; }
.dh-wrap, .frames-view { max-width: 100%; }
.plot { width: 100%; height: auto; max-width: 320px; display: block; margin: 8px auto; background: var(--card); border-radius: 10px; }
.progress-note { display: block; margin-top: 4px; font-weight: 600; color: var(--accent); }
.docs-link { margin-bottom: 12px; }

/* Text marks and line icons (no emoji) */
.tab-icon { display: block; width: 24px; height: 24px; margin: 0 auto 2px; }
.tab-icon svg, .track-icon svg, .big-icon svg, .lesson-num svg { width: 100%; height: 100%; display: block; }
.track-icon svg, .big-icon svg { width: 28px; height: 28px; color: var(--accent); }
.big-icon, .module-icon, .career-icon, .track-icon, .badge-icon {
  font-weight: 800; color: var(--accent); letter-spacing: -0.02em;
}
.module-icon, .career-icon, .track-icon { font-size: 0.95rem; }
.big-icon { font-size: 1.4rem; width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--bg2); flex: none; }
.module-icon svg, .career-icon svg { width: 20px; height: 20px; color: var(--muted); }
.badge-icon { width: 42px; height: 42px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; background: var(--card2); font-size: 0.9rem; }
.badge:not(.earned) .badge-icon { color: var(--muted); }
.lang-icon { font-size: 0.78rem; font-weight: 800; color: var(--accent); min-width: 1.6em; text-align: center; }
.lesson-num svg { width: 18px; height: 18px; color: var(--muted); }
.lesson-row.done .lesson-num svg { color: #fff; }
.avatar { font-weight: 800; color: var(--accent); font-size: 1.2rem; }
.hero .avatar { color: #fff; }
.big-avatar { font-size: 1.8rem; }

.lang-chip.active .lang-icon { color: #fff; }

/* ===== Native desktop look (wide screens only; phones keep the layout above) =====
   A quieter macOS-style window: a grey sidebar, a thin toolbar, flat cards and regular weights. */
@media (min-width: 1040px) {
  html { font-size: 15px; -webkit-font-smoothing: antialiased; }
  :root { --radius: 10px; }
  .topbar { background: var(--bg); border-bottom-color: transparent; box-shadow: 0 1px 0 var(--line); height: 52px; cursor: default; user-select: none; }
  .brand { font-size: 0.98rem; font-weight: 600; }
  .brand img { width: 24px; height: 24px; border-radius: 6px; }
  .pill { background: transparent; border-color: var(--line); font-weight: 600; }
  .tabbar {
    background: color-mix(in srgb, var(--bg) 92%, var(--text));
    border-right: 1px solid var(--line);
    padding-top: 64px;
    cursor: default; user-select: none;
  }
  .tabbar a { font-weight: 500; color: var(--text); font-size: 0.92rem; padding: 7px 10px; }
  .tabbar a span { font-size: 1.05rem; }
  .tabbar a .tab-icon { width: 18px; height: 18px; color: var(--muted); }
  .tabbar a:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
  .tabbar a.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 600; }
  .tabbar a.active .tab-icon { color: var(--accent); }
  main {
    margin-left: 232px; max-width: none; width: calc(100% - 232px);
    padding: 64px 40px 40px;
    box-sizing: border-box;
  }
  main > * { max-width: 960px; }
  /* Simulators: the 3D view in a sticky column beside the controls, so you can watch the arm while you press buttons. */
  main > .robotics-host:has(.sim-layout) { max-width: 1440px; }
  .sim-layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, 1fr); gap: 20px; align-items: start; }
  .sim-stage-col { top: 64px; }
  .sim-panel > .card:first-child { margin-top: 10px; }
  .stage-main .sandbox-3d { height: calc(100vh - 96px); min-height: 340px; max-height: 760px; }
  .card { box-shadow: none; }
  h1 { font-size: 1.45rem; font-weight: 650; }
  h2 { font-weight: 650; }
  /* The welcome block is a plain tinted card, not a gradient banner. */
  .hero { background: color-mix(in srgb, var(--accent) 10%, var(--card)); color: var(--text); box-shadow: none; border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line)); }
  .hero h1, .hero .rank, .hero .muted, .hero .small { color: var(--text); }
  .hero .avatar { background: var(--card); color: var(--accent); }
  .hero .xpbar { background: var(--card); }
  .hero .xpbar i { background: var(--accent); }
  .hero .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  /* Language chips wrap onto a second line instead of running off the edge. */
  .lang-switch { flex-wrap: wrap; overflow: visible; margin: 2px 0 10px; padding: 0; }
  .lang-chip { font-weight: 500; padding: 6px 11px; }
  .btn { font-weight: 500; padding-top: 7px; padding-bottom: 7px; }
  .btn, .lang-chip, .tabs button { cursor: default; }
}

/* Code surfaces stay dark in both themes (the syntax colours are a dark theme), so their text is always light. */
:root { --code-ink: #e6ebff; --code-muted: #8f9bc0; }
.program, .log, .log-info, .program-view, .rung, code, .prose code, .code-block pre, .editor .CodeMirror, .stdin textarea,
.robotics-sandbox input[type=number], .robotics-sandbox select { color: var(--code-ink); }
.program-view .ln, .rung .line-no, .editor .CodeMirror-linenumber { color: var(--code-muted); }
