/* Landscape layout (rel-landscape-1024, Luke Oct 24: "Sono's UI is far too condensed when the phone is turned"). LAYOUT ONLY: no colours, so it works in light and dark and
   needs no generated twin. Loaded LAST on every page (?v=landscape1024). Everything is inside an orientation + height query: portrait and desktop (height > 700px) are untouched.
   Tier 1 = short landscape (phones turned, <= 520px high: 844x390, 667x375, 932x430, 740x360, iPhone Safari with its bars).
   Tier 2 = short laptops / small tablets in landscape (521-700px high), light touches only.
   Rules: the message list / the page content is the priority; chrome is one compact row; safe-area insets keep the notch off the content. */

/* ================= tier 1: short landscape ================= */
@media (orientation: landscape) and (max-height: 520px) {
  html, body { overflow-x: clip; }
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

  /* ---------- chat: one frame, one header row ---------- */
  .app { height: 100vh; height: 100dvh; margin: 0; max-width: none; border: 0; border-radius: 0; box-shadow: none; }
  .multi-chats .app { max-width: none; }
  .app .bar, .multi-chats .cc-main .bar { min-height: 44px; padding: 4px 12px; gap: 8px; }
  .app .avatar { width: 32px; height: 32px; }
  .app .avatar svg { width: 22px; height: 22px; }
  .app .who-name { font-size: 15px; }
  .app .who-sub { display: none; }
  .app .bar-btn { min-height: 38px; }
  .app .progress { padding: 4px 16px 3px; }
  .app .progress-text { margin-top: 3px; font-size: 11.5px; }
  /* Sono | Trainer segmented control sits in the middle of the header row instead of a row of its own */
  .tr-host { position: relative; }
  .tr-tabs { position: absolute; z-index: 3; top: 0; left: 50%; transform: translateX(-50%); width: 232px; height: 44px; padding: 0; border: 0; background: none; align-items: center; pointer-events: none; }
  .tr-seg { max-width: none; pointer-events: auto; }
  .tr-tab { height: 32px; font-size: 13.5px; padding: 0 10px; }
  .tab-trainer .tr-tabs { width: 232px; }
  /* the message list gets the room */
  .app .log { padding: 8px 12px 10px; gap: 5px; }
  .cc-top { padding: 0 0 4px; }
  .cc-day { margin: 6px 0 2px; }
  .log .bubble { padding: 7px 12px; font-size: 15px; }
  .welcome { padding: 0 12px 8px; }
  .welcome-mascot { width: 36px; height: 36px; margin-bottom: 4px; }
  .app .welcome h1 { font-size: 24px; margin-bottom: 4px; }
  .cc-blank { margin: 10px auto 4px; padding: 10px 14px; }
  .tr-empty { padding: 8px 12px; gap: 4px; }
  .tr-empty-mark { width: 34px; height: 34px; font-size: 17px; }
  .tr-empty-title { font-size: 16px; margin: 0; }
  .tr-restricted { margin: 8px 16px 4px; padding: 12px 14px; }
  .tr-rs-title { font-size: 16px; }
  .tr-rs-text { margin-bottom: 4px; font-size: 14px; line-height: 1.4; }
  .tr-rs-help { margin-bottom: 8px; }
  .tr-rs-delete { padding-top: 8px; }
  /* composer: pinned, slim, always fully visible */
  .composer { padding: 4px 10px calc(4px + env(safe-area-inset-bottom)); }
  .quick { gap: 6px; padding: 0 2px 4px; max-height: 96px; overflow-y: auto; overscroll-behavior: contain; }
  .composer .qr { min-height: 40px; padding: 0 14px; font-size: 14.5px; }
  .composer .qr.provider { min-height: 44px; }
  .cc-chip, .cc-ci-quick .cc-chip { min-height: 40px; }
  .cc-scale-n { min-height: 40px; }
  .send-row { gap: 6px; }
  .composer .input { min-height: 40px; padding: 8px 14px; max-height: 96px; }
  .composer .icon-btn, .cc-attach { width: 40px; height: 40px; }
  .composer .input-hint { display: none; }
  .cc-note.cc-leftchip:not(.cc-empty) { display: none; }   /* "N replies left" lives in the chats drawer foot */
  .cc-note.cc-leftchip { margin-top: 4px; }
  .cc-cap { margin: 0 2px 5px; padding: 6px 12px; }
  .cc-attached { padding-bottom: 5px; }
  .cc-cmds { max-height: 44vh; }
  /* check-in banner (progress / lock / ready): one slim line, same content */
  .ck-lock { margin: 0 0 4px; padding: 3px 10px; gap: 10px; border-radius: 12px; }
  .ck-ico { width: 18px; height: 18px; }
  .ck-body { flex-direction: row; align-items: baseline; gap: 0 10px; overflow: hidden; }
  .ck-title { flex: none; font-size: 14px; white-space: nowrap; }
  .ck-sub { min-width: 0; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ck-btn { min-height: 38px; padding: 0 16px; }
  .ck-lock.ck-ready, .ck-lock.ck-first { flex-wrap: nowrap; }
  .ck-lock.ck-ready .ck-btn, .ck-lock.ck-first .ck-btn { width: auto; }
  .ck-err { margin-top: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* chats list: a slide-over drawer at every width (never a column that takes the screen); opened with the menu button */
  .cc-side { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(62vw, 330px); gap: 6px; padding: 8px 12px 8px calc(12px + env(safe-area-inset-left));
    transform: translateX(-104%); visibility: hidden; box-shadow: 18px 0 50px -20px rgba(0,0,0,.7); transition: transform .25s var(--ease), visibility 0s linear .25s; }
  .cc-drawer-open .cc-side { transform: none; visibility: visible; transition: transform .25s var(--ease), visibility 0s; }
  .cc-scrim { display: block; }
  .cc-side-close { display: inline-block; width: 40px; height: 40px; }
  .cc-menu { display: inline-flex; }
  .cc-new { min-height: 40px; }
  .cc-open { min-height: 48px; padding-top: 6px; padding-bottom: 6px; }
  .cc-side-foot { padding-top: 6px; gap: 4px; }
  .cc-dlg { max-height: calc(100dvh - 24px); overflow-y: auto; }
  .tr-restricted { max-width: none; }

  /* full-screen steps in the chat (Start, waitlisted, sent, sign-in): small mascot, tight spacing, wide text, the button visible */
  .screen { padding: 8px 10px 10px; gap: 8px; }
  .screen-mascot { width: 44px; height: 44px; }
  .screen h1 { font-size: clamp(26px, 8vh, 34px); }
  .screen p { max-width: 62ch; }
  .screen .lede { font-size: 15px; }
  .screen .cta { min-height: 46px; }
  .start-confirm { margin: 2px 0 6px; padding: 8px 14px 2px; }
  .start-check { padding: 4px 0; }
  .crisis-card { margin-bottom: 8px; padding: 12px 14px; }

  /* ---------- sign-in style pages (login, email sign-in, unsubscribe): compact, scrolls only if it must ---------- */
  .login-page-top, body > .top { padding-top: calc(8px + env(safe-area-inset-top)); }
  .login { padding-top: 10px; padding-bottom: 18px; justify-content: flex-start; }
  .mascot { width: 56px; height: 56px; }
  .login h1 { margin-top: 8px; font-size: clamp(28px, 9vh, 40px); }
  .lede { margin-top: 6px; font-size: 15px; }
  .providers { margin-top: 14px; gap: 10px; }
  .bubble-tail { display: none; }
  .signup { margin-top: 12px; padding-top: 8px; }
  .fine { margin-top: 14px; }
  .foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .notice { margin-top: 12px; padding: 9px 14px; }
  .email-auth h1 { font-size: clamp(26px, 9vh, 36px); }
  .email-auth .lede { max-width: 48ch; }

  /* ---------- dashboard / profile / settings / calculator: a short header, content first ---------- */
  .top .hello { grid-template-columns: auto 1fr auto; grid-template-areas: "m t r"; margin-top: 8px; row-gap: 0; column-gap: 12px; }
  .hello-mascot { width: 34px; height: 34px; }
  .hello h1 { font-size: 24px; }
  .hello-sub { margin-top: 2px; }
  .range { justify-self: end; }
  .goal-line { margin-top: 4px; }
  .tabs-wrap { margin-top: 6px; }
  .pf h1, .st h1 { font-size: 24px; }
  .res-bar { padding: 7px 16px; bottom: calc(8px + env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }

  /* ---------- the dashboard's sheets (Log a meal, edit, weigh-ins): always inside the viewport, the body scrolls, Save / Cancel stay reachable ---------- */
  .bf-sheet { margin: auto; width: min(640px, calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right))); max-width: none; max-height: calc(100dvh - 12px); max-height: calc(100svh - 12px);
    padding: 0 16px 0; border-radius: 16px; border-bottom: 1px solid var(--line-2); overscroll-behavior: contain; scroll-padding-bottom: 72px; }
  .bf-sheet .bf-grab { display: none; }
  .bf-sheet .bf-head { padding: 10px 0 8px; }
  .bf-sheet .bf-head h2 { font-size: 16px; }
  .bf-sheet .bf-head p, .bf-sheet .bf-sub { margin-top: 2px; font-size: 12.5px; line-height: 1.3; }
  .bf-sheet .log-form { background: inherit; padding-top: 0; }
  .bf-sheet .log-field { margin-top: 8px; }
  .bf-sheet .log-hint { margin-top: 3px; font-size: 12px; }
  .bf-sheet .bf-input { min-height: 40px; }
  .bf-sheet .log-kcal { margin-top: 8px; padding: 6px 12px; }
  .bf-sheet .log-kcal .lk-n { font-size: 17px; }
  .bf-sheet .bf-btn { min-height: 42px; }
  .bf-sheet .log-alt { margin-top: 8px; }
  .bf-sheet .bf-actions { position: sticky; bottom: 0; z-index: 2; flex-direction: row; justify-content: flex-end; gap: 8px; margin-top: 10px; padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); background: inherit; border-top: 1px solid var(--line); }
  .bf-sheet .bf-actions .bf-btn { min-width: 112px; }

  /* ---------- privacy / landing ---------- */
  .doc h1 { font-size: clamp(30px, 10vh, 44px); }
  .intro-nav nav { height: 3rem; }
  #hero-title { font-size: clamp(2rem, 12vh, 3.4rem); margin-top: 1rem; }
  #top .container-x { padding-top: 4.75rem; }
  #top p.intro { margin-top: 1rem; }
  /* the smallest phones turned (iPhone SE class, 667x375 / 740x360): one more notch off the chrome so the message list still gets half the screen */
  @media (max-height: 400px) {
    .app .bar, .multi-chats .cc-main .bar { min-height: 40px; padding-top: 2px; padding-bottom: 2px; }
    .tr-tabs { height: 40px; }
    .tr-tab { height: 30px; }
    .app .avatar { width: 30px; height: 30px; }
    .app .bar-btn { min-height: 34px; }
    .composer { padding-top: 3px; padding-bottom: calc(3px + env(safe-area-inset-bottom)); }
    .quick { padding-bottom: 3px; }
    .composer .qr, .cc-chip, .cc-ci-quick .cc-chip, .cc-scale-n { min-height: 36px; }
    .composer .input { min-height: 36px; padding: 6px 14px; }
    .composer .icon-btn, .cc-attach { width: 36px; height: 36px; }
    .ck-lock { padding-top: 2px; padding-bottom: 2px; margin-bottom: 3px; }
    .ck-btn { min-height: 34px; }
  }
  /* the calculator's sticky result card would cover most of a short screen: it scrolls with the page */
  .calc-card.res { position: static; }
}

/* ================= tier 2: short laptops / small tablets, landscape, 521-700px high ================= */
@media (orientation: landscape) and (min-height: 521px) and (max-height: 700px) {
  html, body { overflow-x: clip; }
  .app { margin-top: 8px; height: calc(100dvh - 16px); }
  .app .bar, .multi-chats .cc-main .bar { padding-top: 8px; padding-bottom: 8px; }
  .tr-tabs { padding-top: 6px; padding-bottom: 6px; }
  .ck-lock { padding-top: 6px; padding-bottom: 6px; margin-bottom: 6px; }
  .ck-body { flex-direction: row; align-items: baseline; gap: 0 10px; overflow: hidden; }
  .ck-title { flex: none; white-space: nowrap; }
  .ck-sub { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hello { margin-top: 12px; }
  .login { padding-top: 12px; }
}

/* Oct 24 speed: instant taps. touch-action: manipulation removes the double-tap-to-zoom wait on every control (no 300 ms delay on phones); no visual change. */
a, button, input, select, textarea, summary, label, [role="button"], [role="tab"] { touch-action: manipulation; }
