@font-face {
  font-family: 'arcade-fallback';
  src: local('Courier New');
}

:root {
  --cyan: #23e6ff;
  --magenta: #ff3df0;
  --orange: #ff9a23;
  --yellow: #ffe94a;
  --red: #ff3d5e;
  --bg: #05060f;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Courier New', monospace;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#game-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--bg);
  cursor: crosshair;
  image-rendering: auto;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
}

#hud-left { position: absolute; top: 16px; left: 20px; }
#hud-center { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); }
#hud-right { position: absolute; top: 16px; right: 20px; text-align: right; }

#health { display: flex; gap: 6px; margin-bottom: 8px; }
.pip {
  width: 22px; height: 10px;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  clip-path: polygon(15% 0, 100% 0, 85% 100%, 0 100%);
}
.pip.empty { background: #16324a; box-shadow: none; }

#heat-wrap {
  width: 130px; height: 8px;
  background: #101a2e;
  border: 1px solid #1e3a5c;
  position: relative;
}
#heat-bar {
  height: 100%; width: 0%;
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  transition: width 0.05s linear;
}
#heat-bar.hot { background: var(--orange); box-shadow: 0 0 8px var(--orange); }
#heat-bar.overheat { background: var(--red); box-shadow: 0 0 10px var(--red); }
#heat-label {
  position: absolute; top: 10px; left: 0;
  font-size: 9px; letter-spacing: 3px; color: #4a7a9c;
  text-shadow: none;
}

#powers { display: flex; gap: 6px; margin-top: 24px; flex-wrap: wrap; max-width: 220px; }
.pw {
  font-size: 10px;
  letter-spacing: 1px;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: 2px;
  text-shadow: 0 0 6px currentColor;
  box-shadow: 0 0 8px rgba(255,255,255,0.12), inset 0 0 6px rgba(255,255,255,0.06);
  background: rgba(5,6,15,0.45);
}

#wave-label { font-size: 15px; letter-spacing: 5px; }
#score { font-size: 26px; font-weight: bold; letter-spacing: 2px; }
#mult { font-size: 14px; color: var(--yellow); text-shadow: 0 0 8px var(--yellow); }

/* ---------- Boss bar ---------- */
#boss-bar-wrap {
  position: absolute;
  top: 52px; left: 50%; transform: translateX(-50%);
  width: 420px; text-align: center;
  color: var(--red);
  text-shadow: 0 0 8px var(--red);
  font-size: 11px; letter-spacing: 6px;
  pointer-events: none;
}
#boss-bar-bg {
  margin-top: 4px; height: 8px;
  background: #200812;
  border: 1px solid #5c1e2e;
}
#boss-bar {
  height: 100%; width: 100%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
  transition: width 0.15s linear;
}

/* ---------- Wave banner ---------- */
#banner {
  position: absolute;
  top: 40%; left: 50%; transform: translate(-50%, -50%);
  font-size: 44px; letter-spacing: 14px;
  color: var(--cyan);
  text-shadow: 0 0 20px var(--cyan), 0 0 60px var(--cyan);
  pointer-events: none;
  animation: bannerIn 2s ease-out forwards;
  white-space: nowrap;
}
#banner.boss { color: var(--red); text-shadow: 0 0 20px var(--red), 0 0 60px var(--red); }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: radial-gradient(ellipse at center, rgba(5,6,15,0.55) 0%, rgba(5,6,15,0.92) 100%);
  color: #cfefff;
}

.screen h1 {
  font-size: 72px;
  line-height: 0.95;
  text-align: center;
  letter-spacing: 18px;
  color: var(--cyan);
  text-shadow: 0 0 12px var(--cyan), 0 0 45px var(--cyan), 0 0 120px rgba(35,230,255,0.6);
  animation: flicker 4s infinite;
}
.screen h1.small { font-size: 52px; color: var(--red); text-shadow: 0 0 12px var(--red), 0 0 45px var(--red); }

@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.6; }
  94% { opacity: 1; }
  97% { opacity: 0.75; }
  98% { opacity: 1; }
}

