/* === Design Tokens === */
:root {
  --font-display: 'Chillax', 'Trebuchet MS', sans-serif;
  --font-body: 'General Sans', 'Helvetica Neue', sans-serif;
  --color-sky-top: #7ec8e3;
  --color-sky-bottom: #c9e8f5;
  --color-ground: #6abf69;
  --color-text: #2d1b4e;
  --color-text-light: #ffffff;
  --color-surface: rgba(255,255,255,0.92);
  --color-accent: #e0509e;
  --color-accent-hover: #c93d8e;
  --color-p1: #e0509e;
  --color-p2: #6ba4ff;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: clamp(1.8rem, 1rem + 2.5vw, 3rem);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: none;
  touch-action: manipulation;
  background: var(--color-sky-top);
}

.hidden { display: none !important; }

/* === MENU SCREEN === */
#menu-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.menu-bg-canvas-wrap {
  position: absolute; inset: 0; z-index: 0;
}
.menu-bg-canvas-wrap canvas {
  display: block; width: 100%; height: 100%;
}
.menu-content {
  position: relative; z-index: 1;
  text-align: center; padding: var(--space-8) var(--space-4);
}
.title-blob-container { width: 70px; height: 70px; margin: 0 auto var(--space-3); }
.title-blob {
  width: 70px; height: 64px;
  background: var(--color-accent);
  border-radius: 50% 50% 45% 45%;
  position: relative;
  animation: blobBounce 1.2s ease-in-out infinite;
}
.title-blob::before {
  content: ''; position: absolute; top: 19px; left: 15px;
  width: 11px; height: 12px; background: white; border-radius: 50%;
  box-shadow: 24px 0 0 white;
}
.title-blob::after {
  content: ''; position: absolute; top: 22px; left: 19px;
  width: 5px; height: 5px; background: var(--color-text); border-radius: 50%;
  box-shadow: 24px 0 0 var(--color-text);
}
@keyframes blobBounce {
  0%, 100% { transform: translateY(0) scaleX(1) scaleY(1); }
  30% { transform: translateY(-10px) scaleX(0.95) scaleY(1.08); }
  60% { transform: translateY(0) scaleX(1.05) scaleY(0.92); }
}

h1 {
  font-family: var(--font-display); font-size: var(--text-2xl);
  font-weight: 700; color: var(--color-text); line-height: 1.1;
  margin-bottom: var(--space-1);
  text-shadow: 0 2px 0 rgba(255,255,255,0.4);
}
.subtitle {
  font-size: var(--text-base); color: var(--color-text);
  opacity: 0.55; margin-bottom: var(--space-6);
}

.menu-buttons {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
}
.menu-btn {
  font-family: var(--font-display); font-weight: 600;
  border: none; cursor: pointer;
  border-radius: var(--radius-full);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  min-height: 46px;
  -webkit-appearance: none;
  appearance: none;
}
.menu-btn:active { transform: scale(0.96); }
.primary-btn {
  font-size: var(--text-lg); color: var(--color-text-light);
  background: var(--color-accent); padding: var(--space-3) var(--space-8);
  box-shadow: 0 4px 16px rgba(224,80,158,0.4); min-width: 200px;
}
.primary-btn:hover { background: var(--color-accent-hover); transform: translateY(-1px); }
.secondary-btn {
  font-size: var(--text-base); color: var(--color-text);
  background: var(--color-surface); padding: var(--space-2) var(--space-6);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.secondary-btn:hover { background: rgba(255,255,255,1); }
.text-btn {
  font-size: var(--text-sm); color: var(--color-text); opacity: 0.5;
  background: none; padding: var(--space-2) var(--space-4);
}

.join-row {
  display: flex; gap: var(--space-2); align-items: center;
}
#code-input {
  font-family: var(--font-display); font-size: var(--text-lg);
  font-weight: 700; text-align: center; letter-spacing: 0.2em;
  width: 110px; height: 46px; border: 2px solid rgba(45,27,78,0.15);
  border-radius: var(--radius-md); background: rgba(255,255,255,0.85);
  color: var(--color-text); outline: none; text-transform: uppercase;
}
#code-input:focus { border-color: var(--color-accent); }
#code-input::placeholder { letter-spacing: 0.15em; opacity: 0.3; }

