/* ═══════════════════════════════════════════════════════════════════
   Extended Mind — design system
   Warm paper + ink, one amber accent. Inter for UI, Newsreader for
   reading surfaces (headings, highlights, quotes).
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg: #F8F6F2;
  --surface: #FFFFFF;
  --surface-2: #F2EFE9;
  --surface-3: #EAE6DE;
  --border: #E6E1D8;
  --border-strong: #D5CEC2;

  --text: #1C1917;
  --text-2: #57534E;
  --text-3: #8A847B;

  --accent: #B45F06;
  --accent-hover: #9A5005;
  --accent-soft: rgba(180, 95, 6, 0.09);
  --accent-ring: rgba(180, 95, 6, 0.28);
  --on-accent: #FFFFFF;

  --success: #15803D;
  --success-soft: rgba(21, 128, 61, 0.09);
  --danger: #B91C1C;
  --danger-soft: rgba(185, 28, 28, 0.08);
  --info: #1D4ED8;

  --overlay: rgba(28, 25, 23, 0.45);
  --ink-canvas: #15130F;
  /* Knowledge graph (connections page) */
  --graph-bg: #FBF9F5;
  --graph-grid: rgba(28, 25, 23, 0.06);
  --graph-text: #2A2622;
  --graph-muted: rgba(42, 38, 34, 0.55);
  --graph-theme: #D08A2E;
  --graph-tension: #C95E52;
  --graph-book: #BDB3A3;
  --graph-pair: #7F93AB;
  --graph-place: #4F7FB5;
  --graph-ring: #5A3B0E;
  --graph-panel: rgba(255, 255, 255, 0.97);
  --graph-panel-border: rgba(28, 25, 23, 0.12);
  --graph-item: rgba(28, 25, 23, 0.03);
  --graph-item-hover: rgba(28, 25, 23, 0.07);
  --graph-item-border: rgba(28, 25, 23, 0.1);
  --graph-link: #9A5A0C;

  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --font-highlight: var(--font-serif);
  --font-display: var(--font-serif);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 6px 16px -4px rgba(28, 25, 23, 0.10), 0 2px 4px rgba(28, 25, 23, 0.04);
  --shadow-lg: 0 20px 40px -12px rgba(28, 25, 23, 0.22), 0 4px 10px rgba(28, 25, 23, 0.05);

  --sidebar-w: 252px;
  --topbar-h: 60px;
  --content-max: 1180px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --transition: all 0.18s var(--ease);

  /* Legacy aliases — keep older inline styles & scripts rendering */
  --bg-main: var(--bg);
  --bg-card: var(--surface);
  --bg-active: var(--surface-2);
  --text-primary: var(--text);
  --text-secondary: var(--text-2);
  --text-muted: var(--text-3);
  --accent-gold: var(--accent);
  --accent-gold-hover: var(--accent-hover);
  --text-gold: var(--accent);
  --border-light: var(--border);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #121110;
  --surface: #1B1A18;
  --surface-2: #232220;
  --surface-3: #2C2A27;
  --border: #2E2C29;
  --border-strong: #403D38;

  --text: #EEEBE5;
  --text-2: #B7B1A7;
  --text-3: #817B72;

  --accent: #E3A857;
  --accent-hover: #EDB96F;
  --accent-soft: rgba(227, 168, 87, 0.12);
  --accent-ring: rgba(227, 168, 87, 0.35);
  --on-accent: #1A1204;

  --success: #4ADE80;
  --success-soft: rgba(74, 222, 128, 0.10);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.10);
  --info: #93C5FD;

  --overlay: rgba(0, 0, 0, 0.6);
  --ink-canvas: #0D0C0A;
  --graph-bg: #15130F;
  --graph-grid: rgba(255, 255, 255, 0.07);
  --graph-text: #EEEBE5;
  --graph-muted: rgba(238, 235, 229, 0.55);
  --graph-theme: #E3A857;
  --graph-tension: #D4776B;
  --graph-book: #D6D0C4;
  --graph-pair: #A9B8C9;
  --graph-place: #5B8BC0;
  --graph-ring: #FFF6E5;
  --graph-panel: rgba(24, 23, 21, 0.95);
  --graph-panel-border: rgba(255, 255, 255, 0.1);
  --graph-item: rgba(255, 255, 255, 0.03);
  --graph-item-hover: rgba(255, 255, 255, 0.09);
  --graph-item-border: rgba(255, 255, 255, 0.08);
  --graph-link: #F0C27E;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 20px -6px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.65);

  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; color: var(--text); letter-spacing: -0.01em; }

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

img { display: block; max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

::selection { background: var(--accent-soft); }

svg { flex-shrink: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ─── App shell ──────────────────────────────────────────────────── */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--topbar-h);
  padding: 0 20px;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  flex-shrink: 0;
}
.sidebar-logo:hover { color: var(--text); }
.sidebar-logo img { width: 26px; height: 26px; object-fit: contain; }

.sidebar-quick { padding: 4px 14px 8px; position: relative; }

.nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 16px 10px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link svg { width: 17px; height: 17px; stroke-width: 1.8; opacity: 0.85; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link.active svg { opacity: 1; }
.nav-link.nav-sub { padding-left: 37px; font-size: 13px; }

.nav-count {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.nav-link.active .nav-count { color: var(--accent); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 12px 10px 12px 14px;
  border-top: 1px solid var(--border);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.user-meta { flex: 1; min-width: 0; line-height: 1.3; margin-left: 8px; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11.5px; color: var(--text-3); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active { color: var(--accent); }
.sidebar-footer .icon-btn { width: 30px; height: 30px; }
.icon-btn svg { width: 17px; height: 17px; stroke-width: 1.8; }

.main-area {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.topbar-title .crumb { color: var(--text-3); font-weight: 500; }
.topbar-title .crumb:hover { color: var(--accent); }
.topbar-title .sep { color: var(--text-3); margin: 0 6px; font-weight: 400; }

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

.search-container-header { position: relative; width: 320px; max-width: 42vw; }
.search-container-header form { margin: 0; }
.search-container-header > svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.search-input-top {
  width: 100%;
  height: 36px;
  padding: 0 52px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 13.5px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input-top::placeholder { color: var(--text-3); }
.search-input-top:hover { border-color: var(--border-strong); }
.search-input-top:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-family: var(--font-sans);
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--surface-2);
  pointer-events: none;
}

.content-wrapper {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 32px 80px;
}

.nav-toggle { display: none; }
.nav-overlay { display: none; }

/* ─── Dropdown menu ──────────────────────────────────────────────── */
.menu {
  position: absolute;
  z-index: 80;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: none;
}
.menu.open { display: block; animation: pop 0.14s var(--ease); }
.menu a, .menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--surface-2); color: var(--text); }
.menu svg { width: 16px; height: 16px; color: var(--text-3); }
.menu-hint { margin-left: auto; font-size: 11.5px; color: var(--text-3); }
.sidebar-quick .menu { left: 14px; right: 14px; top: 100%; }

@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ─── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.page-title, .page-heading {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.page-heading { margin-bottom: 24px; }
.page-subtitle { margin-top: 6px; color: var(--text-2); font-size: 14.5px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
.back-link::before { content: '←'; }
.back-link:hover { color: var(--accent); }

/* ─── Sections ───────────────────────────────────────────────────── */
.section { margin-bottom: 40px; }
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.section-title { font-size: 15px; font-weight: 600; color: var(--text); }
.section-meta { font-size: 12.5px; color: var(--text-3); }
.section-link { font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.section-link:hover { color: var(--accent); }

/* ─── Layout helpers ─────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.narrow { max-width: 680px; }
.narrow-center { max-width: 680px; margin: 0 auto; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.dashboard-col { display: flex; flex-direction: column; gap: 28px; min-width: 0; }

/* ─── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xs);
}
.card + .card { margin-top: 16px; }
.stack > .card + .card, .grid-2 > .card + .card, .grid-3 > .card + .card { margin-top: 0; }
a.card { display: block; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
a.card:hover { color: inherit; border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-subtitle { font-size: 13px; color: var(--text-2); margin-bottom: 18px; }
.card-flush { padding: 0; overflow: hidden; }

/* ─── Stats ──────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 36px;
}
.stat-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
a.stat-card:hover { color: inherit; border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.stat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}
.stat-title svg { width: 16px; height: 16px; color: var(--text-3); stroke: currentColor; stroke-width: 1.8; fill: none; }
.stat-value {
  margin-top: 8px;
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 500;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat-trend { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.stat-trend.up { color: var(--success); }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.btn svg { width: 16px; height: 16px; stroke-width: 1.9; }
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn.disabled { opacity: 0.45; cursor: default; pointer-events: none; }

.btn-primary, .btn-gold {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-primary:hover, .btn-gold:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }

.btn-secondary { background: var(--surface); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--surface); border-color: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14.5px; }
.btn-block { width: 100%; }

.btn-amazon { background: #FF9900; border-color: #FF9900; color: #111; font-weight: 600; }
.btn-amazon:hover { background: #F08C00; border-color: #F08C00; color: #111; }

/* ─── Forms ──────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; position: relative; }
.form-group:last-child { margin-bottom: 0; }
.form-label { font-size: 13px; font-weight: 500; color: var(--text); }
.form-hint { font-size: 12px; color: var(--text-3); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.form-stack { display: flex; flex-direction: column; gap: 16px; }
.form-stack > .form-group { margin-bottom: 0; }

.form-input, .form-textarea, .form-select, select.form-input {
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-3); }
.form-input:hover, .form-textarea:hover { border-color: var(--text-3); }
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.form-textarea.quote-input { font-family: var(--font-serif); font-size: 17px; }
input[type="file"].form-input { padding: 6px 8px; font-size: 13px; }
input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
select.form-input, .form-select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238A847B' stroke-width='2.2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}
.date-inputs { display: grid; grid-template-columns: 76px 1fr 96px; gap: 8px; }

.input-with-icon { position: relative; }
.input-with-icon svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-3); pointer-events: none;
}
.input-with-icon .form-input { padding-left: 34px; }

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--surface-3);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }

/* ─── Alerts ─────────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 20px;
}
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.alert-warning, .alert-info { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 22%, transparent); }
.alert-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); font-weight: 400; }
.alert a { color: inherit; text-decoration: underline; }

.danger-zone {
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
  border-radius: var(--radius-lg);
  padding: 24px;
  background: var(--surface);
}
.danger-zone-title { font-size: 15px; font-weight: 600; color: var(--danger); margin-bottom: 6px; }

/* ─── Tags & chips ───────────────────────────────────────────────── */
.tag, .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
a.tag:hover, a.chip:hover { border-color: var(--border-strong); color: var(--text); }
.tag.active, .chip.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip-removable button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 0 1px 2px;
  opacity: 0.7;
}
.chip-removable button:hover { opacity: 1; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-list:empty { display: none; }

/* Search-as-you-type list (country picker). In the page flow rather than
   floating, so a scrolling form (the add-highlight modal) never cuts it off. */
.combo-list {
  max-height: 240px; overflow-y: auto; overscroll-behavior: contain;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.combo-list[hidden], .combo-list li[hidden] { display: none; }
.combo-list [role="option"] {
  padding: 9px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.combo-list [role="option"]:hover, .combo-list [role="option"].is-active { background: var(--surface-2); }
.combo-list [role="option"].is-active { box-shadow: inset 2px 0 0 var(--accent); }
.combo-empty { padding: 9px 10px; font-size: 13.5px; color: var(--text-3); }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.segmented button, .segmented a {
  height: 28px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.segmented button:hover, .segmented a:hover { color: var(--text); }
.segmented .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar .form-input { min-height: 36px; height: 36px; padding-top: 0; padding-bottom: 0; }

/* ─── Progress ───────────────────────────────────────────────────── */
.progress { height: 6px; background: var(--surface-3); border-radius: var(--radius-full); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.6s var(--ease); }

/* ─── Pagination ─────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 36px; flex-wrap: wrap; }
.pagination a, .pagination span {
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.pagination a:hover { background: var(--surface-2); color: var(--text); }
.pagination .current { background: var(--text); color: var(--bg); }
.pagination .disabled { opacity: 0.35; }
.pagination .gap { min-width: 20px; padding: 0; color: var(--text-3); }

/* ─── Empty states ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-2);
}
.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 20px;
}
.empty-state-icon svg { width: 22px; height: 22px; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state-text { font-size: 14px; color: var(--text-2); max-width: 420px; margin: 0 auto; }
.empty-state .btn { margin-top: 18px; }

/* ─── Book covers ────────────────────────────────────────────────── */
.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 4px 8px 8px 4px;
  overflow: hidden;
  background: var(--surface-3);
  box-shadow: var(--shadow-md), inset 3px 0 0 rgba(0, 0, 0, 0.08);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,0.14) 0, rgba(255,255,255,0.08) 3%, transparent 8%);
  pointer-events: none;
}
.cover-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  text-align: center;
  color: #fff;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  background: #6B5B4B;
  overflow: hidden;
}
.cover-sm .cover-fallback { font-size: 16px; padding: 4px; }

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 32px 24px;
}
.book-tile { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.book-tile:hover { color: inherit; }
.book-tile .cover { transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease); }
.book-tile:hover .cover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.book-tile-title { font-size: 13.5px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-tile-author { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-tile-meta { font-size: 12px; color: var(--text-3); }

.shelf {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 128px;
  gap: 20px;
  overflow-x: auto;
  padding: 4px 2px 14px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.shelf > * { scroll-snap-align: start; }

/* ─── Highlights ─────────────────────────────────────────────────── */
.highlights-grid { columns: 2 340px; column-gap: 16px; }
.highlights-grid > * { break-inside: avoid; margin-bottom: 16px; }
.highlight-list { display: flex; flex-direction: column; gap: 12px; }

.highlight-card-item, .quote-card, .highlight-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.highlight-card-item[data-highlight], .quote-card[data-highlight] { cursor: pointer; }
.highlight-card-item[data-highlight]:hover, .quote-card[data-highlight]:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.highlight-text, .quote-text {
  font-family: var(--font-highlight);
  font-size: 18px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.quote-text.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }

.highlight-note, .note {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2);
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.highlight-source { display: flex; align-items: center; gap: 10px; min-width: 0; }
.highlight-source .cover { width: 26px; flex-shrink: 0; border-radius: 2px 4px 4px 2px; box-shadow: var(--shadow-xs); }
.highlight-source-text { min-width: 0; line-height: 1.35; }
.highlight-book-title { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
a.highlight-book-title:hover { color: var(--accent); }
.highlight-book-author { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.highlight-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--text-3);
}
.highlight-meta span { display: inline-flex; align-items: center; gap: 4px; }
.highlight-meta svg { width: 13px; height: 13px; }
.highlight-tags { display: flex; flex-wrap: wrap; gap: 5px; }

.highlight-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.highlight-actions { display: flex; gap: 6px; margin-left: auto; }
.highlight-actions form { margin: 0; }

mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }

/* On this day */
.otd-card {
  background: linear-gradient(160deg, var(--accent-soft), transparent 70%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.otd-item { padding: 12px 0; border-top: 1px solid var(--border); cursor: pointer; }
.section-header + .otd-item { border-top: none; padding-top: 4px; }
.otd-year { font-family: var(--font-serif); font-size: 20px; font-weight: 600; color: var(--accent); line-height: 1; margin-bottom: 6px; }
.otd-text { font-family: var(--font-serif); font-size: 15.5px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.otd-item:hover .otd-text { color: var(--accent); }

/* ─── Book detail ────────────────────────────────────────────────── */
.book-hero {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  margin-bottom: 36px;
}
.book-hero-title { font-family: var(--font-serif); font-size: 36px; font-weight: 500; line-height: 1.15; letter-spacing: -0.015em; }
.book-hero-author { margin-top: 6px; font-size: 16px; color: var(--text-2); }
.book-hero-stats { display: flex; gap: 20px; margin: 18px 0; font-size: 13px; color: var(--text-2); }
.book-hero-stats strong { color: var(--text); font-weight: 600; font-size: 15px; }

details.add-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 28px;
}
details.add-panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
details.add-panel > summary::-webkit-details-marker { display: none; }
details.add-panel > summary .plus {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  transition: transform 0.2s var(--ease);
}
details.add-panel[open] > summary .plus { transform: rotate(45deg); }
details.add-panel > summary .hint { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--text-3); }
details.add-panel > form { padding: 4px 18px 18px; border-top: 1px solid var(--border); padding-top: 18px; }

/* ─── Modals ─────────────────────────────────────────────────────── */
.modal-overlay, .surprise-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.16s ease;
}
.modal-content, .surprise-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: rise 0.2s var(--ease);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 17px; font-weight: 600; }
.modal-header h2 { font-family: var(--font-sans) !important; font-size: 17px !important; font-weight: 600 !important; }
.modal-close, .surprise-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.modal-close:hover, .surprise-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 20px 22px 22px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }

.surprise-card { max-width: 620px; padding: 36px 40px 28px; overflow-y: auto; }
.surprise-close { position: absolute; top: 12px; right: 12px; }
.surprise-quote {
  font-family: var(--font-highlight);
  font-size: 23px;
  line-height: 1.55;
  color: var(--text);
  margin: 14px 0 18px;
  white-space: pre-line;
}
.surprise-note { margin-bottom: 18px; }
.surprise-note:not(:empty) {
  font-size: 14px; line-height: 1.6; color: var(--text-2);
  padding: 10px 14px; background: var(--surface-2);
  border-left: 2px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.surprise-meta { display: flex; flex-direction: column; gap: 3px; }
.surprise-book { font-weight: 600; font-size: 14px; color: var(--text); }
.surprise-book:hover { color: var(--accent); }
.surprise-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }
.surprise-actions form { margin: 0; }
.surprise-actions .spacer { flex: 1; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.9s linear infinite; }

/* ─── Dashboard widgets ──────────────────────────────────────────── */
.greeting-title { font-family: var(--font-serif); font-size: 32px; font-weight: 500; letter-spacing: -0.015em; line-height: 1.15; }

.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.widget-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 0;
}
.widget-body { padding: 14px 18px 18px; }

.map-side { position: relative; height: 220px; padding: 8px 12px 0; }
#choropleth-map { width: 100%; height: 100%; display: block; }
.choropleth-country { stroke: var(--surface); stroke-width: 0.4; cursor: pointer; transition: opacity 0.15s; }
.choropleth-country.active { opacity: 0.75; }
.map-heat-legend {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px 16px; font-size: 11.5px; color: var(--text-3);
}
.heat-bar { flex: 1; max-width: 120px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--surface-3), var(--accent)); }

