:root {
  --bg: #0a0e1a;
  --panel: #141b2d;
  --panel-2: #1b2438;
  --border: #2a3652;
  --text: #e8edf7;
  --muted: #8a97b1;
  --accent: #6ea8fe;
  --accent-strong: #3b82f6;
  --card-back-1: #3b82f6;
  --card-back-2: #7c3aed;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 50% -200px, #101a33 0%, var(--bg) 60%);
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ---------- Header ---------- */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 27, 45, 0.6);
}

.logo { font-size: 18px; font-weight: 700; }

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

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 18px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #0b1020;
}
.btn-primary:hover { background: #8dbbff; }
.btn-primary:disabled { background: #33415e; color: #6b7690; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover { background: rgba(110, 168, 254, 0.12); }

.btn-big { width: 100%; padding: 13px; font-size: 16px; }

/* ---------- Landing ---------- */
.view { flex: 1; display: flex; flex-direction: column; align-items: center; }

#landing { justify-content: center; gap: 32px; padding: 20px; }

.landing-hero { text-align: center; }
.landing-hero h1 { font-size: 42px; margin-bottom: 10px; }
.tagline { color: var(--muted); font-size: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: min(420px, 92vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.panel h2 { margin-bottom: 20px; font-size: 20px; }

.field { display: block; margin-bottom: 18px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type='text'], select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #0d1322;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input[type='text']:focus, select:focus { border-color: var(--accent); }

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 14px;
  user-select: none;
}
.toggle-label input { accent-color: var(--accent-strong); width: 16px; height: 16px; }
#spectator-toggle { margin-bottom: 0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

/* ---------- Game layout ---------- */
#game { justify-content: space-between; }

#table-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 16px;
  width: 100%;
}

#mid-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.seat-row {
  display: flex;
  gap: 28px;
  justify-content: center;
  min-height: 118px;
  align-items: flex-end;
}

.seat-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  justify-content: center;
  min-width: 82px;
}

#table {
  width: min(560px, 55vw);
  height: 220px;
  border-radius: 120px;
  background: linear-gradient(180deg, #1d2a4a 0%, #16203a 100%);
  border: 2px solid #2c3c63;
  box-shadow: inset 0 4px 30px rgba(0, 0, 0, 0.35), 0 18px 50px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

#table-content { text-align: center; }
#table-content .prompt { color: var(--muted); font-size: 17px; }
#table-content .countdown { font-size: 72px; font-weight: 800; color: var(--accent); }

/* ---------- Player tiles ---------- */
.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  position: relative;
}

.player-card {
  width: 46px;
  height: 70px;
  border-radius: 9px;
  perspective: 300px;
}

.player-card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}
.player-card.flipped .player-card-inner { transform: rotateY(180deg); }

.player-card-face {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-card-back-empty {
  border: 2px dashed #33415e;
  background: rgba(20, 27, 45, 0.6);
}

.player-card-back-voted {
  background: linear-gradient(135deg, var(--card-back-1), var(--card-back-2));
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}
.player-card-back-voted::after {
  content: '🂠';
  font-size: 26px;
  color: rgba(255, 255, 255, 0.85);
}

.player-card-front {
  background: #f4f7ff;
  color: #16203a;
  font-weight: 800;
  font-size: 20px;
  transform: rotateY(180deg);
  border: 2px solid var(--accent-strong);
}

.player-name {
  font-size: 13px;
  font-weight: 600;
  max-width: 96px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player.self .player-name { color: var(--accent); }

.player .spectator-badge {
  width: 46px;
  height: 70px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: 2px dotted #33415e;
  color: var(--muted);
}

.player.shake { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-7px) rotate(-6deg); }
  40% { transform: translateX(7px) rotate(6deg); }
  60% { transform: translateX(-5px) rotate(-4deg); }
  80% { transform: translateX(5px) rotate(3deg); }
}

/* ---------- Card deck ---------- */
#footer {
  padding: 14px 20px 22px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-height: 150px;
}

#pick-label { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 10px; }

#cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.deck-card {
  width: 52px;
  height: 84px;
  border-radius: 10px;
  border: 2px solid var(--accent-strong);
  background: rgba(13, 19, 34, 0.9);
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.deck-card:hover { transform: translateY(-8px); }
.deck-card.selected {
  transform: translateY(-14px);
  background: var(--accent-strong);
  color: #fff;
  box-shadow: 0 10px 22px rgba(59, 130, 246, 0.4);
}
.deck-card:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ---------- Results ---------- */
#results {
  display: flex;
  gap: 40px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.result-group { display: flex; gap: 18px; }

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

.result-card {
  width: 44px;
  height: 70px;
  border-radius: 9px;
  border: 2px solid var(--accent-strong);
  background: #f4f7ff;
  color: #16203a;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-count { color: var(--muted); font-size: 13px; }

.result-average { text-align: center; }
.result-average .avg-label { color: var(--muted); font-size: 13px; }
.result-average .avg-value { font-size: 40px; font-weight: 800; color: var(--accent); }

/* ---------- Emoji popover ---------- */
#emoji-popover {
  position: fixed;
  z-index: 60;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
#emoji-popover button {
  font-size: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px 6px;
  border-radius: 8px;
  transition: transform 0.1s ease, background 0.1s ease;
}
#emoji-popover button:hover { background: rgba(110, 168, 254, 0.15); transform: scale(1.25); }

.emoji-quick { display: flex; gap: 4px; align-items: center; }

#emoji-popover .emoji-more {
  font-size: 17px;
  color: var(--muted);
  border: 1px dashed var(--border);
}
#emoji-popover .emoji-more:hover { color: var(--accent); transform: none; }

.emoji-panel {
  width: 380px;
  max-width: 84vw;
  max-height: 240px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.emoji-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #0d1322;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
  margin-bottom: 4px;
}
.emoji-input:focus { border-color: var(--accent); }

.emoji-cat {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 8px 0 2px;
}

.emoji-grid { display: flex; flex-wrap: wrap; }

.flying-emoji {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 70;
  font-size: 30px;
  pointer-events: none;
  will-change: transform;
}
.flying-emoji.splat { transition: transform 0.4s ease, opacity 0.4s ease; }

/* ---------- Confetti / toast ---------- */
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 80;
}

#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  z-index: 90;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  font-size: 14px;
}
