:root {
  color-scheme: light;

  --bg: #fbfbf7;
  --bg-image:
    linear-gradient(to right, rgba(60, 100, 180, .085) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(to bottom, rgba(60, 100, 180, .085) 1px, transparent 1px) 0 0 / 24px 24px;
  --fg: #262a33;
  --muted: #565d6d;
  --heading: #1c3c98;
  --title: #1c3c98;
  --highlight: #fff0a0;
  --rule: #d7dde8;
  --border: #b4bed0;
  --accent: #1f4fbf;
  --accent-soft: #e9effc;
  --on-accent: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --selection: color-mix(in srgb, var(--accent) 24%, transparent);

  --ok: #217638;
  --ok-bg: #e8f5eb;
  --bad: #bf3329;
  --bad-bg: #fcebe9;

  --code-bg: #f2f4f9;
  --code-fg: var(--fg);
  --editor-bg: var(--surface);
  --k: #1f4fbf;
  --s: #b1352a;
  --c: #747d8f;
  --n: #8f5400;

  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-heading: "Kalam", "Segoe Print", "Comic Sans MS", cursive;
  --font-ui: var(--font-body);
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --size: 18px;
  --size-sm: 17px;
  --code-size: 14.5px;
  --leading: 1.65;
  --heading-weight: 700;
  --h1-size: 2.7rem;

  --button: var(--surface-2);
  --button-hover: var(--rule);
  --button-border: #9aa6bd;
  --button-fg: var(--fg);
  --primary-bg: var(--accent);
  --primary-fg: var(--on-accent);
  --primary-border: var(--accent);
  --primary-hover: #1a44a6;

  --radius: 3px;
  --radius-lg: 4px;
  --shadow: 0 1px 0 rgba(31, 79, 191, .07), 0 2px 8px rgba(38, 42, 51, .05);

  --chrome-bg: #ffffff;
  --chrome-fg: var(--fg);
  --chrome-muted: var(--muted);
  --chrome-border: var(--rule);
  --chrome-accent: var(--accent);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--fg); font: var(--size)/var(--leading) var(--font-body);
  background: var(--bg-image), var(--bg);
  -webkit-text-size-adjust: 100%;
}
::selection { background: var(--selection); }

main { min-width: 0; }

a { color: var(--accent); }
h1, h2, h3 {
  font-family: var(--font-heading); font-weight: var(--heading-weight);
  color: var(--heading); text-wrap: balance;
}
h1 { font-size: var(--h1-size); line-height: 1.15; margin: .15rem 0 1rem; }

h1 {
  text-decoration: underline; text-decoration-color: var(--highlight); text-decoration-thickness: .42em;
  text-underline-offset: -.2em; text-decoration-skip-ink: none;
}
h2 { font-size: 1.5rem; line-height: 1.25; margin: 2.5rem 0 .9rem; }
h3 { font-size: 1.2rem; margin: 2rem 0 .6rem; }
p, ul, ol { margin: 0 0 1.1rem; }
li { margin-bottom: .3rem; }
.kicker { color: var(--muted); font-size: .95rem; margin: 0; font-family: var(--font-ui); }
.intro { font-size: 1.08rem; margin-bottom: 1.75rem; }
.intro-small { margin-bottom: 1.25rem; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.loading { color: var(--muted); }

code, pre, kbd, samp, textarea { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
code { font-family: var(--font-mono); font-size: .84em; background: var(--code-bg); color: var(--code-fg); padding: .08em .32em; border-radius: min(var(--radius), 4px); }
pre {
  font: var(--code-size)/1.55 var(--font-mono); background: var(--code-bg); color: var(--code-fg);
  border: 1px solid var(--rule); border-radius: var(--radius);
  padding: .9rem 1.1rem; overflow-x: auto; margin: 0 0 1.4rem; tab-size: 4;
}
pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; color: inherit; }
.k { color: var(--k); }
.s { color: var(--s); }
.c { color: var(--c); }
.n { color: var(--n); }

button, .button-link {
  display: inline-block; font: inherit; font-family: var(--font-ui); font-size: 1rem; line-height: 1.3; color: var(--button-fg);
  background: var(--button); border: 1px solid var(--button-border); border-radius: var(--radius);
  padding: .5rem 1.15rem; cursor: pointer; text-decoration: none;
}
button:hover:not(:disabled), .button-link:hover { background: var(--button-hover); }
button:disabled { color: var(--muted); cursor: default; }
button.primary {
  font-weight: 700; background: var(--primary-bg); color: var(--primary-fg); border-color: var(--primary-border);
}
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.primary:disabled { opacity: .7; color: var(--primary-fg); }
button.linkish { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; box-shadow: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.rows { list-style: none; padding: 0; margin: 0 0 1.25rem; display: grid; gap: .8rem; }
.rows li { margin: 0; }
.row {
  display: block; padding: 1.05rem 1.35rem 1.15rem; border: 1px solid var(--border); border-radius: var(--radius-lg);
  color: var(--fg); text-decoration: none; background: var(--surface); box-shadow: var(--shadow);
}
.row:hover { border-color: var(--accent); background: var(--accent-soft); }
.row:hover .row-title { text-decoration: underline; }
.row-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .92rem; color: var(--muted); font-family: var(--font-ui); }
.row-status .ok { color: var(--ok); }
.row-status .sep { color: var(--muted); }
.row-title { display: block; font-family: var(--font-heading); font-size: 1.75rem; font-weight: var(--heading-weight); line-height: 1.15; color: var(--title); margin: .2rem 0 .25rem; }
.row-desc { display: block; color: var(--muted); }
.progress { color: var(--muted); }

.runner { margin: 1.25rem 0 1.75rem; }
.runner-file { font: 14px var(--font-mono); color: var(--muted); margin-bottom: .3rem; }

.code-wrap { position: relative; border: 1px solid var(--button-border); border-radius: var(--radius); background: var(--editor-bg); }
.code-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.code-wrap .code-hl,
.code-wrap textarea.code {
  margin: 0; border: 0; border-radius: 0; padding: .75rem .9rem;
  font: var(--code-size)/1.55 var(--font-mono); font-variant-ligatures: none; letter-spacing: normal; word-spacing: normal;
  text-indent: 0; text-transform: none; tab-size: 4; -moz-tab-size: 4; white-space: pre;
}
.code-wrap .code-hl {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  background: transparent; color: var(--code-fg);
}
.code-wrap textarea.code {
  position: relative; z-index: 1; display: block; width: 100%; overflow: auto; resize: vertical; outline: none;
  background: transparent; color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--fg);
}
.code-wrap textarea.code::selection { background: var(--selection); -webkit-text-fill-color: transparent; }

