/* ═══════════════════════════════════════════════
   READER — Reading experience styles
   ═══════════════════════════════════════════════ */

/* ── Inline figures & SVG diagrams ────────────── */
.chapter figure {
  margin: 1.5rem auto;
  text-align: center;
  max-width: 100%;
  overflow-x: auto;
}
.chapter figure svg {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}
.chapter figcaption {
  font-family: var(--font-code);
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
  letter-spacing: 0.04em;
}
/* ── Graphic novel panel layout ────────────────── */
.chapter figure.panel { margin: 0.8rem auto; border-radius: 10px; overflow: hidden; }
.chapter figure.panel svg { border-radius: 10px; border: 1px solid var(--border-subtle); }
.chapter figure.panel-full { max-width: 800px; }
.chapter figure.panel-half { max-width: 420px; }
.chapter .narrator-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin: 0.5rem auto;
  max-width: 620px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text);
  font-style: italic;
  line-height: 1.6;
}
.chapter .narrator-box strong { color: var(--gold); font-style: normal; }

.chapter img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1rem auto;
  display: block;
}

.sidebar-back-link {
  font-family: var(--font-code);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gold-dim);
  text-decoration: none;
  display: inline-block;
  letter-spacing: 0.07em;
  transition: color 0.2s;
}
.sidebar-back-link:hover { color: var(--gold-bright); }

#top-progress {
  position: fixed;
  top: 0; left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright), var(--gold));
  z-index: 9999;
  transition: width 0.15s linear;
  box-shadow: 0 0 12px rgba(201, 169, 110, 0.5);
}

/* ═══════════════════════════════════════════════
   HERO — Cinematic gateway with particle field
   ═══════════════════════════════════════════════ */
#hero {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 1000;
  background: var(--bg-deep);
  transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1), transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

#hero.exiting {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

#hero.hidden { display: none; }

#hero-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#hero-content {
  position: relative;
  z-index: 1;
  max-width: 800px;
  padding: 2rem;
}

#hero h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 4.5rem);
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: 0.02em;
  line-height: 1.15;
  margin-bottom: 0.6rem;
  text-shadow: 0 0 80px rgba(201, 169, 110, 0.4), 0 0 160px rgba(201, 169, 110, 0.15);
  opacity: 0; transform: translateY(30px);
  animation: heroReveal 1s 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#hero .subtitle {
  font-family: var(--font-heading);
  font-size: clamp(1rem, 2.5vw, 1.4rem);
  font-weight: 400; font-style: italic;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  opacity: 0; transform: translateY(20px);
  animation: heroReveal 1s 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#hero .manner {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--gold-dim); font-style: italic;
  margin-bottom: 3rem;
  opacity: 0; transform: translateY(20px);
  animation: heroReveal 1s 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.enter-scroll {
  display: inline-block;
  padding: 0.9rem 2.8rem;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: var(--font-heading);
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  background: transparent;
  position: relative;
  overflow: hidden;
  opacity: 0; transform: translateY(20px);
  animation: heroReveal 1s 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.enter-scroll::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(201,169,110,0.2), transparent 60%);
  opacity: 0;
  transition: opacity 0.3s;
}

.enter-scroll:hover { border-color: var(--gold); box-shadow: 0 0 40px rgba(201,169,110,0.2), inset 0 0 40px rgba(201,169,110,0.05); transform: translateY(-2px) !important; }
.enter-scroll:hover::before { opacity: 1; }
.enter-scroll:active { transform: scale(0.97) !important; }

.scroll-hint {
  position: absolute;
  bottom: 2.5rem; left: 50%;
  transform: translateX(-50%);
  color: var(--gold-dim);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-family: var(--font-heading);
  opacity: 0;
  animation: fadeIn 1s 1.5s forwards, hintFloat 3s 2.5s ease-in-out infinite;
}

@keyframes heroReveal {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { to { opacity: 0.6; } }
@keyframes hintFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

/* ═══════════════════════════════════════════════
   CHAPTER COUNTER — floating indicator
   ═══════════════════════════════════════════════ */
#chapter-indicator {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 200;
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
  background: var(--bg-elevated);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

#chapter-indicator.show {
  opacity: 1;
  transform: translateY(0);
}

/* ═══════════════════════════════════════════════
   LAYOUT
   ═══════════════════════════════════════════════ */
#app {
  opacity: 0;
  transition: opacity 0.6s 0.2s ease;
}

#app.visible {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  opacity: 1;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════ */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-elevated);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  padding: 1.2rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#sidebar-header {
  padding: 0.6rem 1.3rem 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}

#sidebar-header h2 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.06em;
}

#reading-progress {
  margin-top: 0.7rem;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
}