.tagline { font-size: 14px; letter-spacing: 3px; color: #7fb8d9; }

.controls {
  display: flex; gap: 26px;
  font-size: 12px; letter-spacing: 2px;
  color: #7fb8d9;
}
.controls b { color: var(--yellow); text-shadow: 0 0 8px var(--yellow); }

.screen button {
  font-family: inherit;
  font-size: 18px;
  letter-spacing: 6px;
  padding: 14px 42px;
  background: transparent;
  color: var(--yellow);
  border: 2px solid var(--yellow);
  box-shadow: 0 0 14px rgba(255,233,74,0.5), inset 0 0 14px rgba(255,233,74,0.15);
  text-shadow: 0 0 8px var(--yellow);
  cursor: pointer;
  animation: pulse 1.4s infinite;
}
.screen button:hover {
  background: rgba(255,233,74,0.12);
  animation: none;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(255,233,74,0.5), inset 0 0 14px rgba(255,233,74,0.15); }
  50% { box-shadow: 0 0 30px rgba(255,233,74,0.85), inset 0 0 20px rgba(255,233,74,0.3); }
}

.hint { font-size: 11px; letter-spacing: 2px; color: #4a7a9c; }

.screen button.mini {
  font-size: 12px;
  letter-spacing: 3px;
  padding: 8px 22px;
  color: var(--cyan);
  border: 1px solid var(--cyan);
  box-shadow: 0 0 10px rgba(35,230,255,0.35), inset 0 0 8px rgba(35,230,255,0.1);
  text-shadow: 0 0 6px var(--cyan);
  animation: none;
}
.screen button.mini:hover { background: rgba(35,230,255,0.12); }

/* ---------- Initials entry ---------- */
.initials-title { color: var(--yellow) !important; text-shadow: 0 0 12px var(--yellow), 0 0 45px var(--yellow) !important; }
#ini-score { font-size: 22px; letter-spacing: 4px; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); }
#ini-slots { display: flex; gap: 14px; }
.ini-slot {
  width: 64px; height: 76px;
  display: flex; align-items: center; justify-content: center;
  font-size: 46px; font-weight: bold;
  color: var(--yellow);
  text-shadow: 0 0 14px var(--yellow);
  border: 2px solid #3a5a7c;
  background: rgba(10,16,34,0.6);
}
.ini-slot.active {
  border-color: var(--yellow);
  box-shadow: 0 0 14px rgba(255,233,74,0.5), inset 0 0 10px rgba(255,233,74,0.15);
  animation: slotBlink 0.8s infinite;
}
@keyframes slotBlink {
  0%, 55% { opacity: 1; }
  56%, 100% { opacity: 0.55; }
}

/* ---------- Leaderboard ---------- */
.scores-title { color: var(--cyan) !important; text-shadow: 0 0 12px var(--cyan), 0 0 45px var(--cyan) !important; }
#board {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 15px; letter-spacing: 2px;
  min-width: 400px;
}
.brow {
  display: grid;
  grid-template-columns: 44px 90px 1fr 70px;
  padding: 3px 12px;
  color: #9fd8ff;
  text-shadow: 0 0 6px rgba(159,216,255,0.6);
}
.brow span:nth-child(3) { text-align: right; }
.brow span:nth-child(4) { text-align: right; color: #5a8cb0; }
.brow.bhead { font-size: 10px; letter-spacing: 3px; color: #4a7a9c; text-shadow: none; }
.brow.bhl {
  color: var(--yellow);
  text-shadow: 0 0 8px var(--yellow);
  border: 1px solid rgba(255,233,74,0.5);
  box-shadow: 0 0 12px rgba(255,233,74,0.25);
  animation: flicker 2s infinite;
}
.brow.bhl span:nth-child(4) { color: var(--yellow); }
.score-btns { display: flex; gap: 16px; align-items: center; }
.coinmark {
  font-style: normal;
  font-size: 10px;
  color: #ff9a23;
  text-shadow: 0 0 6px #ff9a23;
  margin-left: 5px;
  vertical-align: super;
}

.continue-title { color: var(--yellow) !important; text-shadow: 0 0 12px var(--yellow), 0 0 45px var(--yellow) !important; }

/* ---------- Victory ---------- */
.screen.victory {
  background: radial-gradient(ellipse at center, rgba(5,6,15,0.08) 0%, rgba(5,6,15,0.42) 100%);
  justify-content: flex-start;
  padding-top: 5%;
  gap: 10px;
}
.victory-eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 6px;
  color: #ff3df0;
  text-shadow: 0 0 10px #ff3df0, 0 0 28px #ff3df0;
  animation: victoryPulse 1.4s ease-in-out infinite;
}
.victory-title {
  font-size: 64px;
  letter-spacing: 16px;
  color: #4dff88;
  text-shadow:
    0 0 14px #4dff88,
    0 0 40px #4dff88,
    0 0 90px rgba(77,255,136,0.7),
    0 0 160px rgba(35,230,255,0.35);
  animation: victoryTitleIn 1.1s cubic-bezier(.2,.8,.2,1) both, flicker 3s infinite 1.1s;
}
.victory-tag {
  animation: victoryFadeUp 0.9s ease 0.35s both;
}
.victory-sub {
  margin: 0;
  font-size: 11px;
  letter-spacing: 4px;
  color: rgba(255,255,255,0.45);
  animation: victoryFadeUp 0.9s ease 0.7s both;
}
#victory-score {
  font-size: 28px;
  letter-spacing: 5px;
  color: var(--cyan);
  text-shadow: 0 0 14px var(--cyan), 0 0 40px rgba(35,230,255,0.5);
  animation: victoryFadeUp 0.9s ease 0.55s both;
}
.screen.victory .score-btns {
  margin-top: 8px;
  animation: victoryFadeUp 0.9s ease 0.9s both;
}
@keyframes victoryTitleIn {
  0% { transform: scale(0.6) translateY(20px); opacity: 0; letter-spacing: 40px; filter: blur(8px); }
  60% { transform: scale(1.06) translateY(0); opacity: 1; filter: blur(0); }
  100% { transform: scale(1); letter-spacing: 16px; }
}
@keyframes victoryFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes victoryPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
@media (max-width: 760px), (max-height: 460px) {
  .victory-title { font-size: 34px; letter-spacing: 8px; }
  .victory-eyebrow { font-size: 9px; letter-spacing: 3px; }
}
#countdown {
  font-size: 96px;
  font-weight: bold;
  color: var(--red);
  text-shadow: 0 0 16px var(--red), 0 0 60px var(--red);
  line-height: 1;
  animation: countPulse 1s infinite;
}
@keyframes countPulse {
  0% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}
