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

:root {
  --felt: #0a2e17;
  --felt-mid: #0f3d1f;
  --felt-light: #164d28;
  --gold: #c9963a;
  --gold-light: #e8b84b;
  --gold-dim: #7a5a1f;
  --cream: #f5e6c3;
  --cream-dim: #b8a882;
  --red: #c0392b;
  --black: #1a1a1a;
  --card-bg: #fdf8ef;
  --panel-bg: rgba(0,0,0,0.4);
  --border: rgba(201,150,58,0.3);
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.6);
}

html, body {
  height: 100%;
  background: #060f0a;
  font-family: 'Courier Prime', monospace;
  color: var(--cream);
  overflow-x: hidden;
}

/* ── SCREENS ── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ── LOBBY ── */
#screen-lobby {
  align-items: center;
  justify-content: center;
  position: relative;
  background:
    radial-gradient(ellipse 100% 80% at 50% 30%, #0f3d1f 0%, #060f0a 70%);
}

.lobby-bg {
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 50px, rgba(201,150,58,0.03) 50px, rgba(201,150,58,0.03) 51px),
    repeating-linear-gradient(90deg, transparent, transparent 50px, rgba(201,150,58,0.03) 50px, rgba(201,150,58,0.03) 51px);
  pointer-events: none;
}

.lobby-content {
  width: 100%;
  max-width: 860px;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  position: relative;
}

/* Logo */
.logo { text-align: center; }
.logo-pineapple {
  font-size: 64px;
  display: block;
  margin-bottom: 12px;
  animation: sway 3s ease-in-out infinite;
}
@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.logo h1 {
  font-family: 'Cinzel', serif;
  font-size: clamp(32px, 6vw, 56px);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.08em;
  color: var(--cream);
  text-shadow: 0 0 40px rgba(201,150,58,0.4);
}
.logo h1 span {
  color: var(--gold-light);
  text-shadow: 0 0 30px rgba(232,184,75,0.6), 0 0 60px rgba(232,184,75,0.2);
}
.logo-line {
  width: 120px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 16px auto 0;
}

/* Lobby panels */
.lobby-panels {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  max-width: 700px;
}

.panel {
  flex: 1;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(10px);
}

.panel h2 {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  letter-spacing: 0.2em;
  color: var(--gold);
  margin-bottom: 4px;
}

.panel-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  flex-shrink: 0;
  position: relative;
}
.panel-divider::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
}
.panel-divider span {
  background: #0a1a0f;
  padding: 8px 4px;
  font-size: 11px;
  color: var(--cream-dim);
  letter-spacing: 0.1em;
  position: relative;
  z-index: 1;
}

/* Inputs */
input[type="text"] {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--cream);
  font-family: 'Courier Prime', monospace;
  font-size: 14px;
  padding: 10px 14px;
  width: 100%;
  transition: border-color 0.2s;
  outline: none;
}
input[type="text"]:focus { border-color: var(--gold); }
input[type="text"]::placeholder { color: var(--cream-dim); opacity: 0.5; }
input[type="text"]#input-room-code { text-transform: uppercase; letter-spacing: 0.2em; font-size: 18px; text-align: center; }

/* Buttons */
.btn {
  font-family: 'Cinzel', serif;
  font-size: 13px;
  letter-spacing: 0.15em;
  padding: 12px 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 700;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-gold {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-light) 100%);
  color: #1a0e00;
  box-shadow: 0 2px 12px rgba(201,150,58,0.3);
}
.btn-gold:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(201,150,58,0.5);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
}
.btn-outline:hover:not(:disabled) {
  background: rgba(201,150,58,0.1);
}

.btn-small {
  font-family: 'Courier Prime', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--cream-dim);
  border-radius: 4px;
  cursor: pointer;
}
.btn-small:hover { border-color: var(--gold); color: var(--gold); }

.lobby-error {
  color: #e74c3c;
  font-size: 13px;
  min-height: 20px;
  text-align: center;
}

/* ── WAITING ROOM ── */
#screen-waiting {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, #0f3d1f 0%, #060f0a 100%);
}

.waiting-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  max-width: 500px;
  padding: 40px 20px;
}
.waiting-content h2 {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  letter-spacing: 0.15em;
  color: var(--gold);
}

