/* Touch devices keep one layout even when a pen or mouse is also detected. */
body.touch-device{overflow-x:hidden}
body.touch-device #selection{zoom:1;min-width:0;min-height:0}
body.touch-device #selection .section-title{flex-wrap:wrap;gap:4px;margin:0}
body.touch-device #selection .section-title span{max-width:none;font-size:10px}
body.touch-device #selection #selection-note{height:auto;max-height:none;min-height:0;line-height:1.5}
body.touch-device #selection .character b{white-space:normal;overflow-wrap:anywhere;line-height:1.3}
body.touch-device #selection .fighter canvas{object-fit:contain}
body.touch-device #selection .fighter strong{line-height:1.3}
body.touch-device #selection .fighter small{line-height:1.4}

/* Portrait selection grows with its content, including all fourteen cards. */
@media(orientation:portrait){
 body.touch-device:not(.title-open):has(#arena[hidden]) #game-main{display:block;width:100%;height:auto;max-height:none;padding:6px 10px 16px}
 body.touch-device .game-header{height:auto;min-height:52px;padding:8px 10px;flex-wrap:wrap;gap:6px}
 body.touch-device .game-brand{font-size:15px}
 body.touch-device .audio-settings{gap:4px}
 body.touch-device .audio-settings button{padding:6px;font-size:10px}
 body.touch-device #game-main>#game-nav{margin:0 0 10px}
 body.touch-device #selection{display:flex;flex-direction:column;gap:10px;width:100%;height:auto;max-height:none;overflow:visible;padding:12px;margin:0;border-radius:18px}
 body.touch-device #selection .section-title h2{font-size:17px}
 body.touch-device #selection .selection-banner{font-size:10px;letter-spacing:.6px;padding:6px 0;gap:6px;margin:0}
 body.touch-device #selection .fullscreen-toggle{padding:6px 9px;font-size:11px}
 body.touch-device #selection .versus-portraits{display:grid;grid-template-columns:minmax(0,1fr) 48px minmax(0,1fr);gap:4px;margin:0;min-height:0}
 body.touch-device #selection .fighter{display:block;min-height:0;padding-bottom:6px}
 body.touch-device #selection .fighter canvas{display:block;flex:none;width:100%;height:clamp(100px,29vw,160px);max-height:none}
 body.touch-device #selection .fighter strong{font-size:18px}
 body.touch-device #selection .fighter small{font-size:9px;min-height:13px;margin-top:3px}
 body.touch-device #selection .player-tag{font-size:14px;top:6px;left:6px}
 body.touch-device #selection .fighter-two .player-tag{left:auto;right:6px}
 body.touch-device #selection .versus-center>b{font-size:32px}
 body.touch-device #selection .versus-center>span{font-size:9px;margin-top:6px}
 body.touch-device #selection #stage-picker{font-size:12px}
 body.touch-device #selection #stage-picker select{max-width:100%;padding:6px 8px;margin-left:6px}
 body.touch-device #selection #selection-note{font-size:12px;padding:8px 10px;margin:0}
 body.touch-device #selection #roster{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:6px;flex:none;min-height:auto;margin:0}
 body.touch-device #selection .character{min-width:0;padding:3px 2px 6px}
 body.touch-device #selection .character canvas{display:block;width:100%;height:56px;max-height:none;max-width:100%;aspect-ratio:auto;object-fit:contain}
 body.touch-device #selection .character b{font-size:11px;min-height:29px;margin:0}
 body.touch-device #selection .selection-keys{font-size:11px;line-height:1.5;margin:0}
 body.touch-device #selection .match-settings{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:10px;margin:0;padding-top:10px}
 body.touch-device #selection .match-settings select{margin-left:6px;padding:6px 8px}
 body.touch-device #selection #start{padding:10px 12px;font-size:13px}
 body.touch-device #achievements,body.touch-device #controls-help{position:static;margin-top:10px}
}

/* Landscape selection has explicit, non-overlapping portrait and roster rows. */
@media(orientation:landscape){
 body.touch-device:not(.title-open):has(#arena[hidden]) #game-main{display:grid;grid-template-columns:100px minmax(0,1fr);gap:8px;width:100%;max-width:none;height:var(--play-height,100dvh);padding:6px;align-items:stretch}
 body.touch-device .selection-sidebar{display:flex;flex-direction:column;gap:6px;min-width:0;min-height:0;overflow:auto}
 body.touch-device .selection-sidebar .game-header{display:flex;flex-direction:column;align-items:stretch;width:100%;height:auto;min-height:0;padding:0;margin:0;gap:5px}
 body.touch-device .selection-sidebar .game-brand{font-size:12px;text-align:center;letter-spacing:0}
 body.touch-device .selection-sidebar .header-home{padding:5px;font-size:10px}
 body.touch-device .selection-sidebar .audio-settings{display:flex;flex-direction:column;gap:4px;margin:0}
 body.touch-device .selection-sidebar .audio-settings button{padding:5px;font-size:10px}
 body.touch-device .selection-sidebar #game-nav{display:flex;flex-direction:column;gap:2px;padding:3px;margin:0}
 body.touch-device .selection-sidebar #game-nav button{padding:7px 4px;font-size:12px}
 body.touch-device .selection-sidebar #achievements,body.touch-device .selection-sidebar #controls-help{margin:0}
 body.touch-device .selection-sidebar summary{padding:7px;font-size:10px}
 body.touch-device .selection-sidebar footer{margin-top:auto;padding:3px 0;font-size:8px}
 body.touch-device #selection{display:grid;grid-template-columns:minmax(0,1fr) 136px;grid-template-rows:auto auto minmax(76px,1fr) auto;gap:6px 10px;height:100%;max-height:100%;padding:8px;margin:0;overflow:auto;border-radius:16px}
 body.touch-device #selection .section-title{grid-column:1/-1}
 body.touch-device #selection .section-title h2{font-size:14px}
 body.touch-device #selection .section-title span{font-size:9px}
 body.touch-device #selection .selection-banner{grid-column:1;grid-row:2;font-size:10px;letter-spacing:.5px;padding:3px 0;margin:0;gap:5px;flex-wrap:nowrap}
 body.touch-device #selection .fullscreen-toggle{padding:4px 7px;font-size:10px}
 body.touch-device #selection .versus-portraits{display:grid;grid-column:1;grid-row:3;grid-template-columns:minmax(0,1fr) 46px minmax(0,1fr);gap:4px;align-items:stretch;min-height:0;margin:0}
 body.touch-device #selection .fighter{display:flex;flex-direction:column;min-height:0;padding-bottom:3px}
 body.touch-device #selection .fighter canvas{flex:1;min-height:35px;width:100%;height:0;max-height:230px}
 body.touch-device #selection .fighter strong{flex-shrink:0;font-size:16px}
 body.touch-device #selection .fighter small{flex-shrink:0;font-size:8px;min-height:12px;margin-top:1px}
 body.touch-device #selection .player-tag{font-size:12px;top:4px;left:5px}
 body.touch-device #selection .fighter-two .player-tag{left:auto;right:5px}
 body.touch-device #selection .versus-center{align-self:center}
 body.touch-device #selection .versus-center>b{font-size:28px}
 body.touch-device #selection .versus-center>span{font-size:8px;line-height:1.4;margin-top:4px}
 body.touch-device #selection #roster{grid-column:1;grid-row:4;grid-template-columns:repeat(7,minmax(0,1fr));gap:5px;margin:0;min-height:0}
 body.touch-device #selection .character{padding:2px 1px 4px}
 body.touch-device #selection .character canvas{width:100%;height:clamp(30px,9dvh,65px);max-height:none;max-width:95px;aspect-ratio:auto;object-fit:contain}
 body.touch-device #selection .character b{font-size:10px;min-height:24px;margin:0}
 body.touch-device .selection-settings-side{display:flex;grid-column:2;grid-row:2/5;flex-direction:column;gap:9px;min-width:0;min-height:0;border-left:1px solid #718099;padding-left:9px;overflow:auto}
 body.touch-device #selection #stage-picker{font-size:11px;line-height:1.5}
 body.touch-device #selection #stage-picker select{display:block;width:100%;padding:5px 4px;margin:4px 0 0;font-size:11px}
 body.touch-device #selection #selection-note{font-size:11px;padding:6px;margin:0}
 body.touch-device #selection .selection-keys{font-size:10px;line-height:1.5;margin:0}
 body.touch-device #selection .match-settings{display:flex;flex-direction:column;align-items:stretch;gap:8px;font-size:11px;margin-top:auto;padding-top:8px}
 body.touch-device #selection .match-settings select{padding:5px 8px;margin-left:4px}
 body.touch-device #selection #start{font-size:12px;line-height:1.4;white-space:normal;padding:8px 5px}
 body.touch-device #network,body.touch-device #ending{grid-column:2;min-width:0;overflow:auto}
}

/* The match owns the usable viewport, with or without browser fullscreen. */
body.touch-device.mobile-match{overflow:hidden;overscroll-behavior:none}
body.touch-device.mobile-match #arena{position:fixed;inset:0 auto auto 0;z-index:1000;width:var(--play-width,100vw);height:var(--play-height,100dvh);max-width:none;max-height:none;border:0;border-radius:0;margin:0;padding:4px;overflow:hidden;background:#faf8ee}
body.touch-device.mobile-match .court-stage{display:block;position:relative;min-width:0;min-height:0;aspect-ratio:864/608;overflow:hidden;border-radius:8px}
body.touch-device.mobile-match .court-stage #court{position:absolute;inset:0;display:block;width:100%;height:100%;min-width:0;min-height:0;max-width:none;max-height:none;border-radius:0;object-fit:contain;touch-action:none}
body.touch-device.mobile-match .court-stage .scoreboard{display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);align-items:start;position:absolute;inset:0 0 auto;z-index:2;width:100%;height:auto;min-height:0;max-height:none;margin:0;padding:5px 8px 10px;gap:8px;background:linear-gradient(#fff9e9eb,#fff9e99c,transparent);pointer-events:none;overflow:visible}
body.touch-device.mobile-match .scoreboard>div{width:auto;min-width:0}
body.touch-device.mobile-match .scoreboard>div>b{--name-font-max:20;display:block;font-size:20px;height:26px;min-height:26px;max-height:26px;line-height:26px;padding:0;white-space:nowrap;text-shadow:0 1px 2px #fff}
body.touch-device.mobile-match .scoreboard>strong{font-size:clamp(28px,7dvh,40px);padding:0;line-height:1.15;letter-spacing:0;-webkit-text-stroke:1px #805a4e}
body.touch-device.mobile-match .scoreboard>div>.meter{margin:0}
body.touch-device.mobile-match .charge-meter{height:auto;min-height:0;padding:0;white-space:normal}
body.touch-device.mobile-match .charge-caption{display:flex;justify-content:space-between;gap:4px;line-height:14px;font-size:9px;white-space:nowrap;letter-spacing:0}
body.touch-device.mobile-match .charge-count{font-size:9px;flex-shrink:0;white-space:nowrap}
body.touch-device.mobile-match .charge-track{height:12px;margin-top:3px}
body.touch-device.mobile-match .charge-state{display:none}
body.touch-device.mobile-match #touch{touch-action:none}
body.touch-device.mobile-match #touch button{min-width:0;min-height:44px;height:52px;width:100%;padding:4px;font-size:20px}
body.touch-device.mobile-match #touch .touch-jump{width:50%}
body.touch-device.mobile-match #touch .touch-spike{width:70px;height:70px;max-width:100%}
body.touch-device.mobile-match #mobile-fullscreen:not([hidden]){display:inline-block}
body.touch-device.mobile-match .arena-foot{font-size:10px;gap:6px;min-width:0}
body.touch-device.mobile-match .match-actions{display:flex;gap:4px;flex-shrink:0}
body.touch-device.mobile-match .match-actions button{font-size:10px;padding:4px 7px;white-space:nowrap}
body.touch-device.mobile-match #stage-label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
body.touch-device.mobile-match #result{position:absolute;z-index:4;left:15%;right:15%;top:25%;max-height:65%;overflow:auto;padding:16px;background:#fffdf1f5;border-radius:18px;box-shadow:0 8px 32px #405b4530}
body.touch-device.mobile-match #rotate-hint{display:none}

@media(orientation:landscape){
 body.touch-device.mobile-match #arena{display:grid;grid-template-columns:clamp(68px,10vw,96px) minmax(0,1fr) clamp(68px,10vw,96px);grid-template-rows:minmax(0,1fr);gap:4px;padding:4px max(4px,env(safe-area-inset-right)) 4px max(4px,env(safe-area-inset-left))}
 body.touch-device.mobile-match .court-stage{grid-column:2;grid-row:1;align-self:center;justify-self:center;width:min(100%,calc((var(--play-height,100dvh) - 8px)*864/608));height:auto;max-height:100%;margin:0}
 body.touch-device #game-main #arena:not([hidden]) #touch{display:contents!important}
 body.touch-device.mobile-match .touch-side{grid-row:1;align-self:center;min-width:0;width:100%;margin:0;gap:5px}
 body.touch-device.mobile-match .touch-left{grid-column:1;display:grid}
 body.touch-device.mobile-match .touch-right{grid-column:3;display:flex;justify-content:center}
 body.touch-device.mobile-match .arena-foot{position:absolute;inset:auto 6px 3px;display:flex;justify-content:space-between;flex-wrap:nowrap;padding:0;z-index:3}
}
@media(orientation:portrait){
 body.touch-device.mobile-match #arena{display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto auto;align-content:start;gap:12px;overflow-y:auto;padding:6px max(4px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(4px,env(safe-area-inset-left))}
 body.touch-device.mobile-match .court-stage{width:100%;height:calc((var(--play-width,100vw) - 8px)*608/864);flex-shrink:0;margin:0}
 body.touch-device.mobile-match #arena:not([hidden]) #touch{display:flex!important;justify-content:space-between;align-items:center;gap:20px;margin:10px 8px;flex-shrink:0}
 body.touch-device.mobile-match .touch-left{width:130px}
 body.touch-device.mobile-match .touch-right{width:78px}
 body.touch-device.mobile-match .arena-foot{position:static;display:flex;flex-wrap:wrap;padding:0 4px;flex-shrink:0}
}

body.touch-device .selection-sidebar>*{flex-shrink:0}
body.touch-device .selection-settings-side>*{flex-shrink:0}
.touch-local-only{display:none!important}
body.local-versus.mobile-match #touch .touch-local-only{display:block!important}
body.local-versus.mobile-match #touch .touch-spike{display:none!important}
body.local-versus.mobile-match #touch .touch-side{display:grid;position:relative;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:44px 52px 52px;gap:5px}
body.local-versus.mobile-match #touch .touch-player{position:absolute;top:-23px;left:0;right:0;text-align:center;font-size:15px;font-weight:bold;color:#466a53}
body.local-versus.mobile-match #touch .touch-jump{grid-column:1/3;grid-row:2;width:50%;justify-self:center}
body.local-versus.mobile-match #touch .touch-move-left{grid-column:1;grid-row:3}
body.local-versus.mobile-match #touch .touch-move-right{grid-column:2;grid-row:3}
body.local-versus.mobile-match #touch .touch-local-attack{grid-column:1/3;grid-row:1;height:44px;background:#ffe6a3;border-color:#d6bd7b;font-size:17px}
@media(orientation:landscape){body.local-versus.touch-device.mobile-match #arena{grid-template-columns:clamp(100px,14vw,140px) minmax(0,1fr) clamp(100px,14vw,140px)}}
@media(orientation:portrait){body.local-versus.touch-device.mobile-match #touch .touch-side{width:140px;max-width:calc(50% - 10px)}}
.selection-settings-copy{display:flex;flex-direction:column;gap:16px;min-height:0;overflow:auto;flex:1}
.selection-settings-copy>*{flex-shrink:0}
@media(orientation:landscape){
 body.touch-device .selection-settings-side{overflow:hidden}
 body.touch-device .selection-settings-side>.selection-settings-copy{flex:1;min-height:0;overflow:auto;gap:9px}
 body.touch-device #selection .match-settings{flex:none;margin-top:0;gap:6px}
}
/* Solo landscape controls have thumb-sized square targets. Portrait and dual pads keep their layout. */
@media(orientation:landscape){
 body.touch-device.mobile-match:not(.local-versus) #arena{grid-template-columns:148px minmax(0,1fr) 100px}
 body.touch-device.mobile-match:not(.local-versus) #touch .touch-left{grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:68px 68px;gap:8px}
 body.touch-device.mobile-match:not(.local-versus) #touch .touch-left button{width:68px;height:68px;min-height:68px;justify-self:center;padding:6px;font-size:28px;border-radius:22px}
 body.touch-device.mobile-match:not(.local-versus) #touch .touch-jump{width:68px}
 body.touch-device.mobile-match:not(.local-versus) #touch .touch-spike{width:88px;height:88px;min-height:88px;font-size:25px}
}
