/* lobby.css — the door of the show: room code as a marquee, a QR big enough
   to scan from the sofa, and eight seats that fill with real faces. */

/* Four bands: rail, invite, theme picker + start, seats.
   Tighter row gap than the house default: START moved up into the picker band,
   and those ~50px have to come back out of the layout or the seats fall off the
   bottom of a 1080p screen. */
[data-screen="lobby"].screen {
  grid-template-rows: auto 1fr auto auto;
  gap: 1.1rem;
}

.lobby__body {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  align-items: center;
  gap: var(--gap-xl);
}

.lobby__invite {
  display: grid;
  gap: var(--gap);
  justify-items: start;
}

/* "ROOM CODE" lands on the hottest part of the themed aura — the one spot on
   this screen where --ink-faint drops under the 3:1 large-text floor (measured
   2.98:1 on familia at the brightest phase of the drift). One step up in ink
   buys 4.3:1 there without flattening the label hierarchy. */
[data-screen="lobby"] .lobby__invite .eyebrow {
  color: var(--ink-dim);
}

.code {
  display: grid;
  gap: 1rem;
}

.code__tiles {
  display: flex;
  gap: 0.9rem;
}

.code__tile {
  width: 7.6rem;
  height: 9.4rem;
  font-size: 5.8rem;
  letter-spacing: 0;
  color: var(--ink);
  position: relative;
}

.code__tile::after {
  content: "";
  position: absolute;
  inset: auto 22% 0.55rem;
  height: 0.18rem;
  border-radius: 999px;
  background: var(--hot);
  opacity: 0.85;
}

.code__url {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  word-break: break-all;
}

.qr {
  display: grid;
  justify-items: center;
  gap: 1.1rem;
  padding: 1.6rem;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: 0 2rem 5rem rgb(0 0 0 / 0.6);
}

.qr__code > * {
  width: min(30rem, 46vh);
  height: auto;
  image-rendering: pixelated;
}

.qr__hint {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #0b0d11;
}

.qr__frame {
  position: relative;
  display: grid;
  justify-items: center;
}

/* The lobby QR shares the row with the theme picker, so it runs smaller here
   than on the podium — still ~2.5x the size a phone camera needs from a sofa. */
[data-screen="lobby"] .qr {
  padding: 1.2rem;
}

[data-screen="lobby"] .qr__code > * {
  width: min(20rem, 27vh);
}

/* Seats along the bottom: occupied seats in colour, free seats as outlines.
   START moved up into the selection block, so this band is seats only. */
.lobby__foot {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: var(--gap-lg);
  border-top: 1px solid var(--line-soft);
  padding-top: 1.1rem;
}

.seats {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1.5rem;
  /* Hueco para el boton SALIR, anclado en la esquina inferior izquierda. */
  padding-left: 13rem;
}

.seats .avatar {
  --size: 5.6rem;
}

/* ============================================================================
   START — end of the selection band, right edge.

   The tally sits to its left, not under it: the button is the loudest thing on
   the screen and the sentence that explains a dark button has to read at the
   same glance. Both are inside .picker__settings now.
   ========================================================================== */

.lobby__cta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* `.tally` is shared with the question screen — only the lobby copy is the one
   sitting to the left of START, so only that one gets pulled to the right. */
.tally {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}

.lobby__cta .tally {
  text-align: right;
}

.tally b {
  color: var(--ink);
}

/* ---------- The rig: button + halo + running rim + focus sparks ---------- */

.start-slot {
  position: relative;
  display: inline-grid;
  isolation: isolate;
  transition: transform var(--dur) var(--ease-slam);
}

/* Bounce on focus lives on the slot, so the button keeps its heartbeat for
   itself and the two transforms multiply instead of fighting. */
.start-slot:focus-within {
  transform: scale(1.07);
}

