/* Book Lab on a phone (DESIGN.md "Book Lab on a phone", 2026-12-01): the phone's own navigation,
   made by phone.js. Everything is inside the 760 px query (PHONE_MQ in app.js), and the markup it
   styles exists only there, so a wide window is exactly as it was. Same tokens as app.css. */
@media (max-width: 760px) {
  :root { --pbar: 52px; --ptabs: 58px; --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --top: calc(var(--pbar) + var(--safe-t)); }

  /* The app is as tall as the visual viewport (phone.js phoneViewport), so its bottom row (the tab
     bar, the write toolbar, the wizard's footer) stays above the on-screen keyboard. */
  #app { position: relative; top: var(--vvt, 0px); height: var(--vvh, 100dvh); grid-template-rows: auto minmax(0, 1fr) auto; }

  /* ---- the top bar: back, title and chapter, the save dot, the menu ---- */
  .pbar { height: auto; min-height: var(--top); padding: var(--safe-t) max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left)); gap: 2px; }
  .pb-mark { width: 44px; height: 44px; display: grid; place-items: center; flex: none; }
  .pb-mark .mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
  .pb-title { flex: 1; min-width: 0; display: grid; line-height: 1.25; padding: 4px; }
  .pb-t { font: 600 16.5px var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pb-s { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pb-s:empty { display: none; }
  .pb-save { width: 44px; height: 44px; flex: none; border: 0; background: transparent; display: grid; place-items: center; padding: 0; }
  .pb-save:disabled { cursor: default; }
  .pb-save .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
  .pb-save.st-saving .dot, .pb-save.st-dirty .dot { background: var(--faint); animation: pdot .9s ease-in-out infinite alternate; }
  .pb-save.st-error .dot, .pb-save.st-conflict .dot { background: var(--danger); width: 13px; height: 13px; }
  @keyframes pdot { to { opacity: .3; } }

  /* ---- the tab bar inside a book, and the shelf's New book button ---- */
  .ptabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--surface); border-top: 1px solid var(--line); padding: 0 env(safe-area-inset-right) var(--safe-b) env(safe-area-inset-left); position: relative; z-index: 46; }
  .ptabs button { min-height: var(--ptabs); border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; padding: 4px 0; }
  .ptabs button .ic { padding: 2px 10px; box-sizing: content-box; border-radius: 999px; }
  .ptabs button[aria-current] { color: var(--accent); font-weight: 600; }
  .ptabs button[aria-current] .ic { background: var(--accent-soft); stroke-width: 2.1; }
  .pfoot { padding: 8px max(12px, env(safe-area-inset-right)) calc(10px + var(--safe-b)) max(12px, env(safe-area-inset-left)); background: var(--bg); border-top: 1px solid var(--line); }
  .p-fab { width: 100%; min-height: 52px; justify-content: center; font-size: 16px; border-radius: 14px; box-shadow: var(--shadow); }
  .lib-head .btn.primary { display: none; }
  :root.kbd .ptabs, :root.kbd .pfoot { display: none; }

  /* ---- the tabs' screens ---- */
  .ws > .rail { display: none; }
  .ws.ptab-chapters > .rail { display: flex; width: auto; border-right: 0; min-height: 0; overflow: auto; }
  .ws.ptab-chapters > .center { display: none; }
  .pmore { display: none; }
  .ws.ptab-more .center > :not(.pmore):not(.compare) { display: none !important; }
  .ws.ptab-more .pmore { display: block; flex: 1; min-height: 0; overflow: auto; padding: 14px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left)); }
  .pmore h2 { font: 600 22px var(--serif); margin: 2px 4px 12px; }
  .more-list { display: grid; gap: 6px; }

  /* Chapters: the whole outline; the open chapter marked; a ⋯ per row (no hover tools) */
  .rail .walk-btns, .rail .rail-foot { display: none; }
  .rail-head { padding: 14px 16px 10px; }
  .chapters { padding: 6px 8px; }
  .ch { min-height: 52px; }
  .ch-main { min-height: 52px; font-size: 15.5px; align-items: center; }
  .ch .ch-w, .ch:hover .ch-w, .ch.sel .ch-w, .ch:focus-within .ch-w { display: inline; }
  .ch.sel { box-shadow: inset 3px 0 0 var(--accent); }
  .ch-more { flex: none; color: var(--muted); }
  .rail-part .ch-more { display: inline-flex; }
  .rail-actions { padding: 8px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); }

  /* ---- Write: the text, then the chapter before and after; the toolbar at the bottom ---- */
  .center > .panes { order: 1; }
  .center > .toolbar { order: 2; height: auto; min-height: 52px; border-bottom: 0; border-top: 1px solid var(--line); background: var(--surface); gap: 8px; flex-wrap: wrap; padding: 4px max(8px, env(safe-area-inset-right)) 4px max(8px, env(safe-area-inset-left)); }
  .center > .statusbar { display: none; }
  .toolbar .title, .toolbar .spacer, .toolbar .btn.tool, .toolbar #coach-btn { display: none !important; }
  .toolbar .hint { order: 9; flex-basis: 100%; justify-content: center; min-height: 44px; }
  .pwords { margin-left: auto; color: var(--muted); font-size: 13px; }
  .pdone { display: none; }
  :root.kbd .pdone { display: inline-flex; }
  .mode-seg button { min-width: 72px; }
  .mode-seg button[data-mode="split"] { display: none; }
  .mode-split .mode-seg button[data-mode="write"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .mode-seg button + button[data-mode="read"] { border-left: 1px solid var(--line); }
  .panes, .mode-write .panes, .mode-read .panes { grid-template-columns: minmax(0, 1fr) !important; }
  .mode-split .pane.view { display: none; }
  .mode-split .pane.edit, .mode-write .pane.edit { border: 0; }
  .pane.edit, .pane.view { overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
  /* reading typography: 18 px (the text size in the menu), a line of about 34 em at most */
  #editor { height: auto; min-height: 100%; overflow: hidden; font-size: max(16px, var(--fs)); line-height: 1.7; padding: 20px max(18px, calc((100% - 34em) / 2)) 28px; }
  .prose, .mode-read .prose { font-size: max(16px, var(--fs)); line-height: 1.7; padding: 22px max(18px, calc((100% - 34em) / 2)) 24px; }
  .chnav { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding: 4px max(18px, calc((100% - 34em) / 2)) 28px; }
  .chnav:empty { display: none; }
  .chnav .btn { min-height: 60px; height: auto; justify-content: flex-start; text-align: left; gap: 8px; padding: 8px 12px; white-space: normal; }
  .chnav .chnav-next { grid-column: 2; justify-content: flex-end; text-align: right; }
  .chnav .btn > span { display: grid; min-width: 0; font: 600 14px/1.3 var(--serif); overflow-wrap: anywhere; }
  .chnav small { font: 400 12px var(--sans); color: var(--muted); }

  /* ---- the coach as a bottom sheet at half or full height; Checks and Versions full ---- */
  .panel, .panel.plan-on {
    position: absolute; left: 0; right: 0; width: auto; max-height: none; z-index: 45;
    top: var(--top); bottom: calc(var(--ptabs) + var(--safe-b));
    border: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(20, 18, 12, .22);
    transition: top .22s ease;
  }
  .panel.sheet-half { top: calc(var(--top) + (100% - var(--top) - var(--ptabs) - var(--safe-b)) * .42); }
  .panel.sheet-full { top: var(--top); border-radius: 0; box-shadow: none; }
  .panel.dragging { transition: none; }
  :root.kbd .panel { bottom: 0; }
  :root.kbd .panel:focus-within { top: var(--top); }
  .sheet-head { display: flex; align-items: center; flex: none; border-bottom: 1px solid var(--line); padding-right: 4px; }
  .sheet-grip { flex: 1; min-width: 0; min-height: 52px; border: 0; background: transparent; display: grid; align-content: center; justify-items: start; padding: 10px 12px 6px 16px; position: relative; touch-action: none; cursor: grab; text-align: left; }
  .sheet-grip .bar { position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--faint); opacity: .6; }
  .sheet-grip b { font: 600 16px var(--serif); }
  .sheet-grip:disabled { cursor: default; opacity: 1; }
  .sheet-grip:disabled .bar { display: none; }
  .panel-body { padding: 12px 12px calc(24px + var(--safe-b)); overscroll-behavior: contain; }
  .actions { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .act { min-height: 48px; padding: 8px 9px; font-size: 13px; }
  .act.primary { min-height: 52px; font-size: 15px; }
  .tiers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* the model picker, compare (answers A and B as tabs) and the judge, in the sheet (2026-12-01) */
  .panel.coach-wide { width: auto; }
  .cmp-sides { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .cmp-pair { grid-template-columns: minmax(0, 1fr); }
  .cmp-tabs button { min-height: 44px; }

  /* ---- the menu and the action sheets: from the bottom, over a shade ---- */
  .psheet-shade { padding: 0; place-items: end stretch; }
  .psheet { background: var(--surface); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); max-height: 86%; display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: psheet-in .18s ease-out; }
  @keyframes psheet-in { from { transform: translateY(24%); opacity: .5; } }
  .ps-head { display: flex; align-items: center; padding: 4px 4px 4px 18px; border-bottom: 1px solid var(--line); }
  .ps-head b { flex: 1; min-width: 0; font: 600 16px var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ps-list { overflow: auto; padding: 6px 8px 10px; display: grid; gap: 2px; }
  .ps-item, .more-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; border: 0; background: transparent; padding: 6px 12px; border-radius: 10px; text-align: left; color: var(--ink); text-decoration: none; font-size: 15px; }
  .more-row { background: var(--surface); border: 1px solid var(--line); min-height: 60px; }
  .ps-item:active, .more-row:active { background: var(--accent-soft); }
  .ps-item.danger { color: var(--danger); }
  .ps-item:disabled, .more-row:disabled { opacity: .45; cursor: default; }
  .ps-item .ic, .more-row .ic { color: var(--muted); }
  .ps-item.danger .ic { color: var(--danger); }
  .ps-l { flex: 1; min-width: 0; display: grid; gap: 1px; }
  .ps-d { color: var(--muted); font-size: 12.5px; font-weight: 400; }
  .ps-row { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 4px 12px; }
  .ps-row .ic { color: var(--muted); }
  .ps-row .btn { min-width: 56px; justify-content: center; font-weight: 600; }

  /* ---- the Plan tab: which screen; the walk's Back / Next and auto mode's Start stay low ---- */
  .plan-switch { display: flex; margin: 0 0 12px; }
  .plan-switch button { flex: 1 1 0; min-height: 44px; }
  .walk { padding-bottom: 0; }
  .walk > :last-child:not(.plan) { padding-bottom: 24px; }
  .walk .walk-nav { position: sticky; bottom: 0; z-index: 3; margin: 8px -12px 0; padding: 10px 12px 12px; background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -6px 16px rgba(20, 18, 12, .08); flex-wrap: nowrap; }
  .walk .auto-controls:not(:has(.rv-gate)) { position: sticky; bottom: 0; z-index: 3; box-shadow: 0 -6px 16px rgba(20, 18, 12, .14); }

  /* ---- compare: the text, and the chapter picker as a sheet ---- */
  .compare { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .compare-head { flex-wrap: wrap; gap: 8px; padding: 6px 10px; }
  .compare-head h2 { font-size: 15px; flex: 1 1 100%; min-width: 0; }
  .compare-head .spacer { display: none; }
  .cmp-pick { flex: 1 1 0; min-width: 0; justify-content: flex-start; }
  .cmp-pick .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .cmp-list { display: none; position: absolute; left: 0; right: 0; bottom: 0; max-height: 70%; z-index: 6; overflow: auto; border: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(20, 18, 12, .25); padding: 10px 8px calc(10px + var(--safe-b)); }
  .compare.pick-open .cmp-list { display: block; }
  .compare.pick-open .cmp-view { opacity: .35; }
  .cmp-view { padding: 16px 14px 40px; }

  /* ---- the wizard: one question per screen, the footer low and above the keyboard ---- */
  .library.wizp { display: flex; flex-direction: column; padding-bottom: 0; }
  .wizp .wiz { flex: 1 0 auto; width: 100%; display: flex; flex-direction: column; gap: 14px; }
  .wizp .wiz-body { display: grid; gap: 14px; }
  .wizp .field textarea { min-height: 160px; }
  .wizp .wiz-nav { margin-top: auto; position: sticky; bottom: 0; z-index: 2; flex-wrap: nowrap; background: var(--bg); border-top: 1px solid var(--line); padding: 10px 0 calc(12px + var(--safe-b)); }
  .wizp .wiz-nav .spacer { display: none; }
  .wizp .wiz-nav .btn { flex: 1 1 auto; justify-content: center; }
  .wizp .wz-top { gap: 4px 10px; }

  /* the shelf's Unfinished new books: first, above the books, each with two full-width buttons */
  .unfinished { margin: 0 0 18px; padding: 14px 14px 14px 18px; }
  .unf { flex-wrap: wrap; gap: 10px; }
  .unf-acts { width: 100%; }
  .unf-acts .btn { flex: 1 1 0; justify-content: center; min-height: 44px; }

  /* messages at the top, never over the text being typed or the toolbar */
  #toasts { top: calc(var(--top) + 6px); bottom: auto; }
}

/* One movement less: the sheets and the save dot hold still. */
@media (max-width: 760px) and (prefers-reduced-motion: reduce) {
  .panel, .psheet, .pb-save .dot { transition: none !important; animation: none !important; }
}
