:root { --bg: #10101a; --ink: #f2efe6; }
* { 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: ui-monospace, Menlo, Consolas, monospace;
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#app { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; padding-top: env(safe-area-inset-top); }
#c { width: 100%; height: 100%; display: block; }
#tools { position: absolute; top: calc(env(safe-area-inset-top) + 4px); right: 6px; display: flex; gap: 5px; }
.tool { font: inherit; font-size: 10px; color: var(--ink); background: var(--bg); border: 2px solid var(--ink); padding: 4px 6px; }
#pad {
  --s: calc(clamp(64px, min(21vw, 15dvh), 120px) * var(--k, 1)); --pb: calc(env(safe-area-inset-bottom) + 9dvh);
  position: absolute; left: 0; right: 0; bottom: 0; height: 38dvh; /* zona táctil; los botones flotan sobre el juego */
}
#pad b { position: absolute; display: block; opacity: .88; }
#pad i {
  display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; height: 100%;
  border: 3px solid var(--ink); font-style: normal; font-size: calc(var(--s) * .42); line-height: 1; color: var(--ink);
  background: var(--bg); pointer-events: none; box-shadow: 4px 4px 0 var(--ink); transition: transform .05s, box-shadow .05s;
}
#pad small { font-size: calc(var(--s) * .13); margin-top: 4px; letter-spacing: 1px; }
/* Pulgar izquierdo: ← → pegados abajo a la izquierda */
#pad b[data-b="left"], #pad b[data-b="right"] { width: var(--s); height: calc(var(--s) * 1.15); bottom: var(--pb); }
#pad b[data-b="left"] { left: calc(env(safe-area-inset-left) + 2vw); }
#pad b[data-b="right"] { left: calc(env(safe-area-inset-left) + 2vw + var(--s)); }
#pad b[data-b="left"] i { border-radius: 22px 6px 6px 22px; }
#pad b[data-b="right"] i { border-radius: 6px 22px 22px 6px; }
/* Pulgar derecho: SALTO grande abajo-derecha, DASH en arco por encima */
#pad b[data-b="jump"] {
  width: calc(var(--s) * 1.25); height: calc(var(--s) * 1.25); bottom: var(--pb); right: calc(env(safe-area-inset-right) + 3vw);
}
#pad b[data-b="dash"] { /* junto al salto, mismo nivel */
  width: var(--s); height: var(--s); bottom: calc(var(--pb) + var(--s) * .25);
  right: calc(env(safe-area-inset-right) + 3vw + var(--s) * 1.25 + 8px);
}
#pad b[data-b="jump"] i, #pad b[data-b="dash"] i, #pad b[data-b="potion"] i { border-radius: 50%; }
#pad b[data-b="potion"] { width: calc(var(--s) * .7); height: calc(var(--s) * .7); bottom: calc(env(safe-area-inset-bottom) + 1.5dvh); right: calc(env(safe-area-inset-right) + 3vw + var(--s) * 1.4 + 8px); }
#pad b[data-b="potion"] i { font-size: calc(var(--s) * .34); position: relative; }
#pad em { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; font: bold 12px/16px inherit; font-style: normal; text-align: center; background: var(--ink); color: var(--bg); border: 2px solid var(--bg); border-radius: 10px; }
#pad b.dim { opacity: .6; }
#pad b[data-b="dash"] i { font-size: calc(var(--s) * .34); }
#pad b.on { opacity: 1; }
#pad b.on i { background: var(--ink); color: var(--bg); transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }

