/* Kernel Systems Academy — KSA Terminal Course & Component Stylesheet (course.css) */
*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--text);
  scroll-padding-top: calc(var(--topbar-h) + 16px);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-prose);
  font-size: var(--prose-size, 18px);
  line-height: var(--prose-leading, 1.7);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}
a:hover { color: var(--accent-hover); }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--term-bg);
  color: var(--term-bright);
  font: 700 14px var(--font-mono);
  border-radius: var(--radius-control);
  text-decoration: none;
}
.skip-link:focus, .skip-link:focus-visible { top: 8px; }

:where(button, .btn, summary, [role="button"], input[type="checkbox"], input[type="radio"],
a.heading-anchor, .term-gloss, .topbar a, .footer-links a) {
  min-width: 24px;
  min-height: 24px;
}

/* Reading progress bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 60;
  pointer-events: none;
  background: transparent;
}
.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--ansi-green);
  transition: width 80ms linear;
}

/* Top bar (52px sticky terminal bar, single non-wrapping row down to 320px) */
.topbar, .site-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 16px;
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  max-height: var(--topbar-h);
  padding: 0 12px 0 16px;
  background: var(--term-bg);
  color: var(--term-fg);
  font: 14px/1.4 var(--font-mono);
  border-bottom: 1px solid var(--term-edge);
}
.topbar :focus-visible { outline-color: var(--term-badge-bg); }

.brand, .topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  flex: none;
  color: var(--term-bright);
  font: 700 14px/1.4 var(--font-mono);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover, .topbar-brand:hover { color: var(--term-bright); }
.brand-mark { color: var(--ansi-green); font-weight: 700; }

.topbar-course {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--term-dim);
}
.topbar-course b { color: var(--term-fg); }

.topbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  flex: none;
}

.tb-btn, .topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-control);
  color: var(--term-fg);
  font: 600 14px var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
}
.tb-btn:hover, .topbar-btn:hover { background: var(--term-hover); color: var(--term-bright); }
.tb-btn[aria-pressed="true"], .topbar-btn[aria-pressed="true"] {
  background: var(--term-hl);
  color: var(--term-bright);
}

.tb-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  min-width: 210px;
  padding: 0 10px;
  border: 1px solid var(--term-grid);
  border-radius: var(--radius-control);
  background: var(--term-bg);
  color: var(--term-dim);
  font: 14px var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
}
.tb-search:hover { border-color: var(--term-dim); background: var(--term-hover); }
.fzf-p, .tb-search .fzf-p { color: var(--ansi-blue); font-weight: 700; }
kbd, .tb-search kbd {
  margin-left: auto;
  padding: 0 6px;
  border: 1px solid var(--term-grid);
  border-radius: 4px;
  background: transparent;
  color: var(--term-fg);
  font: 600 14px var(--font-mono);
}

.tb-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tb-progress .br { color: var(--term-dim); }
.tb-progress .fill { color: var(--ansi-green); }
.tb-progress .empty { color: var(--term-grid); }

.tb-cta, .topbar-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  margin-left: 6px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--ansi-green);
  color: var(--term-bg);
  font: 700 14px var(--font-mono);
  text-decoration: none;
  white-space: nowrap;
}
.tb-cta:hover, .topbar-cta:hover {
  background: var(--ansi-br-green);
  color: var(--term-bg);
}

.outline-toggle { display: none; flex: none; }
.search-ico { display: none; }

