/* ============================================================================
   MOBILE STYLES — everything touch-specific lives here.
   Activated by body.is-mobile (set in js/input/mobile.js on touch devices).
   Desktop is untouched: without .is-mobile every rule below is inert.

   Sections:
     1. Base behaviour + desktop-only element hiding
     2. Menu / join screen (portrait + landscape)
     3. Lobby globe
     4. Touch controls (joystick + action buttons, per-round sets)
     5. In-round HUD scaling
     6. Rotate-device prompt (in-game portrait only)
   ========================================================================== */

/* ─── 1. Base ───────────────────────────────────────────────────────────── */

body.is-mobile {
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}
/* Text fields still need selection/caret behaviour. */
body.is-mobile input,
body.is-mobile textarea {
  -webkit-user-select: text; user-select: text;
  touch-action: auto;
}

/* Keyboard-centric or debug chrome — meaningless on touch. */
body.is-mobile #kb-hints,
body.is-mobile #diag-stats,
body.is-mobile #balloon-controls-hint,
body.is-mobile #obj-controls,
body.is-mobile #balloon-clicktoplay { display: none !important; }

/* ─── 2. Menu / join screen ─────────────────────────────────────────────── */

body.is-mobile #game-title-bar { padding-top: max(8px, env(safe-area-inset-top)); }
body.is-mobile #game-title {
  font-size: clamp(22px, 6.4vw, 36px);
  letter-spacing: 4px;
  text-shadow:
    0 2px 0 #d4456a, 0 4px 0 #b83a5c,
    0 6px 12px rgba(0,0,0,0.3),
    0 0 24px rgba(255,150,180,0.4);
}

/* Lobby slots strip — smaller dots tucked in the corner */
body.is-mobile #lobby-strip { top: 10px; right: max(12px, env(safe-area-inset-right)); }
/* Portrait: the centred title spans the full width — drop the strip below it. */
body.is-mobile.is-portrait #lobby-strip { top: 56px; }
body.is-mobile .lobby-slot { width: 20px; height: 20px; font-size: 10px; }
body.is-mobile #lobby-slots { gap: 4px; margin-bottom: 4px; }
body.is-mobile #lobby-status { font-size: 10px; padding: 3px 8px; }

body.is-mobile #menu-content { padding: 0 max(12px, env(safe-area-inset-left)); }

/* Landscape: panel on the left like desktop, just tighter. */
body.is-mobile #left-panel {
  width: clamp(220px, 42vw, 280px);
  min-width: 0;
  margin-left: 6px;
}
/* Portrait: the panel becomes the centred main column. */
body.is-mobile.is-portrait #menu-content { justify-content: center; }
body.is-mobile.is-portrait #left-panel {
  width: min(86vw, 320px);
  margin-left: 0;
}

body.is-mobile .panel-card { padding: 14px 14px; border-radius: 14px; }
body.is-mobile .panel-label { font-size: 10px; letter-spacing: 2px; margin-bottom: 4px; }

body.is-mobile #player-name-input {
  padding: 8px 12px; font-size: 16px; /* 16px+ stops iOS auto-zoom on focus */
  border-radius: 9px; margin-bottom: 12px;
}

body.is-mobile #char-selector { margin-bottom: 12px; }
body.is-mobile .arrow-btn { width: 36px; height: 36px; font-size: 14px; }
body.is-mobile #char-name { font-size: 16px; letter-spacing: 1.5px; }
body.is-mobile #char-counter { font-size: 9px; }

body.is-mobile .menu-btn { padding: 10px; font-size: 14px; }
body.is-mobile .menu-btn.primary {
  font-size: 16px; letter-spacing: 2px; margin-bottom: 6px;
  box-shadow: 0 3px 0 #d4456a, 0 4px 12px rgba(255,100,120,0.3);
}
body.is-mobile .menu-btn.secondary { margin-bottom: 6px; }
body.is-mobile #join-btn { padding: 11px; font-size: 16px; letter-spacing: 2px; border-radius: 10px; }

body.is-mobile #join-code-row { gap: 6px; margin-bottom: 4px; }
body.is-mobile #join-code-input { padding: 8px 10px; font-size: 16px; letter-spacing: 3px; }
body.is-mobile #join-code-row .menu-btn { min-width: 64px; padding: 8px 12px; font-size: 12px; }

body.is-mobile #room-error { font-size: 11px; min-height: 14px; }

body.is-mobile #room-code-display { padding: 10px; margin-top: 10px; }
body.is-mobile #room-code-text { font-size: 26px; letter-spacing: 5px; margin: 6px 0 8px; }
body.is-mobile #copy-link-btn { padding: 6px 12px; font-size: 11px; }

/* Decorative labels that overlap the centred character preview on phones. */
body.is-mobile #char-spotlight,
body.is-mobile #taken-banner { display: none; }

body.is-mobile #lobby-timer-bar { bottom: 10px; padding: 4px 12px; font-size: 11px; }

/* ─── 3. Lobby globe ────────────────────────────────────────────────────── */

