/* The Mind - Playful & Animated */

:root {
  --bg: #fef7f0;
  --bg-warm: #fff5eb;
  --surface: #ffffff;
  --text: #3d2c29;
  --text-muted: #8b7355;
  --border: #f0ddd0;
  --border-light: #f8ece3;

  /* Warm cozy palette */
  --coral: #ff6b6b;
  --peach: #ffa07a;
  --honey: #ffc078;
  --sage: #8fbc8f;
  --lavender: #b39ddb;
  --sky: #87ceeb;

  /* Functional */
  --accent: #ff6b6b;
  --accent-light: #fff0f0;
  --accent-dark: #e85555;
  --success: #6abf69;
  --success-light: #e8f5e8;
  --danger: #e57373;
  --danger-light: #ffebee;

  --shadow-sm: 0 2px 4px rgba(139, 115, 85, 0.08);
  --shadow: 0 4px 12px rgba(139, 115, 85, 0.12);
  --shadow-lg: 0 8px 24px rgba(139, 115, 85, 0.15);

  /* Animation timing */
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --snap: cubic-bezier(0.5, 0, 0.25, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Nunito", "Quicksand", -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-warm) 100%);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Flash messages */
.flash {
  max-width: 980px;
  margin: 1rem auto 0;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, var(--success-light), #f0fff0);
  border: 2px solid var(--success);
  color: #2d5a2d;
}

.flash.alert {
  background: linear-gradient(135deg, var(--danger-light), #fff5f5);
  border-color: var(--danger);
  color: #8b3a3a;
}

.page {
  max-width: 980px;
  margin: 1.5rem auto 2rem;
  padding: 0 1rem;
}

.page-narrow {
  max-width: 480px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.page-header h1 {
  font-size: 2rem;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, var(--coral), var(--peach), var(--honey), var(--coral));
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradient-shift 4s ease infinite;
}

.page-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

/* Cards */
.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.25rem;
  margin-top: 1rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow);
  border-color: var(--peach);
  transform: translateY(-2px);
}

/* Form fields */
.field { margin-bottom: 1rem; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border-light);
}

.form-actions .button {
  width: 100%;
}

label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  transition: all 0.2s ease;
}

input:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 4px var(--accent-light);
  transform: scale(1.01);
  transition: all 0.2s var(--bounce);
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 2px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  padding: 0.625rem 1.25rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  transition: all 0.2s var(--bounce);
  position: relative;
}

.button:hover {
  background: var(--bg-warm);
  border-color: var(--peach);
  transform: translateY(-3px) scale(1.02);
  box-shadow: var(--shadow);
}

.button:active {
  transform: translateY(0) scale(0.95);
  transition-duration: 0.1s;
}

.button-primary {
  background: linear-gradient(135deg, #e85555, var(--coral));
  border: none;
  color: white;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3), 0 2px 0 #c94545;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.button-primary:hover {
  background: linear-gradient(135deg, var(--coral), var(--peach));
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.45), 0 3px 0 #c94545;
  transform: translateY(-4px) scale(1.03);
  animation: button-wiggle 0.4s var(--bounce);
}

.button-primary:active {
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3), 0 1px 0 #c94545;
  transform: translateY(1px) scale(0.97);
}

@keyframes button-wiggle {
  0%, 100% { transform: translateY(-4px) scale(1.03) rotate(0); }
  25% { transform: translateY(-4px) scale(1.03) rotate(-1deg); }
  75% { transform: translateY(-4px) scale(1.03) rotate(1deg); }
}

.button-ghost {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
}

.button-muted {
  background: linear-gradient(135deg, #fff1d8, #ffe6b8);
  border-color: #f2c66d;
  color: #8a5c00;
}

.button:disabled,
.button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.button:disabled:hover,
.button[disabled]:hover {
  transform: none;
  box-shadow: none;
  background: var(--surface);
  border-color: var(--border);
}

.button-primary:disabled,
.button-primary[disabled] {
  background: var(--border);
  box-shadow: none;
}

.button-primary:disabled:hover,
.button-primary[disabled]:hover {
  background: var(--border);
}

/* Icon buttons */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 2px solid var(--border);
  border-radius: 0.625rem;
  background: var(--surface);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s ease;
}

