:root {
  --bg: #05060d;
  --ink: #e8edff;
  --ink-dim: #9aa3c7;
  --ink-faint: #5d6690;
  --glass: rgba(14, 17, 34, 0.72);
  --glass-strong: rgba(12, 14, 30, 0.9);
  --line: rgba(160, 175, 255, 0.14);
  --accent: #8fb0ff;
  --panel-w: 380px;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", var(--font);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  /* Deep-space backdrop with faint nebulae; the canvas draws stars on top. */
  background:
    radial-gradient(ellipse 60% 50% at 18% 22%, rgba(84, 60, 180, 0.16), transparent 70%),
    radial-gradient(ellipse 50% 45% at 82% 78%, rgba(30, 110, 190, 0.13), transparent 70%),
    radial-gradient(ellipse 80% 70% at 50% 50%, #0a0c1c, var(--bg));
  background-color: var(--bg);
}

button, input { font: inherit; color: inherit; }

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#map.grabbing { cursor: grabbing; }
#map.pointing { cursor: pointer; }

/* ── Brand ─────────────────────────────────────────── */
.brand {
  position: fixed;
  top: 18px;
  left: 20px;
  pointer-events: none;
  max-width: 46vw;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, #fff, #b9c8ff 60%, #ff9fd0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-dim);
}

/* ── Search ────────────────────────────────────────── */
.search {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 300px;
  z-index: 20;
}
.search input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  outline: none;
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
}
.search input::placeholder { color: var(--ink-faint); }
.search input:focus {
  border-color: rgba(143, 176, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(143, 176, 255, 0.12);
}
.search-icon {
  position: absolute;
  left: 13px;
  top: 11px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink-faint);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}
.results {
  list-style: none;
  margin: 8px 0 0;
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  max-height: 360px;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: rgba(143, 176, 255, 0.12); }
.results .r-kind {
  flex: none;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-faint);
  width: 44px;
}
.results .r-text { min-width: 0; }
.results .r-label { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results .r-sub { font-size: 12px; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results .r-empty { color: var(--ink-dim); font-size: 13px; cursor: default; }

/* ── Tooltip ───────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 15;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  font-size: 12.5px;
  white-space: nowrap;
  transform: translate(14px, 14px);
}
.tooltip b { font-weight: 600; }
.tooltip span { color: var(--ink-dim); }

/* ── Bottom dock: chips + timeline ─────────────────── */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(980px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10;
  transition: width .35s ease, left .35s ease;
}
body.panel-open .dock {
  left: calc((100vw - var(--panel-w) - 16px) / 2);
  width: min(980px, calc(100vw - var(--panel-w) - 64px));
}

.ticker {
  align-self: center;
  min-height: 24px;
  font-size: 13px;
  color: var(--ink-dim);
  text-align: center;
  opacity: 0;
  transition: opacity .35s;
}
.ticker.show { opacity: 1; }
.ticker b { color: var(--ink); font-weight: 600; }
.ticker i { font-style: normal; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: opacity .2s, border-color .2s, background .2s;
  white-space: nowrap;
}
.chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
}
.chip .n { color: var(--ink-faint); font-size: 11px; }
.chip[aria-pressed="false"] { opacity: .38; }
.chip[aria-pressed="false"] .dot { box-shadow: none; }
.chip:hover { border-color: rgba(160, 175, 255, 0.35); }
.chip.all { font-weight: 600; }

.timeline {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px 10px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.play {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #7d9bff, #c77dff);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(140, 130, 255, 0.45);
}
.play svg { width: 16px; height: 16px; fill: #fff; }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }

.year {
  flex: none;
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  width: 58px;
  font-variant-numeric: tabular-nums;
}
.count {
  flex: none;
  font-size: 12.5px;
  color: var(--ink-dim);
  white-space: nowrap;
}
.count b { color: var(--ink); font-weight: 600; }

input[type="range"] {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 28px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--p, 100%), rgba(160, 175, 255, 0.18) var(--p, 100%));
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(160, 175, 255, 0.18); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(143, 176, 255, 0.25), 0 0 14px rgba(143, 176, 255, 0.8);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(143, 176, 255, 0.25), 0 0 14px rgba(143, 176, 255, 0.8);
}

.hint {
  position: fixed;
  top: 74px;
  left: 20px;
  font-size: 12px;
  color: var(--ink-faint);
  pointer-events: none;
  transition: opacity 1s;
}
.hint.gone { opacity: 0; }

/* ── Detail panel (side panel on desktop) ──────────── */
.panel {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: var(--panel-w);
  z-index: 30;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--glass-strong);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  transform: translateX(calc(100% + 32px));
  transition: transform .4s cubic-bezier(.2, .8, .2, 1);
  display: flex;
  flex-direction: column;
}
.panel.open { transform: none; }
.panel-handle { display: none; }
.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 1;
}
.panel-close svg { width: 16px; height: 16px; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.panel-close:hover { background: rgba(255, 255, 255, 0.1); }

.panel-body {
  overflow-y: auto;
  padding: 26px 24px 28px;
  overscroll-behavior: contain;
}
.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding-right: 40px;
}
.eyebrow .dot, .cl-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 10px var(--c);
  flex: none;
}
.panel h2 {
  margin: 10px 0 16px;
  font-family: var(--display);
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  padding-right: 30px;
}
.sides {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.side {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  transition: background .2s, border-color .2s;
}
.side:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--c); }
.link-glyph {
  flex: none;
  font-size: 20px;
  color: var(--c);
  text-shadow: 0 0 10px var(--c);
}
.panel section { margin-bottom: 20px; }
.panel h3 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}
.panel p { margin: 0; line-height: 1.55; font-size: 15px; color: #d5dbf5; }
.friction {
  padding: 12px 14px;
  border-left: 3px solid var(--c);
  border-radius: 0 10px 10px 0;
  background: rgba(255, 255, 255, 0.035);
}
.muted { color: var(--ink-dim) !important; font-size: 14px !important; margin: -8px 0 18px !important; }

.conn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.conn-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.conn-list button:hover { background: rgba(255, 255, 255, 0.06); }
.conn-list .off { opacity: .4; }
.cl-text { min-width: 0; flex: 1; }
.cl-name { display: block; font-size: 14.5px; font-weight: 500; }
.cl-meta { display: block; font-size: 12.5px; color: var(--ink-dim); }
.cl-year { flex: none; font-size: 12.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ── Mobile: compact chrome, panel becomes a bottom sheet ── */
@media (max-width: 720px) {
  .brand { top: 14px; left: 16px; max-width: none; }
  .brand h1 { font-size: 19px; }
  .brand p { display: none; }
  .search { top: 50px; left: 16px; right: 16px; width: auto; }
  .hint { top: 98px; left: 16px; }
  .dock { width: calc(100vw - 24px); bottom: calc(10px + env(safe-area-inset-bottom)); gap: 8px; }
  body.panel-open .dock { left: 50%; width: calc(100vw - 24px); }
  .chips {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -12px;
    padding: 0 12px;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip .n { display: none; }
  .timeline { gap: 10px; padding: 8px 12px 8px 8px; }
  .year { font-size: 18px; width: 46px; }
  .count { display: none; }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 62vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: none; }
  .panel-handle {
    display: block;
    width: 40px;
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.25);
    margin: 10px auto 0;
    flex: none;
    touch-action: none;
  }
  .panel-body { padding: 14px 18px 22px; }
  .panel h2 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .dock, .ticker, .hint { transition: none; }
}
