/* Phone layout of the onboarding (templates/onboarding.html) on the text chat
   page.

   Before it, the onboarding on a phone was a card that scrolled as a whole:
   on the character step Next sat at the end of a long one-per-row list, 1.7
   to 2.4 screens down (measured 2026-11-14 at 412x784, 402x714 and 360x640),
   and on the name and scenario steps the keyboard covered the buttons.

   Here it is a full-height sheet: a small header, the step scrolling in the
   middle, and Back / Next pinned to the bottom edge. The character list
   itself is untouched (the owner wants the portraits the size they are, and
   signed-in visitors have many more characters than the seven built-ins).

   Every rule is scoped to .onboarding-v2, which the overlay carries only
   where utils/onboarding_layout.py says so, and to phones (600px, as
   chat_phone.css). Plain CSS, loaded by chat.html only, so it needs no
   Tailwind build; scripts/build_dark_css.py reads it for the dark scheme.

   The overlay is positioned against <body>, not the screen: on this page the
   body is exactly the visible area (chat_phone.css, chat_viewport.js), so
   when the keyboard opens the sheet shortens with it and the pinned buttons
   sit on the keys. (A fixed box is moved late by iOS Safari.) */

@media (max-width: 600px) {
  body.chat-page > .onboarding-overlay.onboarding-v2 {
    position: absolute;
    inset: 0;
    align-items: stretch;
    justify-content: stretch;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  /* The sheet. A column: header, the active step (which scrolls), and the
     step's own button bar pinned at its bottom. The top 52px is a bar zone
     for Login (left) and the exit button (right), which are positioned
     absolutely; on the first step the welcome title sits in it too. */
  body.chat-page > .onboarding-v2 > .onboarding-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    padding: 52px 0 0;
    overflow: hidden;
    border-radius: 0;
    box-shadow: none;
    animation: none;
  }

  body.chat-page > .onboarding-v2 .onboarding-login-btn {
    top: 0;
    left: 16px;
    height: 52px;
    display: flex;
    align-items: center;
    font-size: 15px;
  }

  body.chat-page > .onboarding-v2 .onboarding-exit-btn {
    top: 8px;
    right: 12px;
    width: 36px;
    height: 36px;
  }

  /* Header: the welcome title, small, in the bar zone, and the tagline under
     it. Only on the first step; the later steps start with their own
     heading (the history view has its own header too). */
  body.chat-page > .onboarding-v2 > .onboarding-content > h2 {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    margin: -52px 0 0;
    padding: 0 68px;
    font-size: 17px;
    line-height: 1.25;
  }

  body.chat-page > .onboarding-v2 > .onboarding-content > p {
    flex: none;
    margin: 0 20px 10px;
    font-size: 14px;
    line-height: 1.4;
  }

  body.chat-page > .onboarding-v2 > .onboarding-content:not(:has(> .onboarding-step[data-step="1"].active)) > h2,
  body.chat-page > .onboarding-v2 > .onboarding-content:not(:has(> .onboarding-step[data-step="1"].active)) > p {
    display: none;
  }

  /* The active step fills what is left and is what scrolls. !important:
     onboarding.js sets an inline display on the step it shows. */
  body.chat-page > .onboarding-v2 .onboarding-step.active {
    display: flex !important;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding: 4px 16px 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* The pinned bar covers the bottom of this scroll area: anything the
       browser scrolls into view for focus (a character tile on the way Back,
       "Show more" reached with the keyboard) must stop above it. */
    scroll-padding-bottom: calc(80px + var(--chat-safe-bottom, 0px));
    animation: none;
  }

  /* The History view (signed-in visitors) takes the active step's place: it
     fills what is left and scrolls as one, its list no longer a second
     scroller half a screen tall (with the keyboard up for its search field
     that left the list's end out of reach). */
  body.chat-page > .onboarding-v2 .onboarding-history-view {
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 16px 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  body.chat-page > .onboarding-v2 .onboarding-history-list {
    max-height: none;
    overflow-y: visible;
    padding-right: 0;
  }

  /* The name and scenario steps keep their fields and buttons in a form. */
  body.chat-page > .onboarding-v2 .onboarding-step.active > form {
    display: flex;
    flex: 1 0 auto;
    flex-direction: column;
  }

  /* The pinned bar: margin-top:auto sends it to the bottom when the step is
     short; sticky keeps it there when the step scrolls under it. It spans
     the sheet (the step's side padding is taken back). */
  body.chat-page > .onboarding-v2 .onboarding-step .onboarding-buttons,
  body.chat-page > .onboarding-v2 .onboarding-step1-bar {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    flex: none;
    align-items: center;
    gap: 10px;
    margin: auto -16px 0;
    padding: 10px 16px calc(10px + var(--chat-safe-bottom, 0px));
    border-top: 1px solid #ece6f3;
    background: #ffffff;
  }

  /* The keyboard leaving: the home-indicator inset (--chat-safe-bottom,
     chat_phone.css) returns at once while the sheet glides back down over
     0.3s (chat_viewport.js); the bar's padding goes with the glide, or
     Back / Next jumped 34px up as the keys started down. */
  html.chat-kb-closing body.chat-page > .onboarding-v2 .onboarding-step .onboarding-buttons,
  html.chat-kb-closing body.chat-page > .onboarding-v2 .onboarding-step1-bar {
    transition: padding-bottom 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
  }

  /* Next takes the width; Back keeps its own. No lift on hover: under a
     finger it sticks after the tap. */
  body.chat-page > .onboarding-v2 .onboarding-step .onboarding-next-btn,
  body.chat-page > .onboarding-v2 .onboarding-step .onboarding-start-btn {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    min-height: 48px;
    margin: 0;
    transform: none;
  }

  body.chat-page > .onboarding-v2 .onboarding-step .onboarding-back-btn {
    flex: none;
    min-height: 48px;
    margin: 0;
    padding-left: 22px;
    padding-right: 22px;
    transform: none;
  }

  /* Fields use the sheet's width. 16px text already (no iOS zoom). */
  body.chat-page > .onboarding-v2 #onboarding-name,
  body.chat-page > .onboarding-v2 #onboarding-scenario {
    width: 100%;
    max-width: none;
  }

  body.chat-page > .onboarding-v2 .onboarding-step > p,
  body.chat-page > .onboarding-v2 .onboarding-step > form > p {
    margin-bottom: 12px;
  }

  /* The scenario box is five lines (~148px). With the keyboard up the room
     between the 52px bar zone and the pinned bar (~69px) is the visible
     height less ~137px (revealOnboardingField keeps 8px clear each side; the
     cap takes 140, 3px of slack): enough on a 375px iPhone SE in Safari (box
     10px clear of the bar), not on a 320px phone or a short window, where the
     box's lower lines sat under Back / Start (33px at 320x460 with a 216px
     keyboard). There it shrinks to the room and scrolls inside, never below
     52px (one line); a 320px phone in Safari shows ~200px with the keyboard
     up, a 60px box. Where it fits, the cap is larger than the box and
     nothing changes, and the 120px floor stays wherever there is room for
     it. The height is not animated (input.css transitions `all`): the cap
     lands with the fit, so the reveal and the box agree at once. */
  body.chat-page > .onboarding-v2 #onboarding-scenario {
    min-height: min(120px, max(52px, calc(var(--chat-vh, 100dvh) - 140px)));
    max-height: max(52px, calc(var(--chat-vh, 100dvh) - 140px));
    transition-property: border-color, box-shadow;
  }
}
