:root {
  --felt-a: #1b7a5b;
  --felt-b: #0f5c44;
  --felt-edge: #0a3f30;
  --ink: #22303c;
  --card-face: #fdfdf8;
  --gold: #f2b33d;
  --danger: #e5484d;
  --muted: #b9c8c2;
  --freeze: #5db4ee;
  --second: #f2b33d;
  --flip3: #37c2a0;
  --flip4: #a983e0;
  --steal: #ef7d8c;
  --swap: #6f9de8;
  --discard: #e88f5f;
  --jom: #b98be0;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  background:
    radial-gradient(1200px 700px at 50% 35%, var(--felt-a), var(--felt-b) 60%, var(--felt-edge));
  color: var(--card-face);
  min-height: 100vh;
}
.auth-page main{display:grid;place-items:center;min-height:100vh}.auth-panel h1{text-align:center;font-size:44px;margin-bottom:24px}.auth-panel form button{width:100%}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 26px;
}

.header-actions { display: flex; align-items: center; gap: 10px; }
.header-actions button{padding:6px 11px}
body.room-active #leaderboardBtn,body.room-active #inviteBtn,body.room-active #logoutBtn{display:none}

.chat-panel{position:fixed;right:18px;bottom:18px;width:min(360px,calc(100vw - 36px));height:460px;background:#102d25;border:1px solid rgba(255,255,255,.18);border-radius:16px;box-shadow:0 18px 45px rgba(0,0,0,.45);z-index:60;display:flex;flex-direction:column;overflow:hidden}.chat-panel.collapsed{height:48px}.chat-heading{height:48px;flex:0 0 48px;padding:10px 14px;display:flex;align-items:center;justify-content:space-between;background:rgba(0,0,0,.22)}.chat-heading button{padding:3px 10px}.chat-messages{padding:10px;overflow-y:auto;flex:1;overscroll-behavior:contain}.chat-message{padding:8px 5px;border-bottom:1px solid rgba(255,255,255,.09)}.chat-message>div:first-child{display:flex;justify-content:space-between}.chat-message time{font-size:11px;color:var(--muted)}.chat-message p{margin:4px 0 7px;overflow-wrap:anywhere}.reactions{display:flex;gap:3px}.reaction{padding:2px 6px;font-size:12px;border-radius:999px}.reaction.active{border-color:var(--gold);background:rgba(242,179,61,.2)}.chat-form{display:flex;padding:9px;gap:6px;background:rgba(0,0,0,.2)}.chat-form input{min-width:0;flex:1}.chat-form button{padding:8px}
.chat-unread{display:inline-grid;place-items:center;min-width:20px;height:20px;margin-left:5px;padding:0 6px;border-radius:999px;background:var(--danger);color:#fff;font-size:11px}.chat-toasts{position:fixed;z-index:70;top:76px;right:18px;width:min(340px,calc(100vw - 36px));pointer-events:none;opacity:0;transform:translateY(-8px);transition:opacity .18s ease,transform .18s ease}.chat-toasts.visible{pointer-events:auto;opacity:1;transform:none}.chat-toast{display:flex;width:100%;flex-direction:column;align-items:flex-start;gap:3px;padding:12px 14px;border-color:rgba(255,255,255,.2);background:#123f34;box-shadow:0 12px 30px rgba(0,0,0,.4);text-align:left}.chat-toast span{display:block;width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}
.account-panel{width:min(1040px,100%);max-width:1040px}.account-panel #accountContent{min-height:0;overflow:auto;padding:2px}.account-intro{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-bottom:10px}.account-intro p,.ranking-subtitle{color:var(--muted);margin:0}.ranking-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:20px}.ranking-board{min-width:0;overflow:hidden;border:1px solid rgba(255,255,255,.13);border-radius:16px;background:rgba(3,28,22,.38)}.ranking-title{display:flex;align-items:center;gap:12px;padding:16px}.ranking-title>span{display:grid;place-items:center;width:42px;height:42px;border-radius:12px;background:rgba(242,179,61,.14);font-size:22px}.ranking-title h3{margin:0}.ranking-title small{color:var(--muted)}.ranking-list{border-top:1px solid rgba(255,255,255,.1)}.ranking-row{display:grid;grid-template-columns:52px minmax(0,1fr) auto;align-items:center;gap:10px;min-height:58px;padding:9px 14px;border-bottom:1px solid rgba(255,255,255,.08)}.ranking-row:last-child{border-bottom:0}.ranking-row:nth-child(odd){background:rgba(255,255,255,.025)}.ranking-row.is-me{background:rgba(242,179,61,.12);box-shadow:inset 3px 0 var(--gold)}.ranking-place{font-size:18px}.ranking-player{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:700}.ranking-player small{display:inline-block;margin-left:7px;padding:2px 6px;border-radius:999px;background:var(--gold);color:#4a3106;font-size:10px}.ranking-row>strong{text-align:right;color:var(--gold);font-size:18px}.ranking-row>strong small{display:block;color:var(--muted);font-size:10px;text-transform:uppercase}.ranking-subtitle{margin:-6px 0 16px}.account-empty{padding:28px;text-align:center;color:var(--muted)}
.invite-list{margin-top:12px}.invite-row{display:grid;grid-template-columns:minmax(170px,.7fr) minmax(0,1.8fr);gap:18px;align-items:center;padding:14px 0;border-bottom:1px solid rgba(255,255,255,.12)}.invite-meta{display:flex;flex-direction:column;gap:2px;min-width:0}.invite-meta small{color:var(--muted)}.invite-status{width:max-content;padding:3px 8px;border-radius:999px;background:rgba(255,255,255,.1);font-weight:700;text-transform:capitalize}.invite-active .invite-status{background:rgba(63,181,123,.18);color:#8ce5b5}.invite-used{opacity:.72}.invite-link-wrap{display:flex;align-items:center;gap:8px;min-width:0}.invite-link-wrap input{min-width:0;flex:1;font-family:ui-monospace,SFMono-Regular,monospace;font-size:12px}.invite-link-wrap button{flex:0 0 auto;padding:9px 12px}.danger-button{color:#ffb1b5}.legacy-invite{flex:1;color:var(--muted);font-size:13px}

.scoreboard-button {
  padding: 6px 13px;
  border-radius: 999px;
  background: rgba(8, 20, 16, .62);
  color: var(--gold);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
h1 span { color: var(--gold); }

#roomBadge {
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

main { padding: 8px 22px 90px; max-width: 1200px; margin: 0 auto; }

.hidden { display: none !important; }

.panel {
  background: rgba(8, 20, 16, 0.55);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(3px);
  border-radius: 16px;
  padding: 26px;
  max-width: 520px;
  margin: 40px auto;
  box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}

.panel h2 { margin-top: 0; letter-spacing: 1px; }

.field { display: block; margin-bottom: 14px; font-weight: 600; }
.field input { display: block; margin-top: 6px; width: 100%; }

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

input, button {
  font-family: inherit;
  font-size: 15px;
  border-radius: 10px;
  padding: 10px 16px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.35);
  color: #fff;
}

input#roomCode { text-transform: uppercase; letter-spacing: 3px; text-align: center; width: 120px; font-weight: 700; }

button { cursor: pointer; transition: transform .08s ease, box-shadow .12s ease; }
button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,0.3); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary {
  background: linear-gradient(180deg, #ffd466, var(--gold));
  border: none;
  color: #4a3106;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 0 #b07d17, 0 8px 18px rgba(0,0,0,0.3);
}
button.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #b07d17; }

.error { color: #ff9aa0; min-height: 1.2em; margin-bottom: 0; }
.muted { color: var(--muted); }

/* ---- Lobby ---- */
#lobbyPlayers { list-style: none; padding: 0; margin: 0 0 14px; display: flex; gap: 10px; flex-wrap: wrap; }
#lobbyPlayers li {
  background: rgba(255,255,255,0.12);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
}
.code { color: var(--gold); letter-spacing: 2px; }

.modes { display: flex; gap: 10px; margin-bottom: 14px; }
.mode { position: relative; }
.mode input { position: absolute; opacity: 0; }
.mode span {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(0,0,0,0.35);
  border: 2px solid rgba(255,255,255,0.18);
  font-weight: 700;
  cursor: pointer;
  transition: all .12s ease;
}
.mode input:checked + span {
  background: #fff;
  color: var(--ink);
  border-color: #fff;
  box-shadow: 0 6px 14px rgba(0,0,0,0.25);
}

.options { display: flex; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.opt { font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }

/* ---- Table ---- */
#table { display: flex; flex-direction: column; gap: 18px; }

#opponents {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 130px;
}

.opponent {
  background: rgba(8, 20, 16, 0.5);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 190px;
}
.opponent.current { outline: 3px solid var(--gold); box-shadow: 0 0 22px rgba(242,179,61,0.4); }
.opponent .who { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-bottom: 8px; }
.opponent .who .nm { font-weight: 700; }
.opponent .who .sc { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }

#centerRow {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 42px;
  padding: 6px 0;
}

.pile { text-align: center; color: var(--muted); font-size: 13px; }
.pile span { display: block; margin-top: 6px; }

#turnInfo {
  min-width: 240px;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

#turnInfo:has(.pending-card-preview) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

#turnInfo .pending-card-preview {
  --w: 72px;
  flex: 0 0 auto;
  text-align: initial;
}

#myArea {
  background: rgba(8, 20, 16, 0.5);
  border-radius: 16px;
  padding: 14px 18px 18px;
  border: 1px solid rgba(255,255,255,0.12);
}
#myArea .who { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 16px; }
#myArea .who .nm { font-weight: 700; font-size: 18px; }
#myArea .who .sc { color: var(--gold); font-weight: 700; }

