/* ═══════════════════════════════════════════════════════════════════════════
   OLYMPIA SERVICES & DEVELOPMENT LLC
   Florida Building Code Reference — Visual Identity v4
   Oswald · Nunito Sans · Blueprint Gold Theme
   Brand: #FBB03B Gold · #1F1F1F Dark · #FDECB8 Cream
═══════════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  /* Brand Colors */
  --gold:         #FBB03B;
  --gold-dk:      #D9920A;
  --gold-lt:      #FDECB8;
  --gold-pale:    #FEF7E4;
  --gold-glow:    rgba(251, 176, 59, 0.20);
  --gold-border:  rgba(251, 176, 59, 0.35);
  --dark:         #1F1F1F;
  --dark-2:       #2D2D2D;
  --dark-3:       #3D3D3D;

  /* Surfaces — DARK THEME (default) */
  --bg:           #0A0A0A;
  --surface:      #111111;
  --paper:        #141414;
  --card:         #1A1A1A;
  --elevated:     #212121;
  --hdr-bg:       #0A0A0A;
  --sb-bg:        #0D0D0D;

  /* Typography — DARK THEME */
  --ink:          #E4E0D8;
  --ink-2:        #A8A49C;
  --ink-3:        #6A6666;
  --ink-4:        #484444;
  --ink-inv:      #FFFFFF;
  --ink-inv-2:    rgba(255,255,255,0.75);
  --ink-inv-3:    rgba(255,255,255,0.45);

  /* Borders — DARK THEME */
  --rule:         rgba(255,255,255,0.07);
  --rule-2:       rgba(255,255,255,0.13);
  --rule-dk:      rgba(255,255,255,0.12);

  /* Cross-reference */
  --xref:         #D4A820;
  --xref-bg:      rgba(212,168,32,0.12);
  --xref-bd:      rgba(212,168,32,0.35);

  /* Layout */
  --hdr-h:        62px;
  --sb-w:         300px;
  --toc-w:        240px;

  /* Fonts */
  --font-disp:    'Oswald', 'Arial Narrow', sans-serif;
  --font-body:    'Nunito Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', monospace;

  /* Transitions */
  --t-fast:   0.13s ease;
  --t-med:    0.22s ease;
  --t-slow:   0.35s cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows — DARK THEME */
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.35);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.60);
  --shadow-gold: 0 0 0 3px rgba(251,176,59,0.25);
}

/* ── Light Theme Override ───────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #F0EDE6;
  --surface:      #F8F6F1;
  --paper:        #FFFFFF;
  --card:         #FAFAF7;
  --elevated:     #FFFFFF;
  --hdr-bg:       #1F1F1F;
  --sb-bg:        #F8F6F1;
  --ink:          #1A1A1A;
  --ink-2:        #444444;
  --ink-3:        #777777;
  --ink-4:        #AAAAAA;
  --rule:         #E2DDD5;
  --rule-2:       #CEC7BB;
  --xref:         #B8860B;
  --xref-bg:      rgba(184,134,11,0.10);
  --xref-bd:      rgba(184,134,11,0.35);
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.16);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--gold-dk); text-decoration: none; }
button { cursor: pointer; background: none; border: none; color: inherit; font-family: var(--font-body); }
input, select { font-family: var(--font-body); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
::selection { background: var(--gold-lt); color: var(--dark); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #B0A898; }

/* ── Reading Progress Bar ─────────────────────────────────────────────── */
#reading-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 2000;
  background: transparent;
  opacity: 0;
  transition: opacity var(--t-med);
  pointer-events: none;
}
#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dk), var(--gold), var(--gold-lt));
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--gold-glow);
}

/* ── Shell ────────────────────────────────────────────────────────────── */
#shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════════════════════════════════ */
#hdr {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--hdr-h);
  min-height: var(--hdr-h);
  padding: 0 18px;
  background: var(--dark);
  border-bottom: 2px solid var(--gold);
  position: relative;
  z-index: 200;
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
}

/* Sidebar toggle */
#sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 6px;
  color: var(--ink-inv-2);
  flex-shrink: 0;
  transition: color var(--t-fast), background var(--t-fast);
}
#sidebar-toggle:hover { color: var(--gold); background: rgba(255,255,255,0.06); }
#sidebar-toggle svg { width: 20px; height: 20px; }

/* Logo */
#logo {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity var(--t-fast);
}
#logo:hover { opacity: 0.88; }

#logo-icon {
  width: 46px; height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: var(--gold);
  /* Gold circle shows as fallback when image fails to load */
}
.logo-img { width: 100%; height: 100%; object-fit: cover; display: none; }
.logo-img-dark  { display: block; }
.logo-img-light { display: none; }
[data-theme="light"] .logo-img-dark  { display: none; }
[data-theme="light"] .logo-img-light { display: block; }

#logo-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#logo-top {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  color: var(--gold);
  line-height: 1.1;
  text-transform: uppercase;
}
#logo-btm {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--ink-inv-3);
  letter-spacing: 0.03em;
  line-height: 1;
  font-weight: 400;
}

/* Search trigger */
#search-trigger {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 14px;
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: rgba(255,255,255,0.5);
  font-size: 15px;
  font-family: var(--font-body);
  font-weight: 400;
  cursor: text;
  transition: all var(--t-fast);
  max-width: 520px;
}
#search-trigger:hover {
  background: rgba(255,255,255,0.10);
  border-color: var(--gold-border);
  color: rgba(255,255,255,0.7);
}
#search-trigger svg { width: 17px; height: 17px; flex-shrink: 0; }
#search-trigger span { flex: 1; text-align: left; }
#search-trigger kbd {
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  padding: 2px 6px;
  color: rgba(255,255,255,0.4);
  flex-shrink: 0;
}

/* Header nav */
#hdr-nav {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}
.nav-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  font-family: var(--font-disp);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-inv-3);
  transition: color var(--t-fast), background var(--t-fast);
}
.nav-tab svg { width: 15px; height: 15px; }
.nav-tab:hover { color: var(--ink-inv); background: rgba(255,255,255,0.08); }
.nav-tab.active { color: var(--gold); background: rgba(251,176,59,0.12); }

/* ══════════════════════════════════════════════════════════════════════════
   BODY LAYOUT
══════════════════════════════════════════════════════════════════════════ */
#body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ══════════════════════════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════════════════════════ */
#sidebar {
  width: var(--sb-w);
  min-width: var(--sb-w);
  background: var(--sb-bg);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--t-slow), min-width var(--t-slow), opacity var(--t-slow);
  position: relative;
}
#sidebar::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, var(--gold-border), transparent 40%);
  pointer-events: none;
}
body.sb-collapsed #sidebar { width: 0; min-width: 0; opacity: 0; overflow: hidden; }

/* Sidebar search */
#sidebar-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--sb-bg);
}
#sidebar-search-wrap svg { width: 14px; height: 14px; color: var(--ink-4); flex-shrink: 0; }
#sidebar-filter {
  flex: 1;
  border: none;
  background: none;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
}
#sidebar-filter::placeholder { color: var(--ink-4); }

/* Tree */
#tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 24px;
}
.tree-group { margin-bottom: 2px; }
.tree-group-hd {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 5px;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}
.tree-group-hd:hover { background: rgba(0,0,0,0.03); }
.tree-group-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tree-group-label {
  font-family: var(--font-disp);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
  flex: 1;
}
.tree-group-count {
  font-size: 10px;
  color: var(--ink-4);
  background: var(--rule);
  border-radius: 10px;
  padding: 1px 6px;
  font-weight: 500;
}
.tree-group-arrow {
  font-size: 10px;
  color: var(--ink-4);
  transition: transform var(--t-fast);
  line-height: 1;
}
.tree-group.collapsed .tree-group-arrow { transform: rotate(-90deg); }
.tree-items { padding: 0 0 6px; }
.tree-group.collapsed .tree-items { display: none; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 10px 0 28px;
  height: 32px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-item:hover {
  background: rgba(251,176,59,0.06);
  color: var(--ink);
  border-color: var(--gold-border);
}
.tree-item.active {
  background: var(--gold-pale);
  color: var(--dark);
  border-color: var(--gold);
  font-weight: 600;
}
.tree-code-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* Chapter items under tree */
.tree-ch-list { margin: 0; }
.tree-ch-item {
  display: flex;
  align-items: center;
  padding: 0 10px 0 36px;
  height: 28px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-3);
  border-left: 3px solid transparent;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-ch-item:hover { background: rgba(251,176,59,0.05); color: var(--ink-2); border-color: var(--rule-2); }
.tree-ch-item.active { background: var(--gold-pale); color: var(--dark); border-color: var(--gold); font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════════════════════════════════════════ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  min-width: 0;
}
.view { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.view.hidden { display: none; }

/* ══════════════════════════════════════════════════════════════════════════
   HOME VIEW
══════════════════════════════════════════════════════════════════════════ */
#view-home { background: var(--bg); }
#home-scroll { flex: 1; overflow-y: auto; }
#home-inner { max-width: 1100px; margin: 0 auto; padding: 40px 40px 80px; }

/* Hero */
#home-hero {
  position: relative;
  padding: 52px 52px 52px;
  background: var(--dark);
  border-radius: 16px;
  margin-bottom: 36px;
  overflow: hidden;
}
#home-hero::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(251,176,59,0.15) 0%, transparent 70%);
  pointer-events: none;
}
#home-hero::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--gold-lt), transparent);
}

#home-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-dk);
  background: rgba(251,176,59,0.15);
  border: 1px solid var(--gold-border);
  border-radius: 20px;
  padding: 4px 12px;
  margin-bottom: 18px;
}

#home-company {
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
  opacity: 0.85;
}

#home-title {
  font-family: var(--font-disp);
  font-size: clamp(48px, 6vw, 76px);
  font-weight: 700;
  line-height: 0.92;
  color: #FFFFFF;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
}
.title-accent { color: var(--gold); }

#home-sub {
  font-size: 15px;
  color: rgba(255,255,255,0.55);
  max-width: 460px;
  line-height: 1.6;
  margin-bottom: 28px;
}

/* Home search CTA */
.home-search-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 22px;
  background: var(--gold);
  border-radius: 8px;
  font-family: var(--font-disp);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dark);
  transition: all var(--t-fast);
  box-shadow: 0 2px 12px rgba(251,176,59,0.35);
}
.home-search-cta:hover {
  background: var(--gold-dk);
  color: #fff;
  box-shadow: 0 4px 20px rgba(251,176,59,0.45);
  transform: translateY(-1px);
}
.home-search-cta svg { width: 17px; height: 17px; }
.home-search-cta kbd {
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 4px;
  padding: 2px 7px;
  color: rgba(0,0,0,0.6);
}

