/* Carve — application chrome. The viewport canvas is full-bleed; panels float above it. */

:root {
  --ink: #26282c;
  --ink-soft: #6f7278;
  --ink-faint: #989ba1;
  --paper: #f4f3f0;
  --panel: #ffffff;
  --line: rgba(0, 0, 0, 0.1);
  --accent: #2a63d9;
  --danger: #c03a24;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  /* viewport drags must never start selecting the UI text */
  user-select: none;
}

/* typing fields still need normal text selection */
input, textarea { user-select: text; }

#app { height: 100%; }

.boot-splash {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.boot-title { font-size: 28px; font-weight: 800; letter-spacing: 0.14em; }
.boot-sub { font-size: 13px; color: var(--ink-faint); }

#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff3cd;
  padding: 10px 16px;
  z-index: 999;
  font-size: 14px;
}

/* ---- layout ---- */

.viewport-root { position: fixed; inset: 0; }

#carve-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.hud { position: absolute; pointer-events: none; }
.hud > * { pointer-events: auto; }

/* top bar */
.topbar {
  top: 12px; left: 12px; right: 12px;
  z-index: 2; /* wrapped toolbar rows must beat the side panels */
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.brand {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 9px 14px;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.brand b { font-size: 15px; font-weight: 800; letter-spacing: 0.08em; }
.brand span { font-size: 10px; font-weight: 600; color: var(--ink-faint); letter-spacing: 0.08em; }

.tool-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
  display: flex;
  gap: 1px;
  flex-wrap: wrap;
}

/* quiet segmented toggle (units): solid blue stays reserved for the ACTIVE TOOL */
button.tb.seg.active { background: rgba(42, 99, 217, 0.13); color: var(--accent); }

/* toolbar-resident selects styled like flat buttons */
.tb-select {
  min-height: 36px;
  border: none;
  border-radius: 9px;
  background: transparent;
  padding: 0 8px;
  font: 600 13.5px inherit;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
}
.tb-select:hover { background: rgba(0, 0, 0, 0.05); }

.toolbar .sep { width: 1px; background: var(--line); margin: 4px 2px; }

button.tb {
  min-height: 36px;
  padding: 0 9px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: 600 13.5px/1 inherit;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
button.tb:hover { background: rgba(0, 0, 0, 0.05); }
button.tb.active { background: var(--accent); color: #fff; }
button.tb.danger { color: var(--danger); }
button.tb:disabled { opacity: 0.35; cursor: default; }

/* side panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  width: 300px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
}

.left-stack { top: 68px; left: 12px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 92px); }
.right-stack { top: 68px; right: 12px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 92px); }
.left-stack .panel, .right-stack .panel { flex: 0 1 auto; min-height: 0; overflow-y: auto; }

.panel h3 {
  margin: 2px 4px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.row-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
.row-item:hover { background: rgba(0, 0, 0, 0.045); }
.row-item.selected { background: rgba(42, 99, 217, 0.12); color: var(--accent); font-weight: 600; }
.row-item.dim { opacity: 0.45; }
.row-item .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .eye {
  border: none; background: none; cursor: pointer;
  font-size: 15px; padding: 3px 5px; color: var(--ink-soft);
  border-radius: 6px;
}
.row-item .eye:hover { background: rgba(0, 0, 0, 0.07); color: var(--ink); }

.empty-note { font-size: 12.5px; color: var(--ink-faint); padding: 4px 6px 6px; }

/* scene tree: VS-Code-style indent guides + chevrons + icons */
.tree-row { padding: 5px 8px 5px 4px; gap: 4px; }
.tree-rail { flex: 0 0 15px; align-self: stretch; border-left: 1px solid var(--line); }
.row-item .twist {
  flex: none; border: none; background: none; cursor: pointer;
  width: 15px; font-size: 10px; color: var(--ink-soft); padding: 0; line-height: 1; text-align: center;
}
.row-item .twist:hover { color: var(--ink); }
.twist-spacer { flex: 0 0 15px; }
.ticon { flex: none; width: 16px; text-align: center; font-size: 12px; opacity: 0.85; }
.ride-tag {
  flex: none; font-size: 11px; color: var(--ink-faint);
  background: rgba(42, 99, 217, 0.10); border-radius: 5px; padding: 1px 5px; margin-left: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 96px;
}

/* bill of materials list (exploded-view panel) */
.bom-list { max-height: 240px; overflow-y: auto; padding: 0 2px; }
.bom-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.bom-table th { text-align: left; color: var(--ink-faint); font-weight: 500; padding: 2px 6px; border-bottom: 1px solid var(--line, rgba(128,128,128,0.25)); }
.bom-table td { padding: 2px 6px; border-bottom: 1px solid var(--line, rgba(128,128,128,0.12)); }
.bom-joints { margin-top: 6px; font-size: 12px; color: var(--ink-faint); }
.bom-joints > div { padding: 1px 6px; }

/* joint inference chip — the "Hinge here?" prompt */
.suggestion {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  margin: 2px 0 6px;
  border-radius: 9px;
  background: rgba(217, 145, 20, 0.10);
  border: 1px dashed rgba(217, 145, 20, 0.55);
  font-size: 13px;
}
.suggestion .grow { flex: 1; }

/* history rollback / suppress / diagnostics */
.row-item.future { opacity: 0.4; }
.row-item.muted .grow { text-decoration: line-through; color: var(--ink-faint); }
.diag-badge {
  flex-shrink: 0;
  width: 16px; height: 16px;
  border-radius: 50%;
  font: 700 11px/16px inherit;
  text-align: center;
  color: #fff;
}
.diag-badge.err { background: var(--danger); }
.diag-badge.warn { background: #d99114; }
.marker-bar {
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  margin: 3px 6px;
  cursor: pointer;
  position: relative;
}
.marker-bar span {
  position: absolute;
  right: 0; top: -8px;
  background: var(--accent);
  color: #fff;
  font: 600 11px inherit;
  padding: 1px 6px;
  border-radius: 6px;
}
.marker-bar:hover { filter: brightness(1.2); }

/* parameter fields */
.fields { display: flex; flex-direction: column; gap: 8px; padding: 2px 2px 4px; }
.field { display: flex; align-items: center; gap: 8px; }
.field label { font-size: 12.5px; color: var(--ink-soft); width: 58px; flex-shrink: 0; }
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button { display: none; }
.mat-select {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 500 13.5px inherit;
  font-family: inherit;
  color: var(--ink);
  background: #fbfbfa;
}
.field input[type="color"] { width: 100%; height: 32px; border: 1px solid var(--line); border-radius: 7px; background: #fbfbfa; padding: 2px; }
.field input[type="range"] { width: 100%; }

.field input[type="number"], .field input[type="text"] {
  width: 100%;
  min-width: 0;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 500 13.5px inherit;
  appearance: textfield;
  -moz-appearance: textfield;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: #fbfbfa;
}
.field input:focus { outline: 2px solid rgba(42, 99, 217, 0.35); border-color: transparent; }
.field-triple { display: flex; gap: 5px; flex: 1; }
.field-triple input { min-width: 0; flex: 1 1 0; }

/* ---- bottom Motion bar (wide timeline) ---- */
.motion-bar {
  left: 12px;
  right: 108px; /* clear of the view cube */
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.motion-bar .tb { height: 28px; padding: 0 9px; }
.motion-bar .tb.play { min-width: 38px; font-size: 15px; }
.motion-bar .tb.danger { color: var(--danger); }
.mb-seq, .mb-transport, .mb-keys, .mb-opts { display: flex; align-items: center; gap: 5px; flex: none; }
.mb-seq .tb-select { max-width: 150px; }
.mb-timeline { position: relative; flex: 1 1 auto; min-width: 120px; }
.mb-timeline input[type=range] { width: 100%; display: block; }
.mb-time { font: 600 12px "Segoe UI", sans-serif; color: var(--ink-soft); white-space: nowrap; flex: none; min-width: 78px; text-align: center; }
.mb-len { width: 54px; }
.mb-opts .check { font-size: 12px; gap: 4px; }
.mb-opts .tb-select { max-width: 120px; }
.hintbar.raised { bottom: 66px; }

/* animation timeline keyframe markers */
.anim-timeline { position: relative; flex: 1; }
.anim-timeline input[type=range] { width: 100%; display: block; }
.keymarks { position: relative; height: 8px; margin-top: 1px; }
.keymark {
  position: absolute; top: 0; width: 7px; height: 7px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--accent); border: 1px solid #fff; cursor: pointer;
}
.keymark:hover { background: #fff; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; padding: 2px; }

.btn-row { display: flex; gap: 6px; padding-top: 4px; flex-wrap: wrap; }
button.small {
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: 600 12.5px inherit;
  font-family: inherit;
  cursor: pointer;
  color: var(--ink);
}
button.small:hover { background: rgba(0, 0, 0, 0.04); }
button.small.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small.primary:hover { background: #2456bd; }
button.small.danger { color: var(--danger); }
/* section-level commit action — fills its row, echoing the ✓ Extrude language */
button.small.cta { flex: 1 1 100%; min-height: 34px; font-size: 13px; }

/* segmented control (panel) — same visual language as the mm/m unit toggle */
.seg-field { display: flex; flex-direction: column; gap: 5px; }
.seg-field > label { font-size: 12.5px; color: var(--ink-soft); }
.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fbfbfa;
}
.segmented button {
  flex: 1 1 0;
  min-width: 0;
  border: none;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: 600 12.5px inherit;
  font-family: inherit;
  padding: 6px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  gap: 1px;
}
.segmented button:first-child { border-left: none; }
.segmented button:hover { background: rgba(0, 0, 0, 0.05); }
.segmented button.on { background: var(--accent); color: #fff; }
.segmented button small { font-size: 10.5px; font-weight: 600; opacity: 0.72; font-variant-numeric: tabular-nums; }
.segmented button.on small { opacity: 0.88; }

/* two stacked rows of material preset chips */
.mat-presets { display: flex; flex-direction: column; gap: 4px; }
.mat-presets .segmented button { font-size: 11px; padding: 5px 2px; }

/* drill-in cue under the gizmo mode buttons */
.drill-hint { font-size: 11.5px; color: var(--ink-faint); font-style: italic; padding: 0 4px 2px; }

/* inviting empty-scene note */
.scene-empty { text-align: center; padding: 14px 10px 12px; line-height: 1.5; }

/* bottom hint */
/* view-cube / quick orientation widget (bottom-right) */
.viewcube {
  right: 18px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#vcube-host {
  width: 88px;
  height: 88px;
  perspective: 320px;
  cursor: grab;
}
#vcube-host.dragging { cursor: grabbing; }
.vcube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
}
.vcube-face {
  position: absolute;
  left: 14px; top: 14px;
  width: 60px; height: 60px;
  display: flex; align-items: center; justify-content: center;
  font: 700 12px "Segoe UI", sans-serif;
  color: var(--ink-soft);
  background: rgba(250, 250, 249, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-sizing: border-box;
  cursor: pointer;
  user-select: none;
  backface-visibility: hidden;
}
.vcube-face:hover { background: var(--accent); color: #fff; }
.vc-row { display: flex; gap: 4px; }
.vc-btn {
  min-width: 30px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: 600 11px inherit;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.vc-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.hintbar {
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  max-width: min(720px, 92vw);
  text-align: center;
  backdrop-filter: blur(4px);
}

/* on-screen dimension labels (positioned per-frame by the renderer) */
.dim-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: #26282c;
  color: #fff;
  border-radius: 8px;
  padding: 4px 10px;
  font: 600 13.5px "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 5;
  pointer-events: auto;
  user-select: none;
}
.dim-label:hover { background: #2a63d9; }
/* inline editor: a bare number field sized for ~6 digits, no spinner arrows, clear focus */
.dim-label.editing { background: #2a63d9; padding: 3px 6px; }
.dim-label input {
  width: 66px;
  border: none;
  outline: 2px solid #fff;
  outline-offset: 1px;
  background: #fff;
  color: #26282c;
  border-radius: 5px;
  padding: 2px 6px;
  font: 600 13.5px "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.dim-label input:focus { outline: 2px solid #fff; }
.dim-label input::-webkit-inner-spin-button,
.dim-label input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; display: none; }

/* measure tool: green two-line readout, view-only (no pointer, multi-line set inline) */
.dim-label.measure-label { background: #12633a; cursor: default; line-height: 1.35; }
.dim-label.measure-label:hover { background: #12633a; }

/* measure panel readout + part-stats line (selectable text) */
.measure-readout { padding: 2px 2px 6px; user-select: text; }
.measure-main { font: 700 15px "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; }
.measure-delta { font: 500 12px "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; opacity: 0.8; margin-top: 2px; }
.stat-line {
  padding: 5px 2px 1px;
  font: 500 11.5px "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
  user-select: text;
  line-height: 1.45;
}

/* subtle "autosaved ✓ 14:32" indicator next to Save */
.autosave-ind {
  align-self: center;
  font: 500 11.5px "Segoe UI", sans-serif;
  opacity: 0.7;
  padding: 0 4px;
  white-space: nowrap;
}

/* transient degradation toasts (top-right stack, click or 6s to dismiss) */
.toast-stack {
  position: absolute;
  top: 56px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 60;
  pointer-events: none;
  max-width: 320px;
}
.toast {
  pointer-events: auto;
  cursor: pointer;
  background: rgba(28, 30, 34, 0.94);
  color: #f2e9dc;
  border: 1px solid rgba(210, 150, 90, 0.55);
  border-left: 3px solid #d2965a;
  border-radius: 6px;
  padding: 8px 12px;
  font: 500 12px "Segoe UI", sans-serif;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease-out;
}
.toast:hover { border-color: rgba(230, 170, 110, 0.85); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* recent-docs / named-views dropdown menus */
.menu-wrap { position: relative; display: inline-flex; }
.drop-menu {
  position: absolute;
  min-width: 190px;
  background: rgba(30, 32, 36, 0.98);
  border: 1px solid rgba(210, 150, 90, 0.4);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  padding: 4px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.recent-menu { top: 100%; left: 0; margin-top: 4px; }
.views-menu { bottom: 100%; right: 0; margin-bottom: 6px; }
.drop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: #e8e2d8;
  font: 500 12px "Segoe UI", sans-serif;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
}
.drop-item:hover { background: rgba(210, 150, 90, 0.18); }
.di-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.di-time { opacity: 0.6; font-size: 11px; flex: none; }
.add-view { color: #f0c088; font-weight: 600; }
.view-row { padding: 0; }
.vr-name {
  flex: 1; background: transparent; border: none; color: #e8e2d8;
  font: 500 12px "Segoe UI", sans-serif; padding: 6px 8px; border-radius: 4px;
  cursor: pointer; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.vr-name:hover { background: rgba(210, 150, 90, 0.18); }
.vr-del {
  flex: none; background: transparent; border: none; color: #b98; cursor: pointer;
  padding: 4px 8px; border-radius: 4px; font-size: 12px;
}
.vr-del:hover { background: rgba(200, 90, 80, 0.25); color: #f2b8b0; }
.view-name-input {
  width: 100%;
  background: rgba(18, 20, 22, 0.9);
  border: 1px solid rgba(210, 150, 90, 0.5);
  border-radius: 4px;
  color: #f2e9dc;
  font: 500 12px "Segoe UI", sans-serif;
  padding: 6px 8px;
}
.drop-empty { padding: 6px 8px; opacity: 0.55; font: 500 11.5px "Segoe UI", sans-serif; }

/* File ▾ (right cluster): dark dropdown holding Open… + recent files */
.file-menu { top: 100%; right: 0; margin-top: 4px; }
.drop-sub {
  padding: 6px 8px 2px; font: 700 10px "Segoe UI", sans-serif;
  letter-spacing: 0.08em; text-transform: uppercase; color: #b0a894;
}

/* View ▾ (right cluster): light popover matching the panels — holds the moved
   shading select + X-ray / Section / Explode toggles */
.tb-pop {
  position: absolute; top: 100%; right: 0; margin-top: 6px;
  min-width: 196px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.2);
  padding: 6px;
  z-index: 80;
  display: flex; flex-direction: column; gap: 3px;
}
.tb-pop-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 5px 6px 2px;
}
.tb-pop .pop-select {
  width: 100%; min-height: 32px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.tb-pop .pop-row { justify-content: flex-start; width: 100%; min-height: 32px; }

/* grouped inspector action rows (Arrange / Make / Pattern) */
.op-group { margin-top: 6px; }
.op-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 2px 2px 3px;
}
.delete-row { justify-content: flex-end; margin-top: 6px; }

/* crash-recovery banner (top-center, dismissible) */
.recover-banner {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: #26282c;
  color: #fff;
  border-radius: 10px;
  padding: 8px 10px 8px 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  z-index: 20;
  font: 600 13px "Segoe UI", sans-serif;
  pointer-events: auto;
}
.recover-banner .grow { margin-right: 4px; }

/* ---- narrower desktop: tighten the toolbars so they stay on one row ---- */
@media (max-width: 1440px) {
  .topbar { gap: 6px; }
  button.tb { padding: 0 6px; font-size: 12.5px; }
  .toolbar { gap: 1px; padding: 3px; }
  .toolbar .sep { margin: 4px 2px; }
  .tb-select { padding: 0 5px; font-size: 12.5px; }
}
@media (max-width: 1340px) {
  .topbar { gap: 5px; }
  button.tb { padding: 0 5px; font-size: 12px; }
  .toolbar .sep { margin: 4px 1px; }
  .tb-select { padding: 0 4px; font-size: 12px; max-width: 116px; }
  .brand { padding: 9px 10px; }
  .brand span { display: none; }
  .asi-word { display: none; } /* compact autosave badge ("✓ time") so the row stays single */
}
@media (max-width: 1180px) {
  button.tb { padding: 0 4px; font-size: 11.5px; }
  .brand b { font-size: 14px; }
}

.webgpu-error {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.webgpu-error > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 30px;
  font-size: 15px;
  color: var(--ink-soft);
  max-width: 420px;
  text-align: center;
}

/* ---- material library: docked right drawer (no scrim — viewport stays live to its left) ---- */
.mat-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 200;
  width: min(400px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.22);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: mat-drawer-in 160ms ease-out;
}
@keyframes mat-drawer-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-head {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink); }
.modal-count { font-size: 12px; color: var(--ink-faint); }
.modal-x {
  margin-left: auto; border: none; background: none; cursor: pointer;
  font-size: 16px; color: var(--ink-soft); padding: 4px 9px; border-radius: 7px;
}
.modal-x:hover { background: rgba(0, 0, 0, 0.06); color: var(--ink); }
.drawer-lib {
  flex: 0 1 auto; max-height: 48%; min-height: 116px; overflow-y: auto;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.drawer-editor {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 9px;
}
.drawer-foot {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.drawer-foot .primary { margin-left: auto; }
.mat-stock-note {
  font-size: 11.5px; color: var(--ink-faint);
  background: rgba(0, 0, 0, 0.04); border-radius: 7px; padding: 6px 9px; margin: -2px 0 2px;
}
.mat-lock {
  position: absolute; left: 5px; top: 5px;
  font-size: 11px; line-height: 1; background: rgba(0, 0, 0, 0.42);
  padding: 3px 4px; border-radius: 6px;
}
.mat-section-h {
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em;
  color: var(--ink-faint); text-transform: uppercase; margin: 4px 2px 8px;
}
.mat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px;
  margin-bottom: 16px;
}
.mat-card {
  cursor: pointer; border-radius: 9px; padding: 4px;
  outline: 2px solid transparent; outline-offset: -2px;
}
.mat-card:hover { background: rgba(0, 0, 0, 0.035); }
.mat-card.sel { outline-color: var(--accent); }
.mat-swatch {
  position: relative; aspect-ratio: 1.4; border-radius: 7px;
  overflow: hidden; border: 1px solid var(--line);
}
.mat-swatch-fill { position: absolute; inset: 0; }
/* live WebGPU material ball, blitted over the flat CSS fill (which stays as a fallback) */
.mat-thumb { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mat-badge {
  position: absolute; right: 5px; bottom: 5px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.03em;
  color: #fff; background: rgba(0, 0, 0, 0.42);
  padding: 2px 6px; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 3px;
}
.mat-badge i { font-style: normal; animation: mat-badge-pulse 1.6s ease-in-out infinite; }
@keyframes mat-badge-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.mat-name {
  font-size: 12.5px; font-weight: 600; margin: 6px 2px 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink);
}
.mat-use { font-size: 11px; color: var(--ink-faint); margin: 0 2px 2px; }
.mat-editor-use { font-size: 12px; color: var(--ink-faint); margin: -2px 2px 2px; }
.drawer-editor .cta { margin-top: 4px; }

@media (max-width: 720px) {
  /* full-width sheet on phones (the viewport is small — full cover is fine) */
  .mat-drawer { width: 100%; border-left: none; }
  .drawer-lib { max-height: 42%; }
}

/* ---- command palette (Ctrl+K / Ctrl+P) ---- */
.palette-scrim {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, 0.18);
  display: flex; justify-content: center; align-items: flex-start;
}
.palette {
  margin-top: 12vh; width: min(560px, 92vw);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.28);
  display: flex; flex-direction: column; overflow: hidden;
  animation: palette-in 120ms ease-out;
}
@keyframes palette-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }
.palette-input {
  border: none; outline: none; background: transparent;
  font-size: 16px; padding: 15px 18px; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.palette-input::placeholder { color: var(--ink-faint); }
.palette-list { max-height: 52vh; overflow-y: auto; padding: 6px 0; }
.palette-group {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ink-faint);
  padding: 9px 18px 3px;
}
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; cursor: pointer; font-size: 13.5px; color: var(--ink);
}
.palette-item .pi-label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item .pi-tag { font-size: 10.5px; color: var(--ink-faint); flex: 0 0 auto; }
.palette-item.sel { background: var(--accent); color: #fff; }
.palette-item.sel .pi-tag { color: rgba(255, 255, 255, 0.82); }
.palette-item.disabled { color: var(--ink-faint); cursor: default; }
.palette-item.disabled.sel { background: rgba(0, 0, 0, 0.06); color: var(--ink-faint); }
.palette-empty { padding: 18px; text-align: center; color: var(--ink-faint); font-size: 13px; }
