/* On-screen touch controls (touch.js). They live inside #stage as an overlay: only the stick zone and the buttons take the
   pointer, so the rest of the pitch stays tappable. Landscape: stick zone left, buttons right. Portrait: a controls strip
   under the play area (renderer.bottomInset reserves it, so the camera frames the pitch above it). */
/* Scope: every rule here is either on a new .touch-* element or needs body.touch-capable (set at start-up from the pointer type:
   coarse pointer or touch points), body.touch-device (a finger has touched the page) or body.touch-ui / .touch-live (controls up). A
   desktop mouse and keyboard session computes the same styles as without this file (tests/touch-controls.test.mjs, scripts/e2e-desktop-identical.mjs). */
html:has(body.touch-capable),body.touch-capable{overscroll-behavior:none}
body.touch-capable.immersive,body.touch-device,.touch-controls{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
body.touch-capable.immersive #pitch{touch-action:none}
/* 100dvh, with the older iOS fallbacks first. */
body.touch-capable.immersive .play-section,body.touch-capable.immersive .stage{height:100vh;height:-webkit-fill-available;height:100dvh}
:root{--tb:clamp(60px,17vmin,84px);--edge:max(16px,env(safe-area-inset-right));--strip-h:calc(3.35*var(--tb) + 22px + env(safe-area-inset-bottom))}
.touch-controls{
  position:absolute;inset:0;z-index:7;pointer-events:none;touch-action:none;font-family:var(--display-font,'Arial Narrow',sans-serif)}
.touch-controls[hidden]{display:none!important}
.touch-strip{position:absolute;left:0;right:0;top:0;bottom:0;pointer-events:none}
/* The floating stick: it appears under the left thumb anywhere in the zone. Inset from the left edge (Safari's back swipe). */
.touch-stick-zone{position:absolute;left:max(30px,env(safe-area-inset-left));top:24%;bottom:max(30px,env(safe-area-inset-bottom));width:calc(45% - 30px);pointer-events:auto;touch-action:none}
.touch-stick-rest,.touch-stick-base{position:absolute;width:112px;height:112px;border-radius:50%;border:2px solid #ffe04a;background:#0c171066;pointer-events:none}
.touch-stick-base{left:-56px;top:-56px;opacity:0;transition:opacity .08s}  /* moved to the thumb with transform */
.touch-stick-base.on{opacity:.78}
.touch-stick-rest{left:6px;bottom:6px;opacity:.28;border-style:dashed}
.touch-stick-zone:has(.touch-stick-base.on) .touch-stick-rest{opacity:0}
.touch-stick-knob{position:absolute;left:50%;top:50%;width:52px;height:52px;margin:-26px 0 0 -26px;border-radius:50%;background:#ffe04acc;box-shadow:0 2px 8px #0008}
.touch-buttons{position:absolute;right:var(--edge);bottom:max(18px,env(safe-area-inset-bottom));width:calc(3.6*var(--tb));height:calc(3.2*var(--tb));pointer-events:none}
.touch-btn{position:absolute;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;width:var(--tb);height:var(--tb);padding:0;border-radius:50%;border:2px solid #ffe04a;background:#0c1710b8;color:#fff7e0;opacity:.75;pointer-events:auto;touch-action:none;transition:transform .05s,background .05s,opacity .05s}
.touch-btn svg{width:calc(var(--tb)*.38);height:calc(var(--tb)*.38);fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.touch-btn span{font-weight:800;font-size:calc(var(--tb)*.19);letter-spacing:.05em;text-transform:uppercase;line-height:1}
.touch-btn.pressed{transform:scale(.92);background:#ffe04a;color:#0c1710;opacity:1}
.touch-btn-shoot{right:0;bottom:calc(.9*var(--tb));width:calc(1.15*var(--tb));height:calc(1.15*var(--tb))}
.touch-btn-pass{right:calc(1.3*var(--tb));bottom:0;width:calc(1.15*var(--tb));height:calc(1.15*var(--tb))}
.touch-btn-through{right:calc(1.9*var(--tb));bottom:calc(1.45*var(--tb))}
.touch-btn-sprint{right:0;bottom:calc(2.2*var(--tb))}
.touch-btn-switch{right:calc(2.7*var(--tb));bottom:0;width:calc(.95*var(--tb));height:calc(.95*var(--tb));border-color:#8fa293}
.touch-btn-switch span{font-size:calc(var(--tb)*.17)}
.touch-pause{position:absolute;right:max(12px,env(safe-area-inset-right));top:max(12px,env(safe-area-inset-top));width:54px;height:54px;padding:0;border-radius:14px;border:2px solid #8fa293;background:#0c1710b8;color:#fff7e0;opacity:.75;pointer-events:auto;touch-action:none;display:flex;flex-direction:column;align-items:center;justify-content:center;overflow:visible}
.touch-pause svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2.4;stroke-linecap:round}
.touch-pause span{font:800 10px/1 var(--display-font,sans-serif);letter-spacing:.06em;text-transform:uppercase}
.touch-pause em{position:absolute;top:calc(100% + 6px);right:0;white-space:nowrap;padding:5px 9px;border-radius:8px;background:#0c1710ee;color:#ffe04a;font:700 12px/1 system-ui,sans-serif;font-style:normal;opacity:0;pointer-events:none;transition:opacity .15s}
.touch-pause.hint em{opacity:1}
.touch-pause.holding{background:linear-gradient(#ffe04a,#ffe04a) no-repeat left/0 100%,#0c1710b8;animation:touch-hold var(--hold,450ms) linear forwards}
@keyframes touch-hold{to{background-size:100% 100%}}
/* The HUD makes room. */
body.touch-ui .taker-open-button{top:calc(max(12px,env(safe-area-inset-top)) + 64px);right:max(12px,env(safe-area-inset-right));min-height:44px;padding:9px 16px}
body.touch-device .team-talk-open-button{min-height:48px;padding:10px 18px}
body.touch-device .replay-controls button,body.touch-device .replay-controls select,body.touch-device .replay-controls input[type=range]{min-height:44px}
body.touch-ui.immersive .pitch-topbar .selected-player{bottom:calc(max(18px,env(safe-area-inset-bottom)) + 8px)}
body.touch-ui.immersive .player-stamina{bottom:max(18px,env(safe-area-inset-bottom))}
/* the narrow-window rule stretches the card to the full width: keep it a compact chip between the stick and the buttons */
body.touch-ui.immersive .pitch-topbar .selected-player{width:auto;max-width:min(300px,34vw);order:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
body.touch-ui.immersive .keeper-guide{bottom:auto;top:64px;font-size:12px;max-width:min(520px,60vw)}
body.touch-ui .referee-call{pointer-events:none}
/* Landscape: the corner is taken (Pause, minimap), so the taker button sits bottom-centre above the player chip, and the commentary caption above it. */
@media (orientation:landscape){
  body.touch-ui .taker-open-button{top:auto;right:auto;left:50%;transform:translateX(-50%);bottom:calc(max(18px,env(safe-area-inset-bottom)) + 40px)}
  body.touch-device.touch-live .commentary-caption{bottom:calc(max(18px,env(safe-area-inset-bottom)) + 96px);font-size:13px;max-width:min(420px,40vw);padding:6px 12px}
}
@media (orientation:portrait){
  body.touch-device.touch-live .commentary-caption{bottom:calc(var(--strip-h) + 46px);max-width:92vw;font-size:13px;padding:6px 12px}
  :root{--tb:clamp(58px,15.5vw,80px)}
  .touch-pause{top:calc(max(12px,env(safe-area-inset-top)) + 92px)}  /* below the score bug and its wrapped tactic badge */
  body.touch-ui .taker-open-button{top:calc(max(12px,env(safe-area-inset-top)) + 156px)}
  .touch-strip{top:auto;height:var(--strip-h);background:linear-gradient(0deg,#0c1710cc,#0c171000)}
  .touch-stick-zone{top:0;bottom:max(14px,env(safe-area-inset-bottom));width:calc(52% - 30px)}
  .touch-buttons{bottom:max(14px,env(safe-area-inset-bottom))}
  body.touch-ui.immersive .pitch-topbar .selected-player{bottom:calc(var(--strip-h) + 8px);max-width:80vw}
  body.touch-ui.immersive .player-stamina{bottom:calc(var(--strip-h) + 2px)}
  body.touch-ui .power-display{bottom:calc(var(--strip-h) + 20px)}
  body.touch-ui.immersive .keeper-guide{top:auto;bottom:calc(var(--strip-h) + 8px);max-width:92vw}
}
@media (prefers-reduced-motion:reduce){.touch-btn,.touch-stick-base{transition:none}}
/* Touch players get no keyboard key caps on the toolbar, and the paused toolbar does not sit on the player card. */
body.touch-device .pitch-toolbar .key{display:none}
body.touch-device.match-paused .pitch-topbar .selected-player,body.touch-device.match-paused .player-stamina{display:none}

/* Screens that are not live play (pause, half time, full time, replay, procession, team talk, sheets): for a touch player the
   sheet owns the screen. The HUD chips, the score bug, the commentary caption and (renderer.mapHidden) the minimap step aside so
   nothing overlaps, and every sheet scrolls inside itself, never the page. Desktop is untouched: all of this needs body.touch-device. */
body.touch-device.immersive:not(.touch-live) .pitch-topbar,
body.touch-device.immersive:not(.touch-live) .player-stamina,
body.touch-device:not(.touch-live) .power-display,
body.touch-device:not(.touch-live) #referee-call,
body.touch-device:not(.touch-live) #strategy-banner,
body.touch-device:not(.touch-live) .commentary-caption{display:none!important}
body.touch-device.immersive.match-paused .overlay{padding:12px}
body.touch-device.match-paused .pitch-toolbar{display:none}  /* the pause card has Resume; the old Reset ball / Last shot / Resume strip sat on the pitch under it */
body.touch-device.immersive.match-paused .start-panel{max-height:100%;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}
body.touch-device .pitch-toolbar button,body.touch-device .sub-player,body.touch-device .sub-confirm,body.touch-device .start-panel button,body.touch-device .fulltime-continue{min-height:44px}
body.touch-device .start-panel,body.touch-device .team-talk,body.touch-device .taker-picker,body.touch-device .replay-controls{overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
/* Full-time and half-time cards: inside the viewport on a short landscape phone. */
body.touch-device .match-broadcast.fulltime-pop{top:8px;bottom:auto;max-height:calc(100% - 16px);overflow-y:auto;overscroll-behavior:contain}
@media (max-height:430px){
 /* the half-time card (score-pop) sits at the top and is compacted so all its rows fit a short landscape phone */
 body.touch-device .score-pop:not(.fulltime-pop){top:8px;bottom:auto;transform:translateX(-50%);max-height:calc(100% - 16px);overflow:hidden;padding:8px 18px}
 body.touch-device .score-pop:not(.fulltime-pop) .broadcast-heading{margin-bottom:4px}
 body.touch-device .score-pop:not(.fulltime-pop) .broadcast-score{font-size:18px}body.touch-device .score-pop:not(.fulltime-pop) .broadcast-score strong{font-size:30px}
 body.touch-device .score-pop:not(.fulltime-pop) table{margin-top:4px;font-size:13px}body.touch-device .score-pop:not(.fulltime-pop) td,body.touch-device .score-pop:not(.fulltime-pop) th{padding:2px 0}
 body.touch-device .score-pop:not(.fulltime-pop) .broadcast-scorers{margin-top:4px;padding-top:4px;font-size:13px;line-height:1.3}
 body.touch-device .fulltime-pop td,body.touch-device .fulltime-pop th{padding:2px 0}
 body.touch-device .fulltime-pop .broadcast-score{font-size:15px}body.touch-device .fulltime-pop .broadcast-score strong{font-size:34px}
}
body.touch-device:has(.fulltime-pop:not([hidden])) .pitch-toolbar{display:none}  /* Reset ball / Last shot mean nothing at full time and sit under the sheet on a short phone */
body.touch-device .match-broadcast.fulltime-pop{background:rgba(9,20,27,.84)}  /* the pitch lines behind it made the stats hard to read */
@media (max-height:430px){
 /* short landscape phone: the pause card leads with its actions, and the rest scrolls inside it */
 body.touch-device.match-paused #overlay-eyebrow,body.touch-device.match-paused #overlay-copy{display:none}
 body.touch-device.match-paused .start-panel{padding:14px 20px}
 body.touch-device.match-paused .start-panel h2{margin:0 0 8px;font-size:24px}
}
/* The set-piece taker dialog: rows and buttons at least 44 px, scrolls inside the viewport, nothing behind it shows through on top. */
body.touch-device .taker-picker{overflow:hidden;overscroll-behavior:contain;padding:8px}
body.touch-device .taker-picker .tp-card{max-height:100%;display:flex;flex-direction:column;overflow:hidden}
body.touch-device .taker-picker .tp-list{flex:1 1 auto;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain}  /* the list scrolls; title and Confirm / Cancel stay put */
body.touch-device .taker-picker [role="option"]{min-height:44px;align-content:center}
body.touch-device .taker-picker .tp-actions button{min-height:44px}
/* The penalty-shootout order dialog (a sheet): controls and HUD step aside (app.js: not live play), the list scrolls inside the card,
   Go stays visible, every button is at least 44 px. */
body.touch-device .shootout-order{display:flex;flex-direction:column;width:min(460px,calc(100% - 24px));max-height:calc(100% - 16px);overflow:hidden;padding:12px 14px}
body.touch-device .shootout-order ol{flex:1 1 auto;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;margin-bottom:8px}
body.touch-device .shootout-order li{display:flex;align-items:center;gap:6px}
body.touch-device .shootout-order li span{flex:1;width:auto;min-width:0}
body.touch-device .shootout-order button{min-height:44px;min-width:44px}
body.touch-device .shootout-order p{margin-bottom:6px}
@media (max-height:430px){body.touch-device .shootout-order p{display:none}body.touch-device .shootout-order h3{margin:0 0 6px}}
body.touch-device .shootout-order{background:#0c1710}

/* A live one-on-one: a quiet "TAP = PLACE" under the Shoot button (touch.js setHint). Touch controls only. */
.touch-btn.hint[data-hint]::after{content:attr(data-hint);position:absolute;left:50%;top:100%;transform:translateX(-50%);margin-top:4px;padding:2px 6px;border-radius:8px;background:#0c1710cc;color:#ffe04a;font-weight:800;font-size:calc(var(--tb)*.16);letter-spacing:.04em;white-space:nowrap;pointer-events:none}
