/* Party Hub on the big screen (/host and /tv). Everything is sized to be read from the sofa:
   a big join code and QR on the left, a dedicated player area that fills up seat by seat,
   and one row of game tiles along the bottom. */

body.hub-host {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.hub-layout {
  display: grid;
  grid-template-columns: clamp(320px, 27vw, 540px) minmax(0, 1fr);
  /* One row exactly the window's height: nothing may push the page past the bottom */
  grid-template-rows: minmax(0, 1fr);
  height: 100%;
}

/* ------------------------------------------------------------------ Join panel */
.join-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  gap: clamp(1rem, 2.5vh, 2rem);
  padding: clamp(1.5rem, 4vh, 3rem) clamp(1.5rem, 2.5vw, 3rem);
  background: var(--surface);
  border-right: 1px solid var(--border);
  text-align: center;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: clamp(1.3rem, 1.6vw, 2rem);
  font-weight: 700;
}

.app-brand img {
  width: clamp(40px, 3vw, 60px);
  height: clamp(40px, 3vw, 60px);
  border-radius: 14px;
}

.join-step {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1.1rem, 1.4vw, 1.7rem);
  font-weight: 600;
}

.invite-qr-wrapper {
  flex-shrink: 0;
  box-sizing: border-box;
  width: min(100%, 52vh);
  aspect-ratio: 1 / 1;
  padding: clamp(10px, 1vw, 20px);
  background: #fff;
  border-radius: var(--radius-lg);
}

.invite-qr,
.invite-qr canvas,
.invite-qr img {
  width: 100% !important;
  height: 100% !important;
}

.party-code {
  font-size: clamp(3.5rem, 6.5vw, 8rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-right: -0.12em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.join-url {
  margin: -0.5rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.2vw, 1.4rem);
}

.party-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.copy-feedback {
  min-height: 1.2em;
  font-size: 0.95rem;
  color: var(--success);
}


/* ------------------------------------------------------------------ Main area */
/* Two fixed zones: players on top, games (the bigger one) along the bottom.
   Neither zone changes size when people join, so nothing jumps around. */
.hub-main {
  display: grid;
  position: relative;
  grid-template-rows: minmax(0, 2fr) minmax(0, 3fr);
  gap: clamp(1.25rem, 3.2vh, 2.5rem);
  min-height: 0;
  padding: clamp(1.5rem, 4vh, 3rem) clamp(1.5rem, 3vw, 3.5rem);
}

.hub-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem 1.5rem;
  flex-wrap: wrap;
  margin-bottom: clamp(0.8rem, 1.8vh, 1.4rem);
}

.hub-header h1 {
  margin: 0;
  font-size: clamp(2rem, 2.8vw, 3.4rem);
  font-weight: 800;
  line-height: 1.1;
}

.hub-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 2vw, 2.5rem);
  font-weight: 800;
  line-height: 1.1;
}

.hub-hint {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.2vw, 1.5rem);
}

.hub-hint strong {
  color: var(--text-primary);
}

.hub-host .phase-pill {
  margin-left: auto;
  align-self: center;
  font-size: clamp(1rem, 1.2vw, 1.5rem);
  padding: 0.5rem 1.2rem;
}

.error-banner {
  display: none;
  position: absolute;
  top: clamp(0.75rem, 1.5vh, 1.25rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  max-width: calc(100% - 3rem);
  padding: 0.9rem 1.2rem;
  border-radius: 12px;
  background: #2a1517;
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--danger);
  font-size: 1.2rem;
}

.error-banner[aria-hidden='false'] {
  display: block;
}

/* ------------------------------------------------------------------ Players */
.players-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.player-grid {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  /* host.js sizes the cards so they fill the whole area (see layoutPlayerGrid); cards on a
     short last row stretch to fill it. */
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: clamp(0.75rem, 1.2vw, 1.4rem);
}

.player-card,
.player-seat {
  position: relative;
  flex: 1 1 var(--card-width, 12rem);
  height: var(--card-height, auto);
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-lg);
  container-type: size;
}

