/* Colours, sizes and shadows are tokens: dark slate is the default (:root), and
   html[data-theme=light] swaps the tokens for the light theme. Rules below use tokens only. */
:root {
  --chrome: #17191e;        /* title bar */
  --chrome-text: #c9ced8;
  --chrome-hover: rgba(255,255,255,.08);
  --doc-tab: #2b2f38;
  --ribbon: #1d2026;
  --ribbon-line: #121418;
  --divider: #2c3038;       /* between ribbon groups, inside panels */
  --bg: #2a2e37;            /* viewport */
  --panel: #22252c;         /* floating panels, menus, cards */
  --panel-2: #2a2e36;       /* raised things on a panel: hovers, chips, history steps */
  --hover: #2b2f38;
  --line: #33373f;          /* panel borders */
  --line-2: #2c3038;        /* lighter separators */
  --input: #1a1c21;
  --input-line: #363a42;
  --text: #d7dce4;
  --strong: #eef1f5;
  --muted: #8b93a0;
  --label: #c3cbd4;         /* form labels */
  --accent: #4c8df6;
  --accent-soft: rgba(76,141,246,.16);
  --primary: #3b7be8;
  --primary-hover: #4c8df6;
  --sel: #2c4a78;           /* selected / active fill */
  --sel-text: #ffffff;
  --sel-line: #3a6299;
  --sketch: #f08a4b;
  --sketch-fill: rgba(240,138,75,.24);
  --sketch-text: #ffd9c2;
  --ok: #5fcf8f;
  --danger: #e5534b;
  --warn: #e0a030;
  --err-bg: #3a1f22; --err-text: #ff9d9d;
  --warn-bg: #3a3020; --warn-text: #f1c26b;
  --info-bg: #262b33; --info-text: #b9c3cd;
  --good-bg: #1d3328; --good-text: #7fdcaa;
  --ent-sel: #4a2e1f;
  --chip: #2f343d;
  --kbd: #2a2f37;
  --expr: #c3a6ff;
  --toast: #343944; --toast-warn: #7a5414;
  --scrim: rgba(8,10,14,.45);
  --busy-scrim: rgba(10,12,14,.35);
  --spin-track: #3a404a;
  --float: rgba(34,37,44,.94);      /* translucent panel for labels over the model */
  --dim-ink: #ced4da; --dim-text: #e9ecef; --dim-ref: #909aa4; --dim-expr: #b197fc;
  --dim-sel: #38d9a9; --dim-sel-text: #8cc0ff; --dim-sel-line: #4c8df6;
  --dim-bad: #ff6b6b; --dim-bad-line: #a33d3d; --dim-preview: #ff922b; --dim-preview-line: #8a5420; --dim-hover: #5c6470;
  --cg-bg: #1f3550; --cg-text: #9cc5f5; --cg-line: #2f5a8a; --cg-bad-bg: #4a2224; --cg-bad-text: #ffa8a8; --cg-bad-line: #8a3a3a;
  --def-under: #4c8df6; --def-full: #e9ecef; --def-over: #e5534b;
  --heart: #ff5e5b;
  --shadow: 0 6px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.45);
  --radius: 7px;
  --radius-sm: 5px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: dark;
}
html[data-theme=light] {
  --chrome: #f3f4f6;
  --chrome-text: #39414d;
  --chrome-hover: rgba(0,0,0,.06);
  --doc-tab: #e3e6eb;
  --ribbon: #fafbfc;
  --ribbon-line: #dfe3e8;
  --divider: #e3e6ea;
  --bg: #e6e9ee;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --hover: #eef1f5;
  --line: #d9dde3;
  --line-2: #e6e9ee;
  --input: #ffffff;
  --input-line: #cfd5dc;
  --text: #1f2530;
  --strong: #0f141b;
  --muted: #6b7380;
  --label: #3b4652;
  --accent: #2f6fe0;
  --accent-soft: #e3edfc;
  --primary: #2f6fe0;
  --primary-hover: #245fc9;
  --sel: #dce8fb;
  --sel-text: #1d4f9e;
  --sel-line: #b5cff0;
  --sketch: #d9480f;
  --sketch-fill: #fde8dc;
  --sketch-text: #a8380b;
  --ok: #2f855a;
  --danger: #c23b3b;
  --warn: #b7791f;
  --err-bg: #fdecec; --err-text: #c23b3b;
  --warn-bg: #fdf5e6; --warn-text: #9a6516;
  --info-bg: #eef3f8; --info-text: #3b4652;
  --good-bg: #e8f6ee; --good-text: #1f6f43;
  --ent-sel: #fde8dc;
  --chip: #e4e9ef;
  --kbd: #eef1f4;
  --expr: #6a3fb5;
  --toast: #26303b; --toast-warn: #8a5a12;
  --scrim: rgba(20,30,40,.3);
  --busy-scrim: rgba(240,242,245,.35);
  --spin-track: #c8d3df;
  --float: rgba(255,255,255,.94);
  --dim-ink: #343a40; --dim-text: #212529; --dim-ref: #868e96; --dim-expr: #6741d9;
  --dim-sel: #0ca678; --dim-sel-text: #087f5b; --dim-sel-line: #0ca678;
  --dim-bad: #e03131; --dim-bad-line: #ffa8a8; --dim-preview: #d9480f; --dim-preview-line: #ffc078; --dim-hover: #adb5bd;
  --cg-bg: #e9f1fb; --cg-text: #1f5fae; --cg-line: #9cc0ea; --cg-bad-bg: #fde3e3; --cg-bad-text: #b42323; --cg-bad-line: #e7a1a1;
  --def-under: #1c6fd6; --def-full: #1d2433; --def-over: #e03131;
  --shadow: 0 6px 20px rgba(20,30,40,.12);
  --shadow-lg: 0 10px 40px rgba(20,30,40,.22);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 12px/1.35 var(--font); user-select: none; }
