/* =====================================================================
   Ponto — phone-first layer. Baseline width 360px, thumb-reach first.
   Scoped to html[data-ph="1"] (set by phone.js only on ≤640px), so the
   desktop skin is never touched. Noon language: hazy sky glass, peach
   warmth, dusk dark. Motion: transform + opacity only.
   ===================================================================== */

html[data-ph="1"] {
  --ph-tap: 44px;
  --ph-vh: 100dvh;          /* visualViewport height, written by phone.js */
  --ph-vt: 0px;             /* visualViewport offsetTop (iOS keyboard) */
  --ph-composer-h: 66px;    /* measured live with ResizeObserver */
  --ph-dock-h: 52px;
  --ph-edge: 10px;
}

/* 1 ─ Shell geometry: the app is exactly the visible viewport ---------- */
html[data-ph="1"] #app {
  position: fixed;
  inset-inline: 0;
  top: 0;
  height: var(--ph-vh);
  transform: translate3d(0, var(--ph-vt), 0);
  padding-inline: var(--sal) var(--sar);
}
html[data-ph="1"] .pane-list,
html[data-ph="1"] .pane-conv { will-change: transform; }
html[data-ph="1"] .pane-head { padding-top: calc(8px + var(--sat)); min-height: 56px; }
html[data-ph="1"] .conv-head { padding-top: calc(6px + var(--sat)); min-height: 56px; }

/* header keeps identity + back; utilities move to the thumb dock */
html[data-ph="1"] #convSearch,
html[data-ph="1"] #convInfo { display: none; }
html[data-ph="1"] .conv-id { padding: 2px 4px; }
html[data-ph="1"] .conv-id .av { width: 36px; height: 36px; border-radius: 13px; }
html[data-ph="1"] .conv-meta b { font-size: 15.5px; }
html[data-ph="1"] .conv-meta i { font-size: 11.5px; }
html[data-ph="1"] .lock-chip { width: 28px; height: 28px; }

/* 2 ─ Thumb dock: chat utilities parked at the bottom, not the top ----- */
html[data-ph="1"] .ph-dock {
  position: absolute;
  inset-inline-end: var(--ph-edge);
  bottom: calc(var(--ph-composer-h) + 26px);
  z-index: 8;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--overlay);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  box-shadow: var(--shadow-lift);
  transition: opacity .22s var(--ease), transform .26s var(--spring);
}
html[data-ph="1"] .ph-dock::before {
  content: "";
  position: absolute;
  inset-inline: 12px;
  top: 0;
  height: 1px;
  border-radius: 99px;
  background-image: linear-gradient(90deg, transparent, var(--sky), var(--peri), var(--peach), transparent);
  opacity: .7;
}
html[data-ph-view="conv"] .ph-dock { display: flex; }
html[data-ph-scrolling="1"] .ph-dock,
html[data-ph-kb="1"] .ph-dock {
  opacity: 0;
  transform: translate3d(0, 12px, 0) scale(.94);
  pointer-events: none;
}
html[data-ph="1"] .ph-dock-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--ph-tap);
  height: var(--ph-tap);
  border-radius: 16px;
  color: var(--muted);
  touch-action: manipulation;
  transition: color .18s, background-color .18s, transform .16s var(--spring);
}
html[data-ph="1"] .ph-dock-btn svg { width: 21px; height: 21px; }
html[data-ph="1"] .ph-dock-btn:active { transform: scale(.9); background: var(--surface-2); color: var(--ink); }
html[data-ph="1"] .ph-dock-btn[aria-pressed="false"] { color: var(--faint); }
html[data-ph="1"] .ph-dock-btn .i-off { display: none; }
html[data-ph="1"] .ph-dock-btn[aria-pressed="false"] .i-on { display: none; }
html[data-ph="1"] .ph-dock-btn[aria-pressed="false"] .i-off { display: block; }