/* Home stats */
#home-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}
.home-stat {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 20px;
  text-align: center;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.home-stat:hover { border-color: var(--gold-border); box-shadow: var(--shadow-sm); }
.home-stat-num {
  font-family: var(--font-disp);
  font-size: 32px;
  font-weight: 700;
  color: var(--gold-dk);
  line-height: 1;
  margin-bottom: 5px;
}
.home-stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* Home group headings */
.home-group-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  margin-top: 28px;
}
.home-group-label-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
}
.home-group-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.home-group-label {
  font-family: var(--font-disp);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.home-group-count {
  font-size: 11px;
  color: var(--ink-4);
  background: var(--rule);
  border-radius: 10px;
  padding: 2px 8px;
  font-weight: 500;
}

/* Code cards */
.home-group-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.code-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  overflow: hidden;
}
.code-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-color, var(--gold));
  opacity: 0;
  transition: opacity var(--t-fast);
}
.code-card:hover {
  border-color: var(--gold-border);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.code-card:hover::before { opacity: 1; }

.code-card-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-disp);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--card-color, var(--gold));
  color: #fff;
  margin-bottom: 8px;
  opacity: 0.9;
}
.code-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
  margin-bottom: 4px;
}
.code-card-ch {
  font-size: 11px;
  color: var(--ink-4);
}

/* ══════════════════════════════════════════════════════════════════════════
   CHAPTER BAR
══════════════════════════════════════════════════════════════════════════ */
#chapter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 20px;
  background: var(--dark);
  border-bottom: 2px solid var(--gold-border);
  flex-shrink: 0;
}
#ch-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 4px 10px;
  border-radius: 5px;
  transition: background var(--t-fast);
  flex-shrink: 0;
}
#ch-back svg { width: 14px; height: 14px; }
#ch-back:hover { background: rgba(251,176,59,0.12); }

#ch-breadcrumb {
  flex: 1;
  font-size: 13.5px;
  color: rgba(255,255,255,0.45);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bc-code {
  font-family: var(--font-disp);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
}
.bc-sep { margin: 0 6px; color: rgba(255,255,255,0.25); }
.bc-title { color: rgba(255,255,255,0.65); font-size: 13px; }

#ch-external {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  transition: color var(--t-fast);
  flex-shrink: 0;
}
#ch-external svg { width: 13px; height: 13px; }
#ch-external:hover { color: var(--gold); }

/* ══════════════════════════════════════════════════════════════════════════
   CHAPTER LAYOUT
══════════════════════════════════════════════════════════════════════════ */
#chapter-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
#chapter-content-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
  max-width: 860px;
  min-width: 0;
}
#chapter-content { min-height: 400px; }

/* ── Chapter content typography ────────────────────────────────────────── */
#chapter-content h1 {
  font-family: var(--font-disp);
  font-size: 26px;
  font-weight: 700;
  color: var(--dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--gold);
}
#chapter-content h2 {
  font-family: var(--font-disp);
  font-size: 18px;
  font-weight: 700;
  color: var(--dark);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 32px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
#chapter-content h3 {
  font-family: var(--font-disp);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 22px 0 8px;
}
#chapter-content h4, #chapter-content h5, #chapter-content h6 {
  font-family: var(--font-disp);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  margin: 16px 0 6px;
  letter-spacing: 0.03em;
}
#chapter-content .sec-title {
  font-family: var(--font-disp);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dark);
}
#chapter-content .sec-ref {
  color: var(--gold-dk);
  font-weight: 700;
  margin-right: 4px;
}
#chapter-content .sec-body {
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--ink-2);
  margin: 4px 0 14px;
}
#chapter-content div {
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--ink-2);
}
#chapter-content p {
  font-size: 15.5px;
  line-height: 1.75;
  color: var(--ink-2);
  margin-bottom: 12px;
}
#chapter-content strong { color: var(--ink); font-weight: 600; }
#chapter-content em { font-style: italic; color: var(--ink); }

/* Tables */
#chapter-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  border-radius: 8px;
  overflow: hidden;
}
#chapter-content thead tr {
  background: var(--dark);
  color: #fff;
}
#chapter-content th {
  padding: 11px 14px;
  text-align: left;
  font-family: var(--font-disp);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: none;
  color: var(--gold-lt);
}
#chapter-content td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-2);
  vertical-align: top;
}
#chapter-content tbody tr:nth-child(even) { background: var(--card); }
#chapter-content tbody tr:hover { background: var(--gold-pale); }
#chapter-content tbody tr:last-child td { border-bottom: none; }

/* Cross-reference links */
#chapter-content a.crossref {
  color: var(--xref);
  border-bottom: 1.5px dotted var(--xref-bd);
  transition: background var(--t-fast), color var(--t-fast);
  padding: 0 1px;
  border-radius: 2px;
}
#chapter-content a.crossref:hover {
  background: var(--xref-bg);
  color: var(--xref);
}
#chapter-content a.ext-link {
  color: var(--gold-dk);
  border-bottom: 1px solid var(--gold-border);
}
#chapter-content a.autolink,
#chapter-content a.autolink_target {
  color: var(--xref);
  border-bottom: 1px dotted var(--xref-bd);
}

/* Informational notes */
#chapter-content .u-text-12px,
#chapter-content [class*="u-text-12"] {
  font-size: 13.5px !important;
  line-height: 1.65;
  color: var(--ink-3);
  background: var(--gold-pale);
  border-left: 3px solid var(--gold);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  margin: 12px 0;
  font-style: italic;
}
#chapter-content [class*="u-indent"] { padding-left: 24px; }
#chapter-content [class*="u-mt"] { margin-top: 10px; }
#chapter-content [class*="u-mb"] { margin-bottom: 10px; }

/* Empty chapter */
.empty-chapter {
  padding: 48px;
  text-align: center;
  color: var(--ink-4);
  font-style: italic;
  font-size: 15px;
}

/* ── Chapter TOC ─────────────────────────────────────────────────────── */
#ch-toc {
  width: var(--toc-w);
  min-width: var(--toc-w);
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  padding: 24px 0;
  background: var(--surface);
  flex-shrink: 0;
}
#ch-toc-label {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 8px;
}
.toc-item {
  display: block;
  padding: 5px 16px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.4;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all var(--t-fast);
}
.toc-item:hover { color: var(--ink); background: rgba(251,176,59,0.05); border-color: var(--gold-border); }
.toc-item.active { color: var(--gold-dk); background: var(--gold-pale); border-color: var(--gold); font-weight: 600; }
.toc-item.depth-2 { padding-left: 24px; font-size: 12px; }
.toc-item.depth-3 { padding-left: 32px; font-size: 11.5px; color: var(--ink-4); }

/* ══════════════════════════════════════════════════════════════════════════
   SEARCH OVERLAY
══════════════════════════════════════════════════════════════════════════ */
#search-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
#search-overlay.hidden { display: none; }
#search-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 15, 0.75);
  backdrop-filter: blur(4px);
}
#search-modal {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 680px;
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(251,176,59,0.2);
  overflow: hidden;
  border-top: 3px solid var(--gold);
  animation: searchIn 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes searchIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#search-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--rule);
  height: 60px;
}
#search-input-wrap svg { width: 20px; height: 20px; color: var(--gold); flex-shrink: 0; }
#search-field {
  flex: 1;
  border: none;
  background: none;
  font-size: 18px;
  font-family: var(--font-body);
  color: var(--ink);
  outline: none;
  font-weight: 400;
}
#search-field::placeholder { color: var(--ink-4); }
#search-esc {
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 3px 8px;
  color: var(--ink-4);
  flex-shrink: 0;
}
#search-esc:hover { background: var(--dark); color: var(--gold); border-color: var(--gold-border); }

#search-filters {
  display: flex;
  gap: 6px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--rule);
}
.sf {
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 5px;
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--rule);
  transition: all var(--t-fast);
}
.sf:hover { border-color: var(--gold-border); color: var(--ink); }
.sf.active { background: var(--gold); color: var(--dark); border-color: var(--gold); }

#search-results {
  max-height: 420px;
  overflow-y: auto;
}
.sr-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
  transition: background var(--t-fast);
}
.sr-item:hover, .sr-item.focused { background: var(--gold-pale); }
.sr-item:last-child { border-bottom: none; }

.sr-icon {
  width: 32px; height: 32px;
  border-radius: 7px;
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sr-icon svg { width: 15px; height: 15px; color: var(--gold); }
.sr-diag-icon { background: rgba(251,176,59,0.12); }
.sr-diag-icon svg { color: var(--gold-dk); }

.sr-body { flex: 1; min-width: 0; }
.sr-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.sr-meta {
  font-size: 12px;
  color: var(--ink-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sr-code {
  font-family: var(--font-disp);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold-dk);
  text-transform: uppercase;
}
.sr-arrow { color: var(--ink-4); font-size: 14px; }
mark { background: var(--gold-lt); color: var(--dark); border-radius: 2px; padding: 0 1px; }

.sr-empty {
  padding: 48px 18px;
  text-align: center;
  color: var(--ink-4);
  font-size: 15px;
}
.sr-prompt {
  padding: 32px 18px;
  text-align: center;
  color: var(--ink-4);
  font-size: 14px;
}

#search-footer {
  display: flex;
  gap: 16px;
  padding: 10px 18px;
  border-top: 1px solid var(--rule);
  background: var(--surface);
}
#search-footer span {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-4);
}
#search-footer kbd {
  font-size: 10px;
  font-family: var(--font-mono);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--ink-3);
}

/* ══════════════════════════════════════════════════════════════════════════
   LIGHTBOX (DIAGRAMS)
══════════════════════════════════════════════════════════════════════════ */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#lightbox.hidden { display: none; }
#lb-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.80);
  backdrop-filter: blur(4px);
}
#lb-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1100px;
  max-height: calc(100vh - 48px);
  background: var(--paper);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  border-top: 3px solid var(--gold);
}
#lb-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  height: 50px;
  border-bottom: 1px solid var(--rule);
  background: var(--dark);
  flex-shrink: 0;
}
#lb-title {
  flex: 1;
  font-family: var(--font-disp);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold-lt);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#lb-head-tags { display: flex; gap: 6px; }
#lb-close {
  width: 30px; height: 30px;
  border-radius: 6px;
  color: rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
#lb-close:hover { background: rgba(255,255,255,0.1); color: #fff; }
#lb-close svg { width: 16px; height: 16px; }

#lb-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
#lb-canvas {
  flex: 1;
  overflow: auto;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#lb-img { max-width: 100%; max-height: 100%; object-fit: contain; }
#lb-info {
  width: 260px;
  border-left: 1px solid var(--rule);
  padding: 20px;
  overflow-y: auto;
  flex-shrink: 0;
}
#lb-info h4 {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-bottom: 8px;
}
#lb-info p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 18px;
}
#lb-phases { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 18px; }
.lb-phase-tag {
  font-size: 11px;
  background: var(--gold-pale);
  color: var(--gold-dk);
  border-radius: 4px;
  padding: 3px 8px;
  font-weight: 500;
}
#lb-open {
  display: block;
  text-align: center;
  padding: 10px;
  background: var(--dark);
  color: var(--gold);
  border-radius: 6px;
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: all var(--t-fast);
}
#lb-open:hover { background: var(--dark-2); }

