/* ==============================================================================
 * PolyTuring Master Documentation Portal — Cosmic Liquid Glass & Acrylic Aero
 * Theme: Year 2500 Liquid Glass / Acrylic Aero Engineering Notebook
 * ============================================================================== */

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

:root {
  --bg-space: #06080e;
  --bg-deep: #0b0f19;
  --bg-surface: rgba(15, 23, 42, 0.65);
  --bg-surface-hover: rgba(30, 41, 59, 0.75);
  --bg-card: rgba(18, 26, 47, 0.55);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-border-glow: rgba(0, 242, 254, 0.25);
  
  --glass-blur: blur(24px) saturate(190%);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.45);
  --glass-highlight: inset 0 1px 1px 0 rgba(255, 255, 255, 0.12);

  --accent-cyan: #00f2fe;
  --accent-blue: #38bdf8;
  --accent-violet: #a855f7;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-display: 'Outfit', sans-serif;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --topbar-height: 64px;
  --sidebar-width: 320px;
  --sidebar-min-width: 240px;
  --sidebar-max-width: 560px;
  --toc-width: 250px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  background-color: var(--bg-space);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.7;
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

/* Ambient Cosmic Background Mesh */
.ambient-mesh {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 15% 15%, rgba(0, 242, 254, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 25%, rgba(168, 85, 247, 0.09) 0%, transparent 45%),
    radial-gradient(circle at 50% 85%, rgba(16, 185, 129, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(56, 189, 248, 0.07) 0%, transparent 40%);
  filter: blur(60px);
}

.ambient-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.8;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

/* Top Progress Bar */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-violet), var(--accent-emerald));
  z-index: 1000;
  transition: width 0.1s ease-out;
  box-shadow: 0 0 10px var(--accent-cyan);
}

/* Navigation Header */
.header-glass {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  width: 100%;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--bg-card-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

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

.mobile-nav-toggle {
  display: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.mobile-nav-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  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-display);
  font-weight: 800;
  font-size: 1.1rem;
  color: #000;
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.4);
}

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

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

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  line-height: 1.2;
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(0, 242, 254, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 242, 254, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 240px;
}

.search-trigger:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--accent-cyan);
  color: var(--text-main);
  box-shadow: 0 0 12px rgba(0, 242, 254, 0.2);
}

.shortcut-kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.2), rgba(168, 85, 247, 0.2));
  border-color: rgba(0, 242, 254, 0.4);
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.35), rgba(168, 85, 247, 0.35));
  border-color: var(--accent-cyan);
  box-shadow: 0 0 16px rgba(0, 242, 254, 0.3);
}

/* Master Layout */
.layout-container {
  display: flex;
  position: relative;
  z-index: 10;
  max-width: 1760px;
  margin: 0 auto;
  padding-top: var(--topbar-height);
  overflow-x: clip;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Sidebar Navigation — Calibrated Hierarchical Tree */
.sidebar {
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
  overflow-y: auto;
  padding: 20px 14px 40px 18px;
  border-right: 1px solid var(--bg-card-border);
  background: rgba(8, 12, 22, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1), padding 0.3s ease;
}

.sidebar.rail-collapsed {
  width: 68px;
  padding: 20px 8px 40px 8px;
}

.sidebar.rail-collapsed .nav-group-title,
.sidebar.rail-collapsed .tree-title-text,
.sidebar.rail-collapsed .tree-chevron,
.sidebar.rail-collapsed .nav-tree-children,
.sidebar.rail-collapsed .sidebar-header-actions,
.sidebar.rail-collapsed .nav-pill {
  display: none !important;
}

.sidebar.rail-collapsed .nav-tree-header {
  justify-content: center;
  padding: 10px 0;
}

/* Interactive Sidebar Resizer Splitter */
.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: 44px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.sidebar-resizer:hover,
.sidebar-resizer.is-resizing {
  background: rgba(0, 242, 254, 0.08);
}

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

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

/* Mobile Drawer Base Classes (Desktop Hidden) */
.mobile-drawer-header {
  display: none;
}

.mobile-drawer-tools {
  display: none;
}

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

.sidebar-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 16px 4px;
  border-bottom: 1px solid var(--bg-card-border);
  margin-bottom: 12px;
}

.sidebar-rail-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  transition: all 0.15s ease;
}

.sidebar-rail-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: var(--accent-cyan);
}

.sidebar-quick-actions {
  display: flex;
  gap: 6px;
}

.sidebar-quick-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.sidebar-quick-btn:hover {
  color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.04);
}

