[hidden] { display: none !important; }
html, body, canvas { touch-action: none; overscroll-behavior: none; }
body.touch-layout > main { width: 100%; height: 100%; aspect-ratio: auto; }

#touch-controls {
  --pad-size: clamp(76px, 27dvh, 114px);
  --stick-left: max(14px, calc(env(safe-area-inset-left) + 8px));
  --stick-right: max(14px, calc(env(safe-area-inset-right) + 8px));
  --stick-bottom: max(9px, calc(env(safe-area-inset-bottom) + 8px));
  --width-bottom: calc(var(--stick-bottom) + var(--pad-size) + 2px);
  --ivory: #fff0d1;
  --cyan: #40e6ff;
  --coral: #ff9c7d;
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  color: var(--ivory);
  font: 12px MenuPixel, monospace;
  text-transform: uppercase;
}
#touch-controls svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
  pointer-events: none;
}
#touch-controls button, #touch-controls .pad, #dig-width-slider {
  pointer-events: auto;
  touch-action: none;
}
#touch-controls .pad {
  position: absolute;
  bottom: var(--stick-bottom);
  width: var(--pad-size);
  height: var(--pad-size);
  display: grid;
  place-items: center;
}
#move-pad { left: var(--stick-left); color: var(--cyan); }
#aim-pad { right: var(--stick-right); color: var(--coral); }
#touch-controls .pad-face {
  position: relative;
  display: grid;
  place-items: center;
  width: 70%;
  height: 70%;
  border: 2px solid color-mix(in srgb, currentColor 65%, transparent);
  border-radius: 50%;
  background: #10232b54;
  pointer-events: none;
}
#touch-controls .stick {
  width: 43%;
  height: 43%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: #10232bd0;
}
#touch-controls .boost-cue { position: absolute; top: 3px; width: 14px; height: 11px; }
#touch-controls .held .pad-face { border-color: currentColor; }
#touch-controls .boost .pad-face { border-color: var(--ivory); }
#touch-controls .boost .boost-cue { color: var(--ivory); }

#touch-controls button {
  position: absolute;
  min-width: 48px;
  min-height: 48px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-transform: inherit;
}
#touch-controls .touch-button-face, #dig-width {
  border: 1px solid #fff0d155;
  border-radius: 4px;
  background: #1b303bdc;
  box-shadow: 0 2px 0 #0b1b2380;
}
#touch-controls .touch-button-face { display: grid; place-items: center; }
#touch-controls button:active .touch-button-face { background: #364951; }
#touch-menu {
  right: max(var(--stick-right), var(--gem-hud-gutter, 80px));
  top: max(calc(env(safe-area-inset-top) + 4px), var(--touch-hud-top, 8px));
}
#touch-menu .touch-button-face { width: 30px; height: 30px; }
#touch-width {
  right: calc(var(--stick-right) + max(0px, (var(--pad-size) - 84px) / 2));
  bottom: var(--width-bottom);
  width: 84px;
}
#touch-width .touch-button-face { display: block; padding: 7px 6px; white-space: nowrap; }
#dig-width {
  position: absolute;
  right: var(--stick-right);
  bottom: calc(var(--width-bottom) + 49px);
  width: 157px;
  padding: 7px 9px 0;
}
.width-labels { display: flex; justify-content: space-between; font-size: 10px; pointer-events: none; }
.width-ticks {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 19px;
  height: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.width-ticks i { display: block; width: 1px; height: 6px; background: var(--ivory); }
#dig-width-slider {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
#dig-width-slider::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: var(--cyan); }
#dig-width-slider::-moz-range-track { height: 3px; border-radius: 2px; background: var(--cyan); }
#dig-width-slider::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 14px; height: 17px; margin-top: -7px; border: 1px solid var(--ivory); border-radius: 4px; background: var(--coral); }
#dig-width-slider::-moz-range-thumb { width: 14px; height: 16px; border: 1px solid var(--ivory); border-radius: 4px; background: var(--coral); }
#touch-controls button:focus-visible, #dig-width-slider:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
@media (max-height: 235px) {
  #touch-controls { --pad-size: 66px; }
  #dig-width { right: calc(var(--stick-right) + 87px); bottom: var(--width-bottom); }
}

/* The child viewport stays landscape, so Unity and browser input use the same axes. */
body.landscape-host > main, body.landscape-host > #touch-controls { display: none !important; }
#landscape-frame { position: fixed; border: 0; left: env(safe-area-inset-left); top: env(safe-area-inset-top); width: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)); height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); transform-origin: top left; background: #101d27; }
@media (orientation: portrait) {
  #landscape-frame { left: calc(100vw - env(safe-area-inset-right)); width: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); height: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right)); transform: rotate(90deg); }
}
