/* The game only enables this layer while a touch player has control of the camera. */
#touchControls {
  --touch-button: clamp(46px, 7.2vmin, 60px);
  --touch-gap: clamp(5px, 1vmin, 9px);
  --touch-step: calc(var(--touch-button) + var(--touch-gap));
  --touch-stick: clamp(90px, 21vmin, 142px);
  --touch-left: max(10px, env(safe-area-inset-left, 0px));
  --touch-right: max(10px, env(safe-area-inset-right, 0px));
  --touch-top: max(8px, env(safe-area-inset-top, 0px));
  --touch-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  color: #f3f7ee;
}
#touchControls[hidden], body:not([data-mode="play"]) #touchControls {display: none}
#touchControls [data-touch-stick], #touchControls button {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}
#touchControls [data-touch-stick="look"] {
  inset: 0;
  background: transparent;
}
#touchControls [data-touch-stick="move"] {
  left: var(--touch-left);
  bottom: var(--touch-bottom);
  width: var(--touch-stick);
  height: var(--touch-stick);
  z-index: 1;
  border-radius: 50%;
  border: 1.5px solid #d4e0d78c;
  background: radial-gradient(circle at center, #0d212964 0 38%, #a9d5c512 39% 43%, #10202a73 44%);
  box-shadow: inset 0 0 0 3px #15262748, 0 1px 5px #0a111b59;
}
#touchControls .touch-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 43%;
  height: 43%;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  border: 1px solid #dce8dbc2;
  background: #60766d9c;
  box-shadow: inset 0 0 0 3px #e1e8da16;
  transform: translate(-50%, -50%) translate(var(--touch-x, 0px), var(--touch-y, 0px));
  pointer-events: none;
}
#touchControls [data-touch-stick="move"].is-pressed .touch-knob {background: #7aa898db}
#touchControls button {
  box-sizing: border-box;
  z-index: 2;
  width: var(--touch-button);
  height: var(--touch-button);
  padding: 2px;
  border-radius: 14px;
  border: 1px solid #d8e8d480;
  box-shadow: inset 0 0 0 2px #d7ede911, 0 1px 4px #07121b66;
  background: #101f25be;
  color: #f1f4ef;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  font: 650 clamp(15px, 2.75vmin, 23px)/1 var(--display);
  text-align: center;
  text-shadow: 0 1px 1px #0b131a;
}
#touchControls button > * {pointer-events: none}
#touchControls button svg {display: block; width: 43%; height: 43%}
#touchControls .touch-label {
  max-width: 100%;
  font: 650 clamp(9px, 1.8vmin, 12px)/1.08 var(--text);
  overflow-wrap: anywhere;
}
#touchControls button:focus-visible {outline: 3px solid #e0f29e; outline-offset: 2px}
#touchControls button.is-pressed, #touchControls button[aria-pressed="true"] {
  border-color: #e4f5c3;
  background: #4b7161e8;
  color: #fff;
}
#touchControls [data-touch-action="fire"] {
  right: var(--touch-right);
  bottom: calc(var(--touch-bottom) + var(--touch-step));
  background: #2e4645d9;
  border-color: #def4d6;
  border-radius: 50%;
}
#touchControls [data-touch-action="jump"] {right: var(--touch-right); bottom: var(--touch-bottom)}
#touchControls [data-touch-action="interact"] {right: calc(var(--touch-right) + var(--touch-step)); bottom: calc(var(--touch-bottom) + var(--touch-step))}
#touchControls [data-touch-action="aim"] {right: calc(var(--touch-right) + var(--touch-step)); bottom: var(--touch-bottom)}
#touchControls [data-touch-action="cycle"] {right: calc(var(--touch-right) + 2 * var(--touch-step)); bottom: calc(var(--touch-bottom) + var(--touch-step))}
#touchControls [data-touch-action="reload"] {right: calc(var(--touch-right) + 2 * var(--touch-step)); bottom: var(--touch-bottom)}
#touchControls [data-touch-action="crouch"] {left: calc(var(--touch-left) + var(--touch-stick) + var(--touch-gap)); bottom: var(--touch-bottom)}
#touchControls [data-touch-action="sprint"] {left: calc(var(--touch-left) + var(--touch-stick) + var(--touch-gap)); bottom: calc(var(--touch-bottom) + var(--touch-step))}
#touchControls [data-touch-action="phone"] {right:calc(var(--touch-right) + var(--touch-step));top:var(--touch-top)}
#touchControls [data-touch-action="legend"] {right:var(--touch-right);top:calc(var(--touch-top) + var(--touch-step))}
#touchControls [data-touch-action="pause"] {right: var(--touch-right); top: var(--touch-top)}
#touchControls [data-touch-action="flashlight"] {right: calc(var(--touch-right) + var(--touch-step)); top: var(--touch-top)}
#touchControls [data-touch-action="drone"] {right: calc(var(--touch-right) + 2 * var(--touch-step)); top: var(--touch-top)}

