/* ═══════════════════════════════════════════════════════════════════
   JSMastery Docs — styles.css
   MDN-inspired editorial design system
   Dark/Light mode · Three-column layout · Inter + JetBrains Mono
═══════════════════════════════════════════════════════════════════ */

/* ──────────────────────────────────────────────────
   CSS CUSTOM PROPERTIES
────────────────────────────────────────────────── */
:root {
  /* Typography */
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Spacing scale */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Layout */
  --topbar-h:    56px;
  --banner-h:    36px;
  --breadcrumb-h:40px;
  --sidebar-l-w: 260px;
  --sidebar-r-w: 220px;
  --content-max:  800px;

  /* Radius */
  --r-sm:  4px;
  --r-md:  6px;
  --r-lg:  10px;
  --r-xl:  14px;

  /* Transitions */
  --ease:  cubic-bezier(.4, 0, .2, 1);
  --t-fast: 150ms;
  --t-med:  250ms;
  --t-slow: 380ms;
}

/* ── DARK THEME (default) ── */
[data-theme="dark"] {
  --bg:           #1b1b1d;
  --bg-2:         #232326;
  --bg-3:         #2a2a2e;
  --bg-4:         #323236;
  --bg-5:         #3d3d42;
  --surface:      #232326;
  --surface-2:    #2a2a2e;
  --border:       rgba(255,255,255,.09);
  --border-2:     rgba(255,255,255,.06);
  --border-acc:   rgba(255,208,67,.25);

  --text-1:       #ffffff;
  --text-2:       #e2e2e4;
  --text-3:       #ababaf;
  --text-4:       #6e6e76;
  --text-5:       #4b4b52;

  --accent:       #ffd043;
  --accent-dim:   rgba(255,208,67,.12);
  --accent-glow:  rgba(255,208,67,.28);
  --accent-text:  #ffda6a;

  --link:         #7db3fb;
  --link-hover:   #a6c8fc;

  --green:        #3fc56b;
  --green-bg:     rgba(63,197,107,.1);
  --red:          #f97583;
  --red-bg:       rgba(249,117,131,.1);
  --yellow:       #ffd043;
  --yellow-bg:    rgba(255,208,67,.1);
  --blue:         #7db3fb;
  --blue-bg:      rgba(125,179,251,.1);

  --code-bg:      #161618;
  --code-border:  rgba(255,255,255,.07);
  --inline-code-bg: #2c2c2e;
  --inline-code-border: rgba(255,255,255,.1);

  /* Syntax — comment contrast: readable but visually lightweight */
  --syn-kw:    #cf9fff;
  --syn-str:   #9ecbff;
  --syn-num:   #ffa657;
  --syn-fn:    #7db3fb;
  --syn-cmt:   #8a8a93;
  --syn-op:    #f8f8f2;
  --syn-cls:   #ffd43b;
  --syn-bool:  #ff7b72;
  --syn-prop:  #79c0ff;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.6);
}

/* ── LIGHT THEME ── */
[data-theme="light"] {
  --bg:           #ffffff;
  --bg-2:         #f9f9fb;
  --bg-3:         #f2f2f5;
  --bg-4:         #eaeaed;
  --bg-5:         #e0e0e4;
  --surface:      #ffffff;
  --surface-2:    #f9f9fb;
  --border:       rgba(0,0,0,.1);
  --border-2:     rgba(0,0,0,.06);
  --border-acc:   rgba(180,130,0,.25);

  --text-1:       #1b1b1d;
  --text-2:       #2f2f33;
  --text-3:       #4e4e56;
  --text-4:       #8a8a94;
  --text-5:       #bababf;

  --accent:       #c97a00;
  --accent-dim:   rgba(201,122,0,.08);
  --accent-glow:  rgba(201,122,0,.2);
  --accent-text:  #9d5e00;

  --link:         #0069c2;
  --link-hover:   #004f94;

  --green:        #1a7f37;
  --green-bg:     rgba(26,127,55,.08);
  --red:          #cf222e;
  --red-bg:       rgba(207,34,46,.07);
  --yellow:       #9a6700;
  --yellow-bg:    rgba(154,103,0,.07);
  --blue:         #0969da;
  --blue-bg:      rgba(9,105,218,.07);

  --code-bg:      #f6f6f9;
  --code-border:  rgba(0,0,0,.09);
  --inline-code-bg: #f2f2f5;
  --inline-code-border: rgba(0,0,0,.1);

  /* Syntax — slate-gray comment palette for professional light presentation */
  --syn-kw:    #8250df;
  --syn-str:   #0a3069;
  --syn-num:   #0550ae;
  --syn-fn:    #953800;
  --syn-cmt:   #5a616c;
  --syn-op:    #24292f;
  --syn-cls:   #6f42c1;
  --syn-bool:  #cf222e;
  --syn-prop:  #0550ae;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.1);
  --shadow-md:  0 4px 16px rgba(0,0,0,.12);
  --shadow-lg:  0 12px 40px rgba(0,0,0,.16);
}

