:root {
  --ink: #07080a;
  --ink-2: #0c0e11;
  --land: #14161a;
  --hair: #2a2e35;
  --hair-soft: rgba(232, 230, 225, 0.08);
  --text: #e8e6e1;
  --text-2: rgba(232, 230, 225, 0.66);
  --text-3: rgba(232, 230, 225, 0.42);
  --text-4: rgba(232, 230, 225, 0.22);
  --ember: #c9643f;
  --ember-soft: rgba(201, 100, 63, 0.18);
  --steel: #8fa3b8;
  --sage: #9aa88a;
  --glass: rgba(12, 14, 17, 0.56);
  --glass-strong: rgba(10, 11, 14, 0.82);
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dock-h: 200px;
  --side-w: 320px;
  --gutter: 28px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible, .track:focus-visible { outline: 1px solid var(--text-3); outline-offset: 3px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- stage ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#fx { mix-blend-mode: screen; }
#pins { position: absolute; inset: 0; pointer-events: none; }

.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 55%, rgba(4, 5, 6, 0.75) 100%),
    linear-gradient(to bottom, rgba(7, 8, 10, 0.7) 0, transparent 120px, transparent calc(100% - 300px), rgba(7, 8, 10, 0.94) 100%);
}
.grain {
  position: absolute; inset: -50%; pointer-events: none; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

/* ---------- header ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px var(--gutter);
}
.mark {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text); text-decoration: none;
  font-family: var(--serif); font-size: 24px; letter-spacing: 0.005em;
}
.mark-icon { position: relative; display: inline-block; width: 30px; height: 30px; margin: -2px -4px -2px -4px; }
.mark-icon svg { display: block; overflow: visible; }
.m-rot { transform-origin: 16px 16px; transform: rotate(-35deg); }
.m-body { animation: m-hover 3.4s ease-in-out infinite; }
@keyframes m-hover { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(0.9px); } }
.m-flame { transform-origin: 8.6px 16px; animation: m-flame 0.16s steps(2) infinite alternate; filter: drop-shadow(0 0 2.5px rgba(201, 100, 63, 0.9)); }
@keyframes m-flame { from { transform: scaleX(0.7); opacity: 0.75; } to { transform: scaleX(1.12); opacity: 1; } }
.m-puff { opacity: 0; transform-origin: 8.6px 21.2px; stroke-width: 0.8; }
/* arming: the motor wakes up */
.mark-icon.arming .m-flame { animation-duration: 0.06s; }
.mark-icon.arming .m-body { animation: m-shiver 0.12s linear infinite; }
@keyframes m-shiver { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-0.4px, 0.3px); } }
/* fire: the missile leaves along its axis, then a fresh one slides back onto the rail */
.mark-icon.fire .m-body { animation: m-launch 1.6s cubic-bezier(0.5, 0, 0.2, 1) both; }
@keyframes m-launch {
  0% { transform: translateX(0); opacity: 1; }
  6% { transform: translateX(-1.4px); opacity: 1; }
  26% { transform: translateX(24px); opacity: 0; }
  27% { transform: translateX(-12px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}
.mark-icon.fire .m-puff { animation: m-puff 1.1s ease-out both; }
@keyframes m-puff { from { opacity: 0.55; transform: scale(0.3); } to { opacity: 0; transform: scale(2.6); } }
.top-right { display: flex; align-items: center; gap: 22px; }
.era-label {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3);
  transition: opacity 0.6s var(--ease);
}
.ghost {
  font-size: 12px; color: var(--text-2); padding: 7px 12px;
  border: 1px solid var(--hair-soft); border-radius: 999px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.ghost:hover { color: var(--text); border-color: rgba(232, 230, 225, 0.2); background: rgba(232, 230, 225, 0.03); }

/* ---------- panels ---------- */
.side {
  position: fixed; z-index: 5; top: 84px; right: var(--gutter);
  width: var(--side-w); bottom: calc(var(--dock-h) + 6px);
  display: flex; flex-direction: column; gap: 12px;
  pointer-events: none;
}
.now, .feed {
  pointer-events: auto;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--glass);
  border: 1px solid var(--hair-soft);
  border-radius: 14px;
  backdrop-filter: blur(14px) saturate(110%);
  -webkit-backdrop-filter: blur(14px) saturate(110%);
  overflow: hidden;
}
.now { flex: 0 1 auto; max-height: 60%; }
.feed { flex: 1 1 0; min-height: 120px; }
.side-body { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-head {
  display: flex; justify-content: space-between; align-items: baseline; width: 100%; text-align: left; cursor: default;
  padding: 14px 16px 10px;
  font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-3);
  border-bottom: 1px solid var(--hair-soft);
}
.panel-head .count { color: var(--text); font-size: 12px; letter-spacing: 0; }

.now-list, .feed-list { list-style: none; overflow-y: auto; scrollbar-width: none; padding: 4px 0 8px; }
.now-list::-webkit-scrollbar, .feed-list::-webkit-scrollbar { display: none; }

.now-item {
  position: relative; padding: 11px 16px 12px 30px;
  border-bottom: 1px solid rgba(232, 230, 225, 0.04);
  animation: rise 0.5s var(--ease) both;
  cursor: default;
}
.now-item:last-child { border-bottom: 0; }
.now-item::before {
  content: ""; position: absolute; left: 15px; top: 17px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ember); box-shadow: 0 0 10px rgba(201, 100, 63, 0.7);
  opacity: var(--heat, 0.6);
}
.now-name { font-size: 13.5px; font-weight: 500; color: var(--text); line-height: 1.3; }
.now-meta { margin-top: 3px; font-family: var(--mono); font-size: 10.5px; color: var(--text-3); display: flex; gap: 10px; flex-wrap: wrap; }
.now-gain { margin-top: 6px; font-size: 12px; color: var(--text-2); line-height: 1.4; }
.now-gain b { font-weight: 500; color: var(--text-3); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; margin-right: 6px; }
.now-empty { padding: 16px; font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--text-3); }
.now-empty.hidden { display: none; }