/* Each player gets a card: big icon, big name. host.js sets --icon-size and --name-size from
   the card size, so they shrink as more players join. */
.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35em;
  padding: calc(var(--name-size, 1.6rem) * 0.4) calc(var(--name-size, 1.6rem) * 0.5);
  background: var(--surface-2);
  border: 2px solid var(--border-strong);
  text-align: center;
}

.player-icon {
  min-height: 0;
  font-size: var(--icon-size, 4rem);
  line-height: 1;
}

.player-name {
  /* overflow: hidden would otherwise let a short card squeeze the name to nothing */
  flex-shrink: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--name-size, 1.6rem);
  font-weight: 800;
  line-height: 1.15;
}

.player-status {
  color: var(--muted);
  font-size: calc(var(--name-size, 1.6rem) * 0.55);
  font-weight: 600;
}

.player-card.offline {
  background: var(--surface);
  border-style: dashed;
}

.player-card.offline .player-icon,
.player-card.offline .player-name {
  opacity: 0.45;
}

/* Sips still owed: big and bright between games, the time to drink them. */
.player-owed {
  position: absolute;
  top: 0.4em;
  right: 0.4em;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  background: #f59e0b;
  color: #1c1305;
  font-size: clamp(0.85rem, calc(var(--name-size, 1.6rem) * 0.8), 2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.55);
  animation: owe-pulse 1.4s ease-in-out infinite;
}

@keyframes owe-pulse {
  50% { transform: scale(1.12); }
}

.debt-call {
  margin-left: 0.6em;
  padding: 0.3em 0.9em;
  border-radius: 999px;
  background: #f59e0b;
  color: #1c1305;
  font-size: clamp(1rem, 1.3vw, 1.8rem);
  font-weight: 800;
  white-space: nowrap;
  animation: owe-pulse 1.4s ease-in-out infinite;
}

.debt-call[hidden] {
  display: none;
}

/* The vote line under "Pick a game": a countdown once the vote is decided. */
.games-section .hub-hint.counting {
  padding: 0.25em 0.8em;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--text-primary);
  font-size: clamp(1.1rem, 1.4vw, 2rem);
}

/* Empty seats show where the next players will appear */
.player-seat {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5em;
  border: 2px dashed rgba(255, 255, 255, 0.1);
  color: var(--muted);
  font-size: clamp(0.8rem, calc(var(--name-size, 1.6rem) * 0.8), 1.9rem);
  font-weight: 600;
  text-align: center;
}

.player-seat.next {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  color: var(--accent);
  animation: seat-breathe 2.4s ease-in-out infinite;
}

.player-seat.next.full {
  border-color: rgba(255, 255, 255, 0.12);
  background: none;
  color: var(--muted);
  animation: none;
}

.player-card.just-joined {
  animation: player-pop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) both,
    player-glow 2.4s ease-out both;
}

@keyframes player-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes player-glow {
  from {
    border-color: var(--accent);
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent);
  }
  to {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 0 transparent;
  }
}