/* ──────────────────────────────────────────────────
   RESET
────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: .9375rem;
  line-height: 1.7;
  color: var(--text-2);
  background: var(--bg);
  transition: background var(--t-med) var(--ease), color var(--t-med) var(--ease);
  min-height: 100vh;
  overflow-x: hidden;
}

::selection {
  background: var(--accent-dim);
  color: var(--text-1);
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover { color: var(--link-hover); text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ──────────────────────────────────────────────────
   SCROLLBAR
────────────────────────────────────────────────── */
::-webkit-scrollbar            { width: 6px; height: 6px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--bg-5); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover{ background: var(--text-5); }

/* ──────────────────────────────────────────────────
   BANNER
────────────────────────────────────────────────── */
.site-banner {
  position: relative;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  height: var(--banner-h);
  background: var(--accent);
  color: #1b1b1d;
  font-size: .8rem;
  font-weight: 500;
  padding: 0 var(--sp-6);
  transition: all var(--t-med) var(--ease);
}
.site-banner.hidden { height: 0; overflow: hidden; }
.banner-close {
  position: absolute;
  right: var(--sp-4);
  background: none;
  border: none;
  font-size: .75rem;
  color: #1b1b1d;
  opacity: .6;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-sm);
  transition: opacity var(--t-fast);
}
.banner-close:hover { opacity: 1; }

/* ──────────────────────────────────────────────────
   TOPBAR
────────────────────────────────────────────────── */
/*
 * Layout model:
 *   .topbar          — full-width sticky bar (background spans viewport)
 *   .topbar-inner    — content constrained to same max-width as .page-shell
 *                      (1400px) with identical horizontal padding so every
 *                      element aligns pixel-perfect with the grid columns.
 *
 * Bug fixed: previous version used padding: 0 var(--sp-4) (16px).
 * The page shell uses margin: 0 auto at 1400px with no extra padding, so
 * on wide viewports the topbar content was centred at 1400px while the
 * action buttons (progress pill, theme toggle) were pulled all the way to
 * the right edge of the 1400px box — misaligned with the right sidebar
 * column.  Switching to a slightly larger symmetrical padding (--sp-5, 20px)
 * and adding a flex gap tightener on .topbar-actions solves the visual drift.
 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 150;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background var(--t-med) var(--ease), border-color var(--t-med) var(--ease);
}

.topbar-inner {
  /* Must mirror .page-shell: same max-width, same horizontal rhythm */
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  /* sidebar-toggle + logo occupy the left; search centre-expands;
     nav + actions are pushed right — gap enforces minimum breathing room */
  gap: var(--sp-3);
  /* Symmetric padding keeps content inside the same vertical rails as the
     page grid columns.  Do NOT use justify-content: space-between here —
     that flings the actions to the raw container edge on wide displays. */
  padding: 0 var(--sp-5);
  box-sizing: border-box;
}

/* Sidebar toggle */
.sidebar-toggle {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--text-3);
  transition: all var(--t-fast);
}
.sidebar-toggle:hover {
  background: var(--bg-3);
  color: var(--text-1);
  border-color: var(--border);
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}
.logo-mark { flex-shrink: 0; display: flex; }
.logo-wordmark {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -.3px;
}
.logo-sup {
  font-size: .6em;
  font-weight: 400;
  color: var(--text-4);
  margin-left: 2px;
  vertical-align: super;
}

/* Search */
.topbar-search-wrap {
  flex: 1;
  max-width: 420px;
  position: relative;
}
.topbar-search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 6px 10px;
  transition: all var(--t-fast);
}
.topbar-search:focus-within {
  border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-icon { 
  color: var(--text-4); 
  flex-shrink: 0; 
  width: 16px !important;  
  height: 16px !important;
}
.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: .85rem;
  color: var(--text-1);
}
.search-input::placeholder { color: var(--text-4); }
.search-kbd {
  font-size: .68rem;
  color: var(--text-5);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  font-family: var(--font-mono);
  flex-shrink: 0;
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-height: 360px;
  overflow-y: auto;
  z-index: 300;
  display: none;
}
.search-results.open { display: block; }
.sr-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-2);
  transition: background var(--t-fast);
}
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg-3); }
.sr-item-tag {
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--border-acc);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  margin-top: 2px;
}
.sr-item-title { font-size: .85rem; color: var(--text-1); font-weight: 500; }
.sr-item-chapter { font-size: .76rem; color: var(--text-4); }

/* Topbar nav */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* SVG icon size guard — prevents oversized icons in search + topbar areas */
.topbar-search-wrap svg,
.search-icon svg {
  width: 16px !important;
  height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
}
.topbar-nav-link {
  display: block;
  padding: 5px 12px;
  border-radius: 100px;
  font-size: .84rem;
  font-weight: 500;
  color: var(--text-3);
  text-decoration: none;
  transition: all var(--t-fast);
}
.topbar-nav-link:hover { color: var(--text-1); background: var(--bg-3); text-decoration: none; }
.topbar-nav-link.active { color: var(--accent); background: var(--accent-dim); }