/* ══════════════════════════════════════════════════════════════════════════
   ASSEMBLIES VIEW
══════════════════════════════════════════════════════════════════════════ */
#view-assemblies { overflow: hidden; }
#asm-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  flex-shrink: 0;
}
#asm-bar-left { flex-shrink: 0; }
#asm-heading {
  font-family: var(--font-disp);
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dark);
  line-height: 1;
}
#asm-count {
  font-size: 12px;
  color: var(--ink-4);
  display: block;
  margin-top: 2px;
}
#asm-bar-center { flex: 1; }
#asm-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 0 12px;
  height: 38px;
  transition: border-color var(--t-fast);
}
#asm-search-wrap:focus-within { border-color: var(--gold); box-shadow: var(--shadow-gold); }
#asm-search-wrap svg { width: 14px; height: 14px; color: var(--ink-4); flex-shrink: 0; }
#asm-search {
  flex: 1;
  border: none;
  background: none;
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
#asm-search-clear {
  font-size: 12px;
  color: var(--ink-4);
  padding: 2px 6px;
  border-radius: 4px;
}
#asm-search-clear:hover { background: var(--rule); color: var(--ink); }
#asm-bar-right { flex-shrink: 0; }
#asm-filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 7px;
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--surface);
  border: 1.5px solid var(--rule);
  color: var(--ink-3);
  transition: all var(--t-fast);
}
#asm-filter-toggle.active { background: var(--gold-pale); border-color: var(--gold-border); color: var(--gold-dk); }
#asm-filter-toggle svg { width: 14px; height: 14px; }

#asm-publishers {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.asm-pub-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--paper);
  border: 1.5px solid var(--rule);
  transition: all var(--t-fast);
  font-weight: 500;
}
.asm-pub-pill:hover { border-color: var(--gold-border); color: var(--ink); }
.asm-pub-pill.active { background: var(--gold); border-color: var(--gold); color: var(--dark); font-weight: 700; }
.pub-badge {
  font-family: var(--font-disp);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}
.pub-ul { background: var(--dark); color: var(--gold); }
.pub-ga { background: #1565C0; color: #fff; }
.pub-up { background: #2E7D32; color: #fff; }
.asm-pub-count { font-size: 11px; color: var(--ink-4); }

#asm-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#asm-filters {
  width: 240px;
  min-width: 240px;
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  background: var(--surface);
  flex-shrink: 0;
  transition: width var(--t-slow), min-width var(--t-slow), opacity var(--t-slow);
}
#asm-filters.hidden { width: 0; min-width: 0; opacity: 0; overflow: hidden; }
#asm-filters-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
#asm-filters-clear {
  font-size: 11px;
  color: var(--gold-dk);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: none;
  font-family: var(--font-body);
}
#asm-filters-clear:hover { text-decoration: underline; }

.asm-filter-section { border-bottom: 1px solid var(--rule); }
.asm-filter-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--font-disp);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: background var(--t-fast);
}
.asm-filter-hd:hover { background: rgba(0,0,0,0.03); }
.asm-filter-items { padding: 4px 8px 8px; }
.asm-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-2);
  transition: background var(--t-fast);
}
.asm-filter-item:hover { background: rgba(251,176,59,0.07); }
.asm-filter-item input[type=checkbox] { accent-color: var(--gold); width: 14px; height: 14px; }
.asm-filter-item.active { color: var(--gold-dk); font-weight: 600; }

#asm-main { flex: 1; overflow-y: auto; padding: 20px; }
#asm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

/* Assembly card */
.asm-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all var(--t-fast);
}
.asm-card:hover {
  border-color: var(--gold-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.asm-card-thumb {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 130px;
  overflow: hidden;
}
.asm-card-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 8px; }
.asm-card-body { padding: 10px 12px; }
.asm-card-pub {
  font-family: var(--font-disp);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-bottom: 4px;
}
.asm-card-key {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold-dk);
  margin-bottom: 4px;
  font-family: var(--font-mono);
}
.asm-card-title {
  font-size: 12px;
  color: var(--ink-2);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#asm-load-more-wrap { padding: 24px; text-align: center; }
#asm-load-more {
  height: 40px;
  padding: 0 24px;
  background: var(--dark);
  color: var(--gold);
  border-radius: 7px;
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all var(--t-fast);
}
#asm-load-more:hover { background: var(--gold); color: var(--dark); }

/* ══════════════════════════════════════════════════════════════════════════
   ASSEMBLY DETAIL
══════════════════════════════════════════════════════════════════════════ */
#asm-detail {
  position: fixed;
  inset: 0;
  z-index: 7000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#asm-detail.hidden { display: none; }
#asm-detail-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(3px);
}
#asm-detail-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1000px;
  max-height: calc(100vh - 48px);
  background: var(--paper);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  border-top: 3px solid var(--gold);
}
#asm-detail-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 50px;
  border-bottom: 1px solid var(--rule);
  background: var(--dark);
  flex-shrink: 0;
}
#asm-detail-hd-left { display: flex; align-items: center; gap: 10px; }
#asm-detail-pub-badge {
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--gold);
  color: var(--dark);
}
#asm-detail-title {
  font-family: var(--font-disp);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold-lt);
  text-transform: uppercase;
}
#asm-detail-hd-right { display: flex; align-items: center; gap: 4px; }
#asm-detail-ext {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  padding: 0 10px;
  height: 32px;
  border-radius: 5px;
  transition: all var(--t-fast);
}
#asm-detail-ext svg { width: 13px; height: 13px; }
#asm-detail-ext:hover { color: var(--gold); background: rgba(255,255,255,0.06); }
#asm-detail-prev, #asm-detail-next, #asm-detail-close {
  width: 32px; height: 32px;
  border-radius: 6px;
  color: rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
#asm-detail-prev:hover, #asm-detail-next:hover { background: rgba(255,255,255,0.08); color: #fff; }
#asm-detail-close:hover { background: rgba(255,80,80,0.15); color: #ff6b6b; }
#asm-detail-prev svg, #asm-detail-next svg, #asm-detail-close svg { width: 14px; height: 14px; }

#asm-detail-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
#asm-detail-img-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  background: var(--surface);
}
#asm-detail-img { max-width: 100%; max-height: 500px; object-fit: contain; }
#asm-detail-caption { font-size: 11px; color: var(--ink-4); margin-top: 8px; text-align: center; }
#asm-detail-info {
  width: 300px;
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  padding: 20px;
  flex-shrink: 0;
}
#asm-detail-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 16px; }
.asm-tag {
  font-size: 11px;
  background: var(--gold-pale);
  color: var(--gold-dk);
  border: 1px solid var(--gold-border);
  border-radius: 4px;
  padding: 3px 8px;
  font-weight: 500;
}
#asm-detail-metrics { margin-bottom: 16px; }
.asm-metric {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}
.asm-metric-label { color: var(--ink-4); font-family: var(--font-disp); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 600; }
.asm-metric-val { color: var(--ink); font-weight: 600; }
#asm-detail-summary { font-size: 13.5px; line-height: 1.65; color: var(--ink-2); margin-bottom: 16px; }

/* Assembly rich detail */
.asm-overview-html { font-size: 13.5px; line-height: 1.65; color: var(--ink-2); }
.asm-sections-wrap { margin-top: 12px; }
.asm-sec-item {
  border: 1px solid var(--rule);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}
.asm-sec-title {
  font-family: var(--font-disp);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-inv);
  background: var(--dark);
  padding: 8px 12px;
}
.asm-sec-body { font-size: 12.5px; line-height: 1.6; color: var(--ink-2); padding: 10px 12px; }
.asm-sec-sub { padding-left: 16px; border-left: 2px solid var(--gold-border); margin: 8px 12px; }
.asm-sec-products { padding: 8px 12px; border-top: 1px solid var(--rule); background: var(--surface); }
.asm-prod-mfr { font-size: 11px; font-weight: 700; color: var(--gold-dk); text-transform: uppercase; letter-spacing: 0.05em; }
.asm-prod-name { font-size: 12px; color: var(--ink-2); }
.asm-detail-gallery { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.asm-last-updated { font-size: 11px; color: var(--ink-4); padding-top: 12px; border-top: 1px solid var(--rule); margin-top: 12px; }

/* ══════════════════════════════════════════════════════════════════════════
   DIAGRAMS VIEW
══════════════════════════════════════════════════════════════════════════ */
#view-diagrams { overflow: hidden; }
#diag-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  flex-shrink: 0;
  flex-wrap: wrap;
}
#diag-heading {
  font-family: var(--font-disp);
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--dark);
}
#diag-controls { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
#diag-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--rule);
  border-radius: 7px;
  padding: 0 12px;
  height: 36px;
  flex: 1;
  min-width: 160px;
  transition: border-color var(--t-fast);
}
#diag-search-wrap:focus-within { border-color: var(--gold); }
#diag-search-wrap svg { width: 13px; height: 13px; color: var(--ink-4); flex-shrink: 0; }
#diag-search { flex: 1; border: none; background: none; font-size: 14px; color: var(--ink); outline: none; }
.diag-sel {
  height: 36px;
  padding: 0 10px;
  border: 1.5px solid var(--rule);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--t-fast);
}
.diag-sel:focus { border-color: var(--gold); }
#diag-count { font-size: 12px; color: var(--ink-4); flex-shrink: 0; }

#diag-grid-outer { flex: 1; overflow-y: auto; padding: 20px; }
#diag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.diag-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all var(--t-fast);
}
.diag-card:hover {
  border-color: var(--gold-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.diag-thumb {
  height: 120px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.diag-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 8px; }
.diag-info { padding: 10px 12px; }
.diag-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 4px;
}
.diag-topics { display: flex; flex-wrap: wrap; gap: 4px; }
.diag-topic {
  font-size: 10.5px;
  background: var(--gold-pale);
  color: var(--gold-dk);
  border-radius: 3px;
  padding: 2px 6px;
  font-weight: 500;
}

/* ══════════════════════════════════════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--ink-4);
  font-size: 14px;
  gap: 10px;
}
.loading-spinner::before {
  content: '';
  width: 20px; height: 20px;
  border: 2px solid var(--rule);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════════════
   APP.JS GENERATED CLASSES — SIDEBAR TREE
══════════════════════════════════════════════════════════════════════════ */
/* Tree group */
.tg { margin-bottom: 4px; }
.tg-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px 8px;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}
.tg-hd:hover { background: rgba(255,255,255,0.04); }
[data-theme="light"] .tg-hd:hover { background: rgba(0,0,0,0.04); }
.tg-hd.open .chev { transform: rotate(90deg); }
.tg-hd .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tg-hd .chev {
  display: flex;
  align-items: center;
  color: var(--ink-4);
  transition: transform var(--t-fast);
  flex-shrink: 0;
  margin-left: auto;
}
.tg-hd .chev svg { width: 11px; height: 11px; }
.tg-label {
  font-family: var(--font-disp);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  flex: 1;
}
.tg-count {
  font-size: 10.5px;
  color: var(--ink-4);
  background: var(--rule);
  border-radius: 10px;
  padding: 2px 7px;
  font-weight: 500;
}
.tg-codes { display: none; }
.tg-codes.vis { display: block; padding-bottom: 4px; }

