/* SKYBONK! big-screen HUD — full-res HTML over the pixelated canvas (§3.2, §6). */

@font-face {
  font-family: 'Press Start 2P';
  src: url('/fonts/press-start-2p.woff2') format('woff2');
  font-display: block;
}
@font-face {
  font-family: 'VT323';
  src: url('/fonts/vt323.woff2') format('woff2');
  font-display: block;
}

:root {
  --ink: #2A1E3F;
  --cream: #FFF3D6;
  --mint: #BDE8CA;
  --sky: #4FC4E8;
  --danger: #FF4F64;
  --gold: #FFD24A;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: var(--ink); font-family: 'VT323', monospace; color: var(--cream); }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

kbd {
  font: inherit; font-size: .75em;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,243,214,.4);
  border-radius: 4px; padding: 0 6px; margin-left: 6px;
}

/* ---------------- LOBBY ---------------- */
.panel {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3vh;
}
.hidden { display: none !important; }

.logo {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(28px, 6vw, 72px);
  color: var(--cream);
  text-shadow: 0 6px 0 var(--ink), 0 10px 0 rgba(0,0,0,.3);
  display: flex; gap: .08em;
}
.logo span { display: inline-block; animation: letterbounce 1.6s ease-in-out infinite; }
.logo span:nth-child(2) { animation-delay: .08s; }
.logo span:nth-child(3) { animation-delay: .16s; }
.logo span:nth-child(4) { animation-delay: .24s; }
.logo span:nth-child(5) { animation-delay: .32s; }
.logo span:nth-child(6) { animation-delay: .40s; }
.logo span:nth-child(7) { animation-delay: .48s; }
.logo span:nth-child(8) { animation-delay: .56s; }
.logo .g { color: var(--gold); }
.logo .x { color: var(--danger); }
@keyframes letterbounce { 0%,100% { transform: translateY(0); } 30% { transform: translateY(-.22em) rotate(-4deg); } }

.lobby-grid { display: flex; gap: 4vw; align-items: center; }

.join-panel {
  background: rgba(42, 30, 63, .92);
  border: 4px solid var(--cream);
  border-radius: 18px;
  padding: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 10px 0 rgba(0,0,0,.35);
}
#qr { width: clamp(140px, 20vw, 260px); image-rendering: pixelated; border-radius: 8px; border: 4px solid var(--cream); }
.code {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(22px, 3.4vw, 44px);
  letter-spacing: .35em; margin-left: .35em;
  color: var(--gold);
}
.joinurl { font-size: clamp(14px, 1.6vw, 22px); color: var(--mint); }
.scanhint { font-size: clamp(14px, 1.5vw, 20px); opacity: .7; }

.slots { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.slot {
  width: clamp(150px, 17vw, 240px);
  background: rgba(42, 30, 63, .85);
  border: 3px dashed rgba(255,243,214,.35);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: clamp(16px, 1.8vw, 26px);
  min-height: 58px;
}
.slot.filled { border-style: solid; border-color: var(--c); }
.slot .dot {
  width: 26px; height: 26px; flex: none;
  background: var(--c, #555); border: 3px solid var(--ink); border-radius: 50% 50% 44% 44%;
  position: relative;
}
.slot.filled .dot::before, .slot.filled .dot::after {
  content: ''; position: absolute; top: 28%; width: 22%; height: 22%;
  background: #fff; border-radius: 50%;
}
.slot.filled .dot::before { left: 18%; }
.slot.filled .dot::after { right: 18%; }
.slot .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .rdy { color: var(--mint); }
.slot .bot { opacity: .65; font-size: .8em; }
.slot.empty { color: rgba(255,243,214,.4); justify-content: center; }

.lobby-actions { display: flex; gap: 18px; }
.lobby-actions button {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(12px, 1.4vw, 18px);
  color: var(--cream); background: #4a3a6e;
  border: 3px solid var(--ink); border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 6px 0 rgba(0,0,0,.4);
  cursor: pointer;
}
.lobby-actions button.gold { background: var(--gold); color: var(--ink); }
.lobby-actions button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.4); }
.lobby-actions button:disabled { filter: grayscale(.8) brightness(.6); cursor: default; }
.game-hint { font-size: clamp(11px, 1.15vw, 15px); color: var(--cream); opacity: .55; margin-top: 8px; letter-spacing: .03em; }
.lobby-note { font-size: clamp(14px, 1.6vw, 22px); color: var(--mint); min-height: 1.4em; }

