/* ============================================================
   BookMind by Nabchee — Persian-first RTL design system
   Dark elegant theme · system font stack (no external assets)
   AA contrast · responsive · reduced-motion friendly
   ============================================================ */

:root {
  /* palette */
  --bg: #0e1420;
  --bg-soft: #131b2a;
  --card: #172234;
  --card-2: #1b2840;
  --line: #26334d;
  --line-soft: #202b42;
  --text: #e9edf6;
  --muted: #a7b1c6;
  --faint: #8792a9;
  --accent: #e5b455;          /* saffron gold */
  --accent-soft: rgba(229, 180, 85, 0.14);
  --accent-ink: #241a05;
  --teal: #6fd3c7;
  --teal-soft: rgba(111, 211, 199, 0.13);
  --rose: #f2a2c0;
  --rose-soft: rgba(242, 162, 192, 0.12);
  --danger: #ef9a8f;
  --danger-soft: rgba(239, 154, 143, 0.12);
  --ok: #8fd6a8;
  --ok-soft: rgba(143, 214, 168, 0.12);

  /* dimensions D1..D6 */
  --d1: #7ea6e0;
  --d2: #5fd0be;
  --d3: #c9a0f5;
  --d4: #f2a2c0;
  --d5: #f5c86e;
  --d6: #9fb0c8;

  /* shape */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow: 0 10px 30px rgba(3, 7, 15, 0.45);
  --shadow-soft: 0 4px 14px rgba(3, 7, 15, 0.35);

  --font: "Vazirmatn", "Segoe UI", Tahoma, "Iranian Sans", "Noto Naskh Arabic", sans-serif;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;

  --header-h: 64px;
  --footer-h: 96px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--text);
  background:
    radial-gradient(1100px 500px at 85% -10%, rgba(229, 180, 85, 0.055), transparent 60%),
    radial-gradient(900px 500px at 5% 110%, rgba(111, 211, 199, 0.045), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
}

.container { width: min(1180px, 100% - 2rem); margin-inline: auto; }

img { max-width: 100%; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: rgba(229, 180, 85, 0.3); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- skip link ---------- */
.skip-link {
  position: fixed; top: -48px; right: 1rem; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.5rem 1rem; border-radius: var(--radius-sm);
  font-weight: 700; transition: top 0.2s ease;
}
.skip-link:focus { top: 0.75rem; text-decoration: none; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(14, 20, 32, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: var(--header-h); flex-wrap: wrap; padding-block: 0.4rem;
}
.brand { display: inline-flex; align-items: center; gap: 0.65rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, rgba(229,180,85,0.22), rgba(111,211,199,0.14));
  border: 1px solid rgba(229, 180, 85, 0.45);
  color: var(--accent); font-weight: 800; font-size: 1.25rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 1.05rem; letter-spacing: 0.2px; }
.brand-text small { color: var(--muted); font-size: 0.72rem; }

.mode-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin-inline-start: 0.6rem; padding: 0.2rem 0.7rem;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted); font-size: 0.72rem; background: var(--bg-soft);
}
.mode-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); }

.mainnav { display: flex; align-items: center; gap: 0.25rem; flex-wrap: wrap; }
.mainnav a {
  color: var(--muted); padding: 0.45rem 0.85rem; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.92rem; transition: color .15s, background .15s;
}
.mainnav a:hover { color: var(--text); background: var(--card); text-decoration: none; }
.mainnav a.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- main / layout ---------- */
.view-root { flex: 1 1 auto; padding-block: 1.6rem 3rem; min-height: 55vh; }

.page-skeleton { padding-block: 2rem; display: grid; gap: 0.9rem; }
.sk-title { height: 2.4rem; width: 45%; }
.sk-block { height: 180px; margin-top: 1rem; }

