@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&family=JetBrains+Mono:wght@400;500&family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

:root {
  --bg: #FAFAF7;
  --bg-card: #FFFFFF;
  --bg-code: #1E1E2E;
  --bg-aside: #F0EDE6;
  --bg-interactive: #F5F3ED;
  --text: #2C2C2A;
  --text-muted: #6B6A65;
  --text-light: #9C9A92;
  --accent: #3D5A80;
  --accent-light: #E8EDF3;
  --orange: #C4621A;
  --orange-bg: #FDF0E6;
  --teal: #0F6E56;
  --teal-bg: #E1F5EE;
  --purple: #534AB7;
  --purple-bg: #EEEDFE;
  --coral: #D85A30;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --border: #D3D1C7;
  --border-light: #E8E6DE;
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'DM Sans', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LAYOUT — Sidebar + Main Content
   ============================================================ */

.page-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  width: 250px;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border-light);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.sidebar-brand {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.01em;
}

.sidebar-brand-icon {
  font-size: 18px;
  opacity: 0.6;
}

.sidebar-brand:hover { opacity: 0.8; }

.sidebar-section-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-light);
  padding: 8px 12px 6px;
}

.sidebar-nav {
  flex: 1;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 1px 0;
  border-radius: 6px;
  text-decoration: none;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.sidebar-link.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

.sidebar-link-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--bg-card);
  background: var(--accent);
  min-width: 22px;
  height: 22px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-link.active .sidebar-link-num {
  background: var(--accent);
}

.sidebar-link:not(.active) .sidebar-link-num {
  background: var(--border);
  color: var(--bg-card);
}

.sidebar-link-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar search */
.sidebar-search {
  padding: 12px 14px 8px;
  position: relative;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 10px 7px 32px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--bg);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.search-input::placeholder {
  color: var(--text-light);
}

.search-input:focus {
  border-color: var(--accent);
}

.search-results {
  display: none;
  position: absolute;
  left: 10px;
  right: 10px;
  top: calc(100% - 2px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
}

.search-results.open {
  display: block;
}

.search-page-title {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 12px 4px;
}

.search-result {
  display: block;
  padding: 6px 12px 8px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover {
  background: var(--accent-light);
}

.search-result-heading {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.search-result-snippet {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.search-result-snippet mark,
.search-result-heading mark {
  background: #FFF3CD;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.search-empty {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px;
  text-align: center;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 150;
}

/* Mobile header */
.mobile-header {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.mobile-menu-toggle {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.mobile-header-title {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* Main content area */
.main-content {
  flex: 1;
  min-width: 0;
}

.course-container {
  max-width: 980px;
  margin: 0 auto;
  padding: 36px 48px 80px;
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */

.module-badge {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-light);
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  margin-bottom: 14px;
}

h1 {
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

h1 em { font-style: italic; color: var(--accent); }

.subtitle {
  font-size: 19px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 32px;
  max-width: 720px;
}

h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  margin: 48px 0 8px;
  letter-spacing: -0.01em;
}

h2 .lesson-num {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 6px;
}

h3 {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 32px 0 10px;
}

p { margin-bottom: 16px; }

strong { font-weight: 600; }

a { color: var(--purple); }

/* ============================================================
   CODE
   ============================================================ */

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg-aside);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--orange);
}

pre {
  background: var(--bg-code);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 14px 0 20px;
  overflow-x: auto;
  line-height: 1.6;
  border: 1px solid rgba(255,255,255,0.06);
  position: relative;
  transition: box-shadow 0.2s, transform 0.15s;
}

pre:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translateY(-1px);
}

pre::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--purple) 100%);
  border-radius: 10px 10px 0 0;
}

pre code {
  background: none;
  padding: 0;
  color: #CDD6F4;
  font-size: 14px;
}

.code-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.code-label .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.dot-naive { background: var(--coral); }
.dot-better { background: var(--teal); }
.dot-pyfloe { background: var(--purple); }
.dot-python { background: var(--accent); }

