/* Phone shell (crates/web/src/phone, docs/mobile/PROPOSAL.md direction A). Every rule is under
   body.phone, which the shell sets before its first render; the desktop page never has it.

   Portrait: four fixed bands, top to bottom: top bar 48, main (the rest), run bar 56, tab bar 58
   plus the safe area. Sheets open inside main and never move the bands.
   Landscape (phone held sideways, height ≤ 500): the tabs become a 76 px rail on the left with the
   run controls at its foot; the top bar and main fill the rest at full height. */

body.phone {
  --ph-top: 48px; --ph-run: 56px; --ph-tabs: 58px;
  --ph-safe-b: env(safe-area-inset-bottom, 0px);
  overscroll-behavior: none;
}
body.phone .ph {
  position: fixed; inset: 0; display: grid;
  grid-template-columns: 100%;
  grid-template-rows: var(--ph-top) minmax(0, 1fr) var(--ph-run) calc(var(--ph-tabs) + var(--ph-safe-b));
  grid-template-areas: "top" "main" "run" "tabs";
  background: var(--bg);
}
body.phone .ico-sm { width: 20px; height: 20px; }
body.phone .hidden { display: none !important; }
body.phone .gone { visibility: hidden; }
body.phone .ph-sp { flex: 1; }
body.phone .ph-rot-msg { min-width: 0; padding: 0 8px; font-size: 12px; line-height: 14px; text-align: right; color: var(--stop); }

/* ---- top bar ---- */
body.phone .ph-top {
  grid-area: top; position: relative; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0;
}
body.phone .ph-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; }
body.phone .ph-title h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.phone .ph-back { height: 44px; margin-left: -12px; padding: 0 10px 0 4px; display: inline-flex; align-items: center; gap: 2px; background: transparent; border: 0; font-size: 16px; color: var(--accent); }
body.phone .ph-chal {
  min-width: 0; height: 44px; margin-left: -8px; padding: 0 8px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
  background: transparent; border: 0; text-align: left;
}
body.phone .ph-chal-t { max-width: 100%; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.phone .ph-chal-n { font-size: 12px; color: var(--muted); }
body.phone .ph-acts { display: none; align-items: center; gap: 4px; flex: none; }
body.phone .ph-acts.shown { display: flex; }
/* Undo and Redo sit next to the tab's own actions on Board and Schematic. With the four schematic tools
   that is six 44 px buttons: no gap between them keeps the title on one line at 390 px. */
body.phone .ph-top { gap: 0; }
body.phone .ph-title { margin-right: 8px; }
body.phone .ph-acts, body.phone .ph-acts .schtools { gap: 0; }
body.phone .ph-acts button { height: 44px; min-width: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 0; border-radius: 10px; }
body.phone .ph-acts button.on { background: var(--btn-on); color: var(--accent-ink); }
body.phone .ph-acts .hb-label { display: none; }
/* Schematic tools in the top bar: icons only (Volts, Re-layout, SVG, KiCad). */
body.phone .ph-acts .schtools { display: flex; gap: 0; padding: 0; border-left: 0; }
body.phone .ph-acts .schtools button.tog.on { background: var(--btn-on); color: var(--accent-ink); border: 0; }
body.phone #btn-split, body.phone #btn-schem { display: none !important; }

/* ---- main ---- */
body.phone .ph-main { grid-area: main; position: relative; min-height: 0; overflow: hidden; }
body.phone :is(.ph-stage, .ph-code, .ph-bench, .ph-more) { position: absolute; inset: 0; display: none; }
body.phone .ph[data-tab="board"] .ph-stage,
body.phone .ph[data-tab="schematic"] .ph-stage,
body.phone .ph[data-tab="bench"] .ph-stage,
body.phone .ph[data-tab="code"] .ph-code,
body.phone .ph[data-tab="bench"] .ph-bench,
body.phone .ph[data-tab="more"] .ph-more { display: block; }

/* ---- stage: board / schematic / device ---- */
body.phone .ph-stage { container-type: size; overflow: hidden; background: var(--bg); }
body.phone .ph-stage .views { position: absolute; inset: 0; display: block; }
body.phone #board { position: absolute; inset: 0; width: 100%; height: 100%; }
/* The board fills the canvas; Fit keeps the drawing clear of the floating controls' bands (ui::FLOAT_*). */
body.phone #schem { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
body.phone .ph[data-tab="schematic"] #schem { display: block; }
body.phone .ph[data-tab="schematic"] #board { display: none; }
/* Turned: the element is as tall as the stage is wide and as wide as it is tall, turned about its
   centre (dom::board_client maps touches back). */
body.phone .ph-stage.rot #board {
  inset: auto; left: 50%; top: 50%; width: 100cqh; height: 100cqw;
  transform: translate(-50%, -50%) rotate(90deg);
}
body.phone .ph-stage .device { display: none; }
body.phone .ph-stage.device-mode .views, body.phone .ph-stage.device-mode .ph-float, body.phone .ph-stage.device-mode #readout { display: none; }
body.phone .ph-stage.device-mode .device {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 16px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--bg);
}
body.phone .dev-top { gap: 12px; width: 100%; justify-content: center; }
body.phone .dev-case { border-radius: 10px; padding: 6px; }
body.phone #dev-screen { width: 200px; height: 200px; }
body.phone .dev-btns { flex: 1; gap: 8px; max-width: 140px; }
body.phone .dev-btn { width: 100%; height: 64px; }
body.phone .dev-sliders { width: 100%; }

