/* WaferFlow styles: three-panel layout (library, runsheet, info). */

/* "Thin Film" theme: cobalt accent, magenta counterpoint, near-white surfaces with
   soft contours (light), deep blue-black with lifted panels (dark). The structure follows
   the Virtual SEM design system: a panel surface, a light header surface (--bar-*),
   one accent plus one counterpoint, small state colours. */
:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e3e7ee;
  --border-strong: #b0b6c4;
  --text: #242b3f;
  --text-muted: #555e75;
  --accent: #2453c4;
  --accent-hover: #1d45a6;
  --accent-soft: #ecf1fc;
  --on-accent: #ffffff;
  --accent-2: #ad2872;
  --accent-2-soft: #fbecf4;
  --bar-bg: #f0f3fb;
  --bar-text: #2f3850;
  --bar-muted: #555e75;
  --bar-line: #c9cfdc;
  --bar-hover: rgba(36, 83, 196, 0.07);
  --bar-pressed: rgba(36, 83, 196, 0.12);
  --bar-cta: #2453c4;
  --bar-cta-hover: #1d45a6;
  --bar-cta-text: #ffffff;
  --danger: #c2342b;
  --danger-soft: #fbebea;
  --success: #1f7543;
  --success-soft: #eaf6ef;
  --status-uncertain: #fdf5e5;
  --status-uncertain-text: #694200;
  /* Text fields and selects: a boundary of at least 3:1 (buttons and cards keep --border-strong). */
  --control-border: #7f889d;
  /* Select arrow in the --text-placeholder colour (VIS5-5). */
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23687087' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  --side-fs: #e7f5f8;
  --side-fs-text: #074e5e;
  --side-fs-line: #2f8497;
  --side-bs: #fbecf4;
  --side-bs-text: #6e1347;
  --side-bs-line: #c25e95;
  --focus: #2453c4;
  --icon: #2453c4;
  --icon-strong: #173580;
  --warning-text: #694200;
  --warning-soft: #fdf5e5;
  --warning-border: #d9a441;
  /* Amber marks that carry meaning alone (dots, bars, ticks): at least 3:1 on the surfaces. */
  --warning-mark: #a8741a;
  /* Text of a pressed toggle / segment (on --bar-pressed or --accent-soft). */
  --pressed-text: #2453c4;
  --metro: #ad2872;
  --shadow-pop: 0 6px 20px rgba(15, 18, 27, 0.16);
  --shadow-1: 0 1px 4px rgba(15, 18, 27, 0.08);
  /* Motion: one short duration and an ease-out curve for hover / press colour changes. */
  --dur-1: 120ms;
  /* Enter (dialogs, the message), the flash fade and the spotlight pulse (COL4-9). */
  --dur-2: 160ms;
  --dur-flash: 900ms;
  --dur-pulse: 1200ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  /* One disabled look for every control (VIS4-10 / COL4-5). */
  --disabled-opacity: 0.45;
  /* Placeholder text: lighter than --text-muted, still >= 4.5:1 (COL4-4). */
  --text-placeholder: #687087;
  --backdrop: rgba(15, 18, 27, 0.45);
  --topbar-h: 50px;
  --message-h: 0px;
  --radius: 4px;
  --radius-card: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
  /* Native checkboxes, radios and ranges in the accent (not the browser's own blue). */
  accent-color: var(--accent);
  color-scheme: light;
}

/* Dark theme: js/theme.js sets data-theme on <html> from the saved choice or the system setting. */
:root[data-theme="dark"] {
  --bg: #0f121b;
  --surface: #171b27;
  --surface-2: #1d2231;
  --border: #262c3d;
  --border-strong: #47506a;
  --text: #d3d8e6;
  --text-muted: #959db3;
  --accent: #7aa2ff;
  --accent-hover: #9bb9ff;
  --accent-soft: #1a2645;
  --on-accent: #0b1430;
  --accent-2: #f075b5;
  --accent-2-soft: #3b1930;
  --bar-bg: #1f2536;
  --bar-text: #e3e7f2;
  --bar-muted: #959db3;
  --bar-line: #3a425a;
  --bar-hover: rgba(122, 162, 255, 0.09);
  --bar-pressed: rgba(122, 162, 255, 0.24);
  --bar-cta: #7aa2ff;
  --bar-cta-hover: #9bb9ff;
  --bar-cta-text: #0b1430;
  --danger: #f06d64;
  --danger-soft: #391e20;
  --success: #55c784;
  --success-soft: #163126;
  --status-uncertain: #332917;
  --status-uncertain-text: #f6ddb0;
  --control-border: #6a7390;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23848ca3' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  --side-fs: #142e38;
  --side-fs-text: #c4eef6;
  --side-fs-line: #4cc3db;
  --side-bs: #3b1930;
  --side-bs-text: #ffd0e8;
  --side-bs-line: #f075b5;
  --focus: #7aa2ff;
  --icon: #7aa2ff;
  --icon-strong: #d3dfff;
  --warning-text: #f6ddb0;
  --warning-soft: #332917;
  --warning-border: #a57a2c;
  --warning-mark: #c99a45;
  --pressed-text: #9bb9ff;
  --metro: #f075b5;
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-1: 0 1px 4px rgba(0, 0, 0, 0.4);
  --text-placeholder: #848ca3;
  --backdrop: rgba(5, 7, 12, 0.65);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
}

