/* ==============================================================================
   DSA LIVING DOCUMENTATION PORTAL — DESIGN SYSTEM & CYBER HUD STYLESHEET
   Vision 2500: Deep Space Liquid Glass, Fluent Mica, Holo 2050, Matrix Obsidian
   ============================================================================== */

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

/* -----------------------------------------------------------------------------
   1. ROOT VARIABLES & THEMES
   ----------------------------------------------------------------------------- */
:root {
  --topbar-height: 64px;
  --sidebar-width: 330px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --font-display: 'Outfit', 'Rajdhani', -apple-system, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --font-hud: 'Orbitron', 'Chakra Petch', sans-serif;
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 0.15s;
  --t-normal: 0.25s;
  --t-slow: 0.45s;
  --mx: 50vw;
  --my: 40vh;
}

/* THEME 1: DEEP SPACE LIQUID GLASS (Default) */
:root,
[data-theme="liquid"] {
  --bg-deep: #050813;
  --bg-subtle: #0a0f24;
  --bg-card: rgba(13, 20, 39, 0.65);
  --bg-card-hover: rgba(18, 28, 54, 0.8);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-border-glow: rgba(0, 242, 254, 0.35);
  --glass-blur: blur(24px) saturate(190%);
  --accent-cyan: #00f2fe;
  --accent-violet: #a855f7;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-blue: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --halo-glow: rgba(0, 242, 254, 0.15);
  --halo-aurora: rgba(168, 85, 247, 0.12);
  --code-bg: rgba(6, 10, 20, 0.85);
  --code-border: rgba(255, 255, 255, 0.06);
  --badge-bg: rgba(0, 242, 254, 0.12);
  --badge-text: #00f2fe;
  --scrollbar-thumb: rgba(255, 255, 255, 0.16);
  --scrollbar-thumb-hover: rgba(0, 242, 254, 0.5);
}

/* THEME 2: FLUENT AERO MICA (Crisp Light Frosted Paper) */
[data-theme="mica"] {
  --bg-deep: #f6f4ee;
  --bg-subtle: #eae6db;
  --bg-card: rgba(255, 255, 255, 0.78);
  --bg-card-hover: rgba(255, 255, 255, 0.92);
  --bg-card-border: rgba(30, 41, 59, 0.1);
  --bg-card-border-glow: rgba(30, 58, 138, 0.4);
  --glass-blur: blur(20px) saturate(140%);
  --accent-cyan: #0284c7;
  --accent-violet: #7c3aed;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-blue: #1e40af;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --halo-glow: rgba(2, 132, 199, 0.12);
  --halo-aurora: rgba(124, 58, 237, 0.08);
  --code-bg: #090e1a;
  --code-text: #f1f5f9;
  --code-border: rgba(15, 23, 42, 0.18);
  --badge-bg: rgba(2, 132, 199, 0.1);
  --badge-text: #0369a1;
  --scrollbar-thumb: rgba(15, 23, 42, 0.18);
  --scrollbar-thumb-hover: rgba(15, 23, 42, 0.4);
}

/* THEME 3: HOLO 2050 (Cyberpunk Terminal HUD) */
[data-theme="holo"] {
  --bg-deep: #03020a;
  --bg-subtle: #08061a;
  --bg-card: rgba(12, 10, 28, 0.75);
  --bg-card-hover: rgba(20, 16, 44, 0.88);
  --bg-card-border: rgba(77, 225, 255, 0.22);
  --bg-card-border-glow: #ffaa00;
  --glass-blur: blur(20px) saturate(220%);
  --accent-cyan: #4de1ff;
  --accent-violet: #ff4de1;
  --accent-emerald: #b2ff4d;
  --accent-amber: #ffaa00;
  --accent-rose: #ff2a6d;
  --accent-blue: #05d9e8;
  --text-main: #d8f4ff;
  --text-muted: #9ac8dd;
  --text-dim: #628ea4;
  --halo-glow: rgba(77, 225, 255, 0.18);
  --halo-aurora: rgba(255, 77, 225, 0.14);
  --code-bg: rgba(5, 4, 18, 0.95);
  --code-border: rgba(77, 225, 255, 0.18);
  --badge-bg: rgba(255, 170, 0, 0.14);
  --badge-text: #ffaa00;
  --scrollbar-thumb: rgba(77, 225, 255, 0.25);
  --scrollbar-thumb-hover: #ffaa00;
}

