/* ============================================================
   Heritage Vault — Light theme (SBL-inspired)
   ============================================================ */
:root {
  --bg:        #fafaf7;        /* warm off-white page */
  --bg-dim:    #f3f3ee;        /* gentle band */
  --surface:   #ffffff;        /* cards */
  --surface-2: #f7f7f3;
  --ink:       #0f1c3f;        /* deep navy — primary text */
  --ink-2:     #1a2542;
  --ink-dim:   #4a5468;
  --ink-mute:  #8a92a3;
  --line:      rgba(15,28,63,.10);
  --line-2:    rgba(15,28,63,.18);
  --line-3:    rgba(15,28,63,.28);

  --green:     #95c11f;        /* lime accent */
  --green-2:   #7ca31a;
  --green-soft:#e8f3cb;

  --gold:      #d99a2b;
  --cyan:      #2c8fa8;
  --violet:    #7c5cd1;
  --rose:      #d34a72;
  --emerald:   #2fa56a;
  --amber:     #c98d13;

  --shadow-1:  0 1px 2px rgba(15,28,63,.04), 0 6px 22px rgba(15,28,63,.06);
  --shadow-2:  0 4px 14px rgba(15,28,63,.08), 0 22px 60px rgba(15,28,63,.10);
  --radius:    14px;
  --radius-lg: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-weight: 400;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
button { font-family: inherit; }

/* keep the wrapper divs from the old theme but make them invisible */
.aurora, .grain, .blob { display: none !important; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 28px;
  padding: 18px 40px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--ink);
  font-weight: 700; letter-spacing: -.01em; font-size: 18px;
}
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--green);
  color: var(--ink); font-weight: 800;
  border-radius: 8px; font-size: 18px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
}
.topnav { display: flex; gap: 28px; }
.topnav a {
  color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 14px;
  padding: 6px 0; transition: color .2s;
}
.topnav a:hover { color: var(--green-2); }
.topright { margin-left: auto; }

/* connection indicator (unchanged structure, restyled) */
.conn {
  background: var(--surface); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 100px;
  font-size: 11px; color: var(--ink-dim); display: inline-flex; align-items: center; gap: 8px;
  font-weight: 500; letter-spacing: .04em;
}
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-mute); }
.conn.live .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(149,193,31,.18); }

/* ============================================================
   LAYOUT
   ============================================================ */
.wrap { max-width: 1320px; margin: 0 auto; padding: 56px 40px 120px; }
.book-view { padding-top: 32px; }

.backlink {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-dim); text-decoration: none;
  font-size: 12px; font-weight: 500; letter-spacing: .04em;
  margin-bottom: 26px;
  transition: color .2s;
}
.backlink:hover { color: var(--green-2); }

/* ============================================================
   SECTION LABEL — horizontal line + small-caps
   ============================================================ */
.crest {
  display: inline-flex; align-items: center; gap: 16px;
  font-size: 11px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--ink-dim); font-weight: 600;
  background: none; border: none; padding: 0; border-radius: 0;
  backdrop-filter: none;
}
.crest::before {
  content: ""; display: inline-block;
  width: 56px; height: 1px; background: var(--ink);
}

/* ============================================================
   HERO
   ============================================================ */
.hero { padding: 18px 0 48px; border-bottom: 1px solid var(--line); position: relative; }

h1.title {
  font-size: clamp(48px, 7vw, 96px);
  font-weight: 800; line-height: .95;
  margin: 28px 0 22px; letter-spacing: -.025em;
  color: var(--ink);
  background: none; -webkit-background-clip: initial; background-clip: initial;
  animation: none;
}
h1.title em {
  font-style: italic;
  font-weight: 700;
  color: var(--green);
  letter-spacing: -.02em;
}
.book-title { font-size: clamp(36px, 5vw, 64px); }

.lede {
  color: var(--ink-dim); font-size: 17px;
  max-width: 720px; font-weight: 400;
  margin-top: 8px;
}
.lede b { color: var(--ink); font-weight: 600; }
.lede em { font-style: italic; color: var(--green-2); font-weight: 500; }