h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Buttons and inputs */

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.btn, .icon-btn, .sv-seg-btn, .wafer-view-btn, .fam-head, .menu-item, .side-btn, .sv-btn, .sv-tab, .col-tab {
  transition: background-color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
/* Hover is neutral (the accent is kept for focus, selection and the open step). */
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-muted); }
.btn:active:not(:disabled) { background: var(--bar-pressed); }
.btn:disabled { opacity: var(--disabled-opacity); cursor: not-allowed; }
::placeholder { color: var(--text-placeholder); opacity: 1; }
.btn-small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
/* Dialog footers: one 30 px button size. */
.sv-modal-foot .btn { min-height: 30px; padding: 4px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
/* "Generate" with missing fields stays a full-strength primary (it still explains what is missing; the
   status button beside it carries the state). No transparency: white on 60 % cobalt failed AA (COL4-3). */
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover:not(:disabled) { border-color: transparent; background: var(--bar-hover); }
/* Icon-only buttons with a text-button height (Undo / Redo). */
.btn-icon { justify-content: center; min-width: 28px; padding-left: 4px; padding-right: 4px; }
.btn-icon .rs-icon { width: 16px; height: 16px; }

/* Process-kind icons (js/icons.js) */

.icon-slot {
  flex: none;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  background: var(--fam-bg, transparent);
  color: var(--fam-fg, var(--icon));
}
.icon-slot.icon-strong { font-weight: 600; }
.icon-slot.fam-substrate { --fam-bg: #ececee; --fam-fg: #5c5d61; }
.icon-slot.fam-litho { --fam-bg: #eceff7; --fam-fg: #3d4f8a; }
.icon-slot.fam-deposition { --fam-bg: #e2f2ee; --fam-fg: #2f7a69; }
.icon-slot.fam-etch { --fam-bg: #e0ebf2; --fam-fg: #226384; }
.icon-slot.fam-clean { --fam-bg: #dcf5f7; --fam-fg: #087f88; }
.icon-slot.fam-metrology { --fam-bg: #fbecf4; --fam-fg: #ad2872; }
.icon-slot.fam-backend { --fam-bg: #f3ece2; --fam-fg: #7a5a2c; }
:root[data-theme="dark"] .icon-slot.fam-substrate { --fam-bg: #232838; --fam-fg: #c3c9da; }
:root[data-theme="dark"] .icon-slot.fam-litho { --fam-bg: #20263a; --fam-fg: #b3bde0; }
:root[data-theme="dark"] .icon-slot.fam-deposition { --fam-bg: #183630; --fam-fg: #8fd6c5; }
:root[data-theme="dark"] .icon-slot.fam-etch { --fam-bg: #15303f; --fam-fg: #8cc4e3; }
:root[data-theme="dark"] .icon-slot.fam-clean { --fam-bg: #10363a; --fam-fg: #7fe3ea; }
:root[data-theme="dark"] .icon-slot.fam-metrology { --fam-bg: var(--accent-2-soft); --fam-fg: var(--accent-2); }
:root[data-theme="dark"] .icon-slot.fam-backend { --fam-bg: #3a2e1d; --fam-fg: #e0c08f; }
.rs-icon { display: block; width: 16px; height: 16px; }
.fam-head { display: flex; align-items: center; gap: 6px; width: 100%; padding: 7px 8px; border: 0; border-bottom: 1px solid var(--border); background: transparent; cursor: pointer; text-align: left; font-weight: 600; font-size: 13px; }
.fam-head:hover { background: var(--surface-2); }
.fam-head.open .chevron-text { transform: rotate(90deg); }
.fam-head .chevron-text { display: inline-flex; transition: transform var(--dur-1) var(--ease-out); }
.fam-swatch { width: 8px; height: 8px; border-radius: 50%; background: var(--fam-fg, var(--border-strong)); opacity: 0.8; }
.family-body { padding-left: 8px; }
.icon-btn.collapse-btn { width: 18px; height: 18px; margin: 0; padding: 0; font-size: 10px; }
.collapse-spacer { flex: none; width: 18px; }
.tool-link { flex: none; font-size: 12px; font-weight: 500; color: var(--accent); text-decoration: none; }
.tool-link:hover { text-decoration: underline; }
.brand-mark { flex: none; display: inline-flex; align-items: center; gap: 8px; }

.icon-btn {
  flex: none;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px; line-height: 1;
}
.icon-btn:hover:not(:disabled) { border-color: transparent; color: var(--text); background: var(--bar-hover); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.chevron { font-size: 11px; transition: transform var(--dur-1) var(--ease-out); }
/* Shared SVG line icons (js/icons.js): chevrons, close, carets, grip, minus / plus, trash. */
.ui-icon { display: block; flex: none; }
.icon-btn.danger { color: var(--text-muted); }
.chevron.open { transform: rotate(90deg); }

input[type="text"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
/* Themed select arrow (the native one was black in light mode and differed per OS, VIS5-5). */
select:not([multiple]):not([size]) { appearance: none; -webkit-appearance: none; padding-right: 26px; background: var(--surface) var(--select-arrow) no-repeat right 8px center / 12px 12px; }
select:disabled { opacity: var(--disabled-opacity); }
textarea { resize: vertical; font-size: 13px; }
@media (hover: hover) and (pointer: fine) { textarea.mono { font-size: 12px; } }
/* Process details mirror the fixed-format runsheet text. */
textarea.mono { font-family: var(--mono); }
/* Invalid: a 2 px danger edge, no fill (the placeholder keeps AA on --surface, COL5-5). */
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }

/* Top bar */

.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 16px;
  min-width: 0;
  background: var(--bar-bg);
  color: var(--bar-text);
  border-bottom: 1px solid var(--border);
}
.topbar .runsheet-name { color: var(--bar-text); }
.topbar .btn { background: transparent; border-color: transparent; color: var(--bar-text); }
.topbar .btn:hover:not(:disabled) { background: var(--bar-hover); border-color: transparent; }
/* Panel toggles: one segmented control; pressed = panel shown and expanded. */
.topbar-seg { display: inline-flex; border: 1px solid var(--bar-line); border-radius: var(--radius); overflow: hidden; }
.topbar-seg > .btn { border: none; border-radius: 0; }
.topbar-seg > .btn + .btn { border-left: 1px solid var(--bar-line); }
.topbar-seg > .btn[aria-pressed="true"] { background: var(--bar-pressed); color: var(--pressed-text); }
.topbar-seg > .btn[hidden] + .btn { border-left: none; }
.topbar .btn-primary { background: var(--bar-cta); border-color: var(--bar-cta); color: var(--bar-cta-text); }
.topbar .btn-primary:hover:not(:disabled) { background: var(--bar-cta-hover); border-color: var(--bar-cta-hover); }
.topbar .btn-primary.blocked { background: var(--bar-cta); border-color: var(--bar-cta); color: var(--bar-cta-text); }
.generate-reason { padding: 2px 4px; border: 0; border-radius: var(--radius); background: none; font: inherit; font-size: 12px; color: var(--bar-muted); white-space: nowrap; cursor: pointer; }
.generate-reason:hover { color: var(--bar-text); text-decoration: underline; }
.generate-reason:empty { display: none; }
.generate-reason.sv-ico::before { background: var(--warning-mark); margin-right: 4px; }
.topbar :focus-visible { outline-color: var(--focus); }
.brand { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-name { font-weight: 700; font-size: 15px; white-space: nowrap; }
.runsheet-name {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { flex: none; display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }
.runsheet-name.untitled { font-family: var(--font); }
.menu-caret { display: inline-flex; margin-left: 4px; opacity: 0.7; }
.topbar .menu[open] > summary { background: var(--bar-pressed); border-color: transparent; }
.topbar .menu-list { color: var(--text); }
.menu-check { gap: 8px; }
.sub-layers { display: flex; flex-direction: column; gap: 6px; }
.sub-layer { display: grid; grid-template-columns: 18px 1fr 1fr 28px; gap: 6px; align-items: center; }
.sub-layer-n { font-size: 11px; color: var(--text-muted); text-align: right; font-variant-numeric: tabular-nums; }
.sub-layer-acts { display: flex; gap: 12px; align-items: center; }
.menu-select { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.menu-select select { font-size: 12px; }
@media (max-width: 720px) { .menu-select select { font-size: 16px; } }
.menu-check input { margin: 0; }
.menu-sub { padding: 4px 10px 0; font-size: 11px; color: var(--text-muted); }
/* Help → Theme: Light / Dark / Auto (js/theme.js); the chosen one carries a check mark. */
.theme-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 4px 6px 4px 10px; }
.theme-row-label { font-size: 13px; color: var(--text); }
.theme-opts { display: inline-flex; border: 1px solid var(--control-border); border-radius: var(--radius); overflow: hidden; }
.theme-opt { width: 32px; height: 28px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; background: transparent; color: var(--text-muted); font-size: 14px; cursor: pointer; }
.theme-opt + .theme-opt { border-left: 1px solid var(--border); }
.theme-opt:hover { background: var(--surface-2); color: var(--text); }
.theme-opt[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
@media (pointer: coarse) { .theme-opt { width: 44px; height: 40px; } }
.checks-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--success); }
.checks-badge.checks-warning .checks-dot { background: var(--warning-mark); }
.checks-badge.checks-error .checks-dot { background: var(--danger); }
/* Checks still running: a muted, softly pulsing dot (the label never changes width). */
.checks-badge[aria-busy="true"] .checks-dot { background: var(--text-muted); animation: checks-pulse var(--dur-pulse) var(--ease-out) infinite alternate; }
@keyframes checks-pulse { from { opacity: 1; } to { opacity: 0.3; } }
.checks-count { min-width: 2ch; margin-left: 6px; padding: 0 5px; border-radius: 8px; background: var(--bar-pressed); font-size: 11px; font-weight: 600; text-align: center; }
.checks-count:empty { display: none; }

.message {
  flex: none;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
}
/* Desktop: the message floats over the panels under the top bar (nothing moves when it
   appears or leaves). Phones keep the sticky strip (touch section below). */
@media (min-width: 721px) and (min-height: 501px), (min-width: 1001px) {
  .message {
    /* Centred over the runsheet when the viewer is docked beside it (--msg-left / --msg-max set by JS, UX5-9). */
    position: fixed; z-index: 40; top: auto; bottom: 16px; left: var(--msg-left, 50%); transform: translateX(-50%);
    width: max-content; max-width: min(640px, var(--msg-max, calc(100vw - 32px))); max-height: 50vh; overflow-y: auto;
    padding: 6px 8px 6px 14px; align-items: center;
    border: 1px solid var(--border-strong); border-radius: var(--radius-card); box-shadow: var(--shadow-pop);
  }
}
.message:not([hidden]) { animation: msg-in var(--dur-2) var(--ease-out); }
/* Leaving: no clicks on an Undo that is fading out (COL4-9). */
.message.leaving { opacity: 0; pointer-events: none; transition: opacity var(--dur-1) var(--ease-out); }
@keyframes msg-in { from { opacity: 0; } }
.message ul { margin: 0; padding-left: 18px; flex: 1; }
.message > span { font-weight: 600; }
.message-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.message .message-actions .btn { margin-left: 0; }
.message-info { background: var(--accent-soft); color: var(--text); }
.message-error { background: var(--danger-soft); color: var(--danger); }
.message-success { background: var(--success-soft); color: var(--success); }

/* Layout */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--col-lib, minmax(260px, 300px)) minmax(420px, 1fr) var(--col-info, minmax(300px, 360px));
}

.panel {
  min-height: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.panel-runsheet { background: var(--bg); }
.panel-info { border-right: none; }

.panel-head, .section-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px;
  min-height: 38px;
}
.panel-head { border-bottom: 1px solid var(--border); }
.col-tabs { display: none; align-self: stretch; margin: -8px 0 -9px -4px; min-width: 0; flex: 0 1 auto; gap: 8px; }
.col-tab { padding: 0 10px; border: none; border-bottom: 2px solid transparent; background: transparent; color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; white-space: nowrap; min-width: 0; }
/* Narrow left column: the two tab names ("Process library", "Runsheet info") wrap instead of pushing
   the collapse and close buttons out of the column. */
.col-tab { padding: 0 6px; white-space: normal; line-height: 1.15; text-align: left; }
.col-tab:hover { color: var(--text); }
.col-tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.runsheet-actions { align-items: center; }
.btn-glyph { font-size: 15px; line-height: 1; }
.section-head { padding: 10px 0 6px; }
.section-actions { display: flex; gap: 4px; flex-wrap: wrap; }

.panel-tools { flex: none; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px 16px; }

.empty { color: var(--text-muted); margin: 8px 0; }

/* Library */

.category { margin-bottom: 2px; }
.cat-head {
  width: 100%;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 4px;
  border: none; border-radius: var(--radius);
  background: transparent;
  text-align: left; font-weight: 600;
  cursor: pointer;
}
.cat-head:hover { background: var(--surface-2); }
.chevron-text { display: inline-flex; font-size: 10px; color: var(--text-muted); transition: transform var(--dur-1) var(--ease-out); }
.cat-head.open .chevron-text { transform: rotate(90deg); }
.cat-name { flex: 1; }
.flow-count { flex: none; font-size: 11px; color: var(--text-muted); font-weight: 400; }

.flow-list, .flow-steps { list-style: none; margin: 0; padding: 0; }
.flow-list { padding: 2px 0 6px 14px; }

/* Flow rows: no box, a neutral hover fill (like the family rows above them). */
.flow-card {
  margin: 2px 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
}
.flow-head {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 4px;
  border-radius: var(--radius);
  cursor: grab;
}
.flow-head:hover { background: var(--surface-2); }
.flow-card.open { background: var(--surface-2); }
.flow-head > .chevron.no-steps { visibility: hidden; }
/* Fine pointer: the handle and "+" appear on hover or focus (touch keeps them visible). */
@media (hover: hover) and (pointer: fine) {
  .flow-head > .drag-handle, .lib-step > .drag-handle,
  .flow-head > .icon-btn:last-child, .lib-step > .icon-btn:last-child { opacity: 0; transition: opacity var(--dur-1) var(--ease-out); }
  .flow-head:hover > .drag-handle, .flow-head:focus-within > .drag-handle, .lib-step:hover > .drag-handle, .lib-step:focus-within > .drag-handle,
  .flow-head:hover > .icon-btn:last-child, .flow-head:focus-within > .icon-btn:last-child,
  .lib-step:hover > .icon-btn:last-child, .lib-step:focus-within > .icon-btn:last-child { opacity: 1; }
}
.flow-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }

.flow-steps { padding: 2px 0; }
.lib-step {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 8px;
  cursor: grab;
}
.lib-step.sub { padding-left: 24px; }
.lib-step:hover { background: var(--bar-hover); }
.lib-step.hit .lib-step-name { font-weight: 600; color: var(--text); }
.lib-step-name { flex: 1; min-width: 0; font-size: 12px; overflow-wrap: anywhere; }

.drag-handle {
  flex: none;
  width: 14px;
  color: var(--text-muted);
  font-size: 14px; line-height: 1;
  text-align: center;
  cursor: grab;
  user-select: none;
}

.myflows { flex: none; max-height: 35%; overflow-y: auto; padding: 0 12px 8px; border-top: 1px solid var(--border); }
.myflows .flow-list { padding-left: 0; }


/* Runsheet canvas */

.runsheet-body { padding: 12px 16px 24px; }

.fixed-block {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text-muted);
}
.fixed-title { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text); }
.fixed-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.fixed-name { font-weight: 500; color: var(--text); }
.fixed-detail { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fixed-hint { font-size: 12px; }

.step-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  min-height: 80px;
  /* The step rows and the editor size themselves by the runsheet column, not the window. */
  container: steps / inline-size;
}
/* Empty plan: a light drop zone with one line (VIS4-15). */
.step-list:empty {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-card);
  min-height: 96px;
}
.step-list:empty::before {
  content: "Drag steps from the Library here or press their +, or start from a template (File ▾).";
  max-width: 420px; padding: 0 12px;
  text-align: center;
  color: var(--text-muted);
}
@media (pointer: coarse) { .step-list:empty::before { content: "Tap + on a Library step, or start from a template (New from template)."; } }

.step-card {
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.step-card.level-1 { margin-left: 24px; }
/* Status: a 3 px bar at the left edge (amber = uncertain, grey = custom) next to the badge. */
.step-card.status-uncertain { box-shadow: inset 3px 0 0 var(--warning-mark); }
.step-card.status-custom { box-shadow: inset 3px 0 0 var(--border-strong); }
.step-card.open { border-color: var(--accent); box-shadow: var(--shadow-1); }
.step-card.open.status-uncertain { box-shadow: inset 3px 0 0 var(--warning-mark), var(--shadow-1); }
.step-card.open.status-custom { box-shadow: inset 3px 0 0 var(--border-strong), var(--shadow-1); }
.step-card.sortable-ghost { opacity: 0.4; }
.step-list > .flow-card, .step-list > .lib-step { border: 1px dashed var(--accent); background: var(--accent-soft); }

.step-head { display: flex; align-items: center; gap: 6px; padding: 4px 6px; }
.step-head .drag-handle { font-size: 16px; }
/* Mouse / trackpad: the drag handle shows on the row under the pointer or with the focus in it. */
@media (hover: hover) {
  .step-head > .drag-handle { opacity: 0; transition: opacity var(--dur-1) var(--ease-out); }
  .step-card:hover > .step-head > .drag-handle, .step-card:focus-within > .step-head > .drag-handle { opacity: 1; }
}
/* Fine pointer: the handle sits in the card's left padding (out of the flow), so every row
   starts with the same 18 px chevron slot. Touch keeps the inline, always visible handle. */
@media (hover: hover) and (pointer: fine) {
  .step-card > .step-head { position: relative; padding-left: 14px; }
  .step-card > .step-head > .drag-handle { position: absolute; left: 1px; top: 50%; transform: translateY(-50%); width: 12px; }
}

.side-btn {
  flex: none;
  width: 30px;
  padding: 1px 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
}

.ps { flex: none; min-width: 28px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-muted); }

.step-toggle {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 1px 2px;
  border: none; background: transparent;
  text-align: left; cursor: pointer;
}
.step-name { font-weight: 500; overflow-wrap: anywhere; }
/* Title scale: section (14 px / 600) > module header (13 px / 600) > step (13 px / 500). */
.step-card.module-head .step-name { font-weight: 600; }
.step-detail {
  max-width: 100%;
  font-size: 12px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.badge {
  flex: none;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  text-transform: capitalize;
}
.badge-uncertain { background: var(--status-uncertain); color: var(--status-uncertain-text); box-shadow: inset 0 0 0 1px var(--warning-border); }
.badge-custom { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); }

.editor { padding: 8px 10px 10px; border-top: 1px solid var(--border); background: var(--surface-2); }
.editor-grid { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(96px, 1fr)); gap: 14px 8px; }
.editor-grid .field { gap: 4px; }
.editor-grid .wide { grid-column: 1 / -1; }
.editor-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.editor-actions .btn-danger, .editor-actions .editor-done { margin-left: auto; }

.wafer-editor { margin: 0; padding: 0; border: none; }
.wafer-editor legend { margin-bottom: 4px; padding: 0; font-size: 11px; font-weight: 600; color: var(--text-muted); }
.wafer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px 10px; }
.wafer-cell { display: flex; align-items: center; gap: 4px; }
.wafer-check { flex: none; display: flex; align-items: center; gap: 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.wafer-cell input[type="text"] { padding: 2px 4px; font-size: 12px; }

/* Forms (info panel) */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
/* One form scale: label 11 px / 600, 4 px above a 28 px / 13 px field (editor, Runsheet info, dialogs). */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.field-error { min-height: 0; font-size: 11px; color: var(--danger); }
.field-error:empty { display: none; }
#header-form .field:nth-child(-n+4) { grid-column: auto; }

/* Runsheet info: one line per wafer group (the Substrate details dialog edits it). */
.wafer-group { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.wafer-group-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.wafer-group-title { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.wafer-group-meta { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wafer-group-note { flex: none; font-size: 11px; color: var(--text-muted); cursor: help; }
.icon-btn:disabled { opacity: var(--disabled-opacity); cursor: default; }

/* Narrow screens */

@media (max-width: 1100px) {
  .layout { grid-template-columns: var(--col-lib, minmax(240px, 280px)) 1fr; grid-template-rows: max(480px, calc(100dvh - var(--topbar-h) - var(--message-h))) max-content; overflow-y: auto; }
  .panel-info { grid-column: 1 / -1; border-top: 1px solid var(--border); }
  .panel-info .panel-body { overflow: visible; }
  .editor-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 1280px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .topbar .app-name { display: none; }
}

@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .layout { display: block; overflow-y: auto; }
  .panel { max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
  .panel-body { overflow: visible; }
  .myflows { max-height: none; }
  .panel-head { flex-wrap: wrap; }
  /* Top bar: brand row + one scrollable row of actions (menus open as fixed sheets). */
  html, body { height: auto; }
  body { display: block; }
  /* Phone: review order (runsheet, cross-section, info), library last. */
  .layout, .layout.with-stack { display: flex; flex-direction: column; overflow: visible; }
  .panel-runsheet { order: 1; }
  .panel-stack { order: 2; }
  .panel-info { order: 3; }
  .panel-library { order: 4; }
  /* Scroll anchoring follows DOM order, where Library and Runsheet info come before
     the viewer: an anchor picked there made the page jump whenever the step notes
     under the player changed height while playing. Anchor in Runsheet / viewer only. */
  .panel-library, .panel-info { overflow-anchor: none; }
  .topbar { position: sticky; top: 0; z-index: 20; gap: 8px; padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
  .topbar .app-logo { width: 24px; height: 24px; }
  .brand { gap: 10px; }
  /* Pinned under the bar (top from --topbar-h, the measured bar height): with top: auto iOS Safari keeps
     the position it had when the menu opened and the menu drifts off screen as the page scrolls. */
  .topbar .menu-list { position: fixed; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); top: calc(var(--topbar-h) + 4px); min-width: 0; max-height: 70vh; overflow-y: auto; }
  .form-grid, .editor-grid, .layout.with-stack .editor-grid { grid-template-columns: 1fr; }
  .layout { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  /* Step cards: the name gets its own full-width line; tool link hidden. */
  .runsheet-body { padding: 8px 8px 16px; }
  .step-card.level-1 { margin-left: 12px; }
  .step-head { flex-wrap: wrap; row-gap: 2px; }
  .step-toggle { flex: 1 1 calc(100% - 100px); min-width: 14ch; order: 5; }
  .step-head .badge { order: 4; margin-left: auto; }
  .step-head .icon-btn.danger { order: 4; }
  .step-head .tool-link { display: none; }
  .step-head .step-thumb-wrap { order: 3; }
  .step-detail { white-space: normal; }
}

@media (max-width: 480px) {
  /* The viewer sits at the end of the page here; its toggle makes room for Generate. */
  .topbar #btn-stack-toggle { display: none; }
}

.sortable-fallback { opacity: 0.85 !important; box-shadow: var(--shadow-pop); pointer-events: none; }
body.is-dragging, body.is-dragging * { user-select: none; cursor: grabbing; }
.drag-handle, .flow-head, .lib-step { user-select: none; }

/* Section header steps and runsheet templates */

/* Section headers: a titled rule across the runsheet (and the wafer column), no box. */
.step-card.section-card {
  margin: 20px 0 4px;
  border: none; border-bottom: 1px solid var(--border-strong); border-radius: 0;
  background: transparent;
  color: var(--text);
}
@media (min-width: 721px) and (min-height: 501px), (min-width: 1001px) {
  .step-list.with-wafers > .step-card.section-card { margin-right: calc(-1 * (var(--wafer-w) + 8px)); }
}
.step-list > .step-card.section-card:first-child { margin-top: 4px; }
.section-card .step-head { padding: 4px 6px 3px; }
.section-name {
  flex: 1; min-width: 0;
  padding: 2px 4px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: transparent;
  text-align: left; font-size: 14px; font-weight: 600; letter-spacing: 0.01em; overflow-wrap: anywhere;
  cursor: text;
}
.section-name:hover { border-color: var(--border-strong); }
.section-input { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }

.lib-step.section { border-bottom: 1px solid var(--border-strong); font-weight: 600; }

.template-dialog { width: min(720px, 94vw); }
.template-tools { padding: 10px 14px 0; }
/* Keep the list visible even where a browser resolves the flex basis to 0 (Safari). */
.template-list { min-height: min(240px, 45vh); }
.template-search { width: 100%; }
.template-group + .template-group { margin-top: 16px; }
/* Group label inside a dialog: the 11 px / 600 overline (as Help and the rates group rows, VIS4-12). */
.template-group-title { margin: 4px 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.template-group-sub { font-weight: 400; text-transform: none; letter-spacing: 0; }
.template-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.template-card { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); display: grid; grid-template-columns: minmax(0, 1fr) 224px; gap: 6px 14px; align-items: start; cursor: pointer; transition: border-color var(--dur-1) var(--ease-out); }
.template-card:hover { border-color: var(--border-strong); }
.template-card:hover .template-start, .template-card:focus-within .template-start { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.template-text { min-width: 0; }
.template-preview { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.template-preview-final { width: 220px; height: 110px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.template-preview-big { display: block; width: 220px; height: 110px; }
.template-preview-steps { display: flex; gap: 3px; flex-wrap: nowrap; min-height: 34px; }
.template-preview-step { display: inline-flex; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); overflow: hidden; }
.template-preview-mini { display: block; width: 33px; height: 34px; }
.template-preview-cap { font-size: 11px; color: var(--text-muted); }
.template-preview-wait { font-size: 12px; color: var(--text-muted); }
@media (max-width: 600px) {
  .template-card { grid-template-columns: minmax(0, 1fr); }
  .template-preview-steps { flex-wrap: wrap; }
}
.template-name { font-weight: 600; overflow-wrap: anywhere; }
.template-desc { margin-top: 2px; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.template-meta { margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.template-actions { margin: 6px 0 2px; display: flex; flex-wrap: wrap; gap: 4px; }
.template-empty { margin: 4px 0; font-size: 12px; color: var(--text-muted); }
.wafer-cell { align-items: flex-start; }
.wafer-cell .wafer-check { min-height: 26px; }
.wafer-note { padding: 2px 6px; font-size: 13px; height: 28px; }
.wafer-note.multi { height: auto; min-height: 28px; }

/* Cross-section side panel (viewer styles in css/stack-viewer.css) */

.layout.with-stack {
  grid-template-columns: var(--col-lib, minmax(240px, 280px)) minmax(380px, 1fr) var(--col-info, minmax(280px, 330px)) var(--col-stack, var(--stack-w, 460px));
}
.panel-stack { position: relative; border-left: 1px solid var(--border); border-right: none; }
.panel-info { border-right: 1px solid var(--border); }
.stack-body { display: flex; flex-direction: column; overflow-y: auto; }
/* Cross-section canvases are landscape (16:10, js/stackViewerCss.js); keep them readable in narrow panels. */
.stack-body .sv-canvas-wrap { min-height: 220px; }
/* Docked beside the runsheet (full-height column): the canvas takes the free height of the column
   instead of leaving half of it empty; stacked canvases share it, side by side ones share the width.
   The floating / narrow layouts and the HTML export keep 16:10 (VIS4-5, VIS5-4). */
@media (min-width: 1101px) and (min-height: 501px) {
  .layout.with-stack .stack-body > .sv-views-stack { flex: 1 1 300px; min-height: 260px; max-height: min(72vh, 680px); display: flex; flex-direction: column; }
  .layout.with-stack .stack-body > .sv-views-stack > .sv-canvas-wrap:not([hidden]) { flex: 1 1 0; aspect-ratio: auto; min-height: 120px; max-height: none; }
  /* Side by side fills the same height (one row, the canvases share the width, VIS5-4). */
  .layout.with-stack .stack-body > .sv-views-side { flex: 1 1 300px; min-height: 260px; max-height: min(72vh, 680px); grid-template-rows: minmax(0, 1fr); }
  .layout.with-stack .stack-body > .sv-views-side > .sv-canvas-wrap:not([hidden]) { aspect-ratio: auto; min-height: 120px; max-height: none; height: auto; }
}
.stack-resize {
  position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; z-index: 5;
  cursor: col-resize; background: transparent;
}
.stack-resize:hover, .stack-resize:focus-visible { background: var(--accent-soft); }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
.topbar-opt { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--bar-muted); white-space: nowrap; }
/* Step shown in the cross-section: accent border and PS number (green means "processed" in the wafer cells). */
.step-card.sim-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.step-card.sim-active .ps { color: var(--accent); font-weight: 600; }
.step-card.sim-active.status-uncertain { box-shadow: inset 3px 0 0 var(--warning-mark), 0 0 0 2px var(--accent-soft); }
.step-card.section-card.sim-active { box-shadow: none; border-bottom-color: var(--accent); }
.step-card.sim-active.status-custom { box-shadow: inset 3px 0 0 var(--border-strong), 0 0 0 2px var(--accent-soft); }
dialog.sv-modal { margin: auto; }

/* Medium screens with the viewer: Library and Runsheet info share the first
   column as tabs, so Library/Runsheet/Cross-section stay above the fold. */
@media (max-width: 1799px) {
  .layout.with-stack { grid-template-columns: var(--col-left, minmax(240px, 290px)) minmax(360px, 1fr) var(--col-stack, var(--stack-w, 420px)); grid-template-rows: minmax(0, 1fr); }
  .layout.with-stack .col-tabs { display: flex; }
  .layout.with-stack .panel-title { display: none; }
  .layout.with-stack .panel-library, .layout.with-stack .panel-info { grid-column: 1; grid-row: 1; }
  .layout.with-stack .panel-runsheet { grid-column: 2; grid-row: 1; }
  .layout.with-stack .panel-stack { grid-column: 3; grid-row: 1; }
  .layout.with-stack:not(.tab-info) .panel-info, .layout.with-stack.tab-info .panel-library { display: none; }
  .layout.with-stack .panel-info .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1100px) {
  .layout.with-stack { grid-template-columns: var(--col-left, minmax(240px, 280px)) 1fr; grid-template-rows: max(480px, calc(100dvh - var(--topbar-h) - var(--message-h))) max-content; overflow-y: auto; }
  .layout.with-stack .panel-stack { grid-column: 1 / -1; grid-row: 2; border-top: 1px solid var(--border); border-left: none; }
  .layout.with-stack .panel-stack .panel-body { overflow: visible; }
  /* Runsheet info shares row 1 with the Library tab: it scrolls inside its cell
     instead of spilling over the cross-section row; grid items may shrink below
     their content width (no horizontal page overflow on tablets). */
  .layout.with-stack .panel-info .panel-body { overflow-y: auto; }
  .layout > .panel { min-width: 0; }
  .stack-resize { display: none; }
}
/* 900–1100 px with the viewer (UX5-6): runsheet and cross-section side by side in the first row (the core
   loop: edit a step, check its stack); the Library / Runsheet info tabs move to the full-width second row. */
@media (min-width: 900px) and (max-width: 1100px) and (min-height: 600px) {
  .layout.with-stack { grid-template-columns: minmax(0, 1fr) var(--col-stack, clamp(340px, 38vw, 420px)); }
  .layout.with-stack .panel-runsheet { grid-column: 1; grid-row: 1; }
  .layout.with-stack .panel-stack { grid-column: 2; grid-row: 1; border-top: none; border-left: 1px solid var(--border); }
  .layout.with-stack .panel-stack .panel-body { overflow-y: auto; }
  .layout.with-stack .panel-library, .layout.with-stack .panel-info { grid-column: 1 / -1; grid-row: 2; border-top: 1px solid var(--border); border-right: none; }
  .layout.with-stack .panel-info .panel-body { overflow: visible; }
  .layout.with-stack .stack-body > .sv-views-stack { flex: 1 1 260px; min-height: 220px; max-height: min(72vh, 680px); display: flex; flex-direction: column; }
  .layout.with-stack .stack-body > .sv-views-stack > .sv-canvas-wrap:not([hidden]) { flex: 1 1 0; aspect-ratio: auto; min-height: 120px; max-height: none; }
}
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .layout.with-stack { display: flex; flex-direction: column; overflow: visible; }
  .layout.with-stack .col-tabs { display: none; }
  .layout.with-stack .panel-title { display: block; }
  .layout.with-stack:not(.tab-info) .panel-info, .layout.with-stack.tab-info .panel-library { display: flex; }
  .layout.with-stack > .panel { max-height: none; }
  .layout.with-stack .panel-info .panel-body { overflow: visible; }
}

.topbar .checks-badge { font-variant-numeric: tabular-nums; }
.topbar .checks-badge.checks-error { border-color: var(--danger); }

/* Step thumbnails (cross-section after the step + key parameters) */
.step-thumb-wrap { flex: none; display: inline-flex; align-items: center; gap: 6px; }
.step-thumb { width: 72px; height: 40px; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); }
.step-params { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.step-params.has-warning { color: var(--warning-text); }
.step-params.has-error { color: var(--danger); font-weight: 600; }
@media (max-width: 1500px) { .step-params { display: none; } }

/* Revisions (Runsheet info) */
.revisions { font-size: 12px; margin-bottom: 12px; }
.rev-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.rev-label { font-weight: 600; }
.rev-label.rev-draft { color: var(--warning-text); }
.rev-label.rev-none { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.rev-form { display: grid; gap: 6px; margin: 6px 0 10px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.rev-form input, .rev-form textarea { width: 100%; box-sizing: border-box; font: inherit; }
.rev-form-actions { display: flex; gap: 6px; }
.rev-list { list-style: none; margin: 0; padding: 0; }
.rev-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.rev-letter { flex: none; width: 20px; height: 20px; display: inline-grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 700; }
.rev-meta { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rev-hash { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.rev-changes { margin-top: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); max-height: 320px; overflow: auto; }
.rev-changes ul { margin: 0; padding-left: 0; list-style: none; }
.rev-change { padding: 2px 0; }
.rev-type { display: inline-block; min-width: 56px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.rev-added .rev-type { color: var(--success); }
.rev-removed .rev-type { color: var(--danger); }
.rev-changes-title { margin: 0 0 4px; font-weight: 600; }
.rev-marker { flex: none; font-size: 10px; padding: 0 5px; border-radius: 8px; background: var(--warning-soft); color: var(--warning-text); border: 1px solid var(--warning-border); }

/* Mask registry (Masks dialog) */
.mr-panel { margin: 10px 0; padding: 8px 10px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent-soft); }
.mr-panel-head { display: flex; align-items: center; justify-content: space-between; }
.mr-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.mr-conflicts, .mr-list { list-style: none; margin: 4px 0; padding: 0; }
.mr-conflicts li, .mr-entry { display: flex; align-items: center; gap: 6px; padding: 3px 0; }
.mr-entry-text { flex: 1; min-width: 0; font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-conflict-id { font-family: var(--mono); font-weight: 600; min-width: 48px; }
.mr-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mr-table th, .mr-table td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); }
.mr-unused td { color: var(--text-muted); font-style: italic; }
.mr-status { color: var(--danger); font-weight: 600; }

/* Operator traveler (in-page overlay; printed alone) */
body.traveler-open { overflow: hidden; }
.traveler { position: fixed; inset: 0; z-index: 1000; overflow: auto; background: var(--bg); color: var(--text); }
.trav-toolbar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--bar-bg); color: var(--bar-text); }
.trav-toolbar h2 { margin: 0; font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--bar-text); }
.trav-hint { font-size: 12px; color: var(--text-muted); }
.trav-toolbar .trav-hint { color: var(--bar-muted); }
.trav-spacer { flex: 1; }
/* The traveler is a paper document: always light, whatever the page theme. */
.trav-doc {
  color-scheme: light;
  --text: #111; --text-muted: #444; --border: #999; --border-strong: #888;
  --surface: #fff; --surface-2: #f7f8fb; --accent: #2453c4; --accent-soft: #ecf1fc; --danger: #c2342b; --focus: #2453c4;
  max-width: 190mm; margin: 16px auto; padding: 12mm; background: #fff; color: #111; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2); font-size: 11pt;
}
.trav-doc h1, .trav-doc h2, .trav-doc h3, .trav-section { color: #111; text-transform: none; letter-spacing: 0; }
.trav-doc input { background: #fff; color: #111; border: 1px solid #888; border-radius: 3px; }
.trav-title h1 { margin: 0 0 4px; font-size: 16pt; }
.trav-title p { margin: 2px 0; }
.trav-sign { margin-top: 8px !important; }
.trav-section { margin: 18px 0 6px; padding: 4px 6px; background: #eef1f6; border-bottom: 1px solid #b0b6c4; font-size: 13pt; break-after: avoid; page-break-after: avoid; }
.trav-block { margin: 10px 0; border: 1px solid #999; border-radius: 3px; break-inside: avoid; page-break-inside: avoid; }
.trav-block-head { display: flex; align-items: baseline; gap: 8px; padding: 4px 8px; background: #eef1f6; border-bottom: 1px solid #999; }
.trav-block-head h3 { flex: 1; margin: 0; font-size: 11.5pt; }
.trav-ps { font-family: inherit; font-variant-numeric: tabular-nums; font-weight: 700; }
.trav-side { font-size: 9pt; padding: 0 4px; border: 1px solid #777; border-radius: 3px; }
/* FS / BS in the app's side colours (teal / magenta); fixed light values: the traveler is always white. */
.trav-side-BS { background: #fbecf4; color: #6e1347; border-color: #c25e95; font-weight: 700; }
.trav-side-FS { background: #e7f5f8; color: #074e5e; border-color: #2f8497; }
.trav-wafers { font-size: 9.5pt; color: #444; }
.trav-block-body { display: flex; gap: 10px; padding: 6px 8px; }
.trav-steps { flex: 1; min-width: 0; }
.trav-step + .trav-step { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #bbb; }
.trav-step-head .trav-meta { color: #555; font-size: 9.5pt; }
.trav-details, .trav-info { font-size: 10pt; white-space: pre-wrap; overflow-wrap: anywhere; }
.trav-info { color: #444; font-style: italic; }
.trav-blank { background: #fdf5e5; color: #000; padding: 0 2px; border-bottom: 1px dashed #a8741a; }
.trav-done { margin-top: 4px; font-size: 9.5pt; color: #333; }
.trav-thumb { flex: none; margin: 0; width: 240px; text-align: center; }
.trav-thumb img { width: 240px; height: 140px; border: 1px solid #bbb; }
.trav-thumb figcaption { font-size: 8.5pt; color: #555; }
.trav-metro { margin-top: 6px; }
.trav-table { border-collapse: collapse; font-size: 9.5pt; }
.trav-table th, .trav-table td { border: 1px solid #999; padding: 2px 5px; text-align: left; vertical-align: top; }
.trav-table thead th { background: #eef1f6; }
.trav-exp { color: #444; }
.trav-meas { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.trav-input { width: 80px; font: inherit; }
.trav-input[aria-invalid="true"] { outline: 2px solid #c2342b; }
.trav-dev { display: inline-block; min-width: 56px; margin-left: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trav-ok { color: #1f7543; background: #eaf6ef; }
.trav-out { color: #c2342b; background: #fbebea; }
.trav-none { color: #555; }
.trav-doc .trav-hint { color: #555; margin: 2px 0; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body.traveler-open { overflow: visible; background: #fff; }
  body.traveler-open > :not(.traveler) { display: none !important; }
  body.traveler-open .traveler { position: static; overflow: visible; background: #fff; }
  .trav-toolbar { display: none; }
  .trav-doc { max-width: none; margin: 0; padding: 0; box-shadow: none; }
  .trav-break { break-before: page; page-break-before: always; }
  .trav-block, .trav-table tr { break-inside: avoid; page-break-inside: avoid; }
  .trav-input { border: none; border-bottom: 1px solid #000; }
  .trav-blank, .trav-ok, .trav-out, .trav-block-head, .trav-section, .trav-side { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Traveler toolbar buttons on the purple bar (as in the top bar). */
.trav-toolbar .btn { background: transparent; border-color: var(--bar-line); color: var(--bar-text); }
.trav-toolbar .btn:hover:not(:disabled) { background: var(--bar-hover); border-color: var(--border-strong); }
.trav-toolbar .btn-primary { background: var(--bar-cta); border-color: var(--bar-cta); color: var(--bar-cta-text); }
.trav-toolbar .btn-primary:hover:not(:disabled) { background: var(--bar-cta-hover); border-color: var(--bar-cta-hover); }

/* ---------- Touch and phones ----------
   Desktop (fine pointer, > 1100 px) is unchanged. (pointer: coarse) enlarges the
   tap targets to >= 40 px and the form text to 16 px (iOS zooms the page when a
   smaller field gets the focus); the phone layout is a single column with a
   sticky top bar, a sticky message strip and a bottom section bar. */

.phone-nav { display: none; }

@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-icon { min-width: 40px; }
  .btn-small { min-height: 40px; padding: 4px 10px; font-size: 13px; }
  .icon-btn, .collapse-btn, .icon-btn.collapse-btn { width: 40px; height: 40px; font-size: 16px; }
  .collapse-spacer { width: 40px; }
  .side-btn { min-width: 40px; min-height: 40px; }
  .drag-handle { width: 24px; height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; }
  .menu-item { min-height: 44px; }
  .col-tab { min-height: 44px; }
  .cat-head, .fam-head { min-height: 44px; }
  .flow-head, .lib-step { min-height: 44px; }
  /* With 40 px buttons a nested flow (template sections) left the name ~3 characters
     wide; below 9ch it takes its own line instead of breaking letter by letter. */
  .flow-head { flex-wrap: wrap; }
  .flow-name { min-width: 9ch; }
  .section-name, .step-toggle { min-height: 40px; }
  .tool-link { display: inline-flex; align-items: center; min-height: 40px; }
  input[type="text"], input[type="search"], input[type="number"], select, textarea, .trav-input { font-size: 16px; }
  input[type="text"], input[type="search"], input[type="number"], select { min-height: 40px; }
  input[type="checkbox"] { width: 20px; height: 20px; }
  .wafer-cell input[type="text"], .wafer-note { font-size: 16px; }
  .message .btn { min-height: 40px; }
}

@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  /* Feedback stays in view under the sticky top bar (e.g. after "+" in the library). */
  .message > span { flex: 1 1 60%; }
  .message-actions { margin-left: auto; }
  .message { position: sticky; top: var(--topbar-h); z-index: 19; max-height: 40vh; overflow-y: auto; flex-wrap: wrap; padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); box-shadow: var(--shadow-1); }
  .panel { scroll-margin-top: calc(var(--topbar-h) + var(--message-h)); }
  .step-card { scroll-margin-top: calc(var(--topbar-h) + var(--message-h) + 8px); scroll-margin-bottom: calc(var(--phone-nav-h) + 8px); }
  /* Bottom section bar: jump between Runsheet, Cross-section, Info and Library. */
  :root { --phone-nav-h: 56px; }
  body { padding-bottom: calc(var(--phone-nav-h) + env(safe-area-inset-bottom)); }
  .phone-nav {
    position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: var(--surface); border-top: 1px solid var(--border-strong);
    box-shadow: var(--shadow-1);
  }
  .phone-nav-btn {
    min-height: var(--phone-nav-h); padding: 4px 2px;
    border: none; border-top: 3px solid transparent; background: transparent;
    color: var(--text-muted); font-size: 12px; font-weight: 600; cursor: pointer;
  }
  .phone-nav-btn[aria-current="true"] { color: var(--accent); border-top-color: var(--accent); background: var(--accent-soft); }
  .editor-actions .btn { flex: 1 1 auto; justify-content: center; }
  .editor-actions .btn-danger, .editor-actions .editor-done { margin-left: 0; }
  .runsheet-actions { flex-wrap: wrap; }
  .section-head { flex-wrap: wrap; }
  .rev-head { flex-wrap: wrap; }
  .mr-table { display: block; overflow-x: auto; }
}

@media (max-width: 1100px) {
  /* Step editor: fieldsets may shrink (no overflow from the simulation block or the split table). */
  .editor fieldset { min-width: 0; }
}

/* Touch tablets: the left panel head keeps its ✕ inside the column (the tabs and two 40 px buttons did
   not fit, VIS5-1). Below 1100 px the panels do not fold to strips, and ✕ closes them. */
@media (pointer: coarse) and (max-width: 1100px) {
  .layout.with-stack .panel-library .panel-collapse, .layout.with-stack .panel-info .panel-collapse { display: none; }
}

@media (max-height: 500px) and (max-width: 1000px) {
  /* Landscape phone: one-row top bar, lower section bar, canvas fits the screen height. */
  :root { --phone-nav-h: 44px; }
  .stack-body .sv-canvas-wrap { max-height: calc(100dvh - var(--topbar-h) - var(--phone-nav-h) - 24px); }
  .topbar .app-logo { width: 22px; height: 22px; }
  .topbar .name-wrap .runsheet-name { display: none; }
}

.topbar .menu-more { display: none; }
/* Phones and tablets (≤ 1100 px): one top-bar row (VIS4-1 / UX4-4, VIS5-1): icon + name | (tablets:
   panel toggles) | Checks | ⋯ | Generate. File, Process rates, Export and Help live in the ⋯ menu
   (moved there by bindPhoneMenu()). */
@media (max-width: 1100px) {
  .topbar { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; }
  .topbar .brand { flex: 1 1 auto; min-width: 0; gap: 8px; }
  .topbar .name-wrap { min-width: 0; }
  .topbar .runsheet-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { flex: none; gap: 4px; }
  .topbar .checks-label { display: none; }
  .topbar .checks-badge { min-width: 44px; justify-content: center; }
  .topbar .checks-badge .checks-dot { margin-right: 0; }
  .topbar .checks-badge .checks-count:not(:empty) { margin-left: 4px; }
  .topbar .menu-more { display: block; }
  .menu-more > summary.btn { min-width: 44px; justify-content: center; font-size: 18px; line-height: 1; }
  /* The missing-fields warning is an amber dot on Generate (Generate then goes to the first field).
     On the corner, cut out of the button by a bar-coloured ring (amber on cobalt had no contrast, COL5-2). */
  .topbar .generate-reason { display: none; }
  .topbar #btn-generate { position: relative; overflow: visible; }
  .topbar #btn-generate.blocked::after { content: ""; position: absolute; top: -3px; right: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--warning-mark); box-shadow: 0 0 0 2px var(--bar-bg); }
  /* Inside the ⋯ sheet: Process rates, then File / Export / Help as groups (their menus are always open there). */
  .topbar .menu-more > .menu-list { max-height: calc(100dvh - var(--topbar-h) - var(--phone-nav-h, 0px) - 16px); overflow-y: auto; overscroll-behavior: contain; min-width: 240px; }
  /* While the ⋯ menu is open the page under it does not scroll (js/app.js bindPhoneMenu). */
  html.menu-lock, html.menu-lock body { overflow: hidden; }
  .menu-more-list > .menu { display: block; }
  .menu-more-list > .menu + .menu, .menu-more-list > #btn-rates + .menu { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
  .menu-more-list > .menu > summary { display: block; min-height: 0; padding: 6px 10px 2px; border: 0; background: none !important; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); pointer-events: none; }
  .menu-more-list > .menu > summary .menu-caret { display: none; }
  .topbar .menu-more-list .menu-list { position: static; max-height: none; min-width: 0; padding: 0; border: 0; box-shadow: none; background: transparent; transition: none; }
  /* A plain row, like the menu items (no half box from the button radius, COL5-10). */
  .topbar .menu-more-list > #btn-rates { display: flex; width: 100%; justify-content: flex-start; border: 0; border-radius: 0; font-weight: 400; font-size: 13px; color: var(--text); padding: 6px 10px; }
}
@media (max-width: 720px) {
  .topbar { gap: 4px; }
  .topbar .btn { min-height: 44px; justify-content: center; padding: 4px 8px; }
  .topbar .topbar-seg { display: none; }
  .topbar .gen-ext { display: none; }
  .topbar .menu-more > .menu-list { left: max(8px, env(safe-area-inset-left)); max-height: calc(100dvh - var(--topbar-h) - var(--phone-nav-h, 56px) - 16px); }
}

/* Traveler on phones: full-width document, thumbnails under the text. */
@media (max-width: 720px) {
  .trav-toolbar { flex-wrap: wrap; gap: 6px 8px; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); }
  .trav-toolbar h2 { flex: 1 1 auto; }
  .trav-toolbar .trav-hint { order: 5; flex: 1 1 100%; }
  .trav-toolbar .trav-spacer { display: none; }
  .trav-toolbar .btn { min-height: 44px; min-width: 72px; justify-content: center; }
  .trav-doc { max-width: none; margin: 0; padding: 14px max(12px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); box-shadow: none; }
  .trav-title h1 { font-size: 14pt; overflow-wrap: anywhere; }
  .trav-block-head { flex-wrap: wrap; }
  .trav-block-body { flex-direction: column; }
  .trav-thumb, .trav-thumb img { width: 100%; max-width: 360px; height: auto; }
  .trav-metro { overflow-x: auto; }
  .trav-details, .trav-info { overflow-wrap: anywhere; }
}

/* Collapsible side panels (Library, Runsheet info, Cross-section). A collapsed
   panel is a 40 px strip with its name in columns; in stacked rows and on
   phones only its header stays. */
.panel-collapse { flex: none; margin-left: auto; }
.panel-strip-label { display: none; }
.panel.collapsed > :not(.panel-head) { display: none !important; }
.layout.collapse-library { --col-lib: 40px; }
.layout.collapse-info { --col-info: 40px; }
.layout.collapse-stack { --col-stack: 40px; }
.layout.collapse-library:not(.tab-info), .layout.collapse-info.tab-info { --col-left: 40px; }
.panel.collapsed > .panel-head {
  flex-direction: column; justify-content: flex-start; align-items: center; gap: 10px;
  height: 100%; padding: 6px 0; border-bottom: none; cursor: pointer;
}
.panel.collapsed > .panel-head > :not(.panel-collapse):not(.panel-strip-label) { display: none !important; }
.panel.collapsed > .panel-head > .panel-strip-label {
  display: block; writing-mode: vertical-rl; font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap;
}
.panel.collapsed > .panel-head:hover { background: var(--accent-soft); }
.panel.collapsed > .panel-head > .panel-collapse { order: -1; margin-left: 0; }
.panel.collapsed { min-width: 0; overflow: hidden; }
/* Stacked rows (tablets): Runsheet info without the viewer and the viewer
   itself sit in full-width rows; collapsed, only the header row stays. */
@media (max-width: 1100px) {
  .layout:not(.with-stack) .panel-info.collapsed > .panel-head,
  .layout.with-stack .panel-stack.collapsed > .panel-head {
    flex-direction: row; justify-content: space-between; height: auto; padding: var(--panel-head-pad, 8px 12px);
  }
  .layout:not(.with-stack) .panel-info.collapsed > .panel-head > .panel-title,
  .layout.with-stack .panel-stack.collapsed > .panel-head > h2 { display: block !important; }
  .layout:not(.with-stack) .panel-info.collapsed > .panel-head > .panel-strip-label,
  .layout.with-stack .panel-stack.collapsed > .panel-head > .panel-strip-label { display: none; }
}
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .panel.collapsed > .panel-head { flex-direction: row; justify-content: space-between; height: auto; padding: var(--panel-head-pad, 8px 12px); }
  .panel.collapsed > .panel-head > h2, .panel.collapsed > .panel-head > .panel-title { display: block !important; }
  .panel.collapsed > .panel-head > .panel-strip-label { display: none !important; }
}

/* Step rows: trash can on hover / focus (always shown on touch screens) and
   wafer columns (W01, W02…) at the right of each step. */
.step-trash { opacity: 0; transition: opacity var(--dur-1) var(--ease-out); }
/* Only while the pointer is on the row, or the keyboard focus is in it
   (:focus-visible, so a mouse click on the row does not pin it). */
.step-head:hover > .step-trash,
.step-trash:focus-visible { opacity: 1; }
/* Touch-first devices (no hover, e.g. iPad, phones): only the open step shows its
   trash icon, and a hidden icon cannot be tapped by accident. A trackpad or mouse
   on such a device (any-hover) still reveals it on hover. */
@media (hover: none) {
  .step-trash { visibility: hidden; }
  .step-card.open > .step-head > .step-trash { visibility: visible; opacity: 1; }
}
@media (hover: none) and (any-hover: hover) {
  .step-head:hover > .step-trash { visibility: visible; }
}
.wafer-cols { flex: none; display: inline-flex; gap: 2px; }
.wcell {
  /* A wafer outline with the flat at the bottom (::before = outline, ::after = fill) and the mark
     inside (✓ processed, – skipped, S split); a wafer note is a small amber dot at the top right. */
  --w-line: var(--border-strong); --w-fill: var(--surface); --w-hatch: var(--w-fill);
  /* skipped: the same light shades as "processed", in grey and hatched out */
  --w-off-line: color-mix(in srgb, var(--text-muted) 40%, var(--surface));
  --w-off-fill: var(--surface-2);
  --w-off-hatch: color-mix(in srgb, var(--text-muted) 32%, var(--surface));
  --w-size: 18px; --w-x: 50%; --w-y: 50%;
  flex: none; width: 34px; height: 20px; position: relative; isolation: isolate;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: var(--text-muted);
}
/* Registered, so the outline and fill colours of the wafer shapes ease on hover / press like the buttons. */
@property --w-line { syntax: "<color>"; inherits: true; initial-value: transparent; }
@property --w-fill { syntax: "<color>"; inherits: true; initial-value: transparent; }
.wcell { transition: --w-line var(--dur-1) var(--ease-out), --w-fill var(--dur-1) var(--ease-out); }
.wcell::before, .wcell::after {
  content: ""; position: absolute; left: var(--w-x); top: var(--w-y); width: var(--w-size); height: var(--w-size); transform: translate(-50%, -50%); z-index: -1;
  -webkit-mask: var(--wafer-mask) center / 100% 100% no-repeat; mask: var(--wafer-mask) center / 100% 100% no-repeat;
}
.wcell::before { --wafer-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4.21 15.5A8.4 8.4 0 1 1 13.79 15.5Z'/%3E%3C/svg%3E"); background: var(--w-line); }
.wcell::after { --wafer-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4.6 14.6A7.45 7.45 0 1 1 13.4 14.6Z'/%3E%3C/svg%3E"); background: repeating-linear-gradient(135deg, var(--w-hatch) 0 0.9px, var(--w-fill) 0.9px 3px); }
.wcell-mark { line-height: 1; pointer-events: none; }
.wcell.on { --w-line: color-mix(in srgb, var(--success) 55%, var(--success-soft)); --w-fill: var(--success-soft); color: var(--success); }
.wcell.split { --w-line: color-mix(in srgb, var(--accent) 55%, var(--accent-soft)); --w-fill: var(--accent-soft); color: var(--accent); }
.wcell.off { --w-line: var(--w-off-line); --w-fill: var(--w-off-fill); --w-hatch: var(--w-off-hatch); color: var(--text-muted); }
.wcell.other { --w-line: var(--border); opacity: 0.5; }
/* Module header (or wafer group) processed in some of its steps / wafers: half filled. */
.wcell.part { --w-line: color-mix(in srgb, var(--success) 55%, var(--success-soft)); color: var(--success); }
.wcell.part::after { background: linear-gradient(to top, var(--success-soft) 50%, var(--surface) 50%); }
.wcell.noted { background: radial-gradient(circle at calc(var(--w-x) + var(--w-size) * 0.39) calc(var(--w-y) - var(--w-size) * 0.39), var(--warning-mark) 2.2px, transparent 2.8px); }
.wafer-cols.many .wcell, .wafer-cols.many .wcell-head { width: 22px; }
/* Groups view: the outline at the left of the cell; a partly processed group shows its count beside it. */
.wafer-cols.groups .wcell, .wafer-cols.groups .wcell-head { width: 60px; }
.wafer-cols.groups .wcell { --w-x: 13px; }
.wafer-cols.groups .wcell-mark { position: absolute; left: 13px; top: 50%; transform: translate(-50%, -50%); }
.wafer-cols.groups .wcell.part .wcell-mark { left: 25px; transform: translateY(-50%); font-size: 10px; font-weight: 600; }
.wafer-cols-head {
  position: sticky; top: -12px; z-index: 3;
  display: flex; justify-content: flex-end; align-items: center; gap: 8px;
  margin: 8px 0 -4px; padding: 4px 0 2px 0;
  background: var(--bg);
  font-size: 11px; color: var(--text-muted);
}
.wafer-cols-head[hidden] { display: none; }
.wafer-head-caption { color: var(--text-muted); }
.wcell-head { flex: none; width: 34px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); overflow: hidden; white-space: nowrap; }
/* Phones: rows wrap, so the cells carry their own labels and the header row is hidden. */
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .wafer-cols-head { display: none; }
  .step-head .wafer-cols { order: 4; flex-wrap: wrap; }
  /* Phones: a 22 px wafer outline in a 44 × 40 tap target, the wafer label under it. */
  .wcell { width: auto; min-width: 44px; height: 40px; --w-size: 22px; --w-y: 13px; }
  .wcell-mark { position: absolute; left: 50%; top: 13px; transform: translate(-50%, -50%); font-size: 10px; }
  .wcell-mark::after { content: attr(data-label); position: absolute; left: 50%; top: calc(50% + 11px); transform: translateX(-50%); font-size: 10px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
  .wafer-cols.groups .wcell { width: auto; min-width: 64px; --w-x: 50%; }
  .wafer-cols.groups .wcell-mark, .wafer-cols.groups .wcell.part .wcell-mark { left: 50%; top: 13px; transform: translate(-50%, -50%); font-size: 9px; }
}

/* In-page question dialog (askDialog in app.js). */
.ask-dialog { width: min(480px, 94vw); }
.ask-message { margin: 0 0 10px; overflow-wrap: anywhere; }
.ask-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12px; color: var(--text-muted); }
.ask-field input { width: 100%; font-size: 14px; color: var(--text); }

/* Closed Library / Runsheet info (top-bar toggles, ✕ in the panel header):
   the grid cell stays (0 px column) on wide layouts; elsewhere it is removed. */
.panel-close { flex: none; }
.panel-head > .panel-collapse + .panel-close { margin-left: -4px; }
.layout.close-library { --col-lib: 0px; }
.layout.close-info { --col-info: 0px; }
.layout.close-library.close-info { --col-left: 0px; }
.panel.panel-closed { visibility: hidden; overflow: hidden; border: none !important; min-width: 0; }
.panel.panel-closed .stack-resize { display: none; }
@media (max-width: 1799px) { .layout.with-stack > .panel.panel-closed { display: none !important; } }
@media (max-width: 1100px) { .layout > .panel-info.panel-closed { display: none !important; } }
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .layout > .panel.panel-closed { display: none !important; }
  .topbar .panel-toggle, .topbar #btn-rates { display: none; }
}

/* Runsheet name in the top bar: click to edit its parts in place. */
.name-wrap { position: relative; min-width: 0; display: inline-flex; align-items: center; }
.runsheet-name[role="button"] { cursor: text; border-radius: var(--radius); padding: 2px 4px; margin: -2px -4px; }
.runsheet-name[role="button"]:hover { background: var(--bar-hover); color: var(--bar-text); }
/* Desktop: the editor floats over the bar from the name's position (the buttons are not squeezed). */
.name-wrap.editing .name-edit {
  position: absolute; left: -6px; top: 50%; transform: translateY(-50%); z-index: 61;
  padding: 4px 6px; border-radius: 6px; background: var(--bar-bg); box-shadow: var(--shadow-pop);
}
.name-edit { flex: none; display: inline-flex; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--bar-muted); white-space: nowrap; }
.name-edit .name-input {
  flex: 0 0 auto; width: auto !important; max-width: min(640px, 60vw); min-width: 0; padding: 2px 5px; margin: 0;
  font-family: var(--mono); font-size: 12px; color: var(--bar-text);
  background: var(--surface); border: 1px solid var(--bar-line); border-radius: 3px;
}
.name-input:focus { outline: 2px solid var(--focus); outline-offset: 0; background: var(--surface); }
.name-input[aria-invalid="true"] { border-color: var(--danger); }
.name-wrap.custom .name-input { border-style: dashed; }
.name-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; width: max-content; max-width: min(520px, 92vw);
  padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); font-size: 12px;
}
.name-pop-status { margin: 0 0 4px; padding: 0 6px; font-weight: 600; }
.name-pop-row { display: grid; grid-template-columns: 140px minmax(180px, 1fr); gap: 2px 10px; align-items: center; padding: 3px 6px; border-radius: 4px; }
.name-pop-val { width: 100%; padding: 3px 6px; font-family: var(--mono); font-size: 13px; }
.name-pop-row.unlinked .name-pop-label { color: var(--text-muted); font-weight: 500; }
.name-pop-row.active { background: var(--accent-soft); }
.name-pop-label { font-weight: 600; }
.name-pop-hint { color: var(--text-muted); }
.name-pop-err { grid-column: 2 / -1; color: var(--danger); }
.name-pop-err:empty { display: none; }
.name-pop-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text-muted); }
.name-pop-more { padding: 0; border: none; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  /* Phones: the editor opens as a sheet at the top of the screen (the brand row is too narrow). */
  .name-wrap.editing {
    position: fixed; z-index: 70; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px;
    display: flex; flex-direction: column; align-items: stretch; gap: 8px;
    padding: 10px; border-radius: 8px; background: var(--bar-bg); box-shadow: var(--shadow-pop);
  }
  .name-wrap.editing .name-edit { position: static; transform: none; padding: 0; box-shadow: none; display: flex; flex-wrap: wrap; row-gap: 6px; }
  .name-wrap.editing .runsheet-name { display: none; }
  .name-edit .name-input { flex: 1 1 auto; max-width: none; font-size: 16px; min-height: 40px; }
  .name-wrap.editing .name-pop { position: static; max-width: none; width: auto; box-shadow: none; }
  .name-pop-row { grid-template-columns: 1fr; }
  .name-pop-val { font-size: 16px; min-height: 40px; }
  .name-pop-err { grid-column: 1 / -1; }
  .name-pop-foot { flex-direction: column; align-items: flex-start; }
  .name-pop-more { min-height: 40px; }
}

/* "Get substrate" at the top of the runsheet: one column per wafer group. */
.substrate-cols { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0; padding: 6px 0 4px; }
/* Columns are cells divided by a rule (the block itself is the card). */
.sub-col {
  flex: 0 0 auto; min-width: 150px; max-width: 220px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 2px 12px; border-left: 1px solid var(--border); color: var(--text);
}
.sub-col:first-child { padding-left: 0; border-left: none; }
.sub-col-head { display: flex; align-items: center; gap: 4px; }
.sub-type { flex: 1; min-width: 0; height: 26px; padding-top: 0; padding-bottom: 0; font-weight: 600; }
.sub-count-row { display: flex; align-items: center; gap: 6px; }
/* − count + as one control: a shared border, inner dividers only. */
.sub-stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--control-border, var(--border-strong)); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.sub-stepper .sub-count { width: 40px; height: 24px; padding: 0; border: 0; border-radius: 0; text-align: center; background: transparent; }
.sub-step {
  flex: none; width: 26px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 0; background: var(--surface-2); color: var(--text); cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out);
}
.sub-step:first-child { border-right: 1px solid var(--border); }
.sub-step:last-child { border-left: 1px solid var(--border); }
.sub-step:hover:not(:disabled) { background: var(--bar-hover); }
.sub-step:focus-visible, .sub-stepper .sub-count:focus-visible { outline-offset: -2px; }
.sub-step:disabled { opacity: var(--disabled-opacity); cursor: default; }
.sub-unit { font-size: 12px; line-height: 26px; color: var(--text-muted); }
.sub-labels { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.sub-meta { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-add {
  flex: 0 0 auto; align-self: center; margin-left: 8px; padding: 4px 10px;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--accent); font-size: 12px; font-weight: 600; cursor: pointer;
}
.sub-add:hover:not(:disabled) { background: var(--bar-hover); }
.fixed-title > .sub-add { margin-left: auto; align-self: center; }
.sub-add:disabled { opacity: var(--disabled-opacity); cursor: default; }
.sub-remove:disabled { visibility: hidden; }
.link-btn { padding: 0; border: none; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
@media (pointer: coarse) {
  .sub-step { width: 40px; height: 40px; }
  .sub-count, .sub-stepper .sub-count { min-height: 40px; height: 40px; }
}
@media (max-width: 720px) {
  .sub-col { flex: 1 1 140px; max-width: none; }
  .sub-add { min-height: 40px; }
}
.sub-count { -moz-appearance: textfield; appearance: textfield; }
.sub-count::-webkit-inner-spin-button, .sub-count::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Wafer columns: a divider from the step text, and the Wafers / Groups / Off view switch. */
.wafer-cols-head { gap: 6px; }
.wafer-view { display: inline-flex; margin-right: auto; margin-left: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.wafer-view-btn { min-height: 24px; padding: 1px 8px; border: none; background: var(--surface); color: var(--text-muted); font-size: 12px; cursor: pointer; }
.wafer-view-btn + .wafer-view-btn { border-left: 1px solid var(--border-strong); }
.wafer-view-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--pressed-text); font-weight: 600; }
@media (pointer: coarse) { .wafer-view-btn { min-height: 40px; padding: 0 12px; } }
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .wafer-cols-head { display: flex; justify-content: flex-start; position: static; padding: 4px 0; }
  .wafer-cols-head > .wafer-cols { display: none; }
  .step-head > .wafer-cols { border-left: none; padding-left: 0; margin-left: 0; }
}

/* Desktop: a step row never wraps; the name and detail line are cut with "…" (full text in the
   title) and, in a narrow runsheet, the parameters and then the thumbnail give way. */
.step-card:not(.section-card) > .step-head { flex-wrap: wrap; row-gap: 2px; }
.step-card:not(.section-card) > .step-head > .step-toggle { flex: 1 1 18ch; min-width: min(18ch, 100%); }
.step-card:not(.section-card) > .step-head > .badge + .step-trash { margin-left: auto; }
@media (min-width: 721px) and (min-height: 501px), (min-width: 1001px) {
  .step-card:not(.section-card) > .step-head { flex-wrap: nowrap; }
  .step-card:not(.section-card) > .step-head > .step-toggle { flex: 1 1 0; min-width: 0; }
  .step-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (pointer: coarse) and (max-width: 1100px) {
  .step-card:not(.section-card) > .step-head { flex-wrap: wrap; }
  .step-card:not(.section-card) > .step-head > .step-toggle { flex: 1 1 calc(100% - 100px); min-width: 14ch; }
  .step-name { white-space: normal; }
}
@container steps (max-width: 560px) {
  .step-params { display: none; }
  .editor-grid { grid-template-columns: 1fr 1fr; }
  .editor-grid > :first-child { grid-column: 1 / -1; }
}
@container steps (max-width: 560px) {
  .step-thumb { width: 56px; height: 32px; }
}
@container steps (max-width: 340px) {
  .step-thumb-wrap { display: none; }
}
@container steps (max-width: 340px) {
  .editor-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .editor-grid { grid-template-columns: 1fr; }
  .step-thumb-wrap { display: inline-flex; }
}

/* Wafer card: its own card in a column right of the step cards, aligned for
   every row (sub-steps keep their indent, the wafer column does not). */
.step-list.with-wafers { margin-right: calc(var(--wafer-w) + 8px); }
.step-card { position: relative; }
.wafer-card {
  position: absolute; top: -1px; left: calc(100% + 8px); width: var(--wafer-w);
  display: flex; flex-direction: column; justify-content: center; gap: 3px; box-sizing: border-box;
  height: calc(100% + 2px); padding: 4px 6px;
  /* Lighter than the step card: a faint fill and a softer contour. */
  border: 1px solid color-mix(in srgb, var(--border) 70%, var(--bg)); border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 50%, var(--bg));
}
/* Open step: the card runs along the editor with its cells level with the step head. */
.step-card.open > .wafer-card { justify-content: flex-start; padding-top: 10px; }
.wafer-card.split { justify-content: flex-end; }
.wafer-card .wafer-cols { border: none; padding: 0; margin: 0; }
.wafer-cols-head > .wafer-cols { width: var(--wafer-w); padding: 0 7px; box-sizing: border-box; }
/* Split steps: one line per condition under the name, matching the rows of the wafer card. */
.split-lines { display: flex; flex-direction: column; gap: 3px; padding: 0 6px 4px 92px; font-size: 12px; }
.split-line { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px; align-items: center; height: 20px; color: var(--text-muted); }
.split-tag { font-weight: 600; color: var(--text); }
.split-line.is-split .split-tag { color: var(--accent); }
.split-wafers { font-size: 11px; font-variant-numeric: tabular-nums; }
.split-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-tool { display: flex; flex-direction: row; align-items: center; gap: 8px; }
/* Phones: the wafer card goes under the step head (no room beside the card). */
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .step-list.with-wafers { margin-right: 0; }
  .wafer-card { position: static; width: auto; height: auto; margin: 0 6px 6px; padding: 4px; }
  .wafer-card .wafer-cols { flex-wrap: wrap; }
  .split-lines { padding-left: 12px; }
}

/* Top bar with many buttons: the runsheet name keeps room (the app title gives way first). */
.brand > .name-wrap { flex: 1 1 auto; min-width: 12ch; }
.brand > .name-wrap > .runsheet-name { display: block; max-width: 100%; }
@media (max-width: 1600px) { .topbar .app-name { display: none; } }

/* Wafer cells are clickable: toggle the wafer for that step (or condition row). */
.wafer-card .wcell[data-n], .wafer-card .wcell[data-group] { cursor: pointer; }
.wafer-card .wcell[data-n]:hover, .wafer-card .wcell[data-group]:hover { outline: 2px solid var(--accent); outline-offset: 1px; opacity: 1; }
.wafer-card .wcell:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-radius: 10px; opacity: 1; }

/* Cross-section simulation: a summary line in the step editor, settings in a dialog. */
.sim-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.sim-summary { flex: 1 1 24ch; min-width: 0; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.sim-count { margin-left: 8px; }
.sim-count.sv-ico::before { margin-right: 3px; }
.sim-count.err { color: var(--danger); font-weight: 600; }
.sim-count.warn { color: var(--warning-text); font-weight: 600; }

.sim-dialog-step { margin-top: 2px; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }
.sim-dialog .sv-step-editor { border: none; margin: 0; padding: 0; }
/* Beside the viewer (≥ 1280 px, viewer open): left of it, and the viewer is not shaded. */
.sv-modal.sim-dialog.beside-viewer { margin: 64px auto auto max(16px, calc((100vw - var(--viewer-w) - min(760px, 100vw - var(--viewer-w) - 32px)) / 2)); width: min(760px, calc(100vw - var(--viewer-w) - 32px)); }
.sv-modal.sim-dialog.beside-viewer::backdrop { background: linear-gradient(to right, var(--backdrop) calc(100% - var(--viewer-w, 0px)), transparent 0); }
.sim-dialog .sv-step-editor > legend { display: none; }

/* Substrate columns: details dialog (pencil) and the SOI device-layer select. */
.sub-edit { flex: none; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; }
.sub-device { width: 100%; min-width: 0; font-size: 12px; }

.sub-stack { margin: 10px 0 0; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }

/* ---- Thin Film shapes ---- */
/* Cards and panels: slightly softer corners than buttons (--radius). */
.step-card, .wafer-card, .sub-col, .template-card, .wafer-group, .ask-dialog { border-radius: var(--radius-card); }

/* FS / BS button: a flat wafer seen in perspective; FS arrow lands on the top face,
   BS arrow comes up from below and hits the bottom face behind the wafer (dashed). */
.side-btn { display: inline-flex; align-items: center; justify-content: center; gap: 2px; width: auto; min-width: 26px; height: 18px; padding: 0 5px 0 2px; font-size: 10px; line-height: 1; }
.side-btn.side-none { padding: 0 5px; }
/* FS is the usual case: quiet (no fill, neutral border, the icon keeps its colour); BS stays filled. */
.side-btn.side-FS { background: transparent; color: var(--side-fs-text); border-color: var(--border-strong); }
.side-btn.side-BS { background: var(--side-bs); color: var(--side-bs-text); border-color: var(--side-bs-line); }
/* Neutral hovers like every other button (an accent ring read as focus, COL5-6). */
.side-btn.side-FS:hover { border-color: var(--text-muted); background: var(--bar-hover); }
.side-btn.side-BS:hover { background: color-mix(in srgb, var(--side-bs-line) 18%, var(--side-bs)); }
.side-ic { display: block; width: 17px; height: 12px; flex: none; }
.side-ic .rim, .side-ic .face { stroke-width: 0.55; stroke-opacity: 0.6; }
.side-ic .rim { fill: var(--border); }
.side-ic .arw { stroke-width: 0.9; stroke-linecap: round; }
.side-ic .head { stroke-width: 0.5; stroke-linejoin: round; }
.side-ic .hidden { stroke-width: 0.7; stroke-dasharray: 1 0.9; fill: none; }
.side-FS .side-ic .rim, .side-FS .side-ic .face, .side-FS .side-ic .arw, .side-FS .side-ic .head { stroke: var(--side-fs-line); }
.side-FS .side-ic .face { fill: var(--surface); }
.side-FS .side-ic .head { fill: var(--side-fs-line); }
.side-BS .side-ic .rim, .side-BS .side-ic .face, .side-BS .side-ic .arw, .side-BS .side-ic .head, .side-BS .side-ic .hidden { stroke: var(--side-bs-line); }
.side-BS .side-ic .face { fill: var(--surface); }
.side-BS .side-ic .head { fill: none; }
@media (pointer: coarse) { .side-btn { min-width: 40px; min-height: 40px; height: auto; } }

/* Hover previews the click (desktop): a processed (or split) wafer turns grey and hatched with "–"
   (it would skip this step), a skipped or blank one turns light green with "✓" (it would get it).
   .preview marks the sub-step cells a hovered module-header cell would change. */
@media (hover: hover) {
  .wafer-card .wcell[data-n]:hover { outline: none; }
  .wafer-card .wafer-row[data-row="0"] .wcell.on[data-n]:hover,
  .wafer-card .wafer-row[data-row="0"] .wcell.on.preview { --w-line: var(--w-off-line); --w-fill: var(--w-off-fill); --w-hatch: var(--w-off-hatch); color: var(--text-muted); }
  .wafer-card .wafer-row[data-row="0"] .wcell.off[data-n]:hover,
  .wafer-card .wafer-row[data-row="0"] .wcell.other[data-n]:hover,
  .wafer-card .wafer-row[data-row="0"] .wcell.part[data-n]:hover,
  .wafer-card .wafer-row[data-row="0"] .wcell.off.preview,
  .wafer-card .wafer-row[data-row="0"] .wcell.other.preview,
  .wafer-card .wcell.split[data-n]:hover { --w-line: color-mix(in srgb, var(--success) 55%, var(--success-soft)); --w-fill: var(--success-soft); --w-hatch: var(--w-fill); color: var(--success); opacity: 1; }
  .wafer-card .wafer-row[data-row="0"] .wcell.part[data-n]:hover::after { background: var(--success-soft); }
  .wafer-card .wafer-row:not([data-row="0"]) .wcell.other[data-n]:hover,
  .wafer-card .wafer-row:not([data-row="0"]) .wcell.off[data-n]:hover { --w-line: color-mix(in srgb, var(--accent) 45%, var(--accent-soft)); --w-fill: var(--accent-soft); --w-hatch: var(--w-fill); color: var(--accent); opacity: 1; }
  .wafer-card .wcell[data-n]:hover .wcell-mark, .wafer-card .wcell.preview .wcell-mark { font-size: 0; }
  .wafer-card .wcell[data-n]:hover .wcell-mark::before, .wafer-card .wcell.preview .wcell-mark::before { content: attr(data-alt); font-size: 9px; }
}

/* Reduced motion: no transitions or animations (the cross-section player also skips its tween). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* A step just added (or brought back by undo / redo): a soft accent tint that fades back
   (no ring, so it cannot be mistaken for focus or the open step). A wafer undo tints the wafer card. */
.step-card, .wafer-card { transition: background-color var(--dur-flash) var(--ease-out); }
.step-card.just-added:not(.flash-wafers), .step-card.just-added.flash-wafers > .wafer-card { background-color: var(--accent-soft); transition: none; }
/* Rows scrolled to (added, undone, followed by the player) clear the bottom message. */
@media (min-width: 721px) and (min-height: 501px), (min-width: 1001px) { #step-list > .step-card { scroll-margin-block: 12px 88px; } }

/* Touch: the remaining small targets of the runsheet reach 40 px. */
@media (pointer: coarse) {
  .sub-edit { width: 40px; height: 40px; }
  .fixed-hint .link-btn { display: inline-flex; align-items: center; min-height: 40px; }
  .runsheet-name[role="button"] { line-height: 36px; }
  .wafer-check { min-height: 40px; padding-inline: 8px; }
  .wafer-note { height: 40px; }
}

/* Very wide runsheet (side panels collapsed): the rows keep a readable length, left-aligned;
   the wafer column stays attached to the capped list. */
.runsheet-body > .step-list { max-width: 1180px; }
.runsheet-body > .fixed-block, .runsheet-body > .wafer-cols-head { max-width: calc(1180px + var(--wafer-w, 0px) + 8px); }

/* ---- App icon: flat silicon wafer with one patterned step (substrate, oxide feature, metal draped
   over it). Fixed colours in both themes, apart in lightness so it reads in greyscale and at 16 px:
   substrate L* 20, oxide 39 (the accent), metal 58 (magenta tint), wafer 74. ---- */
.app-logo { display: block; flex: none; }
.app-logo-wafer { fill: #aeb7c8; }
.app-logo-doc { fill: #697996; }
.app-logo-ink { fill: #ffffff; }
/* Help, Tutorials, About: the 760 / 560 px dialog widths, no footer, one scrolling body (VIS4-4 / VIS4-7). */
.help-dialog .sv-modal-body { display: block; font-size: 13px; line-height: 1.5; }
.help-dialog .sv-modal-body > * + * { margin-top: 10px; }
.help-dialog p { margin: 0; }
.about-head { display: flex; align-items: center; gap: 14px; }
.about-name { font-size: 18px; font-weight: 600; }
.about-ver { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.about-note { font-size: 12px; color: var(--text-muted); }
.about-lic { font-size: 12px; }
@media (hover: none) { .about-lic { display: inline-flex; align-items: center; min-height: 40px; } }
.lic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lic-name { font-weight: 600; }
.lic-name a { color: var(--accent); }
.lic-text { font-size: 11px; line-height: 1.5; color: var(--text-muted); }
.help-h { margin: 16px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.help-dialog .sv-modal-body > .help-h:first-child, .help-keys-sec > .help-h { margin-top: 0; }
.help-dialog .sv-modal-body > .help-h + * { margin-top: 0; }
.help-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.help-keys { border-collapse: collapse; width: 100%; font-size: 12px; }
.help-keys td { text-align: left; padding: 3px 8px 3px 0; vertical-align: top; }
.help-keys td:first-child { width: 168px; }
.help-keys-group th { padding: 10px 0 2px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); }
.help-keys tbody:first-child .help-keys-group th { padding-top: 0; }
.help-keys kbd { font: 500 11px var(--font); padding: 1px 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); white-space: nowrap; }
@media (pointer: coarse) and (hover: none) { .help-keys-sec { display: none; } }
/* Tutorials: a list divided by rules, "Show" as a text button, neutral step numbers (VIS4-14). */
.tut { border-bottom: 1px solid var(--border); }
.help-dialog .sv-modal-body > .tut + .tut { margin-top: 0; }
.tut-sum { display: flex; align-items: center; gap: 8px; padding: 8px 2px; cursor: pointer; list-style: none; }
.tut-sum::-webkit-details-marker { display: none; }
.tut-sum-text { flex: 1 1 auto; display: flex; flex-direction: column; gap: 1px; }
.tut-sum > .ui-icon { color: var(--text-muted); transition: transform var(--dur-1) var(--ease-out); }
.tut[open] > .tut-sum > .ui-icon { transform: rotate(90deg); }
.tut-title { font-weight: 600; }
.tut-desc { font-size: 12px; color: var(--text-muted); }
.tut-steps { margin: 0; padding: 2px 2px 10px; display: flex; flex-direction: column; gap: 6px; list-style: none; counter-reset: tut; }
.tut-steps li { display: flex; align-items: flex-start; gap: 10px; counter-increment: tut; }
.tut-steps li::before { content: counter(tut); flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%; background: var(--surface-2); color: var(--text-muted); font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.tut-text { flex: 1 1 auto; }
.tut-show { flex: none; font-size: 12px; font-weight: 600; text-decoration: none; }
.tut-show:hover { text-decoration: underline; }
.tut-done .tut-show { color: var(--text-muted); }
@media (pointer: coarse) { .tut-sum { min-height: 44px; } .tut-show { min-height: 40px; min-width: 48px; } }
/* "Show" in a tutorial: the control is outlined for a moment. */
/* The spotlight is not a focus ring: a wider offset, the card radius and a visible cobalt pulse (COL4-6). */
.step-trash.tour-spot { opacity: 1; visibility: visible; }
.tour-spot { outline: 2px solid var(--accent) !important; outline-offset: 4px; border-radius: var(--radius-card); animation: tour-pulse var(--dur-pulse) var(--ease-out) 2; }
@keyframes tour-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .tour-spot { animation: none; } }
/* Guided tour (js/help.js startTour): a side panel with the steps of one tutorial; the control of the
   current step keeps a steady outline (.tour-target) after the first pulse. */
.tour-target { outline: 2px solid var(--accent) !important; outline-offset: 3px; border-radius: var(--radius); }
.step-trash.tour-target { opacity: 1; visibility: visible; }
/* Floating, translucent (frosted) panel: js places it with left / top, glides it out of the way of the
   outlined control (.tour-glide) and lets the header drag it. More opaque while pointed at or focused. */
.tour-panel {
  position: fixed; z-index: 60; left: auto; right: 12px; top: calc(var(--topbar-h, 52px) + 8px); width: 320px;
  display: flex; flex-direction: column; min-height: 0; max-height: calc(100dvh - var(--topbar-h, 52px) - 24px);
  background: color-mix(in srgb, var(--surface) 62%, transparent); color: var(--text);
  -webkit-backdrop-filter: blur(5px) saturate(1.2); backdrop-filter: blur(5px) saturate(1.2);
  border: 1px solid color-mix(in srgb, var(--border-strong) 70%, transparent); border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  transition: background-color var(--dur-1) var(--ease-out);
}
.tour-panel[style*="left"] { right: auto; }
.tour-panel:hover, .tour-panel:has(:focus-visible) { background: color-mix(in srgb, var(--surface) 94%, transparent); }
.tour-panel.tour-glide { transition: left 420ms var(--ease-out), top 420ms var(--ease-out), background-color var(--dur-1) var(--ease-out); }
.tour-panel .tour-head { cursor: grab; touch-action: none; user-select: none; }
.tour-panel.tour-dragging { opacity: 0.85; }
.tour-panel.tour-dragging .tour-head { cursor: grabbing; }
.tour-step.current { background: color-mix(in srgb, var(--accent-soft) 85%, transparent); }
.tour-head { display: flex; align-items: flex-start; gap: 4px; padding: 12px 10px 8px 14px; }
.tour-head-text { flex: 1 1 auto; min-width: 0; }
.tour-kicker { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tour-title { margin: 2px 0 0; font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; }
.tour-progress { height: 3px; margin: 0 14px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.tour-progress > span { display: block; height: 100%; background: var(--accent); transition: width var(--dur-1) var(--ease-out); }
.tour-steps { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 8px 0 0; padding: 0 8px 8px; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.tour-step-btn { display: flex; align-items: baseline; gap: 8px; width: 100%; padding: 6px 6px; border: 0; border-radius: var(--radius); background: none; color: var(--text-muted); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.tour-step-btn:hover { background: var(--surface-2); color: var(--text); }
.tour-num { flex: none; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border-strong); font-size: 11px; font-variant-numeric: tabular-nums; }
.tour-step.done .tour-num { border-color: transparent; background: var(--success-soft); color: var(--success); }
.tour-step.current { border-radius: var(--radius); }
.tour-step.current .tour-step-btn { color: var(--text); font-weight: 600; }
.tour-step.current .tour-num { border-color: var(--accent); background: var(--accent); color: var(--surface); }
.tour-text { margin: 0; padding: 0 10px 6px 34px; font-size: 13px; line-height: 1.45; }
.tour-again { margin: 0 0 8px 34px; font-size: 12px; }
.tour-miss { margin: 0; padding: 0 10px 8px 34px; font-size: 12px; color: var(--text-muted); }
.tour-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.tour-keys { flex: 1 1 auto; text-align: center; font-size: 11px; color: var(--text-muted); }
.tut-start { margin: 2px 0 8px; }
@media (hover: none) { .tour-keys { visibility: hidden; } .tour-step-btn { min-height: 40px; } }
@media (max-width: 720px) {
  .tour-panel, .tour-panel[style*="left"] {
    left: 8px; right: 8px; width: auto; top: auto;
    bottom: calc(var(--phone-nav-h, 56px) + 8px + env(safe-area-inset-bottom)); max-height: 46dvh;
  }
  .tour-panel .tour-swap { display: none; }
  .tour-panel .tour-head { cursor: default; }
  .tour-panel:not(.tour-expanded) .tour-step:not(.current) { display: none; }
  .tour-panel:not(.tour-expanded) .tour-steps { flex: 0 1 auto; }
}
.tour-all { display: none; }
@media (max-width: 720px) { .tour-all { display: inline-flex; min-height: 40px; } body.tour-on { padding-bottom: 50dvh; } body.tour-on * { scroll-margin-top: calc(var(--topbar-h) + 24px); } }
@media (prefers-reduced-motion: reduce) { .tour-progress > span, .tour-panel.tour-glide { transition: none; } }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .tour-panel { background: var(--surface); } }

/* Wafers / Groups / Off sits on the wafer column, right above the W01 / W02 heads. */
.wafer-cols-head { flex-direction: column; align-items: flex-end; justify-content: flex-start; gap: 3px; }
.wafer-cols-head > .wafer-view { margin: 0; }
@media (max-width: 720px), (max-height: 500px) and (max-width: 1000px) {
  .wafer-cols-head { align-items: flex-start; }
}

/* Collapsed shared left column: the strip names both panels (Library, Runsheet info); the one in
   view is in normal text, the other muted; each opens its panel. Separate columns name only their own. */
.strip-tab { padding: 6px 2px; border: none; background: none; cursor: pointer; border-radius: var(--radius); }
.panel.collapsed > .panel-head > .strip-tab:hover { color: var(--text); background: var(--bar-hover); }
.panel.collapsed > .panel-head > .strip-tab:not(.other) { color: var(--text); }
.layout:not(.left-tabbed) .panel.collapsed > .panel-head > .strip-tab.other { display: none; }
@media (pointer: coarse) { .strip-tab { min-width: 40px; min-height: 44px; } }

/* Phone step cards, one compact row (VIS4-2 / UX4-13): FS | PS | name with the detail on one 12 px
   line | thumbnail | chevron (module heads) or trash (open step). The family icon and the drag grip
   are hidden: the thumbnail and the name identify the step, and the editor's ↑ / ↓ reorder it
   (no drag that competes with scrolling). The wafer card stays a separate card below on phones and
   beside the step on touch tablets, which use the same row (VIS5-2). */
@media (max-width: 720px), (pointer: coarse) and (max-width: 1100px) {
  .step-card:not(.section-card) > .step-head { flex-wrap: nowrap; gap: 6px; min-height: 48px; padding: 4px 6px; }
  .step-card:not(.section-card) > .step-head > .drag-handle,
  .step-card:not(.section-card) > .step-head > .icon-slot,
  .step-card:not(.section-card) > .step-head > .collapse-spacer { display: none; }
  .step-card:not(.section-card) > .step-head > .side-btn { order: 1; }
  .step-card:not(.section-card) > .step-head > .ps { order: 2; min-width: 0; }
  .step-card:not(.section-card) > .step-head > .step-toggle { order: 3; flex: 1 1 auto; min-width: 0; min-height: 40px; justify-content: center; }
  .step-card:not(.section-card) > .step-head > .badge { order: 4; margin-left: 0; }
  .step-card:not(.section-card) > .step-head > .step-thumb-wrap { order: 5; }
  .step-card:not(.section-card) > .step-head > .collapse-btn { order: 6; }
  .step-card:not(.section-card) > .step-head > .step-trash { order: 7; }
  /* The trash appears only on the open step: closed rows give its room to the name. */
  .step-card:not(.open) > .step-head > .step-trash { display: none; }
  .step-card:not(.section-card) .step-name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.25; }
  .step-card:not(.section-card) .step-detail { white-space: nowrap; }
  .step-card:not(.section-card) > .step-head .step-thumb { width: 56px; height: 32px; }
}
@media (max-width: 720px) {
  /* Phone cross-section: taller picture (the legend sits under it, VIS5-6). */
  .stack-body .sv-canvas-wrap { aspect-ratio: 4 / 3; }
  /* Every section can reach the top of the screen, so the bottom nav marks the one tapped (VIS5-7);
     each starts as a new screen. */
  .layout > .panel-library { min-height: calc(100dvh - var(--topbar-h) - var(--phone-nav-h, 56px)); }
  .layout > .panel-stack, .layout > .panel-info, .layout > .panel-library { margin-top: 24px; border-top: 1px solid var(--border); }
  .wafer-card { margin-top: 0; }
  /* Section titles start at the strongest left edge: the grip moves to the end of the row (VIS5-10). */
  .step-card.section-card > .step-head > .drag-handle { order: 10; }
}
.sv-modal-foot.template-foot { justify-content: flex-start; }

/* Skip links (UX4-12): hidden until focused, first in the tab order. */
.skip-link { position: absolute; z-index: 100; left: 8px; top: -60px; padding: 8px 12px; border-radius: var(--radius); background: var(--surface); color: var(--accent); box-shadow: var(--shadow-pop); font-weight: 600; }
.skip-link:focus { top: 8px; }
.sim-done-note { margin-right: auto; align-self: center; }