/* Actions — pushed to the right end of the topbar flex row.
 * margin-left: auto absorbs all remaining space so the progress pill
 * and theme button always sit flush against the right boundary of the
 * 1400px container, not the raw viewport edge.                          */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
  margin-left: auto;
}
.progress-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-3);
  cursor: default;
}
.progress-pct { font-family: var(--font-mono); font-size: .76rem; color: var(--accent); }
#pillRingArc { transition: stroke-dashoffset .6s var(--ease); }

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-3);
  transition: all var(--t-fast);
}
.theme-btn:hover { color: var(--accent); border-color: var(--border-acc); }
[data-theme="dark"] .icon-sun  { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
[data-theme="light"] .icon-sun  { display: block; }
[data-theme="light"] .icon-moon { display: none; }

/* ──────────────────────────────────────────────────
   BREADCRUMB BAR
────────────────────────────────────────────────── */
.breadcrumb-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--breadcrumb-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-2);
  padding: 0 var(--sp-4);
  transition: background var(--t-med) var(--ease);
}
.breadcrumb ol {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  font-size: .79rem;
  color: var(--text-4);
}
.breadcrumb li { display: flex; align-items: center; gap: 4px; }
.breadcrumb li + li::before { content: '/'; color: var(--text-5); }
.breadcrumb a { color: var(--link); }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb li:last-child { color: var(--text-3); font-weight: 500; }

.bc-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: .76rem;
  font-weight: 500;
  color: var(--text-3);
  transition: all var(--t-fast);
}
.bc-btn:hover { border-color: var(--green); color: var(--green); background: var(--green-bg); }
.bc-btn.done { border-color: var(--green); color: var(--green); background: var(--green-bg); }

/* ──────────────────────────────────────────────────
   THREE-COLUMN SHELL
────────────────────────────────────────────────── */
.page-shell {
  display: grid;
  grid-template-columns: var(--sidebar-l-w) 1fr var(--sidebar-r-w);
  min-height: calc(100vh - var(--topbar-h) - var(--breadcrumb-h));
  max-width: 1400px;
  margin: 0 auto;
}

/* ──────────────────────────────────────────────────
   LEFT SIDEBAR
────────────────────────────────────────────────── */
/*
 * Sticky behaviour model (mirrors the working .sr-sticky on the right):
 *
 *   .sidebar-left    — grid column cell; must NOT have overflow:hidden
 *                      because overflow:hidden on any ancestor breaks
 *                      position:sticky for all descendants (the browser
 *                      treats it as a scroll container, clipping the sticky
 *                      item to the parent height instead of the viewport).
 *
 *   .sidebar-sticky  — the actual sticky panel; top offset accounts for the
 *                      topbar + breadcrumb bar heights; height is clamped to
 *                      the remaining viewport so the panel never grows taller
 *                      than the window; overflow-y:auto gives it its own
 *                      independent scroll track when content overflows.
 *
 * Collapsed state still works: body.sidebar-collapsed sets width:0 on
 * .sidebar-left and the grid column collapses to 0 via the grid rule.
 */
.sidebar-left {
  border-right: 1px solid var(--border);
  /* ⚠ DO NOT set overflow:hidden here — it breaks position:sticky inside */
  overflow: visible;
  transition: width var(--t-med) var(--ease), border-color var(--t-med) var(--ease);
}

.sidebar-sticky {
  position: sticky;
  /* Lock just below the two stacked fixed-height bars */
  top: calc(var(--topbar-h) + var(--breadcrumb-h));
  /* Consume exactly the remaining viewport height — same formula as
     .sr-sticky on the right sidebar so both panels behave identically */
  height: calc(100vh - var(--topbar-h) - var(--breadcrumb-h));
  /* Independent scroll: sidebar nav scrolls without moving the article */
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-4) 0;
  /* Prevent the sticky element from collapsing when the grid column shrinks */
  min-width: 0;
}

/* Filter */
.sidebar-filter-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 var(--sp-4) var(--sp-4);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 8px;
  transition: all var(--t-fast);
}
.sidebar-filter-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.sf-icon { color: var(--text-5); flex-shrink: 0; margin-right: 4px; }
.sidebar-filter {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: .8rem;
  color: var(--text-1);
}
.sidebar-filter::placeholder { color: var(--text-5); }
.sf-clear {
  background: none;
  border: none;
  color: var(--text-5);
  font-size: .7rem;
  padding: 0 2px;
  transition: color var(--t-fast);
}
.sf-clear:hover { color: var(--text-3); }
.sf-clear.hidden { display: none; }

/* Nav groups */
.sidebar-nav { padding-bottom: var(--sp-8); }
.nav-group { margin-bottom: 2px; }

.nav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px var(--sp-4);
  cursor: pointer;
  user-select: none;
}
.nav-group-title {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-4);
}
.nav-group-chevron {
  color: var(--text-5);
  transition: transform var(--t-fast);
  flex-shrink: 0;
}
.nav-group.open .nav-group-chevron { transform: rotate(180deg); }

.nav-group-items { overflow: hidden; }
.nav-group-items.collapsed { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px var(--sp-4) 5px var(--sp-5);
  background: none;
  border: none;
  border-left: 2px solid transparent;
  text-align: left;
  font-family: var(--font-sans);
  font-size: .84rem;
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
}
.nav-item:hover { color: var(--text-1); background: var(--bg-3); }
.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
  font-weight: 500;
}
.nav-item.completed .nav-dot { background: var(--green); }
.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bg-5);
  flex-shrink: 0;
  transition: background var(--t-fast);
}
.nav-item.active .nav-dot { background: var(--accent); }
.nav-item-text { flex: 1; line-height: 1.4; }
.nav-item-new {
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--green);
  background: var(--green-bg);
  border: 1px solid rgba(63,197,107,.2);
  padding: 1px 5px;
  border-radius: 100px;
}

