:root {
  --card-width: 76px;
  --card-height: 108px;
  --card-small-width: 50px;
  --card-small-height: 75px;
  --red: #C00;
  --black: #222;
  --bg: #1a472a;
  --table: #2d5a3d;
  --gold: #daa520;
  --text: #eee;
  --border: #444;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Score Bar */
.score-bar {
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: 0.5rem 1rem;
  background: rgba(0,0,0,0.3);
  font-size: 1.1rem;
  font-weight: bold;
  flex-shrink: 0;
}

/* Fix #6: Softer team colors that complement green/gold palette */
.score-ns { color: #e8a830; } /* warm gold-orange */
.score-ew { color: #5bcec8; } /* teal */

/* Teach Me Toggle */
.teach-toggle {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 12px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  margin-left: 8px;
  transition: all 0.2s;
}

.teach-toggle.active {
  background: var(--gold);
  color: #111;
}

/* Fix #1: Standalone teach toggle in lobby (when score bar is hidden) */
.lobby-teach-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* Game Content */
.game-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: 140px; /* Fix #1: space for fixed hand-area (cards 108px + padding) */
}

/* ========== LOBBY ========== */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  flex: 1;
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  position: relative; /* for absolute-positioned teach toggle */
}

.lobby h1 {
  font-size: 2rem;
  color: var(--gold);
}

.name-input {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.name-input input {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 1rem;
  min-width: 200px;
}

.player-list {
  list-style: none;
  padding: 0;
  width: 100%;
  max-width: 300px;
}

.player-list li {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.share-link {
  background: rgba(0,0,0,0.3);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.9rem;
  word-break: break-all;
  text-align: center;
  max-width: 100%;
}

/* Room code display */
.room-code-display {
  text-align: center;
  padding: 16px;
  margin: 12px 0;
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--gold);
  border-radius: 8px;
}

.room-code-label {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--gold);
  margin-bottom: 4px;
}

.room-code-value {
  display: block;
  font-family: 'Courier New', monospace;
  font-size: 2rem;
  font-weight: bold;
  letter-spacing: 8px;
  color: white;
  margin: 8px 0;
  user-select: all;
}

.room-code-copy {
  margin-top: 8px;
}

.room-code-input {
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
  width: 120px;
  padding: 8px;
}

/* ========== BUTTONS ========== */
.btn {
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.4);
  color: var(--gold);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 44px;
  min-width: 44px;
}

.btn:hover {
  background: rgba(218,165,32,0.2);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--gold);
  color: var(--bg);
  border-color: var(--gold);
  font-weight: bold;
}

.btn-primary:hover,
.btn-primary:active {
  background: #c4941d;
}

/* ========== GAME TABLE LAYOUT ========== */
.game-table {
  display: grid;
  grid-template-areas:
    ".    top    ."
    "left center right"
    ".    bottom .";
  grid-template-columns: 180px 1fr 180px;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
  flex: 1;
  padding: 0.5rem;
  min-height: 0;
}

.player-zone {
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(0,0,0,0.2);
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
  z-index: 1; /* Fix #1: below fixed hand-area (z-index: 100) */
}

.player-zone.current-player {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(218,165,32,0.4);
}

.player-zone .player-name {
  font-weight: bold;
  font-size: 0.95rem;
  text-align: center;
}

.player-zone .player-tricks {
  font-size: 0.8rem;
  opacity: 0.7;
}

.player-zone .ready-indicator {
  font-size: 0.75rem;
  color: var(--gold);
}

/* Teammate indicator */
.player-zone.teammate {
  border-left: 3px solid gold;
  background: rgba(218,165,32,0.1);
}

.teammate-badge {
  font-size: 0.75rem;
  color: var(--gold);
  opacity: 0.9;
}

.player-top { grid-area: top; }
.player-left { grid-area: left; }
.player-right { grid-area: right; }
.player-bottom { grid-area: bottom; }

