/* ============================================================================
   Universe Simulator — interface styling
   Dark by default; a light variant is applied under prefers-color-scheme: light.
   ========================================================================= */

:root {
  --bg:            #04060c;
  --ink:           #e9f0fa;
  --ink-soft:      #c3d2e6;
  --ink-dim:       #91a5c0;
  --line:          rgba(150, 180, 215, 0.16);
  --line-strong:   rgba(150, 180, 215, 0.30);
  --panel:         rgba(9, 14, 24, 0.66);
  --panel-solid:   rgba(9, 14, 24, 0.94);
  --raised:        rgba(255, 255, 255, 0.055);
  --raised-hover:  rgba(255, 255, 255, 0.10);
  --accent:        #6fd6ff;
  --accent-warm:   #ffbe6f;
  --accent-ink:    #04222e;
  --track:         rgba(150, 180, 215, 0.20);
  --shadow:        0 24px 70px rgba(0, 0, 0, 0.55);
  --radius:        16px;
  --radius-sm:     10px;
  --blur:          saturate(150%) blur(22px);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* Light variant. The 3D scene itself stays dark — it is space — so only the
   interface chrome switches to a frosted light surface. */
@media (prefers-color-scheme: light) {
  :root {
    --bg:            #0a0f1a;
    --ink:           #0e1a2b;
    --ink-soft:      #24344c;
    --ink-dim:       #4d6178;
    --line:          rgba(12, 30, 56, 0.16);
    --line-strong:   rgba(12, 30, 56, 0.30);
    --panel:         rgba(238, 244, 252, 0.86);
    --panel-solid:   rgba(244, 248, 254, 0.97);
    --raised:        rgba(12, 26, 48, 0.06);
    --raised-hover:  rgba(12, 26, 48, 0.11);
    --accent:        #0b7ea8;
    --accent-warm:   #b4620d;
    --accent-ink:    #ffffff;
    --track:         rgba(12, 26, 48, 0.16);
    --shadow:        0 24px 70px rgba(0, 0, 0, 0.45);
    color-scheme: light;
  }
  .label { background: rgba(244, 248, 254, 0.72); color: var(--ink-soft); }
  .boot { background: radial-gradient(ellipse at center, #0a0f1a 0%, #05080f 70%); }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

#stage { position: fixed; inset: 0; }

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  cursor: grab;
}
#view:active { cursor: grabbing; }
#view:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

/* ------------------------------------------------------------------ labels */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(4, 7, 14, 0.55);
  backdrop-filter: blur(6px);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  will-change: transform;
}
.label.is-active { border-color: var(--accent); color: var(--ink); }
.label.is-hidden { display: none; }

/* --------------------------------------------------------------------- hud */
.hud {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
body[data-hud="off"] .hud { opacity: 0; transform: scale(0.985); pointer-events: none; }

.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(336px, 44vw);
  max-height: calc(100vh - 190px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  pointer-events: none;
}
.col::-webkit-scrollbar { width: 8px; }
.col::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }
.col::-webkit-scrollbar-track { background: transparent; }
.col-right { align-items: stretch; }

.card {
  pointer-events: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
  padding: 16px;
}

h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.012em; }
h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  margin-bottom: 12px;
}

.card-brand h1 {
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: -0.028em;
}
.card-brand h1 span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 6px;
}
.sub { margin: 10px 0 0; font-size: 13px; color: var(--ink-dim); line-height: 1.55; }
.hint { margin: 8px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--ink-dim); }

/* ------------------------------------------------------------------- stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0 0;
}
.stats > div {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--raised);
  padding: 8px 10px;
  min-width: 0;
}
.stats dt {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.stats dd {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ----------------------------------------------------------------- buttons */
.btn, .toggle, .chip, .body-btn, .hud-toggle {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  background: var(--raised);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, color 140ms ease;
}
.btn:hover, .toggle:hover, .chip:hover, .body-btn:hover, .hud-toggle:hover {
  background: var(--raised-hover);
  border-color: var(--accent);
}
.btn:active, .toggle:active, .chip:active, .body-btn:active { transform: translateY(1px); }
.btn:focus-visible, .toggle:focus-visible, .chip:focus-visible,
.body-btn:focus-visible, .hud-toggle:focus-visible, .seg label:focus-within span,
input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.transport { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.btn .glyph { font-size: 10px; color: var(--accent); line-height: 1; }
.btn-primary {
  background: linear-gradient(180deg, rgba(111, 214, 255, 0.22), rgba(111, 214, 255, 0.10));
  border-color: rgba(111, 214, 255, 0.45);
}
.btn-primary .glyph { color: var(--accent); }
.btn[aria-pressed="true"].btn-ghost { background: var(--raised-hover); }

/* ------------------------------------------------------------------ slider */
.field { margin-top: 14px; }
.field label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.field output {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 8px 0 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(90deg,
    var(--accent) 0 var(--fill, 50%), var(--track) var(--fill, 50%) 100%);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--ink);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--accent); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); border: 3px solid var(--accent);
}