body.touch-playing {
  --touch-edge-l: max(10px, env(safe-area-inset-left, 0px));
  --touch-edge-r: max(10px, env(safe-area-inset-right, 0px));
  --touch-edge-t: max(8px, env(safe-area-inset-top, 0px));
  --touch-edge-b: max(12px, env(safe-area-inset-bottom, 0px));
  --touch-clear: calc(var(--touch-edge-b) + max(clamp(90px, 21vmin, 142px), 2 * clamp(46px, 7.2vmin, 60px) + clamp(5px, 1vmin, 9px)) + 7px);
}
.touch-playing #hud .objective {
  top: var(--touch-edge-t);
  left: var(--touch-edge-l);
  max-width: min(48vw, 410px);
  padding: 5px 9px;
}
.touch-playing #hud .boss {
  top: calc(var(--touch-edge-t) + clamp(46px, 7.2vmin, 60px) + 5px);
  right: var(--touch-edge-r);
  width: min(31vw, 230px);
}
.touch-playing #hud .chapterCard {
  top: calc(var(--touch-edge-t) + clamp(46px, 7.2vmin, 60px) + 8px);
  right: var(--touch-edge-r);
  max-width: 37vw;
}
.touch-playing #hud:has(.boss:not([hidden])) .chapterCard {top: 36%}
.touch-playing #hud .health, .touch-playing #hud .weapon {
  bottom: var(--touch-clear);
  min-width: 0;
  padding: 3px 6px;
  background-color: #0b191c9c;
}
.touch-playing #hud .health {left: var(--touch-edge-l); width: clamp(96px, 14vw, 140px)}
.touch-playing #hud .weapon {right: var(--touch-edge-r); max-width: 33vw}
.touch-playing #hud .health .track {height: 5px; margin: 3px 0 0}
.touch-playing #hud .vitalNumber strong, .touch-playing #hud .ammo strong {font-size: clamp(19px, 3.2vmin, 28px)}
.touch-playing #hud .health .micro, .touch-playing #hpCondition {font-size: 9px}
.touch-playing #hud .vitalHeading, .touch-playing #hud .vitalNumber {gap: 4px}
.touch-playing #hud .weaponTitle {font-size: 10px; letter-spacing: .04em}
.touch-playing #hud .ammo {gap: 4px}
.touch-playing #hud .ammo small {font-size: 13px}
.touch-playing #hud #supportDrone {right: var(--touch-edge-r); bottom: calc(var(--touch-clear) + 56px); max-width: 30vw}
.touch-playing .stationGuide {bottom: calc(var(--touch-clear) + 3px); max-width: 41vw}
.touch-playing #hud .droneBottom {bottom: auto; top: 25%}
.touch-playing #subtitle {bottom: calc(var(--touch-clear) + 4px); max-width: min(47vw, 600px); padding: 4px 8px}
.touch-playing #hud .prompt {top: 60%; max-width: 47vw}

