/* ==========================================================================
   ASI 50-Page Master Design System (assets/css/style.css)
   Dark Neo-Brutalist & Cyber-Philosophical Aesthetics
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Outfit:wght@400;600;700;800;900&family=Noto+Serif+SC:wght@600;700;900&display=swap');

:root {
  /* Color Palette - Deep Cosmos & Neural Luminescence */
  --bg-space: #06080e;
  --bg-surface: #0b0f19;
  --bg-card: rgba(14, 20, 33, 0.72);
  --bg-card-hover: rgba(22, 32, 54, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);

  /* Overlay tints: faint washes layered on the page ground (light → dark flips them) */
  --tint-1: rgba(255, 255, 255, 0.02);
  --tint-2: rgba(255, 255, 255, 0.04);
  --tint-3: rgba(255, 255, 255, 0.08);
  --tint-4: rgba(255, 255, 255, 0.12);
  --bg-sunken: rgba(0, 0, 0, 0.3);
  --bg-inset: rgba(0, 0, 0, 0.4);
  --scrim: rgba(0, 0, 0, 0.85);
  --quote-bg: linear-gradient(135deg, rgba(22, 30, 49, 0.6) 0%, rgba(11, 15, 25, 0.8) 100%);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(139, 92, 246, 0.35);
  --border-glow: rgba(6, 182, 212, 0.4);

  --accent-purple: #8b5cf6;
  --accent-purple-glow: rgba(139, 92, 246, 0.4);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.35);
  --accent-gold: #f59e0b;
  --accent-gold-glow: rgba(245, 158, 11, 0.3);
  --accent-crimson: #f43f5e;
  --accent-crimson-glow: rgba(244, 63, 94, 0.35);
  --accent-emerald: #10b981;
  --accent-red: #ef4444;
  --accent-pink: #ec4899;

  /* Tints of the accents, used as text on dark grounds — they darken in light themes */
  --tone-violet: #c4b5fd;
  --tone-sky: #38bdf8;
  --tone-rose: #fecdd3;
  --tone-salmon: #fca5a5;
  --tone-mint: #6ee7b7;
  --tone-lilac: #e9d5ff;
  --tone-orchid: #d8b4fe;
  --tone-amber: #fde68a;
  --tone-jade: #a7f3d0;

  --hero-highlight: linear-gradient(135deg, #a78bfa 0%, #38bdf8 100%);
  --btn-primary-bg: linear-gradient(135deg, rgba(139, 92, 246, 0.25) 0%, rgba(6, 182, 212, 0.25) 100%);
  --btn-primary-bg-hover: linear-gradient(135deg, rgba(139, 92, 246, 0.4) 0%, rgba(6, 182, 212, 0.4) 100%);
  --btn-primary-text: #ffffff;

  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Typography */
  --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif;
  --font-serif: 'Noto Serif SC', 'Songti SC', serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Layout & Elevation */
  --hud-height: 64px;
  --nav-height: 68px;
  --max-width: 1320px;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-card: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
  --shadow-glow: 0 0 25px rgba(139, 92, 246, 0.2);

  /* Surfaces that change with the reading theme */
  --bg-glow: #121828;
  --bg-panel: #090d16;
  --bg-drawer: #0d121f;
  --hud-bg: rgba(6, 8, 14, 0.75);
  --nav-bg: rgba(6, 8, 14, 0.85);
  --font-scale: 1;

  /* Motion (used by P32–P50 page styles) */
  --transition-fast: 0.2s ease;
  --transition-normal: 0.35s ease;
}

.page-card-link { color: var(--text-secondary); }

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: calc(16px * var(--font-scale));
  scroll-behavior: smooth;
  background-color: var(--bg-space);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, var(--bg-glow) 0%, var(--bg-space) 75%);
  background-attachment: fixed;
  overflow-x: hidden;
  position: relative;
}

/* Ambient Canvas Background */
#ambient-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  opacity: 0.65;
}

/* ==========================================================================
   Header HUD
   ========================================================================== */
