*{box-sizing:border-box}
:root{--view-width:100vw;--view-height:100dvh;--view-left:0px;--view-top:0px}
body{margin:0;background:#0d100d;color:#d4d9d1;font:14px system-ui}
main{max-width:1060px;margin:30px auto;padding:0 22px}
header{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:20px}
h1{font:26px Georgia;margin:8px 0}small{color:#9dba85;letter-spacing:.1em}
button,select,input{font:inherit;color:inherit;background:#20271e;border:1px solid #46543c;border-radius:5px;padding:9px 14px}
button{cursor:pointer}button:disabled{opacity:.55;cursor:wait}.actions{display:flex;gap:8px;flex-wrap:wrap}
#menu-toggle{display:none}#screen{margin:20px auto;background:black;max-width:960px;aspect-ratio:4/3;display:flex;align-items:center;justify-content:center;position:relative;min-width:0;overflow:hidden}
canvas{display:block;width:100%;height:100%;min-height:0;object-fit:contain;image-rendering:pixelated;outline:none}
#loading{position:absolute;inset:0;display:grid;place-content:center;background:#0d100d;color:#a6afa0;font-size:13px;text-align:center;padding:0;overflow:hidden}
#loading-intro{position:absolute;inset:0;width:100%;height:100%;object-fit:contain;pointer-events:none}
#loading-message{z-index:1;position:absolute;bottom:12px;left:12px;right:12px;margin:0;padding:6px;background:#0d100dd9;white-space:pre-wrap}
#keyboard-help{flex-basis:100%;display:flex;flex-wrap:wrap;gap:8px 18px;background:#171e15;padding:10px 14px;border-radius:5px;font-size:12px}
#keyboard-help kbd{display:inline-block;margin-left:4px;padding:1px 5px;border:1px solid #46543c;border-radius:3px;font:inherit;color:#f0f5e8}
#loading[hidden]{display:none}#storage-warning{position:absolute;top:4px;left:8px;right:8px;z-index:30;background:#222b20;padding:6px;font-size:12px}#storage-warning[hidden]{display:none}
#fullscreen-notice{position:absolute;top:48px;left:12px;right:12px;z-index:30;background:#222b20;padding:8px;font-size:12px}#fullscreen-notice[hidden]{display:none}
footer{color:#a6afa0;line-height:1.6}pre{white-space:pre-wrap;font-size:12px}#status{min-height:1.5em}
.embed,.embed body{width:100%;height:100%;overflow:hidden}
.embed main{margin:0;padding:0;max-width:none;height:100%;display:grid;grid-template-rows:auto minmax(0,1fr)}
.embed header{padding:2px 8px;gap:0}.embed header>div:first-child,.embed footer,.embed details{display:none}
.embed #keyboard-help{display:flex;padding:5px 6px;gap:3px 10px;font-size:10px;border-radius:0}
.embed #keyboard-help kbd{margin-left:2px;padding:0 3px}
.embed .actions{width:100%;gap:6px}.embed button{padding:5px 10px;font-size:13px}.embed #full{margin-left:auto}
.embed #screen{margin:0;width:100%;height:100%;min-height:0;max-width:none;aspect-ratio:auto}
#touch-controls[hidden]{display:none}
#touch-controls{position:absolute;inset:0;pointer-events:none;user-select:none;-webkit-user-select:none;touch-action:none}
#touch-controls button,#touch-stick{pointer-events:auto;touch-action:none;-webkit-tap-highlight-color:transparent}
#touch-controls button{width:42px;height:42px;min-width:42px;min-height:42px;padding:0;border-radius:50%;font-weight:700;color:#fff;background:#20271ed9;border:1px solid #b8c7a680;box-shadow:0 2px 6px #0008}
#touch-controls button[aria-pressed=true]{box-shadow:0 0 0 3px #e7edd2;filter:brightness(1.3)}
#touch-stick{position:absolute;bottom:16px;left:max(16px,env(safe-area-inset-left));width:110px;height:110px;border-radius:50%;background:#263022b8;border:2px solid #b8c7a680;display:grid;place-items:center}
.stick-knob{width:48px;height:48px;border-radius:50%;background:#a9b397a8;pointer-events:none}
.touch-shoulders{position:absolute;bottom:140px;left:max(8px,env(safe-area-inset-left));display:flex;gap:5px}
.touch-face{position:absolute;bottom:max(12px,env(safe-area-inset-bottom));right:max(16px,env(safe-area-inset-right));width:132px}
.touch-camera{display:grid;grid-template:repeat(3,42px)/repeat(3,42px);justify-content:center}
.touch-camera button{color:#ffe18b!important;font-size:12px}
.touch-camera button:nth-child(1){grid-area:1/2}.touch-camera button:nth-child(2){grid-area:2/1}.touch-camera button:nth-child(3){grid-area:2/3}.touch-camera button:nth-child(4){grid-area:3/2}
.touch-ab{display:flex;justify-content:flex-end;gap:10px;margin-top:4px}.touch-ab button{width:50px!important;height:50px!important}
.touch-ab [data-button=A]{background:#1643a7ed!important}.touch-ab [data-button=B]{background:#22763bed!important}
.touch-start{position:absolute;bottom:max(22px,env(safe-area-inset-bottom));left:calc(50% - 22px);font-size:11px}
.touch-controls:not(.embed) #screen{display:grid;grid-template-rows:minmax(0,1fr) 194px;aspect-ratio:auto}
.touch-controls:not(.embed) canvas{aspect-ratio:4/3;height:auto}
.touch-controls:not(.embed) #touch-controls{position:relative;width:100%;height:194px}
@media(max-width:600px){main{margin:10px auto;padding:0 10px}header{gap:4px}h1{font-size:22px}#screen{margin:12px 0}.actions{gap:5px}.actions button{padding:8px 10px}}
@media(pointer:coarse){
 .touch-controls,.touch-controls body{width:100%;height:100%;overflow:hidden;overscroll-behavior:none}
 .touch-controls:not(.embed) main{position:fixed;left:var(--view-left);top:var(--view-top);width:var(--view-width);height:var(--view-height);margin:0;padding:0;max-width:none;display:grid;grid-template-rows:40px minmax(0,1fr)}
 .touch-controls header{padding:2px max(8px,env(safe-area-inset-right)) 2px max(8px,env(safe-area-inset-left));gap:4px;z-index:20}
 .touch-controls header>div:first-child,.touch-controls footer,.touch-controls details{display:none}
 .touch-controls #keyboard-help{display:none}
 .touch-controls .actions{width:100%;gap:6px;flex-wrap:nowrap}.touch-controls .actions button{min-height:36px;font-size:12px;padding:6px 10px}
 .touch-controls #full{margin-left:auto}
 .touch-controls:not(.embed) #screen{margin:0;width:100%;height:100%;min-height:0;max-width:none;grid-template-rows:minmax(0,min(calc(var(--view-width)*.75),calc(var(--view-height) - 234px))) 194px;align-content:start}
 .touch-controls:not(.embed) canvas{width:100%;height:100%;aspect-ratio:auto}
 .touch-controls #touch-controls{max-width:100%}
}
@media(pointer:coarse) and (orientation:portrait){
 .touch-controls{--touch-clearance:64px}
 .touch-controls:fullscreen{--touch-clearance:env(safe-area-inset-bottom)}
 .touch-controls:not(.embed) #screen,.touch-controls.embed #screen{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,min(calc(var(--view-width)*.75),calc(var(--view-height) - 234px - var(--touch-clearance)))) minmax(0,1fr) calc(194px + var(--touch-clearance))}
 .touch-controls:not(.embed) #touch-controls,.touch-controls.embed #touch-controls{position:relative;grid-row:3;align-self:start;width:100%;height:194px}
 .touch-controls #touch-stick{left:max(32px,env(safe-area-inset-left))}
 .touch-controls .touch-shoulders{left:max(24px,env(safe-area-inset-left))}
 .touch-controls .touch-face{right:max(24px,env(safe-area-inset-right))}
 .touch-controls #loading{bottom:auto;height:min(calc(var(--view-width)*.75),calc(var(--view-height) - 234px - var(--touch-clearance)))}
}
@media(pointer:coarse) and (orientation:landscape){
 .touch-controls{--control-rail:128px;--host-left:56px;--host-right:56px;--host-bottom:52px}
 .touch-controls.embed,.touch-controls:fullscreen{--host-left:0px;--host-right:0px;--host-bottom:0px}
 .touch-controls:not(.embed) main,.touch-controls.embed main{grid-template-rows:minmax(0,1fr)}
 .touch-controls:not(.embed) #screen,.touch-controls.embed #screen{display:grid;grid-template-columns:calc(var(--control-rail) + max(var(--host-left),env(safe-area-inset-left))) minmax(0,1fr) calc(var(--control-rail) + max(var(--host-right),env(safe-area-inset-right)));grid-template-rows:minmax(0,1fr)}
 .touch-controls:not(.embed) canvas,.touch-controls.embed canvas{grid-column:2;grid-row:1;width:100%;height:calc(100% - var(--host-bottom));align-self:start;aspect-ratio:auto}
 .touch-controls:not(.embed) #touch-controls,.touch-controls.embed #touch-controls{position:absolute;inset:0;height:auto}
 .touch-controls header{position:absolute;top:max(6px,env(safe-area-inset-top));left:auto;right:calc(12px + max(var(--host-right),env(safe-area-inset-right)));display:flex;justify-content:flex-end;gap:6px;max-width:124px}
 .touch-controls #menu-toggle{display:block;min-height:36px;padding:5px 10px;font-size:12px;order:2}
 .touch-controls .actions{position:absolute;right:0;top:44px;width:110px;background:#101710ed;padding:3px;border-radius:5px;display:none;flex-direction:column;align-items:stretch}
 .touch-controls.menu-open .actions{display:flex}
 .touch-controls .touch-camera{grid-template:repeat(2,42px)/repeat(2,42px);gap:2px;justify-content:end}
 .touch-controls .touch-camera button:nth-child(n){grid-area:auto}
 .touch-controls .touch-shoulders{display:grid;grid-template-columns:repeat(2,42px);gap:5px;top:max(4px,env(safe-area-inset-top));bottom:auto;left:calc(max(var(--host-left),env(safe-area-inset-left)) + var(--control-rail)/2 - 45px)}
 .touch-controls .touch-start{left:calc(max(var(--host-left),env(safe-area-inset-left)) + var(--control-rail)/2 + 2px);top:max(51px,calc(env(safe-area-inset-top) + 47px));bottom:auto}
 .touch-controls #touch-stick{width:96px;height:96px;left:calc(max(var(--host-left),env(safe-area-inset-left)) + var(--control-rail)/2 - 48px);bottom:max(40px,env(safe-area-inset-bottom))}
 .touch-controls .touch-face{width:110px;right:calc(12px + max(var(--host-right),env(safe-area-inset-right)));bottom:max(40px,env(safe-area-inset-bottom))}
 .touch-controls #loading{left:calc(var(--control-rail) + max(var(--host-left),env(safe-area-inset-left)));right:calc(var(--control-rail) + max(var(--host-right),env(safe-area-inset-right)));bottom:var(--host-bottom)}
}
/* Small framed mobile players use a separate controller area below the image. */
@media(pointer:coarse) and (orientation:landscape) and (max-width:600px){
 .touch-controls.embed #screen{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) 194px}
 .touch-controls.embed canvas{grid-column:1;grid-row:1;height:100%}
 .touch-controls.embed #touch-controls{position:relative;grid-row:2;height:194px}
 .touch-controls.embed #touch-stick{left:16px;width:110px;height:110px;bottom:16px}
 .touch-controls.embed .touch-shoulders{display:flex;left:8px;top:auto;bottom:140px}
 .touch-controls.embed .touch-start{left:calc(50% - 21px);top:auto;bottom:22px}
 .touch-controls.embed .touch-face{width:132px;right:16px;bottom:12px}
 .touch-controls.embed .touch-camera{grid-template:repeat(3,42px)/repeat(3,42px);gap:0;justify-content:center}
 .touch-controls.embed .touch-camera button:nth-child(1){grid-area:1/2}.touch-controls.embed .touch-camera button:nth-child(2){grid-area:2/1}.touch-controls.embed .touch-camera button:nth-child(3){grid-area:2/3}.touch-controls.embed .touch-camera button:nth-child(4){grid-area:3/2}
 .touch-controls.embed #loading{left:0;right:0;bottom:194px}
}
:root:fullscreen,:root:fullscreen body{width:100%;height:100%;background:#000;overflow:hidden}
:root:fullscreen:not(.touch-controls) main{position:fixed;inset:0;margin:0;padding:0;max-width:none;display:grid;grid-template-rows:auto minmax(0,1fr)}
:root:fullscreen:not(.touch-controls) header{padding:2px 8px}:root:fullscreen header>div:first-child,:root:fullscreen footer,:root:fullscreen details{display:none}
:root:fullscreen:not(.touch-controls) #screen{width:100%;height:100%;max-width:none;margin:0;aspect-ratio:auto}
/* The save panel is a top-layer dialog; it never moves the game or controller. */
#save-dialog{color:#d4d9d1;background:#171e15;border:1px solid #667957;border-radius:10px;width:min(480px,calc(100% - 32px));max-height:calc(100dvh - 80px);padding:18px;overflow:auto;font-size:14px;line-height:1.5}
#save-dialog::backdrop{background:#000b}
#save-dialog .save-heading{display:flex;justify-content:space-between;align-items:center;gap:12px}
#save-dialog h2{font-size:19px;margin:0}
#save-dialog button{min-height:40px;padding:8px 12px;font-size:14px}
#save-dialog .save-buttons{display:flex;flex-wrap:wrap;gap:8px;margin:16px 0}
#save-dialog label{display:block;margin:12px 0 6px}
#save-dialog input{width:100%;min-width:0;padding:8px}
#save-dialog .save-replace{color:#c9c7a8;font-size:13px}
#save-message{white-space:pre-wrap;margin-bottom:0}
#save-message:empty{display:none}
#save-dialog [hidden]{display:none}
@media(pointer:coarse) and (max-width:360px){.touch-controls .actions{gap:4px}.touch-controls .actions button{padding:6px 7px}}
@media(pointer:coarse) and (orientation:landscape){#save-dialog{max-height:calc(var(--view-height) - 64px);width:min(480px,calc(var(--view-width) - 144px));margin-top:12px}}

#save-state{position:fixed;top:calc(env(safe-area-inset-top,0px) + 4px);left:50%;transform:translateX(-50%);z-index:45;max-width:calc(100vw - 24px);margin:0;padding:6px 12px;border-radius:6px;background:#243b24;color:#f0f5e8;font:13px/1.4 system-ui;pointer-events:none}#save-state[data-state="pending"]{background:#494124}#save-state[data-state="error"]{background:#602c29}#save-state[hidden]{display:none}
