:root {
  --bg: #0a0518;
  --panel: #1a0f2e;
  --panel2: #221538;
  --ink: #e8ddff;
  --muted: #8a7aa8;
  --p1: #00f0ff;
  --p2: #ff2a6d;
  --p3: #b388ff;
  --p4: #7af7a7;
  --gold: #ffd166;
  --card-bg: #f5efe1;
  --card-edge: #2a1f3d;
  --red-suit: #d23a3a;
  --black-suit: #1a1a1a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 50% 30%, #1c1450 0%, #0c0828 55%, #050214 100%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.012) 0 2px,
      transparent 2px 4px
    );
  background-blend-mode: screen;
  color: var(--ink);
  font-family: 'VT323', ui-monospace, monospace;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 60%, transparent 35%, rgba(0,0,0,0.55) 100%);
  z-index: 1;
}
.app { position: relative; z-index: 2; }

.hidden { display: none !important; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Lobby */
.lobby {
  position: fixed;
  inset: 0;
  background: rgba(8, 4, 22, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  z-index: 100;
}
.lobby.hidden { display: none; }
.lobby h2 {
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: 24px;
  color: var(--gold);
  margin: 0 0 8px;
  letter-spacing: 2px;
}
.lobby-lead {
  color: var(--muted);
  margin: 0;
  text-align: center;
  max-width: 360px;
}
.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, 100%);
}
.lobby-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.lobby-row.col {
  flex-direction: column;
  align-items: stretch;
}
.lobby-row label {
  color: var(--muted);
  font-size: 14px;
}
.lobby-input {
  flex: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel2);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 16px;
}
.lobby-input.center { text-align: center; }
.lobby-btn {
  background: var(--panel);
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 1px;
}
.lobby-btn:hover { background: var(--gold); color: #000; }
.lobby-hint { color: var(--muted); margin: 0; }
.lobby-err { color: #ff6b6b; margin: 0; min-height: 1em; }

/* Table fills the viewport exactly; never scrolls. Play-area absorbs slack. */
.table {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.table.hidden { display: none; }
.topbar {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 14px;
  background: rgba(0,0,0,0.4);
  border-bottom: 1px solid var(--panel2);
}
.score-block { display: flex; flex-direction: column; gap: 2px; }
.score-block.team0 { color: var(--p1); }
.score-block.team1 { color: var(--p2); }
.score-label { font-size: 16px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
.score-label.ours { color: var(--gold); font-weight: bold; }
.score-row { display: flex; align-items: baseline; gap: 8px; }
.score-num { font-size: 28px; font-weight: bold; }
.brote { color: var(--gold); font-size: 15px; }
.tricks-row { font-size: 13px; color: var(--muted); }

.center-info { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.turn-badge {
  background: var(--panel);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 4px 10px;
  font-size: 16px;
  letter-spacing: 1px;
}
.trump-badge {
  color: var(--gold);
  font-size: 22px;
  min-height: 1em;
}
.multiplier-badge {
  background: #2a0f2a;
  border: 1px solid #ff5b6e;
  color: #ff8aa0;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 4px 10px;
  letter-spacing: 1.5px;
  box-shadow: 0 0 12px rgba(255, 91, 110, 0.4);
  animation: mul-pulse 1.4s ease-in-out infinite;
}
.multiplier-badge[hidden] { display: none; }
@keyframes mul-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 91, 110, 0.4); }
  50%      { box-shadow: 0 0 22px rgba(255, 91, 110, 0.85); }
}
.double-btn {
  background: linear-gradient(180deg, #b81d3d 0%, #8a0a26 100%);
  color: #fff;
  border: 1px solid #ff6477;
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 7px 14px;
  letter-spacing: 1.5px;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 14px rgba(255, 91, 110, 0.55), inset 0 0 8px rgba(255, 255, 255, 0.15);
  animation: dbl-pulse 1.2s ease-in-out infinite;
}
.double-btn[hidden] { display: none; }
.double-btn:hover { filter: brightness(1.15); }
.double-btn:active { transform: translateY(1px); }
@keyframes dbl-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
.netstat { color: var(--muted); font-size: 13px; }
.reset-btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel2);
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.reset-btn:hover { background: var(--panel2); }

/* Play area */
.play-area {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 1fr 2fr 1fr;
  grid-template-areas:
    ". top ."
    "left trick right"
    ". bot .";
  gap: 12px;
  padding: 16px;
  /* Felt-table inner glow + trump-suit tint (set via --felt-trump CSS var). */
  background:
    radial-gradient(ellipse at 50% 50%, var(--felt-trump, rgba(80, 40, 140, 0.18)) 0%, transparent 60%),
    radial-gradient(circle at 50% 50%, transparent 65%, rgba(0, 0, 0, 0.35) 100%);
  transition: background 0.6s ease-out;
}

/* Trump-declared moment: short radial flash from center. */
.trump-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  background: radial-gradient(circle at 50% 50%, var(--flash-color, #ffd166) 0%, transparent 50%);
  animation: trump-radial 1.05s ease-out forwards;
}
.trump-flash[hidden] { display: none; }
@keyframes trump-radial {
  0%   { opacity: 0; transform: scale(0.4); }
  20%  { opacity: 0.85; transform: scale(0.9); }
  100% { opacity: 0; transform: scale(2.2); }
}
.seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.seat-top { grid-area: top; }
.seat-left { grid-area: left; justify-content: center; }
.seat-right { grid-area: right; justify-content: center; }
.seat-name {
  color: var(--ink);
  font-size: 15px;
  background: var(--panel);
  padding: 3px 10px;
  border: 1px solid var(--panel2);
  letter-spacing: 0.5px;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.2s ease;
}
.seat-name.active {
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.5);
}
.seat-name.dealer { border-style: dashed; }
.seat-name.forehand { border-style: solid; background: #2a1f3d; }
.opp-hand { display: flex; }
.opp-hand.vert { flex-direction: column; }
.opp-card {
  width: 42px;
  height: 60px;
  border: 1px solid #6ba0d2;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, #1f6db5 0%, #1f6db5 48%, #ffffff 48%, #ffffff 52%, #1c5e9d 52%, #1c5e9d 100%);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.10),
    0 3px 6px rgba(0, 0, 0, 0.35);
}
.opp-card::before,
.opp-card::after {
  content: "BAUER";
  position: absolute;
  left: 50%;
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: 6px;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  writing-mode: vertical-rl;
  font-weight: bold;
  white-space: nowrap;
}
.opp-card::before {
  top: 4px;
  transform: translateX(-50%) rotate(180deg);
}
.opp-card::after {
  bottom: 4px;
  transform: translateX(-50%);
}
.opp-hand .opp-card + .opp-card { margin-left: -26px; }
.opp-hand.vert .opp-card + .opp-card { margin-left: 0; margin-top: -42px; }

.trick-area {
  grid-area: trick;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  align-items: center;
  justify-items: center;
}
.trick-card { min-width: 60px; min-height: 84px; }
.trick-top { grid-column: 2; grid-row: 1; }
.trick-left { grid-column: 1; grid-row: 2; }
.trick-right { grid-column: 3; grid-row: 2; }
.trick-bot { grid-column: 2; grid-row: 3; }

.card {
  width: 64px;
  height: 92px;
  background: var(--card-bg);
  border: 1px solid var(--card-edge);
  border-radius: 6px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  font-family: 'VT323', serif;
  color: var(--black-suit);
  user-select: none;
  position: relative;
}
.card.red { color: var(--red-suit); }
.card.trump { box-shadow: 0 0 12px rgba(255, 209, 102, 0.6), 0 4px 8px rgba(0,0,0,0.5); border-color: var(--gold); }
.card .corner { font-size: 16px; line-height: 1; font-weight: bold; }
.card .center { font-size: 28px; font-weight: bold; }
.card .corner.br { transform: rotate(180deg); }
.card.played { transform: none; }

/* My hand */
.my-hand {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px 16px;
  background: rgba(0,0,0,0.35);
  min-height: 110px;
}
.my-hand .card {
  cursor: pointer;
  transition: transform 0.15s ease;
}
.my-hand .card:hover { transform: translateY(-8px); }
.my-hand .card.illegal { opacity: 0.4; cursor: not-allowed; }
.my-hand .card.illegal:hover { transform: none; }

/* ---- Animations ---- */
@keyframes deal-card {
  from { transform: translateY(140px) rotate(-12deg) scale(0.7); opacity: 0; }
  to   { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
}
@keyframes deal-back-h {
  from { transform: translateY(-100px) scale(0.6); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes deal-back-v-left {
  from { transform: translateX(-100px) scale(0.6); opacity: 0; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}
@keyframes deal-back-v-right {
  from { transform: translateX(100px) scale(0.6); opacity: 0; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}
.my-hand .card.dealing {
  animation: deal-card 0.55s cubic-bezier(0.22, 0.9, 0.32, 1.18) backwards;
}
.opp-hand .opp-card.dealing { animation: deal-back-h 0.45s ease-out backwards; }
.seat-left .opp-hand.vert .opp-card.dealing { animation: deal-back-v-left 0.45s ease-out backwards; }
.seat-right .opp-hand.vert .opp-card.dealing { animation: deal-back-v-right 0.45s ease-out backwards; }
/* Staggered delays — applies to whichever cards are .dealing. */
.dealing[data-stagger="0"] { animation-delay: 0ms; }
.dealing[data-stagger="1"] { animation-delay: 70ms; }
.dealing[data-stagger="2"] { animation-delay: 140ms; }
.dealing[data-stagger="3"] { animation-delay: 210ms; }
.dealing[data-stagger="4"] { animation-delay: 280ms; }

@keyframes fly-from-top {
  from { transform: translateY(-180px) scale(0.6); opacity: 0.2; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes fly-from-bot {
  from { transform: translateY(180px) scale(0.6); opacity: 0.2; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes fly-from-left {
  from { transform: translateX(-220px) scale(0.6); opacity: 0.2; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}
@keyframes fly-from-right {
  from { transform: translateX(220px) scale(0.6); opacity: 0.2; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}
.trick-card .card.fly-top { animation: fly-from-top 0.30s ease-out; }
.trick-card .card.fly-bot { animation: fly-from-bot 0.30s ease-out; }
.trick-card .card.fly-left { animation: fly-from-left 0.30s ease-out; }
.trick-card .card.fly-right { animation: fly-from-right 0.30s ease-out; }

/* Trick-winner spotlight + cards converge on winner's seat */
@keyframes winner-pulse {
  0%   { transform: scale(1); box-shadow: 0 4px 8px rgba(0,0,0,0.5); }
  35%  { transform: scale(1.22); box-shadow: 0 0 32px rgba(255,209,102,0.95), 0 4px 8px rgba(0,0,0,0.5); }
  70%  { transform: scale(1.12); box-shadow: 0 0 22px rgba(255,209,102,0.75), 0 4px 8px rgba(0,0,0,0.5); }
  100% { transform: scale(1); box-shadow: 0 4px 8px rgba(0,0,0,0.5); }
}
/* Each loser card translates toward the winner (--tx/--ty set inline). */
@keyframes loser-converge {
  0% {
    transform: translate(0, 0) scale(1) rotate(0);
    opacity: 1;
    filter: brightness(1);
  }
  60% {
    transform: translate(calc(var(--tx) * 0.65), calc(var(--ty) * 0.65)) scale(0.85) rotate(var(--lr, 0deg));
    opacity: 0.85;
    filter: brightness(0.85);
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0.55) rotate(var(--lr, 0deg));
    opacity: 0;
    filter: brightness(0.55);
  }
}
.trick-card .card.won {
  animation: winner-pulse 0.85s ease-out;
  border-color: var(--gold);
  z-index: 4;
}
.trick-card .card.lost {
  animation: loser-converge 0.85s cubic-bezier(0.55, 0.1, 0.85, 0.3) 0.2s both;
  z-index: 3;
}

/* Mid-trick "currently leading" highlight — shows whose card is winning so far. */
.trick-card .card.leading {
  border-color: #7af7a7;
  box-shadow: 0 0 14px rgba(122, 247, 167, 0.7), 0 4px 8px rgba(0, 0, 0, 0.5);
  z-index: 2;
}
.trick-card .card.leading::after {
  content: "▲";
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  color: #7af7a7;
  font-size: 11px;
  text-shadow: 0 0 6px rgba(122, 247, 167, 0.9);
  pointer-events: none;
}

/* Hand: visible separator between suit groups. */
.my-hand .card.group-start {
  margin-left: 14px;
  position: relative;
}
.my-hand .card.group-start::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 10%;
  bottom: 10%;
  width: 1px;
  background: linear-gradient(180deg, transparent 0%, rgba(255, 255, 255, 0.25) 25%, rgba(255, 255, 255, 0.25) 75%, transparent 100%);
  pointer-events: none;
}

/* Score number pulse */
@keyframes score-bump {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.35); color: var(--gold); }
  100% { transform: scale(1); }
}
.score-num.bump { animation: score-bump 0.55s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes brote-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.6) rotate(-8deg); filter: drop-shadow(0 0 8px var(--gold)); }
  70%  { transform: scale(1.2) rotate(4deg); }
  100% { transform: scale(1); }
}
.brote.pop { animation: brote-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1); display: inline-block; }

/* Turn badge slide-in when changing */
@keyframes turn-slide {
  from { transform: translateY(-8px); opacity: 0.2; }
  to   { transform: translateY(0); opacity: 1; }
}
.turn-badge.slide { animation: turn-slide 0.25s ease-out; }

/* Active seat — soft pulsing glow */
@keyframes seat-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 209, 102, 0.35); }
  50%      { box-shadow: 0 0 16px rgba(255, 209, 102, 0.7); }
}
.seat-name.active { animation: seat-pulse 1.6s ease-in-out infinite; }

/* Smoother hand-card hover with tilt + scale */
.my-hand .card {
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.18s ease;
}
.my-hand .card:hover {
  transform: translateY(-14px) scale(1.06);
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.65), 0 0 18px rgba(255, 209, 102, 0.35);
  z-index: 5;
}
.my-hand .card.illegal:hover {
  transform: none;
  box-shadow: 0 4px 8px rgba(0,0,0,0.5);
}

/* Win banner — cannonhill-style diagonal ribbon + glowing bloom text */
.win-banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
  overflow: hidden;
}
.win-banner[hidden] { display: none; }
.win-banner-ribbon {
  position: absolute;
  left: -15%;
  right: -15%;
  height: 90px;
  background: var(--banner-color, #ffd166);
  transform: rotate(-4deg);
  opacity: 0.22;
  animation: ribbon-breath 1.5s ease-in-out infinite,
             ribbon-slide 0.7s cubic-bezier(0.22, 0.61, 0.36, 1);
}
.win-banner-text {
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: clamp(22px, 5vw, 42px);
  color: var(--banner-color, #ffd166);
  letter-spacing: 2.5px;
  font-weight: bold;
  text-align: center;
  text-shadow:
    0 0 10px var(--banner-color, #ffd166),
    0 0 22px var(--banner-color, #ffd166),
    0 0 34px rgba(0, 0, 0, 0.85);
  animation: banner-text-pop 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.win-banner-sub {
  font-family: 'VT323', monospace;
  font-size: 18px;
  color: var(--banner-color, #ffd166);
  letter-spacing: 1px;
  margin-top: 6px;
  opacity: 0.85;
  text-shadow: 0 0 12px var(--banner-color, #ffd166);
  animation: banner-text-pop 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s backwards;
}
@keyframes ribbon-breath {
  0%, 100% { opacity: 0.18; }
  50%      { opacity: 0.32; }
}
@keyframes ribbon-slide {
  from { transform: rotate(-4deg) translateX(-120%); }
  to   { transform: rotate(-4deg) translateX(0); }
}
@keyframes banner-text-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1.0); opacity: 1; }
}
.win-banner.fading {
  animation: banner-fade-out 0.35s ease-in forwards;
}
@keyframes banner-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* Confetti */
.confetti-piece {
  position: absolute;
  left: 50%;
  top: 30%;
  width: 8px;
  height: 12px;
  pointer-events: none;
  border-radius: 2px;
  animation: confetti-fly 1.8s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  z-index: 50;
}
@keyframes confetti-fly {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  90%  { opacity: 1; }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot));
    opacity: 0;
  }
}

/* Deal complete + game over overlay */
.deal-complete {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 22, 0.78);
  z-index: 10;
}
.deal-complete[hidden] { display: none; }
.dc-card {
  background: var(--panel);
  border: 2px solid var(--gold);
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.dc-title {
  font-family: 'Press Start 2P', 'VT323', monospace;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 1.5px;
}
.dc-result { color: var(--ink); font-size: 18px; }
.dc-hint { color: var(--muted); font-size: 14px; }

/* Trump picker */
.trump-picker {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 22, 0.78);
  z-index: 11;
  gap: 14px;
}
.trump-picker[hidden] { display: none; }
.tp-title {
  font-family: 'Press Start 2P', 'VT323', monospace;
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 1.5px;
}
.tp-row { display: flex; gap: 12px; }
.tp-btn {
  width: 90px;
  height: 110px;
  background: var(--card-bg);
  border: 2px solid var(--card-edge);
  border-radius: 6px;
  cursor: pointer;
  font-family: 'VT323', serif;
  font-size: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--black-suit);
}
.tp-btn.red { color: var(--red-suit); }
.tp-btn:hover { box-shadow: 0 0 16px rgba(255,209,102,0.6); }
.tp-btn span { font-size: 14px; color: #555; }
.tp-hint { color: var(--muted); font-size: 14px; text-align: center; max-width: 320px; }

/* Chat — collapsed by default behind a small arrow toggle in the lower-left.
 * Body slides upward from the toggle when opened. Never overlaps gameplay. */
.chat-panel {
  position: fixed;
  left: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  flex-direction: column-reverse; /* body above, toggle below */
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
.chat-panel > * { pointer-events: auto; }
.chat-panel[hidden] { display: none; }
.chat-toggle {
  background: rgba(26, 15, 46, 0.92);
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}
.chat-toggle:hover { background: rgba(40, 25, 70, 0.95); }
.chat-arrow {
  display: inline-block;
  font-size: 11px;
  color: var(--gold);
  transition: transform 0.18s ease;
}
.chat-panel.open .chat-arrow { transform: rotate(180deg); }
.chat-icon { font-size: 14px; line-height: 1; }
.chat-badge {
  background: var(--p2);
  color: #000;
  padding: 0 5px;
  font-size: 11px;
  border-radius: 2px;
  min-width: 14px;
  text-align: center;
  font-weight: bold;
}
.chat-body {
  width: 240px;
  max-height: 240px;
  background: rgba(20, 12, 40, 0.95);
  border: 1px solid var(--panel2);
  display: flex;
  flex-direction: column;
}
.chat-body[hidden] { display: none !important; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  font-size: 14px;
}
.chat-form { display: flex; }
.chat-input {
  flex: 1;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--panel2);
  border-top: none;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 14px;
}
.chat-send {
  background: var(--panel);
  color: var(--gold);
  border: 1px solid var(--panel2);
  border-top: none;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
}

/* ============== Responsive ============== */
@media (max-width: 720px) {
  /* Topbar — single tight row, hide less-essential buttons (still in DOM) */
  .topbar {
    grid-template-columns: 1fr 1.4fr 1fr auto;
    gap: 6px;
    padding: 6px 8px;
  }
  .topbar #copyInvite,
  .topbar #reset {
    display: none;
  }
  .score-label { font-size: 13px; letter-spacing: 0.6px; }
  .score-num { font-size: 22px; }
  .brote { font-size: 12px; }
  .tricks-row { font-size: 11px; }
  .turn-badge { font-size: 11px; padding: 3px 7px; letter-spacing: 0.4px; }
  .trump-badge { font-size: 16px; }
  .netstat { font-size: 11px; }
  .multiplier-badge { font-size: 10px; padding: 3px 7px; }
  .double-btn { font-size: 9px; padding: 5px 10px; letter-spacing: 1px; }

  /* Play area — tighter gaps, smaller opp cards */
  .play-area {
    padding: 6px;
    gap: 4px;
    min-height: 0;
  }
  .seat-name { font-size: 11px; padding: 2px 7px; }
  .opp-card { width: 28px; height: 40px; }
  .opp-card::before, .opp-card::after { font-size: 5px; letter-spacing: 1px; }
  .opp-hand .opp-card + .opp-card { margin-left: -18px; }
  .opp-hand.vert .opp-card + .opp-card { margin-top: -28px; }

  /* Trick area cards — slightly smaller */
  .trick-card { min-width: 44px; min-height: 62px; }

  /* My hand — keep cards finger-friendly while fitting 5 across a 360px screen */
  .my-hand {
    padding: 6px 6px 10px;
    gap: 3px;
    min-height: 88px;
  }
  .my-hand .card { width: 54px; height: 78px; }
  .my-hand .card .corner { font-size: 13px; }
  .my-hand .card .center { font-size: 22px; }
  .my-hand .card.group-start { margin-left: 8px; }

  /* Trump picker — bigger touch targets, single row */
  .tp-btn { width: 62px; height: 84px; font-size: 28px; }
  .tp-btn span { font-size: 11px; }

  /* Win banner text — fits the viewport */
  .win-banner-text { font-size: 24px; letter-spacing: 1.5px; }
  .win-banner-sub { font-size: 14px; }
  .win-banner-ribbon { height: 60px; }

  /* Chat — keep the lower-left positioning; on mobile the body opens to a
   * slightly narrower width and stays clear of the hand area. */
  .chat-panel {
    left: 6px;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }
  .chat-body {
    width: min(86vw, 320px);
    max-height: 45vh;
    border: 1px solid var(--gold);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
  }

  /* Game-over panel — fits small screens */
  .dc-card { padding: 14px 16px; gap: 8px; }
  .dc-title { font-size: 12px; }
  .dc-result { font-size: 14px; text-align: center; }

  /* Multiplier badge in topbar shouldn't wrap */
  .center-info { gap: 2px; }
}

/* Very narrow phones (e.g. iPhone SE) */
@media (max-width: 380px) {
  .my-hand .card { width: 48px; height: 70px; }
  .my-hand .card .center { font-size: 18px; }
  .my-hand .card .corner { font-size: 11px; }
  .my-hand { gap: 2px; }
  .topbar { grid-template-columns: 1fr 1.2fr 1fr auto; }
  .score-num { font-size: 19px; }
  .trump-badge { font-size: 14px; }
  .turn-badge { font-size: 10px; padding: 2px 5px; }
}

/* Landscape phones — reclaim vertical space */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar { padding: 4px 8px; }
  .score-num { font-size: 18px; }
  .play-area { min-height: 0; padding: 4px; gap: 3px; }
  .my-hand { min-height: 76px; padding: 4px 6px 6px; }
  .my-hand .card { width: 46px; height: 66px; }
  .my-hand .card .center { font-size: 18px; }
  .opp-card { width: 24px; height: 34px; }
}
