/* Phones and tablets (owner decision O-A13): the finished scenes S1–S7, the nav and the reduced layout on small screens. Loaded
   after scenes.css. The desktop (≥ 1280 px, the matrix of master prompt §11.1) is untouched: every rule here sits behind a media
   query below 1280 px wide or for touch (coarse pointer) screens, except what script makes for small screens (the nav's menu
   button, js/ui/navmenu.js; S6's detail buttons and their dialog, js/ui/tiers.js) and the turn-the-phone notice, which are
   display: none until a small screen asks for them.
   Breakpoints
     ≤ 1279 px              tablets and phones: narrower margins, headlines that scale with the screen, frames of the visible
                            height (svh) on small and touch screens
     ≤ 1279 px · portrait   the world above, the copy below: each frame sets its copy at the bottom of the screen and the camera's
                            lens shift (js/scenes.config.js NARROW) lifts the picture above it
     ≤ 899 px               the compact nav: brand · เมนู · สมัครทดลองใช้; the section links and the motion toggle fold into the menu
     ≤ 599 px               phones: one column, phone type sizes, no customer quotes (O-A19), S2 in two columns, S4's floors as
                            a row, S5 without the search figure (pinned), S6 as three compact rows whose details open in a glass
                            dialog (pinned, O-A19), S8 without the steps' lines (pinned), its form one row per field (the label
                            beside it), its footer one link group per row
     ≤ 599 × 760 px         short phones (a phone's real page in Safari, O-A20): S8's blocks closer, without its label
     phone landscape        (landscape, ≤ 500 px high, touch) a full-screen notice asks to turn the phone upright (O-A19)
     pointer: coarse        no pinch or double-tap zoom (O-A19; the viewport meta, touch-action, js/scroll.js); any frame scrolls
                            inside itself when its content is taller than the screen leaves it (a phone lower than the layouts
                            were fitted to, the on-screen keyboard, error lines; js/keys.js marks it and keeps the focused field
                            above the keyboard, js/scroll.js gives it the swipe), never pushing its copy up under the nav
   Phones and tablets (< 1280 px or touch) have the sky's near-black top behind the page, so the browser's own bands above and
   below the page match the scene (O-A20).
   Tokens only (var(--sm-*), --lp-* built from them), like the rest of the landing. */

/* what script makes for small screens, and the turn-the-phone notice: hidden until a breakpoint below shows them */
.lp-nav__menu, .lp-tier__more, .lp-rotate { display: none; }

/* ============ tablets and phones (< 1280 px) ================================================================================ */
@media (max-width: 1279px) {
  :root {
    --sm-container-margin: var(--sm-space-32);   /* .sm-container's hook (the library's 40 px margin is a desktop margin) */
    /* section headlines scale with the screen: title-2 on a phone … display from a large tablet up (the desktop size) */
    --lp-type-h2: clamp(var(--sm-type-size-title-2), 7.6vw, var(--sm-type-size-display));
  }
  .lp-copy__head .sm-head__title { font-size: var(--lp-type-h2); }
}

/* the pinned frames are as tall as the screen a phone or tablet actually shows (its toolbars stay: paging never scrolls natively,
   so the browser never hides them — 100vh would put the bottom of every frame under the toolbar). The world behind them covers
   the largest the screen can be (100lvh from the top, O-A19): where a toolbar is translucent or slides away, the world shows under
   it instead of the body's backdrop (js/world/world.js sizes its picture by this box). With viewport-fit=cover the page reaches
   under a notch and a home indicator: the nav and the frames' copy keep clear of them (safe-area insets, 0 elsewhere). */