@media (max-width: 1199px) {
  .outline-toggle { display: inline-flex; }
}
@media (max-width: 960px) {
  .topbar-course { display: none; }
}
@media (max-width: 767px) {
  .tb-progress .ascii,
  .tb-search .lbl,
  .tb-search kbd,
  .tb-search .fzf-p { display: none; }
  .search-ico { display: block; color: var(--term-fg); }
  .tb-search { min-width: 44px; min-height: 44px; padding: 0 10px; justify-content: center; }
  .topbar, .site-topbar { gap: 8px; padding: 0 6px 0 12px; }
  .brand .full { display: none; }
}
@media (max-width: 560px) {
  .tb-progress { display: none; }
  .outline-toggle .topbar-btn-label { display: none; }
}
@media (max-width: 440px) {
  .topbar, .site-topbar { gap: 4px; padding: 0 6px 0 8px; }
  .tb-btn, .topbar-btn { padding: 0 8px; }
  .tb-search { min-width: 40px; padding: 0 8px; }
  .tb-cta, .topbar-cta { margin-left: 2px; padding: 0 11px; }
}
@media (max-width: 359px) {
  .tb-cta, .topbar-cta { display: none; }
  .topbar, .site-topbar { gap: 3px; padding: 0 4px 0 6px; }
  .tb-btn, .topbar-btn { padding: 0 6px; font-size: 13px; }
}

/* Primary KSA Terminal layout + companion .course-shell compatibility */
.layout {
  flex: 1 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 220px;
  gap: 32px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px 0;
  align-items: start;
}
.rail {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow: auto;
}
.content {
  min-width: 0;
  max-width: 960px;
  font-size: var(--prose-size, 18px);
  line-height: var(--prose-leading, 1.7);
}
.content > * { margin: 0; }
.content > * + * { margin-top: 24px; }
.content > h2 { margin-top: 64px; }
.content > h3 { margin-top: 36px; }
.content > .crumbs + h1 { margin-top: 6px; }
.content > h1 + .lede { margin-top: 10px; }
.content > p,
.content > .lede,
.content > ul:not(.marker-list),
.content > ol:not(.callouts) {
  max-width: var(--prose-measure, 32em);
}
.lede { font-size: 1.06em; color: var(--text-2); }
.toc-inline { display: none; }
.meta .outline-btn { display: none; }

@media (max-width: 1439px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); }
  .layout > .toc-rail { display: none; }
  .toc-inline { display: block; }
}
@media (max-width: 1199px) {
  .layout { grid-template-columns: minmax(0, 1fr); max-width: 1008px; }
  .outline-rail { display: none; }
  .meta .outline-btn { display: inline-flex; }
}
@media (max-width: 767px) {
  .layout { padding: 20px 16px 0; }
}
@media (max-width: 640px) {
  .build-grid > *, .module-card { min-width: 0; }
  .content p, .content li, .content h1, .content h2, .content h3, .content h4,
  .lede, .build-card p, .content :not(pre) > code { overflow-wrap: anywhere; }
}

/* Companion shell (.course-shell / .app-shell) */
.course-shell, .app-shell {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1560px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 960px) 240px;
  justify-content: center;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-5) var(--space-8);
}
.outline-sidebar {
  width: 280px;
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 36px);
  overflow-y: auto;
  padding-right: var(--space-2);
  font-size: 0.9375rem;
}
.content-col { width: 100%; max-width: 960px; min-width: 0; }
.course-shell > .toc-rail {
  width: 240px;
  position: sticky;
  top: calc(var(--topbar-h) + 20px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 36px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  padding-left: var(--space-4);
  font-size: 0.9375rem;
}
.inline-toc {
  display: none;
  margin-block: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-3) var(--space-4);
}
@media (min-width: 1200px) and (max-width: 1439px) {
  .course-shell, .app-shell { grid-template-columns: 280px minmax(0, 960px); }
  .course-shell > .toc-rail { display: none; }
  .inline-toc { display: block; }
}
@media (max-width: 1199px) {
  .course-shell, .app-shell { grid-template-columns: minmax(0, 960px); padding-inline: var(--space-4); }
  .outline-sidebar, .course-shell > .toc-rail { display: none; }
  .inline-toc { display: block; }
}

