:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-surface: #21262d;
  --accent: #e94560;
  --gold: #d4af37;
  --gold-light: #f5d782;
  --text: #f0e6d3;
  --text-dim: #8b949e;
  --success: #3fb950;
  --danger: #f85149;
  --radius: 14px;
}

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

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

/* --- Layout --- */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.header {
  text-align: center;
  padding: 16px 0 8px;
}

.header h1 {
  font-size: 1.8em;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header .subtitle {
  color: var(--text-dim);
  font-size: 1em;
  margin-top: 2px;
}

/* ============================================================
   CARDS - Big, beautiful, with depth
   ============================================================ */
.card-game {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 168px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.12);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1),
              box-shadow 0.25s cubic-bezier(.4,0,.2,1),
              border-color 0.2s;
  animation: card-enter 0.4s cubic-bezier(.4,0,.2,1) both;
}

/* Shine overlay */
.card-game::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%, rgba(0,0,0,0.1) 100%);
  pointer-events: none;
  border-radius: 10px;
}

/* Subtle pattern */
.card-game::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.08) 0%, transparent 60%);
  pointer-events: none;
}

.card-game:active {
  transform: scale(0.93);
}

.card-game.selected {
  border-color: var(--gold);
  box-shadow: 0 0 30px rgba(212, 175, 55, 0.5), 0 8px 25px rgba(0,0,0,0.5);
  transform: translateY(-12px) scale(1.03);
  animation: card-selected-pulse 1.5s ease-in-out infinite;
}

.card-game.playable {
  animation: card-playable 2s ease-in-out infinite;
  border-color: rgba(233, 69, 96, 0.6);
}

.card-game .card-value {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 1.15em;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  z-index: 1;
}

.card-game .card-value-br {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 0.8em;
  font-weight: 800;
  opacity: 0.6;
  transform: rotate(180deg);
  z-index: 1;
}

.card-game .card-emoji {
  font-size: 3.2em;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
  z-index: 1;
}

.card-game .card-name {
  font-size: 0.75em;
  text-align: center;
  color: rgba(255,255,255,0.95);
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  z-index: 1;
  letter-spacing: 0.5px;
}

/* Small cards for discard pile / played area */
.card-game.small {
  width: 68px;
  height: 95px;
  border-radius: 8px;
}

.card-game.small .card-emoji { font-size: 1.8em; }
.card-game.small .card-name { font-size: 0.55em; }
.card-game.small .card-value { font-size: 0.8em; top: 3px; left: 5px; }
.card-game.small .card-value-br { display: none; }

/* Medium cards for reference */
.card-game.medium {
  width: 78px;
  height: 110px;
  border-radius: 9px;
  cursor: default;
}

.card-game.medium .card-emoji { font-size: 2.2em; }
.card-game.medium .card-name { font-size: 0.6em; }
.card-game.medium .card-value { font-size: 0.85em; top: 4px; left: 5px; }
.card-game.medium .card-value-br { display: none; }

.card-game.eliminated {
  opacity: 0.35;
  filter: grayscale(0.8);
}

/* Card back (deck) */
.card-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 95px;
  border-radius: 8px;
  background: linear-gradient(135deg, #8b2252, #5b1a3a);
  border: 2px solid rgba(255,255,255,0.12);
  box-shadow: 0 3px 10px rgba(0,0,0,0.4);
  font-size: 1.8em;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(212,175,55,0.3);
  border-radius: 5px;
  background: repeating-linear-gradient(
    45deg, transparent, transparent 4px,
    rgba(212,175,55,0.05) 4px, rgba(212,175,55,0.05) 8px
  );
}

