:root {
  --denari: #c9a227;
  --coppe: #a4283c;
  --spade: #3a5f82;
  --bastoni: #4c7a3f;
  --gold: #d8b04a;
  --gold-bright: #f0d488;
  --felt-dark: #0b3324;
  --felt: #12472f;
  --felt-light: #17573a;
  --wood: #6b4226;
  --wood-dark: #4a2c18;
  --parchment: #f6ecd6;
  --ink: #241a10;
  --panel: rgba(12, 43, 30, 0.92);
  --panel-border: rgba(216, 176, 74, 0.35);
  --card-w: 78px;
  --card-h: 111px;
  --font-display: 'Cinzel', 'Georgia', serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--parchment);
  min-height: 100vh;
  background:
    radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 55%, var(--felt-dark) 100%);
  background-attachment: fixed;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.015) 0px, rgba(255,255,255,0.015) 1px, transparent 1px, transparent 6px);
  z-index: 0;
}

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

#lobby {
  position: relative;
  z-index: 1;
  max-width: 440px;
  margin: 48px auto;
  background: linear-gradient(160deg, rgba(20, 58, 40, 0.96), rgba(9, 32, 22, 0.96));
  padding: 32px 28px;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 0 1px var(--panel-border);
  border: 1px solid rgba(216, 176, 74, 0.2);
}

.lobby-brand {
  text-align: center;
  margin-bottom: 24px;
}

.lobby-suits {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 10px;
}
.lobby-suits img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
}

#lobby h1 {
  font-family: var(--font-display);
  font-size: 34px;
  margin: 0;
  color: var(--gold-bright);
  letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.lobby-tagline {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(246, 236, 214, 0.7);
  font-style: italic;
}

#lobby label {
  display: block;
  margin: 14px 0 5px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(246, 236, 214, 0.65);
}

#lobby input, #lobby select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(216, 176, 74, 0.3);
  background: rgba(246, 236, 214, 0.96);
  color: var(--ink);
  font-size: 15px;
  font-family: var(--font-body);
}
#lobby input:focus, #lobby select:focus {
  outline: 2px solid var(--gold);
}

#lobby button {
  margin-top: 16px;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  font-family: var(--font-body);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
#lobby button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,0.4); }
#lobby button:active { transform: translateY(0); }

#lobby button.secondary {
  background: transparent;
  border: 1.5px solid var(--gold);
  color: var(--gold-bright);
  box-shadow: none;
}
#lobby button.secondary:hover { background: rgba(216, 176, 74, 0.12); }

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 6px;
  color: rgba(246, 236, 214, 0.4);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.lobby-divider::before, .lobby-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(216, 176, 74, 0.25);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  text-transform: none !important;
  font-size: 14px !important;
  color: var(--parchment) !important;
  cursor: pointer;
}
.checkbox-label input { width: auto !important; }

#vsBotCountWrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
#vsBotCountWrap label { display: inline; margin: 0; }
#vsBotCountWrap select { width: auto; padding: 6px 10px; }

#lobbyError {
  color: #ff9b9b;
  min-height: 18px;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
}

.text-link {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: rgba(246, 236, 214, 0.7);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-link:hover { color: var(--gold-bright); }

/* ---------- Sala d'attesa (lobby) ---------- */

#waitingRoom {
  display: none;
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 48px auto;
  padding: 0 16px;
}
#waitingRoom.visible { display: block; }

.waiting-card {
  background: linear-gradient(160deg, rgba(20, 58, 40, 0.96), rgba(9, 32, 22, 0.96));
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 0 1px var(--panel-border);
  border: 1px solid rgba(216, 176, 74, 0.2);
  text-align: center;
}

.waiting-code-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(246, 236, 214, 0.6);
  margin-bottom: 8px;
}
.waiting-code-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.waiting-code {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--gold-bright);
  text-shadow: 0 2px 12px rgba(216, 176, 74, 0.4);
}
.waiting-code-row button {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  border: 1.5px solid var(--gold);
  color: var(--gold-bright);
}
.waiting-code-row button:hover { background: rgba(216, 176, 74, 0.12); }
.waiting-mode {
  margin: 10px 0 0;
  font-size: 13px;
  color: rgba(246, 236, 214, 0.7);
}

