/* Coach. The progress strip is drawn as Postgres heap pages: one block per lesson or scenario. */

:root {
  --paper: #EEF1F4;
  --surface: #FFFFFF;
  --ink: #17202E;
  --muted: #5B6676;
  --line: #CDD5DF;
  --elephant: #2F5D8A;
  --elephant-deep: #22476C;
  --elephant-wash: #E1EAF3;
  --marker: #FFD84D;
  --marker-ink: #17202E;
  --ok: #23866F;
  --ok-wash: #E0F2EC;
  --bad: #B33A3A;
  --bad-wash: #F8E5E5;
  --warn: #B84A00;
  --warn-soft: #FFF0E2;
  --term: #0F1B2A;
  --term-text: #DCE4EE;
  --dock-shadow: 0 18px 50px rgba(23, 32, 46, 0.22), 0 2px 6px rgba(23, 32, 46, 0.12);

  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --reading: "Literata", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.125rem;
  --step-2: 1.4rem;
  --step-3: clamp(2.1rem, 4.6vw, 3.3rem);
  --radius: 6px;
  --on-accent: #FFFFFF;
  --accent-hover: #22476C;
  --measure: 43rem; /* one reading width for text, quiz, links and the stepper */
  color-scheme: light;
}

/* Dark applies when the system is dark and no light choice was saved, or when dark was chosen.
   The two blocks must stay identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121A24;
    --surface: #1A2431;
    --ink: #E6EBF1;
    --muted: #9AA6B5;
    --line: #314052;
    --elephant: #7FA8D6;
    --elephant-deep: #A9C6E6;
    --elephant-wash: #1F3045;
    --marker: #E8C547;
    --marker-ink: #17202E;
    --ok: #4CC3A3;
    --ok-wash: #173229;
    --bad: #F07B7B;
    --bad-wash: #3A1E22;
    --warn: #FF9B52;
    --warn-soft: #38230F;
    --dock-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
    --on-accent: #0F1B2A;
    --accent-hover: #6A94C2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121A24;
  --surface: #1A2431;
  --ink: #E6EBF1;
  --muted: #9AA6B5;
  --line: #314052;
  --elephant: #7FA8D6;
  --elephant-deep: #A9C6E6;
  --elephant-wash: #1F3045;
  --marker: #E8C547;
  --marker-ink: #17202E;
  --ok: #4CC3A3;
  --ok-wash: #173229;
  --bad: #F07B7B;
  --bad-wash: #3A1E22;
  --warn: #FF9B52;
  --warn-soft: #38230F;
  --dock-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  --on-accent: #0F1B2A;
  --accent-hover: #6A94C2;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--display);
  font-size: var(--step-0);
  font-variation-settings: "opsz" 14;
  line-height: 1.5;
}

a { color: var(--elephant); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--elephant); outline-offset: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip { position: absolute; left: 12px; top: -48px; z-index: 50; background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: var(--radius); }
.skip:focus { top: 8px; }

/* No ligatures in code: "->" in a query plan must look like what Postgres prints. */
code, pre { font-family: var(--mono); font-size: 0.88em; font-variant-ligatures: none; font-feature-settings: "calt" 0, "liga" 0; }

/* --- Buttons ------------------------------------------------------------------------- */