button { font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

#app { display: grid; grid-template-rows: 30px auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); height: 100vh; }
#app > * { min-width: 0; }

/* ---------- title bar ---------- */
#topbar { display: flex; align-items: center; gap: 10px; padding: 0 8px; background: var(--chrome); color: var(--chrome-text); position: relative; }
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; letter-spacing: .2px; color: var(--strong); white-space: nowrap; }
.logo { width: 16px; height: 16px; border-radius: 4px; background: linear-gradient(135deg, #5fa8ff, #1f6fd1 60%, #0e3f7d);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); flex: none; }
.menus { display: flex; gap: 1px; }
.menu-btn { background: none; border: 0; padding: 4px 9px; border-radius: var(--radius-sm); cursor: pointer; color: var(--chrome-text); }
.menu-btn:hover, .menu-btn.open { background: var(--chrome-hover); color: var(--strong); }
.quick { display: flex; gap: 1px; align-items: center; }
#topbar .icon-btn { width: 26px; height: 24px; color: var(--chrome-text); }
#topbar .icon-btn svg { width: 16px; height: 16px; }
#topbar .icon-btn:hover:not(:disabled) { background: var(--chrome-hover); color: var(--strong); }
.qsep { width: 1px; height: 16px; background: var(--line); margin: 0 4px; align-self: center; }
#doc-title { background: var(--doc-tab); color: var(--strong); border-radius: 5px; padding: 2px 10px; max-width: 320px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
#title-search { margin-left: auto; flex: none; }
#tool-search { width: 210px; height: 22px; padding: 2px 8px 2px 25px; border: 1px solid var(--input-line); border-radius: 11px; background: var(--input)
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a0' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6'/%3E%3Cpath d='m20 20-4.5-4.5'/%3E%3C/svg%3E") no-repeat 8px center / 12px;
  font-size: 11.5px; outline: none; color: var(--text); }
#tool-search::placeholder { color: var(--muted); }
#tool-search:focus { border-color: var(--accent); width: 260px; }
#tool-search::-webkit-search-cancel-button { display: none; }
.icon-btn { width: 28px; height: 28px; display: inline-grid; place-items: center; border: 0; background: none; border-radius: var(--radius-sm); cursor: pointer; padding: 0; color: var(--text); }
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- ribbon ---------- */
#ribbon { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; background: var(--ribbon);
  border-bottom: 1px solid var(--ribbon-line); }
/* the workspace badge: the tab you're on */
#ribbon-badge { grid-row: 1 / 3; align-self: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: 60px; margin: 6px 4px 6px 8px; padding: 8px 4px 7px; border-radius: var(--radius); background: var(--panel-2);
  border-top: 2px solid var(--accent); color: var(--strong); font-size: 11px; font-weight: 600; text-align: center; }
#ribbon-badge svg { width: 22px; height: 22px; color: var(--accent); }
#ribbon-badge.sketch { border-top-color: var(--sketch); }
#ribbon-badge.sketch svg { color: var(--sketch); }
#ribbon-tabs { display: flex; gap: 3px; padding: 5px 8px 2px; align-items: center; }
.rtab { border: 0; background: none; padding: 2px 12px; border-radius: 11px; font-weight: 600; font-size: 11.5px; color: var(--muted); cursor: pointer; line-height: 18px; }
.rtab:hover { color: var(--text); background: var(--hover); }
.rtab.active { color: var(--sel-text); background: var(--sel); }
.rtab.sketch.active { color: var(--sketch-text); background: var(--sketch-fill); }
#ribbon-body { display: flex; gap: 0; padding: 3px 4px 3px; overflow: hidden; }
.rgroup { display: flex; flex-direction: column; padding: 0 6px; border-right: 1px solid var(--divider); flex: none; }
.rgroup:last-child { border-right: 0; }
.rgroup.folded { display: none; }
.rgroup.pinned { margin-left: auto; border-left: 1px solid var(--divider); border-right: 0; }
.rmore { margin-left: auto; border-left: 1px solid var(--divider); border-right: 0; }
.rgroup-items { display: flex; gap: 2px; flex: 1; align-items: stretch; min-height: 54px; }
.rgroup-label { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 0; white-space: nowrap; }
.rgroup-label[data-glabel] { cursor: pointer; border-radius: 4px; }
.rgroup-label[data-glabel]::after { content: ' \2304'; font-size: 10px; position: relative; top: -2px; }
.rgroup-label[data-glabel]:hover { color: var(--text); background: var(--hover); }
.tool-btn { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; min-width: 46px;
  padding: 5px 5px 3px; white-space: nowrap; border: 1px solid transparent; background: none; border-radius: var(--radius-sm); cursor: pointer; font-size: 11px; color: var(--text); }