/* Focus mode hides sidebars cleanly */
html[data-focus="1"] .layout,
html[data-focus="1"] .course-shell,
html[data-focus="1"] .app-shell {
  grid-template-columns: minmax(0, 960px);
  justify-content: center;
}
html[data-focus="1"] .outline-rail,
html[data-focus="1"] .toc-rail,
html[data-focus="1"] .outline-sidebar {
  display: none !important;
}

/* Prose breakout helper */
.prose {
  font-size: var(--prose-size, 18px);
  line-height: var(--prose-leading, 1.7);
  max-width: min(960px, 100%);
  color: var(--text);
  min-width: 0;
  overflow-wrap: break-word;
}
.prose > p,
.prose > ul:not(.marker-list),
.prose > ol:not(.callouts),
.prose > blockquote,
.prose > section.topic > p,
.prose > section.topic > ul:not(.marker-list),
.prose > section.topic > ol:not(.callouts) {
  max-width: min(var(--prose-measure, 32em), 100%);
}
.prose p { margin-block: 0 1.1em; }
.prose ul:not(.marker-list), .prose ol:not(.callouts) { margin-block: 0 1.1em; padding-left: 1.4em; }
.prose li { margin-bottom: 0.35em; }
.prose > .term, .prose > .diag, .prose > .panel, .prose > .table-scroll, .prose > .callouts,
.prose > section.topic > .term, .prose > section.topic > .diag, .prose > section.topic > .panel,
.prose > section.topic > .table-scroll, .prose > section.topic > .callouts {
  margin-block: 1.25em;
}

/* Breadcrumb as a prompt */
.crumbs { font: 15px/1.5 var(--font-mono); color: var(--text-2); overflow-wrap: anywhere; }
.crumbs .u { color: var(--prompt-user); font-weight: 700; }
.crumbs a, .crumbs .cur { color: var(--prompt-path); font-weight: 700; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* Headings in Noto Sans Mono 700 */
h1, h2, h3, h4 {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
h1 { font-size: 1.7em; line-height: 1.25; }
h2 { font-size: 1.3em; line-height: 1.35; }
h3 { font-size: 1.05em; line-height: 1.4; }
h4 { font-size: 1.0em; line-height: 1.4; }
.hash {
  color: var(--text-3);
  font-weight: 400;
  user-select: none;
  -webkit-user-select: none;
}
.heading-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  color: var(--text-3);
  text-decoration: none;
  opacity: 0;
  vertical-align: middle;
  border-radius: 4px;
}
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
  color: var(--accent);
}

/* Tags & Meta */
.meta { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-tag);
  background: var(--surface);
  color: var(--text-2);
  font: 14px/1 var(--font-mono);
  text-decoration: none;
}
a.tag, button.tag { color: var(--accent); cursor: pointer; }
a.tag:hover, button.tag:hover { border-color: var(--accent); background: var(--surface-2); }
.tag-preview {
  background: var(--hint-bg);
  color: var(--hint);
  border-color: color-mix(in srgb, var(--hint) 40%, transparent);
}