.icon-button:hover {
  background: var(--bg-warm);
  border-color: var(--peach);
  transform: translateY(-2px) scale(1.1);
  box-shadow: var(--shadow);
}

.icon-button:hover .icon-sound,
.icon-button:hover .icon-music {
  animation: icon-bounce 0.4s var(--bounce);
}

@keyframes icon-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

.icon-button:active {
  transform: scale(0.9);
  transition-duration: 0.1s;
}

.icon-button.muted {
  opacity: 0.4;
  background: var(--bg);
}

.icon-sound, .icon-music {
  color: var(--coral);
  transition: transform 0.2s var(--bounce);
}

/* Room list */
.rooms {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.room-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1rem;
  transition: all 0.25s var(--bounce);
}

.room-row:hover {
  border-color: var(--peach);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px) scale(1.01);
}

.room-row:active {
  transform: translateY(-1px) scale(0.99);
}

.room-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.room-name {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-code {
  font-family: monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--coral);
  background: var(--accent-light);
  padding: 0.2rem 0.5rem;
  border-radius: 0.375rem;
}

.room-lock {
  font-size: 0.75rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.meta { color: var(--text-muted); font-size: 0.875rem; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, var(--sky), #b8e0f0);
  color: #2d6a8a;
  border-radius: 9999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-danger {
  background: linear-gradient(135deg, var(--danger-light), #ffe4e4);
  color: var(--danger);
}

.badge-ready {
  background: linear-gradient(135deg, var(--success-light), #d4edda);
  color: #3d8b3d;
  animation: badge-pop 0.4s var(--bounce);
}

@keyframes badge-pop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.errors {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 0.75rem;
  background: var(--danger-light);
  border: 2px solid var(--danger);
  color: #8b3a3a;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.actions form { margin: 0; }
.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ========== CHAT ========== */
.chat-messages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--peach) transparent;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--peach);
  border-radius: 3px;
}

.chat-message {
  display: flex;
  animation: pop-in 0.25s ease;
}

@keyframes pop-in {
  0% { opacity: 0; transform: translateY(15px) scale(0.9) rotate(-2deg); }
  60% { opacity: 1; transform: translateY(-3px) scale(1.02) rotate(1deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

.chat-bubble {
  width: 100%;
  border: 2px solid var(--border-light);
  border-radius: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-warm);
}

.chat-bubble {
  transition: all 0.2s var(--bounce);
}

.chat-bubble:hover {
  border-color: var(--peach);
  transform: scale(1.01) translateX(2px);
  box-shadow: var(--shadow-sm);
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.chat-meta strong { color: var(--coral); }
.chat-content { font-size: 0.9rem; }

.chat-form-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.chat-form-row input[type="text"] {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.chat-send {
  padding: 0.5rem 0.875rem;
  font-size: 0.8rem;
}

.chat-input-wrap {
  border-top: 2px solid var(--border-light);
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}

.chat-locked { color: var(--text-muted); text-align: center; padding: 1rem; font-size: 0.875rem; }

.chat-new-indicator {
  align-self: center;
  margin: 0.5rem 0;
  background: linear-gradient(135deg, var(--coral), var(--peach));
  color: white;
  border: none;
  border-radius: 9999px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.typing-indicator-shell {
  min-height: 1.75rem;
  margin: 0.35rem 0 0.55rem;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.typing-dots {
  display: inline-flex;
  gap: 0.22rem;
}

.typing-dots span {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 9999px;
  background: var(--peach);
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.14s; }
.typing-dots span:nth-child(3) { animation-delay: 0.28s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0) scale(1); opacity: 0.45; }
  40% { transform: translateY(-5px) scale(1.3); opacity: 1; }
}

/* ========== GAME SHELL ========== */
.game-shell {
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 1rem;
}

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1.25rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.hud-room {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.hud-name {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--coral), var(--peach), var(--honey));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.hud-code {
  font-family: monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--coral);
  background: var(--accent-light);
  padding: 0.25rem 0.625rem;
  border-radius: 0.5rem;
}

.hud-lock {
  font-size: 0.8rem;
}

.hud-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.hud-actions form { margin: 0; }

.hud-audio {
  display: flex;
  gap: 0.375rem;
}

.hud-game-actions {
  display: flex;
  gap: 0.5rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border-light);
}

.hud-nav {
  display: flex;
  gap: 0.5rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border-light);
}

/* Join overlay */
.join-overlay {
  margin-top: 1rem;
  max-width: 360px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.join-header {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 1rem;
  text-align: center;
  background: linear-gradient(135deg, var(--coral), var(--peach));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.join-button {
  width: 100%;
  margin-top: 0.5rem;
}

.join-overlay {
  animation: join-slide-up 0.5s var(--bounce);
}

@keyframes join-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Arena layout */
.arena-layout {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
}

/* Playfield */
.playfield {
  min-width: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Status HUD */
.status-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--bg));
  border-radius: 1rem;
  border: 2px solid var(--border-light);
}

.status-hud span { display: flex; align-items: center; gap: 0.375rem; }
.status-hud strong {
  color: var(--coral);
  font-weight: 800;
}

.status-hud-alert {
  background: linear-gradient(135deg, var(--danger-light), #fff0f0);
  border-color: var(--danger);
  animation: wiggle 0.4s ease;
}

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px) rotate(-1deg); }
  75% { transform: translateX(4px) rotate(1deg); }
}

/* Player strip */
.player-strip {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, var(--lavender), #c9b8e8);
  border: 2px solid #a890d3;
  border-radius: 9999px;
  padding: 0.4rem 0.875rem;
  font-size: 0.875rem;
  color: #4a3a6a;
  transition: all 0.25s var(--bounce);
}

.player-chip:hover {
  transform: translateY(-4px) rotate(-2deg) scale(1.05);
  box-shadow: var(--shadow-lg);
  z-index: 1;
}

.player-name { font-weight: 700; }
.player-cards {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5a4a7a;
  background: rgba(255, 255, 255, 0.5);
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
}

/* Stack field */
.stack-field {
  margin-top: 1.25rem;
  min-height: 110px;
  padding: 1rem;
  background: linear-gradient(135deg, var(--bg-warm), #fff8f0);
  border-radius: 1rem;
  border: 3px dashed var(--border);
  position: relative;
}

.played-stack {
  display: flex;
  gap: 0.625rem;
  overflow-x: auto;
  padding: 0.25rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(to left, transparent 0%, black 4rem, black 100%);
  -webkit-mask-image: linear-gradient(to left, transparent 0%, black 4rem, black 100%);
}

.played-stack::-webkit-scrollbar {
  display: none;
}

/* Stack cards - same size as hand cards for seamless animation */
.stack-card {
  width: 4rem;
  height: 5.5rem;
  border-radius: 0.875rem;
  text-align: center;
  flex-shrink: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.stack-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-6px) rotate(-4deg) scale(1.05);
  border-color: var(--honey);
  z-index: 5;
}

.stack-value {
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text);
}