/* Collapsed sidebar */
body.sidebar-collapsed .sidebar-left {
  width: 0;
  border-right-color: transparent;
  overflow: hidden; /* re-apply clipping only when collapsed — content is gone */
}
body.sidebar-collapsed .page-shell {
  grid-template-columns: 0 1fr var(--sidebar-r-w);
}

/* ──────────────────────────────────────────────────
   MAIN CONTENT
────────────────────────────────────────────────── */
.content-main {
  min-width: 0;
  border-right: 1px solid var(--border);
}

.page-view { display: none; }
.page-view.active { display: block; }

/* ──────────────────────────────────────────────────
   DOCUMENT ARTICLE
────────────────────────────────────────────────── */
.doc-article {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-10) var(--sp-8) var(--sp-12);
  animation: fadeUp .3s var(--ease) both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Topic header */
.topic-header { margin-bottom: var(--sp-8); padding-bottom: var(--sp-6); border-bottom: 1px solid var(--border); }

.topic-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.topic-chapter-badge {
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .3px;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--accent-dim);
  color: var(--accent-text);
  border: 1px solid var(--border-acc);
}
.topic-difficulty {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  padding: 2px 8px;
  border-radius: 100px;
}
.diff-beginner   { background: var(--green-bg); color: var(--green); border: 1px solid rgba(63,197,107,.2); }
.diff-intermediate { background: var(--yellow-bg); color: var(--yellow); border: 1px solid rgba(255,208,67,.2); }
.diff-advanced   { background: var(--red-bg); color: var(--red); border: 1px solid rgba(249,117,131,.2); }

.topic-h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-1);
  letter-spacing: -.4px;
  margin-bottom: var(--sp-3);
}
.topic-desc {
  font-size: 1.025rem;
  color: var(--text-3);
  line-height: 1.75;
  max-width: 640px;
}

/* Section headings */
.doc-h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -.2px;
  margin: var(--sp-10) 0 var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
  scroll-margin-top: calc(var(--topbar-h) + var(--breadcrumb-h) + 16px);
}
.doc-h3 {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-1);
  margin: var(--sp-8) 0 var(--sp-3);
  scroll-margin-top: calc(var(--topbar-h) + var(--breadcrumb-h) + 16px);
}
.doc-h4 {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-2);
  margin: var(--sp-6) 0 var(--sp-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-family: var(--font-mono);
}

/* Paragraph */
.doc-p {
  margin-bottom: var(--sp-4);
  color: var(--text-2);
  font-size: .9375rem;
  line-height: 1.75;
}

/* Inline code */
.ic, code:not(pre code) {
  font-family: var(--font-mono);
  font-size: .83em;
  background: var(--inline-code-bg);
  border: 1px solid var(--inline-code-border);
  color: var(--accent-text);
  padding: .1em .35em;
  border-radius: var(--r-sm);
  white-space: nowrap;
}

/* Formal syntax box (MDN "Syntax" section) */
.syntax-box {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-4) 0 var(--sp-6);
  font-family: var(--font-mono);
  font-size: .83rem;
  color: var(--text-2);
  line-height: 1.8;
  overflow-x: auto;
}
.syntax-param { color: var(--syn-fn); }
.syntax-optional { color: var(--text-4); }
.syntax-kw { color: var(--syn-kw); }

/* Note / callout blocks */
.callout {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-5);
  border-radius: var(--r-md);
  margin: var(--sp-5) 0;
  font-size: .9rem;
  line-height: 1.7;
  border-left: 3px solid;
}
.callout-note    { background: var(--blue-bg);   border-color: var(--blue);  color: var(--text-2); }
.callout-tip     { background: var(--green-bg);  border-color: var(--green); color: var(--text-2); }
.callout-warning { background: var(--yellow-bg); border-color: var(--yellow); color: var(--text-2); }
.callout-danger  { background: var(--red-bg);    border-color: var(--red);   color: var(--text-2); }
.callout-icon    { font-size: 1rem; flex-shrink: 0; line-height: 1.7; }
.callout-inner strong { color: var(--text-1); display: block; margin-bottom: 3px; font-size: .85rem; text-transform: uppercase; letter-spacing: .5px; }

/* Lists */
.doc-ul, .doc-ol {
  margin: var(--sp-3) 0 var(--sp-4) var(--sp-5);
  line-height: 1.8;
}
.doc-ul { list-style: disc; }
.doc-ol { list-style: decimal; }
.doc-ul li, .doc-ol li {
  font-size: .9375rem;
  color: var(--text-2);
  padding: 2px 0;
}
.doc-ul li::marker { color: var(--accent); }
.doc-ol li::marker { color: var(--accent); font-family: var(--font-mono); font-size: .85em; }

