/* 裁衣台 — layout: tool rail | canvas | inspector.
   Design tokens follow 层构 Layerform (compositor-win/src/styles.css): same radius / spacing / type scales,
   elevation, controls and the same dark palette, so the two apps read as one family. 裁衣台 also has a light theme. */
:root {
  /* layout */
  --top-h: 48px;
  --rail-w: 76px;
  --panel-w: 340px;
  --bar-h: 44px;

  /* radii */
  --r-xs: 3px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-pill: 999px;
  --r: var(--r-lg);

  /* spacing */
  --sp-1: 2px;
  --sp-2: 4px;
  --sp-3: 6px;
  --sp-4: 8px;
  --sp-5: 12px;
  --sp-6: 16px;
  --sp-7: 20px;
  --sp-8: 24px;
  --sp-9: 32px;

  /* type: Latin in Segoe UI, Chinese in the system UI font (微软雅黑 / 苹方) */
  --font: 'Segoe UI Variable Text', 'Segoe UI', 'Microsoft YaHei UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Mono', Consolas, ui-monospace, 'SF Mono', monospace;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 13px;
  --fs-lg: 14px;
  --fs-xl: 16px;
  --fs-2xl: 22px;
  --fw-medium: 500;
  --fw-semibold: 600;

  /* controls */
  --ctl-h: 30px;
  --ctl-h-sm: 26px;
  --ctl-h-lg: 38px;

  /* motion */
  --dur-fast: 80ms;
  --dur: 120ms;
  --dur-slow: 200ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  /* region overlay colours (match garment.js) */
  --keep: #ff5a5f;
  --add: #3aa0ff;

  /* light theme */
  --bg: #f3f3f5;
  --panel: #ffffff;
  --panel-2: #f6f6f8;
  --elev: #ffffff;
  --elev-a: rgba(255, 255, 255, 0.92);
  --field: #f1f1f4;
  --raise: #ffffff;
  --raise-hover: #f5f5f8;
  --press-solid: #ececf0;
  --hover: rgba(24, 24, 32, 0.05);
  --press: rgba(24, 24, 32, 0.09);
  --line: #e3e3e8;
  --line-soft: #ededf1;
  --line-strong: #c8c8d0;
  --btn-line: #dcdce2;
  --text: #1d1d22;
  --text-dim: #5b5b67;
  --text-faint: #8a8a96;
  --text-disabled: #b5b5be;
  --accent: #2f6fed;
  --accent-hover: #4380f5;
  --accent-press: #2560d6;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --accent-faint: rgba(47, 111, 237, 0.06);
  --accent-line: rgba(47, 111, 237, 0.42);
  --accent-text: #2459c9;
  --danger: #d93d32;
  --danger-soft: rgba(217, 61, 50, 0.1);
  --warning: #a8650f;
  --warning-soft: rgba(230, 160, 40, 0.16);
  --success: #1e8a50;
  --success-soft: rgba(30, 138, 80, 0.12);
  --canvas-bg: #e1e1e6;
  --grid: rgba(30, 30, 50, 0.045);
  --grid-strong: rgba(30, 30, 50, 0.08);
  --canvas-text: #3b3b45;
  --canvas-hover: rgba(0, 0, 0, 0.06);
  --card-dim: rgba(225, 225, 230, 0.24);
  --chip-edge: rgba(0, 0, 0, 0.12); /* outline that keeps colour chips visible on the panel */
  --track: #dadae0;
  --tip-bg: #202026;
  --tip-text: #f3f3f6;
  --toast-bg: #24242a;
  --toast-text: #f3f3f6;
  --toast-line: rgba(255, 255, 255, 0.06);
  --toast-accent: #8ebcff;
  --shadow-1: 0 1px 2px rgba(20, 20, 30, 0.08);
  --shadow-2: 0 10px 28px rgba(20, 20, 30, 0.14), 0 2px 6px rgba(20, 20, 30, 0.08);
  --shadow-3: 0 18px 50px rgba(20, 20, 30, 0.22), 0 2px 8px rgba(20, 20, 30, 0.1);
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  --focus: rgba(47, 111, 237, 0.55);
  --focus-ring: 0 0 0 2px var(--focus);

  /* names older module code uses */
  --surface: var(--panel);
  --surface-2: var(--panel-2);
  --ink: var(--text);
  --muted: var(--text-dim);
  --good: var(--success);
  --warn: var(--warning);
  --bad: var(--danger);
  --good-soft: var(--success-soft);
  --warn-soft: var(--warning-soft);
  --bad-soft: var(--danger-soft);

  color-scheme: light;
}
/* dark theme = Layerform's palette */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #19191c; --panel: #222226; --panel-2: #29292e; --elev: #2a2a2f; --elev-a: rgba(42, 42, 47, 0.92); --field: #18181b;
    --raise: #33333a; --raise-hover: #3d3d45; --press-solid: #2c2c32; --hover: rgba(255, 255, 255, 0.07); --press: rgba(255, 255, 255, 0.11);
    --line: #38383f; --line-soft: #2d2d33; --line-strong: #4a4a52; --btn-line: rgba(255, 255, 255, 0.07);
    --text: #ececf0; --text-dim: #a6a6b0; --text-faint: #7c7c86; --text-disabled: #5d5d66;
    --accent: #3d8bff; --accent-hover: #5a9dff; --accent-press: #2c76e6; --accent-soft: rgba(61, 139, 255, 0.2); --accent-faint: rgba(61, 139, 255, 0.1); --accent-line: rgba(61, 139, 255, 0.5); --accent-text: #8ebcff;
    --danger: #ff5a4f; --danger-soft: rgba(255, 90, 79, 0.14); --warning: #f0b545; --warning-soft: rgba(255, 210, 63, 0.12); --success: #4cc38a; --success-soft: rgba(76, 195, 138, 0.14);
    --canvas-bg: #141416; --grid: rgba(255, 255, 255, 0.028); --grid-strong: rgba(255, 255, 255, 0.055); --canvas-text: #c9c9d1; --canvas-hover: rgba(255, 255, 255, 0.07); --card-dim: rgba(20, 20, 22, 0.32); --chip-edge: rgba(255, 255, 255, 0.14);
    --track: #45454d; --tip-bg: #3a3a42; --toast-bg: rgba(46, 46, 52, 0.98); --toast-line: #44444c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35); --shadow-2: 0 10px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3); --shadow-3: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
    --edge: inset 0 1px 0 rgba(255, 255, 255, 0.05); --focus: rgba(61, 139, 255, 0.65);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #19191c; --panel: #222226; --panel-2: #29292e; --elev: #2a2a2f; --elev-a: rgba(42, 42, 47, 0.92); --field: #18181b;
  --raise: #33333a; --raise-hover: #3d3d45; --press-solid: #2c2c32; --hover: rgba(255, 255, 255, 0.07); --press: rgba(255, 255, 255, 0.11);
  --line: #38383f; --line-soft: #2d2d33; --line-strong: #4a4a52; --btn-line: rgba(255, 255, 255, 0.07);
  --text: #ececf0; --text-dim: #a6a6b0; --text-faint: #7c7c86; --text-disabled: #5d5d66;
  --accent: #3d8bff; --accent-hover: #5a9dff; --accent-press: #2c76e6; --accent-soft: rgba(61, 139, 255, 0.2); --accent-faint: rgba(61, 139, 255, 0.1); --accent-line: rgba(61, 139, 255, 0.5); --accent-text: #8ebcff;
  --danger: #ff5a4f; --danger-soft: rgba(255, 90, 79, 0.14); --warning: #f0b545; --warning-soft: rgba(255, 210, 63, 0.12); --success: #4cc38a; --success-soft: rgba(76, 195, 138, 0.14);
  --canvas-bg: #141416; --grid: rgba(255, 255, 255, 0.028); --grid-strong: rgba(255, 255, 255, 0.055); --canvas-text: #c9c9d1; --canvas-hover: rgba(255, 255, 255, 0.07); --card-dim: rgba(20, 20, 22, 0.32); --chip-edge: rgba(255, 255, 255, 0.14);
  --track: #45454d; --tip-bg: #3a3a42; --toast-bg: rgba(46, 46, 52, 0.98); --toast-line: #44444c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35); --shadow-2: 0 10px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3); --shadow-3: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  --edge: inset 0 1px 0 rgba(255, 255, 255, 0.05); --focus: rgba(61, 139, 255, 0.65);
  color-scheme: dark;
}
@media (min-width: 1680px) { :root { --panel-w: 360px; } }

