* { box-sizing: border-box; }

:root {
  --font-body: "Segoe UI", system-ui, sans-serif;
  --font-display: "Lilita One", var(--font-body);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0d0d16;
  overflow: hidden;
  font-family: var(--font-body);
  color: #fff;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

h2, button, #hudRow, #hpText, .weaponChip, #stageIntroText, .upgrade-card h3, #codeBox {
  font-family: var(--font-display);
  letter-spacing: 0.5px;
}

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

#gameCanvas {
  background: #1a2233;
  image-rendering: pixelated;
  max-width: 100vw;
  max-height: 100vh;
  aspect-ratio: 1280 / 720;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

.hidden { display: none !important; }

#fadeOverlay {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 1;
  transition: opacity 1s ease;
  pointer-events: none;
  z-index: 500;
}

#stageIntro {
  z-index: 100;
  animation: stageIntroPop 1.8s ease forwards;
}
#stageIntroLogo {
  max-width: min(60%, 320px);
  max-height: 30vh;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.6));
}
#stageIntroLogo[hidden] { display: none; }

@keyframes stageIntroPop {
  0% { opacity: 0; transform: scale(0.7); }
  15% { opacity: 1; transform: scale(1.05); }
  25% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 700px);
  pointer-events: none;
}

#hpBarWrap, #xpBarWrap {
  position: relative;
  width: 100%;
  height: 18px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 4px;
}

#hpBarFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #ff6b6b, #e63946);
  transition: width 0.15s;
}

#hpText {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
}

#xpBarWrap { height: 8px; }
#xpBarFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(180deg, #ffe066, #f5a623);
  transition: width 0.15s;
}

#hudRow {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
  text-shadow: 0 1px 2px #000;
  padding: 0 4px;
}
#powerText { color: #ff7de9; }
#stageText { color: #7fdbff; }

#weaponList {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.weaponChip {
  font-size: 11px;
  font-weight: 700;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  padding: 3px 8px;
  text-shadow: 0 1px 2px #000;
}

#bossHpWrap {
  position: absolute;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, 500px);
  height: 16px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  overflow: hidden;
}
#bossHpFill {
  height: 100%;
  width: 100%;
  background: linear-gradient(180deg, #c77dff, #8e44ad);
  transition: width 0.15s;
}


/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 20, 0.86);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 20px;
}

.overlay h2 {
  font-size: clamp(26px, 5vw, 40px);
  margin: 0;
  color: #ffcc00;
}

.overlay .sub { color: #cfd3e6; margin: 0 0 8px; }
.overlay p { max-width: min(90%, 560px); }

button {
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  padding: 12px 34px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(180deg, #ffd23f, #f5a623);
  color: #3a2600;
  cursor: pointer;
  box-shadow: 0 4px 0 #a8720f;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #a8720f; }

#cardRow {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.upgrade-card {
  width: 190px;
  background: linear-gradient(180deg, #232a45, #171c30);
  border: 2px solid #3d4770;
  border-radius: 14px;
  padding: 16px 12px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.upgrade-card:hover { transform: translateY(-4px); border-color: #ffcc00; }
.upgrade-card h3 { margin: 6px 0; color: #ffcc00; font-size: 16px; }
.upgrade-card p { margin: 0; font-size: 13px; color: #cfd3e6; }

#codeBox {
  font-size: clamp(16px, 3.2vw, 24px);
  font-weight: 800;
  letter-spacing: 1px;
  background: #14182a;
  border: 2px dashed #ffcc00;
  color: #ffcc00;
  padding: 14px 20px;
  border-radius: 12px;
  user-select: all;
  max-width: min(90%, 560px);
  word-break: break-all;
  line-height: 1.4;
}

/* ---------- Touch controls (phones/tablets only) ---------- */
#touchControls { display: none; }

@media (hover: none) and (pointer: coarse) {
  #touchControls { display: block; }
}

#joyBase {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.3);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 0.1s;
  z-index: 50;
}
#joyBase.active { opacity: 1; }

#joyKnob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  border: 2px solid rgba(255,255,255,0.5);
  transform: translate(-50%, -50%);
}

#dashBtn {
  position: fixed;
  right: max(28px, env(safe-area-inset-right));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 84px;
  height: 84px;
  border-radius: 50%;
  padding: 0;
  font-size: 15px;
  background: linear-gradient(180deg, #7ee6ff, #2ecc71);
  color: #06341f;
  box-shadow: 0 4px 0 #1a7a48;
  z-index: 50;
  display: none;
}
#dashBtn.enabled { display: block; }
#dashBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 #1a7a48; }

/* ---------- Rotate-device prompt (phones in portrait) ---------- */
#rotateOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #0d0d16;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
#rotateOverlay p { color: #cfd3e6; font-size: 16px; max-width: 280px; margin: 10px auto 0; }
#rotateIcon { font-size: 48px; animation: rotateHint 1.6s ease-in-out infinite; }
@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  #rotateOverlay { display: flex; }
}
