/* Universe Simulator — HUD styling.
 *
 * One token set, two palettes. Layout is a 3-column grid that collapses to a
 * single column on narrow screens; every panel is real HTML, positioned over a
 * full-bleed canvas.
 */

/* ---------------------------------------------------------------- tokens */

:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 12px;

  --step: 160ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --bg: #04060d;
  --bg-veil: rgba(4, 6, 13, 0.86);
  --panel: rgba(13, 19, 33, 0.72);
  --panel-solid: #0d1321;
  --panel-border: rgba(148, 178, 226, 0.15);
  --sunken: rgba(6, 10, 20, 0.6);
  --raised: rgba(126, 168, 232, 0.13);
  --text: #e9eff9;
  --text-dim: #94a5c1;
  --text-faint: #6b7c9a;
  --accent: #f2b544;
  --accent-2: #6cb6ff;
  --accent-soft: rgba(242, 181, 68, 0.14);
  --accent-border: rgba(242, 181, 68, 0.4);
  --focus: #8ecbff;
  --shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.85), 0 2px 8px -4px rgba(0, 0, 0, 0.6);
  --label: #d9e4f5;
  --label-dim: #93a6c4;
  --label-shadow: 0 1px 3px rgba(0, 0, 0, 0.85), 0 0 12px rgba(0, 0, 0, 0.6);
}

[data-theme="light"] {
  --bg: #e8eef7;
  --bg-veil: rgba(232, 238, 247, 0.9);
  --panel: rgba(255, 255, 255, 0.84);
  --panel-solid: #ffffff;
  --panel-border: rgba(28, 48, 88, 0.14);
  --sunken: rgba(28, 48, 88, 0.07);
  --raised: rgba(28, 48, 88, 0.09);
  --text: #162033;
  --text-dim: #55647d;
  --text-faint: #7d8ba1;
  --accent: #b8651a;
  --accent-2: #1f5fa8;
  --accent-soft: rgba(184, 101, 26, 0.12);
  --accent-border: rgba(184, 101, 26, 0.36);
  --focus: #1f5fa8;
  --shadow: 0 14px 32px -20px rgba(22, 32, 51, 0.5), 0 2px 6px -3px rgba(22, 32, 51, 0.2);
  --label: #22304a;
  --label-dim: #5b6b86;
  --label-shadow: 0 1px 2px rgba(255, 255, 255, 0.9), 0 0 10px rgba(255, 255, 255, 0.75);
}

/* ---------------------------------------------------------------- reset */

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, p, dl, dd, figure { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- stage */

.stage__canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  z-index: 1;
}

.stage__canvas:active { cursor: grabbing; }

.label-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 2;
}

.label {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--label);
  white-space: nowrap;
  text-shadow: var(--label-shadow);
  will-change: transform;
}

.label::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 7px currentColor;
  flex: none;
}

.label__name { font-weight: 650; }

.label__meta {
  font-weight: 500;
  font-size: 10.5px;
  color: var(--label-dim);
  font-variant-numeric: tabular-nums;
}

.label.is-selected { color: var(--accent); font-size: 12.5px; }

.label--moon { font-size: 10.5px; color: var(--label-dim); }
.label--moon::before { width: 3px; height: 3px; }

/* ---------------------------------------------------------------- shell */

.hud {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(190px, 226px) minmax(0, 1fr) minmax(212px, 288px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: var(--gap);
  pointer-events: none;
  transition: opacity var(--step) var(--ease);
}

.hud > * { pointer-events: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  transition: opacity var(--step) var(--ease), transform var(--step) var(--ease),
    visibility var(--step);
}

/* Focus mode: clear the frame, keep the control bar reachable. */
.hud.is-hidden .panel:not(.topbar),
.hud.is-hidden .dock {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.hud.is-hidden .panel--info { transform: translateX(16px); }
.hud.is-hidden .panel--bodies { transform: translateX(-16px); }
.hud.is-hidden .dock { transform: translateY(16px); }

/* ---------------------------------------------------------------- topbar */

.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 9px 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  position: relative;
  width: 26px;
  height: 26px;
  flex: none;
}

.brand__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.55;
}

.brand__core {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff4d0, var(--accent) 62%, #d97706);
  box-shadow: 0 0 14px rgba(242, 181, 68, 0.65);
}

.brand__text { display: flex; flex-direction: column; min-width: 0; }

