/* ═══════════════════════════════════════════════════
   LUMINA STATS : MLP NOTES
   Glassmorphism · Plus Jakarta Sans · Pill shapes
   Full Light & Dark theme · Collapsible sidebar
═══════════════════════════════════════════════════ */


/* ── DESIGN TOKENS: LIGHT ───────────────────────── */
:root {
  /* Backgrounds */
  --bg:              #f0f4ff;
  --surface:         #ffffff;
  --surface-lo:      #eff4ff;
  --surface-med:     #e5eeff;
  --surface-hi:      #dce9ff;
  --surface-dim:     #cbdbf5;

  /* Text */
  --text:            #0b1c30;
  --text-muted:      #494552;
  --outline:         #7a7583;
  --outline-dim:     #cac4d4;

  /* Primary : Lavender */
  --primary:         #674bb5;
  --on-primary:      #ffffff;
  --primary-ctr:     #e8ddff;
  --on-primary-ctr:  #3c1989;
  --primary-accent:  #a78bfa;

  /* Secondary : Mint */
  --secondary:       #006c4b;
  --on-secondary:    #ffffff;
  --secondary-ctr:   #c8fce5;
  --on-secondary-ctr:#003826;

  /* Tertiary : Coral */
  --tertiary:        #a93349;
  --on-tertiary:     #ffffff;
  --tertiary-ctr:    #ffdadc;
  --on-tertiary-ctr: #6e0022;

  /* Component surfaces */
  --sidebar-bg:      rgba(255,255,255,0.68);
  --sidebar-border:  rgba(255,255,255,0.72);
  --card-bg:         rgba(255,255,255,0.78);
  --card-border:     rgba(255,255,255,0.88);
  --topbar-bg:       rgba(240,244,255,0.88);

  /* Shadows */
  --shadow-card:     0 4px 28px rgba(103,75,181,.10), 0 1px 6px rgba(103,75,181,.06);
  --shadow-sidebar:  3px 0 28px rgba(103,75,181,.12);
  --shadow-pop:      0 8px 40px rgba(103,75,181,.18);

  /* Radii */
  --r-xs:   4px;
  --r-sm:   8px;
  --r-md:   14px;
  --r-lg:   20px;
  --r-xl:   28px;
  --r-2xl:  36px;
  --r-pill: 9999px;

  /* Sidebar layout */
  --rail-w:      64px;
  --text-w:      224px;
  --sidebar-w:   288px;   /* rail + text */

  /* Code block */
  --code-bg:     #f4f2ff;
  --code-text:   #442170;
  --code-border: rgba(255,255,255,.06);
}

/* ── DESIGN TOKENS: DARK ────────────────────────── */
[data-theme="dark"] {
  --bg:              #181e27;
  --surface:         #223a1d;
  --surface-lo:      #1c263b;
  --surface-med:     #1e2637;
  --surface-hi:      #27324a;
  --surface-dim:     #0f1421;

  --text:            #e2eaff;
  --text-muted:      #8d9bbf;
  --outline:         #4e5b7a;
  --outline-dim:     #252f47;

  --primary:         #9d82f7;
  --on-primary:      #17004e;
  --primary-ctr:     #291460;
  --on-primary-ctr:  #cebdff;
  --primary-accent:  #7c5fd0;

  --secondary:       #3dd4a0;
  --on-secondary:    #002114;
  --secondary-ctr:   #003828;
  --on-secondary-ctr:#68fcbf;

  --tertiary:        #ff8fa3;
  --on-tertiary:     #400010;
  --tertiary-ctr:    #1e0009;
  --on-tertiary-ctr: #ffb2b9;

  --sidebar-bg:      rgba(24, 32, 51, 0.97);
  --sidebar-border:  rgba(36,50,84,0.55);
  --card-bg:         rgba(20,27,45,0.84);
  --card-border:     rgba(36,50,84,0.50);
  --topbar-bg:       rgba(11,15,25,0.92);

  --shadow-card:     0 4px 28px rgba(0,0,0,.45), 0 1px 4px rgba(0,0,0,.35);
  --shadow-sidebar:  3px 0 28px rgba(0,0,0,.50);
  --shadow-pop:      0 8px 40px rgba(0,0,0,.60);

  --code-bg:         #0d1117;
  --code-text:       #c9d1d9;
  --code-border:     rgba(255,255,255,.04);
}