/* ---- Cards ---- */
.cards { display: flex; flex-wrap: wrap; gap: 8px; min-height: 84px; align-items: flex-end; }
.cards.fan .card { margin-right: -22px; }
.cards.fan .card:last-child { margin-right: 0; }

.card {
  --w: 58px;
  width: var(--w);
  height: calc(var(--w) * 1.38);
  border-radius: 9px;
  position: relative;
  background: var(--card-face);
  color: var(--ink);
  box-shadow: 0 3px 8px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease;
}
.cards.fan .card:hover { transform: translateY(-8px) rotate(1.5deg); }

.card .face {
  font-size: 24px;
  line-height: 1;
  text-align: center;
}
.card .sub {
  font-size: 7.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 3px;
  opacity: 0.75;
  text-align: center;
  max-width: calc(var(--w) - 6px);
}

.card .card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  border-radius: inherit;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

.card.small { --w: 44px; }
.card.small .face { font-size: 18px; }
.card.small .sub { font-size: 6.5px; }

.card.NUMBER.vclass { background: #fff; }
.card.MODIFIER { border: 3px solid #c8e6c9; }
.card.ACTION { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.35); border: none; overflow: hidden; }

.card.ACTION .sub { color: rgba(255,255,255,0.92); opacity: 1; }

.card.r-VENGEANCE_ZERO { background: #263238; color: #fff; }
.card.r-VENGEANCE_UNLUCKY_7 { background: #fff; }
.card.r-VENGEANCE_UNLUCKY_7 .face { color: var(--danger); }
.card.r-VENGEANCE_LUCKY_13 { background: #fff8e6; border: 3px solid var(--gold); }
.card.r-VENGEANCE_LUCKY_13 .face { color: #b8860b; }

.card.act-CLASSIC_FREEZE {
  background:
    radial-gradient(circle at 24% 18%, rgba(255,255,255,.7) 0 3%, transparent 4%),
    linear-gradient(145deg, #9de2ff 0 18%, #54b8ec 18% 82%, #2688c2 82%);
  border: 2px solid #dff7ff;
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 0 0 2px rgba(12,73,112,.28);
}
.card.act-CLASSIC_FLIP_THREE {
  background:
    linear-gradient(35deg, transparent 42%, rgba(255,255,255,.2) 43% 48%, transparent 49%),
    linear-gradient(145deg, #ffe46e 0 18%, #f7be2f 18% 82%, #e58c25 82%);
  border: 2px solid #fff3a7;
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 0 0 2px rgba(126,68,0,.25);
}
.card.act-CLASSIC_FREEZE::before,
.card.act-CLASSIC_FLIP_THREE::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 5px;
  pointer-events: none;
}
.card.act-CLASSIC_FREEZE::after,
.card.act-CLASSIC_FLIP_THREE::after {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 10%;
  padding: 3px 1px;
  background: rgba(255,255,245,.92);
  color: #18384a;
  border-top: 1px solid rgba(25,57,75,.35);
  border-bottom: 1px solid rgba(25,57,75,.35);
  font-size: calc(var(--w) * .13);
  line-height: 1;
  letter-spacing: .6px;
  text-align: center;
  text-shadow: none;
  z-index: 2;
}
.card.act-CLASSIC_FREEZE::after { content: "FREEZE"; }
.card.act-CLASSIC_FLIP_THREE::after { content: "FLIP THREE"; color: #5a3900; }
.card.act-CLASSIC_FREEZE .face,
.card.act-CLASSIC_FLIP_THREE .face {
  position: relative;
  z-index: 1;
  margin-bottom: 25%;
  font-size: calc(var(--w) * .38);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.25));
}
.card.act-CLASSIC_FREEZE .sub,
.card.act-CLASSIC_FLIP_THREE .sub { display: none; }
.card.act-CLASSIC_SECOND_CHANCE { background: linear-gradient(160deg, #ffd67a, var(--second)); color: #4a3106; text-shadow: none; }
.card.act-VENGEANCE_JUST_ONE_MORE { background: linear-gradient(160deg, #cfa9f0, var(--jom)); }
.card.act-VENGEANCE_FLIP_FOUR { background: linear-gradient(160deg, #b899f0, var(--flip4)); }
.card.act-VENGEANCE_STEAL { background: linear-gradient(160deg, #f795a3, var(--steal)); }
.card.act-VENGEANCE_SWAP { background: linear-gradient(160deg, #8fb4f2, var(--swap)); }
.card.act-VENGEANCE_DISCARD { background: linear-gradient(160deg, #f2a885, var(--discard)); }

.card.back {
  background:
    repeating-linear-gradient(45deg, #123, #123 6px, #1d3550 6px, #1d3550 12px);
  border: 3px solid rgba(255,255,255,0.7);
  border-radius: 9px;
  --w: 58px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}
.card.discardghost {
  background: rgba(255,255,255,0.08);
  border: 2px dashed rgba(255,255,255,0.3);
  box-shadow: none;
}

.card.selectable {
  outline: 3px solid var(--gold);
  box-shadow: 0 0 18px rgba(242,179,61,0.7);
  cursor: pointer;
}
.card.selectable:hover { transform: translateY(-10px) scale(1.06); }

.tableau-card-enter { animation: flipIn .5s cubic-bezier(.2,.9,.3,1.2) backwards; }
@keyframes flipIn {
  from { transform: perspective(400px) rotateY(80deg) translateY(-34px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes bustShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.opponent.busted { border-color: var(--danger); }
.busted-flash { animation: bustShake .45s ease 2; border-color: var(--danger) !important; }

/* ---- Second Chance consumed ---- */
#myArea, .opponent { position: relative; }

.second-chance-burn {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(74, 12, 12, .45));
}
.second-chance-burn::before {
  content: "";
  position: absolute;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,244,184,.9), rgba(255,102,76,.56) 42%, transparent 70%);
  animation: secondChancePulse .75s ease-out forwards;
}
.second-chance-burn .second-chance-shield {
  position: relative;
  font-size: 52px;
  line-height: 1;
  animation: secondChanceShield 1.05s cubic-bezier(.2,.9,.3,1) forwards;
}
.second-chance-burn .second-chance-blocked-card {
  --w: 58px;
  position: absolute;
  left: calc(50% + 42px);
  top: 50%;
  z-index: 3;
  text-shadow: none;
  animation: secondChanceBlockedCard 1.65s cubic-bezier(.2,.8,.25,1) forwards;
}
.second-chance-burn b {
  position: relative;
  margin-top: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(74, 18, 18, .78);
  color: #ffe5aa;
  font-size: 10px;
  letter-spacing: 1px;
  animation: secondChanceLabel 1.15s ease-out forwards;
}
.second-chance-burn i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffd66b;
  box-shadow: 0 0 8px #ff6b4a;
  animation: secondChanceSpark .8s ease-out forwards;
}
@keyframes secondChancePulse {
  from { transform: scale(.2); opacity: 1; }
  to { transform: scale(1.6); opacity: 0; }
}
@keyframes secondChanceShield {
  0% { transform: scale(.45) rotate(-12deg); opacity: 0; }
  25% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  62% { transform: scale(.95) rotate(0); opacity: 1; }
  100% { transform: scale(.7) translateY(-15px); opacity: 0; filter: saturate(.3); }
}
@keyframes secondChanceLabel {
  0%, 18% { transform: translateY(8px); opacity: 0; }
  35%, 70% { transform: none; opacity: 1; }
  100% { transform: translateY(-8px); opacity: 0; }
}
@keyframes secondChanceSpark {
  from { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  to { transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) scale(0); opacity: 0; }
}
@keyframes secondChanceBlockedCard {
  0% { transform: translate(30px, -80px) rotate(15deg) scale(.7); opacity: 0; }
  18% { transform: translate(0, -52%) rotate(-5deg) scale(1.08); opacity: 1; }
  68% { transform: translate(0, -52%) rotate(0) scale(1); opacity: 1; }
  100% { transform: translate(18px, -45%) rotate(10deg) scale(.88); opacity: 0; filter: grayscale(.6); }
}

/* ---- Flip 7 celebration ---- */
body.flip7-celebrating::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 45;
  background: radial-gradient(circle at 50% 48%, rgba(255, 224, 112, .34), transparent 58%);
  animation: flip7Glow 2.5s ease-out forwards;
}

.flip7-winner {
  position: relative;
  z-index: 46;
  animation: flip7Winner 1.8s cubic-bezier(.2, .9, .25, 1) both;
}

.flip7-confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 60;
}

.flip7-confetti i {
  position: absolute;
  top: -24px;
  left: var(--x);
  width: 10px;
  height: 18px;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  animation: confettiFall var(--duration) cubic-bezier(.16, .72, .36, 1) var(--delay) forwards;
}

#bigBanner.flip7-banner .inner {
  color: #fff7cf;
  background: linear-gradient(135deg, rgba(103, 68, 5, .94), rgba(20, 66, 48, .94));
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 8px rgba(242, 179, 61, .16), 0 20px 70px rgba(0, 0, 0, .5);
  text-shadow: 0 2px 0 #8a5b00, 0 0 22px rgba(255, 221, 104, .8);
}

@keyframes flip7Glow {
  0% { opacity: 0; }
  18% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes flip7Winner {
  0% { transform: scale(.96); box-shadow: 0 0 0 rgba(242, 179, 61, 0); }
  22% { transform: scale(1.045) rotate(-.5deg); box-shadow: 0 0 38px rgba(255, 210, 80, .95); border-color: #ffe590; }
  48% { transform: scale(1.015) rotate(.4deg); }
  100% { transform: none; box-shadow: 0 0 24px rgba(242, 179, 61, .38); }
}
@keyframes confettiFall {
  0% { transform: translate3d(0, -5vh, 0) rotate(0); opacity: 0; }
  8% { opacity: 1; }
  100% { transform: translate3d(var(--drift), 108vh, 0) rotate(var(--spin)); opacity: .9; }
}

.status-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 2px 8px;
  border-radius: 999px;
}
.status-tag.BUSTED { background: rgba(229,72,77,0.25); color: #ff9aa0; }
.status-tag.STAYED { background: rgba(255,255,255,0.12); color: var(--muted); }
.status-tag.FROZEN { background: rgba(93,180,238,0.25); color: #9ed4f7; }
.status-tag.FLIP_7 { background: var(--gold); color: #4a3106; }

/* ---- Big banner ---- */
#bigBanner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
}
#bigBanner .inner {
  font-size: 54px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0,0,0,0.6);
  background: rgba(0,0,0,0.45);
  padding: 24px 44px;
  border-radius: 24px;
  animation: pop .5s cubic-bezier(.2,1.4,.4,1) backwards, fadeout .6s ease 1.4s forwards;
}
#bigBanner.good .inner { color: var(--gold); }
@keyframes pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeout { to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .flip7-confetti { display: none; }
  .second-chance-burn i { display: none; }
  .second-chance-burn .second-chance-shield,
  .second-chance-burn .second-chance-blocked-card,
  .second-chance-burn b,
  .second-chance-burn::before { animation-duration: .25s; }
  body.flip7-celebrating::after { animation-duration: .6s; }
  .flip7-winner { animation: none; box-shadow: 0 0 24px rgba(242,179,61,.55); }
  #bigBanner .inner { animation: fadeout .3s ease 1.4s forwards; }
}

/* ---- Controls ---- */
#controls {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(8, 20, 16, 0.72);
  padding: 12px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
  max-width: min(96vw, 900px);
  flex-wrap: wrap;
  justify-content: center;
  z-index: 40;
}
#controls:empty { display: none; }

#controls button.big {
  font-size: 19px;
  padding: 14px 34px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 1.5px;
}
#controls button.big.hit {
  background: linear-gradient(180deg, #67d99a, #37b06f);
  border: none;
  color: #04301a;
  box-shadow: 0 4px 0 #1e7a4b, 0 8px 18px rgba(0,0,0,0.3);
}
#controls button.big.stay {
  background: linear-gradient(180deg, #f4f6f8, #d5dbe1);
  border: none;
  color: #333;
  box-shadow: 0 4px 0 #98a2ac, 0 8px 18px rgba(0,0,0,0.3);
}

#controls .pick-note { color: var(--muted); font-weight: 600; }

/* ---- Status bar ---- */
#statusBar {
  position: fixed;
  bottom: 18px;
  right: 18px;
  font-size: 12px;
  color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.3);
  padding: 5px 12px;
  border-radius: 999px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#statusBar:empty { display: none; }

/* ---- Scoreboard ---- */
body.scoreboard-open { overflow: hidden; }

.scoreboard-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 13, 10, .86);
  backdrop-filter: blur(8px);
}

.scoreboard-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1100px, 100%);
  min-width: 0;
  max-height: calc(100dvh - 48px);
  padding: 22px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 20px;
  background: #0b3f31;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
}

.scoreboard-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}
.scoreboard-heading h2 { margin: 0 0 4px; font-size: 28px; }
.scoreboard-stats { margin: 0; color: var(--muted); }
.scoreboard-close {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
}

.scoreboard-table-wrap {
  width: 100%;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
}
.scoreboard-table {
  width: 100%;
  min-width: 520px;
  border-collapse: separate;
  border-spacing: 0;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.scoreboard-table th,
.scoreboard-table td {
  min-width: 110px;
  padding: 13px 16px;
  border-right: 1px solid rgba(255,255,255,.1);
  border-bottom: 1px solid rgba(255,255,255,.1);
  text-align: center;
  white-space: nowrap;
}
.scoreboard-table th:first-child,
.scoreboard-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 100px;
  background: #123f34;
  text-align: left;
}
.scoreboard-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #092f25;
  color: var(--gold);
}
.scoreboard-table thead th:first-child { z-index: 4; background: #092f25; }
.scoreboard-table thead th span,
.scoreboard-table thead th small { display: block; overflow: hidden; text-overflow: ellipsis; }
.scoreboard-table thead th small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.scoreboard-table tbody tr:nth-child(even) td { background: rgba(255,255,255,.035); }
.scoreboard-table tfoot th,
.scoreboard-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 3;
  border-bottom: 0;
  background: #102f27;
  color: var(--gold);
  font-size: 17px;
  font-weight: 700;
}
.scoreboard-table tfoot th { left: 0; z-index: 4; }
.scoreboard-table .winner {
  color: #fff3b0;
  background: rgba(242,179,61,.2);
  box-shadow: inset 0 -3px 0 var(--gold);
}
.scoreboard-empty { padding: 34px !important; color: var(--muted); }

/* ---- Mobile table layout ---- */
@media (max-width: 700px) {
  header {
    padding: 10px 12px 6px;
    gap: 8px;
  }

  body { overflow-x:hidden; }
  .header-actions{min-width:0;justify-content:flex-end}
  body.room-active .header-actions{flex-wrap:nowrap}
  body.room-active #roomBadge{max-width:112px;overflow:hidden;text-overflow:ellipsis}

  h1 { font-size: 25px; }

  #roomBadge {
    padding: 5px 10px;
    font-size: 12px;
    letter-spacing: .5px;
    white-space: nowrap;
  }

  .header-actions { gap: 5px; }
  .scoreboard-button { padding: 5px 8px; font-size: 11px; }

  .scoreboard-overlay { padding: 0; }
  .scoreboard-panel {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
    height: 100dvh;
    max-height: none;
    padding: 14px 10px 10px;
    border: 0;
    border-radius: 0;
    overflow: hidden;
  }
  .scoreboard-heading {
    width: 100%;
    min-width: 0;
    margin: 0 0 12px;
    padding-right: 48px;
  }
  .scoreboard-heading h2 { font-size: 24px; }
  .scoreboard-stats { font-size: 13px; }
  .scoreboard-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
  }
  .scoreboard-table-wrap {
    max-width: 100%;
    flex: 0 1 auto;
  }
  .scoreboard-table {
    width: 100%;
    min-width: max(100%, var(--scoreboard-min-width));
    table-layout: fixed;
  }
  .scoreboard-table th,
  .scoreboard-table td {
    min-width: 0;
    width: auto;
    padding: 11px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .scoreboard-table th:first-child,
  .scoreboard-table td:first-child {
    position: static;
    width: 92px;
    min-width: 92px;
  }
  .scoreboard-table thead th:first-child {
    position: sticky;
    top: 0;
    left: auto;
    z-index: 3;
  }
  .scoreboard-table tfoot th:first-child {
    position: sticky;
    bottom: 0;
    left: auto;
    z-index: 3;
  }

  main {
    width: 100%;
    padding: 4px 8px 88px;
  }

  #table { gap: 10px; }

  #opponents {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-height: 0;
    align-items: stretch;
  }

  .opponent {
    min-width: 0;
    width: 100%;
    min-height: 116px;
    padding: 8px 9px;
    overflow: hidden;
  }

  /* With 3 or 5 opponents, center the final card beneath the pairs. */
  .opponent:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    justify-self: center;
    width: calc(50% - 4px);
  }

  .opponent .who {
    gap: 5px;
    margin-bottom: 6px;
    font-size: 12px;
  }
  .opponent .who .nm {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .opponent .status-tag {
    padding: 2px 5px;
    font-size: 9px;
  }

  .opponent .cards {
    min-height: 58px;
    gap: 4px;
  }

  .opponent .card.small { --w: 38px; }
  .opponent .cards.fan .card { margin-right: -18px; }

  #centerRow {
    min-height: 92px;
    gap: 12px;
    justify-content: space-between;
    padding: 0 4px;
  }

  #centerRow .card { --w: 45px; }
  #turnInfo {
    min-width: 0;
    flex: 1;
    font-size: 14px;
    line-height: 1.2;
  }
  #turnInfo:has(.pending-card-preview) {
    flex-direction: column;
    gap: 4px;
  }
  #turnInfo .pending-card-preview { --w: 52px; }
  .pile { font-size: 11px; }
  .pile span { margin-top: 3px; }

  #myArea {
    min-height: 126px;
    padding: 10px 12px 12px;
  }
  #myArea .who { margin-bottom: 7px; font-size: 14px; }
  #myArea .who .nm { font-size: 16px; }
  #myArea .cards { min-height: 68px; gap: 5px; }
  #myArea .card { --w: 48px; }

  #controls {
    bottom: 9px;
    width: calc(100% - 16px);
    gap: 8px;
    padding: 8px 10px;
    /* Wrapped target choices are the primary interaction on small screens. */
    z-index: 80;
  }
  #controls button.big {
    font-size: 15px;
    padding: 11px 21px;
  }

  #controls:has(> button.big:nth-child(2):last-child) {
    flex-wrap: nowrap;
  }
  #controls:has(> button.big:nth-child(2):last-child) > button.big {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 12px;
    white-space: nowrap;
  }

  #statusBar {
    right: 8px;
    bottom: 72px;
    max-width: calc(100% - 16px);
    font-size: 10px;
  }

  #bigBanner .inner {
    max-width: calc(100vw - 32px);
    padding: 18px 22px;
    font-size: 34px;
    text-align: center;
  }

  .account-panel { height: auto; max-height: calc(100dvh - 16px); padding: 16px 10px 10px; border:1px solid rgba(255,255,255,.16); border-radius:18px; }
  .account-panel #accountContent { flex: 0 1 auto; overflow-y: auto; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .account-intro { align-items: flex-start; flex-direction: column; gap: 12px; }
  .ranking-subtitle { padding-right: 42px; font-size: 13px; }
  .ranking-grid { grid-template-columns: 1fr; gap: 14px; }
  .ranking-title { padding: 12px; }
  .ranking-title > span { width: 38px; height: 38px; }
  .ranking-row { grid-template-columns: 44px minmax(0,1fr) auto; min-height: 52px; padding: 7px 10px; }
  .ranking-row > strong { font-size: 16px; }

  .invite-row { grid-template-columns: 1fr; gap: 9px; padding: 14px 0; }
  .invite-link-wrap { display: grid; grid-template-columns:minmax(0,1fr) auto; }
  .invite-link-wrap input,.legacy-invite { grid-column: 1 / -1; width: 100%; }
  .invite-link-wrap .danger-button { justify-self: end; }

  .chat-panel {
    z-index: 60;
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
    height: min(460px, calc(100dvh - 84px));
    max-height: calc(100dvh - 84px);
  }
  body:has(#controls:not(:empty)) .chat-panel {
    bottom: 80px;
    height: min(420px, calc(100dvh - 156px));
    max-height: calc(100dvh - 156px);
  }
  .chat-panel.collapsed {
    right: 8px;
    bottom: 8px;
    width: min(190px, calc(100vw - 16px));
    height: 48px;
  }
  body:has(#controls:not(:empty)) .chat-panel.collapsed { bottom: 80px; height: 48px; }
  .chat-toasts{top:68px;right:8px;width:calc(100vw - 16px)}
}

@media (max-width: 390px) {
  .opponent { min-height: 106px; }
  .opponent .card.small { --w: 34px; }
  .opponent .cards.fan .card { margin-right: -17px; }
  #myArea .card { --w: 44px; }
}
