:root {
  color-scheme: dark;
  font-family: "Manrope", sans-serif;
  color: #f7f5ec;
  background: #090b1a;
  font-synthesis: none;
  --acid: #d9ff43;
  --blue: #4f75ff;
  --panel: rgba(13, 16, 36, 0.92);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: hidden; }

body {
  min-height: 100svh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 70% 15%, rgba(54, 80, 180, .22), transparent 30%),
    linear-gradient(145deg, #0a0d20, #070813 68%);
}

button { font: inherit; }
button:focus-visible { outline: 3px solid white; outline-offset: 3px; }

#app {
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(100%, 1480px);
  margin: auto;
  padding: 18px clamp(16px, 3vw, 46px);
  max-width: 100vw;
  min-width: 0;
  overflow-x: clip;
  overflow-y: visible;
}

.topbar, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  font-family: "DM Mono", monospace;
  font-size: 11px;
  letter-spacing: .13em;
}
.topbar > *, footer > * { min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.icon-button { flex: 0 0 auto; white-space: nowrap; }
.score-link {
  color: var(--acid);
  border-bottom: 1px solid rgba(217,255,67,.45);
  padding: 4px 0;
}
.short-label { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  color: #090b1a;
  background: var(--acid);
  font-size: 18px;
}

.icon-button, .text-button {
  border: 0;
  color: #9da4bc;
  background: transparent;
  cursor: pointer;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  letter-spacing: .1em;
}

.game-shell {
  align-self: center;
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(8, 10, 25, .75);
  box-shadow: 0 30px 100px rgba(0,0,0,.45);
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.hud {
  height: 66px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.stat {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  font-family: "DM Mono", monospace;
  border-right: 1px solid rgba(255,255,255,.1);
  min-width: 0;
  overflow: hidden;
}

.stat:last-child { border-right: 0; justify-content: flex-end; }
.stat.score { justify-content: center; }
.stat span { color: #747b95; font-size: 10px; letter-spacing: .14em; }
.stat strong { font-size: 22px; letter-spacing: -.04em; }
.stat.score strong { color: var(--acid); }
.stat.countdown strong {
  min-width: 58px;
  color: #f7f5ec;
  font-variant-numeric: tabular-nums;
}
.stat.countdown.urgent strong {
  color: #ff5a47;
  animation: countdown-pulse .55s steps(2, end) infinite;
}
@keyframes countdown-pulse {
  50% { opacity: .45; }
}

.canvas-wrap {
  position: relative;
  height: min(690px, calc(100svh - 174px));
  height: min(690px, calc(100dvh - 174px));
  min-height: 520px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pinch-zoom;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(7,9,22,.95), rgba(7,9,22,.66) 50%, rgba(7,9,22,.95)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(255,255,255,.025) 80px);
  transition: opacity .25s ease, transform .25s ease;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

.overlay.hidden {
  opacity: 0;
  transform: scale(1.04);
  pointer-events: none;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--acid);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  letter-spacing: .22em;
}

h1, h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(42px, 6vh, 70px);
  line-height: .87;
  letter-spacing: -.07em;
  text-transform: uppercase;
}

h1 em { color: var(--acid); font-style: normal; }
.intro { margin: 15px 0 22px; color: #9ea5ba; font-size: 13px; }

.splash-screen {
  isolation: isolate;
  overflow: hidden;
}
.splash-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 50% 44%, rgba(79,117,255,.2), transparent 32%),
    linear-gradient(145deg, rgba(8,10,25,.97), rgba(8,10,25,.78));
}
.splash-screen h1 { font-size: clamp(64px, 11vh, 116px); }
.game-label {
  margin: 12px 0 0;
  color: #f7f5ec;
  font: 800 13px "DM Mono", monospace;
  letter-spacing: .55em;
}
.splash-line {
  margin: 20px 0 0;
  color: #969db4;
  font-size: 13px;
}
.splash-button { margin-top: 28px; }
.splash-orbit {
  position: absolute;
  left: 50%;
  top: 45%;
  z-index: -1;
  width: min(62vw, 480px);
  aspect-ratio: 1;
  border: 1px solid rgba(217,255,67,.22);
  border-radius: 50%;
  transform: translate(-50%, -50%) rotate(-14deg) scaleY(.38);
}
.splash-orbit span {
  position: absolute;
  right: 9%;
  top: 11%;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 24px var(--acid);
}

.programs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 230px));
  gap: 10px;
  width: min(100%, 710px);
}

.program-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 11px;
  min-height: 105px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.12);
  color: inherit;
  background: rgba(19, 22, 46, .78);
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}

.program-card:hover { transform: translateY(-3px); border-color: rgba(255,255,255,.35); }
.program-card.selected { border-color: var(--acid); background: rgba(37, 43, 64, .96); }
.program-card.selected::after {
  content: "✓";
  position: absolute;
  top: -8px;
  right: -8px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: #080a18;
  background: var(--acid);
  font-size: 12px;
}

.program-logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.3);
  font-weight: 800;
}

