/* ============================================================
   AGENTSEE RESEARCH NOTEBOOK — SPA stylesheet
   Dark frame (topbar/sidebar/margin) + light content well (reader/atlas).
   Theme variants override key tokens via [data-theme="..."].
   ============================================================ */

/* -----------------------------------------------------------
   Design tokens
   ----------------------------------------------------------- */
:root {
  /* Reusing parent site tokens where available:
     --bg:#111  --text:#e8e4df  --accent:#d95a7f  --accent2:#6b8aad
     --body:'Source Serif 4'  --display:'Newsreader' */

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif-text: 'Source Serif 4', Georgia, serif;

  /* Surface — content well (light paper) */
  --well-bg: #faf8f4;
  --well-bg-soft: #f5f0e6;
  --well-border: #e6dfcd;

  /* Frame — dark chrome */
  --frame-bg: #0e0d0b;
  --frame-bg-soft: #16140f;
  --frame-border: #2a261e;

  /* Ink (text) — defaults are for the light well; frame overrides further down */
  --ink: #2a2520;
  --ink-dim: #5a5347;
  --ink-faint: #8a8578;

  /* Accent system */
  --accent-ink: #b85a36;       /* warm terracotta — claim emphasis */
  --accent-soft: rgba(184, 90, 54, 0.10);
  --accent-rule: rgba(184, 90, 54, 0.35);

  /* Panels & rules */
  --panel: #ffffff;
  --rule: var(--well-border);
  --rule-strong: #c8c0aa;

  /* Type-coded badge colors */
  --type-axiom: oklch(55% 0.12 260);
  --type-construct: oklch(55% 0.10 180);
  --type-mechanism: oklch(55% 0.13 20);
  --type-prediction: oklch(55% 0.13 140);
  --type-experiment: oklch(55% 0.14 80);
  --type-kill: oklch(45% 0.16 20);
  --type-positioning: oklch(50% 0.06 280);
  --type-gap: oklch(50% 0.04 60);
  --type-open: oklch(50% 0.04 60);

  /* Layout */
  --sidebar-w: 280px;
  --right-w: 340px;
  --topbar-h: 52px;
}

/* Theme: Atlas — lighter, cooler, more academic */
body[data-theme="atlas"] {
  --well-bg: #eee8d9;
  --well-bg-soft: #f5efe0;
  --accent-ink: oklch(48% 0.16 250);
  --accent-soft: oklch(48% 0.16 250 / 0.10);
}

/* Theme: Journal — high-contrast editorial */
body[data-theme="journal"] {
  --well-bg: #fffaf0;
  --well-bg-soft: #fbf3e3;
  --accent-ink: oklch(40% 0.14 25);
  --accent-soft: oklch(40% 0.14 25 / 0.10);
}

/* -----------------------------------------------------------
   Base
   ----------------------------------------------------------- */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--frame-bg);
  color: var(--text, #e8e4df);
  font-family: var(--serif-text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; }

* { box-sizing: border-box; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; background: none; border: 0; outline: 0; padding: 0; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--frame-border);
  color: var(--text-secondary, #a8a29e);
}

/* -----------------------------------------------------------
   Layout grid
   ----------------------------------------------------------- */
#root { height: 100vh; }
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--right-w);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar topbar"
    "sidebar center right";
  height: 100vh;
}
.topbar  { grid-area: topbar; }
.sidebar { grid-area: sidebar; }
.center  { grid-area: center; }
.right   { grid-area: right; }

body.right-hidden .app {
  grid-template-columns: var(--sidebar-w) 1fr 0;
}
body.right-hidden .right { display: none; }

body[data-view="atlas"] .center { padding: 0; }

