/* The screens a PHONE meets before the game — sign in, sign up and its steps, password reset,
   character select, character creation — and the "install the game" card they share (spec
   2026-11-10 mobile full play §5.8). Plain CSS, --hud-* tokens only, no hex.

   Scope: every rule hangs off body[data-phone] (set by layouts/desktop and layouts/application for
   mobile_device? requests only) or off .pwa-install*, so a desktop browser and the desktop shell
   render exactly what they did before. The game itself (/mobile) is mobile_play.css.

   Why these exist:
   - viewport-fit=cover (layouts/_pwa_head) lets an installed app draw under the notch, so the
     content has to be pulled back inside env(safe-area-inset-*), on all four edges (the installed
     app is landscape-locked on Android; the notch is on the left or right).
   - iOS Safari zooms the page when it focuses a field under 16px, and a thumb needs 48px. */

/* ---- safe areas -------------------------------------------------------------------------- */
/* Launcher chrome (layouts/desktop): the padded <main> is the page's edge. */
body[data-phone] main[data-pwa-reserve] {
  --pp: 1.5rem;
  padding-top: max(var(--pp), env(safe-area-inset-top));
  padding-right: max(var(--pp), env(safe-area-inset-right));
  padding-bottom: max(var(--pp), env(safe-area-inset-bottom));
  padding-left: max(var(--pp), env(safe-area-inset-left));
}
@media (max-height: 480px) { body[data-phone] main[data-pwa-reserve] { --pp: 0.75rem; } }
/* Account pages (layouts/application): the body is a fixed-height flex box, so padding it shrinks the
   app area and every scroll container inside follows. */
body[data-phone][data-pwa-reserve] {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}
/* While the install card is up it owns the bottom edge (its own padding already includes the inset):
   the page ends above it, so the card never covers a field or the primary button. */
html[data-pwa-install] body[data-phone][data-pwa-reserve] { padding-bottom: var(--pwa-install-h, 0px); }
html[data-pwa-install] body[data-phone] main[data-pwa-reserve] { padding-bottom: calc(var(--pwa-install-h, 0px) + 0.75rem); }

/* ---- fields and buttons ---------------------------------------------------------------- */
body[data-phone] :is(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"]), select, textarea) {
  font-size: 16px; /* under 16px iOS zooms the page on focus */
}
body[data-phone] :is(.hud-btn, .med-btn, input[type="submit"]) { min-height: 3rem; font-size: 1rem; }
body[data-phone] .hud-btn--sm { min-height: 3rem; font-size: 0.9375rem; }
body[data-phone] input[type="submit"] { padding-block: 0.5rem; }

/* ---- the portal card (password reset, confirmations, magic link) in landscape ---------------
   A squat screen has no room for icon + title stacked over the form: the heading sits beside it. */
@media (max-height: 480px) {
  body[data-phone] [data-testid="portal-card"] {
    min-height: 0; padding-block: 0;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); column-gap: 1.5rem; align-items: center;
  }
  body[data-phone] [data-testid="portal-card"] > .portal-card__stepper { grid-column: 1 / -1; margin-bottom: 0.5rem; }
  body[data-phone] [data-testid="portal-card"] > .portal-card__head { grid-column: 1; margin: 0; }
  body[data-phone] [data-testid="portal-card"] > .portal-card__body { grid-column: 2; margin: 0; max-width: none; width: 100%; }
  body[data-phone] [data-testid="portal-card"] .portal-card__body > * { padding: 1rem 1.25rem; }
}

/* ---- the install card ---------------------------------------------------------------------
   Page surface: a compact bronze card on the bottom edge. pwa_install_controller.js publishes its
   height as --pwa-install-h and the rules above reserve it. Portrait: mark + text on top, the two
   buttons side by side under them. Landscape phone: one row. */