/* ── base ── */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: var(--fs-md)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::selection { background: var(--accent-soft); }
kbd { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: var(--r-xs); font: 500 var(--fs-xs)/17px var(--mono); text-align: center; color: var(--text-dim); background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px; white-space: nowrap; }
i[data-icon] { display: contents; font-style: normal; }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.logo-mark { display: block; flex: none; }

@keyframes cyt-pop { from { opacity: 0; scale: 0.97; } }
@keyframes cyt-fade { from { opacity: 0; } }
@keyframes cyt-rise { from { opacity: 0; translate: 0 8px; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--panel-w);
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  grid-template-areas: "top top top" "rail stage panel";
}

/* ── top bar ── */
.topbar { grid-area: top; display: flex; align-items: center; gap: var(--sp-5); padding: 0 var(--sp-5) 0 var(--sp-6); background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; position: relative; z-index: 10; }
.brand { display: flex; align-items: center; gap: 9px; flex: none; height: 28px; padding-right: var(--sp-5); border-right: 1px solid var(--line); }
.brand .logo-mark { width: 26px; height: 26px; }
.brand-name { font-weight: 700; font-size: var(--fs-xl); letter-spacing: 0.12em; }
.doc-chip { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; flex: 1 1 auto; }
.doc-name { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 420px; }
.doc-chip.is-empty .doc-name { font-weight: 400; color: var(--text-faint); }
.doc-meta { color: var(--text-faint); font-size: var(--fs-sm); white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-meta b { color: var(--text-dim); font-weight: var(--fw-medium); }
.top-actions { display: flex; align-items: center; gap: var(--sp-4); flex: none; }
.top-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.link-slot { display: flex; align-items: center; gap: var(--sp-4); }
.link-slot:empty { display: none; }

/* ── buttons (reusable: .btn .primary .ghost .danger .sm/.small .lg .icon .block .link .accent) ── */
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--ctl-h); padding: 0 12px; border-radius: var(--r-md); border: 1px solid var(--btn-line); background: var(--raise); color: var(--text); box-shadow: var(--shadow-1), var(--edge); font-size: var(--fs-md); font-weight: var(--fw-medium); white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast); }
.btn svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover:not(:disabled) { background: var(--raise-hover); border-color: var(--line-strong); }
.btn:active:not(:disabled) { background: var(--press-solid); box-shadow: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible { box-shadow: var(--focus-ring); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; box-shadow: var(--shadow-1), inset 0 1px 0 rgba(255, 255, 255, 0.14); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: transparent; }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }
.btn.accent { background: var(--accent-faint); border-color: var(--accent-line); color: var(--accent-text); box-shadow: none; }
.btn.accent:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-dim); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); border-color: transparent; color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); border-color: transparent; }
.btn.sm, .btn.small { height: var(--ctl-h-sm); padding: 0 10px; font-size: var(--fs-sm); }
.btn.sm svg, .btn.small svg { width: 14px; height: 14px; }
.btn.lg { height: var(--ctl-h-lg); padding: 0 18px; font-size: var(--fs-lg); border-radius: 8px; }
.btn.lg svg { width: 18px; height: 18px; }
.btn.icon { width: var(--ctl-h); padding: 0; }
.btn.icon.sm, .btn.icon.small { width: var(--ctl-h-sm); }
.btn.block { width: 100%; }
.btn.link { height: auto; padding: 0 2px; border: 0; background: none; box-shadow: none; color: var(--accent-text); font-weight: var(--fw-medium); }
.btn.link:hover:not(:disabled) { background: none; text-decoration: underline; }
.btn .badge { margin-left: 2px; }
.btn.icon .badge { position: absolute; top: -5px; right: -5px; margin: 0; box-shadow: 0 0 0 2px var(--panel); }
.btn-split { display: inline-flex; }
.btn-split > .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-split > .btn.caret { width: 26px; padding: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 1px; }
.btn-split > .btn.caret svg { width: 14px; height: 14px; }