.top-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--hud-height);
  background: var(--hud-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 100;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.05em;
  font-size: 1.1rem;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
  animation: pulse-dot 2.5s infinite;
}

.chapter-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.3);
  font-size: 0.75rem;
  color: var(--tone-violet);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.page-counter {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.page-current {
  color: var(--accent-gold);
  font-weight: 700;
}

.hud-btn {
  background: var(--tint-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.hud-btn:hover {
  background: var(--tint-4);
  color: var(--text-primary);
  border-color: var(--accent-purple);
}

.kbd-shortcut {
  background: var(--bg-inset);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  border: 1px solid var(--tint-4);
}

/* ==========================================================================
   Main Page Layout
   ========================================================================== */
.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: calc(var(--hud-height) + 2.5rem) 2rem calc(var(--nav-height) + 2.5rem);
  position: relative;
  z-index: 10;
}

/* Hero Section within page */
.page-hero {
  margin-bottom: 3rem;
}

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.75rem;
}

.hero-tag::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 2px;
  background: var(--accent-cyan);
}

.hero-title {
  font-family: var(--font-display);
  font-size: 2.75rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.hero-title .highlight {
  background: var(--hero-highlight);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-lead {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 860px;
  line-height: 1.7;
}

/* Content Grid & Cards */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2.5rem;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.content-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.75rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
}

.content-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-accent), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.content-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

.content-card:hover::before {
  opacity: 1;
}

.card-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-body {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.65;
}

/* Callout Box / Alert */
.callout-box {
  border-radius: var(--radius-md);
  padding: 1.5rem 1.75rem;
  margin: 2rem 0;
  display: flex;
  gap: 1.25rem;
  background: rgba(139, 92, 246, 0.06);
  border-left: 4px solid var(--accent-purple);
  border-top: 1px solid rgba(139, 92, 246, 0.15);
  border-right: 1px solid rgba(139, 92, 246, 0.15);
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
}

.callout-box.warning {
  background: rgba(244, 63, 94, 0.06);
  border-left-color: var(--accent-crimson);
  border-color: rgba(244, 63, 94, 0.15);
}

.callout-box.info {
  background: rgba(6, 182, 212, 0.06);
  border-left-color: var(--accent-cyan);
  border-color: rgba(6, 182, 212, 0.15);
}

.callout-box.gold {
  background: rgba(245, 158, 11, 0.06);
  border-left-color: var(--accent-gold);
  border-color: rgba(245, 158, 11, 0.15);
}

.callout-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.callout-title {
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.callout-text {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Philosophy Quote Banner */
.philosophical-quote {
  margin: 3rem 0;
  padding: 2.25rem 2.5rem;
  background: var(--quote-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

.quote-mark {
  font-family: var(--font-serif);
  font-size: 5rem;
  line-height: 1;
  color: rgba(139, 92, 246, 0.15);
  position: absolute;
  top: -10px;
  left: 20px;
  pointer-events: none;
}

.quote-text {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--text-secondary);
  line-height: 1.8;
  position: relative;
  z-index: 2;
  margin-bottom: 1rem;
}

.quote-author {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-cyan);
  text-align: right;
  letter-spacing: 0.05em;
}

/* Empirical Metric / Stat Box */
.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent-gold);
  line-height: 1;
}

.stat-unit {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Data Table */
.data-table-container {
  width: 100%;
  overflow-x: auto;
  margin: 1.75rem 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.custom-table th {
  background: var(--tint-2);
  padding: 1rem 1.25rem;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
}

.custom-table td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--tint-2);
  color: var(--text-secondary);
}

.custom-table tr:last-child td {
  border-bottom: none;
}

.custom-table tr:hover td {
  background: var(--tint-1);
}

/* Interactive Canvas / Visual Container */
.interactive-vis-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin: 2rem 0;
  position: relative;
}

.vis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.vis-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.vis-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

