:root {
  --bg0: #0a041a;
  --cyan: #29e7ff;
  --pink: #ff3d9a;
  --violet: #9b6bff;
  --gold: #ffd34d;
  --green: #46f3a0;
  --danger: #ff4d5e;
  --orange: #ff8a3d;
  --ink: #eafaff;
  --panel: rgba(12, 6, 30, 0.93);
  --font: 'Chakra Petch', system-ui, sans-serif;
  --mono: 'Share Tech Mono', monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: radial-gradient(120% 90% at 50% 0%, #1a0a3a 0%, var(--bg0) 60%, #040110 100%);
  color: var(--ink); font-family: var(--font);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  height: 100vh; height: 100dvh;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#stage { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.bg-glow {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(40% 30% at 20% 10%, rgba(155,107,255,0.25), transparent 70%),
    radial-gradient(45% 35% at 80% 90%, rgba(41,231,255,0.20), transparent 70%);
  animation: glowDrift 12s ease-in-out infinite alternate;
}
@keyframes glowDrift { from { transform: translateY(0); } to { transform: translateY(-14px); } }
.bg-vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 100% at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%); }

#frame {
  position: relative; height: 100%; aspect-ratio: 540 / 960; max-width: 100%; max-height: 100%;
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 0 0 2px rgba(155,107,255,0.20), 0 24px 80px rgba(0,0,0,0.6);
}
canvas#game { display: block; width: 100%; height: 100%; background: #060212; touch-action: none; }

/* HUD */
.hud { position: absolute; top: 0; left: 0; right: 0; z-index: 6; padding: 8px 10px 6px;
  background: linear-gradient(180deg, rgba(6,2,18,0.88) 0%, rgba(6,2,18,0) 100%); pointer-events: none; transition: opacity .3s; }
.hud.hidden { opacity: 0; pointer-events: none; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.hud-group { display: flex; align-items: center; gap: 6px; pointer-events: auto; }
.hud-cell { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hud-label { font-size: 8px; letter-spacing: 2px; font-weight: 700; color: rgba(234,250,255,0.55); }
.hud-value { font-family: var(--mono); font-size: 20px; text-shadow: 0 0 10px currentColor; }
.hud-group.left .hud-value { color: var(--cyan); }
.hud-group.center .hud-value { color: var(--gold); }
.hud-group.right .hud-value { color: var(--orange); }
.hud-btn { pointer-events: auto; width: 44px; height: 44px; min-width: 44px; min-height: 44px; border: none; border-radius: 12px;
  background: rgba(255,255,255,0.08); color: var(--ink); font-size: 18px; cursor: pointer;
  display: grid; place-items: center; backdrop-filter: blur(6px); transition: background .15s, transform .1s; }
.hud-btn:hover { background: rgba(255,255,255,0.16); }
.hud-btn:active { transform: scale(0.92); }

.hud-bottom { display: flex; align-items: center; gap: 8px; margin-top: 6px; pointer-events: none; }
.breath-wrap { flex: 1; display: flex; align-items: center; gap: 6px; }
.breath-label { font-size: 8px; letter-spacing: 2px; color: var(--cyan); font-weight: 700; }
.breath-bar { flex: 1; height: 7px; border-radius: 999px; background: rgba(255,255,255,0.1); overflow: hidden; box-shadow: inset 0 0 6px rgba(0,0,0,0.5); }
.breath-bar > span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet)); box-shadow: 0 0 10px var(--cyan); transition: width .12s ease; }
.breath-bar.danger > span { background: linear-gradient(90deg, var(--danger), var(--orange)); box-shadow: 0 0 14px var(--danger); }
.combo-chip { font-family: var(--mono); font-size: 11px; color: var(--gold); white-space: nowrap; min-width: 48px; text-align: center; text-shadow: 0 0 10px rgba(255,211,77,0.5); }
.lives-wrap { display: flex; align-items: center; gap: 4px; }
.lives-label { font-size: 8px; letter-spacing: 1px; color: rgba(234,250,255,0.55); }
.lives-value { font-family: var(--mono); font-size: 16px; color: var(--pink); text-shadow: 0 0 10px rgba(255,61,154,0.5); }

/* TUTORIAL */
.tutorial-overlay { position: absolute; inset: 0; z-index: 12; display: none; align-items: center; justify-content: center; padding: 20px;
  background: rgba(6,2,18,0.85); backdrop-filter: blur(4px); }