.nav-group-title {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
  margin: 18px 0 6px 8px;
}

/* Collapsible Tree Group */
.nav-tree-group {
  margin-bottom: 6px;
}

.nav-tree-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  position: relative;
  gap: 8px;
}

.nav-tree-header:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-tree-header.active-branch {
  background: rgba(0, 242, 254, 0.08);
  border: 1px solid rgba(0, 242, 254, 0.25);
  color: var(--accent-cyan);
}

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

.tree-chevron {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--text-dim);
  margin-top: 3px;
  flex-shrink: 0;
}

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

.tree-icon {
  font-size: 0.95rem;
  margin-top: 1px;
  flex-shrink: 0;
}

.tree-title-text {
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  font-size: 0.85rem;
  color: var(--text-main);
}

/* Tree Children Sub-branches */
.nav-tree-children {
  display: none;
  padding-left: 20px;
  margin-left: 14px;
  border-left: 1px dashed rgba(255, 255, 255, 0.12);
  margin-top: 3px;
  margin-bottom: 8px;
}

.nav-tree-group.expanded .nav-tree-children {
  display: block;
  animation: slideDownFade 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDownFade {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.nav-tree-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 2px;
  position: relative;
}

.nav-tree-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(2px);
}

.nav-tree-link.active {
  color: var(--accent-cyan);
  font-weight: 600;
  background: rgba(0, 242, 254, 0.09);
}

.nav-tree-link.active::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 50%;
  transform: translateY(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
}

.nav-pill {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  margin-top: 2px;
}
.pill-rust { background: rgba(244, 63, 94, 0.18); color: #fb7185; border: 1px solid rgba(244, 63, 94, 0.3); }
.pill-go { background: rgba(56, 189, 248, 0.18); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.3); }
.pill-core { background: rgba(168, 85, 247, 0.18); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.3); }

/* Main Reading Pane */
.content-area {
  flex: 1;
  min-width: 0;
  padding: 32px 48px 80px 48px;
}

/* Table of Contents (Right Sticky) */
.toc-sidebar {
  width: var(--toc-width);
  height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
  overflow-y: auto;
  padding: 32px 20px 40px 16px;
  border-left: 1px solid var(--bg-card-border);
  font-size: 0.82rem;
  flex-shrink: 0;
}

.toc-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 14px;
}

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

.toc-item {
  margin-bottom: 8px;
}

.toc-link {
  color: var(--text-muted);
  text-decoration: none;
  display: block;
  line-height: 1.4;
  transition: all 0.15s ease;
}

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

.toc-link.active {
  color: var(--accent-cyan);
  font-weight: 600;
}

/* Hero Section */
.hero-glass {
  background: linear-gradient(135deg, rgba(16, 24, 46, 0.8), rgba(20, 16, 38, 0.65));
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  margin-bottom: 48px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  backdrop-filter: var(--glass-blur);
}

.hero-glass::before {
  content: '';
  position: absolute;
  top: -80px;
  right: -80px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 242, 254, 0.2) 0%, transparent 70%);
  pointer-events: none;
}

.hero-tagline {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-tagline::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
}

.hero-heading {
  font-family: var(--font-display);
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #ffffff 40%, #94a3b8 90%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-description {
  font-size: 1.12rem;
  color: var(--text-muted);
  max-width: 850px;
  line-height: 1.7;
  margin-bottom: 28px;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 32px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  transition: all 0.2s ease;
}

.stat-card:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--bg-card-border-glow);
  transform: translateY(-2px);
}

.stat-val {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stat-val span {
  font-size: 0.9rem;
  color: var(--accent-cyan);
  font-weight: 600;
}

.stat-lbl {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

/* Chapter Sections */
.chapter-section {
  margin-bottom: 64px;
  scroll-margin-top: calc(var(--topbar-height) + 24px);
}

.chapter-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(168, 85, 247, 0.12);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: var(--accent-violet);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.chapter-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--bg-card-border);
}

.section-h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin: 36px 0 16px 0;
  scroll-margin-top: calc(var(--topbar-height) + 20px);
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent-blue);
  margin: 24px 0 12px 0;
}

/* Glass Cards & Grids */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 20px 0;
}

.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 24px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.glass-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--bg-card-border-glow);
  transform: translateY(-3px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 242, 254, 0.12);
}