#reading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright));
  transition: width 0.2s linear;
  box-shadow: 0 0 8px rgba(201, 169, 110, 0.4);
}

.nav-part { margin-bottom: 0.15rem; }

.nav-part-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1.3rem;
  font-family: var(--font-heading);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gold-dim);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: color 0.25s, background 0.25s;
  border-radius: 2px;
}

.nav-part-title:hover { color: var(--gold); background: var(--sacred); }

.nav-part-title .chevron {
  font-size: 0.55rem;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-block;
}

.nav-part.collapsed .chevron { transform: rotate(-90deg); }
.nav-part.collapsed .nav-letters {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
}

.nav-letters {
  padding: 0.1rem 0;
  max-height: 2000px;
  opacity: 1;
  transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  overflow: hidden;
}

.nav-letter {
  display: block;
  padding: 0.32rem 1.3rem 0.32rem 1.9rem;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 2px solid transparent;
  line-height: 1.35;
  position: relative;
}

.nav-letter:hover {
  color: var(--text-bright);
  background: var(--sacred);
  padding-left: 2.1rem;
}

.nav-letter.active {
  color: var(--gold-bright);
  border-left-color: var(--gold);
  background: var(--gold-glow);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════
   CONTENT
   ═══════════════════════════════════════════════ */
#content {
  grid-column: 2;
  padding: 2.5rem 2rem 8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 0; /* prevent grid blowout */
  overflow-x: hidden;
}

/* Floating particles canvas behind content */
#particles-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

.chapter {
  max-width: var(--content-max);
  width: 100%;
  padding: 2rem 0;
  position: relative;
  z-index: 1;
  overflow-wrap: break-word;
  word-wrap: break-word;
  min-width: 0;
}

/* Staggered children reveal */
.chapter > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter.visible > * {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger delay for children */
.chapter.visible > *:nth-child(1) { transition-delay: 0s; }
.chapter.visible > *:nth-child(2) { transition-delay: 0.04s; }
.chapter.visible > *:nth-child(3) { transition-delay: 0.08s; }
.chapter.visible > *:nth-child(4) { transition-delay: 0.12s; }
.chapter.visible > *:nth-child(5) { transition-delay: 0.16s; }
.chapter.visible > *:nth-child(6) { transition-delay: 0.2s; }
.chapter.visible > *:nth-child(7) { transition-delay: 0.22s; }
.chapter.visible > *:nth-child(n+8) { transition-delay: 0.24s; }

/* ═══════════════════════════════════════════════
   SACRED DIVIDERS
   ═══════════════════════════════════════════════ */
.sacred-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 0;
  gap: 1.5rem;
  max-width: var(--content-max);
  width: 100%;
  z-index: 1;
}

.sacred-divider .line {
  flex: 1;
  max-width: 140px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

.sacred-divider .symbol {
  color: var(--gold-dim);
  transition: all 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.sacred-divider .symbol svg {
  width: 32px; height: 32px;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.sacred-divider:hover .symbol { color: var(--gold); }
.sacred-divider:hover .symbol svg { transform: rotate(180deg) scale(1.15); }
.sacred-divider:hover .line { background: linear-gradient(90deg, transparent, var(--gold), transparent); }

/* ═══════════════════════════════════════════════
   TYPOGRAPHY — Alive and breathing
   ═══════════════════════════════════════════════ */
.chapter h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--gold);
  margin: 2.5rem 0 0.8rem;
  letter-spacing: 0.02em;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.chapter h3 {
  font-family: var(--font-heading);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--gold-bright);
  margin: 0 0 1.2rem;
  letter-spacing: 0.01em;
  line-height: 1.25;
  text-shadow: 0 0 50px rgba(201, 169, 110, 0.2);
  position: relative;
}

/* Glowing underline for letter titles */
.chapter h3::after {
  content: '';
  display: block;
  width: 0;
  height: 2px;
  margin-top: 0.5rem;
  background: linear-gradient(90deg, var(--gold), transparent);
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 10px rgba(201, 169, 110, 0.3);
}

.chapter.visible h3::after {
  width: 60%;
}

.chapter h4 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--gold);
  margin: 2rem 0 0.6rem;
}

.chapter p {
  margin-bottom: 1.2rem;
  font-weight: 300;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.chapter p strong {
  font-weight: 600;
  color: var(--text-bright);
}

.chapter p em {
  color: var(--gold);
  font-style: italic;
}

/* Drop cap for opening paragraph of each chapter */
.chapter > p:first-of-type::first-letter {
  font-family: var(--font-heading);
  font-size: 3.4em;
  float: left;
  line-height: 0.8;
  margin: 0.05em 0.12em 0 0;
  color: var(--gold-bright);
  text-shadow: 0 0 20px rgba(201, 169, 110, 0.3);
}

.chapter blockquote {
  border-left: 3px solid var(--gold-dim);
  margin: 1.5rem 0;
  padding: 0.8rem 1.5rem;
  background: var(--sacred);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text-dim);
  transition: border-color 0.3s, background 0.3s;
}