/* THEME 4: MATRIX OBSIDIAN (Pure OLED Deep Emerald) */
[data-theme="matrix"] {
  --bg-deep: #000000;
  --bg-subtle: #020b05;
  --bg-card: rgba(4, 18, 9, 0.75);
  --bg-card-hover: rgba(7, 28, 14, 0.88);
  --bg-card-border: rgba(16, 185, 129, 0.22);
  --bg-card-border-glow: #10b981;
  --glass-blur: blur(22px) saturate(180%);
  --accent-cyan: #34d399;
  --accent-violet: #10b981;
  --accent-emerald: #059669;
  --accent-amber: #f59e0b;
  --accent-rose: #ef4444;
  --accent-blue: #065f46;
  --text-main: #e6fced;
  --text-muted: #86efac;
  --text-dim: #4ade80;
  --halo-glow: rgba(16, 185, 129, 0.16);
  --halo-aurora: rgba(5, 150, 105, 0.12);
  --code-bg: rgba(2, 10, 4, 0.95);
  --code-border: rgba(16, 185, 129, 0.2);
  --badge-bg: rgba(16, 185, 129, 0.14);
  --badge-text: #34d399;
  --scrollbar-thumb: rgba(16, 185, 129, 0.25);
  --scrollbar-thumb-hover: #34d399;
}

/* -----------------------------------------------------------------------------
   2. GLOBAL RESET & FOUNDATIONAL INVARIANTS
   ----------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 12px);
  overflow-x: clip; /* CRITICAL: Must be clip to preserve position: sticky */
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-deep);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: clip; /* CRITICAL: Never overflow-x: hidden */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--t-slow) ease, color var(--t-normal) ease;
  position: relative;
}

/* -----------------------------------------------------------------------------
   3. AERO MICA HALO LIGHTING ENGINE
   ----------------------------------------------------------------------------- */
.canvas-ambient-halo {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.halo-orb-pointer {
  position: absolute;
  width: 700px;
  height: 700px;
  left: calc(var(--mx) - 350px);
  top: calc(var(--my) - 350px);
  background: radial-gradient(circle, var(--halo-glow) 0%, transparent 65%);
  filter: blur(50px);
  border-radius: 50%;
  transform: translate3d(0, 0, 0);
  will-change: left, top;
  transition: left 0.18s var(--ease-spring), top 0.18s var(--ease-spring);
  opacity: 0.85;
}

.halo-orb-aurora {
  position: absolute;
  width: 900px;
  height: 600px;
  top: 15%;
  right: -200px;
  background: radial-gradient(ellipse, var(--halo-aurora) 0%, transparent 70%);
  filter: blur(80px);
  border-radius: 50%;
  animation: auroraPulse 14s infinite alternate ease-in-out;
  opacity: 0.7;
}

@keyframes auroraPulse {
  0% { transform: scale(0.9) translate(0, 0); opacity: 0.5; }
  50% { transform: scale(1.15) translate(-60px, 40px); opacity: 0.85; }
  100% { transform: scale(1.0) translate(40px, -30px); opacity: 0.6; }
}

/* -----------------------------------------------------------------------------
   4. STICKY GLASS HEADER (TOP HUD)
   ----------------------------------------------------------------------------- */
.header-glass {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--bg-card-border);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  transition: border-color var(--t-normal) ease;
}

.header-left-cluster {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}

.brand-logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-hud);
  font-weight: 900;
  font-size: 1.1rem;
  color: #ffffff;
  box-shadow: 0 0 16px var(--halo-glow);
  flex-shrink: 0;
}

