:root {
  --bg: #0a0c13;
  --bg2: #11141e;
  --bg3: #1a1e2c;
  --ink: #ece9e0;
  --mut: #9096a6;
  --line: rgba(255, 255, 255, .08);
  --gold: #e8c468;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --top: 54px;
  --eras: 46px;
  --panel: 420px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold); }

/* ── header ── */
#top {
  position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 30;
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: rgba(10, 12, 19, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.brand b { font: 700 19px/1 var(--serif); letter-spacing: .14em; }
.brand span { color: var(--mut); font-size: 13px; letter-spacing: .02em; }
.search { position: relative; flex: 1; max-width: 380px; margin-left: auto; }
.search input {
  width: 100%; height: 34px; padding: 0 14px; border-radius: 17px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .05); color: var(--ink);
  font: inherit; font-size: 14px; outline: none;
}
.search input:focus { border-color: var(--gold); }
.search input::placeholder { color: var(--mut); }
#qres {
  position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6); max-height: 60vh; overflow: auto;
}
#qres li { padding: 7px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 9px; align-items: baseline; }
#qres li:hover, #qres li.on { background: rgba(255, 255, 255, .08); }
#qres i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
#qres small { margin-left: auto; color: var(--mut); white-space: nowrap; font-size: 12px; }
nav { display: flex; gap: 8px; }
nav button, .intro-btns button, #panel .act, #zoomer button, #jbar button {
  height: 34px; padding: 0 15px; border-radius: 17px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .05);
  transition: background .15s, border-color .15s;
}
nav button:hover, .intro-btns button:hover, #panel .act:hover, #zoomer button:hover, #jbar button:hover { background: rgba(255, 255, 255, .12); }
button.primary { background: var(--gold) !important; color: #1a1405; border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }

/* ── stage ── */
#stage {
  position: fixed; top: var(--top); bottom: var(--eras); left: 0; right: 0;
  overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
#stage.dragging { cursor: grabbing; }
#cv { position: absolute; inset: 0; }
#world { position: absolute; left: 0; top: 0; width: 0; height: 0; will-change: transform; }

.node {
  position: absolute; left: 0; top: 0; width: 0; height: 0; padding: 0; border: 0; background: none;
  color: #c3c9d8; font: 12.5px/16px var(--sans); white-space: nowrap; text-align: left;
  animation: pop .7s backwards; transition: opacity .25s;
}
@keyframes pop { from { opacity: 0; } }
.node i {
  position: absolute; left: -4.5px; top: -4.5px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 2px var(--bg);
  transition: transform .15s;
}
.node i::before { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.node span { position: absolute; left: 9px; top: -8px; padding: 0 4px; border-radius: 5px; }
.node.key { color: #f4f1e8; font-weight: 600; }
.node.key i { left: -6.5px; top: -6.5px; width: 13px; height: 13px; box-shadow: 0 0 0 2px var(--bg), 0 0 12px -1px var(--c); }
.node.key span { left: 11px; }
.node.fut i { background: var(--bg); box-shadow: inset 0 0 0 2px var(--c); }
.node.fut span { font-style: italic; }
.node.nolab span { display: none; }
.node:hover, .node:focus-visible { z-index: 6; outline: none; }
.node:hover i, .node:focus-visible i { transform: scale(1.5); }
.node:hover span, .node:focus-visible span, .node.sel span {
  display: block; background: var(--bg3); color: #fff; box-shadow: 0 0 0 1px var(--c);
}
.node.dim { opacity: .13; }
.node.dim:hover { opacity: 1; }
.node.rel { color: #fff; }
.node.sel { z-index: 5; }
.node.sel i { transform: scale(1.35); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--c), 0 0 26px 6px var(--c); }

/* lane names */
#lanes { position: absolute; left: 0; top: 0; pointer-events: none; }
#lanes button {
  position: absolute; left: 8px; pointer-events: auto;
  height: 15px; padding: 0 7px 0 5px; border: 0; border-radius: 8px;
  background: rgba(10, 12, 19, .82); color: var(--c);
  font: 600 10px/15px var(--sans); letter-spacing: .09em; text-transform: uppercase; white-space: nowrap;
}
#lanes button::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
#lanes button:hover, #lanes button.on { background: var(--c); color: #0a0c13; }
#lanes button:hover::before, #lanes button.on::before { background: #0a0c13; }

#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 15px; background: rgba(26, 30, 44, .9); color: var(--mut);
  font-size: 12.5px; white-space: nowrap; pointer-events: none; transition: opacity .6s;
}
#hint.gone { opacity: 0; }
#zoomer { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; z-index: 8; }
#zoomer button { min-width: 34px; padding: 0 10px; background: rgba(26, 30, 44, .92); }
body.panel-open #zoomer { right: calc(var(--panel) + 12px); }

/* journey bar */
#jbar {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%); z-index: 9;
  display: flex; align-items: center; gap: 8px; padding: 6px;
  background: rgba(26, 30, 44, .95); border: 1px solid rgba(232, 196, 104, .45); border-radius: 26px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); max-width: calc(100% - 20px);
}
#jbar[hidden] { display: none; }
#jbar button { width: 34px; padding: 0; font-size: 18px; line-height: 1; flex: none; }
#jbar #jNext { background: var(--gold); color: #1a1405; border-color: transparent; }
.jtxt { display: flex; flex-direction: column; padding: 0 8px; min-width: 0; line-height: 1.25; }
.jtxt small { color: var(--gold); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.jtxt b { font: 600 14px/1.25 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jtxt span { color: var(--mut); font-size: 11.5px; }

/* ── era bar ── */
#eras {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--eras); z-index: 20;
  display: flex; background: var(--bg2); border-top: 1px solid var(--line);
}
#eras button {
  position: relative; min-width: 0; padding: 5px 8px 0; border: 0; border-right: 1px solid var(--line);
  background: none; text-align: left; overflow: hidden; color: var(--mut);
  border-top: 3px solid var(--c);
}
#eras button:hover, #eras button.on { background: rgba(255, 255, 255, .06); color: var(--ink); }
#eras b { display: block; font: 600 11.5px/1.3 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#eras small { display: block; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .75; }
#eraview {
  position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 2;
  background: rgba(232, 196, 104, .12); border: 1px solid rgba(232, 196, 104, .7); border-radius: 3px;
}

