/* Keep battle UI inside the dynamic viewport. The measured puzzle width
   preserves the source frame ratio, within the 560px play-area cap. */
.battle-console{display:contents}
body.story-mode.in-battle{height:100dvh;overflow:hidden;overscroll-behavior:none}
body.story-mode.in-battle[data-battle-chapter] .wrap{width:min(100%,560px)}
.story-mode.in-battle .game{
 height:100dvh;min-height:0;overflow:hidden;
 padding-right:env(safe-area-inset-right);padding-left:env(safe-area-inset-left);padding-bottom:0;
}
/* The remaining height belongs to the battlefield, with room for HP bars. */
.story-mode.in-battle .arena{min-height:clamp(130px,26dvh,260px)}
.story-mode.in-battle .enemy-slot{bottom:24px}
.story-mode.in-battle .enemy-art{max-width:calc(100cqh - 82px)}
.story-mode.in-battle .battle-console{
 --puzzle-width:100%;
 --controls-top-gap:8px;
 --control-ratio:.155;
 --controls-overlap:.07;
 --hint-overlap:.05;
 container-type:inline-size;
 display:flex;flex-direction:column;flex:none;align-self:center;
 width:100%;gap:0;margin:0;padding:var(--controls-top-gap) 0 env(safe-area-inset-bottom);
 position:relative;
 background:none;border:0;box-shadow:none;
}
/* The upper halves of the controls remain over the scenery. The opaque
   wooden backing begins at their centers and continues behind the hint. */
.story-mode.in-battle .battle-console::before{
 content:"";position:absolute;z-index:0;pointer-events:none;
 inset:calc(var(--controls-top-gap) + max(44px,var(--puzzle-width) * var(--control-ratio)) * .5) 0 0;
 background-color:#30251c;
 background-image:linear-gradient(90deg,#1d100a65,transparent 18%,transparent 82%,#1d100a65),url('assets/ui/battle-console-walnut-v1-q80.jpg');
 background-size:100% 100%,100% auto;background-repeat:no-repeat,repeat-y;
 box-shadow:0 -1px #96794c,inset 0 3px 7px #160b0780;
}
.story-mode.in-battle .battle-quick-actions{
 width:var(--puzzle-width);align-self:center;padding-top:0;
 margin-bottom:calc(var(--puzzle-width) * var(--controls-overlap) * -1);
}
.story-mode.in-battle .command-frame{
 bottom:calc(var(--puzzle-width) * -.09);
 height:calc(var(--puzzle-width) * .142315);
}
.story-mode.in-battle #targetInfo{
 position:absolute;z-index:3;left:0;right:0;bottom:0;
 margin:0;padding:4px 10px;background:#14201bce;
 border-top:1px solid #e6d9ad28;color:#ffefcb;text-shadow:0 1px 2px #140a04;
}
.story-mode.in-battle #preview{
 /* Let the board's foreground foliage overlap only the hint's top trim. */
 width:calc(100% - 12px);align-self:center;
 margin:calc(var(--puzzle-width) * var(--hint-overlap) * -1) 6px 4px;
 padding:12px 80px 12px 25px;background:none;border:0;
 text-shadow:0 1px 2px #160d08;
}
/* Nine-slice keeps the existing panel's ornaments at a fixed size. */
.story-mode.in-battle #preview::before{
 content:"";position:absolute;inset:0;z-index:-1;pointer-events:none;
 border-image:url('assets/ui/battle-wood-panel.png') 34 64 fill / 17px 26px / 0 stretch;
}
.story-mode.in-battle #preview{isolation:isolate}
.story-mode.in-battle .lesson-help{
 right:22px;top:max(19px,calc(var(--puzzle-width) * .05 + 2px));
 background:linear-gradient(#765031,#3e271a);
 border-color:#c29a5d;box-shadow:inset 0 1px #e2c38a55,0 2px 4px #1c0d08;
}
.story-mode.in-battle .board{
 width:var(--puzzle-width);max-width:100%;align-self:center;flex:none;margin:0;
 aspect-ratio:1191 / 1218;
 /* The shared console covers every transparent part of the frame. */
 background-color:transparent;
 /* Percent padding resolves against the narrow parent; use the puzzle's own
    width so artwork, insets and tile positions all scale together. */
 padding:calc(var(--puzzle-width) * .1055) calc(var(--puzzle-width) * .1015) calc(var(--puzzle-width) * .11) calc(var(--puzzle-width) * .096);
 gap:calc(var(--puzzle-width) * .00521625);
}
.story-mode.in-battle .board .tile{
 width:100%;height:auto;aspect-ratio:1;align-self:center;
}

.story-mode.in-battle .battle-console .battle-action{width:max(44px,calc(var(--control-ratio) * 100%))}