@keyframes seat-breathe {
  50% {
    border-color: color-mix(in srgb, var(--accent) 80%, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .player-card.just-joined,
  .player-owed,
  .debt-call,
  .player-seat.next {
    animation: none;
  }
}

/* ------------------------------------------------------------------ Games */
.games-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.games-grid {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-columns: repeat(var(--game-columns, 5), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: clamp(0.75rem, 1.2vw, 1.4rem);
  padding: 8px;
  margin: -8px;
}

.game-card {
  position: relative;
  /* A big icon over the name. host.js sizes the icon from the card (--game-icon-size), so it never
     runs into the name however many games there are. */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.4rem, 1.4vh, 1.1rem);
  container-type: inline-size;
  min-width: 0;
  min-height: 0;
  padding: clamp(0.8rem, 1.2vw, 1.4rem) clamp(0.6rem, 0.8vw, 1.1rem);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text-primary);
  font-weight: 400;
  text-align: center;
  overflow: hidden;
}

@media (hover: hover) {
  .game-card:hover {
    filter: none;
    border-color: var(--accent);
  }
}

.game-card .game-icon {
  flex-shrink: 0;
  font-size: var(--game-icon-size, clamp(2.6rem, 6vh, 6rem));
  line-height: 1;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
}

.game-card h3 {
  flex-shrink: 0;
  margin: 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  /* host.js shrinks --game-title-size until the longest name fits, so every card shares one size. */
  font-size: var(--game-title-size, clamp(1.3rem, 1.8vw, 3.4rem));
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

/* With var() the browser cannot fall back line by line, so the card-relative size goes in here. */
@supports (width: 1cqi) {
  .game-card h3 {
    font-size: var(--game-title-size, clamp(1.3rem, min(2.6vw, 15cqi), 3.4rem));
  }
}

/* Top of the card: the game's label on the left and votes from phones on the right.
   A long label takes the whole line and the votes drop below it. */
.game-corner {
  position: absolute;
  top: clamp(0.8rem, 1.2vw, 1.5rem);
  left: clamp(0.8rem, 1.2vw, 1.5rem);
  right: clamp(0.8rem, 1.2vw, 1.5rem);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.4rem;
  pointer-events: none;
}

/* Votes from phones: a badge in the corner, only when someone voted */
.vote-count {
  margin-left: auto;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  background: var(--warning);
  color: #1a1400;
  font-size: clamp(1.05rem, 1.3vw, 1.7rem);
  font-weight: 800;
}

.vote-count:empty {
  display: none;
}

/* "New" label in the top-left corner */
.game-badge {
  padding: 0.25rem 0.8rem;
  border-radius: 1em;
  background: #22c55e;
  color: #052e16;
  font-size: clamp(0.7rem, 0.9vw, 1.4rem);
  font-size: clamp(0.6rem, min(0.9vw, 7.5cqi), 1.4rem);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.25;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}


.game-card.leading {
  border-color: var(--warning);
}

/* Remote control focus (TV) */
.focus-ring,
[data-tv-focusable='true']:focus-visible {
  outline: 5px solid var(--warning);
  outline-offset: 4px;
}

.game-card:focus-visible {
  border-color: var(--warning);
}

/* ------------------------------------------------------------------ Small screens */
@media (max-width: 900px), (max-height: 560px) {
  body.hub-host {
    height: auto;
    overflow: auto;
  }

  .hub-layout {
    grid-template-columns: 1fr;
  }

  .join-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .invite-qr-wrapper {
    width: 240px;
  }

  .hub-main {
    display: flex;
    flex-direction: column;
  }

  .player-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-template-rows: none;
    grid-auto-rows: 130px;
  }

  .player-seat:not(.next) {
    display: none;
  }

  .games-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    grid-auto-rows: auto;
  }

  .game-card {
    min-height: 150px;
  }

  .game-card .game-icon {
    font-size: 3.5rem;
  }
}

/* "Beta": still being tuned */
.game-badge[data-badge='beta'] {
  background: #f59e0b;
  color: #1c1305;
}

/* TV app start-up: the logo fades in, then gives way to the hub once the party is ready. */
.tv-splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  background: var(--bg);
  transition: opacity 0.6s ease;
}

.tv-splash img {
  width: clamp(96px, 9vw, 160px);
  height: clamp(96px, 9vw, 160px);
  border-radius: 28px;
  animation: tv-splash-rise 0.9s ease-out both;
}

