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

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --surface-border: #1e1e2e;
  --text: #e8e8f0;
  --text-dim: #7a7a90;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --red: #ff3b3b;
  --red-glow: rgba(255, 59, 59, 0.5);
  --green: #00e676;
  --green-glow: rgba(0, 230, 118, 0.5);
  --gold: #d4af37;
  --gold-light: #f5e6a3;
  --gold-glow: rgba(212, 175, 55, 0.5);
  --felt: #0d6b3a;
  --felt-dark: #0a4a28;
  --felt-light: #11854a;
  --rail: #3a2210;
  --rail-dark: #241508;
  --card-white: #f8f6f0;
  --card-red: #c0392b;
  --card-black: #1a1a2e;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ====================== SCREENS ====================== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ====================== LOGO ====================== */
.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 4px;
  color: var(--text);
}

.logo span {
  background: linear-gradient(135deg, var(--gold), var(--gold-light), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 32px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 0.75rem;
}

/* ====================== UI CARD (lobby/home panels) ====================== */
.ui-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  text-align: center;
  font-family: inherit;
}

input[type="text"]:focus {
  border-color: var(--gold);
}

input[type="text"]::placeholder {
  color: var(--text-dim);
}

.btn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  font-family: inherit;
}

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

.btn-primary {
  background: linear-gradient(180deg, var(--gold), #b8962e);
  color: #1a1a1a;
  font-weight: 700;
}

.btn-primary:hover {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
}

.btn-secondary {
  background: var(--surface-border);
  color: var(--text);
}

.btn-secondary:hover {
  background: #2a2a3e;
}

.divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface-border);
}

.divider span {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.error-msg {
  color: var(--red);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin-top: 8px;
  text-align: center;
}

/* ====================== LOBBY ====================== */
.room-code-display {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 8px;
  font-family: 'Courier New', monospace;
  color: var(--gold);
  padding: 12px 16px;
  border-radius: 8px;
  transition: background 0.15s, transform 0.1s;
}

.tap-to-copy-hint {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.copyable { cursor: pointer; }
.copyable:hover { background: rgba(212, 175, 55, 0.1); }
.copyable:active { transform: scale(0.97); }
.copyable.copied { background: rgba(0, 230, 118, 0.1); }

.share-link {
  font-size: 0.75rem;
  color: var(--text-dim);
  word-break: break-all;
  text-align: center;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 6px;
  width: 100%;
}

.copy-feedback {
  font-size: 0.8rem;
  color: var(--green);
  min-height: 1.2em;
}

.label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lobby-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--surface-border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.subtle-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  min-height: 1.2em;
  text-align: center;
}

/* ====================== GAME SCREEN ====================== */
#screen-game {
  flex-direction: column;
}

#screen-game.active {
  justify-content: flex-start;
}

.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid rgba(212, 175, 55, 0.15);
  flex-shrink: 0;
  z-index: 10;
}

.player-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 80px;
}

.player-score .player-name {
  font-size: 0.8rem;
  color: var(--gold);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.player-score .score {
  font-size: 2rem;
  font-weight: 800;
  font-family: 'Playfair Display', Georgia, serif;
}

.round-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#game-round-label {
  font-size: 1rem;
  font-weight: 600;
}

.best-of {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ====================== CARD TABLE ====================== */
.card-table {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.felt-surface {
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt-light) 0%, var(--felt) 40%, var(--felt-dark) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 16px;
  border-top: 4px solid var(--rail);
}

.table-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, transparent 30%, rgba(0,0,0,0.5) 100%);
  pointer-events: none;
  z-index: 1;
}

/* ====================== TABLE LAYOUT: deck | pile | deck ====================== */
.table-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
  position: relative;
  width: 100%;
  padding: 0 12px;
}