/* ── badges (reusable) ── */
.badge { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 5px; border-radius: var(--r-pill); background: var(--accent); color: #fff; font: 600 10.5px/1 var(--font); font-variant-numeric: tabular-nums; }
.badge.neutral { background: var(--field); color: var(--text-dim); box-shadow: inset 0 0 0 1px var(--line); }
.badge.danger { background: var(--danger); }
.badge.success { background: var(--success); }
.badge.warn { background: var(--warning); }
.badge.dot { min-width: 8px; width: 8px; height: 8px; padding: 0; }

/* ── menus (reusable: .menu > .item / .sep / .menu-title; .item may hold svg, .lbl, small, .keys) ── */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; max-width: 340px; background: var(--elev); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: var(--shadow-2), var(--edge); z-index: 60; display: grid;
  animation: cyt-pop var(--dur) var(--ease); transform-origin: top right; }
.menu .item, .menu > button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 6px 10px; border: 0; border-radius: var(--r-sm); background: none; text-align: left; color: var(--text); cursor: pointer; font-size: var(--fs-md); }
.menu .item svg { width: 16px; height: 16px; flex: none; color: var(--text-dim); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu .item .lbl { flex: 1; display: grid; line-height: 1.35; min-width: 0; }
.menu .item small { color: var(--text-faint); font-size: var(--fs-xs); }
.menu .item .keys { color: var(--text-faint); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; margin-left: auto; }
.menu .item:hover:not(:disabled), .menu .item:focus-visible, .menu > button:hover { background: var(--accent); color: #fff; box-shadow: none; }
.menu .item:hover:not(:disabled) svg, .menu .item:hover:not(:disabled) small, .menu .item:hover:not(:disabled) .keys, .menu .item:focus-visible small, .menu .item:focus-visible svg { color: rgba(255, 255, 255, 0.85); }
.menu .item:disabled { color: var(--text-disabled); cursor: default; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 6px; }
.menu .menu-title { padding: 6px 10px 2px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-faint); letter-spacing: 0.04em; }
.menu-slot { display: grid; } /* items added by other features bring their own .sep / .menu-title */

/* ── tooltip ── */
.tip { position: fixed; z-index: 300; display: flex; align-items: center; gap: 8px; max-width: 300px; padding: 6px 9px; border-radius: var(--r-md); background: var(--tip-bg); color: var(--tip-text); font-size: var(--fs-sm); line-height: 1.45; box-shadow: var(--shadow-2); pointer-events: none; animation: cyt-fade var(--dur); }
.tip kbd { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.14); color: rgba(255, 255, 255, 0.85); flex: none; }