.stack-meta {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1;
  margin-top: 0.25rem;
}

/* New card from others: animate in with slide */
.stack-card-new {
  animation: card-slide-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Other cards shift right when new card appears */
.stack-card-new ~ .stack-card {
  animation: card-shift-right 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* When YOU are playing: hide new card until flying card is done */
.playing-card .stack-card-new {
  animation: none !important;
  opacity: 0 !important;
  transition: none !important;
}

/* Card revealed after flying card animation - no animation, just visible */
.stack-card-revealed {
  opacity: 1 !important;
  transition: none !important;
}

/* But other cards SHOULD still shift to make room */

@keyframes card-slide-in {
  0% {
    opacity: 0;
    transform: translateY(-20px) rotate(-8deg) scale(0.8);
  }
  60% {
    opacity: 1;
    transform: translateY(3px) rotate(2deg) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) rotate(0) scale(1);
  }
}

@keyframes card-shift-right {
  0% {
    transform: translateX(calc(-4rem - 0.625rem));
  }
  100% {
    transform: translateX(0);
  }
}

.stack-card-mistake {
  background: linear-gradient(135deg, var(--danger-light), #ffe8e8);
  border-color: var(--danger);
}

.stack-card-mistake .stack-value {
  color: var(--danger);
}

.stack-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
  font-size: 0.9rem;
}

/* Activity feed */
.activity-feed {
  margin-bottom: 0.75rem;
  padding: 0.875rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--bg));
  border-radius: 0.875rem;
  border: 2px solid var(--border-light);
}