.brand-text-group {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
  background: linear-gradient(135deg, var(--text-main) 60%, var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.header-telemetry-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.telemetry-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.telemetry-chip .pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulseBeacon 2s infinite ease-in-out;
}

@keyframes pulseBeacon {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.telemetry-chip strong {
  color: var(--text-main);
  font-weight: 600;
}

.header-controls-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* SEARCH BUTTON (CMD+K) */
.hud-search-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

.hud-search-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--bg-card-border-glow);
  color: var(--text-main);
  box-shadow: 0 0 12px var(--halo-glow);
}

.hud-search-btn .kbd-shortcut {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-cyan);
}

/* THEME SELECTOR */
.theme-picker-group {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.theme-pill-btn {
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

.theme-pill-btn:hover {
  color: var(--text-main);
}

.theme-pill-btn.active {
  background: var(--accent-cyan);
  color: #040714;
  box-shadow: 0 0 10px var(--accent-cyan);
}

[data-theme="mica"] .theme-pill-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
}

[data-theme="holo"] .theme-pill-btn.active {
  background: var(--accent-amber);
  color: #03020a;
}

[data-theme="matrix"] .theme-pill-btn.active {
  background: var(--accent-emerald);
  color: #000000;
}

.hud-tool-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--t-fast) ease;
}

.hud-tool-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--bg-card-border-glow);
  color: var(--text-main);
}

.mobile-nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* -----------------------------------------------------------------------------
   5. LAYOUT CONTAINER & DRAGGABLE SPLITTER
   ----------------------------------------------------------------------------- */
.layout-container {
  display: flex;
  min-height: calc(100vh - var(--topbar-height));
  position: relative;
  overflow-x: clip; /* CRITICAL: Never overflow-x: hidden */
  z-index: 10;
}

/* BACKDROP FOR MOBILE DRAWER (Inside layout container for proper stacking context) */
.mobile-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 18, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s var(--ease-spring);
}

.mobile-drawer-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--bg-card-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex-shrink: 0;
  z-index: 30;
  transition: margin-left 0.28s var(--ease-spring), opacity 0.22s ease, visibility 0.28s ease, border-color var(--t-normal) ease;
}

/* SIDEBAR SEARCH & COLLAPSE ROW (ZEN COMMAND DECK) */
.sidebar-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.sidebar-search-row .sidebar-search-box {
  flex: 1;
  min-width: 0;
  position: relative;
}

.sidebar-collapse-pill,
.sidebar-close-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
  transition: all var(--t-fast) ease;
}

.sidebar-collapse-pill:hover,
.sidebar-close-btn:hover {
  background: rgba(0, 242, 254, 0.12);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.3);
  transform: scale(1.04);
}

/* HEADER DOCK TOGGLE BUTTON */
.sidebar-dock-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

@media (min-width: 1025px) {
  .sidebar-dock-toggle {
    display: inline-flex;
  }
}

.sidebar-dock-toggle:hover {
  background: rgba(0, 242, 254, 0.12);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
}

.sidebar-dock-toggle.active {
  color: var(--accent-cyan);
}

/* FLOATING RE-OPEN TAB WHEN SIDEBAR IS COLLAPSED */
.floating-sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(var(--topbar-height) + 14px);
  left: 14px;
  z-index: 45;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(13, 20, 39, 0.88);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-full);
  box-shadow: 0 4px 20px rgba(0, 242, 254, 0.25), 0 0 30px rgba(0, 0, 0, 0.6);
  color: var(--text-main);
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--t-normal) var(--ease-spring);
  animation: floatIn 0.22s var(--ease-spring);
}

