/* ================================================================
   KnowW Knowledge Graph — Premium Dark-Mode, Mobile-First UI
   ================================================================ */

:root {
  --bg:        #0a0b0f;
  --surface:   #13151c;
  --surface2:  #1a1d27;
  --border:    #252836;
  --accent:    #6366f1;
  --accent2:   #818cf8;
  --text:      #e2e8f0;
  --text-muted:#8892a4;
  --text-dim:  #4e5669;

  --green:  #22c55e;
  --amber:  #f59e0b;
  --red:    #ef4444;

  --t-mental_model:  #a78bfa;
  --t-concept:       #6366f1;
  --t-principle:     #2dd4bf;
  --t-behavior:      #4ade80;
  --t-skill:         #a3e635;
  --t-pattern:       #fb923c;
  --t-habit:         #fbbf24;
  --t-strategy:      #f87171;
  --t-warning:       #f472b6;
  --t-decision_rule: #94a3b8;

  --sidebar-w: 280px;
  --nav-h: 56px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,.5);
  --transition: .2s cubic-bezier(.4,0,.2,1);
  --fs-scale: 1;
}

/* Light mode */
body.light {
  --bg:       #f1f5f9;
  --surface:  #ffffff;
  --surface2: #f8fafc;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --text-muted:#64748b;
  --text-dim: #cbd5e1;
}

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

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ================================================================
   KG CONTROLS (Search, Font controls)
   ================================================================ */
/* KG CONTROLS (sticks below navbar) */
.kg-controls {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: 64px; /* Sticks below navbar (navbar is 64px tall) */
  z-index: 90;
}

.kg-controls-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.kg-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-search {
  flex: 1; max-width: 320px;
  position: relative;
}
.nav-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px 7px 36px;
  color: var(--text); font-size: 13px;
  outline: none; transition: border var(--transition);
}
.nav-search input:focus { border-color: var(--accent); }
.nav-search .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}

.nav-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.btn-icon {
  width: 36px; height: 36px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* Font size controls */
.font-size-controls {
  display: flex; align-items: center; gap: 2px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.btn-fs {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: none;
  background: transparent;
}
.btn-fs:hover:not(:disabled) { background: var(--border); }
.btn-fs:disabled { opacity: .3; cursor: default; }
.fs-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
  user-select: none;
}

/* ================================================================
   STATS BAR
   ================================================================ */
.stats-bar {
  margin-top: var(--nav-h);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface2) 100%);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 0;
  overflow-x: auto;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.stat-item {
  flex: 1; min-width: 100px;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 16px;
  position: relative;
  gap: 2px;
}
.stat-item + .stat-item::before {
  content: '';
  position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 1px;
  background: var(--border);
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--accent); letter-spacing: -.3px; }
.stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 500; }

/* ================================================================
   MAIN LAYOUT
   ================================================================ */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform .35s cubic-bezier(.32,.72,0,1);
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}

.sidebar-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text); font-size: 13px;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-sort {
  display: flex; gap: 4px;
}
.sort-btn {
  flex: 1; padding: 5px 8px; font-size: 11px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted); cursor: pointer;
  transition: all var(--transition);
}
.sort-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.sidebar-count {
  padding: 6px 12px;
  font-size: 11px; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.book-list {
  flex: 1; overflow-y: auto;
  padding: 6px;
}

.book-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 4px;
}
.book-card:hover { background: var(--surface2); }
.book-card.active {
  background: rgba(99,102,241,.12);
  border-color: rgba(99,102,241,.3);
}
.book-card-title {
  font-size: 13px; font-weight: 600; line-height: 1.3;
  color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-card-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.book-card-nodes {
  display: flex; align-items: center; gap: 6px; margin-top: 6px;
}
.book-card-count { font-size: 11px; color: var(--accent); font-weight: 600; }

/* ── Content Panel ── */
.content {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* Welcome screen */
.welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 40px;
  text-align: center;
}
.welcome-icon { font-size: 48px; }
.welcome h2 { font-size: 22px; font-weight: 700; color: var(--text); }
.welcome p { font-size: calc(14px * var(--fs-scale)); color: var(--text-muted); max-width: 360px; }

/* Node list panel */
.node-panel {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

.node-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; gap: 8px;
}

.filter-pills-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  margin: 0 -16px;
  padding: 0 16px;
}
.filter-pills-wrap::-webkit-scrollbar { display: none; }

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

