:root {
  --bg: #211f30;
  --ink: #fff4fa;
  --ink-soft: #f3cfe2;
  --pink: #ff6fa8;
  --pink-deep: #d6337a;
  --panel: #3a2a4a;
  --panel-edge: #1a1424;
  --gold: #ffd166;
  --pixel: 'Press Start 2P', monospace;
  --text: 'VT323', monospace;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#game { position: absolute; inset: 0; }
#game canvas { display: block; image-rendering: pixelated; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- HUD */

.hud,
.hud-buttons {
  position: absolute;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
body.playing .hud,
body.playing .hud-buttons { opacity: 1; pointer-events: auto; }

.hud {
  left: calc(12px + var(--safe-l));
  padding: 2px 12px 2px 4px;
  font: 14px var(--pixel);
  background: rgba(26, 20, 36, .55);
  border-radius: 6px;
  text-shadow: 2px 2px 0 var(--panel-edge);
}
.hud.bump .fruit-icon { animation: fruit-spin .85s steps(17) infinite, bump .25s ease-out; }

.fruit-icon {
  width: 40px;
  height: 40px;
  background: url("../assets/images/Items/Fruits/Taco.png") 0 0 / 680px 40px;
  animation: fruit-spin .85s steps(17) infinite;
}
@keyframes fruit-spin { to { background-position: -680px 0; } }
@keyframes bump { 50% { transform: scale(1.35); } }

/* Vidas: la cara de Naomi (fila 24 = de frente) recortada de su hoja LPC, al 150 %. */
.life-icon,
#dialog-face {
  width: 42px;
  height: 36px;
  background: url("../assets/images/Main Characters/Pink Man/Naomii2D.png") -27px -2325px / 1248px 5184px;
  image-rendering: pixelated;
}
.life-icon { margin-left: 10px; }
.hud.life-bump .life-icon { animation: bump .35s ease-out 2; }
.hud.life-bump #lives-count { color: var(--gold); }

.hud-buttons { right: calc(12px + var(--safe-r)); }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  font: 18px var(--pixel);
  color: var(--ink);
  background: rgba(26, 20, 36, .55);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.icon-btn:focus-visible { outline: 2px solid var(--gold); }
.sprite.volume {
  width: 32px;
  height: 32px;
  background: url("../assets/images/Menu/Buttons/Volume.png") center / contain no-repeat;
  image-rendering: pixelated;
}
#mute-btn.off .sprite { opacity: .35; }

#level-banner {
  position: absolute;
  left: 50%;
  top: 22%;
  z-index: 5;
  padding: 10px 18px;
  font: clamp(12px, 2.6vw, 18px) var(--pixel);
  color: var(--ink);
  white-space: nowrap;
  text-shadow: 3px 3px 0 var(--panel-edge);
  background: rgba(26, 20, 36, .7);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
}
#level-banner.show { animation: banner 2.6s ease-out; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -12px); }
  15%, 75% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------- cinemáticas */

/* Durante una cinemática se esconden el HUD y los controles y entran las franjas de cine. */
body.cinematic .hud,
body.cinematic .hud-buttons,
body.cinematic #touch { opacity: 0 !important; pointer-events: none !important; }
body.cinematic #touch { display: none !important; }

#cinema { position: absolute; inset: 0; z-index: 7; pointer-events: none; }
#cinema .bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  background: #000;
  transition: height .6s ease-in-out;
}
#cinema .top { top: 0; }
#cinema .bottom { bottom: 0; display: flex; align-items: center; justify-content: center; }
body.cinematic #cinema .bar { height: max(13vh, 46px); }
body.cinematic #cinema { pointer-events: auto; cursor: pointer; }

#dialog {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(720px, calc(100% - 32px));
  padding: 6px 36px 6px 10px;
  background: var(--panel);
  box-shadow:
    0 -3px 0 0 var(--panel-edge), 0 3px 0 0 var(--panel-edge),
    -3px 0 0 0 var(--panel-edge), 3px 0 0 0 var(--panel-edge);
  transform: translateY(-30%);
  animation: fade-in .2s ease-out;
}
#dialog[hidden] { display: none; }
#dialog-face { flex: none; }
#dialog.novio #dialog-face { background-image: url("../assets/images/Main Characters/Ninja Frog/yo.png"); }
#dialog-name { font: 11px var(--pixel); color: var(--pink); }
#dialog.novio #dialog-name { color: var(--gold); }
#dialog-text { margin: 2px 0 0; font: clamp(18px, 2.6vw, 24px)/1.1 var(--text); color: var(--ink); min-height: 1.1em; }
.dialog-next {
  position: absolute;
  right: 12px;
  bottom: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  opacity: 0;
}
#dialog.done .dialog-next { opacity: 1; animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#title-card {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 16px;
  font: clamp(14px, 3vw, 22px)/1.6 var(--pixel);
  color: var(--ink);
  text-align: center;
  text-shadow: 3px 3px 0 var(--pink-deep);
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .9s ease-in-out;
}
#title-card.show { opacity: 1; }

/* ---------------------------------------------------------------- táctil */

#touch { display: none; }
body.is-touch.playing #touch { display: block; }

#stick, #jump-btn {
  position: absolute;
  z-index: 6;
  touch-action: none;
  image-rendering: pixelated;
}