.chapter blockquote:hover {
  border-left-color: var(--gold);
  background: rgba(201, 169, 110, 0.06);
}

.chapter blockquote p { margin-bottom: 0.5rem; }
.chapter blockquote p:last-child { margin-bottom: 0; }

.chapter ul, .chapter ol { margin: 1rem 0 1.2rem; padding-left: 1.5rem; }
.chapter li { margin-bottom: 0.4rem; font-weight: 300; }
.chapter li strong { font-weight: 600; color: var(--text-bright); }

.chapter hr {
  border: none; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: 2.5rem 0;
}

/* CODE — Glowing incantations */
.chapter code {
  font-family: var(--font-code);
  font-size: 0.82em;
  background: var(--bg-code);
  color: var(--gold);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  word-break: break-all;
}

.chapter pre {
  margin: 1.5rem 0;
  padding: 1.2rem 1.5rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  position: relative;
  transition: border-color 0.3s, box-shadow 0.3s;
  max-width: 100%;
}

.chapter pre:hover {
  border-color: var(--gold-dim);
  box-shadow: 0 0 30px rgba(201, 169, 110, 0.06), inset 0 0 30px rgba(201, 169, 110, 0.02);
}

.chapter pre code {
  background: none; border: none; padding: 0;
  font-size: 0.8rem; line-height: 1.6;
  color: var(--text); white-space: pre; display: block;
  font-variant-ligatures: none; tab-size: 4;
}

/* Copy button on code blocks */
.code-copy {
  position: absolute;
  top: 0.6rem; right: 0.6rem;
  background: rgba(201, 169, 110, 0.1);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 0.65rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chapter pre:hover .code-copy { opacity: 1; }
.code-copy:hover { background: rgba(201, 169, 110, 0.2); color: var(--gold); border-color: var(--gold-dim); }
.code-copy.copied { color: var(--gold-bright); border-color: var(--gold); }

/* Links */
.chapter a {
  color: var(--gold);
  text-decoration: none;
  background-image: linear-gradient(var(--gold-dim), var(--gold-dim));
  background-size: 100% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s, color 0.2s;
}

.chapter a:hover {
  color: var(--gold-bright);
  background-image: linear-gradient(var(--gold), var(--gold));
  background-size: 100% 2px;
}

/* ═══════════════════════════════════════════════
   CHAPTER MARKER — Adinkra with glow
   ═══════════════════════════════════════════════ */
.chapter-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.8rem;
}

.chapter-marker svg {
  width: 30px; height: 30px;
  opacity: 0.4;
  filter: drop-shadow(0 0 6px rgba(201, 169, 110, 0.3));
  transition: all 0.4s;
}

.chapter.visible .chapter-marker svg {
  opacity: 0.7;
  animation: markerPulse 3s ease-in-out infinite;
}

@keyframes markerPulse {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(201, 169, 110, 0.2)); }
  50% { filter: drop-shadow(0 0 14px rgba(201, 169, 110, 0.5)); }
}

/* ═══════════════════════════════════════════════
   MOBILE
   ═══════════════════════════════════════════════ */
#mobile-toggle {
  display: none;
  position: fixed;
  top: 0.8rem; left: 0.8rem;
  z-index: 200;
  width: 42px; height: 42px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--gold);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: all 0.25s;
}

#mobile-toggle:hover { border-color: var(--gold-dim); background: rgba(201,169,110,0.1); }
#mobile-toggle:active { transform: scale(0.92); }

#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.35s;
}
#sidebar-overlay.open { display: block; opacity: 1; }

/* Back to top */
#back-to-top {
  position: fixed;
  bottom: 2rem; right: 2rem;
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--gold-dim);
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(10px) scale(0.9);
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
}

#back-to-top.show { opacity: 1; transform: translateY(0) scale(1); }
#back-to-top:hover { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 20px rgba(201,169,110,0.15); }
#back-to-top:active { transform: scale(0.9); }

/* ═══════════════════════════════════════════════
   KEYBOARD HINTS
   ═══════════════════════════════════════════════ */
#keyboard-hint {
  position: fixed;
  bottom: 1rem; left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-code);
  font-size: 0.65rem;
  color: var(--text-dim);
  background: var(--bg-elevated);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.5s;
  z-index: 50;
  pointer-events: none;
  letter-spacing: 0.04em;
}

#keyboard-hint.show { opacity: 0.7; }