.touch-capable #screenFrame, .touch-capable .modalContent {
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.touch-capable #screenFrame .pageFrame {
  padding-left: max(clamp(16px, 4vw, 48px), env(safe-area-inset-left, 0px));
  padding-right: max(clamp(16px, 4vw, 48px), env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.touch-capable:not([data-input="gamepad"]) .menuFooter .inputHint {display: none}
.touch-capable #modal {
  padding: max(7px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) max(7px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
}
.touch-capable #modal .dialog {max-height: 100%; min-height: 0}
.touch-capable #modal .modalContent {min-height: 0}
.touch-capable :is(#actions, .menuFooter, .menuTools, .tabs) button,
.touch-capable[data-mode="menu"] #actions .action,
.touch-capable #modal #closeModal {min-height: 44px}
.touch-capable #modal #closeModal {min-width: 44px}
.touch-capable #screenFrame .menuFooter {gap: 7px; flex-wrap: wrap}
.touch-capable .openingSkip {bottom: max(4vh, 12px, env(safe-area-inset-bottom, 0px)); right: max(5vw, 15px, env(safe-area-inset-right, 0px))}

@media (max-width: 480px) and (orientation: portrait) {
  .touch-capable[data-mode="menu"] .feature {max-width: 100%}
  .touch-capable[data-mode="menu"] .pageFrame {background: linear-gradient(0deg, #07141cf5 0%, #07141c9c 49%, transparent 85%)}
  .touch-capable[data-mode="menu"] .menuGrid {align-content: end; padding-bottom: max(18px, 4vh)}
  .touch-capable[data-mode="menu"] #screenTitle {font-size: clamp(40px, 11vw, 54px)}
  .touch-capable[data-mode="menu"] #actions {max-width: min(76vw, 310px)}
  .touch-playing #hud .objective {max-width: calc(100% - 3 * 51px - var(--touch-edge-r) - var(--touch-edge-l) - 8px)}
  .touch-playing #hud #objective {font-size: 13px}
  .touch-playing #hud .missionDetail, .touch-playing #hud .branchHint {font-size: 11px}
  .touch-playing #subtitle {bottom: calc(var(--touch-clear) + 70px); max-width: 79vw}
}

.touch-capable #opening button,
.touch-capable #modal :is(.settingLine > .action, .choiceOption, .keyEditor summary, .toggleLine) {min-height: 44px}
.touch-capable #modal input[type="range"] {height: 32px}
.touch-capable #modal label {touch-action: pan-y}

@media (orientation: landscape) {
  body.touch-playing {
    --touch-side-l: max(10px, calc(env(safe-area-inset-left, 0px) + 5px));
    --touch-side-r: max(10px, calc(env(safe-area-inset-right, 0px) + 5px));
    --touch-foot: max(10px, calc(env(safe-area-inset-bottom, 0px) + 5px));
    --touch-btn: clamp(48px, 9vmin, 62px);
    --touch-main-btn: clamp(64px, 14.5vmin, 84px);
    --touch-spacing: clamp(8px, 1.8vmin, 12px);
    --touch-thumb: clamp(96px, 23vmin, 150px);
    --touch-stick-inset: calc(var(--touch-side-l) + clamp(3px, 1vw, 14px));
    --touch-stick-width: calc(var(--touch-stick-inset) + var(--touch-thumb) + var(--touch-spacing) + var(--touch-btn));
    --touch-combat-width: calc(var(--touch-side-r) + 2 * var(--touch-btn) + var(--touch-main-btn) + 2 * var(--touch-spacing));
    --touch-combat-height: calc(var(--touch-foot) + var(--touch-btn) + var(--touch-main-btn) + var(--touch-spacing));
    --touch-joystick-height: calc(var(--touch-foot) + max(var(--touch-thumb), 2 * var(--touch-btn) + var(--touch-spacing)));
  }

  .touch-playing #touchControls {
    --touch-button: var(--touch-btn);
    --touch-gap: var(--touch-spacing);
    --touch-stick: var(--touch-thumb);
    --touch-left: var(--touch-stick-inset);
    --touch-right: var(--touch-side-r);
    --touch-bottom: var(--touch-foot);
    --combat-middle: calc(var(--touch-right) + var(--touch-step));
    --combat-inner: calc(var(--combat-middle) + var(--touch-main-btn) + var(--touch-gap));
    --combat-row: calc(var(--touch-bottom) + var(--touch-step));
    --combat-middle-small: calc(var(--combat-middle) + (var(--touch-main-btn) - var(--touch-btn)) / 2);
    --combat-row-small: calc(var(--combat-row) + (var(--touch-main-btn) - var(--touch-btn)) / 2);
  }
  #touchControls button {border-radius: 13px; background: #102126b8}
  #touchControls .touch-label {white-space: nowrap; overflow-wrap: normal}
  #touchControls [data-touch-action="fire"] {
    right: var(--combat-middle);
    bottom: var(--combat-row);
    width: var(--touch-main-btn);
    height: var(--touch-main-btn);
    border: 2px solid #e2edc4;
    border-radius: 50%;
    background: #223c3cd4;
  }
  #touchControls [data-touch-action="fire"] svg {width: 48%; height: 48%}
  #touchControls [data-touch-action="aim"] {
    right: var(--combat-inner);
    bottom: var(--combat-row-small);
    border-radius: 50%;
    border-color: #d3e2ce;
  }
  #touchControls [data-touch-action="interact"] {right: var(--touch-right); bottom: var(--combat-row-small)}
  .touch-playing.touch-interaction-ready #touchControls [data-touch-action="interact"] {
    border: 2px solid #d7ed8a;
    color: #f0ffc8;
    background: #314536e8;
  }
  #touchControls [data-touch-action="jump"] {right: var(--touch-right); bottom: var(--touch-bottom)}
  #touchControls [data-touch-action="reload"] {right: var(--combat-middle-small); bottom: var(--touch-bottom)}
  #touchControls [data-touch-action="cycle"] {right: var(--combat-inner); bottom: var(--touch-bottom)}

  #touchControls [data-touch-action]:is(.is-pressed, [aria-pressed="true"]) {
    color: white;
    border-color: #f2ffce;
    background: #476756e8;
  }
  #touchControls :is([data-touch-action="aim"], [data-touch-action="sprint"])[aria-pressed="true"]::after {
    content: "✓";
    position: absolute;
    top: 1px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #d7ed8a;
    color: #152419;
    font: bold 11px/14px var(--text);
    pointer-events: none;
  }

  .touch-playing #hud .health {left: var(--touch-stick-inset); bottom: calc(var(--touch-joystick-height) + 6px); max-width: var(--touch-thumb)}
  .touch-playing #hud .weapon {right: var(--touch-side-r); bottom: calc(var(--touch-combat-height) + 6px); max-width: calc(var(--touch-combat-width) - var(--touch-side-r))}
  .touch-playing #hud #supportDrone {right: var(--touch-side-r); bottom: calc(var(--touch-combat-height) + 61px)}
  .touch-playing #hud .objective {left: var(--touch-side-l); max-width: min(40vw, 410px)}
  .touch-playing #hud .boss, .touch-playing #hud .chapterCard {right: var(--touch-side-r)}
  .touch-playing #hud .boss {max-width: min(27vw, 220px)}
  .touch-playing #hud .chapterCard {max-width: min(28vw, 280px)}
  .touch-playing #hud .chapterCard strong {font-size: clamp(14px, 3.25vmin, 22px)}
  .touch-playing #hud .chapterCard span {font-size: clamp(11px, 2.7vmin, 15px)}
  .touch-playing #subtitle, .touch-playing #hud .stationGuide {
    left: calc(var(--touch-stick-width) + 6px);
    right: calc(var(--touch-combat-width) + 6px);
    width: fit-content;
    max-width: calc(100% - var(--touch-stick-width) - var(--touch-combat-width) - 12px);
    margin-inline: auto;
    transform: none;
    overflow-wrap: break-word;
    text-align: center;
  }
  .touch-playing #subtitle {bottom: var(--touch-foot); padding: 3px 7px}
  .touch-playing #subtitle span {font-size: calc(clamp(13px, 3.1vmin, 20px) * var(--subtitle-scale, 1)); line-height: 1.2}
  .touch-playing #hud .stationGuide {bottom: var(--touch-foot)}
  .touch-playing:has(#subtitle:not([hidden])) #hud .stationGuide:not(.routeAlert) {bottom: calc(var(--touch-foot) + 60px)}
}

