/* ═══════════════════════════════════════════
   Mini Games Arena — Mobile-First Styles
   ═══════════════════════════════════════════ */

:root {
  --bg: #1a0a0e;
  --surface: #2a1118;
  --surface-hover: #3a1a24;
  --primary: #8b1a2b;
  --primary-hover: #a32236;
  --secondary: #3d1520;
  --secondary-hover: #4d1f2d;
  --accent: #e8a0b0;
  --danger: #ff6b6b;
  --success: #00b894;
  --warning: #fdcb6e;
  --text: #f5e6ea;
  --text-dim: #b88a95;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

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

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

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

/* ─── Screens ─── */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ─── Typography ─── */

.logo-wrapper {
  text-align: center;
  margin-bottom: 16px;
}

.logo-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 50%;
  filter: drop-shadow(0 0 12px rgba(139, 26, 43, 0.4));
  animation: logoFadeIn 0.8s ease-out;
}

@keyframes logoFadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.logo {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 4px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

h2 {
  font-size: 1.3rem;
  margin-bottom: 16px;
}

/* ─── Buttons ─── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.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(--secondary);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

.btn-large {
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
  margin-top: 16px;
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px 0;
  align-self: flex-start;
  margin-bottom: 8px;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-accent {
  background: linear-gradient(135deg, var(--primary), #c0354d);
  color: white;
  border: none;
}

.btn-accent:hover {
  background: linear-gradient(135deg, var(--primary-hover), #d04060);
}

/* ─── Inputs ─── */

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition);
}

input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--primary);
}

input::placeholder {
  color: var(--text-dim);
}

.name-input-group {
  margin-bottom: 24px;
}

/* ─── Home ─── */

#screen-home .container {
  justify-content: center;
}

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

.home-actions .btn-primary {
  width: 100%;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 4px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--secondary);
}

.join-group {
  display: flex;
  gap: 8px;
}

.join-group input {
  flex: 1;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 4px;
  font-weight: 700;
  font-size: 1.2rem;
}

.join-group .btn {
  flex-shrink: 0;
}

/* ─── Game List ─── */

.games-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  flex: 1;
}

.game-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  border: 2px solid transparent;
}

.game-card:hover {
  background: var(--surface-hover);
}

.game-card:active {
  transform: scale(0.98);
  border-color: var(--primary);
}

.game-card h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.game-card p {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.4;
}

.game-card .game-meta {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--accent);
}

/* ─── Lobby ─── */

.room-code-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.room-code-display strong {
  font-size: 1.5rem;
  letter-spacing: 4px;
  color: var(--accent);
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

.player-chip .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.player-chip .host-badge {
  background: var(--warning);
  color: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-left: auto;
}

.waiting-text {
  text-align: center;
  color: var(--text-dim);
  margin-top: 16px;
  animation: pulse 2s ease-in-out infinite;
}

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

/* ─── Game Header ─── */

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--secondary);
}

#game-title {
  font-weight: 700;
  font-size: 1rem;
}

.game-timer {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  padding: 4px 10px;
  border-radius: 8px;
  letter-spacing: 0.5px;
}

.result-time {
  text-align: center;
  font-size: 1.2rem;
  color: var(--accent);
  padding: 12px 0;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--secondary);
}

#game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ─── Results ─── */

#screen-results .container {
  justify-content: center;
  align-items: center;
  text-align: center;
}

#results-content {
  width: 100%;
  margin-bottom: 24px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.result-row.winner {
  border: 2px solid var(--warning);
}

.result-row .rank {
  font-size: 1.3rem;
  min-width: 36px;
}

.result-row .name {
  flex: 1;
  text-align: left;
  margin-left: 8px;
}

.result-row .score {
  font-weight: 700;
  color: var(--accent);
}

/* ─── Toast ─── */

#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  background: var(--surface);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.9rem;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.5s forwards;
  border-left: 4px solid var(--primary);
}

.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

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

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ═══════════════════════════════════════════
   Game-specific styles
   ═══════════════════════════════════════════ */