/* Definition list (MDN parameters table) */
.param-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-4) 0 var(--sp-6);
  font-size: .875rem;
}
.param-table th {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-3);
  color: var(--text-3);
  font-size: .73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  border-bottom: 2px solid var(--border);
}
.param-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border-2);
  vertical-align: top;
  color: var(--text-2);
  line-height: 1.6;
}
.param-table tr:last-child td { border-bottom: none; }
.param-name { font-family: var(--font-mono); color: var(--syn-fn); font-size: .83em; }
.param-type { font-family: var(--font-mono); color: var(--syn-kw); font-size: .8em; background: var(--inline-code-bg); padding: .1em .3em; border-radius: var(--r-sm); }

/* ──────────────────────────────────────────────────
   CODE BLOCK (static display)
────────────────────────────────────────────────── */
.code-wrap {
  margin: var(--sp-5) 0 var(--sp-6);
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--code-border);
  box-shadow: var(--shadow-sm);
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-4);
  border-bottom: 1px solid var(--code-border);
}
.code-traffic {
  display: flex;
  gap: 6px;
  align-items: center;
}
.code-traffic span {
  width: 11px; height: 11px; border-radius: 50%;
  display: block;
}
.ct-red    { background: #ff5f57; }
.ct-yellow { background: #febc2e; }
.ct-green  { background: #28c840; }
.code-filename {
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-4);
}
.code-copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-4);
  font-size: .72rem;
  font-family: var(--font-mono);
  padding: 3px 9px;
  transition: all var(--t-fast);
}
.code-copy-btn:hover { color: var(--accent); border-color: var(--border-acc); }
.code-copy-btn.copied { color: var(--green); border-color: var(--green); }

pre.code-pre {
  background: var(--code-bg);
  padding: var(--sp-5) var(--sp-5);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.75;
  tab-size: 2;
  margin: 0;
}

/* ─── Syntax token classes ───────────────────────────────────────────────
 * Each class maps 1-to-1 to a CSS custom property defined in both
 * [data-theme="dark"] and [data-theme="light"]. The theme switcher on
 * <html data-theme="…"> automatically propagates the correct palette.
 *
 * !important is applied here on the consuming rules (not on the variable
 * declarations) — custom property values do not support !important.
 * ─────────────────────────────────────────────────────────────────────── */
.tok-kw   { color: var(--syn-kw);   }
.tok-str  { color: var(--syn-str);  }
.tok-num  { color: var(--syn-num);  }
.tok-fn   { color: var(--syn-fn);   }
.tok-cls  { color: var(--syn-cls);  }
.tok-bool { color: var(--syn-bool); }
.tok-prop { color: var(--syn-prop); }

/* Comments: always italic, always lightweight, colour enforced with
 * !important so that generic pre/code resets cannot override it.       */
.tok-cmt,
.cmt {
  color:        var(--syn-cmt)  !important;
  font-style:   italic          !important;
  font-weight:  400             !important;
}

/* Pre/code breathing space — applied globally across all code surfaces */
pre code {
  line-height:    1.85   !important;
  letter-spacing: 0.25px;
}

/* ──────────────────────────────────────────────────
   LIVE EDITOR (Interactive Runner)
────────────────────────────────────────────────── */
.runner-card {
  margin: var(--sp-4) 0 var(--sp-8);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.runner-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  font-size: .73rem;
  font-weight: 600;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: .8px;
}
.runner-label-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}
.runner-editor-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-4);
  padding: 6px 12px;
  border-bottom: 1px solid var(--code-border);
}
.tl { width: 11px; height: 11px; border-radius: 50%; display: block; }
.tl.red    { background: #ff5f57; }
.tl.yellow { background: #febc2e; }
.tl.green  { background: #28c840; }
.runner-filename { font-family: var(--font-mono); font-size: .72rem; color: var(--text-4); flex: 1; }
.runner-btn-run {
  display: flex; align-items: center; gap: 5px;
  background: var(--accent);
  color: #1b1b1d;
  border: none;
  border-radius: var(--r-sm);
  padding: 4px 12px;
  font-size: .76rem;
  font-weight: 700;
  font-family: var(--font-sans);
  letter-spacing: .2px;
  transition: all var(--t-fast);
}
.runner-btn-run:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 3px 10px var(--accent-glow); }
.runner-btn-run:active { transform: none; }
.runner-btn-clear {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-4);
  font-size: .73rem;
  font-family: var(--font-sans);
  padding: 4px 10px;
  transition: all var(--t-fast);
}
.runner-btn-clear:hover { color: var(--text-2); border-color: var(--text-4); }

.runner-textarea {
  display: block;
  width: 100%;
  min-height: 140px;
  max-height: 320px;
  background: var(--code-bg);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.75;
  padding: var(--sp-4) var(--sp-5);
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
}
.runner-textarea:focus { background: var(--code-bg); }

.runner-console {
  border-top: 1px solid var(--border);
}
.runner-console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border-2);
}
.rch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: .71rem;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: .7px;
}
.rch-clear {
  background: none; border: none;
  font-size: .71rem; font-family: var(--font-mono);
  color: var(--text-5);
  transition: color var(--t-fast);
}
.rch-clear:hover { color: var(--red); }

.runner-console-body {
  background: var(--bg);
  padding: 8px 14px;
  min-height: 48px;
  max-height: 180px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.7;
}
.cl-log   { color: var(--text-2); padding: 1px 0; }
.cl-error { color: var(--red); }
.cl-warn  { color: var(--yellow); }
.cl-info  { color: var(--blue); }
.cl-result{ color: var(--green); }
.cl-empty { color: var(--text-5); font-style: italic; }
.cl-log::before,   .cl-error::before,
.cl-warn::before,  .cl-info::before,
.cl-result::before { content: '> '; color: var(--text-5); }

