/* ===== themes (light default) ===== */
:root, [data-theme="light"] {
  --bg: #f6f4ee; --bg2: #efece2; --ink: #1b1e24;
  --muted: #5c6470; --faint: #9098a4; --line: rgba(0,0,0,.10);
  --accent: #d9870a; --coop: #189d76; --conflict: #d23b3b; --neutral: #97a0ad;
  --panel: rgba(255,255,255,.72); --halo: rgba(255,255,255,.92);
  --vig: rgba(246,244,238,.55); --shadow: 0 6px 24px rgba(0,0,0,.10);
}
[data-theme="dark"] {
  --bg: #0e1116; --bg2: #0a0d12; --ink: #f2f0ea; --muted: #9aa3b0; --faint: #5b6472;
  --line: rgba(255,255,255,.08); --accent: #f5a623; --coop: #4fd2a8; --conflict: #ef6a6a;
  --neutral: #6b7686; --panel: rgba(14,18,24,.6); --halo: rgba(6,8,11,.85);
  --vig: rgba(6,8,11,.62); --shadow: 0 8px 28px rgba(0,0,0,.4);
}

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--sans); overflow: hidden; transition: background .4s, color .4s; }
body { height: 100vh; }
button { font-family: inherit; }

#stage { position: fixed; inset: 0; }
#graph { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 50%, var(--vig) 100%); }

/* ---------- chapter card ---------- */
#chapter { position: absolute; top: 24px; left: 30px; max-width: 430px; z-index: 5; pointer-events: none; }
#chapter .kicker { font-size: 12px; letter-spacing: 2.5px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
#chapter h1 { font-family: var(--serif); font-size: 38px; line-height: 1.05; margin: 6px 0 9px; font-weight: 600; }
#chapter .lead { font-family: var(--serif); font-size: 16px; line-height: 1.5; color: var(--ink); opacity: .88; max-width: 410px; }
#chapter .broker { margin-top: 12px; font-size: 13px; color: var(--muted); }
#chapter .broker b { color: var(--accent); font-weight: 800; }
#chapter .stat { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }
#chapter .stat b { color: var(--ink); } #chapter .stat .pakhi { color: var(--accent); font-weight: 700; }
.fade-swap { animation: fadeSwap .7s ease; }
@keyframes fadeSwap { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- date + phase ---------- */
#datebox { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); text-align: center; z-index: 5; pointer-events: none; }
#datebox .d { font-family: var(--serif); font-size: 29px; font-weight: 600; }
#phasebadge { display: inline-block; margin-top: 3px; padding: 2px 12px; border-radius: 20px; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 700; }
#phasebadge.pre { background: var(--line); color: var(--muted); }
#phasebadge.during { background: var(--coop); color: #fff; }
#phasebadge.post { background: var(--accent); color: #1a1205; }

/* ---------- right rail ---------- */
#board, #mentions { position: absolute; right: 26px; width: 256px; z-index: 5;
  background: var(--panel); backdrop-filter: blur(9px); border: 1px solid var(--line);
  border-radius: 14px; padding: 13px 15px; box-shadow: var(--shadow); }
#board { top: 24px; }
#mentions { top: 290px; max-height: 38vh; display: flex; flex-direction: column; }
#board h2, #mentions h2 { margin: 0 0 2px; font-size: 12px; letter-spacing: 1.3px; text-transform: uppercase; }
#board .cap { font-size: 11px; color: var(--faint); margin-bottom: 9px; }
.lbrow { position: relative; height: 25px; margin: 5px 0; display: flex; align-items: center; cursor: pointer; }
.lbbar { position: absolute; left: 0; top: 3px; bottom: 3px; border-radius: 6px; background: var(--line); transition: width .6s cubic-bezier(.4,0,.2,1); }
.lbrow.pak .lbbar { background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent)); }
.lbflag { position: relative; z-index: 1; width: 9px; height: 9px; border-radius: 50%; margin: 0 8px; }
.lbname { position: relative; z-index: 1; font-size: 13px; }
.lbrow.pak .lbname { font-weight: 800; color: var(--accent); }
.lbpct { position: relative; z-index: 1; margin-left: auto; padding-right: 7px; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
#sparkwrap { margin-top: 11px; border-top: 1px solid var(--line); padding-top: 9px; }
#spark { width: 100%; height: 38px; display: block; }
.sparklabel { font-size: 10.5px; color: var(--faint); margin-top: 3px; }

#mentions h2 .x { float: right; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--accent); cursor: pointer; font-size: 11px; }
#mentlist { overflow-y: auto; margin-top: 6px; }
.ment { border-left: 3px solid var(--neutral); padding: 4px 0 5px 8px; margin-bottom: 6px; cursor: pointer; }
.ment.coop { border-left-color: var(--coop); } .ment.conflict { border-left-color: var(--conflict); }
.ment .d { font-size: 11px; color: var(--ink); font-weight: 600; } .ment .d .a { color: var(--accent); }
.ment .m { font-size: 10.5px; color: var(--faint); }
.ment:hover { background: var(--line); border-radius: 0 6px 6px 0; }

/* ---------- citation spotlight ---------- */
#spotlight { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); width: min(820px, 84vw); z-index: 5; }
.card { background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line);
  border-left: 4px solid var(--neutral); border-radius: 14px; padding: 15px 20px; box-shadow: var(--shadow); }
