:root {
  --navy: #0b1d2e;
  --navy-2: #12304a;
  --ink: #1d1409;
  --parchment: #f1e4c3;
  --parchment-2: #e3cf9f;
  --gold: #e9b23f;
  --gold-deep: #b97f17;
  --red: #d6402f;
  --sea: #1f6f8b;
  --text: #2a1d0e;
  --muted: #6b5634;
  --panel-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  --display: "Rockwell", "Roboto Slab", "Georgia", "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--parchment);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 10%, #1b4a6b 0%, var(--navy) 70%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#stage canvas { display: block; width: 100%; height: 100%; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
  overflow-y: auto;
}
.screen[hidden] { display: none; }
.screen.dim { background: rgba(4, 12, 20, .62); backdrop-filter: blur(3px); }

.panel {
  position: relative;
  width: min(440px, 100%);
  padding: 28px 28px 24px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.25), rgba(255,255,255,0) 30%),
    var(--parchment);
  color: var(--text);
  border-radius: 6px;
  border: 3px solid #6e4a1f;
  box-shadow: inset 0 0 0 2px var(--parchment-2), inset 0 0 40px rgba(110, 74, 31, .35), var(--panel-shadow);
  text-align: center;
}
.panel.wide { width: min(640px, 100%); text-align: left; }
.panel h2, .panel h3 { font-family: var(--display); margin: 0 0 .4em; color: var(--ink); }
.panel h2 { font-size: 1.9rem; }
.panel h3 { font-size: 1.05rem; }
.panel.wide h2 { text-align: center; }
.panel ul { padding-left: 1.1em; margin: .3em 0 1em; }
.panel li { margin: .2em 0; }

.title {
  font-family: var(--display);
  font-size: clamp(2rem, 7vw, 2.8rem);
  line-height: 1.05;
  margin: 0 0 .3em;
  color: var(--ink);
  letter-spacing: .01em;
  text-shadow: 0 2px 0 var(--parchment-2);
}
.title span { color: var(--red); }
.lede { margin: 0 0 1.2em; }
.kicker {
  margin: 0;
  font: 700 .8rem/1 var(--mono);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.fine { font-size: .85rem; color: var(--muted); margin: 1em 0 0; }
.error { color: var(--red); font-weight: 600; margin: .5em 0 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
@media (max-width: 560px) { .cols { grid-template-columns: 1fr; } }

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 .35em;
  border: 1px solid #8a6a3a;
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #fbf3dc;
  font: 600 .8em/1.6 var(--mono);
  text-align: center;
}

form { display: grid; gap: 8px; text-align: left; }
label { font-weight: 600; font-size: .9rem; color: var(--muted); }
input {
  width: 100%;
  padding: 12px 14px;
  font: 600 1.1rem/1.2 system-ui, sans-serif;
  color: var(--text);
  background: #fffaf0;
  border: 2px solid #8a6a3a;
  border-radius: 4px;
  outline: none;
}
input:focus { border-color: var(--gold-deep); box-shadow: 0 0 0 3px rgba(233, 178, 63, .35); }

.stack { display: grid; gap: 10px; margin-top: 8px; }
.stack.row { grid-template-columns: 1fr 1fr; }

.btn {
  appearance: none;
  border: 2px solid #6e4a1f;
  border-radius: 4px;
  padding: 11px 18px;
  font: 700 1rem/1.2 var(--display);
  letter-spacing: .03em;
  color: var(--ink);
  background: linear-gradient(#fbf1d6, #e6d2a2);
  box-shadow: 0 3px 0 #6e4a1f;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6e4a1f; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.primary { background: linear-gradient(#f4c45a, #d4921e); color: #2a1600; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); text-decoration: underline; }
.btn[disabled] { opacity: .6; cursor: progress; }
form .btn { margin-top: 6px; }

/* ---------- leaderboard ---------- */
.board {
  list-style: none;
  counter-reset: rank;
  margin: 10px 0 18px;
  padding: 0;
  max-height: min(52vh, 460px);
  overflow-y: auto;
  border-top: 1px solid rgba(110, 74, 31, .35);
}
.board.short { max-height: 30vh; }
.board li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  align-items: baseline;
  gap: 8px;
  padding: 7px 6px;
  border-bottom: 1px solid rgba(110, 74, 31, .25);
}
.board li::before { content: counter(rank) "."; font: 700 .95rem var(--mono); color: var(--muted); text-align: right; }
.board li:nth-child(1)::before { color: #c99412; }
.board li:nth-child(2)::before { color: #8b8f96; }
.board li:nth-child(3)::before { color: #a8642e; }
.board li.me { background: rgba(233, 178, 63, .28); }
.board .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .t { font: 700 1rem var(--mono); }
.board .empty { display: block; color: var(--muted); text-align: center; padding: 14px; }
.board .empty::before { content: none; }
.big-time { font: 800 3rem/1 var(--mono); margin: .2em 0; text-align: center; color: var(--ink); }
#done-rank { text-align: center; margin: 0 0 .6em; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 64px 10px 16px;
  pointer-events: none;
  z-index: 10;
  font-family: var(--mono);
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
#hud[hidden] { display: none; }
.hud-block { display: grid; gap: 3px; }
.hud-center { text-align: center; }
.hud-right { justify-items: end; }
.hud-label { font-size: .7rem; letter-spacing: .18em; text-transform: uppercase; color: #cfe3ee; opacity: .85; }
.hud-kills { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 1.15rem; color: #fff; }
.hud-time { font-weight: 800; font-size: 1.5rem; color: #fff; font-variant-numeric: tabular-nums; }
.hud-ammo { font-size: .8rem; color: #ffe6a8; min-height: 1em; }
.ship-icon {
  width: 18px; height: 14px;
  background:
    linear-gradient(#eae3cf, #eae3cf) 3px 0 / 5px 8px no-repeat,
    linear-gradient(#eae3cf, #eae3cf) 9px 1px / 6px 7px no-repeat,
    linear-gradient(#7a4a24, #7a4a24) 0 9px / 18px 5px no-repeat;
}
.bar { width: 150px; max-width: 30vw; height: 9px; background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.35); border-radius: 2px; overflow: hidden; }
.bar.wide { width: 190px; }
.bar-fill { height: 100%; width: 0; transition: width .25s ease; }
.bar-fill.gold { background: linear-gradient(90deg, #f6cf62, var(--gold-deep)); }
.bar-fill.red { background: linear-gradient(90deg, #ff6b57, #b4261a); }
.hud-pause {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  width: 40px; height: 40px;
  pointer-events: auto;
  border: 2px solid rgba(255,255,255,.5);
  border-radius: 6px;
  background: rgba(5, 15, 25, .5);
  color: #fff;
  font: 900 .9rem var(--mono);
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 10px 22px;
  font: 800 clamp(1.1rem, 4vw, 1.8rem)/1.2 var(--display);
  color: #fff3cf;
  text-align: center;
  text-shadow: 0 2px 0 #4a2a00, 0 0 18px rgba(0,0,0,.7);
  pointer-events: none;
  animation: toast-in .25s ease-out;
}
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px) scale(.96); } }

@media (max-width: 560px) {
  #hud { padding-right: 60px; gap: 6px; }
  .bar, .bar.wide { width: 90px; }
  .hud-time { font-size: 1.15rem; }
  .hud-kills { font-size: .95rem; }
}

.noscript { position: fixed; inset: 0; display: grid; place-items: center; }