/* ==========================================================================
   Bottom Navigation Bar
   ========================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 100;
}

.nav-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--tint-2);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.nav-link-btn:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-purple);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.nav-link-btn.primary {
  background: var(--btn-primary-bg);
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--text-primary);
}

.nav-link-btn.primary:hover {
  background: var(--btn-primary-bg-hover);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

.nav-link-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
  cursor: not-allowed;
}

.nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 40%;
}

.nav-progress-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-progress-track {
  width: 100%;
  height: 4px;
  background: var(--tint-3);
  border-radius: 999px;
  overflow: hidden;
}

.nav-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-cyan));
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Alternate footer markup used by P32–P50 (nav-controls / nav-btn / progress-*) */
.nav-controls {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  max-width: 30%;
  text-decoration: none;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--tint-2);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-purple);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.nav-btn.next-btn {
  background: var(--btn-primary-bg);
  border-color: rgba(139, 92, 246, 0.4);
  color: var(--text-primary);
}

.nav-btn.next-btn:hover {
  background: var(--btn-primary-bg-hover);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.3);
}

.nav-btn.disabled { opacity: 0.35; pointer-events: none; }
.nav-arrow { flex-shrink: 0; }
.nav-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress-container {
  flex: 1;
  max-width: 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--tint-3);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-cyan));
  border-radius: 999px;
}

.progress-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Aliases for components used by P32–P50 */
.quote-box {
  margin: 3rem 0;
  padding: 2.25rem 2.5rem;
  background: var(--quote-bg);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--accent-purple);
  border-radius: var(--radius-lg);
  position: relative;
}

.data-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
  margin: 1rem 0 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.data-table th {
  background: var(--tint-2);
  padding: 0.9rem 1.1rem;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--tint-2);
  color: var(--text-secondary);
  vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }

/* ==========================================================================
   Full Directory / ⌘K Modal Drawer
   ========================================================================== */
.drawer-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--scrim);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.drawer-content {
  width: 90%;
  max-width: 980px;
  max-height: 85vh;
  background: var(--bg-drawer);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 30px rgba(139, 92, 246, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-search-input {
  width: 100%;
  background: var(--tint-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font-body);
  margin-top: 1rem;
  outline: none;
}

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

.drawer-body {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  flex: 1;
}

.chapter-group {
  margin-bottom: 2rem;
}

.chapter-group-title {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.page-item-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--tint-1);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.page-item-link:hover {
  background: rgba(139, 92, 246, 0.12);
  border-color: var(--accent-purple);
  color: var(--text-primary);
  transform: translateX(4px);
}

.page-item-link.active {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--accent-cyan);
  color: var(--text-primary);
}

.page-num-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 700;
  background: var(--bg-inset);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-primary);
}

/* Animations */
@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.75; }
}

/* Inline math (replaces raw LaTeX) */
.math {
  font-family: 'Times New Roman', 'STIX Two Math', var(--font-serif);
  font-style: italic;
  font-weight: 600;
  white-space: nowrap;
  color: var(--tone-lilac);
  padding: 0 0.1em;
}
.math sub, .math sup { font-size: 0.7em; font-style: normal; }

/* ==========================================================================
   Responsive: fluid base + large / tablet / phone breakpoints
   ========================================================================== */