/* jump-to-latest mirrors to the opposite edge so nothing collides */
html[data-ph="1"] .jump {
  inset-inline-end: auto;
  inset-inline-start: var(--ph-edge);
  bottom: calc(var(--ph-composer-h) + 26px);
  width: 46px;
  height: 46px;
}

/* 3 ─ Composer: pinned to the bottom of the visible viewport ----------- */
html[data-ph="1"] .composer {
  position: relative;
  z-index: 9;
  flex: none;
  padding: 6px var(--ph-edge) calc(10px + var(--sab));
  border-top: 1px solid var(--line);
  background: var(--overlay);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}
html[data-ph="1"] .composer::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--hi), transparent);
}
html[data-ph="1"] .comp-row { gap: 5px; align-items: flex-end; }
html[data-ph="1"] .comp-btn { width: var(--ph-tap); height: var(--ph-tap); border-radius: 15px; }
html[data-ph="1"] .comp-btn svg { width: 22px; height: 22px; }
html[data-ph="1"] .send-btn { width: 48px; height: 48px; }
html[data-ph="1"] .send-btn svg { width: 21px; height: 21px; }
html[data-ph="1"] #input {
  min-height: var(--ph-tap);
  max-height: 132px;
  padding: 11px 13px;
  font-size: 16px;              /* prevents iOS focus zoom */
  line-height: 1.45;
}
html[data-ph="1"] .input-wrap { border-radius: 22px; }
html[data-ph="1"] .ctx-bar { padding: 8px 10px; border-radius: 16px; }
html[data-ph="1"] .ctx-bar .icon-btn { width: 36px; height: 36px; }
html[data-ph="1"] .attach-tray { padding: 4px 0 8px; }
html[data-ph="1"] .att-item { width: 76px; height: 76px; border-radius: 16px; }
html[data-ph="1"] .att-item .x { width: 26px; height: 26px; font-size: 14px; }
html[data-ph="1"] .rec-bar { padding: 8px 10px; border-radius: 20px; }
html[data-ph="1"] .rec-stop { width: var(--ph-tap); height: var(--ph-tap); }
html[data-ph="1"] .rec-hint { font-size: 11px; }
html[data-ph="1"] .typing { height: 18px; padding-inline: var(--ph-edge); }

/* the log clears the dock so the newest bubble is never covered */
html[data-ph="1"] .msg-scroll {
  padding-inline: var(--ph-edge);
  padding-bottom: calc(var(--ph-dock-h) + 20px);
  overscroll-behavior-y: contain;
}
html[data-ph="1"] .pin-bar,
html[data-ph="1"] .find-bar { padding: 6px var(--ph-edge); }
html[data-ph="1"] .pin-bar .icon-btn,
html[data-ph="1"] .find-bar .icon-btn { width: 38px; height: 38px; }
html[data-ph="1"] .find-bar input { font-size: 16px; }

