/* ==========================================================================
   Tủ Sách Cá Cơm — Editorial Print Magazine & Warm Paper Design System
   Anti-wall-of-text typography, generous whitespace, high visual scannability
   ========================================================================== */

:root {
  --bg: #f6f2ea;
  --bg-alt: #efe9dd;
  --surface: #fcfbf8;
  --surface-tint: #f8f4ec;
  --ink: #221f1b;
  --ink-soft: #595248;
  --ink-muted: #847b6e;
  --rule: #e2dacb;
  --rule-strong: #cfc4b0;
  --accent: #b54a2a;
  --accent-hover: #973a1e;
  --accent-soft: #f7e6df;
  --green: #2e5a49;
  --green-soft: #e3efe9;
  --amber: #a9711e;
  --amber-soft: #f7eedb;
  --indigo: #394d73;
  --indigo-soft: #e5ebf5;
  --plum: #6c4768;
  --plum-soft: #f0e6ef;
  --shadow-sm: 0 1px 2px rgba(34, 31, 27, 0.04), 0 4px 12px rgba(34, 31, 27, 0.03);
  --shadow-md: 0 8px 28px rgba(34, 31, 27, 0.08), 0 1px 3px rgba(34, 31, 27, 0.05);
  --shadow-lg: 0 24px 60px rgba(24, 20, 15, 0.18);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --reader-font-size: 16.5px;
}

html[data-theme='dark'] {
  --bg: #171512;
  --bg-alt: #201d19;
  --surface: #23201b;
  --surface-tint: #2a2620;
  --ink: #eee8dd;
  --ink-soft: #b8b0a3;
  --ink-muted: #8c8376;
  --rule: #353028;
  --rule-strong: #4a4338;
  --accent: #e07856;
  --accent-hover: #ee8c6c;
  --accent-soft: rgba(224, 120, 86, 0.16);
  --green: #6bb598;
  --green-soft: rgba(107, 181, 152, 0.15);
  --amber: #e2ae56;
  --amber-soft: rgba(226, 174, 86, 0.15);
  --indigo: #8ca6db;
  --indigo-soft: rgba(140, 166, 219, 0.15);
  --plum: #c492be;
  --plum-soft: rgba(196, 146, 190, 0.15);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.6);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* ---------- MASTHEAD & NAVIGATION ---------- */
.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--rule);
}

.masthead-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  cursor: pointer;
  min-width: 0;
}

.brand-kicker {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.brand-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
}

.brand-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(24px, 3vw, 31px);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-title em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.live-pill.static .live-dot {
  background: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-soft);
}

.masthead-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.tool-btn:hover {
  border-color: var(--rule-strong);
  color: var(--ink);
}

.tool-btn.active {
  background: var(--plum-soft);
  border-color: var(--plum);
  color: var(--plum);
}

.tool-btn.icon-only {
  width: 36px;
  padding: 0;
  justify-content: center;
}

.search-trigger {
  min-width: 175px;
  justify-content: space-between;
}

.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg-alt);
  color: var(--ink-muted);
  border: 1px solid var(--rule);
}

.nav-rail {
  border-top: 1px solid color-mix(in srgb, var(--rule) 65%, transparent);
}

.nav-rail-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-rail-inner::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 14px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s;
}

.nav-tab:hover {
  color: var(--ink);
}

.nav-tab.active {
  color: var(--accent);
  font-weight: 600;
}

.nav-tab.active::after {
  content: '';
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 2.5px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}

.nav-count {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-alt);
  color: var(--ink-muted);
}

.nav-tab.active .nav-count {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- UPDATE BANNER ---------- */
.update-banner {
  max-width: 1240px;
  margin: 14px auto 0;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  background: var(--green-soft);
  border: 1px solid color-mix(in srgb, var(--green) 35%, transparent);
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13.5px;
  font-weight: 500;
}

.update-banner button {
  padding: 6px 14px;
  border-radius: 999px;
  border: 0;
  background: var(--green);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.update-banner.mobile-sync {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
}

.update-banner.mobile-sync button {
  background: var(--accent);
}

.update-banner.mobile-sync button:disabled {
  opacity: 0.65;
  cursor: wait;
}

/* ---------- MAIN STAGE ---------- */
.stage {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 1.5px solid var(--ink);
}

.section-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.section-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(22px, 2.5vw, 29px);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.section-sub {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.section-block {
  margin-top: 44px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
  transition: all 0.15s;
}

.link-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  transition: background 0.15s, transform 0.1s;
}

.primary-btn:hover {
  background: var(--accent-hover);
}

.primary-btn:active {
  transform: translateY(1px);
}

/* ---------- EDITORIAL HOME HERO SPREAD ---------- */
.hero-spread {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 24px;
  align-items: stretch;
}

.spotlight-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 30px 32px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.spotlight-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--amber), var(--green));
}