/* ── dialogs (reusable: ui.dialog()) ── */
.dialog-backdrop { position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 24px; background: rgba(12, 12, 16, 0.45); animation: cyt-fade var(--dur); }
.dialog { width: min(var(--dlg-w, 460px), 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--elev); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-3), var(--edge); animation: cyt-pop var(--dur) var(--ease); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px 20px; border-bottom: 1px solid var(--line-soft); }
.dialog-head h3 { margin: 0; flex: 1; font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.dialog-body { padding: 16px 20px 18px; overflow: auto; display: grid; gap: 12px; }
.dialog-body p { margin: 0; color: var(--text-dim); }
.dialog-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line-soft); background: var(--panel-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.dialog-foot .grow { flex: 1; }
.form-field { display: grid; gap: 6px; font-size: var(--fs-md); }
.form-field > span { color: var(--text-dim); font-size: var(--fs-sm); }
.form-error { color: var(--danger); font-size: var(--fs-sm); }
.keys-table { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; font-size: var(--fs-md); }
.keys-table dt { color: var(--text); }
.keys-table dd { margin: 0; display: flex; gap: 4px; justify-content: flex-end; }
.keys-group { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-faint); letter-spacing: 0.06em; margin-top: 6px; grid-column: 1 / -1; }
.keys-table dd .hint { margin: 0 2px; }
.steps { margin: 0 0 4px; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 8px; font-size: var(--fs-md); color: var(--text-dim); }
.steps li { counter-increment: step; display: flex; gap: 10px; align-items: baseline; line-height: 1.55; }
.steps li::before { content: counter(step); flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); font: 600 var(--fs-xs)/1 var(--font); transform: translateY(-1px); }
.steps b { color: var(--text); font-weight: var(--fw-semibold); }

/* ── module rail ── */
.rail { grid-area: rail; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.rail-items { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 1px; scrollbar-width: none; }
.rail-group { font-size: 10.5px; font-weight: var(--fw-semibold); color: var(--text-faint); text-align: center; letter-spacing: 0.16em; margin: 10px 0 2px; }
.rail-group:first-child { margin-top: 0; }
.rail-item { position: relative; display: grid; justify-items: center; gap: 2px; padding: 7px 2px 6px; margin: 0 8px; border: 0; border-radius: var(--r-lg); background: none; color: var(--text-dim); font-size: var(--fs-sm); line-height: 1.3; cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast); }
.rail-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-item:hover { background: var(--hover); color: var(--text); }
.rail-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent-text); font-weight: var(--fw-semibold); }
.rail-item[aria-current="true"]::before { content: ""; position: absolute; left: -8px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.rail-foot { flex: none; display: flex; justify-content: center; gap: 2px; padding: 6px 6px 8px; border-top: 1px solid var(--line-soft); }
.rail-mini { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: var(--r-md); background: none; color: var(--text-faint); cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast); }
.rail-mini svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-mini:hover { background: var(--hover); color: var(--text); }
@media (max-height: 700px) { .rail-item { padding: 5px 2px 4px; } .rail-group { margin-top: 6px; } }