.hand-area {
  display: flex;
  gap: 16px;
  justify-content: center;
  padding: 20px 0;
  flex-wrap: wrap;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes card-enter {
  from { opacity: 0; transform: translateY(30px) scale(0.8) rotate(-5deg); }
  to { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes card-selected-pulse {
  0%, 100% { box-shadow: 0 0 25px rgba(212, 175, 55, 0.4), 0 8px 25px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 0 40px rgba(212, 175, 55, 0.7), 0 8px 30px rgba(0,0,0,0.5); }
}

@keyframes card-playable {
  0%, 100% { border-color: rgba(233, 69, 96, 0.3); box-shadow: 0 4px 15px rgba(0,0,0,0.4); }
  50% { border-color: rgba(233, 69, 96, 0.8); box-shadow: 0 4px 20px rgba(233,69,96,0.2), 0 4px 15px rgba(0,0,0,0.4); }
}

@keyframes turn-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(233, 69, 96, 0.2); border-color: rgba(233,69,96,0.5); }
  50% { box-shadow: 0 0 35px rgba(233, 69, 96, 0.4); border-color: rgba(233,69,96,0.9); }
}

@keyframes bounce-in {
  0% { opacity: 0; transform: scale(0.3); }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

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

@keyframes card-play-out {
  0% { opacity: 1; transform: scale(1) translateY(0); }
  40% { opacity: 1; transform: scale(1.1) translateY(-20px); }
  100% { opacity: 0; transform: scale(0.5) translateY(-80px); }
}

.card-game.playing-out {
  animation: card-play-out 0.5s cubic-bezier(.4,0,.2,1) forwards !important;
  pointer-events: none;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  animation: slide-up 0.3s ease both;
}

.panel-title {
  font-size: 0.95em;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   TURN INDICATOR - big and obvious
   ============================================================ */
.turn-banner {
  text-align: center;
  padding: 16px 18px;
  font-size: 1.25em;
  font-weight: 700;
  border-radius: var(--radius);
  margin-bottom: 10px;
  transition: all 0.3s;
  overflow: hidden;
}

.turn-banner.my-turn {
  background: linear-gradient(135deg, rgba(233,69,96,0.2), rgba(212,175,55,0.15));
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 1.5em;
  animation: turn-glow 2s ease-in-out infinite;
}

.turn-banner.my-turn .turn-hint {
  display: block;
  font-size: 0.55em;
  color: var(--gold);
  margin-top: 4px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  animation: pulse 1.5s ease-in-out infinite;
}

.turn-banner.waiting {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text-dim);
}

.turn-banner.eliminated {
  background: rgba(248,81,73,0.1);
  border: 1px solid rgba(248,81,73,0.3);
  color: var(--danger);
}

.turn-banner.round-over {
  background: linear-gradient(135deg, rgba(212,175,55,0.15), rgba(212,175,55,0.05));
  border: 1px solid rgba(212,175,55,0.3);
  color: var(--gold);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border-radius: var(--radius);
  border: none;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(.4,0,.2,1);
  color: white;
  gap: 8px;
  width: 100%;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d63851);
  box-shadow: 0 4px 15px rgba(233,69,96,0.3);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(233,69,96,0.4); }

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #c4a030);
  color: #1a1a2e;
  box-shadow: 0 4px 15px rgba(212,175,55,0.3);
}

.btn-confirm {
  background: linear-gradient(135deg, var(--success), #2ea043);
  box-shadow: 0 4px 15px rgba(63,185,80,0.3);
  font-size: 1.1em;
  padding: 16px 24px;
  animation: btn-ready-pulse 2s ease-in-out infinite;
}

@keyframes btn-ready-pulse {
  0%, 100% { box-shadow: 0 4px 15px rgba(63,185,80,0.3); }
  50% { box-shadow: 0 4px 25px rgba(63,185,80,0.5); }
}

.btn-confirm:disabled { animation: none; }

.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }

.btn-outline {
  background: transparent;
  border: 2px solid var(--text-dim);
  color: var(--text);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85em;
  width: auto;
}

/* ============================================================
   FORMS
   ============================================================ */
.input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,0.08);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 1em;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(212,175,55,0.15);
}

.input-group { margin-bottom: 12px; }
.input-group label { display: block; font-size: 0.85em; color: var(--text-dim); margin-bottom: 6px; }

/* ============================================================
   ROOM CODE
   ============================================================ */
.room-code {
  font-size: 3.5em;
  font-weight: 800;
  letter-spacing: 12px;
  text-align: center;
  color: var(--gold);
  padding: 20px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 2px dashed rgba(212,175,55,0.4);
  margin: 12px 0;
}

.room-url {
  text-align: center;
  font-size: 0.8em;
  color: var(--text-dim);
  word-break: break-all;
  margin-bottom: 12px;
}

#qr-code {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

#qr-code canvas {
  border-radius: 10px;
  border: 3px solid rgba(212,175,55,0.3);
}

/* ============================================================
   PLAYER LIST
   ============================================================ */
.player-list { list-style: none; }

.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.02);
  border: 1px solid transparent;
  transition: all 0.25s;
}

.player-item.current-turn {
  background: rgba(212, 175, 55, 0.08);
  border-color: rgba(212, 175, 55, 0.25);
}

