/* Applied AI course reader — newspaper / broadsheet system */

:root {
  --bg-page: #ebe6dc;
  --bg-elevated: #f2ede4;
  --bg-card: #faf6ef;
  --ink: #0f0e0d;
  --ink-muted: #3d3832;
  --ink-faint: #6b645b;
  --accent: #6b1414;
  --accent-soft: rgba(107, 20, 20, 0.1);
  --rule: rgba(15, 14, 13, 0.22);
  --rule-hairline: rgba(15, 14, 13, 0.12);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.55) inset,
    0 10px 28px rgba(15, 12, 8, 0.05);
  --hero-texture-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23a)'/%3E%3C/svg%3E");

  --font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-serif: "Newsreader", Georgia, "Times New Roman", serif;
  --font-sans: "Libre Franklin", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --text-hero: clamp(2.35rem, 4.5vw + 1.35rem, 3.85rem);
  --text-section: clamp(1.65rem, 2.2vw + 1rem, 2.5rem);
  --text-card: clamp(1.1rem, 0.55vw + 0.95rem, 1.35rem);
  --text-body: clamp(1.0625rem, 0.2vw + 1rem, 1.1875rem);
  --text-label: clamp(0.6875rem, 0.12vw + 0.65rem, 0.8125rem);
  --text-caption: 0.75rem;

  --leading-body: 1.68;
  --max-prose: none;
  --radius: 3px;

  --main-max-w: 120rem;
  /* Single source for main column + fixed rails (must match .main padding) */
  --main-pad: clamp(1.25rem, 3vw, 2.15rem);
  --main-pad-x: var(--main-pad);
  --main-pad-y: var(--main-pad);
  --layout-gap: clamp(1rem, 2vw, 2rem);
  /* Sticky nav block height — tuned so rails line up with .card--hero top */
  --site-nav-h: 4.1rem;
  --sidebar-fixed-top: calc(var(--site-nav-h) + var(--main-pad-y));
  --sidebar-slide-dur: 0.38s;
  --sidebar-slide-ease: cubic-bezier(0.33, 1, 0.68, 1);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --sidebar-slide-dur: 0.01ms;
  }
}

/* First paint only: app.js removes this after initial loadPage() so margins/rails don’t animate from “empty” state */
.layout--no-sidebar-transition .card--hero,
.layout--no-sidebar-transition .sidebar-stack,
.layout--no-sidebar-transition .sidebar-checklist-rail {
  transition: none !important;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg-page: #121110;
  --bg-elevated: #1a1816;
  --bg-card: #171513;
  --ink: #f0ebe3;
  --ink-muted: #b0a89c;
  --ink-faint: #7f776c;
  --accent: #e8a0a0;
  --accent-soft: rgba(232, 160, 160, 0.12);
  --rule: rgba(255, 255, 255, 0.12);
  --rule-hairline: rgba(255, 255, 255, 0.08);
  --shadow-soft: 0 1px 0 rgba(255, 255, 255, 0.03) inset,
    0 12px 36px rgba(0, 0, 0, 0.4);
}

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

html {
  scroll-behavior: smooth;
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-serif);
  font-size: var(--text-body);
  font-weight: 400;
  font-optical-sizing: auto;
  line-height: var(--leading-body);
  color: var(--ink);
  background: var(--bg-page);
  background-image: repeating-linear-gradient(90deg,
      transparent,
      transparent 1px,
      rgba(15, 14, 13, 0.03) 1px,
      rgba(15, 14, 13, 0.03) 2px),
    linear-gradient(180deg, rgba(255, 252, 247, 0.35) 0%, transparent 28rem);
}

html[data-theme="dark"] body {
  background-image: repeating-linear-gradient(90deg,
      transparent,
      transparent 1px,
      rgba(255, 255, 255, 0.02) 1px,
      rgba(255, 255, 255, 0.02) 2px),
    linear-gradient(180deg, rgba(35, 32, 28, 0.4) 0%, transparent 28rem);
}

/* ——— Site nav (masthead) ——— */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  border-top: 5px solid var(--ink);
  border-bottom: 3px double var(--rule);
  background: var(--bg-elevated);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.45) inset;
}

