:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202c;
  --muted: #5f6b7a;
  --border: #e2e6eb;
  --accent: #1f6feb;
  --accent-soft: #e7f0ff;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --no: #dc2626;
  --no-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --xp: #7c3aed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, "Cascadia Code", "Fira Code", Consolas, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1f2833;
    --text: #e6ebf1;
    --muted: #9aa6b5;
    --border: #2a3441;
    --accent: #5b9dff;
    --accent-soft: #1b2a40;
    --ok: #3fcf75;
    --ok-soft: #14301f;
    --no: #f87171;
    --no-soft: #3a1c1c;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --xp: #a78bfa;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code, kbd, pre { font-family: var(--mono); }
:not(pre) > code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .05em .35em;
  font-size: .9em;
}
kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: .05em .4em;
  font-size: .85em;
}
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }

/* layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.wrap-narrow { max-width: 760px; }
.site-head {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-head .wrap { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--text); color: var(--bg); font: 700 15px/1 var(--mono);
}
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.site-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.site-nav a, .site-nav button {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px;
  background: none; border: 0; font: inherit; font-size: 15px; cursor: pointer;
}
.site-nav a:hover, .site-nav button:hover { background: var(--surface-2); color: var(--text); }
.site-nav .who { color: var(--text); font-weight: 600; padding: 6px 4px 6px 10px; }
main { padding: 28px 0 64px; }
.site-foot { color: var(--muted); font-size: 13px; padding: 24px 0 40px; border-top: 1px solid var(--border); }

/* building blocks */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font: 600 15px/1.2 inherit; font-family: inherit; text-decoration: none; cursor: pointer;
  transition: transform .05s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--no); border-color: var(--border); }
.btn-small { padding: 6px 12px; font-size: 14px; }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--ok-soft); color: var(--ok); letter-spacing: .02em;
}
.badge-muted { background: var(--surface-2); color: var(--muted); }
.flash { padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 20px; }
.errors { padding: 12px 16px; border-radius: 10px; background: var(--no-soft); color: var(--no); margin-bottom: 16px; }
.errors p { margin: 0; }

/* forms */
label.field { display: block; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
.field input, .field textarea, .field select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
  font: 16px/1.4 inherit; font-family: inherit;
}
.field textarea { min-height: 160px; font-family: var(--mono); font-size: 14px; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 16px; }

/* home */
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: clamp(28px, 5vw, 42px); margin: 0 0 10px; }
.hero p { font-size: 18px; color: var(--muted); max-width: 640px; margin: 0; }
.topics { list-style: none; padding: 0; margin: 32px 0 0; display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.topic {
  display: flex; flex-direction: column; gap: 8px; height: 100%;
  color: var(--text); text-decoration: none; transition: transform .15s, border-color .15s;
}
a.topic:hover { transform: translateY(-2px); border-color: var(--accent); }
.topic-head { display: flex; align-items: center; gap: 12px; }
.topic-icon { font-size: 30px; line-height: 1; }
.topic h2 { margin: 0; font-size: 22px; }
.topic p { margin: 0; color: var(--muted); }
.topic-foot { margin-top: auto; padding-top: 8px; display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); }
.topic-foot .go { color: var(--accent); font-weight: 600; }
.topic-soon { border-style: dashed; background: transparent; box-shadow: none; justify-content: center; align-items: center; text-align: center; min-height: 170px; }

