/* ===== Dobble Mint · Game screen (builds on style.css tokens) ===== */

body.playing,
body.in-play {
  overflow: hidden;
}

/* 100vh exceeds the visible area on mobile browsers, which made short pages scroll */
body.in-play {
  min-height: 100dvh;
}

/* ---------- Start screen ---------- */
.start {
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Same .topbar as the designer so the logo stays put when switching views */
.play-topbar {
  width: 100%;
  height: var(--topbar-h);
}

/* Out of flow so the button never changes the bar's height (and the logo's position) */
.play-back {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.play-back:hover {
  transform: translateY(calc(-50% - 1px));
}

.play-back:active {
  transform: translateY(calc(-50% + 1px));
}

.start-panel {
  width: min(400px, 100% - 40px);
  margin: auto 0;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--raised-hover);
}

.start-title {
  font-family: var(--font-serif);
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1.1;
}

.start-rules,
.start-note,
.start-best {
  color: var(--ink-soft);
  line-height: 1.5;
}

.start-note:empty,
.start-best:empty {
  display: none;
}

.start-best {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink);
}

.segmented input:disabled+label {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-large {
  height: 48px;
  font-size: 1rem;
}

.start-edit {
  align-self: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.start-edit:hover {
  color: var(--accent);
}

/* ---------- Pass & Play roster and hand-off ---------- */
.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.player-list li {
  display: flex;
  gap: 8px;
}

.player-list input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--recessed);
}

.handoff-panel {
  text-align: center;
}

/* ---------- Board ---------- */
.board {
  --card: min(34dvh, 88vw);
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: opacity var(--ease), filter var(--ease);
}

/* Far player reads their half upside down when the device lies flat */
.seat-top {
  transform: rotate(180deg);
}

.board[data-mode="solo"] .seat-top,
.board[data-mode="solo"] .seat-hud,
.board[data-mode="duel"] #solo-hud {
  display: none;
}

/* Solo: center card on top, your card below, HUD between */
.board[data-mode="solo"] {
  grid-template-rows: auto 1fr;
}

.board[data-mode="solo"] .seat-bottom {
  align-self: start;
}

.center-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/*
 * Duel: pile on the left, players' cards top-right and bottom-right. The circles interleave,
 * so they can be larger than three stacked cards; play.js computes --card to fit.
 */
.board[data-mode="duel"] {
  display: block;
}

.board[data-mode="duel"] .center-row,
.board[data-mode="duel"] .seat {
  position: absolute;
}

.board[data-mode="duel"] .center-row {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.board[data-mode="duel"] .seat-top {
  right: 12px;
  top: max(12px, env(safe-area-inset-top));
}

.board[data-mode="duel"] .seat-bottom {
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
}

/* Scores sit beside each card toward the open left side (seat-top is rotated: local right) */
.board[data-mode="duel"] .seat-hud {
  position: absolute;
  bottom: 0;
  white-space: nowrap;
}

.board[data-mode="duel"] .seat-bottom .seat-hud {
  right: calc(100% + 8px);
}

.board[data-mode="duel"] .seat-top .seat-hud {
  left: calc(100% + 8px);
}

.board[data-mode="duel"] .center-meta {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  white-space: nowrap; /* stays in the narrow strip left of the bottom player's card */
}

.hud {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 2.4rem;
}

.hud-timer {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hud-penalty {
  color: var(--error);
  font-weight: 600;
  opacity: 0;
}

.hud-penalty.show {
  animation: penalty 900ms ease-out;
}

.center-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-soft);
}

.pile-count {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1rem;
}

.seat-hud {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ink-soft);
}

.seat-score {
  display: inline-block;
  min-width: 3ch; /* fixed width so play.js can reserve room for up to 3 digits */
  text-align: right;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Cards ---------- */
.slot {
  width: var(--card);
  height: var(--card);
}

.slot svg.card {
  width: 100%;
  height: 100%;
  filter: var(--card-depth);
  pointer-events: none; /* only halos take taps, so overlapping card boxes never block them */
}

/* The hidden halo doubles as a generous tap target around each emoji */
.board .symbol-halo {
  pointer-events: all;
  cursor: pointer;
}

.seat.won svg.card {
  animation: pop 260ms cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.seat.shake .slot {
  animation: shake 320ms ease-in-out;
}

.seat.locked {
  opacity: 0.4;
  filter: grayscale(0.8);
}

/* ---------- Pause ---------- */
/* Opaque so nobody can study the cards while the clock is stopped */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  background: var(--bg);
}

/* ---------- Results ---------- */
.results {
  overflow-y: auto;
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  place-items: center;
  gap: 20px;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.results[data-mode="solo"] {
  grid-template-rows: auto auto;
  align-content: safe center; /* stats can make the page taller than the screen */
}

.results[data-mode="solo"] .result-top {
  display: none;
}

.results[data-mode="solo"] .result-actions {
  order: 2;
}

.result-top {
  transform: rotate(180deg);
}

.result-card {
  min-width: min(320px, 90vw);
  padding: 24px 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--raised-hover);
  color: var(--ink-soft);
  line-height: 1.6;
}

.result-title {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--ink);
}

.result-card p:first-of-type {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.result-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.result-buttons {
  display: flex;
  gap: 10px;
}

.leaderboard {
  list-style: none;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leaderboard-row {
  padding: 6px 10px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* ---------- Stats ---------- */
.stats {
  width: min(320px, 90vw);
  color: var(--ink-soft);
}

.stats-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stat-player {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.stat-player h3 {
  margin-bottom: 12px;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
}

.stat-player-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stat-facts {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  font-variant-numeric: tabular-nums;
}

.stat-facts dd {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
}

.stat-figure figcaption {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.stat-chart {
  width: 100%;
  height: auto;
  display: block;
}

.stat-bar {
  fill: var(--ink-muted);
}

.stat-bar.is-wrong {
  fill: var(--error);
}

.stat-bar.p1:not(.is-wrong) {
  fill: var(--accent);
}

.stat-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

/* ---------- Motion ---------- */
@keyframes pop {
  from { transform: scale(0.9); }
  to { transform: scale(1); }
}

@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@keyframes penalty {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-14px); }
}

@media (max-width: 900px) {
  .play-topbar {
    height: auto;
  }

  .play-back {
    right: 16px;
  }
}

/* Solo side by side when play.js finds that gives bigger cards (wide screens) */
.board[data-mode="solo"][data-layout="side"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
}

.board[data-mode="solo"][data-layout="side"] .center-row {
  grid-column: 1;
  grid-row: 1;
}

.board[data-mode="solo"][data-layout="side"] .seat-bottom {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
}

@media (prefers-reduced-motion: reduce) {
  .seat.won svg.card,
  .seat.shake .slot,
  .hud-penalty.show {
    animation: none;
  }

  .hud-penalty.show {
    opacity: 1;
  }
}
