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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0e0f1a;
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none; user-select: none;
}

#app { position: fixed; inset: 0; }

#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  background: radial-gradient(ellipse at 50% 30%, rgba(46, 58, 128, .92), rgba(10, 11, 24, .96));
  text-align: center;
  padding: 24px;
  z-index: 20;
}
#screen-start {
  background:
    linear-gradient(180deg, rgba(10, 12, 30, .55) 0%, rgba(10, 12, 30, .78) 60%, rgba(10, 11, 24, .92) 100%),
    url('../assets/menu-art.jpg') center 22% / cover no-repeat;
}
.screen.transparent { background: transparent; pointer-events: none; }

h1 {
  font-size: clamp(56px, 11vw, 120px);
  font-weight: 800;
  line-height: .92;
  letter-spacing: 2px;
  background: linear-gradient(180deg, #ffe259, #ffa751 55%, #ff5e62);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.35));
  transform: rotate(-2deg);
}

h2 { font-size: clamp(36px, 7vw, 64px); font-weight: 800; letter-spacing: 1px; color: #ffe259; text-shadow: 0 4px 0 rgba(0,0,0,.4); }

.tagline { font-size: 20px; opacity: .9; }

.how { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 10px; }
.how-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 17px;
}
.how-item span { font-size: 24px; }

.btn {
  font-family: inherit;
  font-size: 22px; font-weight: 800;
  padding: 14px 44px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.1);
  color: #fff;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease;
  min-width: 320px;
}
.btn:hover { transform: scale(1.05); background: rgba(255,255,255,.18); }
.btn.primary {
  background: linear-gradient(180deg, #ffd34e, #ff9f2e);
  border-color: #ffdf7e;
  color: #4a2a00;
  box-shadow: 0 6px 0 #b96a00, 0 12px 24px rgba(0,0,0,.35);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffe27a, #ffab45); }

.fineprint { font-size: 13px; opacity: .55; max-width: 440px; }

#username {
  font-family: inherit;
  font-size: 20px; font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  padding: 12px 20px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.3);
  background: rgba(0,0,0,.35);
  color: #ffe259;
  min-width: 320px;
  outline: none;
}
#username::placeholder { color: rgba(255,255,255,.45); }
#username:focus { border-color: #ffd34e; }
#username.shake { animation: shake .4s ease; border-color: #ff5e62; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-9px); } 50% { transform: translateX(9px); } 75% { transform: translateX(-5px); } }

#hud-cal { font-size: 17px; font-weight: 800; color: #ff9d6b; }

#lb-box {
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 16px;
  padding: 12px 22px;
  min-width: 320px;
  max-width: 420px;
}
#lb-rank { font-size: 19px; font-weight: 800; color: #7CFC9A; margin-bottom: 6px; min-height: 24px; }
#lb-list { list-style: none; margin: 0; padding: 0; counter-reset: rank; text-align: left; }
#lb-list li {
  display: flex; justify-content: space-between; gap: 16px;
  font-size: 16px; padding: 3px 0;
  counter-increment: rank;
}
#lb-list li::before { content: counter(rank) "."; opacity: .6; min-width: 24px; }
#lb-list li .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list li .lb-score { font-weight: 800; color: #ffe259; }
#lb-list li.me { color: #7CFC9A; }
#lb-list li.me .lb-score { color: #7CFC9A; }

/* ---------- Calibration ---------- */
#calibrate-msg { font-size: 20px; opacity: .9; max-width: 480px; }
#calibrate-count { font-size: 90px; font-weight: 800; color: #7CFC9A; text-shadow: 0 5px 0 rgba(0,0,0,.4); min-height: 110px; }

#countdown-num {
  font-size: 160px; font-weight: 800;
  color: #ffe259;
  text-shadow: 0 8px 0 rgba(0,0,0,.45);
  animation: pop .9s ease infinite;
}
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 25% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between;
  padding: 16px 22px;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0 3px 0 rgba(0,0,0,.45);
}
#hud-score { font-size: 42px; font-weight: 800; color: #ffe259; line-height: 1; }
#hud-coins { font-size: 22px; font-weight: 800; color: #fff; display: flex; align-items: center; gap: 6px; }
.coin-ico { width: 24px; height: 24px; filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
.hud-right { text-align: right; }
#hud-speed { font-size: 18px; font-weight: 800; color: #8fd3ff; }
#hud-best { font-size: 15px; opacity: .75; }

/* ---------- Camera PiP ---------- */
#cam-wrap {
  position: absolute; right: 16px; bottom: 16px;
  width: 280px; height: 210px;
  cursor: pointer;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.35);
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  z-index: 15;
  background: #000;
}
#cam-video, #cam-overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror like a mirror */
}
#cam-status {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 12px; font-weight: 600;
  text-align: center;
  padding: 3px;
  background: rgba(0,0,0,.55);
}

/* ---------- Game over ---------- */
.stats { display: flex; gap: 34px; margin: 8px 0; }
.stat-num { font-size: 46px; font-weight: 800; color: #ffe259; text-shadow: 0 4px 0 rgba(0,0,0,.4); }
.stat-label { font-size: 15px; text-transform: uppercase; letter-spacing: 2px; opacity: .7; }
.best-banner { font-size: 26px; font-weight: 800; color: #7CFC9A; animation: pop .9s ease; }

/* ---------- Tracking warning ---------- */
#tracking-warn {
  position: absolute; top: 90px; left: 50%;
  transform: translateX(-50%);
  background: rgba(200, 40, 40, .9);
  padding: 10px 24px;
  border-radius: 999px;
  font-weight: 800;
  z-index: 18;
}

/* ---------- mute + power-up indicator ---------- */
#btn-mute {
  pointer-events: auto;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  font-size: 18px;
  padding: 4px 10px;
  cursor: pointer;
  margin-top: 6px;
}
#power-ind {
  position: absolute; top: 14px; left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 6px 14px;
  z-index: 11;
}
#power-icon { width: 26px; height: 26px; }
#power-bar { width: 90px; height: 8px; background: rgba(255,255,255,.2); border-radius: 4px; overflow: hidden; }
#power-bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffe259, #ffa751); border-radius: 4px; }

/* ---------- speed lines + score popups ---------- */
#speedlines {
  position: absolute; inset: -4%;
  background: url('../assets/fx-speed.png') center / cover no-repeat;
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
  z-index: 8;
}
#popup-layer { position: absolute; inset: 0; pointer-events: none; z-index: 12; }
.coin-pop {
  position: absolute;
  font-family: 'Baloo 2', sans-serif;
  font-size: 26px; font-weight: 800;
  color: #ffe259;
  text-shadow: 0 3px 0 rgba(0,0,0,.5);
  transform: translate(-50%, -50%);
  animation: coinPop .8s ease-out forwards;
}
@keyframes coinPop {
  0% { opacity: 0; margin-top: 0; transform: translate(-50%,-50%) scale(.5); }
  20% { opacity: 1; transform: translate(-50%,-50%) scale(1.2); }
  100% { opacity: 0; margin-top: -70px; transform: translate(-50%,-50%) scale(1); }
}

@media (max-width: 640px) {
  #cam-wrap { width: 160px; height: 120px; }
  .btn { min-width: 260px; font-size: 19px; }
}
