/* Learn: shared styles for every course on this site.
   Plain CSS, no build. Light theme by default, dark via the OS setting or the toggle (html[data-theme]).
   Diagram colours are tokens too, so every SVG follows the theme.
   Actors keep one colour everywhere: host violet, client blue, server green, model pink, auth orange, user grey. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1c2333;
  --muted: #586276;
  --border: #d9dee8;
  --accent: #3157cc;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfb;
  --focus: #3157cc;
  --code-bg: #f2f4f9;
  --mark: #fff1b8;

  --host: #7446c4;   --host-bg: #f1eafb;
  --client: #2563c9; --client-bg: #e5eefc;
  --server: #0d8459; --server-bg: #e0f4ea;
  --model: #bf3b76;  --model-bg: #fbe7f0;
  --auth: #b8620e;   --auth-bg: #fcefdf;
  --user: #4b5568;   --user-bg: #eceef3;

  --req: #2563c9;
  --res: #0d8459;
  --err: #c93636;    --err-bg: #fdeaea;
  --ntf: #7446c4;
  --note: #a86b0c;   --note-bg: #fdf3dc;
  --ok: #0d8459;     --ok-bg: #e0f4ea;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 4px 16px rgba(20, 30, 60, 0.06);
  --topbar-h: 56px;
  --sidebar-w: 288px;
  --measure: 46rem;
  --wide: 62rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10131a; --surface: #181c25; --surface-2: #222836; --text: #e5e8ef; --muted: #9ea7b8; --border: #303849;
    --accent: #7f9dff; --accent-ink: #0d1220; --accent-soft: #1e2947; --focus: #9fb6ff; --code-bg: #0c0f15; --mark: #4d4210;
    --host: #b591f2; --host-bg: #2a2142; --client: #72a5ff; --client-bg: #182641; --server: #4fd2a0; --server-bg: #13302a;
    --model: #f27cad; --model-bg: #3b1b2b; --auth: #f2a65c; --auth-bg: #3b2a16; --user: #b3bbcb; --user-bg: #262c38;
    --req: #72a5ff; --res: #4fd2a0; --err: #ff7f7f; --err-bg: #3a1c1f; --ntf: #b591f2; --note: #f2bd5c; --note-bg: #3a2e15;
    --ok: #4fd2a0; --ok-bg: #13302a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}
:root[data-theme="dark"] {
  --bg: #10131a; --surface: #181c25; --surface-2: #222836; --text: #e5e8ef; --muted: #9ea7b8; --border: #303849;
  --accent: #7f9dff; --accent-ink: #0d1220; --accent-soft: #1e2947; --focus: #9fb6ff; --code-bg: #0c0f15; --mark: #4d4210;
  --host: #b591f2; --host-bg: #2a2142; --client: #72a5ff; --client-bg: #182641; --server: #4fd2a0; --server-bg: #13302a;
  --model: #f27cad; --model-bg: #3b1b2b; --auth: #f2a65c; --auth-bg: #3b2a16; --user: #b3bbcb; --user-bg: #262c38;
  --req: #72a5ff; --res: #4fd2a0; --err: #ff7f7f; --err-bg: #3a1c1f; --ntf: #b591f2; --note: #f2bd5c; --note-bg: #3a2e15;
  --ok: #4fd2a0; --ok-bg: #13302a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* ---------- base ---------- */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1.0625rem/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}
