:root {
  --bg: #000000;
  --glass: rgba(12, 14, 20, 0.56);
  --glass-strong: rgba(12, 14, 20, 0.78);
  --line: rgba(255, 255, 255, 0.075);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #eceef3;
  --muted: #8d93a3;
  --faint: #5a5f6e;
  --accent: #ffb347;
  --panel-w: 372px;
  --radius: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.muted { color: var(--muted); }

/* ---------- Glass surfaces ---------- */
.dock, .toolbar, .panel, .bodies-nav .chip, .hint {
  background: var(--glass);
  border: 1px solid var(--line);
}
@media (hover: hover) and (pointer: fine) {
  .dock, .toolbar, .panel, .hint {
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
  }
}
@media (pointer: coarse) {
  .dock, .toolbar, .panel { background: var(--glass-strong); }
}

/* ---------- Brand ---------- */
.brand {
  position: fixed;
  top: calc(20px + var(--safe-t));
  left: 24px;
  z-index: 5;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 1.2s var(--ease) 0.4s, transform 1.2s var(--ease) 0.4s;
}
.ready .brand { opacity: 1; transform: none; }
.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff6d8 0%, #ffb347 55%, #ff7a18 100%);
  box-shadow: 0 0 12px 2px rgba(255, 170, 70, 0.55);
}
.brand-date {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: fixed;
  top: calc(16px + var(--safe-t));
  right: 16px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 14px;
  opacity: 0;
  transition: opacity 1s var(--ease) 0.6s;
}
.ready .toolbar { opacity: 1; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  flex: none;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: currentColor;
}
.icon-btn svg path[fill="none"], .icon-btn svg [fill="none"] { fill: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn.is-on { color: var(--text); }
.icon-btn:focus-visible, .text-btn:focus-visible, .seg-btn:focus-visible, .chip:focus-visible, .label:focus-visible {
  outline: 1.5px solid rgba(255, 255, 255, 0.5);
  outline-offset: 1px;
}

.seg {
  display: flex;
  padding: 2px;
  margin-right: 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.25s, color 0.25s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: rgba(255, 255, 255, 0.1); color: var(--text); }

.fps {
  position: fixed;
  top: calc(66px + var(--safe-t));
  right: 22px;
  z-index: 5;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--faint);
  cursor: pointer;
  user-select: none;
}
.fps.is-hidden { display: none; }

/* ---------- Labels ---------- */
.labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(236, 238, 243, 0.72);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  will-change: transform, opacity;
  transition: color 0.2s, background 0.2s, opacity 0.35s;
  user-select: none;
}
.label .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
.label:hover, .label.is-hover { color: #fff; background: rgba(255, 255, 255, 0.07); }
.label.is-hidden { opacity: 0; pointer-events: none; }
.labels.is-off .label { opacity: 0; pointer-events: none; }

/* ---------- Bodies nav ---------- */
.bodies-nav {
  position: fixed;
  left: 50%;
  bottom: calc(92px + var(--safe-b));
  z-index: 4;
  display: flex;
  gap: 6px;
  max-width: min(920px, calc(100vw - 32px));
  padding: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 1s var(--ease) 0.8s, transform 0.7s var(--ease);
}
.bodies-nav::-webkit-scrollbar { display: none; }
.ready .bodies-nav { opacity: 1; }

.chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px 7px 10px;
  border-radius: 999px;
  background: rgba(12, 14, 20, 0.42);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
}
.chip:hover { color: var(--text); background: rgba(24, 27, 36, 0.7); }
.chip.is-active { color: #fff; border-color: var(--line-2); background: rgba(34, 38, 50, 0.72); }
.chip.is-active .dot { box-shadow: 0 0 10px var(--accent); opacity: 1; }

/* ---------- Dock ---------- */
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(600px, calc(100vw - 32px));
  padding: 8px 10px 8px 8px;
  border-radius: 18px;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 1s var(--ease) 0.7s, transform 0.7s var(--ease);
}
.ready .dock { opacity: 1; }

