/* Anticode on a phone, as an app of its own: the tab bar, Home, Create, Agents and More (public/phone-app.js).
   Every rule is inside the 820px query and keyed to body.ph, which only phone-app.js sets, so a desktop is unchanged
   (test/phone.test.mjs checks both). Loaded right before phone.css, which stays the last stylesheet.

   Tokens, from calm.css's dark set: page #151515 (--c-main), card #222222 (--c-card), raised #2e2e2e (--c-sel),
   text #f7f7f7 (16.9:1 on the page), secondary #9f9f9f (7.1:1 on the page, 6.0:1 on a card). Type is Plus Jakarta
   Sans throughout: 28/700 page titles, 17/600 row names, 15 secondary lines, 13/600 section names, 11/600 tab
   labels (the smallest text, at Apple's 11pt floor). No outlines: cards are set apart by their fill. */
@media (max-width: 820px) {
  body.ph { --ph-tabs: calc(64px + max(8px, env(safe-area-inset-bottom, 0px))); }

  /* ---------- the tab bar: floats over the page's foot, clear of the home indicator ---------- */
  body.ph .ph-tabs { position: fixed; z-index: 30; left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(8px, env(safe-area-inset-bottom, 0px)); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 60px; padding: 4px;
    border-radius: 30px; background: rgba(30, 30, 30, 0.86); -webkit-backdrop-filter: blur(24px) saturate(1.4); backdrop-filter: blur(24px) saturate(1.4); }
  body.ph .ph-tabs a { display: grid; place-items: center; align-content: center; gap: 3px; min-width: 0; border-radius: 26px; color: var(--muted, #9f9f9f);
    font: 600 11px/1.1 var(--font); letter-spacing: 0.01em; text-decoration: none; -webkit-tap-highlight-color: transparent; transition: background-color 160ms ease, color 160ms ease; }
  body.ph .ph-tabs a .ic { width: 22px; height: 22px; stroke-width: 1.8; }
  body.ph .ph-tabs a[aria-current="page"] { color: var(--text, #f7f7f7); background: var(--c-sel, #2e2e2e); }
  body.ph .ph-tabs a[aria-current="page"] .ic { stroke-width: 2.2; }
  body.ph .ph-tabs a:focus-visible { outline: 2px solid var(--text, #f7f7f7); outline-offset: -2px; }
  /* the keyboard is up: the bar would sit on it, so it steps aside until the keyboard goes */
  body.ph.ph-kb .ph-tabs { display: none; }
  /* a dialog or the drawer covers the page: the bar goes with it */
  body.ph.is-drawer .ph-tabs { display: none; }

  /* the page ends above the bar, so nothing is ever under it */
  body.ph .panel > .panel-scroll { padding-bottom: var(--ph-tabs); scroll-padding-bottom: var(--ph-tabs); }
  body.ph.ph-kb .panel > .panel-scroll { padding-bottom: 0; }
  body.ph .view-home { padding-bottom: 24px; }

  /* the top bar: Search on the right; the sidebar's button gives way (its rows are all in More) */
  body.ph .mob-menu { display: none; }
  body.ph #main > .ph-search { display: grid; place-items: center; position: absolute; left: auto; z-index: 5; right: max(6px, env(safe-area-inset-right, 0px)); top: calc(env(safe-area-inset-top, 0px) + 4px);
    width: 44px; height: 44px; border-radius: 50%; color: var(--text, #f7f7f7); }
  body.ph .ph-search .ic { width: 20px; height: 20px; }

  /* ---------- shared pieces ---------- */
  body.ph .ph-title { margin: 4px 0 16px; font: 700 28px/1.15 var(--font); letter-spacing: -0.02em; color: var(--text, #f7f7f7); }
  body.ph .ph-lead { margin: -8px 0 20px; color: var(--muted, #9f9f9f); font-size: 15px; line-height: 1.45; }
  body.ph .ph-sec { margin-top: 28px; }
  body.ph .ph-sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 4px 8px; }
  body.ph .ph-sec-head h2, body.ph .ph-group { margin: 0; font: 600 13px/1.3 var(--font); color: var(--muted, #9f9f9f); }
  body.ph .ph-group { margin: 0 4px 8px; }
  body.ph .ph-sec-head a { display: inline-flex; align-items: center; min-height: 44px; margin: -12px 0; padding: 0 4px; color: var(--text, #f7f7f7); font: 600 15px/1 var(--font); text-decoration: none; }
  body.ph .ph-list { list-style: none; margin: 0; padding: 4px; border-radius: 18px; background: var(--c-card, #222222); }
  body.ph .ph-list > li + li { margin-top: 2px; }
  body.ph .ph-empty { padding: 14px 12px; color: var(--muted, #9f9f9f); font-size: 15px; line-height: 1.45; list-style: none; }
  body.ph :is(.ph-row, .ph-proj) { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 12px; border: 0; border-radius: 14px;
    background: transparent; color: var(--text, #f7f7f7); font: 500 16px/1.35 var(--font); text-align: left; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  body.ph :is(.ph-row, .ph-proj):active { background: var(--c-sel, #2e2e2e); }
  body.ph :is(.ph-row, .ph-proj):focus-visible { outline: 2px solid var(--text, #f7f7f7); outline-offset: -2px; }
  body.ph .ph-row > .ic:first-child { flex: none; width: 20px; height: 20px; color: var(--muted, #9f9f9f); }
  body.ph .ph-row > span, body.ph .ph-proj > .ph-proj-txt { flex: 1 1 auto; min-width: 0; }
  body.ph .ph-row small { display: block; margin-top: 2px; color: var(--muted, #9f9f9f); font-size: 13px; }
  body.ph :is(.ph-row, .ph-proj) > .ic:last-child { flex: none; width: 16px; height: 16px; color: var(--muted, #9f9f9f); }
  body.ph .ph-row.ph-danger { color: #ff8a80; }
  body.ph .ph-row.ph-danger .ic { color: inherit; }

  /* ---------- Home: one column, no hero ---------- */
  body.ph:not(.ph-create) .view-home > :not(.ph-home) { display: none !important; }
  body.ph.ph-create .view-home > .ph-home { display: none; }
  body.ph .ph-home { padding: 8px 16px 0; }
  body.ph .ph-ask { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px; border-radius: 28px; background: var(--c-card, #222222);
    color: var(--muted, #9f9f9f); font: 500 16px/1 var(--font); text-decoration: none; }
  body.ph .ph-ask > span { flex: 1; }
  body.ph .ph-ask .ic { width: 20px; height: 20px; }
  body.ph .ph-ask .ic:last-child { width: 32px; height: 32px; padding: 7px; border-radius: 50%; background: var(--c-go, #e8e8e8); color: var(--c-on-go, #08090a); }
  body.ph .ph-ask:active { background: var(--c-sel, #2e2e2e); }
  body.ph .ph-tile { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--c-sel, #2e2e2e); color: var(--text, #f7f7f7); }
  body.ph .ph-tile .ic { width: 20px; height: 20px; }
  body.ph .ph-proj-txt { display: grid; gap: 2px; }
  body.ph .ph-proj-txt b { overflow: hidden; font-weight: 600; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
  body.ph .ph-st { color: var(--muted, #9f9f9f); font-size: 14px; line-height: 1.35; }
  body.ph .ph-st[data-tone="work"] { color: var(--text, #f7f7f7); }
  body.ph .ph-st[data-tone="warn"] { color: #f2c46d; }
  body.ph .ph-act { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; font-size: 15px; line-height: 1.4; color: var(--body, #d6d6d6); }
  body.ph .ph-act > span:nth-child(2) { flex: 1; min-width: 0; }
  body.ph .ph-act b { color: var(--text, #f7f7f7); font-weight: 600; }
  body.ph .ph-act time { flex: none; color: var(--muted, #9f9f9f); font-size: 13px; padding-top: 2px; }
  body.ph .ph-av { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--c-sel, #2e2e2e); color: var(--text, #f7f7f7); }
  body.ph .ph-av .ic { width: 18px; height: 18px; }

  /* ---------- Create: the one box, with the paths that exist; the options wait behind a button ---------- */
  body.ph.ph-create .home-main > .connect, body.ph.ph-create .view-home > .home-rail { display: none !important; }
  /* the box first, right under the title, so the keyboard never covers it; the kinds of build follow it */
  body.ph.ph-create .home-main { min-height: 0; justify-content: flex-start; padding-top: 8px; }
  body.ph.ph-create .greet { order: 1; margin: 4px 0 0; padding: 0; text-align: left; font: 700 28px/1.15 var(--font); letter-spacing: -0.02em; }
  body.ph.ph-create .ph-opts { order: 4; }
  body.ph.ph-create .dcomp { order: 3; margin-top: 16px; }
  body.ph.ph-create .dfirst { order: 7; }
  body.ph .ph-opts { display: none; }
  body.ph.ph-create .ph-opts { display: inline-flex; align-items: center; gap: 6px; align-self: flex-end; min-height: 44px; margin: 4px 0 4px auto; padding: 0 14px; border: 0; border-radius: 22px;
    background: transparent; color: var(--muted, #9f9f9f); font: 600 14px/1 var(--font); }
  body.ph.ph-create .ph-opts .ic { width: 16px; height: 16px; }
  body.ph.ph-create .ph-opts[aria-expanded="true"] { color: var(--text, #f7f7f7); background: var(--c-card, #222222); }
  body.ph.ph-create .dcomp:not(.ph-opts-on) .dcomp-top { display: none; }

  /* ---------- Agents: a row each, more on a press ---------- */
  body.ph .ph-agents-list { list-style: none; margin: 0; padding: 4px; border-radius: calc(20px + 11px + 4px); background: var(--c-card, #222222); }
  body.ph .ph-ag + .ph-ag { margin-top: 2px; }
  body.ph .ph-ag-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 12px; border: 0; border-radius: calc(20px + 11px); background: transparent;
    color: var(--text, #f7f7f7); font: inherit; text-align: left; -webkit-tap-highlight-color: transparent; }
  body.ph .ph-ag-row:active { background: var(--c-sel, #2e2e2e); }
  body.ph .ph-ag-row:focus-visible { outline: 2px solid var(--text, #f7f7f7); outline-offset: -2px; }
  body.ph .ph-ag-row .ph-av { width: 40px; height: 40px; }
  body.ph .ph-ag-row .ph-av .ic { width: 20px; height: 20px; }
  body.ph .ph-ag-txt { flex: 1; min-width: 0; display: grid; gap: 2px; }
  body.ph .ph-ag-txt b { font: 600 17px/1.3 var(--font); }
  body.ph .ph-ag-txt span { color: var(--muted, #9f9f9f); font-size: 14px; line-height: 1.35; }
  body.ph .ph-ag-row > .ic:last-child { flex: none; width: 16px; height: 16px; color: var(--muted, #9f9f9f); transition: rotate 180ms ease; }
  body.ph .ph-ag-row[aria-expanded="true"] > .ic:last-child { rotate: 180deg; }
  body.ph .ph-chip { flex: none; padding: 4px 10px; border-radius: 999px; background: var(--c-sel, #2e2e2e); color: var(--body, #d6d6d6); font: 600 12px/1.3 var(--font); }
  body.ph .ph-chip[data-tone="work"] { background: #f7f7f7; color: #151515; }
  body.ph .ph-chip[data-tone="warn"] { background: #3a2f17; color: #f2c46d; }
  body.ph .ph-chip[data-tone="ok"] { background: #18301f; color: #8fd6a8; }
  body.ph .ph-ag-more { padding: 0 12px 12px 64px; }
  body.ph .ph-ag-role { margin: 0 0 8px; color: var(--muted, #9f9f9f); font-size: 14px; }
  body.ph .ph-ag-hist { list-style: none; margin: 0; padding: 0; }
  body.ph .ph-ag-hist a { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; color: var(--body, #d6d6d6); font-size: 15px; text-decoration: none; }
  body.ph .ph-ag-hist time { flex: none; color: var(--muted, #9f9f9f); font-size: 13px; }
  body.ph .ph-ag-more .ph-empty { padding: 4px 0 8px; }

  /* ---------- the views of their own ---------- */
  body.ph .panel-scroll > .ph-view { padding-top: 8px; }
  body.ph .ph-more .ph-sec:first-of-type { margin-top: 8px; }

  @media (prefers-reduced-motion: reduce) {
    body.ph .ph-tabs a, body.ph .ph-ag-row > .ic:last-child { transition: none; }
  }
  @media (prefers-contrast: more) {
    body.ph .ph-tabs { background: #1e1e1e; -webkit-backdrop-filter: none; backdrop-filter: none; }
    body.ph .ph-list, body.ph .ph-agents-list, body.ph .ph-ask { box-shadow: inset 0 0 0 1px #5a5a5a; }
  }
}
/* landscape on a phone: a shorter bar */
@media (max-width: 820px) and (max-height: 500px) {
  body.ph { --ph-tabs: calc(56px + max(6px, env(safe-area-inset-bottom, 0px))); }
  body.ph .ph-tabs { height: 52px; bottom: max(6px, env(safe-area-inset-bottom, 0px)); left: 50%; right: auto; width: min(520px, calc(100% - 24px)); translate: -50% 0; }
  body.ph .ph-tabs a { grid-auto-flow: column; gap: 6px; font-size: 12px; }
  body.ph .ph-tabs a .ic { width: 20px; height: 20px; }
}
/* a small tablet held upright: the bar keeps a phone's width, in the middle */
@media (min-width: 600px) and (max-width: 820px) and (min-height: 501px) {
  body.ph .ph-tabs { left: 50%; right: auto; width: 520px; translate: -50% 0; }
}
