/* Universe Simulator — HUD and layout styles */

:root {
  --bg: #04050a;
  --panel: rgba(10, 13, 22, 0.62);
  --panel-strong: rgba(8, 11, 19, 0.86);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --ink: #f2efe6;
  --ink-dim: rgba(242, 239, 230, 0.62);
  --ink-faint: rgba(242, 239, 230, 0.38);
  --accent: #8a93ff;
  --accent-deep: #5b64d8;
  --accent-soft: rgba(138, 147, 255, 0.16);
  --warm: #ffb46b;
  --good: #7fd8a4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Keep semantic hiding authoritative even against explicit display rules */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
}
#stage canvas { display: block; }

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.body-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-200vw, -200vh); /* off-screen until first frame */
  pointer-events: auto;
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(242, 239, 230, 0.78);
  background: rgba(8, 11, 19, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
  will-change: transform;
  user-select: none;
}
.body-label:hover,
.body-label:focus-visible {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(8, 11, 19, 0.75);
}
.body-label.selected {
  color: #eef0ff;
  background: var(--accent-soft);
  border-color: rgba(138, 147, 255, 0.55);
}

/* ---------- shared panel chrome ---------- */

.hud {
  position: fixed;
  z-index: 5;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel { background: var(--panel-strong); }
}

.panel-title {
  margin: 14px 16px 8px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

button {
  font-family: inherit;
  color: inherit;
}
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}
.chip:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}
.chip[aria-pressed="true"],
.toggle-on {
  color: #eef0ff;
  background: var(--accent-soft);
  border-color: rgba(138, 147, 255, 0.55);
}

/* ---------- title panel ---------- */

#hud-title {
  top: 20px;
  left: 20px;
  max-width: 330px;
  padding: 16px 20px 14px;
}
.eyebrow {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
}
#hud-title h1 {
  margin: 0;
  font-size: clamp(19px, 2.4vw, 24px);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.lede {
  margin: 7px 0 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-dim);
}
.status-line {
  margin: 11px 0 0;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 8px rgba(127, 216, 164, 0.8);
}
.status-dot.paused { background: var(--warm); box-shadow: 0 0 8px rgba(255, 180, 107, 0.8); }

/* ---------- bodies / options panel ---------- */

#hud-bodies {
  top: 20px;
  right: 20px;
  width: 228px;
  padding-bottom: 14px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

#body-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}
.body-btn {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 13px;
  color: var(--ink-dim);
  cursor: pointer;
  transition: background-color 130ms ease, color 130ms ease;
}
.body-btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--ink); }
.body-btn.selected {
  background: var(--accent-soft);
  color: #eef0ff;
}
.body-btn .swatch {
  width: 11px; height: 11px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset -1px -2px 3px rgba(0, 0, 0, 0.55), 0 0 6px rgba(255, 255, 255, 0.06);
}
.body-btn .dist {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--ink-faint);
  font-feature-settings: "tnum" 1;
}
.body-btn.sub { padding-left: 28px; font-size: 12px; }

/* ---------- info card ---------- */

#hud-info {
  left: 20px;
  bottom: 108px;
  width: 272px;
  padding: 15px 18px 16px;
}
.close-btn { position: absolute; top: 9px; right: 9px; }
.info-kicker {
  margin: 0 0 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}
#info-name {
  margin: 0 0 10px;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.facts {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  font-size: 12px;
}
.facts dt { color: var(--ink-faint); }
.facts dd {
  margin: 0;
  text-align: right;
  font-feature-settings: "tnum" 1;
  color: var(--ink);
}
.info-note {
  margin: 11px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-dim);
}

/* ---------- playback dock ---------- */

#hud-playback {
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  padding: 13px 18px 14px;
}
.date-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.date-caption {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.sim-date {
  font-size: clamp(15px, 2.6vw, 18px);
  font-weight: 600;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0.01em;
}
.rate {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--accent);
  font-feature-settings: "tnum" 1;
  letter-spacing: 0.03em;
}
.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ctl-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  cursor: pointer;
  transition: background-color 130ms ease, border-color 130ms ease;
}
.ctl-btn:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }
.ctl-btn.primary {
  width: 42px; height: 42px;
  background: var(--accent-deep);
  border-color: rgba(138, 147, 255, 0.7);
  color: #fff;
}
.ctl-btn.primary:hover { background: #6670e0; }
.ctl-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: rgba(138, 147, 255, 0.55);
  color: #eef0ff;
}

#rate-slider {
  flex: 1;
  min-width: 120px;
  height: 28px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
#rate-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent-deep), var(--accent));
  opacity: 0.85;
}
#rate-slider::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent-deep), var(--accent));
  opacity: 0.85;
}
#rate-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--accent-deep);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
#rate-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--accent-deep);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.preset-row {
  display: flex;
  gap: 5px;
}
.preset { padding: 4px 9px; font-size: 10.5px; }

/* ---------- hint ---------- */

.hint {
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: rgba(4, 5, 10, 0.35);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- fallback ---------- */

#webgl-fallback {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
  background: radial-gradient(ellipse at 50% 30%, #10131f 0%, #04050a 70%);
}
.fallback-card {
  max-width: 420px;
  padding: 28px 30px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.fallback-card h1 { margin: 0 0 10px; font-size: 22px; }
.fallback-card p { margin: 0 0 10px; font-size: 13px; line-height: 1.6; color: var(--ink-dim); }

/* ---------- light scheme adjustments ---------- */

@media (prefers-color-scheme: light) {
  :root {
    --panel: rgba(240, 240, 246, 0.72);
    --panel-strong: rgba(244, 244, 248, 0.92);
    --line: rgba(10, 14, 25, 0.14);
    --line-strong: rgba(10, 14, 25, 0.28);
    --ink: #171a24;
    --ink-dim: rgba(23, 26, 36, 0.68);
    --ink-faint: rgba(23, 26, 36, 0.45);
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
    color-scheme: light;
  }
  .chip { background: rgba(12, 16, 30, 0.05); }
  .body-label {
    color: rgba(17, 20, 30, 0.82);
    background: rgba(246, 246, 250, 0.6);
    border-color: rgba(10, 14, 25, 0.12);
  }
  .body-label.selected {
    background: var(--accent-soft);
    color: #2a2f52;
    border-color: rgba(91, 100, 216, 0.6);
  }
  .hint { background: rgba(246, 246, 250, 0.5); }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .hint { display: none; }
  #hud-title { max-width: 280px; }
  .lede { display: none; }
}

@media (max-width: 700px) {
  #labels { z-index: 2; }
  #stage { z-index: 1; }

  #hud-title {
    top: 12px; left: 12px;
    right: auto;
    max-width: calc(100vw - 24px);
    padding: 11px 14px;
  }
  #hud-title h1 { font-size: 15px; }

  #hud-bodies {
    position: fixed;
    top: auto;
    bottom: 148px;
    right: 12px;
    width: 172px;
    padding-bottom: 8px;
    max-height: 34vh;
  }
  .panel-title:first-child { margin-top: 10px; }

  #hud-info {
    position: fixed;
    bottom: 148px;
    left: 12px;
    right: 12px;
    width: auto;
    z-index: 8;               /* layer over the bodies list as a bottom sheet */
    max-height: 38vh;
    overflow-y: auto;
    padding: 12px 14px;
  }

  #hud-playback {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: none;
    width: auto;
    padding: 10px 12px 12px;
  }
  .controls-row { flex-wrap: wrap; gap: 8px; }
  .preset-row { order: 5; }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .chip, .ctl-btn, .body-btn, .body-label, .icon-btn {
    transition: none;
  }
}