/* 4 ─ Bubbles + swipe-to-reply (transform only) ------------------------ */
html[data-ph="1"] .vrow {
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
html[data-ph="1"] .vrow.ph-swiping { contain: layout style; }
html[data-ph="1"] .vrow.ph-swiping .bubble {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
html[data-ph="1"] .vrow.ph-swiping .msg-body,
html[data-ph="1"] .vrow.ph-swiping .msg-gutter { will-change: transform; }
html[data-ph="1"] .vrow.ph-settle .msg-body,
html[data-ph="1"] .vrow.ph-settle .msg-gutter {
  transition: transform .24s var(--spring);
}
html[data-ph="1"] .swipe-icon {
  inset-inline-start: auto !important;
  inset-inline-end: auto !important;
  top: 50%;
  width: 32px;
  height: 32px;
  opacity: 0;
  color: var(--peri);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: color .16s, background-color .16s;
}
html[data-ph="1"] .swipe-icon svg { width: 17px; height: 17px; }
html[data-ph="1"] .swipe-icon.ph-ready { color: #fff; background-image: linear-gradient(135deg, var(--blue), var(--peri)); border-color: transparent; }
[data-theme="dark"] html[data-ph="1"] .swipe-icon.ph-ready { color: #0b1430; }
html[data-ph="1"] .msg-body { max-width: 84%; }
html[data-ph="1"] .msg-gutter { width: 30px; }
html[data-ph="1"] .msg-gutter .av { width: 30px; height: 30px; border-radius: 11px; }
html[data-ph="1"] .bubble { padding: 9px 13px 7px; }
html[data-ph="1"] .btext { font-size: calc(var(--fs) + .5px); line-height: 1.62; }
html[data-ph="1"] .btext .spoiler { padding: 3px 5px; margin: -3px -2px; border-radius: 7px; }
html[data-ph="1"] .btext a { padding-block: 2px; }
html[data-ph="1"] .media-grid { max-width: min(80vw, 300px); }
html[data-ph="1"] .rx-chip { min-height: 34px; padding: 5px 11px; font-size: 13px; }
html[data-ph="1"] .rx-chip b { font-size: 11px; }
html[data-ph="1"] .voice-play { width: var(--ph-tap); height: var(--ph-tap); }
html[data-ph="1"] .voice-card { min-width: 0; gap: 9px; }
html[data-ph="1"] .voice-wave { min-width: 60px; }
html[data-ph="1"] .speed-btn { min-height: 30px; padding: 4px 10px; font-size: 11px; }
html[data-ph="1"] .file-card { min-width: 0; padding: 10px 11px; }
html[data-ph="1"] .file-card .icon-btn { width: 38px; height: 38px; }
html[data-ph="1"] .day-sep span,
html[data-ph="1"] .sys-msg span { font-size: 11.5px; }

/* 5 ─ Long-press menu lives in a bottom sheet -------------------------- */
html[data-ph="1"] #sheet[data-ph="menu"] .sheet {
  border-radius: 28px 28px 0 0;
  background: var(--deck-solid);
  padding-bottom: calc(6px + var(--sab));
  max-height: 88dvh;
}
html[data-ph="1"] #sheet[data-ph="menu"] .sheet-body { padding: 2px 12px 8px; }
html[data-ph="1"] .ph-menu { display: flex; flex-direction: column; gap: 10px; }
html[data-ph="1"] .ph-menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px 10px;
  border-bottom: 1px solid var(--line);
}
html[data-ph="1"] .ph-menu-head .t { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.35; }
html[data-ph="1"] .ph-menu-head b { font-size: 14px; font-weight: 750; }
html[data-ph="1"] .ph-menu-head i {
  font-style: normal;
  font-size: 11.5px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-ph="1"] .ph-rx {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0 4px;
}
html[data-ph="1"] .ph-rx::-webkit-scrollbar { display: none; }
html[data-ph="1"] .ph-rx button {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  font-size: 24px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: transform .16s var(--spring);
}
html[data-ph="1"] .ph-rx button:active { transform: scale(.88); }
html[data-ph="1"] .ph-rx button.more { color: var(--peri); }
html[data-ph="1"] .ph-rx button.more svg { width: 22px; height: 22px; }
html[data-ph="1"] .ph-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
html[data-ph="1"] .ph-act {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 10px 12px;
  border-radius: 17px;
  text-align: start;
  font-size: 13.6px;
  font-weight: 650;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: transform .16s var(--spring), background-color .18s;
}
html[data-ph="1"] .ph-act:active { transform: scale(.97); }
html[data-ph="1"] .ph-act svg { width: 19px; height: 19px; color: var(--peri); flex: none; }
html[data-ph="1"] .ph-act.wide { grid-column: 1 / -1; }
html[data-ph="1"] .ph-act.danger { color: var(--danger); background: rgba(214, 69, 69, .09); border-color: rgba(214, 69, 69, .26); }
html[data-ph="1"] .ph-act.danger svg { color: var(--danger); }
html[data-ph="1"] .ph-cancel {
  min-height: 50px;
  border-radius: 17px;
  font-size: 14px;
  font-weight: 750;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
}
html[data-ph="1"] .ph-pick { display: flex; flex-direction: column; gap: 2px; max-height: 62dvh; overflow-y: auto; }
html[data-ph="1"] .ph-pick .chat-row { min-height: 62px; }

/* any floating context menu becomes a thumb sheet on the phone */
html[data-ph="1"] #ctxMenu {
  left: 0 !important;
  right: 0 !important;
  top: auto !important;
  bottom: 0;
  width: auto;
  min-width: 0;
  max-width: none;
  padding: 10px 12px calc(12px + var(--sab));
  border-radius: 28px 28px 0 0;
  border-bottom: 0;
  transform: none !important;
  box-shadow: 0 0 0 100vmax var(--scrim), var(--shadow-lift);
  animation: ph-sheet-in .28s var(--spring);
  max-height: 84dvh;
  overflow-y: auto;
}
html[data-ph="1"] #ctxMenu::before {
  content: "";
  display: block;
  width: 38px;
  height: 4px;
  margin: 2px auto 8px;
  border-radius: 99px;
  background: var(--border-strong);
}
html[data-ph="1"] #ctxMenu button { min-height: 52px; padding: 13px 12px; font-size: 14.5px; border-radius: 16px; }
html[data-ph="1"] #ctxMenu button svg { width: 20px; height: 20px; }
html[data-ph="1"] #ctxMenu .ctx-rx { gap: 4px; padding: 2px 0 10px; }
html[data-ph="1"] #ctxMenu .ctx-rx button { width: 48px; height: 48px; min-height: 48px; font-size: 23px; }
@keyframes ph-sheet-in { from { transform: translate3d(0, 100%, 0); } }