/* ============================================================
   STATS
   ============================================================ */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
  margin: 42px 0 4px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stat {
  padding: 26px 28px; background: transparent;
  border-right: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.stat:last-child { border-right: none; }
.stat .lbl {
  font-size: 10px; letter-spacing: .28em; text-transform: uppercase;
  color: var(--ink-mute); font-weight: 600;
}
.stat .val {
  font-size: 44px; font-weight: 700; margin-top: 8px;
  letter-spacing: -.025em; line-height: 1; color: var(--ink);
}
.stat .sub {
  font-size: 12px; color: var(--ink-dim);
  margin-top: 8px; font-weight: 400;
}
.stat.gold    .val { color: var(--ink); }
.stat.cyan    .val { color: var(--ink); }
.stat.emerald .val { color: var(--green-2); }
.stat.violet  .val { color: var(--ink); }

@media (max-width: 720px) { .stats { grid-template-columns: 1fr 1fr; } .stat:nth-child(2) { border-right: none; } }

/* ============================================================
   MASTER BAR
   ============================================================ */
.master {
  margin: 36px 0 32px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 32px;
  box-shadow: var(--shadow-1);
}
.master .progblock { flex: 1; min-width: 280px; }
.master h2 {
  margin: 0 0 8px; font-size: 11px; letter-spacing: .28em;
  text-transform: uppercase; color: var(--ink-mute); font-weight: 600;
}
.master .pcount { font-size: 22px; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }
.master .pcount span { color: var(--green-2); font-weight: 700; }

.megabar {
  height: 8px; border-radius: 100px;
  background: var(--bg-dim);
  overflow: hidden; margin-top: 14px;
}
.megabar > div {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--green), var(--green-2));
  border-radius: 100px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}

.actions { display: flex; gap: 10px; }

/* ============================================================
   BUTTONS
   ============================================================ */
button.btn, a.btn {
  font-family: inherit; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  padding: 14px 26px;
  border-radius: 8px; font-size: 14px; letter-spacing: .005em;
  transition: transform .15s ease, box-shadow .25s ease, opacity .2s, background .2s, color .2s;
  display: inline-flex; align-items: center; gap: 9px; text-decoration: none;
  line-height: 1;
}
button.btn:active { transform: scale(.98); }
button.btn:disabled, a.btn.disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--ink); color: #fff; border-color: var(--ink);
}
.btn.primary:hover:not(:disabled) {
  background: var(--ink-2); border-color: var(--ink-2);
  box-shadow: 0 6px 22px rgba(15,28,63,.18);
}
.btn.ghost {
  background: transparent; color: var(--ink); border-color: var(--line-2);
}
.btn.ghost:hover:not(:disabled) {
  border-color: var(--ink); background: var(--surface);
}
.btn.danger {
  background: #fff; color: var(--rose); border-color: rgba(211,74,114,.4);
}
.btn.danger:hover:not(:disabled) {
  background: var(--rose); color: #fff; border-color: var(--rose);
}
.btn.green {
  background: var(--green); color: var(--ink); border-color: var(--green);
  font-weight: 700;
}
.btn.green:hover:not(:disabled) {
  background: var(--green-2); border-color: var(--green-2); color: #fff;
}

/* ============================================================
   FILTERS
   ============================================================ */
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.pill {
  padding: 8px 16px; border-radius: 100px; cursor: pointer;
  background: transparent; border: 1px solid var(--line-2);
  font-size: 12px; font-weight: 500; letter-spacing: .02em;
  color: var(--ink-dim); transition: all .15s;
}
.pill:hover { color: var(--ink); border-color: var(--ink); }
.pill.active {
  background: var(--ink); color: #fff; border-color: var(--ink);
}
.search {
  margin-left: auto; background: var(--surface); border: 1px solid var(--line-2);
  padding: 11px 18px; border-radius: 100px; min-width: 260px;
  color: var(--ink); font-family: inherit; font-size: 13px; outline: none;
  transition: border-color .2s;
}
.search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(149,193,31,.18); }
.search::placeholder { color: var(--ink-mute); }

