:root { --panel-w: 305px; }
#stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: radial-gradient(ellipse at 51% 45%, #101727 0%, #080c16 46%, #05070d 82%);
}
.stage-head { padding: 17px 23px 0; z-index: 2; }
.stage-head h2 { color: var(--accent); margin: 10px 0 2px; font-size: 18px; }
.stage-head p { margin: 0; color: #aab7ca; font-size: 12px; }
.stage-head .seg button { min-height: 34px; padding: 3px 12px; color: var(--accent); }
.stage-head .seg button.on { color: #161105; }
#space { position: relative; min-height: 0; overflow: hidden; }
#space canvas, .space-labels { position: absolute; inset: 0; width: 100%; height: 100%; }
.orbit-canvas { cursor: grab; touch-action: none; }
.orbit-canvas:active { cursor: grabbing; }
.space-labels, .stars { pointer-events: none; }
.space-labels span {
  position: absolute; left: 0; top: 0; height: 18px; padding: 0 3px; white-space: nowrap;
  line-height: 18px; font-size: 12px; font-weight: 600; text-shadow: 0 1px 4px #05070d, 0 0 5px #05070d;
  border-radius: 3px; background: #080d19ba;
}
.space-labels span.selected { background: #131b29; outline: 1px solid #8199b062; }
.view-tools { position: absolute; right: 21px; top: 17px; display: flex; flex-wrap: wrap; gap: 5px; z-index: 3; }
#stage button.small, #panel button.small, #panelToggle {
  color: var(--accent); border-color: #ffc94a45; background: #101722;
}
#stage button.small:hover, #panel button.small:hover, #panelToggle:hover { border-color: var(--accent); }
.view-tools button.small { min-height: 34px; }
.stage-foot {
  z-index: 2; margin: 0 23px 12px; border: 1px solid #28354c; border-radius: 12px;
  background: #0c1422; padding: 8px 12px; min-width: 0;
}
.compare-races { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 0 0 7px; }
.race { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 6px; align-items: baseline; color: var(--race); font-size: 12px; }
.race strong { font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.race small { color: #aab7ca; white-space: nowrap; }
.progress { grid-column: 1 / -1; height: 3px; overflow: hidden; border-radius: 10px; background: #23334b; }
.progress i { display: block; height: 100%; transform: scaleX(0); transform-origin: left; background: var(--race); }
.transport { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.transport button.small { min-width: 53px; min-height: 34px; }
#timeline { margin: 0; min-width: 0; min-height: 34px; }
#elapsed { min-width: 78px; color: #f2e5c4; font-size: 14px; white-space: nowrap; }
.stage-meta { display: flex; justify-content: space-between; align-items: center; gap: 4px; color: #aab7ca; font-size: 11px; margin-top: 3px; }
.stage-meta .learn-fab { position: static; transform: none; padding: 1px 8px; white-space: nowrap; color: var(--accent); }
#panel { padding-top: 17px; }
#panel h1 { margin-bottom: 5px; color: #f4f6fb; }
#panel .readout { margin: 0 0 13px; padding: 11px 12px !important; }
#planetName { font-size: 18px; }
#planetType { color: #aab7ca; font-size: 12px; font-weight: 400; }
#panel dl { grid-template-columns: 1fr max-content; gap: 5px 10px; }
#panel dd { text-align: right; font-variant-numeric: tabular-nums; }
.planet-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.planet-button {
  display: flex; align-items: center; gap: 7px; min-height: 36px; padding: 5px 8px;
  background: #172131; border: 1px solid #2b3a50; border-radius: 7px;
  text-align: left; color: #f0d18e; font: inherit; font-size: 12px; cursor: pointer;
}
.planet-button::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--planet); flex: none; }
.planet-button:hover, .planet-button[aria-pressed=true] { border-color: var(--accent); }
.planet-button[aria-pressed=true] { background: #392e1d; color: #ffe7a7; }
.choice-row { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 8px; margin: 0 0 8px; }
.choice-row label { font-size: 12px; color: #aab7ca; }
.choice-row select { min-height: 34px; }
.moves { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 5px; }
.moves button.small { min-height: 30px; }
#panel .switch { font-size: 12px; min-height: 34px; }
#webglFallback { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #aab7ca; font-size: 12px; }
#webglFallback img { justify-self: center; width: min(86vw, 420px); max-height: 60%; }
[hidden] { display: none !important; }

@media (max-width: 760px) {
  .stage-head { padding: 10px 11px 0; }
  .stage-head .seg button { min-height: 42px; padding: 2px 9px; }
  .stage-head h2 { font-size: 16px; margin-top: 5px; }
  .stage-head p { font-size: 11px; }
  #panelToggle { top: 10px; right: 10px; min-height: 42px; font-size: 11px; padding: 4px 8px; }
  .view-tools { top: 98px; right: 10px; gap: 4px; }
  .view-tools button.small { min-height: 40px; font-size: 11px; padding: 3px 6px; }
  .stage-foot { margin: 0 9px 8px; padding: 6px 8px; }
  .transport { gap: 4px; }
  .transport button.small { min-width: 42px; min-height: 42px; padding-inline: 4px; }
  #timeline { min-height: 42px; }
  #elapsed { min-width: 63px; font-size: 12px; }
  .space-labels span { font-size: 11px; }
  .compare-races { gap: 8px; }
  .race { gap: 2px 4px; font-size: 11px; }
  .race strong { font-size: 12px; }
  #panel .choice-row select, .moves button.small, .planet-button { min-height: 42px; }
  .stage-meta .learn-fab { padding-block: 5px; }
}
@media (max-width: 355px) {
  .stage-head .seg button { padding-inline: 5px; }
  .stage-head p { max-width: 284px; }
  .view-tools { top: 110px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .stage-head { padding-top: 5px; }
  .stage-head h2 { margin-top: 2px; }
  .view-tools { top: 5px; }
  #panelToggle { top: 55px; }
  .stage-foot { margin-bottom: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  #panel { transition: none; }
}