.brand__text strong {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand__sub {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.clock {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-end;
  min-width: 0;
}

.clock__value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.clock__note {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.field { display: flex; flex-direction: column; gap: 4px; }

.fps {
  font-family: var(--font-mono);
  color: var(--text-dim);
  padding-bottom: 6px;
  min-width: 52px;
  text-align: right;
}

/* ---------------------------------------------------------------- bits */

.micro {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.085em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.tag {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: var(--sunken);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 4px;
  color: var(--text-dim);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- panels */

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 8px;
}

.panel__title { font-size: 13px; font-weight: 650; letter-spacing: -0.005em; }

.panel__hint { color: var(--text-faint); }

.panel__foot {
  padding: 8px 14px 12px;
  font-size: 11px;
  color: var(--text-dim);
  border-top: 1px solid var(--panel-border);
}

.panel--bodies {
  grid-column: 1;
  grid-row: 2;
  align-self: start;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

.panel--info {
  grid-column: 3;
  grid-row: 2;
  align-self: start;
  max-height: 100%;
  overflow-y: auto;
}

.panel__actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
}

/* ---------------------------------------------------------------- bodies */

.body-list {
  padding: 2px 8px 8px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.body-list__group {
  padding: 9px 6px 3px;
}

.body-btn {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: background var(--step) var(--ease), border-color var(--step) var(--ease);
}

.body-btn:hover { background: var(--raised); }

.body-btn[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.body-btn__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 550;
}

.body-btn__meta {
  font-size: 10.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.body-btn--moon { padding-left: 20px; }
.body-btn--moon .dot { width: 6px; height: 6px; }
.body-btn--moon .body-btn__name { font-weight: 500; color: var(--text-dim); }

/* ---------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 10px;
  padding: 2px 14px 10px;
}

.stats dt {
  font-size: 11.5px;
  color: var(--text-dim);
  align-self: baseline;
}

.stats dd {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: 550;
  white-space: nowrap;
}

.blurb {
  padding: 0 14px 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--sunken);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  transition: background var(--step) var(--ease), border-color var(--step) var(--ease),
    transform var(--step) var(--ease);
}

.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.btn--icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.btn--play { width: 40px; height: 40px; }

.btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.icon {
  position: relative;
  width: 12px;
  height: 12px;
  display: inline-block;
  color: currentColor;
}

.icon--pause::before,
.icon--pause::after {
  content: "";
  position: absolute;
  top: 0;
  width: 3.5px;
  height: 12px;
  background: currentColor;
  border-radius: 1px;
}

.icon--pause::before { left: 0.5px; }
.icon--pause::after { left: 8px; }

.icon--play::before {
  content: "";
  position: absolute;
  top: 0;
  left: 2px;
  border-left: 10px solid currentColor;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.icon--reverse::before,
.icon--reverse::after {
  content: "";
  position: absolute;
  top: 1px;
  border-right: 7px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.icon--reverse::before { left: -1px; }
.icon--reverse::after { left: 5px; }

.icon--now {
  border: 2px solid currentColor;
  border-radius: 50%;
  width: 13px;
  height: 13px;
}

.icon--now::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: currentColor;
}

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

.dock {
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-columns: auto minmax(200px, 1.3fr) minmax(220px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
}

.dock__transport { display: flex; align-items: center; gap: 6px; }

.dock__rate { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.dock__rate-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.rate__value {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.dock__pace { font-size: 11px; color: var(--text-dim); }

.dock__presets { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.dock__keys { color: var(--text-faint); line-height: 1.7; }

/* Range slider ---------------------------------------------------------- */

.slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--accent) 0 var(--fill, 50%),
    var(--sunken) var(--fill, 50%) 100%
  );
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
}

.slider::-moz-range-track {
  height: 4px;
  border-radius: 3px;
  background: var(--sunken);
}

.slider::-moz-range-progress {
  height: 4px;
  border-radius: 3px;
  background: var(--accent);
}

.slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid var(--accent);
}

/* Segmented control ----------------------------------------------------- */

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--sunken);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.segmented--wrap { flex-wrap: wrap; }

.seg {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--step) var(--ease), color var(--step) var(--ease);
}

.seg:hover { color: var(--text); }

.seg[aria-pressed="true"] {
  background: var(--raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--panel-border);
}

/* ---------------------------------------------------------------- loader */

.loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: var(--bg-veil);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 600ms var(--ease), visibility 600ms var(--ease);
}

.loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader.is-failed { background: var(--bg); }

.loader__card {
  width: min(430px, calc(100vw - 32px));
  padding: 24px;
  display: grid;
  gap: 12px;
  justify-items: start;
}

.loader__mark {
  position: relative;
  width: 34px;
  height: 34px;
  display: block;
}

.loader__mark::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.5;
}

.loader__title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.loader__step {
  font-size: 12.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.loader__note { font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }

.meter {
  width: 100%;
  height: 4px;
  border-radius: 3px;
  background: var(--sunken);
  overflow: hidden;
}

.meter__fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 220ms var(--ease);
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
  text-align: center;
  color: var(--text);
}

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

@media (max-width: 1180px) {
  .fps { display: none; }
  .brand__sub { display: none; }
}

@media (max-width: 940px) {
  .hud {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px;
  }

  .topbar {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 12px;
    padding: 8px 10px;
  }

  .brand { grid-column: 1; grid-row: 1; }
  .clock { grid-column: 2; grid-row: 1; align-items: flex-end; margin-left: 0; }

  .topbar__actions {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    align-items: flex-start;
  }

  .topbar__actions .field { flex: none; }

  .panel--bodies {
    grid-column: 1;
    grid-row: 2;
    max-height: none;
  }

  .panel--bodies .body-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 8px 8px;
    gap: 4px;
  }

  .panel--bodies .body-list__group { display: none; }
  .panel--bodies .panel__foot,
  .panel--bodies .panel__hint { display: none; }

  .body-btn {
    grid-template-columns: auto auto;
    flex: 0 0 auto;
    width: auto;
    padding: 6px 10px;
  }

  .body-btn__name { overflow: visible; text-overflow: clip; }
  .body-btn__meta { display: none; }
  .body-btn--moon { display: none; }

  .panel--info {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
    max-height: 30vh;
  }

  .dock {
    grid-column: 1;
    grid-row: 4;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
  }

  .dock__keys { display: none; }
  .dock__transport { justify-content: center; }
}

@media (max-width: 560px) {
  /* The blurb is the first thing to go when the screen is short. */
  .blurb { display: none; }
  .brand__text strong { font-size: 12.5px; }
  .clock__value { font-size: 13px; }
  .segmented { max-width: 100%; overflow-x: auto; }
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