/* ── RESET ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  scroll-behavior: smooth;
  /* Offset anchors so sticky mobile topbar (56px) doesn't cover them */
  scroll-padding-top: 70px;
}
body {
  font-family: 'Plus Jakarta Sans', 'Poppins', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
  /* Remove 300ms tap delay on mobile */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.material-symbols-outlined {
  vertical-align: middle;
  user-select: none;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR : rail (always) + text panel (toggleable)
═══════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  height: 100vh;
  display: flex;
  flex-direction: row;
  z-index: 100;
}

/* ── Icon rail ──────────────────────────────────── */
.sidebar-rail {
  width: var(--rail-w);
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 16px;
  gap: 2px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: var(--shadow-sidebar);
  transition: background 0.3s;
  overflow: hidden;
}

.rail-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--r-md);
  transition: background 0.18s, color 0.18s;
  flex-shrink: 0;
}
.rail-btn:hover { background: var(--surface-med); color: var(--primary); }

.rail-sep {
  height: 1px;
  width: 32px;
  background: var(--outline-dim);
  opacity: 0.6;
  margin: 5px 0;
  flex-shrink: 0;
}

.rail-groups {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  width: 100%;
  padding: 2px 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.rail-groups::-webkit-scrollbar { display: none; }

.rail-group-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--r-md);
  transition: background 0.18s, color 0.18s;
  position: relative;
  flex-shrink: 0;
}
.rail-group-btn:hover { background: var(--surface-med); color: var(--primary); }
.rail-group-btn.active {
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
}
[data-theme="dark"] .rail-group-btn.active {
  background: var(--primary-ctr);
  color: var(--primary);
}

/* Tooltip on rail icon hover */
.rail-tooltip {
  display: none;
  position: absolute;
  left: calc(100% + 10px);
  top: 50%; transform: translateY(-50%);
  background: var(--surface-hi);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--outline-dim);
  pointer-events: none;
  z-index: 200;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.rail-group-btn:hover .rail-tooltip { display: block; }

/* ── Text panel ─────────────────────────────────── */
.sidebar-text {
  width: var(--text-w);
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border-right: 1px solid var(--sidebar-border);
  overflow: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--outline-dim) transparent;
  transition: width 0.28s cubic-bezier(.4,0,.2,1),
              padding 0.28s cubic-bezier(.4,0,.2,1);
}
.sidebar-text::-webkit-scrollbar { width: 3px; }
.sidebar-text::-webkit-scrollbar-thumb {
  background: var(--outline-dim);
  border-radius: 99px;
}

body.sidebar-collapsed .sidebar-text {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 14px;
  flex-shrink: 0;
}
.brand-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-accent) 100%);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-family: 'Sniglet', 'Plus Jakarta Sans', sans-serif;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 10px rgba(103,75,181,.40);
  flex-shrink: 0;
}
.brand-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  line-height: 1.2;
}
.brand-sub {
  font-size: 10px;
  font-weight: 600;
  color: var(--outline);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.text-sep {
  height: 1px;
  background: var(--outline-dim);
  opacity: 0.55;
  margin: 2px 4px 10px;
  flex-shrink: 0;
}

/* Side nav */
.side-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.side-nav .nav-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--outline);
  padding: 12px 10px 5px;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.side-nav li a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--r-pill);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}
.side-nav li a .nav-icon {
  font-size: 17px;
  flex-shrink: 0;
  color: var(--outline);
  transition: color 0.15s;
}
.side-nav li a .nav-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.side-nav li a:hover {
  background: var(--surface-lo);
  color: var(--primary);
}
.side-nav li a:hover .nav-icon { color: var(--primary); }
.side-nav li a.active {
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
  font-weight: 600;
}
.side-nav li a.active .nav-icon { color: var(--primary); }

/* ─── Mobile backdrop ───────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,14,24,.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 99;
}
.sidebar-backdrop.active { display: block; }

/* Minimum touch target on all clickable elements */
.rail-btn, .rail-group-btn, .icon-btn, .mobile-menu-btn,
.page-nav-btn, .copy-btn {
  min-width: 44px;
  min-height: 44px;
}