.waiting-teams {
  display: flex;
  gap: 16px;
  margin: 26px 0 20px;
}
.waiting-team-col { flex: 1; min-width: 0; }
.waiting-team-title {
  font-family: var(--font-display);
  font-size: 14px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--panel-border);
}
.waiting-team-col.team-A .waiting-team-title { color: #ffb3bf; }
.waiting-team-col.team-B .waiting-team-title { color: #a8d0ff; }

.waiting-team-list { display: flex; flex-direction: column; gap: 8px; }
.waiting-slot {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
  min-height: 20px;
}
.waiting-slot.empty { border-style: dashed; opacity: 0.5; }
.waiting-slot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.waiting-slot-empty { font-style: italic; opacity: 0.7; }
.waiting-move-btn {
  flex-shrink: 0;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(216, 176, 74, 0.4);
  background: transparent;
  color: var(--gold-bright);
  cursor: pointer;
}
.waiting-move-btn:hover { background: rgba(216, 176, 74, 0.15); }

.waiting-actions button.primary-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  font-weight: 700;
  font-family: var(--font-display);
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.12s ease;
}
.waiting-actions button.primary-btn:hover:not(:disabled) { transform: translateY(-1px); }
.waiting-actions button.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.waiting-hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: rgba(246, 236, 214, 0.65);
}

@media (max-width: 480px) {
  .waiting-teams { flex-direction: column; }
  .waiting-code { font-size: 30px; letter-spacing: 2px; }
}

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

#game {
  display: none;
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 16px 32px;
}
#game.visible { display: block; }

.scoreboard {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: var(--panel);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 14px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  flex-wrap: wrap;
}
.roomCode {
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.5px;
  color: var(--gold-bright);
  white-space: nowrap;
}
.roomCode span { font-weight: 700; }

#scores {
  display: flex;
  gap: 16px;
  flex: 1;
  min-width: 220px;
  justify-content: flex-end;
}
.score-team {
  min-width: 120px;
  flex: 1;
  max-width: 200px;
}
.score-team-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}
.score-team-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(246, 236, 214, 0.6);
}
.score-team.team-A .score-team-label { color: #ffb3bf; }
.score-team.team-B .score-team-label { color: #a8d0ff; }
.score-team-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--gold-bright);
}
.score-team-value small { font-size: 11px; font-weight: 400; opacity: 0.55; margin-left: 1px; }
.score-bar {
  height: 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.score-team.team-A .score-bar-fill { background: linear-gradient(90deg, var(--coppe), #ff8a9a); }
.score-team.team-B .score-bar-fill { background: linear-gradient(90deg, var(--spade), #7fb3ea); }
.score-team.bump .score-team-value { animation: score-bump 0.5s ease; }
.score-team.bump .score-bar { animation: score-bar-glow 0.6s ease; }

@keyframes score-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); color: #fff5da; }
  100% { transform: scale(1); }
}
@keyframes score-bar-glow {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: 0 0 10px 2px rgba(216, 176, 74, 0.7); }
}

.opponents {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.opponent {
  background: var(--panel);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  min-width: 180px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.opponent.turn {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 2px rgba(216, 176, 74, 0.35), 0 0 18px rgba(216, 176, 74, 0.35);
  animation: pulse-glow 1.6s ease-in-out infinite;
}
.opponent.disconnected { opacity: 0.55; }

.opponent-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 6px;
}
.team-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.team-badge.team-A { background: rgba(164, 40, 60, 0.35); color: #ffb3bf; }
.team-badge.team-B { background: rgba(58, 95, 130, 0.35); color: #a8d0ff; }

.disconnected-badge {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #ff9b9b;
  border: 1px solid rgba(255, 155, 155, 0.5);
  border-radius: 20px;
  padding: 1px 6px;
}

.opponent-cards {
  display: flex;
  gap: -18px;
  margin-bottom: 6px;
}
.opponent-cards .card {
  width: 34px;
  height: 48px;
  margin-right: -18px;
}
.opponent-cards .card.revealed-card {
  border: 2px solid var(--gold-bright);
  box-shadow: 0 0 8px rgba(216, 176, 74, 0.6), 0 4px 10px rgba(0,0,0,0.45);
  z-index: 1;
}
.opponent-stats {
  font-size: 11.5px;
  color: rgba(246, 236, 214, 0.65);
}

.status-line {
  text-align: center;
  margin-bottom: 10px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--gold-bright);
  min-height: 20px;
  letter-spacing: 0.3px;
}

.table-area {
  position: relative;
  background:
    radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 70%);
  border-radius: 16px;
  padding: 28px;
  min-height: 150px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  margin-bottom: 18px;
  border: 8px solid var(--wood);
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.45),
    0 10px 30px rgba(0,0,0,0.4),
    0 0 0 1px var(--wood-dark);
}

.table-empty {
  opacity: 0.5;
  font-style: italic;
  font-size: 14px;
}

.hand-area {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 14px 0 4px;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 7px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.45);
  border: 1px solid rgba(0,0,0,0.35);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  overflow: hidden;
  background: var(--parchment);
  animation: card-in 0.25s ease;
}
.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.card:hover { transform: translateY(-8px) scale(1.03); box-shadow: 0 10px 20px rgba(0,0,0,0.5); z-index: 2; }
.card.static { cursor: default; }
.card.static:hover { transform: none; box-shadow: 0 4px 10px rgba(0,0,0,0.45); }
.card:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; }
.card.back { cursor: default; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 2px rgba(216, 176, 74, 0.35), 0 0 14px rgba(216, 176, 74, 0.25); }
  50% { box-shadow: 0 0 0 2px rgba(216, 176, 74, 0.55), 0 0 24px rgba(216, 176, 74, 0.55); }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}