/* ============================================================
   BOOK CARDS
   ============================================================ */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 18px; }
.card {
  position: relative; background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  transition: transform .25s cubic-bezier(.2,.7,.3,1), border-color .25s, box-shadow .25s;
  display: flex; flex-direction: column; gap: 16px;
  overflow: hidden;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--line-3);
  box-shadow: var(--shadow-2);
}
.card.done { border-left: 3px solid var(--green); }
.card.error { border-left: 3px solid var(--rose); }
.card.downloading, .card.building { border-left: 3px solid var(--cyan); }
.card.queued { border-left: 3px solid var(--amber); }

.card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card .card-title {
  margin: 0; font-size: 17px; font-weight: 600; line-height: 1.3; color: var(--ink);
  letter-spacing: -.005em;
}
.card .meta { font-size: 12px; color: var(--ink-mute); margin-top: 4px; font-weight: 500; letter-spacing: .03em; }

/* status pill */
.status {
  flex-shrink: 0; padding: 4px 10px; border-radius: 4px;
  font-size: 9px; letter-spacing: .18em; text-transform: uppercase; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
.status.idle    { background: #eef0f4; color: var(--ink-mute); }
.status.idle::before { background: var(--ink-mute); }
.status.queued  { background: #fdf3dc; color: var(--amber); }
.status.queued::before { background: var(--amber); animation: pulse 1.5s infinite; }
.status.downloading { background: #d8eaf0; color: var(--cyan); }
.status.downloading::before { background: var(--cyan); animation: pulse 1s infinite; }
.status.building { background: #ece6f7; color: var(--violet); }
.status.building::before { background: var(--violet); animation: pulse 1s infinite; }
.status.done    { background: var(--green-soft); color: var(--green-2); }
.status.done::before { background: var(--green-2); }
.status.error   { background: #fbe1e8; color: var(--rose); }
.status.error::before { background: var(--rose); }
.status.stopped { background: #eef0f4; color: var(--ink-dim); }
.status.stopped::before { background: var(--ink-dim); }
.status.running { background: #ece6f7; color: var(--violet); }
.status.running::before { background: var(--violet); animation: pulse 1s infinite; }
.status.partial { background: #fdf3dc; color: var(--amber); }
.status.partial::before { background: var(--amber); }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

.progress { display: flex; flex-direction: column; gap: 8px; }
.progress .num {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--ink-dim); font-weight: 500;
}
.progress .num b { color: var(--ink); font-weight: 600; }
.bar {
  height: 4px; border-radius: 100px; background: var(--bg-dim); overflow: hidden;
}
.bar > div {
  height: 100%; width: 0; border-radius: 100px;
  background: linear-gradient(90deg, var(--green), var(--green-2));
  transition: width .5s cubic-bezier(.4,0,.2,1);
}
.card.error .bar > div { background: var(--rose); }
.card.downloading .bar > div, .card.building .bar > div {
  background: linear-gradient(90deg, var(--cyan), var(--violet));
}

/* mini pipeline indicators on each card */
.pipeline-mini { display: flex; gap: 6px; flex-wrap: wrap; }
.pchip {
  font-size: 9px; letter-spacing: .12em; text-transform: uppercase; font-weight: 700;
  padding: 4px 9px; border-radius: 4px;
  background: var(--bg-dim); color: var(--ink-mute);
  display: inline-flex; align-items: center; gap: 5px;
}
.pchip::before { content:""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pchip.done   { background: var(--green-soft); color: var(--green-2); }
.pchip.running, .pchip.downloading, .pchip.building { background: #ece6f7; color: var(--violet); }
.pchip.partial, .pchip.queued { background: #fdf3dc; color: var(--amber); }
.pchip.error  { background: #fbe1e8; color: var(--rose); }

.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm {
  padding: 9px 14px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); font-family: inherit; font-weight: 500;
  cursor: pointer; transition: all .15s; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-sm:hover:not(:disabled) { border-color: var(--ink); }
.btn-sm:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm.go { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.btn-sm.go:hover:not(:disabled) { background: var(--ink-2); }
.btn-sm.dl { background: var(--green); color: var(--ink); border-color: var(--green); font-weight: 600; }
.btn-sm.dl:hover:not(:disabled) { background: var(--green-2); color: #fff; border-color: var(--green-2); }
.btn-sm.open { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; flex: 1; }
.btn-sm.open:hover:not(:disabled) { background: var(--ink-2); }

.card .err {
  font-size: 11px; color: var(--rose);
  background: #fff5f8; border-left: 2px solid var(--rose);
  padding: 8px 12px; border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', monospace;
  word-break: break-word;
}

.footer {
  margin-top: 80px; padding-top: 28px; border-top: 1px solid var(--line);
  text-align: center; font-size: 12px; color: var(--ink-mute); font-weight: 400; letter-spacing: .04em;
}
.footer a { color: var(--green-2); text-decoration: none; font-weight: 600; }
.footer a:hover { color: var(--ink); }

/* ============================================================
   BOOK DETAIL — HERO
   ============================================================ */
.book-hero {
  display: grid; grid-template-columns: 1fr 220px; gap: 48px;
  padding: 8px 0 36px; border-bottom: 1px solid var(--line); margin-bottom: 32px;
  align-items: center;
}
@media (max-width: 800px) { .book-hero { grid-template-columns: 1fr; } .book-hero-cover { display: none; } }
.book-hero-cover {
  width: 220px; aspect-ratio: 3/4; border-radius: 6px;
  background: var(--bg-dim); border: 1px solid var(--line);
  background-size: cover; background-position: center top;
  box-shadow: var(--shadow-2);
}

/* Pipeline chips on detail hero */
.pipeline { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.stage {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); min-width: 180px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-1);
}
.stage .stage-label {
  font-size: 9px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--ink-mute); font-weight: 700;
}
.stage .stage-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stage .stage-state { font-size: 14px; font-weight: 600; color: var(--ink); }
.stage .stage-action {
  font-size: 11px; padding: 5px 12px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--ink); background: var(--ink); color: #fff;
  font-family: inherit; font-weight: 600; letter-spacing: .02em;
  transition: all .15s;
}
.stage .stage-action:hover:not(:disabled) { background: var(--ink-2); }
.stage .stage-action:disabled { opacity: .35; cursor: not-allowed; }
.stage.done    { border-left: 3px solid var(--green); }
.stage.done    .stage-state { color: var(--green-2); }
.stage.running { border-left: 3px solid var(--violet); }
.stage.running .stage-state { color: var(--violet); }
.stage.error   { border-left: 3px solid var(--rose); }
.stage.error   .stage-state { color: var(--rose); }
.stage.partial { border-left: 3px solid var(--amber); }
.stage.partial .stage-state { color: var(--amber); }

.stage::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2px;
  background: var(--green);
  transform: scaleX(var(--p, 0)); transform-origin: left; transition: transform .4s;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--line);
  margin-bottom: 28px; overflow-x: auto;
}
.tab {
  background: transparent; border: none; cursor: pointer;
  padding: 14px 20px; color: var(--ink-mute); font-weight: 500;
  font-family: inherit; font-size: 14px; letter-spacing: .005em;
  position: relative; transition: color .2s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); font-weight: 600; }
.tab.active::after {
  content: ""; position: absolute; left: 18px; right: 18px; bottom: -1px; height: 2px;
  background: var(--green);
}
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================================================
   INSIGHTS TAB
   ============================================================ */
.insights-body { display: flex; flex-direction: column; gap: 26px; }

.insight-summary {
  padding: 22px 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.insight-headline {
  margin: 4px 0 0; font-size: clamp(20px, 2.2vw, 28px); font-weight: 500;
  color: var(--ink); letter-spacing: -.012em; line-height: 1.4;
  max-width: 980px;
}
.insight-headline b { font-weight: 700; color: var(--ink); }
.insight-headline b:has(+ b) { color: var(--green-2); }

.insight-metric-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
}
@media (max-width: 800px) { .insight-metric-row { grid-template-columns: 1fr 1fr; } }
.metric {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-1);
  position: relative; overflow: hidden;
}
.metric::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--green);
}
.metric-lbl {
  font-size: 10px; letter-spacing: .26em; text-transform: uppercase;
  color: var(--ink-mute); font-weight: 700;
}
.metric-val {
  font-size: 38px; font-weight: 700; margin-top: 6px;
  letter-spacing: -.02em; line-height: 1; color: var(--ink);
}
.metric-sub { font-size: 12px; color: var(--ink-dim); margin-top: 6px; font-weight: 400; }

.insight-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px;
}
.insight-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 14px;
}
.ic-header { display: flex; flex-direction: column; gap: 2px; }
.ic-header h3 {
  margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -.005em;
}
.ic-header .dim { font-size: 11px; color: var(--ink-mute); font-weight: 400; letter-spacing: .02em; }

.ic-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: il; }
.ic-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px;
  align-items: center; padding: 8px 0;
  border-top: 1px solid var(--line);
}
.ic-list li:first-child { border-top: none; }
ol.ic-list li::before {
  counter-increment: il; content: counter(il);
  font-size: 10px; color: var(--ink-mute); font-weight: 700;
  font-family: ui-monospace, monospace;
  width: 18px; text-align: right; margin-right: 8px;
  display: inline-block;
  grid-row: 1 / span 2; grid-column: -1 / -1;
}
ol.ic-list li {
  grid-template-columns: 22px 1fr auto;
}
ol.ic-list li::before { grid-column: 1; grid-row: 1; }
ol.ic-list .ic-name { grid-column: 2; }
ol.ic-list .ic-tag { grid-column: 3; }
ol.ic-list .ic-bar { grid-column: 2 / -1; grid-row: 2; }

.ic-name { font-size: 14px; font-weight: 500; color: var(--ink); }
.ic-tag {
  font-size: 11px; font-weight: 500; color: var(--ink-dim);
  font-family: ui-monospace, monospace; letter-spacing: .02em;
}
.ic-bar { display: block; height: 3px; background: var(--bg-dim); border-radius: 100px; overflow: hidden; }
.ic-bar > span { display: block; height: 100%; background: var(--green); border-radius: 100px; }

.ic-bar.lg-parent-bar > span,
.ic-bar.lg-child-bar > span,
.ic-bar.lg-father-bar > span,
.ic-bar.lg-mother-bar > span { background: var(--green); }
.ic-bar.lg-spouse-bar > span { background: var(--rose); }
.ic-bar.lg-sibling-bar > span { background: var(--cyan); }
.ic-bar.lg-other-bar > span { background: var(--ink-mute); }

.gen-bars { display: flex; flex-direction: column; gap: 8px; }
.gen-bar {
  display: grid; grid-template-columns: 70px 1fr 40px; align-items: center; gap: 10px;
}
.gb-label { font-size: 11px; color: var(--ink-mute); font-weight: 600; letter-spacing: .06em; }
.gb-fill { height: 8px; background: var(--bg-dim); border-radius: 100px; overflow: hidden; }
.gb-fill > div { height: 100%; background: linear-gradient(90deg, var(--green), var(--green-2)); border-radius: 100px; }
.gb-count { font-size: 12px; color: var(--ink); font-weight: 600; text-align: right; font-family: ui-monospace, monospace; }

.insight-suggest .ic-header { flex-direction: row; align-items: baseline; justify-content: space-between; }
.suggest-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.sg {
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--ink); font-family: inherit; font-size: 12px;
  padding: 10px 16px; border-radius: 100px; cursor: pointer;
  transition: all .15s; font-weight: 500; line-height: 1.3; text-align: left;
}
.sg:hover { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ============================================================
   PAGES TAB
   ============================================================ */
.pages-layout { display: grid; grid-template-columns: 130px 1fr; gap: 22px; }
@media (max-width: 800px) { .pages-layout { grid-template-columns: 1fr; } }
.page-rail {
  max-height: 80vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.page-rail::-webkit-scrollbar { width: 6px; }
.page-rail::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 100px; }
.thumb {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 11px; border-radius: 6px; cursor: pointer;
  font-size: 12px; color: var(--ink-dim); font-weight: 500;
  border: 1px solid transparent; transition: all .12s;
}
.thumb:hover { background: var(--bg-dim); color: var(--ink); }
.thumb.active { background: var(--ink); color: #fff; }
.thumb.active .dot { background: var(--green); }
.thumb .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-3); }
.thumb.has-text .dot { background: var(--cyan); }
.thumb.lang-mal .dot { background: var(--gold); }
.thumb.lang-hin .dot { background: var(--violet); }
.thumb.lang-tam .dot { background: var(--rose); }
.thumb.lang-eng .dot { background: var(--emerald); }

