:root {
  --felt: #146b3a;
  --felt-dark: #073d20;
  --felt-deep: #04260f;
  --gold: #e9c46a;
  --gold-light: #fbe7a1;
  --gold-dark: #a87d22;
  --wood: #6b3d1c;
  --wood-dark: #3b1f0b;
  --paper: #fffdf6;
  --paper-shade: #efe6cf;
  --ink: #1b1b1f;
  --red-ink: #c1121f;
  --muted: #b7c9bc;
  --team-0: #2563eb;
  --team-0-dark: #1e3a8a;
  --team-1: #16a34a;
  --team-1-dark: #14532d;
  --team-2: #dc2626;
  --team-2-dark: #7f1d1d;
  --radius: 12px;
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --board: min(calc(100vw - 16px), calc(100dvh - 270px), 700px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: #f5f1e6;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--felt-dark);
  /* Felt: soft table lamp, vignette and a fine fabric grain. */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 18%, #1f8a4c 0%, var(--felt) 32%, var(--felt-dark) 70%, var(--felt-deep) 100%);
  background-attachment: fixed;
}

button {
  font: inherit;
  cursor: pointer;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  letter-spacing: 0.01em;
}

.screen {
  max-width: 760px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.center {
  text-align: center;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.red {
  color: var(--red-ink);
}

.stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.row.between {
  justify-content: space-between;
  align-items: center;
}

.grow {
  flex: 1;
  min-width: 0;
}

/* Panels and controls ----------------------------------------------------- */

.panel-felt,
.code-box,
.team {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.28), rgba(0, 0, 0, 0.42));
  border: 1px solid rgba(233, 196, 106, 0.35);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 10px 30px rgba(0, 0, 0, 0.35);
}

.panel-felt {
  padding: 20px;
}

.btn {
  border: 1px solid rgba(233, 196, 106, 0.45);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03));
  color: #fdf6e3;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition:
    transform 0.12s,
    box-shadow 0.12s,
    filter 0.12s;
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn.primary {
  color: #3b2606;
  border: 1px solid #fff3c4;
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 45%, var(--gold-dark) 100%);
  box-shadow:
    0 3px 0 #6e4f12,
    0 8px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn.primary:hover {
  filter: brightness(1.06);
}