.player-item.eliminated {
  opacity: 0.35;
}

.player-item.eliminated .player-name {
  text-decoration: line-through;
}

.player-item.protected .player-name::after {
  content: ' 🧤';
}

.player-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1em;
}

.player-tokens { display: flex; gap: 4px; }

.token {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border: 1px solid rgba(0,0,0,0.3);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.token.empty {
  background: transparent;
  border: 1.5px solid var(--text-dim);
  box-shadow: none;
}

.player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  position: relative;
}

.player-avatar .connection-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.player-avatar .connection-indicator.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.player-avatar .connection-indicator.offline { background: var(--danger); }

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.connection-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.connection-dot.offline { background: var(--danger); }

/* ============================================================
   DISCARD PILE
   ============================================================ */
.discard-pile {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.discard-pile::-webkit-scrollbar { display: none; }

.discard-section {
  margin-top: 8px;
}

.discard-label {
  font-size: 0.7em;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

/* Played cards inline in player list */
.played-cards-inline {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ============================================================
   GAME LOG
   ============================================================ */
.game-log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.95em;
  scrollbar-width: thin;
}

.game-log .log-entry {
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-dim);
  transition: color 0.2s;
}

.game-log .log-entry:last-child {
  color: var(--text);
  font-weight: 500;
}

/* ============================================================
   ACTION PANEL - prominent when it's your turn
   ============================================================ */
.action-panel {
  background: linear-gradient(135deg, rgba(233,69,96,0.08), rgba(212,175,55,0.06));
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 10px;
  animation: bounce-in 0.4s cubic-bezier(.4,0,.2,1) both;
}

.action-title {
  font-size: 1.4em;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 4px;
  text-align: center;
}

.action-desc {
  font-size: 1em;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 16px;
  line-height: 1.4;
}

.action-step {
  margin-bottom: 16px;
}

.action-step-label {
  font-size: 0.75em;
  color: var(--gold);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-step-label .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--bg);
  font-size: 0.85em;
  font-weight: 800;
}

.target-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.target-btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.12);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
  min-width: 100px;
  text-align: center;
}

.target-btn:active { transform: scale(0.95); }

.target-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.2);
  box-shadow: 0 0 15px rgba(233,69,96,0.2);
}

.guess-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.guess-btn {
  padding: 10px 6px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.08);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.8em;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.guess-btn .guess-emoji { font-size: 1.6em; }
.guess-btn .guess-name { font-size: 0.9em; font-weight: 600; }
.guess-btn .guess-val { font-size: 0.8em; color: var(--text-dim); }

.guess-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.2);
  box-shadow: 0 0 12px rgba(233,69,96,0.2);
}

/* ============================================================
   CHANCELLOR CHOICE
   ============================================================ */
.chancellor-panel { text-align: center; }
.chancellor-panel .hand-area { margin-bottom: 16px; }

/* ============================================================
   TOAST / NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 90vw;
  padding-top: 8px;
}

.toast {
  background: var(--bg-surface);
  color: var(--text);
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 0.95em;
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  animation: toast-in 0.35s cubic-bezier(.4,0,.2,1);
  text-align: center;
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--gold); background: rgba(212,175,55,0.15); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-30px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   MODAL / OVERLAY
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.1);
  animation: bounce-in 0.4s cubic-bezier(.4,0,.2,1);
}

.modal h2 {
  color: var(--gold);
  margin-bottom: 16px;
  text-align: center;
}

/* ============================================================
   LANDING PAGE
   ============================================================ */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  text-align: center;
}

.landing h1 { font-size: 3.2em; margin-bottom: 8px; }

.landing .tagline {
  color: var(--text-dim);
  margin-bottom: 40px;
  font-size: 1.1em;
}

.landing-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  margin: 8px 0;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* ============================================================
   STATUS BADGE
   ============================================================ */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.badge-waiting { background: rgba(139,148,158,0.15); color: var(--text-dim); }
.badge-playing { background: rgba(63,185,80,0.15); color: var(--success); }
.badge-over { background: rgba(212,175,55,0.15); color: var(--gold); }

/* ============================================================
   ROUND RESULT
   ============================================================ */
.round-result {
  text-align: center;
  padding: 20px;
}

.round-result .winner-emoji {
  font-size: 3em;
  animation: bounce-in 0.6s cubic-bezier(.4,0,.2,1) both;
}

.round-result .winner-name {
  font-size: 2em;
  font-weight: 800;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 8px 0;
}