/* Fix #1: Fixed hand-area at bottom of viewport */
.hand-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(26, 71, 42, 0.95);
  padding: 8px 12px;
  z-index: 100;
  overflow-x: auto;
  display: flex;
  justify-content: flex-start;
  border-top: 2px solid rgba(218, 165, 32, 0.4);
}

.center-zone {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  min-height: 0;
}

/* ========== CARDS ========== */
.card {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 8px;
  background: #fff;
  color: var(--black);
  box-shadow: 1px 2px 6px rgba(0,0,0,0.3);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
}

.card.red {
  color: var(--red);
}

.card.black {
  color: var(--black);
}

.card .rank {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 14px;
  font-weight: bold;
  line-height: 1;
}

.card .suit {
  font-size: 40px;
  line-height: 1;
}

.card.face-down {
  background: #600000;
  border: 2px solid #999;
}

.card.face-down::before {
  content: '';
  position: absolute;
  inset: 3px;
  background: 
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.15) 3px,
      rgba(255,255,255,0.15) 6px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 3px,
      rgba(255,255,255,0.15) 3px,
      rgba(255,255,255,0.15) 6px
    );
  border: 2px solid #aaa;
  border-radius: 3px;
}

.card.face-down .rank,
.card.face-down .suit {
  display: none;
}

.card.selectable {
  cursor: pointer;
  touch-action: manipulation;
}

.card.selectable:hover,
.card.selectable:active {
  box-shadow: 0 0 12px rgba(218,165,32,0.6);
}

/* Fix #1: Prominent card selection */
.card.selected {
  border: 2px solid var(--gold);
  transform: translateY(-8px);
  box-shadow: 0 0 16px rgba(218,165,32,0.8);
}

/* Fix #1: Play Card confirm button */
.play-card-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 4px 10px 4px 0;
  padding: 0.6rem 1.4rem;
  font-size: 1.1rem;
  font-weight: bold;
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: var(--gold);
  color: var(--bg);
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

.play-card-btn:hover {
  background: #c4941d;
  transform: scale(1.03);
}

.play-card-btn:active {
  transform: scale(0.97);
}

.play-card-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  background: rgba(218,165,32,0.5);
  color: rgba(0,0,0,0.5);
}

.card.played {
  width: var(--card-small-width);
  height: var(--card-small-height);
}

.card.played .rank {
  font-size: 11px;
  top: 2px;
  left: 4px;
}

.card.played .suit {
  font-size: 22px;
}

.card.playable {
  border: 2px solid var(--gold);
  box-shadow: 0 0 8px rgba(218,165,32,0.5);
}

/* Fix #3: Disabled cards — visible but not interactive */
.card.disabled {
  pointer-events: none;
  opacity: 0.5;
}

/* Fix #3: Hand loading indicator */
.hand-loading {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-bottom: 4px;
  display: block;
  text-align: center;
}

/* ========== HAND ========== */
.hand {
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  padding: 0.5rem;
  gap: 0;
  justify-content: flex-start;
  align-items: flex-end;
  -webkit-overflow-scrolling: touch;
  width: max-content;
  min-width: 100%;
  flex-wrap: nowrap;
}

.hand .card {
  margin-right: -30px;
  transition: transform 0.15s ease;
}

.hand .card:last-child {
  margin-right: 0;
}

.hand .card:hover,
.hand .card:active {
  transform: translateY(-15px);
  z-index: 10;
}

.hand .card.selectable:hover,
.hand .card.selectable:active {
  transform: translateY(-15px);
  z-index: 10;
}

.hand .card.selected {
  transform: translateY(-15px);
  z-index: 10;
}

/* ========== TRICK AREA ========== */
.trick-area {
  position: relative;
  width: 250px;
  height: 250px;
}

.trick-card {
  position: absolute;
}

.trick-card-0 { bottom: 0; left: 50%; transform: translateX(-50%); }
.trick-card-1 { left: 0; top: 50%; transform: translateY(-50%); }
.trick-card-2 { top: 0; left: 50%; transform: translateX(-50%); }
.trick-card-3 { right: 0; top: 50%; transform: translateY(-50%); }