.pwa-install { z-index: 40; }
.pwa-install[hidden], .pwa-install [hidden] { display: none !important; }
.pwa-install--page {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; pointer-events: none;
  padding: 0 max(0.75rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}
.pwa-install__card {
  pointer-events: auto; width: 100%; max-width: 40rem; min-width: 0;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.5rem 0.75rem; align-items: center;
  padding: 0.75rem; color: var(--hud-text);
  background: var(--hud-bg); border: 1px solid var(--hud-frame); border-radius: 0.5rem;
  box-shadow: 0 -0.5rem 1.5rem color-mix(in srgb, var(--hud-bg-2) 70%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--hud-title) 6%, transparent);
}
.pwa-install__mark { width: 2.75rem; height: 2.75rem; border-radius: 0.6rem; border: 1px solid var(--hud-frame); background: var(--hud-bg-2); object-fit: cover; }
.pwa-install__text { min-width: 0; }
.pwa-install__title { margin: 0; font-size: 1rem; font-weight: 600; line-height: 1.3; color: var(--hud-title); }
.pwa-install__title[role="button"] { cursor: pointer; border-radius: 0.25rem; }
.pwa-install__title[role="button"]:focus-visible { outline: 2px solid var(--hud-ring); outline-offset: 2px; }
.pwa-install__body { margin: 0.125rem 0 0; font-size: 1rem; line-height: 1.35; color: var(--hud-text-dim); }
.pwa-install__steps { margin: 0.25rem 0 0; padding: 0; list-style: none; display: grid; gap: 0.2rem; font-size: 1rem; line-height: 1.3; color: var(--hud-text); }
.pwa-install__steps li { display: flex; align-items: center; gap: 0.5rem; }
.pwa-install__step-icon {
  flex: none; display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem;
  border: 1px solid var(--hud-frame); border-radius: 0.375rem; background: var(--hud-bg-2); color: var(--hud-title);
}
.pwa-install__actions { grid-column: 1 / -1; display: flex; gap: 0.5rem; }
.pwa-install__actions .pwa-install__btn { flex: 1 1 0; justify-content: center; white-space: nowrap; }
/* iOS (Share steps / open in Safari): nothing to tap but Not now, so it sits on the title row at the end —
   the steps take the full width under it and the card stays short enough to leave the form's button visible. */
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__card {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "mark title later" "body body body";
}
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) :is(.pwa-install__text, .pwa-install__actions) { display: contents; }
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__mark { grid-area: mark; }
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__title { grid-area: title; }
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) :is(.pwa-install__steps, .pwa-install__body) { grid-area: body; margin: 0; }
.pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__btn { grid-area: later; flex: none; min-width: 0; padding-inline: 1rem; }
/* Landscape phone: one row — mark, text, buttons — and as slim as it can be, since the page above is
   already short: the install button needs no sentence next to it. */
@media (orientation: landscape) and (max-height: 480px) {
  .pwa-install--page .pwa-install__card { grid-template-columns: auto minmax(0, 1fr) auto; padding: 0.5rem 0.75rem; }
  .pwa-install--page .pwa-install__actions { grid-column: auto; }
  .pwa-install--page .pwa-install__actions .pwa-install__btn { flex: none; min-width: 6.5rem; }
  .pwa-install--page .pwa-install__steps { grid-auto-flow: column; justify-content: start; column-gap: 1rem; }
  .pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__card {
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "mark title later" "mark body later";
  }
  .pwa-install--page .pwa-install__mark { width: 2.5rem; height: 2.5rem; }
}
/* Short landscape (<= 400px tall: every landscape phone): the iOS card is ONE row, title + Not now. The steps
   (or the open-in-Safari sentence) fold behind the title, which turns into a toggle, and open as a second row
   when tapped; the page reserves the extra height while they are open. */
@media (orientation: landscape) and (max-height: 400px) {
  .pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__card {
    grid-template-areas: "mark title later"; padding: 0.4rem 0.75rem;
  }
  .pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) :is(.pwa-install__steps, .pwa-install__body) { display: none; }
  .pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__title {
    display: flex; align-items: center; gap: 0.5rem; min-height: 3rem;
  }
  .pwa-install--page:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__title[role="button"]::after {
    content: ""; width: 0.55rem; height: 0.55rem; border: solid var(--hud-text-dim); border-width: 2px 2px 0 0;
    transform: rotate(-45deg) translate(-0.1rem, 0.1rem); transition: transform 0.15s;
  }
  .pwa-install--page[data-expanded="true"]:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__card {
    grid-template-areas: "mark title later" "body body body";
  }
  .pwa-install--page[data-expanded="true"]:is([data-state="ios"], [data-state="ios-other"]) :is(.pwa-install__steps, .pwa-install__body) { display: grid; margin-top: 0.1rem; }
  .pwa-install--page[data-expanded="true"]:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__body { display: block; }
  .pwa-install--page[data-expanded="true"]:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__steps { grid-auto-flow: row; }
  .pwa-install--page[data-expanded="true"]:is([data-state="ios"], [data-state="ios-other"]) .pwa-install__title[role="button"]::after { transform: rotate(135deg) translate(-0.1rem, 0.1rem); }
}
/* Not much height (a small phone, or any landscape one): the sentence next to the Install button goes —
   the title and the button say it — so the card stays out of the form's way. */
@media (max-height: 740px) {
  .pwa-install--page[data-state="prompt"] .pwa-install__body { display: none; }
}
.pwa-install--page[data-keyboard="open"] { display: none; } /* the on-screen keyboard is up: pwa_install_controller.js */
@media (prefers-reduced-motion: no-preference) {
  .pwa-install--page:not([hidden]) .pwa-install__card { animation: pwa-install-rise 0.3s ease-out both; }
  @keyframes pwa-install-rise { from { opacity: 0; transform: translateY(0.75rem); } to { opacity: 1; transform: none; } }
}
