:root {
  --felt-1: #17603a;
  --felt-2: #0c3b23;
  --felt-3: #072517;
  --gold: #e8c568;
  --gold-dim: #b99a4e;
  --gold-deep: #8a6d2f;
  --ivory: #faf6ec;
  --ivory-dim: #e8e2d2;
  --ink: #1d222b;
  --red: #c62f39;
  --red-hot: #e8414d;
  --purple: #7c3aed;
  --good: #2f9e5f;
  --bad: #d4544d;
  --panel: rgba(6, 26, 16, 0.72);
  --panel-line: rgba(232, 197, 104, 0.22);
  --card-w: 96px;
  --mini-w: 34px;
  --back-w: 30px;
  --shadow-card: 0 4px 10px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.4);
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { overscroll-behavior: none; } /* no accidental pull-to-refresh mid-game */
button, .card, .card-back, .hand-slot, .pile-spot, .code-chip { touch-action: manipulation; } /* kill double-tap zoom on controls */
body {
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ivory);
  background:
    radial-gradient(ellipse 120% 90% at 50% 30%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  background-attachment: fixed;
  min-height: 100%;
  overflow-x: hidden;
}
/* subtle felt texture */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}
button { font: inherit; cursor: pointer; border: none; }
input, select { font: inherit; }
#app { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ======================= generic ======================= */
.screen { display: none; flex: 1; flex-direction: column; }
.screen.active { display: flex; }
.btn {
  padding: 13px 26px; border-radius: 12px; font-weight: 700; letter-spacing: .4px;
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.btn-gold {
  background: linear-gradient(160deg, #f3d98b 0%, var(--gold) 45%, #c9a24d 100%);
  color: #3a2c0c; box-shadow: 0 4px 14px rgba(232,197,104,.35), inset 0 1px 0 rgba(255,255,255,.55);
}
.btn-gold:hover:not(:disabled) { filter: brightness(1.06); box-shadow: 0 6px 20px rgba(232,197,104,.45); }
.btn-ghost {
  background: rgba(255,255,255,.07); color: var(--ivory);
  border: 1px solid rgba(255,255,255,.2);
}
.btn-ghost:hover { background: rgba(255,255,255,.13); }
.btn-danger {
  background: linear-gradient(160deg, #f2606b, var(--red) 60%, #9c1f28);
  color: #fff; box-shadow: 0 4px 16px rgba(198,47,57,.45), inset 0 1px 0 rgba(255,255,255,.3);
}
.panel {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: var(--radius); backdrop-filter: blur(8px);
  box-shadow: 0 10px 34px rgba(0,0,0,.4);
}
.field { display: flex; flex-direction: column; gap: 7px; text-align: left; }
.field label { font-size: 12px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; color: var(--gold-dim); }
.field input, .field select {
  padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.35); color: var(--ivory); outline: none; transition: border-color .15s;
}
.field input:focus, .field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,197,104,.15); }
.field input::placeholder { color: rgba(250,246,236,.35); }

/* ======================= HOME ======================= */
#screen-home { align-items: center; justify-content: center; padding: 16px; gap: 16px; }
.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(52px, 11vw, 92px); font-weight: 700; letter-spacing: .14em;
  background: linear-gradient(175deg, #f7e3a3 8%, var(--gold) 42%, #a5813a 78%, #f1d788 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.55));
  line-height: 1; text-align: center;
}
.tagline { color: var(--ivory-dim); opacity: .75; letter-spacing: 3.5px; text-transform: uppercase; font-size: 13px; text-align: center; margin-top: -14px; }
.logo-cards { display: flex; justify-content: center; gap: 0; margin-bottom: -8px; height: 74px; }
.logo-cards .card { --card-w: 52px; position: relative; animation: fan-in .7s cubic-bezier(.2,.8,.3,1.2) backwards; }
.logo-cards .card:nth-child(1) { transform: rotate(-16deg) translateY(8px); animation-delay: .05s; }
.logo-cards .card:nth-child(2) { transform: rotate(-5deg); animation-delay: .15s; }
.logo-cards .card:nth-child(3) { transform: rotate(6deg) translateY(2px); animation-delay: .25s; }
.logo-cards .card:nth-child(4) { transform: rotate(17deg) translateY(12px); animation-delay: .35s; }
@keyframes fan-in { from { opacity: 0; transform: translateY(40px) rotate(0); } }
#rejoin-banner {
  display: none; align-items: center; gap: 14px; padding: 12px 18px; border-radius: 12px;
  background: rgba(232,197,104,.12); border: 1px solid var(--panel-line); font-size: 14px;
}
#rejoin-banner.visible { display: flex; }
#rejoin-banner button { padding: 8px 16px; font-size: 13px; }
.home-panels { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 760px; }
.home-card { flex: 1 1 300px; max-width: 360px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.home-card h2 { font-size: 15px; letter-spacing: 2.5px; text-transform: uppercase; color: var(--gold); display: flex; align-items: center; gap: 9px; }
.home-hint { font-size: 13.5px; line-height: 1.55; color: var(--ivory-dim); flex: 1; }
.home-hint b { color: var(--gold); }
#name-wrap { width: 100%; max-width: 760px; }
#input-code { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; text-align: center; font-size: 19px; }
.rules-toggle { background: none; color: var(--gold-dim); text-decoration: underline dotted; font-size: 13px; }
#rules-box { max-width: 640px; padding: 20px 24px; font-size: 14px; line-height: 1.65; color: var(--ivory-dim); display: none; }
#rules-box.open { display: block; }
#rules-box b { color: var(--gold); }

#more-games {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px;
  padding-top: 12px; border-top: 1px solid var(--panel-line); width: 100%; max-width: 420px;
  font-size: 12.5px;
}
.more-games-label { text-transform: uppercase; letter-spacing: 1px; font-size: 11px; color: var(--ivory-dim); opacity: .7; }
.more-games-link { color: var(--gold-dim); text-decoration: underline dotted; }
.more-games-link:hover { color: var(--gold); }

#watermark {
  display: block; text-align: center; font-size: 11px; letter-spacing: .5px;
  color: var(--ivory-dim); opacity: .5; text-decoration: none;
}
#watermark:hover { opacity: .8; color: var(--gold-dim); }

/* short viewports (landscape phones, small browser windows) — the home
   screen would otherwise need to scroll to show everything */
@media (max-height: 720px) {
  #screen-home { gap: 10px; padding: 10px 16px; }
  .logo { font-size: clamp(38px, 9vw, 60px); }
  .tagline { margin-top: -8px; }
  .logo-cards { height: 46px; margin-bottom: -4px; }
  .logo-cards .card { --card-w: 36px; }
  .home-card { padding: 12px 16px; gap: 6px; }
  .home-panels { gap: 10px; }
  #more-games { padding-top: 8px; font-size: 11.5px; }
}

