* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #14110d; }
body { font-family: 'Jersey 15', 'Pixelify Sans', 'Courier New', monospace; font-weight: 500; font-size: 21px; line-height: 1.35; color: #2b2118; }
#screen { position: fixed; inset: 0; overflow: hidden; background: #000; }
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }

#dialog, #choices, #panel, .hpbox {
  background: linear-gradient(#f8f1de, #eadfc4); border: 4px solid #2b2118; border-radius: 10px;
  box-shadow: inset 0 0 0 3px #b5522d, inset 0 0 26px rgba(120, 80, 30, .18), 0 6px 0 rgba(0, 0, 0, .35), 0 12px 28px rgba(0, 0, 0, .35);
}
#dialog-name {
  position: absolute; left: 18px; top: -22px; padding: 2px 14px; border-radius: 7px;
  background: #b5522d; color: #fdf6e3; border: 3px solid #2b2118; font-weight: 700; letter-spacing: 1px;
}
#dialog {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: min(760px, 94%); min-height: 96px; padding: 14px 22px; cursor: pointer;
}
#dialog.sticky { display: block !important; }
#dialog-arrow { position: absolute; right: 16px; bottom: 8px; color: #b5522d; animation: bob .7s infinite alternate; }
@keyframes bob { to { transform: translateY(4px); } }

#choices {
  position: absolute; bottom: 126px; right: max(3%, calc(50% - 380px));
  display: grid; gap: 4px 18px; padding: 12px 18px 12px 12px; z-index: 2;
}
body.battle #choices { bottom: 18px; }
.choice { padding: 3px 6px 3px 22px; position: relative; cursor: pointer; white-space: nowrap; }
.choice.sel::before { content: '▶'; position: absolute; left: 2px; color: #b5522d; }

#panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(640px, 94%); padding: 20px 24px;
}
#panel h2 { font-size: 21px; margin: 0 0 8px; color: #b5522d; }
#panel h2:not(:first-child) { margin-top: 18px; }
#panel .line { display: flex; justify-content: space-between; gap: 12px; }
#panel .dim { opacity: .55; }
#panel .album { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#panel .album figure { margin: 0; text-align: center; font-size: 12px; line-height: 1.1; }
#panel .album img, #panel .album .falta div { width: 100%; aspect-ratio: 256 / 358; display: block; border: 1px solid #5a3a22; }
#panel .album .falta div { background: #cdbf9c; display: flex; align-items: center; justify-content: center; font-size: 40px; color: #8a7a5a; }
#panel .album figcaption { margin-top: 3px; height: 2.2em; overflow: hidden; }
.hpbox .pips { font-size: 13px; letter-spacing: 1px; margin-top: 3px; color: #b5522d; }
#panel svg.mapa { width: 100%; height: auto; display: block; border: 2px solid #5a3a22; }
#panel svg.mapa text { font-family: inherit; }
@keyframes mapa-late { 50% { opacity: .25; } }
#panel svg.mapa .aqui { animation: mapa-late 1s infinite; }
#panel .quest { margin-bottom: 12px; font-size: 18px; line-height: 1.25; }
#panel .quest b { font-size: 20px; }
#panel .dex { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px 14px; font-size: 16px; margin-bottom: 4px; }

#banner {
  position: absolute; top: 18px; left: 18px; padding: 10px 16px;
  background: #2b2118; color: #f4ecd8; border: 3px solid #b5522d; border-radius: 6px;
}

#hint { position: absolute; left: 12px; bottom: 2px; font-size: 13px; color: rgba(255, 255, 255, .55); text-shadow: 0 1px 0 #000; }