#final-coins { font-size: 13px; letter-spacing: 4px; color: #ff9a23; text-shadow: 0 0 8px #ff9a23; }

/* ---------- Touch controls (touch devices only) ---------- */
#touch-controls { display: none; }
body.touch #touch-controls:not(.hidden) { display: block; }

.tc-zone {
  position: absolute;
  top: 18%;
  bottom: 0;
  z-index: 4;
  pointer-events: none; /* canvas owns the pointers; zones are visual guides */
}
.tc-move-zone {
  left: 0;
  width: 42%;
  background: linear-gradient(90deg, rgba(35,230,255,0.06), transparent 85%);
  border-right: 1px solid rgba(35,230,255,0.12);
}
.tc-aim-zone {
  right: 0;
  width: 58%;
  background: linear-gradient(270deg, rgba(255,61,240,0.05), transparent 80%);
}

.tc-cluster {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 12px;
  z-index: 6;
}
.tc-move { left: max(12px, env(safe-area-inset-left, 0px)); }
.tc-act { right: max(12px, env(safe-area-inset-right, 0px)); }

.tc-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(35,230,255,0.75);
  background: rgba(5,10,24,0.55);
  color: var(--cyan);
  font-family: inherit;
  font-size: 22px;
  font-weight: bold;
  text-shadow: 0 0 8px var(--cyan);
  box-shadow: 0 0 14px rgba(35,230,255,0.3), inset 0 0 12px rgba(35,230,255,0.1);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  user-select: none;
}
.tc-btn.tc-word { font-size: 12px; letter-spacing: 1px; }
.tc-btn:active, .tc-btn.held {
  background: rgba(35,230,255,0.32);
  box-shadow: 0 0 22px rgba(35,230,255,0.65), inset 0 0 16px rgba(35,230,255,0.25);
  transform: scale(0.96);
}
#tc-dash {
  border-color: rgba(255,233,74,0.75);
  color: var(--yellow);
  text-shadow: 0 0 8px var(--yellow);
  background: rgba(5,10,24,0.55);
  box-shadow: 0 0 14px rgba(255,233,74,0.28), inset 0 0 12px rgba(255,233,74,0.08);
}
#tc-dash:active, #tc-dash.held {
  background: rgba(255,233,74,0.3);
  box-shadow: 0 0 22px rgba(255,233,74,0.55);
}
body.day .tc-btn { background: rgba(5,20,40,0.5); }

