:root {
  --bg: #070617;
  --panel: rgba(22, 19, 52, 0.78);
  --panel-solid: #16133a;
  --line: rgba(200, 190, 255, 0.12);
  --ink: #eef0ff;
  --muted: #9d9fc9;
  --accent: #a78bfa;
  --accent-ink: #140a2e;
  --gold: #ffd479;
  --teal: #5eead4;
  --danger: #ff6b8a;
  --font: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 0.75em; padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); margin-right: 3px;
}

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- top bar ---------- */
.bar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 14px 6px; position: relative; z-index: 2;
}
.bar-side { display: flex; gap: 8px; }
.bar-side.end { justify-content: flex-end; }
.title { text-align: center; line-height: 1.1; }
.title h1 {
  margin: 0; font-size: 1.5rem; font-weight: 700; letter-spacing: 0.02em;
  background: linear-gradient(90deg, #c4b5fd, #f0abfc 55%, #fcd34d); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.title p { margin: 2px 0 0; font-size: 0.78rem; color: var(--muted); text-wrap: balance; } /* a long system name wraps instead of pushing the buttons off-screen */
.title p b { color: var(--ink); font-weight: 500; white-space: nowrap; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); text-decoration: none;
  cursor: pointer; font-size: 1rem; font-weight: 700; transition: background 0.15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* ---------- stage ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.stage { position: relative; flex: 1; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.stage canvas.flying { cursor: pointer; }
/* While the day's system is charted (js/boot.js). It fades in late, so a quick day never flashes it. */
.charting {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%); margin: 0; z-index: 2;
  color: var(--muted); font-size: 0.95rem; letter-spacing: 0.02em; white-space: nowrap;
  animation: charting 0.4s 0.25s both;
}
.charting[hidden] { display: none; }
@keyframes charting { from { opacity: 0; } }

/* At the bottom: the beacon world is always near the top of the map. */
.banner {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 2;
  max-width: min(420px, calc(100% - 32px)); padding: 10px 14px; border-radius: 14px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px);
  font-size: 0.88rem; line-height: 1.35; pointer-events: none; transition: opacity 0.6s, transform 0.6s;
}
.banner b { color: var(--accent); display: block; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 2px; }
.banner a { color: var(--accent); font-weight: 700; pointer-events: auto; }
.banner.below-chip { top: 54px; bottom: auto; }
.banner.fade { opacity: 0; transform: translate(-50%, 8px); }

.flash {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%) scale(0.9); z-index: 2;
  font-size: clamp(1.4rem, 5vw, 2.1rem); font-weight: 700; letter-spacing: 0.01em; white-space: nowrap;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.8); opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
.flash.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.flash.good { color: var(--teal); }
.flash.bad { color: var(--danger); }
.flash.meh { color: var(--muted); }
.flash small { display: block; text-align: center; font-size: 0.5em; font-weight: 500; color: var(--gold); margin-top: 4px; }

.chip-btn {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 7px 8px 7px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line);
  font-size: 0.82rem; color: var(--muted); cursor: pointer; white-space: nowrap; backdrop-filter: blur(8px);
}
a.chip-btn { text-decoration: none; }
.chip-btn b { margin-left: 8px; padding: 3px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ---------- dock ---------- */
.dock {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
  width: 100%; max-width: 760px; margin: 0 auto; padding: 8px 16px max(12px, env(safe-area-inset-bottom));
}
.status { display: flex; flex-direction: column; gap: 6px; }
.probes { display: flex; gap: 5px; align-items: center; min-height: 20px; }
.probes i {
  width: 12px; height: 18px; border-radius: 6px 6px 3px 3px; background: var(--accent);
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.55); transition: background 0.2s, box-shadow 0.2s;
}
.probes i.used { background: rgba(255, 255, 255, 0.12); box-shadow: none; }
.probes i.crash { background: var(--danger); opacity: 0.55; box-shadow: none; }
.probes i.land { background: var(--teal); box-shadow: 0 0 10px rgba(94, 234, 212, 0.6); }
.probes .pip { display: flex; padding: 8px 2px; margin: -8px -2px; border: 0; background: none; cursor: pointer; border-radius: 6px; }
.probes .pip:disabled { cursor: default; }
.probes .pip:not(:disabled):hover i { outline: 2px solid rgba(255, 255, 255, 0.35); outline-offset: 1px; }
.probes .inf { font-size: 0.82rem; color: var(--muted); }
.dust { display: flex; gap: 4px; font-size: 1rem; color: rgba(255, 255, 255, 0.16); }
.dust span.on { color: var(--gold); text-shadow: 0 0 10px rgba(255, 212, 121, 0.7); }