.btn--start {
  position: relative;
  z-index: 1;
  padding: 1.15rem 3.2rem;
  font-size: 1.7rem;
  letter-spacing: 0.09em;
  color: #180f06;
  background: linear-gradient(178deg, #ffb877 0%, var(--hot) 48%, #bf5320 100%);
  box-shadow:
    inset 0 0.14rem 0 rgb(255 255 255 / 0.55),
    inset 0 -0.2rem 0 rgb(0 0 0 / 0.3),
    0 1.1rem 2.6rem rgb(224 112 58 / 0.34);
  animation: start-beat 2.9s ease-in-out infinite;
  will-change: transform;
}

.btn--start:hover:not(:disabled) {
  transform: none;
}

/* The glow the room sees from the sofa, breathing on the same clock as the
   heartbeat so the button reads as one object. */
.start-slot__halo,
.start-slot__rim,
.start-slot__spark {
  position: absolute;
  pointer-events: none;
}

.start-slot__halo {
  z-index: 0;
  inset: -1.9rem;
  border-radius: 999px;
  background: radial-gradient(50% 50% at 50% 50%, rgb(255 148 74 / 0.45), transparent 70%);
  animation: start-halo 2.9s ease-in-out infinite;
}

/* A light that runs the edge: a conic sweep clipped to a pill, with the opaque
   button on top of it — only the 0.34rem lip is ever visible. */
.start-slot__rim {
  z-index: 0;
  inset: -0.34rem;
  border-radius: 999px;
  overflow: hidden;
}

.start-slot__rim::before {
  content: "";
  position: absolute;
  inset: -70%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg 186deg,
    rgb(255 214 140 / 0.35) 254deg,
    #fff4d6 296deg,
    rgb(255 157 77 / 0.55) 328deg,
    transparent 354deg
  );
  animation: start-rim 3.4s linear infinite;
}

/* Sparks: only while the remote is on the button. Six dots that burst outward
   from the pill, drawn as one painted layer that scales — no per-dot nodes. */
.start-slot__spark {
  z-index: 2;
  inset: -1.4rem;
  opacity: 0;
  background-repeat: no-repeat;
  background-image:
    radial-gradient(circle, #fff6dc 0 0.17rem, transparent 0.24rem),
    radial-gradient(circle, #ffd08a 0 0.13rem, transparent 0.2rem),
    radial-gradient(circle, #fff6dc 0 0.15rem, transparent 0.22rem),
    radial-gradient(circle, #ffb066 0 0.12rem, transparent 0.19rem),
    radial-gradient(circle, #fff6dc 0 0.16rem, transparent 0.23rem),
    radial-gradient(circle, #ffd08a 0 0.12rem, transparent 0.19rem);
  background-position: 6% 22%, 24% 90%, 46% 4%, 66% 94%, 88% 20%, 97% 74%;
}

#btnStart:focus ~ .start-slot__spark,
#btnStart:focus-visible ~ .start-slot__spark {
  animation: start-sparks 1.15s var(--ease-out) infinite;
}

#btnStart:focus ~ .start-slot__rim::before,
#btnStart:focus-visible ~ .start-slot__rim::before {
  animation-duration: 1.5s;
}

#btnStart:focus ~ .start-slot__halo,
#btnStart:focus-visible ~ .start-slot__halo {
  animation-duration: 1.5s;
}

/* ---------- Not enough players: visibly off, and the tally says why ---------- */

.btn--start:disabled {
  animation: none;
  background: linear-gradient(180deg, #232a37, #12171f);
  /* --ink-dim, not --ink-faint: 6.4:1 on this slab, still large text. */
  color: var(--ink-dim);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.06);
}

#btnStart:disabled ~ .start-slot__halo,
#btnStart:disabled ~ .start-slot__rim {
  opacity: 0.12;
  animation: none;
}

#btnStart:disabled ~ .start-slot__rim::before {
  animation: none;
}

#btnStart:disabled ~ .start-slot__spark {
  display: none;
}

@keyframes start-beat {
  0%,
  100% {
    transform: scale(1);
  }
  46% {
    transform: scale(1.035);
  }
  62% {
    transform: scale(1.012);
  }
}

@keyframes start-halo {
  0%,
  100% {
    opacity: 0.5;
    transform: scale(0.94);
  }
  46% {
    opacity: 1;
    transform: scale(1.06);
  }
}

@keyframes start-rim {
  to {
    transform: rotate(1turn);
  }
}

@keyframes start-sparks {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }
  30% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

/* ============================================================================
   A lobby that never stands still.

   Every loop below is transform/opacity only and runs on its own period
   (2.6 / 2.9 / 4.8 / 5.6 / 6.4 s) with per-element offsets — synchronised
   idle motion is what makes a screen look cheap.
   ========================================================================== */

/* ---------- Room code: a glint crossing each tile, left to right ---------- */

.code__tile {
  overflow: hidden;
}

.code__tile::before {
  content: "";
  position: absolute;
  inset: -30% -60%;
  pointer-events: none;
  background: linear-gradient(
    74deg,
    transparent 42%,
    rgb(255 255 255 / 0.17) 50%,
    rgb(255 196 120 / 0.12) 56%,
    transparent 65%
  );
  transform: translate3d(-130%, 0, 0);
  animation: tile-shine 5.6s cubic-bezier(0.36, 0, 0.2, 1) infinite;
  /* --i is already on the tile (lobby.js) and inherits down here. */
  animation-delay: calc(var(--i, 0) * 640ms);
}

