/* 81_parts_editor.css - T62b-1 / T62b-2 (Fable): the parts marking editor (81_parts_editor.js).
 * One full-screen layer over the plan: 1. pick a machine, 2. its numbered parts list beside its 3D model.
 * Tokens from 01_tokens.css only. Every breakpoint is `screen` scoped. Touch targets are at least 44 px.
 * List numbers and the marks on the model share one colour, so they read as one thing; a suggestion that is not yet
 * accepted is violet and dashed, in the list and on the model. No control ever sits on the model.
 * T66b-1 (design pass, to read as one app with pick-a-part, 82_part_pick.css): the layout follows the SHAPE of the screen.
 *  - wide (from 900 px: tablet on its side, PC): the list on the left, the model on the right.
 *  - upright or narrow (under 900 px): the model on top with about three fifths of the height, the list under it.
 *    A phone (700 px and down) has a one-row head and the rare actions (Change model, Discard) at the end of the list.
 *  - on its side and short (a phone on its side): the model on the left, the list on the right, tighter bars.
 * 81_parts_editor.js keeps the DOM in the order on screen, with the same queries.
 * The message line takes the place of the hint line above the model for a few seconds, so it never lies over the list
 * or a control. The model file's name sits in a strip under the model, not on it. Two marks of ONE part that land closer
 * than 44 px are drawn as one number with a second edge. A mouse-over look is given only where there is a mouse.
 * T66b-2: the marks of the part picked in the list are never merged. In Place mark the model can take keyboard focus:
 * a crosshair is moved with the arrow keys and Enter places the mark. The hint line tells the keys while it has focus. */

.pe-root { position: fixed; inset: 0; z-index: 600; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.4; }
.pe-root[hidden], .pe-root [hidden] { display: none !important; }
.pe-root *, .pe-root *::before, .pe-root *::after { box-sizing: border-box; }
.pe-root button { -webkit-tap-highlight-color: transparent; }
.pe-root :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* the title is focused after a load so a screen reader starts there; it is not a control, so it shows no focus box */
.pe-root h1:focus, .pe-root h1:focus-visible { outline: none !important; box-shadow: none !important; }
.pe-ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pe-grow { flex: 1 1 auto; }
.pe-meta { font-size: 13px; color: var(--ink-soft); }
.pe-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---- head: the house bar look, so the screen belongs to the app ---- */
.pe-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); padding: var(--sp-2) var(--sp-4); padding-top: max(var(--sp-2), env(safe-area-inset-top)); background: var(--kp-bar); color: var(--kp-bar-ink); box-shadow: var(--kp-bar-shadow); position: relative; z-index: 1; }
.pe-head :focus-visible { outline-color: var(--kp-bar-ring); }
.pe-title { flex: 1 1 0; min-width: 0; }
.pe-h1 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; text-wrap: balance; } /* FX-2: a machine name wraps onto a second line; it is never cut */
.pe-sub { margin: 0; font-size: 13px; color: var(--kp-bar-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pe-head-actions { display: flex; align-items: center; gap: var(--sp-2); }
.pe-bar-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; min-width: 44px; padding: 0 var(--sp-4); border: 1px solid var(--kp-bar-line); border-radius: var(--r-pill); background: var(--kp-bar-tint); color: var(--kp-bar-ink); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; }
.pe-bar-btn-primary { background: var(--kp-bar-on); border-color: var(--kp-bar-on); color: var(--navy); }
[data-theme="dark"] .pe-bar-btn-primary { color: var(--on-brand); }
.pe-bar-btn:disabled { opacity: .5; cursor: not-allowed; }
.pe-back { padding-left: var(--sp-3); }
.pe-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); background: var(--kp-bar-tint); color: var(--kp-bar-ink-2); font-size: 13px; white-space: nowrap; }
.pe-chip::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .6; }
.pe-chip.is-ok { color: var(--kp-bar-ink); }
.pe-chip.is-ok::before { background: var(--kp-dot-ok); opacity: 1; }
.pe-chip.is-bad { color: var(--kp-bar-ink); font-weight: 600; }
.pe-chip.is-bad::before { background: var(--kp-dot-bad); opacity: 1; }
.pe-banner { margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--warning-bg); color: var(--ink); border-bottom: 2px solid var(--warning); font-size: 15px; }