.trump-badge {
  background: var(--gold);
  color: var(--bg);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: bold;
  white-space: nowrap;
}

.trick-info {
  text-align: center;
  font-size: 0.9rem;
}

/* Fix #2: Running score during trick play */
.running-score {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  padding: 4px 0;
  font-size: 0.85rem;
  font-weight: bold;
}

.running-score .score-ns,
.running-score .score-ew {
  display: inline;
}

.trick-winner-glow {
  box-shadow: 0 0 20px rgba(218,165,32,0.8) !important;
}

/* Fix #3: Trick history (accumulated completed tricks) */
.trick-history {
  max-height: 200px;
  overflow-y: auto;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.trick-history-title {
  text-align: center;
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: bold;
  margin-bottom: 4px;
}

.trick-history-entry {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 3px;
  padding: 2px 4px;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.trick-history-entry .trick-number {
  min-width: 28px;
  color: var(--gold);
  font-weight: bold;
  font-size: 0.7rem;
}

.trick-history-winner {
  font-size: 0.7rem;
  opacity: 0.7;
  min-width: 60px;
}

.trick-history-entry .trick-cards {
  display: flex;
  gap: 0;
}

/* ========== BID PROGRESS (FIX #3) ========== */
.bid-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 400px;
  padding: 6px 10px;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
}

.bid-progress-text {
  font-size: 0.75rem;
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
}

.bid-progress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  overflow: hidden;
}

.bid-progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.bid-progress-green {
  background: #4a4;
}

.bid-progress-yellow {
  background: #da0;
}

.bid-progress-red {
  background: #c44;
}

.bid-progress-warn {
  font-size: 0.7rem;
  color: #da0;
  text-align: center;
  font-style: italic;
}

/* ========== BIDDING ========== */
.bidding-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  flex: 1;
  justify-content: center;
}

.current-bid {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--gold);
}

.bid-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.bid-input-row input {
  width: 80px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  -moz-appearance: textfield;
}

.bid-input-row input::-webkit-outer-spin-button,
.bid-input-row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.bid-history {
  list-style: none;
  padding: 0;
  font-size: 0.9rem;
  text-align: center;
}

.bid-history li {
  padding: 0.2rem 0;
}