.btn.warn {
  color: #3b1606;
  border-color: #ffd7b0;
  background: linear-gradient(180deg, #ffc08a, #f97316);
  box-shadow: 0 2px 0 #9a3f0b;
}

.btn.small {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.btn.ghost {
  background: transparent;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.field input {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  text-transform: none;
  letter-spacing: normal;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(233, 196, 106, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

.field input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.4),
    0 0 0 3px rgba(233, 196, 106, 0.25);
}

.field input[name='code'] {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-weight: 800;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gold);
  font-family: var(--serif);
  font-style: italic;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(233, 196, 106, 0.5), transparent);
}

.segmented {
  display: inline-flex;
  border: 1px solid rgba(233, 196, 106, 0.45);
  border-radius: 999px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 6px 16px;
  font-weight: 700;
}

.segmented button.active {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  color: #3b2606;
}

.tag {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(233, 196, 106, 0.18);
  color: var(--gold-light);
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Home -------------------------------------------------------------------- */

.home {
  max-width: 440px;
  padding-top: max(28px, 6vh);
  text-align: center;
}

.home form {
  text-align: left;
  margin-top: 22px;
}

.hero {
  position: relative;
  height: 120px;
  margin-bottom: 8px;
}

.hero-card {
  --w: 62px;
  position: absolute;
  left: 50%;
  bottom: 0;
  width: var(--w);
  height: calc(var(--w) * 1.4);
  margin-left: calc(var(--w) / -2);
  border-radius: 7px;
  background: linear-gradient(160deg, var(--paper), var(--paper-shade));
  color: var(--ink);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
  transform-origin: 50% 140%;
  transform: rotate(calc(var(--i) * 13deg));
  animation: deal 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  animation-delay: calc((var(--i) + 2) * 70ms);
  display: block;
  font-family: var(--serif);
}

.hero-card.red {
  color: var(--red-ink);
}

@keyframes deal {
  from {
    transform: rotate(0deg) translateY(30px);
    opacity: 0;
  }
}

.logo {
  font-size: clamp(2.6rem, 11vw, 3.6rem);
  font-weight: 900;
  margin: 6px 0 0;
  background: linear-gradient(180deg, #fff6d2 0%, var(--gold) 55%, var(--gold-dark) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.45));
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-style: italic;
  font-family: var(--serif);
}

.suits {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 1.2rem;
  color: #f5f1e6;
  opacity: 0.85;
}

.suits .red {
  color: #ff5a64;
}

/* Lobby ------------------------------------------------------------------- */

.lobby {
  display: grid;
  gap: 14px;
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bar h2 {
  margin: 0;
  color: var(--gold-light);
}

.code-box {
  text-align: center;
  padding: 18px;
}

.code-box p {
  margin: 0 0 8px;
}

.code {
  font-family: var(--serif);
  font-size: clamp(2.4rem, 12vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.35em;
  padding-left: 0.35em;
  background: linear-gradient(180deg, #fff6d2, var(--gold) 55%, var(--gold-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent !important;
}

.lobby h3 {
  margin: 0;
}

.teams {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.team {
  padding: 12px 14px;
  border-top: 4px solid var(--team-color);
}

.team header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.team header .btn {
  margin-left: auto;
}

.team ul {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 6px;
}

.offline {
  opacity: 0.5;
}

.lobby > .btn.primary {
  width: 100%;
  padding: 15px;
  font-size: 1.05rem;
}

.team-0 {
  --team-color: var(--team-0);
  --team-dark: var(--team-0-dark);
}
.team-1 {
  --team-color: var(--team-1);
  --team-dark: var(--team-1-dark);
}
.team-2 {
  --team-color: var(--team-2);
  --team-dark: var(--team-2-dark);
}

.chip-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--team-color);
  border: 2px dashed rgba(255, 255, 255, 0.85);
  flex: none;
}

/* Poker chips ------------------------------------------------------------- */

.chip {
  position: absolute;
  inset: 11%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.55), transparent 32%),
    radial-gradient(circle, var(--team-color) 0 44%, rgba(255, 255, 255, 0.9) 45% 50%, transparent 51%),
    repeating-conic-gradient(from 8deg, #fff 0 14deg, var(--team-color) 14deg 45deg);
  box-shadow:
    0 2px 0 var(--team-dark),
    0 4px 6px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1.5px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.chip.mini {
  position: relative;
  inset: auto;
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: none;
  box-shadow:
    0 1px 0 var(--team-dark),
    0 2px 3px rgba(0, 0, 0, 0.5);
}

.chip.big {
  position: relative;
  inset: auto;
  display: inline-block;
  width: 72px;
  height: 72px;
}

.chip.locked {
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 10px 2px rgba(250, 204, 21, 0.75),
    0 3px 5px rgba(0, 0, 0, 0.5);
}

.chip.drop {
  animation: drop 0.55s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}

@keyframes drop {
  0% {
    transform: translateY(-140%) scale(1.5);
    opacity: 0;
  }
  60% {
    transform: translateY(0) scale(0.92);
    opacity: 1;
  }
  80% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

.chip.removed {
  background: transparent;
  border: 2px dashed #ff8a3d;
  box-shadow: none;
  animation: vanish 0.6s ease-out;
}

@keyframes vanish {
  from {
    transform: scale(1.3);
    opacity: 0;
  }
}

/* Game -------------------------------------------------------------------- */

.game {
  padding-left: 8px;
  padding-right: 8px;
  display: grid;
  gap: 10px;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2a1608, #160b03);
  border: 1px solid rgba(233, 196, 106, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 6px 16px rgba(0, 0, 0, 0.4);
}

.status.my-turn {
  animation: glow 1.8s ease-in-out infinite;
}

.status.my-turn strong {
  color: var(--gold-light);
}

@keyframes glow {
  50% {
    box-shadow:
      0 0 0 2px var(--gold),
      0 0 18px rgba(250, 204, 21, 0.55);
  }
}

.turn,
.scores,
.score {
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn strong {
  font-family: var(--serif);
  font-size: 1.05rem;
}

.scores {
  gap: 12px;
  font-size: 0.85rem;
}

.score b {
  font-size: 1rem;
}

.score small {
  color: var(--muted);
}

.deck-icon {
  width: 13px;
  height: 17px;
  border-radius: 2px;
  background: repeating-linear-gradient(45deg, #9b1c1c 0 3px, #c53030 3px 6px);
  border: 1.5px solid #fff;
  box-shadow: 2px 2px 0 rgba(255, 255, 255, 0.35);
}

.score.deck {
  color: var(--muted);
}

/* Wooden board */
.board-wrap {
  display: flex;
  justify-content: center;
}

.board {
  width: var(--board);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: calc(var(--board) * 0.004 + 1px);
  padding: calc(var(--board) * 0.022);
  border-radius: 14px;
  background:
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(88deg, rgba(0, 0, 0, 0.08) 0 1px, transparent 1px 13px),
    linear-gradient(135deg, #8a5329 0%, var(--wood) 40%, var(--wood-dark) 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 214, 150, 0.25),
    inset 0 3px 10px rgba(0, 0, 0, 0.55),
    0 3px 0 #2a1406,
    0 22px 45px rgba(0, 0, 0, 0.6);
}

.cell {
  position: relative;
  border: 0;
  padding: 0;
  border-radius: calc(var(--board) * 0.006 + 1px);
  background: linear-gradient(160deg, var(--paper) 0%, var(--paper-shade) 100%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  overflow: hidden;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.12s;
}

.cell.red {
  color: var(--red-ink);
}

.cell .rank {
  font-family: var(--serif);
  font-weight: 900;
  font-size: calc(var(--board) / 36);
}

.cell .suit {
  font-size: calc(var(--board) / 26);
  margin-top: 1px;
}

.cell.corner {
  background: radial-gradient(circle at 50% 40%, #fff6cf, var(--gold) 60%, var(--gold-dark));
  color: #6e4f12;
}

.cell .crown {
  font-size: calc(var(--board) / 18);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.cell.in-seq {
  box-shadow:
    inset 0 0 0 2px var(--gold),
    0 0 8px rgba(250, 204, 21, 0.6);
}

.cell.seq-new {
  animation: shine 1.4s ease-out 2;
}

@keyframes shine {
  0%,
  100% {
    filter: none;
  }
  40% {
    filter: brightness(1.35) drop-shadow(0 0 6px #fde047);
    transform: scale(1.08);
  }
}

.cell.target {
  background: linear-gradient(160deg, #fff7c2, #fde68a);
  box-shadow:
    inset 0 0 0 3px #eab308,
    0 0 10px rgba(250, 204, 21, 0.9);
  animation: pulse 1.1s ease-in-out infinite;
  z-index: 1;
}

.cell.target.remove {
  background: linear-gradient(160deg, #ffe1e1, #fecaca);
  box-shadow:
    inset 0 0 0 3px #ef4444,
    0 0 10px rgba(239, 68, 68, 0.9);
}

/* Let the player see the card under each removable chip. */
.cell.target.remove .chip {
  opacity: 0.35;
  transition: opacity 0.2s ease;
}

/* The covered card is in the player's hand: they could take the cell back. */
.cell.target.remove.in-hand {
  box-shadow:
    inset 0 0 0 3px #22c55e,
    0 0 12px rgba(34, 197, 94, 0.95);
}

.cell.target.remove.in-hand::before {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #16a34a;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  pointer-events: none;
}

@keyframes pulse {
  50% {
    transform: scale(1.07);
  }
}

.cell.last::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px #ff8a3d;
  pointer-events: none;
}

/* Hand of cards */
.hand-area {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.hint {
  margin: 0;
  font-size: 0.92rem;
  color: var(--gold-light);
  font-style: italic;
  font-family: var(--serif);
  min-height: 1.2em;
}

.hand {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding-top: 14px;
}

.card {
  --w: min(54px, calc((100vw - 70px) / 7));
  position: relative;
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * 0.12);
  border: 0;
  padding: 0;
  background: linear-gradient(160deg, var(--paper) 0%, var(--paper-shade) 100%);
  color: var(--ink);
  font-family: var(--serif);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.45),
    inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transform: rotate(calc(var(--i) * 2.5deg)) translateY(calc(var(--i) * var(--i) * 1.2px));
  transition:
    transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1),
    box-shadow 0.18s;
}

.card.fresh {
  animation: deal-hand 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards;
}

@keyframes deal-hand {
  from {
    transform: translateY(40px) rotate(0deg);
    opacity: 0;
  }
}

.card.red {
  color: var(--red-ink);
}

:is(.card, .hero-card) .idx {
  position: absolute;
  display: grid;
  justify-items: center;
  font-weight: 900;
  font-size: calc(var(--w) * 0.24);
  line-height: 0.95;
}

:is(.card, .hero-card) .idx i {
  font-style: normal;
  font-size: 0.9em;
}

:is(.card, .hero-card) .tl {
  top: 6%;
  left: 8%;
}

:is(.card, .hero-card) .br {
  bottom: 6%;
  right: 8%;
  transform: rotate(180deg);
}

:is(.card, .hero-card) .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--w) * 0.56);
}

:is(.card, .hero-card) .jack-mark {
  font-weight: 900;
  font-size: 0.85em;
  width: 1.2em;
  height: 1.2em;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: linear-gradient(160deg, #fff4c9, var(--gold));
  box-shadow: inset 0 0 0 2px var(--gold-dark);
}

:is(.card, .hero-card) .badge {
  position: absolute;
  top: -9px;
  left: 50%;
  margin-left: -10px;
  z-index: 1;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-family: var(--sans);
  font-weight: 800;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

:is(.card, .hero-card) .badge.wild {
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
}

:is(.card, .hero-card) .badge.remove {
  background: linear-gradient(180deg, #f87171, #b91c1c);
}

.card.selected {
  transform: translateY(-16px) rotate(0deg) scale(1.06);
  box-shadow:
    0 0 0 3px var(--gold),
    0 0 18px rgba(250, 204, 21, 0.7),
    0 12px 20px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.card.dead {
  filter: grayscale(0.7);
  opacity: 0.6;
}

.card.dead::after {
  content: '';
  position: absolute;
  inset: 45% 8%;
  border-top: 2px solid rgba(193, 18, 31, 0.8);
  transform: rotate(-35deg);
}

.players {
  list-style: none;
  margin: 2px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  font-size: 0.82rem;
  color: var(--muted);
}

.players li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
}

.players li.current {
  color: #fff;
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--gold);
}

.players .count {
  font-size: 0.72rem;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

/* Winner overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.8));
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
  animation: fade 0.4s ease-out;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.panel {
  background:
    radial-gradient(ellipse at 50% 0%, #1f8a4c, var(--felt) 45%, var(--felt-dark));
  border: 2px solid var(--gold);
  border-radius: 20px;
  padding: 26px 24px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow:
    0 0 0 6px rgba(233, 196, 106, 0.15),
    0 20px 60px rgba(0, 0, 0, 0.6);
}

.winner-panel {
  animation: pop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.winner-panel h2 {
  color: var(--gold-light);
  font-size: 1.7rem;
  margin: 12px 0 18px;
}

.trophy {
  font-size: 3.4rem;
  animation: bounce 1.4s ease-in-out infinite;
}

@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
}

@keyframes bounce {
  50% {
    transform: translateY(-8px) rotate(-4deg);
  }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 40px);
  opacity: 0;
  background: linear-gradient(180deg, #2a1608, #160b03);
  border: 1px solid var(--gold);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  transition: all 0.2s;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  z-index: 20;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 15;
}

@media (min-width: 700px) {
  .card {
    --w: 64px;
  }

  .hand {
    gap: 0;
  }

  .hand .card + .card {
    margin-left: -10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Computer players -------------------------------------------------------- */

.solo {
  border: 0;
  margin: 0;
  padding: 0;
  /* Fieldsets default to min-content width, which overflows narrow phones. */
  min-width: 0;
  display: grid;
  gap: 10px;
}

.solo legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
}

.levels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.level {
  --level: #4ade80;
  position: relative;
  display: block;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  color: inherit;
}

.level-medium {
  --level: #fbbf24;
}

.level-hard {
  --level: #f87171;
}

.level input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.level span {
  display: block;
  text-align: center;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.3);
  font-weight: 700;
  font-size: 0.9rem;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}

.level span::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--level);
  margin-right: 6px;
  vertical-align: middle;
  box-shadow: 0 0 6px var(--level);
}

.level input:checked + span,
button.level:hover span {
  border-color: var(--level);
  background: rgba(0, 0, 0, 0.45);
  box-shadow:
    0 0 0 1px var(--level),
    0 0 12px color-mix(in srgb, var(--level) 45%, transparent);
}

.level input:focus-visible + span {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.add-bot {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px dashed rgba(233, 196, 106, 0.4);
  background: rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
}

.tag.level-easy {
  background: rgba(74, 222, 128, 0.18);
  color: #bbf7d0;
}

.tag.level-medium {
  background: rgba(251, 191, 36, 0.18);
  color: #fde68a;
}

.tag.level-hard {
  background: rgba(248, 113, 113, 0.2);
  color: #fecaca;
}

.icon-btn {
  margin-left: auto;
  border: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fecaca;
  font-size: 0.75rem;
}

.team li {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.thinking {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

/* Accounts, ranking and reviews ------------------------------------------- */

.account {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 36px;
}

.sign-hint {
  text-align: right;
  margin: 4px 0 0;
}

.btn.google {
  background: #fff;
  color: #1f1f1f;
  border-color: #dadce0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn.google .g {
  font-weight: 900;
  background: conic-gradient(from -45deg, #ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.btn.me {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  border: 1.5px solid var(--gold);
}

.avatar.sm {
  width: 22px;
  height: 22px;
}

.avatar.lg {
  width: 72px;
  height: 72px;
  border-width: 3px;
}

.avatar.lg.letter {
  font-size: 2rem;
}

.avatar.letter {
  display: inline-grid;
  place-items: center;
  background: var(--gold-dark);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.review {
  text-align: left;
  margin: 4px 0 16px;
}

.review h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--gold-light);
  text-align: center;
}

.table-wrap {
  overflow-x: auto;
}

.review table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.review th,
.review td {
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
}

.review td:first-child {
  text-align: left;
}

.review tbody tr + tr td {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.pills {
  display: inline-flex;
  gap: 3px;
}

.pill {
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #111;
  background: var(--q);
}

.legend .pill {
  font-size: 0.65rem;
}

.q-best {
  --q: #4ade80;
}
.q-good {
  --q: #a3e635;
}
.q-inaccuracy {
  --q: #facc15;
}
.q-mistake {
  --q: #fb923c;
}
.q-blunder {
  --q: #f87171;
}

.up {
  color: #86efac;
  font-weight: 700;
}

.down {
  color: #fca5a5;
  font-weight: 700;
}

.winner-panel {
  max-width: 520px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.stats-screen {
  display: grid;
  gap: 14px;
  max-width: 640px;
}

.stats-screen h3 {
  margin: 8px 0 0;
  color: var(--gold-light);
}

.ranking,
.recent,
.h2h {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.ranking li,
.recent li,
.h2h li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(233, 196, 106, 0.18);
}

.ranking li.me {
  border-color: var(--gold);
}

.ranking .pos {
  width: 28px;
  text-align: center;
  font-weight: 800;
}

.ranking .rating,
.h2h strong {
  margin-left: auto;
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--gold-light);
}

.recent li {
  justify-content: space-between;
  flex-wrap: wrap;
}

.link {
  border: 0;
  background: none;
  color: inherit;
  padding: 0;
  font-weight: 700;
  text-align: left;
}

.profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
}

.profile-head h3 {
  margin: 0;
}

.big-rating {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(180deg, #fff6d2, var(--gold) 55%, var(--gold-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.profile-head p {
  margin: 2px 0 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.stat {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(233, 196, 106, 0.18);
}

.stat strong {
  font-size: 1.2rem;
}

.quality-bars {
  display: grid;
  gap: 6px;
}

.qbar {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 32px;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.qbar .mark {
  color: var(--q);
  display: inline-block;
  width: 1.6em;
}

.qbar .track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.qbar .fill {
  display: block;
  height: 100%;
  background: var(--q);
}

/* Room chat ---------------------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.chat {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 18;
  display: grid;
  justify-items: end;
  gap: 8px;
}

.chat[hidden],
.chat-panel[hidden],
.chat-badge[hidden] {
  display: none;
}

.chat-toggle {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: radial-gradient(circle at 35% 30%, #2a1608, #160b03);
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgb(0 0 0 / 0.45);
  order: 2;
}

.chat.open .chat-toggle {
  display: none;
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--red-ink);
  color: #fff;
  font-size: 0.75rem;
  line-height: 18px;
}

.chat-panel {
  width: min(340px, calc(100vw - 24px));
  height: min(420px, 60dvh);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  background: linear-gradient(180deg, #1c0f05, #0f0802);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.55);
  overflow: hidden;
}

.chat-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgb(233 196 106 / 0.3);
  color: var(--gold-light);
}

.chat-close {
  background: none;
  border: 0;
  color: var(--gold-light);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  font-size: 0.92rem;
}

.chat-list li {
  overflow-wrap: anywhere;
}

.chat-list li b {
  margin: 0 6px 0 4px;
  color: var(--gold-light);
}

.chat-list li.mine b {
  color: var(--muted);
}

.chat-empty {
  color: var(--muted);
  text-align: center;
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid rgb(233 196 106 / 0.3);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgb(233 196 106 / 0.4);
  background: rgb(255 255 255 / 0.06);
  color: inherit;
  font: inherit;
  font-size: 16px; /* avoids the iPhone zoom on focus */
}

.chat-form .btn {
  flex: none;
  width: auto;
  min-width: 0;
  padding: 8px 14px;
}

/* Modal dialogs (sign-in offer, confirmations) ---------------------------- */

.modal {
  color: inherit;
  width: min(360px, calc(100vw - 32px));
}

.modal::backdrop {
  background: radial-gradient(circle, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.8));
}

.modal h2 {
  margin: 0 0 10px;
  font-family: var(--serif);
  color: var(--gold-light);
}

.modal p {
  margin: 0 0 12px;
  line-height: 1.4;
}

.sign-in-offer .warning {
  color: var(--gold);
  font-weight: 600;
}

.guest-note {
  color: var(--gold);
}

.abandon {
  margin-top: 4px;
  opacity: 0.85;
}

/* Voice call ---------------------------------------------------------------- */

.voice {
  position: fixed;
  right: calc(12px + 48px + 10px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 17;
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice[hidden],
.voice-mute[hidden],
.voice-badge[hidden],
.voice audio {
  display: none;
}

.voice-toggle,
.voice-mute {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: radial-gradient(circle at 35% 30%, #2a1608, #160b03);
  font-size: 1.35rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgb(0 0 0 / 0.45);
}

.voice-mute {
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
}

.voice.live .voice-toggle {
  border-color: #22c55e;
  background: radial-gradient(circle at 35% 30%, #166534, #052e16);
  box-shadow:
    0 0 0 3px rgb(34 197 94 / 0.35),
    0 6px 16px rgb(0 0 0 / 0.45);
}

.voice.live.connecting .voice-toggle {
  border-color: #f59e0b;
  animation: voice-connecting 1.2s ease-in-out infinite;
}

@keyframes voice-connecting {
  50% {
    box-shadow:
      0 0 0 6px rgb(245 158 11 / 0.45),
      0 6px 16px rgb(0 0 0 / 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice.live.connecting .voice-toggle {
    animation: none;
  }
}

.voice-mute[aria-pressed='true'] {
  border-color: var(--red-ink);
}

.voice-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  font-size: 0.75rem;
  line-height: 18px;
}
