:root {
  --bg: #fbfaf7;
  --bg-alt: #f2f0ea;
  --surface: #ffffff;
  --text: #1f2330;
  --muted: #5d6270;
  --line: #e3e0d8;
  --accent: #4b47d6;
  --accent-soft: #e9e8ff;
  --new: #d9480f;
  --new-soft: #fff0e6;
  --seen: #2b7a5b;
  --seen-soft: #e3f4ec;
  --good: #1f8a4c;
  --good-soft: #e2f6e9;
  --bad: #c92a2a;
  --bad-soft: #fde8e8;

  --code-bg: #1e1f2b;
  --code-text: #e6e6ef;
  --code-gutter: #6c6f85;
  --code-hl: rgba(255, 196, 0, 0.16);
  --code-hl-edge: #ffc400;
  --tok-kw: #c792ea;
  --tok-cls: #4fd1c5;
  --tok-fn: #82aaff;
  --tok-str: #c3e88d;
  --tok-num: #f78c6c;
  --tok-com: #8b8fa7;
  --tok-op: #89ddff;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 6px 24px rgba(20, 20, 40, .06);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14151c;
    --bg-alt: #1a1b24;
    --surface: #20212c;
    --text: #ececf3;
    --muted: #a3a6b8;
    --line: #33354a;
    --accent: #8f8cff;
    --accent-soft: #2b2a4d;
    --new: #ff8a4c;
    --new-soft: #3a2418;
    --seen: #5fd0a0;
    --seen-soft: #193329;
    --good: #5fd08a;
    --good-soft: #17301f;
    --bad: #ff7b7b;
    --bad-soft: #3a1c1c;
    --code-bg: #0f1017;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14151c; --bg-alt: #1a1b24; --surface: #20212c; --text: #ececf3; --muted: #a3a6b8;
  --line: #33354a; --accent: #8f8cff; --accent-soft: #2b2a4d; --new: #ff8a4c; --new-soft: #3a2418;
  --seen: #5fd0a0; --seen-soft: #193329; --good: #5fd08a; --good-soft: #17301f; --bad: #ff7b7b;
  --bad-soft: #3a1c1c; --code-bg: #0f1017; color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
code, pre { font-family: var(--mono); font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }

/* inline code inside prose */
code.inl {
  background: var(--code-bg);
  color: var(--code-text);
  padding: .08em .4em;
  border-radius: 6px;
  font-size: .86em;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; text-decoration: none; color: var(--text); }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: #fff; font-family: var(--mono); font-size: 14px; font-weight: 600;
}
.main-nav { display: flex; gap: 6px; }
.main-nav a {
  text-decoration: none; color: var(--text); font-weight: 700; padding: 6px 14px; border-radius: 999px;
}
.main-nav a:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- hero ---------- */
.hero { padding: 56px 0 40px; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); font-weight: 800; max-width: 18ch; }
.lead { font-size: 19px; color: var(--muted); max-width: 60ch; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 13px; font-weight: 800; color: var(--accent); margin: 0 0 8px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.tag { display: inline-block; padding: 0 8px; border-radius: 999px; font-weight: 700; font-size: .9em; }
.tag-new { background: var(--new-soft); color: var(--new); }
.tag-seen { background: var(--seen-soft); color: var(--seen); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 12px; font-weight: 800; text-decoration: none;
  border: 2px solid transparent; cursor: pointer; transition: transform .08s ease, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- sections ---------- */
.section { padding: 48px 0 64px; }
.section-alt { background: var(--bg-alt); border-top: 1px solid var(--line); }
.section-head { margin-bottom: 24px; }
.section-head h2 { font-size: clamp(26px, 4vw, 34px); font-weight: 800; }
.section-head p { color: var(--muted); margin: 0; }

.color-key {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
  font-size: 14px; color: var(--muted); margin-bottom: 20px;
}
.color-key .key-title { font-weight: 800; color: var(--text); }
.color-key code { background: var(--code-bg); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

/* ---------- program picker ---------- */
.picker { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; scrollbar-width: thin; }
.pick {
  flex: 0 0 auto; border: 2px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 6px 12px; cursor: pointer; text-align: left; min-width: 112px;
}
.pick .n { font-family: var(--mono); font-size: 12px; color: var(--muted); display: block; }
.pick .t { font-weight: 700; font-size: 14px; white-space: nowrap; }
.pick:hover { border-color: var(--accent); }
.pick[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.pick[aria-selected="true"] .n { color: var(--accent); }

/* ---------- program card ---------- */
.program {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-top: 8px;
}
.prog-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.prog-num { font-family: var(--mono); font-weight: 600; color: var(--accent); font-size: 18px; }
.prog-head h3 { font-size: 26px; font-weight: 800; margin: 0; }
.prog-file { font-family: var(--mono); font-size: 13px; color: var(--muted); background: var(--bg-alt); padding: 2px 8px; border-radius: 6px; }
.purpose {
  margin: 16px 0 20px; padding: 14px 16px; border-radius: 12px; background: var(--accent-soft);
  border-left: 4px solid var(--accent);
}
.purpose strong { color: var(--accent); }

.prog-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .prog-grid { grid-template-columns: 1fr; } }

.panel-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; color: var(--muted); margin: 0 0 8px; }

/* ---------- code blocks ---------- */
.code {
  background: var(--code-bg); color: var(--code-text); border-radius: 12px; padding: 14px 0;
  font-family: var(--mono); font-size: 14px; line-height: 1.65; overflow-x: auto; margin: 0;
}
.code .ln { display: flex; padding: 0 16px 0 0; border-left: 3px solid transparent; transition: background .15s; min-width: max-content; }
.code .ln .num { width: 3.2em; flex: 0 0 auto; text-align: right; padding-right: 14px; color: var(--code-gutter); user-select: none; }
.code .ln .src { white-space: pre; }
.code .ln.hl { background: var(--code-hl); border-left-color: var(--code-hl-edge); }
.code.small { font-size: 13.5px; padding: 12px 0; }

.tok-kw { color: var(--tok-kw); font-weight: 600; }
.tok-cls { color: var(--tok-cls); }
.tok-fn { color: var(--tok-fn); }
.tok-str { color: var(--tok-str); }
.tok-num { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }
.tok-op { color: var(--tok-op); }
.color-key code { color: var(--code-text); }

/* ---------- building blocks ---------- */
.blocks-group { margin-bottom: 14px; }
.blocks-group h4 { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid transparent; border-radius: 999px; padding: 4px 12px; cursor: pointer;
  font-weight: 700; font-size: 14px; line-height: 1.3; text-align: left;
}
.chip small { font-weight: 600; opacity: .75; margin-left: 4px; }
.chip.new { background: var(--new-soft); color: var(--new); }
.chip.seen { background: var(--seen-soft); color: var(--seen); }
.chip:hover { border-color: currentColor; }
.chip.active { border-color: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent); }
.none-new { color: var(--muted); font-size: 14px; margin: 0; }
.block-info {
  border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; font-size: 15px;
  color: var(--muted); min-height: 64px;
}
.block-info strong { color: var(--text); display: block; margin-bottom: 2px; }

/* ---------- output & steps ---------- */
.console {
  background: #0b0c10; color: #d7f5d7; font-family: var(--mono); font-size: 14px;
  border-radius: 12px; padding: 14px 16px; white-space: pre-wrap; margin: 0; overflow-x: auto;
}
.console .in { color: #ffd166; font-weight: 600; }
.console-note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.console-note .in-key { color: #b8860b; font-weight: 700; }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 10px 0 10px 44px; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 10px; width: 30px; height: 30px;
  border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px;
  background: var(--accent-soft); color: var(--accent);
}
.prog-lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 20px; margin-top: 24px; }
@media (max-width: 860px) { .prog-lower { grid-template-columns: 1fr; } }

.tip {
  margin-top: 20px; padding: 12px 16px; border-radius: 12px; background: var(--seen-soft);
  border-left: 4px solid var(--seen);
}
.tip.warn { background: var(--new-soft); border-left-color: var(--new); }
.tip strong { display: block; }

.prog-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

/* ---------- map ---------- */
.map-wrap {
  margin-top: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 20px; box-shadow: var(--shadow);
}
.map-wrap summary { cursor: pointer; padding: 14px 0; list-style: none; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.map-wrap summary::-webkit-details-marker { display: none; }
.map-wrap summary::before { content: "▸"; color: var(--accent); transition: transform .15s; display: inline-block; }
.map-wrap[open] summary::before { transform: rotate(90deg); }
.map-title { font-weight: 800; font-size: 18px; }
.map-sub { color: var(--muted); font-size: 14px; }
.map-help { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.map-scroll { overflow-x: auto; padding-bottom: 16px; }
.block-map { border-collapse: collapse; font-size: 14px; min-width: 640px; width: 100%; }
.block-map th, .block-map td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: center; }
.block-map th:first-child, .block-map td:first-child {
  text-align: left; position: sticky; left: 0; background: var(--surface); padding-right: 12px; white-space: nowrap; font-weight: 700;
}
.block-map thead th { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.block-map thead th button { background: none; border: 0; cursor: pointer; font: inherit; color: inherit; padding: 2px 4px; border-radius: 6px; }
.block-map thead th button:hover { background: var(--accent-soft); color: var(--accent); }
.dot { font-weight: 800; }
.dot-new { color: var(--new); }
.dot-seen { color: var(--seen); }

/* ---------- quiz ---------- */
.quiz-app { max-width: 820px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.setup h3 { font-size: 18px; margin-bottom: 12px; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
@media (max-width: 640px) { .levels { grid-template-columns: 1fr; } }
.level {
  border: 2px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; background: var(--surface);
  text-align: left; display: block; width: 100%;
}
.level:hover { border-color: var(--accent); }
.level[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.level .lv-name { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.level .lv-desc { font-size: 14px; color: var(--muted); margin-top: 4px; display: block; }
.lv-dots { letter-spacing: 2px; color: var(--accent); font-size: 14px; }

.counts { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 24px; }
.counts button { border: 0; background: var(--surface); padding: 10px 22px; font-weight: 800; cursor: pointer; }
.counts button + button { border-left: 2px solid var(--line); }
.counts button[aria-checked="true"] { background: var(--accent); color: #fff; }

.q-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); font-weight: 700; flex-wrap: wrap; }
.q-level { background: var(--accent-soft); color: var(--accent); padding: 2px 10px; border-radius: 999px; }
.progress { height: 8px; background: var(--bg-alt); border-radius: 999px; overflow: hidden; margin: 10px 0 20px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s; }
.q-text { font-size: 20px; font-weight: 700; margin: 0 0 14px; }
.q-code { margin-bottom: 16px; }

.options { display: grid; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%;
  border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px;
  cursor: pointer; font-size: 16px; transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt .letter {
  flex: 0 0 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--bg-alt); font-weight: 800; font-size: 14px;
}
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.correct .letter { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt.dim { opacity: .55; }

.feedback { margin-top: 16px; border-radius: 12px; padding: 14px 16px; }
.feedback.good { background: var(--good-soft); border-left: 4px solid var(--good); }
.feedback.bad { background: var(--bad-soft); border-left: 4px solid var(--bad); }
.feedback .fb-title { font-weight: 800; margin-bottom: 4px; }
.feedback.good .fb-title { color: var(--good); }
.feedback.bad .fb-title { color: var(--bad); }
.q-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 10px; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); }

.result { text-align: center; }
.score-ring {
  --p: 0; width: 160px; height: 160px; border-radius: 50%; margin: 8px auto 16px;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg-alt) 0);
  display: grid; place-items: center;
}
.score-ring > div {
  width: 128px; height: 128px; border-radius: 50%; background: var(--surface);
  display: grid; place-items: center; align-content: center;
}
.score-big { font-size: 34px; font-weight: 800; line-height: 1; }
.score-pct { color: var(--muted); font-weight: 700; font-size: 14px; }
.result-msg { font-size: 20px; font-weight: 800; margin: 0 0 4px; }
.result-sub { color: var(--muted); margin: 0 0 20px; }
.result-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.review { margin-top: 24px; }
.review h3 { font-size: 22px; }
.review-item { margin-bottom: 16px; text-align: left; }
.review-item .ri-num { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.ans-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; border-radius: 10px; margin-top: 8px; }
.ans-row .lbl { font-weight: 800; font-size: 13px; flex: 0 0 auto; min-width: 104px; padding-top: 2px; }
.ans-row.yours { background: var(--bad-soft); }
.ans-row.yours .lbl { color: var(--bad); }
.ans-row.right { background: var(--good-soft); }
.ans-row.right .lbl { color: var(--good); }
.explain { margin-top: 10px; font-size: 15px; }
.explain strong { color: var(--accent); }
@media (max-width: 520px) {
  .ans-row { flex-direction: column; gap: 2px; }
  .program, .card { padding: 18px; }
  .q-text { font-size: 18px; }
}

.site-footer { padding: 28px 0; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); text-align: center; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }

/* long programs scroll inside their own box so highlighted lines stay in view */
.program .prog-grid .code { max-height: 640px; overflow: auto; position: relative; }
@media (max-width: 420px) {
  .brand { font-size: 15px; white-space: nowrap; }
  .main-nav a { padding: 6px 10px; }
}
