@font-face {
  font-family: 'system-ui-fallback';
  src: local('Arial');
}

:root {
  --neon-cyan: #4df3ff;
  --neon-pink: #ff3ea5;
  --neon-purple: #b56bff;
  --neon-yellow: #ffe14d;
  --neon-green: #5bffb0;
  --bg-deep: #05060f;
  --panel-bg: rgba(12, 14, 30, 0.9);
  --shield-color: #47c9ff;
  --hp-color: #ff5566;
  safe-top: env(safe-area-inset-top);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 20%, #151935 0%, #05060f 70%);
  overflow: hidden;
}

#frame {
  position: relative;
  /* width/height set by JS to match the fitted canvas size */
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #05060f;
  box-shadow: 0 0 60px rgba(77, 243, 255, 0.15), 0 0 120px rgba(181, 107, 255, 0.08);
  image-rendering: -webkit-optimize-contrast;
}

#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px;
}
.screen.active { display: flex; }

/* ---------- MAIN MENU ---------- */
#screen-menu {
  background: radial-gradient(ellipse at 50% 15%, #1b2050 0%, #05060f 65%);
  gap: 6%;
}

.logo { text-align: center; margin-top: 4%; }
.logo-title {
  font-size: clamp(28px, 8vmin, 46px);
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 12px var(--neon-cyan), 0 0 30px rgba(77,243,255,0.5);
  line-height: 1.05;
}
.logo-title span {
  color: var(--neon-pink);
  text-shadow: 0 0 14px var(--neon-pink), 0 0 36px rgba(255,62,165,0.6);
}
.logo-sub {
  margin-top: 10px;
  font-size: clamp(12px, 3.2vmin, 18px);
  letter-spacing: 10px;
  color: var(--neon-yellow);
  text-shadow: 0 0 10px rgba(255,225,77,0.7);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: min(86%, 420px);
}

.big-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 22px 14px;
  border-radius: 22px;
  border: 3px solid rgba(255,255,255,0.25);
  background: linear-gradient(160deg, #2a3164 0%, #14172f 100%);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  overflow: hidden;
}
.big-btn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.15);
}
.big-btn::after {
  content: '';
  position: absolute;
  top: -60%; left: -20%;
  width: 40%; height: 220%;
  background: rgba(255,255,255,0.12);
  transform: rotate(20deg);
  pointer-events: none;
}
.big-btn-icon { font-size: clamp(30px, 8vmin, 42px); filter: drop-shadow(0 0 8px rgba(255,255,255,0.4)); }
.big-btn-label { font-size: clamp(16px, 4.2vmin, 22px); letter-spacing: 1.5px; }
.big-btn-desc { font-size: clamp(10px, 2.6vmin, 13px); font-weight: 500; opacity: 0.7; }

/* Kids/Arcade must dominate the menu -- everything else is a secondary,
   visually much smaller action so there's zero doubt what to tap first. */
.menu-buttons .big-btn { padding: 34px 16px; gap: 8px; border-width: 4px; }
.menu-buttons .big-btn-icon { font-size: clamp(42px, 11vmin, 58px); }
.menu-buttons .big-btn-label { font-size: clamp(22px, 5.6vmin, 30px); }
.menu-buttons .big-btn-desc { font-size: clamp(11px, 2.8vmin, 14px); }