.floating-sidebar-toggle:hover {
  transform: translateX(3px) scale(1.02);
  background: rgba(0, 242, 254, 0.15);
  border-color: #ffffff;
  color: #ffffff;
  box-shadow: 0 6px 25px rgba(0, 242, 254, 0.45);
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* COLLAPSED SIDEBAR BEHAVIOR (DESKTOP) */
@media (min-width: 1025px) {
  body.sidebar-collapsed .sidebar {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  body.sidebar-collapsed .sidebar-resizer {
    display: none !important;
  }

  body.sidebar-collapsed .content-area {
    padding-left: 68px;
    padding-right: 68px;
  }

  body.sidebar-collapsed .floating-sidebar-toggle {
    display: inline-flex;
  }
}

/* SIDEBAR RESIZER STANDARD */
.sidebar-resizer {
  width: 10px;
  margin-left: -5px;
  margin-right: -5px;
  cursor: col-resize;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  z-index: 35;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.sidebar-resizer::after {
  content: '';
  width: 2px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.2s var(--ease-spring);
}

.sidebar-resizer:hover::after,
.sidebar-resizer.is-resizing::after {
  height: 90px;
  width: 3px;
  background: var(--accent-cyan);
  box-shadow: 0 0 14px var(--accent-cyan);
}

body.resizing-sidebar {
  cursor: col-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

body.resizing-sidebar .sidebar {
  transition: none !important;
}

/* -----------------------------------------------------------------------------
   6. SIDEBAR INTERNAL NAVIGATION & 7-FAMILY FILTER
   ----------------------------------------------------------------------------- */
.sidebar-search-box {
  position: relative;
  width: 100%;
}

.sidebar-search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease;
}

.sidebar-search-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px var(--halo-glow);
}

.sidebar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

/* 7 FAMILY FILTER CHIPS WITH DYNAMIC COUNT BADGES */
.family-filter-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.family-filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.family-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.family-chip {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.76rem;
  cursor: pointer;
  transition: all var(--t-fast) ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.family-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--bg-card-border-glow);
}

.family-chip.active {
  background: var(--badge-bg);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  font-weight: 600;
  box-shadow: 0 0 10px var(--halo-glow);
}

/* UX HIGHLIGHT COUNT BADGE SUFFIX */
.family-count-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  transition: all var(--t-fast) ease;
}

.family-chip:hover .family-count-badge {
  background: rgba(0, 242, 254, 0.18);
  color: var(--accent-cyan);
}

.family-chip.active .family-count-badge {
  background: var(--accent-cyan);
  color: #040714;
}

/* TREE CONTROLS BAR (EXPAND/COLLAPSE IN SIDEBAR) */
.tree-controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.mini-tool-btn {
  flex: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--t-fast) ease;
  text-align: center;
}

.mini-tool-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--accent-cyan);
}

/* NAVIGATION TREE GROUPS */
.nav-tree-section-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
  margin-bottom: 2px;
}

.nav-tree-group {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 4px;
}

.nav-tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--t-fast) ease;
}

.nav-tree-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

.nav-tree-header.active-branch {
  border-left: 2px solid var(--accent-cyan);
  background: rgba(0, 242, 254, 0.06);
}

.tree-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.tree-chevron {
  font-size: 0.75rem;
  color: var(--text-dim);
  transition: transform 0.2s var(--ease-spring);
  flex-shrink: 0;
}

.nav-tree-group.expanded .tree-chevron {
  transform: rotate(90deg);
  color: var(--accent-cyan);
}

/* ZERO TRUNCATION INVARIANT */
.tree-title-text {
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-main);
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
}

.nav-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  flex-shrink: 0;
}

.nav-tree-children {
  display: none;
  flex-direction: column;
  padding-left: 24px;
  margin-top: 2px;
  border-left: 1px dashed var(--bg-card-border);
  margin-left: 14px;
}

.nav-tree-group.expanded .nav-tree-children {
  display: flex;
}

.nav-tree-link {
  display: block;
  padding: 5px 8px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 4px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  transition: all var(--t-fast) ease;
}

.nav-tree-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.nav-tree-link.active {
  color: var(--accent-cyan);
  font-weight: 600;
  background: var(--badge-bg);
}

/* -----------------------------------------------------------------------------
   7. MAIN CONTENT AREA & READING STAGE
   ----------------------------------------------------------------------------- */
.content-area {
  flex: 1;
  min-width: 0;
  padding: 32px 48px 100px;
  position: relative;
  z-index: 20;
  overflow-x: clip; /* CRITICAL */
}

.stage-wrapper {
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

/* -----------------------------------------------------------------------------
   8. MASTER COMMAND DECK (HERO, SIFT, FLOWCHART, TRIAGE)
   ----------------------------------------------------------------------------- */
.command-deck-hero {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 36px 32px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.command-deck-hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet), var(--accent-amber));
}