.tutorial-overlay.show { display: flex; animation: fadeIn .3s ease; }
.tut-panel { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid rgba(155,107,255,0.25); border-radius: 22px; padding: 26px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.55); }
.tut-panel h2 { font-size: 22px; letter-spacing: 3px; color: var(--cyan); margin-bottom: 16px; text-shadow: 0 0 16px rgba(41,231,255,0.4); }
.tut-list { text-align: left; margin-bottom: 18px; font-size: 13px; line-height: 1.7; color: rgba(234,250,255,0.8); }
.tut-list li { margin-bottom: 8px; list-style: none; padding-left: 18px; position: relative; }
.tut-list li::before { content: '▸'; position: absolute; left: 0; color: var(--violet); }
.tut-list b { color: var(--ink); }

/* FX */
.flash { position: absolute; inset: 0; z-index: 7; background: #fff; opacity: 0; pointer-events: none; mix-blend-mode: screen; }
.flash.hit { animation: flashHit .3s ease; }
@keyframes flashHit { 0% { opacity: .35; } 100% { opacity: 0; } }
.raid-banner { position: absolute; top: 35%; left: 0; right: 0; z-index: 8; text-align: center;
  font-size: clamp(30px, 10vw, 56px); font-weight: 700; letter-spacing: 5px; opacity: 0; pointer-events: none; transform: scale(0.7); }
.raid-banner.show { animation: bannerPop 1.2s ease; }
.raid-banner.raid { color: var(--cyan); text-shadow: 0 0 30px var(--cyan); }
.raid-banner.tag { color: var(--gold); text-shadow: 0 0 30px var(--gold); font-size: clamp(24px, 8vw, 44px); }
.raid-banner.success { color: var(--green); text-shadow: 0 0 30px var(--green); }
.raid-banner.tackled { color: var(--danger); text-shadow: 0 0 30px var(--danger); }
@keyframes bannerPop { 0% { opacity: 0; transform: scale(0.4); } 18% { opacity: 1; transform: scale(1.08); } 65% { opacity: 1; } 100% { opacity: 0; transform: scale(1.02); } }

/* Screens */
.screen { position: absolute; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(20,8,48,0.6), rgba(4,1,16,0.82) 75%); backdrop-filter: blur(2px); }
.screen.active { display: flex; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.panel { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid rgba(155,107,255,0.18); border-radius: 22px; padding: 26px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.06); }
.tag { display: inline-block; font-size: 11px; letter-spacing: 4px; font-weight: 700; color: var(--violet); padding: 4px 12px; margin-bottom: 14px; border: 1px solid rgba(155,107,255,0.4); border-radius: 999px; text-shadow: 0 0 12px rgba(155,107,255,0.6); }
.logo { font-size: clamp(28px, 9vw, 44px); line-height: 0.95; font-weight: 700; letter-spacing: 1px; margin-bottom: 14px; color: var(--cyan); text-shadow: 0 0 22px rgba(41,231,255,0.55); }
.logo span { display: block; color: var(--violet); text-shadow: 0 0 22px rgba(155,107,255,0.6); }
.logo em { display: block; font-style: normal; font-size: 0.55em; letter-spacing: 7px; color: var(--gold); text-shadow: 0 0 18px rgba(255,211,77,0.6); }
.subtitle { font-size: 13px; color: rgba(234,250,255,0.72); margin-bottom: 22px; line-height: 1.5; }
.screen-title { font-size: 28px; font-weight: 700; letter-spacing: 2px; margin-bottom: 18px; color: var(--ink); }
.final-score { font-family: var(--mono); font-size: 42px; margin-bottom: 16px; color: var(--gold); text-shadow: 0 0 18px rgba(255,211,77,0.5); }

