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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #0a0a1a;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", system-ui, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#app { position: relative; width: 100%; height: 100%; }
#game { display: block; width: 100%; height: 100%; background: #050510; cursor: crosshair; touch-action: none; }
.hidden { display: none !important; }

/* ─── HUD ─── */
#hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start;
  padding: max(8px, env(safe-area-inset-top)) 12px 0; gap: 10px;
  pointer-events: none; color: #fff; text-shadow: 2px 2px 0 #000;
  font-weight: 800; font-size: 14px;
}
.hud-block { display: flex; flex-direction: column; gap: 4px; }
.hud-left { align-items: flex-start; }
.hud-center { align-items: center; text-align: center; }
.hud-right { align-items: flex-end; padding-right: 128px; }
.hp-row { display: flex; align-items: center; gap: 6px; }
.hp-icon { color: #ff2d95; font-size: 20px; }
#hp-bar {
  position: relative; width: clamp(90px, 18vw, 180px); height: 18px;
  background: #1a1a2e; border: 3px solid #000; border-radius: 10px; overflow: hidden;
  box-shadow: 2px 2px 0 #000;
}
#hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff2d95, #ff9a35); transition: width 0.12s; }
#hp-bar.low #hp-fill { background: linear-gradient(90deg, #ff0033, #ff2d95); animation: pulse 0.6s infinite alternate; }
#hp-text { position: absolute; inset: 0; font-size: 11px; line-height: 12px; text-align: center; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.8); } }
.weapon-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
#weapon-name { background: #ffe600; color: #000; text-shadow: none; border: 3px solid #000; border-radius: 10px; padding: 1px 8px; box-shadow: 2px 2px 0 #000; }
#weapon-name.spread { background: #ff7a00; }
#weapon-name.rapid { background: #7dfffd; }
#weapon-ammo { color: #ffe600; min-width: 28px; }
#dash-pip { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #000; background: #39ff6a; box-shadow: 0 0 8px #39ff6a; }
#dash-pip.cooling { background: #334; box-shadow: none; }
#level-name { font-size: 15px; color: #7dfffd; }
.hud-sub { font-size: 12px; opacity: 0.95; }
#wave-info { color: #ffb0d8; }
#wave-info.alert { color: #ff3355; animation: pulse 0.3s infinite alternate; }
#score { font-size: 22px; color: #ffe600; letter-spacing: 1px; }
.combo { display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; color: #ff2d95; }
#combo-mult { font-size: 22px; color: #39ff6a; }
#combo-bar { width: 90px; height: 6px; background: #000; border-radius: 4px; overflow: hidden; }
#combo-fill { height: 100%; width: 100%; background: #39ff6a; }
.combo.pop #combo-mult { animation: pop 0.2s; }
@keyframes pop { 50% { transform: scale(1.5); } }

.hud-buttons { position: absolute; right: 10px; top: max(8px, env(safe-area-inset-top)); display: flex; gap: 6px; pointer-events: auto; }
.icon-btn {
  appearance: none; min-width: 36px; height: 36px; padding: 0 6px;
  border: 3px solid #000; border-radius: 12px; background: #7dfffd; color: #000;
  font-weight: 900; font-size: 13px; font-family: inherit; cursor: pointer; box-shadow: 2px 2px 0 #000;
}
.icon-btn.off { background: #555; color: #bbb; text-decoration: line-through; }
.icon-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #000; }

#boss-bar {
  position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 10;
  width: min(460px, 80vw); text-align: center; pointer-events: none;
  color: #ffe600; font-weight: 900; text-shadow: 2px 2px 0 #000; font-size: 14px; letter-spacing: 2px;
}
.boss-track { height: 16px; background: #1a0a0a; border: 3px solid #000; border-radius: 10px; overflow: hidden; box-shadow: 3px 3px 0 #000; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff3300, #ffb300); transition: width 0.1s; }
#boss-bar.shielded #boss-fill { background: linear-gradient(90deg, #7a4dff, #c44dff); }

.banner {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%) scale(0.6);
  z-index: 12; pointer-events: none; opacity: 0;
  font-size: clamp(22px, 5vw, 46px); font-weight: 900; color: #ffe600; white-space: nowrap;
  text-shadow: 4px 4px 0 #000, 0 0 18px #ff7a00; -webkit-text-stroke: 1.5px #000;
  transition: opacity 0.2s, transform 0.2s;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.danger { color: #ff3355; text-shadow: 4px 4px 0 #000, 0 0 18px #ff0033; }
.banner.good { color: #39ff6a; text-shadow: 4px 4px 0 #000, 0 0 18px #39ff6a; }

.hint {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: rgba(0,0,0,0.75); color: #7dfffd; border: 3px solid #000; border-radius: 14px;
  padding: 8px 16px; font-size: 13px; pointer-events: none; white-space: nowrap;
  box-shadow: 3px 3px 0 #ff2d95; transition: opacity 0.6s;
}
.hint b { color: #ffe600; }
.hint .touch { display: none; }
.hint.fade { opacity: 0; }

/* ─── Sticks táctiles ─── */
.vstick { position: absolute; bottom: max(26px, env(safe-area-inset-bottom)); z-index: 20; display: none; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.vstick-label { color: #fff; font-size: 11px; font-weight: 800; text-shadow: 2px 2px 0 #000; letter-spacing: 1px; }
.vstick-base { width: 120px; height: 120px; border-radius: 50%; background: rgba(125,255,253,0.16); border: 4px solid rgba(0,0,0,0.7); position: relative; pointer-events: auto; touch-action: none; }
.vstick-knob { width: 50px; height: 50px; border-radius: 50%; background: #ff2d95; border: 4px solid #000; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); box-shadow: 2px 2px 0 #000; pointer-events: none; }
#stick-move { left: max(20px, env(safe-area-inset-left)); }
#stick-aim { right: max(20px, env(safe-area-inset-right)); }
#stick-aim .vstick-knob { background: #ffe600; }
.dash-btn {
  position: absolute; z-index: 21; display: none; right: 158px; bottom: 120px;
  width: 78px; height: 78px; border-radius: 50%; border: 4px solid #000; background: #39ff6a; color: #000;
  font-weight: 900; font-size: 12px; font-family: inherit; box-shadow: 3px 3px 0 #000; touch-action: none;
}
.dash-btn.cooling { background: #445; color: #999; }
body.touch .vstick { display: flex; }
body.touch .dash-btn { display: block; }
body.touch .hint { bottom: 170px; white-space: normal; text-align: center; max-width: 90%; font-size: 12px; }
body.touch .hint .desk { display: none; }
body.touch .hint .touch { display: inline; }
body.touch #game { cursor: default; }

/* ─── Overlays ─── */
.overlay {
  position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20,10,40,0.88), rgba(5,5,16,0.96));
  overflow-y: auto; padding: 12px;
}
.panel {
  background: linear-gradient(160deg, #2a1a5e, #0d1b3a); border: 5px solid #000; border-radius: 28px;
  padding: 24px 28px; text-align: center; max-width: 460px; width: 94%; margin: auto;
  box-shadow: 8px 8px 0 #ff2d95, 0 0 40px rgba(125,255,253,0.3); color: #fff;
}
.panel.wide { max-width: 760px; }
.panel h1 { font-size: clamp(1.6rem, 5vw, 2.3rem); line-height: 1.05; color: #7dfffd; text-shadow: 4px 4px 0 #000, 0 0 12px #7dfffd; margin-bottom: 8px; }
.panel h1 .sub { color: #ffe600; font-size: 0.75em; }
.panel h2 { color: #ffe600; text-shadow: 3px 3px 0 #000; margin: 10px 0; font-size: 1.2rem; }
.tagline { color: #ff9a35; font-weight: 700; margin-bottom: 14px; }
.howto { text-align: left; list-style: none; margin: 0 auto 18px; display: inline-block; font-size: 14px; }
.howto li { margin: 6px 0; padding-left: 8px; border-left: 4px solid #ffe600; }
.howto b { color: #ffe600; }
.mini { margin-top: 12px; font-size: 12px; opacity: 0.75; }
.stats-line { margin: 6px 0 12px; color: #cfe; font-size: 14px; line-height: 1.5; }
.btn {
  appearance: none; border: 4px solid #000; background: #ffe600; color: #000; font-weight: 900;
  font-size: 1.2rem; padding: 11px 32px; border-radius: 999px; cursor: pointer; box-shadow: 4px 4px 0 #000;
  font-family: inherit; transition: transform 0.1s, box-shadow 0.1s; margin: 5px;
}
.btn.alt { background: #7dfffd; font-size: 1rem; }
.btn.small { font-size: 0.9rem; padding: 7px 16px; background: #c44dff; color: #fff; text-shadow: 1px 1px 0 #000; }
.btn.small.off { background: #555; }
.btn:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 #000; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
.toggles { display: flex; justify-content: center; flex-wrap: wrap; margin: 8px 0 12px; }
.panel.win h1 { color: #ffe600; }
.panel.lose h1 { color: #ff2d95; }
.stars { font-size: 2.4rem; color: #ffe600; letter-spacing: 6px; text-shadow: 3px 3px 0 #000; margin: 6px 0 8px; }
.cards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.card {
  appearance: none; font-family: inherit; cursor: pointer; width: 200px; min-height: 150px; padding: 14px 12px;
  border: 4px solid #000; border-radius: 18px; background: linear-gradient(170deg, #ffe600, #ff9a35);
  color: #000; box-shadow: 5px 5px 0 #000; transition: transform 0.1s; text-align: center;
}
.card:nth-child(2) { background: linear-gradient(170deg, #7dfffd, #3d9eff); }
.card:nth-child(3) { background: linear-gradient(170deg, #ff8ad0, #c44dff); }
.card:hover, .card:focus { transform: translateY(-4px) rotate(-1deg); outline: none; box-shadow: 7px 9px 0 #000; }
.card .ic { font-size: 30px; font-weight: 900; display: block; }
.card .t { font-size: 17px; font-weight: 900; display: block; margin: 4px 0; }
.card .d { font-size: 13px; display: block; }
.card .k { font-size: 11px; opacity: 0.7; display: block; margin-top: 6px; }

@media (max-width: 700px) {
  #hud { font-size: 12px; padding-left: 8px; padding-right: 8px; gap: 4px; }
  .hud-right { padding-right: 0; padding-top: 40px; }
  #score { font-size: 17px; }
  #level-name { font-size: 12px; }
  .hud-sub { font-size: 10px; }
  .card { width: 150px; min-height: 120px; padding: 10px 8px; }
  .card .d { font-size: 12px; }
  #boss-bar { top: 88px; }
}
@media (max-height: 460px) {
  .vstick-base { width: 100px; height: 100px; }
  .vstick-knob { width: 42px; height: 42px; }
  .dash-btn { width: 64px; height: 64px; right: 130px; bottom: 96px; font-size: 10px; }
  .panel { padding: 14px 18px; }
  .howto { font-size: 12px; margin-bottom: 8px; }
  .howto li { margin: 3px 0; }
  .card { min-height: 100px; }
  .card .ic { font-size: 22px; }
  body.touch .hint { bottom: 140px; }
  #boss-bar { top: 64px; }
}

/* Vertical (móvil de pie) */
@media (orientation: portrait) and (max-width: 600px) {
  #hud { grid-template-columns: 1fr 1fr; }
  .hud-left { grid-column: 1; grid-row: 1; }
  .hud-right { grid-column: 2; grid-row: 1; padding-top: 42px; }
  .hud-center { grid-column: 1 / span 2; grid-row: 2; }
  #boss-bar { top: 118px; }
  body.touch .dash-btn { right: 50px; bottom: 200px; }
  body.touch .hint { bottom: 290px; }
}