.tv-splash-name {
  font-size: clamp(2rem, 3.2vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  animation: tv-splash-rise 0.9s ease-out 0.15s both;
}

.tv-splash-dots {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.6rem;
  animation: tv-splash-rise 0.9s ease-out 0.3s both;
}

.tv-splash-dots span {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  animation: tv-splash-dot 1.2s ease-in-out infinite;
}

.tv-splash-dots span:nth-child(2) { animation-delay: 0.2s; }
.tv-splash-dots span:nth-child(3) { animation-delay: 0.4s; }

.tv-splash.done {
  opacity: 0;
  pointer-events: none;
}

@keyframes tv-splash-rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes tv-splash-dot {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* In the card's corner, so a short card still has room for the name. */
.player-level {
  position: absolute;
  top: 0.4em;
  left: 0.4em;
  padding: 0.15em 0.7em;
  border-radius: 999px;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  color: #fff;
  font-size: calc(var(--name-size, 24px) * 0.45);
  font-weight: 800;
}

/* No one signed in yet: the games wait, and the hint says what to do */
.games-grid.locked .game-card {
  opacity: 0.55;
  filter: grayscale(0.4);
}

.games-section .hub-hint.needs-account {
  padding: 0.5em 0.9em;
  border-radius: 14px;
  background: color-mix(in srgb, #facc15 14%, transparent);
  border: 1px solid color-mix(in srgb, #facc15 50%, transparent);
  color: #fde68a;
}

.games-section .hub-hint.needs-account strong {
  color: #fef3c7;
}

.games-section .hub-hint.nudge {
  animation: hint-nudge 0.5s ease;
}

@keyframes hint-nudge {
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(3px); }
}

/* "Full screen: press F11" on computers */
.fullscreen-tip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-left: auto;
  box-sizing: border-box;
  padding: 0.45rem 0.4rem 0.45rem 0.6rem;
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  border: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  color: var(--text-primary);
  text-align: left;
  animation: fullscreen-tip-glow 2.4s ease-in-out 3;
}

.fullscreen-tip[hidden] {
  display: none;
}

.fullscreen-tip__keys {
  flex-shrink: 0;
  display: flex;
  gap: 0.2rem;
}

.fullscreen-tip kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0.15em 0.45em;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 4px;
  background: var(--surface);
  color: var(--text-primary);
  font: 800 clamp(1.1rem, 1.4vw, 1.6rem) var(--font-sans);
  text-align: center;
}

.fullscreen-tip__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  line-height: 1.25;
}

.fullscreen-tip__text b {
  font-size: clamp(1rem, 1.1vw, 1.25rem);
}

.fullscreen-tip__text small {
  color: var(--muted);
  font-size: clamp(0.8rem, 0.85vw, 0.95rem);
}

.hub-host .fullscreen-tip {
  align-self: center;
}

.hub-host .fullscreen-tip + .phase-pill {
  margin-left: 0;
}

.fullscreen-tip__close {
  flex-shrink: 0;
  align-self: center;
  width: 1.8em;
  height: 1.8em;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.9em;
  cursor: pointer;
}

.fullscreen-tip__close:hover {
  background: var(--surface);
  color: var(--text-primary);
}

@keyframes fullscreen-tip-glow {
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }
}

/* Each player's party colour: the card's border and a band along the bottom, as in every game */
.player-card {
  border-color: color-mix(in srgb, var(--c, var(--border-strong)) 75%, transparent);
  box-shadow: inset 0 calc(var(--name-size, 1.6rem) * -0.22) 0 var(--c, transparent);
}

.player-card .player-name {
  color: color-mix(in srgb, var(--c, #fff) 35%, #fff);
}

/* CPU players: a tile to add one, a ✕ on each to take it out again */
.player-seat.cpu-seat {
  padding: 0;
  border-style: dashed;
}

.cpu-add {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: inherit;
  background: transparent;
  color: var(--muted);
  font: 800 calc(var(--name-size, 1.6rem) * 0.8) var(--font-sans);
  cursor: pointer;
}

.cpu-add:hover,
.cpu-add:focus-visible {
  background: var(--surface-2);
  color: var(--text-primary);
}

.player-card.cpu {
  border-style: dashed;
}

.cpu-remove {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  width: 2em;
  height: 2em;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
  font-size: calc(var(--name-size, 1.6rem) * 0.45);
  cursor: pointer;
}