/* ── stage: neutral canvas (judging colour needs a neutral surround) with a faint 1 cm cutting-mat grid ── */
.stage { grid-area: stage; position: relative; display: grid; grid-template-rows: minmax(0, 1fr) var(--bar-h); min-width: 0; min-height: 0; background: var(--canvas-bg); }
.viewport { position: relative; overflow: hidden; min-height: 0; touch-action: none;
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px), linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 190px 190px, 190px 190px, 38px 38px, 38px 38px; }
/* infinite board: cards live in world coordinates inside #board (pan/zoom transform); --z = 1 / zoom keeps outlines a constant screen width.
   Their title bars live in screen space (#labels) so they stay readable at any zoom */
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; --z: 1; }
.card { position: absolute; background: repeating-conic-gradient(#d6d6db 0 25%, #f4f4f6 0 50%) 0 0 / 16px 16px; box-shadow: 0 calc(8px * var(--z)) calc(30px * var(--z)) rgba(0, 0, 0, 0.25); }
.card canvas { display: block; width: 100%; height: 100%; }
.card .card-ov { position: absolute; inset: 0; pointer-events: none; }
.card.active { outline: calc(2px * var(--z)) solid var(--accent); outline-offset: calc(3px * var(--z)); }
.card:not(.active) { cursor: pointer; }
.card:not(.active)::after { content: ""; position: absolute; inset: 0; background: var(--card-dim); transition: background-color var(--dur); }
.card:not(.active):hover::after { background: transparent; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.card-label { position: absolute; display: flex; align-items: center; gap: 8px; height: 26px; padding: 0 3px 0 10px; border-radius: 7px 7px 0 0; color: var(--canvas-text); font-size: var(--fs-sm); pointer-events: auto; cursor: grab; user-select: none; min-width: 0; transition: background-color var(--dur-fast); }
.card-label:hover { background: var(--canvas-hover); }
.card-label.active { background: var(--accent); color: #fff; font-weight: var(--fw-semibold); }
.card-label .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.card-label .sz { opacity: 0.7; font: var(--fs-xs) var(--mono); white-space: nowrap; font-weight: 400; }
.card-label .st { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); white-space: nowrap; font-weight: 400; opacity: 0.9; }
.card-label .st.err { color: var(--danger); opacity: 1; }
.card-label.active .st.err { color: #fff; }
.card-label button { margin-left: auto; flex: none; width: 20px; height: 20px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: inherit; cursor: pointer; opacity: 0.75; }
.card-label button svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.card-label button:hover { background: var(--danger); color: #fff; opacity: 1; }
.viewport.tool-click { cursor: crosshair; }
.viewport.panning { cursor: grabbing; }
.viewport.on-divider { cursor: ew-resize; }

/* empty board: welcome + drop target */
.board-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; overflow: auto; }
.viewport:has(.drop-hint:not([hidden])) .board-empty { visibility: hidden; }
.welcome { width: min(540px, 100%); display: grid; justify-items: center; gap: 10px; padding: 32px 32px 24px; text-align: center; border-radius: 18px; background: var(--panel); border: 1.5px dashed var(--line-strong); box-shadow: var(--shadow-2); animation: cyt-rise var(--dur-slow) var(--ease); }
.welcome .logo-mark.big { width: 60px; height: 60px; margin-bottom: 4px; filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.25)); }
.welcome h1 { margin: 0; font-size: var(--fs-2xl); font-weight: var(--fw-semibold); letter-spacing: 0.02em; }
.welcome > p { margin: 0; color: var(--text-dim); }
.welcome-actions { display: flex; gap: 10px; margin: 10px 0 6px; flex-wrap: wrap; justify-content: center; }
.welcome-feats { list-style: none; margin: 8px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line-soft); display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; width: 100%; }
.welcome-feats button { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px 0 8px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--panel-2); color: var(--text-dim); font-size: var(--fs-sm); cursor: pointer; }
.welcome-feats button:hover { color: var(--accent-text); border-color: var(--accent-line); background: var(--accent-faint); }
.welcome-feats svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.welcome-note { display: inline-flex; align-items: center; gap: 6px; margin: 6px 0 0; font-size: var(--fs-sm); color: var(--text-faint); }
.welcome-note svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.welcome kbd { margin: 0 1px; }
.drop-hint { position: absolute; inset: 12px; z-index: 6; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 14px; background: var(--accent-faint); pointer-events: none; animation: cyt-fade var(--dur); }
.drop-hint > div { display: grid; justify-items: center; gap: 4px; padding: 20px 32px; border-radius: var(--r-xl); background: var(--elev); box-shadow: var(--shadow-2); color: var(--text); }
.drop-hint svg { width: 30px; height: 30px; color: var(--accent); fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 4px; }
.drop-hint b { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
.drop-hint span { color: var(--text-dim); font-size: var(--fs-sm); }

/* AI status (top-left of the canvas) */
.status { position: absolute; left: 12px; top: 12px; z-index: 4; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; pointer-events: none; max-width: calc(100% - 24px); }
.status:empty { display: none; }
.mchip { pointer-events: auto; display: inline-flex; align-items: center; gap: 8px; min-height: 28px; padding: 3px 12px 3px 10px; border-radius: var(--r-pill); background: var(--elev-a); border: 1px solid var(--line); box-shadow: var(--shadow-1); font-size: var(--fs-sm); color: var(--text-dim); backdrop-filter: blur(12px); animation: cyt-fade var(--dur); }
.mchip i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.mchip[data-s="ready"] { opacity: 0.8; }
.mchip[data-s="ready"] i { background: var(--success); }
.mchip[data-s="busy"] i { background: var(--warning); animation: pulse 1s infinite; }
.mchip[data-s="busy"] { color: var(--text); }
.mchip[data-s="error"] { color: var(--danger); border-color: var(--danger); }
.mchip[data-s="error"] i { background: var(--danger); }
.mchip .bar { width: 96px; height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; flex: none; }
.mchip .bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width var(--dur-slow) linear; }
.mchip .num { font: var(--fs-xs) var(--mono); color: var(--text-faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mchip .btn.link { font-size: var(--fs-sm); }

/* busy pill (top-centre of the canvas) */
.busy { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: min(460px, calc(100% - 24px)); padding: 9px 16px 9px 12px; border-radius: var(--r-lg); background: var(--elev); border: 1px solid var(--line); box-shadow: var(--shadow-2), var(--edge); font-size: var(--fs-md); animation: cyt-pop var(--dur) var(--ease); }
.busy-body { flex: 1; display: grid; gap: 6px; min-width: 0; }
.busy-body > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busy-bar { height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.busy-bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width var(--dur-slow) linear; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--track); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; }
.spinner.xs { width: 10px; height: 10px; border-width: 1.5px; border-color: currentColor; border-top-color: transparent; opacity: 0.8; }

/* canvas toolbar (docked under the canvas) */
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: 0 var(--sp-4); background: var(--panel); border-top: 1px solid var(--line); min-width: 0; overflow-x: auto; scrollbar-width: none; }
.sb-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 10px; border: 0; border-radius: var(--r-md); background: none; color: var(--text-dim); font-size: var(--fs-sm); white-space: nowrap; cursor: pointer; flex: none; user-select: none; transition: background-color var(--dur-fast), color var(--dur-fast); }
.tb-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tb-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.tb-btn:active:not(:disabled), .tb-btn.held { background: var(--press); color: var(--text); }
.tb-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.tb-btn:disabled { opacity: 0.4; cursor: default; }
.tb-btn.icon { width: 30px; padding: 0; }
.tb-btn.zoom { min-width: 54px; padding: 0 6px; font: var(--fs-sm) var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.stage-bar input.split-range { width: 120px; flex: none; margin: 0 6px; }
.stage.no-doc .stage-bar .tb-btn { opacity: 0.4; pointer-events: none; }

/* ── inspector panel ── */
.panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); }
.p-head { flex: none; display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px 14px; border-bottom: 1px solid var(--line-soft); }
.p-icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-text); }
.p-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.p-head h2 { margin: 0; font-size: var(--fs-xl); font-weight: var(--fw-semibold); line-height: 1.35; text-wrap: balance; }
.p-head p { margin: 3px 0 0; color: var(--text-dim); font-size: var(--fs-sm); line-height: 1.55; }
.p-body { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 18px 24px; display: grid; align-content: start; }
.p-foot { flex: none; display: grid; gap: 6px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--panel); border-top: 1px solid var(--line); }
.p-foot .hint { text-align: center; }
.p-foot .foot-note { display: flex; gap: 8px; align-items: flex-start; text-align: left; color: var(--text-dim); }
.p-foot .foot-note svg { width: 15px; height: 15px; margin-top: 2px; flex: none; color: var(--accent-text); }
.p-foot .row > .btn { flex: 1; }
.p-empty { display: grid; justify-items: center; gap: 10px; margin-top: 18px; padding: 24px 16px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--panel-2); color: var(--text-dim); }
.p-empty b { color: var(--text); font-size: var(--fs-lg); }
.p-empty .row { justify-content: center; }
.sec { display: grid; gap: 10px; padding: 14px 0 16px; border-bottom: 1px solid var(--line-soft); }
.sec:last-child { border-bottom: 0; }
.sec-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 18px; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-dim); letter-spacing: 0.04em; }
.sec-title .btn.link { font-size: var(--fs-sm); letter-spacing: 0; }
.hint { font-size: var(--fs-sm); line-height: 1.6; color: var(--text-dim); margin: 0; }
.p-body .hint { color: var(--text-faint); }
.sec-inner { display: grid; gap: 12px; }