.room-code-display {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.room-code-display p { font-size: 12px; color: var(--cream-dim); letter-spacing: 0.1em; }
.big-code {
  font-family: 'Cinzel', serif;
  font-size: 48px;
  font-weight: 900;
  color: var(--gold-light);
  letter-spacing: 0.3em;
  text-shadow: 0 0 30px rgba(232,184,75,0.5);
}

.player-slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}
.player-slot {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.player-slot.filled { border-color: var(--gold-dim); }
.player-slot .slot-num {
  font-family: 'Cinzel', serif;
  color: var(--gold-dim);
  font-size: 11px;
  width: 20px;
}
.player-slot .slot-name { color: var(--cream); }
.player-slot.empty .slot-name { color: var(--cream-dim); opacity: 0.4; }
.player-slot .you-badge {
  margin-left: auto;
  font-size: 10px;
  background: var(--gold-dim);
  color: #1a0e00;
  padding: 2px 8px;
  border-radius: 2px;
  letter-spacing: 0.05em;
}

.waiting-hint { font-size: 12px; color: var(--cream-dim); letter-spacing: 0.05em; }

/* ── GAME SCREEN ── */
#screen-game {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 120% 80% at 50% 50%, #0f3d1f 0%, #060f0a 80%);
  padding: 0 0 20px;
}
#screen-game.active { display: flex; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 100;
}
.game-logo {
  font-family: 'Cinzel', serif;
  font-size: 14px;
  color: var(--gold);
  letter-spacing: 0.1em;
}
.game-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--cream-dim);
  letter-spacing: 0.05em;
}
#game-round-label { color: var(--cream); font-weight: 700; }
.game-room-code { font-size: 11px; color: var(--cream-dim); letter-spacing: 0.05em; }

/* Opponents */
.opponents-area {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 16px 16px 8px;
  flex-wrap: wrap;
}

.opponent-board {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 260px;
  flex: 1;
  max-width: 380px;
}
.opponent-name {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--gold-dim);
  letter-spacing: 0.15em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.opponent-name .turn-indicator {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  display: none;
  animation: pulse 1s ease-in-out infinite;
}
.opponent-name.their-turn .turn-indicator { display: block; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.3;} }

.opp-rows { display: flex; flex-direction: column; gap: 6px; }
.opp-row { display: flex; align-items: center; gap: 6px; }
.opp-row-label { font-size: 9px; color: var(--cream-dim); width: 26px; letter-spacing: 0.05em; }
.opp-row-cards { display: flex; gap: 4px; }