/* ======================= LOBBY ======================= */
#screen-lobby { align-items: center; justify-content: center; padding: 28px 16px; gap: 22px; }
.room-code-display { text-align: center; }
.room-code-display .label { font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: var(--gold-dim); margin-bottom: 8px; }
.code-chip {
  display: inline-flex; align-items: center; gap: 14px; padding: 14px 26px; cursor: pointer;
  border-radius: 16px; background: rgba(0,0,0,.4); border: 1.5px dashed var(--gold-dim);
  transition: border-color .15s, transform .12s;
}
.code-chip:hover { border-color: var(--gold); transform: scale(1.02); }
.code-chip .code { font-family: Georgia, serif; font-size: 42px; letter-spacing: 12px; font-weight: 700; color: var(--gold); text-indent: 12px; }
.code-chip .copy-hint { font-size: 11px; color: var(--ivory-dim); opacity: .6; }
#invite-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.invite-btn { padding: 9px 18px; font-size: 13.5px; }
#lobby-players { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-width: 700px; }
.lobby-player {
  display: flex; align-items: center; gap: 10px; padding: 11px 18px; border-radius: 999px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); font-weight: 600;
  animation: pop-in .3s cubic-bezier(.3,1.4,.5,1) backwards;
}
.lobby-player .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }
.lobby-player.offline .dot { background: #888; box-shadow: none; }
.lobby-player.me { border-color: var(--gold); background: rgba(232,197,104,.13); }
.lobby-player.bot { border-style: dashed; }
.lobby-player .kick {
  background: none; border: none; color: #ff9aa1; font-weight: 800; font-size: 14px;
  padding: 0 2px; margin-left: 2px; line-height: 1; cursor: pointer; opacity: .7;
}
.lobby-player .kick:hover { opacity: 1; transform: scale(1.15); }
.lobby-player .rename {
  background: none; border: none; color: var(--ivory-dim); font-size: 13px;
  padding: 0 2px; margin-left: -2px; line-height: 1; cursor: pointer; opacity: .6;
}
.lobby-player .rename:hover { opacity: 1; color: var(--gold); }
.lobby-player .rename-input {
  background: rgba(0,0,0,.35); border: 1px solid var(--gold-dim); border-radius: 6px;
  color: var(--ivory); font: inherit; font-weight: 600; padding: 2px 6px; width: 110px; outline: none;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.6); } }
#lobby-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; align-items: center; }
#lobby-status { color: var(--ivory-dim); font-size: 14px; }
#lobby-count { color: var(--gold); font-weight: 700; }

/* ======================= GAME ======================= */
#screen-game { padding: 0 0 12px; }
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(0,0,0,.5), rgba(0,0,0,.18) 85%, transparent);
  border-bottom: 1px solid rgba(232,197,104,.12);
}
.tb-group { display: flex; align-items: center; gap: 10px; }
.tb-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px; border-radius: 999px;
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.12); font-size: 13px; font-weight: 600;
  color: var(--ivory-dim); white-space: nowrap;
}
.tb-chip b { color: var(--gold); font-weight: 800; letter-spacing: 1px; }
#tb-room { cursor: pointer; }
#tb-room:hover { border-color: var(--gold-dim); }
#turn-pill {
  margin-left: auto; padding: 8px 20px; border-radius: 999px; font-weight: 800; font-size: 14px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  transition: all .2s; white-space: nowrap;
}
#turn-pill.mine {
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  box-shadow: 0 0 22px rgba(232,197,104,.5); animation: pill-pulse 1.6s ease-in-out infinite;
}
@keyframes pill-pulse { 50% { box-shadow: 0 0 34px rgba(232,197,104,.8); } }
.tb-btn { background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.12); color: var(--ivory-dim);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.tb-btn:hover { border-color: var(--gold-dim); color: var(--ivory); }