/* ═══════════════════════════════════════════════════
   SHELL (content to the right of sidebar)
═══════════════════════════════════════════════════ */
.shell {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.28s cubic-bezier(.4,0,.2,1);
}
body.sidebar-collapsed .shell {
  margin-left: var(--rail-w);
}

/* ── Top bar ───────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  height: 60px;
  background: var(--topbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--outline-dim);
  transition: background 0.3s;
}

.mobile-menu-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  width: 38px; height: 38px;
  align-items: center; justify-content: center;
  border-radius: var(--r-md);
  transition: background 0.15s;
}
.mobile-menu-btn:hover { background: var(--surface-med); }

.topbar-crumb {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: var(--surface-lo);
  border : none;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-width: 150px;
}
.search-pill:hover { background: var(--surface); }
.search-hint {
  font-size: 13px;
  color: var(--outline);
  font-weight: 500;
  white-space: nowrap;
}

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--r-md);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-med); color: var(--primary); }

/* ── Content row ───────────────────────────────── */
.content-row {
  display: flex;
  flex: 1;
}

/* ── Article ───────────────────────────────────── */
.article {
  flex: 1;
  padding: 36px 40px 72px;
  min-width: 0;
}

.article-card {
  background: var(--card-bg);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-radius: var(--r-2xl);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-card);
  padding: 44px 50px;
  min-height: 500px;
  transition: background 0.3s, border-color 0.3s;
}

/* Loading */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 300px;
  color: var(--outline);
  font-size: 15px;
}
.spin { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════
   MARKDOWN CONTENT
═══════════════════════════════════════════════════ */

#contentRenderer h1 {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--text);
  margin-top: 0;
  margin-bottom: 16px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--surface-hi);
}

#contentRenderer h2 {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  margin-top: 44px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#contentRenderer h2::before {
  content: '';
  display: inline-block;
  width: 4px; height: 20px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-accent) 100%);
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

#contentRenderer h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 28px;
  margin-bottom: 9px;
}

#contentRenderer h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 20px;
  margin-bottom: 7px;
}

#contentRenderer p {
  font-size: 16px;
  line-height: 1.78;
  color: var(--text-muted);
  margin-bottom: 14px;
}

#contentRenderer ul,
#contentRenderer ol {
  padding-left: 22px;
  margin-bottom: 14px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.78;
}
#contentRenderer li { margin-bottom: 5px; }
#contentRenderer ul li::marker { color: var(--primary); }
#contentRenderer ol li::marker { color: var(--primary); font-weight: 700; }

#contentRenderer strong { font-weight: 700; color: var(--text); }
#contentRenderer em { color: var(--primary); font-style: italic; }

/* Inline code */
#contentRenderer code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(103,75,181,.18);
  /* Break long identifiers inside inline code on narrow screens */
  word-break: break-all;
  overflow-wrap: anywhere;
}

/* Code blocks */
#contentRenderer pre {
  background: var(--code-bg);
  border-radius: var(--r-lg);
  padding: 22px 26px;
  overflow-x: auto;
  margin: 20px 0;
  box-shadow: 0 6px 24px rgba(0,0,0,.28);
  border: 1px solid var(--code-border);
  position: relative;
}
#contentRenderer pre code {
  background: transparent;
  color: var(--code-text);
  padding: 0; border: none;
  font-size: 13px;
  line-height: 1.7;
}

/* Copy button — icon-only, no bg or border */
.copy-btn {
  position: absolute; top: 10px; right: 10px;
  background: none;
  border: none;
  color: rgba(68,33,112,.38);
  border-radius: var(--r-sm);
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: color .15s;
  z-index: 2;
}
.copy-btn:hover { color: rgba(68,33,112,.82); }

[data-theme="dark"] .copy-btn       { color: rgba(255,255,255,.35); }
[data-theme="dark"] .copy-btn:hover { color: rgba(255,255,255,.85); }