/* ---- buttons ---- */
.pe-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 44px; padding: 0 var(--sp-4); border: 1px solid var(--ink-muted); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; }
.pe-btn-primary { background: var(--brand-solid); border-color: var(--brand-solid); color: var(--acc-ink); }
.pe-btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: var(--acc-ink); }
.pe-btn-danger-quiet { border-color: transparent; background: transparent; color: var(--danger-fg); }
.pe-btn-quiet { border-color: transparent; background: transparent; color: var(--ink-soft); }
.pe-btn:disabled { opacity: .5; cursor: not-allowed; }
.pe-icon-btn, .pe-grip { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-soft); cursor: pointer; }
.pe-icon-btn:disabled, .pe-grip:disabled { opacity: .35; cursor: not-allowed; }
.pe-grip { color: var(--ink-muted); cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---- view 1: pick a machine ---- */
.pe-pick { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--sp-3); width: 100%; max-width: 760px; margin: 0 auto; padding: var(--sp-4); padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }
.pe-search, .pe-field { display: grid; gap: 4px; }
.pe-label { font-size: 14px; font-weight: 600; }
.pe-input { width: 100%; min-height: 44px; padding: 0 var(--sp-3); border: 1px solid var(--ink-muted); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; }
.pe-input[aria-invalid="true"] { border-color: var(--danger-fg); box-shadow: 0 0 0 1px var(--danger-fg); }
.pe-input-short { max-width: 120px; }
.pe-count { margin: 0; font-size: 14px; color: var(--ink-soft); }
.pe-machines { flex: 1 1 auto; min-height: 0; overflow: auto; margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.pe-machine { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 60px; padding: var(--sp-2) var(--sp-4); border: 0; border-bottom: 1px solid var(--line); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.pe-machines li:last-child .pe-machine { border-bottom: 0; }
.pe-machine > .pe-ic { color: var(--ink-muted); }
.pe-machine-text { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }
.pe-machine-name { font-weight: 600; overflow-wrap: anywhere; }

/* ---- tags ---- */
.pe-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pe-tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface-alt); color: var(--ink-soft); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pe-tag-review, .pe-tag-wait { border-color: transparent; background: var(--warning-bg); color: var(--warning-fg); }
.pe-tag-open { border-color: transparent; background: var(--violet-bg); color: var(--violet); }
.pe-tag-draft { border-color: transparent; background: var(--info-bg); color: var(--info); }
.pe-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---- view 2: list beside model ---- */
.pe-work { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(320px, 372px) minmax(0, 1fr); gap: var(--sp-3); padding: var(--sp-3); padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom)); }
.pe-panel { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.pe-panel-head { flex: none; display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3) var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--line); }
.pe-h2 { margin: 0; font-size: 17px; font-weight: 600; }
.pe-count-pill { margin-right: auto; min-width: 26px; padding: 1px 8px; border-radius: var(--r-pill); background: var(--surface-alt); border: 1px solid var(--line); color: var(--ink-soft); font-size: 13px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.pe-note { margin: 0; padding: var(--sp-3) var(--sp-4); font-size: 14px; border-bottom: 1px solid var(--line); }
.pe-note-warn { background: var(--warning-bg); color: var(--ink); }
.pe-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.pe-empty-list { margin: 0; padding: var(--sp-5) var(--sp-4); color: var(--ink-soft); text-align: center; }

.pe-parts { margin: 0; padding: 0; list-style: none; }
.pe-part { display: grid; grid-template-columns: 44px minmax(0, 1fr) 48px; align-items: center; border-bottom: 1px solid var(--line); background: var(--surface); }
.pe-part.is-selected { background: var(--brand-soft); box-shadow: inset 4px 0 0 var(--brand); }
.pe-part.is-dragging { position: relative; z-index: 1; background: var(--surface-alt); box-shadow: var(--shadow); }
.pe-part-main, .pe-prop-text { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--sp-3); min-height: 60px; padding: var(--sp-2) var(--sp-1); border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.pe-part-text { display: grid; gap: 2px; min-width: 0; }
.pe-part-name { display: flex; align-items: baseline; gap: var(--sp-2); min-width: 0; }
.pe-part-name strong, .pe-part-text > strong { font-weight: 600; overflow-wrap: anywhere; }
.pe-qty { flex: none; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.pe-no { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-solid); color: var(--acc-ink); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pe-no-open { background: var(--surface); color: var(--violet); border: 2px dashed var(--violet); }

.pe-props { margin: var(--sp-3); padding: var(--sp-3); border: 1px dashed var(--violet); border-radius: var(--r); background: var(--surface-alt); }
.pe-h3 { margin: 0 0 2px; font-size: 15px; font-weight: 600; }
.pe-props > .pe-meta { margin: 0 0 var(--sp-2); }
.pe-prop-list { margin: 0; padding: 0; list-style: none; }
.pe-prop { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0; border-top: 1px solid var(--line); }
.pe-prop-text { flex: 1 1 170px; min-height: 44px; padding: 0; }
.pe-prop-actions { display: flex; gap: var(--sp-2); margin-left: auto; }

/* the home of the rare actions on a phone; on wider screens they sit in the head and the model toolbar */
.pe-list-foot { display: none; }
.pe-foot-row { display: flex; align-items: center; gap: var(--sp-3); }
.pe-foot-file { flex: 1 1 0; min-width: 0; margin: 0; overflow-wrap: anywhere; }

/* ---- model panel: tools, the hint line, the model, then the file's name ---- */
.pe-toolbar { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line); }
.pe-tools-right { display: flex; align-items: center; gap: var(--sp-2); }
.pe-seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-alt); }
.pe-seg-btn { min-height: 44px; min-width: 44px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-soft); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; }
.pe-seg-btn[aria-pressed="true"] { background: var(--brand-solid); color: var(--acc-ink); }
.pe-seg-btn:disabled { opacity: .5; cursor: not-allowed; }
.pe-hint-row { position: relative; flex: none; background: var(--surface-alt); border-bottom: 1px solid var(--line); }
.pe-hint { margin: 0; padding: var(--sp-2) var(--sp-4); min-height: 56px; display: flex; align-items: center; color: var(--ink-soft); font-size: 14px; }
/* nothing on the model can be selected as text or called out by a long press: a gloved press is a press */
.pe-stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: var(--surface-alt); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pe-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.pe-stage[data-mode="place"] .pe-canvas { cursor: crosshair; }
.pe-stage[data-mode="link"] .pe-canvas { cursor: pointer; }
.pe-empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: var(--sp-2); padding: var(--sp-5); text-align: center; }
.pe-empty > .pe-ic { width: 44px; height: 44px; stroke-width: 1.4; color: var(--ink-muted); }
.pe-empty-title { margin: 0; font-size: 17px; font-weight: 600; }
.pe-empty-text { margin: 0 0 var(--sp-2); max-width: 36ch; color: var(--ink-soft); font-size: 15px; }
.pe-loading { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; color: var(--ink-soft); }
/* the model file's name: a quiet strip under the model, never on it */
.pe-file-line { flex: none; margin: 0; padding: 6px var(--sp-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-top: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; }

/* marks: numbered buttons laid over the canvas; the visible disc is 28 px inside a 44 px target.
 * clip, not hidden: a focused mark near the edge must never scroll the layer away from the model under it */
.pe-pins { position: absolute; inset: 0; pointer-events: none; overflow: hidden; overflow: clip; }
.pe-pin { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; border-radius: 50%; background: transparent; font: inherit; pointer-events: auto; touch-action: none; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pe-pin:focus-visible { outline-offset: -2px; }
.pe-pin-dot { display: grid; place-items: center; width: 28px; height: 28px; border: 2px solid var(--surface); border-radius: 50%; background: var(--brand-solid); color: var(--acc-ink); box-shadow: var(--shadow); font-size: 14px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pe-pin.is-open .pe-pin-dot { border: 2px dashed var(--violet); background: var(--surface); color: var(--violet); box-shadow: none; }
/* one number standing for two marks of the same part that sit together: a second edge shows behind it */
.pe-pin.is-stack .pe-pin-dot { box-shadow: 5px 4px 0 -1px var(--surface), 5px 4px 0 1px var(--brand-solid), var(--shadow); }
.pe-pin.is-open.is-stack .pe-pin-dot { box-shadow: 5px 4px 0 -1px var(--surface), 5px 4px 0 1px var(--violet); }
.pe-pin.is-selected { z-index: 1; }
.pe-pin.is-selected .pe-pin-dot { width: 32px; height: 32px; box-shadow: 0 0 0 3px var(--amber-action), var(--shadow); }
.pe-pin.is-selected.is-stack .pe-pin-dot { box-shadow: 0 0 0 3px var(--amber-action), 8px 6px 0 0 var(--surface), 8px 6px 0 2px var(--brand-solid), var(--shadow); }
.pe-pin.is-back { opacity: .45; }
.pe-pin.is-dragging { z-index: 2; cursor: grabbing; }
.pe-pin.is-dragging .pe-pin-dot { width: 36px; height: 36px; box-shadow: 0 0 0 3px var(--amber-action), var(--shadow-lg); }

/* ---- T66b-2: placing a mark with the keyboard ----
 * The model with keyboard focus shows its ring just inside its edge (a ring outside would be cut off by the panel).
 * The crosshair is drawn in the ink colour with an edge in the surface colour, so it stands out on any model in both
 * themes. The ring is the size of a mark's 44 px target. It takes no press, and it is in the page only while the
 * model has keyboard focus. Off the model (nothing there to mark) it is faint and its ring is dashed. */
.pe-canvas:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.pe-cross { position: absolute; left: 0; top: 0; z-index: 3; width: 0; height: 0; pointer-events: none; }
.pe-cross-ring { position: absolute; left: -20px; top: -20px; width: 40px; height: 40px; border: 2px solid var(--ink); border-radius: 50%; box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 2px var(--surface); }
.pe-cross-dot { position: absolute; left: -2px; top: -2px; width: 4px; height: 4px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); }
.pe-cross::before, .pe-cross::after, .pe-cross-dot::before, .pe-cross-dot::after { content: ""; position: absolute; border-radius: 1px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); }
.pe-cross::before, .pe-cross::after { top: -1px; width: 14px; height: 2px; }
.pe-cross::before { left: -40px; }
.pe-cross::after { left: 26px; }
.pe-cross-dot::before, .pe-cross-dot::after { left: 1px; width: 2px; height: 14px; }
.pe-cross-dot::before { top: -38px; }
.pe-cross-dot::after { top: 28px; }
.pe-cross.is-miss { opacity: .55; }
.pe-cross.is-miss .pe-cross-ring { border-style: dashed; }
.pe-hint.is-keys { color: var(--ink); }
.pe-key { font: inherit; font-weight: 700; }

/* ---- dialogs ---- */
.pe-dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); font: inherit; }
.pe-dialog[open] { display: flex; flex-direction: column; }
.pe-dialog::backdrop { background: var(--scrim); }
.pe-dialog-title { margin: 0; padding: var(--sp-4) var(--sp-4) var(--sp-2); font-size: 18px; font-weight: 600; }
.pe-dialog-text { margin: 0; padding: 0 var(--sp-4); color: var(--ink-soft); }
.pe-dialog-text + .pe-dialog-text { margin-top: var(--sp-3); }
.pe-dialog-body { display: grid; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4) 0; overflow: auto; }
.pe-dialog-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4); }
.pe-field-hint { font-size: 13px; color: var(--ink-soft); }
.pe-fixed { margin: 0; }
.pe-summary { padding: 11px 0; color: var(--brand-hover); font-weight: 600; cursor: pointer; }
[data-theme="dark"] .pe-summary { color: var(--brand); }
.pe-lang-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); padding-bottom: var(--sp-2); }
.pe-error { margin: 0; color: var(--danger-fg); font-size: 14px; font-weight: 600; }