.site-nav__inner {
  max-width: 120rem;
  margin: 0 auto;
  padding: 0.875rem var(--main-pad-x);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.site-nav__brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
  text-transform: none;
}

.site-nav__logo {
  display: block;
  flex-shrink: 0;
  height: 2.25rem;
  width: auto;
  object-fit: contain;
}

.site-nav__brand:hover {
  color: var(--accent);
}

.site-nav__brand:hover .site-nav__logo {
  opacity: 0.92;
}

.site-nav__links {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.site-nav__links a {
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.site-nav__links a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent-soft);
}

.site-nav__search {
  position: relative;
  flex: 1 1 22rem;
  min-width: min(100%, 18rem);
  max-width: 36rem;
}

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

.site-nav__search-input {
  width: 100%;
  margin: 0;
  height: 2.75rem;
  padding: 0 0.85rem 0 2.5rem;
  line-height: 2.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237a736b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.7rem 50%;
  background-size: 1.05rem;
}

html[data-theme="dark"] .site-nav__search-input {
  box-shadow: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a837a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
}

.site-nav__search-input::placeholder {
  color: var(--ink-faint);
}

.site-nav__search-input:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--rule-hairline));
}

.site-nav__search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.site-nav__search-panel {
  position: absolute;
  z-index: 50;
  left: 0;
  right: 0;
  top: calc(100% + 0.35rem);
  max-height: min(70vh, 22rem);
  overflow: auto;
  padding: 0.35rem 0;
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.site-nav__search-results {
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav__search-results li {
  margin: 0;
}

.site-nav__search-option {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-caption);
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  color: var(--ink);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 0;
}

.site-nav__search-option:hover,
.site-nav__search-option:focus-visible {
  background: var(--accent-soft);
  color: var(--ink);
  outline: none;
}

.site-nav__search-option.is-active {
  background: var(--accent-soft);
  outline: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}

.site-nav__search-option__title {
  display: block;
  color: var(--ink);
}

.site-nav__search-option__path {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  word-break: break-all;
}

.site-nav__search-empty {
  margin: 0;
  padding: 0.65rem 0.75rem;
  font-size: var(--text-caption);
  color: var(--ink-muted);
}

.site-nav__actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-family: var(--font-sans);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--ink-muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: var(--bg-card);
}

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

.theme-toggle__icon {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.theme-toggle__icon--sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

html[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

/* Header: page layout (sidebars) */
.layout-menu {
  position: relative;
  flex-shrink: 0;
}

.layout-menu__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font-family: var(--font-sans);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--ink-muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.layout-menu__trigger:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
  background: var(--bg-card);
}

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

.layout-menu__trigger-icon {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.layout-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem;
  min-width: 9.5rem;
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.layout-menu__panel[hidden] {
  display: none !important;
}

.layout-menu__toggle {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  font-family: var(--font-sans);
  font-size: var(--text-caption);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: center;
  color: var(--ink);
  background: var(--bg-card);
  border: 1px solid var(--rule-hairline);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.layout-menu__toggle:hover {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--rule-hairline));
}

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

.layout-menu__toggle[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--rule-hairline));
  color: var(--ink);
}

.layout-menu__toggle.is-off {
  color: var(--ink-muted);
  background: transparent;
  opacity: 0.85;
}

/* ——— Layout ——— */
.main {
  max-width: var(--main-max-w);
  margin: 0 auto;
  padding: calc(var(--main-pad-y) - 14px) var(--main-pad-x);
}

.bento-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--layout-gap);
  align-items: start;
}