.round-result .win-reason {
  color: var(--text-dim);
  margin-bottom: 16px;
  font-size: 0.95em;
}

/* ============================================================
   CARD REFERENCE - beautiful grid
   ============================================================ */
.card-ref-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}

.card-ref-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  background: rgba(255,255,255,0.02);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.04);
}

.card-ref-entry .ref-card-wrapper {
  flex-shrink: 0;
}

.card-ref-entry .ref-info {
  flex: 1;
  min-width: 0;
}

.card-ref-entry .ref-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.card-ref-entry .ref-title {
  font-weight: 700;
  font-size: 0.95em;
}

.card-ref-entry .ref-qty-badge {
  font-size: 0.65em;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
}

.card-ref-entry .ref-desc {
  font-size: 0.82em;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ============================================================
   DECK INFO BAR
   ============================================================ */
.deck-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  padding: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}

.deck-bar.has-excluded {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto;
}

.deck-bar .deck-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  position: relative;
}

.deck-bar .deck-stat:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 20%;
  height: 60%;
  width: 1px;
  background: rgba(255,255,255,0.06);
}

.deck-bar .deck-stat-label {
  font-size: 0.65em;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.deck-bar .deck-stat-value {
  font-size: 1.3em;
  font-weight: 800;
  color: var(--text);
}

.deck-bar .deck-stat-excluded {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.8em;
  color: var(--text-dim);
}

.deck-bar .deck-stat-excluded .excluded-label {
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.deck-bar .deck-stat-excluded .excluded-cards {
  font-size: 1.3em;
  letter-spacing: 2px;
}

/* ============================================================
   ADMIN CONTROLS
   ============================================================ */
.admin-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-controls .btn { width: auto; flex: 1; min-width: 120px; }

/* ============================================================
   WAITING
   ============================================================ */
.waiting-message {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 1.1em;
}

.waiting-message .pulse {
  display: inline-block;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ============================================================
   COLLAPSIBLE
   ============================================================ */
.collapsible-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.collapsible-header::after {
  content: '▾';
  font-size: 0.8em;
  color: var(--text-dim);
  transition: transform 0.3s;
}

.collapsible-header.collapsed::after {
  transform: rotate(-90deg);
}

.collapsible-body {
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.collapsible-body.collapsed {
  max-height: 0 !important;
}

/* ============================================================
   SETTINGS
   ============================================================ */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.setting-row label { font-size: 0.9em; }

.setting-row input[type="number"] {
  width: 60px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg);
  color: var(--text);
  text-align: center;
  font-size: 1em;
}

/* ============================================================
   LIVE NARRATIVE - what's happening now
   ============================================================ */
.narrative-panel {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-surface));
  border: 1px solid rgba(212,175,55,0.15);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.narrative-panel .narrative-title {
  font-size: 0.85em;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.narrative-panel .narrative-title .live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

.narrative-entry {
  padding: 6px 0;
  font-size: 1em;
  line-height: 1.5;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(255,255,255,0.03);
  animation: slide-up 0.3s ease both;
}

.narrative-entry:last-child {
  border-bottom: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1.05em;
}

.narrative-entry .narr-emoji {
  margin-right: 6px;
}

/* ============================================================
   CARD COUNTER - remaining cards tracker
   ============================================================ */
.card-counter-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.card-counter-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.04);
  transition: opacity 0.3s;
}

.card-counter-item.gone {
  opacity: 0.25;
  filter: grayscale(0.8);
}

.counter-mini-card {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.counter-emoji { font-size: 1.1em; }

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

.counter-name {
  font-size: 0.6em;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.counter-nums {
  font-size: 0.75em;
  font-weight: 700;
  color: var(--text);
}

.counter-bar {
  width: 100%;
  height: 3px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}

.counter-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ============================================================
   FLOATING EMOJI (reactions)
   ============================================================ */
.floating-emoji {
  position: fixed;
  font-size: 2em;
  pointer-events: none;
  z-index: 1100;
  animation: float-up 2s ease-out forwards;
}

@keyframes float-up {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-120px) scale(1.5); }
}

/* ============================================================
   REACTION BAR
   ============================================================ */
.reaction-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 0;
  margin-bottom: 8px;
}

.reaction-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--bg-card);
  font-size: 1.5em;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reaction-btn:active {
  transform: scale(1.3);
  background: rgba(255,255,255,0.1);
}

.reaction-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1em;
  color: var(--text);
  background: var(--bg-surface);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
  z-index: 1100;
  pointer-events: none;
  animation: reaction-toast-anim 1.5s ease-out forwards;
}