/* ---- message line ----
 * With a machine open it lies exactly over the hint line above the model (and grows down a little for a long
 * sentence), so it never covers the list or a control. On the machine list it floats at the foot of the screen.
 * Dark on light and light on dark: the ink and the surface swap, so it stands out in both themes. */
.pe-toast { margin: 0; background: var(--ink); color: var(--surface); font-size: 14px; font-weight: 600; line-height: 1.35; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }
.pe-toast.is-on { opacity: 1; }
.pe-hint-row > .pe-toast { position: absolute; left: 0; right: 0; top: 0; z-index: 2; display: flex; align-items: center; min-height: 100%; padding: var(--sp-2) var(--sp-4); box-shadow: var(--shadow); }
.pe-root > .pe-toast { position: absolute; left: 50%; bottom: calc(var(--sp-4) + env(safe-area-inset-bottom)); z-index: 3; transform: translateX(-50%); width: max-content; max-width: min(560px, calc(100vw - 32px)); padding: var(--sp-3) var(--sp-4); border-radius: var(--r); box-shadow: var(--shadow-lg); font-size: 15px; font-weight: 400; }

/* ---- a mouse over a control (never on touch, where a hover would stick) ---- */
@media screen and (hover: hover) {
  .pe-btn:not(:disabled):hover { background: var(--surface-alt); }
  .pe-btn-primary:not(:disabled):hover { background: var(--brand-solid-hover); }
  .pe-btn-danger:not(:disabled):hover { background: var(--danger-solid); }
  .pe-icon-btn:not(:disabled):hover { color: var(--ink); background: var(--surface-alt); }
  .pe-machine:hover { background: var(--surface-alt); }
  .pe-seg-btn[aria-pressed="false"]:not(:disabled):hover { color: var(--ink); }
}

