@font-face {
  font-family: 'Heebo';
  src: local('Heebo');
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0B1F3A;
  color: #fff;
  font-family: 'Heebo', 'Segoe UI', Arial, sans-serif;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* phone URL-bar safe; old webOS ignores it and keeps the vh above */
  padding: 5%;
}
.screen.active {
  display: flex;
}

/* ---------- Role chooser (small screens only) ---------- */
#screen-role.active {
  align-items: center;
  justify-content: center;
}
.role-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.role-wrap h1 { font-size: 32px; margin: 0; }
.role-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 20px 24px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.role-btn span { font-size: 14px; font-weight: 400; color: #B9C6E0; }
.role-btn:active { transform: scale(0.98); }
.role-btn-primary { background: #4BD37B; color: #06331A; border-color: transparent; }
.role-btn-primary span { color: #0A5B2E; }

/* ---------- Lobby ---------- */
#screen-lobby.active {
  align-items: stretch;
}
.lobby-wrap {
  display: flex;
  gap: 48px;
  width: 100%;
  height: 100%;
}
.lobby-left {
  flex: 1.2;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 12px;
}
.lobby-left > * { flex-shrink: 0; }
.lobby-left h1 {
  font-size: 56px;
  margin: 0 0 8px;
}
.lobby-left h1 .sub {
  font-size: 28px;
  color: #FFD23F;
}
.hint { font-size: 22px; color: #B9C6E0; margin: 0; }
.join-url { font-size: 32px; font-weight: 700; color: #3FA9FF; }
.room-code {
  font-size: 96px;
  font-weight: 800;
  letter-spacing: 16px;
  color: #FFD23F;
  background: rgba(255,255,255,0.06);
  border-radius: 24px;
  padding: 8px 32px;
}
.qr-wrap {
  background: #fff;
  padding: 12px;
  border-radius: 16px;
}
.qr-wrap img { display: block; width: 180px; height: 180px; }

.btn-start {
  margin-top: 16px;
  font-size: 32px;
  font-weight: 700;
  padding: 20px 48px;
  min-height: 44px;
  border: none;
  border-radius: 20px;
  background: #4BD37B;
  color: #06331A;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn-start:focus, .btn-start:hover { transform: scale(1.05); outline: 4px solid #fff; }
.btn-start:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.lobby-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.lobby-right h2 { font-size: 28px; margin: 0 0 12px; }
.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 26px;
  background: rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 10px 16px;
  border-inline-start: 8px solid var(--c, #fff);
}
.player-list .dot { font-size: 30px; }

.hof {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 2px solid rgba(255,255,255,0.15);
}
.hof h3 { font-size: 20px; margin: 0 0 8px; color: #FFD23F; }
.empty { list-style: none; color: #7A88A8; font-size: 18px; }
/* The empty-state row is a message, not a player card — drop the pill and the colour stripe. */
.player-list li.empty { background: none; border-inline-start: none; padding: 4px 0; justify-content: center; }
.hof ol { margin: 0; padding-inline-start: 24px; font-size: 20px; color: #DCE4F5; }

/* ---------- Countdown ---------- */
#screen-countdown.active {
  align-items: center;
  justify-content: center;
}
.countdown-num {
  font-size: 280px;
  font-weight: 800;
  color: #FFD23F;
  animation: pop 0.8s ease;
}
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Game ---------- */
#screen-game.active {
  padding: 0;
  align-items: center;
  justify-content: center;
  position: relative;
}
#game-canvas {
  background: linear-gradient(#7EC8F7, #BFE8FF);
}
.hud {
  position: absolute;
  top: 3%;
  inset-inline-start: 3%;
}
.timer {
  font-size: 40px;
  font-weight: 800;
  background: rgba(11,31,58,0.6);
  padding: 8px 20px;
  border-radius: 16px;
}
.scoreboard {
  position: absolute;
  top: 3%;
  inset-inline-end: 3%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(11,31,58,0.55);
  border-radius: 16px;
  padding: 12px 16px;
  min-width: 220px;
}
.scoreboard .row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 22px;
  font-weight: 600;
}
.scoreboard .row.dead { opacity: 0.45; }

.toast-layer {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  font-size: 30px;
  font-weight: 700;
  background: rgba(255,255,255,0.92);
  color: #0B1F3A;
  padding: 10px 24px;
  border-radius: 999px;
  animation: toast-in 2.4s ease forwards;
}
@keyframes toast-in {
  0% { opacity: 0; transform: translateY(20px); }
  10% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* ---------- End ---------- */
#screen-end.active {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  position: relative;
}
.end-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; z-index: 2; }
.end-wrap h1 { font-size: 48px; margin: 0; }
.podium {
  display: flex;
  align-items: flex-end;
  gap: 20px;
}
.podium .place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 24px;
  font-weight: 700;
  padding: 16px 20px;
  border-radius: 16px;
  background: rgba(255,255,255,0.08);
}
.podium .place.p1 { background: #FFD23F; color: #3A2A00; order: 2; min-height: 200px; justify-content: flex-end; }
.podium .place.p2 { order: 1; min-height: 150px; justify-content: flex-end; }
.podium .place.p3 { order: 3; min-height: 120px; justify-content: flex-end; }
.record-banner {
  font-size: 30px;
  font-weight: 800;
  color: #FFD23F;
  animation: pop 0.6s ease;
}
#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ---------- Rotate hint ---------- */
.rotate-hint {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 600;
  background: rgba(11,31,58,0.75);
  padding: 8px 16px;
  border-radius: 999px;
}

/* ---------- Phone / small-screen layout ----------
   The shared screen is normally a 16:9 TV. When it is a phone instead (or a tablet held
   portrait) the two-column lobby has nowhere to go, so it stacks and everything steps down a
   size. The canvas needs no rule here — resizeCanvas() already fits it to whatever box it gets. */
@media (max-width: 900px), (max-height: 500px) {
  .screen { padding: 16px; }

  .lobby-wrap {
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    align-items: center;
  }
  .lobby-left, .lobby-right {
    flex: none;
    width: 100%;
    align-items: center;
    text-align: center;
  }
  .lobby-left h1 { font-size: 26px; }
  .lobby-left h1 .sub { font-size: 18px; }
  .hint { font-size: 14px; }
  .join-url { font-size: 18px; }
  .room-code { font-size: 44px; letter-spacing: 8px; padding: 4px 16px; }
  .qr-wrap { padding: 8px; }
  .qr-wrap img { width: 108px; height: 108px; }
  .btn-start { margin-top: 8px; font-size: 20px; padding: 14px 28px; }

  .lobby-right h2 { font-size: 20px; margin-bottom: 8px; }
  .player-list { max-height: 30vh; width: 100%; }
  .player-list li { font-size: 18px; padding: 8px 12px; }
  .hof { margin-top: 12px; padding-top: 12px; width: 100%; }
  .hof h3 { font-size: 16px; }
  .hof ol { font-size: 15px; }

  .countdown-num { font-size: 120px; }

  .timer { font-size: 18px; padding: 4px 12px; }
  /* 10 rows would swallow a phone-sized canvas; rows are score-sorted so the leaders survive. */
  .scoreboard { min-width: 0; padding: 6px 10px; gap: 2px; max-height: 46%; overflow: hidden; }
  .scoreboard .row { font-size: 13px; gap: 8px; }
  .toast { font-size: 16px; padding: 6px 16px; }

  .end-wrap h1 { font-size: 28px; }
  .podium { gap: 8px; }
  .podium .place { font-size: 16px; padding: 10px 12px; }
  .podium .place.p1 { min-height: 120px; }
  .podium .place.p2 { min-height: 92px; }
  .podium .place.p3 { min-height: 72px; }
  .record-banner { font-size: 20px; }
}

/* Portrait on a phone gives the 16:9 canvas a tiny letterbox — nudge them to turn it. */
@media (max-width: 900px) and (orientation: portrait) {
  #screen-game.active .rotate-hint { display: block; }
}

/* ---------- 720p TVs ----------
   A five-year-old LG reports a 1280x720 viewport, where the full-size host column does not fit and
   the start button gets squashed to its min-height with the label spilling out. Step the column
   down so the whole thing clears the bottom with room to spare. */
@media (max-height: 800px) and (min-width: 901px) {
  .lobby-left h1 { font-size: 36px; }
  .lobby-left h1 .sub { font-size: 20px; }
  .hint { font-size: 18px; }
  .join-url { font-size: 24px; }
  .room-code { font-size: 64px; letter-spacing: 12px; padding: 4px 24px; }
  .qr-wrap img { width: 130px; height: 130px; }
  .btn-start { font-size: 24px; padding: 14px 32px; margin-top: 8px; }
  .lobby-right h2 { font-size: 22px; }
  .player-list li { font-size: 20px; padding: 8px 12px; }
  .player-list .dot { font-size: 24px; }
  .hof h3 { font-size: 18px; }
  .hof ol, .empty { font-size: 17px; }
}

/* ---------- Wide but short (phone in landscape, or a short browser window) ----------
   The stacked small-screen layout runs 605px tall, which pushes the start button below a 390px
   landscape viewport. Go back to two columns and drop the explanatory lines, which are the least
   load-bearing thing on screen once the code and the QR are both visible. */
@media (max-height: 500px) and (min-width: 600px) {
  .lobby-wrap { flex-direction: row; gap: 24px; }
  .lobby-left, .lobby-right { width: auto; flex: 1; }
  .lobby-left .hint { display: none; }
  .lobby-left h1 { font-size: 22px; margin-bottom: 0; }
  .room-code { font-size: 36px; letter-spacing: 6px; }
  .qr-wrap img { width: 88px; height: 88px; }
  .btn-start { font-size: 18px; padding: 10px 24px; }
  .player-list { max-height: 40vh; }
  .hof { display: none; }
}

/* ---------- Elimination round furniture ---------- */
.scoreboard .row.head {
  justify-content: center;
  color: #FFD23F;
  font-size: 18px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 4px;
  margin-bottom: 2px;
}
.podium .survived { font-size: 14px; font-weight: 400; opacity: 0.7; }
.break-label { font-size: 26px; font-weight: 700; color: #FFD23F; }
.end-actions { display: flex; gap: 16px; align-items: center; }
.btn-secondary {
  font-size: 20px;
  font-weight: 700;
  padding: 14px 28px;
  min-height: 44px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  background: transparent;
  color: #fff;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.btn-secondary:focus, .btn-secondary:hover { transform: scale(1.05); outline: 3px solid #fff; }
@media (max-width: 900px), (max-height: 500px) {
  .break-label { font-size: 18px; }
  .btn-secondary { font-size: 16px; padding: 10px 20px; }
  .scoreboard .row.head { font-size: 13px; }
}
