:root {
  --bg: #05070d;
  --bg2: #0a0f1a;
  --ink: #dbe7f5;
  --muted: #6f8296;
  --line: #1b2736;
  --accent: #28e2ff;
  --accent2: #ff3ea5;
  --warn: #ff5a4d;
  --p0: #28e2ff;
  --p1: #ff3ea5;
  --p2: #ffc23e;
  --p3: #63ff5c;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(900px 600px at 20% -10%, #10203a 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 110%, #2a0e28 0%, transparent 60%);
}

#app { height: 100%; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

/* ── panels ─────────────────────────────────────────────────────────── */
.panel {
  width: min(560px, calc(100vw - 32px));
  background: linear-gradient(180deg, rgba(12,18,30,.94), rgba(8,12,20,.94));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 0 0 1px rgba(40,226,255,.06), 0 24px 70px rgba(0,0,0,.6);
}
.panel.wide { width: min(760px, calc(100vw - 32px)); }

.logo {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 0 0 6px; font-size: 15px; letter-spacing: .42em; color: var(--muted);
  text-transform: uppercase;
}
.logo b {
  font-size: 62px; letter-spacing: 0; color: var(--accent);
  text-shadow: 0 0 26px rgba(40,226,255,.55);
  font-weight: 800;
}
.tagline { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 26px; }
.tagline b { color: var(--ink); }

/* ── form bits ──────────────────────────────────────────────────────── */
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 10px; letter-spacing: .2em; color: var(--muted); margin-bottom: 7px; }

input {
  width: 100%; padding: 13px 14px;
  background: #070b13; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px;
  font-family: var(--mono); font-size: 15px; letter-spacing: .06em;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(40,226,255,.12); }