.nasa-logo { background: #173278; }
.spacex-logo { background: #e8e8e3; color: #080a18; }
.blue-logo { background: #286a9b; }
.program-copy { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.program-copy strong { font-size: 13px; }
.program-copy small, .program-copy > span:last-child {
  color: #777f99;
  font-family: "DM Mono", monospace;
  font-size: 8px;
  letter-spacing: .07em;
}
.program-copy .team-tag {
  color: #a5adc2;
  font-size: 7px;
  letter-spacing: .12em;
}

.meter { height: 3px; margin: 4px 0; background: rgba(255,255,255,.1); }
.meter i { display: block; width: var(--fill); height: 100%; background: var(--acid); }
.risk {
  position: absolute;
  right: 10px;
  top: 10px;
  padding: 3px 5px;
  font-family: "DM Mono", monospace;
  font-size: 7px;
  letter-spacing: .08em;
}
.safe { color: var(--acid); background: rgba(217,255,67,.1); }
.hot { color: #8ba2ff; background: rgba(79,117,255,.14); }
.danger { color: #ff755e; background: rgba(255,91,67,.12); }

.primary-button {
  min-width: 286px;
  margin-top: 20px;
  padding: 15px 22px;
  border: 0;
  color: #090b1a;
  background: var(--acid);
  box-shadow: 5px 5px 0 #6f7d25;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.primary-button:hover { transform: translate(-2px,-2px); box-shadow: 8px 8px 0 #6f7d25; }
.primary-button:active { transform: translate(4px,4px); box-shadow: 1px 1px 0 #6f7d25; }
.primary-button span { float: right; font-size: 17px; }
.scoring-key { margin: 12px 0 0; color: #d9ff43; font: 800 9px "DM Mono", monospace; letter-spacing: .06em; }
.howto { margin: 8px 0 0; color: #5d647c; font-family: "DM Mono", monospace; font-size: 9px; letter-spacing: .13em; }

.end-screen h2 { color: var(--acid); }
.end-screen.pad-failure {
  align-items: flex-end;
  padding-right: clamp(28px, 10vw, 150px);
  background:
    linear-gradient(90deg, transparent 0 30%, rgba(7,9,22,.55) 48%, rgba(7,9,22,.96) 72%),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(255,255,255,.025) 80px);
}
.end-screen.pad-failure > * {
  width: min(420px, 52vw);
  text-align: center;
}
.final-score { display: flex; flex-direction: column; align-items: center; margin: 25px 0 10px; }
.final-score strong { font-size: clamp(58px, 8vh, 80px); line-height: 1; letter-spacing: -.08em; }
.final-score span { color: #747b95; font: 9px "DM Mono", monospace; letter-spacing: .2em; }
.end-screen p { color: #9da4bc; font-size: 13px; }
.end-screen .text-button { margin-top: 18px; }
.scores-screen {
  z-index: 5;
  background:
    radial-gradient(circle at 50% 35%, rgba(79,117,255,.18), transparent 34%),
    rgba(7,9,22,.96);
}
.scores-screen h2 em { color: var(--acid); font-style: normal; }
.scores-screen .leaderboard { margin: 20px 0 22px; }

.leaderboard {
  width: min(390px, 92vw);
  margin-top: 8px;
  padding: 10px 14px 12px;
  border: 2px solid #616a87;
  color: #e8e9df;
  background: #090b16;
  box-shadow: 5px 5px 0 #22283d, inset 0 0 24px rgba(79,117,255,.12);
  font-family: "DM Mono", monospace;
}
.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--acid);
}
.leaderboard h3 {
  margin: 0;
  font-size: 11px;
  letter-spacing: .15em;
}
.leaderboard-rows {
  min-height: 66px;
  max-height: 138px;
  margin: 8px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  counter-reset: rank;
}
.leaderboard-rows li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 24px 1fr 72px 54px;
  gap: 6px;
  padding: 2px 3px;
  color: #aeb5cb;
  font-size: 9px;
  line-height: 1.35;
}
.leaderboard-rows li::before {
  content: counter(rank, decimal-leading-zero);
  color: #69718c;
}
.leaderboard-rows li:nth-child(1) { color: #d9ff43; }
.leaderboard-rows li:nth-child(2) { color: #f5f4e9; }
.leaderboard-rows li:nth-child(3) { color: #ffb648; }
.leaderboard-rows .leaderboard-loading {
  display: block;
  text-align: center;
  color: #69718c;
  padding-top: 18px;
}
.leaderboard-rows .leaderboard-loading::before { content: ""; }
.leaderboard-score { text-align: right; color: inherit; }
.leaderboard-program { text-align: right; color: #626b87; }
.score-entry {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed #4b536c;
}
.score-entry label {
  display: block;
  margin-bottom: 6px;
  color: #ffcf3a;
  font-size: 8px;
  letter-spacing: .08em;
  animation: countdown-pulse .65s steps(2,end) infinite;
}
.score-entry div { display: flex; gap: 6px; }
.score-entry input {
  min-width: 0;
  flex: 1;
  border: 1px solid #626b87;
  padding: 7px 9px;
  color: var(--acid);
  background: #11162a;
  font: 11px "DM Mono", monospace;
  text-transform: uppercase;
}
.score-entry button {
  border: 0;
  padding: 0 14px;
  color: #090b16;
  background: var(--acid);
  font: 800 9px "DM Mono", monospace;
  cursor: pointer;
}
.leaderboard-message {
  min-height: 10px;
  margin: 5px 0 0 !important;
  color: #7c849d !important;
  font: 8px "DM Mono", monospace !important;
}
.is-hidden { display: none !important; }

.toast {
  position: absolute;
  left: 50%;
  top: 33%;
  z-index: 4;
  display: flex;
  width: min(330px, calc(100% - 38px));
  padding: 9px 15px 10px;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  color: #f7f5ec;
  background: linear-gradient(105deg, rgba(10,13,29,.9), rgba(25,29,48,.94), rgba(10,13,29,.9));
  border: 1px solid rgba(217,255,67,.25);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0,0,0,.24);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translate(-50%, 12px) scale(.97);
  pointer-events: none;
}
.toast::after {
  position: absolute;
  right: 18%;
  bottom: 0;
  left: 18%;
  height: 2px;
  background: var(--acid);
  content: "";
  opacity: .7;
}
.toast-label {
  color: var(--acid);
  font: 800 6.5px "DM Mono", monospace;
  letter-spacing: .22em;
}
.toast-message {
  max-width: 100%;
  font: 800 10px/1.35 "DM Mono", monospace;
  letter-spacing: .045em;
  text-align: center;
  text-transform: uppercase;
}
.toast.is-danger {
  border-color: rgba(255,123,97,.3);
  background: linear-gradient(105deg, rgba(12,14,29,.84), rgba(37,24,33,.86), rgba(12,14,29,.84));
}
.toast.is-danger::after { background: #ff7b61; }
.toast.is-danger .toast-label { color: #ff9a82; }
.toast.show { animation: status-banner 2.5s cubic-bezier(.2,.75,.25,1) both; }
@keyframes status-banner {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(.97); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -10px) scale(.985); }
}

footer { color: #4e556c; min-height: 38px; }

@media (max-width: 700px) {
  #app { padding: 8px; }
  .topbar { min-height: 42px; }
  .topbar-actions { gap: 7px; }
  .score-link { font-size: 8px; }
  .score-link .wide-label { display: none; }
  .score-link .short-label { display: inline; }
  .canvas-wrap {
    height: calc(100svh - 114px);
    height: calc(100dvh - 114px);
    min-height: 0;
  }
  .hud { height: 54px; }
  .stat {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px 4px;
    gap: 1px;
    text-align: center;
  }
  .stat:last-child, .stat.score { justify-content: center; }
  .stat strong { max-width: 100%; font-size: clamp(13px, 4.3vw, 17px); }
  .stat span { max-width: 100%; font-size: 7px; line-height: 1.1; }
  .stat.countdown strong { min-width: 0; }
  .overlay {
    justify-content: flex-start;
    padding: 24px 14px 18px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  .splash-screen { justify-content: center; overflow: hidden; padding: 24px 14px; }
  .splash-screen h1 { font-size: clamp(50px, 15vw, 72px); }
  h1, h2 { font-size: 42px; }
  .intro { text-align: center; font-size: 11px; margin: 12px 0 16px; }
  .programs { grid-template-columns: 1fr; width: 100%; max-width: 390px; }
  .program-card { min-height: 78px; grid-template-columns: 38px 1fr; padding: 10px; }
  .program-logo { width: 34px; height: 34px; }
  .primary-button { min-width: min(286px, 90vw); }
  .end-screen.pad-failure {
    align-items: center;
    justify-content: flex-start;
    padding: 24px 12px;
    background: linear-gradient(180deg, rgba(7,9,22,.94), rgba(7,9,22,.42) 60%, transparent);
  }
  .end-screen.pad-failure > * { width: min(100%, 390px); }
  footer { display: none; }
}

@media (max-width: 700px) and (max-height: 720px) {
  .start-screen { padding-top: 14px; }
  .start-screen .eyebrow { margin-bottom: 5px; font-size: 8px; }
  .start-screen h1 { font-size: 34px; line-height: .88; }
  .start-screen .intro { margin: 8px 0 10px; font-size: 9px; }
  .start-screen .programs { gap: 6px; }
  .start-screen .program-card {
    min-height: 65px;
    padding: 7px 9px;
    grid-template-columns: 32px 1fr;
    gap: 8px;
  }
  .start-screen .program-logo { width: 30px; height: 30px; font-size: 12px; }
  .start-screen .program-copy { gap: 1px; }
  .start-screen .program-copy strong { font-size: 11px; }
  .start-screen .program-copy > span:last-child { font-size: 7px; }
  .start-screen .meter { margin: 2px 0; }
  .start-screen .risk { top: 6px; right: 7px; }
  .start-screen .primary-button { margin-top: 11px; padding: 12px 18px; }
  .start-screen .howto { margin-top: 9px; font-size: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