.tool-btn svg { width: 22px; height: 22px; color: var(--accent); }
.tool-btn .caret { font-style: normal; font-size: 9px; margin-left: 2px; color: var(--muted); }
/* stacked small buttons: icon + label in a row, up to three high */
.rstack { display: flex; flex-direction: column; justify-content: flex-start; gap: 0; }
.tool-btn.small { flex-direction: row; gap: 5px; min-width: 0; max-width: none; padding: 1px 6px 1px 3px; white-space: nowrap; font-size: 11px; height: 18px; }
.tool-btn.small svg { width: 15px; height: 15px; flex: none; }
/* icon-only block */
.rgrid { display: grid; grid-template-columns: repeat(var(--cols, 5), 26px); grid-auto-rows: 26px; gap: 1px 2px; align-content: start; padding-top: 2px; }
.tool-btn.mini { min-width: 0; max-width: none; width: 26px; height: 26px; padding: 2px; justify-content: center; }
.tool-btn.mini svg { width: 18px; height: 18px; }
.tool-btn.mini span { display: none; }
/* narrower windows: smaller buttons, then icons only (labels stay in the tooltips) */
#ribbon.compact .tool-btn:not(.small):not(.mini) { min-width: 40px; padding: 5px 2px 3px; font-size: 10px; }
#ribbon.compact .tool-btn:not(.small):not(.mini) svg { width: 20px; height: 20px; }
#ribbon.compact .rgroup { padding: 0 3px; }
#ribbon.tight .tool-btn:not(.small):not(.mini) { min-width: 34px; padding-top: 7px; }
#ribbon.tight .tool-btn:not(.small):not(.mini) span { display: none; }
#ribbon.tight .tool-btn.drop span { display: block; font-size: 0; }
#ribbon.tight .tool-btn.drop .caret { font-size: 9px; }
#ribbon.tight .tool-btn.small span { display: none; }
#ribbon.tight .tool-btn.small { padding: 1px 3px; }
.tool-btn:hover:not(:disabled) { background: var(--hover); border-color: var(--line); }
.tool-btn.active { background: var(--sel); border-color: var(--sel-line); color: var(--sel-text); }
.tool-btn.active svg { color: var(--sel-text); }
.tool-btn:disabled { opacity: .4; cursor: default; }
.tool-btn span { line-height: 1.1; text-align: center; }
.tool-btn.finish, .tool-btn.finish svg { color: var(--ok); }

/* ---------- workspace: the model fills it, panels float over it ---------- */
#workspace { position: relative; min-height: 0; overflow: hidden; }
.panel { background: var(--panel); display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); }
/* 8px insets; the history bar (36px) sits along the bottom */
#browser { position: absolute; z-index: 4; top: 8px; left: 8px; width: 240px; max-height: calc(100% - 60px); overflow: hidden; }
#tool-panel { position: absolute; z-index: 5; top: 8px; right: 8px; width: 290px; max-height: calc(100% - 60px); overflow: hidden; }
.panel-title { display: flex; align-items: center; gap: 7px; padding: 7px 8px 7px 10px; font-weight: 600; font-size: 12px; color: var(--strong);
  border-bottom: 1px solid var(--divider); flex: none; }
.panel-title > span:first-child, #tool-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tool-panel .panel-title > #tool-icon { flex: none; display: inline-grid; place-items: center; color: var(--accent); }
#tool-icon:empty { display: none !important; }
#tool-icon svg { width: 17px; height: 17px; }
.panel-title .count { color: var(--muted); font-weight: 400; font-size: 11px; }
.panel-title .x { border: 0; background: none; font-size: 17px; line-height: 1; cursor: pointer; color: var(--muted); width: 22px; height: 22px;
  border-radius: 4px; padding: 0; flex: none; }