body.is-mobile #lobby-globe-overlay .lg-banner { top: max(10px, env(safe-area-inset-top)); }
body.is-mobile #lobby-globe-overlay .lg-banner-plate {
  padding: 7px 14px 6px;
  border-radius: 12px;
}
body.is-mobile #lobby-globe-overlay .lg-title { font-size: clamp(13px, 3.4vw, 18px); }
body.is-mobile #lobby-globe-overlay .lg-sub {
  margin-top: 3px;
  font-size: 9px;
  letter-spacing: .12em;
}
body.is-mobile #lobby-globe-overlay .lg-dots-group { gap: 4px; margin-left: 8px; }
body.is-mobile #lobby-globe-overlay .lg-bottom-row { bottom: max(14px, env(safe-area-inset-bottom)); }
body.is-mobile #lobby-globe-overlay .lg-timer-pill {
  padding: 6px 16px 8px;
  border-radius: 14px;
}
body.is-mobile #lobby-globe-overlay .lg-timer-label { font-size: 9px; letter-spacing: .18em; }
body.is-mobile #lobby-globe-overlay .lg-timer { font-size: clamp(20px, 6vw, 30px); }
body.is-mobile #lg-start-bots-btn .lg-bots-label,
body.is-mobile #lg-start-bots-btn .lg-bots-action {
  font-size: clamp(11px, 2.6vw, 14px);
  white-space: nowrap;
}

/* Banner + timer reserve far less height on mobile — let the sphere grow. */
body.is-mobile #lobby-globe-overlay .lg-sphere {
  --lg-reserved: 110px;
  width: min(454px, 63vmin, 75vw, calc(100vh - var(--lg-reserved)));
  height: min(454px, 63vmin, 75vw, calc(100vh - var(--lg-reserved)));
}
body.is-mobile #lobby-globe-overlay .lg-halo {
  width: min(620px, 92vmin, 130%);
  height: min(620px, 92vmin, 130%);
  filter: blur(4px);
}

/* ─── 4. Touch controls ─────────────────────────────────────────────────── */

#m-controls, #m-rotate-prompt { display: none; }

/* Controls exist only on mobile, inside a round, while still alive. */
body.is-mobile.in-game:not(.is-eliminated) #m-controls { display: block; }

#m-joystick {
  position: fixed;
  left: max(28px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 130px; height: 130px;
  z-index: 80;
  border-radius: 50%;
  background: radial-gradient(circle at center,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.10) 65%,
    rgba(255, 255, 255, 0.02) 100%);
  border: 2px solid rgba(255, 255, 255, 0.30);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35), inset 0 0 24px rgba(255, 255, 255, 0.04);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
  touch-action: none;
}
#m-joystick-knob {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(220, 220, 230, 0.85) 50%,
    rgba(180, 180, 200, 0.75) 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45), inset 0 -2px 4px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  transition: transform 0.05s linear;
}

.m-btn {
  position: fixed;
  z-index: 80;
  border: 1.5px solid rgba(255, 255, 255, 0.30);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0) 55%),
    linear-gradient(155deg, rgba(40, 30, 60, 0.30) 0%, rgba(15, 10, 25, 0.40) 100%);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: rgba(255, 246, 234, 0.92);
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.30),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.07s ease, box-shadow 0.14s ease, background 0.14s ease;
}
.m-btn .m-svg {
  width: 44%; height: 44%;
  filter: drop-shadow(0 1.5px 2px rgba(0, 0, 0, 0.45));
}
.m-btn:active {
  transform: scale(0.92);
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 55%),
    linear-gradient(155deg, rgba(60, 45, 90, 0.55) 0%, rgba(20, 14, 32, 0.6) 100%);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.4),
    inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* Jump (glass-bridge, hex-fall) — sky-blue accent in the thumb corner. */
.m-btn-jump {
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 76px; height: 76px;
  border-color: rgba(120, 200, 255, 0.5);
  color: #d6ecff;
}

/* Balloon set — Shoot owns the corner; Rise sits ABOVE Descend beside it. */
.m-btn-rise {
  right: calc(max(18px, env(safe-area-inset-right)) + 94px);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 78px);
  width: 72px; height: 72px;
  border-color: rgba(120, 200, 255, 0.5);
  color: #d6ecff;
}
.m-btn-descend {
  right: calc(max(18px, env(safe-area-inset-right)) + 94px);
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 72px; height: 72px;
  color: #c8d2e0; border-color: rgba(180, 200, 220, 0.4);
}
.m-btn-shoot {
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 86px; height: 86px;
  border-color: rgba(255, 160, 90, 0.6);
  color: #ffd8b0;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 220, 180, 0.20) 0%, rgba(255,180,100,0) 55%),
    linear-gradient(155deg, rgba(80, 36, 18, 0.40) 0%, rgba(35, 14, 6, 0.48) 100%);
}
.m-btn-shoot:active {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 230, 200, 0.30) 0%, rgba(255,200,120,0) 55%),
    linear-gradient(155deg, rgba(110, 50, 22, 0.62) 0%, rgba(50, 20, 8, 0.7) 100%);
}
.m-btn-reload {
  right: calc(max(18px, env(safe-area-inset-right)) + 10px);
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 98px);
  width: 46px; height: 46px;
}
.m-btn-reload .m-svg { width: 52%; height: 52%; }

