/* ── Google Font (loaded async, fallback to system mono) ─────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&display=swap');

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #000;
  font-family: 'Rajdhani', 'Courier New', monospace;
  -webkit-font-smoothing: antialiased;
}
#c { display: block; width: 100%; height: 100%; }

/* ── CSS Variables — world theme colors injected via JS ──────────────────────── */
:root {
  --accent: #8844ff;
  --accent2: #ff44aa;
  --glass-bg: rgba(0,0,0,0.6);
  --glass-border: rgba(255,255,255,0.10);
  --hud-pad: clamp(10px, 2vw, 18px);
  --glow: rgba(136,68,255,0.5);
}

/* ── Glassmorphism utility ───────────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   HUD
═══════════════════════════════════════════════════════════════════════════════ */
#ui {
  position: absolute; top: 0; left: 0; width: 100%;
  pointer-events: none;
  padding: var(--hud-pad);
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 8px;
}
.ui-left  { display: flex; flex-direction: column; gap: 5px; }
.ui-right { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; }

/* Score */
.ui-score {
  font-size: clamp(24px, 5.5vw, 38px);
  font-weight: 700;
  color: #fff;
  letter-spacing: 3px;
  line-height: 1;
  text-shadow: 0 0 24px var(--glow), 0 2px 4px rgba(0,0,0,.9);
  transition: transform .1s;
  filter: drop-shadow(0 0 8px var(--glow));
}
.ui-score.pop { transform: scale(1.18); }

/* Coins */
.ui-coins {
  font-size: clamp(14px, 3.2vw, 18px);
  font-weight: 600;
  color: #FFD700;
  letter-spacing: 1px;
  text-shadow: 0 0 12px rgba(255,200,0,.5), 0 1px 3px rgba(0,0,0,.8);
  display: flex; align-items: center; gap: 5px;
}
.ui-coins::before {
  content: '';
  display: inline-block;
  width: clamp(10px, 2vw, 14px);
  height: clamp(10px, 2vw, 14px);
  background: radial-gradient(circle at 35% 35%, #ffe066, #cc8800);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255,200,0,.6);
  flex-shrink: 0;
}

/* World badge */
.ui-dim {
  font-size: clamp(9px, 1.8vw, 11px);
  font-weight: 600;
  color: #aaeeff;
  letter-spacing: 3px;
  text-transform: uppercase;
  padding: 4px 10px;
  background: rgba(0,0,0,.5);
  border-left: 2px solid currentColor;
  border-radius: 0 4px 4px 0;
  width: fit-content;
  transition: color .4s, border-color .4s, box-shadow .4s;
  box-shadow: inset 0 0 12px rgba(0,0,0,.3);
}

/* ── Speed bar ───────────────────────────────────────────────────────────────── */
#speedWrap {
  width: clamp(70px, 12vw, 100px);
  height: 4px;
  background: rgba(255,255,255,.1);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
#speedBar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4488ff, #aa44ff, #ff44aa);
  border-radius: 2px;
  transition: width .2s;
  box-shadow: 0 0 6px rgba(170,68,255,.8);
}
#speedLabel {
  font-size: clamp(8px, 1.5vw, 10px);
  color: rgba(255,255,255,.4);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* ── Multiplier ──────────────────────────────────────────────────────────────── */
.ui-mult {
  font-size: clamp(10px, 2vw, 13px);
  font-weight: 700;
  color: #ffaa00;
  letter-spacing: 1px;
  text-shadow: 0 0 10px rgba(255,170,0,.8);
  opacity: 0;
  transition: opacity .25s, transform .15s;
  transform: scale(0.9);
}
.ui-mult.visible { opacity: 1; transform: scale(1); }

/* ── Combo ───────────────────────────────────────────────────────────────────── */
.ui-combo {
  font-size: clamp(12px, 2.5vw, 16px);
  font-weight: 700;
  color: #ff44aa;
  letter-spacing: 2px;
  text-shadow: 0 0 14px rgba(255,68,170,.9);
  opacity: 0;
  transition: opacity .25s, transform .15s;
  text-align: right;
}

/* ── Powerup stack ───────────────────────────────────────────────────────────── */
.ui-powerup {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: fit-content;
  align-items: flex-end;
}
.pu-card {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  background: rgba(0,0,0,.75);
  border: 1.5px solid rgba(255,255,255,.3);
  border-radius: 6px;
  min-width: clamp(130px, 22vw, 160px);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color .2s, box-shadow .2s;
  animation: puSlideIn .2s ease-out;
}
@keyframes puSlideIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}
.pu-icon { font-size: clamp(16px, 3vw, 20px); line-height: 1; flex-shrink: 0; }
.pu-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.pu-label {
  font-size: clamp(9px, 1.8vw, 11px);
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
}
.pu-desc {
  font-size: clamp(7px, 1.4vw, 9px);
  color: rgba(255,255,255,.45);
  letter-spacing: 0.3px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pu-timer {
  font-size: clamp(11px, 2vw, 13px);
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
  flex-shrink: 0;
  min-width: 30px;
  text-align: right;
  opacity: 0.9;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   OVERLAY (Start / Game Over)
═══════════════════════════════════════════════════════════════════════════════ */
#overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
  gap: clamp(12px, 3vh, 22px);
  transition: opacity .4s;
  /* Layered background: radial glow + dark base */
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(88,0,180,.25) 0%, transparent 70%),
    rgba(0,0,0,.82);
}
#overlay.hidden { opacity: 0; pointer-events: none; }