.activity-header {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  max-height: 130px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.75rem;
  padding: 0.4rem 0.625rem;
  border-radius: 0.5rem;
  background: var(--surface);
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.activity-item:hover {
  background: var(--bg-warm);
}

.activity-perfect {
  border-left-color: var(--sage);
}

.activity-mistake {
  border-left-color: var(--danger);
  background: var(--danger-light);
}

.activity-latest {
  animation: pop-in 0.3s ease;
}

.activity-round {
  flex-shrink: 0;
  font-size: 0.625rem;
  font-weight: 800;
  color: var(--coral);
  background: var(--accent-light);
  padding: 0.15rem 0.4rem;
  border-radius: 0.375rem;
}

.activity-text {
  color: var(--text-muted);
  line-height: 1.4;
  font-weight: 500;
}

.activity-mistake .activity-text {
  color: #8b3a3a;
}

/* Hand section */
.hand-hud {
  margin-top: 1.25rem;
  border-top: 2px solid var(--border-light);
  padding-top: 1rem;
}

.hand-status {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  background: var(--bg-warm);
  border-radius: 0.75rem;
  text-align: center;
}

.hand-status-done {
  background: linear-gradient(135deg, var(--success-light), #e8f5e8);
  color: #3d6b3d;
}

.hand-prompt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--accent-light), #fff8f8);
  border: 2px solid var(--coral);
  border-radius: 0.75rem;
  animation: prompt-pulse 2s ease-in-out infinite;
}

@keyframes prompt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
  50% { box-shadow: 0 0 0 6px rgba(255, 107, 107, 0.15); }
}

.hand-prompt span {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}

/* Hand cards - same size as stack cards */
.hand-card {
  width: 4rem;
  height: 5.5rem;
  border-radius: 0.875rem;
  font-weight: 900;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--honey);
  box-shadow: var(--shadow), 0 4px 0 var(--peach);
  color: var(--text);
  transition: all 0.2s var(--bounce);
}

.hand-card:hover {
  transform: translateY(-12px) rotate(-5deg) scale(1.08);
  box-shadow: var(--shadow-lg), 0 8px 0 var(--peach);
  border-color: var(--coral);
  animation: card-hover-wiggle 0.5s var(--bounce);
  z-index: 10;
}

@keyframes card-hover-wiggle {
  0%, 100% { transform: translateY(-12px) rotate(-5deg) scale(1.08); }
  20% { transform: translateY(-14px) rotate(-7deg) scale(1.08); }
  40% { transform: translateY(-10px) rotate(-3deg) scale(1.08); }
  60% { transform: translateY(-13px) rotate(-6deg) scale(1.08); }
}

