/* ==========================================================================
   Estructura y layout. Solo variables: colores y fuentes en theme.css.
   El juego es un rectángulo 9:16 fijo; todo se mide en --u (1/100 del ancho).
   ========================================================================== */

:root {
    --w: min(100vw, calc(100vh * 9 / 16));
    --u: calc(var(--w) / 100);
}
@supports (height: 100dvh) { :root { --w: min(100vw, calc(100dvh * 9 / 16)); } }
/* --H (altura visible real en px) la fija un script en index.php: en PWA/móvil 100vh y 100dvh pueden ser mayores que lo que se ve */
:root { --w: min(100vw, calc(var(--H, 100dvh) * 9 / 16)); }

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
    background: var(--page);
    color: var(--text);
    font-family: var(--font-body);
    position: fixed;
    inset: 0;
    width: 100%;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
svg { display: block; width: 100%; height: 100%; }

.stage { height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); display: grid; place-items: center; overflow: hidden; }
.game {
    position: relative;
    width: var(--w);
    height: calc(var(--w) * 16 / 9);   /* en pantallas más altas que 9:16 (móviles actuales) se estira hasta llenar la altura: el extra es para el tablero */
    height: min(100%, calc(var(--w) * 2.3));
    display: grid;
    grid-template-rows: auto 1fr auto;
    font-size: calc(var(--u) * 5);
    overflow: hidden;
}

/* ---------- Marcador ---------- */
.hud { display: flex; flex-direction: column; justify-content: space-between; gap: calc(var(--u) * .5); aspect-ratio: 320 / 90; width: 100%; min-height: 0; overflow: hidden; padding: calc(var(--u) * 1.5) calc(var(--u) * 3) calc(var(--u) * 4.5); }   /* el tamaño lo marca header.png (320×90 de arte) */
.hud-top { display: flex; align-items: center; gap: calc(var(--u) * 2); }
.title { flex: 1; margin: 0; text-align: center; font-size: calc(var(--u) * 3); line-height: 1.5; font-weight: normal; }
.title b { display: block; font-weight: normal; }
/* Botones de menú y ayuda: el PNG (32×32, con su marco) es el botón entero */
.icon-btn { width: calc(var(--u) * 8); height: calc(var(--u) * 8); display: block; flex: none; }
.icon-btn span { display: block; width: 100%; height: 100%; }
.stats { display: flex; justify-content: space-between; align-items: center; }
.stat { display: flex; align-items: center; gap: calc(var(--u) * 1.2); }
.stat i { width: calc(var(--u) * 5); height: calc(var(--u) * 5); display: block; }
.stat b { font-weight: normal; font-variant-numeric: tabular-nums; }
.lives { gap: calc(var(--u) * .4); }

/* ---------- Tablero ---------- */
.board-wrap { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), var(--cell));
    grid-auto-rows: var(--cell);
    touch-action: none;
}
.cell { position: relative; display: grid; place-items: center; font-size: calc(var(--cell) * .4); line-height: 1; }
.cell[data-i] { cursor: pointer; }
.cell > svg { width: 100%; height: 100%; }
.cell b { font-weight: normal; }
.cell .corner { position: absolute; left: 7%; top: 7%; font-size: .55em; }
.cell .x { position: absolute; inset: 18%; }
.knight {
    position: absolute; left: 0; top: 0; z-index: 2;
    width: var(--cell); height: var(--cell);
    display: grid; place-items: center;
    pointer-events: none;
    transition: transform 45ms linear;
}
.knight svg { width: 100%; height: 100%; }
.knight.left svg { transform: scaleX(-1); }
.float {
    position: absolute; left: 0; top: 0; z-index: 3;
    width: var(--cell); height: var(--cell);
    display: grid; place-items: center;
    pointer-events: none;
    font-size: calc(var(--cell) * .28);
}
.float span { animation: float-up .9s forwards; }
@keyframes float-up { to { transform: translateY(calc(var(--cell) * -.9)); opacity: 0; } }

/* ---------- Pie ---------- */
/* Zona inferior: el mensaje (msg-bg.png, 262×23 px de arte) sobre el dock (dock.png, 320×65). Todo colocado en % del arte.
   Los botones (97×49) encajan en los dos huecos del dock: x=62 y x=163, y=7. */
