/* Mobile / iOS full-screen rules — Shell lane (docs/mobile-contract.md).
   Everything here is scoped under html.touch so a desktop browser renders exactly as before. */

html.touch {
  /* Safe-area insets; the gate in index.html overrides these inline for tests (?safe=T,R,B,L). */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* Extra corner inset where no safe area guards a screen corner (iPad, foldables, fullscreen
     Android): the display's rounded corner would otherwise crowd the HUD pieces tucked into it. */
  --c-tl: max(0px, 10px - var(--safe-t) - var(--safe-l));
  --c-tr: max(0px, 10px - var(--safe-t) - var(--safe-r));

  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html.touch body {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Full-bleed canvas that follows the real visible viewport (lvh fallback, then dvh). */
html.touch canvas#game {
  width: 100vw;
  height: 100vh;
  height: 100lvh;
  height: 100dvh;
  inset: 0;
  touch-action: none;
}

/* No focus zoom on iOS: every text field is at least 16px. */
html.touch input,
html.touch select,
html.touch textarea {
  font-size: 16px;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}
html.touch input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html.touch select,
html.touch textarea {
  font-size: 16px;
}
/* Id-scoped desktop sizes in style.css would otherwise win. */
html.touch #authForm input { font-size: 16px; }
html.touch #chatInput { font-size: 16px; }

/* Scrollable regions keep one-finger vertical scrolling. */
html.touch .screen,
html.touch .win,
html.touch .win-body,
html.touch .win-tabs,
html.touch .chatlog,
html.touch .list,
html.touch .toasts {
  touch-action: pan-y;
  overscroll-behavior: contain;
}

/* ---------- Login screen ---------- */
html.touch #login.screen {
  align-items: safe center;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
html.touch #login .login-card {
  margin: 0 auto;
  width: min(520px, 100%);
}

/* Keyboard hints are useless on a phone. */
html.touch .hint { display: none; }

/* Short landscape (e.g. 874x402 with safe areas): tighten the card so nothing is cut off, and use
   the width a landscape phone has — the creator's stage and swatch rows need it. */
@media (orientation: landscape) and (max-height: 510px) {
  html.touch #login .login-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: var(--s3);
    padding: var(--s1) var(--s3);
    border-radius: var(--r-lg);
    width: min(820px, 100%);
  }
  html.touch #login .login-card.creating .logo { grid-column: 1; grid-row: 1; font-size: var(--f-xl); letter-spacing: .09em; white-space: nowrap; }
  html.touch #login .login-card.creating .tabs { grid-column: 2; grid-row: 1; margin: 0; gap: var(--s1); }
  html.touch #login .login-card .tag,
  html.touch #login .login-card #authForm { grid-column: 1 / -1; }
  html.touch #login .logo { font-size: 26px; letter-spacing: 4px; margin: 0; }
  html.touch #login .tag { font-size: 12px; line-height: 1.3; margin: 2px 0 8px; }
  html.touch #login .tabs { margin-bottom: var(--s2); }
  html.touch #login .tab { padding: 5px; }
  html.touch #login #authForm { gap: var(--s1); }
  html.touch #login #authForm input { min-height: var(--h-touch); padding: 0 var(--s2); }
  html.touch #login .btn.primary { min-height: var(--h-touch); padding: 0 var(--s3); }
  html.touch #login .err { min-height: 16px; font-size: 13px; }
  html.touch #login .conn { margin-top: 2px; }
  html.touch #login .pn-link { margin-top: 4px; }
}

/* Portrait: a little more air, the card is the whole screen anyway. The side padding is tight so
   the weapon row and the ‹ name › controls fit the width without clipping. */
@media (orientation: portrait) {
  html.touch #login .login-card { padding: var(--s4) var(--s3); }
  html.touch #login .logo { font-size: var(--f-xl); letter-spacing: .09em; }
}


/* Keyboard-key hints inside window text mean nothing without a keyboard. */
html.touch .kh { display: none; }