/* ------------------------------------------------------------------- chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  color: var(--ink-soft);
}
.chip.is-active { border-color: var(--accent); background: var(--raised-hover); color: var(--ink); }

/* ----------------------------------------------------------------- toggles */
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.toggle {
  padding: 8px 10px;
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  color: var(--ink-dim);
  display: flex;
  align-items: center;
  gap: 7px;
}
.toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--track);
  flex: none;
  transition: background 140ms ease, box-shadow 140ms ease;
}
.toggle.is-on { color: var(--ink); border-color: var(--line-strong); }
.toggle.is-on::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

/* --------------------------------------------------------------- segmented */
.seg { border: 0; margin: 14px 0 0; padding: 0; }
.seg legend {
  padding: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.seg-track {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 7px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--raised);
}
.seg label { position: relative; display: block; }
.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.seg span {
  display: block;
  padding: 6px 4px;
  border-radius: 7px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--ink-dim);
  transition: background 140ms ease, color 140ms ease;
}
.seg input:checked + span {
  background: linear-gradient(180deg, rgba(111, 214, 255, 0.26), rgba(111, 214, 255, 0.12));
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(111, 214, 255, 0.4);
}
@media (prefers-color-scheme: light) {
  .seg input:checked + span {
    background: linear-gradient(180deg, rgba(11, 126, 168, 0.20), rgba(11, 126, 168, 0.08));
    box-shadow: inset 0 0 0 1px rgba(11, 126, 168, 0.4);
  }
}

/* ------------------------------------------------------------------ bodies */
.bodies { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.body-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  min-width: 0;
  color: var(--ink-soft);
}
.body-btn .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18) inset;
}
.body-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.body-btn.is-active {
  border-color: var(--accent);
  background: var(--raised-hover);
  color: var(--ink);
}
.body-btn .key {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--ink-dim);
}

/* -------------------------------------------------------------------- info */
.body-name { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: -0.015em; }
.body-desc { margin: 4px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-dim); }
.facts { margin: 12px 0 0; display: grid; gap: 1px; border-radius: var(--radius-sm); overflow: hidden; }
.facts > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  background: var(--raised);
}
.facts dt { font-size: 11px; color: var(--ink-dim); }
.facts dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  text-align: right;
}

/* ------------------------------------------------------- hud toggle + legend */
.hud-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 650;
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: var(--raised);
  color: var(--ink-dim);
}

.legend {
  position: fixed;
  left: 16px;
  bottom: 16px;
  right: 172px;
  max-width: 640px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
  padding: 11px 14px;
  transition: opacity 220ms ease;
}
body[data-hud="off"] .legend { opacity: 0; pointer-events: none; }
.legend-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 11.5px;
  color: var(--ink-dim);
}
.legend-keys span { display: inline-flex; align-items: center; gap: 4px; }
.legend-note {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-dim);
  opacity: 0.85;
}

/* -------------------------------------------------------------------- boot */
.boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #070b16 0%, #02040a 70%);
  transition: opacity 500ms ease;
}
.boot.is-done { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
.boot-ring {
  width: 46px;
  height: 46px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 2px solid rgba(111, 214, 255, 0.18);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink);
}
.boot-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-dim); }

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  text-align: center;
  font-size: 13px;
}

/* ------------------------------------------------------------------ utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ----------------------------------------------------------------- responsive */
@media (max-width: 1080px) {
  .col { width: min(300px, 46vw); }
  .legend { right: 16px; max-width: none; }
  .hud-toggle { bottom: auto; top: 16px; right: 16px; }
}

@media (max-width: 860px) {
  .hud {
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    max-height: 62vh;
    pointer-events: auto;
    padding: 12px;
    gap: 12px;
  }
  .col { width: 100%; max-height: none; overflow: visible; }
  .card { padding: 14px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .legend { display: none; }
  .hud-toggle { top: 12px; right: 12px; }
  .btn, .toggle, .chip, .body-btn { min-height: 40px; }
}
@media (max-width: 860px) and (orientation: landscape) {
  .hud { max-height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .boot-ring { animation: none; border-top-color: var(--accent); opacity: 0.6; }
}