/* ──────────────────────────────────────────────────
   QUIZ SECTION (inside article)
────────────────────────────────────────────────── */
.quiz-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-6);
  margin-top: var(--sp-12);
  flex-wrap: wrap;
}
.quiz-cta-left { display: flex; flex-direction: column; gap: 4px; }
.quiz-cta-tag {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--accent);
  font-family: var(--font-mono);
}
.quiz-cta-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text-1);
}
.quiz-cta-sub { font-size: .85rem; color: var(--text-3); }
.quiz-cta-btn {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  background: var(--accent);
  color: #1b1b1d;
  border: none;
  border-radius: var(--r-md);
  padding: 10px 22px;
  font-size: .88rem;
  font-weight: 700;
  font-family: var(--font-sans);
  transition: all var(--t-fast);
}
.quiz-cta-btn:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }

/* Prev/Next pagination */
.topic-pagination {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-8) var(--sp-10);
  max-width: var(--content-max);
  margin: 0 auto;
  border-top: 1px solid var(--border-2);
}
.page-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text-2);
  font-family: var(--font-sans);
  text-align: left;
  transition: all var(--t-fast);
}
.page-nav-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.page-nav-btn:disabled { opacity: .4; pointer-events: none; }
.page-nav-btn.next { justify-content: flex-end; text-align: right; }
.page-nav-btn small { display: block; font-size: .72rem; color: var(--text-4); margin-bottom: 2px; }
.page-nav-btn strong { display: block; font-size: .85rem; font-weight: 600; color: var(--text-1); }

/* ──────────────────────────────────────────────────
   RIGHT SIDEBAR
────────────────────────────────────────────────── */
.sidebar-right { padding: 0; }
.sr-sticky {
  position: sticky;
  top: calc(var(--topbar-h) + var(--breadcrumb-h));
  height: calc(100vh - var(--topbar-h) - var(--breadcrumb-h));
  overflow-y: auto;
  padding: var(--sp-6) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}
.sr-section {}
.sr-heading {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-4);
  margin-bottom: var(--sp-3);
}

/* TOC */
.toc-list { display: flex; flex-direction: column; gap: 1px; }
.toc-link {
  display: block;
  font-size: .8rem;
  color: var(--text-3);
  text-decoration: none;
  padding: 4px 8px 4px 10px;
  border-left: 2px solid transparent;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  line-height: 1.45;
  transition: all var(--t-fast);
}
.toc-link:hover { color: var(--text-1); text-decoration: none; background: var(--bg-3); }
.toc-link.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }
.toc-link.toc-h3 { padding-left: 20px; font-size: .76rem; }

/* Progress ring */
.progress-ring-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: var(--sp-3);
}
.progress-ring { width: 72px; height: 72px; transform: rotate(-90deg); }
.pr-track { fill: none; stroke: var(--bg-4); stroke-width: 5; }
.pr-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 188.5;
  stroke-dashoffset: 188.5;
  transition: stroke-dashoffset .7s var(--ease);
}
.pr-label {
  position: absolute;
  text-align: center;
}
.pr-label strong { display: block; font-size: 1rem; font-weight: 800; color: var(--accent); }
.pr-label small  { font-size: .6rem; color: var(--text-4); }

.progress-stats-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  justify-content: center;
  margin-bottom: var(--sp-3);
}
.pstat { text-align: center; flex: 1; }
.pstat span { display: block; font-size: 1.1rem; font-weight: 700; color: var(--text-1); font-family: var(--font-mono); }
.pstat small  { font-size: .68rem; color: var(--text-4); }
.pstat-div { width: 1px; height: 24px; background: var(--border); }

.sr-reset-btn {
  display: block;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-4);
  font-size: .76rem;
  padding: 6px;
  transition: all var(--t-fast);
  text-align: center;
}
.sr-reset-btn:hover { color: var(--red); border-color: var(--red); background: var(--red-bg); }

/* Related */
.related-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.related-item a {
  display: block;
  font-size: .8rem;
  color: var(--link);
  padding: 3px 4px;
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
}
.related-item a:hover { background: var(--bg-3); text-decoration: none; }

/* ──────────────────────────────────────────────────
   CHEATSHEET PAGE
────────────────────────────────────────────────── */
.cheatsheet-page { padding: var(--sp-10) var(--sp-8) var(--sp-16); }