.readout { display: flex; justify-content: center; gap: 10px; }
.dial {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 6px 6px;
  border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
}
.dial small { font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.dial-row { display: flex; align-items: center; gap: 4px; }
.dial b { font-family: var(--mono); font-weight: 500; font-size: 1.02rem; min-width: 4.4em; text-align: center; font-variant-numeric: tabular-nums; }
.step {
  width: 30px; height: 30px; border-radius: 9px; border: 0; background: rgba(255, 255, 255, 0.07);
  cursor: pointer; font-size: 1.1rem; line-height: 1; touch-action: manipulation; user-select: none;
}
.step:hover { background: rgba(255, 255, 255, 0.13); }
.step:disabled { opacity: 0.3; cursor: default; }
/* The numbers scrub: drag one sideways for fine steps (game.js). */
#rAngle, #rPower { touch-action: none; cursor: ew-resize; user-select: none; -webkit-user-select: none; border-radius: 6px; }
#rAngle.scrubbing, #rPower.scrubbing { background: rgba(255, 255, 255, 0.13); }

.launch {
  height: 54px; min-width: 116px; padding: 0 20px; border-radius: 16px; border: 0; cursor: pointer;
  font-size: 1.08rem; font-weight: 700; letter-spacing: 0.02em; color: var(--accent-ink);
  background: linear-gradient(135deg, #c4b5fd, #a78bfa 50%, #f0abfc);
  box-shadow: 0 6px 24px rgba(167, 139, 250, 0.35); transition: transform 0.12s, filter 0.12s, opacity 0.2s;
}
.launch:hover { filter: brightness(1.08); }
.launch:active { transform: scale(0.97); }
.launch:disabled { opacity: 0.35; cursor: default; box-shadow: none; }
.launch.alt { background: rgba(255, 255, 255, 0.08); color: var(--ink); box-shadow: none; border: 1px solid var(--line); }

@media (max-width: 560px) {
  .dock { grid-template-columns: 1fr auto; grid-template-areas: 'status launch' 'read read'; gap: 8px 10px; padding-left: 12px; padding-right: 12px; }
  .status { grid-area: status; flex-direction: row; align-items: center; gap: 14px; }
  .launch { grid-area: launch; height: 44px; min-width: 104px; }
  .readout { grid-area: read; }
  .dial { flex: 1; min-width: 0; }
  .dial-row { width: 100%; justify-content: space-between; }
  .step { width: 38px; height: 34px; }
  .bar { padding-left: 12px; padding-right: 12px; }
}
/* Two full-size dials need about 350px: tighten them so the dock fits 320px phones without scrolling sideways. */
/* Small phones: the twist banner takes less of the sky (it also goes as soon as you aim). */
@media (max-width: 374px), (max-height: 640px) {
  .banner { font-size: 0.8rem; padding: 7px 10px; line-height: 1.3; }
  .banner b { font-size: 0.64rem; }
}
/* Desktop: bigger dials, and the keys written out, not only in Help. */
.keys { display: none; }
@media (min-width: 900px) and (min-height: 640px) and (hover: hover) and (pointer: fine) {
  .dock { max-width: 900px; grid-template-areas: 'status readout launch' 'keys keys keys'; row-gap: 6px; }
  .dock .status { grid-area: status; }
  .dock .readout { grid-area: readout; }
  .dock .launch { grid-area: launch; }
  .dial b { font-size: 1.2rem; }
  .step { width: 42px; height: 38px; }
  .keys { display: block; grid-area: keys; margin: 0; text-align: center; font-size: 0.76rem; color: var(--muted); }
  .keys kbd { font-family: var(--mono); font-size: 0.72rem; padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); }
}
@media (max-width: 374px) {
  .readout { gap: 6px; }
  .dial { padding: 5px 4px 6px; }
  .dial-row { gap: 2px; }
  .dial b { font-size: 0.9rem; min-width: 3.9em; }
  .step { width: 34px; }
}

/* ---------- dialogs ---------- */
.dialog {
  width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
  padding: 24px 22px 20px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--panel-solid); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(4, 3, 14, 0.65); backdrop-filter: blur(3px); }