@media (max-width: 1279px), (pointer: coarse) {
  /* the bands above and below the page (O-A20): in portrait iOS Safari draws no page under its status band and its bottom
     toolbar, whatever viewport-fit says, and tints them itself — the top one from theme-color (index.html), the bottom one from
     the page's background. The page behind the world is the sky's near-black top, solid (the desktop's night gradient ended in
     the ink blue, which showed as a blue band), so both bands meet the scene: its sky above, its dark ground below */
  html, .lp-canvas { background: var(--lp-night-zenith); }
  /* O-A21: Safari tints its status band and bottom toolbar itself and a page cannot draw into them, so the world melts into them:
     a soft blurred fade to the band colour along the top and bottom edges. Above the canvas, under every frame (the copy stays
     sharp); the CSS night canvas shows the same colour, so without WebGL nothing changes. */
  .lp-full body::before, .lp-full body::after {
    content: ""; position: fixed; inset-inline: 0; pointer-events: none;
    -webkit-backdrop-filter: blur(var(--sm-space-8)); backdrop-filter: blur(var(--sm-space-8));
  }
  /* stacking: the canvas (z 0) comes after main, ::before before everything, ::after after everything; the scenes are z 1–8 */
  .lp-full body::before {
    z-index: 1; inset-block-start: 0; block-size: calc(var(--sm-space-40) + env(safe-area-inset-top, 0px));
    background: linear-gradient(to bottom, var(--lp-night-zenith), transparent);
    -webkit-mask-image: linear-gradient(to bottom, var(--lp-night-zenith) 30%, transparent); mask-image: linear-gradient(to bottom, var(--lp-night-zenith) 30%, transparent);
  }
  .lp-full body::after {
    z-index: 0; inset-block-end: 0; block-size: calc(var(--sm-space-64) + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, var(--lp-night-zenith), transparent);
    -webkit-mask-image: linear-gradient(to top, var(--lp-night-zenith) 30%, transparent); mask-image: linear-gradient(to top, var(--lp-night-zenith) 30%, transparent);
  }
  .lp-full .lp-scene { block-size: calc(var(--lp-s) + 100svh); }
  .lp-full .lp-scene + .lp-scene { margin-block-start: calc(-1 * (100svh + var(--lp-t))); }
  .lp-full .lp-frame { block-size: 100svh; }
  .lp-world { inset: 0 0 auto; block-size: 100lvh; }
  .lp-navbar { margin-block-start: env(safe-area-inset-top, 0px); }
  .lp-frame {
    padding-block: calc(var(--lp-safe-top) + env(safe-area-inset-top, 0px)) calc(var(--lp-safe-bottom) + env(safe-area-inset-bottom, 0px));
  }
}

/* ============ compact nav (< 900 px) ======================================================================================== */
@media (max-width: 899px) {
  .lp-nav[data-menu] { flex-wrap: wrap; row-gap: var(--sm-space-2); }
  .lp-nav[data-menu] .lp-nav__menu { display: inline-flex; }
  .lp-nav[data-menu] .lp-progress { display: none; }
  .lp-nav[data-menu="closed"] > :is(.sm-fnav__link[data-goto]:not(.lp-nav__brand, .lp-nav__cta), [data-motion-toggle], .lp-nav__login) { display: none; }
  .lp-nav__menu[aria-expanded="true"] { background-color: var(--sm-glass-selected-fill); box-shadow: inset 0 0 0 var(--sm-border-width) var(--sm-glass-selected-edge); }
  /* open: the pill becomes a panel; one item per row under the bar, the call to action last */
  .lp-nav[data-menu="open"] { border-radius: var(--sm-radius-20); padding-block-end: var(--sm-space-12); }
  .lp-nav[data-menu="open"] > :is(.sm-fnav__link[data-goto]:not(.lp-nav__brand), [data-motion-toggle], .lp-nav__login) { flex: 1 1 100%; justify-content: flex-start; }
  .lp-nav[data-menu="open"] .lp-nav__lbl { display: inline; margin-inline-start: var(--sm-space-8); }
  .lp-nav[data-menu="open"] > [data-motion-toggle] { margin-block-start: var(--sm-space-8); }
  .lp-nav[data-menu="open"] > .lp-nav__cta { justify-content: center; margin-block-start: var(--sm-space-8); }
}