.glass-card h4 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.glass-card p {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* Callout Alerts */
.callout {
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 24px 0;
  background: rgba(15, 23, 42, 0.7);
  border-left: 4px solid var(--accent-cyan);
  border-top: 1px solid var(--bg-card-border);
  border-right: 1px solid var(--bg-card-border);
  border-bottom: 1px solid var(--bg-card-border);
  box-shadow: var(--glass-shadow);
}

.callout.callout-theory {
  border-left-color: var(--accent-violet);
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.07), rgba(15, 23, 42, 0.8));
}

.callout.callout-math {
  border-left-color: var(--accent-cyan);
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.07), rgba(15, 23, 42, 0.8));
}

.callout.callout-warning {
  border-left-color: var(--accent-amber);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.07), rgba(15, 23, 42, 0.8));
}

.callout.callout-success {
  border-left-color: var(--accent-emerald);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.07), rgba(15, 23, 42, 0.8));
}

.callout-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.callout-theory .callout-header { color: var(--accent-violet); }
.callout-math .callout-header { color: var(--accent-cyan); }
.callout-warning .callout-header { color: var(--accent-amber); }
.callout-success .callout-header { color: var(--accent-emerald); }

.callout-body {
  font-size: 0.94rem;
  color: var(--text-main);
  line-height: 1.65;
}

/* Interactive Code Snippets */
.code-container {
  border-radius: var(--radius-md);
  background: #090d16;
  border: 1px solid var(--bg-card-border);
  margin: 20px 0;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--bg-card-border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.copy-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: var(--accent-cyan);
}

pre {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
  color: #e2e8f0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  color: var(--accent-cyan);
}

pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  margin: 24px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
  background: rgba(11, 15, 25, 0.5);
  box-shadow: var(--glass-shadow);
}

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

th {
  background: rgba(255, 255, 255, 0.04);
  padding: 14px 18px;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid var(--bg-card-border);
}

td {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-main);
}

/* Content View Controls (Accordion / Reading Modes) */
.content-view-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  margin-bottom: 32px;
  backdrop-filter: var(--glass-blur);
}

.mode-btn-group {
  display: flex;
  gap: 8px;
}

.view-mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--bg-card-border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-mode-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.view-mode-btn.active {
  background: rgba(0, 242, 254, 0.12);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

/* Collapsible Chapter Sections */
.chapter-section {
  margin-bottom: 40px;
  scroll-margin-top: calc(var(--topbar-height) + 24px);
  background: rgba(11, 16, 28, 0.4);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  box-shadow: var(--glass-shadow);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter-section:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.chapter-section.is-collapsed {
  margin-bottom: 16px;
}

.chapter-header-trigger {
  padding: 24px 32px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, rgba(16, 24, 44, 0.6), rgba(20, 16, 36, 0.4));
  border-bottom: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.chapter-section:not(.is-collapsed) .chapter-header-trigger {
  border-bottom: 1px solid var(--bg-card-border);
}

.chapter-header-trigger:hover {
  background: linear-gradient(135deg, rgba(20, 30, 56, 0.8), rgba(26, 20, 48, 0.6));
}

.chapter-toggle-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-toggle-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter-section:not(.is-collapsed) .chapter-toggle-icon {
  transform: rotate(180deg);
  color: var(--accent-cyan);
  border-color: rgba(0, 242, 254, 0.3);
  background: rgba(0, 242, 254, 0.1);
}

.chapter-body {
  padding: 32px 36px 40px 36px;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.chapter-section.is-collapsed .chapter-body {
  display: none;
}

/* ─── Zoomable Visual Canvas & Fullscreen Theater ────────────────────────────── */
.canvas-container {
  position: relative;
  background: rgba(9, 13, 24, 0.85);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  margin: 28px 0;
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

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

.canvas-type-tag {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.canvas-type-tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
}

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

.canvas-tool-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  border-radius: 6px;
  height: 30px;
  min-width: 30px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: nowrap;
}

.canvas-tool-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

.canvas-tool-btn.fullscreen-btn {
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.12), rgba(168, 85, 247, 0.12));
  border-color: rgba(0, 242, 254, 0.35);
  color: #fff;
  padding: 0 14px;
  font-weight: 600;
}

.canvas-tool-btn.fullscreen-btn:hover {
  background: linear-gradient(135deg, rgba(0, 242, 254, 0.25), rgba(168, 85, 247, 0.25));
  border-color: var(--accent-cyan);
  box-shadow: 0 0 14px rgba(0, 242, 254, 0.35);
}

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

.canvas-viewport {
  overflow: auto;
  padding: 28px 24px;
  display: block;
  text-align: center;
  min-height: 220px;
  max-height: 600px;
  cursor: grab;
  user-select: none;
}

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

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

.canvas-viewport img,
.theater-surface img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--bg-card-border);
  -webkit-user-drag: none;
  user-select: none;
}