/* Tree code item */
.tc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 26px;
  height: 38px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 400;
}
.tc:hover { background: rgba(251,176,59,0.08); color: var(--ink); border-color: var(--gold-border); }
.tc.active { background: var(--gold-pale); color: var(--dark); border-color: var(--gold); font-weight: 600; }
.tc-chev {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  color: var(--ink-4);
  flex-shrink: 0;
  transition: transform var(--t-fast);
}
.tc-chev svg { width: 10px; height: 10px; }
.tc.open .tc-chev { transform: rotate(90deg); }
.tc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-count {
  font-size: 10.5px;
  color: var(--ink-4);
  background: var(--rule);
  border-radius: 8px;
  padding: 2px 6px;
  flex-shrink: 0;
}

/* Tree chapters */
.tc-chapters { display: none; }
.tc-chapters.vis {
  display: block;
  margin: 0 8px 6px 28px;
  background: rgba(255,255,255,0.025);
  border-left: 2px solid rgba(251,176,59,0.25);
  border-radius: 0 4px 4px 0;
}
[data-theme="light"] .tc-chapters.vis {
  background: rgba(0,0,0,0.03);
  border-left-color: rgba(184,134,11,0.3);
}
.tch {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-3);
  border-bottom: 1px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: normal;
  line-height: 1.4;
}
.tch:last-child { border-bottom: none; }
.tch:hover { background: rgba(251,176,59,0.06); color: var(--ink-2); }
.tch.active { background: rgba(251,176,59,0.12); color: var(--gold); font-weight: 600; }
[data-theme="light"] .tch.active { background: var(--gold-pale); color: var(--dark); }
.tch-ref {
  font-family: var(--font-disp);
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-dk);
  flex-shrink: 0;
  min-width: 28px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-top: 1px;
}

/* ── HOME CARDS (app.js generated) ──────────────────────────────────────── */
.home-group {
  animation: fadeUp 0.4s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.home-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 10px;
}
.home-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--group-color, var(--gold));
  opacity: 0;
  transition: opacity var(--t-fast);
}
.home-card:hover { border-color: var(--gold-border); background: #fff; box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.home-card:hover::before { opacity: 1; }
.hc-accent {
  width: 4px; height: 36px;
  border-radius: 2px;
  background: var(--group-color, var(--gold));
  flex-shrink: 0;
  opacity: 0.7;
}
.hc-body { flex: 1; min-width: 0; }
.hc-title { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.3; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-meta { font-size: 11px; color: var(--ink-4); }
.hc-arrow { width: 14px; height: 14px; color: var(--ink-4); flex-shrink: 0; transition: color var(--t-fast), transform var(--t-fast); }
.home-card:hover .hc-arrow { color: var(--gold-dk); transform: translateX(2px); }
.hc-badge {
  font-family: var(--font-disp);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--group-color, var(--gold));
  color: #fff;
  flex-shrink: 0;
  opacity: 0.85;
}

/* ── STATS (app.js generated) ─────────────────────────────────────────── */
.stat-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 18px 20px;
  text-align: center;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.stat-card:hover { border-color: var(--gold-border); box-shadow: var(--shadow-sm); }
.stat-num {
  font-family: var(--font-disp);
  font-size: 32px;
  font-weight: 700;
  color: var(--gold-dk);
  line-height: 1;
  display: block;
  margin-bottom: 5px;
}
.stat-lbl {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ── RECENTLY VIEWED ─────────────────────────────────────────────────── */
.home-recent-card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all var(--t-fast);
  display: flex;
  align-items: center;
  gap: 10px;
}
.home-recent-card:hover { border-color: var(--gold-border); background: #fff; box-shadow: var(--shadow-sm); }
.rc-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); flex-shrink: 0; }
.rc-body { flex: 1; min-width: 0; }
.rc-code { font-family: var(--font-disp); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-dk); }
.rc-title { font-size: 12.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── DIAGRAM CARDS (dc) ───────────────────────────────────────────────── */
.dc {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: all var(--t-fast);
}
.dc:hover { border-color: var(--gold-border); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.dc-thumb {
  height: 120px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.dc-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 8px; }
.dc-info { padding: 10px 12px; }
.dc-title { font-size: 12.5px; font-weight: 600; color: var(--ink); line-height: 1.35; margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.dc-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.dc-tag { font-size: 10.5px; background: var(--gold-pale); color: var(--gold-dk); border-radius: 3px; padding: 2px 6px; font-weight: 500; }

/* ── ASSEMBLY FILTER GROUPS ───────────────────────────────────────────── */
.afg { border-bottom: 1px solid var(--rule); }
.afg-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--font-disp);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  transition: background var(--t-fast);
}
.afg-hd:hover { background: rgba(0,0,0,0.03); }
.afg-hd .afg-chev { font-size: 10px; color: var(--ink-4); transition: transform var(--t-fast); }
.afg-hd.open .afg-chev { transform: rotate(90deg); }
.afg-body { display: none; padding: 4px 8px 8px; }
.afg-body.vis { display: block; }
.afo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-2);
  transition: background var(--t-fast);
}
.afo:hover { background: rgba(251,176,59,0.07); }
.afo.active { color: var(--gold-dk); font-weight: 600; }
.afo-num { font-size: 11px; color: var(--ink-4); margin-left: auto; }
.afo-label { flex: 1; }

/* ── ASSEMBLY CARD CLASSES ─────────────────────────────────────────────── */
.asm-card-body { padding: 10px 12px; }
.asm-card-metric { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; border-bottom: 1px solid var(--rule); }
.asm-card-metrics { margin: 8px 0; }
.asm-card-tag { font-size: 10px; padding: 2px 6px; border-radius: 3px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.tag-hr { background: var(--dark); color: var(--gold); }
.tag-type { background: var(--gold-pale); color: var(--gold-dk); }
.asm-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.asm-card-title { font-size: 12px; color: var(--ink-2); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.asm-card-img-placeholder { height: 130px; background: var(--surface); display: flex; align-items: center; justify-content: center; color: var(--ink-4); font-size: 12px; }
.asm-ph-guide::after { content: 'Loading…'; font-style: italic; }
.asm-ph-noimg::after { content: 'No image'; }
.asm-detail-ph { font-size: 12px; color: var(--ink-4); padding: 24px; text-align: center; }
.asm-detail-ph-icon { font-size: 32px; margin-bottom: 8px; }
.asm-detail-ph-type, .asm-ph-code, .asm-detail-ph-code, .asm-detail-ph-desc { font-size: 12px; color: var(--ink-4); display: block; }
.asm-ph-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-4); }
.asm-gallery-img { width: 80px; height: 80px; object-fit: contain; border: 1px solid var(--rule); border-radius: 6px; cursor: pointer; }
.asm-metric-mfr { font-weight: 700; font-size: 12px; }
.asm-metric-name { font-size: 12px; color: var(--ink-2); }
.asm-metric-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 12.5px; }
.asm-metrics-label { font-family: var(--font-disp); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-4); margin: 12px 0 6px; }
.asm-overview-html { font-size: 13.5px; line-height: 1.65; color: var(--ink-2); }
.asm-disc-text { font-size: 11.5px; color: var(--ink-4); font-style: italic; line-height: 1.6; padding: 10px 0; border-top: 1px solid var(--rule); margin-top: 12px; }
.asm-empty { padding: 48px 20px; text-align: center; color: var(--ink-4); font-size: 14px; }
.asm-std-badge { font-size: 11px; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 3px 8px; color: var(--ink-3); font-weight: 500; display: inline-block; margin: 3px 2px; }
.asm-sum-hdr { font-family: var(--font-disp); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-4); margin: 12px 0 6px; }
.asm-sum-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.asm-sum-lbl { color: var(--ink-4); }
.asm-sum-val { color: var(--ink); font-weight: 600; }
.asm-sum-p { font-size: 13px; color: var(--ink-2); line-height: 1.6; margin: 8px 0; }
.asm-sum-adopted { font-size: 11px; color: var(--gold-dk); font-weight: 600; background: var(--gold-pale); border-radius: 4px; padding: 4px 10px; display: inline-block; margin-top: 8px; }
.asm-ul-note { font-size: 11.5px; color: var(--ink-4); font-style: italic; margin-top: 10px; }
.asm-summary-body { font-size: 13.5px; line-height: 1.65; color: var(--ink-2); }
.asm-summary-label { font-family: var(--font-disp); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-4); margin: 14px 0 6px; }
.asm-sec-product { padding: 6px 0; border-bottom: 1px solid var(--rule); }
.asm-sec-product:last-child { border-bottom: none; }
.asm-sec-sub { padding: 6px 10px; border-left: 2px solid var(--gold-border); margin: 6px 12px; }

/* ── SEARCH RESULT EXTRAS ─────────────────────────────────────────────── */
.sr-badge { font-size: 10px; font-weight: 700; font-family: var(--font-disp); letter-spacing: 0.06em; text-transform: uppercase; background: var(--gold-pale); color: var(--gold-dk); padding: 2px 6px; border-radius: 3px; }
.sr-ch { font-size: 11px; color: var(--gold-dk); font-weight: 600; margin-top: 2px; }
.sr-excerpt { font-size: 12px; color: var(--ink-3); line-height: 1.5; margin-top: 3px; }
.sr-label { font-size: 10px; color: var(--ink-4); text-transform: uppercase; letter-spacing: 0.08em; }
.hl { background: var(--gold-lt); color: var(--dark); border-radius: 2px; padding: 0 1px; }

/* ── CHAPTER CONTENT INNER ────────────────────────────────────────────── */
.ch-inner { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── CHAPTER FIGURES — paper card with hover + lightbox ──────────────── */
#chapter-content figure {
  position: relative;
  display: block;
  margin: 28px auto;
  padding: 20px 20px 14px;
  text-align: center;
  background: #FFFFFF;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  cursor: zoom-in;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.22s ease,
              border-color 0.22s ease;
  max-width: 100%;
  overflow: hidden;
}
#chapter-content figure:hover {
  transform: scale(1.025) translateY(-2px);
  box-shadow: 0 8px 32px rgba(251,176,59,0.28), 0 2px 8px rgba(0,0,0,0.12);
  border-color: var(--gold);
}
#chapter-content figure::after {
  content: '⤢';
  position: absolute;
  top: 8px; right: 10px;
  font-size: 14px;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
  line-height: 1;
}
#chapter-content figure:hover::after { opacity: 1; }
#chapter-content figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}
#chapter-content figcaption {
  margin-top: 10px;
  font-size: 12.5px;
  color: #666;
  font-style: italic;
  line-height: 1.4;
}

/* Dark mode: figures glow like lit documents in a dark room */
[data-theme="dark"] #chapter-content figure {
  background: #F5F2EC;
  border-color: rgba(251,176,59,0.2);
  box-shadow: 0 0 0 1px rgba(251,176,59,0.12),
              0 4px 24px rgba(0,0,0,0.55),
              0 1px 4px rgba(0,0,0,0.4);
}
[data-theme="dark"] #chapter-content figure:hover {
  box-shadow: 0 0 0 2px var(--gold),
              0 0 40px rgba(251,176,59,0.18),
              0 8px 32px rgba(0,0,0,0.65);
  border-color: var(--gold);
}
[data-theme="dark"] #chapter-content figcaption { color: #888; }