.country-rank { list-style: none; display: flex; flex-direction: column; gap: 2px; padding: 0 10px 12px; }
.country-rank a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: var(--radius-sm); font-size: 13px;
}
.country-rank a:hover { background: var(--surface-2); color: var(--text); }
.country-rank .count { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; }

.mini-graph-container { height: 280px; position: relative; }
#mini-graph-svg { display: block; width: 100%; height: 100%; }

.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.quick-action {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 500; cursor: pointer; text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.quick-action:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text); }
.quick-action .qa-icon { width: 30px; height: 30px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.quick-action .qa-icon svg { width: 16px; height: 16px; }

/* ─── Timelines ──────────────────────────────────────────────────── */
.country-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.country-card { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.country-card .flag { font-size: 28px; line-height: 1; }
.country-card .name { font-weight: 600; font-size: 14.5px; }
.country-card .meta { font-size: 12.5px; color: var(--text-3); }
.country-card .chev { margin-left: auto; color: var(--text-3); transition: transform 0.15s; }
.country-card:hover .chev { transform: translateX(3px); color: var(--accent); }
.country-card .span { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.country-hero { display: flex; align-items: center; gap: 18px; margin-bottom: 36px; }
.country-hero .flag { font-size: 52px; line-height: 1; }

.vtimeline { position: relative; max-width: 760px; padding-left: 132px; }
.vtimeline::before {
  content: '';
  position: absolute;
  left: 111px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(to bottom, transparent, var(--border-strong) 4%, var(--border-strong) 96%, transparent);
}
.vt-item { position: relative; margin-bottom: 18px; }
.vt-date {
  position: absolute;
  left: -132px;
  width: 96px;
  top: 18px;
  text-align: right;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.2;
}
.vt-date small { display: block; font-family: var(--font-sans); font-size: 11.5px; font-weight: 500; color: var(--text-3); }
.vt-item::before {
  content: '';
  position: absolute;
  left: -26px;
  top: 22px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2.5px solid var(--accent);
  box-shadow: 0 0 0 4px var(--bg);
}

/* ─── Connections graph ──────────────────────────────────────────── */
.graph-container {
  background: var(--graph-bg);
  color: var(--graph-text);
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 32px;
}
.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--graph-grid);
  flex-wrap: wrap;
}
.graph-title { font-size: 14px; font-weight: 600; color: var(--graph-text); }
.graph-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 12px; color: var(--graph-muted); }
.graph-legend span { display: inline-flex; align-items: center; gap: 6px; }
.graph-legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.view-toggle { display: inline-flex; gap: 2px; padding: 3px; background: rgba(255, 255, 255, 0.06); border-radius: var(--radius-md); }
.view-toggle-btn {
  height: 28px; padding: 0 12px; border: none; border-radius: 6px;
  background: transparent; color: rgba(238, 235, 229, 0.6);
  font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.view-toggle-btn:hover { color: #EEEBE5; }
.view-toggle-btn.active { background: rgba(255, 255, 255, 0.12); color: #fff; }
.graph-svg-wrapper { position: relative; height: 560px; cursor: grab; }
.graph-svg-wrapper.grabbing { cursor: grabbing; }
#graph-svg { display: block; width: 100%; height: 100%; }
.graph-empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.graph-empty-state-text { font-size: 15px; font-weight: 500; color: var(--graph-text); opacity: 0.8; margin-bottom: 6px; }

.network-tooltip {
  position: absolute;
  z-index: 1100;
  max-width: 280px;
  padding: 10px 12px;
  background: rgba(21, 19, 15, 0.96);
  border: 1px solid rgba(227, 168, 87, 0.3);
  border-radius: var(--radius-md);
  color: #EEEBE5;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  font-size: 12.5px;
}
.network-tooltip-label { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
.network-tooltip-type { display: inline-block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; margin-bottom: 6px; }
.network-tooltip-type.theme { color: #E3A857; }
.network-tooltip-type.book { color: #D6D0C4; }
.network-tooltip-type.country { color: #7FA7D4; }
.network-tooltip-detail { color: rgba(238, 235, 229, 0.7); line-height: 1.45; }

.connections-list { display: flex; flex-direction: column; gap: 28px; }
.connection-group { }
.connection-theme { font-family: var(--font-serif); font-size: 22px; font-weight: 500; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.connection-theme::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.connection-quotes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.connection-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 22px 22px 18px;
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}
.connection-card.kept { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: 0 0 0 3px var(--accent-soft); }
.connection-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.connection-card .connection-theme { margin-bottom: 0; }
.connection-card .connection-theme::before { display: none; }
.connection-insight { margin-top: 8px; max-width: 72ch; color: var(--text-2); font-size: 14.5px; line-height: 1.6; }
.connection-actions { display: flex; gap: 4px; flex-shrink: 0; }
.connection-actions form { margin: 0; }
.connection-card .connection-quotes-grid .highlight-card-item { padding: 16px 18px; gap: 10px; }
.connection-card .connection-quotes-grid .quote-text { font-size: 16px; }
.chip-tension { background: rgba(212, 119, 107, 0.12); border-color: transparent; color: #B4533F; }
[data-theme="dark"] .chip-tension { color: #E59A8E; }
.connection-quote-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; }
.connection-quote-text { font-family: var(--font-serif); font-size: 16px; line-height: 1.55; margin-bottom: 10px; }
.connection-quote-book { font-size: 12.5px; font-weight: 500; color: var(--text-3); }

/* ─── To-read ────────────────────────────────────────────────────── */
.tr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.tr-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tr-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.tr-head { display: flex; gap: 14px; align-items: flex-start; }
.tr-cover { width: 52px; flex-shrink: 0; }
.tr-cover .cover { border-radius: 2px 5px 5px 2px; }
.tr-title { font-weight: 600; font-size: 14.5px; line-height: 1.35; }
.tr-author { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.tr-desc { font-size: 13px; color: var(--text-2); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tr-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.tr-foot form { margin: 0; }
.owned-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--success); }

.cover-preview { display: flex; gap: 14px; align-items: flex-start; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); margin-top: 10px; }
.cover-preview img, .cover-preview .ph { width: 64px; height: 94px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.cover-preview .ph { display: flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-3); }

/* ─── Stats page ─────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.chart-card { padding: 20px; }
.chart-card .card-title { margin-bottom: 14px; }
.chart-box { position: relative; height: 230px; }
.chart-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -62%); text-align: center; pointer-events: none; }
.chart-center strong { display: block; font-family: var(--font-serif); font-size: 26px; font-weight: 600; }
.chart-center span { font-size: 11.5px; color: var(--text-3); }
.insight-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.insight-pill { padding: 6px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-full); font-size: 12.5px; color: var(--text-2); }
.insight-pill strong { color: var(--text); }
.span-2 { grid-column: 1 / -1; }
.cloud { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cloud-tag {
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.cloud-tag:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.book-list { list-style: none; display: flex; flex-direction: column; }
.book-list li { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.book-list li:last-child { border-bottom: none; }

/* ─── Settings ───────────────────────────────────────────────────── */
.settings-layout { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.settings-section { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; }
.settings-section h2 { font-size: 15px; font-weight: 600; }
.settings-section .desc { margin-top: 4px; font-size: 13px; color: var(--text-2); line-height: 1.5; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

/* ─── Auth ───────────────────────────────────────────────────────── */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-aside {
  position: relative;
  background: var(--ink-canvas);
  color: #EEEBE5;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.auth-aside::before {
  content: '';
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(40% 35% at 25% 30%, rgba(227, 168, 87, 0.22), transparent 70%),
    radial-gradient(35% 30% at 80% 75%, rgba(127, 167, 212, 0.14), transparent 70%);
  pointer-events: none;
}
.auth-brand { position: relative; display: flex; align-items: center; gap: 10px; font-family: var(--font-serif); font-size: 20px; font-weight: 600; color: #EEEBE5; }
.auth-brand img { width: 28px; height: 28px; }
.auth-quote { position: relative; max-width: 460px; }
.auth-quote blockquote { font-family: var(--font-serif); font-size: 30px; line-height: 1.35; font-weight: 400; letter-spacing: -0.01em; }
.auth-quote cite { display: block; margin-top: 16px; font-style: normal; font-size: 13px; color: rgba(238, 235, 229, 0.55); }
.auth-aside-foot { position: relative; font-size: 12.5px; color: rgba(238, 235, 229, 0.45); }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-family: var(--font-serif); font-size: 30px; font-weight: 500; letter-spacing: -0.015em; }
.auth-card .lead { margin: 6px 0 28px; color: var(--text-2); }
.auth-card .form-input { min-height: 42px; }
.auth-links { margin-top: 20px; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--text-2); }
.auth-links a { color: var(--accent); font-weight: 500; }
.auth-mobile-brand { display: none; }

/* ─── Error pages ────────────────────────────────────────────────── */
.error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 24px; }
.error-page .auth-mobile-brand { margin-bottom: 40px; }
.error-code { font-family: var(--font-serif); font-size: 88px; font-weight: 500; line-height: 1; color: var(--accent); letter-spacing: -0.03em; }
.error-page h1 { margin-top: 12px; font-family: var(--font-serif); font-size: 30px; font-weight: 500; }
.error-page .lead { margin: 8px 0 28px; max-width: 440px; color: var(--text-2); }

/* ─── World map page ─────────────────────────────────────────────── */
.worldmap-page .content-wrapper { max-width: none; padding: 0; }
#worldmap-root {
  position: fixed;
  top: var(--topbar-h);
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  background: var(--surface-2);
  z-index: 10;
}
#leaflet-map { width: 100%; height: 100%; z-index: 1; background: var(--surface-2); }
.explorer-legend {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  min-width: 210px;
  padding: 14px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  pointer-events: none;
}
.legend-title { font-family: var(--font-serif); font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.legend-stats { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.legend-stat { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.legend-hint { font-size: 11.5px; color: var(--text-3); }

.country-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  z-index: 600;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  transition: transform 0.3s var(--ease);
}
.country-panel.open { transform: none; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.panel-flag { font-size: 28px; line-height: 1; }
.panel-country { font-family: var(--font-serif); font-size: 22px; font-weight: 500; }
.panel-close { width: 32px; height: 32px; border: none; border-radius: var(--radius-md); background: var(--surface-2); color: var(--text-2); font-size: 20px; cursor: pointer; }
.panel-close:hover { color: var(--text); background: var(--surface-3); }
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-link { display: inline-flex; margin: 0 20px 18px; }
.panel-timeline { position: relative; padding-left: 22px; }
.panel-timeline::before { content: ''; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.panel-event { position: relative; margin-bottom: 14px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-md); }
.panel-event::before { content: ''; position: absolute; left: -21px; top: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--surface); }
.panel-event-year { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.panel-event-text { font-family: var(--font-serif); font-size: 15px; line-height: 1.5; margin-bottom: 6px; }
.panel-event-book { font-size: 12px; color: var(--text-3); }

.em-marker-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 0 var(--accent-ring);
  animation: markerPulse 2.6s ease-in-out infinite;
  transition: transform 0.2s;
  position: relative;
}
.em-marker-dot:hover { transform: scale(1.35); }
.em-marker-dot.multi { width: 18px; height: 18px; }
.em-marker-count {
  position: absolute; top: -8px; right: -10px;
  background: var(--text); color: var(--bg);
  font-size: 9.5px; font-weight: 700; padding: 1px 5px; border-radius: 8px; line-height: 1.4;
}
@keyframes markerPulse { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-ring); } 50% { box-shadow: 0 0 0 7px transparent; } }
.leaflet-container { font-family: var(--font-sans) !important; }
.leaflet-tooltip.em-tooltip {
  background: var(--text); color: var(--bg); border: none;
  border-radius: var(--radius-sm); padding: 5px 9px; font-size: 12px; box-shadow: var(--shadow-md);
}
.leaflet-tooltip.em-tooltip::before { display: none; }
.leaflet-bar a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar { border: 1px solid var(--border) !important; box-shadow: var(--shadow-md) !important; }
[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9) saturate(0.6); }

/* Timeline player (world map) */
.tl-player {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 22px;
  z-index: 550;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.tl-player[hidden] { display: none; }
.tl-player > * { pointer-events: auto; }
.tl-controls, .tl-now {
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.tl-controls { display: flex; align-items: center; gap: 14px; padding: 10px 14px; }
.tl-play {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background 0.15s, transform 0.15s;
}
.tl-play:hover { background: var(--accent-hover); }
.tl-play:active { transform: scale(0.96); }
.tl-play:disabled { opacity: 0.4; cursor: default; }
.tl-play .tl-icon-pause, .is-playing .tl-play .tl-icon-play { display: none; }
.is-playing .tl-play .tl-icon-pause { display: inline; }
.tl-play .tl-icon-play svg { margin-left: 2px; }
.tl-year {
  min-width: 3.2ch;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tl-track { flex: 1; min-width: 0; position: relative; padding-top: 22px; }
.tl-density {
  position: absolute; left: 7px; right: 7px; top: 0; height: 22px;
  display: flex; align-items: flex-end; gap: 1px;
  pointer-events: none;
}
.tl-density i { flex: 1; max-width: 14px; margin: 0 auto; background: var(--accent); opacity: 0.28; border-radius: 1px 1px 0 0; }
.tl-density { justify-content: space-between; }
.tl-slider { width: 100%; margin: 0; accent-color: var(--accent); cursor: pointer; }
.tl-ends { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-all { visibility: hidden; }
.is-filtered .tl-all { visibility: visible; }
.tl-now { padding: 12px 16px; cursor: pointer; animation: rise 0.25s var(--ease); }
.tl-now[hidden] { display: none; }
.tl-now-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.tl-now-year { font-family: var(--font-serif); font-size: 18px; font-weight: 600; color: var(--accent); }
.tl-now-place { font-size: 13px; font-weight: 600; }
.tl-now-more { margin-left: auto; font-size: 12px; color: var(--text-3); }
.tl-now-text { font-family: var(--font-serif); font-size: 16px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tl-now-book { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.tl-now-progress { height: 2px; margin: 10px -16px -12px; background: var(--surface-3); border-radius: 0 0 var(--radius-lg) var(--radius-lg); overflow: hidden; visibility: hidden; }
.is-playing .tl-now-progress { visibility: visible; }
.tl-now-progress span { display: block; height: 100%; width: 0; background: var(--accent); }
@keyframes tlProgress { from { width: 0; } to { width: 100%; } }
.tl-speed {
  height: 30px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 600; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.tl-speed:hover { color: var(--text); border-color: var(--text-3); }
.em-marker-dot.fresh { transform: scale(1.35); box-shadow: 0 0 0 6px var(--accent-ring); animation: markerPop 0.6s var(--ease); }
@keyframes markerPop { from { transform: scale(0.2); opacity: 0; } 60% { transform: scale(1.6); opacity: 1; } to { transform: scale(1.35); } }
.panel-event.future { opacity: 0.45; }
.map-unavailable { margin: 100px auto 0; max-width: 420px; background: var(--surface); }

/* ─── Misc ───────────────────────────────────────────────────────── */
.fade-in { animation: rise 0.3s var(--ease) both; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s var(--ease); box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .nav-overlay { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 55; opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  .main-area { margin-left: 0; }
  .nav-toggle { display: inline-grid; margin-left: -8px; }
  .top-header { padding: 0 16px; gap: 10px; }
  .content-wrapper { padding: 24px 16px 64px; }
  #worldmap-root { left: 0; }
  .settings-section { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .auth-shell { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .auth-mobile-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 32px; font-family: var(--font-serif); font-size: 18px; font-weight: 600; }
  .auth-mobile-brand img { width: 24px; height: 24px; }
}

@media (max-width: 720px) {
  .search-container-header { width: auto; flex: 1; max-width: none; }
  .kbd { display: none; }
  .search-input-top { padding-right: 12px; }
  .topbar-title { display: none; }
  .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title, .page-heading, .greeting-title { font-size: 26px; }
  .book-hero { grid-template-columns: 112px minmax(0, 1fr); gap: 18px; }
  .book-hero-title { font-size: 25px; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 24px 16px; }
  .tr-grid { grid-template-columns: minmax(0, 1fr); }
  .vtimeline { padding-left: 26px; }
  .vtimeline::before { left: 5px; }
  .vt-item::before { left: -26px; }
  .vt-date { position: static; width: auto; text-align: left; margin-bottom: 6px; font-size: 16px; }
  .vt-date small { display: inline; margin-left: 6px; }
  .surprise-card { padding: 28px 22px 20px; }
  .surprise-quote { font-size: 19px; }
  .modal-overlay, .surprise-overlay { padding: 12px; align-items: flex-end; }
  .modal-content, .surprise-card { max-height: calc(100vh - 24px); }
  .date-inputs { grid-template-columns: 64px 1fr 84px; }
  .highlight-text, .quote-text { font-size: 17px; }
  .graph-svg-wrapper { height: 440px; }
  .quick-actions { grid-template-columns: minmax(0, 1fr); }
  .tl-player { left: 8px; right: 8px; bottom: 10px; }
  .tl-controls { gap: 8px 10px; padding: 8px 12px 10px; flex-wrap: wrap; }
  .tl-track { order: 5; flex-basis: 100%; }
  .tl-speed { margin-left: auto; }
  .tl-year { font-size: 20px; }
  .tl-now-text { -webkit-line-clamp: 2; font-size: 15px; }
  .explorer-legend { left: 8px; top: 8px; min-width: 0; padding: 10px 12px; }
  .explorer-legend .legend-hint { display: none; }
  .connection-head { flex-direction: column; }
}

/* Fields filled in for the reader to check (e.g. from shared text) */
.form-input.is-prefilled, .form-textarea.is-prefilled { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ─── Articles (books with kind = "article") ─────────────────────── */
.kind-badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em; color: var(--accent); background: var(--accent-soft); vertical-align: 1px;
}
.book-hero-source { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: -6px 0 14px; }
.book-hero-source a { display: inline-flex; align-items: center; gap: 5px; }
.book-hero-source a:hover { color: var(--accent); }
.form-group[hidden] { display: none; }

/* ─── Settings: "Save from anywhere" how-to ──────────────────────── */
.howto { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.howto-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.howto-item summary { cursor: pointer; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; list-style: none; }
.howto-item summary::-webkit-details-marker { display: none; }
.howto-item summary::after { content: "+"; margin-left: auto; color: var(--text-3); font-weight: 400; }
.howto-item[open] summary::after { content: "–"; }
.howto-item ol { margin: 12px 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.5; }
.howto-item p { margin: 8px 0 4px; font-size: 14px; }
.copy-field { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; }
.copy-field code {
  flex: 1; min-width: 0; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--surface-2);
  font-size: 12px; line-height: 1.45; word-break: break-all; white-space: pre-wrap;
}
.bookmarklet { cursor: grab; margin-left: 6px; }

/* Book / Article switch: a .segmented control built from radio buttons */
.segmented[data-source-switch] { align-self: flex-start; }
.segmented label { position: relative; cursor: pointer; }
.segmented label input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label span {
  height: 30px; padding: 0 14px; border-radius: 6px; color: var(--text-2);
  font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
}
.segmented label:hover span { color: var(--text); }
.segmented label input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented label input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
[data-source-panel][hidden] { display: none; }

.code-block {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--border); font-size: 13px; overflow-x: auto; white-space: pre;
}

/* ─── Knowledge graph: controls, focus, side panel, legend ──────── */
.graph-legend i { box-shadow: 0 0 0 1px var(--graph-item-border); }
.graph-legend .legend-line { display: inline-block; width: 18px; border-top: 2px solid var(--graph-theme); }
.graph-legend .legend-line.new { border-top-style: dashed; opacity: 0.7; }
.graph-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 18px; border-bottom: 1px solid var(--graph-grid); }
.graph-chip {
  height: 28px; padding: 0 11px; border-radius: 999px; font-size: 12.5px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--graph-item-border); background: var(--graph-item); color: var(--graph-muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.graph-chip[aria-pressed="true"] { color: var(--graph-text); background: var(--graph-item-hover); border-color: var(--graph-muted); }
.graph-chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.graph-chip:focus-visible, .graph-tool:focus-visible, .graph-search:focus-visible { outline: 2px solid var(--graph-theme); outline-offset: 1px; }
.graph-controls .spacer { flex: 1; }
.graph-search {
  height: 30px; min-width: 0; width: 200px; padding: 0 10px; border-radius: var(--radius-sm); font-size: 13px;
  border: 1px solid var(--graph-item-border); background: var(--graph-item); color: var(--graph-text);
}
.graph-search { max-width: 100%; cursor: pointer; text-overflow: ellipsis; }
.graph-search option, .graph-search optgroup { background: var(--surface); color: var(--text); }
.graph-tool {
  height: 30px; padding: 0 10px; border-radius: var(--radius-sm); font-size: 12.5px; cursor: pointer;
  border: 1px solid var(--graph-item-border); background: var(--graph-item); color: var(--graph-text);
  display: inline-flex; align-items: center; gap: 6px;
}
.graph-tool:hover, .graph-chip:hover { background: var(--graph-item-hover); }
.graph-toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--graph-text); font-size: 12.5px; }
.graph-toggle[hidden] { display: none; }
.graph-toggle input { accent-color: var(--graph-theme); }
.graph-hint { position: absolute; left: 16px; bottom: 10px; margin: 0; font-size: 11.5px; color: var(--graph-muted); pointer-events: none; }
.graph-note { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); margin: 0; padding: 6px 12px; border-radius: 999px;
  font-size: 12.5px; background: var(--graph-panel); color: var(--graph-text); border: 1px solid var(--graph-panel-border); }
.graph-note[hidden] { display: none; }
#graph-svg .node circle, #graph-svg .edge, #graph-svg .node-label { transition: opacity 0.2s, stroke-opacity 0.2s; }
#graph-svg .node.dim, #graph-svg .node-label.dim { opacity: 0.12; }
#graph-svg .edge.dim { stroke-opacity: 0.04 !important; }
#graph-svg .node.selected circle:first-of-type { stroke: var(--graph-ring); stroke-width: 3; }
#graph-svg .node:focus { outline: none; }
#graph-svg .node:focus-visible circle:first-of-type { stroke: var(--graph-ring); stroke-width: 3; }

.graph-side {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 340px; max-width: calc(100% - 24px);
  overflow-y: auto; padding: 18px 18px 16px; border-radius: var(--radius-lg);
  background: var(--graph-panel); border: 1px solid var(--graph-panel-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25); color: var(--graph-text); cursor: default;
  backdrop-filter: blur(6px);
}
.graph-side[hidden] { display: none; }
.graph-side-close {
  position: absolute; top: 8px; right: 10px; border: none; background: transparent;
  color: var(--graph-muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px;
}
.graph-side-close:hover { color: var(--graph-text); }
.graph-side-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; padding-right: 24px; }
.graph-side .chip { background: var(--graph-item-hover); color: var(--graph-text); border-color: transparent; }
.graph-side .chip-accent { background: color-mix(in srgb, var(--graph-theme) 20%, transparent); color: var(--graph-link); }
.graph-side .chip-tension { background: color-mix(in srgb, var(--graph-tension) 22%, transparent); color: var(--graph-tension); }
.graph-side-title { font-family: var(--font-serif); font-size: 19px; font-weight: 500; line-height: 1.3; margin: 0 0 8px; color: var(--graph-text); }
.graph-side-text { font-size: 13.5px; line-height: 1.55; color: var(--graph-text); opacity: 0.85; margin: 0 0 10px; }
.graph-side-text.muted { color: var(--graph-muted); opacity: 1; }
.graph-side-label { margin: 14px 0 6px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--graph-muted); }
.graph-side-item {
  display: block; width: 100%; text-align: left; padding: 7px 10px; margin-bottom: 4px;
  border: 1px solid var(--graph-item-border); border-radius: var(--radius-sm);
  background: var(--graph-item); color: var(--graph-text); font-size: 13px; cursor: pointer;
}
.graph-side-item:hover, .graph-side-item:focus-visible { background: var(--graph-item-hover); outline: none; }
.graph-side-item .muted { color: var(--graph-muted); }
.graph-passage {
  margin: 0 0 8px; padding: 8px 10px; border-left: 2px solid var(--graph-theme);
  background: var(--graph-item); font-family: var(--font-serif); font-size: 14px; line-height: 1.5;
}
.graph-passage cite { display: block; margin-top: 4px; font-family: var(--font-sans); font-style: normal; font-size: 11.5px; color: var(--graph-muted); }
.graph-passage cite a, .graph-side-link { color: var(--graph-link); }
.graph-side-actions { display: flex; gap: 8px; margin: 14px 0 6px; }
.graph-side-actions form { margin: 0; }
.graph-side-link { display: inline-block; margin-top: 10px; font-size: 13px; }

/* Full screen (any size; the phone's best way to explore the graph) */
.graph-container.is-fullscreen {
  position: fixed; inset: 0; z-index: 200; margin: 0; border-radius: 0; border: none;
  display: flex; flex-direction: column;
}
.graph-container.is-fullscreen .graph-svg-wrapper { flex: 1; height: auto; }
body.graph-fullscreen-open { overflow: hidden; }

@media (max-width: 700px) {
  /* Bottom sheet on phones */
  .graph-side { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 62%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .graph-hint { display: none; }
  /* One row of controls that scrolls sideways, so the graph keeps the room */
  .graph-controls { flex-wrap: nowrap; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
  .graph-controls::-webkit-scrollbar { display: none; }
  .graph-controls > * { flex-shrink: 0; }
  .graph-controls .spacer { display: none; }
  /* The book dropdown first, so it is on screen without scrolling */
  .graph-search { width: 150px; order: -1; }
  .graph-container.is-fullscreen .graph-legend { display: none; }
  .graph-container.is-fullscreen .graph-toolbar { padding: 10px 12px; }
}
