:root {
  --felt-1: #0e4a37;
  --felt-2: #0a3528;
  --panel: rgba(0, 0, 0, 0.28);
  --panel-2: rgba(255, 255, 255, 0.06);
  --accent: #f4c542;
  --accent-2: #2ecc8f;
  --red: #e0533d;
  --text: #f3f7f4;
  --muted: #a9c4b8;
  --card-face: #ffffff;
  --card-black: #1c2530;
  --suit-spade: #243240;
  --suit-club: #7c3aed;
  --suit-heart: #d12b2b;
  --suit-diamond: #18923f;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 100% at 50% 0%, var(--felt-1), var(--felt-2));
  overflow: hidden;
}

button {
  font: inherit; font-weight: 700; color: #07211a;
  background: var(--accent-2); border: none; border-radius: 12px;
  padding: 12px 16px; cursor: pointer; transition: transform .06s ease, filter .1s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); }
button.ghost { background: rgba(255, 255, 255, 0.12); color: var(--text); }
button.big { padding: 15px 18px; font-size: 17px; width: 100%; }

input {
  font: inherit; color: var(--text); border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.25); border-radius: 12px; padding: 13px 14px; width: 100%;
}
input:focus { outline: 2px solid var(--accent-2); }

.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 13px; }
.version { text-align: center; color: var(--muted); opacity: .55; font-size: 11px; margin-top: 6px; }
.center { text-align: center; }
.error { color: #ffb4a8; font-size: 14px; min-height: 18px; }

/* ---------- screens ---------- */
.screen {
  height: 100%; display: flex; flex-direction: column; gap: 16px;
  padding: 22px 18px calc(18px + var(--safe-b));
  max-width: 560px; margin: 0 auto;
}
#screen-lobby { justify-content: center; }

.brand { font-size: 40px; font-weight: 800; text-align: center; color: var(--accent); letter-spacing: .5px; }

.card-panel {
  background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px;
}
.card-panel label { font-size: 13px; color: var(--muted); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.14); }

.row { display: flex; flex-direction: column; gap: 10px; }
.row .codeInput { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 800; font-size: 20px; }

/* ---------- waiting room ---------- */
.leave-btn {
  align-self: flex-start; background: rgba(255, 255, 255, 0.1); color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 10px;
}
.leave-btn.push-right { margin-left: auto; align-self: center; }

.room-head { display: flex; justify-content: center; }
.code-chip {
  position: relative; background: var(--panel); border-radius: 16px;
  padding: 12px 54px; display: flex; flex-direction: column; align-items: center;
}
.code-label { font-size: 11px; color: var(--muted); letter-spacing: 2px; }
.code-big { font-size: 34px; font-weight: 800; letter-spacing: 8px; padding-left: 8px; color: var(--accent); }
.chip-actions {
  position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px;
}
.icon-btn {
  background: rgba(255, 255, 255, 0.1); color: var(--text);
  padding: 7px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 17px; height: 17px; display: block; }