/* ── FIGURE LIGHTBOX ──────────────────────────────────────────────────── */
#fig-lb {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: zoom-out;
  animation: figLbIn 0.22s ease;
}
#fig-lb.open { display: flex; }
@keyframes figLbIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#fig-lb-card {
  position: relative;
  background: #FFFFFF;
  border-radius: 12px;
  padding: 24px;
  max-width: min(90vw, 1100px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 0 0 1px rgba(251,176,59,0.3),
              0 32px 80px rgba(0,0,0,0.7);
  cursor: default;
  animation: figLbCardIn 0.25s cubic-bezier(0.34,1.3,0.64,1);
  text-align: center;
}
@keyframes figLbCardIn {
  from { transform: scale(0.88); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
#fig-lb-img {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
#fig-lb-caption {
  margin-top: 12px;
  font-size: 13px;
  color: #555;
  font-style: italic;
  line-height: 1.5;
}
#fig-lb-close {
  position: absolute;
  top: 10px; right: 12px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(0,0,0,0.08);
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #444;
  transition: background 0.15s ease, transform 0.15s ease;
  line-height: 1;
  padding: 0;
}
#fig-lb-close:hover { background: rgba(251,176,59,0.2); transform: scale(1.1); }
.loading { display: flex; align-items: center; justify-content: center; min-height: 200px; }
.error-state { padding: 60px 40px; text-align: center; }
.error-state h2 { font-family: var(--font-disp); font-size: 20px; color: var(--ink); margin-bottom: 10px; }
.error-state p { font-size: 14px; color: var(--ink-3); line-height: 1.7; }
.error-state code { background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 2px 8px; font-family: var(--font-mono); font-size: 13px; color: var(--gold-dk); }

/* ── BODY SIDEBAR COLLAPSE ────────────────────────────────────────────── */
body.sidebar-collapsed #sidebar { width: 0; min-width: 0; overflow: hidden; }

/* ══════════════════════════════════════════════════════════════════════════
   DARK-MODE SPECIFIC OVERRIDES
   Fix elements that use var(--dark) as text/heading colour —
   those would be near-invisible black on dark backgrounds.
══════════════════════════════════════════════════════════════════════════ */
[data-theme="dark"] #chapter-content h1,
[data-theme="dark"] #chapter-content h2 { color: var(--gold); }
[data-theme="dark"] #chapter-content .sec-title { color: var(--gold); }
[data-theme="dark"] #asm-heading { color: var(--ink); }

/* Active states: swap light-yellow bg for dark gold tint */
[data-theme="dark"] .tree-item.active  { background: rgba(251,176,59,0.13); color: var(--gold); border-color: var(--gold); }
[data-theme="dark"] .tree-ch-item.active { background: rgba(251,176,59,0.10); color: var(--gold); border-color: var(--gold); }
[data-theme="dark"] .toc-item.active   { background: rgba(251,176,59,0.10); color: var(--gold); border-color: var(--gold); }
[data-theme="dark"] #asm-filter-toggle.active { background: rgba(251,176,59,0.12); border-color: var(--gold-border); color: var(--gold); }

/* Hover backgrounds that use hardcoded light colours */
[data-theme="dark"] .code-card:hover   { background: #252525; }
[data-theme="dark"] .sr-item:hover,
[data-theme="dark"] .sr-item.focused   { background: rgba(251,176,59,0.08); }
[data-theme="dark"] #chapter-content tbody tr:hover { background: rgba(251,176,59,0.06); }
[data-theme="dark"] #chapter-content tbody tr:nth-child(even) { background: rgba(255,255,255,0.03); }
[data-theme="dark"] #chapter-content .u-text-12px,
[data-theme="dark"] #chapter-content [class*="u-text-12"] { background: rgba(251,176,59,0.07); }
[data-theme="dark"] .lb-phase-tag { background: rgba(251,176,59,0.12); color: var(--gold); }
[data-theme="dark"] mark { background: rgba(251,176,59,0.22); color: var(--gold-lt); }
[data-theme="dark"] .hl  { background: rgba(251,176,59,0.22); color: var(--gold-lt); }
[data-theme="dark"] .sr-badge { background: rgba(251,176,59,0.10); color: var(--gold); }
[data-theme="dark"] .tree-group-hd:hover { background: rgba(255,255,255,0.04); }

/* Light-theme-only: active states that look correct with light bg */
[data-theme="light"] .tree-item.active  { background: var(--gold-pale); color: var(--dark); border-color: var(--gold); }
[data-theme="light"] .tree-ch-item.active { background: var(--gold-pale); color: var(--dark); border-color: var(--gold); }
[data-theme="light"] .toc-item.active   { background: var(--gold-pale); color: var(--dark); border-color: var(--gold); }

/* ══════════════════════════════════════════════════════════════════════════
   SETTINGS PANEL
══════════════════════════════════════════════════════════════════════════ */
#settings-wrap {
  position: relative;
  flex-shrink: 0;
}

#settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 6px;
  color: var(--ink-inv-2);
  transition: color var(--t-fast), background var(--t-fast);
}
#settings-btn:hover { color: var(--gold); background: rgba(255,255,255,0.06); }
#settings-btn.open  { color: var(--gold); background: rgba(251,176,59,0.12); }
#settings-btn svg { width: 18px; height: 18px; }

/* ── Admin panel link ──────────────────────────────────────────────────── */
#admin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 6px;
  color: var(--gold);
  flex-shrink: 0;
  opacity: 0.7;
  transition: color var(--t-fast), background var(--t-fast), opacity var(--t-fast);
  text-decoration: none;
}
#admin-link:hover {
  background: rgba(251,176,59,0.12);
  opacity: 1;
}
#admin-link svg { width: 18px; height: 18px; }

/* ── Logout button ─────────────────────────────────────────────────────── */
#logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 6px;
  color: var(--ink-inv-3);
  flex-shrink: 0;
  transition: color var(--t-fast), background var(--t-fast);
}
#logout-btn:hover {
  color: #EF9090;
  background: rgba(220,38,38,0.1);
}
#logout-btn svg { width: 18px; height: 18px; }

#settings-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 228px;
  background: #1A1A1A;
  border: 1px solid rgba(255,255,255,0.11);
  border-top: 2px solid var(--gold);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.65), 0 2px 8px rgba(0,0,0,0.4);
  overflow: hidden;
  z-index: 500;
  animation: spIn 0.16s cubic-bezier(0.4,0,0.2,1);
}
#settings-panel.hidden { display: none; }
@keyframes spIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.sp-header {
  padding: 10px 14px 9px;
  font-family: var(--font-disp);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.sp-section {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sp-section:last-child { border-bottom: none; }

.sp-section-label {
  font-family: var(--font-disp);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.30);
  margin-bottom: 9px;
}

.sp-opts {
  display: flex;
  gap: 6px;
}

.sp-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 34px;
  border-radius: 6px;
  font-family: var(--font-disp);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.40);
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  transition: all var(--t-fast);
  cursor: pointer;
  position: relative;
}
.sp-opt:hover:not(:disabled) { color: rgba(255,255,255,0.80); background: rgba(255,255,255,0.09); }
.sp-opt.active {
  background: rgba(251,176,59,0.16);
  border-color: rgba(251,176,59,0.40);
  color: var(--gold);
}
.sp-opt:disabled { opacity: 0.30; cursor: not-allowed; }
.sp-opt svg { width: 13px; height: 13px; flex-shrink: 0; }

.sp-soon {
  position: absolute;
  top: -7px; right: -3px;
  font-size: 7px;
  font-family: var(--font-disp);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(251,176,59,0.22);
  color: var(--gold);
  border-radius: 3px;
  padding: 1px 4px;
  pointer-events: none;
}


/* ══════════════════════════════════════════════════════════════════════════
   WEATHER WIDGET  — hover to expand, no API key (Open-Meteo)
══════════════════════════════════════════════════════════════════════════ */
#wx-widget {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 9100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ── Compact pill (always visible) ──────────────────────────────────── */
#wx-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px 7px 10px;
  border-radius: 30px;
  cursor: default;
  user-select: none;
  white-space: nowrap;

  /* DARK default — vivid gold */
  background: rgba(251,176,59,0.15);
  border: 1.5px solid #FBB03B;
  box-shadow: 0 0 12px rgba(251,176,59,0.35), 0 3px 12px rgba(0,0,0,0.45);
  color: #FBB03B;

  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
#wx-pill:hover { transform: scale(1.05); box-shadow: 0 0 20px rgba(251,176,59,0.55), 0 4px 16px rgba(0,0,0,0.5); }
.wx-pill-icon  { font-size: 20px; line-height: 1; }
.wx-pill-temp  { font-family: var(--font-disp); font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }
.wx-pill-city  { font-size: 10.5px; font-weight: 500; letter-spacing: 0.05em; opacity: 0.75; }

/* LIGHT override — deep blue */
[data-theme="light"] #wx-pill {
  background: rgba(30,64,175,0.1);
  border-color: #1E40AF;
  box-shadow: 0 0 12px rgba(30,64,175,0.25), 0 3px 12px rgba(0,0,0,0.12);
  color: #1E40AF;
}
[data-theme="light"] #wx-pill:hover { box-shadow: 0 0 20px rgba(30,64,175,0.35), 0 4px 16px rgba(0,0,0,0.15); }

/* ── Expanded card (shows on hover) ─────────────────────────────────── */
#wx-card {
  width: 260px;
  margin-bottom: 10px;
  border-radius: 16px;
  overflow: hidden;

  /* DARK */
  background: #111111;
  border: 1px solid rgba(251,176,59,0.35);
  box-shadow: 0 0 0 1px rgba(251,176,59,0.1), 0 16px 48px rgba(0,0,0,0.7), 0 4px 12px rgba(0,0,0,0.5);

  /* animation */
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.34,1.4,0.64,1);
  max-height: 0;
}
[data-theme="light"] #wx-card {
  background: #FFFFFF;
  border-color: rgba(30,64,175,0.3);
  box-shadow: 0 0 0 1px rgba(30,64,175,0.08), 0 16px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.08);
}

#wx-widget:hover #wx-card {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
  max-height: 500px;
}