.panel-title .x:hover { color: var(--strong); background: var(--hover); }
#tree { overflow: auto; padding: 4px 0 8px; flex: 0 1 auto; min-height: 0; }
.tnode { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px calc(8px + var(--d, 0) * 14px); cursor: default; white-space: nowrap; }
.tnode:hover { background: var(--hover); }
.tnode.selected { background: var(--sel); color: var(--sel-text); }
.tnode .tw { width: 12px; color: var(--muted); cursor: pointer; text-align: center; font-size: 10px; }
.tnode .eye { width: 18px; height: 18px; display: grid; place-items: center; cursor: pointer; color: var(--muted); opacity: .8; }
.tnode .eye svg { width: 15px; height: 15px; }
.tnode .eye.off { opacity: .35; }
.tnode .sw { width: 11px; height: 11px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); flex: none; }
.tnode .nm { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tnode .tag { font-size: 10.5px; color: var(--muted); }
.tnode .tag.bad { color: var(--warn); font-weight: 600; }
.tnode.folder { font-weight: 600; color: var(--label); }

/* ---------- viewport ---------- */
#viewport { position: absolute; inset: 0; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
#view3d { width: 100%; height: 100%; display: block; outline: none; }
/* standard views: a small toolbar at the top right, left of the tool panel when that's open */
#viewcube { position: absolute; z-index: 3; top: 8px; right: 8px; display: flex; gap: 1px; padding: 2px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
#workspace:has(#tool-panel:not(.hidden)) #viewcube { right: 306px; }
#viewcube button { border: 0; background: none; color: var(--text); border-radius: 4px; padding: 2px 7px; font-size: 11px; line-height: 18px; cursor: pointer; }
#viewcube button:hover { background: var(--hover); color: var(--strong); }
#viewcube button[data-view="fit"] { color: var(--accent); font-weight: 600; }
#viewcube #btn-section { margin-left: 3px; box-shadow: -1px 0 0 var(--divider); border-radius: 0 4px 4px 0; }
#viewcube #btn-section.on { background: var(--sel); color: var(--sel-text); }
#hint { position: absolute; z-index: 3; left: 50%; bottom: 54px; transform: translateX(-50%); background: var(--float); color: var(--strong);
  border: 1px solid var(--line); box-shadow: var(--shadow); padding: 5px 12px; border-radius: 14px; font-size: 12px; pointer-events: none; max-width: 60%; text-align: center; }
#hint:empty { display: none; }
#viewport:has(#web-bar) #hint { bottom: 98px; }
#hud { position: absolute; left: 256px; top: 8px; background: var(--float); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 10px; font-size: 12px; min-width: 160px; box-shadow: var(--shadow); }
#hud .k { color: var(--muted); }
#sketch-hud { position: absolute; z-index: 6; background: var(--float); border: 1px solid var(--sketch); border-radius: var(--radius-sm); padding: 4px 6px; font-size: 11.5px;
  box-shadow: var(--shadow); pointer-events: auto; }
#sketch-hud .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#sketch-hud label { width: 46px; color: var(--muted); }
#sketch-hud input { width: 70px; border: 1px solid var(--input-line); border-radius: 4px; padding: 1px 4px; background: var(--input); color: var(--text); }
#sketch-hud input:focus { border-color: var(--sketch); outline: none; }
#empty-state { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; padding-bottom: 44px; }
#empty-state .empty-card { pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px 28px 16px; text-align: center;
  box-shadow: var(--shadow); min-width: 340px; max-width: calc(100% - 32px); }
#empty-state h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--strong); }
#empty-state p { margin: 0 0 14px; color: var(--muted); }
.empty-actions { display: flex; gap: 8px; justify-content: center; }
#empty-recent { margin-top: 14px; text-align: left; }
#empty-recent .rec { padding: 4px 8px; border-radius: 4px; cursor: pointer; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
#empty-recent .rec:hover { background: var(--hover); }
#drop-overlay { position: absolute; z-index: 9; inset: 0; background: var(--accent-soft); border: 3px dashed var(--accent); display: grid; place-items: center;
  font-size: 18px; color: var(--accent); font-weight: 600; pointer-events: none; }

