:root {
  --bg: #eef1ed; --panel: #ffffff; --panel-2: #f5f7f4; --border: #cfd8d1;
  --text: #1b2621; --text-dim: #55685e;
  --accent: #1a7f52; --accent-soft: #e1f1e8; --on-accent: #ffffff;
  --warn: #8a5f0f; --warn-soft: #f7ecd6;
  --err: #b3444a;
  --font-ui: 'Sora', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1210; --panel: #121a17; --panel-2: #0f1614; --border: #26352d;
    --text: #dde9e2; --text-dim: #8fa69b;
    --accent: #5fe3a0; --accent-soft: #173425; --on-accent: #06140d;
    --warn: #e8c068; --warn-soft: #332a12;
    --err: #f08a8f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 15px; line-height: 1.5; }
#app { max-width: 1120px; margin: 0 auto; padding: 20px 16px 32px; display: flex; flex-direction: column; gap: 18px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }
code, .mono { font-family: var(--font-mono); }
.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }
.warn-text { color: var(--warn); }

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, a.primary {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 9px;
  padding: 10px 16px; font-weight: 600; font-size: 14px;
}
button.primary:hover, a.primary:hover { filter: brightness(1.08); }
button.ghost, a.ghost {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 11px; font-size: 13px; font-weight: 600;
}
button.ghost:hover, a.ghost:hover { color: var(--text); border-color: var(--accent); }
button.ghost.small { padding: 3px 8px; font-size: 11.5px; }
button.link {
  background: none; border: 0; padding: 0; color: var(--text-dim); font-size: 12.5px;
  text-decoration: underline; text-underline-offset: 3px; align-self: flex-start;
}
button.link:hover, button.link[data-armed] { color: var(--warn); }
.muted-on-primary { font-weight: 400; opacity: .85; }