/* Floating controls over the canvas: Flow and the warnings chip top left, zoom bottom right. */
body.phone .ph-float { position: absolute; z-index: 4; display: flex; gap: 8px; align-items: center; }
body.phone .ph-tl { top: 8px; left: 8px; }
body.phone .ph-br { right: 8px; bottom: 8px; }
body.phone .ph[data-tab="bench"] .ph-float, body.phone .ph[data-tab="schematic"] .ph-tl { display: none; }
body.phone .ph-float button {
  height: 44px; min-width: 44px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
body.phone .ph-float .hb-label { display: none; }
body.phone .ph-float button.tog.on { background: color-mix(in srgb, var(--accent) 16%, var(--panel)); border-color: var(--accent); color: var(--ink); }
body.phone .ph-warn { display: none !important; color: var(--warn-ink, var(--ink)); }
body.phone .ph-warn.shown { display: inline-flex !important; border-color: var(--warn); background: color-mix(in srgb, var(--warn) 18%, var(--panel)); }
body.phone .ph-br.zoomctl { gap: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
body.phone .ph-br.zoomctl button { border: 0; box-shadow: none; background: transparent; }
body.phone #btn-zoom-pct { width: 64px; font-size: 14px; }
/* Placement or wiring: one line over the top of the canvas with Cancel; a solver error the same way. */
body.phone #readout.ph-banner {
  position: absolute; top: 8px; left: 8px; right: 8px; z-index: 5; height: auto; min-height: 44px; display: none;
  align-items: center; gap: 8px; padding: 0 4px 0 12px; font-size: 14px; white-space: normal;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
body.phone #readout.ph-banner.shown { display: flex; }
body.phone #readout.ph-banner > span { flex: 1; min-width: 0; padding: 6px 0; line-height: 18px; }
/* Taps and drags go through the banner to the holes under it (a probe or wire is armed); only Cancel takes touches. */
body.phone #readout.ph-banner { pointer-events: none; }
body.phone #ph-cancel { pointer-events: auto; }
body.phone #ph-cancel { display: none; flex: none; height: 36px; padding: 0 12px; }
body.phone #ph-cancel.shown { display: inline-flex; align-items: center; }

/* Bench: the stage is a strip of the board at the top (probes are dropped on it), the instruments below. */
body.phone .ph[data-tab="bench"] .ph-stage { bottom: auto; height: 170px; border-bottom: 1px solid var(--line); }
body.phone .ph[data-tab="bench"] .ph-bench { top: 170px; }

/* ---- Code tab: Editor / Serial / Debug ---- */
body.phone .ph-code { display: none; background: var(--panel); }
body.phone .ph[data-tab="code"] .ph-code { display: flex; flex-direction: column; }
body.phone .ph-seg { flex: none; display: flex; gap: 4px; padding: 8px 12px 4px; }
body.phone .ph-seg button { flex: 1; height: 44px; font-size: 14px; }
body.phone .ph-seg button.on { background: var(--btn-on); color: var(--accent-ink); border-color: var(--btn-on); font-weight: 600; }
body.phone #code, body.phone #code.open {
  position: relative; inset: auto; flex: 1; min-height: 0; height: auto; display: flex; flex-direction: column;
  border: 0; background: var(--panel); overflow: hidden;
}
body.phone #code .code-pane, body.phone #code .serial-pane { flex: 1; min-height: 0; padding: 4px 12px 12px; border: 0; }
body.phone #code .code-bar h2, body.phone #code-toggle, body.phone #code-debug, body.phone #code .dbg-toggle { display: none; }
/* Template and Build & run (Editor), Autoscroll and Clear (Serial) sit in the top bar's action slot. */
body.phone #code .code-bar {
  position: fixed; top: 0; right: 8px; z-index: 21; height: var(--ph-top); display: flex; align-items: center; gap: 6px; padding: 0;
}
body.phone #code .code-bar button, body.phone #code .code-bar select { height: 44px; padding: 0 12px; font-size: 14px; }
/* One width for "Build & run" and "Building…": the top bar does not shift. */
body.phone #code .code-bar button.primary { width: 116px; padding: 0 8px; }
body.phone .ph-code[data-sub="editor"] .serial-pane, body.phone .ph-code[data-sub="editor"] .debug-pane,
body.phone .ph-code[data-sub="serial"] .code-pane, body.phone .ph-code[data-sub="serial"] .debug-pane,
body.phone .ph-code[data-sub="debug"] .serial-pane { display: none !important; }
body.phone .ph-code[data-sub="debug"] .code-pane .code-bar { display: none; }
body.phone .code-body { grid-template-rows: minmax(0, 1fr) 96px; }
body.phone .code-editor { --code-fs: 16px; }
body.phone .code-fallback { font-size: 16px; }
body.phone .code-diags button.diag { min-height: 44px; }
body.phone .code-status { white-space: normal; height: auto; min-height: 18px; }
body.phone .code-status.code-src { white-space: nowrap; }
body.phone .code-guide { font-size: 13px; }
body.phone .code-guide p { margin: 2px 0; }
/* The box is short: the button and the link stay, the sentence is in the steps. */
body.phone .code-guide p + p { display: none; }
body.phone .code-guide button { height: 44px; padding: 0 16px; }
body.phone .code-guide a { display: inline-block; line-height: 44px; }
body.phone .serial-out { flex: 1; min-height: 0; }
/* Debug: source on top, the stop line and Stack / Breakpoints under it, the steps at the bottom. */
body.phone .ph-steps { display: none; }
body.phone .ph-code[data-sub="debug"] .ph-steps {
  order: 3; flex: none; display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line);
}
body.phone .ph-steps button { height: 48px; font-size: 15px; }
body.phone .ph-steps button.primary { background: var(--btn-on); border-color: var(--btn-on); color: var(--accent-ink); font-weight: 600; }
body.phone .ph-code[data-sub="debug"] #code { order: 2; }
body.phone .ph-code[data-sub="debug"] #code .code-pane { flex: 1 1 55%; padding-bottom: 6px; }
body.phone #code.debugging .dbg-src { flex: 1; }
body.phone .sl-n { width: 44px; }
body.phone .debug-pane { flex: 0 0 auto; height: 40%; min-height: 200px; max-height: 260px; padding: 0 12px 6px; border: 0; border-top: 1px solid var(--line); }
body.phone .dbg-more, body.phone .dbg-close { display: none; }
body.phone .dbg-stop { height: 52px; font-size: 13px; line-height: 17px; }
body.phone .dbg-tabs button { height: 44px; font-size: 14px; }
body.phone .dbg-body { flex: 1; min-height: 0; overflow-y: auto; }
body.phone .bpi input[type="checkbox"], body.phone .dbg-check input[type="checkbox"] { width: 22px; height: 22px; margin: 0 11px 0 0; flex: none; }
body.phone .dbg-check { display: flex; align-items: center; min-height: 44px; }
body.phone .dbg-row input[type="text"] { height: 44px; font-size: 16px; }
body.phone .dbg-row button, body.phone .dbg-row select { height: 44px; min-width: 44px; }
body.phone button.dbg-frame { padding: 8px 4px; }
body.phone button.bpi-x { width: 44px; height: 44px; }
body.phone .bpi { min-height: 44px; }