/* Blockquotes : key insight / pen-and-paper */
#contentRenderer blockquote {
  margin: 36px 0;
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--primary-ctr) 0%, rgba(232,221,255,.3) 100%);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
#contentRenderer blockquote p {
  color: var(--on-primary-ctr);
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.78;
}
#contentRenderer blockquote strong { color: var(--primary); }

/* First bold in a blockquote acts as the block's heading */
#contentRenderer blockquote p > strong:first-child {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(103,75,181,.22);
  letter-spacing: -0.01em;
}
[data-theme="dark"] #contentRenderer blockquote p > strong:first-child {
  color: var(--primary);
  border-bottom-color: rgba(157,130,247,.25);
}
/* Remove the <br> that markdown inserts after the heading line (double-space trailing) */
#contentRenderer blockquote p > strong:first-child + br {
  display: none;
}

/* Tables */
#contentRenderer table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--outline-dim);
  font-size: 13.5px;
  table-layout: auto;
}
#contentRenderer thead {
  background: linear-gradient(90deg, var(--primary-ctr) 0%, var(--surface-med) 100%);
}
#contentRenderer th {
  padding: 12px 18px;
  font-weight: 700;
  font-size: 12px;
  color: var(--on-primary-ctr);
  text-align: left;
  border-bottom: 2px solid var(--outline-dim);
  /* Headers never wrap — they anchor column width */
  white-space: nowrap;
}
#contentRenderer td {
  padding: 11px 18px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--surface-med);
  vertical-align: top;
  line-height: 1.55;
}
/* Non-last columns: no wrapping, browser auto-distributes width naturally */
#contentRenderer td:not(:last-child) {
  white-space: nowrap;
}
/* Inline code inside tables: never break mid-token */
#contentRenderer td code,
#contentRenderer th code {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}
#contentRenderer tr:last-child td { border-bottom: none; }
#contentRenderer tbody tr:hover td { background: var(--surface-lo); }

/* HR */
#contentRenderer hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--outline-dim), transparent);
  margin: 36px 0;
}

/* ═══════════════════════════════════════════════════
   SPECIAL COMPONENTS
═══════════════════════════════════════════════════ */

/* Exam trap callout */
.exam-trap {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--tertiary-ctr) 0%, rgba(250,112,132,.08) 100%);
  border-left: 3px solid var(--tertiary);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  margin: 18px 0;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--tertiary);
}
.exam-trap strong { color: inherit; }

/* Key concept tags */
.concept-tag {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600;
  margin: 2px;
}

/* Info / tip card */
.info-card {
  background: var(--card-bg);
  border: 1px solid var(--outline-dim);
  border-radius: var(--r-lg);
  padding: 18px 22px;
  margin: 18px 0;
  backdrop-filter: blur(10px);
}

/* ── Progress step strip ─────────────────────────── */
.progress-strip {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 24px 0;
  overflow-x: auto;
  padding-bottom: 4px;
}
.step-pill {
  flex: 1;
  min-width: 100px;
  padding: 10px 14px;
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  position: relative;
}
.step-pill:first-child { border-radius: var(--r-pill) 0 0 var(--r-pill); }
.step-pill:last-child  { border-radius: 0 var(--r-pill) var(--r-pill) 0; }
.step-pill + .step-pill { border-left: 1px solid rgba(103,75,181,.2); }
.step-pill--mint {
  background: var(--secondary-ctr);
  color: var(--on-secondary-ctr);
}
.step-pill--coral {
  background: var(--tertiary-ctr);
  color: var(--on-tertiary-ctr);
}

/* ── HTML/CSS Flowchart diagrams ─────────────────── */
.flowchart {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 24px 12px 28px;
  margin: 24px 0;
  background: var(--surface-lo);
  border-radius: var(--r-xl);
  border: 1px solid var(--outline-dim);
}
.flowchart-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--outline);
  margin-bottom: 18px;
}

/* Row of nodes */
.flow-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  flex-wrap: wrap;
}