.hpbox { position: absolute; width: min(260px, 44%); padding: 10px 14px; }
#hp-enemy { top: 26px; left: max(3%, calc(50% - 380px)); }
#hp-player { bottom: 196px; right: max(3%, calc(50% - 380px)); }
.hpbox .row { display: flex; justify-content: space-between; }
.bar, .xpbar { background: #4a4036; border-radius: 4px; overflow: hidden; }
.bar { height: 10px; margin-top: 4px; }
.bar i { display: block; height: 100%; width: 100%; background: #5cb85c; transition: width .4s; }
.bar i.mid { background: #e0b020; }
.bar i.low { background: #d04a3a; }
.hpnum { text-align: right; font-size: 17px; margin-top: 4px; }
.xpbar { height: 5px; margin-top: 2px; }
.xpbar i { display: block; height: 100%; background: #4a8fd0; transition: width .4s; }

#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s linear; }

#title {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #f4ecd8;
  background: radial-gradient(ellipse at 50% 45%, rgba(26, 18, 13, .35) 0%, rgba(26, 18, 13, .78) 70%, rgba(26, 18, 13, .95) 100%);
}
#title h1 { font-size: clamp(40px, 10vw, 96px); margin: 18px 0 6px; letter-spacing: 6px; text-shadow: 6px 6px 0 #1a120d, 0 0 40px rgba(181, 82, 45, .7); }
.t-year { letter-spacing: 4px; color: #e6c25a; }
.t-sub { font-size: 26px; color: #e6c25a; }
.t-menu { margin-top: 48px; display: grid; gap: 10px; justify-items: center; }
.t-menu div { padding: 4px 18px; cursor: pointer; opacity: .6; }
.t-menu div.sel { opacity: 1; color: #e6c25a; }
.t-menu div.sel::before { content: '▶ '; }

#card {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #f4ecd8; cursor: pointer;
  padding: 8vw; animation: cardin .8s ease-out;
}
#card h2 { font-size: clamp(26px, 5vw, 44px); margin: 0 0 18px; color: #e6c25a; letter-spacing: 2px; }
#card p { font-size: clamp(18px, 2.6vw, 24px); max-width: 34em; margin: 0 auto; line-height: 1.6; }
#card span { display: block; margin-top: 30px; color: #b5522d; animation: bob .7s infinite alternate; }
@keyframes cardin { from { opacity: 0; } }

.dmg {
  position: absolute; transform: translate(-50%, -50%); pointer-events: none; z-index: 3;
  font-size: 34px; font-weight: 700; color: #fff; text-shadow: 0 3px 0 #2b2118, 0 0 8px rgba(0, 0, 0, .6);
  animation: dmg .9s ease-out forwards;
}
.dmg.big { font-size: 48px; color: #ffd24a; }
@keyframes dmg {
  0% { opacity: 0; margin-top: 10px; scale: .5; }
  18% { opacity: 1; margin-top: -14px; scale: 1.25; }
  100% { opacity: 0; margin-top: -64px; scale: 1; }
}

#debug-badge {
  display: none; position: absolute; top: 14px; right: 14px; padding: 2px 10px; border-radius: 6px;
  background: #e3bd2f; color: #16130f; border: 3px solid #16130f; font-weight: 700; font-size: 16px;
}
body.debug #debug-badge { display: block; }

/* ---------- Móvil: formato consola portátil (solo con body.touch) ----------
   Arriba, la pantalla en 4:3; abajo, la cruceta y los botones, como en una Game Boy.
   Todo lo que va sobre la imagen (diálogos, menús, barras) se dibuja a 560 px de ancho y se escala
   al ancho real de la pantalla (--s lo calcula main.js), así se ve igual en cualquier teléfono. */
body.touch { --ratio: 0.86; background: #b9b0a0; touch-action: none; overscroll-behavior: none; } /* alto de la pantalla respecto a su ancho */
body.touch #screen { inset: auto; top: 0; left: 0; width: 100vw; height: calc(100vw * var(--ratio)); }
body.touch #ui, body.touch #title, body.touch #card {
  inset: auto; top: 0; left: 0; width: 560px; height: calc(560px * var(--ratio)); transform: scale(var(--s, 1)); transform-origin: 0 0;
}
body.touch #title h1 { font-size: 64px; }
body.touch #card { padding: 30px; }
body.touch #card h2 { font-size: 30px; }
body.touch #card p { font-size: 19px; }
body.touch #hint { display: none; }
body.touch #hp-player { bottom: 186px; }
body.touch .hpbox { width: 38%; padding: 8px 12px; } /* más estrechas: en esta pantalla tapaban al bicho rival */
body.touch #choices { bottom: 122px; }
body.touch.battle #choices { bottom: 18px; }
body.touch #panel { max-height: 380px; overflow: auto; }
body.touch .choice { padding-top: 6px; padding-bottom: 6px; }

#gb { position: fixed; left: 0; right: 0; top: calc(100vw * var(--ratio)); bottom: 0; border-top: 6px solid #2b2118; }
#gb > * { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#gb .brand { position: absolute; top: 8px; left: 0; right: 0; text-align: center; font-size: 15px; letter-spacing: 3px; color: #5a5046; }
#dpad {
  position: absolute; left: 6vw; top: 50%; width: 38vw; height: 38vw; max-width: 190px; max-height: 190px;
  transform: translateY(-58%); border-radius: 50%; background: #9c9384; box-shadow: inset 0 3px 8px rgba(0, 0, 0, .25);
}
/* La cruz: dos barras oscuras que se cruzan. */
#dpad::before, #dpad::after { content: ''; position: absolute; background: #2b2118; border-radius: 8px; box-shadow: 0 4px 0 rgba(0, 0, 0, .35); }
#dpad::before { left: 36%; right: 36%; top: 8%; bottom: 8%; }
#dpad::after { top: 36%; bottom: 36%; left: 8%; right: 8%; }
#dpad i { position: absolute; z-index: 1; font-style: normal; font-size: 17px; color: #8a8072; transform: translate(-50%, -50%); }
#dpad .up { left: 50%; top: 20%; } #dpad .down { left: 50%; top: 80%; }
#dpad .left { left: 20%; top: 50%; } #dpad .right { left: 80%; top: 50%; }
#dpad b { display: none; }
#dpad[data-dir="up"] .up, #dpad[data-dir="down"] .down, #dpad[data-dir="left"] .left, #dpad[data-dir="right"] .right { color: #e6c25a; }
#tbtn { position: absolute; right: 6vw; top: 50%; transform: translateY(-58%) rotate(-20deg); display: flex; gap: 5vw; align-items: center; }
#tbtn button, #gb .pill {
  font: inherit; font-weight: 700; color: #f4ecd8; border: 0; padding: 0;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .35), inset 0 2px 0 rgba(255, 255, 255, .2);
}
#tbtn button { width: 19vw; height: 19vw; max-width: 92px; max-height: 92px; border-radius: 50%; font-size: 26px; background: #8f2f22; }
#tbtn button:active, #gb .pill:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); filter: brightness(1.2); }
#gb .pill {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%) rotate(-20deg);
  width: 84px; height: 26px; border-radius: 13px; font-size: 13px; letter-spacing: 1px; background: #6a6054;
}
#gb .pill:active { transform: translateX(-50%) rotate(-20deg) translateY(4px); }
#gb .full {
  position: absolute; right: max(10px, env(safe-area-inset-right)); top: 8px; width: 34px; height: 30px; border: 0; border-radius: 8px; padding: 0;
  font: inherit; font-size: 20px; line-height: 1; color: #f4ecd8; background: #6a6054; box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}
#gb .full.on { background: #8f2f22; }
/* El alto útil de verdad (sin la barra del navegador), donde el navegador sabe decirlo. */
@supports (height: 100dvh) { html, body { height: 100dvh; } }

/* En apaisado, la pantalla va centrada y los mandos a los lados. */
@media (orientation: landscape) {
  body.touch { --ratio: 0.75; }
  body.touch #screen { top: 0; left: calc(50vw - 66.667vh); width: 133.333vh; height: 100vh; }
  #gb { top: 0; border-top: 0; pointer-events: none; }
  #gb > * { pointer-events: auto; }
  #gb .brand { display: none; }
  #dpad { left: max(8px, env(safe-area-inset-left)); width: 22vh; height: 22vh; max-width: calc(50vw - 66.667vh - 16px); max-height: calc(50vw - 66.667vh - 16px); min-width: 96px; min-height: 96px; }
  #tbtn { right: max(8px, env(safe-area-inset-right)); flex-direction: column-reverse; gap: 3vh; transform: translateY(-58%); }
  #tbtn button { width: 15vh; height: 15vh; min-width: 54px; min-height: 54px; }
  #gb .pill { left: auto; right: max(10px, env(safe-area-inset-right)); bottom: 10px; transform: none; }
  #gb .pill:active { transform: translateY(4px); }
}