/* ---- Bench tab ---- */
body.phone .ph-bench { background: var(--panel); overflow: hidden; }
body.phone #bench, body.phone #bench.open { position: absolute; inset: 0; height: auto; display: flex; flex-direction: column; border: 0; z-index: auto; }
body.phone .bench-resize, body.phone .bench-close { display: none !important; }
body.phone .bench-bar { height: 52px; padding: 0 12px; }
body.phone .bench-tabs { flex: 1; }
body.phone .bench-tabs button { flex: 1; }
body.phone #bench button, body.phone #bench select, body.phone .bench-tabs button { height: 44px; }
body.phone #bench select { font-size: 16px; }
body.phone .bench-body { overflow-y: auto; -webkit-overflow-scrolling: touch; display: block; }
body.phone #bench .stp button, body.phone #sc-edge { width: 44px; min-width: 44px; }
body.phone .meter-bench { flex-direction: column; }
body.phone .meter-face { flex: none; height: 120px; }
/* The meter readout stays in view while its controls scroll. The trace does not: it and the primary
   controls (Run/Stop, Time, Trigger) fit the body at its top, and the body is the only scroller. */
body.phone .meter-face { position: sticky; top: 0; z-index: 3; }
body.phone .meter-ctl { width: auto; }
body.phone #bench .probe-dot { width: 44px; height: 44px; }
body.phone .scope, body.phone .sc-main { display: contents; }
body.phone .sc-screen { width: 100%; height: 160px; }
body.phone .sc-ctl, body.phone .la-ctl { width: auto; border-left: 0; padding: 8px 12px; overflow: visible; }
body.phone .ctl-row { min-height: 48px; }
body.phone .sc-table { padding: 0 12px; overflow: visible; }
body.phone .sc-head { display: none; }
body.phone .sc-row {
  height: auto; min-width: 0; padding: 8px 0; row-gap: 6px; border-top: 1px solid var(--line);
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-areas: "ch probe probe probe probe probe" "vdiv vdiv vdiv off off off" "freq freq per per duty duty" "vpp vpp vavg vavg rise rise";
}
body.phone .sc-row > .sc-ch { grid-area: ch; } body.phone .sc-row > .sc-probe { grid-area: probe; }
body.phone .sc-row > .sc-vdiv { grid-area: vdiv; } body.phone .sc-row > .sc-off { grid-area: off; }
body.phone .sc-row > .sc-freq { grid-area: freq; } body.phone .sc-row > .sc-per { grid-area: per; } body.phone .sc-row > .sc-duty { grid-area: duty; }
body.phone .sc-row > .sc-vpp { grid-area: vpp; } body.phone .sc-row > .sc-vavg { grid-area: vavg; } body.phone .sc-row > .sc-rise { grid-area: rise; }
body.phone .sc-m { text-align: left; font-size: 13px; }
body.phone .sc-m::before { content: attr(data-l) " "; color: var(--muted); }
body.phone .stp-val { min-width: 0; flex: 1; font-size: 13px; }
body.phone #bench .stp { display: flex; width: 100%; }
body.phone .logic { display: grid; grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: 432px auto; }
body.phone .la-lanes { padding: 0 4px 0 8px; height: 432px; }
body.phone #bench .la-lanes select { height: 44px; font-size: 14px; }
body.phone .la-screen { height: 432px; width: 100%; }
body.phone .la-ctl { grid-column: 1 / -1; border-top: 1px solid var(--line); }