@keyframes tile-shine {
  0%,
  58% {
    transform: translate3d(-130%, 0, 0);
  }
  82%,
  100% {
    transform: translate3d(130%, 0, 0);
  }
}

/* ---------- QR: a halo that breathes and a light running its frame ---------- */

/* Shrink the frame to the card so the two glow layers can hug its edge. */
[data-screen="lobby"] .qr__frame {
  justify-self: center;
}

/* The white card rides above both glow layers, so nothing ever crosses the
   code itself — a wash over the modules is a scan that fails. */
[data-screen="lobby"] .qr {
  position: relative;
  z-index: 1;
}

.qr__frame::before,
.qr__frame::after {
  content: "";
  position: absolute;
  z-index: 0;
  pointer-events: none;
}

.qr__frame::before {
  inset: -2.4rem;
  border-radius: var(--radius-lg);
  background: radial-gradient(50% 50% at 50% 50%, rgb(255 255 255 / 0.22), transparent 70%);
  animation: qr-halo 4.8s ease-in-out infinite;
}

/* The periodic flash: a lit rim around the card, dark most of the cycle and
   snapping bright for half a second. Opacity only — the ring itself never
   moves, so the code under it never blurs. */
.qr__frame::after {
  inset: -0.55rem;
  border-radius: calc(var(--radius-lg) + 0.55rem);
  border: 0.16rem solid rgb(255 236 190 / 0.9);
  box-shadow:
    0 0 1.6rem rgb(255 214 140 / 0.7),
    inset 0 0 1.2rem rgb(255 214 140 / 0.5);
  opacity: 0;
  animation: qr-flash 7.2s ease-in-out infinite;
}

@keyframes qr-halo {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.97);
  }
  50% {
    opacity: 1;
    transform: scale(1.03);
  }
}

@keyframes qr-flash {
  0%,
  86%,
  100% {
    opacity: 0;
  }
  90% {
    opacity: 0.95;
  }
  96% {
    opacity: 0.18;
  }
}

/* ---------- Empty seats: eight slots breathing out of step ---------- */

#lobbySeats .avatar--empty {
  animation: seat-wait 2.6s ease-in-out infinite;
}

#lobbySeats li:nth-child(2) .avatar--empty { animation-delay: 180ms; }
#lobbySeats li:nth-child(3) .avatar--empty { animation-delay: 370ms; }
#lobbySeats li:nth-child(4) .avatar--empty { animation-delay: 520ms; }
#lobbySeats li:nth-child(5) .avatar--empty { animation-delay: 730ms; }
#lobbySeats li:nth-child(6) .avatar--empty { animation-delay: 910ms; }
#lobbySeats li:nth-child(7) .avatar--empty { animation-delay: 1080ms; }
#lobbySeats li:nth-child(8) .avatar--empty { animation-delay: 1260ms; }

@keyframes seat-wait {
  0%,
  100% {
    opacity: 0.5;
    transform: scale(0.955);
  }
  50% {
    opacity: 1;
    transform: scale(1.025);
  }
}

/* ---------- The mark: alive, but never dimmer (contrast is fixed) ---------- */

[data-screen="lobby"] .rail__brand {
  transform-origin: left center;
  animation: brand-breathe 6.4s ease-in-out infinite;
}

@keyframes brand-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.024);
  }
}

/* ---------- Budget ---------- */

:root[data-perf="lite"] .start-slot__rim,
:root[data-perf="lite"] .start-slot__spark,
:root[data-perf="lite"] .qr__frame::after,
:root[data-perf="lite"] .code__tile::before {
  display: none;
}

:root[data-perf="lite"] .start-slot__halo,
:root[data-perf="lite"] .qr__frame::before,
:root[data-perf="lite"] #lobbySeats .avatar--empty,
:root[data-perf="lite"] [data-screen="lobby"] .rail__brand {
  animation: none;
}

:root[data-perf="lite"] .btn--start {
  box-shadow: inset 0 0.14rem 0 rgb(255 255 255 / 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .start-slot__spark,
  .qr__frame::after,
  .code__tile::before {
    display: none;
  }

  .start-slot__halo {
    opacity: 0.85;
  }

  /* The rim keeps its lit lip, it just stops running. */
  .start-slot__rim::before {
    background: linear-gradient(120deg, #ffd08a, #fff4d6 45%, #ff9d4d);
    opacity: 0.7;
  }
}