.icon-btn.copied { background: var(--accent-2); color: #07211a; }

.target-row { display: flex; align-items: center; gap: 10px; }
.target-row input { width: 90px; text-align: center; }
.target-row .readonly { font-weight: 800; font-size: 20px; color: var(--accent); }

.players-list { display: flex; flex-direction: column; gap: 10px; overflow: auto; flex: 1; }
.player-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--panel-2); border-radius: 14px; border: 1px solid transparent;
}
.player-row.ready { border-color: var(--accent-2); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: #07211a;
  background: linear-gradient(180deg, #fff, #cfe6db);
}
.player-row .pname { font-weight: 700; flex: 1; }
.player-row .tag { font-size: 12px; color: var(--muted); }
.player-row .tag.ok { color: var(--accent-2); font-weight: 700; }
.player-row .tag.off { color: #ffb4a8; }
.sticky { margin-top: auto; }

/* ---------- game ---------- */
#screen-game { max-width: 720px; padding: 0; gap: 0; }
#playArea {
  flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 8px;
}
.play-head { display: flex; align-items: center; min-height: 26px; }
.hearts-indicator {
  align-self: center; color: #ffb1a4; font-size: 13px; font-weight: 600;
  background: rgba(224, 83, 61, 0.16); padding: 4px 14px; border-radius: 999px;
}

.seats { display: flex; flex-wrap: nowrap; gap: 6px; justify-content: center; }
.seat {
  display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 0 1 auto; min-width: 0;
  padding: 7px 9px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid transparent;
}
.seat > * { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(244, 197, 66, 0.25); }
.seat.off { opacity: .5; }
.seat .sn { font-weight: 700; font-size: 13px; }
.seat .ss { font-size: 12px; color: var(--muted); }
.seat .badge { font-size: 11px; color: var(--accent-2); }

.trick {
  flex: 1; min-height: 0; display: flex; flex-wrap: wrap; gap: 14px;
  align-items: center; justify-content: center; align-content: center;
}
.trick-slot {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: transform .55s cubic-bezier(.35, .8, .3, 1), opacity .55s ease;
}
.trick-slot .tlabel { font-size: 12px; color: var(--muted); }
.trick-slot.winner .tlabel { color: var(--accent); font-weight: 700; }

/* trick win animation */
.trick-slot.score-card .card {
  transform: translateY(-4px) scale(1.07);
  box-shadow: 0 0 0 3px var(--red), 0 0 22px 6px rgba(224, 83, 61, 0.6);
  transition: transform .3s ease, box-shadow .3s ease;
}
.trick-slot.win-glow .card {
  transform: translateY(-6px) scale(1.14);
  box-shadow: 0 0 0 3px var(--accent), 0 0 28px 8px rgba(244, 197, 66, 0.7);
  transition: transform .3s ease, box-shadow .3s ease;
}
.trick-slot.fly { transform: translate(var(--dx, 0), var(--dy, 0)) scale(.32); opacity: 0; }
.pts-pop {
  position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; font-weight: 800; font-size: 16px;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  animation: popIn .35s ease, floatUp 1.1s ease .35s forwards;
}
@keyframes popIn { from { transform: translateX(-50%) scale(0); } to { transform: translateX(-50%) scale(1); } }
@keyframes floatUp { to { transform: translateX(-50%) translateY(-22px); opacity: .85; } }
.seat.collect { animation: collectPulse .55s ease; z-index: 2; }
@keyframes collectPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.2); box-shadow: 0 0 0 3px var(--accent), 0 0 24px rgba(244, 197, 66, 0.75); }
  100% { transform: scale(1); }
}

.banner { text-align: center; font-weight: 700; min-height: 24px; color: var(--accent); }

/* ---------- hand ---------- */
#handArea {
  background: rgba(0, 0, 0, 0.35); border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 12px calc(12px + var(--safe-b));
  display: flex; flex-direction: column; gap: 8px;
}
.you-bar {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: var(--panel-2); border-radius: 12px; border: 1px solid transparent;
}
.you-bar.turn { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(244, 197, 66, 0.25); }
.you-bar .you-name { font-weight: 800; flex: 1; }
.you-bar .you-score { font-weight: 700; }
.you-bar .you-score .rp { color: var(--muted); font-weight: 600; margin-left: 4px; }
.you-bar.collect { animation: collectBar .55s ease; z-index: 2; position: relative; }
@keyframes collectBar {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); box-shadow: 0 0 0 3px var(--accent), 0 0 22px rgba(244, 197, 66, 0.6); }
  100% { transform: scale(1); }
}

