*{box-sizing:border-box}body{margin:0;background:#101e21;color:#edf5e9;font-family:system-ui,sans-serif;overflow:hidden;touch-action:manipulation}canvas{display:block;width:100vw;height:100dvh}button{touch-action:manipulation;border:1px solid #73bf8b;background:#173b32;color:#fff;padding:10px 16px;border-radius:8px;cursor:pointer;font-weight:700}#hud{position:fixed;top:max(14px,env(safe-area-inset-top));left:16px;right:16px;display:flex;align-items:center;gap:10px;z-index:2}#hud b{margin-right:auto}small{font-weight:400;font-size:11px}#hud small{display:block;letter-spacing:2px;color:#94d6ad}#score{font-size:24px;font-weight:800}#cross{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);font-size:26px;pointer-events:none}#cross.hit{color:#ff5873;transform:translate(-50%,-50%) scale(1.5)}#notice{position:fixed;top:22%;width:100%;text-align:center;font-size:24px;font-weight:800;pointer-events:none}#menu{position:fixed;inset:0;display:grid;place-items:center;background:#081a23b8;z-index:5;backdrop-filter:blur(7px)}section{max-width:560px;padding:26px}h1{font-size:clamp(50px,10vw,100px);line-height:.88;margin:25px 0;letter-spacing:-5px}em{color:#ff5272;font-style:normal}section p{line-height:1.8;color:#b9d5d1}#start{background:#ff5272;border:none;padding:16px 38px;font-size:18px}#touch{display:none}body.mobile #touch{display:block}#stick{position:fixed;bottom:max(28px,env(safe-area-inset-bottom));left:30px;width:110px;height:110px;border:2px solid #ffffff55;border-radius:50%;background:#ffffff10}#stick i{display:block;position:absolute;left:32px;top:32px;width:42px;height:42px;border-radius:50%;background:#85e1aa88}#fire{position:fixed;right:28px;bottom:max(35px,env(safe-area-inset-bottom));width:90px;height:90px;border-radius:50%;background:#e83862bb;border:2px solid #ff9fb0}#touch span{position:fixed;right:22px;bottom:140px;font-size:11px;color:#c3d6d5;pointer-events:none}@media(max-width:600px){#hud{gap:6px;left:10px;right:10px}#hud b{font-size:12px}#hud small{font-size:8px}#hud button{padding:8px;font-size:11px}#score{font-size:19px}}

select{background:#173b32;color:white;padding:10px;border:1px solid #73bf8b;border-radius:8px}#score{font-size:18px}
#menu section{max-height:100dvh;overflow-y:auto;touch-action:pan-y pinch-zoom}
@media(max-height:500px){#menu section{padding:12px 20px;max-width:680px}#menu h1{font-size:38px;margin:10px 0;letter-spacing:-2px}#menu p{line-height:1.35;margin:7px 0}#menu #start{padding:10px 28px}#menu select{padding:5px}}

canvas,#stick,#fire,#pause{touch-action:none;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}#hud{pointer-events:none}#hud button{pointer-events:auto}body.mobile #pause{font-size:11px;min-height:44px}body.mobile #notice{font-size:clamp(14px,3vw,22px);padding:0 12px}

#party-panel{position:fixed;inset:0;display:none;place-items:center;background:#081a23ed;z-index:6;touch-action:pan-y pinch-zoom;overflow-y:auto}#party-panel section{width:min(680px,100%);max-width:680px;max-height:100dvh;overflow:auto;padding:20px;touch-action:pan-y pinch-zoom}#party-panel h2{margin:8px 0}#party-panel p{line-height:1.4;margin:10px 0}.party-row{display:flex;flex-wrap:wrap;align-items:end;gap:8px;margin:12px 0}.party-row label{display:flex;flex-direction:column;gap:4px;font-size:12px}.party-row input{width:80px;background:#173b32;color:white;border:1px solid #73bf8b;border-radius:8px;padding:10px}#actions{position:fixed;right:28px;bottom:145px;z-index:2;display:flex;gap:8px;pointer-events:none}#actions button{pointer-events:auto;touch-action:none;min-height:44px}#touch span{bottom:205px}#score{font-size:15px}@media(max-width:600px){#hud b{width:100%;margin:0}#hud small{letter-spacing:1px}#hud{gap:5px}#hud button{padding:7px;min-height:40px}#score{font-size:13px}#actions{right:16px;bottom:140px;gap:5px}#actions button{padding:8px;font-size:12px}#party-panel section{padding:14px}.party-row select{max-width:130px;font-size:12px}.party-row button{padding:9px;font-size:12px}}

#party:disabled,#party-menu:disabled{opacity:.45;cursor:default}
/* Inventory candidate: no combat layout or gameplay selectors changed. */
#party-panel{overflow:hidden;background:#07171f;z-index:70;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}
#party-panel .party-shell{display:grid;grid-template-rows:auto auto minmax(0,1fr) auto;width:min(960px,100%);max-width:960px;height:100%;max-height:100dvh;overflow:hidden;padding:12px 18px;gap:8px}
#party-panel .party-header{display:flex;align-items:center;justify-content:space-between;gap:12px}#party-panel h2{font-size:20px;margin:0}#party-panel h3{font-size:16px;margin:0}#party-panel h4{font-size:14px;margin:12px 0 6px}#party-panel p{font-size:13px;line-height:1.45;margin:6px 0}
#party-panel button{min-width:44px;min-height:44px;font-size:14px;padding:10px 12px;touch-action:manipulation}#party-panel button:focus-visible{outline:3px solid #fff;outline-offset:2px}#party-panel button:disabled{opacity:.45;cursor:default}#party-panel button.selected{background:#285d4b;border-color:#bdffcb;box-shadow:inset 0 0 0 1px #bdffcb}
.party-cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}#party-panel .party-cards button{text-align:left;white-space:pre-line;line-height:1.4;font-size:13px;padding:8px 10px}
.party-content{overflow-y:auto;overscroll-behavior:contain;min-height:0;padding:0 3px 8px}.party-tabs,.party-options,.party-quantity{display:flex;flex-wrap:wrap;gap:8px;margin:8px 0}.party-tabs>button{flex:1}.party-quantity{align-items:center}.party-quantity output{min-width:48px;text-align:center;font-size:22px;font-weight:800;font-variant-numeric:tabular-nums}#party-preview{background:#16342e;border-left:3px solid #8ae3a8;padding:10px}#party-reason{color:#e7cba1}#party-message{color:#bdffcb}
.party-footer{display:grid;grid-template-columns:auto minmax(0,1fr) auto auto;gap:8px;border-top:1px solid #43645a;padding-top:8px;background:#07171f}#party-confirm{background:#285d4b}
@media(max-height:500px) and (orientation:landscape){#party-panel .party-shell{grid-template-columns:210px minmax(0,1fr);grid-template-rows:auto minmax(0,1fr) auto;gap:6px 14px}.party-header{grid-column:1/-1}.party-cards{grid-column:1;grid-row:2;display:flex;flex-direction:column;overflow-y:auto}.party-cards button{flex:1}.party-content{grid-column:2;grid-row:2}.party-footer{grid-column:1/-1;grid-row:3}#party-panel .party-header p{margin:0}}
@media(max-width:600px){#party-panel .party-shell{padding:10px;gap:8px}#party-panel .party-header{align-items:start;flex-direction:column;gap:0}#party-panel .party-cards{gap:5px}#party-panel .party-cards button{font-size:12px;padding:6px}.party-footer{grid-template-columns:repeat(3,minmax(0,1fr))}.party-footer #party-confirm{grid-column:1/-1;grid-row:1}}

/* Keep the before/after numbers beside the action even after content scrolls. */
#party-panel .party-footer>p{grid-column:1/-1;grid-row:1;margin:0;padding:7px 10px;background:#16342e;border-left:3px solid #8ae3a8;overflow-wrap:anywhere}
#party-panel #party-confirm:not(:disabled){background:#a0e8b5;color:#09291c;border-color:#c3ffd2}#party-panel #party-cancel{background:transparent}
@media(max-width:600px){.party-footer #party-confirm{grid-row:2}}
@media(max-height:500px) and (orientation:landscape) and (max-width:600px){#party-panel .party-shell{grid-template-columns:160px minmax(0,1fr);padding:8px;gap:6px 10px}#party-panel .party-header{flex-direction:row;align-items:center}.party-footer{grid-template-columns:auto minmax(0,1fr) auto auto}.party-footer #party-confirm{grid-column:2;grid-row:auto}#party-panel .party-cards button{font-size:12px;flex:none;min-height:64px}.party-cards{gap:6px}}

#party-panel .party-cards button{word-break:keep-all;overflow-wrap:anywhere}

/* Reuse the inventory palette and its portrait/landscape layout. */
#party-panel [hidden],#result-panel[hidden]{display:none!important}
#party-step{color:#bdffcb}#party-panel .party-tabs button{flex:0 1 auto;min-width:100px}
#party-panel #party-access:empty{display:none}
#result-panel{position:fixed;inset:0;z-index:70;display:grid;place-items:center;background:#081a23d9;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left))}
#result-panel section{max-width:560px;max-height:100%;overflow:auto}#result-panel h2{color:#bdffcb;font-size:clamp(26px,6vw,42px)}#result-panel button{min-width:44px;min-height:48px;touch-action:manipulation}#result-panel button:focus-visible{outline:3px solid #fff;outline-offset:3px}

/* Result art is static: no second 3D scene or runtime portrait rendering. */
#result-panel [hidden]{display:none!important}
#result-panel .result-shell{position:relative;isolation:isolate;width:min(900px,100%);max-width:900px;display:grid;grid-template-rows:auto auto minmax(0,1fr) auto auto;gap:8px;padding:clamp(12px,3vw,24px);text-align:center}
#result-panel.victory .result-shell{height:min(740px,100%);overflow:hidden}
#result-panel .result-shell>p{margin:0;font-size:14px;line-height:1.4}#result-panel .result-brand{font-size:12px;letter-spacing:2px}
#result-panel #result-title{margin:0;line-height:1.1;font-size:clamp(34px,7vmin,52px);overflow-wrap:anywhere}#result-panel.defeat #result-title{color:#ff859b}
#result-portraits{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;min-height:0;height:100%}
#result-portraits figure{display:grid;grid-template-rows:minmax(0,1fr) auto;min-height:0;height:100%;margin:0}
#result-portraits img{display:block;width:100%;height:100%;min-height:0;object-fit:contain;pointer-events:none}
#result-portraits figcaption{font-size:14px;color:#bdffcb;font-weight:700;line-height:1.5}
#result-panel #result-retry{justify-self:center;width:min(320px,100%);position:relative;z-index:1}
#result-sparkles{position:absolute;inset:0;pointer-events:none;overflow:hidden;z-index:-1}
#result-sparkles i{position:absolute;left:12%;top:23%;color:#d9f6ba;font-style:normal;font-size:20px;opacity:.25;animation:result-twinkle 2.8s ease-in-out infinite}
#result-sparkles i:nth-child(2){left:31%;top:17%;animation-delay:-.8s}#result-sparkles i:nth-child(3){left:53%;top:26%;animation-delay:-1.5s}#result-sparkles i:nth-child(4){left:83%;top:21%;animation-delay:-2s}
#result-sparkles i:nth-child(5){left:7%;top:66%;animation-delay:-1.2s}#result-sparkles i:nth-child(6){left:35%;top:74%;animation-delay:-2.3s}#result-sparkles i:nth-child(7){left:66%;top:60%;animation-delay:-.5s}#result-sparkles i:nth-child(8){left:92%;top:72%;animation-delay:-1.8s}
@keyframes result-twinkle{0%,100%{opacity:.15;transform:scale(.7)}50%{opacity:.65;transform:scale(1.05)}}
@media(max-height:500px) and (orientation:landscape){#result-panel .result-shell{padding:10px 18px;gap:4px}#result-panel .result-brand{display:none}#result-panel .result-shell{grid-template-rows:auto minmax(0,1fr) auto auto}#result-panel #result-title{font-size:30px}#result-portraits figcaption{font-size:12px}#result-panel .result-shell>p{font-size:12px}#result-panel #result-retry{min-height:44px;padding:8px 14px}}
@media(prefers-reduced-motion:reduce){#result-sparkles i{animation:none;opacity:.25;transform:none}}

/* Search action stays above FIRE/stick and respects safe areas. */
#actions{right:max(16px,env(safe-area-inset-right));bottom:max(140px,calc(env(safe-area-inset-bottom) + 130px))}#interact{min-width:48px;min-height:48px;max-width:min(250px,58vw);white-space:normal}#interact:disabled{opacity:.8;cursor:default}#party-keys{color:#efd69c}

#memo-panel[hidden]{display:none}#memo-panel{position:fixed;inset:0;z-index:80;display:grid;place-items:center;background:#081a23ed;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);touch-action:pan-y pinch-zoom}
#memo-panel .memo-shell{display:grid;grid-template-rows:auto minmax(0,1fr) auto;gap:10px;width:min(720px,100%);height:min(700px,100dvh);max-height:100dvh;padding:20px;overflow:hidden}#memo-panel header p{margin:4px 0}#memo-panel h2{margin:8px 0}#memo-count{color:#bdffcb;font-weight:700}.memo-scroll{overflow-y:auto;min-height:0;overscroll-behavior:contain}#memo-body{white-space:pre-line;font-size:18px;line-height:1.8;margin:8px 0 20px}#memo-list{display:flex;flex-wrap:wrap;gap:8px}#memo-panel button{min-height:44px;min-width:44px;touch-action:manipulation}#memo-panel button:disabled{opacity:.55}#memo-panel footer{display:flex;flex-wrap:wrap;gap:10px;align-items:center}#memo-panel footer small{width:100%;color:#94d6ad}#memo-future{font-size:13px;color:#cbd1c5}#memo-panel button:focus-visible{outline:3px solid white;outline-offset:2px}.story-intro{font-size:14px}#party-notes{margin:6px 0}
@media(max-height:500px) and (orientation:landscape){#memo-panel .memo-shell{height:100dvh;padding:10px 18px;gap:4px}#memo-panel h2{font-size:20px;margin:3px 0}#memo-body{font-size:16px;line-height:1.55;margin:6px 0 12px}#memo-panel footer small{width:auto}}
/* Keep objectives and controls legible against the bright local fog. */
#hud,#notice,#cross,#touch>span{text-shadow:0 1px 3px #07121d,0 0 2px #07121d;}

/* Damage is confined to the periphery. No blinking, shake or input interception. */
#damage-edge{position:fixed;inset:0;z-index:1;pointer-events:none;opacity:0;background:radial-gradient(ellipse at center,transparent 48%,rgba(195,12,38,.5) 77%,rgba(220,18,40,.95) 100%)}
#player-health{position:relative;display:inline-flex;align-items:center;gap:6px;padding:5px 8px 11px;background:#142331;border:2px solid #a7d6ca;border-radius:6px;color:#fff;font-variant-numeric:tabular-nums;min-width:128px}
#player-health #hp-value{font-size:14px}#hp-loss{font-size:14px;color:#fff1ad;min-width:24px}
.hp-track{position:absolute;bottom:3px;left:6px;right:6px;height:4px;background:#080d15;overflow:hidden}.hp-track i{position:absolute;left:0;top:0;height:100%;width:100%}#hp-trail{background:#ffe4a3}#hp-fill{background:#64d5a7}
#player-health.low{border-color:#ff8c87;color:#ffd1c8}#player-health.low #hp-fill{background:#ed7777}#player-health.damaged{border-color:#fff2ad;background:#7f2030;box-shadow:0 0 0 2px #ffb6a6}#player-health.damaged #hp-value{color:#fff}
@media(max-width:600px){#player-health{min-width:112px;padding:3px 5px 10px}#player-health #hp-value,#hp-loss{font-size:12px}}
@media(prefers-reduced-motion:reduce){#hp-trail{visibility:hidden}}

#hud #player-health b{width:auto;margin:0;white-space:nowrap}
@media(max-height:500px) and (orientation:landscape){#hud>b small{display:none}#hud>b{font-size:12px}#hud{gap:6px}#hud button{padding:8px;font-size:11px}}

#control-hint{position:fixed;left:12px;top:76px;z-index:5;font-size:12px;color:#d2e5db;pointer-events:none;text-shadow:0 1px 3px #000}#result-story{white-space:pre-line;font-size:clamp(12px,2vw,16px);line-height:1.6;max-width:660px;margin:12px auto;color:#d7ede2}.mobile #control-hint{display:none}#actions{gap:6px}#switch-character{font-size:12px}@media(max-height:500px){#control-hint{top:61px;font-size:10px}#result-story{font-size:11px;line-height:1.35;margin:6px auto}}

.mobile #actions{flex-wrap:wrap;max-width:calc(100vw - 20px);justify-content:flex-end}.mobile #interact{max-width:min(230px,calc(100vw - 20px))}

#party-talk{position:fixed;left:16px;top:116px;width:min(430px,calc(100vw - 32px));padding:10px 14px;background:#102b25f5;border:1px solid #a3e5bd;border-radius:8px;color:#f2fff4;font-size:14px;line-height:1.55;white-space:pre-line;z-index:3;pointer-events:none}#party-talk[data-important="true"]{background:#25341aff;border:2px solid #ffdf87;color:#fffbe7}.result-active #hud,.result-active #touch,.result-active #actions,.result-active #notice,.result-active #cross,.result-active #control-hint,.result-active #party-talk{visibility:hidden!important}#result-panel{background:#071d25!important;opacity:1!important;z-index:20!important;padding:max(16px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left))!important;overflow-y:auto}#result-summary,#result-story{color:#f2fff5!important;text-shadow:none!important}#result-story{background:#12362d;padding:12px;border-radius:8px}#result-title{color:#c0ffcf!important;line-height:1.15!important;font-size:clamp(26px,6vw,48px)!important}body.mobile #party-talk{top:max(144px,calc(env(safe-area-inset-top) + 132px));left:12px;width:calc(100vw - 24px);font-size:12px;padding:7px 10px;max-height:90px;overflow:hidden}@media(max-height:500px){#party-talk,body.mobile #party-talk{top:82px;left:12px;width:min(390px,46vw);font-size:11px;line-height:1.35;max-height:82px}#result-story{font-size:12px}}

#notice{background:#081f29ed;color:#f0fff4;padding:8px 14px;line-height:1.45;font-size:clamp(14px,2vw,22px)}#party-talk,body.mobile #party-talk{top:auto;bottom:24px}body.mobile #party-talk{bottom:max(270px,calc(env(safe-area-inset-bottom) + 260px))}@media(max-height:500px){#party-talk,body.mobile #party-talk{top:140px;bottom:auto;width:min(310px,36vw);max-height:68px;font-size:10px}}

#captain-fragment{position:fixed;left:50%;top:32%;transform:translateX(-50%);max-width:calc(100vw - 30px);padding:6px 12px;border:1px dashed #dcc3c3;border-radius:5px;background:#261c28f5;color:#fff1ed;font-size:13px;letter-spacing:.06em;z-index:3;pointer-events:none}.result-active #captain-fragment{visibility:hidden!important}@media(max-height:500px){#captain-fragment{top:140px;left:70%;font-size:11px;max-width:48vw}}

/* Keep authored text stable after mobile orientation changes without disabling zoom. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
/* All six result children have explicit rows; the portraits absorb available space. */
#result-panel{inset:0 0 auto;height:100vh;height:100dvh;max-height:100dvh;touch-action:pan-y pinch-zoom}
#result-panel .result-shell{grid-template-rows:auto auto minmax(100px,1fr) auto auto auto}
#result-panel.victory .result-shell{overflow-y:auto}
#result-panel #result-summary,#result-panel #result-story{font-size:14px;line-height:1.4}
@media(max-height:500px) and (orientation:landscape){#result-panel .result-shell{grid-template-rows:auto minmax(64px,1fr) auto auto auto}#result-panel #result-summary,#result-panel #result-story{font-size:12px}}

/* renderer.setSize writes pixel inline sizes; never let a previous landscape canvas widen the mobile viewport. */
canvas{width:100%!important;height:100dvh!important;max-width:100%}

#result-portraits{grid-template-columns:repeat(4,minmax(0,1fr))}

/* Deliberate, isolated turn button; never commits on drag/cancel. */
#quick-turn{display:none;touch-action:none;min-height:44px;min-width:110px}
body.mobile #quick-turn{display:block}

/* Match the uniform 5% visual reduction; captions and other members keep their size. */
#result-portraits img[src$="/hinata.png"],#result-portraits img[src$="/momoka.png"]{transform:scale(.95);transform-origin:50% 100%}

/* Safari: incidental double taps never zoom the game, HUD or result backdrop.
   Reading panels retain deliberate scrolling and pinch zoom. */
html{touch-action:manipulation}
#hud,#cross,#notice,#control-hint,#party-talk,#captain-fragment{touch-action:none}
#result-panel,#result-panel .result-shell{overscroll-behavior:contain}

/* Four rescued characters remain legible on a narrow portrait screen. */
@media(max-width:600px) and (orientation:portrait){#result-portraits{grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));gap:6px}#result-portraits figcaption{font-size:12px}}