/* 6 ─ List: everything the thumb needs sits at the bottom -------------- */
html[data-ph="1"] .chat-scroll { padding: 0 6px calc(92px + var(--sab)); }
html[data-ph="1"] .chat-row { min-height: 68px; padding: 10px; border-radius: 19px; }
html[data-ph="1"] .chat-row .av { width: 50px; height: 50px; }
html[data-ph="1"] .search-wrap { margin: 8px var(--ph-edge); padding: 10px 13px; }
html[data-ph="1"] .search-wrap input { font-size: 16px; }
html[data-ph="1"] .folders { padding-inline: var(--ph-edge); gap: 6px; }
html[data-ph="1"] .folder-chip { min-height: 38px; padding: 8px 14px; font-size: 13px; }
html[data-ph="1"] .tabbar {
  inset-inline: var(--ph-edge);
  bottom: calc(8px + var(--sab));
  padding: 5px;
  border-radius: 24px;
}
html[data-ph="1"] .tabbar::before {
  content: "";
  position: absolute;
  inset-inline: 16px;
  top: 0;
  height: 1px;
  border-radius: 99px;
  background-image: linear-gradient(90deg, transparent, var(--sky), var(--peri), var(--peach), transparent);
  opacity: .65;
}
html[data-ph="1"] .tab { min-height: 50px; padding: 8px 4px 6px; border-radius: 19px; }
html[data-ph="1"] .tab svg { width: 22px; height: 22px; }
html[data-ph="1"] .tab span { font-size: 10.5px; }
html[data-ph="1"] .fab {
  width: 56px;
  height: 56px;
  border-radius: 20px;
  inset-inline-end: var(--ph-edge);
  bottom: calc(78px + var(--sab));
}
html[data-ph="1"] .fab svg { width: 24px; height: 24px; }