/* -----------------------------------------------------------
   Topbar
   ----------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: var(--frame-bg);
  border-bottom: 1px solid var(--frame-border);
  color: var(--text, #e8e4df);
  z-index: 30;
}
/* Brand: AgentSee wordmark is the link back to home. Sub stays static. */
.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.topbar-brand .brand-link {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  padding: 4px 0;
  transition: color 0.15s;
}
.topbar-brand .brand-link:hover { color: var(--accent, #d95a7f); }
.topbar-brand .back {
  display: inline-block;
  font-family: var(--body, 'Source Serif 4', Georgia, serif);
  font-size: 14px;
  color: var(--text-secondary, #a8a29e);
  transition: transform 0.15s, color 0.15s;
}
.topbar-brand .brand-link:hover .back {
  color: var(--accent, #d95a7f);
  transform: translateX(-3px);
}
.topbar-brand .mark {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.topbar-brand .sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #a8a29e);
  text-transform: uppercase;
}

.topbar-nav { display: flex; gap: 4px; padding: 0 6px; }
.topbar-nav button {
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 4px;
  color: var(--text-secondary, #a8a29e);
  letter-spacing: 0.02em;
  transition: color 0.12s, background 0.12s;
}
.topbar-nav button:hover { color: var(--text, #e8e4df); background: rgba(255,255,255,0.04); }
.topbar-nav button.active {
  color: var(--text, #e8e4df);
  background: rgba(255,255,255,0.06);
}

.topbar-spacer { flex: 1; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 8px;
  min-width: 320px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--frame-border);
  border-radius: 5px;
  color: var(--text-secondary, #a8a29e);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.topbar-search:hover { border-color: var(--accent, #d95a7f); background: rgba(255,255,255,0.06); }
.topbar-search span { flex: 1; }
.topbar-search kbd { margin-left: 4px; }

.topbar-actions { display: flex; gap: 4px; }
.topbar-actions button {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--text-secondary, #a8a29e);
  transition: color 0.12s, background 0.12s;
  display: inline-flex;
  align-items: center;
}
.topbar-actions button:hover { color: var(--text, #e8e4df); background: rgba(255,255,255,0.05); }

/* -----------------------------------------------------------
   Sidebar
   ----------------------------------------------------------- */
.sidebar {
  background: var(--frame-bg);
  border-right: 1px solid var(--frame-border);
  color: var(--text, #e8e4df);
  overflow-y: auto;
  padding: 18px 0 32px;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--frame-border); border-radius: 4px; }

.sidebar-intro {
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--frame-border);
  margin-bottom: 12px;
}
.sidebar-intro .label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent, #d95a7f);
  margin-bottom: 6px;
}
.sidebar-intro .counts {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text, #e8e4df);
}
.sidebar-intro .meta {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #a8a29e);
}

.sidebar-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 16px 14px;
  border-bottom: 1px solid var(--frame-border);
  margin-bottom: 10px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--frame-border);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-secondary, #a8a29e);
  transition: border-color 0.12s, color 0.12s;
}
.filter-chip:hover { border-color: rgba(255,255,255,0.18); }
.filter-chip.active { border-color: currentColor; }
.filter-chip .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
}

/* TOC groups */
.toc-group {
  padding: 0 6px 2px;
}
.toc-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 14px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
  transition: color 0.12s, background 0.12s;
}
.toc-group-head:hover { color: var(--text, #e8e4df); background: rgba(255,255,255,0.03); }
.toc-group-head .count {
  font-size: 10px;
  color: var(--text-secondary, #a8a29e);
  opacity: 0.6;
}
.toc-group-head .chev {
  display: inline-flex;
  transition: transform 0.12s;
}
.toc-group.open .toc-group-head .chev { transform: rotate(90deg); }

.toc-items {
  display: none;
  padding: 2px 0 8px;
}
.toc-group.open .toc-items { display: block; }

.toc-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 14px 5px 22px;
  font-family: var(--serif-text);
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--text-secondary, #a8a29e);
  text-align: left;
  border-radius: 3px;
  transition: color 0.12s, background 0.12s;
}
.toc-link:hover { color: var(--text, #e8e4df); background: rgba(255,255,255,0.03); }
.toc-link.active {
  color: var(--accent, #d95a7f);
  background: rgba(217, 90, 127, 0.06);
}
.toc-link.read { color: rgba(232, 228, 223, 0.55); }
.toc-link.read.active { color: var(--accent, #d95a7f); }
.toc-link .toc-dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
  flex-shrink: 0;
}
.toc-link.active .toc-dot { opacity: 1; }

/* -----------------------------------------------------------
   Center / Reader
   ----------------------------------------------------------- */
.center {
  position: relative;
  overflow-y: auto;
  background: var(--well-bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.center::-webkit-scrollbar { width: 10px; }
.center::-webkit-scrollbar-track { background: transparent; }
.center::-webkit-scrollbar-thumb { background: var(--rule-strong); border-radius: 5px; }

.progress-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 2px;
  background: transparent;
  pointer-events: none;
}
.progress-bar .fill {
  height: 100%;
  background: var(--accent-ink);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.08s linear;
}

.reader {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 48px 96px;
}

.reader-hero {
  padding: 28px 0 32px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 28px;
}
.reader-hero .kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 16px;
}
.reader-hero .kicker .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-ink);
}
.reader-hero h1 {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 32px;
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.012em;
  color: var(--ink);
  margin: 0 0 14px;
}
.reader-hero .lede {
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink-dim);
  max-width: 60ch;
  margin: 0 0 18px;
}
.reader-hero .stats {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
}
.reader-hero .stat strong {
  display: block;
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
}

.category-header {
  display: flex;
  gap: 20px;
  padding: 36px 0 14px;
  margin: 16px 0 4px;
  border-bottom: 1px dashed var(--rule);
}
.category-header .num {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  padding-top: 4px;
}
.category-header .title h2 {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 19px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 4px;
  letter-spacing: -0.005em;
}
.category-header .title .desc {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-dim);
}

/* Section card */
.section {
  position: relative;
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
  transition: background 0.18s;
}
.section.dim {
  opacity: 0.32;
  filter: grayscale(0.4);
}
.section.focused .bookmark-indicator { opacity: 1; }
.section.focused { background: rgba(0,0,0,0.012); }
.section.bookmarked .bookmark-indicator {
  background: var(--accent-ink);
  opacity: 1;
}
.bookmark-indicator {
  position: absolute;
  left: -16px;
  top: 26px;
  width: 3px;
  height: 18px;
  background: var(--rule-strong);
  opacity: 0;
  border-radius: 2px;
  transition: opacity 0.15s, background 0.15s;
}

.comment-pin {
  position: absolute;
  right: -36px;
  top: 22px;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--well-bg-soft);
  border: 1px solid var(--rule-strong);
  color: var(--ink-faint);
  transition: color 0.12s, border-color 0.12s, transform 0.12s;
}
.comment-pin:hover { color: var(--accent-ink); border-color: var(--accent-ink); transform: scale(1.06); }
.comment-pin.has {
  background: var(--accent-ink);
  color: #fff;
  border-color: var(--accent-ink);
  font-weight: 500;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.section-title {
  flex: 1;
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 17.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink);
  letter-spacing: -0.004em;
  cursor: pointer;
  text-align: left;
  margin: 0;
}
.section-title:hover { color: var(--accent-ink); }
.section-actions { display: flex; gap: 4px; align-items: center; }
.section-action {
  padding: 4px;
  border-radius: 3px;
  color: var(--ink-faint);
  display: inline-flex;
  transition: color 0.12s, background 0.12s;
}
.section-action:hover { color: var(--accent-ink); background: var(--accent-soft); }
.section-action.on { color: var(--accent-ink); }

/* Badges */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 4px 0 12px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px 2px 6px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--well-bg-soft);
  color: var(--ink-dim);
  border: 1px solid var(--rule);
}
.badge.attr { color: var(--ink-faint); }
.badge.tc { color: var(--ink); }
.badge.tc .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.badge.tc.type-axiom .dot       { background: var(--type-axiom); }
.badge.tc.type-construct .dot   { background: var(--type-construct); }
.badge.tc.type-mechanism .dot   { background: var(--type-mechanism); }
.badge.tc.type-prediction .dot  { background: var(--type-prediction); }
.badge.tc.type-experiment .dot  { background: var(--type-experiment); }
.badge.tc.type-kill .dot        { background: var(--type-kill); }
.badge.tc.type-positioning .dot { background: var(--type-positioning); }
.badge.tc.type-gap .dot         { background: var(--type-gap); }
.badge.tc.type-open .dot        { background: var(--type-open); }

/* When type color-coding is ON, paint the whole badge */
body[data-typecoded="true"] .badge.tc {
  border-color: currentColor;
  color: var(--type-gap);
}
body[data-typecoded="true"] .badge.tc.type-axiom       { color: var(--type-axiom); }
body[data-typecoded="true"] .badge.tc.type-construct   { color: var(--type-construct); }
body[data-typecoded="true"] .badge.tc.type-mechanism   { color: var(--type-mechanism); }
body[data-typecoded="true"] .badge.tc.type-prediction  { color: var(--type-prediction); }
body[data-typecoded="true"] .badge.tc.type-experiment  { color: var(--type-experiment); }
body[data-typecoded="true"] .badge.tc.type-kill        { color: var(--type-kill); }
body[data-typecoded="true"] .badge.tc.type-positioning { color: var(--type-positioning); }

/* Claim callout */
.claim {
  display: block;
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 15.5px;
  font-style: italic;
  line-height: 1.55;
  color: var(--ink);
  padding: 12px 16px;
  margin: 0 0 14px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-ink);
  border-radius: 0 3px 3px 0;
}
.claim-label {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-ink);
  font-style: normal;
  margin-right: 8px;
  vertical-align: 1px;
}

/* Section body wrap (falsifier + expand row + body) */
.section-body-wrap { margin: 6px 0 4px; }

.falsifier {
  margin: 6px 0 12px;
  padding: 10px 14px;
  border: 1px dashed var(--rule-strong);
  border-radius: 4px;
  background: rgba(0,0,0,0.02);
}
.falsifier .f-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.falsifier .f-text {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-dim);
  font-style: italic;
}

.expand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 0;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: left;
}
.expand-row:hover { color: var(--accent-ink); }
.expand-row .glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--well-bg-soft);
  font-family: var(--serif-text);
  font-size: 13px;
}
.expand-row .line {
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.section-body {
  display: none;
  padding: 8px 0 12px;
}
.section.expanded .section-body { display: block; }
.section-body-inner {
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink-dim);
}
.section-body-inner p { margin: 0 0 12px; }
.section-body-inner h2 {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  margin: 18px 0 8px;
  letter-spacing: 0;
}
.section-body-inner h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin: 14px 0 6px;
}
.section-body-inner ul, .section-body-inner ol {
  margin: 6px 0 12px 22px;
  padding: 0;
}
.section-body-inner li { margin-bottom: 4px; }
.section-body-inner strong { color: var(--ink); font-weight: 600; }
.section-body-inner code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--well-bg-soft);
  padding: 1px 4px;
  border-radius: 3px;
}
.section-body-inner a {
  color: var(--accent-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.section-body-inner a:hover { color: var(--ink); }

/* Deps */
.deps {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.deps-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 4px;
}
.dep-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  font-size: 11.5px;
  color: var(--ink-dim);
  text-decoration: none;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.dep-chip:hover {
  color: var(--accent-ink);
  border-color: var(--accent-ink);
  background: var(--accent-soft);
}

/* -----------------------------------------------------------
   Right column (margin rail)
   ----------------------------------------------------------- */
.right {
  background: var(--frame-bg);
  border-left: 1px solid var(--frame-border);
  overflow-y: auto;
  color: var(--text, #e8e4df);
}
.margin-threads { padding: 20px 18px 40px; }

.mt-hdr {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--frame-border);
}

.card {
  background: var(--frame-bg-soft);
  border: 1px solid var(--frame-border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text, #e8e4df);
}
.card .who {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 5px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--accent, #d95a7f);
}
.card .who .when {
  color: var(--text-secondary, #a8a29e);
  opacity: 0.7;
  margin-left: auto;
}

button.add {
  width: 100%;
  padding: 9px 12px;
  border: 1px dashed var(--frame-border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-secondary, #a8a29e);
  transition: color 0.12s, border-color 0.12s;
}
button.add:hover { color: var(--accent, #d95a7f); border-color: var(--accent, #d95a7f); }

.new-comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--frame-bg-soft);
  border: 1px solid var(--frame-border);
  border-radius: 4px;
}
.new-comment-form input,
.new-comment-form textarea {
  background: var(--frame-bg);
  border: 1px solid var(--frame-border);
  border-radius: 3px;
  padding: 7px 9px;
  font-size: 12.5px;
  color: var(--text, #e8e4df);
}
.new-comment-form input::placeholder,
.new-comment-form textarea::placeholder { color: var(--text-secondary, #a8a29e); opacity: 0.6; }
.new-comment-form input:focus,
.new-comment-form textarea:focus { border-color: var(--accent, #d95a7f); }
.new-comment-form textarea { min-height: 70px; resize: vertical; font-family: var(--serif-text); }
.new-comment-form .row {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.new-comment-form button {
  padding: 5px 12px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
  border: 1px solid var(--frame-border);
}
.new-comment-form button:hover { color: var(--text, #e8e4df); }
.new-comment-form button.primary {
  background: var(--accent, #d95a7f);
  color: #fff;
  border-color: var(--accent, #d95a7f);
}
.new-comment-form button.primary:hover { background: #c8456f; color: #fff; }

.reading-path {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--frame-border);
}
.reading-path .hdr {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
  margin-bottom: 8px;
}
.path-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--text-secondary, #a8a29e);
  text-align: left;
  transition: color 0.12s, background 0.12s;
}
.path-item:hover { color: var(--text, #e8e4df); background: rgba(255,255,255,0.03); }
.path-item .num {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--accent, #d95a7f);
  width: 14px;
  text-align: center;
}

/* -----------------------------------------------------------
   Command palette
   ----------------------------------------------------------- */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  animation: cmdk-fade 0.12s ease;
}
@keyframes cmdk-fade { from { opacity: 0; } to { opacity: 1; } }

.cmdk {
  width: min(640px, 92vw);
  background: var(--frame-bg-soft);
  border: 1px solid var(--frame-border);
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55);
  overflow: hidden;
  color: var(--text, #e8e4df);
}
.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--frame-border);
}
.cmdk-input-row .icon { display: inline-flex; color: var(--text-secondary, #a8a29e); }
.cmdk-input-row input {
  flex: 1;
  font-size: 14.5px;
  color: var(--text, #e8e4df);
}
.cmdk-input-row input::placeholder { color: var(--text-secondary, #a8a29e); }

.cmdk-list {
  max-height: 52vh;
  overflow-y: auto;
  padding: 6px;
}
.cmdk-item {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text, #e8e4df);
  cursor: pointer;
  transition: background 0.06s;
}
.cmdk-item.active { background: rgba(255,255,255,0.06); }
.cmdk-item .kind {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent, #d95a7f);
}
.cmdk-item .t {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 14px;
  color: var(--text, #e8e4df);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cmdk-item .c {
  font-size: 11px;
  color: var(--text-secondary, #a8a29e);
  text-align: right;
}
.cmdk-empty {
  padding: 28px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-secondary, #a8a29e);
}
.cmdk-foot {
  display: flex;
  gap: 18px;
  padding: 10px 14px;
  border-top: 1px solid var(--frame-border);
  font-size: 10.5px;
  color: var(--text-secondary, #a8a29e);
}

/* -----------------------------------------------------------
   Tweaks panel
   ----------------------------------------------------------- */
.tweaks {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: 340px;
  background: var(--frame-bg-soft);
  border-left: 1px solid var(--frame-border);
  box-shadow: -16px 0 40px rgba(0,0,0,0.35);
  z-index: 80;
  color: var(--text, #e8e4df);
  display: flex;
  flex-direction: column;
  animation: tweaks-slide 0.18s ease;
}
@keyframes tweaks-slide { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.tweaks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--frame-border);
}
.tweaks-head .t {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
}
.tweaks-head button { padding: 4px; color: var(--text-secondary, #a8a29e); }
.tweaks-head button:hover { color: var(--text, #e8e4df); }

.tweaks-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tweak { display: flex; flex-direction: column; gap: 6px; }
.tweak .lbl {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
}
.theme-swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--frame-border);
  background: var(--frame-bg);
  text-align: left;
  transition: border-color 0.12s;
}
.theme-swatch:hover { border-color: rgba(255,255,255,0.18); }
.theme-swatch.active { border-color: var(--accent, #d95a7f); }
.theme-swatch .hint {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary, #a8a29e);
}
.theme-swatch .name {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 12.5px;
  color: var(--text, #e8e4df);
}
.theme-swatch .preview {
  display: flex;
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--frame-border);
  margin-top: 2px;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 4px;
  border: 1px solid var(--frame-border);
  background: var(--frame-bg);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.switch:hover { border-color: rgba(255,255,255,0.18); }
.switch .dot-track {
  width: 28px; height: 16px;
  border-radius: 999px;
  background: var(--frame-border);
  position: relative;
  transition: background 0.15s;
}
.switch .dot-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text-secondary, #a8a29e);
  transition: transform 0.15s, background 0.15s;
}
.switch.on .dot-track { background: rgba(217, 90, 127, 0.45); }
.switch.on .dot-track::after {
  transform: translateX(12px);
  background: var(--accent, #d95a7f);
}

/* -----------------------------------------------------------
   Atlas (2D + 3D shared chrome)
   ----------------------------------------------------------- */
.atlas {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}
.atlas-chrome {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 32px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--well-bg);
}
.atlas-chrome .sub {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.atlas-chrome h2 {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 4px;
  letter-spacing: -0.005em;
}
.atlas-chrome .desc {
  font-size: 12.5px;
  color: var(--ink-dim);
  max-width: 56ch;
}

.atlas-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}
.atlas-legend .li {
  display: flex;
  align-items: center;
  gap: 6px;
}
.atlas-legend .swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.atlas-canvas {
  position: relative;
  background: var(--well-bg);
  overflow: hidden;
}
.atlas-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.atlas-link {
  fill: none;
  stroke: var(--rule-strong);
  stroke-width: 0.7;
  opacity: 0.45;
  transition: stroke 0.12s, opacity 0.12s, stroke-width 0.12s;
}
.atlas-link.highlight {
  stroke: var(--accent-ink);
  stroke-width: 1.4;
  opacity: 0.95;
}
.atlas-link.dim { opacity: 0.08; }

.atlas-node { cursor: pointer; }
.atlas-node circle { transition: r 0.12s; }
.atlas-node.dim { opacity: 0.22; }
.atlas-node.linked circle { stroke: var(--accent-ink); stroke-width: 1.3; }
.atlas-node.selected circle { stroke: var(--ink); stroke-width: 2; }
.atlas-node text { transition: opacity 0.15s; }

.atlas-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 3px;
}
.atlas-controls button {
  width: 28px; height: 28px;
  border-radius: 3px;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 13px;
}
.atlas-controls button:hover { background: var(--well-bg-soft); color: var(--ink); }

.atlas-detail {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.12);
  display: none;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  z-index: 4;
}
.atlas-detail.open { display: block; }
.atlas-detail .close {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px;
  color: var(--ink-faint);
}
.atlas-detail .close:hover { color: var(--ink); }
.atlas-detail .label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.atlas-detail h3 {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 16.5px;
  font-weight: 500;
  color: var(--ink);
  margin: 0 0 6px;
}
.atlas-detail .claim-mini {
  font-family: var(--display, 'Newsreader', Georgia, serif);
  font-size: 13px;
  font-style: italic;
  color: var(--ink-dim);
  line-height: 1.55;
  margin-bottom: 12px;
}
.btn-open {
  padding: 7px 12px;
  border-radius: 4px;
  background: var(--accent-ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.btn-open:hover { filter: brightness(0.95); }

.linked-list {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.linked-list .hdr {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.linked-list button {
  display: block;
  width: 100%;
  padding: 5px 8px;
  border-radius: 3px;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: left;
}
.linked-list button:hover { background: var(--well-bg-soft); color: var(--accent-ink); }

/* -----------------------------------------------------------
   Mobile advisory banner — hidden on desktop, shown ≤1100px
   ----------------------------------------------------------- */
.nb-mobile-notice {
  display: none;
}
.nb-mobile-notice.dismissed {
  display: none !important;
}
@media (max-width: 1100px) {
  .nb-mobile-notice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 12px 44px 12px 18px;
    background: rgba(217, 90, 127, 0.08);
    border-bottom: 1px solid rgba(217, 90, 127, 0.25);
    color: var(--text, #e8e4df);
    font-family: var(--body, 'Source Serif 4', Georgia, serif);
    font-size: 13px;
    line-height: 1.5;
    backdrop-filter: blur(8px);
  }
  .nb-mobile-notice p {
    margin: 0;
    flex: 1;
  }
  .nb-mobile-notice-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary, #a8a29e);
    font-size: 22px;
    line-height: 1;
    padding: 4px 10px;
    cursor: pointer;
    border-radius: 3px;
  }
  .nb-mobile-notice-close:hover {
    color: var(--text, #e8e4df);
    background: rgba(255, 255, 255, 0.05);
  }
}

/* -----------------------------------------------------------
   Responsive — collapse to single column on narrow screens
   ----------------------------------------------------------- */
@media (max-width: 1100px) {
  :root { --right-w: 0; }
  .app {
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-areas:
      "topbar topbar"
      "sidebar center";
  }
  .right { display: none; }
}

@media (max-width: 720px) {
  :root { --sidebar-w: 0; --topbar-h: 48px; }
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "center";
  }
  .sidebar { display: none; }
  .topbar-brand .sub { display: none; }
  .topbar-search { min-width: 0; flex: 1; }
  .topbar-search span { display: none; }
  .topbar-actions button:nth-child(2) { display: none; }
  .reader { padding: 16px 22px 60px; }
  .reader-hero h1 { font-size: 26px; }
  .comment-pin { right: -12px; }
  .section { padding-right: 18px; }
  .atlas-chrome { padding: 16px 18px; }
  .atlas-detail { width: calc(100% - 32px); }
}