/* Layout tiers: small <40rem (phone, 1 col) · medium 40rem–1499px (tablet/laptop, 2 col) · large ≥1500px (wide, 3 fixed rails) */
@media (min-width: 40rem) and (max-width: 1599px) {
  .bento-grid {
    grid-template-columns: minmax(0, 1fr) minmax(12rem, min(22rem, 40vw));
  }

  .card--hero {
    grid-column: 1;
    grid-row: 1;
    margin-left: 0;
    margin-right: 0;
  }

  .bento-grid.has-sidebar-checklist .card--hero {
    grid-row: 1 / -1;
    margin-right: 0;
  }

  .sidebar-stack {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
    grid-column: 2;
    grid-row: 1;
  }

  .sidebar-checklist-rail {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
    grid-column: 2;
    grid-row: 2;
  }

  /* Slide sidebars (layout toggles) — medium: TOC column sits right of article */
  .sidebar-stack {
    transform: translateX(0);
    opacity: 1;
    max-height: 5000px;
    overflow: visible;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      max-height var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-left .sidebar-stack {
    transform: translateX(calc(100% + var(--layout-gap)));
    opacity: 0;
    max-height: 0;
    margin-block: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .sidebar-checklist-rail:not([hidden]) {
    transform: translateX(0);
    opacity: 1;
    max-height: 5000px;
    overflow: visible;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      max-height var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-right .sidebar-checklist-rail:not([hidden]) {
    transform: translateX(calc(100% + var(--layout-gap)));
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
  }

}

/* Left sidebar: TOC + Browse */
.sidebar-stack {
  display: flex;
  flex-direction: column;
  gap: var(--layout-gap);
  align-items: stretch;
}

/* Right rail: lab checklist (when present) */
.sidebar-checklist-rail {
  display: flex;
  flex-direction: column;
  gap: var(--layout-gap);
  align-items: stretch;
}

.sidebar-checklist-rail[hidden] {
  display: none !important;
}

/* Large: fixed left nav + optional fixed right checklist; hero margins reserve space */
@media (min-width: 1600px) {
  .bento-grid {
    /* Match former grid column: minmax(16rem, 22rem), shrink if viewport is tight */
    --sidebar-w: min(22rem,
        max(16rem,
          calc(100vw - 2 * var(--main-pad-x) - var(--layout-gap) - 40rem)));
    display: block;
  }

  .card--hero {
    margin-left: calc(var(--sidebar-w) + var(--layout-gap));
    margin-right: 0;
    transition:
      margin-left var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      margin-right var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-left .card--hero {
    margin-left: 0;
  }

  .bento-grid.has-sidebar-checklist .card--hero {
    margin-right: calc(var(--sidebar-w) + var(--layout-gap));
  }

  .sidebar-stack {
    position: fixed;
    top: var(--sidebar-fixed-top);
    left: calc((100vw - min(var(--main-max-w), 100vw)) / 2 + var(--main-pad-x));
    right: auto;
    width: var(--sidebar-w);
    max-height: calc(100vh - var(--sidebar-fixed-top) - 1rem);
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 25;
    -webkit-overflow-scrolling: touch;
    transform: translateX(0);
    opacity: 1;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-left .sidebar-stack {
    transform: translateX(calc(-100% - var(--layout-gap)));
    opacity: 0;
    pointer-events: none;
  }

  .sidebar-stack .card--secondary {
    position: static;
    width: 100%;
    max-height: none;
    overflow: visible;
  }

  .sidebar-checklist-rail {
    position: fixed;
    top: var(--sidebar-fixed-top);
    right: calc((100vw - min(var(--main-max-w), 100vw)) / 2 + var(--main-pad-x));
    left: auto;
    width: var(--sidebar-w);
    max-height: calc(100vh - var(--sidebar-fixed-top) - 1rem);
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 25;
    -webkit-overflow-scrolling: touch;
    transform: translateX(0);
    opacity: 1;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-right .sidebar-checklist-rail:not([hidden]) {
    transform: translateX(calc(100% + var(--layout-gap)));
    opacity: 0;
    pointer-events: none;
  }

  .sidebar-checklist-rail .card--secondary {
    position: static;
    width: 100%;
    max-height: none;
    overflow: visible;
  }
}

/* Small: single column — natural DOM order (article, then sidebars) */
@media (max-width: 39.99rem) {
  .bento-grid {
    grid-template-columns: 1fr;
  }

  .card--hero {
    margin-left: 0;
    margin-right: 0;
  }

  .bento-grid.has-sidebar-checklist .card--hero {
    margin-right: 0;
  }

  .sidebar-stack {
    position: static;
    width: auto;
    max-height: 5000px;
    overflow: visible;
    transform: translateX(0);
    opacity: 1;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      max-height var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-left .sidebar-stack {
    transform: translateX(-100%);
    opacity: 0;
    max-height: 0;
    margin-block: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .sidebar-checklist-rail {
    position: static;
    width: auto;
    max-height: none;
    overflow: visible;
  }

  .sidebar-checklist-rail:not([hidden]) {
    transform: translateX(0);
    opacity: 1;
    max-height: 5000px;
    transition:
      transform var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      opacity var(--sidebar-slide-dur) var(--sidebar-slide-ease),
      max-height var(--sidebar-slide-dur) var(--sidebar-slide-ease);
  }

  .layout--hide-right .sidebar-checklist-rail:not([hidden]) {
    transform: translateX(100%);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    pointer-events: none;
  }
}

/* ——— Cards ——— */
.card {
  background: var(--bg-card);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
}

.card--hero {
  position: relative;
  padding: clamp(1.5rem, 3vw, 2.75rem);
  background-color: var(--bg-card);
  background-image: linear-gradient(180deg,
      hsla(40, 20%, 100%, 0.35) 0%,
      transparent 45%),
    var(--hero-texture-noise);
  background-size: auto, 160px 160px;
  background-blend-mode: normal, soft-light;
  border: 1px solid var(--rule-hairline);
  box-shadow: var(--shadow-soft);
}

html[data-theme="dark"] .card--hero {
  background-image: linear-gradient(180deg,
      hsla(0, 0%, 100%, 0.05) 0%,
      transparent 48%),
    var(--hero-texture-noise);
  background-blend-mode: normal, overlay;
}

.card--secondary {
  padding: 1.25rem 1.25rem 1.5rem;
  box-sizing: border-box;
}

/* Breadcrumb (replaces card eyebrow) */
.breadcrumb {
  margin: 0 0 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--rule);
}

.breadcrumb__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.35rem;
  font-family: var(--font-mono);
  font-size: var(--text-label);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.breadcrumb__item {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
}

.breadcrumb__item a {
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.breadcrumb__item a:hover {
  color: var(--ink);
  border-bottom-color: var(--ink-faint);
}

.breadcrumb__item[aria-current="page"] {
  color: var(--ink-muted);
  min-width: 0;
}

.breadcrumb__item+.breadcrumb__item::before {
  content: "/";
  color: var(--rule);
  font-weight: 400;
  margin-right: 0.35rem;
  user-select: none;
}

.display-title {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.035em;
  color: var(--ink);
  margin: 0 0 1.5rem;
  max-width: none;
  text-wrap: balance;
}

.card__heading {
  font-family: var(--font-sans);
  font-size: var(--text-label);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 0.75rem;
  padding-top: 0.35rem;
  border-top: 2px solid var(--ink);
}

.card__divider {
  height: 1px;
  background: var(--rule-hairline);
  margin: 1.25rem 0;
}

/* ——— Prose (markdown) ——— */
.prose {
  width: 100%;
  max-width: var(--max-prose);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--ink);
  text-rendering: optimizeLegibility;
}

.prose>*:first-child {
  margin-top: 0;
}

.prose h1.is-mirrored {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.prose h2 {
  font-family: var(--font-display);
  font-size: var(--text-section);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.03em;
  margin: 2.25rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: var(--text-card);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 18;
  margin: 1.75rem 0 0.5rem;
  color: var(--ink);
}

.prose h4 {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 1.5rem 0 0.5rem;
  color: var(--ink-muted);
}

.prose p {
  margin: 0 0 1.1em;
}

@media (min-width: 40rem) {
  .prose p {
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
    hyphenate-limit-chars: 6 3 3;
  }
}

.prose>p:first-of-type::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 3.25rem;
  line-height: 0.82;
  font-weight: 700;
  padding-right: 0.4rem;
  margin-top: 0.12rem;
  color: var(--ink);
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

.prose a:hover {
  background: var(--accent-soft);
}

.prose strong,
.prose b {
  font-weight: 700;
  font-style: normal;
  color: var(--ink);
}

.prose em {
  font-style: italic;
}

.prose ul,
.prose ol {
  margin: 0 0 1.1em;
  padding-left: 1.35em;
}

.prose li {
  margin: 0.35em 0;
}

.prose blockquote {
  margin: 1.25rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--rule);
  color: var(--ink-muted);
  font-style: italic;
}

.prose blockquote p {
  margin: 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-elevated);
  padding: 0.12em 0.35em;
  border-radius: var(--radius);
  border: 1px solid var(--rule-hairline);
}

.prose pre {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 1.25rem 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  background: var(--ink);
  color: #e8e4dc;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
}

html[data-theme="dark"] .prose pre {
  background: #0d0c0b;
  color: #e8e4dc;
  border-color: var(--rule-hairline);
}

.prose pre code {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.prose hr {
  border: 0;
  height: 1px;
  background: var(--rule);
  margin: 2rem 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  margin: 1.25rem 0;
}

.prose th,
.prose td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--rule-hairline);
}

.prose th {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  border-bottom-color: var(--rule);
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}

/* ——— Interactive checklist (state in localStorage) ——— */
.interactive-checklist {
  list-style: none;
  margin: 1.25rem 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 52rem;
}

.sidebar-checklist-mount .interactive-checklist {
  max-width: none;
  margin: 0.35rem 0 0;
}

/* Right rail: quick links (when present) */
.sidebar-links-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.sidebar-links-group + .sidebar-links-group {
  margin-top: 0.15rem;
}

.sidebar-links__subheading {
  margin: 0 0 0.35rem;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.3;
  color: color-mix(in srgb, var(--ink) 62%, var(--bg-page));
  text-transform: uppercase;
}

.sidebar-links {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-links-group .sidebar-links {
  margin-top: 0;
}

.sidebar-links__item {
  margin: 0;
}

.sidebar-links__link {
  display: block;
  padding: 0.55rem 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.45;
  border-radius: calc(var(--radius) + 1px);
  border: 1px solid var(--rule-hairline);
  background: var(--bg-elevated);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease,
    transform 0.2s ease;
}

.sidebar-links__link:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--rule-hairline));
  background: color-mix(in srgb, var(--bg-card) 55%, var(--bg-elevated));
  box-shadow: 0 2px 10px rgba(15, 14, 13, 0.07),
    0 0 0 1px color-mix(in srgb, var(--accent) 14%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
  .sidebar-links__link:hover {
    transform: translateY(-2px);
  }
}

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

.sidebar-links__link code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-page);
  padding: 0.1em 0.35em;
  border-radius: var(--radius);
  border: 1px solid var(--rule-hairline);
}

.interactive-checklist__item {
  margin: 0;
}

.interactive-checklist__label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  line-height: 1.45;
  border-radius: calc(var(--radius) + 1px);
  border: 1px solid var(--rule-hairline);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease,
    transform 0.2s ease;
}

.interactive-checklist__label:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--rule-hairline));
  background: color-mix(in srgb, var(--bg-card) 55%, var(--bg-elevated));
  box-shadow: 0 2px 10px rgba(15, 14, 13, 0.07),
    0 0 0 1px color-mix(in srgb, var(--accent) 14%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
  .interactive-checklist__label:hover {
    transform: translateY(-2px);
  }
}