/* fields + sliders */
.field { display: grid; gap: 4px; }
.field-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 22px; font-size: var(--fs-md); }
.field-row > label, .field-row > span:first-child { min-width: 0; }
.field-val { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.field-row output { min-width: 42px; text-align: right; font: var(--fs-sm) var(--mono); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.field-row output.changed { color: var(--accent-text); font-weight: var(--fw-semibold); }
.reset { width: 20px; height: 20px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-faint); cursor: pointer; }
.reset svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.reset:hover { background: var(--hover); color: var(--text); }
input[type="range"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 18px; margin: 0; background: transparent; cursor: pointer; --a: 0%; --b: 0%; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--track) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--track) var(--b)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--track) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--track) var(--b)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.3); transition: scale var(--dur-fast); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.3); }
input[type="range"]:hover::-webkit-slider-thumb { scale: 1.12; }
input[type="range"]:active::-webkit-slider-thumb { scale: 1.2; }
input[type="range"]:focus-visible { box-shadow: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28), 0 0 0 4px var(--focus); }
.split-range { --a: 0%; --b: 0%; }

/* segmented control */
.seg { display: flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: var(--field); border: 1px solid var(--line-soft); border-radius: 7px; }
.seg button { flex: 1 1 auto; min-height: 26px; padding: 3px 8px; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-dim); font-size: var(--fs-sm); white-space: nowrap; cursor: pointer; transition: background-color var(--dur-fast), color var(--dur-fast); }
.seg button:hover:not([aria-pressed="true"]) { color: var(--text); background: var(--hover); }
.seg button[aria-pressed="true"] { background: var(--raise); color: var(--text); font-weight: var(--fw-semibold); box-shadow: var(--shadow-1), var(--edge); }
.row > .seg { flex: 1; }

