:root {
  --bg-primary: #000000;
  --bg-secondary: #0a0a0f;
  --bg-tertiary: #14141f;
  --bg-card: #1a1a2e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --cyan: #00e5ff;
  --yellow: #ffd600;
  --magenta: #ff4081;
  --green: #00e676;
  --focus-ring: #00e5ff;
  --focus-glow: rgba(0, 229, 255, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  padding: 8px;
}
.screen.hidden { display: none; }

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.content.centered {
  align-items: center;
  justify-content: center;
}

/* --- Focus States --- */
.focusable {
  transition:
    transform 475ms cubic-bezier(0.6, 0, 0.4, 1),
    border-color 300ms cubic-bezier(0.4, 0.04, 0.5, 1),
    box-shadow 300ms cubic-bezier(0.4, 0.04, 0.5, 1),
    opacity 300ms cubic-bezier(0.4, 0.04, 0.5, 1);
  border: 2px solid transparent;
  cursor: pointer;
}
.focusable:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 20px var(--focus-glow);
}

/* --- Title Screen --- */
.game-title {
  font-size: 64px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--cyan);
  text-shadow: 0 0 40px rgba(0, 229, 255, 0.3);
  margin-bottom: 4px;
}
.game-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 300px;
}
.menu-btn {
  padding: 18px 24px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  min-height: 60px;
}
.menu-btn:focus {
  background: var(--bg-tertiary);
}
.menu-btn:disabled {
  opacity: 0.4;
  color: var(--text-muted);
}

/* --- Labels --- */
.label {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

/* --- Room Code --- */
.room-code {
  font-size: 64px;
  font-weight: 800;
  letter-spacing: 12px;
  color: var(--yellow);
  font-family: 'Courier New', monospace;
  margin-bottom: 24px;
}

/* --- Code Entry --- */
.code-entry {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}
.code-slot {
  width: 64px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  color: var(--text-primary);
}
.code-slot.active {
  border-color: var(--cyan);
  box-shadow: 0 0 20px var(--focus-glow);
  color: var(--cyan);
}
.code-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* --- Player List --- */
.player-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 400px;
  margin-bottom: 16px;
}
.player-tag {
  padding: 8px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 28px;
  text-align: center;
}

/* --- Name Selection --- */
.name-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 400px;
  max-height: 400px;
  overflow-y: auto;
}
.name-item {
  padding: 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  font-size: 36px;
  text-align: center;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.name-item:focus {
  background: var(--bg-card);
}
.name-item.taken {
  opacity: 0.15;
  filter: grayscale(1);
}

/* --- Trivia Screen --- */
.round-label {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  padding: 8px 0 4px;
}
.question-text {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  padding: 16px 20px;
  line-height: 1.3;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px;
  flex: 1;
  max-height: 280px;
}
.answer-btn {
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 88px;
  word-wrap: break-word;
  line-height: 1.2;
}
.answer-btn:focus {
  background: var(--bg-tertiary);
}
.answer-btn.selected {
  border-color: var(--cyan);
  background: rgba(0, 229, 255, 0.1);
}
.answer-btn.correct {
  border-color: var(--green);
  background: rgba(0, 230, 118, 0.15);
  color: var(--green);
}
.answer-btn.wrong {
  border-color: var(--magenta);
  background: rgba(255, 64, 129, 0.15);
  color: var(--magenta);
}
.answer-btn:disabled {
  opacity: 0.7;
}

/* --- Timer Bar --- */
.timer-bar-container {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  margin: 8px 16px 12px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--cyan);
  border-radius: 4px;
  transition: width linear, background-color 1s ease;
}
.timer-bar.warning { background: var(--yellow); }
.timer-bar.danger { background: var(--magenta); }

/* --- Reveal Screen --- */
.reveal-result {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
}
.reveal-result.correct { color: var(--green); }
.reveal-result.wrong { color: var(--magenta); }
.reveal-answer {
  font-size: 18px;
  color: var(--text-secondary);
}
.reveal-scores {
  display: flex;
  gap: 16px;
  margin-top: 20px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
  justify-content: center;
}
.reveal-score-entry {
  font-size: 20px;
  color: var(--text-secondary);
}
.reveal-score-entry.me {
  color: var(--cyan);
  font-weight: 700;
}