/* ============ portrait: the world above, the copy below ===================================================================== */
@media (max-width: 1279px) and (orientation: portrait) {
  :root {
    /* the hero headline: title-1 on a phone … the desktop's 1280 size on a tablet */
    --lp-type-hero: clamp(var(--sm-type-size-title-1), 10.4vw, calc(var(--sm-type-size-display) * 1.3));
  }
  .lp-full .lp-frame { align-content: end; }
  /* every block takes the full measure, in reading order (the desktop places some side by side in rows of their own) */
  .lp-copy--hero, .lp-copy--problems, .lp-problems__foot,
  .lp-layout--pos .lp-copy--side, .lp-layout--backoffice .lp-copy--side, .lp-layout--ui .lp-copy--side,
  .lp-aside--pos, .lp-aside--erp, .lp-aside--search,
  .lp-layout--faq > .sm-split > * { grid-column: 1 / -1; grid-row: auto; }
  /* S5, S6: the long headlines a step under the others, as on the desktop */
  .lp-layout--ui .lp-copy__head .sm-head__title,
  .lp-copy--pricing .lp-copy__head .sm-head__title { font-size: calc(var(--lp-type-h2) * 0.86); }

  /* S3: the figure and the quote side by side under the points (as on the desktop, now across the screen) */
  .lp-aside--pos { grid-template-columns: auto minmax(0, 1fr); }
  /* S4: the floors as one row of four under the head (the current one marked on top, like the tiers), then the floor's
     module and the quote side by side */
  .lp-floors__list { grid-template-columns: repeat(4, minmax(0, 1fr)); border-inline-start: 0; border-block-start: var(--sm-rule-weight-hairline) solid var(--lp-hair); }
  .lp-floor { flex-direction: column; align-items: flex-start; align-content: flex-start; gap: var(--sm-space-2); padding: var(--sm-space-12) var(--sm-space-8) 0 0; }
  .lp-floor[aria-current="true"]::before {
    inset-block: calc(var(--sm-rule-weight-hairline) * -1 - var(--sm-rule-bar-weight-sm) / 2) auto; inset-inline: 0 var(--sm-space-8);
    inline-size: auto; block-size: var(--sm-rule-bar-weight-sm);
  }
  .lp-aside--erp { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; column-gap: var(--sm-grid-gutter); }
  /* S5: the search under the copy, half the measure */
  .lp-aside--search { grid-column: 1 / span 8; }
  /* S6: the toggle under the head */
  .lp-pricing__side { justify-items: start; }
  /* S7: the head and the ask in one row above the questions */
  .lp-copy--faq { grid-template-columns: minmax(0, 1fr) auto; align-items: end; column-gap: var(--sm-grid-gutter); }
  .lp-ask { justify-items: end; text-align: end; }
  /* S8: the copy, the form and the footer one under the other across the screen; the three steps as one row (as S4's floors);
     the quote is the scene's one optional block (as on short desktop screens, L62): not in the pinned layout */
  .lp-copy--signup, .lp-signup, .lp-foot { grid-column: 1 / -1; grid-row: auto; }
  .lp-copy--signup { gap: var(--lp-gap); }
  .lp-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: var(--sm-grid-gutter); }
  .lp-steps__item { grid-template-columns: minmax(0, 1fr); align-content: start; row-gap: var(--sm-space-4); }
  .lp-full .lp-quote--signup { display: none; }
}