/* Panels & Marker Lists */
.panel {
  min-width: 0;
  max-width: 40em;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.panel-head { margin: 0 0 8px; font: 700 15px/1.6 var(--font-mono); color: var(--text); }
summary.panel-head { cursor: pointer; margin: 0; }
details[open] > summary.panel-head { margin-bottom: 8px; }
.marker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.marker-list li { position: relative; padding-left: 2ch; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
.marker-list li::before {
  content: "›" / "";
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
}

/* Inline code */
code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  tab-size: 8;
}
.ic, :not(pre) > code {
  padding: 1px 5px;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.84em;
  overflow-wrap: anywhere;
}

/* Terminal window (.term) */
.term {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--window-edge);
  border-radius: var(--radius-window);
  background: var(--term-bg);
  box-shadow: var(--window-shadow);
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--term-edge);
  background: var(--term-bar);
  color: var(--term-title);
  font: 14px/1.4 var(--font-mono);
}
.term-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
  color: inherit;
  letter-spacing: 0;
}
.term-btn {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--term-fg);
  font: 600 14px var(--font-prose);
  cursor: pointer;
  white-space: nowrap;
}
.term-btn:hover { background: var(--term-hover); color: var(--term-bright); }
.term-btn:disabled { opacity: 0.45; cursor: default; }
.term :focus-visible { outline-color: var(--term-badge-bg); }
.term-step-pos {
  flex: none;
  padding: 0 6px;
  color: var(--term-dim);
  font: 13px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.term-controls { flex: none; display: flex; gap: 8px; padding-left: 4px; }
@media (max-width: 480px) { .term-controls { display: none; } }
@media (max-width: 375px) {
  .term-bar { flex-wrap: wrap; }
  .term-title { flex: 1 1 110px; }
}
.ctl-bg { fill: var(--term-control); }
.ctl-glyph {
  fill: none;
  stroke: var(--term-title);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.term-body {
  margin: 0;
  overflow-x: auto;
  background: var(--term-bg);
  color: var(--term-fg);
  font-family: var(--font-mono);
  font-size: calc(var(--prose-size, 18px) * 0.8055);
  line-height: 22px;
  tab-size: 8;
  font-variant-ligatures: none;
}
.term-body > code {
  display: inline-block;
  min-width: 100%;
  padding: 14px 0 16px;
  font: inherit;
  background: transparent;
  border: 0;
  color: inherit;
  white-space: pre;
}
.row { display: block; padding: 0 16px; min-height: 22px; }
.row.hl { background: var(--term-hl); }
.grid { color: var(--term-grid); }
.ln { color: var(--term-dim); }
.gbadge {
  display: inline-block;
  width: 2ch;
  border-radius: 3px;
  background: var(--term-badge-bg);
  color: var(--term-badge-fg);
  font-weight: 700;
  text-align: center;
}

/* Copy safety inside terminal listings & sessions */
.ln, .term-body .ln,
.gbadge, .term-body .gbadge,
.grid, .term-body .grid,
.pu, .term-body .pu,
.pp, .term-body .pp,
.term-body .term-prompt,
.term-body .cursor {
  user-select: none;
  -webkit-user-select: none;
}

/* Classic Vim, Shell, strace, man, TAP & ANSI SGR token classes */
.k { color: var(--ansi-yellow); font-weight: 700; }
.kl { color: var(--ansi-yellow); }
.t { color: var(--ansi-green); font-weight: 700; }
.p { color: var(--ansi-purple); }
.s { color: var(--ansi-red); }
.n { color: var(--ansi-magenta); }
.c { color: var(--ansi-cyan); }
.pu { color: var(--ansi-green); font-weight: 700; }
.pp { color: var(--ansi-blue); font-weight: 700; }
.exe { color: var(--ansi-green); font-weight: 700; }
.cursor { background: var(--term-fg); color: var(--term-bg); }
.sn { color: var(--ansi-green); }
.ss { color: var(--ansi-red); }
.sc { color: var(--ansi-cyan); }
.sm { color: var(--ansi-magenta); }
.sr { color: var(--ansi-yellow); font-weight: 700; }
.dim { color: var(--term-dim); }
.mb { color: var(--term-bright); font-weight: 700; }
.mu { text-decoration: underline; text-underline-offset: 3px; }
.rev { background: var(--term-fg); color: var(--term-bg); }
.ok { color: var(--ansi-green); font-weight: 700; }
.nok { color: var(--ansi-red); font-weight: 700; }
.fzf-ptr { color: var(--ansi-magenta); }
.hit { color: var(--ansi-green); font-weight: 700; }
.term-link { color: var(--term-badge-bg); }

/* ANSI SGR 30..37, 90..97, 40..47, 100..107 */
.af0 { color: var(--ansi-br-black); }
.af0-bg { color: var(--term-bg); }
.af1 { color: var(--ansi-red); }
.af2 { color: var(--ansi-green); }
.af3 { color: var(--ansi-yellow); }
.af4 { color: var(--ansi-blue); }
.af5 { color: var(--ansi-magenta); }
.af6 { color: var(--ansi-cyan); }
.af7 { color: var(--ansi-white); }
.af8 { color: var(--ansi-br-black); }
.af9 { color: var(--ansi-br-red); }
.af10 { color: var(--ansi-br-green); }
.af11 { color: var(--ansi-br-yellow); }
.af12 { color: var(--ansi-br-blue); }
.af13 { color: var(--ansi-br-magenta); }
.af14 { color: var(--ansi-br-cyan); }
.af15 { color: var(--ansi-br-white); }
.ab0 { background: var(--term-edge); }
.ab1 { background: var(--ansi-red); }
.ab2 { background: var(--ansi-green); }
.ab3 { background: var(--ansi-yellow); }
.ab4 { background: var(--ansi-blue); }
.ab5 { background: var(--ansi-magenta); }
.ab6 { background: var(--ansi-cyan); }
.ab7 { background: var(--ansi-white); }
.ab8 { background: var(--term-hl); }
.ab9 { background: var(--ansi-br-red); }
.ab10 { background: var(--ansi-br-green); }
.ab11 { background: var(--ansi-br-yellow); }
.ab12 { background: var(--ansi-br-blue); }
.ab13 { background: var(--ansi-br-magenta); }
.ab14 { background: var(--ansi-br-cyan); }
.ab15 { background: var(--ansi-br-white); }

/* Listing callout notes */
.callouts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  max-width: 40em;
  font-size: 16px;
  line-height: 1.6;
}
.callouts li { display: flex; gap: 12px; align-items: flex-start; }
.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 5px;
  background: var(--term-badge-bg);
  color: var(--term-badge-fg);
  font: 700 14px/1 var(--font-mono);
}