/* ---- PC ---- */
@media screen and (min-width: 1300px) {
  .pe-work { grid-template-columns: 420px minmax(0, 1fr); gap: var(--sp-4); padding: var(--sp-4); }
  .pe-hint { min-height: 40px; }
}

/* ---- upright tablet and anything narrower: model on top, list under it ---- */
@media screen and (max-width: 899px) {
  .pe-work { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(300px, 60%) minmax(0, 1fr); }
  .pe-hint { min-height: 40px; }
  .pe-model-panel { grid-row: 1; }
  .pe-list-panel { grid-row: 2; }
}

/* ---- phone ---- */
@media screen and (max-width: 700px) {
  /* head: back, name, Save in one row; the draft status sits under the name */
  .pe-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 0 var(--sp-3); padding-left: var(--sp-3); padding-right: var(--sp-3); }
  .pe-back { grid-column: 1; grid-row: 1 / span 2; padding: 0; }
  .pe-back span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .pe-title { grid-column: 2; grid-row: 1; }
  .pe-head-actions { display: contents; }
  .pe-chip { grid-column: 2; grid-row: 2; justify-self: start; max-width: 100%; padding: 0; background: transparent; }
  .pe-head-actions .pe-bar-btn-primary { grid-column: 3; grid-row: 1 / span 2; }
  .pe-banner { padding: var(--sp-2) var(--sp-3); font-size: 13px; }

  .pe-work { gap: var(--sp-2); padding: var(--sp-2); padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom)); grid-template-rows: minmax(280px, 62%) minmax(0, 1fr); }
  .pe-root:has(> .pe-banner:not([hidden])) .pe-work { grid-template-rows: minmax(220px, 48%) minmax(0, 1fr); } /* FX-2: a locked list is for reading, and the notice above takes room too: the list gets half the height (it had about 120 px) */
  .pe-pick { padding: var(--sp-3); }

  /* model tools: the three modes and Reset view share one row above the model; nothing sits on the model */
  .pe-toolbar { padding: 6px var(--sp-2); }
  .pe-hint { min-height: 48px; padding: 6px var(--sp-3); font-size: 13px; line-height: 1.35; }
  .pe-panel-head { padding-left: var(--sp-3); }

  .pe-lang-grid { grid-template-columns: minmax(0, 1fr); }
  .pe-dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r) var(--r) 0 0; border-width: 1px 0 0; }
  .pe-dialog-actions { padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }
}

