* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: #0e0e12;
  color: #eaeaf0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}

:root {
  --controlScale: 1;
  --homeScale: 1;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  z-index: 10;
}

.bar { display: flex; align-items: center; gap: 8px; flex: 1 1 0; min-width: 0; }
.label { font-weight: 600; font-size: calc(12px * var(--controlScale)); color: #a7a7b3; }
.value { font-size: calc(12px * var(--controlScale)); color: #d3d3dc; font-weight: 600; }
.hud-score {
  font-weight: 700;
  font-size: calc(12px * var(--controlScale));
  color: #dfe7ff;
  padding: 6px 10px;
  background: rgba(75, 113, 255, 0.12);
  border: 1px solid #2b2b36;
  border-radius: 10px;
}
.track {
  flex: 1 1 auto;
  height: calc(12px * var(--controlScale));
  background: #2a2a34;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}

/* Make mobile buttons scale more with screen size */
.buttons button {
  font-size: calc(16px * var(--controlScale));
  padding: calc(8px * var(--controlScale)) calc(12px * var(--controlScale));
}

/* Slightly thicken joystick visuals on small screens via the same scale */
#joystick .stick {
  border-width: calc(4px * var(--controlScale));
}
.fill {
  height: 100%;
  width: 100%;
  transition: width 100ms linear;
}
.fill.red { background: linear-gradient(90deg, #ff4d4d, #d82323); }
.fill.green { background: linear-gradient(90deg, #62ff8e, #20b455); }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.6);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
  overflow-y: auto; /* allow scrolling if content is taller than the viewport */
}
.overlay.visible { opacity: 1; pointer-events: auto; }
.overlay.home { background: rgba(0,0,0,0.70); }

.ghost-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.ghost {
  position: absolute;
  opacity: 1; /* solid, no transparency */
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.35));
}
.ghost .shape {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  top: 0;
  width: 100%; height: 70%;
  background: #ffffff;
  border-radius: 60% 60% 36% 36% / 52% 52% 32% 32%;
}
.ghost .arm {
  position: absolute;
  width: 30%; height: 28%;
  top: 26%;
  background: #ffffff;
  border-radius: 50%;
}
.ghost .arm.left { left: -10%; transform: rotate(-18deg); }
.ghost .arm.right { right: -10%; transform: rotate(18deg); }
.ghost .lobe {
  position: absolute;
  bottom: -6%;
  width: 26%; height: 26%;
  background: #ffffff;
  border-radius: 50%;
}
.ghost .lobe.l1 { left: 15%; }
.ghost .lobe.l2 { left: 42%; }
.ghost .lobe.l3 { left: 69%; }
.ghost .eye {
  position: absolute;
  width: 11%; height: 11%;
  border-radius: 50%;
  background: #0f0f12; /* solid eyes */
  top: 30%;
}
.ghost .eye.left { left: 32%; }
.ghost .eye.right { right: 32%; }

/* placements */
.ghost.g1 { width: 160px; height: 180px; top: 8%; left: 6%; transform: rotate(-6deg); }
.ghost.g2 { width: 120px; height: 140px; top: 64%; left: 10%; transform: rotate(8deg); }
.ghost.g3 { width: 140px; height: 160px; top: 18%; right: 8%; transform: rotate(4deg); }
.ghost.g4 { width: 180px; height: 200px; bottom: 8%; right: 6%; transform: rotate(-8deg); }
.ghost.g5 { width: 90px; height: 110px; top: 42%; left: 46%; transform: rotate(2deg); }
.ghost.g6 { width: 110px; height: 130px; bottom: 18%; left: 70%; transform: rotate(-3deg); }

/* Game Over panel remains */
.panel {
  background: #16161d;
  border: 1px solid #2b2b36;
  border-radius: 12px;
  padding: 24px 28px;
  width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  text-align: center;
}
.panel h1 { margin: 0 0 8px; font-size: 22px; }
.panel p { margin: 0 0 16px; color: #bcbcc9; }
.final-score { font-weight: 700; color: #eaeaf0; margin-bottom: calc(24px * var(--homeScale)); font-size: calc(18px * var(--homeScale)); }
.panel button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: #4b71ff;
  color: white;
  font-weight: 600;
  cursor: pointer;
}
.panel button:hover { background: #365aff; }

/* Home brand mark */
/* New Home design (from src/main home) */
.home-gradient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(150vmax circle at 50% 42%, rgba(13, 91, 255, 0.18), rgba(13, 91, 255, 0) 78%),
    linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.55) 60%, rgba(0,0,0,0.85) 100%),
    #0e0e12; /* match game background */
  z-index: 0;
}
.floating-ghosts {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}
.floating-ghosts .ghost {
  position: absolute;
  font-size: calc(60px * var(--homeScale));
  opacity: 0.12; /* softer to match game tone */
  animation: float 15s infinite ease-in-out;
}
.floating-ghosts .ghost:nth-child(1) { left: 10%; top: 20%; animation-delay: 0s; }
.floating-ghosts .ghost:nth-child(2) { left: 80%; top: 60%; animation-delay: 3s; }
.floating-ghosts .ghost:nth-child(3) { left: 30%; top: 70%; animation-delay: 6s; }
.floating-ghosts .ghost:nth-child(4) { left: 70%; top: 30%; animation-delay: 9s; }
.floating-ghosts .ghost:nth-child(5) { left: 50%; top: 10%; animation-delay: 12s; }

@keyframes float {
  0%, 100% { transform: translateY(0px) translateX(0px) rotate(0deg); }
  25% { transform: translateY(-30px) translateX(20px) rotate(5deg); }
  50% { transform: translateY(-60px) translateX(-20px) rotate(-5deg); }
  75% { transform: translateY(-30px) translateX(20px) rotate(3deg); }
}

.container {
  position: relative;
  z-index: 2;
  text-align: center;
  animation: fadeIn 0.8s ease-in;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}
.title {
  font-size: calc(56px * var(--homeScale));
  font-weight: 800;
  color: #eaeaf0; /* game text color */
  text-shadow: 0 0 20px rgba(75, 113, 255, 0.50), 0 0 40px rgba(75, 113, 255, 0.28);
  margin-bottom: 16px;
  letter-spacing: 3px;
}
.subtitle {
  font-size: calc(20px * var(--homeScale));
  color: #bcbcc9; /* game secondary text */
  margin-bottom: 40px;
  text-shadow: none;
}
.menu-buttons { display: flex; align-items: center; justify-content: center; gap: calc(16px * var(--homeScale)); flex-wrap: wrap; }
.menu-btn {
  background: #4b71ff; /* game accent */
  color: white;
  border: none;
  padding: calc(16px * var(--homeScale)) calc(64px * var(--homeScale));
  font-size: calc(20px * var(--homeScale));
  font-weight: 700;
  border-radius: calc(40px * var(--homeScale));
  width: min(calc(360px * var(--homeScale)), 80vw);
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 5px 20px rgba(75, 113, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 2px;
  position: relative;
  overflow: hidden;
}
.menu-btn.secondary-btn {
  background: #363b55;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
}
.menu-btn::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

/* Tighter vertical spacing on Start overlay */
#startOverlay .game-icon { margin-bottom: calc(4px * var(--homeScale)); }
#startOverlay .title { margin-bottom: calc(4px * var(--homeScale)); line-height: 1.03; }
#startOverlay .subtitle { margin-bottom: calc(8px * var(--homeScale)); line-height: 1.2; }
#startOverlay .menu-buttons { gap: calc(8px * var(--homeScale)); }

/* Smaller sizes on Start overlay */
#startOverlay .game-icon { transform: scale(0.9); }
#startOverlay .title { font-size: calc(44px * var(--homeScale)); }
#startOverlay .subtitle { font-size: calc(16px * var(--homeScale)); }
#startOverlay .menu-btn {
  font-size: calc(18px * var(--homeScale));
  padding: calc(12px * var(--homeScale)) calc(40px * var(--homeScale));
  border-radius: calc(28px * var(--homeScale));
  width: min(calc(300px * var(--homeScale)), 70vw);
}
.menu-btn:hover::before { width: 300px; height: 300px; }
.menu-btn:hover { transform: translateY(-5px); box-shadow: 0 8px 30px rgba(75, 113, 255, 0.6); background: #365aff; }
.menu-btn:active { transform: translateY(-2px); }
.secondary-btn { background: #2b2b36; box-shadow: 0 5px 20px rgba(43, 43, 54, 0.45); }
.secondary-btn:hover { box-shadow: 0 8px 30px rgba(43, 43, 54, 0.6); }
.game-icon {
  position: relative;
  width: calc(120px * var(--homeScale));
  height: calc(120px * var(--homeScale));
  margin: 0 auto calc(24px * var(--homeScale));
  border-radius: 50%;
  background: #0d5bff;
  box-shadow: 0 0 0 calc(6px * var(--homeScale)) rgba(124,240,255,0.22), inset 0 0 calc(20px * var(--homeScale)) rgba(0,0,0,0.25), 0 calc(10px * var(--homeScale)) calc(40px * var(--homeScale)) rgba(66, 133, 244, 0.35);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.game-icon .eye {
  position: absolute;
  width: calc(18px * var(--homeScale));
  height: calc(18px * var(--homeScale));
  border-radius: 50%;
  background: #ffffff;
  top: calc(36px * var(--homeScale));
}
.game-icon .eye.left { left: calc(32px * var(--homeScale)); }
.game-icon .eye.right { right: calc(32px * var(--homeScale)); }
.game-icon .mouth {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: calc(34px * var(--homeScale));
  width: calc(64px * var(--homeScale));
  height: calc(10px * var(--homeScale));
  background: #ffffff;
  border-radius: calc(8px * var(--homeScale));
}
/* Remove the face icon from the You Died overlay only */
#gameOverOverlay .game-icon { display: none; }

/* Tighter spacing on the Start overlay */
#startOverlay .game-icon { margin: 0 auto calc(16px * var(--homeScale)); }
#startOverlay .title { margin-bottom: calc(12px * var(--homeScale)); }
#startOverlay .subtitle { margin-bottom: calc(24px * var(--homeScale)); }
.stats-preview { display: flex; gap: calc(24px * var(--homeScale)); justify-content: center; margin-top: calc(36px * var(--homeScale)); color: #a8dadc; }
.stat-item { text-align: center; }
.stat-value { font-size: calc(28px * var(--homeScale)); font-weight: 800; color: #dfe7ff; text-shadow: 0 0 10px rgba(75, 113, 255, 0.35); }
.stat-label { font-size: calc(12px * var(--homeScale)); text-transform: uppercase; letter-spacing: 1px; margin-top: calc(5px * var(--homeScale)); color: #a7a7b3; }

/* Short viewport adjustments to prevent clipping on You Died / Start overlays */
@media (max-height: 720px) {
  .overlay.home .container { padding-bottom: calc(12px * var(--homeScale)); }
  .game-icon { transform: scale(0.92); }
  .subtitle { margin-bottom: calc(24px * var(--homeScale)); }
  .menu-buttons { gap: calc(12px * var(--homeScale)); }
  .menu-btn { padding: calc(14px * var(--homeScale)) calc(52px * var(--homeScale)); }
}

@media (max-height: 620px) {
  .overlay.home { place-items: center; }
  .title { font-size: calc(48px * var(--homeScale)); }
  .subtitle { font-size: calc(18px * var(--homeScale)); }
  .menu-buttons { flex-direction: column; }
  .menu-btn { width: min(calc(360px * var(--homeScale)), 92vw); }
}

.controls {
  text-align: left;
  margin: 0 0 16px;
  padding-left: 18px;
  color: #bcbcc9;
}
.controls li { margin-bottom: 4px; }

/* Mobile Controls */
.mobile-controls {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 15;
  pointer-events: none; /* enable per-child */
}

.joystick {
  width: calc(120px * var(--controlScale));
  height: calc(120px * var(--controlScale));
  background: rgba(255,255,255,0.05);
  border: 1px solid #2b2b36;
  border-radius: 50%;
  position: relative;
  pointer-events: auto;
  touch-action: none;
}
.joystick .stick {
  width: calc(56px * var(--controlScale));
  height: calc(56px * var(--controlScale));
  background: rgba(124,240,255,0.22);
  border: 2px solid #7cf0ff;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: auto;
}
.buttons .btn {
  min-width: calc(88px * var(--controlScale));
  min-height: calc(48px * var(--controlScale));
  border-radius: 12px;
  border: none;
  background: #4b71ff;
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.buttons .btn:active { background: #365aff; }

/* Sprint button styled more like an analog control */
.buttons .btn.sprint {
  min-width: calc(80px * var(--controlScale));
  min-height: calc(80px * var(--controlScale));
  border-radius: 50%;
  background: rgba(75, 113, 255, 0.12); /* semi-transparent */
  border: 2px solid #4b71ff;
  color: #ffffff;
  box-shadow: 0 6px 14px rgba(0,0,0,0.28);
}
.buttons .btn.sprint:hover { background: rgba(75, 113, 255, 0.18); border-color: #365aff; }
.buttons .btn.sprint:active { background: rgba(75, 113, 255, 0.26); }
.buttons .btn.sprint:active {
  background: linear-gradient(180deg, #365aff, #2b47e6);
}

@media (max-width: 640px) {
  .track { width: 140px; }
  /* calc sizes already respond; media left for minor tuning */
}

/* Toast notifications */
.toasts {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--controlScale));
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: rgba(22, 22, 29, 0.95);
  color: #fff;
  padding: calc(8px * var(--controlScale)) calc(12px * var(--controlScale));
  border-radius: calc(10px * var(--controlScale));
  border-left: calc(4px * var(--controlScale)) solid #4b71ff;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  font-size: calc(14px * var(--controlScale));
  font-weight: 600;
  opacity: 0;
  transform: translateY(calc(-10px * var(--controlScale)));
  animation: toast-in 150ms ease-out forwards, toast-out 200ms ease-in forwards 2000ms;
  max-width: min(90vw, 480px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(calc(-10px * var(--controlScale))); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(calc(-10px * var(--controlScale))); }
}

/* New compact Home Card layout */
.home-card {
  background: #12121a;
  border: 1px solid #2b2b36;
  border-radius: 16px;
  padding: calc(18px * var(--homeScale));
  width: min(480px, 92vw);
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  text-align: center;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}
.mark { font-size: calc(42px * var(--homeScale)); }
.home-title {
  margin: 0;
  font-size: calc(32px * var(--homeScale));
  font-weight: 800;
  letter-spacing: 1px;
  color: #eaeaf0;
}
.home-subtitle {
  margin: 2px 0 14px;
  font-size: calc(16px * var(--homeScale));
  color: #bcbcc9;
}
.actions { display: flex; gap: 10px; justify-content: center; margin: 6px 0; flex-wrap: wrap; }
.btn {
  background: #2f2f3a;
  color: #eaeaf0;
  border: 1px solid #3a3a46;
  padding: calc(12px * var(--homeScale)) calc(28px * var(--homeScale));
  font-size: calc(18px * var(--homeScale));
  font-weight: 700;
  border-radius: calc(18px * var(--homeScale));
  cursor: pointer;
}
.btn.primary { background: #4b71ff; border-color: #4b71ff; color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.status { margin-top: 6px; color: #bcbcc9; font-size: calc(14px * var(--homeScale)); }
.score { margin: 10px 0; color: #eaeaf0; font-weight: 700; font-size: calc(16px * var(--homeScale)); }

/* Responsive scaling overrides for Home and Game Over cards */
.home-card {
  padding: clamp(14px, 3.5vw, 22px);
  width: min(520px, 94vw);
  border-radius: clamp(12px, 2.4vw, 18px);
}
.brand { gap: clamp(8px, 2.4vw, 14px); margin-bottom: clamp(6px, 1.6vw, 12px); }
.mark { font-size: clamp(32px, 8vw, 52px); }
.home-title { font-size: clamp(26px, 6vw, 38px); }
.home-subtitle { font-size: clamp(14px, 3.8vw, 18px); margin: 2px 0 clamp(12px, 3vw, 16px); }
.actions { gap: clamp(6px, 2vw, 12px); margin: clamp(6px, 1.6vw, 10px) 0; }
.btn {
  padding: clamp(10px, 2.6vw, 14px) clamp(22px, 5vw, 32px);
  font-size: clamp(16px, 3.6vw, 18px);
  border-radius: clamp(14px, 2.4vw, 18px);
}
.status { font-size: clamp(12px, 3vw, 14px); }
.score { font-size: clamp(14px, 3.6vw, 18px); margin: clamp(8px, 2vw, 12px) 0; }

@media (max-height: 540px) {
  .home-card { padding: clamp(10px, 3vw, 16px); }
  .actions { flex-direction: column; }
}