/* ========== MELD CHART (FIX #1) ========== */
.meld-chart-toggle {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.meld-chart-container {
  width: 100%;
  max-width: 500px;
  overflow-x: auto;
  margin-top: 0.5rem;
}

.meld-chart {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
  overflow: hidden;
}

.meld-chart th,
.meld-chart td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

.meld-chart th {
  background: rgba(218,165,32,0.2);
  color: var(--gold);
  font-weight: bold;
}

.meld-chart td:first-child {
  text-align: left;
}

.meld-chart tr:last-child td {
  border-bottom: none;
}

/* ========== DECLARING TRUMP ========== */
.trump-picker {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.trump-btn {
  width: 60px;
  height: 60px;
  font-size: 2rem;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
}

.trump-btn:hover {
  background: rgba(218,165,32,0.3);
  transform: scale(1.1);
}

.trump-btn:active {
  transform: scale(0.95);
}

/* ========== MELD TABLE ========== */
.meld-container {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

/* Fix #1: 4-column meld layout */
.meld-columns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
}

.meld-column {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  min-width: 0; /* allow columns to shrink */
}

.meld-column h3 {
  text-align: center;
  margin: 0 0 8px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  color: var(--gold);
}

/* Keep old meld-section for backward compat but not in columns */
.meld-section {
  margin-bottom: 1.5rem;
}

.meld-section h3 {
  color: var(--gold);
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.meld-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.meld-table th,
.meld-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.meld-table td:last-child {
  text-align: right;
}

.meld-total {
  font-weight: bold;
  color: var(--gold);
}

.partnership-totals {
  display: flex;
  justify-content: space-around;
  padding: 0.75rem;
  font-size: 1.1rem;
  font-weight: bold;
  background: rgba(0,0,0,0.2);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.bid-coverage {
  text-align: center;
  font-size: 0.9rem;
  padding: 0.25rem;
}

.bid-coverage.covered { color: #4a4; }
.bid-coverage.uncovered { color: #e44; }

.confirm-section {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.5rem;
}

.confirm-badge {
  font-size: 0.8rem;
  color: #4a4;
}

/* ========== MELD CARD DISPLAY (FIX #2) ========== */
.meld-combos {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.meld-combo {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.meld-combo-label {
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 500;
}

.meld-cards {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 3px;
}

.meld-card {
  width: 44px;
  height: 60px;
  margin-right: 0 !important;
}

.meld-card .rank {
  font-size: 10px;
  top: 2px;
  left: 3px;
}

.meld-card .suit {
  font-size: 20px;
}

.meld-total {
  font-weight: bold;
  color: var(--gold);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* Fix #5: Hand summary card at end of each hand */
.hand-summary {
  max-width: 500px;
  margin: 0 auto;
  background: rgba(0,0,0,0.5);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
}

.hand-summary h2 {
  color: var(--gold);
  margin-bottom: 16px;
}

.hand-summary-teams {
  display: flex;
  justify-content: space-around;
  gap: 16px;
  margin: 12px 0;
}

.hand-summary-team {
  text-align: center;
  flex: 1;
}

.hand-summary-team .team-name {
  font-weight: bold;
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.hand-summary-team .team-breakdown {
  font-size: 0.85rem;
  opacity: 0.8;
}

.hand-summary-team .team-total {
  font-size: 1rem;
  margin-top: 4px;
}

.hand-summary-result {
  margin: 12px 0;
  padding: 8px;
  border-radius: 6px;
  font-weight: bold;
}

.hand-summary-result.bid-made {
  background: rgba(68,170,68,0.2);
  color: #4a4;
}

.hand-summary-result.bid-set {
  background: rgba(204,68,68,0.2);
  color: #c44;
}

.hand-summary-game-scores {
  display: flex;
  justify-content: space-around;
  margin-top: 12px;
  font-size: 1.1rem;
  font-weight: bold;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.meld-lost { color: #c44; font-weight: bold; }
.meld-saved { color: #4a4; }

/* ========== SCORES ========== */
.scores-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  flex: 1;
  justify-content: center;
}

.scores-container h2 {
  color: var(--gold);
}

.hand-score-breakdown {
  display: flex;
  gap: 2rem;
  font-size: 1.2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.hand-score-breakdown > div {
  text-align: center;
}

.set-indicator {
  color: #e44;
  font-weight: bold;
}

.next-hand {
  font-size: 1rem;
  opacity: 0.7;
  text-align: center;
}

/* ========== GAME OVER ========== */
.game-over {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  flex: 1;
  justify-content: center;
}

.game-over h1 {
  font-size: 2.5rem;
  color: var(--gold);
}

.final-scores {
  font-size: 1.5rem;
}

.final-scores .score-ns,
.final-scores .score-ew {
  display: inline;
}

/* ========== TOASTS / ERRORS ========== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #c44;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ========== ANIMATIONS ========== */
@keyframes dealIn {
  from { opacity: 0; transform: translateY(-30px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.card.deal {
  animation: dealIn 0.3s ease forwards;
}

@keyframes trickWin {
  0% { box-shadow: 0 0 0 rgba(218,165,32,0); }
  50% { box-shadow: 0 0 24px rgba(218,165,32,0.9); }
  100% { box-shadow: 0 0 0 rgba(218,165,32,0); }
}

.card.trick-winner {
  animation: trickWin 0.8s ease;
}

/* ========== RECONNECTING BANNER ========== */
.reconnecting-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ffc107;
  color: #333;
  text-align: center;
  padding: 0.5rem;
  font-weight: bold;
  z-index: 1001;
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

/* ========== TEACH ME PANEL ========== */
.teach-panel {
  position: fixed;
  right: 0;
  top: 50px;
  width: 280px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: rgba(0,0,0,0.85);
  border-left: 2px solid var(--gold);
  padding: 16px;
  z-index: 200;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}

.teach-panel h3 {
  color: var(--gold);
  margin-top: 0;
}

.teach-panel ul {
  padding-left: 16px;
}

.teach-panel li {
  margin-bottom: 4px;
}

.teach-panel p {
  margin-bottom: 6px;
}

.teach-panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.6;
  line-height: 1;
  padding: 0;
  min-width: auto;
  min-height: auto;
}

.teach-panel-close:hover,
.teach-panel-close:active {
  opacity: 1;
}

/* ========== WAITING ========== */
.waiting-message {
  text-align: center;
  opacity: 0.7;
  font-style: italic;
  padding: 1rem;
}

.dealing-message {
  text-align: center;
  font-size: 1.2rem;
  padding: 2rem;
}

/* ========== FIX #2: TRICK ANIMATION ========== */
@keyframes fly-to-winner {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  50% { opacity: 1; }
  100% { transform: translate(var(--fly-x), var(--fly-y)) scale(0.6); opacity: 0.8; }
}

@keyframes flip-down {
  0% { transform: rotateY(0deg); }
  100% { transform: rotateY(180deg); }
}

.trick-animation-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  pointer-events: none;
}

.trick-animation-card {
  position: absolute;
  width: var(--card-small-width);
  height: var(--card-small-height);
  border-radius: 6px;
  background: #fff;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.4);
  z-index: 301;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  backface-visibility: hidden;
}

.trick-animation-card .rank {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
}

.trick-animation-card .suit {
  font-size: 22px;
  line-height: 1;
}

.trick-animation-card.red { color: var(--red); }
.trick-animation-card.black { color: var(--black); }

.trick-card-stack {
  position: absolute;
  pointer-events: none;
}

/* ========== FIX #3: HAND SUIT GAPS ========== */
.suit-gap {
  width: var(--card-width);
  flex-shrink: 0;
}

.hand-group {
  display: flex;
  flex-direction: row;
}

/* ========== FIX #4: LANDING PAGE ========== */
.landing-options {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
  max-width: 400px;
  align-items: center;
}

.landing-card {
  background: rgba(0,0,0,0.3);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  text-align: center;
}

.landing-card h3 {
  color: var(--gold);
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
}

.landing-card p {
  font-size: 0.85rem;
  opacity: 0.7;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.landing-card .btn {
  margin: 0.25rem;
}

.landing-join-form {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.75rem;
  align-items: center;
}

.landing-join-form.visible {
  display: flex;
}

.landing-join-form input {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 2px solid var(--gold);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-size: 1rem;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}

/* Fix #2: Room-code input same width as name input in join form */
.landing-join-form input.room-code-input {
  padding: 8px;
  width: 100%;
  font-size: 1.2rem;
  letter-spacing: 4px;
  text-transform: uppercase;
}

/* ========== MOBILE RESPONSIVE ========== */
@media (max-width: 768px) {
  :root {
    --card-width: 58px;
    --card-height: 84px;
    --card-small-width: 40px;
    --card-small-height: 58px;
  }

  .game-table {
    grid-template-areas:
      "top"
      "center"
      "left"
      "right"
      "bottom";
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 0.25rem;
    padding: 0.25rem;
  }

  .player-zone {
    flex-direction: row;
    justify-content: flex-start;
    padding: 0.35rem 0.5rem;
    gap: 0.5rem;
  }

  .player-bottom {
    /* Fix #1: Hand is now in fixed .hand-area, no sticky needed */
  }

  .hand {
    overflow-x: auto;
    justify-content: flex-start;
    padding: 0.5rem 0.25rem;
    -webkit-overflow-scrolling: touch;
    width: max-content;
    min-width: 100%;
    flex-wrap: nowrap;
  }

  /* Fix #5: Reduce overlap so cards are legible and tappable
     Card width 58px - 28px overlap = 30px visible per card (~22px for 13 cards/group)
     Total scrollable width ~58 + 12*30 = 418px for 1 suit group — scrolls nicely */
  .hand .card {
    margin-right: -28px;
    min-height: 44px;
  }

  .hand .card:hover,
  .hand .card:active {
    transform: translateY(-20px);
    z-index: 20;
  }

  .hand .card.selectable:hover,
  .hand .card.selectable:active {
    transform: translateY(-20px);
    z-index: 20;
  }

  .hand .card.selected {
    transform: translateY(-20px);
    z-index: 20;
  }

  .card .rank { font-size: 11px; top: 2px; left: 3px; }
  .card .suit { font-size: 30px; }

  .trick-area {
    width: 180px;
    height: 180px;
  }

  .trump-btn {
    width: 48px;
    height: 48px;
    font-size: 1.5rem;
  }

  .btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;
    width: 100%;
  }

  .game-over h1 {
    font-size: 1.8rem;
  }

  .lobby h1 {
    font-size: 1.5rem;
  }

  .score-bar {
    padding: 4px 8px;
    font-size: 0.85rem;
    gap: 8px;
  }

  /* Fix #5: Adjust content padding for mobile hand-area with larger cards */
  .game-content {
    padding-bottom: 110px;
  }

  /* Teach Me panel — mobile: full-width at bottom above hand */
  .teach-panel {
    position: fixed;
    right: 0;
    left: 0;
    top: auto;
    bottom: 80px;
    width: 100%;
    max-height: 40vh;
    border-left: none;
    border-top: 2px solid var(--gold);
    border-radius: 0;
    z-index: 199;
  }

  .meld-columns {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .meld-column {
    padding: 4px;
  }

  .meld-cards .card,
  .meld-card {
    width: 32px;
    height: 46px;
  }

  .meld-combo-label {
    font-size: 0.7rem;
  }

  /* Fix #2: Landing cards stack on mobile */
  .landing-options {
    flex-direction: column;
    gap: 16px;
  }

  .landing-card {
    width: 100%;
    max-width: none;
  }

  /* Fix #3: Trick history scrollable and compact */
  .trick-history {
    max-height: 120px;
    font-size: 0.7rem;
    overflow-y: auto;
  }

  .trick-history-entry {
    padding: 1px 2px;
  }

  .trick-cards .card {
    width: 32px;
    height: 46px;
    font-size: 0.6rem;
  }

  .trick-cards .card .rank {
    font-size: 8px;
  }

  .trick-cards .card .suit {
    font-size: 14px;
  }

  /* Fix #5: Hand area takes minimal vertical space */
  .hand-area {
    padding: 4px 8px;
    min-height: 60px;
  }

  .hand-area .hand {
    gap: 0;
  }

  /* Fix #6: Teach toggle compact */
  .teach-toggle {
    font-size: 0.65rem;
    padding: 1px 8px;
  }

  /* Fix #7: Bid input and meld buttons full-width */
  .bid-input-row {
    flex-direction: column;
    gap: 8px;
  }

  .bid-input-row input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
  }

  .bid-input-row .btn {
    width: 100%;
  }

  .confirm-section {
    flex-direction: column;
    align-items: stretch;
  }

  .confirm-section .btn {
    width: 100%;
  }

  /* Fix #8: Center zone compact and centered */
  .center-zone {
    min-height: 120px;
    padding: 8px;
  }

  .bid-progress {
    font-size: 0.8rem;
  }

  .bid-progress-text {
    font-size: 0.75rem;
  }

  /* Fix #9: Hand summary full-width */
  .hand-summary {
    max-width: 100%;
    padding: 12px;
    margin: 8px;
    font-size: 0.85rem;
  }

  .hand-summary h2 {
    font-size: 1.2rem;
  }

}