/* ---------- tool panel ---------- */
#tool-form { overflow: auto; padding: 8px 10px; flex: 0 1 auto; min-height: 0; }
.field { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 6px; margin: 6px 0; }
.field > label { color: var(--label); }
.field .ctl { display: flex; gap: 4px; align-items: center; min-width: 0; }
.field input[type=text], .field input[type=number], .field select { width: 100%; min-width: 0; border: 1px solid var(--input-line); border-radius: var(--radius-sm);
  padding: 4px 6px; background: var(--input); color: var(--text); }
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.field .unit { color: var(--muted); font-size: 11px; width: 22px; }
.field.vec .ctl input { width: 33%; }
.field.wide { grid-template-columns: 1fr; }
.field .ctl button { border: 1px solid var(--input-line); background: var(--input); color: var(--text); border-radius: var(--radius-sm); padding: 4px 8px; cursor: pointer; }
.field .ctl button:hover:not(:disabled) { border-color: var(--accent); }
.field .ctl button:disabled { opacity: .45; cursor: default; }
.sel-box { flex: 1; min-height: 28px; border: 1px dashed var(--input-line); border-radius: var(--radius-sm); padding: 3px 6px; background: var(--input); cursor: pointer; display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.sel-box.active { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.sel-box .chip { background: var(--chip); border-radius: 10px; padding: 1px 8px; font-size: 11.5px; display: inline-flex; gap: 4px; align-items: center; }
.sel-box .chip b { cursor: pointer; font-weight: 400; color: var(--muted); }
.sel-box .ph { color: var(--muted); font-size: 11.5px; }
.seg { display: flex; border: 1px solid var(--input-line); border-radius: var(--radius-sm); overflow: hidden; width: 100%; }
/* one line always: a choice whose labels don't fit is shown as a list instead (segFits in app.js) */
.seg button { flex: 1 1 auto; min-width: 0; border: 0; background: var(--input); color: var(--text); padding: 4px 3px; cursor: pointer; font-size: 11px;
  border-right: 1px solid var(--input-line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button:hover:not(.on) { background: var(--hover); }
/* inside a form row too (the row's own button style would add borders and padding) */
.field .ctl .seg button { padding: 4px 3px; border: 0; border-right: 1px solid var(--input-line); border-radius: 0; }
.field .ctl .seg button:last-child { border-right: 0; }
.field .ctl .seg button:hover:not(:disabled) { border-color: var(--input-line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--sel); color: var(--sel-text); }
.check { display: flex; align-items: center; gap: 6px; }
input[type=checkbox], input[type=radio], input[type=range] { accent-color: var(--accent); }
.section-label { margin: 12px 0 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#tool-msg { padding: 0 10px; min-height: 0; flex: none; }
.msg { border-radius: var(--radius-sm); }
.msg.info { background: var(--info-bg); color: var(--info-text); padding: 6px 8px; font-size: 12px; }
#tool-msg .msg { padding: 6px 8px; border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 12px; }
#tool-msg .msg.err { background: var(--err-bg); color: var(--err-text); }
#tool-msg .msg.warn { background: var(--warn-bg); color: var(--warn-text); }
#tool-msg .msg.info { background: var(--info-bg); color: var(--info-text); }
#tool-msg .msg.busy { background: var(--info-bg); color: var(--info-text); display: flex; align-items: center; gap: 8px; }
#tool-msg .msg.busy::before { content: ''; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--spin-track); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.walls-n .bad { color: var(--danger); }
.walls-n .ph { color: var(--muted); }
.tool-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 8px 10px; border-top: 1px solid var(--divider); flex: none; }
#tool-credit { margin-right: auto; min-width: 0; font-size: 10.5px; line-height: 1.25; color: var(--muted); }
#tool-credit:empty { display: none; }
button.primary, .tool-actions button, .modal-actions button, .empty-actions button { border: 1px solid var(--input-line); background: var(--panel-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 5px 14px; cursor: pointer; }
.tool-actions button:hover:not(:disabled), .modal-actions button:hover:not(:disabled), .empty-actions button:hover:not(:disabled) { border-color: var(--accent); color: var(--strong); }
button.primary, .tool-actions button.primary, .modal-actions button.primary, .empty-actions button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
button.primary:disabled { opacity: .5; }
.ent-list { border: 1px solid var(--input-line); border-radius: var(--radius-sm); background: var(--input); max-height: 180px; overflow: auto; }
.ent-list .ent { padding: 3px 8px; cursor: pointer; display: flex; justify-content: space-between; }
.ent-list .ent:hover { background: var(--hover); }
.ent-list .ent.sel { background: var(--ent-sel); }
.ent-list .ent .t { color: var(--muted); font-size: 11px; }

/* ---------- history bar (the timeline), floating along the bottom ---------- */
#timeline-bar { position: absolute; z-index: 4; left: 8px; right: 8px; bottom: 8px; height: 36px; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center; gap: 6px; padding: 0 6px 0 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tl-label { font-weight: 600; color: var(--strong); font-size: 12px; }
.tl-controls { display: flex; gap: 0; padding-right: 4px; border-right: 1px solid var(--divider); }
.tl-controls .icon-btn { width: 24px; height: 24px; }
.tl-controls .icon-btn svg { width: 15px; height: 15px; }
#timeline { display: flex; align-items: center; gap: 3px; overflow-x: auto; overflow-y: hidden; padding: 0 4px; height: 100%; scrollbar-width: thin; }
.tl-item { flex: none; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; position: relative; background: var(--panel-2); color: var(--text); }
.tl-item:hover { border-color: var(--accent); }
.tl-item svg { width: 16px; height: 16px; }
.tl-item .lbl { display: none; }
.tl-item.err { background: var(--err-bg); }
.tl-item.err::after, .tl-item.warn::after { content: "!"; position: absolute; top: -3px; right: -1px; font-weight: 700; font-size: 10px; line-height: 1; }
.tl-item.err::after { color: var(--danger); }
.tl-item.warn::after { color: var(--warn); }
.tl-item.supp { opacity: .4; text-decoration: line-through; }
.tl-item.inactive { opacity: .32; }
.tl-item.editing { border-color: var(--sel-line); background: var(--sel); color: var(--sel-text); }
.tl-marker { flex: none; width: 2px; height: 24px; margin: 0 2px; background: var(--accent); border-radius: 1px; cursor: ew-resize; position: relative; }
.tl-marker::before { content: ''; position: absolute; inset: 0 -4px; }
#status { color: var(--muted); font-size: 11.5px; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; }

/* ---------- popups ---------- */
#menu { position: fixed; z-index: 50; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; min-width: 200px; }
#menu .mi { padding: 5px 12px 5px 10px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 18px; white-space: nowrap; }
#menu .mi:hover { background: var(--sel); color: var(--sel-text); }
#menu .mi.dis { opacity: .4; pointer-events: none; }
#menu .mi .k { color: var(--muted); font-size: 11.5px; }
#menu .mi:hover .k { color: inherit; opacity: .8; }
#menu .mi .ml { display: flex; align-items: center; gap: 8px; }
#menu .mi .ml svg { width: 17px; height: 17px; flex: none; color: var(--accent); }
#menu .mi:hover .ml svg { color: inherit; }
#menu .mi.hot { background: var(--sel); color: var(--sel-text); }
#menu .sep { height: 1px; background: var(--divider); margin: 4px 2px; }
#menu .submenu { position: absolute; background: inherit; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; min-width: 210px; }
#menu .mi .arrow { font-size: 12px; }
#menu .hdr { padding: 4px 10px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
#toasts { position: fixed; right: 14px; bottom: 56px; display: flex; flex-direction: column; gap: 6px; z-index: 60; max-width: 420px; }
.toast { background: var(--toast); color: #fff; padding: 8px 12px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,.06); box-shadow: var(--shadow); font-size: 12.5px; }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--toast-warn); }
.toast a { color: #fff; }
#busy { position: fixed; inset: 0; background: var(--busy-scrim); display: grid; place-items: center; z-index: 70; cursor: progress; }
#busy > * { grid-area: 1 / 1; }
#busy .spinner { width: 34px; height: 34px; border: 3px solid var(--spin-track); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 46px; }
#busy-msg { background: var(--panel); color: var(--text); padding: 6px 12px; border-radius: 14px; border: 1px solid var(--line); box-shadow: var(--shadow); margin-top: 40px; }
@keyframes spin { to { transform: rotate(360deg); } }
#modal { position: fixed; inset: 0; background: var(--scrim); display: grid; place-items: center; z-index: 80; }
.modal-card { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 18px 20px 14px; min-width: 340px; max-width: 520px; box-shadow: var(--shadow-lg); }
.modal-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--strong); }
.modal-card input[type=text] { width: 100%; border: 1px solid var(--input-line); border-radius: var(--radius-sm); padding: 6px 8px; background: var(--input); color: var(--text); }
.modal-card input[type=text]:focus { border-color: var(--accent); outline: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 12.5px; }
.help-grid kbd { background: var(--kbd); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; font: 11.5px var(--font); }

/* sketch dimensions */
#dims { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#dims .dimsvg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#dims .dimsvg g { color: var(--dim-ink); }
#dims .dimsvg .dl { stroke: currentColor; stroke-width: 1.1; fill: none; }
#dims .dimsvg .el { stroke: currentColor; stroke-width: .8; fill: none; opacity: .75; }
#dims .dimsvg .ah { fill: currentColor; stroke: none; }
#dims .dimsvg g.ref { color: var(--dim-ref); }
#dims .dimsvg g.expr { color: var(--dim-expr); }
#dims .dimsvg g.sel { color: var(--dim-sel); }
#dims .dimsvg g.bad { color: var(--dim-bad); }
#dims .dimsvg g.preview { color: var(--dim-preview); }
#dims .dim { position: absolute; pointer-events: auto; background: var(--float); border: 1px solid transparent; color: var(--dim-text); border-radius: 3px;
  padding: 0 4px; font-size: 11.5px; line-height: 16px; cursor: move; white-space: nowrap; transform: translate(-50%, -50%); user-select: none; font-variant-numeric: tabular-nums; }
#dims .dim:hover { border-color: var(--dim-hover); }
#dims .dim.ref { color: var(--dim-ref); }
#dims .dim.expr { color: var(--dim-expr); }
#dims .dim.expr::before { content: 'ƒ '; font-size: 10px; opacity: .8; }
#dims .dim.sel { border-color: var(--dim-sel-line); color: var(--dim-sel-text); }
#dims .dim.bad { color: var(--dim-bad); border-color: var(--dim-bad-line); }
#dims .dim.preview { color: var(--dim-preview); border-color: var(--dim-preview-line); }
#dims .dim-modify { position: absolute; pointer-events: auto; z-index: 5; display: flex; align-items: center; gap: 3px; transform: translate(-50%, calc(-100% - 12px));
  background: var(--panel); border: 1.5px solid var(--dim-sel); border-radius: var(--radius-sm); padding: 3px 4px; box-shadow: var(--shadow); }
#dims .dim-modify input { width: 92px; font: 12px var(--font); border: 1px solid var(--input-line); border-radius: 3px; padding: 2px 4px; background: var(--input); color: var(--text); }
#dims .dim-modify .u { font-size: 11px; color: var(--muted); margin-right: 2px; }
#dims .dim-modify button { width: 24px; height: 22px; padding: 0; border: 1px solid var(--input-line); border-radius: 3px; background: var(--input); color: var(--text); cursor: pointer; font-size: 13px; line-height: 1; }
#dims .dim-modify button.ok { color: var(--ok); }
#dims .dim-modify button.x { color: var(--danger); }
#dims .dim-edit { background: var(--input); color: var(--text); }
.sk-def { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 2px 0 8px; }
.sk-def::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--def-under); flex: none; }
.sk-def.full::before { background: var(--def-full); }
.sk-def.over::before { background: var(--def-over); }
.sk-def.over { color: var(--def-over); }

/* ---------- banners & constraint glyphs ---------- */
#banner { position: fixed; top: 38px; right: 14px; z-index: 65; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); max-width: 380px; font-size: 12.5px; }
#banner .b-actions { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
#banner button { border: 1px solid var(--input-line); background: transparent; color: var(--text); border-radius: var(--radius-sm); padding: 4px 10px; cursor: pointer; }
#banner button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
#dims .cg { position: absolute; pointer-events: auto; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 3px; font: 600 10px/15px var(--font);
  text-align: center; background: var(--cg-bg); color: var(--cg-text); border: 1px solid var(--cg-line); cursor: pointer; transform: translate(-50%, -50%); }