/* --------- the table: opponents on a ring around the felt --------- */
#game-table { position: relative; flex: 1; min-height: 460px; }
/* elliptical table edge behind the piles */
#game-table::before {
  content: ""; position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%);
  width: min(62%, 820px); height: min(66%, 440px); border-radius: 50%;
  background: radial-gradient(ellipse at 50% 38%, rgba(255,255,255,.045), rgba(0,0,0,.2) 78%);
  border: 2px solid rgba(232,197,104,.2);
  box-shadow: inset 0 0 46px rgba(0,0,0,.4), 0 0 30px rgba(0,0,0,.25);
  pointer-events: none;
}
#opp-ring { position: absolute; inset: 8px 10px 0; }
#opp-ring .opp { position: absolute; transform: translate(-50%, -50%); }
#opp-ring.crowded { --back-w: 26px; }
#opp-ring.crowded .opp { min-width: 0; padding: 6px 11px 5px; gap: 2px; border-radius: 11px; }
#opp-ring.crowded .opp-name { font-size: 12px; gap: 4px; max-width: 130px; }
#opp-ring.crowded .opp-score { font-size: 11px; gap: 5px; }
#opp-ring.crowded .opp-score b { font-size: 12px; }
#opp-ring.crowded .badge { font-size: 9px; padding: 1px 6px; }
#table-mid {
  position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; max-width: 60%;
}
.opp {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 9px 13px 9px; border-radius: 14px; min-width: 148px;
  background: rgba(0,0,0,.32); border: 1.5px solid rgba(255,255,255,.1);
  transition: border-color .2s, box-shadow .25s, opacity .2s;
}
.opp.turn {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 26px rgba(232,197,104,.4);
  animation: opp-glow 1.8s ease-in-out infinite;
}
@keyframes opp-glow { 50% { box-shadow: 0 0 0 1px var(--gold), 0 0 40px rgba(232,197,104,.62); } }
/* one-shot flash the instant the turn arrives at this seat, layered on the ambient glow above */
.opp.turn.turn-flash { animation: opp-glow 1.8s ease-in-out infinite, opp-flash .6s ease; }
@keyframes opp-flash { from { transform: scale(1.07); } }
.opp.eliminated { opacity: .42; filter: grayscale(.75); }
.opp.eliminated .opp-name { text-decoration: line-through; }
.opp.offline { opacity: .55; border-style: dashed; }
.opp-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* opponents' backs overlap into a compact stack — a fan, like a held hand */
.opp-cards { display: flex; padding: 2px 0 0; }
.opp-cards .card-back { box-shadow: -2px 2px 5px rgba(0,0,0,.45); }
.opp-cards .card-back:not(:first-child) { margin-left: calc(var(--back-w) * -0.55); }
.opp-score { font-size: 12.5px; color: var(--ivory-dim); display: flex; gap: 8px; align-items: center; }
.opp-score b { color: var(--gold); font-size: 14px; }
.badge { font-size: 10px; font-weight: 800; letter-spacing: 1px; padding: 2px 8px; border-radius: 999px; }
.badge.elim { background: rgba(198,47,57,.25); color: #ff9aa1; border: 1px solid rgba(198,47,57,.5); }
.badge.off  { background: rgba(255,255,255,.1); color: #aaa; }
.badge.delta-plus { background: rgba(198,47,57,.22); color: #ffb3b8; }
.badge.delta-zero { background: rgba(47,158,95,.25); color: #9fe8bf; }

/* --------- table center --------- */
#table-center {
  display: flex; align-items: center; justify-content: center; gap: clamp(26px, 7vw, 80px);
  padding: 18px 12px 10px; flex: 1;
}
.pile { display: flex; flex-direction: column; align-items: center; gap: 9px; }
.pile-label { font-size: 11px; letter-spacing: 2.4px; text-transform: uppercase; color: var(--gold-dim); font-weight: 700; }
.pile-spot {
  position: relative; width: var(--card-w); aspect-ratio: 5 / 7; border-radius: 10px;
}
.pile-empty {
  position: absolute; inset: 0; border-radius: 10px; border: 2px dashed rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: rgba(255,255,255,.3);
}
.pile-clickable { cursor: pointer; }
.pile-clickable .card, .pile-clickable .card-back { animation: pile-beckon 1.5s ease-in-out infinite; }
@keyframes pile-beckon {
  0%, 100% { box-shadow: var(--shadow-card), 0 0 0 2px var(--gold), 0 0 18px rgba(232,197,104,.55); }
  50%      { box-shadow: var(--shadow-card), 0 0 0 2px var(--gold), 0 0 34px rgba(232,197,104,.9); }
}
.pile-count {
  position: absolute; top: -9px; right: -9px; z-index: 3; min-width: 26px; height: 26px; padding: 0 7px;
  border-radius: 999px; background: var(--gold); color: #3a2c0c; font-weight: 800; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
/* one-shot feedback: a card just left the draw pile / landed on the discard pile */
.pile-pop { animation: pile-pop .4s cubic-bezier(.3,1.4,.4,1); }
@keyframes pile-pop { 0% { transform: scale(.88) rotate(-4deg); } 60% { transform: scale(1.07) rotate(2deg); } }
.your-discard-note { font-size: 11px; color: var(--ivory-dim); opacity: .75; display: flex; align-items: center; gap: 5px; }
.your-discard-note .mini-tag { color: var(--gold); font-weight: 700; }
#pile-hint { text-align: center; font-size: 13px; color: var(--gold); min-height: 20px; font-weight: 600; letter-spacing: .4px; }

/* --------- table action feed --------- */
#table-feed { display: flex; justify-content: center; min-height: 40px; padding: 2px 12px; }
.feed-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 16px; border-radius: 999px;
  background: rgba(0,0,0,.5); border: 1px solid var(--panel-line);
  font-size: 13.5px; color: var(--ivory-dim); font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  animation: feed-in .35s cubic-bezier(.2,.9,.3,1.2);
  transition: opacity .6s ease, transform .6s ease;
}
.feed-chip.fade { opacity: 0; transform: translateY(-8px); }
.feed-chip b { color: var(--gold); }
.feed-chip .card.mini { --card-w: 26px; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.feed-chip .deck-icon {
  width: 18px; aspect-ratio: 5/7; border-radius: 3px; flex-shrink: 0;
  background: repeating-linear-gradient(45deg, #143c6b 0 3px, #0e2c50 3px 6px);
  border: 1px solid var(--gold);
}
.feed-chip.grab { border-color: rgba(232,197,104,.55); background: rgba(232,197,104,.12); color: var(--ivory); }
@keyframes feed-in { from { opacity: 0; transform: translateY(14px) scale(.9); } }

/* --------- confirm modal --------- */
.confirm-box { max-width: 400px; }
.confirm-box .overlay-title { font-size: 23px; }
.join-code { color: var(--gold); font-family: Georgia, serif; font-size: 17px; letter-spacing: 3px; }

/* --------- cards --------- */
.card {
  width: var(--card-w); aspect-ratio: 5 / 7; border-radius: calc(var(--card-w) * .1);
  background: linear-gradient(160deg, #fffdf6 0%, var(--ivory) 55%, #efe8d5 100%);
  color: var(--ink); position: relative; box-shadow: var(--shadow-card);
  border: 1px solid rgba(0,0,0,.15);
  user-select: none; flex-shrink: 0;
  font-family: Georgia, "Times New Roman", serif;
}
.card.red { color: var(--red); }
.card .corner { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.card .corner.tl { top: 6%; left: 7%; }
.card .corner.br { bottom: 6%; right: 7%; transform: rotate(180deg); }
.card .corner .r { font-size: calc(var(--card-w) * .19); font-weight: 700; }
.card .corner .s { font-size: calc(var(--card-w) * .15); margin-top: 1px; }
.card .center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--card-w) * .42); }
.card .center.face .face-icon { width: calc(var(--card-w) * .8); }
.card .center.face .face-icon .face-svg { display: block; width: 100%; height: auto; }
.card .pts {
  position: absolute; bottom: 5%; left: 50%; transform: translateX(-50%);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif; white-space: nowrap;
  font-size: calc(var(--card-w) * .105); font-weight: 800; padding: 1px 7px; border-radius: 999px;
  background: rgba(29,34,43,.09); color: rgba(29,34,43,.65); letter-spacing: .3px;
}
.card.red .pts { background: rgba(198,47,57,.1); color: rgba(198,47,57,.75); }
/* face cards: the illustration bleeds behind the badge/corners, so they need a
   solid-enough backdrop to stay legible over busy artwork instead of plain ivory */
.card.has-face-art .pts { background: #faf6ec; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.card.has-face-art.red .pts { color: var(--red); }
/* good/bad tints */
.card.low  { box-shadow: var(--shadow-card), inset 0 0 0 2px rgba(47,158,95,.5); }
.card.low  .pts { background: rgba(47,158,95,.16); color: #1c7a45; }
.card.high { box-shadow: var(--shadow-card), inset 0 0 0 2px rgba(212,84,77,.45); }
/* joker */
.card.joker { color: var(--purple); border: 2px solid var(--gold); background: linear-gradient(160deg, #fdf9ff 0%, #f3ecfc 60%, #e9defa 100%); }
.card.joker .jk-label {
  position: absolute; top: 8%; left: 0; right: 0; text-align: center; z-index: 1;
  font-size: calc(var(--card-w) * .11); font-weight: 800; letter-spacing: 2px; font-family: "Avenir Next", system-ui, sans-serif;
  padding: 1px 0; border-radius: 6px; background: rgba(253,249,255,.95);
}
.card.joker .pts { background: #fdf9ff; color: var(--purple); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.card.joker .center.joker-art { padding-top: 2%; }
.card.joker .face-icon { width: calc(var(--card-w) * .78); }
.card.joker .face-icon .face-svg { display: block; width: 100%; height: auto; }
/* card back */
.card-back {
  width: var(--back-w); aspect-ratio: 5 / 7; border-radius: calc(var(--back-w) * .13);
  background:
    radial-gradient(circle at 50% 50%, rgba(232,197,104,.28) 0, transparent 42%),
    repeating-linear-gradient(45deg, #143c6b 0 5px, #0e2c50 5px 10px);
  border: 1.5px solid #e8c568; box-shadow: 0 2px 6px rgba(0,0,0,.45);
  position: relative; flex-shrink: 0;
}
.card-back::after {
  content: "◆"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-size: calc(var(--back-w) * .42); opacity: .9; text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.card-back.big { width: var(--card-w); border-width: 2px; border-radius: calc(var(--card-w) * .1); }
.card.mini { --card-w: var(--mini-w); border-radius: 5px; }
.card.mini .pts { display: none; }
.card.mini .corner.br { display: none; }
.card.mini .corner.tl { top: 5%; left: 8%; }
.card.mini .center { font-size: calc(var(--mini-w) * .5); padding-top: 20%; }
.card.mini .center.face .face-icon { width: calc(var(--mini-w) * .8); }
.card.mini .jk-label { display: none; }

/* --------- my area --------- */
#my-area {
  position: relative; /* anchors the own-reaction bubble — no viewport math, immune to mobile quirks */
  margin: 4px 10px 0; padding: 14px 16px 16px; border-radius: 18px 18px 14px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.42), rgba(0,0,0,.55));
  border: 1px solid rgba(232,197,104,.18);
  display: flex; flex-direction: column; align-items: center; gap: 11px;
}
/* one-shot golden ring the instant it becomes your turn */
#my-area.turn-flash { animation: my-turn-flash .7s ease; }
@keyframes my-turn-flash {
  0%   { box-shadow: 0 0 0 0 rgba(232,197,104,.9); }
  70%  { box-shadow: 0 0 0 10px rgba(232,197,104,0); }
  100% { box-shadow: 0 0 0 0 rgba(232,197,104,0); }
}
#my-header { display: flex; align-items: center; gap: 10px; width: 100%; }
.my-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  font-weight: 800; font-size: 14px;
}
.my-avatar img { width: 100%; height: 100%; object-fit: cover; }
#my-name-label {
  font-weight: 700; font-size: 14.5px; color: var(--ivory); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#my-comms { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#my-status { font-size: 14.5px; font-weight: 700; letter-spacing: .3px; color: var(--ivory-dim); min-height: 21px; }
#my-status.action { color: var(--gold); animation: status-blink 1.5s ease-in-out infinite; }
@keyframes status-blink { 50% { opacity: .65; } }
#hand { display: flex; gap: clamp(6px, 1.6vw, 14px); justify-content: center; perspective: 900px; }
.hand-slot { position: relative; transition: transform .15s ease; }
.hand-slot .card { transition: transform .16s ease, box-shadow .16s ease; }
.hand-slot.selectable { cursor: pointer; }
.hand-slot.selectable .card { animation: card-ready 1.8s ease-in-out infinite; }
.hand-slot.selectable:hover { transform: translateY(-12px); }
.hand-slot.selectable:hover .card { box-shadow: var(--shadow-card), 0 0 0 2.5px var(--gold), 0 14px 30px rgba(0,0,0,.5); }
.hand-slot.selected { transform: translateY(-16px); }
.hand-slot.selected .card {
  animation: none;
  box-shadow: var(--shadow-card), 0 0 0 3px var(--gold), 0 0 26px rgba(232,197,104,.65), 0 14px 30px rgba(0,0,0,.5);
}
.hand-slot.match-hint .card { animation: card-ready .9s ease-in-out infinite; }
@keyframes card-ready {
  0%, 100% { box-shadow: var(--shadow-card), 0 0 0 2px rgba(232,197,104,.55); }
  50%      { box-shadow: var(--shadow-card), 0 0 0 2px rgba(232,197,104,.95), 0 0 20px rgba(232,197,104,.4); }
}
.hand-slot .empty-slot {
  width: var(--card-w); aspect-ratio: 5 / 7; border-radius: calc(var(--card-w) * .1);
  border: 2px dashed rgba(232,197,104,.4); background: rgba(232,197,104,.05);
  display: flex; align-items: center; justify-content: center; color: rgba(232,197,104,.5); font-size: 24px;
}
.dealt { animation: deal-in 2s cubic-bezier(.2,.9,.3,1.1) backwards; }
@keyframes deal-in {
  from { opacity: 0; transform: translateY(-90px) translateX(40px) rotate(14deg) scale(.7); }
}
/* A freshly dealt card that's also selectable (you're opening the round) or
   showing a match-hint would otherwise have its one-shot deal-in animation
   silently overridden by the higher-specificity infinite pulse below —
   this wins on class-count alone regardless of source order. */
.hand-slot.selectable .card.dealt,
.hand-slot.match-hint .card.dealt { animation: deal-in 2s cubic-bezier(.2,.9,.3,1.1) backwards; }
.discarding { animation: fly-up .35s ease-in forwards; }
@keyframes fly-up { to { opacity: 0; transform: translateY(-140px) rotate(-9deg) scale(.85); } }
#hand-total { font-size: 13.5px; color: var(--ivory-dim); }
#hand-total b { color: var(--gold); font-size: 16px; }
#my-bottom-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: center; }
#btn-show {
  padding: 14px 44px; font-size: 19px; font-weight: 900; letter-spacing: 2.5px; border-radius: 14px;
  text-transform: uppercase;
}
#btn-show.armed { animation: show-pulse 1.1s ease-in-out infinite; }
@keyframes show-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(198,47,57,.45); transform: scale(1); }
  50%      { box-shadow: 0 4px 30px rgba(232,65,77,.85); transform: scale(1.035); }
}
#my-total-chip { font-size: 13px; color: var(--ivory-dim); }
#my-total-chip b { color: var(--gold); font-size: 15px; }

/* drew-card popup */
#drew-pop {
  position: fixed; left: 50%; top: 44%; transform: translate(-50%, -50%); z-index: 60;
  display: none; flex-direction: column; align-items: center; gap: 10px; pointer-events: none;
}
#drew-pop.visible { display: flex; animation: drew-in 1.7s ease forwards; }
#drew-pop .label { font-size: 13px; font-weight: 800; letter-spacing: 2.5px; text-transform: uppercase; color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,.8); }
#drew-pop .card { --card-w: 120px; }
@keyframes drew-in {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotateY(90deg); }
  16%  { opacity: 1; transform: translate(-50%, -50%) scale(1.06) rotateY(0); }
  24%  { transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.85); }
}

/* post-login welcome banner — the squiggle draws itself in first, then the
   name fades in below it, then after a hold the whole thing fades out. */
#welcome-banner {
  position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 85;
  display: none; flex-direction: column; align-items: center; gap: 10px; pointer-events: none;
  text-align: center; opacity: 1;
}
#welcome-banner.visible { display: flex; animation: welcome-fade-out .5s ease 3.3s forwards; }
#welcome-banner svg { width: min(72vw, 340px); height: auto; filter: drop-shadow(0 6px 20px rgba(0,0,0,.5)); }
/* stroke-dasharray/dashoffset both use the artwork's pathLength="100" units, so a
   dash the same length as the path (100) offset by a full 100 hides it entirely;
   animating the offset down to 0 reveals it start-to-end, classic SVG line-draw. */