.page-reader {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-1);
}
.reader-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.spacer { flex: 1; }
.page-num { font-weight: 600; padding: 0 10px; color: var(--ink); font-size: 13px; letter-spacing: .03em; }
.lang-pill {
  font-size: 9px; letter-spacing: .22em; text-transform: uppercase;
  background: var(--bg-dim); padding: 5px 10px; border-radius: 4px;
  color: var(--ink-dim); font-weight: 700;
}
.select {
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--ink); padding: 8px 14px; border-radius: 6px;
  font-family: inherit; font-size: 12px; cursor: pointer; font-weight: 500;
}
.select:focus { outline: none; border-color: var(--ink); }

.reader-body { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .reader-body { grid-template-columns: 1fr; } }
.reader-image-wrap {
  background: var(--bg-dim); border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: center;
  max-height: 80vh;
}
.reader-image-wrap img { width: 100%; height: auto; display: block; max-height: 80vh; object-fit: contain; }
.reader-text {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 22px; max-height: 80vh; overflow-y: auto;
}
.reader-text h4 {
  margin: 0 0 12px; font-size: 10px; letter-spacing: .26em;
  text-transform: uppercase; color: var(--ink-mute); font-weight: 700;
}
.reader-text pre {
  font-family: 'Poppins', sans-serif; font-weight: 400;
  white-space: pre-wrap; word-break: break-word; line-height: 1.7;
  font-size: 14px; color: var(--ink); margin: 0;
}
.translation { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }
.translation.hidden { display: none; }
.translation pre { color: var(--green-2); }