/* 7 ─ Overlays -------------------------------------------------------- */
html[data-ph="1"] .icon-btn { width: var(--ph-tap); height: var(--ph-tap); border-radius: 15px; }
html[data-ph="1"] .icon-btn svg { width: 21px; height: 21px; }
html[data-ph="1"] .icon-btn.sm { width: 38px; height: 38px; }
html[data-ph="1"] .icon-btn.sm svg { width: 17px; height: 17px; }
html[data-ph="1"] .btn { min-height: var(--ph-tap); }
html[data-ph="1"] .switch { width: 50px; height: 30px; }
html[data-ph="1"] .switch::after { width: 24px; height: 24px; }
html[data-ph="1"] .switch[aria-checked="true"]::after { transform: translateX(20px); }
html[dir="rtl"][data-ph="1"] .switch[aria-checked="true"]::after { transform: translateX(-20px); }
html[data-ph="1"] .irow,
html[data-ph="1"] .member-row { min-height: 56px; }
html[data-ph="1"] .seg button { min-height: 40px; }
html[data-ph="1"] .field input,
html[data-ph="1"] .field textarea { font-size: 16px; }
html[data-ph="1"] .sw-head input { font-size: 16px; }
html[data-ph="1"] .sw-item { min-height: 58px; }
html[data-ph="1"] .sheet { padding-bottom: calc(4px + var(--sab)); }
html[data-ph="1"] .sheet-body { padding-inline: 14px; }
html[data-ph="1"] .modal { margin-bottom: calc(6px + var(--sab)); }
html[data-ph="1"] .modal .row-btns { flex-direction: column-reverse; }
html[data-ph="1"] .modal .row-btns .btn { width: 100%; }
html[data-ph="1"] .toasts { bottom: calc(96px + var(--sab)); padding-inline: 12px; }
html[data-ph-view="conv"][data-ph="1"] .toasts { bottom: calc(var(--ph-composer-h) + 92px); }
html[data-ph="1"] .toast { max-width: 100%; }
html[data-ph="1"] .hud {
  inset-inline-start: 8px;
  top: calc(62px + var(--sat));
  bottom: auto;
  font-size: 9.5px;
  opacity: .9;
}
html[data-ph="1"] .pane-info { padding-top: var(--sat); }
html[data-ph="1"] .info-body { padding-bottom: calc(28px + var(--sab)); }
html[data-ph="1"] .auth-card { padding-bottom: calc(22px + var(--sab)); }
html[data-ph="1"] .phrase-grid li { min-height: 40px; }

/* 8 ─ 360px baseline refinements -------------------------------------- */
@media (max-width: 380px) {
  html[data-ph="1"] { --ph-edge: 8px; }
  html[data-ph="1"] .comp-row { gap: 4px; }
  html[data-ph="1"] .comp-btn { width: 42px; height: 42px; }
  html[data-ph="1"] .send-btn { width: 46px; height: 46px; }
  html[data-ph="1"] .msg-body { max-width: 88%; }
  html[data-ph="1"] .msg-gutter { width: 26px; }
  html[data-ph="1"] .msg-gutter .av { width: 26px; height: 26px; }
  html[data-ph="1"] .ph-acts { grid-template-columns: 1fr; }
  html[data-ph="1"] .ph-act { min-height: 50px; }
  html[data-ph="1"] .tab span { font-size: 9.6px; }
  html[data-ph="1"] .conv-meta b { font-size: 15px; }
  html[data-ph="1"] .media-grid { max-width: 82vw; }
  html[data-ph="1"] .ph-dock { bottom: calc(var(--ph-composer-h) + 22px); }
}

/* 9 ─ Landscape phone: give the log every pixel ----------------------- */
@media (max-height: 460px) {
  html[data-ph="1"] .tabbar { display: none; }
  html[data-ph="1"] .chat-scroll { padding-bottom: calc(16px + var(--sab)); }
  html[data-ph="1"] .fab { bottom: calc(12px + var(--sab)); }
  html[data-ph="1"] .ph-dock { display: none !important; }
  html[data-ph="1"] #input { max-height: 72px; }
  html[data-ph="1"] .msg-scroll { padding-bottom: 18px; }
  html[data-ph="1"] .jump { bottom: calc(var(--ph-composer-h) + 12px); }
}

/* 10 ─ Reduced motion ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html[data-ph="1"] .ph-dock,
  html[data-ph="1"] .vrow.ph-settle .msg-body,
  html[data-ph="1"] .vrow.ph-settle .msg-gutter,
  html[data-ph="1"] .swipe-icon { transition: none; }
  html[data-ph="1"] #ctxMenu { animation: none; }
}