:root {
  --bg: #05070b;
  --panel: rgba(10, 14, 21, 0.72);
  --panel-solid: #0c111a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e9edf3;
  --muted: #8a94a6;
  --faint: #5b6577;
  --birth: #34e89e;
  --death: #ff4d5e;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "Inter Tight", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--sans); overflow: hidden; }
button, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#map { position: fixed; inset: 0; }
.pulse-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }

.glass {
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
}

/* ---------- top ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: calc(var(--gutter) + env(safe-area-inset-top)) var(--gutter) 0;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand h1 { margin: 0; font: 400 34px/1 var(--serif); letter-spacing: -0.01em; }
.brand h1 em { color: var(--birth); }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.counters { padding: 10px 14px 10px; border-radius: 14px; min-width: 300px; }
.counters, .controls, .card, .feed li button, .replay-banner {
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line);
}
.c-label { margin: 0 0 4px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.c-row { display: flex; gap: 22px; }
.c span { display: block; font: 400 32px/1 var(--serif); font-variant-numeric: tabular-nums; }
.c small { color: var(--muted); font-size: 12px; }
.c-born span { color: var(--birth); }
.c-died span { color: var(--death); }
.c-sub { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; }
.c-sub:empty { display: none; }

.replay-banner {
  display: none;
  position: fixed; z-index: 5; right: var(--gutter); left: auto;
  top: calc(118px + env(safe-area-inset-top));
  margin: 0; padding: 7px 14px; border-radius: 999px; font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.replay-banner b { color: #ffd166; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; font-size: 11px; margin-right: 6px; }
.is-replay .replay-banner { display: block; }

/* ---------- live feed ---------- */
.feed { position: fixed; z-index: 4; right: var(--gutter); top: 150px; width: 280px; pointer-events: none; }
.feed ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.feed li { pointer-events: auto; animation: slide-in 0.45s cubic-bezier(.2,.8,.2,1); }
.feed li:nth-child(n+4) { opacity: 0.55; }
.feed li:nth-child(n+6) { opacity: 0.25; }
.feed li button {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 8px 12px 8px 14px; border-radius: 10px; position: relative;
}
.feed li button::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--birth); }
.feed li.t-death button::before { background: var(--death); }
.feed b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed span { color: var(--muted); font-size: 12px; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- controls ---------- */
.controls {
  position: fixed; z-index: 5; left: var(--gutter); right: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  border-radius: 16px; padding: 10px; display: grid; gap: 8px; max-width: 1100px; margin: 0 auto;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: rgba(255,255,255,0.04); border-radius: 10px; padding: 3px; }
.seg button, .toggle, .select select {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: rgba(255,255,255,0.1); color: var(--text); }
.toggle { background: rgba(255,255,255,0.04); }
.toggle[aria-pressed="true"] { background: rgba(52,232,158,0.16); color: var(--birth); }
.select select { background: rgba(255,255,255,0.04); appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.select option { background: var(--panel-solid); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot-birth { background: var(--birth); box-shadow: 0 0 8px var(--birth); }
.dot-death { background: var(--death); box-shadow: 0 0 8px var(--death); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
.chip i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.chip[aria-pressed="true"] { color: var(--text); border-color: color-mix(in srgb, var(--c, #fff) 55%, transparent); background: color-mix(in srgb, var(--c, #fff) 12%, transparent); }
.chip-all[aria-pressed="true"] { --c: #ffffff; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--birth); outline-offset: 2px; }

/* ---------- card ---------- */
.card {
  position: fixed; z-index: 6; right: var(--gutter); top: 150px; width: 340px;
  border-radius: 16px; padding: 18px 18px 16px; background: var(--panel-solid);
  opacity: 0; transform: translateX(12px); transition: opacity .2s, transform .25s cubic-bezier(.2,.8,.2,1);
}
.card.open { opacity: 1; transform: none; }
.card-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; padding: 4px 8px; }
.card-kicker { margin: 0; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.card-kicker i, .sec i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 7px; vertical-align: 1px; box-shadow: 0 0 8px var(--c); }
.card h2 { margin: 8px 30px 4px 0; font: 400 26px/1.1 var(--serif); }
.card-where { margin: 0 0 14px; color: var(--muted); }
.card dl { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; margin: 0 0 16px; font-size: 13px; }
.card dt { color: var(--faint); }
.card dd { margin: 0; }
.card dd small { display: block; color: var(--muted); margin-top: 3px; }
.card-link { color: var(--birth); text-decoration: none; font-weight: 500; }
.card-link:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ---------- MapLibre chrome ---------- */
.maplibregl-ctrl-attrib { background: rgba(5,7,11,0.6) !important; color: var(--faint); }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.maplibregl-ctrl-bottom-right { bottom: 118px; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .top { flex-direction: column-reverse; gap: 8px; }
  .brand { width: 100%; display: flex; align-items: center; gap: 10px; }
  .brand h1 { font-size: 22px; flex: none; }
  .brand p { display: none; }
  .counters { min-width: 0; width: 100%; padding: 8px 12px; }
  .c-row { justify-content: space-between; }
  .c span { font-size: 26px; }
  .replay-banner { top: calc(196px + env(safe-area-inset-top)); left: var(--gutter); right: var(--gutter); white-space: normal; font-size: 11.5px; border-radius: 12px; }
  .replay-banner .long { display: none; }
  .feed { display: none; }
  .controls { padding: 8px; border-radius: 14px; }
  .seg button, .toggle, .select select { padding: 6px 9px; }
  .select select { max-width: 132px; }
  .card {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; border-radius: 18px 18px 0 0;
    padding: 18px var(--gutter) calc(20px + env(safe-area-inset-bottom));
    transform: translateY(100%); max-height: 70vh; overflow-y: auto;
  }
  .card::before { content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: rgba(255,255,255,0.18); }
  .card.open { transform: none; }
  .maplibregl-ctrl-bottom-right { bottom: 112px; }
}

@media (prefers-reduced-motion: reduce) {
  .feed li { animation: none; }
  .card { transition: none; }
}

/* ---------- explore links (map page) ---------- */
.explore { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.explore a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); }
.explore a:hover { color: var(--text); }
@media (max-width: 760px) { .explore { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-top: 0; } .explore::-webkit-scrollbar { display: none; } }

/* ---------- poster mode (/?og=1, used for the share image) ---------- */
body.og .controls, body.og .feed, body.og .replay-banner, body.og .explore, body.og .maplibregl-control-container, body.og .card { display: none !important; }
body.og .brand h1 { font-size: 64px; }
body.og .brand p { font-size: 22px; margin-top: 10px; display: block; }
body.og .counters { transform: scale(1.25); transform-origin: top right; }