/* empty state */
.reader-empty {
  text-align: center; padding: 50px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.reader-empty .empty-mark {
  font-size: 56px; color: var(--green); opacity: .9;
}
.reader-empty .empty-mark.spin { animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.reader-empty h4 {
  margin: 4px 0 8px; font-size: 18px; font-weight: 600; color: var(--ink); letter-spacing: -.01em;
}
.reader-empty p { color: var(--ink-dim); font-size: 13px; max-width: 360px; line-height: 1.6; }
.reader-empty .btn { margin-top: 18px; }
.reader-empty .bar { width: 100%; max-width: 280px; }

/* ============================================================
   CHAT TAB
   ============================================================ */
.chat {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 26px;
  height: 80vh;
  box-shadow: var(--shadow-1);
}
.chat-header { display: flex; justify-content: space-between; align-items: flex-start; }
.chat-header h3 { margin: 0; font-size: 20px; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }
.dim { color: var(--ink-dim); font-size: 12px; font-weight: 400; }
.chat-state {
  font-size: 11px; padding: 5px 12px; border-radius: 4px;
  background: var(--bg-dim); color: var(--ink-dim); font-weight: 600;
  letter-spacing: .04em;
}
.chat-stream {
  flex: 1; overflow-y: auto;
  padding: 4px; display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
}
.empty-chat { margin: auto; text-align: center; opacity: .8; max-width: 480px; }
.empty-mark { font-size: 56px; color: var(--green); margin-bottom: 12px; }
.empty-chat h4 { margin: 0 0 10px; font-weight: 500; font-size: 18px; color: var(--ink); }
.empty-chat em {
  color: var(--ink); font-style: normal; padding: 3px 8px;
  background: var(--green-soft); border-radius: 4px; font-weight: 500;
}

.bubble {
  max-width: 85%; padding: 14px 18px; border-radius: 10px;
  line-height: 1.6; font-size: 14px;
  background: var(--surface-2); color: var(--ink);
  white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--line);
}
.bubble.user {
  align-self: flex-end;
  background: var(--ink); color: #fff;
  border-color: var(--ink);
}
.bubble.bot { align-self: flex-start; }
.bubble .sources {
  margin-top: 10px; padding-top: 12px;
  border-top: 1px dashed var(--line-2);
  display: flex; flex-direction: column; gap: 6px;
}
.bubble .src {
  font-size: 11px; color: var(--ink-dim);
  font-family: ui-monospace, 'SF Mono', monospace;
  padding: 6px 10px; background: var(--bg-dim); border-radius: 4px; cursor: pointer;
  transition: all .15s;
}
.bubble .src:hover { color: var(--ink); background: var(--green-soft); }
.bubble.thinking { color: var(--ink-dim); font-style: italic; }
.bubble.thinking::after { content: "▋"; animation: pulse 1s infinite; margin-left: 4px; color: var(--green); }
.bubble.error { border-color: var(--rose); color: var(--rose); background: #fff5f8; }

.chat-input {
  display: flex; gap: 10px;
  padding-top: 14px; border-top: 1px solid var(--line);
}
.chat-input input {
  flex: 1; padding: 14px 18px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--ink); font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .2s;
}
.chat-input input:focus { border-color: var(--ink); }
.chat-input input::placeholder { color: var(--ink-mute); }

/* ============================================================
   PEOPLE TAB
   ============================================================ */
.people-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.people-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px;
}
.person {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; transition: all .2s; position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px;
  border-left: 3px solid var(--ink);
}
.person:hover {
  transform: translateY(-2px); border-color: var(--line-3);
  box-shadow: var(--shadow-2);
}
.person.gender-F { border-left-color: var(--rose); }
.person.gender-M { border-left-color: var(--cyan); }
.person h4 {
  margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; color: var(--ink); letter-spacing: -.005em;
}
.person .native { font-size: 13px; color: var(--ink-dim); font-weight: 400; }
.person .pdates {
  font-size: 11px; color: var(--green-2); font-weight: 700;
  letter-spacing: .03em; font-family: ui-monospace, 'SF Mono', monospace;
}
.person .pnotes { font-size: 12px; color: var(--ink-dim); font-weight: 400; line-height: 1.55; }
.person .ppages { font-size: 10px; color: var(--ink-mute); display: flex; gap: 4px; flex-wrap: wrap; }
.person .ppages span {
  background: var(--bg-dim); padding: 2px 7px; border-radius: 3px;
  font-family: ui-monospace, monospace; font-weight: 500;
}