#dims .cg.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
#dims .cg.bad { background: var(--cg-bad-bg); color: var(--cg-bad-text); border-color: var(--cg-bad-line); }
.recov { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin: 6px 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.recov .t { color: var(--muted); font-size: 11.5px; }
.recov button { border: 1px solid var(--input-line); background: transparent; color: var(--text); border-radius: var(--radius-sm); padding: 4px 10px; cursor: pointer; }
.recov button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }

#dims.passive .dim, #dims.passive .cg { pointer-events: none; }
.field label .help { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--line);
  font-size: 9.5px; color: var(--muted); cursor: help; vertical-align: 1px; margin-left: 2px; }
/* web edition: a notice above the history bar */
#web-bar { position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 600px); min-width: min(420px, calc(100% - 32px)); padding: 6px 8px 6px 14px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 12px; color: var(--text); }
#web-bar a { color: var(--accent); font-weight: 600; white-space: nowrap; }
#web-bar button { border: 0; background: none; font-size: 16px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.tool-btn.desk-only { opacity: .38; }
.tool-btn.desk-only:hover { opacity: .55; }

/* ---------- tablets and phones ---------- */
#browser-toggle { display: none; position: absolute; top: 8px; left: 8px; z-index: 6; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius); padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer; color: var(--text); box-shadow: var(--shadow); }
@media (max-width: 1200px) {
  #web-bar { max-width: calc(100% - 32px); }
}
@media (max-width: 760px), (max-height: 520px) {
  /* the browser becomes a drawer over the model */
  #browser { z-index: 8; top: 8px; left: 8px; width: min(280px, 85vw); transform: translateX(calc(-100% - 16px)); transition: transform .18s ease; }
  html.browser-open #browser { transform: none; }
  #browser-toggle { display: block; }
  html.browser-open #browser-toggle { left: calc(min(280px, 85vw) + 16px); }
  /* tool settings slide up from the bottom, leaving the model visible above */
  #tool-panel { z-index: 7; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 48%; border-radius: 10px 10px 0 0;
    border-width: 1px 0 0; }
  #tool-form { overflow: auto; }
  #workspace:has(#tool-panel:not(.hidden)) #viewcube { right: 8px; }
  #web-bar { bottom: 52px; left: 8px; right: 8px; transform: none; max-width: none; min-width: 0; }
  #viewcube { display: grid; grid-template-columns: repeat(5, auto); }
  #viewcube button { padding: 4px 7px; }
  #viewcube #btn-section { margin-left: 0; box-shadow: none; border-radius: 4px; }
  #hud { left: 8px; top: 48px; }
  #hint { max-width: calc(100% - 32px); }
  #topbar { gap: 6px; padding: 0 6px; }
  #topbar .brand { font-size: 0; gap: 0; }
  #doc-title { display: none; }
  #tool-search { width: 30px; padding-right: 0; background-position: 8px center; }
  #tool-search::placeholder { color: transparent; }
  #tool-search:focus { position: absolute; z-index: 2; right: 6px; top: 4px; width: min(260px, calc(100vw - 12px)); padding-right: 8px; }
  #tool-search:focus::placeholder { color: var(--muted); }
  #ribbon { display: block; }
  #ribbon-badge { display: none; }
  #timeline-bar { grid-template-columns: auto minmax(0, 1fr); }
  .tl-label, #status { display: none; }
  .field { grid-template-columns: 92px 1fr; }
}
@media (pointer: coarse) {
  /* bigger targets for fingers */
  #app { grid-template-rows: 38px auto minmax(0, 1fr); }
  .tool-btn, .menu-btn, #viewcube button, .mi { min-height: 32px; }
  #topbar .icon-btn { height: 32px; }
  #timeline-bar { height: 44px; }
  .tl-item { width: 32px; height: 32px; }
  .tnode { padding-top: 7px; padding-bottom: 7px; }
}