@keyframes reaction-toast-anim {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1.2); }
}

/* ============================================================
   TURN TIMER BAR
   ============================================================ */
.turn-timer {
  width: calc(100% + 36px);
  margin: 12px -18px -16px;
  height: 5px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.turn-timer-fill {
  height: 100%;
  transition: width 1s linear, background 0.5s;
  background: var(--success);
}

.turn-timer-fill.warning { background: var(--gold); }
.turn-timer-fill.danger { background: var(--danger); animation: pulse-bar 0.5s ease-in-out infinite; }

@keyframes pulse-bar {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.turn-timer-text {
  text-align: center;
  font-size: 0.65em;
  color: var(--text-dim);
  margin-top: 8px;
  margin-bottom: -8px;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   SCOREBOARD - fullscreen game display
   ============================================================ */
.scoreboard-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 800;
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
}

.scoreboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  overflow: hidden;
}

/* Header */
.scoreboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(212,175,55,0.15);
  flex-shrink: 0;
}

.scoreboard-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.scoreboard-title {
  font-size: 1.4em;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.scoreboard-round-info {
  display: flex;
  gap: 14px;
  font-size: 0.85em;
  color: var(--text-dim);
}

.scoreboard-round-info strong {
  color: var(--text);
}

.scoreboard-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 1em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.scoreboard-close-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

/* Turn banner in scoreboard */
.scoreboard-turn {
  flex-shrink: 0;
  padding: 6px 0;
}

.scoreboard-turn:empty {
  display: none;
}

/* Body */
.scoreboard-body {
  flex: 1;
  overflow-y: auto;
  padding-top: 6px;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 8px;
  min-height: 0;
}

/* Players grid */
.scoreboard-players {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-content: stretch;
}

/* Bottom section: narrative + counter side by side */
.scoreboard-bottom {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  flex-shrink: 0;
}

.scoreboard-section {
  margin: 0;
}

@media (min-width: 640px) {
  .scoreboard {
    padding: 14px 20px;
  }

  .scoreboard-players {
    grid-template-columns: repeat(2, 1fr);
  }

  .scoreboard-bottom {
    grid-template-columns: 1fr 1fr;
  }

  .sb-player-name { font-size: 1.1em; }
  .sb-player-avatar { width: 44px; height: 44px; font-size: 1.4em; }
  .scoreboard-narrative .sb-narr-entry { font-size: 1.05em; }
  .scoreboard-narrative .sb-narr-entry:first-of-type { font-size: 1.2em; }
}

@media (min-width: 1024px) {
  .scoreboard {
    padding: 16px 28px;
  }

  .scoreboard-players {
    grid-template-columns: repeat(2, 1fr);
  }

  .sb-player { padding: 16px 20px; gap: 14px; border-radius: var(--radius); }
  .sb-player-rank { font-size: 1.8em; }
  .sb-player-name { font-size: 1.3em; }
  .sb-player-stats { font-size: 0.8em; }
  .sb-player-avatar { width: 52px; height: 52px; font-size: 1.6em; }
  .sb-player-tokens .token { width: 24px; height: 24px; }
  .sb-player-tokens { gap: 6px; }
  .scoreboard-narrative .sb-narr-entry { font-size: 1.1em; }
  .scoreboard-narrative .sb-narr-entry:first-of-type { font-size: 1.25em; }
  .scoreboard-narrative { max-height: none; }
  .scoreboard-title { font-size: 1.6em; }
  .scoreboard-round-info { font-size: 1em; }
}

@media (min-width: 1400px) {
  .scoreboard-players {
    grid-template-columns: repeat(3, 1fr);
  }

  .scoreboard-bottom {
    grid-template-columns: 3fr 2fr;
  }

  .sb-player { padding: 18px 24px; }
  .sb-player-name { font-size: 1.4em; }
  .sb-player-stats { font-size: 0.85em; }
  .sb-player-rank { font-size: 2em; }
  .sb-player-avatar { width: 56px; height: 56px; font-size: 1.7em; }
  .sb-player-tokens .token { width: 28px; height: 28px; }
  .scoreboard-narrative .sb-narr-entry { font-size: 1.15em; }
  .scoreboard-narrative .sb-narr-entry:first-of-type { font-size: 1.3em; }
}

/* Player cards */
.sb-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 2px solid rgba(255,255,255,0.04);
  transition: all 0.3s;
}