.tc-hint {
  position: absolute;
  left: 50%;
  bottom: max(6px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  z-index: 5;
  pointer-events: none;
  font-size: 9px;
  letter-spacing: 2px;
  color: rgba(35,230,255,0.45);
  text-shadow: 0 0 6px rgba(35,230,255,0.3);
  white-space: nowrap;
}

/* Lift HUD clear of notches / controls on touch */
body.touch #hud-left { top: max(12px, env(safe-area-inset-top, 0px)); left: max(14px, env(safe-area-inset-left, 0px)); }
body.touch #hud-right { top: max(12px, env(safe-area-inset-top, 0px)); right: max(14px, env(safe-area-inset-right, 0px)); }
body.touch #hud-center { top: max(12px, env(safe-area-inset-top, 0px)); }
body.touch #boss-bar-wrap { top: max(52px, calc(env(safe-area-inset-top, 0px) + 40px)); }

@media (max-height: 420px) {
  .tc-btn { width: 58px; height: 58px; font-size: 18px; }
  .tc-btn.tc-word { font-size: 10px; }
  .tc-hint { display: none; }
}

/* ---------- Rotate hint (portrait touch devices) ---------- */
#rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #rotate-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(5,6,15,0.92);
    color: var(--cyan);
    text-align: center;
    font-size: 20px;
    letter-spacing: 4px;
    text-shadow: 0 0 12px var(--cyan);
    pointer-events: none;
  }
  body.touch #rotate-hint p { line-height: 1.8; }
}

/* ---------- Compact layout for small screens ---------- */
@media (max-width: 760px), (max-height: 460px) {
  .screen h1 { font-size: 40px; letter-spacing: 10px; }
  .screen h1.small { font-size: 30px; }
  .screen { gap: 12px; }
  .tagline { font-size: 11px; }
  .controls { gap: 12px; font-size: 10px; flex-wrap: wrap; justify-content: center; }
  .screen button { font-size: 14px; padding: 10px 28px; }
  .screen button.mini { font-size: 10px; padding: 6px 14px; }
  .hint { font-size: 9px; }
  #countdown { font-size: 64px; }
  #ini-slots { gap: 10px; }
  .ini-slot { width: 46px; height: 56px; font-size: 32px; }
  #board { min-width: 0; width: 88vw; max-width: 400px; font-size: 12px; }
  #score { font-size: 19px; }
  #wave-label { font-size: 12px; letter-spacing: 3px; }
  .pip { width: 16px; height: 8px; }
  #heat-wrap { width: 100px; }
  #powers { margin-top: 18px; max-width: 150px; }
  .pw { font-size: 8px; padding: 1px 5px; }
  #boss-bar-wrap { width: 68vw; font-size: 9px; letter-spacing: 4px; }
  #banner { font-size: 26px; letter-spacing: 8px; }
  #final-score { font-size: 22px; }
}

/* ---------- Day mode: keep HUD readable on a bright sky ---------- */
body.day #hud { color: #0a2e4a; text-shadow: 0 0 6px rgba(255,255,255,0.8); }
body.day #heat-label { color: #1c4a6e; }
body.day #mult { color: #7a5200; text-shadow: 0 0 6px rgba(255,255,255,0.8); }
body.day .pip { background: #0a2e4a; box-shadow: 0 0 6px rgba(255,255,255,0.6); }
body.day .pip.empty { background: rgba(255,255,255,0.35); box-shadow: none; }
body.day #heat-wrap { background: rgba(255,255,255,0.3); border-color: rgba(10,46,74,0.5); }

#final-score { font-size: 30px; letter-spacing: 4px; color: var(--cyan); text-shadow: 0 0 12px var(--cyan); }
#final-wave { font-size: 15px; letter-spacing: 4px; color: #7fb8d9; }
#best-score { font-size: 15px; letter-spacing: 4px; color: var(--yellow); text-shadow: 0 0 8px var(--yellow); }