/* Title */
#overlay h1 {
  font-size: clamp(30px, 8vw, 68px);
  font-weight: 700;
  color: #fff;
  text-align: center;
  letter-spacing: clamp(4px, 1.5vw, 10px);
  text-shadow:
    0 0 30px rgba(136,68,255,.9),
    0 0 60px rgba(136,68,255,.5),
    0 0 100px rgba(136,68,255,.2),
    0 4px 8px rgba(0,0,0,.9);
  animation: titlePulse 2.5s ease-in-out infinite;
  line-height: 1.1;
}
@keyframes titlePulse {
  0%,100% {
    text-shadow: 0 0 30px rgba(136,68,255,.9), 0 0 60px rgba(136,68,255,.4), 0 4px 8px rgba(0,0,0,.9);
    letter-spacing: clamp(4px, 1.5vw, 10px);
  }
  50% {
    text-shadow: 0 0 50px rgba(180,100,255,1), 0 0 100px rgba(136,68,255,.7), 0 0 160px rgba(100,50,255,.3), 0 4px 8px rgba(0,0,0,.9);
    letter-spacing: clamp(6px, 2vw, 14px);
  }
}

/* Subtitle */
#overlay .sub {
  font-size: clamp(11px, 2.8vw, 16px);
  font-weight: 600;
  color: rgba(180,220,255,.8);
  text-align: center;
  letter-spacing: clamp(3px, 1vw, 5px);
  text-transform: uppercase;
}

/* Final score card */
#overlay .final-score {
  font-size: clamp(13px, 3vw, 18px);
  font-weight: 600;
  color: #FFD700;
  letter-spacing: 2px;
  text-align: center;
  white-space: pre;
  line-height: 2;
  padding: clamp(10px, 2vw, 16px) clamp(16px, 4vw, 28px);
  background: rgba(255,200,0,.06);
  border: 1px solid rgba(255,200,0,.2);
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

/* Play / Retry button */
#restartBtn {
  pointer-events: all;
  padding: clamp(12px, 2.5vh, 16px) clamp(36px, 8vw, 60px);
  font-size: clamp(14px, 3vw, 18px);
  font-family: 'Rajdhani', 'Courier New', monospace;
  font-weight: 700;
  letter-spacing: clamp(3px, 1vw, 5px);
  text-transform: uppercase;
  color: #fff;
  background: transparent;
  border: 2px solid rgba(255,255,255,.7);
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: color .2s, border-color .2s, box-shadow .2s;
}
#restartBtn::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(136,68,255,.3), rgba(255,68,170,.2));
  opacity: 0;
  transition: opacity .2s;
}
#restartBtn:hover {
  border-color: #fff;
  box-shadow: 0 0 28px rgba(136,68,255,.6), 0 0 8px rgba(255,255,255,.3);
  color: #fff;
}
#restartBtn:hover::before { opacity: 1; }
#restartBtn:active { transform: scale(.97); }

/* Hint text */
#overlay .hint {
  font-size: clamp(10px, 2vw, 12px);
  color: rgba(255,255,255,.38);
  letter-spacing: 1px;
  text-align: center;
  max-width: min(340px, 85vw);
  line-height: 2;
}

/* Mystery tip — rotating lore/hint line */
.mystery-tip {
  font-size: clamp(11px, 2.2vw, 14px);
  font-weight: 600;
  color: rgba(180, 220, 255, 0.75);
  letter-spacing: 1.5px;
  text-align: center;
  max-width: min(420px, 88vw);
  line-height: 1.6;
  font-style: italic;
  padding: 8px 16px;
  border-left: 2px solid rgba(136, 68, 255, 0.5);
  border-right: 2px solid rgba(136, 68, 255, 0.5);
  animation: tipFade 0.6s ease-out;
}
@keyframes tipFade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   FEEDBACK EFFECTS
═══════════════════════════════════════════════════════════════════════════════ */

/* Full-screen flash */
#flash {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s;
}

/* World / tier announce — top-center, below HUD, never blocks player view */
#dimAnnounce {
  position: absolute;
  top: clamp(60px, 12vh, 90px);
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: clamp(16px, 4vw, 28px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 20px currentColor, 0 2px 6px rgba(0,0,0,.9);
  letter-spacing: clamp(3px, 1.2vw, 6px);
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .3s;
  text-align: center;
  white-space: nowrap;
  /* Glass pill background so it reads on any sky */
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,.15);
}

/* Coin pop — injected via JS on collect */
.coin-pop {
  position: absolute;
  pointer-events: none;
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 700;
  color: #FFD700;
  text-shadow: 0 0 10px rgba(255,200,0,.8);
  animation: coinPop .7s ease-out forwards;
  z-index: 10;
}
@keyframes coinPop {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  60%  { opacity: 1; transform: translateY(-28px) scale(1.2); }
  100% { opacity: 0; transform: translateY(-50px) scale(0.8); }
}

/* Hit vignette — red edge flash on damage */
#hitVignette {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(220,30,30,.55) 100%);
  opacity: 0;
  transition: opacity .08s;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
═══════════════════════════════════════════════════════════════════════════════ */

/* Tablet portrait */
@media (max-width: 768px) {
  :root { --hud-pad: 10px; }
  .pu-desc { display: none; } /* hide desc on small screens, keep icon+label+timer */
  .pu-card { min-width: 110px; }
}

/* Small phone */
@media (max-width: 420px) {
  :root { --hud-pad: 8px; }
  #speedWrap { width: 60px; }
  .pu-card { min-width: 90px; padding: 4px 7px; }
  .pu-label { letter-spacing: 1px; }
}

/* Landscape phone — reduce vertical space */
@media (max-height: 420px) {
  #overlay { gap: 8px; }
  #overlay h1 { font-size: clamp(20px, 6vw, 36px); }
  #overlay .hint { display: none; }
}