#welcome-banner svg path { stroke-dasharray: 100; stroke-dashoffset: 100; }
#welcome-banner.visible svg path { animation: draw-squiggle 1.3s ease-out forwards; }
#welcome-banner .welcome-text {
  font-family: Georgia, serif; font-size: 22px; color: var(--gold); letter-spacing: .5px;
  text-shadow: 0 2px 10px rgba(0,0,0,.6);
  opacity: 0; transform: translateY(6px);
}
#welcome-banner.visible .welcome-text { animation: welcome-text-in .5s ease forwards; animation-delay: 1.3s; }
@keyframes draw-squiggle { to { stroke-dashoffset: 0; } }
@keyframes welcome-text-in { to { opacity: 1; transform: translateY(0); } }
@keyframes welcome-fade-out { to { opacity: 0; } }

/* ======================= OVERLAYS ======================= */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(4, 16, 10, .82); backdrop-filter: blur(6px);
}
.overlay.visible { display: flex; }
.overlay-box {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  padding: 26px 26px 22px; text-align: center;
  animation: overlay-in .4s cubic-bezier(.2,.9,.3,1.15);
}
@keyframes overlay-in { from { opacity: 0; transform: translateY(36px) scale(.94); } }
.overlay-title { font-family: Georgia, serif; font-size: 27px; color: var(--gold); letter-spacing: 1px; margin-bottom: 6px; }
.overlay-sub { color: var(--ivory-dim); font-size: 14.5px; margin-bottom: 18px; }
/* personalized round verdict */
.verdict-banner {
  margin: 2px auto 14px; padding: 13px 26px; border-radius: 14px; max-width: 440px;
  animation: verdict-pop .55s cubic-bezier(.25,1.3,.4,1) .15s backwards;
}
.verdict-banner .v-main { font-family: Georgia, serif; font-size: 26px; font-weight: 700; letter-spacing: 1.5px; }
.verdict-banner .v-sub { font-size: 13px; margin-top: 4px; opacity: .9; }
.verdict-banner.win {
  background: linear-gradient(160deg, rgba(47,158,95,.28), rgba(47,158,95,.12));
  border: 1.5px solid rgba(47,158,95,.65); color: #8ff0b6;
  box-shadow: 0 0 34px rgba(47,158,95,.3);
}
.verdict-banner.lose {
  background: linear-gradient(160deg, rgba(198,47,57,.3), rgba(198,47,57,.12));
  border: 1.5px solid rgba(232,65,77,.6); color: #ffa8ae;
  box-shadow: 0 0 34px rgba(198,47,57,.28);
}
.verdict-banner.neutral {
  background: rgba(232,197,104,.1); border: 1.5px solid rgba(232,197,104,.4); color: var(--gold);
}
@keyframes verdict-pop { from { opacity: 0; transform: scale(.55) rotate(-3deg); } }
.result-rows { display: flex; flex-direction: column; gap: 9px; margin-bottom: 16px; }
.result-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 13px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.09); text-align: left;
  animation: pop-in .35s cubic-bezier(.3,1.3,.5,1) backwards;
}
.result-row.winner-row { border-color: rgba(47,158,95,.6); background: rgba(47,158,95,.1); position: relative; overflow: hidden; }
.result-row.winner-row::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 35%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.35), transparent);
  transform: skewX(-20deg);
  animation: podium-shine 2.6s ease-in-out .8s infinite;
}
.result-row.penalty-row { border-color: rgba(198,47,57,.55); background: rgba(198,47,57,.09); }
.result-row .rname { font-weight: 700; font-size: 14px; width: 108px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-row .rcards { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.result-row .rcards .card { animation: flip-in .45s ease backwards; }
@keyframes flip-in { from { transform: rotateY(90deg); opacity: 0; } }
.result-row .rscore { font-weight: 800; font-size: 15px; width: 42px; text-align: right; color: var(--ivory); }
.result-row .rpts { font-weight: 800; font-size: 14px; width: 62px; text-align: right; }
.rpts.zero { color: #7fe0a8; } .rpts.pain { color: #ff9aa1; }
#result-elim { font-size: 13.5px; color: #ff9aa1; min-height: 18px; margin-bottom: 8px; }
#result-countdown { font-size: 14px; color: var(--gold); font-weight: 700; letter-spacing: 1px; }

/* game over */
#go-podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 16px 0 8px; }
.podium-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 118px; animation: pop-in .5s cubic-bezier(.3,1.35,.5,1) backwards; }
.podium-slot .p-medal { font-size: 32px; line-height: 1; }
.podium-slot .p-name { font-weight: 800; font-size: 14px; max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-slot .p-score { font-size: 12px; color: var(--ivory-dim); }
.podium-base {
  width: 100%; border-radius: 9px 9px 4px 4px; display: flex; align-items: center;
  justify-content: center; font-weight: 900; font-size: 19px; box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 4px 12px rgba(0,0,0,.4);
}
.podium-slot.p1 .podium-base {
  height: 78px; background: linear-gradient(160deg, #f3d98b, var(--gold) 55%, #c9a24d); color: #3a2c0c;
  position: relative; overflow: hidden;
}
.podium-slot.p1 .podium-base::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 40%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.75), transparent);
  transform: skewX(-20deg);
  animation: podium-shine 2.6s ease-in-out .6s infinite;
}
@keyframes podium-shine { 0% { left: -60%; } 40%, 100% { left: 130%; } }
.podium-slot.p2 .podium-base { height: 54px; background: linear-gradient(160deg, #d9dde3, #aab2bd 60%, #8b939e); color: #2a2f36; }
.podium-slot.p3 .podium-base { height: 42px; background: linear-gradient(160deg, #dfa06b, #b97843 60%, #96552a); color: #3a2210; }
#go-trophy { font-size: 74px; line-height: 1; animation: trophy-bounce 1.4s ease infinite; }
@keyframes trophy-bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-13px); } }
#go-winner { font-family: Georgia, serif; font-size: 34px; color: var(--gold); margin: 8px 0 2px; }
#go-standings { display: flex; flex-direction: column; gap: 7px; margin: 18px 0; }
.standing {
  display: flex; align-items: center; gap: 12px; padding: 9px 15px; border-radius: 10px;
  background: rgba(255,255,255,.05); font-size: 14.5px; text-align: left;
}
.standing .pos { font-weight: 900; color: var(--gold-dim); width: 26px; }
.standing .sname { flex: 1; font-weight: 700; }
.standing .sscore { font-weight: 800; color: var(--ivory-dim); }
.standing.first { background: rgba(232,197,104,.14); border: 1px solid rgba(232,197,104,.45); }
.go-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
/* confetti — tumbling suit symbols instead of plain rectangles */
.confetti {
  position: fixed; top: -28px; z-index: 55; line-height: 1; pointer-events: none;
  font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 2px 6px rgba(0,0,0,.35); animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(760deg); opacity: .2; }
}
/* round-win burst — a quick pop of symbols from the win banner, not a full rain */
.confetti-burst {
  position: fixed; z-index: 65; line-height: 1; pointer-events: none;
  font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 2px 6px rgba(0,0,0,.35);
  animation: burst-fly .9s cubic-bezier(.15,.7,.3,1) forwards;
}
@keyframes burst-fly {
  from { transform: translate(-50%, -50%) scale(.4) rotate(0deg); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot)); opacity: 0; }
}

