:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg-dark: #070a14;
  --panel-bg: rgba(15, 23, 42, 0.85);
  --panel-border: rgba(255, 255, 255, 0.12);
  --primary: #00d2ff;
  --neon-cyan: #00f0ff;
  --neon-green: #00ff88;
  --neon-orange: #ffaa00;
  --neon-pink: #ff007f;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-glow: 0 0 25px rgba(0, 210, 255, 0.25);
}

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

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* dvh = fix for Clevertouch/Android bottom clipping */
  overflow: hidden;
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -ms-touch-action: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

button, .single-tap-button, .btn-player-select, .floating-gear-btn, .btn-secondary, .btn-primary, .btn-icon-close, .setting-select {
  touch-action: manipulation;
}

/* Glassmorphic Screens (Safe Zone Conformity) */
.screen {
  position: absolute;
  top: 16px;
  left: 16px;
  width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #131d38 0%, #060913 100%);
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  padding: clamp(16px, 3vh, 32px);
  z-index: 20;
  backdrop-filter: blur(10px);
}

.hidden {
  display: none !important;
}

.screen.hidden {
  display: none !important;
}

/* Header & Titles with Fluid Typography */
.game-logo {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 16px);
  margin-bottom: 4px;
}

.logo-icon {
  font-size: clamp(2rem, 5vw, 3.2rem);
  filter: drop-shadow(0 0 16px var(--primary));
  animation: pulseIcon 2s infinite ease-in-out;
}

@keyframes pulseIcon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1) rotate(5deg); }
}

h1 {
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  font-weight: 900;
  letter-spacing: clamp(2px, 0.5vw, 4px);
  background: linear-gradient(135deg, #ffffff 0%, var(--primary) 50%, #00ff88 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 35px rgba(0, 210, 255, 0.5);
  line-height: 1.1;
}

.kids-subtitle {
  font-size: clamp(1.15rem, 2.8vw, 1.8rem);
  font-weight: 900;
  color: #ffaa00;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  text-shadow: 0 0 20px rgba(255, 170, 0, 0.6);
  margin-bottom: 4px;
  animation: glowPulse 2s infinite ease-in-out;
}

@keyframes glowPulse {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.03); filter: brightness(1.2); }
}

.tagline {
  font-size: clamp(0.9rem, 1.8vw, 1.15rem);
  color: var(--text-dim);
  margin-bottom: clamp(14px, 2.5vh, 24px);
  text-align: center;
  max-width: 90%;
}

/* Stats Header */
.top-bar-stats {
  display: flex;
  gap: clamp(12px, 2vw, 24px);
  margin-bottom: clamp(12px, 2vh, 20px);
  background: rgba(255, 255, 255, 0.05);
  padding: clamp(6px, 1.2vh, 10px) clamp(14px, 2vw, 24px);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-wrap: wrap;
  justify-content: center;
}

.stat-item {
  font-size: clamp(0.95rem, 1.8vw, 1.15rem);
  font-weight: 700;
  color: #e2e8f0;
}

.stat-item span {
  color: var(--neon-cyan);
}

/* Last Round Summary */
.last-round-summary {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 16px);
  margin-top: -6px;
  margin-bottom: clamp(16px, 2.5vh, 26px);
  background: rgba(0, 210, 255, 0.08);
  border: 1px solid rgba(0, 210, 255, 0.3);
  padding: clamp(6px, 1vh, 8px) clamp(10px, 1.8vw, 18px);
  border-radius: var(--radius-md);
  box-shadow: 0 0 15px rgba(0, 210, 255, 0.15);
  flex-wrap: wrap;
  justify-content: center;
}