button, .button {
  font: 600 var(--step--1)/1.2 var(--display);
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 0.6em 1.05em;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
button:hover:not(:disabled), .button:hover { background: var(--elephant-wash); }
button:disabled { opacity: 0.55; cursor: progress; }
button.primary, .button.primary { background: var(--elephant); border-color: var(--elephant); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.quiet { border-color: var(--line); background: transparent; }
button.big { font-size: var(--step-0); padding: 0.85em 1.5em; }

/* --- Top bar ------------------------------------------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 22px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: var(--paper);
  border-bottom: 1.5px solid var(--line);
}
.brand {
  font-weight: 800; font-size: 1.3rem; letter-spacing: -0.01em;
  font-variation-settings: "opsz" 48, "wdth" 78;
  color: var(--ink); text-decoration: none;
}
.track-name { color: var(--muted); padding-left: 22px; border-left: 1.5px solid var(--line); }
.top nav { display: flex; gap: 4px; }
.top nav a {
  color: var(--ink); text-decoration: none; font-weight: 500;
  padding: 6px 12px; border-radius: var(--radius);
}
.top nav a:hover { background: var(--elephant-wash); }
.top nav a[aria-current="page"] {
  font-weight: 700;
  box-shadow: inset 0 -3px 0 var(--elephant);
  border-radius: var(--radius) var(--radius) 0 0;
}
.live-dot {
  display: inline-block; width: 8px; height: 8px; margin-left: 6px; vertical-align: 0.15em;
  border-radius: 50%; background: var(--marker); box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--marker-ink);
}
.theme-toggle {
  margin-left: auto;
  border-color: var(--line); background: transparent;
  padding: 6px 11px; gap: 7px; font-weight: 500;
}
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
/* Show the icon of the mode a click switches to. */
.theme-toggle[data-showing="light"] .icon-sun,
.theme-toggle[data-showing="dark"] .icon-moon { display: none; }

.account { display: flex; align-items: center; gap: 14px; min-width: 0; }
.account-email {
  min-width: 0; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: var(--step--1);
}
.account a { color: var(--ink); font-size: var(--step--1); font-weight: 500; }
.account button { padding: 6px 11px; font-weight: 500; white-space: nowrap; }

/* --- Login and messages ------------------------------------------------------------------ */

.gate { max-width: 26rem; }
.gate .status { margin-top: 16px; }
.gate form { display: grid; justify-items: start; margin-top: 30px; }
.gate label { font-weight: 600; margin-bottom: 6px; }
.gate input {
  width: 100%; margin-bottom: 20px; padding: 0.65em 0.8em;
  font: var(--step-0)/1.4 var(--display); color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--muted); border-radius: var(--radius);
}
.gate input[readonly] { color: var(--muted); background: transparent; border-color: var(--line); }
.gate-hint { margin: 0 0 6px; font-size: var(--step--1); color: var(--muted); }
.gate-links { margin: 24px 0 0; }

.in-progress {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px;
  margin-bottom: 36px; padding: 16px 20px;
  background: var(--surface); border: 1.5px solid var(--line); border-left: 6px solid var(--marker); border-radius: 8px;
}
.in-progress p { margin: 0; }
.in-progress-label { font-size: var(--step--1); color: var(--muted); }
.in-progress-title { font-weight: 700; font-size: var(--step-1); }
.in-progress-note { font-size: var(--step--1); color: var(--muted); margin-top: 2px !important; }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.notice {
  margin: 0; padding: 10px clamp(16px, 4vw, 40px);
  background: var(--elephant-wash); color: var(--ink); font-size: var(--step--1);
}

/* --- Page frame ---------------------------------------------------------------------- */

main { padding: clamp(24px, 4vw, 48px) clamp(16px, 4vw, 40px) 120px; }
main.course { max-width: 860px; margin: 0 auto; }
main.wide { max-width: 1560px; margin: 0 auto; padding-top: 24px; }

/* --- The heap-page strip ------------------------------------------------------------- */

.path { margin-bottom: clamp(32px, 5vw, 56px); }
.path-count { margin: 0 0 10px; font-size: var(--step--1); color: var(--muted); }
.path-count strong { color: var(--ink); font-size: var(--step-1); font-variant-numeric: tabular-nums; }
.blocks {
  list-style: none; margin: 0; padding: 0 0 10px;
  display: flex; gap: 5px;
}
.blocks li { flex: 1 1 0; min-width: 0; }
.block {
  position: relative; display: block; height: 34px;
  border: 1.5px solid var(--line); border-radius: 3px;
  background: var(--surface);
  transition: transform 120ms ease, border-color 120ms ease;
}
.block:hover { transform: translateY(-2px); border-color: var(--ink); }
.block.started {
  border-color: var(--elephant);
  background: repeating-linear-gradient(135deg, var(--elephant) 0 1.5px, var(--surface) 1.5px 6px);
}
.block.passed { border-color: var(--elephant); background: var(--elephant); }
.block.upcoming { border-color: var(--marker-ink); background: var(--marker); }
.block.current { transform: translateY(-5px); border: 2px solid var(--ink); }
.block.current::after {
  content: ""; position: absolute; left: 50%; bottom: -13px; translate: -50% 0;
  border: 5px solid transparent; border-bottom-color: var(--ink);
}
.block.just-passed { animation: fill-page 520ms ease-out; }
@keyframes fill-page {
  0% { background: var(--surface); }
  60% { transform: translateY(-9px); }
}

/* --- Stage: one lesson or one scenario ----------------------------------------------- */

.stage { transition: opacity 180ms ease; }
.stage.htmx-added { opacity: 0; }

.stage-head { margin-bottom: 34px; max-width: var(--measure); }
.where {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin: 0 0 14px; font-size: var(--step--1); color: var(--muted);
}
.where a { color: var(--muted); }
.skill {
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 1px 10px; color: var(--ink); font-weight: 500;
}
.badge { border-radius: 999px; padding: 2px 10px; font-weight: 700; }
.badge.ok { background: var(--ok-wash); color: var(--ok); }
.badge.next { background: var(--marker); color: var(--marker-ink); }

h1, h2, h3 { font-family: var(--display); color: var(--ink); text-wrap: balance; }
h1 {
  margin: 0;
  font-size: var(--step-3); font-weight: 800; line-height: 1.02; letter-spacing: -0.015em;
  font-variation-settings: "opsz" 96, "wdth" 76;
}
h2 { font-size: var(--step-2); font-weight: 700; line-height: 1.2; font-variation-settings: "opsz" 32, "wdth" 85; margin: 2em 0 0.5em; }
h3 { font-size: var(--step-1); font-weight: 700; margin: 1.6em 0 0.4em; }
.summary {
  margin: 14px 0 0; font-family: var(--reading); font-style: italic;
  font-size: var(--step-1); color: var(--muted); line-height: 1.55;
}

/* --- Reading text -------------------------------------------------------------------- */

.prose { font-family: var(--reading); font-size: var(--step-1); line-height: 1.72; max-width: var(--measure); }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.05em; }
.prose li { margin-bottom: 0.35em; }
.prose h2 { font-size: var(--step-2); }
.prose strong { font-weight: 650; }
.prose :not(pre) > code { background: var(--elephant-wash); padding: 0.1em 0.35em; border-radius: 4px; }
.prose pre {
  background: var(--term); color: var(--term-text);
  font-size: 0.86rem; line-height: 1.6;
  padding: 16px 18px; border-radius: var(--radius); overflow-x: auto; margin: 0 0 1.3em;
  border: 1px solid var(--line);
}
.prose pre code { font-size: inherit; }
.prose blockquote { margin: 0 0 1.1em; padding: 4px 0 4px 18px; border-left: 4px solid var(--marker); color: var(--muted); }
.prose table { border-collapse: collapse; font-family: var(--display); font-size: var(--step--1); margin: 0 0 1.3em; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose th { font-weight: 700; }

/* The road-sign triangle and the word carry the meaning; the orange only helps to find it. */
.callout {
  margin: 1.7em 0; padding: 16px 20px 18px;
  background: var(--warn-soft); border: 1.5px solid var(--warn); border-radius: var(--radius);
}
.prose .callout > :last-child { margin-bottom: 0; }
.prose .callout-label {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px;
  font: 700 var(--step-1)/1.2 var(--display); font-variation-settings: "opsz" 32, "wdth" 85;
  color: var(--warn);
}
.callout-label svg { flex: none; width: 26px; height: 26px; }
.callout-label .sign { fill: var(--warn); stroke: var(--warn); stroke-width: 2; stroke-linejoin: round; }
.callout-label .mark { fill: none; stroke: var(--warn-soft); stroke-width: 2.4; stroke-linecap: round; }
.prose .callout :not(pre) > code { background: color-mix(in srgb, var(--warn) 14%, var(--warn-soft)); }

/* --- Lesson diagrams ----------------------------------------------------------------- */
/* Diagrams are inline SVG drawn only with these classes, so they follow the light and dark theme.
   Contract for diagram files: tracks/<track>/lessons/img/README.md */

.diagram { margin: 1.6em 0 1.9em; max-width: 640px; }
.diagram svg { display: block; width: 100%; height: auto; overflow: visible; }
.diagram figcaption { margin-top: 10px; font-family: var(--display); font-size: var(--step--1); color: var(--muted); line-height: 1.45; }

.dg text { font-family: var(--display); font-size: 14px; fill: var(--ink); }
.dg .t-sm { font-size: 12px; }
.dg .t-lg { font-size: 17px; font-weight: 700; }
.dg .t-b { font-weight: 700; }
.dg .mono { font-family: var(--mono); font-size: 13px; font-variant-ligatures: none; }
.dg .mono.t-sm { font-size: 12px; }
.dg .mono { white-space: pre; }
.dg .muted { fill: var(--muted); }
.dg .on-hot { fill: var(--marker-ink); }
.dg .on-term { fill: var(--term-text); }
.dg .on-accent { fill: var(--on-accent); }

.dg .box { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
.dg .soft { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.dg .accent { fill: var(--elephant-wash); stroke: var(--elephant); stroke-width: 1.5; }
.dg .solid { fill: var(--elephant); stroke: var(--elephant); stroke-width: 1.5; }
.dg .hot { fill: var(--marker); stroke: var(--marker-ink); stroke-width: 1.5; }
.dg .good { fill: var(--ok-wash); stroke: var(--ok); stroke-width: 1.5; }
.dg .bad { fill: var(--bad-wash); stroke: var(--bad); stroke-width: 1.5; }
.dg .term { fill: var(--term); stroke: var(--line); stroke-width: 1; }
.dg .ghost { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; }

.dg .line { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.dg .line-soft { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.dg .line-dash { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.dg .line-accent { fill: none; stroke: var(--elephant); stroke-width: 2; }
.dg .line-bad { fill: none; stroke: var(--bad); stroke-width: 2; }
.dg .head { fill: var(--ink); }
.dg .head-accent { fill: var(--elephant); }
.dg .head-bad { fill: var(--bad); }
.dg .fill-ink { fill: var(--ink); }
.dg .fill-muted { fill: var(--muted); }
.dg .fill-accent { fill: var(--elephant); }
.dg .fill-ok { fill: var(--ok); }
.dg .fill-bad { fill: var(--bad); }

/* --- Quiz ---------------------------------------------------------------------------- */

.quiz { margin-top: 56px; padding-top: 8px; border-top: 3px solid var(--ink); max-width: var(--measure); }
.quiz h2 { margin-top: 18px; }
.quiz-rule { margin: 0 0 22px; color: var(--muted); font-size: var(--step--1); }
.quiz fieldset { border: 0; padding: 0; margin: 0 0 28px; }
.quiz legend { font-weight: 600; font-size: var(--step-1); line-height: 1.4; margin-bottom: 12px; display: flex; gap: 12px; }
.qn {
  flex: none; display: inline-grid; place-items: center;
  width: 1.7em; height: 1.7em; border-radius: 50%;
  background: var(--ink); color: var(--paper); font-size: 0.8em; font-weight: 700;
}
.option {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  cursor: pointer; line-height: 1.45;
}
.option:hover { border-color: var(--elephant); }
.option:has(input:checked) { border-color: var(--elephant); background: var(--elephant-wash); }
.option input { margin-top: 0.25em; accent-color: var(--elephant); }
.wrong-answer .option:has(input:checked):not(.correct) { border-color: var(--bad); background: var(--bad-wash); }
.option.correct { border-color: var(--ok); background: var(--ok-wash); }
.why { margin: 10px 0 0; font-family: var(--reading); color: var(--ink); line-height: 1.6; }
.right-answer .why { border-left: 3px solid var(--ok); padding-left: 12px; }
.wrong-answer .why { border-left: 3px solid var(--bad); padding-left: 12px; }
.quiz-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }

.status { margin: 0; color: var(--muted); }
.status.ok { color: var(--ok); font-weight: 700; }
.status.bad { color: var(--bad); font-weight: 600; }

/* --- Links out and stepping between items -------------------------------------------- */

.practice-it { margin-top: 44px; max-width: var(--measure); }
.practice-it h2 { font-size: var(--step-1); margin: 0 0 8px; }
.practice-it ul { margin: 0; padding-left: 1.2em; }
.practice-it li { margin-bottom: 4px; }

.stepper { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 56px; max-width: var(--measure); }
.step {
  display: flex; flex-direction: column; gap: 3px;
  padding: 16px 20px; border-radius: 8px;
  border: 1.5px solid var(--line); background: var(--surface);
  color: var(--ink); text-decoration: none;
}
.step:hover { border-color: var(--ink); }
.step.next { text-align: right; background: var(--elephant); border-color: var(--elephant); color: var(--on-accent); }
.step.next:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.step-dir { font-size: var(--step--1); opacity: 0.75; }
.step-title { font-weight: 700; font-size: var(--step-1); line-height: 1.25; }
.keys { margin: 14px 0 0; color: var(--muted); font-size: var(--step--1); }
@media (hover: none) { .keys { display: none; } }

/* --- Scenario ------------------------------------------------------------------------ */

.difficulty { display: inline-flex; align-items: center; gap: 7px; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 9px; height: 14px; border: 1.5px solid var(--muted); border-radius: 2px; }
.pips i.on { background: var(--ink); border-color: var(--ink); }

.incident {
  background: var(--surface); border: 1.5px solid var(--line); border-left: 5px solid var(--elephant);
  border-radius: var(--radius); padding: 22px 26px; max-width: var(--measure);
}
.incident h2 { margin: 0 0 12px; font-size: var(--step-1); }
.incident .prose pre { margin-bottom: 0.4em; }
.launch { margin-top: 30px; display: grid; justify-items: start; gap: 10px; }
.launch-note { margin: 0; color: var(--muted); font-size: var(--step--1); }

.empty { color: var(--muted); }

/* --- Attempt workspace --------------------------------------------------------------- */

.attempt-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.attempt-head h1 { font-size: clamp(1.7rem, 3vw, 2.4rem); }
.attempt-head .where { margin-bottom: 8px; }
.actions { display: flex; gap: 10px; }

.workspace { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 22px; align-items: start; }
.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.panel { background: var(--surface); border: 1.5px solid var(--line); border-radius: 8px; padding: 18px 20px; }
.panel h2 { margin: 0; font-size: var(--step-1); }
.brief summary { font-weight: 700; font-size: var(--step-1); cursor: pointer; }
.brief[open] summary { margin-bottom: 12px; }
.brief .prose { font-size: 1rem; line-height: 1.62; }
.side-links, .side-note { margin: 10px 0 0; color: var(--muted); font-size: var(--step--1); }
.hints-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint-item { margin-top: 16px; padding-top: 14px; border-top: 1.5px dashed var(--line); }
.hint-level { margin: 0 0 6px; font-weight: 700; font-size: var(--step--1); color: var(--elephant); }
.hint-level span { color: var(--muted); font-weight: 500; }
.hint-item .prose { font-size: 0.98rem; line-height: 1.6; }

.terminal {
  height: calc(100vh - 230px); min-height: 440px;
  background: var(--term); border-radius: 8px; overflow: hidden;
}
/* xterm paints its viewport pure black by default; the padding lives on .xterm so the fit addon counts it. */
.terminal .xterm { height: 100%; padding: 12px 6px 6px 14px; }
.terminal .xterm-viewport { background-color: var(--term); }
.result { margin-bottom: 14px; padding: 14px 18px; border-radius: 8px; }
.result.fail { background: var(--bad-wash); color: var(--ink); border-left: 5px solid var(--bad); }
.result ul { margin: 6px 0 0; padding-left: 1.2em; }
.solved h2 { color: var(--ok); font-size: var(--step-2); }

/* --- Skills -------------------------------------------------------------------------- */

.due-card {
  display: grid; gap: 4px; margin-bottom: 34px; max-width: var(--measure);
  padding: 16px 20px; border-radius: 8px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-left: 6px solid var(--marker);
}
.due-card:hover { border-color: var(--ink); border-left-color: var(--marker); }
.due-why { color: var(--muted); font-size: var(--step--1); }
.due-title { font-weight: 700; font-size: var(--step-1); }
.skill-list { list-style: none; margin: 0; padding: 0; }
.skill-list li {
  display: grid; grid-template-columns: minmax(130px, 1fr) auto minmax(150px, 1fr); align-items: center; gap: 18px;
  padding: 13px 0; border-bottom: 1.5px solid var(--line);
}
.skill-name { font-weight: 600; }
.meter { display: inline-flex; gap: 3px; }
.meter i { width: 14px; height: 20px; border: 1.5px solid var(--line); border-radius: 2px; background: var(--surface); }
.meter i.on { background: var(--elephant); border-color: var(--elephant); }
.skill-when { color: var(--muted); font-size: var(--step--1); text-align: right; }

/* --- Home ---------------------------------------------------------------------------- */

.courses { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.course-card {
  display: grid; gap: 10px; padding: 24px 26px; border-radius: 10px;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--ink); text-decoration: none;
}
.course-card:hover { border-color: var(--ink); }
.course-title { font-size: var(--step-2); font-weight: 800; font-variation-settings: "opsz" 48, "wdth" 80; }
.course-desc { font-family: var(--reading); color: var(--muted); line-height: 1.55; max-width: 62ch; }
.course-progress { display: flex; flex-wrap: wrap; gap: 6px 22px; font-size: var(--step--1); color: var(--muted); }
.course-progress strong { color: var(--ink); }
.mini-blocks { display: flex; gap: 3px; }
.mini-blocks i { flex: 1; height: 10px; border: 1.5px solid var(--line); border-radius: 2px; }
.mini-blocks i.on { background: var(--elephant); border-color: var(--elephant); }

/* --- Course home --------------------------------------------------------------------- */

.course-time { margin: 22px 0 0; }
.course-time strong, .chapter-facts span { white-space: nowrap; }
.course-go { margin: 20px 0 0; }
.course-go .button { font-size: var(--step-0); padding: 0.85em 1.5em; }

.chapter { max-width: var(--measure); border-top: 1.5px solid var(--line); }
.chapter:last-of-type { border-bottom: 1.5px solid var(--line); }
.chapter summary {
  position: relative; list-style: none; cursor: pointer;
  display: grid; grid-template-columns: minmax(0, 1fr) 96px; align-items: center; gap: 3px 24px;
  padding: 16px 0 16px 28px;
}
.chapter summary::-webkit-details-marker { display: none; }
.chapter summary::before {
  content: ""; position: absolute; left: 5px; top: 25px; width: 8px; height: 8px;
  border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(-45deg);
  transition: transform 120ms ease;
}
.chapter[open] > summary::before { transform: rotate(45deg); }
.chapter summary:hover h2 { color: var(--elephant); }
.chapter h2 { grid-column: 1; margin: 0; }
.chapter-facts { grid-column: 1; display: flex; flex-wrap: wrap; gap: 0 18px; color: var(--muted); font-size: var(--step--1); }
.chapter .mini-blocks { grid-column: 2; grid-row: 1 / span 2; justify-content: end; }
.chapter .mini-blocks i { flex: 0 1 30px; height: 20px; background: var(--surface); }
.chapter .mini-blocks i.on { background: var(--elephant); }
.chapter h3 { margin: 4px 0 0; padding-left: 28px; font-size: var(--step--1); font-weight: 500; color: var(--muted); }

.rows { list-style: none; margin: 0; padding: 0 0 18px 28px; }
.rows li {
  display: grid; grid-template-columns: minmax(0, 1fr) 4rem 6.5rem; align-items: baseline; gap: 0 14px;
  padding: 7px 0;
}
.rows a { justify-self: start; }
.row-minutes, .row-state { font-size: var(--step--1); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.row-state { text-align: left; }
.row-state.passed { color: var(--ink); font-weight: 600; }
.row-state.next { justify-self: start; border-radius: 999px; padding: 1px 10px; background: var(--marker); color: var(--marker-ink); font-weight: 700; }

/* --- Admin --------------------------------------------------------------------------- */

.account a[aria-current="page"] { font-weight: 700; text-decoration: none; box-shadow: 0 3px 0 var(--elephant); }
.admin-facts { display: flex; flex-wrap: wrap; gap: 4px 32px; margin: 18px 0 0; font-size: var(--step--1); }
.admin-facts div { display: flex; gap: 8px; }
.admin-facts dt { color: var(--muted); }
.admin-facts dd { margin: 0; font-weight: 600; }
.admin input {
  min-width: 0; padding: 0.5em 0.7em; font: var(--step--1)/1.4 var(--display); color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--muted); border-radius: var(--radius);
}
.admin input::placeholder { color: var(--muted); opacity: 1; }
.admin-invite { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 28px 0 24px; }
.admin-invite label { font-weight: 600; }
.admin-invite input { flex: 0 1 22rem; }

.users { width: 100%; border-collapse: collapse; font-size: var(--step--1); }
.users th, .users td { padding: 12px 14px 12px 0; text-align: left; vertical-align: top; border-bottom: 1.5px solid var(--line); }
.users thead th { color: var(--muted); font-weight: 500; }
.users-email { overflow-wrap: anywhere; min-width: 9rem; font-weight: 600; }
.users button { padding: 0.5em 0.8em; }
.users-limit, .users-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.users-limit { flex-wrap: nowrap; margin-top: 8px; }
.users-limit button { white-space: nowrap; }
.users-limit input { width: 5.2rem; }

.admin-note { width: fit-content; max-width: min(100%, var(--measure)); margin-top: 24px; }
.admin-note:has(#admin-message:not(:empty)) {
  padding: 14px 18px; background: var(--surface); border: 1.5px solid var(--ink); border-radius: 8px; box-shadow: var(--dock-shadow);
}
#admin-message { margin: 0; overflow-wrap: anywhere; }
#admin-message .status { color: var(--ink); }
#admin-message .status.bad { color: var(--bad); }
/* Not a box of its own, or the button could not stay in view above the start of this part. */
#admin-link { display: contents; }
#admin-link code { display: block; overflow-wrap: anywhere; user-select: all; }
#admin-link p { margin: 10px 0 6px; overflow-wrap: anywhere; }
#admin-copy { position: sticky; bottom: 0; width: 100%; justify-content: center; margin-top: 16px; box-shadow: 0 0 0 14px var(--surface); }
/* Anything focused scrolls clear of the top bar, the message and the chat button. */
html:has(#users) { scroll-padding: 110px 0 70px; }
/* Stays in view, because the button that was pressed may be far from the end of the table. It never takes more
   than this share of the screen, so everything else can be scrolled clear of it. */
@media (min-height: 600px) {
  .admin-note { position: sticky; bottom: 16px; z-index: 10; max-height: 40vh; overflow-y: auto; }
  html:has(#users) { scroll-padding-bottom: 90px; }
  html:has(#admin-message:not(:empty)) { scroll-padding-bottom: calc(40vh + 30px); }
}

@media (max-width: 1000px) {
  .users thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .users, .users tbody, .users tr, .users td, .users th { display: block; }
  .users tr { padding: 14px 0; border-bottom: 1.5px solid var(--line); }
  .users tbody th, .users td { padding: 4px 0; border: 0; }
  .users tbody th { font-size: var(--step-0); }
  .users td::before { content: attr(data-label) ": "; color: var(--muted); }
  .users-actions { margin-top: 8px; }
}

/* --- Chat dock ----------------------------------------------------------------------- */

.dock-launcher {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  background: var(--ink); color: var(--paper); border-color: var(--ink);
  border-radius: 999px; padding: 0.8em 1.25em; font-size: var(--step-0);
  box-shadow: var(--dock-shadow);
}
.dock-launcher:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.dock-launcher-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--marker); }
.dock-launcher[hidden], .dock-launcher-icon { display: none; }

.dock {
  position: fixed; z-index: 45;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface); border: 1.5px solid var(--ink); border-radius: 10px;
  box-shadow: var(--dock-shadow);
  animation: dock-in 160ms ease-out;
  transform-origin: bottom right;
}
.dock[hidden] { display: none; }
@keyframes dock-in { from { opacity: 0; transform: scale(0.96); } }
.dock.moving, .dock.sizing { user-select: none; }
.dock.moving { cursor: grabbing; }

.dock-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px 9px 14px;
  background: var(--ink); color: var(--paper);
  border-radius: 8px 8px 0 0;
  cursor: grab; touch-action: none;
}
.dock-title { display: grid; min-width: 0; flex: 1; line-height: 1.25; }
.dock-title strong { font-size: var(--step-0); }
.dock-context { font-size: 0.78rem; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-level select {
  font: 500 0.8rem var(--display); color: var(--paper); background: transparent;
  border: 1.5px solid color-mix(in srgb, var(--paper) 40%, transparent); border-radius: var(--radius); padding: 4px 6px;
}
.dock-level select option { color: var(--ink); background: var(--surface); }
.dock-close { background: transparent; color: var(--paper); border-color: color-mix(in srgb, var(--paper) 40%, transparent); padding: 4px 10px; font-size: 0.8rem; }
.dock-close:hover:not(:disabled) { background: color-mix(in srgb, var(--paper) 15%, transparent); }

.dock-log { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--elephant-wash); padding: 9px 13px; border-radius: 10px 10px 2px 10px; }
.msg.assistant { align-self: flex-start; font-family: var(--reading); font-size: 0.97rem; }
.msg.assistant p, .msg.assistant ul, .msg.assistant ol { margin: 0 0 0.7em; }
.msg.assistant pre { background: var(--term); color: var(--term-text); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; font-size: 0.8rem; }
.msg.assistant :not(pre) > code { background: var(--elephant-wash); padding: 0.05em 0.3em; border-radius: 3px; }
.msg.pending { color: var(--muted); font-style: italic; }
.msg.error { color: var(--bad); }
.msg.intro { color: var(--muted); font-size: var(--step--1); }

.dock-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; border-top: 1.5px solid var(--line); }
.dock-form textarea {
  resize: none; font: var(--step--1)/1.45 var(--display); color: var(--ink);
  background: var(--paper); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 8px 10px;
}
.dock-form textarea:focus-visible { outline-offset: 0; }

.dock-grip { position: absolute; z-index: 1; touch-action: none; }
.dock-grip.n { top: -5px; left: 12px; right: 12px; height: 10px; cursor: ns-resize; }
.dock-grip.s { bottom: -5px; left: 12px; right: 12px; height: 10px; cursor: ns-resize; }
.dock-grip.e { right: -5px; top: 12px; bottom: 12px; width: 10px; cursor: ew-resize; }
.dock-grip.w { left: -5px; top: 12px; bottom: 12px; width: 10px; cursor: ew-resize; }
.dock-grip.ne, .dock-grip.nw, .dock-grip.se, .dock-grip.sw { width: 18px; height: 18px; }
.dock-grip.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.dock-grip.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.dock-grip.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.dock-grip.se { bottom: -6px; right: -6px; cursor: nwse-resize; }

/* --- Small screens and reduced motion ------------------------------------------------ */

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .track-name, .theme-label { display: none; }
  .terminal { height: 60vh; min-height: 320px; }
}

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px 14px; }
  .account { flex: 1 1 0; justify-content: flex-end; }
  .theme-toggle { order: 1; }
  .top nav { order: 2; flex-basis: 100%; margin-left: -12px; }
  .blocks { gap: 3px; }
  .block { height: 26px; }
  .stepper { grid-template-columns: 1fr; }
  .step.next { order: -1; }
  .skill-list li { grid-template-columns: 1fr auto; }
  .skill-when { grid-column: 1 / -1; text-align: left; }
  .incident { padding: 18px; }
  /* Icon only, and both the end of a page and anything focused scroll clear of it. */
  .dock-launcher { right: 14px; bottom: 14px; width: 48px; height: 48px; padding: 0; justify-content: center; }
  .dock-launcher-icon { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
  .dock-launcher-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .dock-launcher-dot { position: absolute; top: 3px; right: 3px; }
  html { scroll-padding-bottom: 76px; }
  .callout { padding: 14px 14px 16px; }
  .admin-note { max-width: calc(100% - 62px); }
  .chapter summary { grid-template-columns: minmax(0, 1fr) 48px; gap: 3px 14px; }
  .chapter summary, .rows, .chapter h3 { padding-left: 24px; }
  .rows li { grid-template-columns: auto 1fr; gap: 0 14px; padding: 9px 0; }
  .rows a { grid-column: 1 / -1; }
  .chapter .mini-blocks i { flex-basis: 14px; }
}

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