/* toast + banner */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(90px); z-index: 80;
  padding: 12px 22px; border-radius: 12px; background: rgba(20, 6, 8, .95); color: #ffd9dc;
  border: 1px solid rgba(198,47,57,.6); font-weight: 600; font-size: 14px; max-width: 88vw;
  transition: transform .3s cubic-bezier(.2,.9,.3,1.2); box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#toast.visible { transform: translateX(-50%) translateY(0); }
#toast.info { background: rgba(6, 26, 16, .95); color: var(--ivory); border-color: var(--panel-line); }
#conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90; display: none;
  padding: 9px; text-align: center; font-weight: 700; font-size: 13.5px; letter-spacing: .5px;
  background: linear-gradient(90deg, #7a4a12, #a3670f); color: #ffe9c2;
}
#conn-banner.visible { display: block; }

#invite-toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-20px);
  z-index: 500; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 14px 20px; border-radius: 12px; background: rgba(6, 26, 16, .97); color: var(--ivory);
  border: 1px solid var(--panel-line); max-width: 90vw; text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#invite-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#invite-toast-actions { display: flex; gap: 8px; }

/* ======================= chat & voice ======================= */
.js-chat-toggle { position: relative; }
.chat-badge {
  display: none; position: absolute; top: -7px; right: -7px; min-width: 17px; height: 17px;
  border-radius: 9px; background: #c62f2f; color: #fff; font-size: 11px; font-weight: 800;
  line-height: 17px; text-align: center; padding: 0 4px; pointer-events: none;
}
.chat-badge.has { display: block; }
.js-voice-toggle.active { border-color: rgba(47,158,95,.7); color: #8fe0ae; background: rgba(47,158,95,.18); }
.js-voice-toggle.speaking { box-shadow: 0 0 0 2px rgba(47,158,95,.55), 0 0 12px rgba(47,158,95,.4); }
.js-mic-toggle.muted { border-color: rgba(198,47,47,.7); color: #ff9d9d; background: rgba(198,47,47,.16); }

#chat-panel {
  position: fixed; right: 10px; bottom: 10px; width: 320px; max-width: calc(100vw - 20px);
  height: 430px; max-height: calc(100dvh - 90px); z-index: 85; display: none; flex-direction: column;
  background: linear-gradient(170deg, rgba(10,42,26,.97), rgba(6,26,16,.97));
  border: 1px solid rgba(232,197,104,.25); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
#chat-panel.open { display: flex; }
#chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,.09);
  font-weight: 800; font-size: 14px; color: var(--gold);
}
#chat-close { background: none; border: none; color: var(--ivory-dim); font-size: 15px; cursor: pointer; padding: 2px 6px; }
#chat-close:hover { color: var(--ivory); }
#chat-msgs { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }
.chat-empty { color: rgba(250,246,236,.45); font-size: 13px; text-align: center; margin-top: 18px; }
.chat-msg { max-width: 85%; align-self: flex-start; background: rgba(255,255,255,.07); border-radius: 10px 10px 10px 3px; padding: 6px 10px; }
.chat-msg.mine { align-self: flex-end; background: rgba(232,197,104,.16); border-radius: 10px 10px 3px 10px; }
.chat-name { font-size: 11px; font-weight: 800; color: var(--gold-dim); margin-bottom: 2px; }
.chat-text { font-size: 13.5px; line-height: 1.35; word-break: break-word; white-space: pre-wrap; }
#chat-input-row { display: flex; gap: 7px; padding: 9px 10px; border-top: 1px solid rgba(255,255,255,.09); }
#chat-input {
  flex: 1; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.14); border-radius: 9px;
  color: var(--ivory); padding: 8px 11px; font-size: 16px; outline: none;
}
#chat-input:focus { border-color: var(--gold-dim); }
#chat-send {
  background: var(--gold); color: #2b2109; border: none; border-radius: 9px;
  padding: 0 14px; font-size: 15px; font-weight: 800; cursor: pointer;
}
#chat-send:disabled { opacity: .45; cursor: default; }
#lobby-comms { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.opp.speaking, .lobby-player.speaking {
  box-shadow: 0 0 0 2px rgba(47,158,95,.65), 0 0 16px rgba(47,158,95,.45);
}