.controls button {
  padding: 11px 22px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.4px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.12s ease;
}
.controls button:hover:not(:disabled) { transform: translateY(-1px); }
.controls button:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }

@keyframes card-thrown-in {
  0% { opacity: 0; transform: translateY(-30px) scale(0.7) rotate(var(--r, -8deg)); }
  60% { opacity: 1; transform: translateY(4px) scale(1.05) rotate(calc(var(--r, -8deg) * -0.3)); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}
.card.card-thrown-in {
  animation: card-thrown-in 0.4s cubic-bezier(.2,.8,.2,1);
  --r: -8deg;
}
.card.card-thrown-in:nth-child(odd) { --r: 8deg; }

/* ---------- Mano + mazzo delle prese ---------- */

.hand-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 14px 0 4px;
}
.hand-area { padding: 0; flex: 1; transition: opacity 0.15s ease; }
.hand-area.hand-locked { pointer-events: none; opacity: 0.7; }

.my-pile, .pile {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: var(--card-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.pile.pile-small { min-width: 44px; min-height: 48px; transform: scale(0.85); transform-origin: bottom center; }

.pile-stack {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}
.pile.pile-small .pile-stack, .pile.pile-small .pile-scope { width: 34px; height: 48px; }
.pile-stack.pile-empty {
  border: 2px dashed rgba(255,255,255,0.15);
  border-radius: 7px;
  width: var(--card-w);
  height: var(--card-h);
}
.pile.pile-small .pile-stack.pile-empty { width: 34px; height: 48px; border-width: 1px; }

.pile-stack .card.pile-card {
  position: absolute;
  left: 0;
  top: calc(var(--i, 0) * -3px);
  width: 100%;
  height: 100%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.4);
  animation: none;
}
.pile-count {
  position: absolute;
  right: -6px;
  bottom: -6px;
  background: var(--gold-bright);
  color: #2b1d05;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  z-index: 3;
}

.pile-scope {
  display: flex;
  align-items: center;
  position: relative;
  height: 26px;
}
.pile-scope-card {
  width: 22px;
  height: 30px;
  border-radius: 3px;
  overflow: hidden;
  transform: rotate(90deg);
  margin-left: -6px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.4);
  border: 1px solid rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.pile-scope-card:first-child { margin-left: 0; }
.pile-scope-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pile-scope-label {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold-bright);
  white-space: nowrap;
}

@keyframes pile-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
.pile.pile-bump .pile-stack, .my-pile.pile-bump .pile-stack { animation: pile-bump 0.42s ease; }
.opponent .pile.pile-small.pile-bump { animation: pile-bump 0.42s ease; }

/* ---------- Carte volanti (animazione presa) ---------- */

.fly-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}
.flying-card {
  position: fixed;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
  transition: transform 0.46s cubic-bezier(.22,.8,.25,1), opacity 0.46s ease;
  will-change: transform, opacity;
}
.flying-card img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Banner dichiarazione Sbarazzina ---------- */