/* Individual node box */
.flow-node {
  background: var(--card-bg);
  border: 2px solid var(--primary-accent);
  border-radius: var(--r-lg);
  padding: 12px 18px;
  text-align: center;
  min-width: 130px;
  max-width: 220px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-card);
  position: relative;
  z-index: 1;
}
.flow-node--lavender {
  background: var(--primary-ctr);
  border-color: var(--primary);
}
.flow-node--mint {
  background: var(--secondary-ctr);
  border-color: var(--secondary);
}
.flow-node--coral {
  background: var(--tertiary-ctr);
  border-color: var(--tertiary);
}
.flow-node-week {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin-bottom: 3px;
}
.flow-node--mint .flow-node-week  { color: var(--secondary); }
.flow-node--coral .flow-node-week { color: var(--tertiary); }
.flow-node-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.flow-node-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Arrows */
.flow-arrow-down {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1px 0;
  color: var(--primary);
  flex-shrink: 0;
}
.flow-arrow-down::before {
  content: '';
  display: block;
  width: 2px; height: 22px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-accent) 100%);
  opacity: 0.5;
}
.flow-arrow-down::after {
  content: '▼';
  font-size: 9px;
  color: var(--primary);
  opacity: 0.7;
  margin-top: -2px;
}

.flow-connector {
  height: 2px;
  width: 28px;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-accent) 100%);
  opacity: 0.35;
  flex-shrink: 0;
}
.flow-arrow-right {
  font-size: 13px;
  color: var(--primary);
  opacity: 0.65;
  flex-shrink: 0;
  padding: 0 2px;
  display: flex; align-items: center;
}
.flow-arrow-right::after { content: '→'; }

/* Topic pills inside nodes */
.flow-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  margin-top: 6px;
}
.flow-topic {
  font-size: 10px;
  font-weight: 600;
  background: rgba(103,75,181,.12);
  color: var(--primary);
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.flow-node--mint  .flow-topic { background: rgba(0,108,75,.1); color: var(--secondary); }
.flow-node--coral .flow-topic { background: rgba(169,51,73,.1); color: var(--tertiary); }

/* API reference table */
.api-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--outline-dim);
}
.api-table thead {
  background: linear-gradient(90deg, var(--primary-ctr) 0%, var(--surface-med) 100%);
}
.api-table th {
  padding: 10px 16px;
  font-weight: 700;
  font-size: 11.5px;
  color: var(--on-primary-ctr);
  text-align: left;
}
.api-table td {
  padding: 9px 16px;
  color: var(--text-muted);
  border-top: 1px solid var(--surface-med);
  vertical-align: top;
  line-height: 1.5;
}
.api-table td:first-child {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--on-primary-ctr);
  background: var(--primary-ctr);
  white-space: nowrap;
  font-weight: 600;
}
.api-table tr:hover td { background: var(--surface-lo); }
.api-table tr:hover td:first-child { background: var(--primary-ctr); }

/* Method signature box */
.method-sig {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--code-bg);
  color: #abb2bf;
  padding: 10px 16px;
  border-radius: var(--r-md);
  margin: 8px 0;
  border-left: 3px solid var(--primary-accent);
  overflow-x: auto;
}

/* ═══════════════════════════════════════════════════
   PAGE NAV (prev / next)
═══════════════════════════════════════════════════ */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 44px;
  padding-top: 28px;
  border-top: 1px solid var(--outline-dim);
}

.page-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--card-bg);
  border: 1px solid var(--outline-dim);
  border-radius: var(--r-pill);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
  text-align: left;
  max-width: 260px;
}
.page-nav-btn--next { margin-left: auto; text-align: right; }
.page-nav-btn:hover:not(:disabled) {
  background: var(--primary-ctr);
  color: var(--on-primary-ctr);
  border-color: var(--primary-accent);
  box-shadow: 0 4px 16px rgba(103,75,181,.15);
  transform: translateY(-1px);
}
.page-nav-btn:active:not(:disabled) { transform: scale(0.97); }
.page-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.page-nav-text { display: flex; flex-direction: column; gap: 1px; }
.page-nav-label {
  font-size: 9.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--outline);
}
.page-nav-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

/* ═══════════════════════════════════════════════════
   RIGHT TOC PANEL
═══════════════════════════════════════════════════ */
.toc-panel {
  width: 220px;
  flex-shrink: 0;
  padding: 36px 20px 36px 4px;
  position: sticky;
  top: 24px;
  height: calc(100vh - 24px);
  overflow-y: auto;
  scrollbar-width: none;
}
.toc-panel::-webkit-scrollbar { display: none; }