/* spectator: seats that can be requested */
.opp.claimable { cursor: pointer; }
.opp.claimable:hover { border-color: var(--gold-dim); box-shadow: 0 0 14px rgba(232,197,104,.3); }

/* seat requests: small corner cards, never block the table */
#seat-pops {
  position: fixed; right: 10px; top: 60px; z-index: 86;
  display: flex; flex-direction: column; gap: 8px; width: 250px; max-width: calc(100vw - 20px);
}
.seat-pop-card {
  background: linear-gradient(170deg, rgba(20,50,32,.97), rgba(8,30,19,.97));
  border: 1px solid rgba(232,197,104,.4); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop-in .35s cubic-bezier(.3,1.35,.5,1) backwards;
}
.seat-pop-card .sp-text { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.seat-pop-card .sp-btns { display: flex; gap: 7px; }
.seat-pop-card .sp-btns .btn { padding: 6px 12px; font-size: 12.5px; flex: 1; }

/* spectator list dropdown */
#spec-pop {
  position: fixed; z-index: 86; min-width: 180px; max-width: 250px;
  background: linear-gradient(170deg, rgba(10,42,26,.97), rgba(6,26,16,.97));
  border: 1px solid rgba(232,197,104,.3); border-radius: 12px; padding: 9px 11px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.spec-pop-title { font-size: 12px; font-weight: 800; color: var(--gold); margin-bottom: 6px; letter-spacing: .5px; }
.spec-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13.5px; }
.spec-row .sname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spec-row .kick {
  background: none; border: 1px solid rgba(198,47,47,.5); color: #ff9d9d;
  border-radius: 7px; padding: 1px 8px; font-size: 12px; cursor: pointer;
}
.spec-row .kick:hover { background: rgba(198,47,47,.2); }
#tb-specs { cursor: pointer; }
#tb-specs:hover { border-color: var(--gold-dim); }

/* emoji reaction picker */
#reaction-pop {
  position: fixed; z-index: 86; display: flex; flex-wrap: wrap; gap: 4px; width: 176px;
  background: linear-gradient(170deg, rgba(10,42,26,.97), rgba(6,26,16,.97));
  border: 1px solid rgba(232,197,104,.3); border-radius: 12px; padding: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: picker-in .18s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes picker-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.reaction-opt {
  background: none; border: none; cursor: pointer; font-size: 24px; line-height: 1;
  padding: 5px; border-radius: 8px; transition: transform .12s, background .12s;
}
.reaction-opt:hover { transform: scale(1.3); background: rgba(255,255,255,.08); }

/* floating reaction bubble over the sender's seat */
.reaction-bubble {
  position: fixed; z-index: 200; transform: translate(-50%,-50%); font-size: 44px; line-height: 1;
  pointer-events: none; filter: drop-shadow(0 4px 14px rgba(0,0,0,.6));
  animation: reaction-pop 2.6s ease forwards;
}
/* your own reaction: a plain child of #my-area, no viewport math at all —
   sidesteps mobile browsers where position:fixed anchors to a different
   viewport than getBoundingClientRect() reports (dynamic address bar etc.) */
.reaction-bubble.own-area { position: absolute; left: 50%; top: 46%; z-index: 20; }
/* round-over flourish — a quick celebratory sticker in the reveal overlay, once per round */
.reaction-bubble.round-end-sticker { position: absolute; left: auto; right: 14px; top: 34px; z-index: 5; }
.reaction-bubble.round-end-sticker .reaction-sticker-img { width: 56px; height: 56px; }
.reaction-sticker-img { width: 72px; height: 72px; object-fit: contain; display: block; }
@keyframes reaction-pop {
  0%        { transform: translate(-50%,-50%) scale(0); opacity: 0; }
  12%       { transform: translate(-50%,-50%) scale(1.3); opacity: 1; }
  20%       { transform: translate(-50%,-50%) scale(.9); }
  28%       { transform: translate(-50%,-50%) scale(1.08); }
  36%, 74%  { transform: translate(-50%,-50%) scale(1); opacity: 1; }
  100%      { transform: translate(-50%,-50%) translateY(-34px) scale(.9); opacity: 0; }
}

@media (max-width: 900px) {
  /* bottom-anchored on phones: clears the opponent strip, sits above the hand */
  #seat-pops { top: auto; bottom: calc(250px + env(safe-area-inset-bottom)); }
}
.voice-badge { font-size: 11px; opacity: .9; }

