/* Touch controls + mobile layout. Everything here is scoped to html.is-mobile (set by main.js / core/touch.js). */

/* ---- menus: laid out on a virtual ~1180×640 screen, then scaled down to the phone (--mz, --vw, --vh from
   TouchControls._layoutZoom). The menus size everything from --u (a viewport unit) but give text a px floor, so on a
   small screen the boxes shrank while the text did not and spilled out; laying out at desktop size keeps the design's
   proportions. transform (not `zoom`, which Safari applies differently) scales the result the same in every browser. */
html.is-mobile .iw-ui {
  inset: auto; left: 0; top: 0;
  width: calc(var(--vw, 100vw) / var(--mz, 1)); height: calc(var(--vh, 100vh) / var(--mz, 1));
  transform: scale(var(--mz, 1)); transform-origin: 0 0;
  --u: min(calc(var(--vw, 100vw) / var(--mz, 1) / 100), calc(var(--vh, 100vh) / var(--mz, 1) * .017778));
}
html.is-mobile, html.is-mobile body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }

/* ---- overlay */
.iw-touch { display: none; position: fixed; inset: 0; z-index: 15; touch-action: none; user-select: none; -webkit-user-select: none;
  --tb: clamp(50px, 15vh, 82px);
  --pad-r: max(14px, env(safe-area-inset-right)); --pad-l: max(14px, env(safe-area-inset-left)); --pad-b: max(12px, env(safe-area-inset-bottom)); }
.iw-touch.is-on { display: block; }
.iw-touch__zone { position: absolute; top: 0; bottom: 0; }
.iw-touch__zone.is-move { left: 0; width: 42%; }
.iw-touch__zone.is-look { right: 0; width: 58%; }

.iw-touch__stick { position: absolute; left: 0; top: 0; width: 0; height: 0; opacity: 0; transition: opacity .12s; pointer-events: none; }
.iw-touch__stick.is-on { opacity: 1; }
.iw-touch__stick::before { content: ''; position: absolute; left: -64px; top: -64px; width: 128px; height: 128px; border-radius: 50%;
  background: rgba(20, 16, 30, .28); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .55); }
.iw-touch__stick i { position: absolute; left: -28px; top: -28px; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255, 255, 255, .8); box-shadow: 0 2px 0 3px rgba(21, 18, 28, .45); }

.iw-touch__btn { position: absolute; width: var(--tb); height: var(--tb); padding: 0; border: 0; border-radius: 50%; touch-action: none;
  background: rgba(21, 18, 28, .42); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .7);
  color: #fff; font: 900 calc(var(--tb) * .2) / 1 'Rubik', system-ui, sans-serif; letter-spacing: .06em; text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  -webkit-tap-highlight-color: transparent; transition: scale .08s, background .08s; }
.iw-touch__btn.is-down { scale: .92; background: rgba(255, 255, 255, .38); }
.iw-touch__btn span { pointer-events: none; }

/* right-hand cluster, fire in the corner */
.iw-touch__btn.is-fire { --s: 1.45; width: calc(var(--tb) * var(--s)); height: calc(var(--tb) * var(--s)); font-size: calc(var(--tb) * .26);
  right: var(--pad-r); bottom: calc(var(--pad-b) + var(--tb) * .2); background: rgba(255, 120, 40, .45); }
.iw-touch__btn.is-jump { right: calc(var(--pad-r) + var(--tb) * 1.65); bottom: var(--pad-b); }
.iw-touch__btn.is-squid { right: calc(var(--pad-r) + var(--tb) * 1.55); bottom: calc(var(--pad-b) + var(--tb) * 1.15); }
.iw-touch__btn.is-sub { right: calc(var(--pad-r) + var(--tb) * .25); bottom: calc(var(--pad-b) + var(--tb) * 1.85); }
.iw-touch__btn.is-special { right: calc(var(--pad-r) + var(--tb) * .25); bottom: calc(var(--pad-b) + var(--tb) * 3); background: rgba(255, 210, 40, .4); }