.accuso-banner {
  position: fixed;
  top: 14%;
  left: 50%;
  transform: translate(-50%, -16px) scale(0.92);
  background: linear-gradient(160deg, rgba(20, 58, 40, 0.98), rgba(9, 32, 22, 0.98));
  border: 1.5px solid var(--gold-bright);
  border-radius: 16px;
  padding: 18px 26px;
  text-align: center;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 20px 50px rgba(0,0,0,0.55), 0 0 30px rgba(216, 176, 74, 0.25);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(.2,.8,.2,1);
}
.accuso-banner.visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.accuso-banner-title {
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--gold-bright);
  font-weight: 700;
  margin-bottom: 4px;
  text-shadow: 0 0 14px rgba(216, 176, 74, 0.5);
}
.accuso-banner-sub {
  font-size: 12.5px;
  color: rgba(246, 236, 214, 0.75);
  margin-bottom: 10px;
}
.accuso-banner-cards {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.accuso-banner-cards .card { width: 48px; height: 68px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 10, 0.72);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: linear-gradient(160deg, rgba(20, 58, 40, 0.98), rgba(9, 32, 22, 0.98));
  border-radius: 14px;
  padding: 22px;
  max-width: 480px;
  width: 90%;
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}
.modal h3 {
  margin-top: 0;
  font-family: var(--font-display);
  color: var(--gold-bright);
  font-size: 17px;
}
.option-row {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.05);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}
.option-row .cards { display: flex; gap: 4px; }
.option-row .card { width: 52px; height: 74px; }
.option-row button {
  padding: 8px 16px;
  border: none;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  font-weight: 700;
  cursor: pointer;
  color: #2b1d05;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  padding: 11px 22px;
  border-radius: 10px;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: 0.3px;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 10px 24px rgba(0,0,0,0.4);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.result-modal {
  max-width: 420px;
  text-align: center;
  animation: result-modal-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes result-modal-in {
  from { opacity: 0; transform: scale(0.9) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.round-end-banner { margin-bottom: 16px; }
.round-end-banner h2 {
  font-family: var(--font-display);
  margin: 4px 0 4px;
  font-size: 22px;
  color: var(--gold-bright);
}
.round-end-banner p {
  margin: 0;
  font-size: 13px;
  color: rgba(246, 236, 214, 0.7);
}
.round-end-banner .trophy {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.4));
}
.round-end-banner.match-end.win .trophy { animation: trophy-pop 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.round-end-banner.match-end.win h2 {
  color: var(--gold-bright);
  text-shadow: 0 0 18px rgba(216, 176, 74, 0.6);
}
.round-end-banner.match-end.lose h2 { color: #d9a4a4; }
.round-end-banner.match-end.tie h2 { color: #cfcfcf; }
@keyframes trophy-pop {
  0% { transform: scale(0.3) rotate(-15deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.result-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 4px; }
.result-table td, .result-table th { padding: 7px 8px; text-align: center; }
.result-table th {
  font-family: var(--font-display);
  color: var(--gold-bright);
  border-bottom: 1px solid var(--panel-border);
}
.result-table .result-label { text-align: left; color: rgba(246, 236, 214, 0.75); white-space: nowrap; }
.result-table tr:nth-child(even) { background: rgba(255,255,255,0.03); }
.result-table td.result-win {
  color: var(--gold-bright);
  font-weight: 700;
  background: rgba(216, 176, 74, 0.14);
  border-radius: 6px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.result-actions button {
  padding: 11px 22px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-family: var(--font-display);
  cursor: pointer;
  letter-spacing: 0.3px;
}
#nextRoundBtn {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: transform 0.12s ease;
}
#nextRoundBtn:hover { transform: translateY(-1px); }
.secondary-dark {
  background: transparent;
  border: 1.5px solid var(--panel-border) !important;
  color: var(--parchment);
}
.secondary-dark:hover { background: rgba(255,255,255,0.06); }

@media (max-width: 480px) {
  :root { --card-w: 62px; --card-h: 88px; }
  #lobby { margin: 20px 16px; padding: 24px 18px; }
  #lobby h1 { font-size: 27px; }
  .table-area { padding: 18px; }
  .opponent { min-width: 140px; }
  .option-row .card { width: 42px; height: 60px; }
  .scoreboard { justify-content: center; }
  #scores { justify-content: center; min-width: 0; }
  .score-team { min-width: 110px; max-width: none; }
  .round-end-banner .trophy { font-size: 40px; }
  .round-end-banner h2 { font-size: 19px; }
  .result-actions { flex-direction: column; }
  .stats-modal { max-width: 100%; }
  .history-match { flex-direction: column; gap: 4px; }
}

/* ---------- Classifica & storico partite ---------- */

.stats-modal {
  max-width: 480px;
  width: 92%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
}

.stats-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.stats-tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: transparent;
  color: rgba(246, 236, 214, 0.65);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.stats-tab.active {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1d05;
  border-color: transparent;
}

.stats-panel {
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  margin-bottom: 14px;
}
.stats-loading, .stats-empty {
  text-align: center;
  color: rgba(246, 236, 214, 0.6);
  font-size: 13px;
  padding: 30px 10px;
}

.stats-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.stats-table th {
  font-family: var(--font-display);
  color: var(--gold-bright);
  border-bottom: 1px solid var(--panel-border);
  padding: 6px 8px;
  text-align: center;
}
.stats-table th:nth-child(2) { text-align: left; }
.stats-table td { padding: 7px 8px; text-align: center; }
.stats-table td:nth-child(2) { text-align: left; }
.stats-table tr:nth-child(even) { background: rgba(255,255,255,0.03); }
.stats-table tr.stats-me { background: rgba(216, 176, 74, 0.16); font-weight: 700; }

.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-row {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 10px 12px;
}
.history-meta {
  font-size: 11px;
  color: rgba(246, 236, 214, 0.55);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.history-match {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
}
.history-side { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-side.history-winner { color: var(--gold-bright); font-weight: 700; }
.history-side:last-child { text-align: right; }
.history-score {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--parchment);
  flex-shrink: 0;
  padding: 2px 10px;
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
}