.feed-item { padding: 10px 16px 11px; border-bottom: 1px solid rgba(232, 230, 225, 0.04); animation: rise 0.6s var(--ease) both; }
.feed-item:last-child { border-bottom: 0; }
.feed-y { font-family: var(--mono); font-size: 10.5px; color: var(--text-3); display: flex; gap: 8px; align-items: center; }
.feed-kind { font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; border: 1px solid currentColor; opacity: 0.85; }
.feed-t { margin-top: 3px; font-size: 13px; color: var(--text); font-weight: 500; line-height: 1.3; }
.feed-d { margin-top: 3px; font-size: 12px; color: var(--text-2); }

.k-atrocity { color: #d08a73; } .k-genocide { color: #d0736a; } .k-nuclear { color: #f1eadb; }
.k-turning { color: #b9c2cc; } .k-treaty { color: #9fb3a0; } .k-famine { color: #c9b07a; }
.k-plunder { color: #d3b07c; } .k-weapon { color: #a7b4c4; } .k-exodus { color: #b7a6c9; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- dock ---------- */
.dock {
  position: fixed; z-index: 6; left: 0; right: 0; bottom: 0;
  padding: 0 var(--gutter) 22px;
}
.ledger {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0; margin-bottom: 16px;
  border-top: 1px solid var(--hair-soft);
}
.metric { padding: 14px 18px 0 0; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.metric + .metric { padding-left: 18px; border-left: 1px solid var(--hair-soft); }
.metric-k { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-k em { font-style: normal; color: var(--text-4); margin-left: 4px; letter-spacing: 0.08em; }
.metric-v { font-size: clamp(20px, 2.3vw, 32px); font-weight: 300; color: var(--text); line-height: 1.1; white-space: nowrap; }
.metric-s { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-v.pulse { animation: vpulse 0.9s var(--ease); }
@keyframes vpulse { 0% { color: #f4c8b3; text-shadow: 0 0 18px rgba(201, 100, 63, 0.6); } 100% { color: var(--text); text-shadow: none; } }

.timebar { display: flex; align-items: center; gap: 22px; }
.controls { display: flex; align-items: center; gap: 16px; flex: 0 0 auto; }
.play {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid rgba(232, 230, 225, 0.18);
  background: rgba(232, 230, 225, 0.04);
  transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.play:hover { background: rgba(232, 230, 225, 0.08); border-color: rgba(232, 230, 225, 0.3); }
.play:active { transform: scale(0.95); }
.play svg { width: 14px; height: 14px; fill: var(--text); }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }

.year-wrap { display: flex; align-items: baseline; gap: 8px; min-width: 150px; }
.year { font-family: var(--serif); font-size: 52px; line-height: 0.9; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.year-era { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--text-3); }

.speed { display: flex; border: 1px solid var(--hair-soft); border-radius: 999px; padding: 2px; }
.speed button { font-family: var(--mono); font-size: 10.5px; padding: 5px 9px; border-radius: 999px; color: var(--text-3); transition: color 0.2s, background 0.2s; }
.speed button:hover { color: var(--text-2); }
.speed button.on { background: rgba(232, 230, 225, 0.1); color: var(--text); }

.track { position: relative; flex: 1 1 auto; height: 70px; cursor: pointer; touch-action: none; user-select: none; }
#density { position: absolute; left: 0; right: 0; top: 0; height: 30px; width: 100%; }
.eras { position: absolute; left: 0; right: 0; top: 33px; height: 1px; background: var(--hair); }
.era-band { position: absolute; top: -3px; height: 7px; border-left: 1px solid var(--hair); }
.era-band span {
  position: absolute; top: 9px; left: 6px; white-space: nowrap;
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-4);
  transition: color 0.4s;
}
.era-band.on span { color: var(--text-2); }
.ticks { position: absolute; left: 0; right: 0; top: 56px; height: 12px; }
.tick { position: absolute; transform: translateX(-50%); font-family: var(--mono); font-size: 9.5px; color: var(--text-4); white-space: nowrap; }
.progress { position: absolute; left: 0; top: 32px; height: 3px; width: 0; background: linear-gradient(90deg, rgba(232,230,225,0.05), rgba(201,100,63,0.75)); border-radius: 2px; pointer-events: none; }
.head { position: absolute; top: -4px; bottom: 18px; width: 0; pointer-events: none; }
.head-line { position: absolute; left: -0.5px; top: 0; bottom: 0; width: 1px; background: var(--text); box-shadow: 0 0 10px rgba(232,230,225,0.6); }
.head-line::after { content: ""; position: absolute; left: -4px; top: 33px; width: 9px; height: 9px; border-radius: 50%; background: var(--text); box-shadow: 0 0 0 4px rgba(232,230,225,0.1); }
.hover-year { position: absolute; top: -22px; transform: translateX(-50%); font-size: 10.5px; color: var(--text-2); padding: 2px 6px; border-radius: 4px; background: var(--glass-strong); border: 1px solid var(--hair-soft); opacity: 0; transition: opacity 0.15s; pointer-events: none; white-space: nowrap; }
.track:hover .hover-year { opacity: 1; }

/* ---------- map pins (event cards) ---------- */
.pin { position: absolute; width: 0; height: 0; }
.pin-dot { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; background: var(--text); box-shadow: 0 0 14px rgba(232,230,225,0.8); }
.pin-ring { position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(232,230,225,0.5); animation: ring 2.2s var(--ease) infinite; }
@keyframes ring { from { transform: scale(0.2); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.pin-line { position: absolute; left: 0; bottom: 0; width: 1px; height: 54px; background: linear-gradient(to top, rgba(232,230,225,0.5), rgba(232,230,225,0)); transform-origin: bottom; animation: grow 0.5s var(--ease) both; }
.pin-card {
  position: absolute; left: 12px; bottom: 46px; width: 250px;
  padding: 11px 13px 12px; border-radius: 10px;
  background: var(--glass-strong); border: 1px solid rgba(232,230,225,0.1);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: rise 0.55s var(--ease) both;
}
.pin.left .pin-card { left: auto; right: 12px; }
.pin.below .pin-line { bottom: auto; top: 0; transform-origin: top; background: linear-gradient(to bottom, rgba(232,230,225,0.5), rgba(232,230,225,0)); }
.pin.below .pin-card { bottom: auto; top: 46px; }
.pin-card .feed-t { font-size: 13.5px; }
.pin.out { animation: fadeout 0.8s var(--ease) forwards; }
@keyframes grow { from { transform: scaleY(0); } to { transform: none; } }
@keyframes fadeout { to { opacity: 0; transform: translateY(-4px); } }

/* ---------- tooltip ---------- */
.tip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 280px;
  padding: 10px 12px; border-radius: 9px;
  background: var(--glass-strong); border: 1px solid rgba(232,230,225,0.12);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  opacity: 0; transform: translateY(4px); transition: opacity 0.15s, transform 0.15s;
}
.tip.on { opacity: 1; transform: none; }
.tip .now-meta { margin-top: 4px; }

/* ---------- veils ---------- */
.veil {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(80% 70% at 50% 45%, rgba(7,8,10,0.55), rgba(7,8,10,0.95));
  transition: opacity 1.1s var(--ease), visibility 1.1s;
}
.veil.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.veil-inner { max-width: 620px; text-align: center; }
.kicker { font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-3); }
.veil h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(64px, 11vw, 132px); line-height: 0.95; letter-spacing: -0.02em; margin: 14px 0 22px; }
.veil h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(40px, 6vw, 72px); line-height: 1; margin: 12px 0 28px; }
.lede { font-size: 16px; line-height: 1.6; color: var(--text-2); max-width: 520px; margin: 0 auto; }
.lede.small { font-size: 14px; margin-top: 26px; }
.begin {
  margin-top: 34px; padding: 13px 26px; border-radius: 999px;
  border: 1px solid rgba(232,230,225,0.28); color: var(--text); font-size: 14px; letter-spacing: 0.02em;
  transition: background 0.25s, border-color 0.25s, letter-spacing 0.4s var(--ease);
}
.begin:hover { background: rgba(232,230,225,0.06); border-color: rgba(232,230,225,0.5); letter-spacing: 0.05em; }
.begin span { display: inline-block; margin-left: 6px; transition: transform 0.3s var(--ease); }
.begin:hover span { transform: translateX(3px); }
.hint { margin-top: 22px; font-size: 11.5px; color: var(--text-4); }
.veil-actions { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }
.veil-actions .ghost { margin-top: 34px; padding: 12px 18px; font-size: 13px; }

.totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 36px; text-align: left; max-width: 520px; margin: 0 auto; }
.totals div { border-top: 1px solid var(--hair-soft); padding-top: 10px; }
.totals dt { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); }
.totals dd { font-family: var(--mono); font-weight: 300; font-size: 26px; margin-top: 4px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px; background: rgba(4,5,6,0.7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); transition: opacity 0.4s var(--ease), visibility 0.4s; }
.modal.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.modal-card { position: relative; max-width: 600px; max-height: 84vh; overflow-y: auto; padding: 34px 36px; border-radius: 16px; background: #0d0f12; border: 1px solid var(--hair-soft); }
.modal-card h2 { font-family: var(--serif); font-weight: 400; font-size: 36px; margin-bottom: 18px; }
.modal-card p { color: var(--text-2); font-size: 14px; line-height: 1.65; margin-bottom: 12px; }
.modal-card strong { color: var(--text); font-weight: 500; }
.modal-card .sources { font-size: 12.5px; color: var(--text-3); border-top: 1px solid var(--hair-soft); padding-top: 14px; margin-top: 18px; }
.close { position: absolute; top: 14px; right: 16px; font-size: 22px; color: var(--text-3); width: 34px; height: 34px; border-radius: 50%; }
.close:hover { color: var(--text); background: rgba(232,230,225,0.05); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; color: var(--text-2); }

/* ---------- responsive ---------- */
/* Below 1100px the side column collapses to a pill that opens on demand, so the map keeps the whole width. */
@media (max-width: 1100px) {
  :root { --dock-h: 250px; }
  .side { bottom: auto; width: 290px; }
  .feed { display: none; }
  .now { max-height: calc(100vh - var(--dock-h) - 110px); }
  #sideToggle { cursor: pointer; }
  #sideToggle::after { content: "+"; font-family: var(--mono); color: var(--text-3); margin-left: 10px; }
  .side.open #sideToggle::after { content: "–"; }
  .side:not(.open) .side-body { display: none; }
  .side:not(.open) .panel-head { border-bottom: 0; padding-bottom: 12px; }
  .timebar { flex-wrap: wrap; row-gap: 6px; }
  .track { flex-basis: 100%; }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; --dock-h: 270px; }
  .top { padding: 16px var(--gutter); }
  .mark { font-size: 21px; }
  .era-label { display: none; }
  .side { top: 60px; left: auto; width: min(290px, calc(100vw - 2 * var(--gutter))); }
  .now-gain { display: none; }
  .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(3) { padding-left: 0; border-left: 0; }
  .metric-s { display: none; }
  .metric-v { font-size: 17px; }
  .timebar { flex-direction: column; align-items: stretch; gap: 10px; }
  .controls { justify-content: space-between; }
  .year { font-size: 40px; }
  .year-wrap { min-width: 0; }
  .era-band span { display: none; }
  .pin-card { width: 190px; }
  .totals dd { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .grain, .pin-ring, .m-body, .m-flame { animation: none; }
}
.totals dd { white-space: nowrap; }
