html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #0E2240;
  color: #F5F9FF;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; background: #F5F9FF; display: block; }
#overlay { position: fixed; inset: 0; pointer-events: none; }

/* Lobby: navy panel on the left 40%, player cards on the right */
#lobby { position: absolute; inset: 0; }
#lobbyPanel {
  position: absolute; left: 0; top: 0; bottom: 0; width: 40%;
  box-sizing: border-box;
  background: rgba(14, 34, 64, 0.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.2vh; padding: 3vh 2vw; text-align: center;
}
#lobbyPanel h1 { margin: 0; font-size: clamp(40px, 7vh, 80px); letter-spacing: 0.04em; color: #3FA9F5; }
#lobbyPanel .sub { margin: 0; font-size: clamp(18px, 2.6vh, 28px); opacity: 0.85; }
#qrBox { background: #fff; border-radius: 20px; padding: 16px; line-height: 0; }
#qr { width: clamp(300px, 34vh, 440px); height: clamp(300px, 34vh, 440px); display: block; }
#roomCode { font-size: 96px; font-weight: 800; letter-spacing: 0.18em; padding-left: 0.18em; line-height: 1; }
#joinUrl { font-size: clamp(14px, 2vh, 22px); opacity: 0.75; word-break: break-all; }
.hint { margin-top: 1vh; font-size: clamp(14px, 2vh, 20px); opacity: 0.6; }

#playerCards {
  position: absolute; left: 40%; right: 0; top: 0; bottom: 0; box-sizing: border-box;
  padding: 5vh 3vw; display: grid; align-content: start; gap: 2vh 1.5vw;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  overflow: hidden;
}
.card {
  display: flex; align-items: center; gap: 12px;
  background: rgba(14, 34, 64, 0.88);
  border-left: 14px solid var(--player-color, #3FA9F5);
  border-radius: 14px; padding: 18px 20px;
  font-size: clamp(22px, 3.4vh, 36px); font-weight: 700;
  transition: opacity 0.4s;
}
.card-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-state { font-size: 0.5em; font-weight: 500; opacity: 0.9; }
.card.disconnected { opacity: 0.4; }

.card-keys { display: flex; gap: 6px; }
.key { font-size: 0.6em; opacity: 0.25; transition: opacity 0.05s; }
.key.on { opacity: 1; color: #FFD166; }

#debug {
  position: fixed; right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.75); color: #fff;
  font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 8px 10px; border-radius: 8px;
  min-width: 190px; pointer-events: none; z-index: 10;
}
#debug[hidden] { display: none; }
.dbg-row { display: flex; gap: 6px; align-items: center; }
.dbg-row.off { opacity: 0.45; }
.dbg-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.dbg-key { width: 16px; text-align: center; border-radius: 3px; background: #333; color: #777; }
.dbg-key.on { background: #FFD166; color: #000; }

[hidden] { display: none !important; }
#hud {
  position: absolute; top: 14px; left: 18px; display: flex; gap: 18px;
  background: rgba(255, 255, 255, 0.85); color: #0E2240; border-radius: 999px;
  padding: 8px 20px; font-size: 24px; font-weight: 800;
}

/* Round and match results */
.results {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(920px, 92vw); max-height: 94vh; box-sizing: border-box; overflow: hidden;
  background: rgba(14, 34, 64, 0.95); color: #F5F9FF; border-radius: 24px;
  padding: 3vh 3vw; text-align: center;
}
.results h2 { margin: 0 0 1.5vh; font-size: clamp(30px, 5.5vh, 56px); color: #3FA9F5; letter-spacing: 0.03em; }
.results table { width: 100%; border-collapse: collapse; font-size: clamp(20px, 3.4vh, 36px); }
.results td { padding: 0.8vh 10px; text-align: left; }
.results tr { border-bottom: 1px solid rgba(255, 255, 255, 0.12); }
.c-place { width: 2.2em; text-align: center !important; }
.c-name { font-weight: 700; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-icon { width: 2em; text-align: center !important; }
.c-points { color: #FFD166; font-weight: 800; text-align: right !important; width: 3em; }
.c-total { text-align: right !important; opacity: 0.9; width: 4.5em; }
.dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; }
.results .foot { margin: 2vh 0 0; font-size: clamp(16px, 2.4vh, 26px); opacity: 0.75; }

#podium { display: flex; align-items: flex-end; justify-content: center; gap: 1.5vw; margin: 1vh 0 2vh; }
.block {
  width: clamp(130px, 17vw, 230px); border-radius: 14px 14px 0 0; padding: 1.2vh 8px 1.4vh;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 0.3vh;
  color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); box-sizing: border-box; line-height: 1.15;
}
/* min-height, not height: a long name or short window must never clip the text */
.block.place-1 { min-height: 26vh; }
.block.place-2 { min-height: 20vh; }
.block.place-3 { min-height: 15vh; }
.b-place { font-size: clamp(26px, 4.4vh, 48px); }
.b-name { font-size: clamp(18px, 3vh, 32px); font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; box-sizing: border-box; }
.b-points { font-size: clamp(16px, 2.4vh, 26px); font-weight: 600; }
#mrTable { font-size: clamp(16px, 2.8vh, 30px); }

/* Mode picker in the lobby panel */
#modePick {
  margin: 10px 0 4px; padding: 10px 14px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.08); text-align: center;
}
#modeName { font-size: 24px; font-weight: 800; color: #7FC8FF; letter-spacing: -0.01em; }
#modeHint { font-size: 15px; opacity: 0.8; margin-top: 2px; }
#modePick .mode-keys { font-size: 13px; opacity: 0.55; margin-top: 6px; letter-spacing: 0.04em; }

/* Results arrive instead of appearing (V9). Delays are set per row in ui.js. */
#rrTable tr, #mrTable tr {
  animation: rowIn 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-26px); }
  to { opacity: 1; transform: none; }
}
/* The podium builds from the floor up, 3rd first, the winner last */
#podium .block {
  transform-origin: bottom center;
  animation: blockUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes blockUp {
  from { opacity: 0; transform: scaleY(0.2) translateY(30px); }
  to { opacity: 1; transform: none; }
}

/* How to play: the one thing a passer-by needs to understand the game (V8) */
#howTo {
  position: absolute; left: calc(40% + 24px); bottom: 24px;
  display: flex; gap: 26px; align-items: center;
  padding: 12px 22px; border-radius: 999px;
  background: rgba(14, 34, 64, 0.82); color: #F5F9FF;
  font-size: 22px; letter-spacing: -0.01em;
}
#howTo b { color: #7FC8FF; }
#howTo .danger b { color: #FF8A93; }

/* Cards pop in as people join, so the lobby visibly reacts to a new player */
.card { animation: cardIn 0.34s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

#soundHint {
  position: absolute; left: 14px; bottom: 12px; padding: 6px 14px; border-radius: 999px;
  background: rgba(14, 34, 64, 0.85); color: #F5F9FF; font-size: 16px; opacity: 0.9;
}

/* Small red pill while the host socket is down; the game keeps running locally */
#netPill {
  position: absolute; right: 14px; top: 14px; padding: 6px 14px; border-radius: 999px;
  background: #E63946; color: #FFFFFF; font-size: 16px; font-weight: 700; z-index: 20;
}

/* The server handed the room to a newer tab: this one is dead, say so loudly */
#takeover {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; text-align: center;
  background: #0E2240; color: #F5F9FF;
}
#takeover h2 { margin: 0; font-size: 48px; }
#takeover p { margin: 0; font-size: 24px; opacity: 0.8; }