.hand-card:active {
  transform: translateY(0) rotate(0) scale(0.95);
  box-shadow: var(--shadow-sm), 0 2px 0 var(--peach);
  transition-duration: 0.08s;
}

/* Locked cards (not the lowest) */
.hand-card-locked {
  cursor: not-allowed;
  opacity: 0.5;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--bg-warm);
}

.hand-card-locked:hover {
  transform: none;
  box-shadow: var(--shadow-sm);
  border-color: var(--border);
}

/* Flying card clone - matches stack card exactly */
.flying-card {
  position: fixed;
  z-index: 1000;
  width: 4rem;
  height: 5.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--honey);
  border-radius: 0.875rem;
  box-shadow: var(--shadow-lg), 0 3px 0 var(--peach);
  transition: all 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  overflow: hidden;
}

.flying-card-value {
  font-weight: 900;
  font-size: 1.5rem;
  line-height: 1;
  animation: flying-value-slide 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.flying-card-meta {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-weight: 600;
  line-height: 1;
  margin-top: 0.25rem;
  animation: flying-meta-appear 0.25s ease 0.15s both;
}

@keyframes flying-value-slide {
  0% { transform: translateY(0.5rem); }
  100% { transform: translateY(0); }
}

@keyframes flying-meta-appear {
  0% { opacity: 0; transform: translateY(3px); }
  100% { opacity: 1; transform: translateY(0); }
}

.flying-card-landed {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.flying-card-hidden {
  opacity: 0;
  transition: opacity 0.1s ease;
}

/* Stack shifts right to make room */
.stack-shifting .stack-card {
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  transform: translateX(calc(4rem + 0.625rem));
}

/* Remaining cards slide left */
.hand-card-slide-left {
  animation: slide-left-fill 0.25s ease 0.1s forwards;
}

@keyframes slide-left-fill {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(-4rem - 0.625rem));
  }
}

/* Radio panel (sidebar) */
.radio-panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  height: min(75vh, 700px);
  min-height: 400px;
  box-shadow: var(--shadow-sm);
}