/* checkbox */
.check { display: flex; align-items: center; gap: 8px; min-height: 24px; font-size: var(--fs-md); cursor: pointer; }
.check input { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; margin: 0; flex: none; border: 1.5px solid var(--line-strong); border-radius: 4px; background: var(--field); display: inline-grid; place-content: center; cursor: pointer; transition: background-color var(--dur-fast), border-color var(--dur-fast); }
.check input:hover { border-color: var(--text-faint); }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 8px; height: 4px; border: solid #fff; border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.txt { width: 100%; height: var(--ctl-h); padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--field); color: var(--text); transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.txt:hover { border-color: var(--line-strong); }
.txt:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }
.btn-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.btn-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.btn-grid > .btn { padding-inline: 6px; }

/* colour palette (ui.palette) */
.palette { display: grid; gap: 12px; }
.pal-group { display: grid; gap: 6px; }
.pal-name { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-faint); letter-spacing: 0.04em; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 8px 6px; } /* 6 per row in the side panel */
.sw { display: grid; gap: 4px; min-width: 0; padding: 0; border: 0; background: none; color: var(--text-dim); cursor: pointer; }
.sw-chip { position: relative; display: block; height: 30px; border-radius: var(--r-md); background: var(--c); box-shadow: inset 0 0 0 1px var(--chip-edge); transition: box-shadow var(--dur-fast), transform var(--dur-fast); }
.sw.light .sw-chip { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); }
:root[data-theme="dark"] .sw.light .sw-chip { box-shadow: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sw.light .sw-chip { box-shadow: none; } }
.sw:hover .sw-chip { transform: translateY(-1px); box-shadow: inset 0 0 0 1px var(--chip-edge), 0 3px 8px rgba(0, 0, 0, 0.18); }
.sw-name { font-size: var(--fs-xs); line-height: 1.2; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sw:hover .sw-name { color: var(--text); }
.sw[aria-pressed="true"] .sw-chip { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); transform: none; }
.sw[aria-pressed="true"] .sw-name { color: var(--text); font-weight: var(--fw-semibold); }
.sw:focus-visible { box-shadow: none; }
.sw:focus-visible .sw-chip { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--focus); }
.sw .tick { position: absolute; right: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 0 0 1.5px #fff; }
.sw .tick svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.current { display: flex; gap: 12px; align-items: center; padding: 10px 10px 10px 10px; background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: var(--r-lg); }
.current .big { width: 44px; height: 44px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--chip-edge); flex: none; }
.current .big.none { background: repeating-linear-gradient(45deg, var(--field) 0 5px, var(--panel) 5px 10px) !important; box-shadow: inset 0 0 0 1px var(--line); }
.current > div:not(.big) { flex: 1; min-width: 0; }
.current b { display: block; font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.current code { font: var(--fs-sm) var(--mono); color: var(--text-dim); }
.current .btn { flex: none; }
.custom-color { position: relative; display: flex; align-items: center; gap: 10px; height: var(--ctl-h); padding: 0 10px; border: 1px solid var(--btn-line); border-radius: var(--r-md); background: var(--raise); box-shadow: var(--shadow-1); cursor: pointer; font-size: var(--fs-md); color: var(--text-dim); transition: border-color var(--dur-fast); }
.custom-color:hover { border-color: var(--line-strong); color: var(--text); }
.custom-color .chip { width: 18px; height: 18px; border-radius: 5px; box-shadow: inset 0 0 0 1px var(--chip-edge); flex: none; }
.custom-color .chip.none { background: conic-gradient(#ff5470, #ffc23a, #4cc38a, #3fa2ff, #a46bff, #ff5470) !important; }
.custom-color .color-in { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.color-in { width: 100%; height: var(--ctl-h); border: 1px solid var(--line); border-radius: var(--r-md); padding: 2px; background: var(--field); cursor: pointer; }

/* selected-colour tags (批量色卡) */
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 4px; border-radius: var(--r-pill); background: var(--panel-2); border: 1px solid var(--line-soft); font-size: var(--fs-sm); }
.tag i { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--chip-edge); flex: none; }
.tag button { width: 18px; height: 18px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-faint); cursor: pointer; font-size: 13px; line-height: 1; }
.tag button:hover { background: var(--danger-soft); color: var(--danger); }

/* region list */
.regions { display: grid; gap: 4px; }
.region { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 3px 4px 3px 10px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel); font-size: var(--fs-md); transition: border-color var(--dur-fast); }
.region:hover { border-color: var(--line-strong); }
.region .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.region input { flex: 1; min-width: 0; height: 26px; border: 0; background: none; padding: 0 4px; border-radius: var(--r-sm); }
.region input:hover { background: var(--hover); }
.region input:focus { background: var(--field); box-shadow: 0 0 0 2px var(--accent-soft); }
.region small { color: var(--text-faint); font-size: var(--fs-xs); white-space: nowrap; }
.region button { width: 24px; height: 24px; flex: none; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-faint); cursor: pointer; font-size: 15px; line-height: 1; }
.region button:hover { background: var(--danger-soft); color: var(--danger); }
.empty { font-size: var(--fs-sm); line-height: 1.6; color: var(--text-dim); padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); text-align: center; background: var(--panel-2); }