/* ═══════════════════════════════════════════════
   THEME & TYPOGRAPHY CONTROLS
   ═══════════════════════════════════════════════ */
body, #sidebar, #content, #hero, .chapter, .chapter pre, .chapter blockquote {
  transition: background-color 0.5s ease, color 0.3s ease, border-color 0.3s ease;
}
body { font-size: var(--font-size, 19px); line-height: var(--line-height, 1.85); }

#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin: 0 1.3rem 0.4rem;
}
.sidebar-tab {
  flex: 1;
  padding: 0.45rem 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active { color: var(--gold); border-bottom-color: var(--gold); }

#sidebar-controls {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 1.3rem;
}
.sidebar-ctrl-btn {
  padding: 0.3rem 0.55rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.58rem;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.04em;
}
.sidebar-ctrl-btn:hover { border-color: var(--border); color: var(--text); }
.sidebar-ctrl-btn.active { color: var(--gold); border-color: rgba(201,169,110,0.25); background: rgba(201,169,110,0.06); }

#theme-panel, #typo-panel, #export-panel { display: none; padding: 0.6rem 1.3rem; border-bottom: 1px solid var(--border-subtle); }
#theme-panel.open, #typo-panel.open, #export-panel.open { display: block; }

.export-label {
  font-family: var(--font-code);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}