/* top-left: map + pause */
.iw-touch__btn.is-map, .iw-touch__btn.is-pause { --tb2: calc(var(--tb) * .72); width: var(--tb2); height: var(--tb2); border-radius: 30%; top: max(10px, env(safe-area-inset-top)); font-size: calc(var(--tb) * .17); }
.iw-touch__btn.is-pause { left: var(--pad-l); }
.iw-touch__btn.is-map { left: calc(var(--pad-l) + var(--tb) * .9); }
/* map open: the button turns into a solid close button (moved below the stage-map title) */
.iw-touch__btn.is-map.is-open { left: var(--pad-l); top: calc(max(10px, env(safe-area-inset-top)) + var(--tb) * 1.75); background: #fff; color: #15121c; text-shadow: none; font-size: calc(var(--tb) * .3); box-shadow: 0 0 0 3px #15121c; }

/* ---- portrait: ask for landscape (the game and its HUD are built for a wide screen) */
.iw-rotate { display: none; }
@media (orientation: portrait) {
  html.is-mobile .iw-rotate { display: flex; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
    background: #0d1020; color: #fff; font: 800 20px/1.3 'Rubik', system-ui, sans-serif; text-align: center; padding: 24px; }
  html.is-mobile .iw-rotate svg { width: 72px; height: 72px; animation: iw-rot 1.8s ease-in-out infinite; }
}
@keyframes iw-rot { 0%, 20% { rotate: 0deg; } 60%, 100% { rotate: -90deg; } }

/* size diagnostics (?debug, or hold the pause button 2 s) */
.iw-touch__debug { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 200; margin: 0; padding: 10px 12px; max-width: 94vw;
  background: rgba(0, 0, 0, .78); color: #7dff9a; font: 600 11px/1.45 ui-monospace, Menlo, monospace; white-space: pre-wrap; border-radius: 8px; pointer-events: none; }

/* Russian labels are longer (ОГОНЬ, ПРЫЖОК, КАРТА): a notch smaller, no tracking */
html[lang="ru"] .iw-touch__btn span { font-size: .8em; letter-spacing: 0; }

/* ---- iPhone / iPad: install-to-Home-Screen screen (src/ui/install.js). Read upright, so no "turn sideways" here. */
html.needs-install .iw-rotate { display: none !important; }
.iw-install { position: fixed; inset: 0; z-index: 120; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); box-sizing: border-box; overflow-y: auto;
  --u: 5px; --k: #15121c; --a: #ff3fa4; --a-light: #ff9fd0; --b: #29d3ff; --b-ink: #15121c;
  background: radial-gradient(ellipse at 50% 30%, #2c2540, #0d1020 70%); color: #fff; font-family: 'Rubik', system-ui, sans-serif; text-align: center; }
.iw-install__logo { margin-bottom: 6px; }
.iw-install__title { margin: 0; font: 400 30px/1.1 'Titan One', 'Rubik', sans-serif; letter-spacing: .02em; -webkit-text-stroke: 6px #15121c; paint-order: stroke fill; }
.iw-install__lead { margin: 0; max-width: 330px; font-weight: 600; font-size: 16px; line-height: 1.4; color: rgba(255, 255, 255, .82); }
.iw-install__steps { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; width: min(340px, 100%); counter-reset: s; }
.iw-install__steps li { counter-increment: s; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: rgba(255, 255, 255, .08);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .1); text-align: left; font-weight: 700; font-size: 16px; line-height: 1.3; }
.iw-install__steps li::before { content: counter(s); flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #ff3fa4; color: #fff; font-weight: 900; font-size: 14px; }
.iw-install__steps i { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: #fff; color: #0a84ff; }
.iw-install__steps i svg { width: 22px; height: 22px; }
.iw-install__note { margin: 4px 0 0; max-width: 330px; font-size: 13px; font-weight: 600; color: rgba(255, 255, 255, .6); }
/* points at Safari's Share button: bottom centre on iPhone, top right on iPad */
.iw-install__arrow { position: fixed; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); width: 28px; height: 28px; margin-left: -14px;
  border-right: 5px solid #ff3fa4; border-bottom: 5px solid #ff3fa4; rotate: 45deg; animation: iw-install-bob 1.2s ease-in-out infinite; }
.iw-install__arrow.is-top { left: auto; right: 90px; top: 8px; bottom: auto; rotate: -135deg; }
@keyframes iw-install-bob { 50% { translate: 0 8px; } }
.iw-install__arrow.is-top { animation-name: iw-install-bob-up; }
@keyframes iw-install-bob-up { 50% { translate: 0 -8px; } }
@media (orientation: landscape) and (max-height: 500px) { .iw-install { justify-content: flex-start; } .iw-install__logo { display: none; } }

/* main menu on a phone: no room for the entry description above the wallet chip */
html.is-mobile .iw-main .iw-main__desc { display: none; }

/* ---- computers on the public site: "play on your phone" + QR (src/ui/install.js showPhoneOnly) */
.iw-phoneonly { justify-content: center !important; }
.iw-phoneonly .iw-install__logo { display: block !important; }
.iw-phoneonly__qr { width: 240px; height: 240px; padding: 12px; box-sizing: border-box; border-radius: 22px; background: #fff; box-shadow: 0 0 0 5px #ff3fa4, 0 10px 0 5px rgba(0, 0, 0, .35); rotate: -2deg; margin: 10px 0 6px; }
.iw-phoneonly__qr img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.iw-phoneonly__link { color: #29d3ff; font-weight: 800; font-size: 18px; text-decoration: none; border-bottom: 2px solid currentColor; }