@media (max-height: 450px) and (orientation: landscape) {
  .touch-capable[data-mode="menu"] .menuGrid {padding: 8px 0}
  .touch-capable[data-mode="menu"] #sectionName {margin-bottom: 4px}
  .touch-capable[data-mode="menu"] #screenTitle {font-size: clamp(36px, 6.4vw, 56px)}
  .touch-capable[data-mode="menu"] .feature {max-width: none}
  .touch-capable[data-mode="menu"] #actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: min(50vw, 365px);
    max-width: 100%;
    margin-top: 12px;
  }
  .touch-capable[data-mode="menu"] #actions .action {gap: 4px; padding: 4px 8px; font-size: 14px}
  .touch-capable #modal .dialog {padding: 8px 14px}
  .touch-capable #modal .dialog > header, .touch-capable #modal .tabs {margin-bottom: 4px}
  .touch-playing #hud #objective {font-size: 13px; line-height: 1.15}
  .touch-playing #hud .missionDetail, .touch-playing #hud .branchHint {font-size: 11px; line-height: 1.15}
  .touch-playing #hud .prompt {top: 60%; font-size: 12px; padding: 3px 6px; max-width: min(40vw, 280px)}
  .touch-playing #hud .stationGuide {font-size: 10px}
  .touch-playing #hud .health .vitalNumber span {display: none}
}
@media (max-width: 330px) {
  #touchControls {--touch-button: 44px; --touch-gap: 4px; --touch-stick: 80px; --touch-left: max(5px,env(safe-area-inset-left,0px)); --touch-right: max(5px,env(safe-area-inset-right,0px))}
}

body.touch-playing #touchControls[data-rescue-ready] [data-touch-action="interact"] {
  color: #fff;
  background: #832649;
  border: 2px solid #ffe5f0;
  box-shadow: 0 0 0 2px #b73570, 0 0 12px #ff5aa865;
}
#touchControls[data-rescue-ready] [data-touch-action="interact"] svg {visibility:hidden}
#touchControls[data-rescue-ready] [data-touch-action="interact"]::before {
  position:absolute;
  content:"+";
  top:50%;left:50%;transform:translate(-50%,-51%);
  font:800 27px/1 system-ui;
  pointer-events:none;
}
