/* Shared viewport and safe areas. Keep the outer frame fixed and scroll its content. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
/* The document itself must never pan under iOS browser chrome. Panels scroll inside it. */
html,body{position:fixed;inset:0;overscroll-behavior:none}
#app{--safe-top:max(10px,env(safe-area-inset-top));--safe-left:max(12px,env(safe-area-inset-left));--safe-right:max(12px,env(safe-area-inset-right));--safe-bottom:max(12px,env(safe-area-inset-bottom));position:fixed;top:var(--viewport-top,0px);left:var(--viewport-left,0px);width:var(--viewport-width,100%);height:var(--viewport-height,100dvh);right:auto;bottom:auto}
button,a,input{touch-action:manipulation}
input{font-size:16px}
#app.keyboard-open .menu-shell{display:flex;flex-direction:column}
#app.keyboard-open .menu-shell :is(.menu-title,.selection-title,.load-status){display:none}
#app.keyboard-open .selection-layout{flex:1;min-height:0}
#app.keyboard-open .menu-bottom{flex:none}
.screen{padding-top:calc(var(--safe-top) + 58px);padding-bottom:var(--safe-bottom)}
.screen .menu-shell,.screen .flow-panel{height:min(710px,100%);max-height:100%;margin:auto}
.selection-layout,.brief-slide,.result-layout,#inspect-content,.share-body{overscroll-behavior:contain}
.topbar{top:var(--safe-top)}
#inspect-panel{position:absolute;height:100%;bottom:auto}
.header-actions #inspect-return>span:last-child{display:inline}
#share-modal{padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left)}
.share-shell{width:min(1120px,100%);height:min(790px,100%);max-height:100%;padding:24px;gap:20px}
.share-head{align-items:center}
.share-head button{width:44px;height:44px}
.share-body{grid-template-columns:minmax(0,1fr) minmax(240px,30%);gap:28px;overflow:hidden}
.share-visual{display:grid;grid-template-rows:minmax(0,1fr) auto auto;gap:12px;min-width:0;min-height:0}
.share-preview{height:auto;padding:14px;min-height:0;display:flex;align-items:center;justify-content:center}
.share-preview img{max-height:100%;max-width:100%;width:100%;height:100%;object-fit:contain;border-radius:0}
.share-sizes{grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
.share-sizes button{min-height:52px;justify-content:center;flex-wrap:wrap;gap:5px 10px;font-size:14px;padding:9px 6px;text-align:center}
.share-sizes button small{display:block;font-size:12px}
#share-dimensions{text-align:center;font-size:12px;line-height:1.5}
.share-side{gap:16px;padding:4px 4px 4px 0;overscroll-behavior:contain}
.share-summary{border-bottom:1px solid var(--line);padding-bottom:22px;overflow-wrap:anywhere}
.share-summary .eyebrow{font-size:12px;letter-spacing:1px;line-height:1.8}
.share-summary h3{font-size:26px;margin:16px 0 5px;line-height:1.4}
.share-summary p{font-size:14px;color:var(--muted);margin:0}
.share-details{display:grid;gap:18px;margin:26px 0 0}
.share-details dt{font-size:13px;color:var(--muted);margin-bottom:5px}
.share-details dd{font:26px ui-monospace,monospace;margin:0;color:var(--acid)}
.share-actions{gap:10px;margin:0}
.share-actions .primary,.share-actions .secondary{min-height:46px;font-size:15px}
.share-actions [aria-disabled=true]{opacity:.45;cursor:wait;pointer-events:none}
.share-hint{font-size:13px;line-height:1.8}
#share-status{font-size:13px}
#result-board .leader-switch{grid-template-columns:repeat(2,minmax(0,1fr))}

/* Narrow screens: complete menus, readable labels, and a single scrolling result. */
@media(max-width:760px){
 #app[data-phase=inspect] .topbar{padding-bottom:0;border-bottom:0}
 .topbar{left:var(--safe-left);right:var(--safe-right);gap:6px;min-height:44px}
 .brand{font-size:15px;gap:6px;white-space:nowrap}.brand small{display:none}.brand-mark{width:30px;height:30px}
 .header-actions{gap:4px}.header-actions button{min-width:44px;min-height:44px;padding:8px}
 .header-actions .sound-menu>#volume-toggle span{display:none}
 .header-actions #inspect-return{gap:5px;font-size:13px}
 .screen,#app.handheld .screen{padding:calc(var(--safe-top) + 54px) var(--safe-right) var(--safe-bottom) var(--safe-left);overflow:hidden;align-items:stretch}
 .screen .menu-shell,.screen .flow-panel,#app.handheld .screen .menu-shell,#app.handheld .screen .flow-panel{height:100%;padding:16px;gap:12px}
 .menu-title h1{font-size:24px;margin:0}.menu-title h1 br,.menu-title .eyebrow,.menu-title>p{display:none}
 .selection-title{padding-top:10px;font-size:14px;gap:8px}.selection-title>span:last-child{font-size:12px;letter-spacing:0}
 .selection-layout,#app.handheld .selection-layout{display:block;overflow:auto;min-height:0;max-height:none;scrollbar-gutter:stable;margin:0}
 .roster,#app.handheld .roster{grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:none;grid-auto-rows:max-content;height:auto;gap:10px;max-height:none;min-height:0;overflow:visible}
 .character-card,#app.handheld .character-card{padding:0 0 10px;min-width:0}
 .character-card .roach-art,#app.handheld .character-card .roach-art{width:100%;max-width:145px;margin:auto;aspect-ratio:1}
 .character-card strong,#app.handheld .character-card strong{font-size:14px;padding:0 10px}
 .character-card small,#app.handheld .character-card small{font-size:12px;padding:0 10px}
 .selected-detail,#app.handheld .selected-detail{display:block;border-left:0;border-top:1px solid var(--line);padding:16px 0 0;margin:16px 0 0;max-height:none;overflow:visible}
 .selected-detail .roach-art{display:none}.selected-detail h2{font-size:22px}.selected-detail p,.species-facts dd{font-size:14px;line-height:1.8}
 .selected-detail .species-facts{display:block}.selected-detail .species-facts dt{font-size:13px}
 .menu-bottom,#app.handheld .menu-bottom{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding-top:10px;flex-wrap:wrap}
 .menu-bottom label,#app.handheld .menu-bottom label{font-size:14px;min-width:0;gap:5px}
 .menu-bottom input,#app.handheld .menu-bottom input{max-width:none;font-size:16px;padding:10px 12px;min-height:44px}
 .menu-bottom .primary,#app.handheld .menu-bottom .primary{width:100%;min-width:0;min-height:46px;font-size:15px;justify-content:space-between}
 .menu-note{display:none}.load-status{font-size:12px;text-align:left;line-height:1.6}
 .brief-steps button,#app.handheld .brief-steps button{min-height:44px;font-size:13px}
 .brief-slide p,#app.handheld .brief-slide p{font-size:16px;line-height:1.8}
 .brief-bottom,#app.handheld .brief-bottom{gap:6px;padding-top:10px}
 .brief-bottom button,#app.handheld .brief-bottom button{min-height:44px;padding:10px 8px;font-size:13px}
 .brief-diagram{overflow:hidden}.diagram-unit>svg{max-width:100%}
 .rule-strip{flex-wrap:wrap}.rule-strip>span{min-width:90px;font-size:14px}
 #result-screen .result-shell{grid-template-rows:minmax(0,1fr) auto auto;padding:16px;gap:12px}
 .result-layout{display:block;overflow:auto;min-height:0;padding-right:3px}
 .result-personal{overflow:visible;padding:0;min-height:0}
 #result-screen .result-records{overflow:visible;border-left:0;border-top:1px solid var(--line);padding:18px 0 0;margin-top:18px}
 #result-board{overflow:visible;padding:0}.result-ranking-heading{padding-bottom:12px}
 #result-screen .result-buttons{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;padding-top:12px}
 #result-screen .result-buttons button{font-size:14px;min-height:44px;padding:10px 6px;min-width:0}
 #result-screen .result-personal .result-stats strong{font-size:20px}
 .result-personal .result-heading h2{font-size:28px}
 #inspect-panel,#inspect-panel[data-content=research]{padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left)}
 .inspect-modal-top{padding:16px}.inspect-modal-top h2{font-size:24px}.modal-close{width:44px;height:44px}
 #inspect-content{padding:16px}.field-detail{padding:16px}.field-layout{grid-template-rows:minmax(110px,30%) minmax(0,1fr)}
 #volume-panel{width:min(280px,calc(100vw - 24px));max-height:calc(var(--viewport-height,100dvh) - 80px);overflow:auto}
 #share-modal{padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left)}
 .share-shell{padding:16px;gap:14px;height:100%;border-radius:12px}
 .share-head h2{font-size:22px}.share-head .eyebrow{font-size:11px}
 .share-body{display:block;overflow:auto;scrollbar-gutter:stable;padding-right:3px}
 .share-visual{display:grid;grid-template-rows:auto auto auto;gap:10px}
 .share-preview{height:clamp(220px,43dvh,420px);padding:12px}
 .share-sizes{gap:7px}.share-sizes button{min-height:48px;gap:4px;font-size:14px}
 .share-side{overflow:visible;padding:20px 0 0;gap:16px}
 .share-summary{padding-bottom:16px}.share-summary h3{font-size:22px;margin:9px 0 4px}
 .share-details{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-top:16px}
 .share-details dd{font-size:24px}.share-actions{grid-template-columns:repeat(2,minmax(0,1fr))}
 #share-download,#share-system{grid-column:1/-1}.share-hint{margin:0}
}

/* Portrait touch play: top instruments and two thumb zones leave the street clear. */
@media(orientation:portrait){
 #app.handheld .topbar{left:var(--safe-left);right:var(--safe-right)}
 #app.handheld .health-card{top:calc(var(--safe-top) + 56px);left:50%;transform:translateX(-50%);width:calc(100% - var(--safe-left) - var(--safe-right));height:40px}
 #app.handheld .run-extras{left:var(--safe-left);top:calc(var(--safe-top) + 106px);right:120px;display:flex;flex-wrap:wrap;gap:5px 12px;font-size:12px;transform:none}
 #app.handheld .run-extras #character-name,#app.handheld .run-extras #motion-state,#app.handheld .ground-wear{display:none}
 #app.handheld .timer-panel{top:calc(var(--safe-top) + 106px);right:var(--safe-right)}
 #app.handheld .timer-panel strong{font-size:18px}#app.handheld .timer-panel .eyebrow{display:none}
 #app.handheld .goal-radar{width:calc(100% - 40px);height:32dvh;top:43%}
 #app.handheld .goal-radar .hud-range{left:0;top:calc(50% + 44px);flex-direction:column;align-items:flex-start;gap:3px}
 #app.handheld .goal-radar .hud-range>span{font-size:12px}#app.handheld .goal-radar .hud-flight{right:0;top:calc(50% + 44px);font-size:12px}
 #app.handheld .goal-radar .hud-bearing{font-size:12px}#app.handheld .reticle-ticks{opacity:.25}
 #app.handheld .touch-joystick{width:112px;height:112px;bottom:var(--safe-bottom)}
 #app.handheld .abilities{inset:auto var(--safe-right) var(--safe-bottom) auto;transform:none;width:170px;height:138px;display:block;pointer-events:none}
 #app.handheld .abilities .ability{position:absolute;min-width:0;min-height:44px;padding:7px;border-radius:50%;pointer-events:auto;background:#192e21db;gap:3px}
 #app.handheld .abilities .ability small{display:none}#app.handheld .abilities .ability kbd{border:0;padding:0;font-size:16px}
 #app.handheld #jump-button{right:0;bottom:0;width:76px;height:76px;justify-content:center;border-color:var(--acid);background:#455e2edd}
 #app.handheld #jump-button kbd{display:none}#app.handheld #jump-button>span{font-size:16px}
 #app.handheld #pheromone-button{right:86px;bottom:0;width:64px;height:64px;justify-content:center}#app.handheld #pheromone-button>span{font-size:12px}
 #app.handheld #scare-button{right:0;bottom:84px;width:48px;height:48px}#app.handheld #camera-button{right:64px;bottom:84px;width:48px;height:48px}
 #app.handheld #scare-button>span,#app.handheld #camera-button>span{font-size:0}#app.handheld #scare-button>span:after{content:'嚇人';font-size:12px}#app.handheld #camera-button>span:after{content:'視角';font-size:12px}
 #app.handheld .map-card{top:calc(var(--safe-top) + 150px);bottom:auto;right:var(--safe-right);left:auto;width:100px;padding:6px}
 #app.handheld .map-card canvas{height:60px}#app.handheld .map-card:not(.expanded) :is(.map-legend,.map-distance,.attribution,.map-follow){display:none}
 #app.handheld .map-header{font-size:12px}#app.handheld .map-header button{width:36px;height:36px;border:0}
 #app.handheld .map-card.expanded{inset:calc(var(--safe-top) + 60px) var(--safe-right) auto auto;width:calc(100% - var(--safe-left) - var(--safe-right));max-height:60%;overflow:auto}
 #app.handheld .map-card.expanded canvas{height:34dvh}
 #app.handheld #threat-banner{top:33%;font-size:13px;max-width:85%}
 #app.handheld #toast{top:calc(var(--safe-top) + 105px);font-size:13px}
 #app.handheld #escape-warning{top:53%;max-width:85%;font-size:14px}
 #app.handheld #crowd-warning{bottom:calc(var(--safe-bottom) + 150px);font-size:12px}
 #app.handheld .inspect-heading{top:calc(var(--safe-top) + 66px);left:var(--safe-left)}
 #app.handheld .inspect-heading h1{font-size:27px}#app.handheld .inspect-heading .eyebrow{font-size:10px}
 #app.handheld .inspect-actions{left:var(--safe-left);right:var(--safe-right);top:calc(var(--safe-top) + 180px);max-width:none;justify-content:flex-start;gap:6px}
 #app.handheld .inspect-actions .scene-action{font-size:13px;min-height:44px;padding:8px 10px}
 #app.handheld .inspect-compass,#app.handheld .inspect-location,#app.handheld .inspect-help{display:none}
 #app.handheld .inspect-viewbar{left:var(--safe-left);right:var(--safe-right);bottom:calc(var(--safe-bottom) + 124px);width:auto;transform:none;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));padding:5px;gap:2px}
 #app.handheld .inspect-viewbar button{font-size:12px;min-width:0;min-height:48px;padding:6px 2px;gap:4px;flex-direction:column}
 #app.handheld .inspect-viewbar small,#app.handheld .viewbar-divider{display:none}
 #app.handheld[data-phase=inspect] .map-card{top:auto;left:auto;right:var(--safe-right);bottom:var(--safe-bottom);width:100px}
 #app.handheld[data-phase=inspect] .map-card.expanded{top:calc(var(--safe-top) + 60px);bottom:auto;width:calc(100% - var(--safe-left) - var(--safe-right))}
 #tour-hint{max-width:calc(100% - 32px);width:max-content;top:48%;font-size:14px}
}

/* Short landscape phones keep the same fixed frame instead of scrolling the page. */
@media(orientation:landscape) and (max-height:600px){
 #app[data-phase=inspect] .topbar{padding-bottom:0;border-bottom:0}
 .screen,#app.handheld .screen{padding:calc(var(--safe-top) + 48px) var(--safe-right) var(--safe-bottom) var(--safe-left);overflow:hidden;align-items:stretch}
 .screen .menu-shell,.screen .flow-panel,#app.handheld .screen .menu-shell,#app.handheld .screen .flow-panel{height:100%;max-height:100%;padding:10px 14px;gap:7px;margin:0 auto}
 .selection-layout,#app.handheld .selection-layout{display:grid;grid-template-columns:minmax(0,1fr) minmax(150px,27%);overflow:hidden;gap:12px;min-height:0}
 .roster,#app.handheld .roster{grid-template-columns:repeat(4,minmax(0,1fr));grid-template-rows:none;grid-auto-rows:max-content;height:auto;min-height:0;max-height:none;overflow:auto;align-content:start;gap:7px}
 .character-card .roach-art,#app.handheld .character-card .roach-art{width:min(100%,95px)}
 .character-card strong,#app.handheld .character-card strong{font-size:12px;padding:0 6px}.character-card small,#app.handheld .character-card small{font-size:12px}
 .selected-detail,#app.handheld .selected-detail{margin:0;border-top:0;border-left:1px solid var(--line);padding:0 0 0 12px;display:block;overflow:auto;max-height:none}
 .selected-detail h2{font-size:18px}.selected-detail p,.species-facts dd{font-size:13px}
 .menu-bottom,#app.handheld .menu-bottom{display:flex;flex-wrap:nowrap;align-items:flex-end;padding-top:6px;gap:12px}
 .menu-bottom input,#app.handheld .menu-bottom input{min-height:44px;font-size:16px;padding:7px 9px}
 .menu-bottom .primary,#app.handheld .menu-bottom .primary{width:auto;min-height:44px;font-size:14px}
 .menu-title h1,#app.handheld .menu-title h1{font-size:20px}.selection-title{font-size:13px;padding-top:5px}
 .load-status{font-size:12px}.menu-title .eyebrow{display:none}
 .brief-steps button,#app.handheld .brief-steps button{min-height:40px;font-size:13px;padding:6px}
 .brief-bottom button,#app.handheld .brief-bottom button{min-height:44px;font-size:14px;padding:8px 12px}
 #result-screen .result-shell{grid-template-rows:minmax(0,1fr) auto auto}
 .result-layout,#app.handheld .result-layout{display:grid;grid-template-columns:minmax(180px,.8fr) minmax(0,1.2fr);grid-template-rows:minmax(0,1fr);overflow:hidden;gap:16px}
 .result-personal{overflow:auto}
 #result-screen .result-records,#app.handheld #result-screen .result-records{overflow:hidden;margin:0;padding:0 0 0 16px;border-top:0;border-left:1px solid var(--line)}
 #result-board{overflow:auto}
 #result-screen .result-buttons,#app.handheld #result-screen .result-buttons{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));padding-top:7px;gap:8px}
 #result-screen .result-buttons button,#app.handheld #result-screen .result-buttons button{min-height:44px;font-size:14px;padding:8px}
 #app.handheld .health-card{top:var(--safe-top);left:50%;transform:translateX(-50%);width:clamp(165px,28vw,280px)}
 #app.handheld .health-card .hp-track{min-width:28px}
 #app.handheld .brand{font-size:14px}#app.handheld .header-actions button{min-height:44px}
 #app.handheld .run-extras{left:var(--safe-left);top:calc(var(--safe-top) + 48px);transform:none;right:auto;display:flex;flex-wrap:wrap;max-width:55vw;white-space:normal;font-size:12px}
 #app.handheld .run-extras .ground-wear{display:none}
 #app.handheld .abilities{width:170px}#app.handheld .touch-joystick{width:108px;height:108px}
 #app.handheld .inspect-actions{top:calc(var(--safe-top) + 46px);left:var(--safe-left);right:var(--safe-right);max-width:none}
 #app.handheld .inspect-actions .scene-action{min-height:40px;padding:7px 9px;font-size:13px}
 #app.handheld .inspect-viewbar{left:calc(var(--safe-left) + 122px);right:calc(var(--safe-right) + 112px);padding:4px}
 #app.handheld .inspect-viewbar button{min-height:44px;font-size:12px;padding:6px}#app.handheld .inspect-viewbar small{display:none}
 #app.handheld[data-phase=inspect] .map-card{top:auto;bottom:var(--safe-bottom);width:100px}#app.handheld[data-phase=inspect] .map-card canvas{height:45px}
 #app.handheld #inspect-panel,#app.handheld #inspect-panel[data-content=research]{padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left)}
 #share-modal,#app.handheld #share-modal{padding:var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left)}
 .share-shell{height:100%;padding:12px 16px;gap:10px}.share-head h2{font-size:20px}.share-head .eyebrow{display:none}
 .share-body{display:grid;grid-template-columns:minmax(0,1fr) minmax(210px,36%);gap:18px;overflow:hidden;padding:0}
 .share-visual{grid-template-rows:minmax(0,1fr) auto;gap:8px}.share-preview{height:auto;padding:8px}
 .share-sizes button{min-height:44px;font-size:13px;padding:6px}.share-sizes small{display:block}#share-dimensions{display:none}
 .share-side{overflow:auto;padding:0 4px 0 0;gap:12px}.share-summary{padding-bottom:12px}
 .share-summary h3{font-size:20px;margin:7px 0}.share-details{grid-template-columns:repeat(2,minmax(0,1fr));margin-top:12px;gap:8px}
 .share-details dd{font-size:20px}.share-actions{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
 #share-download,#share-system{grid-column:1/-1}.share-actions .primary,.share-actions .secondary{min-height:44px;padding:9px;font-size:14px}
 #tour-hint{top:48%;max-width:60vw;padding:12px}
}
@media(max-width:359px){.brand>div{font-size:13px}.brand-mark{display:none}.screen .menu-shell,.screen .flow-panel{padding:12px}.selection-title{flex-wrap:wrap}.share-shell{padding:12px}.share-head h2{font-size:20px}}
@media(prefers-reduced-motion:reduce){.share-cta,.share-cta:before,.share-cta:after{animation:none!important}}