/* Menú de cosméticos */
#menu {
  position: absolute; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; touch-action: pan-y;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 18px);
}
#menu[hidden] { display: none; }
#menu h2 { margin: 0 0 10px; font-size: 18px; letter-spacing: 3px; }
#prev { width: 100%; height: 200px; display: block; border: 3px solid var(--ink); margin-bottom: 14px; }
.mlabel { font-size: 11px; letter-spacing: 2px; margin: 12px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 56px; min-height: 48px; padding: 4px 10px; font: inherit; color: var(--ink); background: var(--bg);
  border: 3px solid var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.chip small { font-size: 10px; }
.chip .gl { font-size: 22px; line-height: 1; }
.chip .sw { width: 22px; height: 14px; border: 2px solid var(--ink); display: block; }
.chip.sel { background: var(--ink); color: var(--bg); }
.chip.sel .sw { border-color: var(--bg); }
.chip.lock { opacity: .4; border-style: dashed; }
.chip.ok { width: 100%; margin-top: 22px; font-size: 18px; letter-spacing: 3px; min-height: 54px; }

/* Modo "colocar botones" */
#pad.editing { background: rgba(128, 128, 128, .15); outline: 2px dashed var(--ink); outline-offset: -2px; }
#pad.editing b { opacity: 1; cursor: grab; touch-action: none; }
#pad.editing b i { box-shadow: 4px 4px 0 var(--ink); border-style: dashed; }
#lbar { position: absolute; top: 6px; left: 8px; right: 8px; z-index: 5; text-align: center; background: var(--bg); border: 2px solid var(--ink); padding: 6px; }
#lbar .lt { font-size: 11px; letter-spacing: 2px; margin-bottom: 6px; }
#lbar .lb { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
#lbar button { font: inherit; font-size: 12px; color: var(--ink); background: var(--bg); border: 2px solid var(--ink); min-width: 40px; min-height: 36px; padding: 2px 10px; }
#lbar button[data-a="ok"] { background: var(--ink); color: var(--bg); }

.wallet { font-size: 12px; letter-spacing: 1px; margin-bottom: 10px; }
.wallet b { font-size: 16px; }
.buybar { position: sticky; bottom: 0; margin-top: 14px; padding: 10px; background: var(--bg); border: 3px solid var(--ink); text-align: center; font-size: 12px; letter-spacing: 1px; }
.buybar .bb { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.buybar button { font: inherit; font-size: 12px; color: var(--bg); background: var(--ink); border: 2px solid var(--ink); min-height: 42px; padding: 4px 12px; }
.buybar button:disabled { background: var(--bg); color: var(--ink); opacity: .4; border-style: dashed; }

/* Subida de nivel */
#lvl, #sanct, #home, #fork, #settings, #chars { position: absolute; inset: 0; z-index: 12; background: var(--bg); padding: calc(env(safe-area-inset-top) + 24px) 16px 24px; overflow-y: auto; touch-action: pan-y; }
#lvl[hidden], #sanct[hidden], #home[hidden], #fork[hidden], #settings[hidden], #chars[hidden] { display: none; }
#sanct { z-index: 13; } #fork { z-index: 13; } #home { z-index: 14; } #settings, #chars { z-index: 16; } #menu { z-index: 20; }
#lvl h2, #sanct h2, #fork h2, #settings h2, #chars h2 { margin: 0; font-size: 26px; letter-spacing: 4px; text-align: center; }
.lsub { text-align: center; font-size: 11px; letter-spacing: 2px; margin: 6px 0 18px; }
.card { display: block; width: 100%; text-align: left; margin-bottom: 12px; padding: 14px; font: inherit; color: var(--ink); background: var(--bg); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.card b { font-size: 16px; letter-spacing: 1px; }
.card small { font-size: 11px; }
.card span { display: block; font-size: 12px; margin-top: 6px; line-height: 1.35; }
.card:active { background: var(--ink); color: var(--bg); }

/* Inicio */
.tag { text-align: center; font-size: 11px; letter-spacing: 6px; margin: 8px 0 0; }
.logo { margin: 0; text-align: center; font-size: clamp(34px, 12vw, 58px); letter-spacing: 10px; line-height: 1.05; border: 3px solid var(--ink); padding: 10px 0 10px 8px; box-shadow: 5px 5px 0 var(--ink); }
#hprev { width: 100%; height: 150px; display: block; margin: 14px 0 8px; }
.hstats { text-align: center; font-size: 11px; letter-spacing: 1px; line-height: 1.7; margin-bottom: 16px; }

/* Caminos (puertas) */
.doors { display: flex; gap: 12px; margin-top: 8px; }
.door { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; text-align: center; padding: 38px 8px 16px; font: inherit; color: var(--ink); background: var(--bg); border: 3px solid var(--ink); border-radius: 90px 90px 0 0; box-shadow: 4px 4px 0 var(--ink); }
.door small { font-size: 10px; letter-spacing: 2px; }
.door b { font-size: 16px; letter-spacing: 1px; }
.door span { font-size: 11px; line-height: 1.35; }
.door .plus { border-top: 2px dashed var(--ink); padding-top: 8px; }
.door:active { background: var(--ink); color: var(--bg); }
/* Ajustes */
.srow { margin: 14px 0; } .slabel { font-size: 11px; letter-spacing: 2px; margin-bottom: 6px; }
.srow input[type=range] { width: 100%; accent-color: var(--ink); height: 28px; }
.chip.pal { min-width: 44px; min-height: 40px; padding: 4px; } .chip.pal.sel { outline: 3px solid var(--ink); outline-offset: 2px; background-clip: padding-box; }


/* Título y escenas ASCII */
#title { position: absolute; inset: 0; z-index: 18; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom); }
#title[hidden] { display: none; }
#title { gap: 4px; }
#title pre { margin: 0; font: inherit; font-size: min(3.3vw, 1.5dvh, 13px); line-height: 1.1; white-space: pre; color: var(--ink); }
#title pre.cl { opacity: .75; }
#title .cl1 { animation: drift 9s ease-in-out infinite alternate; } #title .cl2 { animation: drift 13s ease-in-out infinite alternate-reverse; }
@keyframes drift { from { transform: translateX(-4ch); } to { transform: translateX(4ch); } }
#title .logo { margin: 0; }
#title .tap { font-size: 12px; letter-spacing: 4px; animation: blink 1.4s steps(2) infinite; }
@keyframes blink { 50% { opacity: .15; } }
pre.scene { margin: 6px auto 16px; font: inherit; font-size: min(3.9vw, 15px); line-height: 1.15; white-space: pre; width: max-content; max-width: 100%; color: var(--ink); }
pre.scene .tw { animation: blink 2.6s steps(2) infinite; } pre.scene .fl { animation: blink .5s steps(2) infinite; }

#sign { position: absolute; bottom: 38vh; left: 50%; transform: translateX(-50%); z-index: 9; width: min(86vw, 340px); padding: 8px 12px; text-align: center; background: var(--bg); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); pointer-events: none; }
#sign[hidden] { display: none; }
#sign b { display: block; font-size: 16px; letter-spacing: 3px; margin-bottom: 4px; }
#sign span { display: block; font-size: 11px; line-height: 1.5; }

#ascend { position: absolute; inset: 0; z-index: 19; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
#ascend[hidden] { display: none; }
#ascend pre { margin: 0; font: inherit; font-size: min(3.3vw, 2dvh, 13px); line-height: 1.12; white-space: pre; color: var(--ink); }
#ascend h2 { margin: 6px 0 0; font-size: 28px; letter-spacing: 6px; }
#ascend .tag { margin: 0; } #ascend .tap { font-size: 10px; letter-spacing: 3px; opacity: .6; margin-top: 10px; }

.rest { position: relative; width: max-content; max-width: 100%; margin: 0 auto 16px; }
.rest pre.scene { margin: 6px 0 0; }
.rest canvas { position: absolute; left: 52%; bottom: .2em; width: 10em; height: 6.4em; font-size: min(3.9vw, 15px); pointer-events: none; }
.ascw { position: relative; }
.ascw canvas { position: absolute; pointer-events: none; }

/* Equipo (pausa) */
#equip { position: absolute; inset: 0; z-index: 15; background: var(--bg); padding: calc(env(safe-area-inset-top) + 16px) 14px calc(env(safe-area-inset-bottom) + 16px); overflow-y: auto; touch-action: pan-y; }
#equip[hidden] { display: none; }
#equip h2 { margin: 0; font-size: 24px; letter-spacing: 6px; text-align: center; }
#equip .lsub { margin: 4px 0 8px; }
.xpb { height: 6px; border: 2px solid var(--ink); margin: 2px 0 4px; } .xpb i { display: block; height: 100%; background: var(--ink); }
#eprev { display: block; width: 100%; height: 130px; margin: 2px 0; }
.hearts { text-align: center; font-size: 24px; letter-spacing: 3px; margin-bottom: 8px; }
.hearts .h { color: var(--ink); opacity: .35; } .hearts .h.r { color: var(--danger, #e33); } .hearts .h.y { color: var(--reward, #fc3); }
.hearts .h.f { opacity: 1; } .hearts .h.hf { opacity: .65; }
.esec { margin: 10px 0; } .etitle { font-size: 10px; letter-spacing: 3px; margin-bottom: 5px; }
.erow { display: flex; flex-wrap: wrap; gap: 8px; }
.slot { width: 62px; height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; font: inherit; color: var(--ink); background: var(--bg); border: 3px solid var(--ink); padding: 0; }
.slot i { font-style: normal; font-size: 22px; line-height: 1; } .slot small { font-size: 8px; letter-spacing: 1px; margin-top: 3px; max-width: 58px; overflow: hidden; white-space: nowrap; text-overflow: clip; }
.slot.off { border-style: dashed; opacity: .45; } .slot.on { box-shadow: 3px 3px 0 var(--ink); }
.slot:active { background: var(--ink); color: var(--bg); }
.edesc { min-height: 54px; margin: 12px 0; padding: 8px 10px; border: 2px solid var(--ink); font-size: 12px; line-height: 1.45; }
.ego { text-align: center; } .ego span { margin-top: 4px; }
#toast { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18dvh); transform: translateX(-50%); z-index: 30; padding: 8px 14px; background: var(--bg); color: var(--ink); border: 3px solid var(--ink); font-size: 12px; letter-spacing: 1px; pointer-events: none; }
#toast[hidden] { display: none; }

textarea.bk { width: 100%; margin-top: 8px; font: inherit; font-size: 11px; color: var(--ink); background: var(--bg); border: 2px solid var(--ink); padding: 6px; resize: none; user-select: text; -webkit-user-select: text; }
#settings .srow .chip { margin: 4px 6px 0 0; }

/* Modo zurdo: ← → a la derecha; salto, dash y poción a la izquierda */
#pad.lefty b[data-b="right"] { left: auto; right: calc(env(safe-area-inset-right) + 2vw); }
#pad.lefty b[data-b="left"] { left: auto; right: calc(env(safe-area-inset-right) + 2vw + var(--s)); }
#pad.lefty b[data-b="jump"] { right: auto; left: calc(env(safe-area-inset-left) + 3vw); }
#pad.lefty b[data-b="dash"] { right: auto; left: calc(env(safe-area-inset-left) + 3vw + var(--s) * 1.25 + 8px); }
#pad.lefty b[data-b="potion"] { right: auto; left: calc(env(safe-area-inset-left) + 3vw + var(--s) * 1.4 + 8px); }

/* Intro */
#intro { position: absolute; inset: 0; z-index: 22; background: var(--bg); }
#intro[hidden] { display: none; }
#icv { position: absolute; inset: 0; width: 100%; height: 100%; }
#inj { position: absolute; display: none; pointer-events: none; }
.itop { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px; display: flex; gap: 6px; z-index: 2; }
.itop .tool { font-size: 12px; padding: 8px 10px; min-height: 40px; }
.icap { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 14dvh); text-align: center; padding: 0 20px; font-size: 15px; letter-spacing: 1px; line-height: 1.5; color: var(--ink); text-shadow: 0 0 6px var(--bg), 0 0 6px var(--bg); pointer-events: none; }
.icap.big { font-size: 22px; letter-spacing: 3px; }

/* Fin de partida (Infinito / Ruta del día) */
#over { position: absolute; inset: 0; z-index: 16; background: var(--bg); padding: calc(env(safe-area-inset-top) + 24px) 16px 24px; overflow-y: auto; touch-action: pan-y; }
#over[hidden] { display: none; }
#over h2 { margin: 0 0 12px; font-size: 24px; letter-spacing: 4px; text-align: center; }
.olines { text-align: center; font-size: 13px; letter-spacing: 1px; line-height: 1.9; margin-bottom: 12px; }
pre.ocard { margin: 0 auto 16px; width: max-content; max-width: 100%; padding: 10px 12px; border: 2px dashed var(--ink); font: inherit; font-size: 12px; line-height: 1.5; white-space: pre-wrap; }
#over .card:disabled { opacity: .45; }

/* Visitante de la hoguera */
.npcd { margin: 0 auto 14px; max-width: 420px; padding: 10px 12px; border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.npcd .who { font-size: 11px; letter-spacing: 3px; margin-bottom: 6px; }
.npcd .say { font-size: 14px; line-height: 1.5; margin-bottom: 8px; }
.npcd .od { font-size: 10px; line-height: 1.4; margin: 2px 0 8px; opacity: .8; }
.npcd .res { font-size: 12px; margin-top: 8px; border-top: 2px dashed var(--ink); padding-top: 6px; }
.npcd .chip { margin: 2px 6px 4px 0; }
.diario { font-size: 11px; line-height: 1.5; border: 2px dashed var(--ink); padding: 6px 8px; margin: 6px 0; max-height: 30dvh; overflow-y: auto; }
.diario b { letter-spacing: 1px; }

/* Botón ITEM: encima del salto (o a la izquierda en modo zurdo) */
#pad b[data-b="item"] { width: calc(var(--s) * .8); height: calc(var(--s) * .8); bottom: calc(var(--pb) + var(--s) * 1.25 + 10px); right: calc(env(safe-area-inset-right) + 3vw + var(--s) * .22); }
#pad b[data-b="item"] i { border-radius: 50%; font-size: calc(var(--s) * .34); position: relative; }
#pad.lefty b[data-b="item"] { right: auto; left: calc(env(safe-area-inset-left) + 3vw + var(--s) * .22); }
#pad b[data-b="item"].none { display: none; }

.ebag { margin: 8px 0; } .ebag .od { font-size: 10px; line-height: 1.4; margin: 2px 0 8px; opacity: .8; }
.slot.r1 { border-style: dotted; } .slot.r2 { box-shadow: 0 0 0 2px var(--bg), 0 0 0 5px var(--ink); } .slot.r3 { box-shadow: 0 0 0 2px var(--bg), 0 0 0 5px var(--reward), 4px 4px 0 5px var(--ink); }
