:root {
  --bg: #050a1a;
  --ink: #eaf2ff;
  --mia: #3f7bff;
  --mia-gold: #e0b44a;
  --luc: #7dff3a;
  --hp: #ffd23f;
  --hp-low: #ff4d4d;
  --trail: #ff7a3a;
  --panel: rgba(8, 16, 40, 0.92);
  --line: rgba(120, 180, 255, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}
#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.bar-row {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex; align-items: flex-start; gap: 10px;
}
.side { flex: 1; min-width: 0; }
.name { font-weight: 800; letter-spacing: .08em; font-size: clamp(11px, 2.2vh, 15px); text-shadow: 0 1px 3px #000; }
.p2 .name { text-align: right; }
.hp {
  position: relative; height: clamp(12px, 3.4vh, 20px); margin-top: 2px;
  background: rgba(0,0,0,.6); border: 2px solid rgba(255,255,255,.75); border-radius: 3px; overflow: hidden;
  transform: skewX(-12deg);
}
.p2 .hp { transform: skewX(12deg); }
.hp .fill, .hp .trail { position: absolute; top: 0; bottom: 0; right: 0; width: 100%; transform-origin: right; }
.p2 .hp .fill, .p2 .hp .trail { left: 0; right: auto; transform-origin: left; }
.hp .trail { background: var(--trail); }
.hp .fill { background: linear-gradient(180deg, #fff28a, var(--hp) 45%, #d99a10); }
.side.low .hp .fill { background: linear-gradient(180deg, #ff9a9a, var(--hp-low) 50%, #a51a1a); animation: pulse .5s infinite alternate; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.6); } }
.meter { height: 5px; margin-top: 3px; background: rgba(0,0,0,.55); border-radius: 2px; overflow: hidden; width: 70%; }
.p2 .meter { margin-left: auto; }
.mfill { height: 100%; width: 0; background: linear-gradient(90deg, #7fd4ff, #ffffff); }
.p2 .mfill { margin-left: auto; background: linear-gradient(270deg, #9dff6a, #ffffff); }
.pips { margin-top: 3px; display: flex; gap: 5px; }
.p2 .pips { justify-content: flex-end; }
.pips i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); display: block; }
.pips i.on { background: var(--hp); box-shadow: 0 0 6px var(--hp); }
.timer {
  min-width: 54px; text-align: center; font-weight: 900; font-size: clamp(22px, 6vh, 38px);
  line-height: 1; text-shadow: 0 2px 4px #000; padding-top: 2px; font-variant-numeric: tabular-nums;
}
.timer.sd { color: var(--hp-low); font-size: clamp(14px, 3.2vh, 20px); }
.combo {
  position: absolute; top: 22%; font-weight: 900; font-style: italic; font-size: clamp(18px, 5vh, 34px);
  text-shadow: 0 0 10px rgba(0,0,0,.9), 0 2px 0 #000; opacity: 0; transition: opacity .25s;
  font-family: "Consolas", "Courier New", monospace;
}
.combo.c1 { left: 4%; color: #9cd3ff; }
.combo.c2 { right: 4%; color: #b9ff8f; }
.combo.show { opacity: 1; }
.announce {
  position: absolute; left: 0; right: 0; top: 36%; text-align: center;
  font-family: "Consolas", "Courier New", monospace; font-weight: 900;
  font-size: clamp(30px, 11vh, 80px); letter-spacing: .06em;
  color: #fff; text-shadow: 0 0 18px #3fa0ff, 0 0 2px #fff, 0 4px 0 #001a44;
  opacity: 0; transform: scale(1.3); transition: opacity .15s, transform .2s;
}
.announce.show { opacity: 1; transform: scale(1); }
.announce.ko { color: #ffe36b; text-shadow: 0 0 22px #ff7a00, 0 4px 0 #3a1400; }
.proto-tag {
  position: absolute; bottom: max(4px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 10px; letter-spacing: .15em; opacity: .45;
}

/* ---------- Controles ---------- */
#controls { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#stickZone {
  position: absolute; left: 0; bottom: 0; width: 45%; height: 70%;
  pointer-events: auto; touch-action: none;
}
#stick {
  position: absolute; width: 150px; height: 150px; border-radius: 50%;
  left: max(28px, calc(env(safe-area-inset-left) + 16px)); bottom: max(22px, env(safe-area-inset-bottom));
  background: radial-gradient(circle, rgba(255,255,255,.08), rgba(255,255,255,.18));
  border: 2px solid rgba(255,255,255,.35);
}
#knob {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border-radius: 50%; background: rgba(255,255,255,.45); border: 2px solid rgba(255,255,255,.7);
  box-shadow: 0 0 12px rgba(120,190,255,.5);
}
#btns {
  position: absolute; right: max(18px, calc(env(safe-area-inset-right) + 10px)); bottom: max(16px, env(safe-area-inset-bottom));
  width: 230px; height: 190px; pointer-events: none;
}
.btn {
  position: absolute; width: 78px; height: 78px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 26px; color: rgba(255,255,255,.9);
  border: 2px solid rgba(255,255,255,.55); pointer-events: auto; touch-action: none;
  text-shadow: 0 1px 3px #000;
}
#bA { left: 0; bottom: 8px; background: rgba(63,123,255,.35); }
#bB { left: 92px; bottom: 44px; background: rgba(255,90,60,.35); }
#bS { left: 150px; bottom: 124px; width: 68px; height: 68px; font-size: 22px; background: rgba(160,90,255,.35); }
.btn.on { transform: scale(.92); filter: brightness(1.8); border-color: #fff; }
#pauseBtn {
  position: absolute; top: max(52px, calc(env(safe-area-inset-top) + 46px)); left: 50%; transform: translateX(-50%);
  width: 38px; height: 30px; border-radius: 8px; border: 1px solid rgba(255,255,255,.4);
  background: rgba(0,0,0,.35); color: #fff; font-weight: 900; pointer-events: auto;
}
@media (max-height: 380px) {
  #stick { width: 130px; height: 130px; }
  .btn { width: 68px; height: 68px; font-size: 22px; }
  #bB { left: 80px; bottom: 38px; }
  #bS { left: 132px; bottom: 108px; width: 58px; height: 58px; }
}

/* ---------- Pantallas ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at 50% 30%, #13265a 0%, #060c22 60%, #02040c 100%);
  overflow-y: auto; touch-action: pan-y;
}
#pause, #result { background: rgba(3, 6, 18, .88); }
#title { cursor: pointer; }
.logo { font-size: clamp(40px, 12vw, 96px); font-weight: 900; letter-spacing: .04em; line-height: 1;
  text-shadow: 0 0 24px rgba(63,123,255,.8), 0 4px 0 #001236; }
.logo span { color: var(--mia-gold); }
.sub { margin-top: 10px; opacity: .8; letter-spacing: .2em; font-size: 12px; text-transform: uppercase; }
.tap { margin-top: 36px; font-weight: 800; letter-spacing: .2em; font-family: Consolas, monospace; }
.blink { animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.ver { position: absolute; bottom: 10px; font-size: 11px; opacity: .45; }
h2 { margin: 0 0 12px; letter-spacing: .12em; font-size: clamp(18px, 4vh, 26px); }
.row { width: min(620px, 100%); display: flex; align-items: center; gap: 10px; margin: 5px 0; flex-wrap: wrap; }
.lbl { width: 140px; font-size: 13px; opacity: .8; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.opts button, .mbtn, .go {
  font: inherit; color: var(--ink); background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; min-height: 38px;
}
.opts button.sel { background: rgba(63,123,255,.45); border-color: #8fb6ff; font-weight: 700; }
.go { margin-top: 14px; font-size: 20px; font-weight: 900; padding: 10px 36px; background: linear-gradient(180deg, #4f86ff, #2449b8); border-color: #bcd2ff; }
.mbtn { width: min(320px, 100%); margin: 5px 0; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; margin: 10px 0; font-size: 14px; }
.toggles input { transform: scale(1.3); margin-right: 6px; }
.help { max-width: 640px; font-size: 12px; opacity: .75; line-height: 1.5; text-align: center; }
#resultStats { margin: 6px 0 12px; font-size: 14px; opacity: .85; text-align: center; line-height: 1.6; }

/* ---------- Girar teléfono ---------- */
#rotate {
  display: none; position: fixed; inset: 0; z-index: 50;
  flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(ellipse at 50% 40%, #13265a, #02040c 70%);
  font-weight: 800; font-size: 22px; letter-spacing: .06em; text-align: center; padding: 20px;
}
#rotate small { font-weight: 400; opacity: .7; font-size: 14px; }
#rotate .phone {
  width: 54px; height: 92px; border: 4px solid #cfe0ff; border-radius: 10px; margin-bottom: 18px;
  animation: rot 1.8s ease-in-out infinite;
}
@keyframes rot { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) {
  body.fighting #rotate { display: flex; }
}

#fps { position: fixed; right: 6px; bottom: 4px; z-index: 7; font: 11px Consolas, monospace; opacity: .7; pointer-events: none; }

/* ---------- Fase 3: callouts, Super, medidor ---------- */
.callout {
  position: absolute; top: 30%; font-family: Consolas, "Courier New", monospace; font-weight: 900; font-style: italic;
  font-size: clamp(16px, 4.6vh, 30px); letter-spacing: .05em; opacity: 0; transform: translateY(8px);
  transition: opacity .12s, transform .12s; text-shadow: 0 0 10px rgba(0,0,0,.9), 0 2px 0 #000;
}
.callout.k1 { left: 5%; }
.callout.k2 { right: 5%; text-align: right; }
.callout.show { opacity: 1; transform: none; }
.callout.counter { color: #ff7a4a; }
.callout.perfect { color: #fff3a0; }
.callout.dizzy { color: #c9a8ff; }
.callout.info { color: #cfe6ff; }
.meter { position: relative; }
.side.full .meter { box-shadow: 0 0 8px #fff, 0 0 14px var(--mia); animation: pulse .4s infinite alternate; }
.side.p2.full .meter { box-shadow: 0 0 8px #fff, 0 0 14px var(--luc); }
#superCut {
  position: absolute; left: 0; right: 0; top: 34%; height: 30%; pointer-events: none;
  opacity: 0; transition: opacity .12s;
}
#superCut.show { opacity: 1; }
#superCut .sc-band {
  position: absolute; inset: 0; display: flex; align-items: center; gap: 4%;
  padding: 0 6%; background: linear-gradient(90deg, rgba(0,0,0,.85), rgba(10,30,90,.85) 45%, rgba(0,0,0,.85));
  border-top: 3px solid #fff; border-bottom: 3px solid #fff;
  animation: scIn .35s ease-out;
}
#superCut.lucero .sc-band { background: linear-gradient(90deg, rgba(0,0,0,.88), rgba(10,60,10,.88) 45%, rgba(0,0,0,.88)); }
#superCut.right .sc-band { flex-direction: row-reverse; text-align: right; }
.sc-portrait {
  height: 86%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #c98f5e 0 22%, #6b3f1f 23% 34%, #2d5bd6 35% 62%, transparent 63%);
  box-shadow: 0 0 30px #7fd8ff;
}
#superCut.lucero .sc-portrait { background: radial-gradient(circle at 50% 38%, #b57c50 0 22%, #0b0b0b 23% 34%, #1f261f 35% 62%, transparent 63%); box-shadow: 0 0 30px #8dff4a; }
.sc-text small { display: block; letter-spacing: .3em; font-size: clamp(10px, 2.4vh, 14px); opacity: .85; }
.sc-text b { display: block; font-family: Consolas, monospace; font-size: clamp(26px, 8vh, 60px); letter-spacing: .04em; color: #fff;
  text-shadow: 0 0 18px #7fd8ff, 0 3px 0 #001236; }
#superCut.lucero .sc-text b { text-shadow: 0 0 18px #8dff4a, 0 3px 0 #0a2400; }
@keyframes scIn { from { transform: translateX(-30%) skewX(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
#bX {
  left: 150px; bottom: 210px; width: 80px; height: 40px; border-radius: 12px; font-size: 14px; letter-spacing: .08em;
  background: linear-gradient(180deg, rgba(255,230,120,.75), rgba(255,140,40,.6)); border-color: #fff;
  animation: pulse .45s infinite alternate;
}
@media (max-height: 380px) { #bX { left: 128px; bottom: 176px; } }
