/* === DESIGN SYSTEM === */
/* Vectors Prep - Brilliant.org-inspired light theme */
@import url('https://cdn.jsdelivr.net/gh/aaaakshat/cm-web-fonts@latest/fonts.css');

@property --border-draw {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

:root {
  /* Base */
  --bg: #ffffff;
  --bg-soft: #f5f5f7;
  --text: #1d1d1f;
  --text-muted: #595960;
  --border: #e5e5e7;

  /* Chapter accents */
  --ch2: #0b74fe;
  --ch2-light: #0b74fe15;
  --ch3: #ff6602;
  --ch3-light: #ff660215;
  --ch4: #7c4dff;
  --ch4-light: #7c4dff15;
  --ch5: #00be14;
  --ch5-light: #00be1415;

  /* Layout */
  --content-width: 720px;
  --viz-width: 900px;

  /* Typography */
  --font: 'Computer Modern Serif', 'CMU Serif', 'Latin Modern Roman', Georgia, serif;
  --font-mono: 'Computer Modern Typewriter', 'CMU Typewriter Text', 'Consolas', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 17px; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

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

/* === SKIP LINK === */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 10000;
  padding: 0.6rem 1.2rem;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 0;
}

/* === FOCUS STYLES === */
:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Remove outline for mouse clicks but keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* === LAYOUT === */
.page-container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* === NAVIGATION BAR === */
.topnav {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 100;
}
/* Keep the section/breadcrumb text on a single line; truncate gracefully if it ever needs to. */
.topnav > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topnav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.2s;
}

.topnav a:hover { color: var(--text); }

.topnav .chapter-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.topnav .chapter-label[data-chapter="2"] { background: var(--ch2-light); color: var(--ch2); }
.topnav .chapter-label[data-chapter="3"] { background: var(--ch3-light); color: var(--ch3); }
.topnav .chapter-label[data-chapter="4"] { background: var(--ch4-light); color: var(--ch4); }
.topnav .chapter-label[data-chapter="5"] { background: var(--ch5-light); color: var(--ch5); }

/* === PAGE HEADER === */
.page-header {
  margin-bottom: 2.5rem;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.page-header .subtitle {
  color: var(--text-muted);
  font-size: 1rem;
}

.prereq-links {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.prereq-links a {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
}

/* === LESSON CARDS === */
.card {
  background: var(--bg);
  border-left: 3px solid var(--border);
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  border-radius: 0 8px 8px 0;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.4s, border-color 0.3s;
}

.card.active { opacity: 1; }
.card.dimmed { opacity: 0.5; }
.card.hidden { display: none; }

.card[data-chapter="2"] { border-left-color: var(--ch2); }
.card[data-chapter="3"] { border-left-color: var(--ch3); }
.card[data-chapter="4"] { border-left-color: var(--ch4); }
.card[data-chapter="5"] { border-left-color: var(--ch5); }

.card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card p {
  margin-bottom: 0.75rem;
}

/* === HOOK (first card, special style) === */
.hook-card {
  background: var(--bg-soft);
  border-left: none;
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-md);
}

.hook-card .hook-question {
  font-size: 1.3rem;
  font-weight: 600;
  font-style: italic;
  color: var(--text);
  margin-top: 1rem;
}

/* === VISUALIZATION CONTAINERS === */
.viz-container {
  max-width: var(--viz-width);
  margin: 1.5rem auto;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
}

.viz-container canvas,
.viz-container .plotly-container {
  width: 100%;
  display: block;
}

.viz-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.viz-controls label,
.viz-controls .slider-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.viz-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}

.viz-container:not(.interacted) .viz-hint {
  opacity: 1;
  animation: pulse 2s ease-in-out infinite;
}

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

/* === SLIDERS === */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  min-width: 120px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ch4);
  cursor: grab;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
}

/* Chapter-specific slider colors */
[data-chapter="2"] input[type="range"]::-webkit-slider-thumb { background: var(--ch2); }
[data-chapter="3"] input[type="range"]::-webkit-slider-thumb { background: var(--ch3); }
[data-chapter="4"] input[type="range"]::-webkit-slider-thumb { background: var(--ch4); }
[data-chapter="5"] input[type="range"]::-webkit-slider-thumb { background: var(--ch5); }