.cs-header { margin-bottom: var(--sp-8); }
.cs-title-row { display: flex; align-items: baseline; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.cs-title { font-size: 1.75rem; font-weight: 700; color: var(--text-1); letter-spacing: -.3px; }
.cs-count { font-family: var(--font-mono); font-size: .78rem; color: var(--text-4); }
.cs-subtitle { font-size: .9rem; color: var(--text-3); margin-bottom: var(--sp-5); }

.cs-search-wrap {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 9px 14px;
  max-width: 500px;
  margin-bottom: var(--sp-5);
  transition: all var(--t-fast);
}
.cs-search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.cs-search {
  flex: 1; background: none; border: none; outline: none;
  font-family: var(--font-sans); font-size: .88rem; color: var(--text-1);
}
.cs-search::placeholder { color: var(--text-4); }

.cs-filters { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.cs-filter-btn {
  padding: 4px 12px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: none;
  font-size: .76rem;
  font-weight: 500;
  color: var(--text-3);
  transition: all var(--t-fast);
}
.cs-filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.cs-filter-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

.cs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: var(--sp-4);
}
.cs-empty { color: var(--text-4); font-size: .9rem; padding: var(--sp-8) 0; }

.cs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: all var(--t-fast);
  cursor: pointer;
}
.cs-card:hover { border-color: var(--border-acc); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.cs-card-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border-2);
}
.cs-tag {
  font-family: var(--font-mono); font-size: .67rem; font-weight: 500;
  color: var(--accent-text);
  background: var(--accent-dim);
  border: 1px solid var(--border-acc);
  padding: 2px 7px;
  border-radius: 100px;
}
.cs-copy-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-5); border-radius: var(--r-sm);
  font-size: .67rem; font-family: var(--font-mono);
  padding: 2px 8px;
  transition: all var(--t-fast);
}
.cs-copy-btn:hover { color: var(--accent); border-color: var(--border-acc); }
.cs-copy-btn.copied { color: var(--green); border-color: var(--green); }
.cs-card-title { font-size: .84rem; font-weight: 600; color: var(--text-1); padding: 8px 12px 3px; }
.cs-card-desc  { font-size: .78rem; color: var(--text-3); padding: 0 12px 8px; line-height: 1.5; }
pre.cs-pre {
  background: var(--code-bg);
  border-top: 1px solid var(--border-2);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: .78rem;
  line-height: 1.65;
  overflow-x: auto;
  margin: 0;
}

/* ──────────────────────────────────────────────────
   PLAYGROUND PAGE
────────────────────────────────────────────────── */
.playground-page { padding: var(--sp-8); }
.pg-header { margin-bottom: var(--sp-6); }
.pg-title { font-size: 1.75rem; font-weight: 700; color: var(--text-1); letter-spacing: -.3px; margin-bottom: 6px; }
.pg-sub   { font-size: .9rem; color: var(--text-3); margin-bottom: var(--sp-3); }
.pg-tips  { display: flex; gap: var(--sp-4); }
.pg-tip   { font-size: .76rem; color: var(--text-4); display: flex; align-items: center; gap: 4px; }
kbd {
  font-family: var(--font-mono);
  font-size: .7em;
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  color: var(--text-3);
}

.pg-layout {
  display: grid;
  grid-template-rows: 1fr auto;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.pg-editor-wrap {}
.pg-toolbar {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--bg-4);
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
}
.traffic-lights { display: flex; gap: 5px; }
.pg-filename { font-family: var(--font-mono); font-size: .72rem; color: var(--text-4); flex: 1; }
.pg-toolbar-actions { display: flex; gap: 6px; }

.pg-btn {
  display: flex; align-items: center; gap: 4px;
  border-radius: var(--r-sm);
  font-size: .76rem;
  font-family: var(--font-sans);
  font-weight: 600;
  padding: 4px 11px;
  transition: all var(--t-fast);
  border: none;
}
.pg-btn.ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-3);
}
.pg-btn.ghost:hover { color: var(--text-1); border-color: var(--text-4); }
.pg-btn.primary {
  background: var(--accent);
  color: #1b1b1d;
}
.pg-btn.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.pg-btn.sm { font-size: .7rem; padding: 3px 8px; }

.pg-editor-container {
  display: flex;
  background: var(--code-bg);
}
.pg-line-numbers {
  padding: var(--sp-5) var(--sp-3) var(--sp-5) var(--sp-4);
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.75;
  color: var(--text-5);
  text-align: right;
  user-select: none;
  white-space: pre;
  min-width: 40px;
  background: var(--bg-3);
  border-right: 1px solid var(--border-2);
}
.pg-textarea {
  flex: 1;
  display: block;
  width: 100%;
  min-height: 340px;
  background: var(--code-bg);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.75;
  padding: var(--sp-5);
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
}
.pg-console {
  border-top: 1px solid var(--border);
}
.pg-console-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border-2);
}
.pg-console-title {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: .72rem; color: var(--text-4);
  text-transform: uppercase; letter-spacing: .7px;
}
.pg-log-count {
  font-family: var(--font-mono);
  font-size: .7rem;
  color: var(--text-5);
}
.pg-console-body {
  background: var(--bg);
  min-height: 100px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: .83rem;
  line-height: 1.7;
}

