/* Family Games Hub — sala de juego.
 *
 * Reuses the shared admin stylesheet (typography, layout, form controls,
 * skip-link) and adds the player-specific surface:
 *
 *  * ``.room-shell`` wraps the SPA; the JS toggles its ``hidden`` flag
 *    when the URL is not a valid room.
 *  * ``.player-list`` / ``.player-row`` are the lobby list and one row
 *    per participant. The row's ``data-mine`` / ``data-claimed``
 *    attributes are the only state the CSS needs.
 *  * ``.status-pill`` is the small badge on the right of each row
 *    (Libre / Mía / Ocupada). The mine/busy variants colour the pill.
 *  * ``.player-checkbox`` is the square control used to claim seats.
 *  * ``.phase-status`` is the single line of text shown on the
 *    PLAYING / FINISHED placeholders.
 *  * ``.board`` / ``.card`` render the Memory grid. Each card is
 *    full-bleed: the entire surface shows the theme resource (emoji
 *    or text) with no extra label.
 *  * ``.finish-stage`` hosts the scoreboard + celebration after the
 *    game ends. The board is hidden and the user sees a winner
 *    headline, an animated celebration and a single "Salir" button.
 *  * ``.player-error`` is the fatal error band rendered when the URL
 *    is bad, the network is down, or the room has been deleted.
 */

@import url('/static/styles.css');

.room-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.room-shell .layout {
  max-width: none;
}

.player-error {
  margin: 0;
  padding: 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--danger);
  color: var(--danger);
  text-align: center;
  font-size: 1rem;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: var(--touch-min);
}

.player-row[data-mine='true'] {
  border-color: var(--accent);
}

.player-row[data-claimed='true'][data-mine='false'] {
  opacity: 0.65;
}

.player-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

.status-pill {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg-muted);
  white-space: nowrap;
}

.status-pill--mine {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.status-pill--busy {
  border-color: var(--fg-muted);
  color: var(--fg-subtle);
}

.phase-status {
  margin: 0;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 1rem;
  text-align: center;
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
  justify-content: center;
}

.score-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-height: 54px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 108px;
}

.score-item[data-active='true'] {
  border-color: var(--accent);
}

.score-item[data-mine='true'][data-active='true'] {
  background: var(--accent);
  color: #fff;
}

.score-name {
  font-size: 0.98rem;
  color: var(--fg-muted);
  line-height: 1.1;
}

.score-value {
  font-size: 1.65rem;
  font-weight: 600;
  line-height: 1;
}

.board {
  display: grid;
  width: 100%;
  gap: 8px;
  margin: 8px auto 0;
  justify-content: space-between;
  align-content: start;
  max-width: 100%;
}

.board[data-cols='3'] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.board[data-cols='4'] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.board[data-cols='5'] {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.board[data-cols='6'] {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.board[data-cols='7'] {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

/* ``.memo-card`` is the Memory grid cell. We use a dedicated class so
 * it never collides with the global ``.card`` (the centred form card
 * used by login / create) that ``styles.css`` defines for the admin
 * shell. */
.memo-card {
  aspect-ratio: 1 / 1;
  min-height: var(--touch-min);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg);
  /* The theme resource fills the entire cell. JS computes
   * ``--memo-card-size`` from the available viewport, so portrait
   * and landscape layouts can use different column counts without
   * making the page scroll. */
  font-size: min(calc(var(--memo-card-size, 100px) * 0.68), 7.5rem);
  line-height: 0.85;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  text-align: center;
  overflow: hidden;
  /* Two stacked emoji glyphs (e.g. ``1️⃣``) draw a hair lower than
   * the visual middle; nudge them up so they sit centred. */
  letter-spacing: -0.05em;
  position: relative;
}

.memo-card[data-state='hidden'] {
  background: var(--bg-input);
  color: var(--fg-subtle);
  font-size: min(calc(var(--memo-card-size, 100px) * 0.48), 5.8rem);
  border-color: var(--border);
}

.memo-card[data-state='revealed'] {
  background: var(--bg-elevated);
  border-color: var(--accent);
}

.memo-card__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6%;
  pointer-events: none;
  user-select: none;
}

.memo-card[data-image-error='true'] {
  background: var(--bg-input);
  border-style: dashed;
  border-color: var(--fg-subtle);
}

.memo-card[data-state='mismatch'] {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border-color: var(--warn-fg);
}

.memo-card[data-disabled='true'] {
  cursor: not-allowed;
  opacity: .85;
}

/* When the player matches two cards the JS tags them with
 * ``data-just-matched`` for one paint cycle. A pulse + glow signals
 * the moment of success without changing the underlying state. The
 * animation is short and self-removes so a later ``paintBoard`` call
 * (e.g. on a scoreboard refresh) does not re-trigger it. */
@keyframes memoCardMatch {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(90, 209, 154, 0); }
  40%  { transform: scale(1.08); box-shadow: 0 0 0 8px rgba(90, 209, 154, 0.55); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(90, 209, 154, 0); }
}