.card.coop { border-left-color: var(--coop); } .card.conflict { border-left-color: var(--conflict); }
.card .topline { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.card .dyad { color: var(--ink); font-weight: 700; font-size: 14.5px; }
.card .dyad .arrow { color: var(--accent); margin: 0 6px; }
.card .verb { font-style: italic; color: var(--accent); }
.card .when { margin-left: auto; font-variant-numeric: tabular-nums; }
.card .quote { font-family: var(--serif); font-size: 20px; line-height: 1.4; }
.card .src { margin-top: 8px; font-size: 12px; }
.card .src a { color: var(--faint); text-decoration: none; } .card .src a:hover { color: var(--coop); }
.spot-anim { animation: spotIn .55s cubic-bezier(.2,.8,.2,1); }
@keyframes spotIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- dock ---------- */
#dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; padding: 12px 26px 14px;
  background: linear-gradient(transparent, color-mix(in srgb, var(--bg) 88%, transparent) 38%); }
#timeline { position: relative; height: 30px; margin: 0 4px 9px; }
#track { position: absolute; top: 13px; left: 0; right: 0; height: 4px; background: var(--line); border-radius: 3px; }
#progress { position: absolute; top: 13px; left: 0; height: 4px; background: var(--accent); border-radius: 3px; width: 0; }
.chaptick { position: absolute; top: 6px; bottom: 6px; width: 1px; background: var(--faint); opacity: .5; }
.chaplabel { position: absolute; top: -15px; font-size: 10.5px; color: var(--faint); white-space: nowrap; transform: translateX(4px); cursor: pointer; }
.chaplabel.active { color: var(--accent); font-weight: 700; }
.boundary-mark { position: absolute; top: 2px; bottom: 2px; width: 2px; background: var(--accent); }
.boundary-mark .lab { position: absolute; top: -15px; left: 5px; font-size: 10.5px; color: var(--accent); font-weight: 700; white-space: nowrap; }
#playhead { position: absolute; top: 8px; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); transform: translateX(-7px); }
#scrubber { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; margin: 0; }

#controls { display: flex; align-items: center; gap: 13px; }
.play { background: var(--accent); color: #1a1205; border: 0; border-radius: 24px; padding: 9px 20px; font-size: 14px; font-weight: 800; cursor: pointer; min-width: 104px; }
.play.playing { background: var(--line); color: var(--ink); }
.seg { display: inline-flex; background: var(--line); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 7px 14px; font-size: 12.5px; cursor: pointer; }
.seg button.active { background: var(--ink); color: var(--bg); font-weight: 700; }
.seg.small button { padding: 6px 11px; font-size: 12px; }
.ctl-label { font-size: 11px; color: var(--faint); letter-spacing: 1px; text-transform: uppercase; }
.icon-btn { background: var(--line); border: 1px solid var(--line); color: var(--ink); border-radius: 50%; width: 34px; height: 34px; font-size: 15px; cursor: pointer; }
.spacer { flex: 1; } .hint { font-size: 11.5px; color: var(--faint); }

/* ---------- graph ---------- */
.bloc-label { fill: var(--faint); font-size: 11px; letter-spacing: 2px; text-transform: uppercase; pointer-events: none; opacity: .6; }
.edge { fill: none; pointer-events: stroke; cursor: pointer; }
.flow { fill: none; pointer-events: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 1 11; stroke-linecap: round; opacity: .9; animation: flow 1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -36; } }
.node-dot { cursor: pointer; }
.node-halo { fill-opacity: .16; stroke: none; pointer-events: none; }
.node-label { font-family: var(--sans); fill: var(--ink); font-weight: 600; pointer-events: none; paint-order: stroke; stroke: var(--halo); stroke-width: 3.5px; }
.node-label.pak { fill: var(--accent); }
.dim { opacity: .12 !important; }
.legend { position: absolute; left: 30px; bottom: 124px; z-index: 4; font-size: 11px; color: var(--muted); display: grid; grid-template-columns: auto auto; gap: 3px 14px; opacity: .85; pointer-events: none; }
.legend .sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.legend .enc { grid-column: 1 / -1; margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line); color: var(--faint); display: flex; align-items: center; gap: 6px; }
.legend .enc b { color: var(--muted); font-weight: 700; }
.legend .encmark { position: relative; display: inline-block; width: 18px; height: 12px; vertical-align: middle; }
.legend .encmark .h { position: absolute; left: 1px; top: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); opacity: .28; }
.legend .encmark .d { position: absolute; left: 4px; top: 3px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* respect reduced-motion: kill ambient animation (JS also skips flashes/tweens) */
@media (prefers-reduced-motion: reduce) {
  .flow { animation: none; }
  .fade-swap, .spot-anim { animation: none; }
  html, body { transition: none; }
}