.interactive-checklist__label:has(.interactive-checklist__checkbox:checked) {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--rule-hairline));
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.interactive-checklist__label:has(.interactive-checklist__checkbox:checked):hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--rule-hairline));
  background: color-mix(in srgb, var(--accent-soft) 65%, var(--bg-card));
  box-shadow: 0 2px 12px rgba(15, 14, 13, 0.09),
    0 0 0 1px color-mix(in srgb, var(--accent) 28%, transparent);
}

.interactive-checklist__label:has(.interactive-checklist__checkbox:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.interactive-checklist__checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  margin: 0;
  border-radius: 5px;
  border: 1.5px solid var(--ink-muted);
  background: var(--bg-card);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.interactive-checklist__checkbox:hover {
  border-color: var(--ink);
}

.interactive-checklist__checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg-card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.5 8.5L6.5 11.5L12.5 4.5' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 0.85rem;
  background-position: center;
  background-repeat: no-repeat;
}

.interactive-checklist__text {
  flex: 1;
  min-width: 0;
  line-height: 1.45;
}

.interactive-checklist__text code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-page);
  padding: 0.1em 0.35em;
  border-radius: var(--radius);
  border: 1px solid var(--rule-hairline);
}

.prose--error {
  color: var(--ink-muted);
}