/* ========== WIN/LOSS STATES ========== */
.status-win {
  background: linear-gradient(135deg, var(--success-light), #e0f5e0);
  border-color: var(--success);
}

.status-loss {
  background: linear-gradient(135deg, var(--danger-light), #ffe8e8);
  border-color: var(--danger);
}

.status-level-complete {
  background: linear-gradient(135deg, #fff0e6, #ffe8d6);
  border-color: var(--honey);
  animation: bounce-subtle 0.5s ease;
}

@keyframes bounce-subtle {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* Level complete banner */
.level-complete-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.95), rgba(255, 160, 122, 0.95), rgba(255, 192, 120, 0.95));
  border-radius: 0.75rem;
  animation: level-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
}

@keyframes level-pop {
  0% { transform: scale(0.5) rotate(-5deg); opacity: 0; }
  60% { transform: scale(1.05) rotate(2deg); opacity: 1; }
  80% { transform: scale(0.98) rotate(-1deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.level-complete-text {
  font-size: 1.5rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.level-complete-sparkles { display: none; }

/* Victory overlay */
.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(255, 248, 240, 0.98), rgba(254, 247, 240, 0.95));
  animation: fade-in 0.6s ease, fade-out 0.5s ease 4s forwards;
  pointer-events: none;
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; visibility: hidden; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.victory-content {
  text-align: center;
  animation: victory-bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes victory-bounce {
  0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  50% { transform: scale(1.1) rotate(5deg); opacity: 1; }
  70% { transform: scale(0.95) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.victory-stars { margin-bottom: 0.75rem; }

.star {
  display: inline-block;
  font-size: 3rem;
  color: var(--honey);
  text-shadow: 0 4px 12px rgba(255, 192, 120, 0.5);
  animation: star-twinkle 1s ease infinite;
}

.star-1 { font-size: 2.25rem; animation-delay: 0.1s; }
.star-2 { font-size: 3.5rem; }
.star-3 { font-size: 2.25rem; animation-delay: 0.2s; }

@keyframes star-twinkle {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.2) rotate(-10deg); }
  50% { transform: scale(0.9) rotate(5deg); }
  75% { transform: scale(1.15) rotate(-5deg); }
}

.victory-title {
  font-size: 3.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--coral), var(--peach), var(--honey));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.victory-subtitle {
  font-size: 1.25rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-weight: 600;
}

/* Confetti */
.confetti-container {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 999;
}

.confetti {
  position: absolute;
  width: 12px;
  height: 12px;
  top: -20px;
  left: 50%;
  transform: translateX(var(--x));
  animation: confetti-fall var(--duration) cubic-bezier(0.25, 0.46, 0.45, 0.94) var(--delay) forwards;
}

.confetti-0 { background: var(--coral); border-radius: 50%; }
.confetti-1 { background: var(--peach); border-radius: 2px; }
.confetti-2 { background: var(--honey); border-radius: 50%; }
.confetti-3 { background: var(--sage); border-radius: 2px; }
.confetti-4 { background: var(--lavender); border-radius: 50%; }
.confetti-5 { background: var(--sky); border-radius: 2px; }

@keyframes confetti-fall {
  0% { transform: translateX(var(--x)) translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateX(calc(var(--x) + 20vw)) translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Game over */
.game-over-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(255, 248, 240, 0.98), rgba(254, 247, 240, 0.95));
  animation: fade-in 0.6s ease, fade-out 0.5s ease 3s forwards;
  pointer-events: none;
}

.game-over-content {
  text-align: center;
  animation: drop-shake 0.5s ease;
}

@keyframes drop-shake {
  0% { transform: translateY(-30px); opacity: 0; }
  60% { transform: translateY(5px); }
  100% { transform: translateY(0); opacity: 1; }
}

.game-over-icon {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

.game-over-title {
  font-size: 3rem;
  font-weight: 900;
  color: var(--danger);
}

.game-over-subtitle {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-weight: 600;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  .arena-layout { grid-template-columns: 1fr; }
  .radio-panel { height: 350px; min-height: 300px; }
  .game-hud {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }
  .hud-room { justify-content: center; }
  .hud-actions {
    justify-content: center;
    flex-wrap: wrap;
  }
  .hud-game-actions,
  .hud-nav {
    border-left: none;
    padding-left: 0;
  }
  .hand-card { min-width: 3.25rem; min-height: 4.25rem; font-size: 1.35rem; }
  .stack-card { width: 3.25rem; height: 4.25rem; }
  .stack-value { font-size: 1.25rem; }
  .victory-title { font-size: 2.25rem; }
  .game-over-title { font-size: 2rem; }
  .button {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
  }
  .playfield { padding: 1rem; }
}

@media (max-width: 480px) {
  .game-shell { padding: 0.5rem; }
  .game-hud { padding: 0.75rem; }
  .hud-name { font-size: 1rem; }
  .hud-code { font-size: 0.8rem; }
  .hud-lock { font-size: 0.7rem; padding: 0.2rem 0.5rem; }
  .hand-card { width: 3rem; height: 4rem; font-size: 1.2rem; }
  .stack-card { width: 3rem; height: 4rem; }
  .stack-value { font-size: 1.1rem; }
  .status-hud { gap: 0.75rem; font-size: 0.8rem; padding: 0.625rem 0.75rem; }
  .player-chip { padding: 0.3rem 0.625rem; font-size: 0.8rem; }
}

.room-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20rem;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .room-layout { grid-template-columns: 1fr; }
}

.room-main { min-width: 0; }

.chat-shell {
  margin-top: 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 1rem;
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  height: min(60vh, 500px);
  min-height: 350px;
}

/* Focus states */
.button:focus-visible,
.hand-card:focus-visible {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

::selection {
  background: var(--accent-light);
  color: var(--coral);
}