.section { margin-block: 1.9rem; }
.section > h2 {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 1.12rem; margin: 0 0 0.9rem; font-weight: 800;
}
.section > h2::before {
  content: ""; inline-size: 4px; block-size: 1.15em; border-radius: 3px;
  background: linear-gradient(180deg, var(--accent), var(--teal));
}
.section-sub { color: var(--muted); margin: -0.6rem 0 0.9rem; font-size: 0.88rem; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 2.6rem 0.5rem 1.8rem; }
.hero h1 {
  margin: 0 0 0.6rem; font-size: clamp(1.7rem, 4.2vw, 2.6rem); font-weight: 800;
  background: linear-gradient(120deg, #f4e3bb, var(--accent) 45%, var(--teal));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.lead { color: var(--muted); max-width: 640px; margin: 0 auto 1.6rem; font-size: 1.02rem; }

.searchbar {
  display: flex; gap: 0.6rem; align-items: center;
  max-width: 680px; margin-inline: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 0.45rem 0.55rem 0.45rem 0.55rem;
  box-shadow: var(--shadow-soft); transition: border-color .15s;
}
.searchbar:focus-within { border-color: var(--accent); }
.searchbar input {
  flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text);
  font: inherit; padding: 0.45rem 0.8rem; outline: none;
}
.searchbar input::placeholder { color: var(--faint); }

.hero-actions { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; margin-top: 1.4rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font: inherit; font-weight: 700; font-size: 0.92rem;
  padding: 0.6rem 1.25rem; border-radius: 999px; cursor: pointer;
  border: 1px solid transparent; transition: filter .15s, background .15s, border-color .15s;
  user-select: none;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-teal { background: var(--teal-soft); color: var(--teal); border-color: rgba(111,211,199,0.4); }
.btn-teal:hover:not(:disabled) { filter: brightness(1.15); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(239,154,143,0.4); }
.btn-sm { padding: 0.32rem 0.8rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ---------- cards & grids ---------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow-soft);
}
.card.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.card.clickable:hover { border-color: var(--accent); transform: translateY(-2px); }

.grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid-wide { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }

.card-title { font-weight: 800; margin: 0 0 0.25rem; font-size: 1rem; }
.card-sub { color: var(--muted); font-size: 0.83rem; margin: 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 1rem; margin: 0.5rem 0; }
.kv dt { color: var(--faint); font-size: 0.85rem; }
.kv dd { margin: 0; font-size: 0.92rem; }
.kv dd, .card-title, .ent-card strong, .profile-head h1 { overflow-wrap: anywhere; min-width: 0; }

/* ---------- chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.28rem 0.8rem; border-radius: 999px; font-size: 0.83rem; font-weight: 600;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
}
a.chip:hover, button.chip { text-decoration: none; cursor: pointer; }
a.chip:hover, button.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.chips-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-block: 0.5rem; }

.filter-chip {
  padding: 0.25rem 0.75rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600;
  background: transparent; border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  font-family: inherit;
}
.filter-chip:hover { color: var(--text); }
.filter-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.16rem 0.65rem; border-radius: 999px; font-size: 0.74rem; font-weight: 700;
}
.badge-doc { background: var(--teal-soft); color: var(--teal); border: 1px solid rgba(111,211,199,0.35); }
.badge-gen { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(229,180,85,0.35); }
.badge-inferred {
  background: var(--rose-soft); color: var(--rose);
  border: 1px dashed rgba(242, 162, 192, 0.55);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid rgba(143,214,168,0.35); }
.badge-warn { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(229,180,85,0.35); }
.badge-muted { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.badge-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(239,154,143,0.35); }
.badge-wait { background: var(--accent-soft); color: var(--accent); border: 1px dashed rgba(229,180,85,0.5); }

/* ---------- states: loading / empty / error ---------- */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(100deg, var(--card) 40%, var(--card-2) 50%, var(--card) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  min-height: 1em;
}
.sk-line { height: 0.95rem; }
.sk-line.short { width: 55%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state {
  display: grid; place-items: center; gap: 0.3rem; text-align: center;
  padding: 1.6rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); background: rgba(19, 27, 42, 0.45);
}
.empty-state .glyph {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.1rem;
  border: 1px solid var(--line); color: var(--faint); background: var(--bg-soft);
}
.empty-state .hint { font-size: 0.8rem; color: var(--faint); }

.error-state {
  display: grid; gap: 0.55rem; text-align: center; place-items: center;
  padding: 1.4rem 1rem; border: 1px solid rgba(239, 154, 143, 0.4);
  border-radius: var(--radius); background: var(--danger-soft); color: var(--danger);
}
.error-state .msg { font-weight: 700; }
.error-state .trace { font-size: 0.75rem; color: var(--muted); font-family: var(--mono); direction: ltr; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; bottom: 1.1rem; inset-inline: 0; z-index: 300;
  display: grid; gap: 0.5rem; justify-items: center; pointer-events: none;
  padding-inline: 1rem;
}
.toast {
  pointer-events: auto; max-width: 520px; width: fit-content;
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.6rem 1.1rem;
  box-shadow: var(--shadow); font-size: 0.9rem; color: var(--text);
  animation: toast-in 0.25s ease;
}
.toast.warn { border-color: rgba(229, 180, 85, 0.55); color: var(--accent); }
.toast.error { border-color: rgba(239, 154, 143, 0.55); color: var(--danger); }
.toast.ok { border-color: rgba(143, 214, 168, 0.55); color: var(--ok); }
.toast.fade { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(5, 9, 17, 0.6); backdrop-filter: blur(2px);
  animation: fade-in 0.2s ease;
}
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 260;
  width: min(430px, 94vw);
  background: var(--bg-soft); border-inline-end: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 1.2rem 1.3rem;
  overflow-y: auto; animation: drawer-in 0.25s ease;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.drawer-head h3 { margin: 0; font-size: 1.08rem; }
.drawer-close {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 1rem;
  display: grid; place-items: center; flex: none;
}
.drawer-close:hover { color: var(--text); border-color: var(--accent); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
html[dir="rtl"] .drawer { animation-name: drawer-in-rtl; }
@keyframes drawer-in-rtl { from { transform: translateX(-24px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; gap: 1rem; max-width: 860px; margin-inline: auto; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.chat-head h1 { font-size: 1.35rem; margin: 0; }
.chat-log { display: grid; gap: 1rem; padding-block: 0.4rem; }

.msg { display: flex; flex-direction: column; gap: 0.5rem; max-width: 92%; }
.msg.user { align-self: flex-start; }
.msg.ai { align-self: stretch; max-width: 100%; }
.msg .bubble {
  border-radius: var(--radius); padding: 0.85rem 1.1rem; border: 1px solid var(--line);
  background: var(--card); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--accent-soft); border-color: rgba(229, 180, 85, 0.4);
  border-start-start-radius: 4px;
}
.msg.ai .bubble { border-start-start-radius: 4px; background: linear-gradient(180deg, var(--card), var(--bg-soft)); }
.msg.unsupported .bubble { border-style: dashed; border-color: rgba(229,180,85,0.5); }

.msg-meta { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }
.cite-chip {
  font-family: inherit; cursor: pointer; font-weight: 700; font-size: 0.78rem;
  background: var(--teal-soft); color: var(--teal); border: 1px solid rgba(111,211,199,0.35);
  border-radius: 999px; padding: 0.1rem 0.55rem; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cite-chip:hover { filter: brightness(1.2); }

.facts-list { display: grid; gap: 0.4rem; margin: 0.2rem 0; }
.fact-row {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.45rem 0.7rem; border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); background: rgba(19,27,42,0.5); font-size: 0.88rem;
}
.fact-row .rel { color: var(--faint); font-size: 0.78rem; }
.fact-row .conf { color: var(--faint); font-size: 0.74rem; margin-inline-start: auto; }

.ent-grid { display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ent-card {
  display: flex; flex-direction: column; gap: 0.15rem; text-align: start;
  background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem; cursor: pointer; font-family: inherit; color: var(--text); font-size: 0.9rem;
}
.ent-card:hover { border-color: var(--accent); }
.ent-card .type { font-size: 0.72rem; color: var(--faint); display: flex; align-items: center; gap: 0.35rem; }

.composer {
  position: sticky; bottom: 0.6rem; z-index: 50;
  display: flex; gap: 0.6rem; align-items: flex-end;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 0.7rem; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 150px;
  background: transparent; border: 0; color: var(--text); font: inherit; outline: none; padding: 0.4rem 0.6rem;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-help { color: var(--faint); font-size: 0.76rem; margin: -0.5rem 0 0; }
.inline-citation { display: inline; vertical-align: baseline; margin-inline: 0.15rem; }
.chat-suggestion:disabled { opacity: 0.55; cursor: wait; }

.typing { display: inline-flex; gap: 5px; align-items: center; padding: 0.4rem 0.2rem; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.fb-row { display: flex; align-items: center; gap: 0.5rem; color: var(--faint); font-size: 0.82rem; }
.fb-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 0.25rem 0.6rem; cursor: pointer; font-family: inherit; font-size: 0.85rem;
}
.fb-btn:hover { border-color: var(--accent); color: var(--accent); }
.fb-btn.picked { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }

.offer-row {
  display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem; background: rgba(19,27,42,0.5);
}
.offer-row .m-name { font-weight: 700; }
.offer-note { color: var(--faint); font-size: 0.85rem; }

/* ---------- explorer ---------- */
.explorer-wrap { display: grid; gap: 0.9rem; }
.explorer-toolbar {
  display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.explorer-toolbar .grow { flex: 1; min-width: 200px; position: relative; }
.search-input {
  width: 100%; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); font: inherit; font-size: 0.92rem;
  border-radius: var(--radius-sm); padding: 0.5rem 0.8rem; outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-drop {
  position: absolute; top: calc(100% + 6px); inset-inline: 0; z-index: 60;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; text-align: start;
}
.search-drop .item {
  display: flex; align-items: center; gap: 0.55rem; width: 100%;
  background: transparent; border: 0; color: var(--text); font: inherit; font-size: 0.9rem;
  padding: 0.5rem 0.8rem; cursor: pointer; text-align: start;
}
.search-drop .item:hover { background: var(--card-2); }
.search-drop .item:focus-visible { background: var(--card-2); outline-offset: -3px; }
.search-drop { max-height: min(400px, 55vh); overflow-y: auto; }

.rel-pop {
  position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 60;
  min-width: 250px; max-height: 300px; overflow-y: auto;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 0.5rem;
}
.rel-pop label {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.4rem;
  border-radius: 6px; cursor: pointer; font-size: 0.86rem; color: var(--text);
}
.rel-pop label:hover { background: var(--card-2); }
.rel-pop .code { color: var(--faint); font-size: 0.7rem; font-family: var(--mono); direction: ltr; }

.canvas-card {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius);
  background: radial-gradient(700px 400px at 70% 20%, rgba(229,180,85,0.04), transparent 60%), var(--bg-soft);
  overflow: hidden; box-shadow: var(--shadow-soft);
}
#graph-canvas { display: block; width: 100%; height: min(66vh, 640px); min-height: 420px; touch-action: none; cursor: grab; }
#graph-canvas.dragging { cursor: grabbing; }

.legend {
  position: absolute; bottom: 0.8rem; inset-inline-start: 0.8rem; z-index: 20;
  background: rgba(19, 27, 42, 0.88); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.6rem 0.8rem;
  display: grid; gap: 0.25rem; font-size: 0.78rem; color: var(--muted);
  backdrop-filter: blur(4px);
}
.legend .row { display: flex; align-items: center; gap: 0.45rem; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend .line-sample { width: 22px; height: 0; border-top: 2px solid var(--faint); flex: none; }
.legend .line-sample.dashed { border-top-style: dashed; border-top-color: var(--rose); }

.canvas-hint {
  position: absolute; top: 0.8rem; inset-inline-end: 0.8rem; z-index: 20;
  color: var(--faint); font-size: 0.72rem; background: rgba(19,27,42,0.75);
  border-radius: 999px; padding: 0.15rem 0.7rem; border: 1px solid var(--line-soft);
}
.hist-btns { display: flex; gap: 0.4rem; }
.graph-controls { position: absolute; top: 0.8rem; inset-inline-start: 0.8rem; display: flex; gap: 0.35rem; }
.graph-controls .btn { background: var(--bg-soft); min-width: 40px; min-height: 40px; }
.graph-list { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.65rem 0.9rem; color: var(--muted); }
.graph-list summary { cursor: pointer; }
.graph-node-list { max-height: 250px; overflow-y: auto; }

/* ---------- tables (admin) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 480px; }
table.data th, table.data td { padding: 0.55rem 0.8rem; text-align: start; border-bottom: 1px solid var(--line-soft); }
table.data th { color: var(--muted); font-weight: 700; font-size: 0.8rem; background: var(--bg-soft); position: sticky; top: 0; }
table.data tbody tr:hover { background: rgba(27, 40, 64, 0.5); }
table.data tr:last-child td { border-bottom: 0; }
td.num, th.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }

.stat-grid { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat-card {
  background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 0.85rem 1rem;
}
.stat-card .v { font-size: 1.45rem; font-weight: 800; color: var(--accent); line-height: 1.4; }
.stat-card .k { color: var(--muted); font-size: 0.8rem; }

.login-card { max-width: 400px; margin: 3rem auto; }
.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.field input, .field select, .field textarea {
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 0.55rem 0.8rem; font: inherit; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { width: 100%; min-width: 0; resize: vertical; }
.review-check { display: flex; align-items: flex-start; gap: 0.6rem; color: var(--muted); }
.review-check input { flex: none; width: 18px; height: 18px; margin-top: 0.35rem; accent-color: var(--accent); }

.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.admin-head h1 { margin: 0; font-size: 1.4rem; }

/* ---------- profile (book/author/concept) ---------- */
.profile-head { display: flex; gap: 1.2rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 0.5rem; }
.profile-head .titles { flex: 1; min-width: 240px; }
.profile-head h1 { margin: 0 0 0.3rem; font-size: clamp(1.4rem, 3.4vw, 2rem); }
.profile-head .alt { color: var(--muted); font-size: 0.9rem; }
.profile-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.synopsis {
  border-inline-start: 3px solid var(--accent); padding: 0.4rem 1rem;
  background: var(--accent-soft); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.98rem;
}
.evidence-row {
  display: grid; gap: 0.2rem; padding: 0.55rem 0.8rem;
  border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: rgba(19,27,42,0.5);
}
.evidence-row .lbl { font-weight: 700; font-size: 0.9rem; }
.evidence-row .snip { color: var(--muted); font-size: 0.85rem; }
.evidence-row .src { color: var(--faint); font-size: 0.74rem; font-family: var(--mono); direction: ltr; }

.author-card { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.author-card .ava {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card-2); border: 1px solid var(--line);
  color: var(--accent); font-weight: 800; font-size: 1.2rem; flex: none;
}

/* ---------- prose (about/privacy) ---------- */
.prose { max-width: 760px; margin-inline: auto; }
.prose h1 { font-size: 1.6rem; margin: 0.2rem 0 1rem; }
.prose h2 { font-size: 1.15rem; margin: 1.8rem 0 0.6rem; }
.prose p, .prose li { color: var(--muted); }
.prose strong { color: var(--text); }
.prose ul { padding-inline-start: 1.4rem; }
.prose .dim-list { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); list-style: none; padding: 0; }
.prose .dim-list li { display: flex; gap: 0.6rem; align-items: flex-start; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 0.7rem 0.9rem; }
.prose .dim-list .dot { margin-top: 0.55rem; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line-soft); background: rgba(14, 20, 32, 0.7);
  padding-block: 1.4rem; margin-top: auto;
}
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.footer-inner p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.footer-sep { color: var(--faint); margin-inline: 0.4rem; }
.footer-links { display: flex; gap: 1rem; }
.footer-links a { color: var(--muted); font-size: 0.85rem; }
.footer-links a:hover { color: var(--accent); }

.noscript-note {
  position: fixed; inset: auto 0 0 0; z-index: 400; text-align: center;
  background: var(--accent); color: var(--accent-ink); padding: 0.8rem; font-weight: 700;
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .topbar-inner { justify-content: center; }
  .mainnav { justify-content: center; width: 100%; }
  .mainnav a { padding: 0.35rem 0.6rem; font-size: 0.88rem; }
  #graph-canvas { height: 58vh; min-height: 360px; }
  .legend { font-size: 0.72rem; padding: 0.45rem 0.6rem; }
  .msg.user { max-width: 100%; }
  .footer-inner { flex-direction: column; text-align: center; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .hero { padding-block: 1.8rem 1.2rem; }
  .searchbar { flex-direction: row; }
  .btn { padding: 0.55rem 1rem; }
  .drawer { width: 100vw; }
  .canvas-hint { display: none; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .container { width: calc(100% - 1.25rem); }
  .topbar-inner { gap: 0.3rem; }
  .brand { flex-wrap: wrap; justify-content: center; gap: 0.4rem; }
  .mode-pill { margin-inline-start: 0; max-width: 190px; font-size: 0.65rem; }
  .mainnav { flex-wrap: nowrap; justify-content: space-between; gap: 0; }
  .mainnav a { white-space: nowrap; font-size: 0.78rem; padding: 0.5rem 0.3rem; }
  .explorer-toolbar { padding: 0.6rem; }
  .explorer-toolbar .grow { min-width: 0; flex-basis: 100%; order: -1; }
  .explorer-toolbar > .chips-row { flex-basis: 100%; }
  .filter-chip, .chip { min-height: 38px; }
  .grid { grid-template-columns: 1fr; }
  .legend { position: static; border: 0; border-radius: 0; display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; }
  #graph-canvas { min-height: 330px; height: 50svh; }
  .composer { bottom: max(0.4rem, env(safe-area-inset-bottom)); padding: 0.45rem; }
  .composer textarea { font-size: 16px; padding-inline: 0.3rem; }
  .composer .btn { padding-inline: 0.75rem; }
  .fb-row { flex-wrap: wrap; }
  .rel-pop { min-width: 230px; max-width: calc(100vw - 2rem); }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
  html { scroll-behavior: auto; }
  .skeleton { animation: none; }
}