.sb-player.sb-active {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(212,175,55,0.1), rgba(212,175,55,0.04));
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.1);
}

.sb-player.sb-eliminated {
  opacity: 0.3;
}

.sb-player-rank {
  font-size: 1.3em;
  font-weight: 800;
  color: var(--text-dim);
  min-width: 24px;
  text-align: center;
}

.sb-player:first-child .sb-player-rank,
.sb-player.sb-active .sb-player-rank {
  color: var(--gold);
}

.sb-player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3em;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.12);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.sb-player.sb-active .sb-player-avatar {
  border-color: rgba(212,175,55,0.5);
}

.sb-player-info {
  flex: 1;
  min-width: 0;
}

.sb-player-name {
  font-size: 1.05em;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-player-status {
  font-size: 0.7em;
  margin-left: 6px;
  font-weight: 600;
}

.sb-played-cards {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.sb-player-tokens {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.sb-player-tokens .token {
  width: 20px;
  height: 20px;
}

/* Narrative in scoreboard */
.scoreboard-narrative {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-surface));
  border-radius: 10px;
  padding: 12px 16px;
  border: 1px solid rgba(212,175,55,0.1);
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.scoreboard-narrative:empty {
  display: none;
}

.scoreboard-narrative .sb-narr-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8em;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 700;
  margin-bottom: 8px;
}

.scoreboard-narrative .sb-narr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

.scoreboard-narrative .sb-narr-entry {
  padding: 5px 0;
  font-size: 1em;
  line-height: 1.5;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.scoreboard-narrative .sb-narr-entry:first-of-type {
  color: #fff;
  font-weight: 700;
  font-size: 1.15em;
  padding: 6px 0;
}

.scoreboard-narrative .sb-narr-entry:last-child {
  border-bottom: none;
}

/* Player stats line */
.sb-player-stats {
  display: flex;
  gap: 10px;
  font-size: 0.75em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Popup overlay */
.sb-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.sb-popup-content {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  animation: bounce-in 0.3s cubic-bezier(.4,0,.2,1);
}

.sb-popup-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.sb-popup-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6em;
  border: 3px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
}

.sb-popup-name {
  font-size: 1.3em;
  font-weight: 700;
}

.sb-popup-tokens {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.85em;
  color: var(--text-dim);
}

.sb-popup-stat {
  padding: 6px 0;
  font-size: 0.95em;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.sb-popup-desc {
  padding: 10px 0;
  font-size: 0.95em;
  line-height: 1.5;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.sb-popup-cards {
  margin-top: 8px;
}

.sb-popup-card-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9em;
}

/* ============================================================
   MUTE TOGGLE
   ============================================================ */
.mute-btn {
  position: fixed;
  top: env(safe-area-inset-top, 8px);
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg-surface);
  color: var(--text-dim);
  font-size: 1em;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding-top: 8px;
}

.mute-btn:active { transform: scale(0.9); }

/* ============================================================
   BOT BADGE
   ============================================================ */
.bot-badge {
  display: inline-block;
  font-size: 0.65em;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(233, 69, 96, 0.2);
  color: var(--accent);
  border: 1px solid rgba(233, 69, 96, 0.3);
  font-weight: 600;
  vertical-align: middle;
  margin-left: 4px;
}

.bot-controls {
  padding: 4px 0;
}

/* ============================================================
   ADMIN LAYOUT
   ============================================================ */
.admin-layout {
  max-width: 800px;
  margin: 0 auto;
  padding: 12px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.admin-col-ref { display: none; }
.admin-mobile-ref { display: block; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (min-width: 768px) {
  .container { padding: 24px; }
  .card-game { width: 140px; height: 196px; }
  .card-game .card-emoji { font-size: 3.8em; }
  .card-game .card-name { font-size: 0.85em; }
  .card-game .card-value { font-size: 1.3em; }
  .card-game.medium { width: 95px; height: 133px; }
  .card-game.medium .card-emoji { font-size: 2.6em; }
  .room-code { font-size: 4.5em; }
  .turn-banner.my-turn { font-size: 1.7em; }
  .guess-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 1024px) {
  .admin-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    max-width: 1400px;
    padding: 24px;
    align-items: start;
  }

  .admin-col-game {
    min-width: 0;
  }

  .admin-col-ref {
    display: block;
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    scrollbar-width: thin;
  }

  .admin-ref-panel {
    margin-bottom: 0;
  }

  .admin-mobile-ref { display: none; }
}