.hand-instruction {
  text-align: center; font-size: 14px; color: var(--muted);
  height: 20px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#confirmPassBtn { height: 50px; flex: 0 0 auto; }
.reserve-hidden { visibility: hidden; pointer-events: none; } /* hide but keep its space */
.hand-instruction.go { color: var(--accent); font-weight: 700; }
.hand {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; align-items: flex-start;
  gap: 14px 6px; padding: 12px 4px 4px; overflow: visible;
}
.hand .card { width: 54px; height: 78px; }
.hand .card .rank { font-size: 25px; }
.hand .card .suit { font-size: 27px; }
@media (min-height: 760px) { .hand .card { width: 60px; height: 86px; } .hand .card .rank { font-size: 28px; } .hand .card .suit { font-size: 30px; } }
@media (max-width: 360px) { .hand .card { width: 46px; height: 66px; } .hand { gap: 12px 5px; } .hand .card .rank { font-size: 21px; } .hand .card .suit { font-size: 23px; } }

/* ---------- cards ---------- */
.card {
  position: relative; flex: 0 0 auto;
  width: 60px; height: 86px; border-radius: 9px;
  background: var(--card-face); color: var(--card-black);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45); user-select: none;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
  border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.card.suit-s { color: var(--suit-spade); }
.card.suit-c { color: var(--suit-club); }
.card.suit-h { color: var(--suit-heart); }
.card.suit-d { color: var(--suit-diamond); }
.card .rank { font-weight: 800; font-size: 28px; line-height: 1; }
.card .suit { font-size: 30px; line-height: 1; }
.card.small { width: 50px; height: 72px; }
.card.small .rank { font-size: 23px; }
.card.small .suit { font-size: 25px; }

.hand .card.playable { cursor: pointer; transform: translateY(-8px); box-shadow: 0 10px 18px rgba(244, 197, 66, 0.35); border-color: var(--accent); }
.hand .card.pickable { cursor: pointer; }
.hand .card.dim { opacity: .42; }
.card.selected {
  cursor: pointer; border-color: var(--accent-2);
  transform: translateY(-14px) scale(1.05);
  box-shadow: 0 14px 24px rgba(46, 204, 143, 0.5), 0 0 0 3px var(--accent-2);
}
.card.selected::after {
  content: '✓'; position: absolute; right: 3px; top: 3px;
  width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #07211a; background: var(--accent-2); border-radius: 50%;
}
.card.preselected { border-color: var(--accent-2); }
.card.preselected::after {
  content: '✓'; position: absolute; right: 4px; top: 3px; font-size: 12px;
  color: #07211a; background: var(--accent-2); border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center; font-weight: 800;
}

/* cards flying away when passed */
.fly-ghost {
  position: fixed; z-index: 30; pointer-events: none;
  transform: translate(-50%, -50%);
  transition: transform .6s cubic-bezier(.4, .1, .3, 1), opacity .6s ease;
}

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(3, 18, 13, 0.78); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20;
}
.overlay-card {
  background: var(--felt-1); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 20px;
  padding: 24px; width: 100%; max-width: 420px; text-align: center; display: flex; flex-direction: column; gap: 14px;
}
.overlay-card h2 { color: var(--accent); font-size: 24px; }
/* shoot-the-moon & game-over celebration */
.overlay.moon .overlay-card,
.overlay.win .overlay-card { box-shadow: 0 0 60px rgba(244, 197, 66, 0.45); }
.moon-glyph, .win-glyph {
  display: inline-block; font-size: 64px;
  filter: drop-shadow(0 0 16px rgba(244, 197, 66, 0.8));
  animation: moonPop .55s cubic-bezier(.2, 1.4, .4, 1), moonFloat 2.6s ease-in-out .55s infinite;
}
.win-glyph { animation: moonPop .55s cubic-bezier(.2, 1.4, .4, 1), winPulse 2.2s ease-in-out .55s infinite; }
@keyframes moonPop { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes moonFloat { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(6deg); } }
@keyframes winPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.moon-msg { font-size: 17px; line-height: 1.55; }
.win-note { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.score-table { display: flex; flex-direction: column; gap: 8px; }
.score-table .srow {
  display: flex; justify-content: space-between; padding: 9px 14px;
  background: var(--panel-2); border-radius: 10px;
}
.score-table .srow.lead { background: rgba(244, 197, 66, 0.18); font-weight: 700; }
.score-table .srow .delta { color: var(--muted); font-weight: 600; }