.slider-value {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 3rem;
  text-align: center;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  border-radius: 3px;
  transition: border-color 0.15s;
}

.slider-value:hover {
  border-bottom-color: var(--text-muted);
}

.slider-value-input {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  padding: 0 0.25rem;
  outline: none;
  box-sizing: border-box;
  width: 100%;
}

/* === FORMULA BOXES === */
.formula-box {
  padding: 1rem 2rem;
  border-radius: 0;
  margin: 1rem -2rem;
  font-size: 1.1rem;
  text-align: center;
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.formula-box .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.formula-box[data-chapter="2"] { background: var(--ch2-light); }
.formula-box[data-chapter="3"] { background: var(--ch3-light); }
.formula-box[data-chapter="4"] { background: var(--ch4-light); }
.formula-box[data-chapter="5"] { background: var(--ch5-light); }

/* === CONTINUE BUTTON === */
.continue-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--text);
  color: var(--bg);
  margin-top: 1rem;
}

.continue-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.continue-btn::after {
  content: '→';
}
.continue-btn.no-arrow::after {
  content: none;
}

.card-counter {
  flex: 1;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* === CARD NAVIGATION ROW (Back + Continue) === */
.card-nav-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.card-nav-row .continue-btn {
  margin-top: 0;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.5rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  transition: all 0.2s;
}

.back-btn::before {
  content: '←';
}

.back-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* === PRACTICE SECTION === */
.practice-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border);
}

.practice-section h2 {
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
}

.practice-source {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-style: italic;
}

.problem-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.problem-header {
  padding: 1rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: background 0.2s;
}

.problem-header:hover { background: var(--bg-soft); }

.problem-header .problem-number {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.midterm-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  white-space: nowrap;
}

.problem-body {
  padding: 0 1.5rem 1.5rem;
}