.output-label { display: block; font-weight: bold; margin-bottom: .25rem; font-family: var(--font-ui); }
.hint { font-weight: normal; color: var(--muted); font-size: .88rem; font-family: var(--font-ui); }
.runner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; margin: .9rem 0; }

.output { margin: 0; min-height: 3.6rem; max-height: 24rem; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.output:empty::before { content: "Press Run to see the output."; color: var(--muted); font-style: italic; font-family: var(--font-body); }
.output .err { color: var(--bad); }
.output .meta { color: var(--muted); }
.output .in { color: var(--accent); }
.console-input {
  font: inherit; color: var(--accent); background: transparent; caret-color: var(--accent);
  border: 0; border-bottom: 1px solid var(--accent); border-radius: 0;
  margin: 0; padding: 0 .15em; max-width: 100%; outline: none; vertical-align: baseline;
}
.console-input:focus { background: var(--accent-soft); }

.goal { margin: 0 0 1.5rem; }
.passed-note { margin: .6rem 0 0; color: var(--ok); }
.challenge-result {
  margin: 1.25rem 0 0; padding: .9rem 1.2rem; border: 1px solid var(--border); border-radius: var(--radius);
}
.challenge-result.passed { border-color: var(--ok); background: var(--ok-bg); }
.challenge-result.passed strong { color: var(--ok); }
.challenge-result.not-yet { background: var(--surface-2); }

.lesson-end {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 1.5rem;
  margin-top: 2.75rem; padding: 1.15rem 1.35rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2);
}
.finish { display: flex; align-items: center; gap: .65rem; cursor: pointer; font-size: 1.05rem; }
.finish input { width: 1.2rem; height: 1.2rem; margin: 0; accent-color: var(--accent); }

.best { color: var(--muted); }
.questions { list-style: none; padding: 0; margin: 0; display: grid; gap: 1.1rem; }
.question { margin: 0; padding: 1.2rem 1.35rem 1.3rem; border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--surface); }
.qnum { display: block; font-size: .9rem; color: var(--muted); font-family: var(--font-ui); }
.stem { font-size: 1.12rem; font-weight: bold; margin: .15rem 0 .9rem; }
.choices { display: grid; gap: .5rem; }
.choice {
  display: flex; align-items: center; gap: .8rem; padding: .65rem .9rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer;
}
.choice:not(.locked):hover { border-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { flex: none; width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--accent); }
.choice code { background: none; padding: 0; }
.choice.locked { cursor: default; }
.quiz .choice.right { border-color: var(--ok); background: var(--ok-bg); }
.quiz .choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.quiz .choice.wrong .choice-text { text-decoration: line-through; }
.verdict { margin: .8rem 0 0; font-style: italic; }
.verdict.ok { color: var(--ok); }
.verdict.no { color: var(--bad); }
.quiz-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; margin-top: 1.5rem; }
.score { margin: 0; font-size: 1.2rem; font-weight: bold; }

.meter { display: block; height: .45rem; border-radius: 999px; background: var(--rule); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em; }

@media (max-width: 640px) {
  body { font-size: var(--size-sm); }
  h1 { font-size: calc(var(--h1-size) * .79); }
  .row, .question { padding-inline: 1rem; }
  .row-title { font-size: 1.5rem; }
  pre, .code-wrap .code-hl, .code-wrap textarea.code { font-size: min(var(--code-size), 14px); }
  .console-input { font-size: 16px; }
}

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