.canvas-caption {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 10px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
}

/* Fullscreen Theater Modal */
#theater-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, 0.96);
  backdrop-filter: blur(35px);
  -webkit-backdrop-filter: blur(35px);
  z-index: 2000;
  flex-direction: column;
}

#theater-modal.theater-open {
  display: flex;
}

.theater-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--bg-card-border);
  background: rgba(11, 15, 25, 0.9);
}

.theater-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}

.theater-body-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  cursor: grab;
}

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

.theater-surface {
  transform-origin: center center;
  transition: transform 0.1s ease-out;
  display: inline-block;
  text-align: center;
  max-width: 95%;
}

/* Mermaid SVG Readability & Natural Scale Overrides */
.mermaid {
  display: inline-block !important;
  margin: 0 auto !important;
  text-align: center !important;
  overflow: visible !important;
}

.mermaid svg {
  display: inline-block !important;
  max-width: 100% !important;
  height: auto !important;
}

.mermaid svg text, .mermaid svg .label {
  font-family: var(--font-mono) !important;
  font-size: 13.5px !important;
  font-weight: 600 !important;
  fill: #f8fafc !important;
}

.mermaid .node rect, 
.mermaid .node circle, 
.mermaid .node polygon {
  stroke-width: 2px !important;
  stroke: var(--accent-cyan) !important;
  fill: rgba(15, 23, 42, 0.92) !important;
}

.mermaid .edgePath path {
  stroke: var(--accent-violet) !important;
  stroke-width: 2px !important;
}

.mermaid .edgeLabel {
  background: rgba(11, 15, 25, 0.88) !important;
  color: var(--accent-cyan) !important;
  font-size: 12px !important;
}

/* Visual Flash Focus Animation for Bi-Directional Nav */
@keyframes flashFocusGlow {
  0% { box-shadow: 0 0 0 0 rgba(0, 242, 254, 0); border-color: var(--bg-card-border); }
  25% { box-shadow: 0 0 28px 4px rgba(0, 242, 254, 0.45); border-color: var(--accent-cyan); }
  100% { box-shadow: 0 0 0 0 rgba(0, 242, 254, 0); border-color: var(--bg-card-border); }
}

.flash-focus {
  animation: flashFocusGlow 1.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* KaTeX Mathematics Dark Glass Styling */
.katex {
  font-size: 1.05em !important;
  color: #f8fafc;
}

.katex-display {
  margin: 18px 0 !important;
  padding: 14px 22px !important;
  background: rgba(0, 242, 254, 0.05) !important;
  border: 1px solid rgba(0, 242, 254, 0.18) !important;
  border-radius: var(--radius-sm) !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.katex-display .katex {
  color: var(--accent-cyan);
}

/* Interactive Simulator Widget */
.interactive-widget {
  background: linear-gradient(135deg, rgba(16, 25, 48, 0.85), rgba(24, 18, 45, 0.8));
  border: 1px solid rgba(0, 242, 254, 0.3);
  border-radius: var(--radius-lg);
  padding: 32px;
  margin: 36px 0;
  box-shadow: 0 0 30px rgba(0, 242, 254, 0.12);
  position: relative;
}

.widget-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.widget-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.simulator-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.control-item {
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.control-item:hover {
  border-color: rgba(0, 242, 254, 0.35);
  box-shadow: 0 6px 22px rgba(0, 242, 254, 0.08);
}

.control-item .control-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.control-item .control-value {
  font-family: var(--font-mono);
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

.control-item input[type="range"] {
  width: 100%;
  accent-color: var(--accent-cyan);
  cursor: pointer;
  margin-top: auto;
}

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

.res-metric {
  text-align: center;
}

.res-number {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 800;
}

.res-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.sla-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 6px;
}
.sla-pass { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.sla-fail { background: rgba(244, 63, 94, 0.2); color: #fb7185; border: 1px solid rgba(244, 63, 94, 0.4); }

/* Global Search Modal */
.search-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 100px;
}

.search-modal.open {
  display: flex;
}

.search-box {
  width: 100%;
  max-width: 680px;
  background: #0f172a;
  border: 1px solid rgba(0, 242, 254, 0.4);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 40px rgba(0, 242, 254, 0.25);
  overflow: hidden;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--bg-card-border);
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 1.1rem;
  font-family: var(--font-sans);
}

.search-results-list {
  max-height: 400px;
  overflow-y: auto;
  padding: 12px;
}

.search-result-item {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  display: block;
  text-decoration: none;
  color: var(--text-main);
  transition: all 0.15s ease;
}

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

.result-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.result-snippet {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Chapter Pager */
.chapter-pager {
  display: flex;
  justify-content: space-between;
  margin-top: 60px;
  padding-top: 24px;
  border-top: 1px solid var(--bg-card-border);
}

.pager-btn {
  display: flex;
  flex-direction: column;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--bg-card-border);
  text-decoration: none;
  color: var(--text-main);
  transition: all 0.2s ease;
  min-width: 200px;
}

.pager-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
}

.pager-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pager-title {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  margin-top: 4px;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .toc-sidebar {
    display: none;
  }
}

@media (max-width: 1024px) {
  .mobile-nav-toggle {
    display: flex;
  }
  
  .sidebar-resizer {
    display: none !important;
  }

  .mobile-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 6, 12, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

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

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 360px);
    height: 100dvh;
    z-index: 1200;
    background: #090e1a;
    backdrop-filter: blur(32px) saturate(200%);
    -webkit-backdrop-filter: blur(32px) saturate(200%);
    border-right: 1px solid rgba(0, 242, 254, 0.35);
    box-shadow: 16px 0 60px rgba(0, 0, 0, 0.95);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 16px 16px 40px 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

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

  .mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--bg-card-border);
    margin-bottom: 14px;
  }

  .mobile-drawer-close {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--bg-card-border);
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .mobile-drawer-close:hover {
    background: rgba(244, 63, 94, 0.2);
    color: var(--accent-rose);
    border-color: rgba(244, 63, 94, 0.4);
  }

  .mobile-drawer-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
  }

  .mobile-tool-link {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
  }

  .mobile-tool-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
  }

  .content-area {
    padding: 24px 24px 60px 24px;
  }
}

