:root {
  --bg: #050508;
  --text: #e8e6f0;
  --muted: #9ca3af;
  --strand-a: #22d3ee;
  --strand-b: #e879f9;
  --accent: #fbbf24;
  --card-bg: rgba(12, 12, 20, 0.92);
  --key-track: rgba(255, 255, 255, 0.12);
  --key-rail-h: clamp(72px, 12vh, 96px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse at 30% 20%, #1a1028 0%, transparent 55%),
    radial-gradient(ellipse at 70% 80%, #0a1628 0%, transparent 50%), var(--bg);
  transition: filter 0.6s ease;
}

#backdrop.colorful {
  background: radial-gradient(ellipse at 25% 30%, #3d1f4a 0%, transparent 50%),
    radial-gradient(ellipse at 75% 70%, #1e3a5f 0%, transparent 45%),
    linear-gradient(160deg, #120810, #0a1020);
}

#backdrop.transition {
  background: radial-gradient(ellipse at 50% 50%, #111 0%, #000 70%);
}

#backdrop.blackout {
  background: radial-gradient(ellipse at 40% 40%, #222 0%, #000 65%);
  filter: grayscale(0.85) contrast(1.1);
}

#ink-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, transparent 0%, #000 70%);
  transition: opacity 0.4s ease;
}

#canvas-host {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--key-rail-h);
  z-index: 2;
}

#helix-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 1rem 1.25rem;
  padding-right: min(300px, 44vw);
  pointer-events: none;
  max-width: 100vw;
  overflow: visible;
}

header h1 {
  margin: 0;
  font-size: clamp(1.15rem, 3vw, 1.65rem);
  letter-spacing: 0.04em;
  font-weight: 600;
}

header p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: clamp(0.78rem, 2.5vw, 0.88rem);
  max-width: 36rem;
  line-height: 1.35;
}

#site-subtitle {
  color: var(--accent);
  font-size: clamp(0.72rem, 2.2vw, 0.82rem);
}

#search-wrap {
  position: relative;
  z-index: 2;
  margin-top: 0.65rem;
  max-width: min(320px, 88vw);
  pointer-events: auto;
}

#search-input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 0.82rem;
}

#search-results {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.35rem 0;
  list-style: none;
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  max-height: min(220px, 40vh);
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-overflow-scrolling: touch;
}

#search-results:not([hidden]) {
  pointer-events: auto;
}

#search-results button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}

#search-results button:hover {
  background: rgba(255, 255, 255, 0.06);
}

#search-results .sr {
  color: var(--accent);
  margin-right: 0.35rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

#site-footer {
  position: fixed;
  bottom: calc(var(--key-rail-h) + 0.25rem);
  left: 0.75rem;
  z-index: 9;
  font-size: 0.62rem;
  color: var(--muted);
  pointer-events: none;
  max-width: min(280px, 50vw);
}

#dev-tools-bar {
  position: fixed;
  right: 0.75rem;
  bottom: calc(var(--key-rail-h) + 0.35rem);
  z-index: 12;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  max-width: min(420px, 92vw);
  pointer-events: none;
}

#dev-tools-bar > * {
  pointer-events: auto;
}

.dev-badge {
  font-size: 0.65rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.12);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: var(--strand-a);
  white-space: nowrap;
}

.rebuild-btn {
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(0, 0, 0, 0.55);
  color: var(--accent);
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.68rem;
  cursor: pointer;
  white-space: nowrap;
}

.rebuild-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.view-toggle {
  position: fixed;
  top: 0.85rem;
  right: 0.75rem;
  z-index: 22;
  display: flex;
  gap: 0.35rem;
}

.view-toggle .chip {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.view-toggle .chip.active {
  border-color: var(--accent);
  color: var(--accent);
}

#year-display {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 8;
  font-size: clamp(3rem, 14vw, 5.5rem);
  font-weight: 700;
  line-height: 1;
  opacity: 0.22;
  pointer-events: none;
}

#focus-rail {
  position: fixed;
  right: 0.85rem;
  bottom: calc(var(--key-rail-h) + 0.15rem);
  z-index: 13;
  width: min(140px, 28vw);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  pointer-events: auto;
}

#focus-rail label {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--strand-a);
  text-align: right;
}

#focus-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(34, 211, 238, 0.2);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

#focus-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--strand-a);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.55);
}

#focus-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--strand-a);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.55);
}

#key-rail {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 12;
  height: var(--key-rail-h);
  padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom, 0px));
  padding-right: min(10rem, 22vw);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(to top, rgba(5, 5, 8, 0.95), rgba(5, 5, 8, 0.55));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
}

.key-end {
  flex: 0 0 auto;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 2.25rem;
}

.key-end:last-child {
  text-align: right;
}

.key-track-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.key-track-wrap label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-align: center;
}

.key-track-wrap .view-toggle-inline {
  display: none;
}

#key-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  background: var(--key-track);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

#key-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

#key-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}

#controls {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(var(--key-rail-h) + 2.85rem);
  top: auto;
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  max-width: none;
  pointer-events: none;
}

#controls .controls-row {
  pointer-events: auto;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  width: 100%;
  max-width: min(1120px, 100%);
}

@media (min-width: 720px) {
  .controls-row.filters-row,
  .controls-row.eras-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: center;
    scrollbar-width: thin;
    padding: 0.15rem 0.25rem 0.35rem;
    -webkit-overflow-scrolling: touch;
  }

  .controls-row.filters-row button.chip,
  .controls-row.eras-row button.era-jump {
    flex: 0 0 auto;
  }
}

button.chip,
button.era-jump {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  padding: 0.42rem 0.78rem;
  border-radius: 999px;
  font-size: 0.72rem;
  cursor: pointer;
  touch-action: manipulation;
}