/* ---------------- BATTLE CHIPS ---------------- */
#chips {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px;
  max-width: calc(100vw - 2 * clamp(70px, 9vw, 130px)); /* keep clear of Sunny */
}
#chips.dense { gap: 7px; }
#chips.dense .chip { font-size: clamp(12px, 1.2vw, 17px); padding: 3px 7px; gap: 5px; }
#chips.dense .chip .hp { width: 38px; }
#chips.dense .chip .dot { width: 13px; height: 13px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: rgba(42, 30, 63, .85);
  border: 3px solid var(--c);
  border-radius: 12px;
  padding: 4px 10px;
  font-size: clamp(14px, 1.6vw, 22px);
  transition: opacity .3s;
}
.chip .dot { width: 18px; height: 18px; background: var(--c); border: 2px solid var(--ink); border-radius: 50% 50% 44% 44%; }
.chip .pips { color: var(--gold); letter-spacing: 2px; font-size: .85em; }
.chip .hp { width: 54px; height: 8px; background: #120c20; border: 2px solid rgba(255,243,214,.5); border-radius: 3px; overflow: hidden; }
.chip .hp i { display: block; height: 100%; background: var(--c); transition: width .12s; }
.chip.dead { opacity: .35; filter: grayscale(.9); }
.chip .dc { color: var(--danger); }

#timer {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  font-size: clamp(18px, 2.2vw, 30px);
  color: var(--cream); text-shadow: 2px 2px 0 var(--ink);
}
#timer.sudden { color: var(--danger); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }

/* ---------------- BONKRACE placing board ---------------- */
#raceplaces {
  position: absolute; top: clamp(120px, 17vh, 150px); right: clamp(12px, 2vw, 24px);
  display: none; flex-direction: column; gap: 6px; align-items: flex-end;
}
#raceplaces .rp {
  display: flex; align-items: center; gap: 8px;
  background: rgba(42, 30, 63, .85);
  border: 3px solid var(--c);
  border-radius: 10px; padding: 3px 10px;
  font-size: clamp(14px, 1.5vw, 20px);
  transition: opacity .3s, transform .2s;
}
#raceplaces .rp b { color: var(--gold); font-family: 'Press Start 2P', monospace; font-size: .7em; min-width: 2.4em; }
#raceplaces .rp .nm { color: var(--c); }
#raceplaces .rp .pips { color: var(--gold); letter-spacing: 1px; font-size: .8em; }
#raceplaces .rp.out { opacity: .35; filter: grayscale(.85); transform: scale(.94); }

/* ---------------- BONKBUSTERS wave/lives chip ---------------- */
#busterschip {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 12px;
  background: rgba(42, 30, 63, .85);
  border: 3px solid var(--gold); border-radius: 12px;
  padding: 6px 16px;
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(13px, 1.5vw, 20px);
}
#busterschip .wv { color: var(--gold); }
#busterschip .sep { opacity: .5; }
#busterschip .lv { color: var(--danger); letter-spacing: 1px; }
#busterschip.low { border-color: var(--danger); animation: blink .5s steps(2) infinite; }

/* BONKBUSTERS high-score banner (v0.12 §4) — the party's trophy shelf; lobby + ceremony */
#bustersbest {
  position: absolute; top: 62px; left: 50%; transform: translateX(-50%);
  z-index: 6; text-align: center; white-space: nowrap;
  background: rgba(42, 30, 63, .85);
  border: 3px solid var(--gold); border-radius: 10px;
  padding: 5px 14px;
  color: var(--gold);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(10px, 1.15vw, 15px);
  text-shadow: 2px 2px 0 var(--ink);
}
#bustersbest.hidden { display: none; }
#bustersbest.record {
  color: #fff; border-color: #fff; background: rgba(214, 40, 90, .9);
  animation: recordpulse .5s ease-in-out infinite alternate;
}
@keyframes recordpulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.08); } }