img, svg, video { max-width: 100%; height: auto; }
a { color: var(--accent); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.8rem, 1.4rem + 1.6vw, 2.4rem); font-weight: 750; }
h2 { font-size: clamp(1.35rem, 1.2rem + 0.6vw, 1.6rem); font-weight: 700; }
h3 { font-size: 1.15rem; font-weight: 650; }
h4 { font-size: 1rem; font-weight: 650; }
p, ul, ol { margin: 0; }
code, kbd, pre { font-family: var(--mono); }
:not(pre) > code { font-size: 0.86em; background: var(--surface-2); border: 1px solid var(--border); padding: 0.05em 0.35em; border-radius: 5px; overflow-wrap: anywhere; }
strong { font-weight: 650; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 8px; }
.skip:focus { top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

/* ---------- top bar, sidebar, shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar a { color: var(--text); text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-size: 0.85rem; font-weight: 800; }
.crumb-sep { color: var(--muted); }
.crumb { color: var(--muted) !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; height: 40px; padding: 0 10px;
  background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 10px; font: inherit; font-size: 0.95rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: inline-flex; }

.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: calc(100vh - var(--topbar-h)); }
.shell--wide { grid-template-columns: minmax(0, 1fr); }
.sidebar {
  position: sticky; top: var(--topbar-h); align-self: start; height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  padding: 20px 14px 40px 18px; border-right: 1px solid var(--border); background: var(--surface);
}
.sidebar h2 { font-size: 1.05rem; margin: 0 0 4px; }
.sidebar h2 a { color: var(--text); text-decoration: none; }
.side-progress { margin: 10px 0 18px; font-size: 0.85rem; color: var(--muted); }
.side-module { margin-top: 16px; }
.side-module h3 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; margin-bottom: 6px; }
.side-list { list-style: none; padding: 0; margin: 0; }
.side-list a {
  display: flex; gap: 10px; align-items: flex-start; padding: 6px 8px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-size: 0.94rem; line-height: 1.35;
}
.side-list a:hover { background: var(--surface-2); }
.side-list a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dot { flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 11px; color: transparent; }
.is-done > .dot, .dot.is-done { background: var(--ok); border-color: var(--ok); color: #fff; }
.is-done > .dot::after, .dot.is-done::after { content: "✓"; font-weight: 800; }
[aria-current="page"] > .dot { border-color: var(--accent); }
.scrim { display: none; }

/* sidebar hidden on wide screens (menu button) */
@media (min-width: 961px) {
  .side-collapsed .shell { grid-template-columns: minmax(0, 1fr); }
  .side-collapsed .sidebar { display: none; }
  .side-collapsed .site-foot { margin-left: 0 !important; }
}
/* the current page's sections, under its entry in the sidebar */
.side-toc { list-style: none; margin: 2px 0 8px 17px; padding: 0 0 0 10px; border-left: 2px solid var(--border); }
.side-toc a { display: block; padding: 3px 8px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 0.86rem; line-height: 1.35; }
.side-toc .lv3 a { padding-left: 20px; font-size: 0.82rem; }
.side-toc a:hover { background: var(--surface-2); color: var(--text); }
.side-toc a.is-cur { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
/* heading anchors */
.anchor { margin-left: 0.4em; color: var(--muted); text-decoration: none; font-weight: 500; opacity: 0; transition: opacity 120ms; }
h2:hover > .anchor, h3:hover > .anchor, .anchor:focus-visible { opacity: 1; }
@media (hover: none) { .anchor { opacity: 0.5; } }
/* page-wide transport switch */
.tr-switch { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; font-size: 0.85rem; }
.tr-switch .tr-label { padding: 0 8px; color: var(--muted); }
.tr-switch button { font: inherit; padding: 6px 10px; border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.tr-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
html[data-tr="stdio"] [data-tr-only="http"], html[data-tr="http"] [data-tr-only="stdio"] { display: none !important; }
html[data-tr="stdio"] [data-tr-dim="http"], html[data-tr="http"] [data-tr-dim="stdio"] { opacity: 0.18; transition: opacity 250ms var(--ease); }
.tr-tag { display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: 0.1em; }
@media (max-width: 720px) { .tr-switch .tr-label, .spec-link { display: none; } .tr-switch button { padding: 6px 7px; } }

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 60; top: 0; left: 0; bottom: 0; height: 100vh; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform 260ms var(--ease); box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: none; }
  .scrim.is-open { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10, 14, 24, 0.45); }
  .crumb { max-width: 34vw; }
}
@media (max-width: 520px) {
  .brand-name { display: none; }
  .crumb-sep:first-of-type { display: none; }
  .theme-label { display: none; }
}

