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

:root {
  --bg-dark: #0a0f0d;
  --bg-felt: #145a32;
  --bg-felt-light: #1e7a46;
  --bg-card: #1a1f2e;
  --bg-surface: #141923;
  --bg-surface-2: #1c2333;
  --accent: #d4af37;
  --accent-glow: rgba(212, 175, 55, 0.3);
  --text: #e8e6e3;
  --text-muted: #8b919a;
  --text-dim: #5a6070;
  --red: #e74c3c;
  --green: #27ae60;
  --blue: #3498db;
  --white: #ffffff;
  --card-red: #dc3545;
  --card-black: #1a1a2e;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text);
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input { font-family: inherit; }

.screen { display: none; height: 100vh; width: 100vw; position: absolute; top: 0; left: 0; }
.screen.active { display: flex; }

.hidden { display: none !important; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 24px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; transition: all var(--transition);
  letter-spacing: 0.3px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #c9a227);
  color: #1a1a1a; box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-outline {
  background: transparent; border: 1.5px solid var(--text-muted); color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--text); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 40px; font-size: 16px; }

/* ─── Auth Screen ─────────────────────────────────────────────────────────── */
#auth-screen {
  justify-content: center; align-items: center;
  background: radial-gradient(ellipse at center, #0f1a14 0%, var(--bg-dark) 70%);
}
.auth-container {
  width: 380px; padding: 40px; border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: var(--shadow);
}
.logo { text-align: center; margin-bottom: 32px; }
.logo-icon {
  font-size: 48px; color: var(--accent);
  display: block; margin-bottom: 8px;
  text-shadow: 0 0 20px var(--accent-glow);
}
.logo h1 { font-family: var(--font-display); font-size: 36px; color: var(--white); letter-spacing: 1px; }
.tagline { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; background: var(--bg-surface-2); border-radius: var(--radius-sm); padding: 3px; }
.tab-btn {
  flex: 1; padding: 10px; border: none; background: transparent;
  color: var(--text-muted); font-size: 13px; font-weight: 600;
  border-radius: 6px; transition: all var(--transition);
}
.tab-btn.active { background: var(--bg-surface); color: var(--white); box-shadow: var(--shadow-sm); }

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.input-group input {
  padding: 12px 14px; border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm); background: var(--bg-surface-2);
  color: var(--text); font-size: 14px; transition: border-color var(--transition);
  outline: none;
}
.input-group input:focus { border-color: var(--accent); }
.error-msg { color: var(--red); font-size: 13px; text-align: center; margin-top: 12px; min-height: 20px; }

/* ─── Lobby Screen ────────────────────────────────────────────────────────── */
#lobby-screen { flex-direction: column; background: var(--bg-dark); }
.lobby-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; border-bottom: 1px solid rgba(255,255,255,0.06);
  background: var(--bg-surface); flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.logo-sm { font-family: var(--font-display); font-size: 18px; color: var(--accent); font-weight: 700; }
.user-badge {
  background: var(--bg-surface-2); padding: 6px 14px; border-radius: 20px;
  font-size: 13px; font-weight: 500; color: var(--text);
}

.lobby-content { flex: 1; padding: 32px; overflow-y: auto; max-width: 900px; margin: 0 auto; width: 100%; }
.lobby-actions { margin-bottom: 24px; }
.lobby-actions h2 { font-family: var(--font-display); font-size: 24px; margin-bottom: 16px; color: var(--white); }
.create-room-row { display: flex; gap: 10px; }
.create-room-row input {
  flex: 1; padding: 12px 14px; border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm); background: var(--bg-surface-2);
  color: var(--text); font-size: 14px; outline: none;
}
.create-room-row input:focus { border-color: var(--accent); }

.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.room-card {
  background: var(--bg-surface); border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius); padding: 20px; transition: all var(--transition);
  cursor: pointer;
}
.room-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.3); }
.room-card-name { font-size: 16px; font-weight: 600; color: var(--white); margin-bottom: 8px; }
.room-card-info { display: flex; justify-content: space-between; align-items: center; }
.room-card-host { font-size: 12px; color: var(--text-muted); }
.room-card-count {
  font-size: 12px; font-weight: 600; padding: 4px 10px;
  border-radius: 12px; background: var(--bg-surface-2);
}
.room-card-count.full { color: var(--red); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; opacity: 0.3; }

/* ─── Room Screen ─────────────────────────────────────────────────────────── */
#room-screen { flex-direction: column; background: var(--bg-dark); }
.room-content { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 32px; padding: 32px; }
.room-content h2 { font-family: var(--font-display); font-size: 28px; color: var(--white); }