.bottom { position: relative; aspect-ratio: 320 / 94; }   /* 23 de mensaje + 6 de separación + 65 de dock */
.hint { margin: 0; text-align: center; }
.bottom .hint { position: absolute; left: 9.0625%; width: 81.875%; top: 0; height: 24.468%; display: flex; align-items: center; justify-content: center; padding: 0 2%; line-height: 1; white-space: nowrap; overflow: hidden; }
.bottom .dock { position: absolute; left: 0; right: 0; bottom: 0; height: 69.149%; padding: 0; }
.bottom .tools { position: absolute; inset: 0; }
.bottom .tools .btn, .bottom #btnMode { position: absolute; top: 10.769%; width: 30.3125%; height: 75.385%; min-height: 0; padding: 0; }
.bottom .tools .btn[data-tool="walk"], .bottom #btnMode { left: 19.375%; }
.bottom .tools .btn[data-tool="flag"] { left: 50.9375%; }
.bottom #btnEnd { position: absolute; right: 2%; top: 0; min-height: 0; padding: .25em .8em; font-size: calc(var(--u) * 2.6); }
.dock { display: flex; gap: calc(var(--u) * 2.5); padding: calc(var(--u) * 1) calc(var(--u) * 3) calc(var(--u) * 4); }
.btn {
    flex: 1; min-height: calc(var(--u) * 11);
    display: flex; align-items: center; justify-content: center; gap: .5em;
    padding: 0 calc(var(--u) * 2);
    font-size: calc(var(--u) * 3);
}
.btn i { width: calc(var(--u) * 5); height: calc(var(--u) * 5); display: block; flex: none; }
.btn[hidden] { display: none; }
.tools { flex: 1; display: flex; gap: calc(var(--u) * 2); }
.tools[hidden] { display: none; }
.tools .btn { flex-direction: column; gap: .35em; min-height: calc(var(--u) * 14); font-size: calc(var(--u) * 2.6); }
.tools .btn i { width: calc(var(--u) * 6.5); height: calc(var(--u) * 6.5); }

/* Aviso de bajada: ocupa el sitio del texto y los botones de abajo */
.ask { position: absolute; left: 0; right: 0; bottom: 0; z-index: 12; padding: calc(var(--u) * 3) calc(var(--u) * 3) calc(var(--u) * 4); display: flex; flex-direction: column; gap: calc(var(--u) * 2.5); }
.ask[hidden] { display: none; }
.ask p { margin: 0; text-align: center; line-height: 1.1; }
.ask-btns { display: flex; gap: calc(var(--u) * 2.5); }

/* ---------- Avisos ---------- */
.toast {
    position: absolute; left: 50%; bottom: calc(var(--u) * 31); z-index: 20;
    transform: translateX(-50%);
    max-width: 90%; width: max-content;
    padding: .3em .7em; text-align: center;
    pointer-events: none; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.banner { position: absolute; inset: 0; z-index: 15; display: grid; place-items: center; pointer-events: none; opacity: 0; transition: opacity .25s; }
.banner.show { opacity: 1; }
/* Cartel de planta: el tamaño lo marca title-floor.png (239×114 de arte) */
.banner > div { width: calc(var(--u) * 78); aspect-ratio: 239 / 114; padding: 0 0 calc(var(--u) * 1.5); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--u) * 1.2); }
.banner b { font-weight: normal; font-size: calc(var(--u) * 7.5); line-height: 1; white-space: nowrap; }
.banner.long b { font-size: calc(var(--u) * 4.6); }
.banner span { font-size: calc(var(--u) * 3.8); line-height: 1; }
.game.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translate(-1.5%, 0); } 50% { transform: translate(1.5%, .5%); } 75% { transform: translate(-1%, 0); } }

/* ---------- Ventanas ---------- */
.modal { width: calc(var(--w) * .88); max-height: calc(var(--H, 100vh) * .92); padding: calc(var(--u) * 5); font-size: calc(var(--u) * 5); overflow-y: auto; }
.modal h2 { margin: 0 0 calc(var(--u) * 4); text-align: center; font-size: calc(var(--u) * 4.2); font-weight: normal; line-height: 1.4; }
.modal p { margin: 0 0 calc(var(--u) * 3); line-height: 1.15; }
.modal .center { text-align: center; }
.modal .actions { display: flex; gap: calc(var(--u) * 2.5); margin-top: calc(var(--u) * 3); }
.menu { display: flex; flex-direction: column; gap: calc(var(--u) * 2.5); }
.help { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: calc(var(--u) * 2.5); line-height: 1.1; }
.help li { display: flex; gap: calc(var(--u) * 3); align-items: flex-start; }
.help i, .help .num { width: calc(var(--u) * 6); height: calc(var(--u) * 6); flex: none; display: grid; place-items: center; }
.help .num { font-size: calc(var(--u) * 3); font-weight: normal; }
.rows { display: flex; flex-direction: column; gap: calc(var(--u) * 1); margin-bottom: calc(var(--u) * 3); }
.row { display: flex; justify-content: space-between; gap: 1em; }
.row b { font-weight: normal; font-variant-numeric: tabular-nums; }
.row.total { margin-top: calc(var(--u) * 1.5); padding-top: calc(var(--u) * 2); }
.check { display: flex; align-items: center; gap: .5em; cursor: pointer; }
.check input { width: 1em; height: 1em; margin: 0; }