.prose--error a {
  color: var(--accent);
}

/* ——— TOC ——— */
.toc {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  /* ~30% taller than previous min(40vh, 22rem) — mobile / non-fixed sidebar */
  max-height: min(52vh, 29rem);
  overflow-y: auto;
  padding-right: 0.25rem;
}

@media (min-width: 1600px) {
  .card--secondary .toc {
    max-height: none;
    overflow-y: visible;
  }
}

.toc a {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--ink-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  margin-left: -0.5rem;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.toc a:hover {
  color: var(--accent);
}

.toc a.is-active {
  color: var(--ink);
  font-weight: 600;
  border-left-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-soft) 0%, transparent 100%);
}

.toc a[data-depth="3"].is-active {
  opacity: 1;
}

.toc a[data-depth="3"] {
  padding-left: 1rem;
  font-size: 0.85rem;
  opacity: 0.92;
}

.toc-empty {
  font-size: 0.9rem;
  color: var(--ink-faint);
  margin: 0;
}

/* ——— Browse ——— */
.browse details {
  border-bottom: 1px solid var(--rule-hairline);
}

.browse summary {
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0.6rem 0;
  list-style: none;
}

.browse summary::-webkit-details-marker {
  display: none;
}

.browse summary::after {
  content: "+";
  float: right;
  font-family: var(--font-sans);
  opacity: 0.5;
}