.spotlight-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.issue-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.spotlight-title {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: clamp(26px, 3vw, 35px);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.spotlight-summary {
  margin: 0 0 18px;
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.spotlight-takeaways {
  display: grid;
  gap: 8px;
  margin: 0 0 22px;
  padding: 14px 16px;
  background: var(--bg);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--accent);
}

.spotlight-takeaway-item {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
}

.spotlight-takeaway-item strong {
  color: var(--accent);
}

.spotlight-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

/* Right side of hero: Issue Stats & Quick Pulse */
.pulse-panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 24px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.pulse-heading {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
}

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

.metric-tile {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.metric-tile:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.metric-num {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink);
}

.metric-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.progress-box {
  padding-top: 14px;
  border-top: 1px dashed var(--rule-strong);
}

.progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--bg-alt);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  transition: width 0.35s ease;
}

/* ---------- SHELF STRIP (6 NGĂN TỦ BÌA MÀU) ---------- */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.shelf-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 20px 20px 18px;
  cursor: pointer;
  transition: transform 0.16s, box-shadow 0.16s, border-color 0.16s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shelf-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--shelf-accent, var(--accent));
}

.shelf-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.shelf-badge-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--shelf-soft, var(--accent-soft));
  color: var(--shelf-accent, var(--accent));
}

.shelf-count {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-muted);
}

.shelf-name {
  margin: 2px 0 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
}

.shelf-tagline {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* ---------- VISUAL SKILL DECK CARDS ---------- */
.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}

.skill-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.skill-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.skill-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.skill-title {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
}

.skill-title:hover {
  color: var(--accent);
}

.skill-when {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.55;
}

.skill-pillars {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pillar-chip {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}

.prompt-box {
  background: var(--bg);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink);
}

.prompt-box-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.skill-card-foot {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.skill-card-foot > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tiny-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.tiny-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tiny-btn.accent {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.tiny-btn.accent:hover {
  background: var(--accent);
  color: #fff;
}

/* ---------- RECENT CHANGELOG STRIP ---------- */
.recent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 18px 18px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
}

.doc-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.doc-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2.5px 9px;
  border-radius: 999px;
  background: var(--bg-alt);
  color: var(--ink-soft);
  white-space: nowrap;
  flex-shrink: 0;
}

.pill.new {
  background: var(--green-soft);
  color: var(--green);
}

.pill.status-chua_doc {
  background: var(--bg-alt);
  color: var(--ink-muted);
}

.pill.status-dang_ngam {
  background: var(--amber-soft);
  color: var(--amber);
}

.pill.status-da_duyet {
  background: var(--green-soft);
  color: var(--green);
}

.pill.status-da_ap_dung {
  background: var(--indigo-soft);
  color: var(--indigo);
}

.doc-card-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 18.5px;
  font-weight: 600;
  line-height: 1.28;
  color: var(--ink);
}

.doc-card-summary {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.doc-card-meta {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--ink-muted);
  border-top: 1px solid color-mix(in srgb, var(--rule) 65%, transparent);
}

.doc-card-note-tag {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- LIBRARY FILTER BAR ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-pill {
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink-soft);
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.14s;
}

.filter-pill:hover {
  border-color: var(--rule-strong);
  color: var(--ink);
}

.filter-pill.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.filter-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.select-clean {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--accent);
}

.subgroup-block {
  margin-bottom: 34px;
}

.subgroup-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
}

.subgroup-title span {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg-alt);
  padding: 2px 9px;
  border-radius: 999px;
}

/* ---------- AI TEAM 3-CARD MAP ---------- */
.team-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 34px;
}