/* ---------------- ANNOUNCER ---------------- */
#announcer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#card {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(30px, 7vw, 90px);
  color: var(--gold);
  text-shadow: 0 .08em 0 var(--ink), 0 .16em 0 rgba(0,0,0,.35);
  opacity: 0; transform: scale(.3);
  text-align: center; line-height: 1.35;
  white-space: pre-line;
}
#card.show { animation: cardpop .45s cubic-bezier(.2, 2.2, .4, 1) forwards; }
#card.danger { color: var(--danger); }
@keyframes cardpop { to { opacity: 1; transform: scale(1); } }

#sunny {
  position: absolute; top: 3vh; right: 3vw;
  width: clamp(54px, 7vw, 100px); aspect-ratio: 1;
  background: radial-gradient(circle, var(--gold) 58%, transparent 59%);
  transition: transform .15s;
}
#sunny i {
  position: absolute; inset: 0;
  background: conic-gradient(var(--gold) 0 8deg, transparent 8deg 45deg, var(--gold) 45deg 53deg, transparent 53deg 90deg, var(--gold) 90deg 98deg, transparent 98deg 135deg, var(--gold) 135deg 143deg, transparent 143deg 180deg, var(--gold) 180deg 188deg, transparent 188deg 225deg, var(--gold) 225deg 233deg, transparent 233deg 270deg, var(--gold) 270deg 278deg, transparent 278deg 315deg, var(--gold) 315deg 323deg, transparent 323deg);
  border-radius: 50%;
  animation: sunspin 14s linear infinite;
}
#sunny::after {
  content: ''; position: absolute; inset: 30%;
  background:
    radial-gradient(circle at 32% 40%, var(--ink) 12%, transparent 13%),
    radial-gradient(circle at 68% 40%, var(--ink) 12%, transparent 13%),
    radial-gradient(circle at 50% 68%, transparent 28%, var(--ink) 29% 40%, transparent 41%);
}
#sunny.yell { transform: scale(1.25) rotate(-8deg); }
@keyframes sunspin { to { transform: rotate(360deg); } }

/* ---------------- SCORE STRIP ---------------- */
#scorestrip {
  position: absolute; bottom: 8vh; left: 50%; transform: translateX(-50%) translateY(200%);
  opacity: 0; pointer-events: none;
  display: flex; gap: 16px;
  background: rgba(42, 30, 63, .92);
  border: 4px solid var(--cream); border-radius: 16px;
  padding: 12px 22px;
  font-size: clamp(18px, 2.4vw, 32px);
  transition: transform .35s cubic-bezier(.2, 1.6, .4, 1);
}
#scorestrip.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#scorestrip .entry { display: flex; align-items: center; gap: 8px; }
#scorestrip .entry b { color: var(--c); }
#scorestrip .pips { color: var(--gold); }

/* ---------------- PODIUM ---------------- */
#podiumUI { justify-content: flex-start; padding-top: 6vh; }
#podTitle {
  font-family: 'Press Start 2P', monospace;
  white-space: pre-line;
  font-size: clamp(20px, 4vw, 52px);
  color: var(--gold);
  text-shadow: 0 .1em 0 var(--ink);
  animation: letterbounce 1.4s ease-in-out infinite;
  text-align: center; line-height: 1.6;
}
#awards { margin-top: 2vh; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.award {
  background: rgba(42, 30, 63, .92);
  border: 3px solid var(--gold); border-radius: 12px;
  padding: 6px 18px; font-size: clamp(15px, 2vw, 26px);
  opacity: 0; transform: translateX(40px);
  animation: awardin .5s cubic-bezier(.2, 1.7, .4, 1) forwards;
}
.award .ae { font-size: 1.2em; margin-right: 6px; }
.award b { color: var(--gold); }
.award i { color: var(--mint); font-style: normal; opacity: .85; }
@keyframes awardin { to { opacity: 1; transform: translateX(0); } }

#podHint { margin-top: 2vh; font-size: clamp(16px, 2vw, 26px); color: var(--mint); }