.btn-kids { border-color: var(--neon-green); box-shadow: 0 8px 0 #1a5c42, 0 0 26px rgba(91,255,176,0.35), inset 0 2px 0 rgba(255,255,255,0.15); }
.btn-arcade { border-color: var(--neon-pink); box-shadow: 0 8px 0 #7a1c4c, 0 0 26px rgba(255,62,165,0.35), inset 0 2px 0 rgba(255,255,255,0.15); }
.btn-continue { border-color: var(--neon-cyan); box-shadow: 0 8px 0 #1a4c5c, 0 0 26px rgba(77,243,255,0.35); }
.btn-quit { border-color: #ff6b6b; box-shadow: 0 8px 0 #6c1e1e, 0 0 20px rgba(255,107,107,0.3); }
.btn-next { border-color: var(--neon-yellow); box-shadow: 0 8px 0 #6c5c1a, 0 0 26px rgba(255,225,77,0.35); }

.menu-footer-row { display: flex; gap: 10px; margin-top: 2px; }
.pill-btn {
  padding: 8px 18px;
  border-radius: 30px;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 700;
  font-size: clamp(10px, 2.3vmin, 13px);
  letter-spacing: 1px;
  cursor: pointer;
}
.pill-btn:active { transform: scale(0.95); }
.menu-footer-credit { color: rgba(255,255,255,0.35); font-size: 11px; margin-top: 4px; }

.donate-btn {
  margin-top: 4px;
  padding: 10px 26px;
  border-radius: 30px;
  border: 2px solid #ff6bb0;
  background: linear-gradient(135deg, #ff3ea5, #ff8a3d);
  color: #fff;
  font-weight: 800;
  font-size: clamp(12px, 2.8vmin, 15px);
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(255, 62, 165, 0.5);
}
.donate-btn:active { transform: scale(0.96); }
.donate-btn.flash { animation: donateFlash 1s ease-in-out infinite; }
@keyframes donateFlash {
  0%, 100% { box-shadow: 0 0 18px rgba(255, 62, 165, 0.5); transform: scale(1); }
  50% { box-shadow: 0 0 34px rgba(255, 138, 61, 0.9); transform: scale(1.06); }
}

/* ---------- LEVEL SELECT ---------- */
.panel-title {
  color: #fff; font-size: clamp(18px, 5vmin, 26px); font-weight: 900; letter-spacing: 3px;
  margin-bottom: 18px; text-shadow: 0 0 10px var(--neon-cyan);
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: min(88%, 460px);
  max-height: 60vh;
  overflow-y: auto;
}
.level-cell {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.25);
  background: linear-gradient(160deg, #2a3164, #14172f);
  color: #fff;
  font-weight: 800;
  font-size: clamp(14px, 3.6vmin, 18px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.level-cell.boss { border-color: var(--neon-pink); box-shadow: 0 0 14px rgba(255,62,165,0.5); }
.level-cell.locked { opacity: 0.35; filter: grayscale(1); cursor: not-allowed; }
.back-btn { margin-top: 20px; }

/* ---------- HUD ----------
   Its own dedicated field pinned to the bottom of the frame, below the
   paddle's play area, so it never overlaps enemies/bosses higher up. */
.hud {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 0px);
  left: 0; right: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)) 14px;
  display: none;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(180deg, rgba(5,6,15,0) 0%, rgba(5,6,15,0.75) 30%, rgba(5,6,15,0.92) 100%);
  border-top: 1px solid rgba(255,255,255,0.12);
}
.hud.active { display: flex; }
.hud-row { display: flex; gap: 10px; align-items: center; }
.hud-top { width: 100%; }
.hud-stat { flex: 1; }
.hud-label {
  font-size: 9px; font-weight: 800; letter-spacing: 1px; color: rgba(255,255,255,0.75);
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}
.bar-track {
  height: 10px; border-radius: 6px; background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.25); overflow: hidden; margin-top: 2px;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.15s ease; }
.hp-fill { background: linear-gradient(90deg, #ff5566, #ff9966); box-shadow: 0 0 8px #ff5566; }
.shield-fill { background: linear-gradient(90deg, #47c9ff, #7dfcff); box-shadow: 0 0 8px #47c9ff; }
.hud-mid { justify-content: space-between; }
.hud-chip {
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.25);
  border-radius: 20px; padding: 4px 12px; color: #fff; font-weight: 800; font-size: 13px;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}

.autoplay-badge {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 50%; transform: translateX(-50%);
  background: rgba(181,107,255,0.25); border: 1px solid var(--neon-purple); color: #fff;
  font-weight: 800; font-size: 11px; letter-spacing: 1px; padding: 5px 14px; border-radius: 20px;
  box-shadow: 0 0 14px rgba(181,107,255,0.5); z-index: 8; pointer-events: none;
}
.autoplay-badge.hidden { display: none; }

.ascension-badge {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 42px); left: 50%; transform: translateX(-50%);
  background: rgba(255,225,77,0.2); border: 1px solid var(--neon-yellow); color: #fff;
  font-weight: 800; font-size: 11px; letter-spacing: 1px; padding: 5px 14px; border-radius: 20px;
  box-shadow: 0 0 14px rgba(255,225,77,0.5); z-index: 8; pointer-events: none;
}
.ascension-badge.hidden { display: none; }

.autoplay-toggle {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  margin-top: 14px; padding: 10px 14px; border-radius: 14px;
  background: rgba(181,107,255,0.12); border: 1px solid rgba(181,107,255,0.4);
  color: #fff; font-weight: 700; font-size: 13px; cursor: pointer;
}
.autoplay-toggle input { width: 18px; height: 18px; accent-color: var(--neon-purple); }

.credits-list {
  width: min(88%, 460px); max-height: 62vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px; color: #fff;
}
.credits-cat { font-weight: 900; color: var(--neon-cyan); letter-spacing: 1px; font-size: 14px; text-shadow: 0 0 8px var(--neon-cyan); margin-bottom: 6px; }
.credits-item {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 12px; line-height: 1.5;
}
.credits-item b { color: #ffe14d; }
.credits-item a { color: var(--neon-cyan); word-break: break-all; }
.credits-item .used { color: rgba(255,255,255,0.65); font-style: italic; }

.credits-bio {
  width: min(88%, 460px); color: #fff; text-align: left;
  background: rgba(255,225,77,0.06); border: 1px solid rgba(255,225,77,0.3);
  border-radius: 14px; padding: 14px 16px; margin-bottom: 16px; font-size: 12px; line-height: 1.6;
}
.credits-bio h3 { margin: 0 0 8px; color: var(--neon-yellow); font-size: 15px; letter-spacing: 1px; text-shadow: 0 0 8px rgba(255,225,77,0.6); }
.credits-bio p { margin: 0 0 8px; }
.credits-bio a { color: var(--neon-cyan); }

/* ---------- SCROLLING END CREDITS ---------- */
.creditsroll-viewport {
  width: 100%; height: 100%; overflow: hidden; position: relative;
  display: flex; justify-content: center;
}
.creditsroll-content {
  position: absolute; top: 100%; width: min(86%, 440px);
  color: #fff; text-align: center;
  animation: creditsScroll 34s linear forwards;
}
.creditsroll-content h1 { font-size: clamp(24px,7vmin,34px); color: var(--neon-pink); text-shadow: 0 0 14px var(--neon-pink); margin: 0 0 6px; }
.creditsroll-content h2 { font-size: clamp(16px,4.5vmin,20px); color: var(--neon-cyan); text-shadow: 0 0 10px var(--neon-cyan); margin: 34px 0 4px; letter-spacing: 1px; }
.creditsroll-content h3 { font-size: 15px; color: var(--neon-yellow); margin: 22px 0 6px; }
.creditsroll-content p { font-size: 13px; line-height: 1.7; opacity: 0.9; margin: 0 0 12px; }
.creditsroll-content a { color: var(--neon-cyan); }
.creditsroll-content .cred-line { font-size: 12px; opacity: 0.75; margin: 4px 0; }
@keyframes creditsScroll {
  from { top: 100%; }
  to { top: -220%; }
}
#btn-creditsroll-skip {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateX(-50%); z-index: 3;
}

.boss-bar-wrap {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 6px); left: 50%; transform: translateX(-50%);
  width: 70%; z-index: 6; text-align: center; pointer-events: none;
}
.boss-bar-wrap.hidden { display: none; }
.boss-name { color: var(--neon-pink); font-weight: 900; font-size: 13px; letter-spacing: 2px; text-shadow: 0 0 8px var(--neon-pink); }
.boss-track { height: 12px; }
.boss-fill { background: linear-gradient(90deg, #ff3ea5, #ff9ec9); box-shadow: 0 0 10px #ff3ea5; }

.icon-btn {
  position: absolute; top: env(safe-area-inset-top, 8px); right: 10px; z-index: 7;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.3); color: #fff;
  font-weight: 800; pointer-events: auto;
}
.icon-btn.hidden { display: none; }

/* ---------- POPUPS ---------- */
.popup-screen { background: rgba(2,3,10,0.78); backdrop-filter: blur(3px); }
.popup {
  background: var(--panel-bg);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 26px;
  padding: 34px 28px;
  width: min(84%, 380px);
  text-align: center;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}
.popup-title {
  color: #ff5566; font-size: clamp(22px, 6vmin, 30px); font-weight: 900; letter-spacing: 2px;
  text-shadow: 0 0 14px rgba(255,85,102,0.7);
}
.popup-title.good { color: var(--neon-green); text-shadow: 0 0 14px rgba(91,255,176,0.7); }
.popup-sub { color: rgba(255,255,255,0.8); margin-top: 8px; font-size: 14px; }
.popup-buttons { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.small-btn { padding: 14px 10px; border-radius: 16px; }
.small-btn .big-btn-icon { font-size: 22px; }
.small-btn .big-btn-label { font-size: 15px; }

.hidden { display: none !important; }

@media (prefers-color-scheme: light) {
  html, body { background: #000; }
}