/* --- Live Scorebar --- */
.live-scorebar {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  min-height: 36px;
  flex-shrink: 0;
  flex-wrap: wrap;
  width: 100%;
}
.live-score-entry {
  font-size: 20px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.live-score-entry.me {
  color: var(--cyan);
  font-weight: 700;
}

/* --- Minigame Area --- */
#minigame-area {
  width: 100%;
  height: 100%;
}
.mg-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.minigame-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
  white-space: pre-line;
}
.minigame-countdown {
  font-size: 72px;
  font-weight: 800;
  color: var(--cyan);
}

/* Speed Tap */
.speed-arrow {
  font-size: 120px;
  font-weight: 300;
  color: var(--cyan);
  line-height: 1;
  transition: color 0.1s;
}
.speed-arrow.wrong { color: var(--magenta); }
.speed-score {
  font-size: 24px;
  color: var(--text-secondary);
  margin-top: 16px;
}

/* Memory Sequence */
.memory-arrow {
  font-size: 100px;
  font-weight: 300;
  color: var(--yellow);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.memory-arrow.flash { opacity: 1; }
.memory-arrow.dim { opacity: 0.2; }
.memory-label {
  font-size: 18px;
  color: var(--text-secondary);
  margin-top: 12px;
}
.memory-round {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Reaction Race */
.reaction-text {
  font-size: 48px;
  font-weight: 800;
  transition: color 0.05s;
}
.reaction-text.waiting { color: var(--text-secondary); }
.reaction-text.go { color: var(--green); }
.reaction-text.false-start { color: var(--magenta); }
.reaction-text.success { color: var(--cyan); }
.reaction-bg { transition: background 0.05s; }
.reaction-bg.go { background: rgba(0, 230, 118, 0.1); }

/* --- Hide and Seek --- */
.has-grid {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 0 16px;
  flex: 1;
}
.has-spot {
  flex: 1;
  max-width: 140px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border: 2px solid var(--bg-tertiary);
  min-height: 120px;
}
.has-spot.picked {
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(0, 230, 118, 0.3);
}
.has-spot-label {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.has-spot-players {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.has-cursor {
  font-size: 32px;
  transition: transform 0.15s ease;
  opacity: 0.6;
}
.has-cursor.me {
  opacity: 1;
  transform: scale(1.2);
}
.has-cursor.locked {
  opacity: 1;
  filter: drop-shadow(0 0 8px var(--yellow));
}
.has-cursor.revealed {
  opacity: 1;
}
.has-cursor.winner {
  filter: drop-shadow(0 0 10px var(--green));
}
.has-cursor.loser {
  filter: drop-shadow(0 0 10px var(--magenta));
}
.has-spot.safe {
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(0, 230, 118, 0.2);
}
.has-spot.crowded {
  border-color: var(--magenta);
  box-shadow: 0 0 16px rgba(255, 64, 129, 0.2);
}
.has-empty {
  font-size: 12px;
  color: var(--text-muted);
}
.has-reveal-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 12px;
  color: var(--text-primary);
}
.has-timer-bar {
  padding: 0 16px;
  margin-bottom: 12px;
}

/* --- Spectator Screen --- */
.spectator-label {
  font-size: 18px;
  margin-bottom: 16px;
}

/* --- Scoreboard --- */
.score-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 340px;
  max-height: 360px;
}
.score-entry {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  gap: 12px;
}
.score-entry .rank {
  font-size: 14px;
  color: var(--text-muted);
  width: 32px;
  font-weight: 700;
}
.score-entry .name {
  flex: 1;
  font-size: 24px;
}
.score-entry .points {
  font-size: 18px;
  font-weight: 700;
  color: var(--cyan);
}
.score-entry .delta {
  font-size: 13px;
  font-weight: 600;
  min-width: 40px;
  text-align: right;
}
.delta.positive { color: var(--green); }
.delta.negative { color: var(--magenta); }
.score-entry.me {
  border: 1px solid var(--cyan);
}
.score-entry.first .rank { color: var(--yellow); }

/* --- Results Screen --- */
.winner-name {
  font-size: 42px;
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 0 30px rgba(255, 214, 0, 0.4);
  margin: 8px 0;
  animation: winner-glow 2s ease-in-out infinite;
}
@keyframes winner-glow {
  0%, 100% { text-shadow: 0 0 30px rgba(255, 214, 0, 0.3); }
  50% { text-shadow: 0 0 50px rgba(255, 214, 0, 0.6); }
}
.winner-subtitle {
  margin-bottom: 20px;
}

/* --- Error Screen --- */
.error-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

/* --- Loading Spinner --- */
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast --- */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  border: 1px solid var(--cyan);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
  max-width: 536px;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--magenta); }
.toast.success { border-color: var(--green); }

/* --- Utility --- */
.hidden { display: none !important; }