.book-header-bar {
  padding: 14px 16px 12px;
  background: linear-gradient(180deg, var(--surface) 60%, var(--surface2) 100%);
  border-bottom: 1px solid var(--border);
}
.book-header-top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.book-header-title { font-size: calc(17px * var(--fs-scale)); font-weight: 700; line-height: 1.3; flex: 1; }
.book-header-meta { font-size: calc(12px * var(--fs-scale)); color: var(--text-muted); margin-top: 4px; }

/* NodeCore link in book header */
.nodecore-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  color: var(--accent2);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(99,102,241,.08);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
  transition: all var(--transition);
}
.nodecore-link:hover {
  background: rgba(99,102,241,.18);
  border-color: var(--accent);
  color: var(--accent);
}
.nodecore-link svg { flex-shrink: 0; }

.filter-pills { display: flex; flex-wrap: nowrap; gap: 4px; }
.pill {
  padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap; flex-shrink: 0;
}
.pill:active { transform: scale(.95); }
.pill.active { color: #fff; border-color: transparent; }
.pill[data-type="mental_model"].active  { background: var(--t-mental_model); }
.pill[data-type="concept"].active       { background: var(--t-concept); }
.pill[data-type="principle"].active     { background: var(--t-principle); color: #0a0b0f; }
.pill[data-type="behavior"].active      { background: var(--t-behavior); color: #0a0b0f; }
.pill[data-type="skill"].active         { background: var(--t-skill); color: #0a0b0f; }
.pill[data-type="pattern"].active       { background: var(--t-pattern); color: #0a0b0f; }
.pill[data-type="habit"].active         { background: var(--t-habit); color: #0a0b0f; }
.pill[data-type="strategy"].active      { background: var(--t-strategy); }
.pill[data-type="warning"].active       { background: var(--t-warning); }
.pill[data-type="decision_rule"].active { background: var(--t-decision_rule); }
.pill[data-type="all"].active           { background: var(--accent); }

.node-search-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
  color: var(--text); font-size: 12px;
  outline: none; flex: 1; min-width: 0;
}
.node-search-box:focus { border-color: var(--accent); }

.node-sort {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px;
  color: var(--text); font-size: 12px;
  cursor: pointer; outline: none;
}

.node-count { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* Node grid */
.node-grid {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px;
  align-content: start;
}

.node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 12px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex; flex-direction: column; gap: 8px;
}
.node-card:hover {
  border-color: var(--accent);
  border-left-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

/* Type-colored left border accents */
.node-card[data-type="mental_model"]  { border-left-color: var(--t-mental_model); }
.node-card[data-type="concept"]       { border-left-color: var(--t-concept); }
.node-card[data-type="principle"]     { border-left-color: var(--t-principle); }
.node-card[data-type="behavior"]      { border-left-color: var(--t-behavior); }
.node-card[data-type="skill"]         { border-left-color: var(--t-skill); }
.node-card[data-type="pattern"]       { border-left-color: var(--t-pattern); }
.node-card[data-type="habit"]         { border-left-color: var(--t-habit); }
.node-card[data-type="strategy"]      { border-left-color: var(--t-strategy); }
.node-card[data-type="warning"]       { border-left-color: var(--t-warning); }
.node-card[data-type="decision_rule"] { border-left-color: var(--t-decision_rule); }

.node-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.node-card-title {
  font-size: calc(13px * var(--fs-scale)); font-weight: 600; line-height: 1.4;
  flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.score-badge {
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 20px;
  white-space: nowrap; letter-spacing: -.2px;
}
.score-badge.green { background: rgba(34,197,94,.15); color: var(--green); }
.score-badge.amber { background: rgba(245,158,11,.15); color: var(--amber); }
.score-badge.red   { background: rgba(239,68,68,.15);  color: var(--red); }

.type-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  text-transform: uppercase;
  padding: 2px 8px; border-radius: 20px;
  display: inline-block;
}
.type-badge.mental_model  { background: rgba(167,139,250,.15); color: var(--t-mental_model); }
.type-badge.concept       { background: rgba(99,102,241,.15);  color: var(--t-concept); }
.type-badge.principle     { background: rgba(45,212,191,.15);  color: var(--t-principle); }
.type-badge.behavior      { background: rgba(74,222,128,.15);  color: var(--t-behavior); }
.type-badge.skill         { background: rgba(163,230,53,.15);  color: var(--t-skill); }
.type-badge.pattern       { background: rgba(251,146,60,.15);  color: var(--t-pattern); }
.type-badge.habit         { background: rgba(251,191,36,.15);  color: var(--t-habit); }
.type-badge.strategy      { background: rgba(248,113,113,.15); color: var(--t-strategy); }
.type-badge.warning       { background: rgba(244,114,182,.15); color: var(--t-warning); }
.type-badge.decision_rule { background: rgba(148,163,184,.15); color: var(--t-decision_rule); }

.node-card-oneliner {
  font-size: calc(12px * var(--fs-scale)); color: var(--text-muted); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.node-card-footer {
  display: flex; align-items: center; gap: 6px;
  margin-top: auto;
}
.domain-tag {
  font-size: 10px; color: var(--text-dim);
  background: var(--surface2);
  border-radius: 4px; padding: 2px 6px;
}

/* ================================================================
   NODE DETAIL DRAWER
   ================================================================ */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
.drawer-overlay.open { opacity: 1; pointer-events: all; }

.drawer {
  position: fixed; z-index: 201;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(.96);
  width: min(720px, calc(100vw - 64px));
  max-height: calc(100dvh - 64px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,.4);
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: transform .35s cubic-bezier(.32,.72,0,1), opacity .25s ease;
  overflow: hidden;
}
.drawer.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1; pointer-events: all;
}

.drawer-top {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  padding-right: max(12px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* Drawer NodeCore deep-link */
.drawer-nodecore-link {
  font-size: 15px; font-weight: 700; letter-spacing: -.3px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
  transition: color var(--transition);
}
.drawer-nodecore-link span { color: var(--accent); }
.drawer-nodecore-link:hover { color: var(--accent2); }

/* Drawer navigation */
.drawer-nav {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.drawer-nav-btn {
  width: 32px; height: 32px;
  flex-shrink: 0;
}
.drawer-nav-btn:disabled {
  opacity: .3; cursor: default; pointer-events: none;
}
.drawer-nav-pos {
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  min-width: 40px; text-align: center;
  user-select: none;
  white-space: nowrap;
}

.drawer-close {
  width: 36px; height: 36px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}
.drawer-close:hover { border-color: var(--red); color: var(--red); }

.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 20px;
}

/* Sections */
.section { display: flex; flex-direction: column; gap: 8px; }
.section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-dim);
}
.section-body { font-size: calc(14px * var(--fs-scale)); line-height: 1.7; color: var(--text); }

.callout {
  background: rgba(99,102,241,.08);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 16px;
  font-size: calc(14px * var(--fs-scale)); line-height: 1.6; color: var(--text);
}

.example-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.example-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.example-card-label {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px;
}
.example-card-text { font-size: calc(13px * var(--fs-scale)); line-height: 1.6; color: var(--text); }

/* Tabs */
.tab-bar { display: flex; border-bottom: 1px solid var(--border); gap: 0; }
.tab-btn {
  padding: 8px 16px; font-size: 13px; cursor: pointer;
  border: none; background: transparent; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all var(--transition);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { padding: 12px 0; display: none; }
.tab-content.active { display: block; }
.tab-list { display: flex; flex-direction: column; gap: 6px; }
.tab-list-item {
  display: flex; gap: 10px; font-size: calc(13px * var(--fs-scale)); line-height: 1.5; color: var(--text);
}
.tab-list-num {
  flex-shrink: 0; width: 20px; height: 20px;
  background: var(--surface2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-muted); margin-top: 1px;
}

/* Quotes */
.quote-block {
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 12px 16px; position: relative;
  border-left: 3px solid var(--text-dim);
}
.quote-block.quote { border-left-color: var(--accent); }
.quote-text { font-size: calc(13px * var(--fs-scale)); line-height: 1.6; font-style: italic; color: var(--text); }
.quote-type {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-dim); margin-top: 6px;
}

/* Scores */
.score-row { display: flex; flex-direction: column; gap: 10px; }
.score-line { display: flex; flex-direction: column; gap: 4px; }
.score-line-header { display: flex; justify-content: space-between; font-size: 12px; }
.score-line-label { color: var(--text-muted); }
.score-line-val { font-weight: 700; }
.score-bar-bg {
  height: 6px; background: var(--surface2);
  border-radius: 3px; overflow: hidden;
}
.score-bar-fill {
  height: 100%; border-radius: 3px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.score-bar-fill.green { background: var(--green); }
.score-bar-fill.amber { background: var(--amber); }
.score-bar-fill.red   { background: var(--red); }

/* Source */
.source-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 12px;
  font-size: 13px;
}
.source-key { color: var(--text-muted); white-space: nowrap; }
.source-val { color: var(--text); }
.location-badge {
  display: inline-block;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: rgba(99,102,241,.12); color: var(--accent2);
}

/* Tags */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  padding: 3px 10px; border-radius: 20px; font-size: 11px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Meta grid */
.meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.meta-item {
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.meta-key { font-size: 10px; color: var(--text-dim); letter-spacing: .3px; text-transform: uppercase; }
.meta-val { font-size: 12px; color: var(--text); margin-top: 2px; }

.divider {
  height: 1px; background: var(--border); margin: 0;
}

/* ================================================================
   MOBILE (< 768px)
   ================================================================ */
@media (max-width: 767px) {
  .navbar {
    transition: transform .3s cubic-bezier(.4,0,.2,1);
  }
  .stats-bar {
    transition: max-height .3s ease, margin .3s ease, padding .3s ease, opacity .2s ease, border .2s ease;
  }
  .layout {
    height: calc(100dvh - var(--nav-h) - 64px);
    transition: height .3s ease;
  }

  /* ── Auto-hide header on scroll ── */
  body.header-collapsed .navbar {
    transform: translateY(-100%);
  }
  body.header-collapsed .stats-bar {
    margin-top: 0;
    max-height: 0;
    padding: 0;
    overflow: hidden;
    border: none;
    opacity: 0;
  }
  body.header-collapsed .layout {
    height: 100dvh;
  }

  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100%; min-width: unset;
    height: 55vh; z-index: 150;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,.3);
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(.32,.72,0,1);
  }
  .sidebar::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }
  .sidebar.mobile-open { transform: translateY(0); }

  .content { width: 100%; }
  .nav-search { display: none; }

  .node-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .node-card { padding: 16px 14px 16px 12px; }
  .node-card-title { font-size: 14px; }
  .node-card-oneliner { font-size: 13px; }

  .example-grid { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: 1fr; }

  .drawer {
    top: 0; left: auto; right: 0; bottom: 0;
    width: 100vw; max-height: none;
    border: none; border-radius: 0;
    transform: translateX(100%);
    opacity: 1; pointer-events: all;
  }
  .drawer.open {
    transform: translateX(0);
  }

  .book-header-title { font-size: calc(16px * var(--fs-scale)); }

  .node-card-title { font-size: calc(14px * var(--fs-scale)); }
  .node-card-oneliner { font-size: calc(13px * var(--fs-scale)); }

  .stat-value { font-size: 20px; }

  .fs-label { display: none; }

  .mobile-book-btn {
    display: flex;
    position: fixed;
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    left: max(16px, env(safe-area-inset-left, 16px));
    z-index: 140;
    align-items: center; gap: 8px;
    background: var(--accent); color: #fff;
    border: none; border-radius: 24px;
    padding: 12px 18px; font-size: 13px; font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(99,102,241,.4);
    transition: transform var(--transition), box-shadow var(--transition);
  }
  .mobile-book-btn:active { transform: scale(.95); }
}

@media (min-width: 768px) {
  .mobile-book-btn { display: none; }
}

/* ================================================================
   EMPTY + LOADING
   ================================================================ */
.empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; padding: 60px 20px;
  color: var(--text-muted); font-size: 14px; text-align: center;
}
.empty-icon { font-size: 36px; }

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex; align-items: center; justify-content: center;
  padding: 60px;
}