/* course overview */
.course-head { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; }
.course-head h1 { margin: 0; font-size: clamp(26px, 4vw, 36px); }
.course-head p { margin: 4px 0 0; color: var(--muted); }
.xp-card { min-width: 260px; padding: 16px 18px; }
.xp-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.xp-num { font: 700 26px/1 var(--mono); color: var(--xp); }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > div { height: 100%; background: var(--xp); border-radius: 99px; transition: width .4s; }
.bar-ok > div { background: var(--ok); }
.part-title { margin: 32px 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.path { list-style: none; margin: 0; padding: 0; position: relative; }
.path::before { content: ""; position: absolute; left: 27px; top: 20px; bottom: 20px; width: 2px; background: var(--border); }
.path li { position: relative; margin-bottom: 12px; }
.chapter-link { display: flex; gap: 16px; align-items: center; color: var(--text); text-decoration: none; padding: 16px 18px; }
a.chapter-link:hover { border-color: var(--accent); }
.chapter-num {
  flex: 0 0 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; background: var(--surface-2); border: 2px solid var(--border); position: relative; z-index: 1;
}
.state-done .chapter-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.state-active .chapter-num, .state-open .chapter-num { border-color: var(--accent); color: var(--accent); background: var(--surface); }
.state-locked { opacity: .6; }
.chapter-info { flex: 1; min-width: 0; }
.chapter-info h3 { margin: 0; font-size: 17px; }
.chapter-info p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.chapter-meta { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.chapter-meta .bar { width: 90px; margin-left: auto; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }

/* chapter */
.chapter-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.chapter-top h1 { margin: 0; font-size: clamp(22px, 3.5vw, 30px); }
.chapter-top .back { font-size: 14px; color: var(--muted); text-decoration: none; }
.chapter-progress { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.chapter-progress .bar { width: 140px; margin: 0; }
.xp-pill { background: var(--surface); border: 1px solid var(--border); padding: 4px 12px; border-radius: 99px; font-weight: 700; color: var(--xp); font-family: var(--mono); }
.pills { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; margin-bottom: 8px; scrollbar-width: thin; }
.pill {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font: 500 14px/1 inherit; font-family: inherit; cursor: pointer; max-width: 240px;
}
.pill-icon { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 13px; flex: 0 0 26px; }
.pill-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.is-done .pill-icon { background: var(--ok); color: #fff; font-weight: 700; }
.pill.is-current { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent); }
.stage-theory, .stage-quiz { max-width: 780px; }
.step-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }

/* prose */
.prose h2 { font-size: 26px; margin: 0 0 16px; }
.prose h3 { font-size: 19px; margin: 28px 0 8px; }
.prose p, .prose li { font-size: 17px; }
.prose.small p, .prose.small li { font-size: 15px; }
.prose pre { background: #12161c; color: #e4e7eb; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
.prose blockquote {
  margin: 20px 0; padding: 12px 16px; border-left: 4px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
}
.prose blockquote p { margin: 4px 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 16px 0; font-size: 15px; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose img { max-width: 100%; }

/* quiz */
.quiz-dots { display: flex; gap: 6px; margin-bottom: 18px; }
.quiz-dots span { width: 28px; height: 6px; border-radius: 99px; background: var(--surface-2); }
.quiz-dots span.ok { background: var(--ok); }
.quiz-dots span.cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.quiz-q p { font-size: 19px; font-weight: 600; margin: 0 0 12px; }
.code { background: #12161c; color: #e4e7eb; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 14px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  padding: 12px 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface);
  color: var(--text); font: 16px/1.4 inherit; font-family: inherit; cursor: pointer;
}
.option:hover { border-color: var(--accent); }
.option.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.is-correct .option.is-selected { border-color: var(--ok); background: var(--ok-soft); }
.option-key { flex: 0 0 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font-weight: 700; font-size: 14px; }
.gap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: #12161c; color: #e4e7eb; padding: 14px 16px; border-radius: 10px; font-size: 16px; }
.gap code { background: none !important; border: 0 !important; color: inherit; padding: 0 !important; }
.gap-input {
  width: 9em; background: #232a35; color: #fff; border: 2px dashed #5b9dff; border-radius: 8px;
  padding: 4px 8px; font: 16px var(--mono);
}
.is-correct .gap-input { border-color: var(--ok); border-style: solid; }
.order { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; counter-reset: o; }
.order li {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface);
  border: 2px solid var(--border); border-radius: 12px; cursor: grab; counter-increment: o;
}
.order li::before { content: counter(o) "."; font-weight: 700; color: var(--muted); min-width: 1.5em; }
.order .grip { color: var(--muted); letter-spacing: -2px; }
.order-text { flex: 1; font-family: var(--mono); font-size: 15px; }
.order-btns { display: flex; gap: 4px; }
.order-btns button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.order-btns button:disabled { opacity: .3; }
.is-correct .order li { border-color: var(--ok); }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.match-col { display: grid; gap: 8px; align-content: start; }
.match-item {
  text-align: left; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); font: 15px/1.35 inherit; font-family: inherit; cursor: pointer;
}
.match-item.is-selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.match-to { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.match-item.is-paired.c0 { border-color: #2563eb; background: rgba(37, 99, 235, .1); }
.match-item.is-paired.c1 { border-color: #db2777; background: rgba(219, 39, 119, .1); }
.match-item.is-paired.c2 { border-color: #059669; background: rgba(5, 150, 105, .1); }
.match-item.is-paired.c3 { border-color: #d97706; background: rgba(217, 119, 6, .1); }
.match-item.is-paired.c4 { border-color: #7c3aed; background: rgba(124, 58, 237, .1); }
.match-item.is-paired.c5 { border-color: #0891b2; background: rgba(8, 145, 178, .1); }
.is-correct .match-item { border-color: var(--ok) !important; }
.quiz-feedback { margin-top: 16px; }
.fb { margin: 0; padding: 12px 14px; border-radius: 10px; }
.fb-ok { background: var(--ok-soft); color: var(--ok); }
.fb-no { background: var(--no-soft); color: var(--no); }
.fb-info { background: var(--surface-2); color: var(--muted); }
.fb-explain { margin: 10px 0 0; padding: 0 4px; }
.quiz-actions { margin-top: 18px; display: flex; justify-content: flex-end; }
.quiz-done { text-align: center; padding: 20px 0; }
.quiz-done .big { font-size: 54px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* terminal exercise layout */
.split { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 960px) {
  .split { grid-template-columns: minmax(300px, 380px) 1fr; align-items: start; }
  .split-right { position: sticky; top: 76px; }
}
.split-left { display: grid; gap: 16px; }
.split-left h2 { margin: 0 0 8px; font-size: 21px; }
.tasks, .goals { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.task, .goal { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 15px; line-height: 1.45; }
.task-dot {
  flex: 0 0 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.task-current { background: var(--accent-soft); }
.task-current .task-dot { border-color: var(--accent); color: var(--accent); }
.task-todo { opacity: .55; }
.task-done, .goal-ok { color: var(--muted); }
.task-done .task-dot, .goal-ok .task-dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.goal { background: var(--surface-2); }
.goal-ok { background: var(--ok-soft); }
.hintbox { margin-top: 12px; display: grid; gap: 8px; justify-items: start; }
.hint { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); font-size: 15px; width: 100%; }
.hint-solution { background: var(--surface-2); }

/* terminal */
.terminal {
  background: #161b22; color: #e6edf3; border-radius: var(--radius); overflow: hidden;
  font: 14.5px/1.55 var(--mono); display: flex; flex-direction: column;
  height: min(70vh, 560px); min-height: 340px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.t-bar { display: flex; align-items: center; gap: 7px; padding: 9px 12px; background: #21262d; }
.t-bar i { width: 12px; height: 12px; border-radius: 50%; background: #ff5f57; }
.t-bar i:nth-child(2) { background: #febc2e; }
.t-bar i:nth-child(3) { background: #28c840; }
.t-title { margin-left: 8px; color: #8b949e; font-size: 12px; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.t-reset { background: none; border: 1px solid #30363d; color: #8b949e; border-radius: 6px; padding: 3px 8px; font: 12px inherit; font-family: inherit; cursor: pointer; }
.t-reset:hover { color: #e6edf3; border-color: #8b949e; }
.t-out { flex: 1; overflow-y: auto; padding: 12px 14px; white-space: pre-wrap; word-break: break-word; cursor: text; }
.t-line { display: flex; }
.t-prompt { white-space: pre; }
.t-user { color: #3fb950; font-weight: 600; }
.t-path { color: #58a6ff; font-weight: 600; }
.t-input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: inherit; font: inherit; padding: 0; caret-color: #3fb950; }
.t-dir { color: #58a6ff; font-weight: 600; }
.t-err { color: #ff7b72; }
.t-hint { color: #e3b341; }
.t-hint code { background: #2d333b !important; border-color: #444c56 !important; color: #e6edf3; }
.t-ok { color: #3fb950; font-weight: 600; }
.t-muted { color: #8b949e; }

/* file tree */
.tree { font-size: 14px; overflow-x: auto; }
.ft, .ft ul { list-style: none; margin: 0; padding: 0; }
.ft ul { padding-left: 18px; border-left: 1px dashed var(--border); margin-left: 8px; }
.ft li { padding: 2px 0; }
.ft-name { white-space: nowrap; padding: 1px 6px; border-radius: 6px; }
.ft-here > .ft-name { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.ft-new > .ft-name { animation: flash 1.6s; }
@keyframes flash { 0%, 40% { background: var(--ok-soft); color: var(--ok); } }
.ft-badge { font-size: 11px; background: var(--accent); color: #fff; border-radius: 99px; padding: 1px 7px; margin-left: 4px; }
.ft-outside { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* toasts and dialog */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast {
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: pop .25s; transition: opacity .4s, transform .4s;
}
.toast-xp { background: var(--xp); color: #fff; font-family: var(--mono); font-size: 18px; }
.toast-warn { background: var(--warn); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
dialog {
  border: 0; border-radius: 18px; padding: 32px; max-width: 440px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); text-align: center; box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(10, 14, 20, .55); }
dialog .big { font-size: 64px; line-height: 1; }
dialog h2 { margin: 12px 0 8px; }
dialog .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }

/* teacher */
.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 2fr 1fr; align-items: start; } }
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.data td.num, table.data th.num { text-align: center; }
.cell { display: inline-block; min-width: 46px; padding: 2px 6px; border-radius: 6px; font-weight: 600; font-size: 13px; background: var(--surface-2); color: var(--muted); }
.cell-done { background: var(--ok); color: #fff; }
.cell-part { background: var(--accent-soft); color: var(--accent); }
.row-actions { display: flex; gap: 6px; }
.row-actions form { margin: 0; }
.class-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.class-list a { display: flex; justify-content: space-between; padding: 14px 16px; text-decoration: none; color: var(--text); }
.class-list a:hover { border-color: var(--accent); }
.credentials table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.credentials td, .credentials th { border: 1px solid var(--border); padding: 10px; text-align: left; }
.credentials td code { font-size: 15px; }
.print-only { display: none; }
@media print {
  .site-head, .site-foot, .no-print { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .credentials td, .credentials th { border-color: #999; }
}