/* card head */
.wx-card-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex; align-items: flex-start; justify-content: space-between;
}
[data-theme="light"] .wx-card-head { border-bottom-color: rgba(0,0,0,0.07); }
.wx-card-city {
  font-family: var(--font-disp);
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #FBB03B;
}
[data-theme="light"] .wx-card-city { color: #1E40AF; }
.wx-card-date { font-size: 10.5px; color: var(--ink-3); margin-top: 2px; }

/* current */
.wx-card-cur {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
[data-theme="light"] .wx-card-cur { border-bottom-color: rgba(0,0,0,0.06); }
.wx-cur-icon  { font-size: 46px; line-height: 1; flex-shrink: 0; }
.wx-cur-right {}
.wx-cur-temp  {
  font-family: var(--font-disp);
  font-size: 38px; font-weight: 700;
  color: var(--ink); line-height: 1;
  letter-spacing: -0.02em;
}
.wx-cur-desc  { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }

/* details row */
.wx-details {
  display: flex; gap: 0;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
[data-theme="light"] .wx-details { border-bottom-color: rgba(0,0,0,0.06); }
.wx-det {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 3px;
  font-size: 11px; color: var(--ink-3);
}
.wx-det + .wx-det { border-left: 1px solid rgba(255,255,255,0.06); }
[data-theme="light"] .wx-det + .wx-det { border-left-color: rgba(0,0,0,0.07); }
.wx-det-val { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.wx-det-lbl { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-4); }

/* forecast row */
.wx-fc {
  display: flex;
  padding: 10px 8px;
  gap: 2px;
}
.wx-fc-day {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 7px 3px;
  border-radius: 10px;
  transition: background 0.15s;
}
.wx-fc-day:hover { background: rgba(255,255,255,0.05); }
[data-theme="light"] .wx-fc-day:hover { background: rgba(0,0,0,0.04); }
.wx-fc-name  { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-4); }
.wx-fc-icon  { font-size: 20px; line-height: 1; }
.wx-fc-hi    { font-size: 12px; font-weight: 700; color: var(--ink); }
.wx-fc-lo    { font-size: 11px; color: var(--ink-4); }

/* search */
.wx-search {
  display: flex; gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
[data-theme="light"] .wx-search { border-top-color: rgba(0,0,0,0.06); }
.wx-si {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--ink);
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.wx-si:focus { border-color: #FBB03B; background: rgba(255,255,255,0.1); }
[data-theme="light"] .wx-si {
  background: #F5F5F5;
  border-color: #D1D5DB;
  color: #111;
}
[data-theme="light"] .wx-si:focus { border-color: #1E40AF; background: #FFF; }
.wx-si::placeholder { color: var(--ink-4); }
.wx-sb {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
  background: #FBB03B; color: #111;
}
[data-theme="light"] .wx-sb { background: #1E40AF; color: #FFF; }
.wx-sb:hover { opacity: 0.85; transform: scale(1.06); }
.wx-sb svg   { width: 14px; height: 14px; }

/* footer */
.wx-foot {
  padding: 4px 16px 10px;
  font-size: 9.5px;
  color: var(--ink-4);
  text-align: center;
}
.wx-foot a { color: inherit; text-decoration: none; }
.wx-foot a:hover { color: #FBB03B; }
[data-theme="light"] .wx-foot a:hover { color: #1E40AF; }

/* error + loading */
.wx-err { font-size: 11px; color: #ef4444; text-align: center; padding: 4px 16px 8px; min-height: 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   EXTENDED FEATURES — Notes · Calculators · Checklists · History · Highlights
═══════════════════════════════════════════════════════════════════════════ */

/* ── Header utility buttons (calc, history) ─────────────────────────────── */
#calc-open-btn, #history-open-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 6px;
  color: var(--ink-inv-3); flex-shrink: 0;
  transition: color var(--t-fast), background var(--t-fast);
}
#calc-open-btn:hover  { color: var(--gold); background: rgba(251,176,59,0.12); }
#history-open-btn:hover { color: var(--ink-inv); background: rgba(255,255,255,0.07); }
#calc-open-btn svg, #history-open-btn svg { width: 18px; height: 18px; }

/* ── Chapter action bar ─────────────────────────────────────────────────── */
#ch-actions {
  display: flex; gap: 4px; align-items: center;
  margin-left: auto; flex-shrink: 0; flex-wrap: wrap;
}
.ch-act-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 0 10px; height: 30px; border-radius: 5px;
  font-size: 0.75rem; font-family: var(--font-body);
  color: var(--ink-2); background: rgba(255,255,255,0.05);
  border: 1px solid var(--rule); white-space: nowrap;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.ch-act-btn:hover { color: var(--ink); background: rgba(255,255,255,0.09); border-color: var(--rule-2); }
.ch-act-btn.ch-action-active { color: var(--gold); border-color: var(--gold-border); background: var(--gold-glow); }
.ch-act-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.ch-act-badge { font-size: 0.7rem; color: var(--gold); font-weight: 600; }
@media (max-width: 900px) { .ch-act-btn span:not(.ch-act-badge) { display: none; } }

/* ── Floating panel (Notes, History) ────────────────────────────────────── */
.fp-bg {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 300;
  opacity: 0; transition: opacity var(--t-med);
}
.fp-bg.fp-open { display: block; opacity: 1; }
.fp-panel {
  position: fixed; top: 0; right: -420px; bottom: 0;
  width: 400px; max-width: 100vw;
  background: var(--paper); border-left: 1px solid var(--rule-2);
  z-index: 301; display: flex; flex-direction: column;
  transition: right var(--t-slow); box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.fp-panel.fp-open { right: 0; }
.fp-hd {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--rule); flex-shrink: 0;
}
.fp-hd svg { width: 16px; height: 16px; color: var(--gold); flex-shrink: 0; }
.fp-hd-left { display: flex; align-items: center; gap: 0.6rem; }
.fp-title { font-family: var(--font-disp); font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.fp-sub   { font-size: 0.72rem; color: var(--ink-3); }
.fp-close {
  width: 28px; height: 28px; border-radius: 5px; flex-shrink: 0;
  color: var(--ink-3); display: flex; align-items: center; justify-content: center;
  transition: color var(--t-fast), background var(--t-fast);
}
.fp-close:hover { color: var(--ink); background: rgba(255,255,255,0.07); }
.fp-close svg { width: 14px; height: 14px; }
.fp-body { flex: 1; overflow-y: auto; padding: 0.85rem 1.1rem; }
.fp-foot { padding: 0.85rem 1.1rem; border-top: 1px solid var(--rule); flex-shrink: 0; }
.fp-empty { text-align: center; color: var(--ink-3); font-size: 0.83rem; padding: 2rem 0; }
.fp-empty-sm { font-size: 0.78rem; color: var(--ink-4); padding: 0.25rem 0; }

/* Notes */
#note-input {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 72px;
  background: var(--surface); border: 1px solid var(--rule-2); border-radius: 6px;
  padding: 0.6rem 0.75rem; font-family: var(--font-body); font-size: 0.85rem;
  color: var(--ink); outline: none; transition: border-color var(--t-fast);
  margin-bottom: 0.5rem;
}
#note-input:focus { border-color: var(--gold); }
.fp-submit-btn {
  width: 100%; padding: 0.55rem; background: var(--gold); color: #1F1F1F;
  border: none; border-radius: 6px; font-family: var(--font-disp);
  font-size: 0.9rem; font-weight: 600; letter-spacing: 0.04em;
  cursor: pointer; transition: background var(--t-fast);
}
.fp-submit-btn:hover { background: var(--gold-dk); }
.fp-danger-btn {
  width: 100%; padding: 0.5rem; background: rgba(220,38,38,0.1);
  color: #EF9090; border: 1px solid rgba(220,38,38,0.25);
  border-radius: 6px; font-size: 0.82rem; cursor: pointer;
  transition: background var(--t-fast);
}
.fp-danger-btn:hover { background: rgba(220,38,38,0.18); }
.note-item {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: 7px; padding: 0.7rem 0.85rem; margin-bottom: 0.6rem;
}
.note-text { font-size: 0.85rem; color: var(--ink); white-space: pre-wrap; line-height: 1.55; }
.note-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 0.5rem; }
.note-ts   { font-size: 0.7rem; color: var(--ink-4); }
.note-del-btn {
  width: 22px; height: 22px; border-radius: 4px; color: var(--ink-4);
  display: flex; align-items: center; justify-content: center;
  transition: color var(--t-fast), background var(--t-fast);
}
.note-del-btn:hover { color: #EF9090; background: rgba(220,38,38,0.1); }
.note-del-btn svg { width: 12px; height: 12px; }

/* History */
.hist-stats-row {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 0.6rem; margin-bottom: 1rem;
}
.hist-stat { background: var(--surface); border: 1px solid var(--rule); border-radius: 7px; padding: 0.7rem 0.5rem; text-align: center; }
.hist-stat-n { font-family: var(--font-disp); font-size: 1.6rem; font-weight: 600; color: var(--gold); line-height: 1; }
.hist-stat-l { font-size: 0.68rem; color: var(--ink-3); margin-top: 0.2rem; }
.hist-section-lbl { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.4rem; }
.hist-top-row { display: flex; align-items: center; justify-content: space-between; padding: 0.35rem 0; border-bottom: 1px solid var(--rule); }
.hist-top-name { font-size: 0.8rem; color: var(--ink-2); }
.hist-top-n { font-size: 0.75rem; font-weight: 600; color: var(--gold); background: var(--gold-glow); border: 1px solid var(--gold-border); border-radius: 3px; padding: 0 6px; }
.hist-group-lbl { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-3); padding: 0.85rem 0 0.3rem; }
.hist-item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.7rem;
  border-radius: 6px; cursor: pointer; transition: background var(--t-fast);
}
.hist-item:hover { background: rgba(255,255,255,0.04); }
.hist-item-body { flex: 1; min-width: 0; }
.hist-item-title { font-size: 0.82rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item-code  { font-size: 0.7rem; color: var(--ink-3); }
.hist-item-time  { font-size: 0.7rem; color: var(--ink-4); white-space: nowrap; flex-shrink: 0; }

/* ── Highlight toolbar ──────────────────────────────────────────────────── */
#hl-toolbar {
  position: fixed; z-index: 400; display: flex; align-items: center; gap: 4px;
  background: var(--elevated); border: 1px solid var(--rule-2);
  border-radius: 8px; padding: 6px 10px; box-shadow: var(--shadow-md);
  pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
}
#hl-toolbar.hl-toolbar-visible { pointer-events: all; opacity: 1; transform: translateY(0); }
.hl-btn {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
}
.hl-btn:hover { transform: scale(1.2); border-color: rgba(255,255,255,0.7); }
.hl-sep { width: 1px; height: 16px; background: var(--rule-2); margin: 0 2px; }
.hl-label { font-size: 0.7rem; color: var(--ink-3); white-space: nowrap; }

/* ── Modal (Calculator, New Checklist) ──────────────────────────────────── */
.fm-bg {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 350;
}
.fm-bg.fm-open { display: block; }  /* shown when calc-modal or cl-new-modal is open */
/* reuse fm-bg for multiple modals — show via JS toggling fm-open on modal */
.fm-modal {
  display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  z-index: 351; background: var(--paper); border: 1px solid var(--rule-2);
  border-radius: 12px; box-shadow: var(--shadow-lg); flex-direction: column;
  max-height: 90vh; overflow: hidden;
}
.fm-modal.fm-open { display: flex; }
.calc-modal-size { width: 680px; max-width: 96vw; }
.fm-modal-sm { width: 420px; max-width: 96vw; }
.fm-hd {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--rule); flex-shrink: 0;
}
.fm-hd svg { width: 18px; height: 18px; color: var(--gold); flex-shrink: 0; }
.fm-hd-left { display: flex; align-items: center; gap: 0.65rem; }
.fm-title { font-family: var(--font-disp); font-size: 1rem; font-weight: 600; color: var(--ink); }
.fm-sub { font-size: 0.73rem; color: var(--ink-3); }
.fm-close { width: 30px; height: 30px; border-radius: 6px; color: var(--ink-3); display: flex; align-items: center; justify-content: center; transition: color var(--t-fast), background var(--t-fast); flex-shrink: 0; }
.fm-close:hover { color: var(--ink); background: rgba(255,255,255,0.07); }
.fm-close svg { width: 14px; height: 14px; }
.fm-body { padding: 1.1rem 1.25rem; overflow-y: auto; }
.fm-foot { display: flex; gap: 0.6rem; justify-content: flex-end; padding: 0.85rem 1.25rem; border-top: 1px solid var(--rule); flex-shrink: 0; }
.fm-cancel-btn { padding: 0.45rem 1rem; background: rgba(255,255,255,0.06); border: 1px solid var(--rule-2); border-radius: 6px; color: var(--ink-2); font-size: 0.85rem; cursor: pointer; }
.fm-cancel-btn:hover { background: rgba(255,255,255,0.1); }
.fm-create-btn { padding: 0.45rem 1.1rem; background: var(--gold); border: none; border-radius: 6px; color: #1F1F1F; font-family: var(--font-disp); font-size: 0.9rem; font-weight: 600; letter-spacing: 0.04em; cursor: pointer; }
.fm-create-btn:hover { background: var(--gold-dk); }

/* ── Calculator styles ──────────────────────────────────────────────────── */
.calc-tabs {
  display: flex; gap: 2px; padding: 0.75rem 1.25rem 0;
  border-bottom: 1px solid var(--rule); flex-shrink: 0; flex-wrap: wrap;
}
.calc-tab {
  padding: 0.4rem 0.85rem; border-radius: 5px 5px 0 0; font-size: 0.78rem;
  color: var(--ink-3); transition: color var(--t-fast), background var(--t-fast);
  border: 1px solid transparent; border-bottom: none; margin-bottom: -1px;
}
.calc-tab:hover  { color: var(--ink); background: rgba(255,255,255,0.04); }
.calc-tab.active { color: var(--ink); background: var(--surface); border-color: var(--rule-2); }
.calc-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
.calc-pane { display: none; }
.calc-pane.active { display: block; }
.calc-pane-hd { font-family: var(--font-disp); font-size: 0.95rem; font-weight: 600; color: var(--ink); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.calc-ref-badge { font-size: 0.65rem; font-family: var(--font-mono); background: rgba(251,176,59,0.12); color: var(--gold); border: 1px solid var(--gold-border); border-radius: 4px; padding: 1px 7px; font-weight: 400; }
.calc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
@media (max-width: 560px) { .calc-fields { grid-template-columns: 1fr; } }
.calc-field { display: flex; flex-direction: column; gap: 0.35rem; }
.calc-field label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.calc-field input, .calc-field select {
  background: var(--surface); border: 1px solid var(--rule-2); border-radius: 6px;
  padding: 0.55rem 0.75rem; font-family: var(--font-body); font-size: 0.87rem;
  color: var(--ink); outline: none; transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.calc-field input:focus, .calc-field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-glow); }
.calc-field select option { background: var(--elevated); }

/* Calc result card */
.calc-card { background: var(--surface); border: 1px solid var(--rule-2); border-radius: 8px; padding: 1rem 1.1rem; animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform:none; } }
.cc-main { font-family: var(--font-disp); font-size: 2rem; font-weight: 600; color: var(--gold); }
.cc-unit { font-size: 1rem; color: var(--ink-2); }
.cc-detail { font-size: 0.8rem; color: var(--ink-3); margin-top: 0.3rem; }
.cc-badge { background: rgba(255,255,255,0.08); border-radius: 3px; padding: 0 5px; font-size: 0.7rem; }
.cc-table { display: flex; flex-direction: column; gap: 0; }
.cc-row { display: flex; align-items: center; justify-content: space-between; padding: 0.45rem 0; border-bottom: 1px solid var(--rule); font-size: 0.84rem; }
.cc-row:last-child { border-bottom: none; }
.cc-row span { color: var(--ink-2); }
.cc-row b { color: var(--ink); font-weight: 600; }
.cc-ok   { color: #4ADE80 !important; }
.cc-fail { color: #F87171 !important; }
.cc-ref  { font-size: 0.7rem; color: var(--ink-4); font-family: var(--font-mono); margin-top: 0.6rem; }
.cc-note { font-size: 0.78rem; margin-top: 0.6rem; padding: 0.4rem 0.6rem; border-radius: 5px; }
.cc-note-ok   { background: rgba(74,222,128,0.1); color: #86EFAC; }
.cc-note-fail { background: rgba(248,113,113,0.1); color: #FCA5A5; }

/* ── Checklists view ────────────────────────────────────────────────────── */
#view-checklists { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
#cl-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--rule-2); flex-shrink: 0;
}
#cl-heading { font-family: var(--font-disp); font-size: 1.1rem; font-weight: 600; color: var(--ink); margin: 0; }
.cl-new-btn-hd {
  display: flex; align-items: center; gap: 6px;
  padding: 0 1rem; height: 34px; background: var(--gold); color: #1F1F1F;
  border: none; border-radius: 6px; font-family: var(--font-disp);
  font-size: 0.88rem; font-weight: 600; letter-spacing: 0.04em;
  cursor: pointer; transition: background var(--t-fast);
}
.cl-new-btn-hd:hover { background: var(--gold-dk); }
.cl-new-btn-hd svg { width: 14px; height: 14px; }
#cl-body { display: flex; flex: 1; overflow: hidden; }

/* CL sidebar */
#cl-sidebar { width: 260px; flex-shrink: 0; border-right: 1px solid var(--rule-2); overflow-y: auto; background: var(--sb-bg); }
.cl-sidebar-item { padding: 0.85rem 1rem; border-bottom: 1px solid var(--rule); cursor: pointer; transition: background var(--t-fast); position: relative; }
.cl-sidebar-item:hover { background: rgba(255,255,255,0.03); }
.cl-sidebar-item.active { background: rgba(251,176,59,0.07); border-left: 3px solid var(--gold); }
.cl-si-name { font-size: 0.85rem; color: var(--ink); font-weight: 500; margin-bottom: 0.45rem; padding-right: 1.5rem; }
.cl-si-progress { display: flex; align-items: center; gap: 0.5rem; }
.cl-si-bar { flex: 1; height: 4px; background: var(--rule-2); border-radius: 2px; overflow: hidden; }
.cl-si-fill { height: 100%; background: var(--gold); border-radius: 2px; transition: width 0.3s; }
.cl-si-pct { font-size: 0.68rem; color: var(--ink-3); white-space: nowrap; }
.cl-si-del { position: absolute; top: 0.85rem; right: 0.75rem; width: 22px; height: 22px; border-radius: 4px; color: var(--ink-4); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity var(--t-fast), color var(--t-fast), background var(--t-fast); }
.cl-sidebar-item:hover .cl-si-del { opacity: 1; }
.cl-si-del:hover { color: #EF9090; background: rgba(220,38,38,0.1); }
.cl-si-del svg { width: 12px; height: 12px; }

/* CL main */
#cl-main { flex: 1; overflow-y: auto; }
.cl-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 0.75rem; padding: 3rem; text-align: center; }
.cl-empty-icon svg { width: 48px; height: 48px; color: var(--ink-4); }
.cl-empty-title { font-family: var(--font-disp); font-size: 1.1rem; color: var(--ink-2); }
.cl-empty-sub { font-size: 0.83rem; color: var(--ink-3); }
.cl-main-hd { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--rule-2); }
.cl-main-hd-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.cl-main-title { font-family: var(--font-disp); font-size: 1.3rem; font-weight: 600; color: var(--ink); margin: 0 0 0.2rem; }
.cl-main-meta { font-size: 0.78rem; color: var(--ink-3); }
.cl-main-acts { display: flex; gap: 0.5rem; }
.cl-export-btn { display: flex; align-items: center; gap: 5px; padding: 0 10px; height: 30px; border-radius: 5px; font-size: 0.75rem; color: var(--ink-2); background: rgba(255,255,255,0.05); border: 1px solid var(--rule); transition: color var(--t-fast), background var(--t-fast); }
.cl-export-btn:hover { color: var(--ink); background: rgba(255,255,255,0.09); }
.cl-export-btn svg { width: 13px; height: 13px; }
.cl-progress-bar-wrap { display: flex; align-items: center; gap: 0.6rem; }
.cl-progress-bar { flex: 1; height: 6px; background: var(--rule-2); border-radius: 3px; overflow: hidden; }
.cl-progress-fill { height: 100%; background: var(--gold); border-radius: 3px; transition: width 0.3s ease; }
.cl-progress-pct { font-size: 0.75rem; font-weight: 600; color: var(--gold); width: 2.5rem; text-align: right; }
.cl-items-wrap { padding: 1rem 1.5rem 2rem; }
.cl-group { margin-bottom: 0.5rem; }
.cl-group-hd { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); padding: 0.85rem 0 0.4rem; border-bottom: 1px solid var(--rule); margin-bottom: 0.4rem; }
.cl-item { display: flex; align-items: flex-start; gap: 0.65rem; padding: 0.55rem 0.5rem; border-radius: 6px; cursor: pointer; transition: background var(--t-fast); }
.cl-item:hover { background: rgba(255,255,255,0.03); }
.cl-item-done .cl-item-txt { text-decoration: line-through; color: var(--ink-3); }
.cl-check { width: 15px; height: 15px; accent-color: var(--gold); cursor: pointer; flex-shrink: 0; margin-top: 2px; }
.cl-item-body { flex: 1; min-width: 0; }
.cl-item-txt { font-size: 0.85rem; color: var(--ink); line-height: 1.5; }
.cl-item-ref { font-size: 0.7rem; color: var(--gold); font-family: var(--font-mono); margin-top: 2px; }
.cl-add-item-wrap { display: flex; gap: 0.5rem; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--rule); }
#cl-add-input { flex: 1; background: var(--surface); border: 1px solid var(--rule-2); border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.85rem; color: var(--ink); outline: none; font-family: var(--font-body); transition: border-color var(--t-fast); }
#cl-add-input:focus { border-color: var(--gold); }
#cl-add-btn { padding: 0 1rem; height: 36px; background: rgba(251,176,59,0.12); color: var(--gold); border: 1px solid var(--gold-border); border-radius: 6px; font-size: 0.82rem; cursor: pointer; transition: background var(--t-fast); }
#cl-add-btn:hover { background: rgba(251,176,59,0.2); }

/* ── Global Toast ───────────────────────────────────────────────────────── */
#ft-toast {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  display: flex; align-items: center; gap: 7px;
  padding: 0.55rem 0.95rem; border-radius: 7px;
  font-size: 0.82rem; z-index: 9999; pointer-events: none;
  max-width: 320px; opacity: 0; transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
}
#ft-toast.ft-toast-visible { opacity: 1; transform: translateY(0); }
#ft-toast.ft-toast-success { background: #14532D; color: #86EFAC; border: 1px solid #166534; }
#ft-toast.ft-toast-error   { background: #450A0A; color: #FCA5A5; border: 1px solid #7F1D1D; }
#ft-toast.ft-toast-info    { background: var(--elevated); color: var(--ink-2); border: 1px solid var(--rule-2); }
#ft-toast svg { width: 13px; height: 13px; flex-shrink: 0; }

/* ── Print styles ───────────────────────────────────────────────────────── */
#print-header { display: none; }
@media print {
  #hdr, #sidebar, #reading-progress, #ch-bar, #ch-toc,
  #search-overlay, #lightbox, #fig-lb, #hl-toolbar,
  #notes-panel, #notes-panel-bg, #history-panel, #history-panel-bg,
  #calc-modal, #calc-bg, #cl-new-modal, #cl-new-bg,
  #ft-toast, #wx-widget, #asm-detail, #shell > #body > aside { display: none !important; }
  body, html { background: #fff !important; }
  #shell, #body, #main, #view-chapter, #chapter-layout { all: unset; display: block !important; }
  #chapter-content-wrap { overflow: visible !important; height: auto !important; }
  #print-header { display: block !important; margin-bottom: 1.5rem; padding-bottom: 0.75rem; border-bottom: 2px solid #1F1F1F; }
  .ph-logo  { font-family: 'Oswald', sans-serif; font-size: 0.65rem; letter-spacing: 0.15em; color: #666; text-transform: uppercase; }
  .ph-title { font-family: 'Oswald', sans-serif; font-size: 1.4rem; font-weight: 600; color: #1F1F1F; margin: 0.2rem 0 0.1rem; }
  .ph-meta  { font-size: 0.7rem; color: #888; }
  #chapter-content { font-size: 0.85rem; color: #111; }
  a { color: #1F1F1F; text-decoration: underline; }
  h1, h2, h3 { page-break-after: avoid; }
  table { page-break-inside: avoid; }
}

/* Light theme adjustments for new features */
[data-theme="light"] .fp-panel   { background: var(--paper); }
[data-theme="light"] .fm-modal   { background: var(--paper); }
[data-theme="light"] .calc-card  { background: var(--surface); }
[data-theme="light"] .note-item  { background: var(--surface); }
[data-theme="light"] #hl-toolbar { background: var(--elevated); }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile · Tablet · Touch
   Breakpoints: 1024px (laptop), 768px (tablet), 480px (phone)
═══════════════════════════════════════════════════════════════════════════ */

/* ── Sidebar mobile overlay ─────────────────────────────────────────────── */
#sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 499;
  backdrop-filter: blur(2px);
}

/* ── Touch improvements ─────────────────────────────────────────────────── */
button, a, .tree-item, .tc, .nav-tab, .asm-card, .diag-card, .code-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ══════════════════════════════════════════════════════════════════════════
   ≤ 1024px  Laptop / small desktop
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  #home-inner { padding: 28px 28px 60px; }
  #chapter-content-wrap { padding: 28px 32px; }
  #home-hero { padding: 36px 36px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   ≤ 768px  Tablet / large phone
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Layout tokens ─────────────────────────────────────────────────── */
  :root {
    --hdr-h: 54px;
    --sb-w: 280px;
  }

  /* ── Header ─────────────────────────────────────────────────────────── */
  #hdr {
    padding: 0 10px;
    gap: 6px;
  }
  #logo-text { display: none; }
  #logo-icon { width: 38px; height: 38px; }
  #search-trigger {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    padding: 0 10px;
    gap: 8px;
  }
  #search-trigger span { display: none; }
  #search-trigger kbd  { display: none; }
  #hdr-nav { gap: 1px; }
  .nav-tab {
    padding: 0 9px;
    gap: 0;
  }
  .nav-tab span { display: none; }
  .nav-tab svg  { width: 18px; height: 18px; }
  #settings-btn { width: 32px; height: 32px; }
  #calc-open-btn, #history-open-btn { width: 32px; height: 32px; }
  #calc-open-btn svg, #history-open-btn svg { width: 17px; height: 17px; }
  #admin-link { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
  #logout-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }

  /* ── Sidebar — fixed drawer overlay ─────────────────────────────────── */
  #sidebar {
    position: fixed;
    top: var(--hdr-h);
    left: 0;
    bottom: 0;
    z-index: 500;
    width: var(--sb-w) !important;
    min-width: var(--sb-w) !important;
    opacity: 1 !important;
    overflow: hidden !important;
    transform: translateX(0);
    transition: transform var(--t-slow);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  body.sidebar-collapsed #sidebar {
    transform: translateX(calc(-1 * var(--sb-w)));
    width: var(--sb-w) !important;
    min-width: var(--sb-w) !important;
  }
  /* Show overlay when sidebar open on mobile */
  body:not(.sidebar-collapsed) #sb-overlay { display: block; }

  /* ── Main content always full width on mobile ───────────────────────── */
  #main { min-width: 0; width: 100%; }

  /* ── Home ──────────────────────────────────────────────────────────── */
  #home-inner { padding: 16px 16px 60px; }
  #home-hero  { padding: 24px 20px; }
  #home-title { font-size: clamp(36px, 10vw, 56px); }
  #home-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .home-stat  { padding: 14px 12px; }
  .home-stat-num { font-size: 26px; }
  .home-group-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  /* ── Chapter view ───────────────────────────────────────────────────── */
  #chapter-bar { padding: 0 10px; gap: 6px; }
  #ch-back { padding: 4px 6px; }
  #ch-external { display: none; }
  #chapter-content-wrap { padding: 16px 16px 40px; max-width: 100%; }
  #chapter-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #ch-toc { display: none; } /* hide TOC on mobile */

  /* ── Chapter action bar ─────────────────────────────────────────────── */
  #ch-actions { flex-wrap: wrap; gap: 3px; }
  .ch-act-btn { padding: 0 7px; height: 28px; font-size: 0.7rem; }

  /* ── Search modal ───────────────────────────────────────────────────── */
  #search-modal {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0 0 14px 14px;
    border-top: none;
    max-height: 85vh;
  }
  #search-overlay { padding: 0; align-items: flex-start; }
  #search-footer  { display: none; }

  /* ── Lightbox (diagrams) ─────────────────────────────────────────────── */
  #lightbox { padding: 0; }
  #lb-shell {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100dvh;
    border-radius: 0;
  }
  #lb-body { flex-direction: column; }
  #lb-canvas { min-height: 50vh; }
  #lb-info {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--rule);
    padding: 14px 16px;
    max-height: 35vh;
    overflow-y: auto;
  }

  /* ── Figure lightbox ─────────────────────────────────────────────────── */
  #fig-lb-card { max-width: 95vw; max-height: 90dvh; }

  /* ── Diagrams view ──────────────────────────────────────────────────── */
  #diag-bar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  #diag-controls { flex-wrap: wrap; }
  .diag-sel { min-width: 0; flex: 1; }
  #diag-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  #diag-grid-outer { padding: 12px; }

  /* ── Assemblies view ─────────────────────────────────────────────────── */
  #asm-bar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  #asm-bar-left { width: 100%; }
  #asm-bar-center { width: 100%; }
  #asm-bar-right { margin-left: auto; }
  #asm-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  #asm-main { padding: 12px; }
  #asm-filters { display: none; } /* filters hidden on mobile, use filter-toggle */

  /* ── Assembly detail ─────────────────────────────────────────────────── */
  #asm-detail { padding: 0; }
  #asm-detail-shell {
    max-width: 100%;
    width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
  }

  /* ── Floating panels (Notes, History) ───────────────────────────────── */
  .fp-panel { width: 100% !important; right: -100% !important; }
  .fp-panel.fp-open { right: 0 !important; }

  /* ── Calculator modal ───────────────────────────────────────────────── */
  .calc-modal-size {
    width: calc(100% - 16px);
    max-height: 95dvh;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .calc-tabs { padding: 0.5rem 0.75rem 0; }
  .calc-tab  { padding: 0.35rem 0.65rem; font-size: 0.72rem; }

  /* ── Checklists view ─────────────────────────────────────────────────── */
  #cl-body { flex-direction: column; }
  #cl-sidebar {
    width: 100% !important;
    height: auto;
    max-height: 220px;
    border-right: none;
    border-bottom: 1px solid var(--rule-2);
    flex-shrink: 0;
  }
  #cl-main { overflow-y: auto; }

  /* ── Settings panel ─────────────────────────────────────────────────── */
  #settings-panel { right: 6px; }

  /* ── Toast ───────────────────────────────────────────────────────────── */
  #ft-toast { left: 1rem; right: 1rem; max-width: 100%; bottom: 1rem; }

  /* ── Publishers pills wrap ───────────────────────────────────────────── */
  #asm-publishers { padding: 8px 12px; overflow-x: auto; flex-wrap: nowrap; }
}