/* Compiler-diagnostic callouts (.diag) */
.diag {
  max-width: 40em;
  margin: 0;
  padding: 14px 18px;
  border: 1px solid color-mix(in srgb, var(--d) 32%, transparent);
  border-radius: var(--radius-card);
  background: var(--d-bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.65;
}
.diag p { margin: 0; }
.diag p + p { margin-top: 8px; }
.diag-label { color: var(--d); font: 700 16px var(--font-mono); }
.diag-loc { color: var(--text); font: 700 16px var(--font-mono); }
.diag.note { --d: var(--note); --d-bg: var(--note-bg); }
.diag.hint { --d: var(--hint); --d-bg: var(--hint-bg); }
.diag.warning { --d: var(--warning); --d-bg: var(--warning-bg); }
.diag.error { --d: var(--error); --d-bg: var(--error-bg); }
.diag.details > summary { cursor: pointer; list-style: none; }
.diag.details > summary::-webkit-details-marker { display: none; }
.diag.details[open] > summary { margin-bottom: 10px; }
.analogy-limit {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--d) 24%, transparent);
  font-size: 15px;
  color: var(--text-2);
}

/* Figure & StepDiagram window (.term.figure) */
.fig-body { overflow-x: auto; padding: 20px; background: var(--surface); }
.fig-svg, .fig-body svg, .fig-body img { display: block; max-width: 100%; height: auto; margin-inline: auto; }
.fig-cap {
  margin: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.6;
}
.fig-cap b { color: var(--text); font-family: var(--font-mono); font-size: 15px; }
.box { fill: var(--surface-2); stroke: var(--border-strong); stroke-width: 1; }
.box.cur { stroke: var(--accent); stroke-width: 2; }
.fig-badge { fill: var(--term-badge-bg); }
.fig-badge-t { fill: var(--term-badge-fg); font: 700 13px var(--font-mono); }
.fig-call { fill: var(--text); font: 700 15px var(--font-mono); }
.fig-t { fill: var(--text-2); font: 15px var(--font-prose); }
.fig-k { fill: var(--text-3); font: 14px var(--font-mono); }
.fig-o { font: 700 15px var(--font-mono); }
.out-old { fill: var(--text-2); }
.out-either { fill: var(--warning); }
.out-new { fill: var(--hint); }
.arrow { fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.sd-steps {
  margin: 0;
  padding: 12px 16px 12px 34px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.6;
}
.sd-step + .sd-step { margin-top: 6px; }
.sd-num { color: var(--text); font-family: var(--font-mono); font-weight: 700; font-size: 15px; }
.stepdiagram.sd-enhanced .sd-steps { list-style: none; padding: 12px 16px; }
.stepdiagram.sd-enhanced .sd-step { display: none; margin: 0; }
.stepdiagram.sd-enhanced .sd-step.is-active { display: block; }
.sd-dim { opacity: 0.28; transition: opacity 150ms ease; }
.sd-highlight { filter: drop-shadow(0 0 2px var(--accent)); }

/* Data Tables */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}
.table-scroll table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.table-scroll th, .table-scroll td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.table-scroll tr:last-child td { border-bottom: 0; }
.table-scroll th { background: var(--surface-2); font: 700 14px/1.4 var(--font-mono); color: var(--text); }
.table-scroll th.num, .table-scroll td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