.last-round-badge {
  font-size: clamp(0.8rem, 1.5vw, 0.9rem);
  font-weight: 800;
  color: var(--neon-cyan);
  background: rgba(0, 210, 255, 0.15);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.last-round-stats {
  display: flex;
  gap: clamp(8px, 1.8vw, 16px);
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  color: #cbd5e1;
}

.last-stat-item strong {
  color: #ffffff;
  font-weight: 800;
}

/* Player Selection Grid */
.player-select-section {
  text-align: center;
  margin-bottom: clamp(14px, 2.5vh, 24px);
  width: 100%;
}

.section-label {
  font-size: clamp(0.85rem, 1.6vw, 1.05rem);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #94a3b8;
  margin-bottom: clamp(10px, 1.8vh, 16px);
}

.player-select-grid {
  display: flex;
  gap: clamp(10px, 1.8vw, 18px);
  flex-wrap: wrap;
  justify-content: center;
}

.btn-player-select {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: clamp(85px, 16vw, 140px);
  padding: clamp(10px, 1.8vh, 18px) clamp(12px, 1.8vw, 24px);
  background: rgba(30, 41, 59, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-player-select .count {
  font-size: clamp(1.6rem, 3.2vw, 2.2rem);
  font-weight: 900;
  color: var(--primary);
  line-height: 1.1;
}

.btn-player-select .label {
  font-size: clamp(0.8rem, 1.4vw, 0.95rem);
  font-weight: 600;
  color: #cbd5e1;
}

.btn-player-select:hover {
  transform: translateY(-3px) scale(1.03);
  border-color: var(--primary);
  box-shadow: 0 0 20px rgba(0, 210, 255, 0.35);
  background: rgba(30, 41, 59, 0.95);
}

.btn-player-select:active {
  transform: scale(0.96);
}

/* Extra Actions (Mute) */
.menu-actions {
  display: flex;
  gap: 16px;
  margin-top: 6px;
}

.btn-secondary {
  padding: clamp(8px, 1.4vh, 12px) clamp(16px, 2vw, 24px);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: #ffffff;
}

/* Game Multi-Lane Split Screen */
#game-container {
  position: absolute;
  top: 12px;
  left: 12px;
  width: calc(100vw - 24px);
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  display: flex;
  gap: 10px;
  overflow: hidden;
  z-index: 5;
}

.player-lane-column {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--accent-color);
  background: #060913;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.6), inset 0 0 15px rgba(0, 0, 0, 0.5);
}

.lane-header {
  padding: clamp(8px, 1.2vh, 12px) clamp(10px, 1.5vw, 16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10, 15, 30, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
  flex-shrink: 0;
}

.player-badge {
  font-weight: 900;
  font-size: clamp(0.75rem, 1.4vw, 0.85rem);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  color: #000;
}

.lane-title {
  font-weight: 800;
  font-size: clamp(0.95rem, 1.6vw, 1.15rem);
  letter-spacing: 0.5px;
}

.lane-stats-bar {
  display: flex;
  gap: clamp(8px, 1.2vw, 12px);
  font-weight: 700;
  font-size: clamp(0.85rem, 1.4vw, 1rem);
}

.stat-score {
  color: #ffffff;
}

.stat-gems {
  color: var(--neon-cyan);
}

/* Canvas Area */
.lane-canvas-wrapper {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  cursor: pointer;
}

.lane-canvas-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Single Tap Control Pad */
.tap-control-area {
  flex: 0 0 auto;
  height: clamp(80px, 15dvh, 125px);
  display: flex;
  background: rgba(10, 15, 30, 0.95);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: clamp(6px, 1.2vh, 12px);
  z-index: 10;
}

.single-tap-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.1s ease;
}

.single-tap-button:active, .tap-control-area.active .single-tap-button {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.97);
  box-shadow: 0 0 20px var(--accent-color);
}

.tap-icon {
  font-size: clamp(1.3rem, 2.5vw, 1.7rem);
}

.tap-label {
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  font-weight: 900;
  letter-spacing: 0.8px;
}

.key-hint {
  font-size: clamp(0.65rem, 1.1vw, 0.75rem);
  font-weight: 600;
  color: #94a3b8;
}

/* Crash Overlay */
.lane-overlay-crashed {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 15;
  backdrop-filter: blur(6px);
  padding: 16px;
  text-align: center;
}

.crash-title {
  font-size: clamp(1.4rem, 2.8vw, 2rem);
  color: #ef4444;
  margin-bottom: 10px;
  text-shadow: 0 0 15px rgba(239, 68, 68, 0.6);
}

.lane-overlay-crashed p {
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  color: #e2e8f0;
  margin-bottom: 4px;
}

/* Global Winner / Restart Banner */
#global-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 30, 0.96);
  border: 3px solid var(--neon-green);
  padding: clamp(20px, 4vh, 32px) clamp(24px, 4vw, 50px);
  border-radius: var(--radius-lg);
  color: #ffffff;
  z-index: 30;
  box-shadow: 0 0 50px rgba(0, 255, 136, 0.4);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 90%;
}