#stick {
  left: calc(20px + var(--safe-l));
  bottom: calc(20px + var(--safe-b));
  width: 128px;
  height: 128px;
  background: url("../assets/images/HUD/Joystick.png") center / contain no-repeat;
  opacity: .7;
}
#stick.active { opacity: .95; }

#knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  background: url("../assets/images/HUD/Knob.png") center / contain no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
}

#jump-btn {
  right: calc(28px + var(--safe-r));
  bottom: calc(28px + var(--safe-b));
  width: 112px;
  height: 112px;
  background: url("../assets/images/HUD/JumpButton.png") center / contain no-repeat;
  opacity: .7;
  transition: transform .06s;
}
#jump-btn.active { opacity: .95; transform: scale(.9); }

.touch-only { display: none; }
body.is-touch .touch-only { display: list-item; }
body.is-touch .desktop-only { display: none; }

/* ---------------------------------------------------------------- pantallas */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
  touch-action: pan-y;
  background: rgba(33, 31, 48, .78);
  backdrop-filter: blur(2px);
  animation: fade-in .5s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

.card {
  position: relative;
  width: min(520px, 100%);
  padding: 24px 24px 28px;
  text-align: center;
  background: var(--panel);
  /* borde "pixelado" con esquinas recortadas */
  box-shadow:
    0 -4px 0 0 var(--panel-edge), 0 4px 0 0 var(--panel-edge),
    -4px 0 0 0 var(--panel-edge), 4px 0 0 0 var(--panel-edge),
    0 8px 0 4px rgba(0, 0, 0, .35);
}

.hero {
  width: 96px;
  height: 96px;
  margin: 0 auto 8px;
  /* Naomii2D.png: hoja de 13x54 cuadros de 64px; fila 25 = idle mirando a la derecha */
  background: url("../assets/images/Main Characters/Pink Man/Naomii2D.png") 0 -2400px / 1248px 5184px;
  image-rendering: pixelated;
  animation: hero-idle .7s steps(2) infinite;
}
@keyframes hero-idle { to { background-position: -192px -2400px; } }

h1, h2 {
  margin: 0 0 12px;
  font-family: var(--pixel);
  line-height: 1.4;
  color: var(--pink);
  text-shadow: 3px 3px 0 var(--panel-edge);
}
h1 { font-size: clamp(18px, 4vw, 26px); }
h1 small { font-size: .6em; color: var(--ink-soft); }
h2 { font-size: clamp(16px, 4vw, 24px); }

.lead, .message, .stats, .perfect, .keys {
  font-family: var(--text);
  font-size: 22px;
  line-height: 1.15;
}
.lead { margin: 0 0 12px; color: var(--ink-soft); }

.keys {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  color: var(--ink-soft);
}
.keys li { margin: 4px 0; }
kbd {
  display: inline-block;
  min-width: 26px;
  margin: 0 2px;
  padding: 0 6px;
  font: inherit;
  color: var(--ink);
  background: var(--panel-edge);
  border-radius: 3px;
}

.btn {
  font: 14px var(--pixel);
  color: var(--ink);
  background: var(--pink-deep);
  border: 0;
  padding: 14px 22px;
  cursor: pointer;
  box-shadow: inset -4px -4px 0 rgba(0, 0, 0, .25), 0 4px 0 var(--panel-edge);
  transition: transform .08s;
}
.btn:hover:not(:disabled) { background: var(--pink); }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------------------------------------------------------------- final */

#end-screen { background: rgba(33, 31, 48, .88); }
#gameover-screen h2 { color: var(--gold); }

.end-card { animation: pop-in .6s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop-in { from { transform: scale(.6); opacity: 0; } }

.message { margin: 0 0 14px; }
.message p { margin: 0 0 10px; }
.stats { margin: 0 0 4px; color: var(--ink-soft); }
.stats strong { color: var(--gold); font-weight: normal; }
.perfect { margin: 0; color: var(--gold); }
.end-card .btn { margin-top: 16px; }

#end-rain {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#end-rain span {
  position: absolute;
  top: -40px;
  color: var(--pink);
  opacity: .8;
  animation: fall linear infinite;
}
#end-rain span:nth-child(3n) { color: var(--gold); }
#end-rain span:nth-child(4n) { color: var(--ink); }
@keyframes fall {
  to { transform: translateY(calc(100vh + 80px)) rotate(360deg); }
}

/* ---------------------------------------------------------------- orientación */

#rotate-hint {
  display: none;
  position: absolute;
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 8px 12px;
  font: 20px var(--text);
  white-space: nowrap;
  background: var(--panel-edge);
  border-radius: 6px;
  pointer-events: none;
}
@media (orientation: portrait) and (pointer: coarse) {
  body.playing #rotate-hint { display: block; }
}

@media (max-height: 420px) {
  .card { padding: 14px 18px 18px; }
  .hero { width: 64px; height: 64px; background-size: 832px 3456px; background-position-y: -1600px; margin-bottom: 4px; }
  @keyframes hero-idle { to { background-position: -128px -1600px; } }
  .lead, .message, .stats, .perfect, .keys { font-size: 19px; }
  #stick { width: 104px; height: 104px; }
  #knob { width: 52px; height: 52px; }
  #jump-btn { width: 92px; height: 92px; }
}

@media (prefers-reduced-motion: reduce) {
  #end-rain { display: none; }
  .end-card, .screen { animation: none; }
}