.memo-card[data-just-matched='true'] {
  animation: memoCardMatch 650ms ease-out 1;
}

.turn-banner {
  padding: 14px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 8px 0;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.15;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.turn-banner[data-active-mine='true'] {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.winner-banner {
  padding: 16px;
  background: var(--success);
  color: #0a1f17;
  border-radius: var(--radius);
  margin: 0 0 12px 0;
  font-weight: 600;
}

/* Finish stage — the view shown when the game is FINISHED. The board
 * and turn banner are hidden; the user sees a celebration, a
 * scoreboard and a single "Salir" button. */
.finish-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.celebration {
  position: relative;
  background: linear-gradient(
    180deg,
    rgba(90, 209, 154, 0.16) 0%,
    rgba(90, 209, 154, 0.04) 100%
  );
  border: 1px solid var(--success);
  border-radius: var(--radius);
  padding: 34px 18px 28px;
  text-align: center;
  overflow: hidden;
  isolation: isolate;
}

.celebration__headline {
  font-size: clamp(2.2rem, 9vw, 4.8rem);
  font-weight: 800;
  margin: 0;
  color: var(--fg);
  position: relative;
  z-index: 1;
}

.celebration__tied {
  margin: 12px 0 0;
  color: var(--fg-muted);
  font-size: clamp(1.15rem, 3.8vw, 2rem);
  position: relative;
  z-index: 1;
}

/* Confetti: eight radial blobs that drift slowly behind the
 * headline. No external libs, no JS animation. */
.celebration::before,
.celebration::after,
.celebration__confetti {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, var(--accent) 0 6px, transparent 7px),
    radial-gradient(circle at 84% 12%, var(--success) 0 5px, transparent 6px),
    radial-gradient(circle at 24% 78%, var(--warn-fg) 0 6px, transparent 7px),
    radial-gradient(circle at 70% 70%, var(--accent-strong) 0 5px, transparent 6px),
    radial-gradient(circle at 50% 30%, var(--success) 0 4px, transparent 5px),
    radial-gradient(circle at 36% 56%, var(--accent) 0 4px, transparent 5px),
    radial-gradient(circle at 92% 50%, var(--warn-fg) 0 5px, transparent 6px),
    radial-gradient(circle at 6% 50%, var(--accent-strong) 0 4px, transparent 5px);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  opacity: 0.55;
  z-index: 0;
  animation: confettiDrift 6s linear infinite;
}

.celebration::after {
  animation-delay: -3s;
  animation-duration: 7s;
  opacity: 0.4;
}

@keyframes confettiDrift {
  0%   { transform: translate3d(0, 0, 0)        rotate(0deg);   }
  50%  { transform: translate3d(0, -6px, 0)     rotate(2deg);   }
  100% { transform: translate3d(0, 0, 0)        rotate(0deg);   }
}

.scoreboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scoreboard__row {
  display: grid;
  grid-template-columns: 2.8rem 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: var(--touch-min);
  font-size: clamp(1.15rem, 3.8vw, 1.8rem);
}

.scoreboard__row[data-winner='true'] {
  border-color: var(--success);
  background: rgba(90, 209, 154, 0.12);
  font-weight: 600;
}

.scoreboard__rank {
  font-size: clamp(1.35rem, 4vw, 2.1rem);
  color: var(--fg-muted);
  font-weight: 700;
  text-align: center;
}

.scoreboard__row[data-winner='true'] .scoreboard__rank {
  color: var(--success);
}

.scoreboard__name {
  font-weight: 600;
}

.scoreboard__points {
  font-size: clamp(1.55rem, 4.8vw, 2.5rem);
  font-weight: 700;
}

.finish-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.finish-hint {
  margin: 0;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: left;
}

.finish-hint strong {
  color: var(--fg);
  font-weight: 600;
}