/* Quiz (.panel.quiz) */
.quiz fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 8px; min-width: 0; }
.quiz-q {
  display: block;
  margin: 0 0 6px;
  padding: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--text);
}
.quiz-q::before {
  content: "? " / "";
  color: var(--hint);
  font-family: var(--font-mono);
  font-weight: 700;
}
.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
  cursor: pointer;
}
.opt > span {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: break-word;
}
.opt:hover { border-color: var(--border-strong); }
.opt input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.opt.right, .opt.is-correct { border-color: var(--hint); background: var(--hint-bg); }
.opt.wrong, .opt.is-wrong { border-color: var(--error); background: var(--error-bg); }
.quiz-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.quiz-feedback { margin: 12px 0 0; font-size: 16px; line-height: 1.6; color: var(--text); }
.quiz-feedback[hidden] { display: none; }
.quiz-feedback .ok { color: var(--hint); font: 700 15px var(--font-mono); }
.quiz-feedback .nok { color: var(--error); font: 700 15px var(--font-mono); }
.quiz-noscript-key { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 15px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font: 700 15px/1 var(--font-mono);
  text-decoration: none;
  cursor: pointer;
}
.btn-primary {
  background: var(--term-bg);
  border-color: var(--primary-border);
  color: var(--term-bright);
}
.btn-primary:hover { background: var(--term-bar); color: var(--term-bright); }
.btn-primary .sig { color: var(--ansi-green); }
.btn-primary:focus-visible { outline-color: var(--accent); }
.topbar .btn-primary:focus-visible,
.term .btn-primary:focus-visible { outline-color: var(--term-badge-bg); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--text); background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--surface-2); }
.btn[hidden] { display: none; }