/* ============ phones (< 600 px) ============================================================================================= */
@media (max-width: 599px) {
  :root {
    --sm-container-margin: var(--sm-space-16);
    --sm-grid-gutter: var(--sm-space-16);
    --lp-safe-top: calc(var(--sm-space-8) + var(--lp-nav-h) + var(--sm-space-16));   /* nav at 8 px, 60 px tall, 16 px under it */
    --lp-safe-bottom: var(--sm-space-24);
    --lp-gap: clamp(var(--sm-space-12), 2vh, var(--sm-space-20));
    --lp-gap-sm: clamp(var(--sm-space-4), 1vh, var(--sm-space-12));
    --lp-gap-lg: clamp(var(--sm-space-16), 2.6vh, var(--sm-space-24));
    /* figures scale with the phone, one step under the desktop's */
    --lp-type-figure: clamp(var(--sm-type-size-title-1), 11vw, var(--sm-type-size-display));
    --lp-type-figure-lg: clamp(var(--sm-type-size-display), 15vw, calc(var(--sm-type-size-display) * 1.15));
    --lp-type-figure-sm: clamp(var(--sm-type-size-title-2), 8vw, var(--sm-type-size-title-1));
  }
  .lp-navbar { inset-block-start: var(--sm-space-8); }
  .lp-nav .sm-fnav__link { padding-inline: var(--sm-space-12); }
  .lp-copy__head .sm-head__desc, .lp-copy--hero .sm-hero__lede { font-size: var(--sm-type-size-body); }
  .lp-copy__head { gap: var(--sm-space-8); }

  /* S1: the actions and the facts close together, the three proof figures in one row */
  .lp-copy--hero .sm-hero__actions { flex-wrap: wrap; gap: var(--sm-space-12); }
  .lp-proof { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sm-space-16); }

  /* S2: the four problems two by two */
  .lp-problem { grid-column: span 6; gap: var(--sm-space-4); }
  .lp-problem .sm-head__title { font-size: var(--sm-type-size-body); }
  .lp-bridge { font-size: var(--sm-type-size-title-3); }

  /* no customer quotes on a phone, in either layout (O-A19: "ทุกหน้าในมือถือที่แสดงรีวิวจากลูกค้า ให้ตัดรีวิวออกเลย"; S3, S4, S8;
     S1's proof figures are not quotes); tablets keep theirs */
  .lp-quote, .lp-review { display: none; }

  /* S4: one column; the four floors stay one row (the names smaller) */
  .lp-floor__name { font-size: var(--sm-type-size-label); }
  .lp-aside--erp { grid-template-columns: minmax(0, 1fr); }

  /* S5: the three figures in one row; the search figure is an illustration the figures already tell: not on a phone's one screen
     (the reduced layout, which has room, keeps it) */
  .lp-kstats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sm-space-16); }
  .lp-full .lp-aside--search { display: none; }

  /* S6 in the pinned layout (O-A19): the three tiers as compact rows — name, the price of the billing chosen, "ดูรายละเอียด" —
     under their hairlines; the lede, the inclusions and the tier's button open in a glass dialog (js/ui/tiers.js). The reduced
     layout, which has room, keeps the full columns */
  .lp-tier { grid-column: 1 / -1; }
  .lp-full .lp-tiers { row-gap: var(--sm-space-12); }
  .lp-full .lp-tier {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--sm-space-4) var(--sm-space-16);
    padding-block-start: var(--sm-space-12);
  }
  .lp-full .lp-tier > :is(.lp-tier__lede, .lp-inc, .lp-tier__cta), .lp-full .lp-tier .lp-price__bill { display: none; }
  .lp-full .lp-tier > :is(.lp-tier__name, .lp-price) { grid-column: 1; }
  .lp-full .lp-tier__name { font-size: var(--sm-type-size-body-lg); }
  .lp-full .lp-tier .lp-price__fig { font-size: var(--sm-type-size-title-3); }
  .lp-full .lp-tier .lp-price__fig--text { font-size: var(--sm-type-size-body); line-height: var(--sm-type-lh-ui); }
  .lp-full .lp-tier__more { display: inline-flex; grid-column: 2; grid-row: 1 / span 2; }

  /* S7: the questions at body size */
  .lp-faq .sm-faq__q { font-size: var(--sm-type-size-body); padding-block: var(--sm-space-8); }
  .lp-faq .sm-faq__a { padding-block-end: var(--sm-space-12); }

  /* S8, sized to fit a 390 × 844 screen: the blocks closer; the steps by their titles, each number before its title (pinned
     layout; the reduced layout keeps their lines); the form in one column, each field and the plan choice beside its label; the
     footer one link group per row (the links of a group lined up after a label column), the wordmark's clear space kept on the
     sides and lent to the row above and below (as the library's error page and sign-in do). The steps' row: the short titles keep
     one line, the long middle one wraps */
  .lp-scene--signup { --lp-safe-top: calc(var(--sm-space-8) + var(--lp-nav-h) + var(--sm-space-12)); --lp-safe-bottom: var(--sm-space-16); }
  .lp-layout--signup { row-gap: var(--sm-space-12); }
  .lp-copy--signup { gap: var(--sm-space-8); }
  .lp-signup { gap: var(--sm-space-4); }
  .lp-steps { grid-template-columns: max-content minmax(0, 1fr) max-content; column-gap: var(--sm-space-12); }
  .lp-steps__item { grid-template-columns: auto minmax(0, 1fr); column-gap: var(--sm-space-8); }
  .lp-steps__title { font-size: var(--sm-type-size-label); }
  .lp-full .lp-steps__desc { display: none; }
  .lp-signup { padding: var(--sm-space-12) var(--sm-space-16); }
  /* the form in two columns shared by every row (subgrid): each label beside its field, as the plan choice beside its label, the
     fields lined up after the longest label (one row per field instead of two: S8 fits a phone's real page height in Safari,
     e.g. 393 × 709, O-A20); an error line under its field; the button and the consent line across */
  .lp-form { grid-template-columns: max-content minmax(0, 1fr); column-gap: var(--sm-space-12); }
  .lp-form > *, .lp-form__row > .sm-field { grid-column: 1 / -1; }
  .lp-form .sm-field, .lp-form__row, .lp-form__plan { display: grid; grid-template-columns: subgrid; align-items: center; }
  .lp-form .sm-field { row-gap: var(--sm-space-2); }
  .lp-form .sm-field__error { grid-column: 2; }
  .lp-form__row { gap: var(--lp-gap-sm) var(--sm-space-12); }
  .lp-form__seg { min-inline-size: 0; }
  .lp-form__seg .sm-segmented__opt { flex: 1 1 auto; padding-inline: var(--sm-space-4); }
  .lp-consent { line-height: var(--sm-type-lh-ui); }
  .lp-foot { display: grid; justify-content: stretch; gap: var(--sm-space-4); padding-block-start: var(--sm-space-8); }
  .lp-foot__mark { --sm-wordmark-size: var(--sm-type-size-body); margin-block: calc(var(--sm-wordmark-cap) * -1); }
  .lp-foot__nav { display: grid; gap: 0; }
  .lp-foot__label { min-inline-size: var(--sm-space-64); }
  .lp-foot__group a { min-block-size: var(--sm-space-24); }
}