.export-options { display: flex; gap: 0.5rem; }
.export-option-btn {
  flex: 1;
  padding: 0.45rem 0.6rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.68rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.export-option-btn:hover {
  border-color: var(--gold-dim);
  color: var(--gold);
  background: rgba(201,169,110,0.06);
}

.theme-swatches { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.theme-swatch {
  width: 30px; height: 30px;
  border-radius: 7px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.25s;
}
.theme-swatch:hover { transform: scale(1.1); }
.theme-swatch.active { border-color: var(--gold); box-shadow: 0 0 12px rgba(201,169,110,0.3); }
.theme-swatch[data-theme="midnight"] { background: #0a0a14; border-color: #1e1e30; }
.theme-swatch[data-theme="parchment"] { background: #faf7f0; }
.theme-swatch[data-theme="sepia"] { background: #f5edd8; }
.theme-swatch[data-theme="dawn"] { background: #201a2a; border-color: #352a45; }
.theme-swatch.active[data-theme="midnight"] { border-color: #c9a96e; }

.theme-label {
  font-family: var(--font-code);
  font-size: 0.52rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.typo-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.typo-label {
  font-family: var(--font-code);
  font-size: 0.52rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  min-width: 48px;
}
.typo-slider {
  flex: 1;
  -webkit-appearance: none; appearance: none;
  height: 3px; background: var(--border);
  border-radius: 2px; outline: none;
}
.typo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--gold-dim);
  border-radius: 50%;
  cursor: pointer;
}
.typo-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--gold-dim);
  border-radius: 50%;
  cursor: pointer; border: none;
}
.typo-value {
  font-family: var(--font-code);
  font-size: 0.58rem;
  color: var(--text-dim);
  min-width: 26px;
  text-align: right;
}

/* ═══════════════════════════════════════════════
   BOOKMARKS & HIGHLIGHTS
   ═══════════════════════════════════════════════ */
.bookmark-btn {
  float: right;
  background: none; border: none;
  cursor: pointer; color: var(--text-dim);
  font-size: 1rem; opacity: 0.25;
  transition: all 0.25s; padding: 0.2rem;
}
.bookmark-btn:hover { opacity: 0.7; color: var(--gold); }
.bookmark-btn.active { opacity: 1; color: var(--gold); }

.nav-bookmark-dot {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: 0.3rem;
  vertical-align: middle;
}

.text-highlight {
  border-radius: 2px; padding: 0 1px;
  cursor: pointer; transition: filter 0.2s;
}
.text-highlight:hover { filter: brightness(1.3); }
.text-highlight[data-color="gold"] { background: rgba(201,169,110,0.25); }
.text-highlight[data-color="coral"] { background: rgba(205,92,92,0.25); }
.text-highlight[data-color="teal"] { background: rgba(72,166,166,0.25); }
.text-highlight[data-color="lavender"] { background: rgba(148,120,196,0.25); }

#highlight-toolbar {
  position: absolute; display: none; z-index: 200;
  padding: 0.4rem 0.5rem;
  background: var(--bg-elevated);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  gap: 0.3rem; align-items: center;
}
#highlight-toolbar.show { display: flex; }
.hl-color-btn {
  width: 22px; height: 22px;
  border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: all 0.2s;
}
.hl-color-btn:hover { transform: scale(1.2); border-color: rgba(255,255,255,0.3); }
.hl-color-btn[data-color="gold"] { background: #c9a96e; }
.hl-color-btn[data-color="coral"] { background: #cd5c5c; }
.hl-color-btn[data-color="teal"] { background: #48a6a6; }
.hl-color-btn[data-color="lavender"] { background: #9478c4; }

/* ═══════════════════════════════════════════════
   STUDY PANEL
   ═══════════════════════════════════════════════ */
#study-panel-content { display: none; padding: 0 1.3rem 1rem; }
#study-panel-content.open { display: block; }
.study-section-title {
  font-family: var(--font-code);
  font-size: 0.55rem; color: var(--gold-dim);
  letter-spacing: 0.1em; text-transform: uppercase;
  margin: 0.8rem 0 0.3rem;
}
.study-item {
  padding: 0.4rem 0; border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 0.75rem; color: var(--text-dim); cursor: pointer;
  transition: color 0.2s; line-height: 1.4;
}
.study-item:hover { color: var(--text); }
.study-color-dot {
  display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; vertical-align: middle; margin-right: 0.3rem;
}
.study-export-btn {
  display: block; width: 100%; margin-top: 0.8rem;
  padding: 0.5rem; background: rgba(201,169,110,0.06);
  border: 1px solid rgba(201,169,110,0.15); border-radius: 6px;
  color: var(--gold-dim); font-family: var(--font-code);
  font-size: 0.58rem; letter-spacing: 0.06em;
  cursor: pointer; transition: all 0.2s; text-align: center;
}
.study-export-btn:hover { background: rgba(201,169,110,0.12); color: var(--gold); }

/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */
@media (max-width: 960px) {
  :root { --sidebar-w: 280px; --content-max: 100%; }
  #app.visible { grid-template-columns: 1fr; }
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 30px rgba(0,0,0,0.6); }
  #mobile-toggle { display: flex; }
  /* Clear the fixed mobile toggle (≈52px) so sidebar header content isn't hidden behind it */
  #sidebar-header { padding-left: 3.6rem; }
  #content { grid-column: 1; padding: 2.5rem 1.2rem 5rem; }
  #chapter-indicator { display: none; }
  #keyboard-hint { display: none; }
  body { font-size: 17px; }
  .chapter h3 { font-size: 1.45rem; }
  .chapter h2 { font-size: 1.3rem; }
  .chapter > p:first-of-type::first-letter { font-size: 2.6em; }
  .chapter pre { margin-left: -0.4rem; margin-right: -0.4rem; border-radius: 6px; padding: 1rem; }
  .chapter pre code { font-size: 0.72rem; }
}

@media (max-width: 480px) {
  body { font-size: 16px; line-height: 1.75; }
  #hero h1 { font-size: 1.8rem; }
  #hero .subtitle { font-size: 0.95rem; }
  #hero .manner { font-size: 0.85rem; margin-bottom: 2rem; }
  .enter-scroll { padding: 0.7rem 2rem; font-size: 0.95rem; }
  #content { padding: 2rem 1rem 4rem; }
  .chapter h3 { font-size: 1.3rem; }
  .chapter h2 { font-size: 1.15rem; }
  .chapter pre { padding: 0.7rem 0.8rem; margin-left: -0.5rem; margin-right: -0.5rem; }
  .chapter pre code { font-size: 0.65rem; line-height: 1.5; }
  .chapter > p:first-of-type::first-letter { font-size: 2.2em; }
  .chapter blockquote { padding: 0.6rem 1rem; margin-left: 0; margin-right: 0; }
  .sacred-divider { padding: 1.5rem 0; }
  .sacred-divider .symbol svg { width: 24px; height: 24px; }
  #back-to-top { bottom: 1rem; right: 1rem; width: 38px; height: 38px; font-size: 0.95rem; }
  #mobile-toggle { top: 0.6rem; left: 0.6rem; width: 38px; height: 38px; }
}

/* ═══════════════════════════════════════════════
   DEMO PANELS — Live Wasm embedded in chapters
   ═══════════════════════════════════════════════ */
.demo-panel {
  margin: 2rem 0;
  padding: 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}

.demo-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-bright), var(--gold-dim));
  opacity: 0.6;
}

.demo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
}

.demo-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--gold);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.demo-badge {
  font-family: var(--font-code);
  font-size: 0.6rem;
  color: var(--gold-bright);
  background: rgba(201, 169, 110, 0.15);
  padding: 0.2rem 0.5rem;
  border-radius: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: badgePulse 2s ease-in-out infinite;
}

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

.demo-canvas-wrap {
  position: relative;
  width: 100%;
  margin-bottom: 0.6rem;
}

.demo-canvas-wrap canvas {
  width: 100%;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-deep);
}

