* { 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; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

#ui { position: fixed; 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, 94vw); 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(3vw, 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, 94vw); 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 .dex { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 14px; font-size: 17px; 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, 44vw); padding: 10px 14px; }
#hp-enemy { top: 26px; left: max(3vw, calc(50% - 380px)); }
#hp-player { bottom: 196px; right: max(3vw, 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: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s linear; }

#title {
  position: fixed; 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: fixed; 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; }

/* ---------- Controles táctiles (solo con body.touch) ---------- */
#touch { position: absolute; inset: 0; pointer-events: none !important; z-index: 1; }
#touch > * { pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#dpad {
  position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: 176px; width: 148px; height: 148px; border-radius: 50%;
  background: rgba(43, 33, 24, .42); border: 3px solid rgba(244, 236, 216, .5);
}
#dpad i { position: absolute; font-style: normal; font-size: 22px; color: rgba(244, 236, 216, .75); transform: translate(-50%, -50%); }
#dpad .up { left: 50%; top: 17%; } #dpad .down { left: 50%; top: 83%; }
#dpad .left { left: 17%; top: 50%; } #dpad .right { left: 83%; top: 50%; }
#dpad b { position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px; border-radius: 50%; background: rgba(244, 236, 216, .28); }
#dpad[data-dir="up"] .up, #dpad[data-dir="down"] .down, #dpad[data-dir="left"] .left, #dpad[data-dir="right"] .right { color: #e6c25a; font-size: 28px; }
#tbtn { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: 176px; display: flex; gap: 14px; align-items: flex-end; }
#tbtn button {
  width: 68px; height: 68px; border-radius: 50%; font: inherit; font-weight: 700; font-size: 26px; color: #f4ecd8;
  background: rgba(181, 82, 45, .6); border: 3px solid rgba(244, 236, 216, .6);
}
#tbtn button[data-k="cancel"] { width: 56px; height: 56px; font-size: 22px; background: rgba(43, 33, 24, .5); }
#tbtn button[data-k="ok"] { margin-bottom: 26px; }
#tbtn button:active { background: #e6c25a; color: #2b2118; }
/* En combate todo se toca directamente: solo queda B, para volver atrás en los menús. */
/* Con un menú o un panel abierto pasa lo mismo: las opciones se tocan, y los botones no deben pisarlas. */
body.battle #dpad, body.battle #tbtn button[data-k="ok"], body.menu #dpad, body.menu #tbtn button[data-k="ok"] { display: none; }
body.battle #tbtn, body.menu #tbtn { bottom: auto; top: max(58px, env(safe-area-inset-top)); } /* arriba a la derecha, lejos de menús y de las barras de vida */
body.touch #hint { display: none; }
body.touch { touch-action: none; overscroll-behavior: none; }
body.touch .choice { padding-top: 9px; padding-bottom: 9px; }
body.touch #dialog, body.touch #choices, body.touch #panel { z-index: 2; }
body.touch #choices { bottom: 150px; max-width: 92vw; }
body.touch #panel { max-height: 78vh; overflow: auto; }
body.touch.battle #choices { bottom: 18px; }