/* quality check */
.qc-summary { display: flex; gap: 14px; align-items: center; padding: 12px 14px; border-radius: var(--r-lg); background: var(--panel-2); border: 1px solid var(--line-soft); }
.qc-summary b { font-size: var(--fs-lg); }
.qc-score { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: -0.02em; }
.qc-list { display: grid; gap: 6px; }
.qc-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 9px 10px; border-radius: var(--r-md); background: var(--panel); border: 1px solid var(--line-soft); font-size: var(--fs-md); }
.qc-item small { display: block; color: var(--text-dim); font-size: var(--fs-sm); line-height: 1.5; }
.qc-val { font: var(--fs-sm) var(--mono); color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; font-size: var(--fs-xs); padding: 1px 8px; border-radius: var(--r-pill); font-weight: var(--fw-semibold); white-space: nowrap; }
.pill.good { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.qc-batch { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.qc-batch th { text-align: left; padding: 6px 6px; color: var(--text-faint); font-weight: var(--fw-semibold); border-bottom: 1px solid var(--line); }
.qc-batch td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line-soft); }
.qc-batch td:last-child, .qc-batch th:last-child { text-align: right; }
.qc-batch tr[data-i] { cursor: pointer; }
.qc-batch tr[data-i]:hover td { background: var(--hover); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--r-md); }

/* batch swatch results */
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { display: grid; gap: 4px; font-size: var(--fs-xs); color: var(--text-dim); text-align: center; }
.thumb img { width: 100%; border-radius: var(--r-md); background: var(--panel-2); aspect-ratio: 3 / 4; object-fit: cover; }

/* ── toast (one at a time; ui.toast) ── */
.toast { position: fixed; z-index: 120; left: calc(var(--rail-w) + (100vw - var(--rail-w) - var(--panel-w)) / 2); bottom: calc(var(--bar-h) + 16px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: min(560px, calc(100vw - var(--rail-w) - var(--panel-w) - 32px)); padding: 9px 8px 9px 12px; border-radius: var(--r-lg);
  background: var(--toast-bg); color: var(--toast-text); border: 1px solid var(--toast-line); box-shadow: var(--shadow-2); font-size: var(--fs-md); animation: cyt-rise var(--dur-slow) var(--ease); }
.toast .t-icon { flex: none; display: grid; place-items: center; color: var(--toast-accent); }
.toast .t-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.toast.success .t-icon { color: #4cc38a; }
.toast.error { border-color: rgba(255, 90, 79, 0.45); }
.toast.error .t-icon { color: #ff6b61; }
.toast .t-msg { flex: 1; line-height: 1.5; overflow-wrap: anywhere; user-select: text; }
.toast .t-act { flex: none; height: 26px; padding: 0 10px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: var(--r-md); background: rgba(255, 255, 255, 0.08); color: var(--toast-accent); font-weight: var(--fw-semibold); cursor: pointer; }
.toast .t-act:hover { background: rgba(255, 255, 255, 0.14); }
.toast .t-x { flex: none; width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: rgba(255, 255, 255, 0.55); cursor: pointer; }
.toast .t-x svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.toast .t-x:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

/* ── narrow windows / tablets: stack everything ── */
@media (max-width: 960px) {
  :root { --rail-w: 0px; --panel-w: 0px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 62vh auto; grid-template-areas: "top" "rail" "stage" "panel"; height: auto; min-height: 100%; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; row-gap: 8px; }
  .brand { border-right: 0; padding-right: 0; }
  .doc-chip { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  .rail { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-items { flex-direction: row; overflow-x: auto; padding: 6px; }
  .rail-group { display: none; }
  .rail-item { margin: 0; min-width: 64px; }
  .rail-item[aria-current="true"]::before { display: none; }
  .rail-foot { border-top: 0; border-left: 1px solid var(--line-soft); align-items: center; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .p-body { overflow: visible; }
  .toast { left: 50%; max-width: calc(100vw - 32px); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