/* ---- a phone, upright or on its side: the rare actions live at the end of the list, the tools share one row ---- */
@media screen and (max-width: 700px), screen and (orientation: landscape) and (min-width: 560px) and (max-width: 1023px) and (max-height: 520px) {
  .pe-head-discard, .pe-tool-model, .pe-file-line { display: none; }
  .pe-seg { display: flex; flex: 1 1 auto; }
  .pe-seg-btn { flex: 1 1 auto; padding: 0 6px; font-size: 14px; }
  .pe-tools-right { margin-left: auto; }
  .pe-tools-right .pe-btn { padding: 0 var(--sp-2); font-size: 14px; }
  .pe-hint-row > .pe-toast { padding: 6px var(--sp-3); font-size: 13px; }
  .pe-list-foot { display: grid; justify-items: start; gap: var(--sp-1); margin: var(--sp-4) var(--sp-3) var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
  .pe-foot-row { width: 100%; }
  .pe-list-foot .pe-btn-danger-quiet { margin-left: calc(var(--sp-4) * -1); }
}

/* ---- on its side and short (a phone on its side): the model left, the list right, as in pick-a-part; tighter bars ---- */
@media screen and (orientation: landscape) and (min-width: 560px) and (max-width: 1023px) and (max-height: 520px) {
  .pe-head { padding-top: max(2px, env(safe-area-inset-top)); padding-bottom: 2px; padding-left: max(var(--sp-3), env(safe-area-inset-left)); padding-right: max(var(--sp-3), env(safe-area-inset-right)); }
  .pe-h1 { font-size: 16px; }
  .pe-banner { padding: var(--sp-1) max(var(--sp-3), env(safe-area-inset-right)) var(--sp-1) max(var(--sp-3), env(safe-area-inset-left)); font-size: 13px; }
  .pe-work { grid-template-columns: minmax(0, 1fr) clamp(260px, 42%, 400px); grid-template-rows: minmax(0, 1fr); gap: var(--sp-2); padding: 6px max(var(--sp-2), env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(var(--sp-2), env(safe-area-inset-left)); }
  .pe-model-panel { grid-column: 1; grid-row: 1; }
  .pe-list-panel { grid-column: 2; grid-row: 1; }
  .pe-toolbar { padding: var(--sp-1) var(--sp-2); }
  .pe-hint { min-height: 44px; padding: var(--sp-1) var(--sp-3); font-size: 13px; line-height: 1.35; }
  .pe-hint-row > .pe-toast { padding: var(--sp-1) var(--sp-3); }
  .pe-panel-head { padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-3); }
  .pe-part-main { min-height: 52px; padding-top: var(--sp-1); padding-bottom: var(--sp-1); }
  .pe-list-foot { margin-top: var(--sp-3); }
  .pe-empty { gap: var(--sp-1); padding: var(--sp-2); }
  .pe-empty > .pe-ic { display: none; }
  .pe-empty-text { margin-bottom: var(--sp-1); font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) { .pe-toast { transition: none; } }
@media print { .pe-root { display: none !important; } }