.toc-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--outline);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--outline-dim);
}

.toc-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.toc-list li a {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--outline);
  text-decoration: none;
  padding: 5px 9px;
  border-radius: var(--r-md);
  transition: all 0.14s;
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.toc-list li a:hover {
  color: var(--primary);
  background: var(--primary-ctr);
  border-left-color: var(--primary-accent);
}
.toc-list li a.toc-active {
  color: var(--primary);
  background: var(--primary-ctr);
  border-left-color: var(--primary);
  font-weight: 600;
}
.toc-list li a.toc-h3 { padding-left: 20px; font-size: 11.5px; }
.toc-list li a.toc-h4 { padding-left: 32px; font-size: 11px; color: var(--outline-dim); }

/* ═══════════════════════════════════════════════════
   GLOBAL OVERFLOW GUARDS (all screen sizes)
═══════════════════════════════════════════════════ */
/* overflow-x: clip prevents horizontal overflow WITHOUT creating a scroll
   container — so position:sticky on .toc-panel and .topbar still works */
.shell       { min-width: 0; overflow-x: clip; }
.content-row { min-width: 0; }
.article     { min-width: 0; overflow-x: clip; }

/* article-card must NOT have overflow:hidden — it would clip .table-scroll */
.article-card { min-width: 0; }

/* Markdown content — prevent text & element overflow; tables scroll via wrapper */
#contentRenderer {
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}
#contentRenderer img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--r-md);
}

/* Table scroll wrapper — injected by JS postProcess */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 20px 0;
  border-radius: var(--r-lg);
  /* subtle left/right fade to hint scrollability */
  background:
    linear-gradient(to right, var(--card-bg) 0%, transparent 16px) left,
    linear-gradient(to left,  var(--card-bg) 0%, transparent 16px) right;
  background-size: 40px 100%;
  background-attachment: local, local;
}
.table-scroll table {
  margin: 0;
  border-radius: 0;
  min-width: 480px;
}

/* Search pill: hidden on desktop (sidebar has search); icon-only on mobile */
.search-pill {
  display: none;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: var(--surface-lo);
  border: none;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
  font-family: inherit;
  color: var(--text-muted);
}
.search-pill:hover { border-color: var(--primary); background: var(--surface); }

/* ── Sidebar search ──────────────────────────────── */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px;
  background: #f4efff;
  border-radius: var(--r-pill);
  margin: 0 4px 10px;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}
.sidebar-search:focus-within {
  border-color: var(--primary);
  background: var(--surface);
}
.sidebar-search > .material-symbols-outlined {
  font-size: 15px;
  color: var(--outline);
  flex-shrink: 0;
}
.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  min-width: 0;
}
.sidebar-search input::placeholder { color: var(--outline); }
.sidebar-search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--outline);
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 16px; height: 16px;
  flex-shrink: 0;
}
.sidebar-search-clear .material-symbols-outlined { font-size: 12px; }
.sidebar-search-clear:hover { color: var(--primary); }
.sidebar-search.has-query .sidebar-search-clear { display: flex; }

/* Search result state in nav */
.nav-no-results {
  padding: 10px 10px;
  font-size: 12px;
  color: var(--outline);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════
   PDF DOWNLOAD BUTTON — Fixed floating, bottom-right
   Pill (icon + label) on desktop · Circle (icon) on mobile
═══════════════════════════════════════════════════ */

/* No longer needs the article as a positioning context */
.article { position: static; }

.pdf-download-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 200;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 9px 16px 9px 12px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-accent) 100%);
  color: #fff;
  border: none;
  border-radius: var(--r-pill);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(103, 75, 181, 0.42),
              0 2px 8px rgba(0, 0, 0, 0.14);
  transition: transform 0.18s, box-shadow 0.18s, opacity 0.18s;
  user-select: none;
}

.pdf-download-btn .material-symbols-outlined {
  font-size: 18px;
  font-variation-settings: 'FILL' 1, 'wght' 600, 'GRAD' 0, 'opsz' 20;
}