/* ── CARDS ── */
.card {
  width: 42px;
  height: 60px;
  background: var(--card-bg);
  border-radius: 5px;
  border: 1px solid rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 13px;
  font-weight: 700;
  font-family: 'Courier Prime', monospace;
  cursor: default;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  user-select: none;
  color: var(--black);
  flex-shrink: 0;
}
.card.red { color: var(--red); }
.card.face-down {
  background: linear-gradient(135deg, #1a4a2a 25%, #0d2e17 25%, #0d2e17 50%, #1a4a2a 50%, #1a4a2a 75%, #0d2e17 75%);
  background-size: 8px 8px;
  border: 2px solid var(--gold-dim);
}
.card-rank { font-size: 15px; line-height: 1; }
.card-suit { font-size: 14px; line-height: 1; }

/* Hand cards (to place) */
.card.in-hand {
  cursor: pointer;
  width: 52px;
  height: 74px;
}
.card.in-hand:hover { transform: translateY(-6px); box-shadow: 0 8px 16px rgba(0,0,0,0.5); }
.card.in-hand.selected {
  transform: translateY(-10px);
  box-shadow: 0 10px 24px rgba(201,150,58,0.5);
  border: 2px solid var(--gold);
}
.card.in-hand.to-discard {
  transform: translateY(-6px);
  opacity: 0.5;
  border: 2px solid var(--red);
  box-shadow: 0 4px 12px rgba(192,57,43,0.4);
}

/* Small cards for opponents */
.opp-card {
  width: 28px;
  height: 40px;
  border-radius: 4px;
  background: var(--card-bg);
  border: 1px solid rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  font-family: 'Courier Prime', monospace;
  color: var(--black);
  flex-shrink: 0;
}
.opp-card.red { color: var(--red); }
.opp-card.face-down {
  background: linear-gradient(135deg, #1a4a2a 25%, #0d2e17 25%, #0d2e17 50%, #1a4a2a 50%, #1a4a2a 75%, #0d2e17 75%);
  background-size: 6px 6px;
  border: 1px solid var(--gold-dim);
}
.opp-card.empty {
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(201,150,58,0.2);
}

/* My board */
.my-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  gap: 12px;
}

.my-label {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: var(--gold);
  letter-spacing: 0.2em;
  padding: 8px 0 4px;
  border-top: 1px solid var(--border);
}

.my-board {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.row-label {
  font-size: 10px;
  color: var(--cream-dim);
  letter-spacing: 0.08em;
  width: 52px;
  flex-shrink: 0;
  font-family: 'Cinzel', serif;
}
.row-sub { display: block; font-size: 8px; color: var(--cream-dim); opacity: 0.6; }

.row-slots {
  display: flex;
  gap: 6px;
  flex: 1;
}

.slot {
  width: 48px;
  height: 68px;
  border-radius: 5px;
  border: 1.5px dashed rgba(201,150,58,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  flex-shrink: 0;
}
.slot:hover:not(.filled) {
  border-color: var(--gold);
  background: rgba(201,150,58,0.05);
}
.slot.highlight {
  border-color: var(--gold-light);
  background: rgba(201,150,58,0.08);
  animation: highlight-pulse 1s ease-in-out infinite;
}
@keyframes highlight-pulse {
  0%,100% { border-color: var(--gold-light); }
  50% { border-color: var(--gold-dim); }
}
.slot.filled { border-style: solid; border-color: transparent; cursor: default; padding: 0; }
.slot.filled .card { width: 100%; height: 100%; border-radius: 4px; }

.row-hand-name {
  font-size: 10px;
  color: var(--gold-dim);
  letter-spacing: 0.05em;
  width: 90px;
  flex-shrink: 0;
  text-align: right;
  font-style: italic;
}

/* Hand area */
.hand-area {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 120px;
}

.hand-label {
  font-size: 11px;
  color: var(--cream-dim);
  letter-spacing: 0.05em;
}

.hand-cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── SCORE SCREEN ── */
#screen-score {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, #0f3d1f 0%, #060f0a 100%);
}

.score-content {
  width: 100%;
  max-width: 680px;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}
.score-content h2 {
  font-family: 'Cinzel', serif;
  font-size: 24px;
  letter-spacing: 0.15em;
  color: var(--gold);
}

.score-table {
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  border-bottom: 1px solid var(--border);
}
.score-row:last-child { border-bottom: none; }
.score-row.header {
  background: rgba(201,150,58,0.1);
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--gold);
}
.score-cell {
  padding: 12px 16px;
  font-size: 13px;
  border-right: 1px solid var(--border);
  text-align: center;
}
.score-cell:first-child { text-align: left; }
.score-cell:last-child { border-right: none; }
.score-cell.winner { color: var(--gold-light); font-weight: 700; }
.score-cell.foul { color: var(--red); font-style: italic; }
.score-row.total-row { background: rgba(201,150,58,0.05); font-weight: 700; }

.foul-notice {
  font-size: 11px;
  color: var(--red);
  font-style: italic;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(10,30,16,0.95);
  border: 1px solid var(--gold-dim);
  border-radius: 6px;
  padding: 12px 24px;
  font-size: 13px;
  color: var(--cream);
  letter-spacing: 0.05em;
  z-index: 999;
  transition: transform 0.3s ease;
  backdrop-filter: blur(8px);
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── FOUL OVERLAY ── */
.foul-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(192,57,43,0.9);
  color: white;
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 0.15em;
  padding: 3px 8px;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

/* ── TURN OVERLAY ── */
.waiting-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.0);
  pointer-events: none;
  z-index: 50;
  transition: background 0.3s;
}
.waiting-overlay.blocking {
  pointer-events: all;
}

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
  .lobby-panels { flex-direction: column; }
  .panel-divider { width: 100%; height: 40px; flex-direction: row; }
  .panel-divider::before { top: 50%; bottom: auto; left: 0; right: 0; width: auto; height: 1px; }
  .opponents-area { flex-direction: column; align-items: stretch; }
  .board-row { padding: 8px 10px; gap: 8px; }
  .slot { width: 42px; height: 60px; }
  .row-label { width: 40px; font-size: 9px; }
  .row-hand-name { width: 70px; font-size: 9px; }
  .card.in-hand { width: 46px; height: 66px; }
}

/* ── ANIMATIONS ── */
@keyframes deal-in {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.card.deal-anim { animation: deal-in 0.3s ease forwards; }

@keyframes place-anim {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.card.place-anim { animation: place-anim 0.2s ease forwards; }