/* ── detail panel ── */
#panel {
  position: fixed; top: var(--top); bottom: var(--eras); right: 0; width: var(--panel); z-index: 25;
  background: var(--bg2); border-left: 1px solid var(--line);
  padding: 22px 24px 30px; overflow-y: auto; overscroll-behavior: contain;
  box-shadow: -20px 0 60px rgba(0, 0, 0, .45);
  animation: slide .28s ease-out;
}
#panel[hidden] { display: none; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
#panel .close, dialog .close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .07); color: var(--mut); font-size: 14px;
}
#panel .close:hover, dialog .close:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-right: 36px; }
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 11px; border: 1px solid var(--c); color: var(--c);
  font: 600 10.5px/16px var(--sans); letter-spacing: .08em; text-transform: uppercase; background: none;
}
.date { color: var(--mut); font-size: 13px; }
#panel h2 { font: 600 28px/1.15 var(--serif); margin: 12px 0 10px; text-wrap: balance; }
#panel .sum { font-size: 16px; line-height: 1.55; margin: 0 0 16px; color: #dcd9cf; }
.futnote {
  margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: rgba(232, 196, 104, .1); border: 1px dashed rgba(232, 196, 104, .5); color: var(--gold);
}
.wiki { margin: 0 0 18px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: rgba(255, 255, 255, .03); }
.wiki img { display: block; width: 100%; max-height: 240px; object-fit: cover; background: #000; }
.wiki div { padding: 12px 14px; font-size: 13.5px; line-height: 1.5; color: #b9bdc9; }
.wiki a { white-space: nowrap; }
.wiki small { display: block; margin-top: 6px; color: #6d7383; font-size: 11px; }
.wiki.loading div { color: var(--mut); font-style: italic; }
#panel .act { width: 100%; height: 40px; border-radius: 20px; margin-bottom: 6px; }
#panel .act.on { background: var(--gold); color: #1a1405; border-color: transparent; font-weight: 600; }
.lincount { color: var(--mut); font-size: 12.5px; text-align: center; margin: 0 0 8px; }
#panel h3 { font: 600 11px/1 var(--sans); letter-spacing: .13em; text-transform: uppercase; color: var(--mut); margin: 22px 0 8px; }
.links { list-style: none; margin: 0; padding: 0; }
.links button {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 2px 10px; align-items: baseline;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 9px; background: none; text-align: left;
}
.links button:hover { background: rgba(255, 255, 255, .07); }
.links i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.links b { font-weight: 600; font-size: 14.5px; }
.links small { color: var(--mut); font-size: 12px; white-space: nowrap; }
.links em { grid-column: 2 / 4; font-style: normal; font-size: 13px; color: #a9aebb; line-height: 1.4; }
.none { color: var(--mut); font-size: 13.5px; margin: 0; padding: 0 10px; }

/* ── intro ── */
#intro {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse 80% 70% at 50% 45%, rgba(10, 12, 19, .93) 30%, rgba(10, 12, 19, .62) 100%);
  transition: opacity .7s, visibility .7s; overflow: auto;
}
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-in { max-width: 720px; text-align: center; animation: rise 1.2s .2s backwards; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.kicker { color: var(--gold); font-size: 12.5px; letter-spacing: .22em; text-transform: uppercase; margin: 0 0 18px; }
#intro h1 { font: 600 clamp(38px, 7vw, 76px)/1.03 var(--serif); margin: 0 0 22px; letter-spacing: -.01em; text-wrap: balance; }
.lead { font: 400 clamp(16px, 2vw, 19px)/1.6 var(--serif); color: #cfccc2; margin: 0 auto 30px; max-width: 620px; }
.intro-btns { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.intro-btns .big { height: 48px; padding: 0 26px; border-radius: 24px; font-size: 16px; }
.intro-btns .link { border: 0; background: none; color: var(--mut); width: 100%; height: auto; padding: 6px; }
.intro-btns .link:hover { background: none; color: var(--ink); }
.stats { margin: 26px 0 0; color: var(--mut); font-size: 13px; letter-spacing: .03em; }

/* ── dialogs ── */
dialog {
  width: min(880px, calc(100vw - 24px)); max-height: calc(100vh - 40px); padding: 28px 30px 30px;
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 30px 100px rgba(0, 0, 0, .7);
}
dialog::backdrop { background: rgba(5, 6, 10, .72); backdrop-filter: blur(3px); }
dialog h2 { font: 600 30px/1.1 var(--serif); margin: 0 0 8px; }
.dlg-lead { color: var(--mut); margin: 0 0 20px; }
#jlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
#jlist button {
  display: flex; flex-direction: column; gap: 8px; padding: 16px 18px; text-align: left;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 255, 255, .03);
  transition: border-color .15s, background .15s, transform .15s;
}
#jlist button:hover { border-color: var(--gold); background: rgba(232, 196, 104, .07); transform: translateY(-2px); }
#jlist b { font: 600 18px/1.2 var(--serif); }
#jlist p { margin: 0; color: #b0b4c0; font-size: 13.5px; line-height: 1.45; flex: 1; }
#jlist .dots { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
#jlist .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
#jlist .dots small { color: var(--mut); margin-left: 6px; font-size: 12px; }
.about { max-width: 68ch; }
.about h3 { font: 600 12px/1 var(--sans); letter-spacing: .13em; text-transform: uppercase; color: var(--gold); margin: 22px 0 8px; }
.about p, .about li { color: #cfccc2; }
.about ul { padding-left: 20px; margin: 0; }
.about li { margin-bottom: 6px; }

/* ── small screens ── */
@media (max-width: 899px) {
  :root { --eras: 26px; --top: 50px; }
  .brand span { display: none; }
  #top { gap: 10px; padding: 0 10px; }
  nav button { padding: 0 11px; font-size: 14px; }
  #eras b, #eras small { display: none; }
  #eras button { padding: 0; }
  #hint { display: none; }
  #panel {
    top: auto; left: 0; right: 0; bottom: var(--eras); width: auto; height: 50vh;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
    padding: 18px 18px 26px; box-shadow: 0 -20px 60px rgba(0, 0, 0, .55);
  }
  @keyframes slide { from { transform: translateY(30px); opacity: 0; } }
  body.panel-open #stage { bottom: calc(var(--eras) + 50vh); }
  body.panel-open #zoomer { display: none; }
  #panel h2 { font-size: 23px; }
  #panel .sum { font-size: 15px; }
  #lanes button { left: 4px; font-size: 9px; letter-spacing: .05em; }
  #jbar { top: 54px; }
  dialog { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .node, .intro-in, #panel { animation: none; }
}

/* ── epochs, 3D, sound ── */
.chip.ep { border-style: dashed; cursor: pointer; }
.chip.ep:hover, .chip[data-dom]:hover { background: var(--c); color: #0a0c13; }
.kick { margin: 14px 0 -6px; color: var(--mut); font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.pernav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pernav .act { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 12px; font-size: 13.5px; }
body.v3 #world, body.v3 #lanes { display: none; }
#z3d.on, #btnSound.on { background: var(--gold); color: #1a1405; border-color: transparent; font-weight: 600; }
#btnSound.on { animation: hum 2.4s ease-in-out infinite; }
@keyframes hum { 50% { box-shadow: 0 0 0 5px rgba(232, 196, 104, .18); } }
.node.sel i::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--c);
  animation: ring 1.8s ease-out infinite; pointer-events: none;
}
@keyframes ring { to { transform: scale(3.4); opacity: 0; } }
@media (max-width: 899px) { #btnSound span { display: none; } #btnSound { padding: 0 12px; } }
@media (max-width: 480px) { .brand b { display: none; } }
@media (prefers-reduced-motion: reduce) { .node.sel i::after, #btnSound.on { animation: none; } }