.btn { display: block; width: 100%; border: none; border-radius: 14px; padding: 15px; font-family: var(--font); font-size: 16px; font-weight: 700; letter-spacing: 2px; cursor: pointer; margin-bottom: 10px; transition: transform .1s, filter .15s, box-shadow .15s; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--cyan), #1a6ad8); color: #03212b; box-shadow: 0 8px 24px rgba(41,231,255,0.35); }
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 10px 30px rgba(41,231,255,0.5); }
.btn.ghost { background: rgba(255,255,255,0.06); color: var(--ink); border: 1px solid rgba(255,255,255,0.12); }
.btn.ghost:hover { background: rgba(255,255,255,0.12); }
.best-line { margin-top: 8px; font-family: var(--mono); font-size: 13px; letter-spacing: 2px; color: rgba(234,250,255,0.6); }
.best-line span { color: var(--cyan); }
.how-list { text-align: left; margin-bottom: 18px; font-size: 13px; line-height: 1.6; color: rgba(234,250,255,0.85); }
.how-list li { margin-bottom: 9px; list-style: none; padding-left: 18px; position: relative; }
.how-list li::before { content: '▸'; position: absolute; left: 0; color: var(--violet); }
.how-list b { color: var(--ink); }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 4px; border-bottom: 1px solid rgba(255,255,255,0.07); font-size: 14px; }
.stat-row span { color: rgba(234,250,255,0.6); letter-spacing: 1px; font-size: 12px; }
.stat-row b { font-family: var(--mono); font-size: 18px; color: var(--cyan); }
.new-best { margin: 12px 0; font-weight: 700; letter-spacing: 3px; color: var(--green); text-shadow: 0 0 16px rgba(70,243,160,0.6); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
.auth-row { margin-top: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.auth-status { font-size: 12px; color: rgba(234,250,255,0.6); }
.auth-status b { color: var(--cyan); }
.auth-link { background: none; border: none; color: var(--pink); font-size: 12px; cursor: pointer; text-decoration: underline; }
.hidden { display: none !important; }
.controls-hint { margin-top: 16px; font-size: 11px; color: rgba(234,250,255,0.5); line-height: 1.8; }
.controls-hint span { display: block; }
kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.18); font-family: var(--mono); font-size: 11px; }
.touch-only { display: none; }
.leaderboard { margin: 16px 0 4px; text-align: left; position: relative; }
.lb-title { font-size: 11px; letter-spacing: 3px; color: rgba(234,250,255,0.55); margin-bottom: 8px; text-align: center; }
.lb-list { list-style: none; }
.lb-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.lb-list li.me { background: rgba(41,231,255,0.12); }
.lb-rank { font-family: var(--mono); color: var(--cyan); width: 22px; }
.lb-name { flex: 1; color: rgba(234,250,255,0.85); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-pts { font-family: var(--mono); color: var(--violet); }
.lb-loading, .lb-empty { color: rgba(234,250,255,0.45); font-size: 12px; text-align: center; padding: 10px; }
.lb-source { position: absolute; top: 0; right: 0; font-size: 9px; letter-spacing: 1px; color: rgba(234,250,255,0.35); }
.nn-score-nudge { margin: 14px 0; padding: 14px; border-radius: 14px; background: rgba(41,231,255,0.08); border: 1px solid rgba(41,231,255,0.25); }
.nn-score-nudge p { font-size: 13px; margin-bottom: 10px; }
.nn-nudge-btns { display: flex; gap: 8px; }
.nn-nudge-signup { flex: 1; text-decoration: none; text-align: center; padding: 10px; border-radius: 10px; background: linear-gradient(135deg, var(--cyan), #1a6ad8); color: #03212b; font-weight: 700; font-size: 13px; }
.nn-nudge-later { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.15); background: transparent; color: rgba(234,250,255,0.7); font-size: 13px; cursor: pointer; }
.fb-btn:empty { display: none; }
@media (pointer: coarse) { .touch-only { display: block; } .controls-hint span:first-child { display: none; } }
@media (max-height: 560px) { .panel { padding: 18px 16px; } .logo { font-size: clamp(22px, 7vw, 34px); } .subtitle { margin-bottom: 14px; } .leaderboard { display: none; } }

/* Mobile power button */
.power-btn { display: none; position: absolute; bottom: 18px; right: 14px; z-index: 9;
  width: 56px; height: 56px; border-radius: 50%; border: 2px solid rgba(255,211,77,0.3);
  background: rgba(12,6,30,0.8); color: var(--gold); font-size: 26px;
  place-items: center; backdrop-filter: blur(6px); cursor: pointer;
  box-shadow: 0 0 16px rgba(255,211,77,0.15); transition: transform .1s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.power-btn:active { transform: scale(0.88); }
.power-btn.ready { box-shadow: 0 0 30px rgba(255,211,77,0.5); border-color: var(--gold); animation: powerPulse .8s ease-in-out infinite alternate; }
@keyframes powerPulse { from { box-shadow: 0 0 18px rgba(255,211,77,0.3); } to { box-shadow: 0 0 40px rgba(255,211,77,0.6); } }
@media (pointer: coarse) { .power-btn { display: grid; } }