@media (max-width: 768px) {
  :root {
    --topbar-height: 58px;
  }

  .header-glass {
    padding: 0 14px;
    gap: 8px;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .brand-badge {
    display: none;
  }

  .search-trigger {
    min-width: auto;
    padding: 6px 12px;
  }

  .search-trigger-text {
    display: none;
  }

  .header-actions {
    display: none;
  }

  /* Anti-clobbering layout & overflow containment */
  html, body {
    overflow-x: clip;
    width: 100%;
  }

  .layout-container {
    width: 100%;
    max-width: 100vw;
    overflow-x: clip;
  }

  .content-area {
    padding: 16px 12px 60px 12px;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: clip;
  }

  .hero-glass {
    padding: 22px 16px;
    margin-bottom: 28px;
  }

  .hero-tagline {
    font-size: 0.74rem;
    letter-spacing: 0.06em;
  }

  .hero-heading {
    font-size: clamp(1.6rem, 5.5vw, 2.2rem);
    line-height: 1.2;
  }

  .hero-description {
    font-size: 0.96rem;
    line-height: 1.6;
    margin-bottom: 18px;
  }

  .hero-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 12px 14px;
  }

  .stat-val {
    font-size: 1.45rem;
  }

  .chapter-title {
    font-size: clamp(1.25rem, 4.2vw, 1.75rem);
    word-break: break-word;
  }

  .chapter-meta {
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 0.78rem;
  }

  .section-h2 {
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    word-break: break-word;
  }

  .content-view-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
  }

  .content-view-controls > span {
    display: none;
  }

  .mode-btn-group {
    width: 100%;
    display: flex;
    gap: 6px;
  }

  .view-mode-btn {
    flex: 1;
    justify-content: center;
    font-size: 0.75rem;
    padding: 6px 8px;
    text-align: center;
  }

  .table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 16px 0;
  }

  table {
    min-width: 520px;
    font-size: 0.85rem;
  }

  .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    padding: 8px 0;
    font-size: 0.95em;
  }

  .code-container, .code-content, pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.8rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .canvas-header-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
  }

  .canvas-controls-group {
    width: 100%;
    justify-content: space-between;
  }

  .canvas-viewport {
    max-height: 480px;
    padding: 16px 12px;
  }

  .simulator-controls {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .simulator-results {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 14px;
  }

  .chapter-pager {
    flex-direction: column;
    gap: 12px;
  }

  .pager-btn {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 480px) {
  .brand-sub {
    display: none;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

  .simulator-results {
    grid-template-columns: 1fr;
  }

  .view-mode-btn {
    font-size: 0.7rem;
    padding: 5px 6px;
  }
}