.team-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-top: 4px solid var(--team-color, var(--accent));
  border-radius: var(--radius-md);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.team-name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--team-color, var(--ink));
}

.team-sub {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 2px 0 14px;
}

.team-list {
  margin: 0 0 14px;
  padding-left: 18px;
  font-size: 13.5px;
  color: var(--ink);
}

.team-list li {
  margin-bottom: 5px;
}

.team-switch {
  font-size: 12.5px;
  color: var(--ink-soft);
  padding-top: 10px;
  border-top: 1px dashed var(--rule);
}

/* ---------- KNOWLEDGE GRAPH VIEW ---------- */
.graph-shell {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.graph-toolbar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-tint);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.graph-canvas-wrap {
  position: relative;
  width: 100%;
  height: 580px;
  background: radial-gradient(circle at center, var(--surface) 0%, var(--bg) 100%);
}

#graphCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#graphCanvas:active {
  cursor: grabbing;
}

.graph-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  max-width: 280px;
  box-shadow: var(--shadow-md);
  z-index: 5;
}

/* ---------- REFLECT VIEW ---------- */
.reflect-hero {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.reflect-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 22px;
}

.reflect-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 20px 22px;
}

.reflect-note-item {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border-left: 3px solid var(--accent);
  margin-bottom: 12px;
  cursor: pointer;
}

.reflect-note-item:hover {
  background: var(--bg-alt);
}

.sync-panel {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* ---------- EDITORIAL READER OVERLAY (ANTI-WALL-OF-TEXT) ---------- */
.reader-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 17, 13, 0.56);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
}

.reader-sheet {
  width: 100%;
  max-width: 1180px;
  min-height: calc(100vh - 36px);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: auto;
}

.reader-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.reader-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.reader-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
}

.reader-back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.reader-crumb {
  font-size: 12.5px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.segmented {
  display: inline-flex;
  background: var(--bg-alt);
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--rule);
}

.seg-btn {
  border: 0;
  background: transparent;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}

.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.font-controls {
  display: inline-flex;
  gap: 4px;
}

.mini-icon-btn {
  height: 30px;
  min-width: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mini-icon-btn:hover, .mini-icon-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 0;
  flex: 1;
}

.reader-layout.focus-mode {
  grid-template-columns: minmax(0, 1fr);
}

.reader-layout.focus-mode .reader-aside {
  display: none;
}

.reader-article {
  padding: 36px clamp(20px, 5vw, 56px) 64px;
  background: var(--surface);
  min-width: 0;
}

.reader-article-inner {
  max-width: 68ch;
  margin: 0 auto;
}

.article-kicker-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.article-h1 {
  margin: 0 0 14px;
  font-family: var(--font-serif);
  font-size: clamp(28px, 3.4vw, 39px);
  font-weight: 600;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.article-byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 12.5px;
  color: var(--ink-muted);
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

/* At-a-glance 30s box */
.glance-box {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.glance-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.glance-summary {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
}

.chapter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}

.chapter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--rule);
  font-size: 12px;
  color: var(--ink-soft);
}

.chapter-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chapter-pill .ch-num {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
  font-weight: 600;
}

/* Chapter Accordion Cards (Anti-Wall-of-Text!) */
.chapter-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.chapter-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.chapter-card.open {
  border-color: var(--rule-strong);
  box-shadow: var(--shadow-sm);
}

.chapter-card-head {
  width: 100%;
  border: 0;
  background: var(--surface-tint);
  padding: 15px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
}

.chapter-card.open .chapter-card-head {
  border-bottom: 1px solid var(--rule);
}

.chapter-head-left {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.chapter-num-badge {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.1;
  flex-shrink: 0;
  min-width: 28px;
}

.chapter-card-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}