.pdf-download-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 32px rgba(103, 75, 181, 0.52),
              0 4px 12px rgba(0, 0, 0, 0.16);
}
.pdf-download-btn:active {
  transform: scale(0.95);
}

/* Generating state */
.pdf-download-btn.generating {
  opacity: 0.82;
  cursor: wait;
  pointer-events: none;
}
.pdf-download-btn.generating .material-symbols-outlined {
  animation: spin 1.1s linear infinite;
}

/* ── Mobile (≤960px): shrink to circular FAB, icon only ── */
@media (max-width: 960px) {
  .pdf-download-btn {
    bottom: 20px;
    right: 18px;
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }
  .pdf-btn-label { display: none; }
  .pdf-download-btn .material-symbols-outlined { font-size: 22px; }
}

@media (max-width: 480px) {
  .pdf-download-btn {
    bottom: 16px;
    right: 14px;
    width: 48px;
    height: 48px;
  }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════ */

/* ── Desktop (>960px): topbar hidden; sidebar always visible ── */
@media (min-width: 961px) {
  .topbar { display: none; }
}

/* ── Wide: hide right TOC ───────────────────────── */
@media (max-width: 1300px) {
  .toc-panel { display: none; }
}

/* ── Tablet + Mobile (≤960px) ───────────────────── */
@media (max-width: 960px) {

  /* Sidebar: fully hidden off-screen (includes rail + text) */
  .sidebar {
    transform: translateX(calc(-1 * var(--sidebar-w)));
    box-shadow: none;
    transition: transform 0.3s cubic-bezier(.4,0,.2,1),
                box-shadow 0.3s;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-sidebar);
  }

  /* Undo desktop collapse state on mobile — always full sidebar */
  body.sidebar-collapsed .sidebar-text {
    width: var(--text-w);
    padding: 16px 10px;
    overflow: hidden;
    overflow-y: auto;
  }

  /* Shell fills full viewport */
  .shell,
  body.sidebar-collapsed .shell {
    margin-left: 0;
  }

  /* Topbar: fixed on mobile so it stays visible while scrolling */
  .topbar {
    display: flex;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 16px;
    z-index: 90;
  }
  .mobile-menu-btn { display: flex; }

  .search-hint { display: none; }

  /* Push content below the fixed topbar */
  .content-row { padding-top: 56px; }

  /* Article spacing */
  .article      { padding: 14px 10px 80px; }
  .article-card { padding: 22px 18px; overflow: visible; }

  /* Page-nav: stack + full width */
  .page-nav { flex-direction: column; gap: 10px; }
  .page-nav-btn {
    max-width: 100%;
    width: 100%;
    justify-content: space-between;
  }
  .page-nav-btn--next { margin-left: 0; }
  .page-nav-title     { max-width: none; flex: 1; }
}

/* ── Small mobile (≤480px) ──────────────────────── */
@media (max-width: 480px) {
  .topbar { padding: 0 12px; height: 52px; }
  .topbar-crumb { font-size: 13px; }

  .article      { padding: 8px 6px 80px; }
  .article-card {
    padding: 16px 14px;
    border-radius: var(--r-lg);
  }

  /* Headings scale down on small screens */
  #contentRenderer h1 { font-size: 22px; line-height: 1.25; }
  #contentRenderer h2 { font-size: 19px; margin-top: 30px; }
  #contentRenderer h3 { font-size: 17px; }
  #contentRenderer h4 { font-size: 14px; }
  #contentRenderer p  { font-size: 15px; line-height: 1.72; }
  #contentRenderer ul,
  #contentRenderer ol { font-size: 15px; }
  #contentRenderer blockquote p { font-size: 15px; }
  #contentRenderer blockquote p > strong:first-child { font-size: 14px; }

  /* Code blocks — wrap instead of scroll on mobile */
  #contentRenderer pre {
    padding: 14px 12px;
    border-radius: var(--r-md);
    margin: 16px 0;
    overflow-x: visible;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-all;
  }
  #contentRenderer pre code {
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  /* Tables */
  #contentRenderer th { padding: 9px 12px; font-size: 11px; }
  #contentRenderer td { padding: 8px 12px; font-size: 12px; }

  /* Flowcharts */
  .flowchart { padding: 14px 6px 18px; }
  .flow-row  { gap: 8px; }
  .flow-node {
    min-width: 95px;
    max-width: 140px;
    padding: 9px 10px;
  }
  .flow-node-title  { font-size: 11.5px; }
  .flow-topic       { font-size: 9px; padding: 1px 5px; }
  .flow-arrow-down::before { height: 16px; }

  /* Page nav */
  .page-nav-btn  { padding: 10px 14px; font-size: 12px; }
  .page-nav-title { font-size: 12px; }

  /* Exam trap callout */
  .exam-trap { padding: 12px 14px; font-size: 13px; gap: 8px; }
}