/* Player face-down decks on each side */
.player-deck {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.deck-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: rgba(255,255,255,0.5);
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  min-height: 1em;
  text-align: center;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-stack {
  position: relative;
  width: 80px;
  height: 112px;
}

.deck-card {
  position: absolute;
  width: 80px;
  height: 112px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 6px,
      rgba(212,175,55,0.06) 6px,
      rgba(212,175,55,0.06) 12px
    ),
    linear-gradient(135deg, #1a1a5e, #2d2d7a);
  border: 2px solid rgba(212,175,55,0.25);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.deck-card::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(212,175,55,0.15);
  border-radius: 5px;
}

.deck-card:nth-child(1) { top: 0; left: 0; }
.deck-card:nth-child(2) { top: -2px; left: 1px; }
.deck-card:nth-child(3) { top: -4px; left: 2px; }

/* Deck gets thinner as cards are dealt */
.player-deck.thinned .deck-card:nth-child(3) { display: none; }
.player-deck.empty .deck-card:nth-child(2),
.player-deck.empty .deck-card:nth-child(3) { display: none; }

/* Central pile — the snap target */
.center-pile-area {
  position: relative;
  width: 150px;
  height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.pile {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ====================== PLAYING CARDS ====================== */
.playing-card {
  position: absolute;
  width: 120px;
  height: 168px;
  border-radius: 10px;
  transform-style: preserve-3d;
  perspective: 800px;
  left: 50%;
  top: 50%;
  margin-left: -60px;
  margin-top: -84px;
  pointer-events: none;
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  overflow: hidden;
}

.card-front {
  background: var(--card-white);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 0 0 1px rgba(0,0,0,0.05);
}

.card-back {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 6px,
      rgba(212,175,55,0.08) 6px,
      rgba(212,175,55,0.08) 12px
    ),
    linear-gradient(135deg, #1a1a6e, #2d2d8a);
  border: 3px solid rgba(212,175,55,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.card-back::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(212,175,55,0.2);
  border-radius: 6px;
}

/* Card content */
.card-corner {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 1px;
}

.card-corner.top-left {
  align-self: flex-start;
}

.card-corner.bottom-right {
  align-self: flex-end;
  transform: rotate(180deg);
}

.card-rank {
  font-size: 1.1rem;
  font-weight: 800;
}

.card-suit {
  font-size: 0.8rem;
}

.card-center-suit {
  font-size: 2.8rem;
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

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

/* Card dealing: from left deck into center pile */
.playing-card.deal-from-left {
  animation: dealFromLeft 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes dealFromLeft {
  0% {
    transform: translate3d(-140px, 10px, 0) rotateY(180deg) rotateZ(-8deg) scale(0.75);
    opacity: 0.4;
  }
  35% {
    opacity: 1;
  }
  55% {
    transform: translate3d(-20px, -10px, 20px) rotateY(50deg) rotateZ(3deg) scale(1.03);
  }
  100% {
    transform: translate3d(var(--pile-x, 0px), var(--pile-y, 0px), 0) rotateY(0deg) rotateZ(var(--pile-rot, 0deg)) scale(1);
  }
}

/* Card dealing: from right deck into center pile */
.playing-card.deal-from-right {
  animation: dealFromRight 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes dealFromRight {
  0% {
    transform: translate3d(140px, 10px, 0) rotateY(-180deg) rotateZ(8deg) scale(0.75);
    opacity: 0.4;
  }
  35% {
    opacity: 1;
  }
  55% {
    transform: translate3d(20px, -10px, 20px) rotateY(-50deg) rotateZ(-3deg) scale(1.03);
  }
  100% {
    transform: translate3d(var(--pile-x, 0px), var(--pile-y, 0px), 0) rotateY(0deg) rotateZ(var(--pile-rot, 0deg)) scale(1);
  }
}

/* Match glow */
.playing-card.match-glow {
  z-index: 100 !important;
}

.playing-card.match-glow .card-front {
  box-shadow:
    0 0 20px var(--gold-glow),
    0 0 40px var(--gold-glow),
    inset 0 0 0 2px var(--gold);
}

/* Shake on false snap */
.table-layout.shake {
  animation: shakeCards 0.4s ease-out;
}

@keyframes shakeCards {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

/* Slap effect — centered in the pile area */
.slap-effect {
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  left: 50%;
  top: 50%;
  margin-left: -90px;
  margin-top: -90px;
}

.slap-effect.active {
  animation: slapImpact 0.35s ease-out forwards;
}

@keyframes slapImpact {
  0% {
    transform: scale(0.3);
    opacity: 1;
    background: radial-gradient(circle, rgba(212,175,55,0.5) 0%, transparent 70%);
  }
  100% {
    transform: scale(2);
    opacity: 0;
    background: radial-gradient(circle, rgba(212,175,55,0.1) 0%, transparent 70%);
  }
}

/* Scatter cards on round end */
.playing-card.scatter {
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.6s ease;
}

/* Win particles */
.win-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 60;
  animation: particleBurst 0.8s ease-out forwards;
}

@keyframes particleBurst {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--px, 50px), var(--py, -80px)) scale(0);
    opacity: 0;
  }
}

/* ====================== GAME MESSAGE ====================== */
.game-message {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  min-height: 1.5em;
  z-index: 10;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  position: relative;
}

.game-message.false-start {
  color: var(--red);
}

.game-message.win {
  color: var(--gold);
}

.tap-hint {
  color: rgba(255,255,255,0.5);
  font-size: 0.85rem;
  text-align: center;
  padding: 16px;
  flex-shrink: 0;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid rgba(212,175,55,0.1);
  z-index: 10;
}

.tap-hint strong {
  color: var(--gold);
}

/* ====================== RESULTS ====================== */
.results-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.results-title.win {
  background: linear-gradient(135deg, var(--gold), var(--gold-light), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.results-title.lose {
  color: var(--red);
}

.results-title.draw {
  color: var(--text-dim);
}

.final-scores {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 16px 0 24px;
}

.final-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.final-name {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.final-score {
  font-size: 3rem;
  font-weight: 800;
  font-family: 'Playfair Display', Georgia, serif;
}

.vs {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 600;
}

/* ====================== RESPONSIVE ====================== */
@media (max-width: 480px) {
  .logo { font-size: 2.4rem; }
  .room-code-display { font-size: 2rem; letter-spacing: 6px; }
  .table-layout { gap: 10px; padding: 0 8px; }
  .playing-card {
    width: 100px;
    height: 140px;
    margin-left: -50px;
    margin-top: -70px;
  }
  .card-center-suit { font-size: 2.2rem; }
  .card-rank { font-size: 0.95rem; }
  .card-suit { font-size: 0.7rem; }
  .center-pile-area { width: 130px; height: 180px; }
  .deck-stack, .deck-card { width: 65px; height: 91px; }
}

@media (max-height: 600px) {
  .game-header { padding: 8px 16px; }
  .player-score .score { font-size: 1.6rem; }
  .table-layout { gap: 8px; }
  .playing-card {
    width: 85px;
    height: 119px;
    margin-left: -42px;
    margin-top: -60px;
  }
  .card-center-suit { font-size: 1.8rem; }
  .card-rank { font-size: 0.85rem; }
  .center-pile-area { width: 110px; height: 150px; }
  .deck-stack, .deck-card { width: 55px; height: 77px; }
}