/* End of lesson: completion & prev/next */
.completion {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.completion-note { color: var(--text-3); font: 14px var(--font-mono); }
.prevnext { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.nav-card {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.nav-card:hover { border-color: var(--accent); }
.nav-card.next { text-align: right; }
.nav-dir, .nav-time { color: var(--text-3); font: 14px var(--font-mono); }
.nav-title { color: var(--accent); font-weight: 700; overflow-wrap: anywhere; }
@media (max-width: 639px) {
  .prevnext { grid-template-columns: minmax(0, 1fr); }
  .nav-card.next { text-align: left; }
}

/* Outline tree (left rail & drawer) */
.outline { font: 14px/1.5 var(--font-mono); color: var(--text-2); }
.tree-root { margin: 0 0 4px; padding: 0 8px; font-weight: 700; }
.tree-root a { color: var(--text); text-decoration: none; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree a, .tree summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  min-height: 32px;
  padding: 5px 8px;
  border-radius: var(--radius-control);
  color: var(--text-2);
  text-decoration: none;
}
.tree summary { cursor: pointer; list-style: none; }
.tree summary::-webkit-details-marker { display: none; }
.tree a:hover, .tree summary:hover { background: var(--surface-2); color: var(--text); }
.tree .ascii { white-space: pre; color: var(--border-strong); user-select: none; }
.tree .idx { margin-right: 1ch; color: var(--text-3); }
.tree .mod { color: var(--text); font-weight: 700; }
.ico { display: inline-block; vertical-align: -2px; flex: none; }
.tree .done { margin-left: 1ch; color: var(--hint); }
.tree .lock { margin-left: 1ch; color: var(--text-3); }
.tree a[aria-current="page"] { background: var(--tree-current-bg); color: var(--term-bright); font-weight: 700; }
.tree a[aria-current="page"] .ascii,
.tree a[aria-current="page"] .idx { color: var(--term-dim); }

/* On this page TOC */
.toc { font: 14px/1.5 var(--font-mono); }
.toc-head { margin: 0 0 6px; padding: 0 8px; color: var(--text-3); }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: grid;
  grid-template-columns: 2ch 3ch minmax(0, 1fr);
  min-height: 32px;
  padding: 5px 8px;
  border-radius: var(--radius-control);
  color: var(--text-2);
  text-decoration: none;
}
.toc a:hover { background: var(--surface-2); color: var(--text); }
.toc .ptr { visibility: hidden; color: var(--accent); font-weight: 700; }
.toc .n { color: var(--text-3); font-weight: 400; }
.toc a[aria-current="true"] { color: var(--text); font-weight: 700; }
.toc a[aria-current="true"] .ptr { visibility: visible; }
.toc-inline {
  max-width: 40em;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
}

/* Glossary trigger & WCAG 1.4.13 popover */
.term-gloss {
  background: transparent;
  border: 0;
  border-bottom: 1px dashed var(--border-strong);
  border-radius: 0;
  padding: 0 1px;
  font: inherit;
  color: inherit;
  cursor: help;
  display: inline;
}
.term-gloss:hover { border-bottom-color: var(--accent); color: var(--accent); }
.gloss-popover {
  position: fixed;
  z-index: 80;
  max-width: min(360px, calc(100vw - 24px));
  background: var(--term-bg);
  color: var(--term-fg);
  border: 1px solid var(--term-edge);
  border-radius: var(--radius-card);
  box-shadow: var(--window-shadow);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.55;
}
.gloss-popover-term { font: 700 14px var(--font-mono); margin: 0 0 4px; color: var(--term-bright); }
.gloss-popover-def { margin: 0; color: var(--term-dim); font-family: var(--font-prose); }

/* Man-page Footer */
.site-footer {
  width: 100%;
  max-width: 1440px;
  margin: 80px auto 0;
  padding: 20px 24px 40px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font: 14px/1.6 var(--font-mono);
}
.man-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
}
.footer-links {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  margin: 12px 0 0;
  padding: 0;
}
.footer-links a { color: var(--text-2); text-decoration: none; }
.footer-links a:hover { color: var(--accent); text-decoration: underline; }

/* Dialogs, Reading Settings, fzf Search & Toast */
.drawer, dialog.outline-drawer {
  width: min(340px, 92vw);
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 16px 8px;
  border: 0;
  border-right: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg);
  color: var(--text);
}
.drawer::backdrop, dialog.outline-drawer::backdrop, dialog.term-dialog::backdrop {
  background: rgba(11, 12, 15, 0.55);
}
.drawer-close { display: flex; justify-content: flex-end; margin-bottom: 8px; }

.reading-popover {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  right: 12px;
  z-index: 75;
  width: min(360px, calc(100vw - 24px));
}
.reading-popover[hidden] { display: none; }