/* ─── Reaction Race ─── */

.reaction-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: background 0.15s;
  min-height: 250px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.reaction-zone.waiting { background: var(--danger); }
.reaction-zone.go { background: var(--success); }
.reaction-zone.idle { background: var(--surface); }

.reaction-zone .reaction-text {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  padding: 16px;
}

.scores-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.score-chip {
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.score-chip.me {
  border: 1px solid var(--primary);
}

/* ─── Tap Battle ─── */

.tap-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.tap-button {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  color: white;
  font-size: 2.5rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.tap-button:active {
  transform: scale(0.92);
}

.tap-timer {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.tap-scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

/* ─── Memory Match ─── */

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
  width: 100%;
}

.memory-card {
  aspect-ratio: 1;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s, background 0.25s;
  -webkit-tap-highlight-color: transparent;
}

.memory-card.flipped {
  background: var(--surface);
  transform: rotateY(0deg);
}

.memory-card.matched {
  background: var(--success);
  opacity: 0.7;
  cursor: default;
}

.memory-card:not(.flipped):not(.matched) span {
  display: none;
}

.turn-indicator {
  text-align: center;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
}

.turn-indicator.my-turn {
  background: var(--primary);
  color: white;
}

.turn-indicator.their-turn {
  background: var(--secondary);
  color: var(--text-dim);
}

/* ─── Math Duel ─── */

.math-question {
  font-size: 2.5rem;
  font-weight: 700;
  text-align: center;
  padding: 24px 0;
  color: var(--accent);
}

.math-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.math-input-group input {
  flex: 1;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.math-input-group .btn {
  flex-shrink: 0;
  font-size: 1.1rem;
}

.math-feedback {
  text-align: center;
  font-size: 1.1rem;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.math-progress {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

/* ─── Racing ─── */

.race-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.race-distance {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.race-speed {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.race-opponents {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 18px;
  margin-bottom: 4px;
}

.race-opp.crashed {
  color: #ff6b6b;
  text-decoration: line-through;
}

.race-canvas-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-radius: var(--radius);
  background: #222;
  min-height: 300px;
}

#race-canvas {
  display: block;
  border-radius: var(--radius);
}

.race-controls {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.race-ctrl-btn {
  flex: 1;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s, background 0.15s;
}

.race-ctrl-btn:active {
  transform: scale(0.95);
  background: var(--primary-hover);
}

/* ─── Emoji Catch ─── */

.emoji-target {
  text-align: center;
  font-size: 1.1rem;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
}

.emoji-target span {
  font-size: 2.5rem;
  display: block;
  margin-top: 4px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
  width: 100%;
}

.emoji-cell {
  aspect-ratio: 1;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, border-color 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.emoji-cell:active {
  transform: scale(0.9);
  border-color: var(--primary);
}

.emoji-progress {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.emoji-feedback {
  text-align: center;
  font-size: 1.1rem;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
}

/* ═══════════════════════════════════════════
   Responsive — larger screens
   ═══════════════════════════════════════════ */

@media (min-width: 600px) {
  .container {
    max-width: 560px;
    padding: 32px 24px;
  }

  .games-grid {
    grid-template-columns: 1fr 1fr;
  }

  .logo {
    font-size: 2.5rem;
  }

  .memory-grid {
    max-width: 420px;
    gap: 10px;
  }

  .memory-card {
    font-size: 2.2rem;
  }
}

/* ═══════════════════════════════════════════
   Mode Choice Overlay
   ═══════════════════════════════════════════ */

.mode-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.mode-overlay.hidden {
  display: none;
}

.mode-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-card h3 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 8px;
}

/* ═══════════════════════════════════════════
   Lobby
   ═══════════════════════════════════════════ */

#screen-lobby .room-code-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

#screen-lobby .room-code-display strong {
  font-size: 1.8rem;
  letter-spacing: 5px;
  color: var(--accent);
  flex: 1;
  text-align: center;
}

#lobby-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

#lobby-waiting {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 16px;
  animation: pulse 2s ease-in-out infinite;
}