.player-slots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; width: 100%; max-width: 480px; }
.player-slot {
  background: var(--bg-surface); border: 2px dashed rgba(255,255,255,0.1);
  border-radius: var(--radius); overflow: hidden; transition: all var(--transition);
}
.player-slot.filled { border-style: solid; border-color: var(--accent); }
.slot-inner { display: flex; align-items: center; gap: 12px; padding: 20px; }
.slot-icon { font-size: 28px; opacity: 0.3; }
.player-slot.filled .slot-icon { opacity: 1; color: var(--accent); }
.slot-name { font-size: 15px; font-weight: 500; color: var(--text-muted); }
.player-slot.filled .slot-name { color: var(--white); font-weight: 600; }

.status-msg { color: var(--text-muted); font-size: 14px; }

/* ─── Game Screen ─────────────────────────────────────────────────────────── */
#game-screen {
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 40%, var(--bg-felt-light) 0%, var(--bg-felt) 40%, #0d3b1a 80%, #081f0f 100%);
}

.game-topbar {
  display: flex; justify-content: center; align-items: center;
  padding: 10px 20px; background: rgba(0,0,0,0.4);
  backdrop-filter: blur(10px); flex-shrink: 0; z-index: 10;
  position: relative;
}
.game-info { display: flex; gap: 16px; align-items: center; font-size: 13px; font-weight: 600; }
.game-info span {
  padding: 4px 12px; border-radius: 6px;
  background: rgba(255,255,255,0.08);
}
.truf-badge { font-weight: 700; }
.truf-badge.suit-spades, .truf-badge.suit-clubs { color: #c8d6e5; }
.truf-badge.suit-hearts, .truf-badge.suit-diamonds { color: #ff6b6b; }
.mode-badge { color: var(--accent); }

.scoreboard-btn {
  position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12);
  color: var(--text); padding: 5px 14px; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.scoreboard-btn:hover { background: rgba(255,255,255,0.14); border-color: var(--accent); color: var(--accent); }

.scoreboard-modal { max-width: 640px; min-width: 500px; max-height: 80vh; overflow-y: auto; }
.scoreboard-full { width: 100%; border-collapse: collapse; margin: 8px 0; }
.scoreboard-full th, .scoreboard-full td {
  padding: 8px 10px; text-align: center; font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.scoreboard-full th {
  color: var(--text-muted); font-weight: 600; text-transform: uppercase;
  font-size: 10px; letter-spacing: 0.5px;
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.scoreboard-full td { color: var(--text); }
.scoreboard-full .round-header { color: var(--accent); font-weight: 700; }
.scoreboard-full .player-col { text-align: left; font-weight: 600; color: var(--white); }

/* ─── Game Table Layout ───────────────────────────────────────────────────── */
.game-table {
  flex: 1; position: relative; display: flex;
  align-items: center; justify-content: center;
  min-height: 0;
}

.seat {
  position: absolute; display: flex; flex-direction: column; align-items: center;
  gap: 6px; z-index: 5;
}
.seat-top { top: 8px; left: 50%; transform: translateX(-50%); }
.seat-left { left: 16px; top: 50%; transform: translateY(-50%); }
.seat-right { right: 16px; top: 50%; transform: translateY(-50%); }
.seat-bottom { bottom: 8px; left: 50%; transform: translateX(-50%); }

.seat-info {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px);
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.08);
  min-width: 100px; text-align: center;
}
.seat.active-turn .seat-info {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}
.seat-name { font-size: 13px; font-weight: 700; color: var(--white); }
.seat-target { font-size: 11px; color: var(--text-muted); }
.seat-wins { font-size: 11px; color: var(--accent); }
.seat-score { font-size: 11px; color: var(--text-muted); }

.seat-cards { display: flex; gap: 2px; }
.card-back {
  width: 30px; height: 42px; border-radius: 4px;
  background: linear-gradient(135deg, #1a3a5c, #0d2240);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow-sm);
}
.seat-left .seat-cards { flex-direction: column; }
.seat-left .card-back { width: 36px; height: 20px; }

.seat-right .seat-cards { flex-direction: column; }
.seat-right .card-back { width: 36px; height: 20px; }

/* ─── Center / Trick Area ─────────────────────────────────────────────────── */
.table-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 240px; height: 180px;
  z-index: 6;
}
.trick-area {
  position: relative; width: 100%; height: 100%;
}
.trick-card {
  position: absolute; transition: all 0.3s ease;
}
.trick-card[data-pos="top"] { top: 0; left: 50%; transform: translateX(-50%); }
.trick-card[data-pos="bottom"] { bottom: 0; left: 50%; transform: translateX(-50%); }
.trick-card[data-pos="left"] { left: 0; top: 50%; transform: translateY(-50%); }
.trick-card[data-pos="right"] { right: 0; top: 50%; transform: translateY(-50%); }

.announcement {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  padding: 12px 24px; border-radius: var(--radius);
  background: rgba(0,0,0,0.8); backdrop-filter: blur(8px);
  font-size: 15px; font-weight: 700; text-align: center;
  border: 1px solid var(--accent); color: var(--accent);
  animation: fadeIn 0.3s ease;
  z-index: 20; white-space: nowrap;
}

@keyframes fadeIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }

/* ─── Card Styling ────────────────────────────────────────────────────────── */
.card {
  width: 64px; height: 90px; border-radius: 6px;
  background: var(--white); color: var(--card-black);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: 1px solid rgba(0,0,0,0.1);
  user-select: none; flex-shrink: 0;
}
.card.red { color: var(--card-red); }
.card .card-rank { font-size: 16px; line-height: 1; }
.card .card-suit { font-size: 22px; line-height: 1; }
.card .card-corner {
  position: absolute; top: 4px; left: 5px;
  font-size: 9px; line-height: 1.1; text-align: center;
}
.card .card-corner-br {
  position: absolute; bottom: 4px; right: 5px;
  font-size: 9px; line-height: 1.1; text-align: center;
  transform: rotate(180deg);
}

.card-sm { width: 48px; height: 67px; }
.card-sm .card-rank { font-size: 12px; }
.card-sm .card-suit { font-size: 16px; }
.card-sm .card-corner, .card-sm .card-corner-br { font-size: 7px; }

.card-facedown {
  width: 48px; height: 67px; border-radius: 5px;
  background: linear-gradient(135deg, #1a3a5c 0%, #0d2240 100%);
  border: 1.5px solid rgba(255,255,255,0.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  position: relative; overflow: hidden;
}
.card-facedown::after {
  content: ''; position: absolute; inset: 3px; border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.08);
  background: repeating-linear-gradient(
    45deg, transparent, transparent 3px,
    rgba(255,255,255,0.03) 3px, rgba(255,255,255,0.03) 6px
  );
}

/* ─── My Hand ─────────────────────────────────────────────────────────────── */
.my-hand {
  display: flex; justify-content: center; align-items: flex-end;
  padding: 8px 16px 16px; gap: 0; flex-shrink: 0;
  min-height: 120px; z-index: 110;
  position: relative;
}
.my-hand .card {
  transition: all 0.15s ease; cursor: pointer;
  margin-left: -12px;
}
.my-hand .card:first-child { margin-left: 0; }
.my-hand .card:hover { transform: translateY(-14px); z-index: 2; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.my-hand .card.selected {
  transform: translateY(-20px);
  box-shadow: 0 0 0 2px var(--accent), 0 4px 20px var(--accent-glow);
  z-index: 3;
}
.my-hand .card.playable { cursor: pointer; }
.my-hand .card.not-playable {
  filter: brightness(0.45) saturate(0.3);
  cursor: not-allowed;
  transform: translateY(4px);
}
.my-hand .card.not-playable:hover {
  transform: translateY(4px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ─── Overlays ────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; animation: fadeIn 0.2s ease;
}
.overlay.overlay-passthrough {
  background: none; backdrop-filter: none;
  pointer-events: none; align-items: flex-start; padding-top: 10vh;
}
.overlay.overlay-passthrough .overlay-card {
  pointer-events: auto;
}
.overlay-card {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  padding: 32px; min-width: 320px; max-width: 480px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow); text-align: center;
}
.overlay-card h3 { font-family: var(--font-display); font-size: 22px; margin-bottom: 12px; color: var(--white); }
.overlay-card p { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
.overlay-wide { min-width: 420px; max-width: 560px; }

.declare-hint { font-size: 13px; color: var(--text-muted); }
.selected-cards-display { display: flex; justify-content: center; gap: 12px; margin: 16px 0; min-height: 90px; align-items: center; }
.mode-selector { display: flex; gap: 10px; justify-content: center; margin-bottom: 12px; }
.mode-btn { min-width: 100px; }
.mode-btn.active { background: var(--accent); color: #1a1a1a; }
.target-preview { font-size: 18px; font-weight: 700; color: var(--accent); margin-bottom: 16px; min-height: 28px; }

.main-select-btns { display: flex; gap: 12px; justify-content: center; }
.main-select-btns .btn { min-width: 140px; }

/* ─── Score Table ─────────────────────────────────────────────────────────── */
.score-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.score-table th, .score-table td {
  padding: 10px 14px; text-align: center; font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.score-table th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.score-table td { color: var(--text); }
.score-positive { color: var(--green) !important; font-weight: 700; }
.score-negative { color: var(--red) !important; font-weight: 700; }

.winner-display {
  font-size: 20px; font-weight: 800; color: var(--accent);
  margin-bottom: 16px; padding: 16px;
  background: rgba(212, 175, 55, 0.1); border-radius: var(--radius);
}

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; border-radius: var(--radius-sm);
  background: var(--bg-surface); border: 1px solid rgba(255,255,255,0.08);
  color: var(--text); font-size: 13px; box-shadow: var(--shadow);
  animation: slideIn 0.3s ease; max-width: 320px;
}
.toast.error { border-color: var(--red); color: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