.problem-statement {
  padding: 1rem;
  background: var(--bg-soft);
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* Step-by-step solution reveal */
.solution-step {
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  border-left: 3px solid var(--border);
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.solution-step .step-viz {
  flex: 0 0 300px;
}

.solution-step .step-math {
  flex: 1;
}

.solution-step.hidden {
  display: none;
}

/* === PRESET BUTTONS (visualization controls) === */
.preset-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0; }
.preset-btn {
  padding: 0.35rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.reveal-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.reveal-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

[data-chapter="2"] .reveal-btn:hover { border-color: var(--ch2); color: var(--ch2); }
[data-chapter="3"] .reveal-btn:hover { border-color: var(--ch3); color: var(--ch3); }
[data-chapter="4"] .reveal-btn:hover { border-color: var(--ch4); color: var(--ch4); }
[data-chapter="5"] .reveal-btn:hover { border-color: var(--ch5); color: var(--ch5); }

/* === PLAYGROUND SECTION === */
.playground {
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 2rem;
  margin: 2rem 0;
}

.playground h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.playground input[type="text"],
.playground textarea {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.playground input[type="text"]:focus,
.playground textarea:focus {
  border-color: var(--ch4);
}

.playground .go-btn {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  color: white;
  transition: transform 0.15s;
}

.playground .go-btn:hover { transform: translateY(-1px); }

[data-chapter="2"] .go-btn { background: var(--ch2); }
[data-chapter="3"] .go-btn { background: var(--ch3); }
[data-chapter="4"] .go-btn { background: var(--ch4); }
[data-chapter="5"] .go-btn { background: var(--ch5); }

/* === LANDING PAGE === */
.landing-hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.landing-hero h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.landing-hero p {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 2rem 0 1rem;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.topic-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  transition: box-shadow 0.2s;
  position: relative;
}
.topic-card[data-chapter="2"] { --card-accent: var(--ch2); }
.topic-card[data-chapter="3"] { --card-accent: var(--ch3); }
.topic-card[data-chapter="4"] { --card-accent: var(--ch4); }
.topic-card[data-chapter="5"] { --card-accent: var(--ch5); }

.topic-card::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 12px;
  background: conic-gradient(from 180deg, var(--card-accent) var(--border-draw), transparent var(--border-draw));
  --border-draw: 0deg;
  z-index: -1;
  opacity: 0;
}

.topic-card:hover {
  box-shadow: var(--shadow-md);
}
.topic-card:hover::before {
  animation: border-draw 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes border-draw {
  0%   { --border-draw: 0deg; opacity: 0; }
  30%  { opacity: 0.4; }
  100% { --border-draw: 360deg; opacity: 1; }
}

.topic-card .card-chapter {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.topic-card[data-chapter="2"] .card-chapter { color: var(--ch2); }
.topic-card[data-chapter="3"] .card-chapter { color: var(--ch3); }
.topic-card[data-chapter="4"] .card-chapter { color: var(--ch4); }
.topic-card[data-chapter="5"] .card-chapter { color: var(--ch5); }

.topic-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.topic-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.topic-card .checkmark {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #16a34a;
  color: white;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.topic-card.completed .checkmark { display: flex; }

.foundations-row {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.foundation-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  flex: 0 0 200px;
  padding: 1rem;
  background: var(--bg-soft);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.foundation-card:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.foundation-card .refresher-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.foundation-card h4 {
  font-size: 0.85rem;
  font-weight: 600;
}

/* === COMPLETION BUTTON (bottom of each topic page) === */
.complete-btn {
  display: block;
  width: 100%;
  padding: 1rem;
  margin-top: 3rem;
  border: 2px dashed var(--border);
  border-radius: 8px;
  background: none;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.complete-btn:hover {
  border-color: #16a34a;
  color: #16a34a;
}

.complete-btn.done {
  border-style: solid;
  border-color: #16a34a;
  background: #16a34a10;
  color: #16a34a;
}

/* === SITE FOOTER === */
.site-footer {
  text-align: center;
  padding: 2rem 1.5rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  line-height: 1.6;
}
.site-footer a {
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer a:hover {
  color: var(--text);
}

/* === NOTES DRAWER === */
.notes-btn {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
}
.notes-btn:hover { border-color: var(--text-muted); color: var(--text); background: var(--bg-soft); box-shadow: var(--shadow-sm); }


/* Fixed button group for pages without topnav. When the drawer is open,
   shift left by --app-drawer-width so buttons stay visible alongside the panel. */
.fixed-btn-group {
  position: fixed;
  top: 1rem;
  right: calc(var(--app-drawer-width, 0px) + 1.5rem);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: right 0.15s ease;
}
/* The fixed button group (Search/Notes/Settings on landing) stays visible
   while the drawer is open so users can switch tabs or close it. */
body:has(.stale-banner) .fixed-btn-group {
  position: sticky;
  top: 1rem;
  width: fit-content;
  margin-left: auto;
  margin-right: 1.5rem;
}

/* === SHARED APP DRAWER (Notes + Settings tabs) === */
.app-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 500px;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 150;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.06);
  font-family: var(--font);
}

.app-drawer-resize {
  position: absolute;
  left: -3px;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
}
.app-drawer-resize:hover,
.app-drawer-resize.dragging {
  background: var(--ch3);
  opacity: 0.3;
}

body.app-drawer-open {
  margin-right: 500px;
  transition: margin-right 0.15s ease;
}

/* Corner-floating close button - no dedicated header row, panels use full height.
   Vertically centered on the Notes search row / Settings first section so it
   reads as part of that row rather than a stray corner glyph. */
.app-drawer-close {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 5;
  background: var(--bg);
  border: 1px solid var(--border);
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.app-drawer-close:hover {
  color: var(--text);
  background: var(--bg-soft);
  border-color: var(--text-muted);
}

.app-drawer-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.app-drawer-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* === NOTES PANEL SUBHEADER (only shown in editor view) === */
.notes-subheader {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  /* Right padding clears the drawer's floating close × button. */
  padding: 0.55rem 3rem 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-header-title {
  font-size: 0.9rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.notes-header-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: all 0.15s;
}
.notes-header-btn:hover { color: var(--text); background: var(--bg-soft); }

.notes-search {
  /* Reserve right space so the search input doesn't run under the
     drawer's floating close × button (top: 0.5rem, right: 0.5rem). */
  padding: 0.5rem 3rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-search input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  font-family: var(--font);
  background: var(--bg-soft);
  outline: none;
  transition: border-color 0.2s;
}
.notes-search input:focus { border-color: var(--ch3); }

.notes-current-btn {
  display: block;
  width: calc(100% - 2rem);
  margin: 0.5rem 1rem;
  padding: 0.45rem 0.75rem;
  border: 1.5px solid var(--ch3);
  border-radius: 6px;
  background: var(--ch3-light);
  color: var(--ch3);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.notes-current-btn:hover { background: var(--ch3); color: white; }

.notes-list-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notes-editor-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}
.notes-chapter-group { padding: 0.25rem 0; }
.notes-chapter-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.4rem 1rem 0.2rem;
}
.notes-section-row {
  display: block;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
}
.notes-section-row:hover { background: var(--bg-soft); }
.notes-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.notes-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ch3);
  flex-shrink: 0;
}
.notes-section-snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notes-section-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.notes-footer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.notes-footer button {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.notes-footer button:hover { border-color: var(--text-muted); color: var(--text); }

.notes-editor-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.notes-editor-wrap .EasyMDEContainer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.notes-editor-wrap .EasyMDEContainer .CodeMirror {
  flex: 1;
  height: 0;
  border: none;
  border-radius: 0;
  font-family: var(--font);
  font-size: var(--editor-font-size, 0.88rem);
}
.notes-editor-wrap .CodeMirror-scroll {
  overflow-x: hidden !important;
}
.notes-editor-wrap .CodeMirror .cm-header-1 { font-size: 1.3em; }
.notes-editor-wrap .CodeMirror .cm-header-2 { font-size: 1.2em; }
.notes-editor-wrap .CodeMirror .cm-header-3 { font-size: 1.1em; }
.notes-editor-wrap .CodeMirror .cm-header-4,
.notes-editor-wrap .CodeMirror .cm-header-5,
.notes-editor-wrap .CodeMirror .cm-header-6 { font-size: 1.05em; }
.notes-editor-wrap .editor-preview h1 { font-size: 1.35em; }
.notes-editor-wrap .editor-preview h2 { font-size: 1.2em; }
.notes-editor-wrap .editor-preview h3 { font-size: 1.1em; }
.notes-editor-wrap .editor-preview h4,
.notes-editor-wrap .editor-preview h5,
.notes-editor-wrap .editor-preview h6 { font-size: 1.05em; }
.notes-editor-wrap .editor-toolbar {
  border-top: none;
  border-left: none;
  border-right: none;
}
.notes-editor-wrap .editor-preview,
.notes-editor-wrap .editor-preview-side {
  padding: 1rem;
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.6;
}
.notes-editor-wrap .editor-preview blockquote,
.notes-editor-wrap .editor-preview-side blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.75rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

/* Prevent EasyMDE fullscreen/side-by-side from escaping drawer */
.notes-editor-wrap .EasyMDEContainer .CodeMirror-fullscreen {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  height: auto !important;
  flex: 1;
  min-height: 0;
}
.notes-editor-wrap .editor-toolbar.fullscreen {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  width: auto !important;
  z-index: auto !important;
  opacity: 1 !important;
}
.notes-editor-wrap .editor-preview-side {
  position: absolute !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 50% !important;
  width: 50% !important;
  z-index: 9 !important;
}
.notes-editor-wrap .EasyMDEContainer.sided--no-fullscreen {
  display: flex !important;
  flex-direction: column !important;
  flex: 1;
  min-height: 0;
}



.notes-quote-btn {
  position: absolute;
  z-index: 1000;
  padding: 0.35rem 0.75rem;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  white-space: nowrap;
}
.notes-quote-btn::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
}
.notes-quote-btn:hover { opacity: 0.85; }

@media (max-width: 768px) {
  .app-drawer { width: 100vw !important; }
  body.app-drawer-open { margin-right: 0 !important; }
  .app-drawer-resize { display: none; }
}

/* === SEARCH TRIGGER BUTTON === */
/* Visually matches .section-nav-group anchors so the topnav reads as one row. */
/* Identical visual treatment to .notes-btn so the row is uniform. */
.search-trigger {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  text-decoration: none;
}
.search-trigger:hover {
  border-color: var(--text-muted);
  color: var(--text);
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
}
.search-trigger:focus-visible {
  outline: none;
  border-color: var(--ch3);
  box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.18);
}
.search-trigger-icon { flex-shrink: 0; color: var(--text-muted); }
.search-trigger:hover .search-trigger-icon { color: var(--text); }
.search-trigger-label {
  font-weight: 600;
  line-height: 1;
  color: inherit;
}
.search-trigger:hover .search-trigger-label { color: var(--text); }
.search-trigger-kbd {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.38rem;
  line-height: 1;
  white-space: nowrap;
}

/* In-topnav placement: full pill (icon + "Search" + shortcut), matching the
   landing-page button. Pushed to the right; mobile @640px collapses to icon-only. */
.search-trigger-nav { margin-left: auto; }
/* When the section-nav-group is also present, share the right cluster -
   the nav-group also has margin-left:auto, so only the first one wins;
   neutralize the second so they read as a single right-aligned cluster. */
.search-trigger-nav + .section-nav-group { margin-left: 0; }


/* Mobile: collapse Search to an icon-only circle matching .settings-btn. */
@media (max-width: 640px) {
  .search-trigger-label,
  .search-trigger-kbd { display: none; }
  .search-trigger {
    width: 1.75rem;
    padding: 0.25rem;
    justify-content: center;
    gap: 0;
    border-radius: 10px;
  }
  .search-trigger-icon { width: 16px; height: 16px; }
}

/* === SITE SEARCH (Ctrl+K) === */
.search-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  justify-content: center;
  padding-top: 15vh;
}
.search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
}
.search-dialog {
  position: relative;
  width: 92%;
  max-width: 960px;
  max-height: 78vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font);
}
.search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.search-chip {
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.search-chip:hover { color: var(--text); border-color: var(--text-muted); }
.search-chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.search-chip[data-chapter="2"].active { background: var(--ch2); border-color: var(--ch2); }
.search-chip[data-chapter="3"].active { background: var(--ch3); border-color: var(--ch3); }
.search-chip[data-chapter="4"].active { background: var(--ch4); border-color: var(--ch4); }
.search-chip[data-chapter="5"].active { background: var(--ch5); border-color: var(--ch5); }
.search-body {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  flex: 1;
  min-height: 0;
}
.search-preview {
  border-left: 1px solid var(--border);
  padding: 1rem 1.1rem;
  overflow-y: auto;
  background: var(--bg-soft);
  font-size: 0.88rem;
}
.search-preview-thumb {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  object-position: center top;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 0.85rem;
  background: var(--bg);
}
.search-preview-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}
.search-preview-head { margin-bottom: 0.75rem; }
.search-preview-section {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}
.search-preview-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.search-preview-head[data-chapter="2"] .search-preview-title { color: var(--ch2); }
.search-preview-head[data-chapter="3"] .search-preview-title { color: var(--ch3); }
.search-preview-head[data-chapter="4"] .search-preview-title { color: var(--ch4); }
.search-preview-head[data-chapter="5"] .search-preview-title { color: var(--ch5); }
.search-preview-formulas {
  margin: 0.5rem 0 0.85rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}
.search-preview-formula {
  overflow-x: auto;
  font-size: 0.95em;
}
.search-preview-formula .katex-display { margin: 0; font-size: 1em; }
.search-preview-text {
  color: var(--text);
  line-height: 1.5;
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
}
.search-preview-text mark {
  background: rgba(234, 88, 12, 0.18);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.search-preview-link {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ch3);
  text-decoration: none;
}
.search-preview-link:hover { text-decoration: underline; }
.search-footer {
  display: flex;
  gap: 1.2rem;
  padding: 0.5rem 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-soft);
}
.search-footer kbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  margin-right: 0.2rem;
}
@media (max-width: 720px) {
  .search-body { grid-template-columns: 1fr; }
  .search-preview { display: none; }
}
.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.search-icon { font-size: 1rem; opacity: 0.5; }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 1rem;
  background: transparent;
  color: var(--text);
}
.search-input::placeholder { color: var(--text-muted); }
.search-kbd {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  background: var(--bg-soft);
}
.search-results {
  overflow-y: auto;
  padding: 0.5rem;
  min-height: 0;
}
.search-hint {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.search-result {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "section title"
    "section page"
    "snippet snippet";
  column-gap: 0.7rem;
  row-gap: 0.15rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.search-result.active,
.search-result:hover { background: var(--bg-soft); }
.search-result.active { border-left-color: var(--ch3); }
.search-result[data-chapter="2"].active { border-left-color: var(--ch2); }
.search-result[data-chapter="3"].active { border-left-color: var(--ch3); }
.search-result[data-chapter="4"].active { border-left-color: var(--ch4); }
.search-result[data-chapter="5"].active { border-left-color: var(--ch5); }
.search-result-section {
  grid-area: section;
  align-self: center;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.02em;
  min-width: 2.6rem;
}
.search-result[data-chapter="2"] .search-result-section { color: var(--ch2); }
.search-result[data-chapter="3"] .search-result-section { color: var(--ch3); }
.search-result[data-chapter="4"] .search-result-section { color: var(--ch4); }
.search-result[data-chapter="5"] .search-result-section { color: var(--ch5); }
.search-result-title {
  grid-area: title;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
}
.search-result-page {
  grid-area: page;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.search-result-snippet {
  grid-area: snippet;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 0.15rem;
}
.search-result-snippet mark,
.search-result-title mark {
  background: rgba(234, 88, 12, 0.15);
  color: var(--ch3);
  border-radius: 2px;
  padding: 0 1px;
}

/* === KaTeX OVERRIDES === */
.katex-display { margin: 1rem 0; overflow-x: visible; overflow-y: visible; font-size: 1.1em; }
.katex { font-size: 1.05em; }

/* === SECTION NAV (prev/next in topnav) === */
.section-nav-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: auto;
}

.section-nav-group a {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
}
/* Compact topnav: hide the wordy section title, keep only the §X.Y label.
   Full title is still surfaced in the bottom-of-page section nav and in
   tooltips (the link's own title attribute / aria-label can carry it). */
.section-nav-group .nav-name { display: none; }
.section-nav-group .nav-info { flex-direction: row; }

.section-nav-group a:hover {
  border-color: var(--text-muted);
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
}

.section-nav-group .nav-arrow {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
}

.section-nav-group .nav-info {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.section-nav-group .nav-section {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.section-nav-group .nav-name {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-nav-group .topnav-next .nav-info { text-align: right; }

@media (max-width: 600px) {
  .section-nav-group .nav-info { display: none; }
}

/* === FONT OVERRIDES === */
.font-sans {
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.font-dyslexic {
  --font: 'OpenDyslexic', sans-serif;
}
.font-dyslexic .topnav { gap: 0.5rem; padding: 0.75rem 1rem; }
.font-dyslexic .topnav a { font-size: 0.75rem; }
.font-dyslexic .topnav .chapter-label { font-size: 0.65rem; padding: 0.15rem 0.45rem; }
.font-dyslexic .section-nav-group { gap: 0.35rem; }
.font-dyslexic .section-nav-group a { padding: 0.25rem 0.5rem; gap: 0.35rem; }
.font-dyslexic .section-nav-group .nav-section { font-size: 0.58rem; }
.font-dyslexic .section-nav-group .nav-name { font-size: 0.65rem; max-width: 120px; }
.font-dyslexic .section-nav-group .nav-arrow { font-size: 1rem; }
.font-dyslexic .notes-btn,
.font-dyslexic .settings-btn { font-size: 0.65rem; padding: 0.25rem 0.5rem; }

/* === SETTINGS DRAWER === */
.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  width: 1.75rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
}
.settings-btn:hover { border-color: var(--text-muted); color: var(--text); background: var(--bg-soft); box-shadow: var(--shadow-sm); }

/* Settings panel content (chrome lives in .app-drawer; outer panel inherits its flex layout). */
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.settings-section {
  padding: 0.5rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }

.settings-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.settings-action-btn {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.settings-action-btn + .settings-action-btn { margin-top: 0.4rem; }
.settings-action-btn:hover { border-color: var(--text-muted); background: var(--bg-soft); }
.settings-action-btn:disabled { opacity: 0.5; cursor: default; }

.settings-action-btn.settings-caching {
  pointer-events: none;
  color: var(--text-muted);
}
.settings-action-btn.settings-cached {
  border-color: #059669;
  color: #059669;
  pointer-events: none;
}

.settings-danger-btn { color: #dc2626; border-color: #fca5a5; }
.settings-danger-btn:hover { background: #fef2f2; border-color: #dc2626; }

.settings-offline-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.settings-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
  display: none;
}
.settings-progress.active { display: block; }

.settings-progress-bar {
  height: 100%;
  width: 0%;
  background: #2563eb;
  border-radius: 2px;
  transition: width 0.15s ease;
}

.settings-offline-size {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.settings-font-row {
  display: flex;
  gap: 0.4rem;
}

.settings-font-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.settings-font-btn:hover { border-color: var(--text-muted); color: var(--text); }
.settings-font-btn.active {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

.settings-font-size-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.settings-font-size-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.settings-font-size-row input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.settings-font-size-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: none;
  cursor: pointer;
}
.settings-font-size-row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: none;
  cursor: pointer;
}
.settings-font-size-value {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 2.5rem;
  text-align: right;
  font-family: var(--font-mono);
}

/* === CONTINUE TOAST === */
.continue-toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  margin: 1.5rem 0 -0.5rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  animation: fadeInUp 0.3s ease;
}
.continue-toast:hover {
  border-color: #2563eb;
  box-shadow: var(--shadow-sm);
}
.continue-toast-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.continue-toast-page {
  font-size: 0.85rem;
  font-weight: 600;
  flex: 1;
}
.continue-toast-dismiss {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
  transition: all 0.15s;
}
.continue-toast-dismiss:hover { color: var(--text); background: var(--border); }
.toast-hiding { opacity: 0; transform: translateY(-8px); transition: all 0.2s; }

/* === STALE CACHE BANNER === */
.stale-banner {
  position: relative;
  z-index: 201;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  margin-bottom: 0.5rem;
  font-size: 0.82rem;
  color: #92400e;
  animation: fadeInUp 0.3s ease;
}
.stale-banner span { flex: 1; }
.stale-banner-update {
  padding: 0.3rem 0.75rem;
  border: 1.5px solid #f59e0b;
  border-radius: 6px;
  background: #fef3c7;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 600;
  color: #92400e;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.stale-banner-update:hover { background: #fde68a; }
.stale-banner-dismiss {
  background: none;
  border: none;
  font-size: 1rem;
  color: #b45309;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  line-height: 1;
}
.stale-banner-dismiss:hover { background: #fde68a; }
.stale-banner-hiding { opacity: 0; transition: opacity 0.2s; }

@media (max-width: 600px) {
  .continue-toast { flex-wrap: wrap; }
  .continue-toast-text { width: 100%; }
  .stale-banner { flex-wrap: wrap; font-size: 0.78rem; }
}

/* === UTILITY === */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .fade-in,
  .fade-in-delay-1,
  .fade-in-delay-2,
  .fade-in-delay-3,
  .fade-in-delay-4,
  .fade-in-delay-5 {
    opacity: 1 !important;
    animation: none !important;
  }
}

/* === LIVE REGION FOR SCREEN READERS === */
.sr-live {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* === KEYBOARD SHORTCUTS OVERLAY === */
.keyshort-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: keyshort-fade 0.14s ease-out;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
@keyframes keyshort-fade {
  from { opacity: 0; } to { opacity: 1; }
}
.keyshort-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.6rem 2rem 1.3rem;
  max-width: 440px;
  width: calc(100% - 2rem);
  box-shadow: var(--shadow-lg);
  font-family: var(--font);
  animation: keyshort-pop 0.18s ease-out;
}
@keyframes keyshort-pop {
  from { transform: translateY(6px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.keyshort-panel h3 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}
.keyshort-panel table {
  width: 100%;
  border-collapse: collapse;
}
.keyshort-panel td {
  padding: 0.38rem 0.4rem;
  font-size: 0.95rem;
  color: var(--text);
  vertical-align: middle;
}
.keyshort-panel td:first-child {
  width: 78px;
  text-align: left;
}
.keyshort-panel kbd {
  display: inline-block;
  min-width: 1.8rem;
  padding: 0.14rem 0.5rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  line-height: 1.4;
}
.keyshort-footer {
  margin: 1rem 0 0;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.keyshort-footer kbd { font-size: 0.75rem; }

/* === COMPLETION FX (topic-aware particle canvas) === */
.completion-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
}
@media (prefers-reduced-motion: reduce) {
  .completion-fx { display: none; }
}

/* === GLYPH RAIN (nabla easter egg + chapter-scoped fallback) === */
.nabla-rain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}
.nabla-glyph {
  position: absolute;
  top: -3rem;
  font-family: var(--font);
  font-weight: 700;
  opacity: 0;
  will-change: transform, opacity;
  animation: nabla-fall linear forwards;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
@keyframes nabla-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.92; }
  90%  { opacity: 0.92; }
  100% { transform: translateY(110vh) rotate(360deg); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .nabla-rain { display: none; }
}

/* === SURPRISE-ME ROW (landing page) === */
.progress-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.85rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.progress-bottom-row .hint-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}
.progress-bottom-row .hint-text kbd {
  display: inline-block;
  min-width: 1.1rem;
  padding: 0.05rem 0.35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
}
.surprise-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  /* Idle: a full four-stop chapter-color gradient, all colors visible at once
     (ch2 teal -> ch3 orange -> ch4 indigo -> ch5 emerald). */
  background-image: linear-gradient(135deg,
    var(--ch2) 0%,
    var(--ch3) 33%,
    var(--ch4) 66%,
    var(--ch5) 100%);
  background-size: 100% 100%;
  background-position: 0% 0%;
  color: #fff;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 1.05rem;
  border-radius: 10px;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.12s ease, box-shadow 0.25s ease, filter 0.12s ease,
              background-size 0.5s ease, background-position 0.5s ease;
}
.surprise-btn:hover {
  transform: translateY(-1px);
  /* Hover: expand the gradient canvas and add a fifth stop that wraps back to
     ch2, so the keyframe pan is seamless and reveals all colors flowing past. */
  background-image: linear-gradient(135deg,
    var(--ch2), var(--ch3), var(--ch4), var(--ch5), var(--ch2));
  background-size: 300% 300%;
  /* Layered glow + drop shadow (orange + indigo) for a rainbow halo. */
  box-shadow:
    0 0 22px 2px rgba(234, 88, 12, 0.35),
    0 0 32px 4px rgba(99, 102, 241, 0.22),
    0 6px 18px rgba(0, 0, 0, 0.18);
  filter: brightness(1.06) saturate(1.1);
  animation: surprise-flow 3.5s ease-in-out infinite;
}
.surprise-btn:active { transform: translateY(0); filter: brightness(0.97); }
.surprise-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

@keyframes surprise-flow {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

/* Respect reduced-motion - keep the static lift/glow but skip the pan loop. */
@media (prefers-reduced-motion: reduce) {
  .surprise-btn:hover { animation: none; }
}