.hero-eyebrow-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-cyan);
  background: var(--badge-bg);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.hero-headline {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #ffffff 40%, var(--accent-cyan) 85%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="mica"] .hero-headline {
  background: linear-gradient(135deg, #0f172a 40%, var(--accent-blue) 85%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subdeck {
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  color: var(--text-muted);
  max-width: 820px;
  line-height: 1.6;
}

/* 3 PILLARS CONTAINER */
.three-pillars-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 8px;
}

.pillar-card {
  padding: 22px 20px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all var(--t-normal) ease;
}

.pillar-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--bg-card-border-glow);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--halo-glow);
}

.pillar-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-cyan);
}

.pillar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-main);
}

.pillar-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* -----------------------------------------------------------------------------
   9. INTERACTIVE SIFT METHOD FINDER WIDGET
   ----------------------------------------------------------------------------- */
.sift-interactive-panel {
  padding: 28px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.section-hud-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.25rem, 3vw, 1.6rem);
  color: var(--text-main);
}

.sift-simulator-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--bg-card-border);
}

.sift-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sift-input-label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-cyan);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sift-select {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

.sift-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px var(--halo-glow);
}

.sift-output-deck {
  padding: 20px;
  border-radius: var(--radius-md);
  background: rgba(0, 242, 254, 0.05);
  border: 1px solid var(--bg-card-border-glow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sift-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sift-matched-pattern {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--accent-cyan);
}

.sift-mantra-box {
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-muted);
  border-left: 3px solid var(--accent-cyan);
  padding-left: 12px;
}

/* -----------------------------------------------------------------------------
   10. ZOOMABLE MERMAID CANVAS ENGINE
   ----------------------------------------------------------------------------- */
.canvas-container {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin: 16px 0;
}

.canvas-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--bg-card-border);
}

.canvas-type-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.canvas-controls-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-tool-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

.canvas-tool-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-cyan);
}

.zoom-level-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-cyan);
  min-width: 44px;
  text-align: center;
}

.canvas-viewport {
  overflow: auto;
  padding: 32px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 240px;
  max-height: 640px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.canvas-viewport:active {
  cursor: grabbing;
}

.canvas-content-surface {
  transform-origin: center top;
  transition: transform 0.12s ease-out;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
  text-align: center;
  width: 100%;
  max-width: 100%;
}

/* CRITICAL SVG LAYOUT RULES (100% AUTO-FIT SPACE UTILIZATION) */
.mermaid {
  display: flex !important;
  justify-content: center !important;
  align-items: center !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 auto !important;
  overflow: visible !important;
}

.mermaid svg {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: 580px !important;
  object-fit: contain;
  margin: 0 auto;
}

.canvas-caption {
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.15);
  border-top: 1px solid var(--bg-card-border);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}

/* -----------------------------------------------------------------------------
   NATIVE TOP-LAYER FULLSCREEN THEATER MODAL (HTML5 <dialog>)
   Complies with Modern Web Guidance (prevent-page-scroll-under-modal-dialog)
   ----------------------------------------------------------------------------- */
dialog#theater-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(5, 8, 19, 0.96);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  z-index: 999999;
  display: none;
  flex-direction: column;
  overscroll-behavior: contain;
}

dialog#theater-modal[open] {
  display: flex;
}

dialog#theater-modal::backdrop {
  background: rgba(3, 5, 12, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  overflow: hidden;
  overscroll-behavior: contain;
  cursor: pointer;
}

body.theater-open {
  overflow: hidden !important;
}

.theater-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: rgba(10, 15, 30, 0.94);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.theater-title-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theater-icon {
  font-size: 1.3rem;
}

.theater-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: #f8fafc !important;
  margin: 0;
  letter-spacing: -0.01em;
}

.theater-controls-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theater-tool-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.45);
  color: #ffffff !important;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all var(--t-fast) ease;
}

