/* Mini Games Platform — Mobile-first styles */
:root {
  --bg: #0f0f23;
  --surface: #1a1a2e;
  --surface2: #252545;
  --primary: #6c63ff;
  --primary-hover: #5a52d5;
  --accent: #ff6584;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #ef4444;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --radius: 12px;
  --radius-sm: 8px;
}

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

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

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
}

/* Screens */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: calc(100dvh - 32px); }

/* HOME */
.home-hero {
  text-align: center;
  padding: 40px 0 24px;
}
.logo { font-size: 64px; margin-bottom: 8px; }
.home-hero h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle { color: var(--text-dim); margin-top: 8px; font-size: 15px; }

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
}

input[type="text"] {
  background: var(--surface);
  border: 2px solid var(--surface2);
  color: var(--text);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--primary); }
input[type="text"]::placeholder { color: var(--text-dim); }

.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover { background: #2f2f55; }
.btn-small { padding: 8px 16px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-large { padding: 18px; font-size: 18px; margin-top: 16px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--surface2);
}

.join-row {
  display: flex;
  gap: 8px;
}
.join-row input { flex: 1; text-align: center; font-size: 20px; letter-spacing: 4px; font-weight: 700; }
.join-row .btn { flex-shrink: 0; }

.error-msg {
  color: var(--red);
  text-align: center;
  font-size: 14px;
  min-height: 20px;
  margin-top: 12px;
}

/* LOBBY */
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
}
.lobby-header h2 { font-size: 20px; }
.code-badge {
  font-family: monospace;
  font-size: 24px;
  background: var(--primary);
  color: white;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  letter-spacing: 3px;
}

.players-section { margin: 16px 0; }
.players-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.players-section h3 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.btn-bot { background: var(--surface2); border: 1px dashed var(--text-dim); font-size: 12px; padding: 6px 12px; }
#player-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
#player-list li {
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
#player-list li .host-badge { font-size: 11px; }
.bot-badge {
  font-size: 10px;
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 4px;
  color: var(--text-dim);
}
.remove-bot {
  margin-left: 6px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12px;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.remove-bot:hover { opacity: 1; color: var(--red); }

.game-picker { margin: 20px 0; }
.game-picker h3 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }
.game-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.game-card:hover { border-color: var(--surface2); }
.game-card.selected { border-color: var(--primary); background: #1e1e40; }
.game-card .game-icon { font-size: 32px; margin-bottom: 6px; }
.game-card .game-name { font-size: 14px; font-weight: 600; }
.game-card .game-desc { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

.waiting-text { text-align: center; color: var(--text-dim); padding: 20px; font-size: 15px; }

/* GAME HUD */
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--surface2);
  margin-bottom: 16px;
}
.game-title { font-weight: 700; font-size: 16px; }
.game-round { font-size: 13px; color: var(--text-dim); }