.badge {
  font-size: 11px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase;
  border: 1px solid var(--border); color: var(--text-dim); border-radius: 5px; padding: 2px 7px; white-space: nowrap;
}
.badge.ok { color: var(--accent); border-color: var(--accent); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.tag {
  font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 3px 8px;
}
.icon {
  font-family: var(--font-mono); font-weight: 600; font-size: 13px; color: var(--accent);
  background: var(--accent-soft); border-radius: 7px; padding: 3px 7px; min-width: 38px; text-align: center;
}
.bar { height: 6px; flex: none; width: 100%; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width .3s ease; }

/* header */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand h1 { font-size: 21px; }
.brand span, .top-stats { font-size: 13px; color: var(--text-dim); }
.top-stats b { color: var(--accent); font-family: var(--font-mono); }

/* home */
.hero { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; max-width: 68ch; }
.hero p { color: var(--text-dim); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tcard, .final {
  text-align: left; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.tcard:hover:not(:disabled) { border-color: var(--accent); }
.tcard.soon { opacity: .62; }
.tcard p, .final p { font-size: 13.5px; color: var(--text-dim); }
.tcard-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.tcard-title { font-weight: 700; font-size: 16px; margin-right: auto; }
.tcard-foot { display: flex; gap: 12px; font-size: 12.5px; color: var(--text-dim); flex-wrap: wrap; }
.final { border-style: dashed; }
.final.locked .icon { color: var(--text-dim); background: var(--panel-2); }
.reqs { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-dim); }
.reqs li.ok { color: var(--accent); }
footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 14px; }

/* track screen */
.track-head { display: flex; flex-direction: column; gap: 10px; max-width: 72ch; }
.track-head h1 { font-size: 22px; display: flex; align-items: center; gap: 8px; }
.track-head p { color: var(--text-dim); }
.sol-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.levels { display: flex; flex-direction: column; gap: 10px; }
.lcard { display: flex; gap: 14px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.lcard.complete { border-color: var(--accent); }
.lnum {
  flex: 0 0 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 600; background: var(--accent-soft); color: var(--accent);
}
.lbody { flex: 1 1 auto; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ltitle { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lbody p { font-size: 13px; color: var(--text-dim); }
.lmeta { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--text-dim); flex-wrap: wrap; }
.lmeta .bar { flex: 1 1 120px; width: auto; max-width: 180px; }
@media (max-width: 640px) { .lcard { flex-wrap: wrap; } .lcard > button { width: 100%; } }

/* play */
.playbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--text-dim); }
.crumbs b { color: var(--text); }
.dots { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.mdot { width: 14px; height: 14px; padding: 0; border-radius: 4px; border: 1px solid var(--border); background: var(--panel-2); }
.mdot.done { background: var(--accent); border-color: var(--accent); }
.mdot.review { background: var(--warn); border-color: var(--warn); }
.mdot.current { outline: 2px solid var(--text); outline-offset: 1px; }
.board { display: flex; gap: 14px; align-items: flex-start; }
@media (max-width: 820px) { .board { flex-direction: column; } }
.mission {
  flex: 0 0 320px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
@media (max-width: 820px) { .mission { flex: 1 1 auto; width: 100%; } }
.card-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mission h2 { font-size: 17px; line-height: 1.3; }
.brief { font-size: 14px; }
.hints { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.hint-row { display: flex; gap: 6px; }
.hint-btn {
  flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 4px; font-size: 12.5px; font-weight: 600;
}
.hint-btn:hover:not(:disabled) { border-color: var(--warn); color: var(--warn); }
.hint-btn.used { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.hint-btn:disabled { opacity: .45; }
.hint-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.hint { background: var(--warn-soft); border-radius: 7px; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.hint-k { font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--warn); }
.hint-t { font-size: 13px; }
.hint-t.mono { white-space: pre-wrap; word-break: break-word; }
.solution { display: flex; flex-direction: column; gap: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 12px; }
.sol-head { font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--text-dim); }
.sol-code { font-size: 13.5px; color: var(--accent); white-space: pre-wrap; word-break: break-word; }
.sol-parts { margin: 0; display: flex; flex-direction: column; font-size: 13px; }
.sol-parts dt { font-family: var(--font-mono); color: var(--accent); word-break: break-word; }
.sol-parts dd { margin: 0 0 7px 12px; color: var(--text-dim); }
.mscore { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-dim); border-top: 1px solid var(--border); padding-top: 10px; }
.mscore b { color: var(--accent); font-family: var(--font-mono); }
.pane { flex: 1 1 auto; min-width: 0; width: 100%; }
.summary { flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.summary h2 { font-size: 20px; }
.stats { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.stats b { font-family: var(--font-mono); color: var(--accent); }

/* terminal */
.term { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.term-bar { display: flex; gap: 6px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.r { background: #e2777c; } .dot.y { background: #e3b95f; } .dot.g { background: #5fe3a0; }
.term-title { margin: 0 auto 0 6px; font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); }
.term-body {
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6; padding: 14px;
  height: min(58vh, 520px); min-height: 260px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.line.cmd { color: var(--text-dim); }
.line.cmd .p { color: var(--accent); }
.line.err { color: var(--err); }
.line.nudge { color: var(--warn); }
.line.tip, .line.note { color: var(--accent); }
.line.note { border-left: 2px solid var(--accent); padding-left: 8px; margin: 4px 0; }
.line.ok { color: var(--accent); font-weight: 700; }
.line.sys { color: var(--text-dim); font-style: italic; }
.term-input-row { display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-top: 1px solid var(--border); }
.prompt { font-family: var(--font-mono); font-size: 14px; color: var(--accent); white-space: pre; }
.term-input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text); font-family: var(--font-mono); font-size: 14px; }
.term-input::placeholder { color: var(--text-dim); opacity: .7; }

/* track notice */
.notice { font-size: 13.5px; color: var(--text-dim); background: var(--warn-soft); border-left: 3px solid var(--warn); border-radius: 6px; padding: 10px 12px; }
.notice b { color: var(--text); }

/* SQL */
.sqlpane { display: flex; flex-direction: column; gap: 10px; }
.schema { display: flex; flex-wrap: wrap; gap: 6px; font-family: var(--font-mono); font-size: 12.5px; }
.schema-t { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; color: var(--text-dim); }
.schema-t b { color: var(--accent); font-weight: 600; }
.editor { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.editor:focus-within { border-color: var(--accent); }
.sql-input {
  display: block; width: 100%; resize: vertical; min-height: 120px; border: 0; outline: none; padding: 14px;
  background: transparent; color: var(--text); font-family: var(--font-mono); font-size: 14px; line-height: 1.6;
}
.sql-input::placeholder { color: var(--text-dim); opacity: .7; }
.editor-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 9px 12px; border-top: 1px solid var(--border); }
.feedback { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.feedback:empty { display: none; }
.result { display: flex; flex-direction: column; gap: 6px; }
.table-wrap { overflow: auto; max-height: min(50vh, 460px); border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.rtable { border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; width: max-content; min-width: 100%; }
.rtable th, .rtable td { padding: 6px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: pre; }
.rtable th { position: sticky; top: 0; background: var(--panel-2); color: var(--accent); font-weight: 600; }
.rtable td.null { color: var(--text-dim); font-style: italic; }

/* Excel */
.xlpane { display: flex; flex-direction: column; gap: 10px; }
.xl-bar { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; }
.xl-bar:focus-within { border-color: var(--accent); }
.xl-name { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--accent); min-width: 38px; }
.fx { font-family: var(--font-mono); font-style: italic; color: var(--text-dim); font-size: 13px; }
.xl-input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-family: var(--font-mono); font-size: 14px; padding: 4px 0; }
.xl-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--text-dim); }
.xl-tool { display: inline-flex; gap: 6px; align-items: center; }
.xl-row { width: 64px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font: inherit; }
.xl-pivot { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--text-dim); background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.xl-pivot b { color: var(--accent); }
.xl-pivot select { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 6px; font: inherit; max-width: 46vw; }
.xl-actions { border: 0; padding: 0; }
.xl-grid-wrap { overflow: auto; max-height: min(58vh, 540px); border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.xl-grid { border-collapse: collapse; font-family: var(--font-mono); font-size: 12.5px; width: max-content; }
.xl-grid th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); color: var(--text-dim); font-weight: 600; padding: 4px 8px; border: 1px solid var(--border); }
.xl-grid th.rownum { position: sticky; left: 0; z-index: 1; min-width: 34px; text-align: right; }
.xl-grid th.corner { left: 0; z-index: 3; }
.xl-grid td { min-width: 78px; max-width: 220px; height: 26px; padding: 3px 7px; border: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: cell; }
.xl-grid td.num { text-align: right; }
.xl-grid td.hdr { font-weight: 600; color: var(--accent); }
.xl-grid td.err { color: var(--err); }
.xl-grid td.formula { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.xl-grid td.target { outline: 1px dashed var(--warn); outline-offset: -3px; }
.xl-grid td.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.xl-pivot-out:empty { display: none; }
.xl-pivot-out .rtable tr.total td { font-weight: 700; border-top: 2px solid var(--border); }

/* Python */
.py-files { display: flex; flex-direction: column; gap: 6px; }
.py-files:empty { display: none; }
.py-file { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--text-dim); }
.py-file summary { cursor: pointer; }
.py-file code { color: var(--accent); }
.py-file pre { margin: 8px 0 2px; font-family: var(--font-mono); font-size: 12px; color: var(--text); overflow-x: auto; }
.py-input { min-height: 240px; tab-size: 4; }
.py-output { display: flex; flex-direction: column; gap: 6px; }
.py-stdout { margin: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-family: var(--font-mono); font-size: 13px; max-height: 240px; overflow: auto; white-space: pre-wrap; }
.py-tests { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.py-tests li.ok { color: var(--accent); }
.py-tests li.fail { color: var(--err); }
.py-msg { color: var(--text-dim); font-family: var(--font-mono); font-size: 12.5px; margin: 2px 0 0 18px; white-space: pre-wrap; word-break: break-word; }

/* sync */
.sync-code { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 8px; padding: 9px; margin-bottom: 8px;
  background: var(--panel-2); color: var(--text); font-family: var(--font-mono); font-size: 12px; word-break: break-all; }
.sync-code:focus { outline: none; border-color: var(--accent); }
.ok-text { color: var(--accent); }
.err-text { color: var(--err); }

/* cheat sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; width: min(640px, 100%); max-height: 85vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal h2 { font-size: 18px; }
.modal h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .3px; color: var(--text-dim); margin: 8px 0 4px; }
.cheat { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.cheat td { padding: 5px 8px 5px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.cheat code { color: var(--accent); white-space: nowrap; }

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

/* ---- MongoDB and the Final Case ---- */
.mongo-out { max-height: 420px; overflow: auto; }
button.final { cursor: pointer; font: inherit; width: 100%; }
button.final:hover { border-color: var(--accent); }
.case-text { font-family: inherit; line-height: 1.5; }
.case-model { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.case-model h3 { margin: 6px 0 0; font-size: 14px; }
.case-model p { margin: 0; line-height: 1.55; }
.case-check { display: flex; gap: 8px; align-items: baseline; font-size: 13.5px; color: var(--text-dim); }
.case-check b { color: var(--text); }
.case-summary { text-align: left; display: flex; flex-direction: column; gap: 6px; }
.case-summary ol { margin: 0; padding-left: 20px; color: var(--text-dim); font-size: 13.5px; }

/* ---- welcome note and star link ---- */
a.primary, a.ghost { text-decoration: none; display: inline-block; }
.welcome p { margin: 0; line-height: 1.55; color: var(--text-dim); }
.welcome p b { color: var(--text); }
.welcome .wave { font-size: 28px; }
.star-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.star-link:hover { text-decoration: underline; }