.banner-title {
  font-size: clamp(1.5rem, 3.2vw, 2.2rem);
  font-weight: 900;
  color: var(--neon-green);
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.banner-sub {
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  color: #94a3b8;
}

.btn-restart-now {
  padding: 12px 26px;
  font-size: clamp(0.95rem, 1.8vw, 1.1rem);
  font-weight: 800;
  background: var(--neon-green);
  color: #000;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.1s;
}

.btn-restart-now:active {
  transform: scale(0.95);
}

/* Pre-round 3-2-1 Countdown Overlay */
.countdown-overlay {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
  text-align: center;
}

.countdown-number {
  font-size: clamp(5.5rem, 14vw, 10rem);
  font-weight: 900;
  color: #00f0ff;
  text-shadow: 0 0 45px rgba(0, 240, 255, 0.9), 0 0 90px rgba(0, 210, 255, 0.6);
  line-height: 1;
  animation: countdownPop 0.85s ease-out forwards;
}

.countdown-number.go {
  color: #00ff88;
  text-shadow: 0 0 45px rgba(0, 255, 136, 0.9), 0 0 90px rgba(0, 255, 136, 0.6);
}

.countdown-sub {
  font-size: clamp(1.2rem, 3vw, 2rem);
  font-weight: 900;
  letter-spacing: 3px;
  color: #ffffff;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.7);
  margin-top: 8px;
}

@keyframes countdownPop {
  0% { transform: scale(0.3); opacity: 0; }
  30% { transform: scale(1.15); opacity: 1; }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1); opacity: 0.9; }
}

/* Floating Gear Settings Button (Only on Launch Screen) */
.floating-gear-btn {
  position: absolute;
  bottom: clamp(14px, 2.5vh, 24px);
  right: clamp(14px, 2.5vw, 24px);
  width: clamp(46px, 6.5vw, 56px);
  height: clamp(46px, 6.5vw, 56px);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(0, 210, 255, 0.5);
  font-size: clamp(1.4rem, 2.5vw, 1.85rem);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  z-index: 25;
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.7), 0 0 15px rgba(0, 210, 255, 0.25);
  backdrop-filter: blur(8px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.floating-gear-btn:hover {
  transform: rotate(45deg) scale(1.12);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 25px rgba(0, 210, 255, 0.6);
}

.floating-gear-btn:active {
  transform: scale(0.92);
}

/* Floating Speed Tier Up Notification */
.speedup-notification {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 15, 30, 0.96);
  border: 3px solid #ffaa00;
  border-radius: var(--radius-lg);
  padding: clamp(12px, 2vh, 16px) clamp(20px, 3.5vw, 36px);
  color: #ffaa00;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 25px rgba(255, 170, 0, 0.7);
  box-shadow: 0 0 45px rgba(255, 170, 0, 0.45);
  z-index: 35;
  pointer-events: none;
  animation: speedUpPulse 1.2s forwards cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes speedUpPulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.15); opacity: 0; }
}

/* Settings Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 60;
  backdrop-filter: blur(10px);
  padding: 16px;
}

.settings-modal-content {
  background: #0f172a;
  border: 2px solid rgba(0, 210, 255, 0.3);
  border-radius: var(--radius-lg);
  padding: clamp(18px, 3vh, 28px) clamp(20px, 3vw, 36px);
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.9), 0 0 30px rgba(0, 210, 255, 0.2);
  text-align: left;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.settings-header h2 {
  font-size: clamp(1.4rem, 2.5vw, 1.8rem);
  font-weight: 800;
  color: #ffffff;
}

.btn-icon-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.btn-icon-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.settings-desc {
  font-size: clamp(0.85rem, 1.5vw, 1rem);
  color: var(--text-dim);
  margin-bottom: 20px;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2vh, 18px);
  margin-bottom: 24px;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.setting-label-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  color: #e2e8f0;
}

.setting-value {
  color: var(--neon-cyan);
  font-weight: 800;
  font-size: 1.1rem;
}

input[type="range"] {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
  accent-color: var(--primary);
}

.setting-select {
  width: 100%;
  padding: clamp(8px, 1.2vh, 10px) 14px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: clamp(0.85rem, 1.5vw, 1rem);
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.setting-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px rgba(0, 210, 255, 0.4);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.btn-primary {
  padding: clamp(8px, 1.4vh, 12px) clamp(16px, 2vw, 24px);
  background: var(--primary);
  color: #000000;
  border: none;
  border-radius: var(--radius-md);
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: var(--neon-cyan);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
}

.btn-primary:active {
  transform: scale(0.96);
}