/* folding sections: a header row folds the settings under it */
.field-hdr { display: flex; align-items: center; gap: 6px; width: calc(100% + 20px); margin: 8px -10px 2px; padding: 7px 10px; border: 0;
  border-top: 1px solid var(--divider); background: none; font: inherit; font-size: 11px; font-weight: 600; letter-spacing: .5px;
  text-transform: uppercase; color: var(--muted); text-align: left; cursor: pointer; }
.field-hdr:hover { background: var(--hover); color: var(--text); }
.field-hdr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.field-hdr .chev { display: inline-block; width: 10px; font-size: 14px; line-height: 1; text-align: center; transition: transform .12s ease; }
.field-hdr.open .chev { transform: rotate(90deg); }
.field-hdr .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-hdr .chg { flex: none; font-size: 10.5px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); }

/* a quiet thank-you link on the start screen */
.empty-foot { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--divider); font-size: 11.5px; color: var(--muted); }
.empty-foot a { color: inherit; text-decoration: none; }
.empty-foot a:hover { color: var(--text); text-decoration: underline; }
.empty-foot span { color: var(--heart); }

/* Support Fins: suggestions, strength, support plastic */
.sf-pose { display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin: 6px 0; }
.sf-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.sf-pose button { border: 1px solid var(--input-line); background: var(--input); color: var(--text); border-radius: var(--radius-sm); padding: 4px 8px; cursor: pointer; font: inherit; font-size: 12px; }
.sf-pose button:hover:not(:disabled) { border-color: var(--accent); }
.sf-pose button:disabled { opacity: .45; cursor: default; }
.sf-note { font-size: 12px; color: var(--muted); line-height: 1.35; }
.sf-note.bad { color: var(--danger); }
.sf-note.busy { display: flex; gap: 8px; align-items: center; }
.sf-note.busy::before { content: ''; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--spin-track); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.sf-cand { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; padding: 3px 4px 3px 7px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.sf-cand b { font-weight: 600; color: var(--strong); }
.sf-cand button { flex: none; padding: 2px 8px; }
.sf-verdict { font-size: 12px; padding: 5px 7px; border-radius: 4px; background: var(--info-bg); }
.sf-verdict.good { background: var(--good-bg); color: var(--good-text); }
.sf-verdict.mixed { background: var(--warn-bg); color: var(--warn-text); }
.sf-verdict.poor { background: var(--err-bg); color: var(--err-text); }
/* Support Fins: Held and Support plastic, two small cards side by side */
.sf-status { margin: 8px 0; }
.sf-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 6px; }
.sf-card { min-width: 0; padding: 6px 8px; background: var(--input); border: 1px solid var(--input-line); border-radius: 6px; }
.sf-card .cap { font-size: 11px; color: var(--muted); }
.sf-card .val { font-size: 14px; font-weight: 500; line-height: 1.3; color: var(--strong); overflow-wrap: anywhere; }
.sf-card .val b { font-weight: 500; }
.sf-card .val .muted { color: var(--muted); }
.sf-card .val .bad { color: var(--danger); font-size: 12px; }
.sf-card .val .sf-ok { color: var(--ok); }
.sf-card .val .sf-bad { color: var(--danger); }
.sf-card .val .busy { display: inline-flex; align-items: center; gap: 6px; }
.sf-card .val .busy::before { content: ''; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--spin-track); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.sf-card .sub { font-size: 11px; line-height: 1.35; color: var(--muted); overflow-wrap: anywhere; }
.sf-cover-note { margin-top: 6px; }