/* ---------- main column ---------- */
.page { padding: 32px 16px 80px; min-width: 0; }
.page > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }
.page > .wide, .page .wide { max-width: var(--wide); }
.lesson section, .page > section { margin-top: 48px; }
.lesson section > * + *, .page > section > * + *, .flow > * + * { margin-top: 16px; }
.lesson section > h2 + *, .page > section > h2 + * { margin-top: 12px; }
.lesson section h3 { margin-top: 28px; }
ul.bullets, ol.bullets { padding-left: 1.3rem; }
ul.bullets li + li, ol.bullets li + li { margin-top: 8px; }
.lede { font-size: 1.18rem; color: var(--muted); max-width: 40rem; }
.lesson-head > * + * { margin-top: 14px; }
.lesson-kicker { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.lesson-kicker:empty { display: none; }

/* objectives */
.objectives { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.objectives h2 { font-size: 1rem; margin-bottom: 8px; }
.objectives ul { list-style: none; padding: 0; }
.objectives li { position: relative; padding-left: 28px; }
.objectives li + li { margin-top: 6px; }
.objectives li::before { content: ""; position: absolute; left: 2px; top: 0.45em; width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--accent); }

/* callouts */
.callout { border-radius: var(--radius); padding: 14px 18px 14px 16px; border: 1px solid var(--border); border-left: 5px solid var(--accent); background: var(--surface); }
.callout > * + * { margin-top: 8px; }
.callout-label { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 750; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.callout-label::before { content: ""; width: 18px; height: 18px; border-radius: 50%; background: currentColor; -webkit-mask: var(--icon) center / 18px no-repeat; mask: var(--icon) center / 18px no-repeat; }
.callout--key { border-left-color: var(--accent); background: var(--accent-soft); }
.callout--key .callout-label { color: var(--accent); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 21h6v-2H9v2zm3-19a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2z'/%3E%3C/svg%3E"); }
.callout--myth { border-left-color: var(--note); background: var(--note-bg); }
.callout--myth .callout-label { color: var(--note); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z'/%3E%3C/svg%3E"); }
.callout--rule { border-left-color: var(--host); background: var(--host-bg); }
.callout--rule .callout-label { color: var(--host); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 2h9l5 5v15H6V2zm8 1.5V8h4.5L14 3.5zM8 12h10v2H8v-2zm0 4h10v2H8v-2z'/%3E%3C/svg%3E"); }
.callout--lab { border-left-color: var(--server); background: var(--server-bg); }
.callout--lab .callout-label { color: var(--server); --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 2h6v2h-1v5.3l5.6 9.7A2 2 0 0 1 17.9 22H6.1a2 2 0 0 1-1.7-3l5.6-9.7V4H9V2z'/%3E%3C/svg%3E"); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; vertical-align: top; padding: 10px 14px; border-bottom: 1px solid var(--border); }
thead th { background: var(--surface-2); font-weight: 650; font-size: 0.9rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody td:first-child { font-weight: 600; }
.table-wrap.plain-first tbody td:first-child { font-weight: 400; }
@media (max-width: 640px) { table { min-width: 560px; } }

/* code */
pre.code, .code-block pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  overflow-x: auto; font-size: 0.84rem; line-height: 1.6; margin: 0; tab-size: 2;
}
.code-title { font-size: 0.85rem; color: var(--muted); font-family: var(--mono); margin-bottom: 6px; }
.c { color: var(--muted); font-style: italic; }
.k { color: var(--host); }
.s { color: var(--server); }
.n { color: var(--auth); }
.hl { background: var(--mark); border-radius: 3px; }

/* figures and photos */
figure { margin: 0; }
figcaption { font-size: 0.88rem; color: var(--muted); margin-top: 8px; }
.photo { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 18px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.photo img { border-radius: var(--radius-sm); display: block; width: 100%; height: auto; max-height: 300px; object-fit: cover; }
.photo figcaption { margin: 0; font-size: 0.95rem; color: var(--text); }
.photo figcaption small { display: block; margin-top: 6px; color: var(--muted); font-size: 0.8rem; }
@media (max-width: 560px) { .photo { grid-template-columns: 1fr; } }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 760px) { .two-col { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.card > * + * { margin-top: 8px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 0.95rem; font-weight: 550; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn--sm { min-height: 34px; padding: 5px 12px; font-size: 0.88rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select, input[type="text"], textarea {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; min-height: 40px; max-width: 100%;
}
textarea { width: 100%; min-height: 120px; line-height: 1.5; }
label { cursor: pointer; }

/* ---------- interactive panels ---------- */
.try {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px 20px; box-shadow: var(--shadow);
}
.lesson section.try { padding: 22px 20px; }
.try > h2::before { content: "Try it"; display: block; font-size: 0.78rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--server); margin-bottom: 4px; }
.panel { background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }
.panel pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.8rem; line-height: 1.55; max-height: 340px; overflow: auto; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
.verdict { font-weight: 650; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--err); }
.pill-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.pill-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-family: var(--mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.pill-list li.bad { background: var(--err-bg); border-color: var(--err); color: var(--err); }
.pill-list li.good { background: var(--ok-bg); border-color: var(--ok); }
.pill-list li span { font-family: var(--font); font-size: 0.8rem; color: inherit; opacity: 0.85; white-space: nowrap; }
.log { font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; max-height: 360px; overflow: auto; margin: 0; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* tabs */
.tab-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tab-list button { font: inherit; font-size: 0.92rem; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.tab-list button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.js [data-tabs] > [data-tab][hidden] { display: none; }
[data-tabs] > [data-tab] > * + * { margin-top: 10px; }
.js [data-tabs] > [data-tab] > .tab-heading { display: none; }
.js [data-tabs] > [data-tab] > .tab-heading + * { margin-top: 0; }
html:not(.js) [data-tabs] > [data-tab] + [data-tab] { margin-top: 18px; }

/* ---------- glossary term + tooltip ---------- */
.term { border-bottom: 1.5px dotted var(--accent); cursor: help; color: inherit; }
.term:focus-visible { outline-offset: 1px; }
.term-tip {
  position: absolute; z-index: 80; max-width: min(340px, calc(100vw - 32px)); padding: 12px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 0.9rem; line-height: 1.5; box-shadow: var(--shadow);
}
.term-tip strong { display: block; margin-bottom: 2px; }
.term-tip a { color: inherit; font-size: 0.85rem; }
.term-tip[hidden] { display: none; }

/* ---------- animated diagram player ---------- */
.anim { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.anim-title { font-weight: 650; font-size: 0.98rem; margin: 2px 4px 10px; }
.anim > svg, .anim-scroll > svg { display: block; width: 100%; height: auto; }
.anim-scroll { overflow-x: auto; }
.anim-scroll > svg { min-width: 600px; }
.swipe-hint { font-size: 0.82rem; color: var(--muted); margin: 0 4px 6px; }
.anim-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.anim-controls { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.anim-controls input[type="range"] { flex: 1 1 140px; width: auto; }
.anim-pos { font-size: 0.85rem; color: var(--muted); min-width: 6.5em; text-align: right; }
.anim .anim-steps { margin-top: 10px; padding-left: 1.6rem; font-size: 0.93rem; }
.anim .anim-steps li + li { margin-top: 4px; }
.js .anim .anim-steps li { padding: 6px 8px; border-radius: 8px; cursor: pointer; border-left: 3px solid transparent; }
.js .anim .anim-steps li::marker { font-weight: 700; color: var(--muted); }
.js .anim .anim-steps li.is-past { color: var(--muted); }
.js .anim .anim-steps li.is-past:hover { background: var(--surface-2); }
.js .anim .anim-steps li.is-cur { background: var(--accent-soft); border-left-color: var(--accent); color: var(--text); }
.js .anim .anim-steps li.is-cur::marker { color: var(--accent); }
.js .anim .anim-steps li.is-future { display: none; }
.anim-steps .code-ref { margin-top: 6px; }
/* diagram parts */
svg text { font-family: var(--font); fill: var(--text); font-size: 15px; }
svg .t-sm { font-size: 12.5px; }
svg .t-lg { font-size: 17px; }
svg .t-b { font-weight: 650; }
svg .t-muted { fill: var(--muted); }
svg .t-mono { font-family: var(--mono); font-size: 12.5px; }
svg .t-req { fill: var(--req); } svg .t-res { fill: var(--res); } svg .t-err { fill: var(--err); } svg .t-ntf { fill: var(--ntf); }
svg .t-host { fill: var(--host); } svg .t-client { fill: var(--client); } svg .t-server { fill: var(--server); } svg .t-model { fill: var(--model); } svg .t-auth { fill: var(--auth); }
svg .box { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
svg .box-2 { fill: var(--surface-2); stroke: none; }
svg .box.host { fill: var(--host-bg); stroke: var(--host); }
svg .box.client { fill: var(--client-bg); stroke: var(--client); }
svg .box.server { fill: var(--server-bg); stroke: var(--server); }
svg .box.model { fill: var(--model-bg); stroke: var(--model); }
svg .box.auth { fill: var(--auth-bg); stroke: var(--auth); }
svg .box.user { fill: var(--user-bg); stroke: var(--user); }
svg .box.err { fill: var(--err-bg); stroke: var(--err); }
svg .box.ok { fill: var(--ok-bg); stroke: var(--ok); }
svg .box.note { fill: var(--note-bg); stroke: var(--note); }
svg .box.dash { stroke-dasharray: 6 5; }
svg .ln { fill: none; stroke: var(--muted); stroke-width: 2; }
svg .ln.req { stroke: var(--req); } svg .ln.res { stroke: var(--res); } svg .ln.err { stroke: var(--err); } svg .ln.ntf { stroke: var(--ntf); }
svg .ln.host { stroke: var(--host); } svg .ln.client { stroke: var(--client); } svg .ln.server { stroke: var(--server); } svg .ln.auth { stroke: var(--auth); } svg .ln.model { stroke: var(--model); }
svg .ln.dash { stroke-dasharray: 6 5; }
svg .ln.thin { stroke-width: 1.5; }
svg .ln.faint { stroke: var(--border); }
svg .guide { fill: none; stroke: none; }
svg .ah { fill: var(--muted); }
svg .ah.req { fill: var(--req); } svg .ah.res { fill: var(--res); } svg .ah.err { fill: var(--err); } svg .ah.ntf { fill: var(--ntf); }
svg .pkt circle, svg circle.pkt { stroke: var(--surface); stroke-width: 2; }
svg .pkt.req circle, svg circle.pkt.req { fill: var(--req); }
svg .pkt.res circle, svg circle.pkt.res { fill: var(--res); }
svg .pkt.err circle, svg circle.pkt.err { fill: var(--err); }
svg .pkt.ntf circle, svg circle.pkt.ntf { fill: var(--ntf); }
svg .pkt rect { stroke-width: 1.5; }
svg .pkt.req rect { fill: var(--client-bg); stroke: var(--req); }
svg .pkt.res rect { fill: var(--ok-bg); stroke: var(--res); }
svg .pkt.err rect { fill: var(--err-bg); stroke: var(--err); }
svg .pkt.ntf rect { fill: var(--host-bg); stroke: var(--ntf); }
svg .pkt.note rect { fill: var(--note-bg); stroke: var(--note); }
svg .pkt text { font-size: 12px; font-weight: 600; font-family: var(--mono); }
.pkt { opacity: 0; }
.js .anim [data-in], .js .anim [data-only] { opacity: 0; transition: opacity 350ms var(--ease); }
.js .anim [data-in].is-in, .js .anim [data-only].is-in { opacity: 1; }
.js .anim .is-out { opacity: 0 !important; }
.js .anim .pkt.is-active { opacity: 1; }
.anim .is-active > .box, .anim .box.is-active { stroke-width: 3; }
.anim .is-active { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 45%, transparent)); }
html:not(.js) .anim .pkt { display: none; }

/* ---------- sequence stepper ---------- */
.stepper { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.stepper:focus-visible { outline-offset: 4px; }
.st-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.st-bar + .st-bar { margin-top: 8px; }
.st-bar select { flex: 1 1 260px; }
.st-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.st-seg button { font: inherit; font-size: 0.9rem; padding: 7px 12px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; }
.st-seg button + button { border-left: 1px solid var(--border); }
.st-seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.st-bar input[type="range"] { flex: 1 1 160px; width: auto; }
.st-pos { font-size: 0.85rem; color: var(--muted); }
.st-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 12px; align-items: start; }
.st-diagram { max-height: 380px; overflow: auto; border-radius: var(--radius); background: var(--surface-2); padding: 6px; }
.st-diagram svg { display: block; width: 100%; min-width: 520px; height: auto; }
.st-diagram .msg { cursor: pointer; }
.st-diagram .msg.future { opacity: 0.22; }
.st-diagram .msg.cur .mline { stroke-width: 3.5; }
.st-diagram .msg.cur .mlabel { font-weight: 700; }
.st-diagram .msg:hover .mhit { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.st-diagram .mhit { fill: transparent; }
.st-diagram .msg.cur .mhit { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.st-detail > * + * { margin-top: 10px; }
.st-title { font-weight: 650; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.kind { display: inline-block; font-size: 0.72rem; font-weight: 750; letter-spacing: 0.04em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--req); }
.kind--res { background: var(--res); } .kind--err { background: var(--err); } .kind--ntf { background: var(--ntf); } .kind--note { background: var(--note); }
:root[data-theme="dark"] .kind { color: #0d1220; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kind { color: #0d1220; } }
.st-wire { background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.78rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; margin: 0; }
.st-wire-wrap { position: relative; }
.st-raw { position: absolute; top: 6px; right: 6px; font: inherit; font-size: 0.75rem; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; }
.st-raw[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
/* JSON and wire colours */
.jk { color: var(--client); }
.js-s { color: var(--server); }
.jn { color: var(--auth); }
.jb { color: var(--model); }
.wh { color: var(--host); font-weight: 600; }
.wk { color: var(--note); }
/* lab code references */
.code-ref details { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.code-ref summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; padding: 6px 10px; font-size: 0.88rem; }
.code-ref-k { font-size: 0.7rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.05em; color: var(--server); }
.code-ref-file { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); margin-left: auto; }
.code-ref pre { margin: 0 8px; font-size: 0.78rem; border-radius: 6px; }
.code-ref-gh { font-size: 0.82rem; padding: 6px 10px 8px; }
.code-lines .lno { display: inline-block; width: 2.6em; margin-right: 10px; text-align: right; color: var(--muted); opacity: 0.6; user-select: none; }
.panel pre .lno { width: 2.2em; }
.st-rule { font-size: 0.9rem; border-left: 4px solid var(--host); background: var(--host-bg); padding: 8px 12px; border-radius: 0 8px 8px 0; }
.st-rule:empty { display: none; }
.st-why { font-size: 0.95rem; }
.st-state { font-size: 0.9rem; }
.st-steps { font-size: 0.9rem; }
.st-steps summary { cursor: pointer; color: var(--muted); }
.st-steps ol { margin-top: 8px; padding-left: 1.5rem; }
.st-steps li { cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.st-steps li.cur { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.st-steps li.past { color: var(--muted); }

/* ---------- quiz ---------- */
.quiz { display: grid; gap: 18px; }
.quiz-q { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.quiz-prompt { font-weight: 600; }
.quiz-prompt .qnum { color: var(--muted); font-weight: 500; margin-right: 6px; }
.quiz-options { list-style: none; padding: 0; margin-top: 10px; display: grid; gap: 8px; }
.quiz-opt {
  width: 100%; text-align: left; font: inherit; font-size: 0.97rem; padding: 10px 14px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text); display: flex; gap: 10px; align-items: flex-start;
}
.quiz-opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-opt .mark { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 12px; font-weight: 800; margin-top: 1px; }
.quiz-opt.is-right { border-color: var(--ok); background: var(--ok-bg); }
.quiz-opt.is-right .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.quiz-opt.is-right .mark::after { content: "✓"; }
.quiz-opt.is-wrong { border-color: var(--err); background: var(--err-bg); }
.quiz-opt.is-wrong .mark { background: var(--err); border-color: var(--err); color: #fff; }
.quiz-opt.is-wrong .mark::after { content: "✕"; }
.quiz-opt:disabled { cursor: default; }
.quiz-feedback { margin-top: 10px; font-weight: 650; }
.quiz-feedback.ok { color: var(--ok); } .quiz-feedback.bad { color: var(--err); }
.quiz-explain { margin-top: 8px; font-size: 0.95rem; }
.js .quiz-explain:not(.is-shown) { display: none; }
.quiz-summary { font-weight: 600; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---------- sorter ---------- */
.sort-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.sort-item { background: var(--bg); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.sort-item.is-right { border-color: var(--ok); background: var(--ok-bg); }
.sort-item.is-wrong { border-color: var(--err); background: var(--err-bg); }
.sort-item .btn-row { margin-top: 8px; }
.sort-why { display: block; margin-top: 8px; font-size: 0.92rem; }
.js .sort-item:not(.is-answered) .sort-why { display: none; }
.sort-score { font-weight: 600; margin-top: 12px; }

/* ---------- recap, lesson footer ---------- */
.recap ul { list-style: none; padding: 0; display: grid; gap: 10px; }
.recap li { position: relative; padding: 12px 14px 12px 44px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.recap li::before { content: "✓"; position: absolute; left: 14px; top: 12px; width: 20px; height: 20px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.lesson-foot { margin-top: 56px; display: grid; gap: 18px; }
.complete-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-radius: var(--radius); background: var(--accent-soft); }
.complete-box.is-done { background: var(--ok-bg); }
.pager { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.pager a { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--text); }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--muted); font-size: 0.82rem; }
.pager strong { color: var(--accent); }
.pager .next { text-align: right; grid-column: 2; }
@media (max-width: 520px) { .pager { grid-template-columns: minmax(0, 1fr); } .pager .next { grid-column: 1; } }
.site-foot { border-top: 1px solid var(--border); padding: 24px 16px 40px; color: var(--muted); font-size: 0.88rem; }
.site-foot > div { max-width: var(--measure); margin: 0 auto; }
@media (min-width: 961px) { .has-sidebar .site-foot { margin-left: var(--sidebar-w); } }

/* ---------- progress, course outline, hub ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--ok); width: 0; transition: width 400ms var(--ease); }
.hero { padding: 8px 0 0; }
.hero > * + * { margin-top: 14px; }
.continue { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; padding: 18px 20px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.continue .progress { width: 100%; }
.continue-text { flex: 1 1 260px; }
.continue-text > * + * { margin-top: 4px; }
.module { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; }
.module + .module { margin-top: 14px; }
.module-head { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.module-head p { color: var(--muted); font-size: 0.9rem; }
.module ol { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 4px; }
.module ol a { display: flex; gap: 12px; align-items: flex-start; padding: 10px 10px; border-radius: 10px; text-decoration: none; color: var(--text); }
.module ol a:hover { background: var(--surface-2); }
.module ol .ltitle { font-weight: 600; display: block; }
.module ol .lsum { color: var(--muted); font-size: 0.92rem; display: block; }
.module ol .lmin { margin-left: auto; color: var(--muted); font-size: 0.85rem; white-space: nowrap; padding-left: 8px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.topic { display: flex; flex-direction: column; gap: 10px; padding: 20px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); text-decoration: none; }
a.topic:hover { border-color: var(--accent); }
.topic h2 { font-size: 1.3rem; }
.topic p { color: var(--muted); }
.topic .btn { align-self: flex-start; margin-top: auto; }
.topic--soon { box-shadow: none; border-style: dashed; background: transparent; }
.loop { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; counter-reset: loop; }
.loop li { list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; counter-increment: loop; }
.loop li::before { content: counter(loop); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 0.9rem; margin-bottom: 8px; }
.loop li strong { display: block; }
.loop li span { color: var(--muted); font-size: 0.92rem; }
@media (max-width: 760px) { .loop { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 18px; }
.faq details + details { margin-top: 10px; }
.faq summary { cursor: pointer; padding: 14px 0; font-weight: 600; }
.faq details > div { padding-bottom: 16px; }
.faq details > div > * + * { margin-top: 10px; }
.glossary-list { display: grid; gap: 10px; }
.glossary-list dt { font-weight: 700; }
.glossary-list dd { margin: 2px 0 0; color: var(--text); }
.glossary-list div { padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.phase { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; }
.phase + .phase { margin-top: 12px; }
.phase.is-current { border: 2px solid var(--accent); }
.phase-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.phase-num { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface-2); flex: none; }
.phase.is-done .phase-num { background: var(--ok); color: #fff; }
.phase.is-current .phase-num { background: var(--accent); color: var(--accent-ink); }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge--here { background: var(--accent); color: var(--accent-ink); }
.badge--done { background: var(--ok-bg); color: var(--ok); }
.phase .bullets { margin-top: 8px; }
.phase details { margin-top: 8px; }
.phase summary { cursor: pointer; color: var(--accent); font-size: 0.95rem; }
.checklist { list-style: none; padding: 0; display: grid; gap: 8px; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.checklist input { margin-top: 0.35em; width: 18px; height: 18px; accent-color: var(--ok); flex: none; }

/* motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .sidebar, .anim-controls, .lesson-foot .pager { display: none !important; }
  .shell { display: block; }
}

/* form fields inside panels */
.panel.flow > label { display: block; font-size: 0.92rem; }
.panel.flow > label > select, .panel.flow > label > input[type="text"] { display: block; width: 100%; margin-top: 4px; }
fieldset.panel { margin: 0; min-width: 0; }
fieldset.panel label { display: flex; gap: 8px; align-items: center; padding: 3px 0; }

/* where things run: your machine vs the internet */
svg .region { stroke-width: 1.5; stroke-dasharray: 7 5; }
svg .region.local { fill: none; stroke: var(--border); }
svg .region.net { fill: color-mix(in srgb, var(--client) 6%, transparent); stroke: var(--client); }
svg .region-label { font-size: 11.5px; letter-spacing: 0.08em; }
svg .globe circle, svg .globe ellipse, svg .globe path { fill: none; stroke: var(--client); stroke-width: 1.4; }
svg .box.server.remote { stroke-width: 2.5; stroke-dasharray: none; filter: drop-shadow(0 2px 4px color-mix(in srgb, var(--client) 25%, transparent)); }

.grid-3 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.verdict.warn { color: var(--note); }
.side-n { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 2px; }