.demo-controls {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.demo-btn {
  background: rgba(201, 169, 110, 0.08);
  border: 1px solid var(--border);
  color: var(--gold);
  font-family: var(--font-code);
  font-size: 0.7rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}

.demo-btn:hover { background: rgba(201, 169, 110, 0.18); border-color: var(--gold-dim); }
.demo-btn:active { transform: scale(0.95); }
.demo-btn.active { background: var(--gold-dim); color: var(--bg-deep); border-color: var(--gold); font-weight: 500; }
.demo-btn.primary { background: rgba(201, 169, 110, 0.15); border-color: var(--gold-dim); }

.demo-stats {
  font-family: var(--font-code);
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.demo-stats span { color: var(--gold); }

/* Stack machine specific */
.stack-vm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.stack-vm-panel {
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.6rem;
  min-height: 120px;
}

.stack-vm-panel h4 {
  font-family: var(--font-code);
  font-size: 0.65rem;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}

.stack-vm-panel .values {
  font-family: var(--font-code);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text);
}

.stack-val {
  display: inline-block;
  background: rgba(201, 169, 110, 0.12);
  border: 1px solid var(--border);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  margin: 0.1rem;
  transition: all 0.2s;
}

.stack-val.new { background: rgba(201, 169, 110, 0.3); border-color: var(--gold); }

.program-line {
  font-family: var(--font-code);
  font-size: 0.7rem;
  padding: 0.1rem 0.3rem;
  color: var(--text-dim);
  border-radius: 2px;
  transition: all 0.15s;
}

.program-line.active {
  background: rgba(201, 169, 110, 0.2);
  color: var(--gold-bright);
}

.demo-output {
  font-family: var(--font-code);
  font-size: 0.75rem;
  color: var(--gold);
  margin-top: 0.4rem;
  min-height: 1.2rem;
}

.demo-error {
  color: var(--accent-crimson);
  font-family: var(--font-code);
  font-size: 0.7rem;
  margin-top: 0.3rem;
}

.demo-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-dim);
  font-family: var(--font-heading);
  font-size: 0.9rem;
}

@media (max-width: 960px) {
  .demo-panel { margin: 1.5rem -0.5rem; padding: 1rem; }
  .stack-vm-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .demo-panel { margin: 1rem -0.3rem; padding: 0.8rem; }
  .demo-btn { font-size: 0.65rem; padding: 0.3rem 0.6rem; }
  .demo-stats { font-size: 0.6rem; }
}

/* ═══════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════ */
#loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh;
  color: var(--text-dim);
  font-family: var(--font-heading);
  font-size: 1.1rem;
}

.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 1rem;
}

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

/* ═══════════════════════════════════════════════
   PRINT
   ═══════════════════════════════════════════════ */