dialog.term-dialog {
  padding: 0;
  max-width: min(680px, calc(100vw - 24px));
  width: 100%;
  color: var(--term-fg);
}
dialog.fig-zoom-dialog {
  max-width: min(1160px, 96vw);
}
dialog.fig-zoom-dialog .fig-body {
  max-height: 78vh;
  overflow: auto;
}

.set-body {
  display: grid;
  gap: 12px;
  padding: 16px;
  color: var(--term-fg);
  font: 14px/1.5 var(--font-mono);
}
.set-row { display: grid; gap: 6px; }
.set-label { color: var(--term-dim); }
.segs { display: flex; flex-wrap: wrap; gap: 6px; }
.seg {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--term-grid);
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--term-fg);
  font: 600 14px var(--font-mono);
  cursor: pointer;
}
.seg:hover { background: var(--term-hover); }
.seg[aria-pressed="true"] {
  background: var(--term-fg);
  border-color: var(--term-fg);
  color: var(--term-bg);
}
.set-check { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; }
.set-check input { width: 18px; height: 18px; accent-color: var(--term-badge-bg); }

/* fzf Search Dialog internals */
.fzf-body {
  padding: 12px 0 14px;
  max-height: 72vh;
  overflow-y: auto;
}
.fzf-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fzf-input {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 2px 0;
  background: transparent;
  color: var(--term-bright);
  font: 14.5px/22px var(--font-mono);
  caret-color: var(--term-bright);
}
.fzf-input::placeholder { color: var(--term-grid); }
.fzf-input:focus { outline: none; }
.fzf-input:focus-visible { outline: 2px solid var(--term-badge-bg); outline-offset: 2px; border-radius: 3px; }
.fzf-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.fzf-item { padding: 0; }
.fzf-link {
  display: block;
  padding: 0 16px;
  color: var(--term-fg);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fzf-link:hover { background: var(--term-hover); color: var(--term-bright); }
.fzf-item.hl .fzf-link { background: var(--term-hl); color: var(--term-bright); }

.shortcuts-list {
  display: grid;
  grid-template-columns: 7ch 1fr;
  gap: 8px 16px;
  margin: 0;
}
.shortcuts-list dt { color: var(--term-bright); font-weight: 700; }
.shortcuts-list dd { margin: 0; color: var(--term-dim); }

.back-to-top {
  position: fixed;
  right: 16px;
  bottom: 20px;
  z-index: 38;
  box-shadow: var(--window-shadow);
}
.back-to-top[hidden] { display: none; }

.toast, .ksa-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--term-edge);
  border-radius: var(--radius-control);
  background: var(--term-bg);
  color: var(--term-fg);
  font: 14px/1.4 var(--font-mono);
  box-shadow: var(--window-shadow);
}
.toast[hidden], .ksa-toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .topbar, .site-topbar, .rail, .outline-sidebar, .toc-rail, .toc-inline, .inline-toc,
  .term-btn, .term-controls, .completion, .prevnext, .back-to-top, .reading-progress,
  .reading-popover, dialog, .toast, .ksa-toast {
    display: none !important;
  }
  body { background: #fff; color: #000; font-size: 11pt; }
  .layout, .course-shell, .app-shell { display: block; padding: 0; }
  .term { background: #fff; border: 1px solid #000; box-shadow: none; break-inside: avoid; }
  .term-bar { background: #fff; color: #000; border-bottom: 1px solid #000; }
  .term-body { background: #fff; color: #000; font-size: 9pt; line-height: 1.35; }
  .row.hl { background: #eee; }
  .k, .kl, .t, .p, .s, .n, .c, .pu, .pp, .exe, .sn, .ss, .sc, .sm, .sr, .dim, .mb, .ok, .nok, .hit {
    color: #000;
  }
  .k, .t, .mb, .sr { font-weight: 700; }
  .c { font-style: italic; }
  .grid, .ln { color: #555; }
  .stepdiagram.sd-enhanced .sd-step { display: block !important; margin-bottom: 6px; }
}