/* Per-round visibility: balloon buttons only in the balloon round, and the
   jump button everywhere else. */
.m-btn-balloon { display: none; }
body[data-round="hot-air-balloon"] .m-btn-balloon { display: flex; }
body[data-round="hot-air-balloon"] .m-btn-jump { display: none; }

/* ─── 5. In-round HUD scaling ───────────────────────────────────────────── */

/* Corner-anchored HUDs can scale as a block from their anchor. */
body.is-mobile #hex-hud,
body.is-mobile #glass-bridge-hud {
  transform: scale(0.65); transform-origin: top right;
}
body.is-mobile #playing-hud,
body.is-mobile #race-hud,
body.is-mobile #koth-hud {
  transform: scale(0.7); transform-origin: top center;
}

/* Balloon HUD — scale children individually: center-anchored elements
   (crosshair, HP bar, reload ring) must stay at true viewport center, so the
   wrapper itself is never transformed. */
body.is-mobile #balloon-hud #balloon-alive-counter {
  font-size: 11px; letter-spacing: 1.6px;
  padding: 6px 12px; border-radius: 9px;
  top: 10px; right: 14px;
}
body.is-mobile #balloon-hud #balloon-ammo {
  left: 12px; bottom: auto; top: 168px; /* under the wind pill, clear of the joystick */
  transform: scale(0.7); transform-origin: top left;
}
body.is-mobile #balloon-hud #balloon-hp-bar { width: 160px; bottom: 16px; }
body.is-mobile #balloon-hud #balloon-hp-label { font-size: 10px; margin-bottom: 2px; }
body.is-mobile #balloon-hud #balloon-hp-track { height: 10px; }
body.is-mobile #balloon-hud #balloon-kill-feed { top: 50px; right: 14px; max-width: 220px; }
body.is-mobile #balloon-hud #balloon-kill-feed .kill-msg {
  font-size: 10px; padding: 2px 8px; border-radius: 6px; margin-bottom: 2px;
}
/* Wind indicator: default top-center fights the kill feed — move top-left. */
body.is-mobile #balloon-hud #balloon-wind-indicator {
  top: 86px; left: 12px;
  transform: none;
  padding: 6px 12px;
  border-radius: 9px;
}
body.is-mobile #balloon-hud .balloon-wind-title { font-size: 9px; letter-spacing: 1.6px; }
body.is-mobile #balloon-hud #balloon-wind-arrow { font-size: 18px; }
body.is-mobile #balloon-hud #balloon-wind-label { font-size: 10px; }
/* Crosshair smaller and lighter. */
body.is-mobile #balloon-hud #balloon-crosshair { width: 28px; height: 28px; }
body.is-mobile #balloon-hud #balloon-crosshair::before { width: 1.5px; height: 28px; left: 13.25px; }
body.is-mobile #balloon-hud #balloon-crosshair::after  { width: 28px; height: 1.5px; top: 13.25px; }
body.is-mobile #balloon-hud .balloon-crosshair-dot { width: 4px; height: 4px; top: 12px; left: 12px; }
/* Reload ring matches the smaller crosshair so it wraps cleanly. */
body.is-mobile #balloon-hud #balloon-reload-ring {
  width: 60px; height: 60px; margin: -30px 0 0 -30px;
}

/* ─── 6. Rotate-device prompt (in-game + portrait only) ─────────────────── */

body.is-mobile.in-game.is-portrait #m-rotate-prompt {
  display: flex;
  position: fixed; inset: 0;
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(15, 12, 25, 0.85) 0%, rgba(5, 4, 10, 0.95) 80%);
  z-index: 200;
}
#m-rotate-prompt .m-rotate-card {
  text-align: center;
  padding: 36px 50px;
  background: rgba(20, 16, 30, 0.7);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 210, 63, 0.45);
  border-radius: 16px;
  box-shadow: 0 18px 44px rgba(0,0,0,0.55);
}
#m-rotate-prompt .m-rotate-icon {
  font-size: 64px;
  color: #ffd23f;
  margin-bottom: 14px;
  animation: mRotateIconSpin 2.4s ease-in-out infinite;
}
#m-rotate-prompt .m-rotate-title {
  font-family: 'Bungee', sans-serif;
  font-size: 22px;
  letter-spacing: 0.14em;
  color: #ffd23f;
  margin-bottom: 8px;
}
#m-rotate-prompt .m-rotate-sub {
  font-family: 'Fredoka One', 'Bungee', sans-serif;
  font-size: 13px; letter-spacing: 0.06em;
  color: rgba(255, 246, 234, 0.78);
}
@keyframes mRotateIconSpin {
  0%, 40%   { transform: rotate(0deg); }
  60%, 100% { transform: rotate(90deg); }
}