@media print {
  #sidebar, #mobile-toggle, #back-to-top, #hero, #particles-canvas,
  #top-progress, #chapter-indicator, #keyboard-hint, #highlight-toolbar,
  #portal-overlay, #export-panel,
  .sacred-divider, .chapter-marker, .code-copy, .demo-panel { display: none !important; }
  #app.visible { display: block !important; }
  #content { padding: 0 !important; }
  .chapter, .chapter > * { opacity: 1 !important; transform: none !important; max-width: 100%; }
  body { color: #000; background: #fff; font-size: 11pt; }
  .chapter h3 { color: #000; text-shadow: none; }
  .chapter h3::after { display: none; }
  .chapter pre { border: 1px solid #ccc; }
  .chapter > p:first-of-type::first-letter { color: #333; text-shadow: none; }
}

/* ═══════════════════════════════════════════════
   SOVEREIGN PROMPT — first-letter completion bar
   ═══════════════════════════════════════════════ */
.sovereign-prompt {
  position: fixed;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 560px;
  width: calc(100% - 2rem);
  background: var(--void-deep, #0a0a14);
  border: 1px solid rgba(201,169,110,0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-dim, #888);
  z-index: 900;
  transition: bottom 0.4s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.sovereign-prompt.visible { bottom: 1.5rem; }
.sovereign-prompt-btn {
  background: none;
  border: 1px solid rgba(201,169,110,0.4);
  border-radius: 4px;
  color: var(--gold, #c9a96e);
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.sovereign-prompt-btn:hover { background: rgba(201,169,110,0.08); }
.sovereign-prompt-close {
  background: none;
  border: none;
  color: var(--text-dim, #888);
  font-size: 1rem;
  cursor: pointer;
  margin-left: auto;
  padding: 0 0.25rem;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   ATTESTATION BANNER — book completion moment
   ═══════════════════════════════════════════════ */
.attestation-banner {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 560px;
  width: calc(100% - 2rem);
  background: var(--void-deep, #0a0a14);
  border: 1px solid rgba(201,169,110,0.5);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text, #e8e4dc);
  z-index: 900;
  transition: top 0.4s cubic-bezier(0.34,1.56,0.64,1);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.attestation-banner.visible { top: 1.5rem; }
.attestation-icon {
  color: var(--gold, #c9a96e);
  font-size: 1rem;
  flex-shrink: 0;
}
.attestation-close {
  background: none;
  border: none;
  color: var(--text-dim, #888);
  font-size: 1rem;
  cursor: pointer;
  margin-left: auto;
  padding: 0 0.25rem;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   SHARE — Nostr note publishing from chapters
   ═══════════════════════════════════════════════ */
.share-btn {
  float: right;
  background: none; border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  opacity: 0.4;
  transition: all 0.25s; padding: 0.2rem;
  margin-left: 0.25rem;
}
.share-btn:hover { opacity: 0.8; color: var(--gold); }

.share-popover {
  background: var(--bg-elevated);
  border: 1px solid rgba(201,169,110,0.25);
  border-radius: 0.75rem;
  padding: 1rem;
  margin: 0.75rem 0 1.5rem;
  position: relative;
}

.share-textarea {
  width: 100%;
  box-sizing: border-box;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(201,169,110,0.2);
  border-radius: 0.4rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 0.65rem 0.75rem;
  resize: vertical;
  min-height: 100px;
  outline: none;
}
.share-textarea:focus { border-color: rgba(201,169,110,0.45); }

.share-popover-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  align-items: center;
}

.share-publish-btn {
  background: rgba(201,169,110,0.14);
  border: 1px solid rgba(201,169,110,0.35);
  border-radius: 99px;
  color: var(--gold-bright);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.4rem 1rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.15s;
}
.share-publish-btn:hover { background: rgba(201,169,110,0.26); }

.share-cancel-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  transition: color 0.2s;
}
.share-cancel-btn:hover { color: var(--text); }

.share-status {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold-dim);
  margin: 0.4rem 0 0;
  min-height: 1em;
}

/* ═══════════════════════════════════════════════
   READER IDENTITY — Sidebar portal access
   ═══════════════════════════════════════════════ */
.sidebar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.1rem;
}

.reader-identity-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: 1px solid rgba(201,169,110,0.2);
  border-radius: 99px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
.reader-identity-btn:hover {
  border-color: rgba(201,169,110,0.55);
  color: var(--gold-bright);
}

/* ── Discuss link — community shortcut in sidebar ── */
.discuss-link {
  display: inline-block;
  font-family: var(--font-code);
  font-size: 0.62rem;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 0.06em;
  margin-top: 0.35rem;
  padding: 0.15rem 0;
  transition: color 0.2s;
}
.discuss-link:hover { color: var(--gold-bright); }
.discuss-link[hidden] { display: none; }

/* ═══════════════════════════════════════════════
   THE PALAVER TREE — Per-chapter discussions
   ═══════════════════════════════════════════════ */
.palaver-footer {
  max-width: var(--content-max, 72ch);
  margin: 0.4rem auto 0;
  padding: 0 0.5rem;
}
.palaver-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: none; border: 1px solid var(--border-subtle);
  border-radius: 8px; padding: 0.35rem 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-code);
  font-size: 0.58rem; letter-spacing: 0.06em;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.palaver-btn:hover { border-color: var(--gold-dim); color: var(--gold); }
.palaver-icon { font-size: 0.7rem; }
.palaver-count {
  font-size: 0.5rem; color: var(--gold-dim);
}
.palaver-thread {
  margin-top: 0.6rem;
  padding: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.palaver-loading {
  font-family: var(--font-code);
  font-size: 0.6rem; color: var(--text-dim);
  text-align: center; padding: 0.5rem;
}
.palaver-empty {
  font-family: var(--font-body);
  font-size: 0.72rem; color: var(--text-dim);
  text-align: center; padding: 0.5rem;
  font-style: italic;
}
.palaver-compose {
  margin-bottom: 0.8rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border-subtle);
}
.palaver-input {
  width: 100%; resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.75rem;
}
.palaver-input:focus {
  outline: none; border-color: var(--gold-dim);
}
.palaver-compose-actions {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.3rem;
}
.palaver-submit {
  background: var(--gold-dim); color: var(--bg);
  border: none; border-radius: 6px;
  padding: 0.3rem 0.8rem;
  font-family: var(--font-code);
  font-size: 0.55rem; letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.2s;
}
.palaver-submit:hover { background: var(--gold); }
.palaver-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.palaver-status {
  font-family: var(--font-code);
  font-size: 0.52rem; color: var(--text-dim);
}
.palaver-reply {
  padding: 0.4rem 0;
  border-left: 2px solid var(--gold-dim);
  padding-left: 0.6rem;
  margin-bottom: 0.3rem;
}
.palaver-reply + .palaver-reply {
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.5rem;
}
.palaver-reply-meta {
  display: flex; gap: 0.5rem; align-items: baseline;
  margin-bottom: 0.15rem;
}
.palaver-author {
  font-family: var(--font-code);
  font-size: 0.52rem; color: var(--gold-dim);
}
.palaver-time {
  font-family: var(--font-code);
  font-size: 0.48rem; color: var(--text-dim);
}
.palaver-reply-text {
  font-family: var(--font-body);
  font-size: 0.75rem; color: var(--text);
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   MARGIN NOTES — Paragraph annotations
   ═══════════════════════════════════════════════ */
.margin-add-btn {
  position: absolute;
  right: -1.5rem; top: 0.2rem;
  width: 1.2rem; height: 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-dim);
  font-size: 0.7rem; line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, border-color 0.2s;
}
p:hover .margin-add-btn { opacity: 0.6; }
.margin-add-btn:hover { opacity: 1 !important; border-color: var(--gold-dim); color: var(--gold); }

.margin-notes {
  position: absolute;
  right: calc(-1 * var(--margin-gutter, 210px));
  top: 0; width: 190px;
}
.margin-note {
  background: var(--bg-elevated);
  border-left: 2px solid var(--gold-dim);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.65rem;
  line-height: 1.4;
}
.margin-note-author {
  font-family: var(--font-code);
  font-size: 0.48rem; color: var(--gold-dim);
  display: block; margin-bottom: 0.1rem;
}
.margin-note-text {
  font-family: var(--font-body);
  color: var(--text-dim);
}

.margin-input {
  max-width: var(--content-max, 72ch);
  margin: 0.4rem 0;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.margin-textarea {
  width: 100%; resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.72rem;
}
.margin-textarea:focus { outline: none; border-color: var(--gold-dim); }
.margin-input-actions {
  display: flex; gap: 0.4rem; margin-top: 0.3rem;
}
.margin-submit, .margin-cancel {
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 0.25rem 0.6rem;
  font-family: var(--font-code);
  font-size: 0.52rem; color: var(--text-dim);
  cursor: pointer; transition: color 0.2s;
}
.margin-submit { background: var(--gold-dim); color: var(--bg); border-color: var(--gold-dim); }
.margin-submit:hover { background: var(--gold); }
.margin-cancel:hover { color: var(--gold); }

/* ═══════════════════════════════════════════════
   SCROLL LABORATORIES — Interactive lab panels
   ═══════════════════════════════════════════════ */
.lab-panel {
  margin: 1.5rem auto;
  max-width: var(--content-max, 72ch);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.lab-badge {
  background: rgba(72,166,166,0.15) !important;
  color: #48a6a6 !important;
}
.lab-input, .lab-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 0.68rem;
}
.lab-input:focus, .lab-select:focus { outline: none; border-color: var(--gold-dim); }
.lab-input-sm {
  width: 3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.3rem;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 0.62rem;
  text-align: center;
}
.lab-label { display: block; font-family: var(--font-code); font-size: 0.55rem; color: var(--gold-dim); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 0.3rem; }
.lab-label-inline { font-family: var(--font-code); font-size: 0.6rem; color: var(--text-dim); display: inline-flex; align-items: center; gap: 0.3rem; }
.lab-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  color: var(--text);
  font-family: var(--font-code);
  font-size: 0.68rem;
  resize: vertical;
}
.lab-textarea:focus { outline: none; border-color: var(--gold-dim); }
.lab-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; padding: 0.6rem; }
.lab-sliders { padding: 0.6rem 0.8rem; display: flex; flex-direction: column; gap: 0.5rem; }
.lab-slider-label {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  font-family: var(--font-code);
  font-size: 0.58rem; color: var(--text-dim);
}
.lab-slider { flex: 1; min-width: 120px; accent-color: var(--gold); }
.lab-slider-sm { width: 80px; accent-color: var(--gold); }
.lab-slider-val {
  font-family: var(--font-code);
  font-size: 0.6rem; color: var(--gold);
  min-width: 3rem; text-align: right;
}

@media (max-width: 600px) {
  .lab-two-col { grid-template-columns: 1fr; }
}

/* Mobile: collapse margin notes inline */
@media (max-width: 1200px) {
  .margin-notes {
    position: static;
    width: auto;
    margin-top: 0.3rem;
  }
  .margin-add-btn {
    position: static;
    display: inline-flex;
    opacity: 0.5;
    margin-left: 0.3rem;
    vertical-align: middle;
  }
}