/* parameters */
#tool-form input.expr { color: var(--expr); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
table.params { width: 100%; border-collapse: collapse; margin-bottom: 8px; font-size: 13px; }
table.params th { text-align: left; font-weight: 600; font-size: 11px; color: var(--muted); padding: 2px 4px; }
table.params td { padding: 2px 4px; vertical-align: middle; }
table.params input { width: 100%; box-sizing: border-box; border: 1px solid var(--input-line); border-radius: 4px; padding: 3px 5px; background: var(--input); color: var(--text); }
table.params input:focus { border-color: var(--accent); outline: none; }
table.params td:nth-child(1) { width: 22%; } table.params td:nth-child(2) { width: 26%; }
table.params td.pv { width: 22%; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
table.params .bad, #tree .bad { color: var(--danger); }
table.params .muted { color: var(--muted); }
table.params button { border: 1px solid var(--input-line); background: var(--panel-2); color: var(--text); border-radius: 4px; cursor: pointer; }
.pmsg { color: var(--danger); font-size: 12px; margin-top: 6px; }
.modal-card:has(table.params) { max-width: 760px; width: min(760px, calc(100vw - 32px)); }

/* one-click update progress */
#banner .b-progress { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 12px; }
#banner .b-progress.hidden { display: none; }
#banner .b-progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
#banner .b-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

/* scrollbars that suit the theme */
#tree, #tool-form, #timeline, .ent-list, #menu { scrollbar-color: var(--line) transparent; }