[data-theme="mica"] .theater-tool-btn {
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

[data-theme="mica"] .floating-sidebar-toggle {
  background: rgba(255, 255, 255, 0.94);
  color: #0f172a;
  border-color: rgba(30, 41, 59, 0.25);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 0 10px rgba(14, 165, 233, 0.2);
}

[data-theme="mica"] .floating-sidebar-toggle:hover {
  background: #ffffff;
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  box-shadow: 0 6px 25px rgba(14, 165, 233, 0.3);
}

[data-theme="mica"] .sidebar-dock-toggle {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(30, 41, 59, 0.15);
  color: #475569;
}

[data-theme="mica"] .sidebar-dock-toggle:hover {
  background: rgba(14, 165, 233, 0.1);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

[data-theme="mica"] .sidebar-collapse-pill,
[data-theme="mica"] .sidebar-close-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(30, 41, 59, 0.15);
  color: #475569;
}

[data-theme="mica"] .sidebar-collapse-pill:hover,
[data-theme="mica"] .sidebar-close-btn:hover {
  background: rgba(14, 165, 233, 0.1);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(14, 165, 233, 0.25);
}

.theater-tool-btn:hover {
  background: rgba(0, 242, 254, 0.28);
  border-color: #00f2fe;
  color: #00f2fe !important;
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.6);
}

.theater-close-btn {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  background: rgba(244, 63, 94, 0.18);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fda4af;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  margin-left: 8px;
  transition: all var(--t-fast) ease;
}

.theater-close-btn:hover {
  background: rgba(244, 63, 94, 0.35);
  color: #ffffff;
  border-color: #fb7185;
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.5);
}

.theater-viewport {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  padding: 24px;
}

.theater-viewport:active {
  cursor: grabbing;
}

.theater-content-surface {
  transform-origin: center center;
  transition: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  border-radius: var(--radius-md);
  will-change: transform;
}

.theater-content-surface svg {
  display: block !important;
  max-width: none !important;
  max-height: none !important;
  overflow: visible !important;
}

.theater-content-surface svg text,
.theater-content-surface svg foreignObject,
.theater-content-surface svg span {
  user-select: text !important;
  -webkit-user-select: text !important;
  cursor: text;
}

/* -----------------------------------------------------------------------------
   11. 7 PATTERN FAMILIES RADAR & COMPLEXITY TRIAGE TABLE
   ----------------------------------------------------------------------------- */
.families-radar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.family-radar-card {
  padding: 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all var(--t-fast) ease;
}

.family-radar-card:hover {
  border-color: var(--bg-card-border-glow);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--halo-glow);
}

.family-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.family-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.family-gut-say {
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* TABLE TOUCH OVERFLOW CONTAINMENT (CRITICAL) */
.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
}

table {
  width: 100%;
  min-width: 580px; /* CRITICAL: Prevents columns from crushing */
  border-collapse: collapse;
  text-align: left;
}

th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-card-border);
  font-size: 0.88rem;
}

th {
  background: rgba(0, 0, 0, 0.2);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

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

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.badge-kill-mode {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-block;
}

.badge-pull-plug {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-block;
}

/* -----------------------------------------------------------------------------
   12. 10 INTERVIEW-KILLING MISTAKES GRID
   ----------------------------------------------------------------------------- */
.mistakes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.mistake-card {
  padding: 18px;
  border-radius: var(--radius-md);
  background: rgba(244, 63, 94, 0.04);
  border: 1px solid rgba(244, 63, 94, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mistake-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-rose);
  display: flex;
  align-items: center;
  gap: 8px;
}

.mistake-fix {
  font-size: 0.85rem;
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--accent-emerald);
}

/* -----------------------------------------------------------------------------
   READING CONTROLS TOOLBAR (EXPAND / COLLAPSE & FOCUS ACCORDION)
   ----------------------------------------------------------------------------- */
.reading-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 12px;
}

.mode-toggles-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast) ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--bg-card-border-glow);
}

.mode-btn.active {
  background: var(--badge-bg);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
  font-weight: 600;
  box-shadow: 0 0 12px var(--halo-glow);
}

/* -----------------------------------------------------------------------------
   DYNAMIC CHEVRONS ROTATION (CRITICAL UX REQUIREMENT)
   ----------------------------------------------------------------------------- */
