/* iPhone pass (2026-11-22). Shared by the plain and the motion versions: keep the two copies identical.
   Loaded last, so it only overrides. Covers: safe areas (notch, home bar, landscape sides), dvh instead of vh,
   44px tap targets, keyboard-aware save bar, solid enough frosted bars, short landscape screens. */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --tabh: 68px;   /* tab bar height above the home bar */
  --kb: 0px;      /* on-screen keyboard height, set by mobile.js */
}

/* 100vh on iPhone is taller than what you can see (it ignores the Safari bars) */
.app { min-height: calc(100vh - 38px); min-height: calc(100dvh - 38px); }
.side { height: 100vh; height: 100dvh; }

/* 44px minimum for everything you tap (some of these were 32 to 42) */
.seg button, .seg.small button, .btn.sm, .btn.link, .savebar .btn, details.tbl summary { min-height: 44px; }
.chip { min-height: 44px !important; }
.btn.link[data-openmsg] { min-height: 44px !important; }
.switch::before { content: ""; position: absolute; inset: -6px -4px; } /* 52x32 switch, 60x44 hit area */
.summary dd a { display: inline-block; padding: 12px 0; margin: -12px 0; }

/* The screen title gets focus after a screen change (for screen readers). A ring around a title looks broken on a phone. */
.screen h1[tabindex="-1"]:focus { outline: none; }

/* No grey flash on tap; no double-tap zoom delay */
a, button, label, summary, [role="switch"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

@media (max-width: 900px) {
  html { scroll-padding-top: 84px; scroll-padding-bottom: calc(var(--tabh) + var(--sab) + 96px); }
  .sample-strip { padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar)); padding-top: calc(8px + var(--sat)); }
  .top { padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar)); }
  main { padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar)); padding-bottom: calc(150px + var(--sab)); }

  /* Frosted bars: keep them readable even where the blur is weak or off */
  .scrolled .top { background: color-mix(in srgb, var(--bg) 90%, transparent); }
  .tabbar { background: color-mix(in srgb, var(--card) 96%, transparent);
            padding: 6px calc(4px + var(--sar)) calc(6px + var(--sab)) calc(4px + var(--sal)); }
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .scrolled .top { background: var(--bg); } .tabbar { background: var(--card); }
  }

  /* Save bar sits just above the tab bar and the home bar, never on top of them */
  .savebar { bottom: calc(var(--tabh) + var(--sab) + 12px); left: calc(12px + var(--sal)); right: calc(12px + var(--sar));
             z-index: 34; transform: translateY(calc(100% + var(--tabh) + var(--sab) + 40px)); }
  /* it slides up from behind the tab bar and, when hidden, is fully off the screen (it used to peek out under the tab bar) */
  .savebar.on { transform: none; }
  .toast { top: calc(12px + var(--sat)); }

  /* More sheet: home bar room, and it scrolls instead of running off a short screen */
  .more-sheet .sheet { padding-bottom: calc(64px + var(--sab)); max-height: calc(100dvh - 12px); overflow-y: auto; overscroll-behavior: contain; padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar)); }

  /* Keyboard open: the tab bar steps aside and the save bar rides on top of the keyboard */
  .kb-open .tabbar { transform: translateY(110%); visibility: hidden; }
  .kb-open .savebar { bottom: calc(var(--kb) + 8px); }
  .kb-open main { padding-bottom: calc(110px + var(--kb)); }
}

/* "Kept current" card: the ring and its list sit side by side only when there is room, otherwise they stack (it ran 9px off a 932px-wide sideways phone) */
.ringrow { flex-wrap: wrap !important; justify-content: center; }
.ringrow .list { flex: 1 1 220px; min-width: 0; }

/* History filter has 5 long names: two per row on a narrow phone instead of squeezed onto two lines each */
@media (max-width: 480px) {
  .seg:has([data-hist]) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg:has([data-hist]) button:last-child { grid-column: 1 / -1; }
}

/* Sideways phone (about 852x320 visible): every pixel of height counts */
@media (min-width: 901px) and (max-height: 560px) { .side { overflow-y: auto; padding-top: 12px; } }
@media (max-width: 900px) and (max-height: 500px) {
  .top { position: relative; }                 /* scrolls away instead of eating a fifth of the screen */
  .sample-strip { padding-top: 4px; padding-bottom: 4px; font-size: 14px; }
  :root { --tabh: 50px; }
  .tabbar { padding-top: 3px; }
  .tabbar a, .tabbar button { min-height: 44px; grid-auto-flow: column; align-items: center; justify-content: center; gap: 8px; padding: 0; }
  .tabbar svg { width: 22px; height: 22px; }
  /* icon and label sit side by side here, so the selected pill wraps both (the gliding pill only knows the icon) */
  .tabbar .tab-ind { display: none !important; }
  .tabbar a, .tabbar button { margin: 0 6px; border-radius: 99px; }
  .tabbar [aria-current="page"] { background: var(--fill); }
  .head { margin: 8px 0 20px; }
  .savebar { bottom: calc(var(--tabh) + var(--sab) + 6px); padding-top: 4px; padding-bottom: 4px; }
  .savebar .btn { min-height: 44px; }
  .more-sheet a, .more-sheet button.mi { padding-top: 10px; padding-bottom: 10px; }
  .more-sheet .grab { margin-bottom: 6px; }
  .more-sheet .sheet { max-width: 560px; margin-left: auto; margin-right: auto; }
  .prev-first .phone { max-width: 260px; }
}
