:root {
  --primary: #2e7d32;
  --primary-glow: rgba(46, 125, 50, 0.4);
  --accent: #ff9800;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  --card-bg: rgba(30, 41, 59, 0.85);
  --card-border: rgba(255, 255, 255, 0.12);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --rank-gold: #ffd700;
  --rank-silver: #c0c0c0;
  --rank-bronze: #cd7f32;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* GESTIÓN DE PANTALLAS */
.screen {
  display: none;
  width: 100%;
  max-width: 500px;
  padding: 16px;
  animation: fadeIn 0.3s ease-out forwards;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* TARJETAS GLASSMORPHISM */
.glass-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
}

.text-center {
  text-align: center;
}

.logo-badge {
  display: inline-block;
  background: rgba(46, 125, 50, 0.25);
  border: 1px solid var(--primary);
  color: #4ade80;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.title {
  font-size: 1.9rem;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 4px;
}

.subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* FORMULARIO */
.input-group {
  margin-bottom: 18px;
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1.5px solid var(--card-border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.1rem;
  color: #ffffff;
  font-weight: 600;
  outline: none;
  transition: all 0.2s ease;
}

.input-group input:focus {
  border-color: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

/* SELECTOR DE COLOR */
.color-picker-section {
  margin-bottom: 24px;
  text-align: left;
}

.color-picker-section label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
}

.color-options {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.color-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c);
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.color-btn:hover {
  transform: scale(1.1);
}

.color-btn.active {
  border-color: #ffffff;
  transform: scale(1.15);
  box-shadow: 0 0 15px var(--c);
}

/* BOTONES */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #ffffff;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:active {
  transform: scale(0.98);
  box-shadow: 0 4px 10px rgba(34, 197, 94, 0.25);
}

.error-msg {
  color: #f87171;
  font-size: 0.9rem;
  margin-top: 14px;
  text-align: center;
  font-weight: 600;
}

/* LOBBY DE ESPERA */
.room-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.95rem;
  color: #cbd5e1;
  margin-bottom: 20px;
}

.room-tag strong {
  color: #38bdf8;
  letter-spacing: 2px;
  font-size: 1.1rem;
}

.dino-avatar-preview {
  margin: 10px auto 16px;
  width: 90px;
  height: 90px;
}

.avatar-ring {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(46, 125, 50, 0.2);
  border: 3px solid #22c55e;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}

.avatar-icon {
  font-size: 2.8rem;
}

.player-heading {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

.status-pill.pulse {
  animation: pulseGlow 1.5s infinite alternate;
}

@keyframes pulseGlow {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

.waiting-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 20px;
}

.players-counter-badge {
  font-size: 0.9rem;
  color: #cbd5e1;
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 16px;
  border-radius: 12px;
}

/* CUENTA REGRESIVA */
#screen-countdown {
  position: fixed;
  inset: 0;
  max-width: none;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  z-index: 100;
}

.countdown-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.countdown-number {
  font-size: 8rem;
  font-weight: 900;
  color: #22c55e;
  text-shadow: 0 0 40px rgba(34, 197, 94, 0.8);
  animation: popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) infinite;
}

.countdown-text {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: #f8fafc;
}

@keyframes popIn {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* PANTALLA DE JUEGO ACTIVO */
#screen-game {
  max-width: 650px;
  padding: 8px 12px;
}

.game-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 8px 14px;
  margin-bottom: 10px;
}

.hud-item {
  display: flex;
  flex-direction: column;
}

.hud-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.hud-value {
  font-size: 1.15rem;
  font-weight: 800;
}

.hud-rank .hud-value {
  color: #fbbf24;
}

.leader-name {
  color: #38bdf8;
  font-size: 0.95rem;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-val {
  color: #4ade80;
  font-family: monospace;
}

.rank-toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(34, 197, 94, 0.95);
  color: #ffffff;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

.rank-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(4px);
}

.rank-toast.down {
  background: rgba(239, 68, 68, 0.95);
}

.game-viewport-wrapper {
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 150px;
}

.dino-runner-canvas-box {
  width: 100%;
  max-width: 600px;
  min-height: 150px;
  position: relative;
  margin: 0 auto;
}

.runner-container {
  position: relative;
  width: 100%;
  max-width: 600px;
  height: 150px;
  overflow: hidden;
  margin: 0 auto;
}

.runner-canvas {
  position: relative;
  top: 0;
  left: 0;
  display: block;
  margin: 0 auto;
  width: 100%;
  height: 150px;
  z-index: 2;
}

.touch-controls-bar {
  width: 100%;
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.touch-btn {
  flex: 1;
  padding: 16px 8px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  font-weight: 800;
  font-size: 0.95rem;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  touch-action: manipulation;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.touch-btn:active {
  transform: scale(0.95);
  filter: brightness(1.2);
}

.duck-btn {
  background: linear-gradient(135deg, #475569 0%, #334155 100%);
}

.jump-btn {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  box-shadow: 0 6px 16px rgba(22, 163, 74, 0.35);
}

/* PANTALLA DE CHOCADO */
.crash-icon {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.crash-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 20px;
}

.final-stats-grid {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  flex: 1;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
}

.stat-lbl {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-num {
  font-size: 1.5rem;
  color: #38bdf8;
  font-family: monospace;
}

/* PODIO */
.podium-badge {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.top3-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 18px 0;
}

.top3-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 14px;
}

.top3-item.rank-1 {
  border-color: #ffd700;
  background: rgba(255, 215, 0, 0.12);
}

.top3-item.rank-2 {
  border-color: #c0c0c0;
  background: rgba(192, 192, 192, 0.1);
}

.top3-item.rank-3 {
  border-color: #cd7f32;
  background: rgba(205, 127, 50, 0.1);
}

.your-final-result {
  background: rgba(46, 125, 50, 0.25);
  border: 1px solid var(--primary);
  padding: 12px;
  border-radius: 12px;
  font-size: 1rem;
  color: #4ade80;
}