/* ══════════════════════════════════════════════════════════════════════════
   ≤ 480px  Phone
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  :root { --hdr-h: 50px; }

  /* Tighter header */
  #logo-icon { width: 32px; height: 32px; }
  .nav-tab { padding: 0 7px; }
  .nav-tab svg { width: 16px; height: 16px; }
  #search-trigger { padding: 0 8px; height: 34px; }

  /* Home */
  #home-inner { padding: 12px 12px 60px; }
  #home-hero  { padding: 20px 16px; }
  #home-title { font-size: clamp(30px, 10vw, 44px); }
  #home-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .home-stat-num { font-size: 22px; }
  .home-group-cards { grid-template-columns: 1fr 1fr; }
  .home-search-cta kbd { display: none; }

  /* Chapter */
  #chapter-content-wrap { padding: 12px 12px 40px; }
  #chapter-bar { height: 42px; }
  #chapter-content h1 { font-size: 20px; }
  #chapter-content h2 { font-size: 16px; }

  /* Diagrams */
  #diag-grid { grid-template-columns: 1fr 1fr; }
  .diag-thumb { height: 90px; }

  /* Assemblies */
  #asm-grid { grid-template-columns: 1fr 1fr; }
  .asm-card-thumb { height: 100px; }

  /* Hero CTA  */
  .home-search-cta { padding: 0 16px; font-size: 13px; height: 42px; }

  /* Calculator modal — full screen on small phone */
  .calc-modal-size {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    top: 0;
    left: 0;
    transform: none;
    position: fixed;
  }

  /* Checklist sidebar shorter */
  #cl-sidebar { max-height: 160px; }

  /* Floating panels full screen */
  .fp-panel { top: 0 !important; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Mobile sidebar auto-collapse on start (JS will restore preference)
══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Default collapsed on mobile so page loads without sidebar covering content */
  body:not([data-sb-init]) #sidebar { transform: translateX(calc(-1 * var(--sb-w))); }
  body:not([data-sb-init]) #sb-overlay { display: none; }
}