/* Short screens (Chrome for iOS, about 390x600): a smaller board strip and trace leave room for the controls. */
@media (max-height: 640px) and (orientation: portrait) {
  body.phone .ph[data-tab="bench"] .ph-stage { height: 130px; }
  body.phone .ph[data-tab="bench"] .ph-bench { top: 130px; }
  body.phone .meter-face { height: 96px; }
  body.phone .sc-screen { height: 108px; }
  body.phone .sc-ctl { padding: 4px 12px; }
  body.phone .sc-ctl .ctl-row { min-height: 44px; }
}

/* ---- More ---- */
body.phone .ph-more { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 24px; background: var(--bg); }
body.phone .ph-more > h2 { margin: 16px 4px 6px; }
body.phone .ph-group { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
body.phone .ph-group + .ph-group { margin-top: 12px; }
body.phone .ph-row, body.phone .ph-group > button, body.phone .ph-group .burn-btn {
  width: 100%; min-height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px; text-align: left;
  font-size: 16px; background: transparent; border: 0; border-radius: 0;
}
body.phone .ph-group > * + * { border-top: 1px solid var(--line); }
body.phone .ph-row > span { flex: 1; }
body.phone .ph-chev { color: var(--muted); }
body.phone #btn-clear { color: var(--err); }
/* The project panel as rows: Examples picker full width, then Import / Export / Share. */
body.phone #project.ph-group > .panel, body.phone #project .panel { padding: 0; border: 0; }
body.phone #project h2 { display: none; }
body.phone #project .proj-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
body.phone #project .proj-row .pick-btn { grid-column: 1 / -1; height: 48px; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 0 12px 0 16px; font-size: 16px; }
body.phone #project .proj-row button { height: 48px; border: 0; border-radius: 0; background: transparent; font-size: 15px; }
body.phone #project .proj-row button + button { border-left: 1px solid var(--line); }
body.phone #project .muted { padding: 8px 16px; }
body.phone .ph-group .damage, body.phone .ph-group .panel { padding: 0; border: 0; }

/* ---- sheets ---- */
body.phone .ph-scrim { position: absolute; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.32); display: none; }
body.phone .ph-scrim.open { display: block; }
body.phone .ph-sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 31; display: none; flex-direction: column;
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2);
}
body.phone .ph-sheet.open { display: flex; }
body.phone .ph-sheet.half { height: 55%; }
body.phone .ph-sheet.tall { height: calc(100% - 24px); }
/* The part sheet leaves the canvas live above it (no scrim): a tap on another part selects it. */
body.phone #ph-part-sheet { z-index: 25; }
body.phone .ph-sheet-head { flex: none; height: 52px; display: flex; align-items: center; gap: 4px; padding: 0 4px 0 16px; border-bottom: 1px solid var(--line); }
body.phone .ph-sheet-head h2 { margin: 0; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--ink); font-weight: 600; }
body.phone #ph-part-sheet .ph-sheet-head { padding-left: 8px; }
body.phone .ph-sh-act { height: 44px; padding: 0 12px; display: inline-flex; align-items: center; gap: 6px; font-size: 15px; background: transparent; border: 0; }
body.phone #tool-delete { color: var(--err); }
body.phone .ph-close { width: 44px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; background: transparent; border: 0; }
body.phone .ph-sheet-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
body.phone .ph-sheet-body > section, body.phone .ph-sheet-body > .panel, body.phone .ph-sheet-body > #firmware { padding: 12px 16px; border: 0; }
body.phone .ph-sheet-body > section > h2:first-child, body.phone #inspector h2, body.phone #learn > h2 { display: none; }
body.phone #inspector { height: auto; padding-bottom: 4px; }
body.phone #elec { height: auto; overflow: visible; border-top: 1px solid var(--line); }
body.phone .gpio-btn { height: 44px; }
body.phone .warn-list li { padding: 12px 8px; }
body.phone .row { flex-wrap: wrap; }
body.phone .row button, body.phone .row select, body.phone .row input, body.phone .swatch { height: 44px; }
body.phone .row input, body.phone .row select { font-size: 16px; }
body.phone .swatch { width: 44px; }
body.phone .slider { height: 44px; }
body.phone #firmware .row + .row, body.phone #fw-status { margin-top: 10px; }
body.phone #firmware .row > * { flex: 1; }
body.phone #fw-status { font-size: 14px; line-height: 20px; white-space: normal; overflow: visible; text-overflow: clip; height: auto; }
/* Add part: search and category chips, then the parts of the chosen category in a grid. */
body.phone .ph-sheet-body > .palette { display: flex; flex-direction: column; height: 100%; border: 0; background: transparent; }
body.phone .pal-find { flex: none; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
body.phone #pal-search { width: 100%; height: 44px; font-size: 16px; padding: 0 10px; }
body.phone .pal-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
body.phone .pal-chips::-webkit-scrollbar { display: none; }
body.phone .palette .chip { flex: none; height: 44px; padding: 0 14px; flex-direction: row; font-size: 14px; border-radius: 20px; }
body.phone .pal-groups { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 72px; gap: 8px; align-content: start; padding: 12px; overflow-y: auto; }
body.phone .pal-group { display: none; }
body.phone .pal-group.chip-on, body.phone .pal-groups.searching .pal-group { display: contents; }
body.phone .pal-group.miss, body.phone .pal-head { display: none !important; }
body.phone .pal-items, body.phone .pal-group.closed .pal-items { display: contents; }
body.phone .pal-item.miss { display: none; }
body.phone .pal-none.shown { grid-column: 1 / -1; padding: 12px 0; }
body.phone .palette button { height: 72px; font-size: 13px; }
/* Challenges sheet */
body.phone #learn { padding: 12px 16px; border: 0; }
body.phone #learn-close, body.phone #learn .learn-head:not(:has(#learn-list)) { display: none; }
body.phone .learn-head button, body.phone .learn-status button { height: 44px; padding: 0 14px; }
body.phone .learn-item { height: 48px; }
body.phone .learn-status { min-height: 48px; height: auto; }
/* .learn-status > span clamps to two lines (display: -webkit-box), which drops the row gap. */
body.phone .learn-status > .learn-confirm { display: flex; gap: 8px; overflow: visible; -webkit-line-clamp: none; line-clamp: none; }
body.phone .learn-confirm button { margin: 0; }
body.phone .checks { font-size: 14px; gap: 6px 8px; }

/* Pickers (Examples, Firmware, part options): a bottom sheet over everything. --pick-b / --pick-vh
   (picker.rs): with the keyboard up, the sheet ends on the keyboard's top edge. */
body.phone .pick-back.open { background: rgba(0, 0, 0, 0.4); z-index: 60; }
body.phone .pick-pop {
  z-index: 61; left: 0; right: 0; top: auto; bottom: var(--pick-b, 0px); width: auto; height: 82vh;
  height: min(82dvh, 640px, calc(var(--pick-vh, 100dvh) - 8px));
  border-width: 1px 0 0; border-radius: 14px 14px 0 0;
}
body.phone .pick-title { display: block; flex: none; margin: 14px 16px 0; }
body.phone .pick-find { height: 44px; margin: 8px 12px; font-size: 16px; }
body.phone .pick-head { padding: 10px 16px 4px; }
body.phone .pick-row { min-height: 52px; align-content: center; padding: 6px 16px; column-gap: 10px; }
body.phone .pick-row:active { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
body.phone .pick-d { font-size: 13px; }
body.phone .pick-foot { display: block; flex: none; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
body.phone .pick-close { width: 100%; height: 48px; font-size: 15px; }

/* Notice (a shared link opened, an import failed): at the foot of main, just above the run bar, over
   the canvas (above the zoom and Fit pill), so nothing moves and the tabs stay free. */
body.phone .ph-main .toast {
  position: absolute; left: 8px; right: 8px; bottom: 64px; transform: none; max-width: none; z-index: 50;
  padding: 4px 4px 4px 14px; font-size: 14px;
}
body.phone .ph-main .toast button { height: 44px; min-width: 44px; }

/* ---- run bar ---- */
body.phone .ph-run {
  grid-area: run; position: relative; z-index: 20; display: flex; align-items: center; gap: 6px; padding: 0 8px 0 4px;
  background: var(--panel); border-top: 1px solid var(--line);
}
body.phone .ph-fw {
  flex: 1; min-width: 0; height: 48px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 1px;
  padding: 0 8px 0 12px; text-align: left; background: transparent; border: 0; border-radius: 10px;
}
body.phone .ph-fw.on { background: var(--btn); color: var(--ink); }
body.phone .ph-fw-name { max-width: 100%; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.phone .ph-fw-state { max-width: 100%; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; }
body.phone .ph-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
body.phone .ph-dot.run { background: var(--run, #23803a); }
body.phone .ph-fw-word { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
body.phone #fw-time { flex: none; min-width: 52px; }
body.phone #fw-speed { flex: none; min-width: 40px; }
body.phone #fw-reset, body.phone .ph-go { flex: none; width: 48px; height: 44px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
body.phone .ph-go { width: 64px; background: var(--btn-on); border-color: var(--btn-on); color: var(--accent-ink); }
body.phone .ph-go[hidden] { display: none; }
body.phone .ico-fill { fill: currentColor; stroke: none; }
body.phone .ico-thick { stroke-width: 3; }

/* ---- tab bar ---- */
body.phone .ph-tabs {
  grid-area: tabs; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0 4px var(--ph-safe-b); background: var(--panel); border-top: 1px solid var(--line);
}
body.phone .ph-tabs button {
  height: calc(var(--ph-tabs) - 1px); min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 0; font-size: 11px; color: var(--muted); background: transparent; border: 0; border-radius: 0;
}
body.phone .ph-tabs button .ico-sm { width: 22px; height: 22px; }
body.phone .ph-tabs button.on { color: var(--accent); font-weight: 600; background: transparent; }
body.phone .ph-tabs button { position: relative; }
body.phone .ph-tabs button.on::before { content: ""; position: absolute; top: 0; left: 50%; width: 32px; height: 3px; transform: translateX(-50%); border-radius: 0 0 3px 3px; background: var(--accent); }

/* ---- landscape: the tabs are a rail on the left; top bar, canvas and run bar fill the rest ---- */
@media (orientation: landscape) {
  body.phone .ph {
    grid-template-columns: calc(76px + env(safe-area-inset-left, 0px)) minmax(0, 1fr);
    grid-template-rows: var(--ph-top) minmax(0, 1fr) calc(var(--ph-run) + var(--ph-safe-b));
    grid-template-areas: "tabs top" "tabs main" "tabs run";
    padding-right: env(safe-area-inset-right, 0px);
  }
  body.phone .ph-tabs {
    grid-template-columns: 100%; grid-auto-rows: minmax(0, 1fr); padding: 0 0 var(--ph-safe-b) env(safe-area-inset-left, 0px);
    border-top: 0; border-right: 1px solid var(--line);
  }
  body.phone .ph-tabs button { height: auto; min-height: 44px; }
  body.phone .ph-tabs button.on::before { top: 50%; left: 0; width: 3px; height: 28px; transform: translateY(-50%); border-radius: 0 3px 3px 0; }
  body.phone .ph-run { padding-bottom: var(--ph-safe-b); }
  body.phone .ph-sheet.half { height: calc(100% - 16px); }
  body.phone .ph-sheet { left: auto; width: min(440px, 100%); border-left: 1px solid var(--line); border-radius: 14px 0 0 0; }
  body.phone .ph[data-tab="bench"] .ph-stage { bottom: 0; height: auto; right: 55%; border-bottom: 0; border-right: 1px solid var(--line); }
  body.phone .ph[data-tab="bench"] .ph-bench { top: 0; left: 45%; }
  /* Debug: the source on the left, the stop line and Stack / Breakpoints beside it. */
  body.phone .ph-code[data-sub="debug"] #code { flex-direction: row; }
  body.phone .ph-code[data-sub="debug"] .debug-pane { height: auto; max-height: none; width: 300px; border-top: 0; border-left: 1px solid var(--line); }
  /* Code: Editor / Serial / Debug sit in the top bar beside the title, so the editor gets the height
     (the diagnostics list is one row, it scrolls). */
  body.phone .ph-seg {
    position: fixed; top: 2px; left: calc(76px + env(safe-area-inset-left, 0px) + 84px); z-index: 21; width: 300px; padding: 0; gap: 4px;
  }
  body.phone .code-body { grid-template-rows: minmax(0, 1fr) 48px; }
  body.phone #code .code-pane, body.phone #code .serial-pane { padding-top: 8px; }
  /* Pickers (Examples, Firmware list) are a right-side panel like the sheets. */
  body.phone .pick-pop {
    left: auto; right: 0; top: 0; width: min(440px, 100%); height: calc(var(--pick-vh, 100dvh) - 0px); bottom: var(--pick-b, 0px);
    border-width: 0 0 0 1px; border-radius: 14px 0 0 14px;
  }
}