/* === Global Material-style thin scrollbar === */

/* For Chrome, Edge, Safari */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent; /* clean, minimal */
}

::-webkit-scrollbar-thumb {
  background-color: rgba(199, 139, 245, 0.35);
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(112, 75, 173, 0.55);
}


/* For Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(133, 105, 246, 0.35) transparent;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR CONTENT SEARCH RESULTS
═══════════════════════════════════════════════════ */
/* Floats over the nav, anchored just below the search bar.
   top / left / width injected by JS from sidebar-text bounds. */
.search-results-nav {
  position: fixed;
  left : 4px !important; 
  z-index: 200;           /* above sidebar content (z-index: 100) */
  background: rgb(254, 247, 255);
  border: 1px solid var(--outline-dim);
  border-radius: var(--r-md);
  box-shadow: 0 6px 24px rgba(103,75,181,.18), 0 2px 8px rgba(0,0,0,.10);
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 0 8px;
  list-style: none;
  scrollbar-width: thin;
    scrollbar-color: rgba(133, 105, 246, 0.35) transparent;
}
.search-results-nav[hidden] { display: none; }

/* Page group heading inside results */
.search-res-group-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 4px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--outline);
}
.search-res-group-label .material-symbols-outlined {
  font-size: 12px;
  color: var(--primary);
  font-variation-settings: 'FILL' 1;
}

/* Individual section result */
.search-res-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 7px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.13s;
  user-select: none;
  -webkit-user-select: none;
}
.search-res-item:hover { background: var(--surface-lo); }
.search-res-item:hover .search-res-heading { color: var(--primary); }
.search-res-item.active { background: var(--primary-ctr); }
.search-res-item.active .search-res-heading { color: var(--on-primary-ctr); }
.search-res-item.active .search-res-snippet { opacity: 0.72; }

.search-res-lvl-icon {
  font-size: 12px;
  color: var(--primary-accent);
  flex-shrink: 0;
  margin-top: 2px;
  font-variation-settings: 'FILL' 0;
}
.search-res-item.active .search-res-lvl-icon { color: var(--primary); }

.search-res-body { flex: 1; min-width: 0; }

.search-res-heading {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.search-res-snippet {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 2px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.search-res-heading mark,
.search-res-snippet mark {
  background: rgba(103, 75, 181, 0.2);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 700;
}
.search-res-item.active .search-res-heading mark,
.search-res-item.active .search-res-snippet mark {
  background: rgba(103, 75, 181, 0.36);
}

/* Separator between result groups */
.search-res-sep {
  height: 1px;
  background: var(--outline-dim);
  margin: 5px 8px;
  opacity: 0.5;
}

/* No results message */
.search-res-empty {
  padding: 18px 10px;
  font-size: 11.5px;
  color: var(--outline);
  font-style: italic;
  text-align: center;
}

/* ── Dark theme overrides: sidebar search + results panel ── */
[data-theme="dark"] .sidebar-search {
  background: var(--surface-hi);
}
[data-theme="dark"] .sidebar-search:focus-within {
  background: var(--surface-med);
}

[data-theme="dark"] .search-results-nav {
  background: var(--surface-lo);
  box-shadow: 0 6px 24px rgba(0,0,0,.50), 0 2px 8px rgba(0,0,0,.40);
}

[data-theme="dark"] .search-res-heading mark,
[data-theme="dark"] .search-res-snippet mark {
  background: rgba(157,130,247,0.28);
}

