* { box-sizing: border-box; }

body {
  margin: 0;
  /* Exactly one screen: #app is centered on it and scaled to fit
     (fitToScreen in host.js), even when its unscaled layout is taller. */
  height: 100vh;
  overflow: hidden;
  background: #12121f;
  color: #f5f5f7;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 32px;
}

/* #app is laid out for a DESIGN_W-wide screen and scaled to the display
   (fitToScreen in host.js): its layout width is the viewport in design px. */
#app {
  width: calc((100vw - 64px) / var(--ui-zoom, 1));
  max-width: 1100px;
  flex-shrink: 0;
  text-align: center;
  transform: scale(var(--ui-zoom, 1));
  transform-origin: center center;
}

.hidden { display: none !important; }
/* Elements that only exist in some themes (e.g. the battle arena) */
.theme-only { display: none; }
.screen { animation: screenIn 0.4s ease both; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

h1 { font-size: 2.6rem; margin-bottom: 24px; }

.lobby-grid {
  display: flex;
  gap: 48px;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.qr-box, .players-box {
  background: #1c1c2e;
  border-radius: 16px;
  padding: 24px 32px;
  min-width: 300px;
}

.qr-box img { width: 230px; height: 230px; background: #fff; border-radius: 8px; }
.join-url { opacity: 0.7; font-size: 0.9rem; word-break: break-all; }
.room-code { font-size: 1.8rem; font-weight: 700; letter-spacing: 4px; }

.players-box ul { list-style: none; padding: 0; margin: 0; text-align: left; }

/* Scrolling player list (see renderPlayers in host.js) */
.player-scroll { position: relative; }
#playerList {
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: none;
  padding-right: 2px;
}
#playerList::-webkit-scrollbar { display: none; }
#playerList li.newest { animation: playerJoin 0.6s ease both; box-shadow: inset 4px 0 0 #ff5c8a; }
@keyframes playerJoin {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: none; }
}
.scroll-more {
  display: block;
  height: 1.2em;
  line-height: 1.2em;
  font-size: 0.9rem;
  text-align: center;
  opacity: 0.7;
  visibility: hidden;
}
.scroll-more.on { visibility: visible; }

/* Wide layout (PC and TV, once scaled — see fitToScreen in host.js): QR ·
   players · settings side by side, so the whole lobby fits on one screen.
   Only a narrow window falls back to the stacked layout. */
html.wide #app:has(#screen-lobby:not(.hidden)) { max-width: 1400px; }
html.wide .lobby-grid {
  display: grid;
  grid-template-columns: auto minmax(260px, 320px) minmax(560px, 1fr);
  align-items: start;
  gap: 28px;
}
html.wide .lobby-setup .theme-box,
html.wide .lobby-setup .rounds-box { margin-bottom: 18px; }
html.wide .lobby-setup .round-column { max-width: none; }
@media (prefers-reduced-motion: reduce) {
  #playerList li.newest { animation: none; }
}
.players-box li {
  padding: 10px 14px;
  background: #2a2a44;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.auth-form { display: grid; gap: 12px; max-width: 420px; margin: 24px auto 0; text-align: left; }
.auth-form label { font-weight: 700; }
.auth-form input {
  font: inherit;
  font-size: 1.2rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid #3a3a5c;
  background: #1c1c2e;
  color: inherit;
}
.auth-form input:focus-visible { outline: 3px solid #ffd166; outline-offset: 2px; }
.auth-error { min-height: 1.4em; color: #ff8fa8; font-weight: 700; margin-top: 16px; }
.theme-box { margin-bottom: 28px; }
.theme-box h2 { margin: 0 0 12px; }
.theme-picker { display: inline-flex; gap: 8px; padding: 6px; border-radius: 14px; background: #1c1c2e; }
.theme-picker button {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
}
.theme-picker button[aria-checked="true"] { background: #ff5c8a; color: white; font-weight: 700; }
.theme-picker button:focus-visible { outline: 3px solid #ffd166; outline-offset: 2px; }
.rounds-box { margin-bottom: 28px; }
.rounds-box .hint { margin: 0 0 16px; font-size: 0.95rem; }
.drag-handle-hint { opacity: 0.8; }

.round-columns {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.round-column {
  background: #1c1c2e;
  border-radius: 16px;
  padding: 16px 18px;
  min-width: 280px;
  max-width: 340px;
  flex: 1;
}
.round-column h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  opacity: 0.7;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.round-dnd-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
  min-height: 48px;
}

.round-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #2a2a44;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 1.05rem;
  touch-action: none;
  user-select: none;
  position: relative;
}
.round-card.dragging {
  z-index: 1000;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  background: #35355a;
  pointer-events: none;
  margin: 0; /* fixed-position card, no flow margin needed */
}

.round-card-placeholder {
  border-radius: 10px;
  margin-bottom: 8px;
  border: 2px dashed #4a4a70;
  background: rgba(255, 255, 255, 0.03);
}

.drag-handle {
  cursor: grab;
  opacity: 0.5;
  font-size: 1.2rem;
  padding: 4px;
  touch-action: none;
}
.drag-handle:active { cursor: grabbing; }

.round-rank {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ff5c8a;
  color: white;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.round-card-label { flex: 1; }

.round-toggle-btn {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.7;
  padding: 4px 8px;
  touch-action: manipulation;
}
.round-toggle-btn:hover { opacity: 1; }

.team-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 1.1rem;
  opacity: 0.4;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  touch-action: manipulation;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.team-toggle:has(.team-toggle-input:checked) {
  opacity: 1;
  background: rgba(255, 92, 138, 0.25);
}
.team-toggle-input { width: 16px; height: 16px; accent-color: #ff5c8a; cursor: pointer; }

.round-dnd-list:empty::after {
  content: 'Vide';
  display: block;
  opacity: 0.4;
  font-size: 0.9rem;
  padding: 8px 0;
}

.btn-primary {
  font-size: 1.3rem;
  padding: 16px 40px;
  border: none;
  border-radius: 12px;
  background: #ff5c8a;
  color: white;
  cursor: pointer;
  touch-action: manipulation;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:active { transform: scale(0.97); }
.btn-secondary {
  display: block;
  margin: 18px auto 0;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
}
#playerList li.offline { opacity: 0.45; }

.round-progress { opacity: 0.6; font-size: 1.1rem; }

.timer-bar {
  width: 100%;
  max-width: 700px;
  height: 24px;
  background: #2a2a44;
  border-radius: 12px;
  margin: 32px auto;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff5c8a, #ffb15c);
  transform-origin: left;
  transition: width 0.1s linear, background 0.3s ease;
}
.timer-fill.low { background: #ff2d55; animation: pulse 0.5s ease infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.hint { font-size: 1.4rem; opacity: 0.8; }

.correct-answer { font-size: 1.6rem; margin-bottom: 24px; }

.leaderboard { max-width: 640px; margin: 0 auto 24px; text-align: left; }

/* --- Podium (top 3) ----------------------------------------------------- */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  margin-bottom: 28px;
  padding: 28px 12px 0;
  border-radius: 28px;
  background: radial-gradient(ellipse 80% 70% at 50% 100%, rgba(255, 179, 71, 0.18), transparent 70%);
}

.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 160px;
  opacity: 0;
  animation: podiumIn 0.5s ease both;
  position: relative;
}
.podium-slot.empty { opacity: 0.25; animation: none; }

.podium-info {
  margin-bottom: 10px;
  text-align: center;
  padding: 14px 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
}
.podium-slot.first .podium-info {
  background: linear-gradient(165deg, rgba(255, 224, 122, 0.28), rgba(255, 224, 122, 0.05));
  box-shadow: 0 0 22px rgba(255, 209, 102, 0.3);
}
.podium-slot.second .podium-info {
  background: linear-gradient(165deg, rgba(220, 220, 236, 0.22), rgba(220, 220, 236, 0.05));
}
.podium-slot.third .podium-info {
  background: linear-gradient(165deg, rgba(230, 168, 120, 0.24), rgba(230, 168, 120, 0.05));
}

.podium-medal {
  font-size: 2.6rem;
  line-height: 1;
  display: inline-block;
  animation: medalBounce 1.8s ease-in-out infinite;
}
.podium-slot.second .podium-medal { animation-delay: 0.2s; }
.podium-slot.third .podium-medal { animation-delay: 0.4s; }

.podium-slot.first::before,
.podium-slot.first::after {
  content: '✨';
  position: absolute;
  top: -6px;
  font-size: 1.4rem;
  animation: twinkle 1.6s ease-in-out infinite;
}
.podium-slot.first::before { left: 6px; animation-delay: 0.3s; }
.podium-slot.first::after { right: 6px; animation-delay: 0.9s; }

.podium-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin-top: 4px;
  overflow-wrap: break-word;
}
.podium-score {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #ffd166;
}
.podium-detail { display: block; font-size: 0.8rem; font-weight: 400; opacity: 0.75; }
.podium-slot.tied .podium-name { font-size: 1rem; margin-top: 6px; }
.podium-more { margin-top: 6px; font-size: 0.85rem; opacity: 0.7; }

.podium-bar {
  width: 100%;
  border-radius: 10px 10px 0 0;
  transform-origin: bottom;
  animation: barGrow 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: inherit;
  position: relative;
  overflow: hidden;
}
.podium-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.35) 45%, transparent 60%);
}
.podium-slot.first .podium-bar { height: 170px; background: linear-gradient(180deg, #ffe07a, #ffb703); box-shadow: 0 0 28px rgba(255, 209, 102, 0.45); }
.podium-slot.second .podium-bar { height: 120px; background: linear-gradient(180deg, #eef0ff, #b6bce0); box-shadow: 0 0 18px rgba(200, 205, 235, 0.3); }
.podium-slot.third .podium-bar { height: 90px; background: linear-gradient(180deg, #ffb37a, #d4823f); box-shadow: 0 0 18px rgba(255, 160, 90, 0.3); }
.podium-slot.empty .podium-bar { height: 70px; background: #2a2a44; box-shadow: none; }

@keyframes podiumIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes barGrow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}
@keyframes medalBounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(-6deg); }
}
@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* --- Ranks 4+ ------------------------------------------------------------ */

.rest-list { list-style: none; padding: 0; max-width: 520px; margin: 0 auto; }
.rest-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(90deg, rgba(255, 92, 138, 0.08), rgba(42, 42, 68, 0.9));
  padding: 10px 18px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 1.05rem;
  opacity: 0;
  animation: rowIn 0.4s ease both;
}
.rest-list li.closest {
  border-left: 4px solid #ffd166;
  background: linear-gradient(90deg, rgba(255, 209, 102, 0.16), rgba(42, 42, 68, 0.9));
}
.rest-rank {
  opacity: 0.8;
  font-weight: 700;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rest-name { flex: 1; display: flex; flex-wrap: wrap; gap: 2px 14px; }
.rest-player.more { opacity: 0.7; font-size: 0.9em; }
.rest-name small { opacity: 0.7; font-weight: 400; display: block; }
/* Team members sit on the team's line (a round end can list 6 teams). */
.rest-name .rest-player { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.rest-name .rest-player small { display: inline; }
#roundEndTitle .round-label { display: block; font-size: 0.5em; font-weight: 600; opacity: 0.8; margin-top: 4px; }
.rest-score { font-variant-numeric: tabular-nums; text-align: right; color: #ffd166; }
.rest-score .gap { display: block; opacity: 0.6; font-weight: 400; font-size: 0.8em; color: #f5f5f7; }

@keyframes rowIn {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 16px;
  opacity: 0.9;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* Round 1 is audio-only, so this player must stay hidden from view — but it
   must also stay genuinely on-screen at a normal size. A 1x1 iframe parked at
   -9999px looks, to YouTube/the browser, exactly like a hidden ad iframe, and
   playback silently never starts at all (not just muted — literally stuck at
   player state -1/unstarted). Instead: keep it on-screen at a real size, and
   visually hide it under an opaque cover element on top (#ytPlayerCover). */
#ytPlayerSlotHidden {
  position: fixed;
  bottom: 8px;
  right: 8px;
  width: 160px;
  height: 90px;
  overflow: hidden;
  z-index: 1;
}

#ytPlayerCover {
  position: fixed;
  bottom: 8px;
  right: 8px;
  width: 160px;
  height: 90px;
  background: #12121f;
  z-index: 2;
  pointer-events: none;
}

.yt-slot-visible {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
  margin: 0 auto 24px;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
/* YouTube briefly overlays the video title at the top of the player when it
   starts (and the title literally IS the answer for a "guess the title"
   round) — blur/cover that strip so it can't be read, for both the QCM
   visible slot and round 2's. */
.yt-slot-visible::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 22%;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.9) 45%, transparent 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: none;
  z-index: 5;
}
/* Bottom band: at start-up YouTube shows a "more videos" panel with another
   clip's thumbnail (often the same artist's face) and its logo along the
   bottom edge — blurred away like the title band at the top. */
.yt-veil-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 20%;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.9) 40%, transparent 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: none;
  z-index: 5;
}

/* Opt-in per playlist entry (maskBottomLeft): hides a broadcaster logo
   burnt into the bottom-left corner of some archive clips. */
.yt-slot-visible.mask-bottom-left::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 26%;
  height: 30%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  /* fade the blurred patch out towards the picture instead of a hard box */
  mask-image: radial-gradient(ellipse at 0% 100%, #000 55%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse at 0% 100%, #000 55%, transparent 100%);
  pointer-events: none;
  z-index: 5;
}
/* A percentage height only resolves against an ancestor with an explicit
   height — #ytPlayerMount (and its #ytPlayer child, before YT.Player swaps
   it for an iframe) were plain auto-height divs, so "height: 100%" on the
   iframe below had nothing real to resolve against and fell back toward its
   raw creation size. Give the whole wrapper chain 100%/100% so it actually
   reaches the iframe. */
.yt-slot-visible #ytPlayerMount,
.yt-slot-visible #ytPlayer {
  width: 100%;
  height: 100%;
}
/* !important: YT.Player also sets width/height as an inline style on the
   iframe it creates, which otherwise outranks this rule. */
.yt-slot-visible iframe {
  width: 100% !important;
  height: 100% !important;
  display: block;
  /* No hover controls (pause button, "more videos" panel that can show a
     title) and no accidental click-to-pause from the host's mouse. */
  pointer-events: none;
}
