/* =====================================================================
   Ponto — phone layer (≤ 640 px). The phone is the primary target:
   thumb-reach controls, bottom composer above the keyboard, safe areas,
   stack navigation with swipe-back, 360 px minimum width.
   ===================================================================== */
@media (max-width: 640px) {
  :root { --fs: 15.5px; --rail: 0px; --list: 100%; --info: 100%; }

  body { font-size: var(--fs); }

  /* ── landing ── */
  .l-nav { gap: 8px; padding-inline: 14px; }
  .l-links { display: none; }
  .l-open { display: none; }
  .brand-word { font-size: 17px; }
  .l-hero { grid-template-columns: 1fr; gap: 28px; padding: 26px 16px 20px; }
  .l-copy h1 { font-size: clamp(30px, 8.6vw, 40px); }
  .lead { font-size: 14.6px; }
  .l-cta { gap: 10px; }
  .l-cta .btn { flex: 1 1 100%; }
  .trust { gap: 10px 14px; }
  .trust li { font-size: 12px; }
  .l-demo { order: -1; }
  .phone { width: min(280px, 78vw); transform: none; animation: none; border-radius: 34px; }
  .l-strip { grid-template-columns: 1fr 1fr; margin-inline: 16px; }
  .l-strip b { font-size: 19px; }
  .l-features { grid-template-columns: 1fr; gap: 12px; margin-block: 32px; }
  .fcard { padding: 18px; }
  .l-faq { margin-bottom: 32px; }

  /* ── auth ── */
  .auth { align-items: flex-start; padding-top: calc(16px + var(--sat)); }
  .auth-card { padding: 26px 18px 20px; border-radius: 22px; }
  .auth-card h2 { font-size: 20px; }
  .phrase-grid { grid-template-columns: repeat(2, 1fr); }
  .row-btns { flex-direction: column-reverse; }

  /* ── app: single pane stack ── */
  .app, .app[data-info="1"] { display: block; position: relative; grid-template-columns: none; }
  .rail { display: none; }

  .pane-list, .pane-conv {
    position: absolute; inset: 0; width: 100%; height: 100%;
    border: 0; will-change: transform;
    transition: transform .3s var(--ease), opacity .3s var(--ease);
  }
  .pane-list { z-index: 2; transform: none; }
  .pane-conv { z-index: 3; background: var(--bg); transform: translateX(100%); }
  [dir="rtl"] .pane-conv { transform: translateX(-100%); }
  .app[data-view="conv"] .pane-conv { transform: none; }
  .app[data-view="conv"] .pane-list { transform: translateX(-24%); opacity: .5; }
  [dir="rtl"] .app[data-view="conv"] .pane-list { transform: translateX(24%); }
  .pane-conv::before {
    content: ""; position: absolute; inset-block: 0; inset-inline-start: -14px; width: 14px;
    background: linear-gradient(to var(--from, right), rgba(18,32,64,.16), transparent);
    pointer-events: none;
  }
  [dir="rtl"] .pane-conv::before { --from: left; }

  .only-mobile { display: inline-grid !important; }
  .conv-head .back { display: inline-grid; }
  .pane-head { padding-inline: 8px; min-height: 54px; }
  .pane-title { font-size: 20px; }
  .conn-pill span { display: none; }
  .conn-pill { padding: 6px; }
  .search-wrap { margin: 8px 10px; }
  .search-wrap .kbd { display: none; }
  .folders { padding-inline: 10px; }
  .folder-chip { padding: 7px 14px; font-size: 13px; }

  .chat-scroll { padding: 0 6px calc(84px + var(--sab)); }
  .chat-row { padding: 10px; border-radius: 18px; }
  .chat-row .av { width: 50px; height: 50px; }
  .cr-name { font-size: 15px; }
  .cr-prev { font-size: 13px; }

  /* bottom pill nav — thumb reach */
  .tabbar {
    display: flex; position: absolute; z-index: 6;
    inset-inline: 12px; bottom: calc(10px + var(--sab));
    padding: 5px; gap: 2px; border-radius: 22px;
    border: 1px solid var(--border); background: var(--overlay);
    backdrop-filter: var(--glass); -webkit-backdrop-filter: var(--glass);
    box-shadow: var(--shadow-lift);
  }
  .tab {
    position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 7px 4px 6px; border-radius: 17px; color: var(--faint);
    transition: color .2s, background-color .2s, transform .18s var(--spring);
  }
  .tab svg { width: 21px; height: 21px; }
  .tab span { font-size: 10px; font-weight: 700; }
  .tab:active { transform: scale(.93); }
  .tab.on { color: var(--accent); background: var(--dream-soft); }
  .tab .dot { inset-inline-end: 18%; top: 5px; }
  .fab { bottom: calc(80px + var(--sab)); inset-inline-end: 14px; width: 52px; height: 52px; }

  /* conversation */
  .conv-empty { display: none; }
  .conv-head { padding-inline: 6px; min-height: 56px; }
  .conv-id .av { width: 38px; height: 38px; }
  .conv-meta b { font-size: 15px; }
  .msg-scroll { padding-inline: 8px; }
  .msg-body { max-width: 86%; }
  .msg-gutter { width: 28px; }
  .msg-gutter .av { width: 28px; height: 28px; border-radius: 10px; }
  .bubble { padding: 8px 12px 6px; }
  .btext { font-size: 15px; line-height: 1.62; }
  .media-grid { max-width: min(78vw, 300px); }
  .jump { bottom: calc(104px + var(--sab) + var(--kb)); inset-inline-end: 12px; }

  /* composer sits above the keyboard, never under it */
  .composer { padding: 6px 8px calc(8px + var(--sab) + var(--kb)); }
  .comp-btn { width: 42px; height: 42px; }
  #input { font-size: 16px; min-height: 42px; padding: 11px 13px; } /* 16px stops iOS zoom */
  .send-btn { width: 46px; height: 46px; }
  .fmt-bar { display: none !important; }
  .rec-hint { font-size: 10.5px; }
  .typing { padding-inline: 12px; }

  /* swipe-to-reply affordance */
  .vrow { touch-action: pan-y; }
  .swipe-icon { inset-inline-start: -30px; }
  [dir="rtl"] .swipe-icon { inset-inline-end: -30px; }

  /* info becomes a full sheet */
  .pane-info {
    position: fixed; inset: 0; z-index: 40; border: 0;
    background: var(--deck-solid); animation: sheetin .3s var(--spring);
    padding-top: var(--sat);
  }
  .info-body { padding-bottom: calc(24px + var(--sab)); }

  /* overlays */
  .switcher { padding: 0; align-items: stretch; }
  .sw-card { width: 100%; max-height: 100dvh; border-radius: 0; border: 0; padding-top: var(--sat); }
  .sw-head { padding-top: 16px; }
  .sheet { width: 100%; max-height: 90dvh; }
  .modal-wrap { padding: 14px; align-items: flex-end; }
  .modal { width: 100%; border-radius: 24px 24px 18px 18px; margin-bottom: var(--sab); }
  .ctx-menu { min-width: 230px; max-width: calc(100vw - 24px); }
  .ctx-menu button { padding: 12px; font-size: 14.5px; }
  .ctx-rx button { width: 40px; height: 40px; font-size: 21px; }
  .toasts { bottom: calc(84px + var(--sab)); }
  .hud { font-size: 10px; bottom: calc(78px + var(--sab)); }
}

/* very small phones (360 px and below) */
@media (max-width: 380px) {
  .msg-body { max-width: 90%; }
  .cr-name { font-size: 14.4px; }
  .tab span { font-size: 9.4px; }
  .l-copy h1 { font-size: 28px; }
  .phrase-grid { grid-template-columns: 1fr 1fr; gap: 5px; }
  .phrase-grid li { font-size: 11.6px; padding: 7px; }
}

/* coarse pointers: no hover-only affordances, bigger targets */
@media (pointer: coarse) {
  .chat-row:hover, .fcard:hover, .choice:hover, .btn:hover { transform: none; }
  .icon-btn { width: 42px; height: 42px; }
  .rx-chip { padding: 4px 10px; }
  .kbd { display: none; }
}

/* landscape phone: keep the composer reachable */
@media (max-width: 900px) and (max-height: 460px) {
  .tabbar { display: none; }
  .chat-scroll { padding-bottom: 16px; }
  .fab { bottom: calc(14px + var(--sab)); }
  #input { max-height: 76px; }
}