.chapter-chevron,
.problem-chevron,
.tree-chevron {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-dim);
  transition: transform 0.22s var(--ease-spring), color 0.2s ease;
  transform: rotate(0deg); /* Points right ▶ when collapsed */
  flex-shrink: 0;
}

/* Rotate down ▼ when open */
.pattern-chapter:not(.is-collapsed) .chapter-chevron {
  transform: rotate(90deg);
  color: var(--accent-cyan);
}

.problem-card[open] > .problem-summary .problem-chevron,
.theory-details[open] > .theory-summary .problem-chevron {
  transform: rotate(90deg);
  color: var(--accent-cyan);
}

.nav-tree-group.expanded > .nav-tree-header .tree-chevron {
  transform: rotate(90deg);
  color: var(--accent-cyan);
}

/* -----------------------------------------------------------------------------
   13. PATTERN CHAPTERS & ACCORDION COLLAPSE
   ----------------------------------------------------------------------------- */
.pattern-chapter {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: border-color var(--t-fast) ease, box-shadow var(--t-normal) ease;
}

.pattern-chapter:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.pattern-chapter:not(.is-collapsed) {
  border-color: var(--bg-card-border-glow);
  box-shadow: 0 10px 32px var(--halo-glow);
}

/* Clickable Chapter Header Bar */
.chapter-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px;
  cursor: pointer;
  user-select: none;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid transparent;
  transition: background-color var(--t-fast) ease;
  gap: 16px;
}

.pattern-chapter:not(.is-collapsed) .chapter-header-bar {
  border-bottom-color: var(--bg-card-border);
  background: rgba(0, 0, 0, 0.2);
}

.chapter-header-bar:hover {
  background: rgba(255, 255, 255, 0.05);
}

.chapter-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.chapter-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  letter-spacing: -0.01em;
  color: var(--text-main);
  margin: 0;
}

.chapter-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.chapter-toggle-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  pointer-events: none; /* Inherits click from header */
}

/* Collapsible Content Body */
.chapter-content-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
}

.pattern-chapter.is-collapsed .chapter-content-body {
  display: none !important;
}

/* -----------------------------------------------------------------------------
   THEORY DETAILS & MARKDOWN STYLES
   ----------------------------------------------------------------------------- */
.theory-details {
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--bg-card-border);
  overflow: hidden;
}

.theory-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  background: rgba(255, 255, 255, 0.02);
  list-style: none;
}

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

.theory-summary:hover {
  background: rgba(255, 255, 255, 0.05);
}

.theory-body-wrapper {
  padding: 24px;
  border-top: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 0.94rem;
  line-height: 1.65;
}

/* MARKDOWN HEADERS & ELEMENTS */
.md-h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  color: var(--text-main);
  margin-top: 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--bg-card-border);
  padding-bottom: 6px;
}

.md-h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent-cyan);
  margin-top: 14px;
  margin-bottom: 4px;
}

.md-h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.0rem;
  color: var(--text-main);
  margin-top: 10px;
  margin-bottom: 4px;
}

.md-h5 {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--accent-violet);
  margin-top: 8px;
}

.md-p {
  margin: 6px 0;
  color: var(--text-main);
  line-height: 1.65;
}

.md-list, .md-list-ol {
  margin: 8px 0 8px 24px;
  color: var(--text-main);
  line-height: 1.6;
}

.md-list li, .md-list-ol li {
  margin-bottom: 4px;
}

.callout-glass {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: rgba(0, 242, 254, 0.05);
  border-left: 3px solid var(--accent-cyan);
  font-style: italic;
  color: var(--text-muted);
  margin: 12px 0;
}

.md-divider {
  border: none;
  border-top: 1px solid var(--bg-card-border);
  margin: 20px 0;
}

.eli5-frosted-card {
  padding: 20px;
  border-radius: var(--radius-md);
  background: rgba(0, 242, 254, 0.04);
  border: 1px solid rgba(0, 242, 254, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.eli5-label {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.eli5-body {
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.6;
}

/* PATTERN DNA MUSCLE SKELETON */
.dna-skeleton-box {
  border-radius: var(--radius-md);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  overflow: hidden;
}

.dna-skeleton-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid var(--code-border);
}

.dna-label {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-violet);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--t-fast) ease;
}