@media (max-width: 900px) {
  #chat-panel { left: 0; right: 0; bottom: 0; width: auto; max-width: none; height: 55dvh; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ======================= responsive ======================= */
/* =============== mobile: app-like fixed layout, no page scroll =============== */
@media (max-width: 900px) {
  :root { --card-w: 60px; --mini-w: 26px; --back-w: 20px; }

  /* the game screen is exactly one viewport tall — everything always visible */
  #screen-game.active { height: 100vh; height: 100dvh; overflow: hidden; }

  /* one compact row — chips, turn pill, and the (now much shorter) action
     group all fit together since chat/reaction/voice moved to #my-header.
     The chip strip is the one part with genuinely variable-length content
     (room code, round, draw count), so it's the part that scrolls internally
     if it doesn't all fit — the row itself never wraps to a second line. */
  #topbar { padding: 7px 8px calc(0px + env(safe-area-inset-top)) 8px; gap: 5px 6px; flex-shrink: 0; flex-wrap: nowrap; }
  .tb-group { gap: 5px; }
  #tb-actions { flex-shrink: 0; }
  #tb-info {
    flex: 1 1 0; min-width: 40px; overflow-x: auto; scrollbar-width: none;
  }
  #tb-info::-webkit-scrollbar { display: none; }
  .tb-chip { font-size: 11px; padding: 4px 8px; gap: 4px; flex-shrink: 0; }
  .tb-btn { padding: 4px 8px; font-size: 12.5px; min-width: 30px; }
  /* fixed to its own (now short) content width — it must NOT compete for
     shrink room with #tb-info above, or it gets squeezed into illegibility */
  #turn-pill {
    flex-shrink: 0; max-width: 128px; overflow: hidden;
    text-overflow: ellipsis; font-size: 12px; padding: 6px 10px;
  }

  #game-table { display: flex; flex-direction: column; padding: 0; min-height: 0; }
  #game-table::before { display: none; }

  /* opponents: one swipeable strip — the active player is auto-scrolled into view */
  #opp-ring {
    position: static; inset: auto; flex-shrink: 0;
    display: flex; flex-wrap: nowrap; justify-content: flex-start;
    gap: 7px; padding: 8px 10px 6px; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  #opp-ring::-webkit-scrollbar { display: none; }
  #opp-ring .opp {
    position: static; transform: none; flex: 0 0 auto;
    min-width: 92px; padding: 6px 10px 5px; gap: 3px; border-radius: 11px;
  }
  .opp-name { font-size: 11.5px; max-width: 110px; gap: 4px; }
  .opp-score { font-size: 10.5px; gap: 4px; }
  .opp-score > span:first-child { display: none; } /* drop the "Score:" label */
  .opp-score b { font-size: 12px; }
  .badge { font-size: 8.5px; padding: 1px 5px; }

  #table-mid {
    position: static; transform: none; max-width: none;
    flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center;
  }
  #table-center { padding: 4px 8px; gap: clamp(20px, 9vw, 44px); flex: 0 0 auto; }
  .pile-label { font-size: 10px; letter-spacing: 1.8px; }
  .pile-count { min-width: 22px; height: 22px; font-size: 11px; top: -7px; right: -7px; }
  #table-feed { min-height: 32px; padding: 2px 8px; }
  .feed-chip { font-size: 12px; padding: 5px 12px; max-width: 94vw; }
  #pile-hint { font-size: 11.5px; min-height: 16px; }

  /* my area pinned at the bottom, safe-area aware, big touch targets */
  #my-area {
    flex-shrink: 0; margin: 2px 6px 0; padding: 9px 8px calc(10px + env(safe-area-inset-bottom));
    gap: 8px; border-radius: 14px 14px 0 0;
  }
  #my-header { gap: 7px; }
  .my-avatar { width: 28px; height: 28px; font-size: 12px; }
  #my-name-label { font-size: 13px; }
  #my-comms { gap: 4px; }
  #my-status { font-size: 12.5px; min-height: 17px; }
  #hand { gap: 6px; }
  .hand-slot.selected { transform: translateY(-10px); }
  #my-bottom-row { gap: 10px; width: 100%; }
  #my-total-chip { font-size: 11.5px; }
  #btn-show { padding: 13px 0; font-size: 15px; flex: 1; max-width: 240px; letter-spacing: 1.5px; }
  #btn-discard-sel { padding: 12px 16px; font-size: 13.5px; }

  /* overlays */
  .overlay { padding: 10px; }
  .overlay-box { padding: 18px 14px 16px; }
  .overlay-title { font-size: 22px; }
  .verdict-banner { padding: 10px 16px; }
  .verdict-banner .v-main { font-size: 20px; }
  /* two lines: name + score on top, all 5 cards on one full-width row below */
  .result-row { flex-wrap: wrap; gap: 6px 8px; padding: 8px 10px; }
  .result-row .rname { order: 1; flex: 1; width: auto; font-size: 12.5px; }
  .result-row .rscore { order: 2; width: auto; font-size: 12.5px; }
  .result-row .rpts { order: 3; width: auto; font-size: 12px; }
  .result-row .rcards { order: 4; width: 100%; flex: none; flex-wrap: nowrap; justify-content: center; }
  .result-row .rcards .card.mini { --card-w: 30px; --mini-w: 30px; }
  .podium-slot { width: 88px; }
  .podium-slot .p-name { font-size: 12px; max-width: 88px; }
  .podium-slot .p-medal { font-size: 26px; }
  #go-trophy { font-size: 56px; }
  #go-winner { font-size: 26px; }

  /* home & lobby */
  .code-chip .code { font-size: 30px; letter-spacing: 8px; text-indent: 8px; }
  #drew-pop .card { --card-w: 92px; }
  #invite-actions { flex-wrap: wrap; }
}
@media (max-width: 380px) {
  :root { --card-w: 54px; }
  #opp-ring .opp { min-width: 86px; }
}