.browse details[open] summary::after {
  content: "−";
}

.browse__phase-body {
  padding: 0.15rem 0 0.35rem;
}

.browse__section {
  margin: 0.65rem 0 0;
}

.browse__section:first-child {
  margin-top: 0;
}

.browse__section-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.3rem;
  padding: 0;
  line-height: 1.3;
}

.browse ul {
  margin: 0 0 0.75rem;
  padding: 0 0 0 0.75rem;
  list-style: none;
}

.browse__section ul {
  margin: 0 0 0.5rem;
}

.browse__section:last-child ul {
  margin-bottom: 0;
}

.browse li {
  margin: 0.25rem 0;
}

.browse a {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--accent);
  text-decoration: none;
  display: block;
  padding: 0.2rem 0;
}

.browse a:hover {
  text-decoration: underline;
}

.browse a[aria-current="page"] {
  font-weight: 600;
  color: var(--ink);
}

/* ——— Status ——— */
.status-bar {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 50;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  background: var(--ink);
  color: var(--bg-elevated);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.status-bar.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

html[data-theme="dark"] .status-bar {
  background: #0d0c0b;
  color: var(--ink);
}

/* ——— FAB ——— */
.fab {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 60;
  width: 3.25rem;
  height: 3.25rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg-elevated);
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(20, 16, 12, 0.2);
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease;
}

@media (max-width: 39.99rem) {
  .fab {
    display: flex;
  }
}

.fab:hover {
  transform: scale(1.04);
  background: var(--accent);
}

html[data-theme="dark"] .fab {
  background: var(--bg-elevated);
  color: var(--ink);
}

html[data-theme="dark"] .fab:hover {
  background: var(--accent);
  color: #0d0c0b;
}

.fab__icon {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

.fab-panel {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(20, 16, 12, 0.35);
  backdrop-filter: blur(4px);
}

.fab-panel[hidden] {
  display: none !important;
}

.fab-panel__sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 78vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-top: 1px solid var(--rule);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -8px 40px rgba(20, 16, 12, 0.12);
}

.fab-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: var(--text-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--rule-hairline);
}

.fab-panel__close {
  border: 0;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-muted);
  padding: 0.25rem;
}

.fab-panel__body {
  overflow-y: auto;
  padding: 0.75rem 1.25rem 1.5rem;
}

.fab-panel__body .browse details:last-child {
  border-bottom: 0;
}