:root {
  color-scheme: dark;
  --bg: #0a0e1a;
  --felt: #1b5e20;
  --felt-light: #2e7d32;
  --card-bg: #1a2236;
  --ink: #f8faff;
  --accent: #a855f7;
  --good: #4ade80;
  --warn: #fb923c;
  --hot-pink: #ec4899;
  --cyan: #22d3ee;
  --gold: #fbbf24;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

h1 {
  margin-bottom: 0.25rem;
  background: linear-gradient(90deg, var(--gold), var(--hot-pink), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 2rem;
}

.subtitle { margin-top: 0; opacity: 0.7; font-size: 0.9rem; }

.controls {
  background: rgba(30, 40, 70, 0.7);
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: 12px;
  padding: 0.9rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(8px);
}

input {
  width: min(100%, 420px);
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.5);
  background: rgba(20, 24, 40, 0.8);
  color: var(--ink);
  margin-right: 0.5rem;
}

select {
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(168, 85, 247, 0.5);
  background: rgba(20, 24, 40, 0.8);
  color: var(--ink);
  margin-right: 0.5rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  background: linear-gradient(135deg, var(--accent), var(--hot-pink));
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

button:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
}

button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Table Layout ── */
.table-layout {
  display: grid;
  grid-template-areas:
    "top top top"
    "left table right"
    "bottom bottom bottom";
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 0.75rem;
  min-height: 70vh;
}

/* ── Center Table (felt) ── */
.table-center {
  grid-area: table;
  background: radial-gradient(ellipse at center, var(--felt-light), var(--felt), #0d3b12);
  border: 4px solid #4a2c00;
  border-radius: 50%;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  box-shadow:
    inset 0 0 40px rgba(0,0,0,0.4),
    0 0 30px rgba(27, 94, 32, 0.3);
  min-height: 300px;
  aspect-ratio: 1;
  margin: auto;
  max-width: 340px;
  width: 100%;
}

.table-center .table-info {
  text-align: center;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.table-center .table-info p { margin: 0.2rem 0; }

.table-center .discard-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.table-center .draw-pile {
  width: 60px;
  height: 90px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1a237e, #283593);
  border: 2px solid #5c6bc0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #aaa;
  box-shadow: 2px 3px 8px rgba(0,0,0,0.5);
  text-align: center;
}

/* ── Player positions ── */
.player-slot {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.player {
  background: rgba(20, 28, 50, 0.75);
  border: 1px solid rgba(100, 116, 180, 0.3);
  border-radius: 14px;
  padding: 0.75rem;
  backdrop-filter: blur(6px);
  width: 100%;
}

.player h3 {
  margin: 0 0 0.4rem 0;
  font-size: 0.9rem;
  color: var(--cyan);
}

.player.active {
  border-color: var(--good);
  box-shadow:
    0 0 12px rgba(74, 222, 128, 0.3),
    inset 0 0 12px rgba(74, 222, 128, 0.05);
}

.player.active h3 {
  color: var(--good);
}

/* Active player layout: hand + buttons side by side */
.player.active .player-body {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.player-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 130px;
  padding-top: 0.25rem;
}

.player-actions button {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
}

.player-actions select {
  width: 100%;
  font-size: 0.8rem;
  padding: 0.35rem;
}

.hand {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

/* Opponent (side) hands render smaller */
.player-slot.left .hand,
.player-slot.right .hand {
  flex-direction: column;
}

/* ── Card styling ── */
.card {
  width: 56px;
  height: 84px;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  border: 2px solid #ddd;
  background: #fff;
  color: #111;
  box-shadow: 1px 2px 6px rgba(0,0,0,0.3);
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
}

.card .card-rank {
  font-size: 1rem;
  line-height: 1;
}

.card .card-suit {
  font-size: 1.2rem;
  line-height: 1;
  margin-top: 2px;
}

/* Suit colors — vivid */
.card.suit-hearts,
.card.suit-diamonds {
  color: #e91e63;
  border-color: #f06292;
}

.card.suit-spades,
.card.suit-clubs {
  color: #1a1a2e;
  border-color: #555;
}

.card.suit-joker {
  color: #9c27b0;
  border-color: #ce93d8;
  background: linear-gradient(135deg, #fffde7, #f3e5f5);
}

/* Hover / clickable cards */
button.card {
  cursor: pointer;
}

button.card:hover {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 2px 8px 16px rgba(0,0,0,0.4);
  border-color: var(--gold);
}

/* Hidden (opponent) cards */
.card.hidden {
  width: 48px;
  height: 72px;
  color: #fff;
  background: linear-gradient(135deg, #1a237e, #311b92);
  border-color: #5c6bc0;
  font-size: 1.3rem;
}

/* Selected card */
.card.selected {
  outline: 3px solid var(--good);
  outline-offset: 2px;
  transform: translateY(-10px) scale(1.05);
  background: #e8f5e9;
  box-shadow: 0 6px 20px rgba(74, 222, 128, 0.5);
}

.card.selected.suit-hearts,
.card.selected.suit-diamonds {
  background: #fce4ec;
}

.card.selected.suit-joker {
  background: #f3e5f5;
}

/* Top card on table */
.top-card-display {
  display: inline-flex;
  vertical-align: middle;
}

.top-card-display .card {
  width: 60px;
  height: 90px;
  font-size: 0.85rem;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.5);
}

.top-card-display .card .card-suit {
  font-size: 1.3rem;
}

.warning { color: var(--warn); font-weight: 600; }
.winner { color: var(--gold); font-weight: 700; text-shadow: 0 0 10px rgba(251, 191, 36, 0.5); }
.meta { opacity: 0.7; margin-bottom: 0; font-size: 0.8rem; }

/* ── Screen Cards (Auth / Lobby / Room) ── */
.screen-card {
  background: rgba(30, 40, 70, 0.7);
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 440px;
  margin: 1.5rem auto;
  backdrop-filter: blur(10px);
  text-align: center;
}

.screen-card h2 {
  margin-top: 0;
  color: var(--cyan);
}

.screen-card label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  opacity: 0.8;
}

.screen-card input {
  width: 100%;
  margin-bottom: 0.75rem;
}

.screen-card button {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

.greeting {
  font-size: 0.95rem;
  opacity: 0.8;
  margin-bottom: 1rem;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.divider {
  font-size: 0.8rem;
  opacity: 0.5;
  margin: 0.3rem 0;
}

.error-msg {
  color: var(--warn);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* Room code display */
.room-code {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  background: linear-gradient(90deg, var(--gold), var(--hot-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 0.5rem 0;
  user-select: all;
}

.hint {
  font-size: 0.8rem;
  opacity: 0.6;
  margin-top: 0;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
}

.player-list li {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: rgba(20, 24, 40, 0.6);
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-secondary {
  background: rgba(60, 70, 110, 0.6);
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.btn-secondary:hover {
  background: rgba(80, 90, 140, 0.6);
}

/* Turn indicator */
.turn-badge {
  display: inline-block;
  background: var(--good);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  margin-left: 0.3rem;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.waiting-indicator {
  font-size: 0.85rem;
  color: var(--gold);
  animation: pulse-badge 1.5s ease-in-out infinite;
  margin-top: 0.5rem;
}

/* Game footer */
.game-footer {
  text-align: center;
  margin-top: 1rem;
}

.game-footer button {
  width: auto;
  font-size: 0.8rem;
  padding: 0.4rem 1rem;
}

/* Toast notifications */
#toastContainer {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: rgba(30, 40, 70, 0.95);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  color: var(--ink);
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
  animation: toast-in 0.3s ease-out;
  max-width: 300px;
}

.toast.toast-exit {
  animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(60px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(60px); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .table-layout {
    grid-template-areas:
      "top"
      "table"
      "bottom";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }
  .player-slot.left,
  .player-slot.right { display: none; }
  .table-center {
    border-radius: 24px;
    aspect-ratio: auto;
    max-width: 100%;
    min-height: 200px;
  }
  .screen-card { margin: 1rem 0.5rem; }
  .room-code { font-size: 1.8rem; }
}