/* ======================= AUTH ======================= */
#auth-status { display: flex; align-items: center; justify-content: center; gap: 8px; }
#btn-open-friends { height: 42px; padding: 0 14px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.auth-user-chip {
  display: inline-flex; align-items: center; gap: 10px; padding: 8px 16px; border-radius: 999px;
  background: rgba(232,197,104,.12); border: 1px solid var(--panel-line); font-size: 13.5px; font-weight: 600;
}
.auth-user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  font-weight: 800; font-size: 12px; overflow: hidden;
}
.auth-user-chip .avatar img { width: 100%; height: 100%; object-fit: cover; }
.auth-box { max-width: 400px; text-align: left; position: relative; }
.auth-box .overlay-title { text-align: center; }
.overlay-close {
  position: absolute; top: 14px; right: 14px; background: none; color: var(--ivory-dim);
  font-size: 15px; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.overlay-close:hover { color: var(--ivory); background: rgba(255,255,255,.08); }
.google-signin-wrap { display: flex; justify-content: center; min-height: 42px; align-items: center; margin-top: 6px; }
.google-signin-placeholder { font-size: 13px; color: var(--ivory-dim); }
.google-signin-placeholder.error { color: #ff9aa1; }
.auth-error {
  color: #ff9aa1; font-size: 13.5px; text-align: center; margin-top: 12px;
  background: rgba(198,47,57,.12); border: 1px solid rgba(198,47,57,.35); border-radius: 8px; padding: 8px 12px;
}
.auth-use-email-link {
  display: block; margin: 16px auto 0; background: none; color: var(--gold-dim);
  font-size: 13px; text-decoration: underline dotted;
}
.auth-use-email-link:hover { color: var(--gold); }
.auth-divider {
  display: flex; align-items: center; gap: 10px; margin: 18px 0 14px;
  color: var(--ivory-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
}
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,.14); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-password-row { display: flex; gap: 8px; }
.auth-password-row input { flex: 1; }
.auth-password-toggle {
  background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.18); border-radius: 10px;
  padding: 0 12px; color: var(--ivory-dim); font-size: 15px;
}
.auth-password-toggle:hover { color: var(--gold); }
.auth-hint { font-size: 11.5px; color: var(--ivory-dim); opacity: .7; margin-top: 6px; }
.auth-forgot-link, .auth-switch-mode button, .auth-back-link {
  background: none; color: var(--gold-dim); font-size: 12.5px; text-decoration: underline dotted; margin-top: 6px;
}
.auth-forgot-link:hover, .auth-switch-mode button:hover, .auth-back-link:hover { color: var(--gold); }
.auth-switch-mode { text-align: center; margin-top: 16px; font-size: 13px; color: var(--ivory-dim); }
.auth-step { display: none; flex-direction: column; gap: 14px; }
.auth-step.active { display: flex; }
.auth-back-link { display: block; margin: 18px auto 0; text-align: center; }
.auth-info {
  color: var(--good); font-size: 13.5px; text-align: center; margin-top: 12px;
  background: rgba(47,158,95,.12); border: 1px solid rgba(47,158,95,.35); border-radius: 8px; padding: 8px 12px;
}

/* ======================= PROFILE / AVATAR / PASSWORD MODALS ======================= */
.auth-user-chip { cursor: pointer; transition: background .12s; }
.auth-user-chip:hover { background: rgba(232,197,104,.2); }
.profile-header-row { display: flex; align-items: center; gap: 16px; text-align: left; margin-bottom: 18px; }
.profile-avatar-btn { position: relative; padding: 0; background: none; border-radius: 50%; flex-shrink: 0; }
.profile-avatar {
  width: 72px; height: 72px; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  font-weight: 800; font-size: 28px;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-overlay {
  position: absolute; inset: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); color: var(--ivory); font-size: 20px; opacity: 0; transition: opacity .15s;
}
.profile-avatar-btn:hover .profile-avatar-overlay { opacity: 1; }
.profile-name-display { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.profile-name-edit-btn {
  background: none; color: var(--ivory-dim); font-size: 13px; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.profile-name-edit-btn:hover { color: var(--gold); background: rgba(255,255,255,.08); }
.profile-name-edit-row { display: flex; align-items: center; gap: 6px; }
.profile-name-edit-row input {
  padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.35); color: var(--ivory); outline: none; font-size: 14px; width: 140px;
}
.profile-name-edit-row input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,197,104,.15); }
.profile-email { font-size: 13px; color: var(--ivory-dim); margin-top: 4px; }
.profile-section { text-align: left; margin: 18px 0; }
.profile-section h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--gold-dim); margin-bottom: 10px;
}
.profile-stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.profile-stat-cell {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 10px 6px; border-radius: 10px; background: rgba(255,255,255,.05); border: 1px solid var(--panel-line);
}
.profile-stat-value { font-size: 19px; font-weight: 800; color: var(--gold); }
.profile-stat-label { font-size: 11px; color: var(--ivory-dim); text-transform: uppercase; letter-spacing: .4px; text-align: center; }
.profile-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; }
.avatar-grid-item {
  aspect-ratio: 1; border-radius: 12px; overflow: hidden; padding: 0; background: rgba(255,255,255,.05);
  border: 2px solid transparent; display: flex; align-items: center; justify-content: center;
}
.avatar-grid-item img { width: 100%; height: 100%; object-fit: cover; }
.avatar-grid-item.selected { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232,197,104,.3); }
.avatar-grid-item:hover:not(:disabled) { border-color: var(--panel-line); }
.avatar-grid-upload {
  flex-direction: column; gap: 4px; font-size: 22px; color: var(--ivory-dim);
  border-style: dashed; border-color: rgba(255,255,255,.2);
}

/* ---------- friends / chat ---------- */
.btn-sm { padding: 7px 14px; font-size: 13px; }

.friend-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.08);
}
.friend-row-name {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; color: inherit; font-size: 14.5px;
  cursor: pointer; padding: 0;
}
.friend-row-actions { display: flex; align-items: center; gap: 6px; }
.friend-row-pending { font-size: 12.5px; color: var(--ivory-dim); opacity: .75; white-space: nowrap; }
.friend-online-dot { width: 8px; height: 8px; border-radius: 50%; background: #666; flex-shrink: 0; }
.friend-online-dot.on { background: #4caf50; }

/* Bounds the friend list to its own scroll area so a long list (dozens/hundreds of
   friends) doesn't push the code/add-friend/requests controls above it out of view. */
#friends-list { max-height: 38vh; overflow-y: auto; }

#friend-chat-msgs {
  display: flex; flex-direction: column; gap: 7px;
  max-height: 45vh; overflow-y: auto; margin: 12px 0; padding: 4px;
}

.chat-header-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; text-align: left; margin: 8px 0 14px; padding-right: 34px;
}
.chat-header-identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.friend-chat-avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  font-weight: 800; font-size: 16px;
}
.friend-chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-name-block { display: flex; flex-direction: column; min-width: 0; }
.chat-header-name {
  font-weight: 700; font-size: 16px; color: var(--ivory);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-header-status { font-size: 12px; color: var(--ivory-dim); }
.chat-header-status.online { color: #4caf50; }

.chat-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.chat-header-action-btn {
  display: flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.06); border: 1px solid var(--panel-line);
  border-radius: 999px; color: var(--ivory-dim); font-size: 12px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.chat-header-action-btn:hover { background: rgba(255,255,255,.12); color: var(--ivory); }
.chat-header-action-danger:hover { background: rgba(198,47,57,.22); color: #ff9aa1; }

.chat-remove-confirm { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }

@media (max-width: 480px) {
  .chat-header-action-btn span { display: none; }
  .chat-header-action-btn { padding: 6px 8px; }
}
.avatar-grid-upload-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; }

/* ---------- opponent avatar + profile popup ---------- */
.opp-avatar {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3d98b, var(--gold) 60%, #c9a24d); color: #3a2c0c;
  font-weight: 800; font-size: 10px;
}
.opp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.opp-avatar-clickable { cursor: pointer; }
.opp-avatar-clickable:hover { box-shadow: 0 0 0 2px rgba(232,197,104,.5); }

#player-profile-backdrop { position: fixed; inset: 0; z-index: 399; display: none; }
#player-profile-backdrop.visible { display: block; }

#player-profile-popup {
  display: none;
  position: fixed;
  z-index: 400;
  min-width: 200px;
  max-width: calc(100vw - 24px);
  background: #1a1310;
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
}
#player-profile-popup.visible { display: block; }

.player-profile-close { position: absolute; top: 6px; right: 8px; background: none; border: none; color: inherit; cursor: pointer; }

.player-profile-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.player-profile-header .opp-avatar { width: 28px; height: 28px; font-size: 13px; }

.player-profile-stats { margin-bottom: 10px; }
.player-profile-stat-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13px; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.06);
}