button.chip.active {
  border-color: var(--accent);
  color: var(--accent);
}

button.era-jump:hover,
button.chip:hover {
  border-color: var(--strand-a);
}

#stats-panel {
  position: fixed;
  top: auto;
  bottom: calc(var(--key-rail-h) + 5.35rem);
  left: 0.75rem;
  z-index: 10;
  max-width: min(240px, 42vw);
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

#stats-panel strong {
  color: var(--text);
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
}

#materialize-overlay {
  position: fixed;
  inset: 0;
  z-index: 14;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

#materialize-overlay.active {
  opacity: 1;
}

#card {
  position: fixed;
  top: auto;
  bottom: calc(var(--key-rail-h) + 0.75rem);
  left: 50%;
  transform: translateX(-50%) scale(0.94);
  z-index: 15;
  width: min(380px, calc(100vw - 1.5rem));
  max-height: min(54vh, 440px);
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  filter: blur(10px);
  transition:
    opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.55s ease;
  backdrop-filter: blur(8px);
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 0 0 rgba(34, 211, 238, 0);
}

#card.visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
  filter: blur(0);
  pointer-events: auto;
  box-shadow:
    0 0 40px rgba(34, 211, 238, 0.12),
    0 0 80px rgba(251, 191, 36, 0.08);
}

@media (prefers-reduced-motion: reduce) {
  #card {
    transition: opacity 0.15s ease;
    filter: none;
    transform: translateX(-50%);
  }

  #card.visible {
    transform: translateX(-50%);
    box-shadow: none;
  }
}

#card .summary {
  margin: 0.65rem 0 0.85rem;
  line-height: 1.5;
  font-size: 0.88rem;
  color: var(--text);
  overflow-wrap: anywhere;
}

#card .meta {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.verify-badge {
  display: inline-block;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: none;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid transparent;
  line-height: 1.3;
  max-width: 100%;
}

.verify-unproven {
  color: #fcd34d;
  border-color: rgba(252, 211, 77, 0.45);
  background: rgba(252, 211, 77, 0.12);
}

.verify-disputed {
  color: #fb923c;
  border-color: rgba(251, 146, 60, 0.45);
  background: rgba(251, 146, 60, 0.12);
}

.verify-conflict {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.12);
}

.verify-note {
  font-size: 0.78rem;
  color: #fde68a;
  border-left: 3px solid rgba(252, 211, 77, 0.55);
  padding: 0.35rem 0.55rem;
  margin: 0 0 0.65rem;
  background: rgba(252, 211, 77, 0.08);
  border-radius: 0 6px 6px 0;
}

#card h2 {
  margin: 0.35rem 0 0.5rem;
  font-size: 1.05rem;
}

#card p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #cbd5e1;
}

#card img.thumb {
  width: 100%;
  border-radius: 8px;
  margin-top: 0.75rem;
}

#card a.watch {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--strand-a);
  font-size: 0.85rem;
}

#card .embed-wrap {
  margin-top: 0.75rem;
  aspect-ratio: 16/9;
  display: none;
}

#card .embed-wrap.active {
  display: block;
}

#card .embed-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 8px;
}

#card .card-close {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

#card .card-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

#card .card-tabs button {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: var(--muted);
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  cursor: pointer;
}

#card .card-tabs button.active {
  border-color: var(--strand-a);
  color: var(--strand-a);
}

#card .tab-panel {
  display: none;
  margin-top: 0.65rem;
  font-size: 0.82rem;
}

#card .tab-panel.active:not([hidden]) {
  display: block;
}

#card .card-tabs:not([hidden]) {
  margin-top: 0.65rem;
}

#card .muted,
#card .music-stats {
  color: var(--muted);
  font-size: 0.78rem;
}

#card .detail-list {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
}

#card .detail-list a,
#card .link-moment {
  color: var(--strand-a);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}

#card .comment-author {
  color: var(--accent);
}

#card .frame-cap {
  font-size: 0.78rem;
  color: var(--muted);
  border-left: 2px solid var(--strand-b);
  padding-left: 0.5rem;
  margin: 0.35rem 0;
}

#fallback-list {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  padding: 5rem 1.5rem 2rem;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

#fallback-list h2 {
  margin-top: 0;
}

#fallback-list .item {
  border-left: 3px solid var(--strand-a);
  padding-left: 1rem;
  margin-bottom: 1.25rem;
}

#fallback-list .year {
  color: var(--accent);
  font-weight: 600;
}

body.no-webgl #canvas-host,
body.no-webgl #key-rail,
body.no-webgl #controls,
body.no-webgl #stats-panel {
  display: none !important;
}

body.no-webgl #fallback-list {
  display: block;
}

@media (max-width: 640px) {
  header {
    padding-right: 5.5rem;
  }

  .view-toggle {
    top: 0.75rem;
    bottom: auto;
    right: 0.65rem;
  }

  #controls {
    bottom: calc(var(--key-rail-h) + 2.65rem);
    left: 0.5rem;
    right: 0.5rem;
    gap: 0.4rem;
  }

  .controls-row {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
  }

  #dev-tools-bar {
    left: 0.5rem;
    right: 0.5rem;
    max-width: none;
    bottom: calc(var(--key-rail-h) + 0.25rem);
  }

  #stats-panel {
    bottom: calc(var(--key-rail-h) + 5rem);
    max-width: 52vw;
    font-size: 0.62rem;
  }

  #year-display {
    top: 38%;
    font-size: clamp(2.5rem, 18vw, 4rem);
  }

  #card {
    bottom: calc(var(--key-rail-h) + 4.25rem);
    max-height: 38vh;
  }

  #key-rail {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  .key-end {
    font-size: 0.62rem;
    min-width: 1.75rem;
  }
}