/* ============ short phones (< 600 px wide, ≤ 760 px high) ==================================================================== */
/* A phone's real page in Safari is much lower than its screen (O-A20: 393 × 709 on the owner's iPhone, the status band and the
   bottom toolbar outside the page). S8 is the one scene that does not fit there: its blocks closer, its headline one step down,
   and its label ("เริ่มใช้งาน", the one line the headline already says) left out. Lower still (375 × 548, an iPhone SE) the frames
   that do not fit scroll inside themselves (below) instead of losing more */
@media (max-width: 599px) and (max-height: 760px) {
  .lp-scene--signup { --lp-safe-top: calc(var(--sm-space-8) + var(--lp-nav-h) + var(--sm-space-8)); --lp-safe-bottom: var(--sm-space-12); }
  .lp-scene--signup .lp-copy__head .sm-head__label { display: none; }
  .lp-scene--signup .lp-copy__head .sm-head__title { font-size: var(--sm-type-size-title-2); }
  .lp-layout--signup { row-gap: var(--sm-space-8); }
  .lp-form, .lp-form__row { row-gap: var(--sm-space-4); }
}

/* ============ touch screens: frames that scroll inside themselves =========================================================== */
/* Every frame (data-lp-scroll) may be taller than the room its screen leaves it: a phone shorter than the layouts were fitted to
   (a 375 × 548 iPhone SE in Safari), the error lines of the form, the on-screen keyboard, which covers the lower part of the screen
   without resizing the page. Paging never scrolls the page on touch, so such a frame scrolls itself: js/keys.js marks it
   [data-lp-overflow] (measured from layout boxes, never the copy's motion), a swipe it can follow scrolls it (js/scroll.js), a key
   reads it to its end before it pages, and while a field has focus js/keys.js adds the keyboard's height (--lp-kb) to the bottom
   padding and scrolls the field into the part left visible. A frame whose copy fits stays as it was (clipped, nothing scrolls:
   check-fit r2).
   The copy never goes up under the nav: the frame's one row fills it (1fr: at least as tall as the copy) and the copy sits at its
   end (portrait) or in its middle, so copy taller than the room overflows at the bottom, reachable by scrolling, never at the top
   (the "unsafe" end alignment of the frames had pushed it up under the nav). While a frame scrolls, its copy fades out above the
   nav's lower edge (mask), so a line scrolled up is never read through the glass. */
