/* Snake on a phone — loaded only by web/index.html, after the shared
   style.css (which every game links, so nothing snake-only goes there).

   `body.touch-ui` is set by game.js from isTouchDevice() (a coarse pointer),
   the same predicate that sizes the board, so layout and canvas agree.
   Probe + before/after shots: tests/_probe_mobile_snake_tanks.py,
   web/_scratch/mobile/. */

/* ── Overlays scroll instead of clipping (all devices) ─────────────────────
   The lobby card is taller than a landscape phone and than a short desktop
   window; a centred flex box cut off its top AND its bottom, Start included.
   Auto margins centre it while it fits and let it scroll once it does not. */
.overlay { overflow-y: auto; align-items: flex-start; }
.overlay > .overlay-card { margin: auto; }

/* ── Desktop: nothing moves ────────────────────────────────────────────── */
#audioDock   { display: contents; }
#audioToggle { display: none; }
#fsBtn {
  position: fixed; top: 8px; right: 412px; z-index: 1000;
  background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px; color: #fff; font: inherit; font-size: 0.85rem;
  padding: 4px 8px; cursor: pointer;
}
#fsBtn:hover { background: rgba(255, 255, 255, 0.15); }
[data-theme="light"] #fsBtn { background: rgba(255, 255, 255, 0.8); border-color: rgba(0, 0, 0, 0.2); color: #333; }

/* ── Touch ─────────────────────────────────────────────────────────────── */

/* Two buttons in the HUD's right end instead of six controls at desktop
   offsets (they ran 400 px wide on a 390 px screen, over the HUD text). */
body.touch-ui #fsBtn,
body.touch-ui #audioToggle {
  display: flex; align-items: center; justify-content: center;
  position: fixed; top: 4px; z-index: 1001;
  width: 40px; height: 34px; padding: 0;
  font-size: 1.15rem; line-height: 1;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
body.touch-ui #audioToggle { right: 8px; }
body.touch-ui #fsBtn       { right: 54px; }
body.touch-ui #fsBtn[hidden] { display: none; }

body.touch-ui #audioDock {
  display: none;
  position: fixed; top: 44px; right: 8px; z-index: 1001;
  flex-direction: column; align-items: stretch; gap: 10px;
  padding: 12px; min-width: 190px;
  background: rgba(14, 16, 30, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
body.touch-ui #audioDock.open { display: flex; }
/* Every control in the dock is position:fixed with a desktop `right:` in
   style.css — `.volume-slider` included (the shared top:12px trap). */
body.touch-ui #audioDock > * {
  position: static; inset: auto; margin: 0;
  min-height: 40px; font-size: 0.95rem;
}
body.touch-ui #audioDock > .volume-slider { width: 100%; height: 32px; min-height: 0; }

body.touch-ui #hud { padding-right: 104px; font-size: 0.72rem; gap: 6px; }
body.touch-ui #hudLeft  { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
body.touch-ui #hudRight { min-width: 0; }

/* Lobby: room for the corner buttons, and Start never scrolls out of reach. */
body.touch-ui .overlay { padding: 48px 0 20px; }
body.touch-ui .overlay > .overlay-card { padding: 22px 16px; width: calc(100% - 20px); }
body.touch-ui #startBtn {
  position: sticky; bottom: 10px; z-index: 5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

/* Controls: bigger targets, one per thumb. */
body.touch-ui #mobileControls {
  display: flex;
  height: 196px;
  justify-content: space-between;
  padding: 8px 22px 12px;
}
body.touch-ui #dpad { gap: 4px; }
body.touch-ui .dpad-row { gap: 4px; }
body.touch-ui .dpad-btn,
body.touch-ui .dpad-center { width: 58px; height: 58px; }
body.touch-ui .dpad-btn { font-size: 1.3rem; border-radius: 10px; touch-action: none; }
body.touch-ui .btn-fire { width: 96px; height: 96px; font-size: 1rem; touch-action: none; }

/* Landscape: the board takes the full height and the controls flank it, so
   neither covers the other and both thumbs rest where they already are. */
@media (orientation: landscape) {
  body.touch-ui { --snake-side: 172px; }
  body.touch-ui #gameWrapper { position: relative; }
  body.touch-ui #canvasWrap { padding: 0 var(--snake-side); box-sizing: border-box; }
  body.touch-ui #mobileControls {
    position: absolute; left: 0; right: 0; top: var(--hud-h); bottom: 0;
    height: auto; padding: 0 8px 12px;
    background: none; border: 0;
    align-items: flex-end; justify-content: space-between;
    pointer-events: none;   /* the gaps belong to the swipe surface */
  }
  body.touch-ui #mobileControls > * { pointer-events: auto; }
  body.touch-ui .dpad-btn,
  body.touch-ui .dpad-center { width: 50px; height: 50px; }
  body.touch-ui .btn-fire { margin: 0 30px 18px 0; }
}