/* ---------------- TRAINING ---------------- */
#trainingUI {
  position: absolute; right: 2vw; top: 50%; transform: translateY(-50%);
  background: rgba(42, 30, 63, .92);
  border: 4px solid var(--cream); border-radius: 16px;
  padding: 18px 22px;
  font-size: clamp(16px, 1.8vw, 24px);
  max-width: min(34vw, 380px);
}
#trainingUI h3 { font-family: 'Press Start 2P', monospace; font-size: clamp(12px, 1.3vw, 18px); color: var(--gold); margin-bottom: 12px; }
#checklist { list-style: none; }
#checklist li { padding: 3px 0; opacity: .75; }
#checklist li::before { content: '☐ '; color: var(--mint); }
#checklist li.done { opacity: 1; color: var(--mint); text-decoration: none; }
#checklist li.done::before { content: '✔ '; }
#checklist li.done.fresh { animation: tickpop .4s cubic-bezier(.2, 2.2, .4, 1); }
@keyframes tickpop { 0% { transform: scale(1.25); } }
.trainhint { margin-top: 12px; font-size: .8em; opacity: .65; }

/* ---------------- NAME TAGS ---------------- */
#nametags { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.nametag {
  position: absolute;
  font-size: clamp(15px, 1.7vw, 24px);
  color: var(--c);
  text-shadow: 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink);
  transform: translate(-50%, -100%);
  letter-spacing: 1px;
  transition: opacity .4s;
}
.nametag.you { font-weight: bold; }
.nametag .dummy { opacity: .7; font-size: .8em; }

/* ---------------- POPUPS (damage numbers) ---------------- */
#popups { position: absolute; inset: 0; overflow: hidden; }
.pop {
  position: absolute;
  font-size: clamp(28px, 3.6vw, 54px);
  font-weight: bold;
  color: var(--c, #fff);
  text-shadow: 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink);
  transform: translate(-50%, -50%);
  animation: poparc .7s ease-out forwards;
}
.pop.big { font-size: clamp(38px, 5vw, 72px); color: var(--gold); }
.pop.heal { color: var(--mint); }
@keyframes poparc {
  0% { opacity: 0; translate: 0 10px; scale: .4; }
  15% { opacity: 1; scale: 1.25; }
  30% { scale: 1; }
  100% { opacity: 0; translate: 0 -46px; scale: .9; }
}

/* ---------------- FLASH & SOUND ---------------- */
#whiteflash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#whiteflash.go { animation: wf .12s ease-out; }
@keyframes wf { 0% { opacity: .22; } 100% { opacity: 0; } }

/* ---------------- REPLAY ---------------- */
#replayUI { position: absolute; inset: 0; pointer-events: none; }
#replayUI.hidden { display: none; }
#replayUI .bar { position: absolute; left: 0; right: 0; height: 12vh; background: var(--ink); }
#replayUI .bar.top { top: 0; }
#replayUI .bar.bottom { bottom: 0; }
#replayStamp {
  position: absolute; top: calc(12vh + 14px); left: 24px;
  font-family: 'Press Start 2P', monospace; font-size: clamp(12px, 1.6vw, 22px);
  color: var(--danger); text-shadow: 2px 2px 0 var(--ink);
  animation: blink .6s steps(2) infinite;
}

#gaspflash {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 200px 60px var(--danger);
}
#gaspflash.go { animation: gaspf .5s ease-out; }
@keyframes gaspf { 0% { opacity: .7; } 100% { opacity: 0; } }

/* BONKRACE elimination-line warning: a red screen-edge vignette pulse (§5) */
#racewarn {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 160px 40px var(--danger);
}
#racewarn.go { animation: racewarn .55s ease-out; }
@keyframes racewarn { 0% { opacity: 0; } 30% { opacity: .55; } 100% { opacity: 0; } }

#soundhint {
  position: absolute; bottom: 12px; right: 16px;
  font-size: clamp(13px, 1.4vw, 18px);
  opacity: .55;
}
#soundhint.off { display: none; }

/* v1.0 cloud relay: connection trouble is visible in every phase, not just the lobby */
#netbanner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-family: 'Press Start 2P', monospace; font-size: clamp(11px, 1.3vw, 17px);
  color: var(--ink); background: var(--gold);
  border: 3px solid var(--ink); border-radius: 12px; padding: 10px 16px;
  box-shadow: 0 5px 0 rgba(0,0,0,.35); z-index: 50; white-space: nowrap;
  animation: blink 1s steps(2) infinite;
}
#netbanner.dead { background: var(--danger); color: var(--cream); animation: none; }
#netbanner.hidden { display: none; }