@media (pointer: coarse) {
  /* zoom locked on touch screens (O-A19): a finger may only pan up and down (no pinch, no double-tap zoom), so the reduced layout
     still scrolls and the pinned layout's swipes still arrive */
  html { touch-action: pan-y; }
  .lp-full .lp-frame[data-lp-scroll] {
    --lp-nav-edge: calc(env(safe-area-inset-top, 0px) + var(--sm-space-16) + var(--lp-nav-h));   /* the nav's lower edge */
    grid-template-rows: 1fr; align-content: stretch;
    padding-block-end: calc(var(--lp-safe-bottom) + env(safe-area-inset-bottom, 0px) + var(--lp-kb, 0px));
  }
  .lp-full .lp-frame[data-lp-scroll] > .lp-layout { align-self: center; }
  /* the active frame takes the finger when it scrolls (the frames are otherwise see-through to the pointer, landing.css) */
  .lp-full .lp-scene[data-active] .lp-frame[data-lp-scroll][data-lp-overflow] { pointer-events: auto; }
  .lp-full .lp-frame[data-lp-scroll][data-lp-overflow] {
    overflow: hidden auto; overscroll-behavior: contain;
    -webkit-mask-image: linear-gradient(transparent var(--lp-nav-edge), black calc(var(--lp-nav-edge) + var(--sm-space-8)));
    mask-image: linear-gradient(transparent var(--lp-nav-edge), black calc(var(--lp-nav-edge) + var(--sm-space-8)));
  }
}
@media (pointer: coarse) and (max-width: 1279px) and (orientation: portrait) {
  .lp-full .lp-frame[data-lp-scroll] > .lp-layout { align-self: end; }
}
@media (pointer: coarse) and (max-width: 599px) {
  .lp-full .lp-frame[data-lp-scroll] { --lp-nav-edge: calc(env(safe-area-inset-top, 0px) + var(--sm-space-8) + var(--lp-nav-h)); }
}

/* ============ S6's detail dialog on phones (O-A19, js/ui/tiers.js) ========================================================== */
/* The library's modal (native <dialog>, showModal): with data-glass="on" its panel is blurred glass and its text ink, so the
   copied price, VAT note and inclusions drop their on-canvas colours. Neither the panel nor the dialog hands a scroll on to the
   page behind (paging also stands still while it is open, js/scroll.js · js/keys.js). */
.lp-tierdlg, .lp-tierdlg .sm-modal__panel, .lp-tierdlg .sm-modal__body { overscroll-behavior: contain; }
.lp-tierdlg :is(.lp-price__line, .lp-price__unit, .lp-price__bill, .lp-vat, .lp-inc > li, .lp-inc .sm-icon) { color: inherit; }
.lp-tierdlg .sm-modal__title { display: flex; align-items: center; gap: var(--sm-space-8); }
.lp-tierdlg .lp-price__fig { font-size: var(--sm-type-size-title-1); }
.lp-tierdlg .lp-tier__cta { flex: 1 1 auto; }

/* ============ phones held sideways (O-A19) ================================================================================== */
/* A page cannot lock the orientation; a phone on its side (too low for any scene) gets a full-screen glass notice over the page.
   Tablets in landscape are higher than 500 px and keep working. */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .lp-rotate {
    display: grid; position: fixed; inset: 0; z-index: var(--sm-z-toast); place-content: center; justify-items: center;
    gap: var(--sm-space-12); padding: var(--sm-space-24); border-radius: 0; text-align: center;
    font-size: var(--sm-type-size-body-lg); font-weight: var(--sm-type-weight-medium); color: var(--sm-color-text-default);
  }
  .lp-rotate p { margin: 0; }
}