.copy-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-cyan);
}

.code-container {
  padding: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.code-container pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--code-text, #f1f5f9);
}

.code-container code {
  color: inherit;
}

/* -----------------------------------------------------------------------------
   14. PROBLEM ACCORDIONS & WALKTHROUGHS
   ----------------------------------------------------------------------------- */
.problems-catalog {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.problem-card {
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--bg-card-border);
  overflow: hidden;
  transition: border-color var(--t-fast) ease;
}

.problem-card[open] {
  border-color: var(--bg-card-border-glow);
  box-shadow: 0 4px 16px var(--halo-glow);
}

.problem-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  background: rgba(255, 255, 255, 0.02);
  list-style: none;
  transition: background-color var(--t-fast) ease;
}

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

.problem-summary:hover {
  background: rgba(255, 255, 255, 0.05);
}

.problem-left-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.problem-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: normal;
  word-break: break-word;
}

.difficulty-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.diff-easy {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.diff-medium {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
}

.diff-hard {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
}

.problem-details-body {
  padding: 24px;
  border-top: 1px solid var(--bg-card-border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* -----------------------------------------------------------------------------
   15. KATEX MATHEMATICAL TYPESETTING CONTAINMENT
   ----------------------------------------------------------------------------- */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  padding: 8px 0;
}

/* -----------------------------------------------------------------------------
   16. CMD+K FUZZY SEARCH MODAL
   ----------------------------------------------------------------------------- */
.search-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 14, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 3000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  opacity: 0;
  transition: opacity 0.2s var(--ease-spring);
}

.search-modal-backdrop.show {
  display: flex;
  opacity: 1;
}

.search-dialog-panel {
  width: min(92vw, 680px);
  max-height: 72vh;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--bg-card-border-glow);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-dialog-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--bg-card-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-dialog-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 1.1rem;
  outline: none;
}

.search-dialog-results {
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--t-fast) ease;
}

.search-result-item:hover,
.search-result-item.selected {
  background: rgba(0, 242, 254, 0.08);
  border-color: var(--accent-cyan);
}

.search-result-item .item-title {
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.92rem;
}

.search-result-item .item-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.search-dialog-footer {
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.25);
  border-top: 1px solid var(--bg-card-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* -----------------------------------------------------------------------------
   17. MOBILE COMMUTE GADGET VIEWPORT RESPONSIVENESS (<= 1024px)
   ----------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .header-telemetry-cluster {
    display: none;
  }

  .mobile-nav-toggle {
    display: flex;
  }

  .sidebar-dock-toggle {
    display: none !important;
  }

  .floating-sidebar-toggle {
    display: none !important;
  }

  .sidebar-resizer {
    display: none !important;
  }

  .mobile-drawer-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 360px);
    height: 100dvh;
    z-index: 1200;
    background: var(--bg-deep);
    backdrop-filter: blur(32px) saturate(200%);
    box-shadow: 16px 0 60px rgba(0, 0, 0, 0.95);
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease-spring);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .content-area {
    padding: 24px 20px 80px;
  }
}

@media (max-width: 640px) {
  .header-glass {
    padding: 0 16px;
  }

  .theme-picker-group {
    display: none; /* Accessible in mobile drawer */
  }

  .command-deck-hero {
    padding: 24px 20px;
  }

  .three-pillars-grid {
    grid-template-columns: 1fr;
  }

  .content-area {
    padding: 16px 12px 60px;
  }
}

/* -----------------------------------------------------------------------------
   PRECISION NAVIGATION FLASH FOCUS
   ----------------------------------------------------------------------------- */
@keyframes flashGlow {
  0% { box-shadow: 0 0 0px var(--accent-cyan); border-color: var(--accent-cyan); }
  25% { box-shadow: 0 0 35px var(--accent-cyan), inset 0 0 15px rgba(0, 242, 254, 0.15); border-color: var(--accent-cyan); }
  100% { box-shadow: none; }
}

.flash-focus {
  animation: flashGlow 1.8s var(--ease-spring) forwards !important;
}