input::placeholder { color: #3d4b5c; }

.code-input { text-transform: uppercase; letter-spacing: .5em; text-align: center; font-size: 22px; }

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.row .code-input { flex: 2; }

.btn {
  padding: 13px 18px; border-radius: 9px; cursor: pointer;
  background: #101823; color: var(--ink);
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 13px; letter-spacing: .14em;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: #16212f; border-color: #2b3d52; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #12a5c4, #0b7f99);
  border-color: #1cc6e8; color: #02141a; font-weight: 700;
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #18bade, #0d90ad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 12px; font-size: 11px; }
.btn.on { background: #0f3d2c; border-color: #2fbf82; color: #7dffc4; }

.or { text-align: center; margin: 20px 0; position: relative; }
.or::before { content: ""; position: absolute; inset: 50% 0 auto; height: 1px; background: var(--line); }
.or span { position: relative; background: #0b111c; padding: 0 12px; color: var(--muted); font-size: 11px; letter-spacing: .16em; }

.error { color: var(--warn); font-size: 12px; min-height: 16px; margin: 12px 0 0; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.center { text-align: center; }

.howto { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.howto summary { cursor: pointer; color: var(--muted); font-size: 12px; letter-spacing: .1em; }
.howto ul { color: var(--muted); font-size: 12px; line-height: 1.75; padding-left: 18px; margin: 12px 0 0; }
.howto b { color: var(--ink); }

.credit { margin-top: 18px; color: #2c3949; font-size: 11px; letter-spacing: .3em; }

/* ── lobby ──────────────────────────────────────────────────────────── */
.lobby-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.roomcode { font-size: 38px; letter-spacing: .32em; color: var(--accent); text-shadow: 0 0 22px rgba(40,226,255,.45); }

.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
@media (max-width: 620px) { .slots { grid-template-columns: repeat(2, 1fr); } }

.slot {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px 12px;
  background: #080d15; min-height: 104px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  position: relative; overflow: hidden;
}
.slot.empty { opacity: .35; border-style: dashed; }
.slot .ship { font-size: 26px; line-height: 1; }
.slot .nm { font-size: 13px; letter-spacing: .08em; text-align: center; word-break: break-all; }
.slot .tag { font-size: 9px; letter-spacing: .18em; color: var(--muted); }
.slot .ok { font-size: 10px; letter-spacing: .14em; color: #62e5a4; }
.slot .wait { font-size: 10px; letter-spacing: .14em; color: #6b5a2a; }
.slot::after { content: ""; position: absolute; inset: auto 0 0; height: 3px; background: currentColor; opacity: .9; }

.stake-box { border: 1px solid var(--line); border-radius: 10px; padding: 16px; background: #080d15; margin-bottom: 18px; }
.stake-label { font-size: 10px; letter-spacing: .2em; color: var(--accent); margin-bottom: 10px; }
.stake-readonly { font-size: 17px; line-height: 1.5; min-height: 26px; color: #ffe9a8; }
.stake-note { font-size: 11px; color: var(--muted); margin-top: 9px; }

.lobby-actions { margin-bottom: 10px; }
.controls-ref { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
kbd {
  background: #131c28; border: 1px solid #263447; border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 6px; margin: 0 1px; color: var(--ink); font-size: 10px;
}

/* ── game ───────────────────────────────────────────────────────────── */
#screen-game.active { display: block; position: relative; overflow: hidden; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hud { position: absolute; inset: 0; pointer-events: none; }

.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 12px 16px; gap: 16px;
}
.scorechips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: rgba(6,10,18,.78); border: 1px solid var(--line);
  border-left-width: 3px; border-radius: 7px;
  padding: 6px 11px; min-width: 108px;
  backdrop-filter: blur(4px);
}
.chip .nm { font-size: 11px; letter-spacing: .1em; opacity: .85; }
.chip .sc { font-size: 21px; line-height: 1.15; font-weight: 700; }
.chip .st { font-size: 9px; letter-spacing: .1em; color: #ffb03a; }
.chip .lives { font-size: 10px; letter-spacing: .22em; color: #7dffc4; }
.chip.dead { opacity: .45; }

.timer {
  font-size: 46px; font-weight: 800; letter-spacing: .04em;
  background: rgba(6,10,18,.78); border: 1px solid var(--line); border-radius: 9px;
  padding: 2px 16px; min-width: 96px; text-align: center;
  backdrop-filter: blur(4px); font-variant-numeric: tabular-nums;
}
.timer.urgent { color: var(--warn); border-color: #52201c; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { text-shadow: 0 0 22px rgba(255,90,77,.9); } }

.stake-ticker {
  position: absolute; top: 76px; left: 50%; transform: translateX(-50%);
  font-size: 11px; letter-spacing: .16em; color: #8a7a4a;
  background: rgba(6,10,18,.6); padding: 4px 14px; border-radius: 20px;
  max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.killfeed {
  position: absolute; top: 108px; right: 16px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 5px;
}
.kf {
  background: rgba(6,10,18,.75); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 10px; font-size: 11px; letter-spacing: .06em;
  animation: kfin .2s ease-out;
}
@keyframes kfin { from { opacity: 0; transform: translateX(14px); } }

.center-msg {
  position: absolute; top: 42%; left: 50%; transform: translate(-50%,-50%);
  font-size: 64px; font-weight: 800; letter-spacing: .06em; text-align: center;
  text-shadow: 0 0 40px rgba(40,226,255,.6); pointer-events: none;
}
.center-msg .cm-sub {
  font-size: 15px; font-weight: 600; color: #9fb4c4; letter-spacing: .14em;
  margin-top: 10px; text-shadow: none; line-height: 1.8; max-width: 60vw;
}

/* last life: the whole screen breathes red */
#screen-game.danger::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  box-shadow: inset 0 0 130px rgba(255,90,77,.38);
  animation: dangerPulse 1.05s infinite alternate;
}
@keyframes dangerPulse { from { opacity: .4; } to { opacity: 1; } }

.netstat { position: absolute; bottom: 8px; right: 12px; font-size: 10px; color: #3a4a5c; letter-spacing: .1em; }

/* ── overlays ───────────────────────────────────────────────────────── */
.overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(3,5,10,.86); backdrop-filter: blur(6px);
}
.overlay.show { display: flex; }
.overlay-inner { width: min(680px, calc(100vw - 32px)); text-align: center; }
.overlay h2 { font-size: 15px; letter-spacing: .34em; color: var(--muted); margin: 0 0 22px; font-weight: 400; }
.win-name { font-size: 58px; font-weight: 800; letter-spacing: .04em; margin-bottom: 6px; }
.win-stake {
  font-size: 22px; line-height: 1.5; color: #ffe9a8; margin: 20px auto 28px;
  border: 1px solid #4a3f1c; background: rgba(60,48,12,.2); border-radius: 10px; padding: 20px;
}

/* scoring readouts */
.pos { color: #7dffc4; }
.neg { color: #ff8a7a; }
.bounty {
  background: rgba(255,194,62,.16); border: 1px solid #6b551d; color: #ffc23e;
  border-radius: 4px; padding: 0 5px; font-size: 9px; letter-spacing: .12em;
}
.legend {
  display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center;
  margin: 0 0 18px; font-size: 11px; color: var(--muted); letter-spacing: .04em;
}
.legend b { margin-right: 5px; }
.rarity-list li { line-height: 1.9; }

.board { width: 100%; border-collapse: collapse; margin: 0 auto 26px; }
.board th { font-size: 10px; letter-spacing: .18em; color: var(--muted); font-weight: 400; padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); }
.board th:first-child, .board td:first-child { text-align: left; }
.board td { padding: 11px 10px; text-align: right; font-size: 16px; border-bottom: 1px solid #101823; }
.board td.nm { font-size: 15px; letter-spacing: .08em; }
.board .lead td { background: rgba(40,226,255,.05); }

.overlay .btn { pointer-events: auto; }
.overlay .row { justify-content: center; }
.overlay .row .btn { flex: 0 1 220px; }

/* ── touch ──────────────────────────────────────────────────────────── */
.touch { position: absolute; inset: auto 0 0; height: 190px; pointer-events: none; }
.stick {
  position: absolute; left: 22px; bottom: 22px; width: 132px; height: 132px;
  border: 1px solid #1e2c3d; border-radius: 50%; background: rgba(10,16,26,.5);
  pointer-events: auto; touch-action: none;
}
.stick-nub {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(40,226,255,.28); border: 1px solid var(--accent);
}
.tbtns { position: absolute; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.tbtn {
  pointer-events: auto; touch-action: none;
  background: rgba(16,24,35,.8); border: 1px solid #263447; color: var(--ink);
  border-radius: 12px; padding: 12px 18px; font-family: var(--mono); font-size: 12px; letter-spacing: .12em;
}
.tbtn.fire { width: 108px; height: 76px; font-size: 15px; background: rgba(60,16,30,.8); border-color: #7a2545; }
.tbtn.held { background: rgba(40,226,255,.25); border-color: var(--accent); }

@media (max-width: 760px) {
  .center-msg { font-size: 40px; }
  .win-name { font-size: 38px; }
  .timer { font-size: 32px; min-width: 70px; }
  .chip { min-width: 84px; padding: 5px 8px; }
  .chip .sc { font-size: 17px; }
  .killfeed { display: none; }
}
.survivor { font-size:14px; color:#7dffc4; margin:0 0 14px; letter-spacing:.06em; }
.chip .lives .spent { opacity: .3; }
.chip .lives .out { color: #ff5a4d; letter-spacing: .12em; }
