/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt: #1a6b3c;
  --felt-dark: #145a30;
  --felt-light: #1e7d46;
  --gold: #f5c542;
  --red: #e74c3c;
  --white: #fff;
  --card-w: 72px;
  --card-h: 100px;
  --card-radius: 8px;
}

html, body {
  width: 100%; height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--felt);
  color: var(--white);
  overflow: hidden;
  user-select: none;
}

/* ─── Game Layout ─── */
#game {
  width: 100vw; height: 100vh;
  display: flex; flex-direction: column;
  position: relative;
  background: radial-gradient(ellipse at center, var(--felt-light) 0%, var(--felt) 50%, var(--felt-dark) 100%);
}

/* ─── Table (center area) ─── */
.table {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* ─── Player Positions ─── */
.player-area {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.player-area--south { bottom: 0; left: 50%; transform: translateX(-50%); }
.player-area--north { top: 12px; left: 50%; transform: translateX(-50%); }
.player-area--west  { left: 12px; top: 50%; transform: translateY(-50%); }
.player-area--east  { right: 12px; top: 50%; transform: translateY(-50%); }

.player-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.85;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  white-space: nowrap;
}
.player-label .score {
  font-weight: 400;
  opacity: 0.7;
  font-size: 0.65rem;
}
.player-area--active .player-label {
  color: var(--gold);
  opacity: 1;
}

/* ─── Trick Pile (center) ─── */
.trick-pile {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 280px; height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trick-card {
  position: absolute;
  transition: all 0.3s ease;
}
.trick-card--0 { transform: translate(-42px, -50px); }
.trick-card--1 { transform: translate(-80px, -10px); }
.trick-card--2 { transform: translate(-42px, 30px); }
.trick-card--3 { transform: translate(-4px, -10px); }

/* ─── Cards ─── */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--card-radius);
  background: #fff;
  border: 1px solid #ccc;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  cursor: default;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card--red   { color: #c0392b; }
.card--black { color: #2c3e50; }

.card__rank {
  position: absolute;
  top: 5px; left: 7px;
  font-size: 0.7rem;
  line-height: 1;
}
.card__rank-br {
  position: absolute;
  bottom: 5px; right: 7px;
  font-size: 0.7rem;
  line-height: 1;
  transform: rotate(180deg);
}
.card__suit {
  font-size: 1.6rem;
  line-height: 1;
}

.card--back {
  background: linear-gradient(135deg, #8B0000 0%, #a01010 50%, #8B0000 100%);
  border-color: #6b0000;
  color: transparent;
  background-image: 
    linear-gradient(135deg, #8B0000 0%, #a01010 50%, #8B0000 100%),
    repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255,255,255,0.04) 4px, rgba(255,255,255,0.04) 8px);
}
.card--back::after {
  content: '♠';
  font-size: 1.6rem;
  color: rgba(255,255,255,0.12);
}

/* ─── Hand (south player) ─── */
.hand {
  display: flex;
  justify-content: center;
  padding: 10px 0 16px;
  position: relative;
  min-height: calc(var(--card-h) + 36px);
}
.hand .card {
  margin-left: -24px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, margin-top 0.15s ease;
}
.hand .card:first-child { margin-left: 0; }
.hand .card:hover:not(.card--disabled) {
  transform: translateY(-12px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  z-index: 10;
}
.hand .card--selected {
  transform: translateY(-20px);
  box-shadow: 0 8px 20px rgba(245, 197, 66, 0.4);
  border-color: var(--gold);
}
.hand .card--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.hand .card--playable {
  cursor: pointer;
}
.hand .card--playable::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--card-radius) + 2px);
  border: 2px solid rgba(245, 197, 66, 0.5);
  pointer-events: none;
}

/* ─── AI Hands (facedown) ─── */
.ai-hand {
  display: flex;
  gap: 2px;
}
.ai-hand--vertical {
  flex-direction: column;
}
.ai-hand .card {
  width: 36px; height: 52px;
}
.ai-hand--vertical .card {
  width: 52px; height: 36px;
  margin-top: -20px;
}
.ai-hand--vertical .card:first-child { margin-top: 0; }
.ai-hand:not(.ai-hand--vertical) .card {
  margin-left: -20px;
}
.ai-hand:not(.ai-hand--vertical) .card:first-child { margin-left: 0; }

/* ─── Status / Messages ─── */
.status-bar {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -80px);
  text-align: center;
  z-index: 20;
}
.status-msg {
  background: rgba(0,0,0,0.6);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

/* ─── Pass Button ─── */
.pass-btn {
  position: absolute;
  bottom: 160px; left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 10px 32px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #1a1a1a;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: all 0.15s ease;
}
.pass-btn:hover { background: #f7d060; transform: translateX(-50%) translateY(-1px); }
.pass-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pass-btn--hidden { display: none; }

/* ─── Scoreboard Overlay ─── */
.scoreboard {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.scoreboard__card {
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 32px 40px;
  min-width: 320px;
  text-align: center;
}
.scoreboard__title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--gold);
}
.scoreboard__table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}
.scoreboard__table th,
.scoreboard__table td {
  padding: 8px 12px;
  text-align: center;
  font-size: 0.8rem;
}
.scoreboard__table th {
  color: rgba(255,255,255,0.5);
  font-weight: 400;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.scoreboard__table td {
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.scoreboard__table tr.you td { color: var(--gold); font-weight: 600; }
.scoreboard__table tr.winner td { color: #2ecc71; }

.scoreboard__btn {
  padding: 10px 32px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #1a1a1a;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.scoreboard__btn:hover { background: #f7d060; }

.scoreboard__result {
  margin: 12px 0 4px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.05em;
}
.scoreboard__result:first-of-type { margin-top: 16px; }

/* ─── Responsive ─── */
@media (max-width: 600px) {
  :root {
    --card-w: 54px;
    --card-h: 76px;
  }
  .card__suit { font-size: 1.2rem; }
  .card__rank, .card__rank-br { font-size: 0.55rem; }
  .hand .card { margin-left: -18px; }
  .trick-card--0 { transform: translate(-32px, -40px); }
  .trick-card--1 { transform: translate(-64px, -6px); }
  .trick-card--2 { transform: translate(-32px, 26px); }
  .trick-card--3 { transform: translate(0px, -6px); }
  .ai-hand .card { width: 28px; height: 42px; }
  .ai-hand--vertical .card { width: 42px; height: 28px; margin-top: -16px; }
  .ai-hand:not(.ai-hand--vertical) .card { margin-left: -14px; }
  .player-label { font-size: 0.6rem; }
  .pass-btn { bottom: 120px; }
}