.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* RESULTS */
.results-content {
  padding: 24px 0;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.results-content h2 { font-size: 28px; margin-bottom: 24px; }

.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 24px;
  min-height: 180px;
}
.podium-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.podium-bar {
  width: 80px;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12px;
  font-size: 24px;
  font-weight: 800;
}
.podium-name { font-size: 14px; font-weight: 600; }
.podium-score { font-size: 12px; color: var(--text-dim); }
.podium-item.rank-1 .podium-bar { height: 120px; background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.podium-item.rank-2 .podium-bar { height: 90px; background: linear-gradient(180deg, #94a3b8, #64748b); }
.podium-item.rank-3 .podium-bar { height: 70px; background: linear-gradient(180deg, #cd7c32, #a0522d); }

.results-list {
  list-style: none;
  text-align: left;
  margin: 0 auto;
  width: 100%;
  max-width: 360px;
}
.results-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}
.results-list li:nth-child(odd) { background: var(--surface); }
.results-list .rank { color: var(--text-dim); width: 30px; }
.results-list .score { font-weight: 700; color: var(--primary); }

/* GAME-SPECIFIC STYLES */

/* Reaction Race */
.reaction-zone {
  width: 100%;
  height: 300px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
  margin: 20px 0;
}
.reaction-zone.waiting { background: var(--surface2); }
.reaction-zone.ready { background: var(--red); color: white; }
.reaction-zone.go { background: var(--green); color: #0f0f23; }
.reaction-zone.early { background: var(--yellow); color: #0f0f23; }

/* Trivia */
.trivia-question {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  padding: 20px;
  line-height: 1.4;
}
.trivia-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin-top: 16px;
}
.trivia-option {
  background: var(--surface);
  border: 2px solid var(--surface2);
  color: var(--text);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.trivia-option:hover { border-color: var(--primary); }
.trivia-option.selected { border-color: var(--primary); background: #1e1e40; }
.trivia-option.correct { border-color: var(--green); background: #0d2818; }
.trivia-option.wrong { border-color: var(--red); background: #2a0a0a; }
.trivia-timer {
  width: 100%;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  margin: 16px 0;
  overflow: hidden;
}
.trivia-timer-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s linear;
}

/* Tap Frenzy */
.tap-zone {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  transition: transform 0.05s;
  margin: 20px 0;
}
.tap-zone:active { transform: scale(0.93); }
.tap-leaderboard {
  width: 100%;
  margin-top: 16px;
}
.tap-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}
.tap-bar {
  flex: 1;
  height: 24px;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}
.tap-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 12px;
  transition: width 0.3s;
}
.tap-bar-count {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 700;
}

/* Word Scramble */
.scramble-word {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 8px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 20px 0;
  font-family: monospace;
}
.scramble-input {
  display: flex;
  gap: 8px;
  width: 100%;
}
.scramble-input input {
  flex: 1;
  text-align: center;
  font-size: 20px;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.scramble-hint { color: var(--text-dim); font-size: 13px; margin-top: 8px; }
.scramble-solvers {
  width: 100%;
  margin-top: 20px;
}
.solver-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 14px;
}
.solver-rank { color: var(--yellow); font-weight: 700; }

/* Emoji Match */
.emoji-board {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 360px;
  margin: 16px auto;
}
.emoji-cell {
  aspect-ratio: 1;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.emoji-cell.revealed { background: var(--surface); }
.emoji-cell.matched { background: #0d2818; border: 2px solid var(--green); opacity: 0.7; }
.emoji-cell.hidden::after { content: '❓'; }
.emoji-turn-info {
  text-align: center;
  font-size: 16px;
  padding: 8px;
  color: var(--text-dim);
}
.emoji-turn-info .current { color: var(--primary); font-weight: 700; }

/* Math Blitz */
.math-problem {
  font-size: 42px;
  font-weight: 800;
  text-align: center;
  padding: 28px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 16px 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 2px;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.math-timer-bar {
  width: 100%;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0 16px;
}
.math-timer-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: background 0.3s;
  width: 100%;
}
.math-input-area {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}
.math-answer-input {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--surface2);
  color: var(--text);
  padding: 16px;
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
.math-answer-input::-webkit-inner-spin-button,
.math-answer-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.math-answer-input:focus { border-color: var(--primary); }
.math-submit {
  width: 56px;
  font-size: 20px;
  flex-shrink: 0;
}
.math-feedback {
  text-align: center;
  font-size: 15px;
  padding: 12px;
  margin-top: 12px;
  border-radius: var(--radius-sm);
  white-space: pre-line;
  min-height: 40px;
}
.math-feedback.correct { color: var(--green); background: #0d2818; }
.math-feedback.wrong { color: var(--red); background: #2a0a0a; }
.math-feedback.result { color: var(--text); background: var(--surface); }
.math-level {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 8px;
}

/* Simon Says */
.simon-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 280px;
  margin: 20px auto;
}
.simon-pad {
  aspect-ratio: 1;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  border: 3px solid transparent;
  opacity: 0.5;
}
.simon-pad.red { background: #dc2626; }
.simon-pad.blue { background: #2563eb; }
.simon-pad.green { background: #16a34a; }
.simon-pad.yellow { background: #eab308; }

.simon-pad.lit {
  opacity: 1;
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(255,255,255,0.3);
}

.simon-board.input-mode .simon-pad {
  opacity: 0.7;
  cursor: pointer;
}
.simon-board.input-mode .simon-pad:hover {
  opacity: 0.9;
}
.simon-board.input-mode .simon-pad:active,
.simon-pad.pressed {
  opacity: 1;
  transform: scale(0.95);
}

.simon-board.showing-mode .simon-pad {
  cursor: default;
  opacity: 0.4;
}

.simon-board.eliminated .simon-pad {
  opacity: 0.2;
  cursor: not-allowed;
}

.simon-progress {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 12px;
  min-height: 28px;
}
.simon-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 8px;
}

/* Countdown overlay */
.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.countdown-number {
  font-size: 120px;
  font-weight: 800;
  color: var(--primary);
  animation: countPulse 0.5s ease-out;
}
@keyframes countPulse {
  from { transform: scale(2); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Game status messages */
.game-status {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  margin: 12px 0;
}
.game-status.success { background: #0d2818; color: var(--green); }
.game-status.warning { background: #2a1a00; color: var(--yellow); }
.game-status.info { background: #1a1a2e; color: var(--text); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.fade-in { animation: fadeIn 0.3s ease-out; }
.shake { animation: shake 0.3s ease; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 2px; }

/* Reconnect overlay */
#reconnect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 35, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.reconnect-content { text-align: center; }
.reconnect-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--surface2);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reconnect-text { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.reconnect-sub { font-size: 14px; color: var(--text-dim); }

/* Away badge */
.away-badge {
  font-size: 11px;
  margin-left: 4px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 200;
  animation: fadeIn 0.2s;
}