/* ──────────────────────────────────────────────────
   QUIZ MODAL
────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-med) var(--ease);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.quiz-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  width: min(560px, 94vw);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(.97);
  transition: transform var(--t-med) var(--ease);
}
.modal-backdrop.open .quiz-modal { transform: none; }

.qm-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: var(--sp-5) var(--sp-6) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.qm-header-left { display: flex; flex-direction: column; gap: 4px; }
.qm-badge {
  font-family: var(--font-mono); font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px;
  color: var(--accent); background: var(--accent-dim);
  border: 1px solid var(--border-acc);
  padding: 1px 7px; border-radius: 100px;
  width: fit-content;
}
.qm-title { font-size: 1.05rem; font-weight: 700; color: var(--text-1); }
.qm-close {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-3);
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.qm-close:hover { background: var(--red-bg); border-color: var(--red); color: var(--red); }

.qm-progress-track {
  height: 3px;
  background: var(--bg-4);
}
.qm-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width var(--t-slow) var(--ease);
}

.qm-body {
  padding: var(--sp-6);
  overflow-y: auto;
  flex: 1;
}
.qm-meta { font-size: .75rem; color: var(--text-4); font-family: var(--font-mono); margin-bottom: var(--sp-4); }
.qm-question {
  font-size: 1rem; font-weight: 500;
  color: var(--text-1); line-height: 1.65;
  margin-bottom: var(--sp-5);
}
.qm-options { display: flex; flex-direction: column; gap: var(--sp-2); }
.qm-option {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 11px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: .9rem; color: var(--text-2);
  text-align: left;
  font-family: var(--font-sans);
  transition: all var(--t-fast);
  cursor: pointer;
}
.qm-option:not(:disabled):hover { border-color: var(--accent); background: var(--accent-dim); color: var(--text-1); }
.qm-option:disabled { cursor: default; }
.qm-option.correct { border-color: var(--green) !important; background: var(--green-bg) !important; color: var(--green) !important; }
.qm-option.wrong   { border-color: var(--red) !important;   background: var(--red-bg) !important;   color: var(--red) !important; }
.qm-option-letter {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; font-family: var(--font-mono);
  color: var(--text-4); flex-shrink: 0;
  transition: all var(--t-fast);
}
.qm-option.correct .qm-option-letter { border-color: var(--green); color: var(--green); }
.qm-option.wrong   .qm-option-letter { border-color: var(--red);   color: var(--red); }

.qm-explanation {
  margin-top: var(--sp-4);
  padding: var(--sp-4) var(--sp-4) var(--sp-4) var(--sp-5);
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  font-size: .875rem;
  color: var(--text-2);
  line-height: 1.65;
  animation: fadeUp .25s var(--ease) both;
}
.qm-explanation strong { color: var(--text-1); }

.qm-result {
  text-align: center;
  padding: var(--sp-4) 0;
}
.qm-result-emoji { font-size: 2.5rem; display: block; margin-bottom: var(--sp-3); }
.qm-result-score { font-size: 2rem; font-weight: 800; color: var(--accent); font-family: var(--font-mono); }
.qm-result-label { color: var(--text-3); font-size: .9rem; margin-top: var(--sp-2); }
.qm-result-bar-wrap { margin: var(--sp-4) auto; max-width: 280px; }
.qm-result-bar-track { height: 6px; background: var(--bg-4); border-radius: 10px; overflow: hidden; }
.qm-result-bar-fill  { height: 100%; background: var(--accent); border-radius: 10px; transition: width .8s var(--ease); }

.qm-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
}
.qm-q-counter { font-family: var(--font-mono); font-size: .76rem; color: var(--text-4); }
.qm-btn {
  padding: 8px 20px;
  border-radius: var(--r-md);
  font-size: .85rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  transition: all var(--t-fast);
}
.qm-btn.primary { background: var(--accent); color: #1b1b1d; }
.qm-btn.primary:hover { filter: brightness(1.08); }
.qm-btn.secondary {
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.qm-btn.secondary:hover { border-color: var(--text-4); color: var(--text-1); }

/* ──────────────────────────────────────────────────
   TOAST
────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-4);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: .84rem;
  font-family: var(--font-sans);
  padding: 9px 20px;
  border-radius: 100px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: all .3s var(--ease);
  z-index: 999;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ──────────────────────────────────────────────────
   MOBILE OVERLAY
────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 90;
}
.sidebar-overlay.active { display: block; }

/* ──────────────────────────────────────────────────
   RESPONSIVE
────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .sidebar-right { display: none; }
  .page-shell { grid-template-columns: var(--sidebar-l-w) 1fr; }
  body.sidebar-collapsed .page-shell { grid-template-columns: 0 1fr; }
}

@media (max-width: 768px) {
  :root {
    --sidebar-l-w: 260px;
    --topbar-h: 52px;
    --banner-h: 32px;
  }
  .page-shell { grid-template-columns: 1fr; }
  .sidebar-left {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--t-med) var(--ease);
    background: var(--surface);
  }
  body.mobile-sidebar-open .sidebar-left { transform: translateX(0); }
  body.mobile-sidebar-open .sidebar-overlay { display: block; }

  .topbar-nav { display: none; }
  .search-kbd { display: none; }
  .topbar-search-wrap { max-width: 200px; }

  .doc-article { padding: var(--sp-6) var(--sp-5) var(--sp-10); }
  .topic-h1 { font-size: 1.6rem; }
  .topic-pagination { padding: var(--sp-6) var(--sp-5); flex-direction: column; }
  .cheatsheet-page { padding: var(--sp-5); }
  .cs-grid { grid-template-columns: 1fr; }
  .playground-page { padding: var(--sp-5); }
  .breadcrumb-bar { display: none; }
}

@media (max-width: 480px) {
  .quiz-cta { flex-direction: column; }
  .pg-tips { flex-direction: column; gap: var(--sp-2); }
}