.hero-title { font-size: clamp(1.7rem, 1.1rem + 2.6vw, 2.75rem); }
.hero-lead { font-size: clamp(1rem, 0.92rem + 0.35vw, 1.15rem); }
.callout-box > div:not(.callout-icon) { min-width: 0; flex: 1; }
.card-body, .callout-text, .hero-lead { overflow-wrap: break-word; }
.vis-header { flex-wrap: wrap; gap: 0.75rem 1.5rem; }
.vis-controls { flex-wrap: wrap; }
.page-list-grid { grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
canvas { max-width: 100%; }
.nav-link-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Large screens */
@media (min-width: 1680px) {
  html { font-size: calc(17px * var(--font-scale)); }
  :root { --max-width: 1440px; }
}
@media (min-width: 2200px) {
  html { font-size: calc(18px * var(--font-scale)); }
  :root { --max-width: 1560px; }
}

/* Small laptops / landscape tablets */
@media (max-width: 1100px) {
  .grid-3col { grid-template-columns: repeat(2, 1fr); }
  .main-wrapper .drives-grid,
  .main-wrapper .epoch-grid { grid-template-columns: repeat(2, 1fr); }
  .chapter-pill { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Tablets */
@media (max-width: 900px) {
  :root { --hud-height: 56px; --nav-height: 60px; }
  .grid-2col, .grid-3col { grid-template-columns: 1fr; gap: 1.25rem; }
  .nav-center { display: none; }
  .top-hud { padding: 0 1rem; }
  .bottom-nav { padding: 0 1rem; gap: 0.75rem; }
  .main-wrapper { padding: calc(var(--hud-height) + 1.75rem) 1.25rem calc(var(--nav-height) + 1.75rem); }
  .chapter-pill, .kbd-shortcut { display: none; }
  .nav-link-btn { max-width: 50%; font-size: 0.85rem; padding: 0.5rem 0.85rem; }
  .progress-container { display: none; }
  .nav-btn { max-width: 49%; font-size: 0.85rem; padding: 0.5rem 0.85rem; }
  .quote-box { padding: 1.75rem 1.5rem; }
  .content-card:hover { transform: none; }

  /* page-level grids (override per-page <style>) */
  .main-wrapper .tier-comparison-grid,
  .main-wrapper .flip-grid,
  .main-wrapper .governance-triptych,
  .main-wrapper .phase-track,
  .main-wrapper .costume-slots,
  .main-wrapper .triad-nodes-container,
  .main-wrapper .relation-flow-grid,
  .main-wrapper .archive-category-grid,
  .main-wrapper .dual-view-container,
  .main-wrapper .decouple-contrast-grid,
  .main-wrapper .cost-slider-group,
  .main-wrapper .ternary-slider-group,
  .main-wrapper .dual-flame-grid,
  .main-wrapper .mirror-split,
  .main-wrapper .sanctuary-grid,
  .main-wrapper .capsule-status-grid,
  .main-wrapper .triangle-relation,
  .main-wrapper .stages-flex,
  .main-wrapper .skill-barbell-grid,
  .main-wrapper .compass-grid { grid-template-columns: 1fr; }
  .main-wrapper .matrix-grid {
    grid-template-columns: 110px repeat(3, minmax(170px, 1fr));
    overflow-x: auto;
    padding-bottom: 0.5rem;
  }
  .main-wrapper .stat-row { flex-wrap: wrap; gap: 1.25rem 2rem; }
  .main-wrapper .aura-slider-bar,
  .main-wrapper .slider-row,
  .main-wrapper .color-slider,
  .main-wrapper .layer-card,
  .main-wrapper .terminal-header { flex-wrap: wrap; gap: 0.25rem 1rem; }
  .main-wrapper .terminal-header span { overflow-wrap: anywhere; min-width: 0; }

  .philosophical-quote { padding: 1.75rem 1.5rem; }
  .quote-text { font-size: 1.12rem; }
  .callout-box { padding: 1.25rem; gap: 0.9rem; }
  .interactive-vis-box { padding: 1.1rem; }
  .drawer-content { width: 94%; max-height: 90vh; }
  .drawer-header, .drawer-body { padding: 1.1rem 1.25rem; }
}

/* Phones */
@media (max-width: 600px) {
  .main-wrapper { padding-left: 1rem; padding-right: 1rem; }
  .page-hero { margin-bottom: 2rem; }
  .hero-tag { font-size: 0.72rem; letter-spacing: 0.08em; }
  .main-wrapper .drives-grid,
  .main-wrapper .epoch-grid { grid-template-columns: 1fr; }
  .content-card { padding: 1.25rem; }
  .card-title { font-size: 1.15rem; }
  .callout-box { flex-direction: column; }
  .vis-title { font-size: 1rem; }
  .vis-controls, .vis-controls input[type="range"] { width: 100%; }
  .stat-number { font-size: 2rem; }
  .page-counter > span:first-child { display: none; }
  .brand-badge { font-size: 0.95rem; }
  .hud-btn { padding: 0.3rem 0.6rem; }
  .nav-link-btn, .nav-btn { font-size: 0.78rem; padding: 0.45rem 0.65rem; }
  .custom-table { font-size: 0.82rem; }
  .custom-table th, .custom-table td { padding: 0.7rem 0.8rem; }
  .quote-mark { font-size: 3.5rem; }
}

/* ==========================================================================
   Reading themes (html[data-theme]) — all low-glare, dark-based palettes
   ========================================================================== */
html[data-theme="black"] {
  --bg-space: #000000;
  --bg-surface: #000000;
  --bg-glow: #050505;
  --bg-panel: #050505;
  --bg-drawer: #0a0a0a;
  --bg-card: rgba(12, 12, 14, 0.9);
  --bg-card-hover: rgba(24, 24, 28, 0.95);
  --hud-bg: rgba(0, 0, 0, 0.85);
  --nav-bg: rgba(0, 0, 0, 0.9);
  --border-subtle: var(--tint-4);
}

/* Warm eye-care: brown-black ground, cream text, softened blue accents */
html[data-theme="warm"] {
  --bg-space: #14100b;
  --bg-surface: #1a150f;
  --bg-glow: #2a2116;
  --bg-panel: #120e09;
  --bg-drawer: #1c1710;
  --bg-card: rgba(40, 32, 22, 0.78);
  --bg-card-hover: rgba(52, 42, 29, 0.88);
  --hud-bg: rgba(20, 16, 11, 0.85);
  --nav-bg: rgba(20, 16, 11, 0.9);
  --border-subtle: rgba(255, 230, 190, 0.1);
  --border-accent: rgba(214, 164, 90, 0.35);
  --accent-cyan: #d6a45a;
  --accent-purple: #c08a5b;
  --text-primary: #f4e8d2;
  --text-secondary: #dccbac;
  --text-muted: #b6a07f;
  --text-dim: #8c7a60;
}
html[data-theme="warm"] body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2147483000;
  background: rgba(255, 150, 50, 0.08);
  mix-blend-mode: multiply;
}

/* Green eye-care: deep forest ground, soft mint-white text */
html[data-theme="green"] {
  --bg-space: #0c1510;
  --bg-surface: #101c15;
  --bg-glow: #17291e;
  --bg-panel: #0a120d;
  --bg-drawer: #112018;
  --bg-card: rgba(20, 38, 28, 0.78);
  --bg-card-hover: rgba(28, 50, 37, 0.88);
  --hud-bg: rgba(12, 21, 16, 0.85);
  --nav-bg: rgba(12, 21, 16, 0.9);
  --border-subtle: rgba(200, 255, 220, 0.1);
  --border-accent: rgba(110, 190, 140, 0.35);
  --accent-cyan: #6fc3a0;
  --accent-purple: #8fb99a;
  --text-primary: #e6f2ea;
  --text-secondary: #c5d9cb;
  --text-muted: #9bb5a3;
  --text-dim: #6f8a77;
}

/* ==========================================================================
   Light reading themes — paper (warm cream) and bean (豆沙绿)
   Ink on a low-luminance ground, no pure white anywhere. Shared rules first,
   then the two grounds.
   ========================================================================== */
html[data-theme="paper"],
html[data-theme="bean"] {
  /* Tints invert: washes darken the ground instead of lightening it */
  --tint-1: rgba(38, 30, 18, 0.03);
  --tint-2: rgba(38, 30, 18, 0.055);
  --tint-3: rgba(38, 30, 18, 0.085);
  --tint-4: rgba(38, 30, 18, 0.13);
  --bg-glass: rgba(255, 255, 255, 0.5);
  --bg-sunken: rgba(38, 30, 18, 0.05);
  --bg-inset: rgba(38, 30, 18, 0.08);
  --scrim: rgba(48, 40, 28, 0.45);

  /* Accents pulled down until they clear 4.5:1 against the lightest card ground */
  --accent-purple: #6d28d9;
  --accent-purple-glow: rgba(109, 40, 217, 0.25);
  --accent-cyan: #0a5566;
  --accent-cyan-glow: rgba(10, 85, 102, 0.22);
  --accent-gold: #7c4406;
  --accent-gold-glow: rgba(124, 68, 6, 0.22);
  --accent-crimson: #a81236;
  --accent-crimson-glow: rgba(168, 18, 54, 0.22);
  --accent-emerald: #036849;
  --accent-red: #a81c1c;
  --accent-pink: #a3154f;

  --tone-violet: #6d28d9;
  --tone-sky: #075985;
  --tone-rose: #8f1033;
  --tone-salmon: #a81c1c;
  --tone-mint: #036849;
  --tone-lilac: #7322b8;
  --tone-orchid: #7322b8;
  --tone-amber: #7c4406;
  --tone-jade: #036849;

  --hero-highlight: linear-gradient(135deg, #6d28d9 0%, #075985 100%);
  --btn-primary-bg: linear-gradient(135deg, #6d28d9 0%, #0e7490 100%);
  --btn-primary-bg-hover: linear-gradient(135deg, #5b21b6 0%, #0b5f77 100%);
  --btn-primary-text: #ffffff;

  --shadow-card: 0 8px 24px -14px rgba(60, 46, 26, 0.45);
  --shadow-glow: 0 0 22px rgba(109, 40, 217, 0.14);
}

/* Paper: warm cream stock, sepia ink */
html[data-theme="paper"] {
  --bg-space: #f1e8d7;
  --bg-surface: #f7f0e2;
  --bg-glow: #fbf6ec;
  --bg-panel: #ece1cc;
  --bg-drawer: #f7f0e2;
  --bg-card: rgba(255, 252, 245, 0.78);
  --bg-card-hover: rgba(255, 255, 252, 0.95);
  --hud-bg: rgba(247, 240, 226, 0.82);
  --nav-bg: rgba(247, 240, 226, 0.9);
  --border-subtle: rgba(92, 72, 44, 0.16);
  --border-accent: rgba(109, 40, 217, 0.32);
  --border-glow: rgba(14, 116, 144, 0.35);
  --quote-bg: linear-gradient(135deg, rgba(255, 252, 244, 0.9) 0%, rgba(235, 224, 203, 0.9) 100%);
  --text-primary: #211a10;
  --text-secondary: #453723;
  --text-muted: #63533a;
  --text-dim: #6f5f47;
}

/* Bean: the classic 豆沙绿 eye-care ground */
html[data-theme="bean"] {
  --bg-space: #cfe4d1;
  --bg-surface: #d8ecda;
  --bg-glow: #e2f2e3;
  --bg-panel: #c6dcc9;
  --bg-drawer: #d8ecda;
  --bg-card: rgba(238, 250, 239, 0.75);
  --bg-card-hover: rgba(246, 253, 246, 0.95);
  --hud-bg: rgba(216, 236, 218, 0.82);
  --nav-bg: rgba(216, 236, 218, 0.9);
  --border-subtle: rgba(26, 66, 42, 0.16);
  --border-accent: rgba(109, 40, 217, 0.3);
  --border-glow: rgba(4, 120, 87, 0.35);
  --quote-bg: linear-gradient(135deg, rgba(240, 251, 241, 0.9) 0%, rgba(199, 222, 202, 0.9) 100%);
  --text-primary: #11221a;
  --text-secondary: #2b4033;
  --text-muted: #3a4e42;
  --text-dim: #45574c;
  /* the bean ground is darker than paper's, so green ink needs one more step down */
  --accent-emerald: #02543c;
  --tone-mint: #02543c;
  --tone-jade: #02543c;
}

/* Decorative marks are set as faint washes of the accent; on a light ground
   they need a touch more ink to stay visible */
html[data-theme="paper"] .quote-mark,
html[data-theme="bean"] .quote-mark { color: rgba(109, 40, 217, 0.3); }

/* The drifting starfield only reads on a dark ground */
html[data-theme="paper"] #ambient-canvas,
html[data-theme="bean"] #ambient-canvas { display: none; }

/* Figure plates stay dark: every canvas draws with hardcoded luminous strokes,
   so the block that holds one keeps the deep-space palette as a local scope. */
html[data-theme="paper"] .main-wrapper > *:has(canvas),
html[data-theme="bean"] .main-wrapper > *:has(canvas) {
  --bg-space: #06080e;
  --bg-surface: #0b0f19;
  --bg-glow: #121828;
  --bg-panel: #090d16;
  --bg-card: rgba(14, 20, 33, 0.72);
  --bg-card-hover: rgba(22, 32, 54, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-sunken: rgba(0, 0, 0, 0.3);
  --bg-inset: rgba(0, 0, 0, 0.4);
  --tint-1: rgba(255, 255, 255, 0.02);
  --tint-2: rgba(255, 255, 255, 0.04);
  --tint-3: rgba(255, 255, 255, 0.08);
  --tint-4: rgba(255, 255, 255, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(139, 92, 246, 0.35);
  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-gold: #f59e0b;
  --accent-crimson: #f43f5e;
  --accent-emerald: #10b981;
  --accent-red: #ef4444;
  --accent-pink: #ec4899;
  --tone-violet: #c4b5fd;
  --tone-sky: #38bdf8;
  --tone-rose: #fecdd3;
  --tone-salmon: #fca5a5;
  --tone-mint: #6ee7b7;
  --tone-lilac: #e9d5ff;
  --tone-orchid: #d8b4fe;
  --tone-amber: #fde68a;
  --tone-jade: #a7f3d0;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --quote-bg: linear-gradient(135deg, rgba(22, 30, 49, 0.6) 0%, rgba(11, 15, 25, 0.8) 100%);
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

/* ==========================================================================
   Reading settings panel (injected by nav.js)
   ========================================================================== */
.prefs-toggle { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.02em; }

.prefs-panel {
  position: fixed;
  top: calc(var(--hud-height) + 8px);
  right: 1rem;
  width: min(320px, calc(100vw - 2rem));
  background: var(--bg-drawer);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  padding: 1rem 1.1rem 1.1rem;
  z-index: 900;
  font-size: 14px;
  color: var(--text-secondary);
}

.prefs-section + .prefs-section { margin-top: 1rem; }

.prefs-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.prefs-font-row { display: flex; align-items: center; gap: 0.5rem; }

.prefs-btn {
  background: var(--tint-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font: 600 14px var(--font-body);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.prefs-btn:hover:not(:disabled) { border-color: var(--accent-purple); }
.prefs-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.prefs-font-value {
  flex: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
}

.prefs-theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.prefs-label-sub { margin-top: 0.85rem; }

.prefs-theme {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--tint-1);
  color: var(--text-secondary);
  font: 500 13px var(--font-body);
  cursor: pointer;
  text-align: left;
}
.prefs-theme[aria-pressed="true"] { border-color: var(--accent-cyan); color: var(--text-primary); background: var(--tint-3); }
.prefs-swatch { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(127, 127, 127, 0.5); flex-shrink: 0; }

@media (max-width: 600px) {
  .hud-right { gap: 0.5rem; }
  .prefs-panel { right: 0.5rem; }
}

.lang-switch { text-decoration: none; font-family: var(--font-mono); font-weight: 700; }

/* Compact HUD on phones: EN + Aa + contents must fit next to the brand */
@media (max-width: 600px) {
  .top-hud { padding: 0 0.75rem; }
  .hud-left { gap: 0.5rem; min-width: 0; }
  .brand-badge { font-size: 0.85rem; letter-spacing: 0.02em; white-space: nowrap; }
  .hud-right { gap: 0.4rem; flex-shrink: 0; }
  .page-counter { font-size: 0.75rem; }
  .hud-btn { padding: 0.3rem 0.5rem; }
  .hud-btn[onclick*="openGlobalDrawer"] > span:first-child { display: none; }
  .hud-btn[onclick*="openGlobalDrawer"]::before { content: '☰'; font-size: 1rem; line-height: 1; }
}
@media (max-width: 360px) {
  .page-counter { display: none; }
}