.icon-btn--primary { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.icon-btn--primary:hover { background: rgba(255, 255, 255, 0.14); }
#btn-play .i-play { display: none; }
#btn-play.is-paused .i-play { display: block; }
#btn-play.is-paused .i-pause { display: none; }
#btn-reverse[aria-pressed="true"] { color: var(--accent); }

.speed { flex: 1; min-width: 0; padding: 0 6px; }
.speed input {
  --p: 50%;
  width: 100%;
  height: 22px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
.speed input::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.75) var(--p), rgba(255, 255, 255, 0.13) var(--p));
}
.speed input::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.75) var(--p), rgba(255, 255, 255, 0.13) var(--p));
}
.speed input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08), 0 0 14px rgba(255, 255, 255, 0.35);
  transition: box-shadow 0.2s;
}
.speed input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08), 0 0 14px rgba(255, 255, 255, 0.35);
}
.speed input:active::-webkit-slider-thumb { box-shadow: 0 0 0 7px rgba(255, 255, 255, 0.1), 0 0 18px rgba(255, 255, 255, 0.5); }
.speed-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 1px;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: var(--faint);
  user-select: none;
}
.speed-label {
  min-width: 86px;
  text-align: right;
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.text-btn {
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 11px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  flex: none;
}
.text-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

/* ---------- Info panel ---------- */
.panel {
  --accent: #ffb347;
  position: fixed;
  top: calc(16px + var(--safe-t));
  right: 16px;
  bottom: 16px;
  z-index: 8;
  width: var(--panel-w);
  border-radius: 20px;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateX(28px);
  transition: opacity 0.5s var(--ease), transform 0.6s var(--ease), visibility 0s linear 0.6s;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.5s var(--ease) 0.15s, transform 0.7s var(--ease) 0.15s, visibility 0s;
}
.panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 180px;
  background: radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%);
  opacity: 0.55;
  pointer-events: none;
}
.panel-grip { display: none; }
.panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.panel-close svg { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.panel-close:hover { background: rgba(255, 255, 255, 0.12); color: var(--text); }

.panel-body {
  position: relative;
  height: 100%;
  overflow-y: auto;
  padding: 30px 28px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.panel-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-kicker .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.panel-title {
  margin: 12px 0 4px;
  font-size: 40px;
  font-weight: 300;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.panel-sub {
  font-size: 12.5px;
  color: var(--muted);
}
.panel-desc {
  margin: 18px 0 22px;
  font-size: 13.5px;
  line-height: 1.62;
  color: rgba(236, 238, 243, 0.82);
  font-weight: 400;
}
.panel-section {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}
.live {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-bottom: 22px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--line);
  border: 1px solid var(--line);
}
.live-item { padding: 12px 10px; background: rgba(10, 12, 17, 0.55); }
.live-item .v {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.live-item .u { font-size: 11px; color: var(--muted); margin-left: 3px; font-weight: 400; }
.live-item .k { margin-top: 4px; font-size: 10.5px; color: var(--muted); line-height: 1.3; }
.live-item .s { margin-top: 2px; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 18px;
  margin: 0;
}
.fact {
  padding: 11px 0;
  border-top: 1px solid var(--line);
  opacity: 0;
  transform: translateY(6px);
  animation: fact-in 0.6s var(--ease) forwards;
}
.fact dt { font-size: 10.5px; color: var(--muted); letter-spacing: 0.02em; }
.fact dd { margin: 3px 0 0; font-size: 13.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
@keyframes fact-in { to { opacity: 1; transform: none; } }

.panel-note {
  margin: 18px 0 0;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--faint);
}
.panel-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.panel-nav button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 0;
  background: transparent;
  padding: 4px 0;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.2s;
}
.panel-nav button span { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); font-weight: 600; }
.panel-nav button:last-child { text-align: right; align-items: flex-end; }
.panel-nav button:hover { opacity: 0.7; }

/* Desktop: shift bottom controls away from the panel */
@media (min-width: 900px) {
  body.panel-open .dock,
  body.panel-open .bodies-nav { transform: translateX(calc(-50% - var(--panel-w) / 2 - 8px)); }
  body.panel-open .dock { width: min(600px, calc(100vw - var(--panel-w) - 64px)); }
  body.panel-open .bodies-nav { max-width: calc(100vw - var(--panel-w) - 64px); }
}

/* ---------- Hint ---------- */
.hint {
  position: fixed;
  left: 50%;
  top: calc(22px + var(--safe-t));
  z-index: 4;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  transform: translate(-50%, -8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
}
.hint.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Loading veil ---------- */
.veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #000;
  transition: opacity 1.4s var(--ease), visibility 0s linear 1.4s;
}
.veil.is-gone { opacity: 0; visibility: hidden; }
.veil-inner { display: grid; justify-items: center; gap: 18px; }
.veil p {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--faint);
}
.veil-orbit {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: spin 1.6s linear infinite;
}
.veil-orbit::before {
  content: "";
  position: absolute;
  inset: 17px;
  border-radius: 50%;
  background: #ffb347;
  box-shadow: 0 0 14px #ffb347;
}
.veil-orbit span {
  position: absolute;
  top: -3px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: #cfe3ff;
}
@keyframes spin { to { transform: rotate(360deg); } }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); }

.webgl-error {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: #000;
  line-height: 1.6;
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .brand { left: 16px; top: calc(14px + var(--safe-t)); }
  .brand-mark { font-size: 12px; }
  .brand-date { font-size: 11.5px; flex-direction: column; gap: 2px; margin-top: 6px; }
  .toolbar { top: calc(10px + var(--safe-t)); right: 10px; padding: 3px; }
  .icon-btn { width: 34px; height: 34px; }
  .seg-btn { padding: 7px 8px; font-size: 11px; }
  #btn-fullscreen { display: none; }
  .fps { top: calc(56px + var(--safe-t)); right: 16px; }

  .dock {
    bottom: calc(10px + var(--safe-b));
    width: calc(100vw - 20px);
    padding: 6px 8px 6px 6px;
    gap: 4px;
  }
  .speed-scale { display: none; }
  .speed-label { min-width: 70px; font-size: 12px; }
  .text-btn { padding: 7px 9px; }
  .bodies-nav {
    bottom: calc(72px + var(--safe-b));
    max-width: 100vw;
    width: 100vw;
    padding: 2px 10px;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
  }
  .bodies-nav { justify-content: flex-start; }
  .chip { padding: 7px 11px 7px 9px; font-size: 11.5px; }

  .hint {
    top: auto;
    bottom: calc(126px + var(--safe-b));
    width: max-content;
    max-width: calc(100vw - 40px);
    white-space: normal;
    text-align: center;
    line-height: 1.5;
    border-radius: 14px;
    font-size: 11.5px;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 56vh;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    transform: translateY(40px);
  }
  .panel.is-open { transform: translateY(var(--drag, 0px)); }
  .panel.is-dragging { transition: none; }
  .panel-grip {
    display: block;
    position: absolute;
    top: 8px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.18);
    z-index: 2;
  }
  .panel-body {
    max-height: 56vh;
    padding: 26px 20px calc(20px + var(--safe-b));
  }
  .panel-title { font-size: 32px; margin-top: 10px; }
  .panel-desc { margin: 14px 0 18px; font-size: 13px; }
  body.panel-open .dock,
  body.panel-open .bodies-nav { opacity: 0; pointer-events: none; }
}

@media (max-width: 380px) {
  .seg { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