/* Syntax highlighting */
.kw { color: #CBA6F7; }
.fn { color: #89B4FA; }
.st { color: #A6E3A1; }
.cm { color: #6C7086; font-style: italic; }
.nu { color: #FAB387; }
.op { color: #89DCEB; }
.bi { color: #F9E2AF; }
.va { color: #CDD6F4; }
.cl { color: #F5C2E7; }
.dc { color: #94E2D5; }

/* ============================================================
   CALLOUT BOXES
   ============================================================ */

.aside {
  background: var(--bg-aside);
  border-left: 4px solid var(--accent);
  padding: 16px 20px;
  margin: 16px 0 20px;
  border-radius: 0 8px 8px 0;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
}

.aside-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 6px;
}

.callout-orange { background: var(--orange-bg); border-left-color: var(--orange); }
.callout-orange .aside-title { color: var(--orange); }

.callout-teal { background: var(--teal-bg); border-left-color: var(--teal); }
.callout-teal .aside-title { color: var(--teal); }

.callout-purple { background: var(--purple-bg); border-left-color: var(--purple); }
.callout-purple .aside-title { color: var(--purple); }

.callout-red { background: var(--red-bg); border-left-color: var(--red); }
.callout-red .aside-title { color: var(--red); }

.callout-deepcut {
  background: #F5F4F0;
  border-left: 3px dashed #9E9E9E;
  border-radius: 0 8px 8px 0;
}
.callout-deepcut .aside-title {
  color: #757575;
  font-style: italic;
}

/* Side quest callout */
.side-quest-callout {
  border: 2px dashed var(--teal);
  border-radius: 12px;
  padding: 28px 32px;
  margin: 48px 0 32px;
  background: var(--teal-bg);
}
.side-quest-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.side-quest-icon {
  font-size: 16px;
  color: var(--teal);
}
.side-quest-label {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--teal);
}
.side-quest-title {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 8px;
}
.side-quest-desc {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.side-quest-link {
  display: inline-block;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--teal);
  text-decoration: none;
  padding: 8px 20px;
  border: 1.5px solid var(--teal);
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.side-quest-link:hover {
  background: var(--teal);
  color: #fff;
}

/* ============================================================
   INTERACTIVE & QUIZ
   ============================================================ */

.interactive-box {
  background: var(--bg-interactive);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 22px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.interactive-box h4 {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 20px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }

.btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.output-box {
  background: var(--bg-code);
  border-radius: 8px;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 13px;
  color: #A6E3A1;
  margin-top: 12px;
  white-space: pre-wrap;
  min-height: 40px;
}

.output-box.error { color: #F38BA8; }

/* ============================================================
   CARDS & GRIDS
   ============================================================ */

.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0 20px;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.feature-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.feature-card h4 {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.feature-card p {
  font-size: 14.5px;
  line-height: 1.6;
  margin-bottom: 0;
  color: var(--text-muted);
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0 20px;
}

.comparison-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, transform 0.15s;
}

.comparison-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.comparison-card h4 {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.comparison-card p, .comparison-card .card-body {
  font-size: 14.5px;
  line-height: 1.65;
  margin-bottom: 0;
}

.recap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 20px 0 24px;
}

.recap-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, transform 0.15s;
}

.recap-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.recap-card h4 {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.recap-card p {
  font-size: 14.5px;
  line-height: 1.6;
  margin-bottom: 0;
  color: var(--text-muted);
}

/* ============================================================
   TAGS
   ============================================================ */

.tag {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-eager { background: var(--red-bg); color: var(--red); }
.tag-lazy { background: var(--teal-bg); color: var(--teal); }
.tag-lambda { background: var(--red-bg); color: var(--red); }
.tag-expr { background: var(--teal-bg); color: var(--teal); }
.tag-naive { background: var(--red-bg); color: var(--red); }
.tag-hash { background: var(--teal-bg); color: var(--teal); }
.tag-sorted { background: var(--purple-bg); color: var(--purple); }
.tag-before { background: var(--red-bg); color: var(--red); }
.tag-after { background: var(--teal-bg); color: var(--teal); }

/* ============================================================
   TIMELINE
   ============================================================ */

.timeline {
  border-left: 2px solid var(--border);
  margin: 20px 0 20px 12px;
  padding-left: 24px;
}

.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item:last-child { margin-bottom: 0; }

.timeline-item::before {
  content: '';
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  left: -34px;
  top: 6px;
}

.timeline-year {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.timeline-text { font-size: 15.5px; line-height: 1.6; }

/* ============================================================
   ARCHITECTURE BOX
   ============================================================ */

.arch-box {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 22px;
  margin: 20px 0 24px;
  box-shadow: var(--shadow-sm);
}

.arch-file {
  display: flex;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 16px;
}

.arch-file:last-child { border-bottom: none; }

.arch-name {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--purple);
  min-width: 120px;
  flex-shrink: 0;
}

.arch-lines {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  min-width: 70px;
  flex-shrink: 0;
  text-align: right;
}

.arch-desc {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.arch-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}

.arch-total-label {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.arch-total-num {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
}

/* ============================================================
   MODULE MAP
   ============================================================ */

.module-map { margin: 20px 0 24px; }

.map-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

.map-item:last-child { border-bottom: none; }

.map-num {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--bg-card);
  background: var(--accent);
  min-width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.map-num.map-extra { background: var(--bg-aside); color: var(--text-muted); }

.map-title {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.map-desc {
  font-size: 14.5px;
  color: var(--text-muted);
  line-height: 1.55;
}

.map-files {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--purple);
  margin-top: 4px;
}

/* ============================================================
   TOC (in-page)
   ============================================================ */

.toc {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 20px 0 32px;
  box-shadow: var(--shadow-sm);
}

.toc-title {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 14px;
}

.toc-item {
  font-family: var(--sans);
  font-size: 15px;
  padding: 6px 0;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
}

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

.toc-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  min-width: 28px;
}

/* ============================================================
   DEEP DIVE & RECALL (expandable)
   ============================================================ */

.deep-dive {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin: 18px 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.deep-dive summary {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  padding: 16px 22px;
  cursor: pointer;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

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

.deep-dive summary::before {
  content: '\25B6';
  font-size: 10px;
  transition: transform 0.2s;
}

.deep-dive[open] summary::before { transform: rotate(90deg); }

.deep-dive-body {
  padding: 0 22px 22px;
  font-size: 15.5px;
  line-height: 1.7;
}

.deep-dive-body p { margin-bottom: 16px; }
.deep-dive-body pre { margin: 14px 0 18px; }

details.recall {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  margin: 16px 0 24px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

details.recall summary {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 12px 18px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

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

details.recall summary::before {
  content: '\25B8';
  font-size: 11px;
  color: var(--text-light);
  transition: transform 0.15s;
}

details.recall[open] summary::before { transform: rotate(90deg); }
details.recall summary:hover { color: var(--accent); }

details.recall .recall-body { padding: 0 18px 16px; border-top: 1px solid var(--border-light); }
details.recall .recall-body pre { margin: 12px 0 4px; }

details.recall .recall-note {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.6;
}

/* ============================================================
   TABLES
   ============================================================ */

.complexity-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 14px;
  margin: 24px 0 28px;
}

.complexity-table th {
  background: var(--bg-aside);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}

.complexity-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-light); }
.complexity-table tr:hover td { background: var(--bg-aside); }
.complexity-table code { font-size: 0.88em; }

.rule-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0 28px;
  font-size: 15px;
}

.rule-table th {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-light);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
}

.rule-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.rule-table tr:hover td { background: var(--bg-aside); }
.rule-table td code { font-size: 0.85em; }

/* ============================================================
   PLAN TREE DIAGRAMS
   ============================================================ */

.plan-tree {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 16px 0 20px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
  box-shadow: var(--shadow-sm);
}

.plan-tree .node { color: var(--accent); font-weight: 500; }
.plan-tree .filter-node { color: var(--coral); font-weight: 500; }
.plan-tree .pushed { color: var(--teal); font-weight: 500; }
.plan-tree .pruned { color: var(--purple); font-weight: 500; }
.plan-tree .dim { color: var(--text-light); }

.plan-tree .annotation {
  color: var(--orange);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
}

/* ============================================================
   BEFORE/AFTER SPLIT
   ============================================================ */

.before-after {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0 20px;
}

.before-after-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.before-after-panel h4 {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.before-after-panel pre {
  margin: 0;
  padding: 14px 16px;
  font-size: 12.5px;
  line-height: 1.65;
}

/* ============================================================
   CONVERGENCE DIAGRAM
   ============================================================ */

.convergence-box {
  background: linear-gradient(135deg, var(--purple-bg) 0%, var(--teal-bg) 100%);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 22px;
  margin: 20px 0;
  text-align: center;
}

.convergence-box .trees {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 16px 0;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  flex-wrap: wrap;
}

.convergence-box .tree-label {
  padding: 10px 20px;
  border-radius: 6px;
  background: var(--bg-card);
}

.convergence-box .arrow { font-size: 24px; color: var(--text-muted); }

.convergence-box .result {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--purple);
  margin-top: 8px;
}

/* ============================================================
   PLAN ANNOTATION
   ============================================================ */

.plan-annotation {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  background: var(--bg-code);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 14px 0 20px;
  overflow-x: auto;
  border: 1px solid rgba(255,255,255,0.06);
  color: #CDD6F4;
}

.plan-annotation .node { color: #89B4FA; }
.plan-annotation .detail { color: #A6E3A1; }
.plan-annotation .arrow { color: #6C7086; }
.plan-annotation .waste { color: #F38BA8; }
.plan-annotation .good { color: #A6E3A1; }

/* ============================================================
   INVENTORY GRID
   ============================================================ */

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin: 16px 0 20px;
}

.inventory-item {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.inventory-item .icon { font-size: 24px; margin-bottom: 6px; }

.inventory-item .name {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.inventory-item .source {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--text-light);
}

/* ============================================================
   FLOW / MEMORY DIAGRAMS
   ============================================================ */

.flow-diagram {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 16px 0 20px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
  box-shadow: var(--shadow-sm);
}

.flow-diagram .node { color: var(--accent); font-weight: 500; }
.flow-diagram .data { color: var(--teal); font-weight: 500; }
.flow-diagram .mem { color: var(--coral); font-weight: 500; }
.flow-diagram .dim { color: var(--text-light); }

.flow-diagram .annotation {
  color: var(--orange);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
}

/* Memory calculator */
.mem-calc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}

.mem-result {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.mem-result .value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  margin: 8px 0 4px;
}

.mem-result .label {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.mem-result.bad .value { color: var(--coral); }
.mem-result.good .value { color: var(--teal); }

/* ============================================================
   DOWNLOAD BOX
   ============================================================ */

.download-box {
  background: var(--purple-bg);
  border: 1px solid rgba(83, 74, 183, 0.2);
  border-radius: 8px;
  padding: 18px 22px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.download-icon { font-size: 28px; flex-shrink: 0; }

.download-box .dl-text { flex: 1; }

.download-box .dl-title {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 15px;
  color: var(--purple);
  margin-bottom: 2px;
}

.download-box .dl-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 0;
  line-height: 1.5;
}

/* ============================================================
   OPEN QUESTION
   ============================================================ */

.open-question {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 22px 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.open-question h4 {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.open-question p {
  font-size: 15.5px;
  line-height: 1.65;
  margin-bottom: 0;
  color: var(--text-muted);
}

/* ============================================================
   RESOURCE CARD
   ============================================================ */

.resource-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 28px 32px;
  margin: 20px 0;
  display: flex;
  align-items: flex-start;
  gap: 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm);
}

.resource-card:hover {
  border-color: var(--purple);
  box-shadow: var(--shadow-md);
}

.resource-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
}

.resource-icon.docs { background: var(--purple-bg); }
.resource-icon.repo { background: var(--teal-bg); }

.resource-body h4 {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.resource-body h4 a { text-decoration: none; color: var(--text); }
.resource-body h4 a:hover { color: var(--purple); }

.resource-body p {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 0;
}

.resource-body code { font-size: 0.85em; }

/* ============================================================
   MISC
   ============================================================ */

.separator {
  border: none;
  height: 1px;
  background: var(--border-light);
  margin: 36px 0;
}

.highlight {
  background: linear-gradient(to bottom, transparent 60%, rgba(61, 90, 128, 0.12) 60%);
}

.chapter-end { text-align: center; padding: 28px 0; }

.chapter-end .label {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 12px;
}

.chapter-end .next {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
}

.closing-mark { text-align: center; padding: 40px 0 16px; }

.closing-mark .ornament {
  font-size: 28px;
  color: var(--border);
  letter-spacing: 12px;
  margin-bottom: 32px;
}

.closing-mark .sign-off {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  letter-spacing: 0.04em;
}

/* ============================================================
   PAGE NAVIGATION (prev/next)
   ============================================================ */

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-light);
  font-family: var(--sans);
}

.page-nav a {
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.page-nav a:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   LANDING PAGE
   ============================================================ */

.landing-hero {
  text-align: center;
  padding: 80px 24px 32px;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.landing-hero h1 {
  font-family: var(--serif);
  font-size: 56px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 20px;
  letter-spacing: -0.03em;
}

.landing-hero h1 em {
  font-style: italic;
  color: var(--accent);
}

.landing-hero .tagline {
  font-size: 21px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 600px;
  margin: 0 auto 44px;
}

.landing-start {
  display: inline-block;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 600;
  color: white;
  background: var(--accent);
  padding: 14px 32px;
  border-radius: 8px;
  text-decoration: none;
  transition: opacity 0.15s, box-shadow 0.15s, transform 0.15s;
  box-shadow: var(--shadow-md);
}

.landing-start:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(61, 90, 128, 0.2);
}

.landing-toc {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

.landing-toc h2 {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 20px;
}

.toc-list { list-style: none; }

.landing-toc .toc-item {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.landing-toc .toc-item:last-child { border-bottom: none; }

.landing-toc .toc-num {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: white;
  background: var(--accent);
  min-width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.landing-toc .toc-num.toc-extra {
  background: var(--bg-aside);
  color: var(--text-muted);
}

.toc-link {
  text-decoration: none;
  flex: 1;
}

.landing-toc .toc-title {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.toc-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.55;
}

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

.landing-about {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px 60px;
  text-align: center;
}

.landing-about p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 12px;
}

.landing-about a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.landing-about a:hover { text-decoration: underline; }

.site-footer {
  text-align: center;
  padding: 32px 24px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-light);
  border-top: 1px solid var(--border-light);
  margin-top: 40px;
}

/* ============================================================
   SVG DIAGRAM STYLES (inline)
   ============================================================ */

.node-box {
  rx: 8;
  fill: none;
  stroke: var(--border-light);
  stroke-width: 1;
}

.scan-fill { fill: #F5F3ED; }
.filter-fill { fill: #F0F4FA; }
.result-fill { fill: #EEEDFE; }

/* Module-2 expression AST diagrams */
.ast-box {
  rx: 8;
  stroke: var(--border-light);
  stroke-width: 1;
}
.ast-op { fill: var(--purple-bg); }
.ast-val { fill: var(--accent-light); }
.ast-lbl { font-family: var(--sans); font-size: 16px; font-weight: 600; }
.ast-tag { font-family: var(--sans); font-size: 10px; font-weight: 500; }
.ast-edge { stroke: var(--border); stroke-width: 1.5; }

/* Module-2 expression tree node diagrams */
.n-box {
  rx: 8;
  stroke: var(--border-light);
  stroke-width: 1;
}
.n-bin { fill: var(--purple-bg); }
.n-lit { fill: var(--teal-bg); }
.n-col { fill: var(--accent-light); }
.n-type { font-family: var(--sans); font-size: 13px; font-weight: 600; }
.n-label { font-family: var(--sans); font-size: 15px; font-weight: 600; }
.edge { stroke: var(--border); stroke-width: 1.5; }

.label {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
}

.label-scan { fill: var(--teal); }
.label-filter { fill: var(--accent); }
.label-result { fill: var(--purple); }

.row-text {
  font-family: var(--mono);
  font-size: 11px;
}

.row-neutral { fill: var(--text-muted); }
.row-pass { fill: var(--teal); }
.row-fail { fill: var(--red); }

.verdict {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sub {
  font-family: var(--sans);
  font-size: 10px;
  fill: var(--text-light);
}

.arr-line {
  stroke: #B4B2A9;
  stroke-width: 1.5;
  marker-end: url(#arw);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    transition: left 0.25s ease;
    box-shadow: none;
  }

  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .mobile-header {
    display: flex;
  }

  .course-container {
    padding: 28px 20px 60px;
  }
}

@media (max-width: 600px) {
  .landing-hero h1 { font-size: 34px; }
  .landing-hero { padding: 48px 24px 32px; min-height: 60vh; }
  .landing-hero .tagline { font-size: 18px; }

  .page-nav { flex-direction: column; gap: 12px; }
  .page-nav a { text-align: center; }

  h1 { font-size: 32px; }
  h2 { font-size: 24px; }

  .feature-grid { grid-template-columns: 1fr; }
  .comparison-grid { grid-template-columns: 1fr; }
  .before-after { grid-template-columns: 1fr; }
  .recap-grid { grid-template-columns: 1fr; }
  .mem-calc { grid-template-columns: 1fr; }
  .inventory-grid { grid-template-columns: 1fr 1fr; }

  .arch-file { flex-wrap: wrap; gap: 4px; }
  .arch-lines { text-align: left; min-width: auto; }

  .download-box { flex-direction: column; text-align: center; }
  .resource-card { flex-direction: column; gap: 14px; }

  body { font-size: 16px; }
  .course-container { padding: 20px 16px 48px; }
}

@media (min-width: 1400px) {
  .course-container {
    max-width: 1040px;
    padding-left: 56px;
    padding-right: 56px;
  }
}

/* ============================================================
   READING PROGRESS BAR
   ============================================================ */

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  z-index: 1000;
  transition: width 0.1s linear;
}

/* ============================================================
   SCROLL-REVEAL ANIMATIONS
   ============================================================ */

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.45s ease, transform 0.45s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children in grids */
.feature-grid .feature-card,
.comparison-grid .comparison-card,
.recap-grid .recap-card {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.4s ease, transform 0.4s ease, border-color 0.2s, box-shadow 0.2s;
}

.feature-grid.visible .feature-card,
.comparison-grid.visible .comparison-card,
.recap-grid.visible .recap-card {
  opacity: 1;
  transform: translateY(0);
}

.feature-grid.visible .feature-card:nth-child(2),
.comparison-grid.visible .comparison-card:nth-child(2),
.recap-grid.visible .recap-card:nth-child(2) {
  transition-delay: 0.08s;
}

.feature-grid.visible .feature-card:nth-child(3),
.comparison-grid.visible .comparison-card:nth-child(3),
.recap-grid.visible .recap-card:nth-child(3) {
  transition-delay: 0.16s;
}

.feature-grid.visible .feature-card:nth-child(4),
.comparison-grid.visible .comparison-card:nth-child(4),
.recap-grid.visible .recap-card:nth-child(4) {
  transition-delay: 0.24s;
}

/* Copy button on code blocks */
.code-block-wrapper {
  position: relative;
}

pre .copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.5);
  border-radius: 5px;
  padding: 4px 10px;
  font-family: var(--sans);
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.15s, color 0.15s;
}

pre:hover .copy-btn {
  opacity: 1;
}

pre .copy-btn:hover {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
}

pre .copy-btn.copied {
  color: #A6E3A1;
  border-color: rgba(166, 227, 161, 0.3);
}

/* Active heading highlight */
h2[id] {
  scroll-margin-top: 20px;
}

/* Smooth link hover in sidebar */
.sidebar-link {
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.sidebar-link:hover {
  transform: translateX(2px);
}

.sidebar-link.active {
  transform: none;
}

/* ============================================================
   PYODIDE INTERACTIVE RUNNER
   ============================================================ */

.runner-block {
  margin: 14px 0 20px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  transition: box-shadow 0.2s;
}

.runner-block:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

/* Collapse / expand */
.runner-body {
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease;
}

.runner-block.collapsed .runner-body {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.runner-block.expanded .runner-body {
  max-height: 2000px;
  opacity: 1;
}

.runner-block.collapsed .runner-header {
  border-bottom: none;
}

.runner-toggle-hint {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 500;
  color: rgba(255,255,255,0.2);
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.runner-header:hover .runner-toggle-hint {
  color: rgba(255,255,255,0.4);
}

.runner-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.runner-toggle-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color 0.15s, transform 0.25s;
}

.runner-header:hover .runner-toggle-btn {
  color: rgba(255,255,255,0.5);
}

.runner-block.collapsed .runner-toggle-btn .runner-chevron {
  transform: rotate(-90deg);
}

.runner-block.expanded .runner-toggle-btn .runner-chevron {
  transform: rotate(0deg);
}

.runner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #181825;
  padding: 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px 8px 0 0;
  user-select: none;
}

.runner-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.runner-play-icon {
  color: #A6E3A1;
  flex-shrink: 0;
  transition: color 0.15s, transform 0.15s;
}

.runner-block.collapsed .runner-play-icon {
  animation: pulse-play 2s ease-in-out infinite;
}

.runner-block.expanded .runner-play-icon {
  color: rgba(255,255,255,0.3);
  animation: none;
}

@keyframes pulse-play {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.runner-label {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

.runner-badge {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #A6E3A1;
  background: rgba(166, 227, 161, 0.1);
  padding: 2px 8px;
  border-radius: 3px;
}

.runner-badge.loading {
  color: #FAB387;
  background: rgba(250, 179, 135, 0.1);
}

.runner-editor {
  background: #1E1E2E;
  padding: 0;
  position: relative;
}

.runner-editor .cm-editor {
  min-height: 80px;
  max-height: 500px;
}

.runner-editor .cm-editor.cm-focused {
  outline: none;
}

.runner-editor .cm-scroller {
  overflow: auto;
}

.runner-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #181825;
  padding: 8px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  border-radius: 0 0 8px 8px;
}

.runner-toolbar:has(~ .runner-output.visible) {
  border-radius: 0;
}

.runner-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.runner-btn-run {
  background: var(--accent);
  color: white;
}

.runner-btn-run:hover {
  background: #4A6B94;
}

.runner-btn-run:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.runner-btn-run.running {
  background: var(--orange);
}

.runner-btn-reset {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.5);
}

.runner-btn-reset:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
}

.runner-output {
  background: #11111B;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 14px 20px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  color: #A6E3A1;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  border-radius: 0 0 8px 8px;
}

.runner-output.visible {
  display: block;
}

.runner-output.has-error {
  color: #F38BA8;
}

.runner-output .output-label {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
  margin-bottom: 6px;
  display: block;
}

/* Pyodide loading banner */
.pyodide-banner {
  background: linear-gradient(135deg, var(--accent-light), var(--purple-bg));
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 14px 20px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text-muted);
}

.pyodide-banner .pyodide-status {
  font-weight: 600;
  color: var(--accent);
}

.pyodide-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pyodide-banner.ready {
  background: var(--teal-bg);
  border-color: rgba(15, 110, 86, 0.2);
}

.pyodide-banner.ready .pyodide-status {
  color: var(--teal);
}

/* ============================================================
   SOURCE CODE LINKS
   ============================================================ */

a.source-link {
  text-decoration: none;
  border-bottom: 1px dashed var(--accent);
  transition: border-color 0.15s;
}

a.source-link:hover {
  border-bottom-style: solid;
  border-color: var(--purple);
}

a.source-link code {
  color: var(--orange);
}

a.source-link:hover code {
  color: var(--purple);
}

a.source-link::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 3px;
  margin-bottom: -1px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%233D5A80'%3E%3Cpath d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.4;
  transition: opacity 0.15s;
}

a.source-link:hover::after {
  opacity: 0.8;
}

/* ============================================================
   SOURCE REFERENCES SECTION
   ============================================================ */

.source-references {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border-light);
}

.source-references summary {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.source-references summary::before {
  content: '▶';
  font-size: 12px;
  transition: transform 0.2s;
}

.source-references details[open] > summary::before {
  transform: rotate(90deg);
}

.source-references details .source-ref-content {
  margin-top: 16px;
}

.source-references h2 {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.source-ref-group {
  margin-bottom: 20px;
}

.source-ref-group h4 {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.source-ref-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  list-style: none;
}

.source-ref-list li a {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--accent-light);
  transition: background 0.15s, color 0.15s;
}

.source-ref-list li a:hover {
  background: var(--purple-bg);
  color: var(--purple);
}