.controls-hint { font-size: var(--text-xs); color: var(--color-text); opacity: 0.35; margin-top: var(--space-4); }
.menu-version { position: absolute; bottom: 16px; right: 20px; font-size: 15px; font-weight: 600; color: var(--color-text); opacity: 0.7; margin: 0; }
.menu-error { color: #e74c3c; font-size: var(--text-sm); font-weight: 500; margin-top: var(--space-2); }

/* === LOBBY === */
#lobby-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--color-sky-top), var(--color-sky-bottom));
}
.lobby-content { text-align: center; padding: var(--space-8); }
.lobby-content h2 {
  font-family: var(--font-display); font-size: var(--text-xl);
  font-weight: 700; color: var(--color-text); margin-bottom: var(--space-3);
}
.lobby-instruction { font-size: var(--text-base); color: var(--color-text); opacity: 0.6; margin-bottom: var(--space-3); }
.room-code {
  font-family: var(--font-display); font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 700; color: var(--color-accent); letter-spacing: 0.3em;
  padding: var(--space-4); background: var(--color-surface);
  border-radius: var(--radius-lg); display: inline-block;
  box-shadow: 0 4px 20px rgba(255,107,157,0.2);
  user-select: all; -webkit-user-select: all;
}
.lobby-hint { font-size: var(--text-xs); color: var(--color-text); opacity: 0.4; margin-top: var(--space-3); margin-bottom: var(--space-4); }

.loader-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: var(--space-4); }
.loader-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--color-accent);
  animation: dotPulse 1.2s ease-in-out infinite;
}
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotPulse {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* === GAME AREA === */
#game-area {
  position: fixed; inset: 0; display: flex; flex-direction: column;
}
#game-area.solo-mode .split-half { height: 100%; }
#game-area.solo-mode #split-divider,
#game-area.solo-mode #split-bottom { display: none !important; }

.split-half {
  position: relative; flex: 1; overflow: hidden; min-height: 0;
}
.split-half canvas {
  display: block; width: 100%; height: 100%;
}

#split-divider {
  height: 3px; background: rgba(45,27,78,0.15); flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.split-hud {
  position: absolute; top: var(--space-2); left: var(--space-2); right: var(--space-2);
  display: flex; gap: var(--space-2); pointer-events: none; z-index: 5;
}
.hud-pill {
  background: var(--color-surface);
  padding: 3px 10px; border-radius: var(--radius-full);
  display: flex; align-items: center; gap: 5px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}
.hud-label { font-size: var(--text-xs); font-weight: 600; color: var(--color-text); opacity: 0.4; letter-spacing: 0.04em; }
.hud-val {
  font-size: var(--text-sm); font-weight: 700; color: var(--color-text);
  font-variant-numeric: tabular-nums lining-nums; min-width: 24px; text-align: right;
}
.hud-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 0.05em;
  padding: 1px 6px; border-radius: var(--radius-full); color: white;
}
.p1-badge { background: var(--color-p1); }
.p2-badge { background: var(--color-p2); }

#sound-toggle {
  position: fixed; top: var(--space-2); right: var(--space-2); z-index: 20;
  cursor: pointer; background: var(--color-surface);
  border-radius: var(--radius-full); width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08); color: var(--color-text);
}

/* === GAME OVER === */
#game-over-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.3); backdrop-filter: blur(4px);
}
.gameover-content {
  text-align: center; background: var(--color-surface);
  padding: var(--space-6) var(--space-8); border-radius: var(--radius-xl);
  box-shadow: 0 12px 48px rgba(0,0,0,0.2); min-width: 260px;
  animation: slideUp 0.4s cubic-bezier(0.16,1,0.3,1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.gameover-content h2 {
  font-family: var(--font-display); font-size: var(--text-xl);
  font-weight: 700; color: var(--color-text); margin-bottom: var(--space-4);
}
.final-stats { margin-bottom: var(--space-4); }
.stat-row {
  display: flex; justify-content: space-between;
  padding: var(--space-1) 0; border-bottom: 1px solid rgba(45,27,78,0.06);
}
.stat-row:last-child { border-bottom: none; }
.stat-name { font-size: var(--text-sm); color: var(--color-text); opacity: 0.45; font-weight: 500; }
.stat-val { font-size: var(--text-base); font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums lining-nums; }
.best-row .stat-val { color: var(--color-accent); }

.gameover-content .menu-btn { margin-top: var(--space-2); }
.gameover-content .primary-btn { width: 100%; }

/* === FOOTER === */
.game-footer {
  position: fixed; bottom: var(--space-1); left: 0; right: 0;
  text-align: center; z-index: 5;
}
.game-footer a { font-size: 10px; color: rgba(45,27,78,0.25); text-decoration: none; }