.empty-state {
  grid-column: 1/-1; padding: 80px 24px; text-align: center; color: var(--ink-mute);
  border: 1px dashed var(--line-2); border-radius: var(--radius); background: var(--surface);
}
.empty-state p { font-size: 14px; }
.empty-state .dim { font-size: 12px; }
.empty-state code {
  background: var(--bg-dim); padding: 2px 6px; border-radius: 3px;
  font-size: 11px; color: var(--ink); font-weight: 500;
}

/* ============================================================
   FAMILY TREE TAB — dark feature panel (SBL-style accent)
   ============================================================ */
.tree-toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.seg {
  display: flex; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 100px; padding: 3px;
}
.seg-btn {
  background: transparent; border: none; cursor: pointer;
  padding: 8px 18px; color: var(--ink-dim); font-family: inherit;
  font-size: 12px; font-weight: 500; letter-spacing: .02em;
  border-radius: 100px; transition: all .15s;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--ink); color: #fff; }
.legend {
  display: flex; gap: 14px; font-size: 11px; color: var(--ink-dim); font-weight: 500;
  letter-spacing: .04em;
}
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content:""; width: 18px; height: 2px; border-radius: 100px; }
.lg-parent::before  { background: var(--green); }
.lg-spouse::before  { background: var(--rose); }
.lg-sibling::before { background: var(--cyan); }
.lg-other::before   { background: var(--ink-mute); }