.dialog h2 { margin: 0 0 12px; font-size: 1.45rem; }
.close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 10px; border: 0;
  background: transparent; font-size: 1.5rem; cursor: pointer; color: var(--muted);
}
.close:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }

.howto { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.howto li { display: flex; gap: 12px; align-items: flex-start; line-height: 1.42; font-size: 0.94rem; }
.howto small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8rem; }
.how-ico { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.06); }
.how-ico.gold { color: var(--gold); font-size: 1.1rem; }
.teal { color: var(--teal); }
.fine { color: var(--muted); font-size: 0.84rem; margin: 8px 0; line-height: 1.4; }
.fine b { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 46px; padding: 0 18px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07);
  font-weight: 700; cursor: pointer; width: 100%; margin-top: 8px; transition: filter 0.12s;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { border: 0; color: var(--accent-ink); background: linear-gradient(135deg, #c4b5fd, #a78bfa 50%, #f0abfc); }
.btn.ghost { background: transparent; }
.modes { display: flex; gap: 6px; align-items: center; margin: 10px 0 0; padding: 0; border: 0; }
.modes legend { float: left; margin-right: 6px; color: var(--muted); font-size: 0.84rem; }
.modes label { flex: 1; position: relative; }
.modes input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.modes span { display: block; padding: 7px 0; border-radius: 10px; border: 1px solid var(--line); text-align: center; font-size: 0.86rem; font-weight: 600; color: var(--muted); }
.modes input:checked + span { border-color: var(--accent); background: rgba(167, 139, 250, 0.18); color: var(--ink); }
.modes input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
#modeNote { margin-top: 6px; }
.help-practice { display: block; padding: 10px 4px 2px; text-align: center; color: var(--accent); font-weight: 600; font-size: 0.9rem; text-underline-offset: 3px; }
.help-practice[hidden] { display: none; }
.row { display: flex; flex-wrap: wrap; gap: 0 8px; }
.row > .btn { flex: 1 1 120px; }

/* result */
.res-head { text-align: center; padding-top: 4px; }
.res-kicker { margin: 0; font-size: 0.74rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.res-title { margin: 6px 0 2px !important; font-size: 2rem !important; }
.res-title.good { color: var(--teal); }
.res-title.bad { color: var(--danger); }
.res-stars { font-size: 2rem; letter-spacing: 6px; color: rgba(255, 255, 255, 0.14); margin: 4px 0; }
.res-stars .on { color: var(--gold); text-shadow: 0 0 18px rgba(255, 212, 121, 0.7); }
.res-sub { margin: 0; color: var(--muted); font-size: 0.92rem; }
.res-strip { font-size: 1.35rem; letter-spacing: 4px; margin: 10px 0 2px; }
.res-bonus { opacity: 0.7; letter-spacing: 2px; }
/* the stardust chase: spare probes after a landing */
.chase {
  margin: 14px 0 2px; padding: 12px 14px; border-radius: 14px; text-align: center;
  border: 1px solid rgba(255, 212, 121, 0.35); background: rgba(255, 212, 121, 0.07);
}
.chase p { margin: 0; font-size: 0.9rem; line-height: 1.4; }
.chase p b { color: var(--gold); }
.chase .fine { margin: 8px 0 0; font-size: 0.78rem; }
.btn.gold { border: 0; color: #2a1a00; background: linear-gradient(135deg, #fff1c9, #ffd479 60%, #f5b94a); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 16px 0 12px; text-align: center; }
.stats b { display: block; font-size: 1.5rem; font-weight: 700; }
.stats span { font-size: 0.72rem; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.dist div { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.dist i {
  display: block; height: 18px; min-width: 22px; border-radius: 5px; background: rgba(255, 255, 255, 0.1);
  font-style: normal; color: var(--ink); font-size: 0.72rem; text-align: right; padding: 1px 6px 0;
}
.dist i.me { background: var(--accent); color: var(--accent-ink); }
.dist.wide div { grid-template-columns: 26px 1fr; }
.dist-h { margin: 12px 0 6px; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.countdown { text-align: center; color: var(--muted); font-size: 0.86rem; margin: 12px 0 0; }
.countdown b { font-family: var(--mono); color: var(--ink); font-weight: 500; }

/* Short screens: tighter dialogs, and the main buttons stay in view while the rest scrolls. */
@media (max-height: 640px) {
  .dialog { padding: 18px 16px 14px; }
  .dialog h2 { font-size: 1.25rem; margin-bottom: 8px; }
  .howto { gap: 8px; margin-bottom: 8px; }
  .howto li { font-size: 0.88rem; line-height: 1.35; }
  .how-ico { width: 28px; height: 28px; }
  .res-title { font-size: 1.6rem !important; }
  .res-stars { font-size: 1.6rem; }
  .res-strip { margin-top: 6px; }
  .chase { margin-top: 10px; padding: 10px 12px; }
  .stats { margin: 10px 0 8px; }
  .stats b { font-size: 1.25rem; }
  .dist { gap: 3px; }
  .dist-h { margin: 8px 0 4px; }
  .dist i { height: 14px; font-size: 0.66rem; line-height: 14px; padding-top: 0; }
  .dialog > .btn.primary, .dialog > .help-go { position: sticky; bottom: 0; z-index: 1; box-shadow: 0 0 0 8px var(--panel-solid), 0 14px 0 8px var(--panel-solid); }
  .dialog > .help-go { background: var(--panel-solid); }
  .dialog .row {
    position: sticky; bottom: -14px; z-index: 1; margin-bottom: -14px; padding: 2px 0 14px;
    background: var(--panel-solid); box-shadow: 0 -10px 12px -6px var(--panel-solid);
  }
}

.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translate(-50%, 10px); z-index: 20;
  padding: 10px 16px; border-radius: 12px; background: #fff; color: #111; font-weight: 700; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Landscape phones and other short screens: the sky takes the full height on the left, and the
   header and dock stack in a column on the right (the world is portrait, so height is what counts). */
@media (orientation: landscape) and (max-height: 520px) {
  .app { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto 1fr; grid-template-areas: 'stage bar' 'stage dock'; }
  .bar { grid-area: bar; padding-left: 10px; padding-right: 12px; }
  .stage { grid-area: stage; }
  .dock {
    grid-area: dock; align-self: start; max-width: none; padding: 4px 12px max(10px, env(safe-area-inset-bottom)) 10px;
    grid-template-columns: 1fr; grid-template-areas: 'status' 'read' 'launch'; gap: 8px;
  }
  .status { grid-area: status; flex-direction: row; align-items: center; justify-content: space-between; }
  .readout { grid-area: read; flex-direction: column; gap: 6px; }
  .dial { width: 100%; }
  .dial-row { width: 100%; justify-content: space-between; }
  .launch { grid-area: launch; width: 100%; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
/* the same for the site-wide Reduce motion setting (hub/prefs.js) */
html.reduce-motion * { transition: none !important; }