.chapter-card-preview {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.chapter-card.open .chapter-card-preview {
  display: none;
}

.chapter-chevron {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  padding-top: 4px;
}

.chapter-card-body {
  padding: 20px 22px 22px;
  display: none;
}

.chapter-card.open .chapter-card-body {
  display: block;
}

/* Prose styling inside reader */
.prose {
  font-size: var(--reader-font-size);
  line-height: 1.8;
  color: var(--ink);
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.48em;
  font-weight: 600;
  margin: 2em 0 0.7em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
  line-height: 1.25;
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.2em;
  font-weight: 600;
  margin: 1.5em 0 0.5em;
  color: var(--ink);
}

.prose p {
  margin: 0 0 1em;
}

.prose ul, .prose ol {
  margin: 0 0 1.1em;
  padding-left: 1.4em;
}

.prose li {
  margin-bottom: 0.48em;
}

.prose li strong {
  color: var(--ink);
}

.prose blockquote {
  margin: 1.3em 0;
  padding: 14px 18px;
  border-left: 3.5px solid var(--accent);
  background: var(--bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-size: 1.07em;
  font-style: italic;
  color: var(--ink-soft);
}

.prose .callout-box {
  margin: 1.2em 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border-left: 3.5px solid var(--amber);
  font-size: 0.94em;
}

.prose .callout-box.rule {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-alt);
  color: var(--accent);
}

.prose .code-wrap {
  position: relative;
  margin: 1.2em 0;
}

.prose pre {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: #23201b;
  color: #f2ece2;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

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

.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #f2ece2;
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.prose .table-wrap {
  overflow-x: auto;
  margin: 1.3em 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88em;
  line-height: 1.5;
}

.prose th {
  background: var(--bg-alt);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  border-bottom: 1.5px solid var(--rule-strong);
}

.prose td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.prose tr:last-child td {
  border-bottom: 0;
}

.wikilink-btn {
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  margin: 0 2px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--indigo) 35%, transparent);
  background: var(--indigo-soft);
  color: var(--indigo);
  font-size: 0.88em;
  font-weight: 500;
}

.wikilink-btn:hover {
  background: var(--indigo);
  color: #fff;
}

/* Reader Aside (Reflection & Metadata) */
.reader-aside {
  background: var(--bg);
  border-left: 1px solid var(--rule);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.aside-box {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: 16px;
}

.aside-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 10px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.status-btn {
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 8px;
  border-radius: 8px;
  text-align: center;
}

.status-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

.reflect-textarea {
  width: 100%;
  min-height: 112px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  font-size: 13.5px;
  line-height: 1.55;
  resize: vertical;
}

.reflect-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.save-hint {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.related-item {
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--bg);
  font-size: 12.5px;
}

.related-item:hover {
  border-color: var(--accent);
}

.related-item strong {
  display: block;
  font-size: 13px;
  color: var(--ink);
}

.related-item span {
  font-size: 11.5px;
  color: var(--ink-muted);
}

/* ---------- SEARCH MODAL ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 17, 13, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 24px;
}

.search-dialog {
  width: 100%;
  max-width: 680px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--rule);
}

.search-input-wrap input {
  flex: 1;
  border: 0;
  background: transparent;
  font-size: 16px;
  outline: none;
}

.esc-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink-muted);
}

.search-hints {
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}

.hint-chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-soft);
}

.hint-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.search-results {
  max-height: 55vh;
  overflow-y: auto;
  padding: 10px;
}

.search-item {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-item:hover {
  background: var(--bg);
}

.search-item-title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.search-item-snippet {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
}

/* ---------- RESPONSIVE MOBILE (390px SAFE) ---------- */
@media (max-width: 980px) {
  .hero-spread,
  .shelf-grid,
  .team-grid,
  .reflect-grid,
  .reader-layout {
    grid-template-columns: 1fr;
  }

  .reader-aside {
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
}

@media (max-width: 640px) {
  .masthead-inner {
    padding: 12px 14px 10px;
  }
  .nav-rail-inner {
    padding: 0 12px;
  }
  .stage {
    padding: 18px 14px 64px;
  }
  .hide-sm {
    display: none;
  }
  .search-trigger {
    min-width: auto;
    padding: 0 10px;
  }
  .search-trigger span,
  .search-trigger kbd {
    display: none;
  }
  .spotlight-card {
    padding: 22px 18px;
  }
  .skills-grid {
    grid-template-columns: 1fr;
  }
  .reader-backdrop {
    padding: 0;
  }
  .reader-sheet {
    border-radius: 0;
    min-height: 100vh;
  }
  .reader-topbar {
    padding: 10px 12px;
  }
  .reader-crumb {
    display: none;
  }
  .reader-article {
    padding: 22px 16px 40px;
  }
  .graph-canvas-wrap {
    height: 430px;
  }
}