.tree-frame {
  position: relative;
  background: #0d1530;          /* dark panel — feature contrast block */
  border: 1px solid #1c2647;
  border-radius: var(--radius-lg);
  height: 78vh; overflow: hidden;
  box-shadow: var(--shadow-2);
}
.tree-frame::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(149,193,31,.10), transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(124,92,209,.10), transparent 60%);
  pointer-events: none;
}
.tree-frame::after {
  /* subtle dot grid */
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none; opacity: .9;
}
.tree-frame svg { width: 100%; height: 100%; display: block; cursor: grab; position: relative; z-index: 1; }
.tree-frame svg:active { cursor: grabbing; }
.tree-info {
  position: absolute; top: 18px; right: 18px; max-width: 300px;
  background: rgba(13,21,48,.94); border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 14px 16px; backdrop-filter: blur(20px);
  font-size: 12px; line-height: 1.55; opacity: 0; transition: opacity .25s;
  pointer-events: none; color: #e8ebf3; z-index: 5;
}
.tree-info.show { opacity: 1; }
.tree-info h4 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: #fff; }
.tree-info .ti-row { color: #b8bfd0; margin: 2px 0; }
.tree-info .ti-row b { color: #fff; font-weight: 500; }

/* SVG nodes/edges in dark frame */
.node-circle {
  fill: url(#nodeGrad);
  stroke: rgba(255,255,255,.45);
  stroke-width: 1.5;
  cursor: pointer;
  transition: filter .15s;
}
.node-circle.gender-F { fill: url(#nodeGradF); }
.node-circle.gender-M { fill: url(#nodeGradM); }
.node-circle.highlight {
  stroke: var(--green); stroke-width: 3;
  filter: drop-shadow(0 0 12px rgba(149,193,31,.7));
}
.node-label {
  font-family: 'Poppins'; font-size: 11px; font-weight: 500;
  fill: #e8ebf3; pointer-events: none;
  text-shadow: 0 1px 4px rgba(0,0,0,.85);
}
.edge { fill: none; stroke-width: 1.5; opacity: .6; transition: opacity .2s; }
.edge.parent  { stroke: var(--green); }
.edge.child   { stroke: var(--green); }
.edge.spouse  { stroke: var(--rose); stroke-dasharray: 4 3; }
.edge.sibling { stroke: var(--cyan); }
.edge.other   { stroke: rgba(255,255,255,.25); }
.edge.dim     { opacity: .1; }

/* edge labels */
.edge-label {
  font-family: 'Poppins', sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  pointer-events: none;
  paint-order: stroke;
  stroke: #0d1530;
  stroke-width: 3px;
  stroke-linejoin: round;
  opacity: .85;
  transition: opacity .2s;
}
.edge-label.edge-parent  { fill: #b9d973; }
.edge-label.edge-spouse  { fill: #f0789f; }
.edge-label.edge-sibling { fill: #7ddae8; }
.edge-label.edge-other   { fill: rgba(255,255,255,.55); }
.edge-label.dim          { opacity: .1; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 720px) {
  .topbar { padding: 14px 22px; }
  .wrap { padding: 36px 22px 80px; }
  .master { padding: 20px; }
  .master h2 { font-size: 10px; }
}
