:root {
  color-scheme: dark;
  --bg: #05070f;
  --panel: rgba(10, 14, 26, .96);
  --line: rgba(226, 232, 240, .14);
  --text: #f8fafc;
  --muted: #94a3b8;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background: radial-gradient(circle at 50% 45%, #0a0e1a 0, var(--bg) 52%);
  color: var(--text);
  font-family: -apple-system, "Segoe UI Variable Display", "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 13px;
}

button, input, select { font: inherit; }
button, select { color: var(--text); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #a78bfa; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

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

#galaxy.dragging { cursor: grabbing; }

.topbar {
  position: fixed;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 22px 0;
  pointer-events: none;
}

.brand, .controls { display: flex; align-items: center; gap: 8px; }
.brand { font-size: 15px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.brand-mark { width: 8px; height: 8px; border: 1px solid #a78bfa; border-radius: 50%; box-shadow: 0 0 0 4px rgba(167,139,250,.12); }

.controls { pointer-events: auto; }

#zoom-level {
  min-width: 102px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-align: right;
  text-transform: uppercase;
}

#lang-toggle, .control-button, #trail-select {
  min-width: 42px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(5,7,15,.72);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

#trail-select { max-width: 160px; font-weight: 400; }
.control-button.active { border-color: #e2e8f0; background: rgba(226,232,240,.14); }
.search-box { position: relative; }
#search { width: 210px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: rgba(5,7,15,.78); color: var(--text); }
#search::placeholder { color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 7px); right: 0; width: min(340px, 80vw); padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: 0 14px 35px rgba(0,0,0,.38); }
.search-results button, .search-empty { display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 7px; background: none; color: var(--text); text-align: left; }
.search-results button:hover, .search-results button:focus-visible { background: rgba(148,163,184,.12); }
.search-empty { color: var(--muted); }

.hint {
  position: fixed;
  z-index: 1;
  bottom: 18px;
  left: 22px;
  color: rgba(148,163,184,.65);
  font-size: 11px;
  pointer-events: none;
}

.filters {
  position: fixed;
  z-index: 4;
  top: 0;
  left: 0;
  width: min(330px, 92vw);
  height: 100%;
  padding: 68px 24px 28px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 20px 0 50px rgba(0,0,0,.3);
  overflow: auto;
  transform: translateX(-102%);
  transition: transform 220ms ease;
}
.filters.open { transform: translateX(0); }
.filters h2 { margin: 0 0 26px; font-size: 20px; font-weight: 600; }
.filters h3 { margin: 24px 0 10px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.panel-close { position: absolute; top: 18px; right: 20px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 28px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.preset-grid button, .data-buttons button, .wide-button { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(148,163,184,.06); cursor: pointer; }
.cluster-filters { display: grid; gap: 5px; }
.cluster-filters label { display: flex; align-items: center; gap: 9px; min-height: 28px; cursor: pointer; }
.cluster-filters input { accent-color: #a78bfa; }
.cluster-filters span::before { display: inline-block; width: 7px; height: 7px; margin-right: 8px; border-radius: 50%; background: var(--cluster); content: ''; }
.data-buttons { display: flex; gap: 7px; }
.data-status { min-height: 18px; color: var(--muted); font-size: 11px; }

.card {
  position: fixed;
  z-index: 3;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100%;
  padding: 72px 34px 34px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: -20px 0 50px rgba(0,0,0,.3);
  transform: translateX(102%);
  transition: transform 260ms ease;
  overflow: auto;
}

.card.open { transform: translateX(0); }
.card-close { position: absolute; top: 20px; right: 22px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 28px; line-height: 1; }
.eyebrow { color: var(--cluster, #a78bfa); font-size: 11px; font-weight: 600; letter-spacing: .13em; text-transform: uppercase; }
.card h1 { margin: 14px 0 6px; font-size: 28px; font-weight: 600; line-height: 1.08; }
.card-full { margin: 0; color: var(--muted); font-size: 13px; }
.card-def { margin: 30px 0; font-size: 20px; line-height: 1.45; }
.card-meta { display: flex; justify-content: space-between; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); }
.card-meta strong { color: var(--text); font-weight: 600; }
.card-label { display: block; margin: 26px 0 8px; color: var(--muted); }
#progress-select { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #0a0e1a; }
.wide-button { width: 100%; margin-top: 10px; }

.chain-rail {
  position: fixed;
  z-index: 2;
  left: 50%;
  bottom: 22px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 38px;
  align-items: center;
  width: min(920px, calc(100% - 44px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(5,7,15,.9);
  box-shadow: 0 12px 36px rgba(0,0,0,.35);
  transform: translateX(-50%);
}
.chain-rail[hidden] { display: none; }
.chain-rail > button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: rgba(148,163,184,.07); cursor: pointer; font-size: 24px; line-height: 1; }
.chain-rail > button:disabled { opacity: .25; cursor: default; }
.chain-steps { position: relative; display: flex; align-items: flex-start; gap: 20px; padding: 0 10px; overflow-x: auto; scrollbar-width: thin; }
.chain-steps::before { position: absolute; top: 14px; left: 20px; right: 20px; height: 2px; background: rgba(226,232,240,.2); content: ''; }
.chain-step { position: relative; display: grid; justify-items: center; flex: 0 0 92px; gap: 5px; padding: 0; border: 0; background: none; cursor: pointer; }
.step-number { display: grid; place-items: center; width: 30px; height: 30px; border: 2px solid var(--cluster); border-radius: 50%; background: #05070f; color: var(--text); font-size: 11px; font-weight: 600; }
.chain-step.current .step-number { background: var(--cluster); color: #05070f; }
.step-name { max-width: 92px; color: var(--muted); font-size: 11px; line-height: 1.2; text-align: center; }
.chain-step.current .step-name { color: var(--text); }

@media (max-width: 600px) {
  .topbar { display: block; padding: max(14px, env(safe-area-inset-top)) 14px 0; }
  .brand { font-size: 13px; }
  .controls { margin-top: 11px; padding: 2px 2px 8px; overflow-x: auto; }
  #search { width: 150px; }
  #trail-select { max-width: 130px; }
  .control-button { white-space: nowrap; }
  #zoom-level { display: none; }
  .hint { display: none; }
  .filters { top: auto; bottom: 0; width: 100%; height: min(78%, 620px); padding: 52px 20px max(24px, env(safe-area-inset-bottom)); border: 1px solid var(--line); border-width: 1px 0 0; border-radius: 18px 18px 0 0; transform: translateY(102%); }
  .filters.open { transform: translateY(0); }
  .card {
    top: auto;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 68%;
    padding: 42px 24px max(26px, env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    transform: translateY(102%);
  }
  .card.with-rail { bottom: 78px; max-height: 55%; }
  .card.open { transform: translateY(0); }
  .card-close { top: 13px; right: 18px; }
  .chain-rail { left: 0; right: 0; bottom: 0; width: 100%; min-height: 78px; padding: 8px; border-width: 1px 0 0; border-radius: 0; transform: none; }
  .chain-steps { gap: 10px; }
  .chain-step { flex-basis: 74px; }
  .step-name { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .filters { transition: none; }
}
