:root {
  --bg: #0e1116;
  --panel: #161b22cc;
  --panel-solid: #161b22;
  --border: #2a313c;
  --text: #d7dde5;
  --muted: #7d8794;
  --accent: #4c8dff;
  --accent-dim: #2b4a86;
  --danger: #ff5d5d;
  --good: #3fb950;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

#app { position: relative; width: 100vw; height: 100vh; }

/* touch-action:none stops the browser from scrolling / page-zooming the canvas,
   so one-finger orbit, two-finger pan and pinch-zoom all reach OrbitControls. */
#viewport { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.panel {
  position: absolute;
  top: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  z-index: 10;
}

#toolbar  { left: 12px;  width: var(--toolbar-w, 200px); max-height: calc(100vh - 24px); overflow-y: auto; }
#inspector { right: 12px; width: var(--side-w, 200px);    max-height: 52vh; overflow-y: auto; }

/* Resize handles live in #app (not the panels — a panel's overflow:auto clips
   horizontal overflow). Full-height gutter strips anchored to each panel edge. */
.resize-handle {
  position: absolute; top: 12px; bottom: 12px; width: 11px;
  cursor: ew-resize; z-index: 30; touch-action: none;
}
.resize-handle.toolbar { left:  calc(12px + var(--toolbar-w, 200px) + 1px); }   /* just over the canvas, clear of the scrollbar */
.resize-handle.side    { right: calc(12px + var(--side-w, 200px) + 1px); }
.resize-handle::after {
  content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 3px; height: 30px; border-radius: 3px;
  background: var(--border); opacity: 0; transition: opacity .15s;
}
.resize-handle:hover::after, .resize-handle.dragging::after { opacity: 1; background: var(--accent); }

/* Slim, themed scrollbars — replaces the chunky default OS bar inside panels. */
.panel { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.panel::-webkit-scrollbar { width: 8px; height: 8px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.panel::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); background-clip: content-box; }

.brand { font-weight: 600; font-size: 15px; margin-bottom: 12px; letter-spacing: .2px; }
.tag {
  font-size: 10px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--accent-dim); border-radius: 5px;
  padding: 1px 5px; margin-left: 4px; vertical-align: middle;
}

/* Per-panel collapse toggle (top-right). Collapsing hides everything but the
   panel's header line, reclaiming screen for the viewport. */
button.collapse-btn {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; margin: 0; padding: 0;
  text-align: center; line-height: 18px; font-size: 15px;
  color: var(--muted);
}
button.collapse-btn:hover { color: var(--text); }
.panel.collapsed { padding-bottom: 10px; }
.panel.collapsed > *:not(:first-child) { display: none; }

/* Arrange tools — a label plus three compact axis buttons on one row. */
.arrange-row { display: flex; align-items: center; gap: 5px; margin: 3px 0; }
.arrange-lbl { flex: 1; font-size: 12px; color: var(--muted); }
button.mini { width: 30px; margin: 0; padding: 6px 0; text-align: center; flex: 0 0 auto; }

.group { margin-bottom: 14px; }
.group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 6px; }
.hint { text-transform: none; letter-spacing: 0; opacity: .8; }

button {
  display: inline-block;
  width: 100%;
  margin: 3px 0;
  padding: 7px 9px;
  background: #1f262f;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: background .12s, border-color .12s;
}
button:hover { background: #283039; border-color: #3a434f; }
button:active { transform: translateY(1px); }
button.mode { width: calc(33% - 4px); display: inline-block; text-align: center; padding: 7px 2px; }
button.mode.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
button.danger:hover { border-color: var(--danger); color: var(--danger); }

button.tool.active { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

/* Primitive buttons in 2 columns — keeps the toolbar from getting tall/crowded. */
button[data-add] { width: calc(50% - 3px); text-align: center; padding: 7px 4px; }

/* Settings rows — label + dropdown */
.setrow { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.setrow label { flex: none; width: 58px; font-size: 11px; color: var(--muted); }
.setrow select {
  flex: 1; padding: 5px 6px;
  background: #0c1014; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; cursor: pointer;
}
.setrow select:focus { outline: none; border-color: var(--accent); }
.btnmap { flex: 1; display: flex; gap: 4px; }
.btnmap select {
  flex: 1; min-width: 0; padding: 4px 3px; font-size: 11px;
  background: #0c1014; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.btnmap select:focus { outline: none; border-color: var(--accent); }

.check { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 12px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.snaprow { display: flex; gap: 6px; margin-top: 6px; }
.snaprow label { flex: 1; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.snaprow input { width: 100%; padding: 3px 4px; background: #0c1014; color: var(--text); border: 1px solid var(--border); border-radius: 5px; font: inherit; }

.muted { color: var(--muted); font-size: 12px; }

/* Inspector numeric rows */
.field { margin-bottom: 10px; }
.field > label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
.vec { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.axis { display: flex; flex-direction: column; }
.axis span { font-size: 10px; color: var(--muted); margin-bottom: 2px; padding-left: 2px; }
.axis.x span { color: #ff6b6b; }
.axis.y span { color: #4ade80; }
.axis.z span { color: #5b9bff; }
input[type="number"], input[type="text"] {
  width: 100%; padding: 5px 4px;
  background: #0c1014; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit;
}
input[type="number"]:focus, input[type="text"]:focus { outline: none; border-color: var(--accent); }
/* Drop the spinner arrows — they steal ~16px and clip values like "-68.0". */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.swatch-row { display: flex; align-items: center; gap: 8px; }
.swatch-row input[type="color"] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: none; }
.meta { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.meta b { color: var(--text); font-weight: 600; }

/* Solid / Hole segmented toggle */
.seg { display: flex; gap: 5px; }
.seg button { width: 50%; text-align: center; padding: 6px 2px; }
.seg button.on { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.seg button[data-role="hole"].on { background: #5c2b2b; border-color: var(--danger); }

/* Outliner (Objects panel) */
#outliner { right: 12px; width: var(--side-w, 200px); bottom: 36px; top: auto; max-height: 38vh; overflow-y: auto; }
.outliner-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.outliner-head .group-label { margin-bottom: 6px; }
.multi-toggle { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; line-height: 1;
  padding: 4px 8px; margin: 0 0 6px; border: 1px solid var(--border); border-radius: 999px;
  background: none; color: var(--muted); cursor: pointer; }
.multi-toggle:hover { color: var(--text); border-color: var(--accent); }
.multi-toggle.active { background: var(--accent); color: #0c1108; border-color: var(--accent); }
/* coarse pointers (touch): bigger tap target for the multi-select toggle */
@media (pointer: coarse) { .multi-toggle { padding: 8px 12px; font-size: 11px; } }
#outliner.multi .orow { cursor: copy; }
.orow { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.orow:hover { background: #1f262f; }
.orow.sel { background: var(--accent-dim); }
.oname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eye { width: auto; margin: 0; padding: 0 4px; background: none; border: none; color: var(--muted); font-size: 13px; }
.eye:hover { background: none; color: var(--text); }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; flex: none; }
.b-add { background: #23314f; color: #9cc2ff; }
.b-cut { background: #4a2626; color: #ff9b9b; }
.b-group { background: #274027; color: #9ad29a; }

#statusbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 5px 14px;
  background: var(--panel-solid);
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 11.5px;
  z-index: 10;
  display: flex; justify-content: space-between;
}
#statusbar .units { color: var(--text); }

/* Lasso overlay — a freehand selection loop drawn over the viewport. */
/* Fixed + explicit 100vw/100vh so the overlay actually fills the viewport. Without a CSS
   size an inline SVG falls back to its 300x150 intrinsic box and clips the selection box,
   which is why it drew "in the distance". 1 user unit = 1px now maps to the pointer. */
#lasso-svg { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 9; pointer-events: none; }
#lasso-svg path { fill: var(--accent); fill-opacity: 0.10; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }

/* ============================================================
   UI styles — flip live via Settings ▸ UI style. Each overrides
   the palette (and a few button traits) so the whole app re-skins.
   "midnight" is the base defined in :root above.
   ============================================================ */
html[data-ui="graphite"] {
  --bg: #0b0d10; --panel: #14171ccc; --panel-solid: #14171c;
  --border: #2c2f36; --text: #d4d7dc; --muted: #767b84;
  --accent: #9aa0aa; --accent-dim: #3a3f47;
}
html[data-ui="graphite"] button,
html[data-ui="graphite"] .panel,
html[data-ui="graphite"] .setrow select { border-radius: 4px; }

html[data-ui="blueprint"] {
  --bg: #0a1622; --panel: #0f2236cc; --panel-solid: #0f2236;
  --border: #1d3a55; --text: #cfe6f5; --muted: #6f96b3;
  --accent: #4fc3f7; --accent-dim: #15466b;
}
html[data-ui="blueprint"] button,
html[data-ui="blueprint"] .setrow select { border-radius: 3px; }
html[data-ui="blueprint"] .group-label { color: #4fc3f7; }

html[data-ui="paper"] {
  --bg: #eef0f3; --panel: #ffffffe6; --panel-solid: #ffffff;
  --border: #d3d8e0; --text: #1b2230; --muted: #5d6675;
  --accent: #2f6df6; --accent-dim: #bcd2ff;
}
html[data-ui="paper"] button { background: #f3f5f8; }
html[data-ui="paper"] button:hover { background: #e9edf3; }
html[data-ui="paper"] input[type="number"],
html[data-ui="paper"] input[type="text"],
html[data-ui="paper"] .setrow select,
html[data-ui="paper"] .snaprow input { background: #fbfcfe; }
html[data-ui="paper"] button.mode.active,
html[data-ui="paper"] button.tool.active { color: #0b2f8a; }

html[data-ui="neon"] {
  --bg: #0d0a18; --panel: #160f2acc; --panel-solid: #160f2a;
  --border: #2e2350; --text: #ece6ff; --muted: #9d8fc7;
  --accent: #b36bff; --accent-dim: #3c2a63; --good: #38e8c0;
}
html[data-ui="neon"] button,
html[data-ui="neon"] .panel,
html[data-ui="neon"] .setrow select { border-radius: 12px; }
html[data-ui="neon"] button.mode.active,
html[data-ui="neon"] button.tool.active { box-shadow: 0 0 10px -2px var(--accent); }

/* "plush" — soft lavender light skin, matches the site directory palette. */
html[data-ui="plush"] {
  --bg: #efe9fb; --panel: #ece4fbe6; --panel-solid: #ece4fb;
  --border: #d9cef3; --text: #332d4f; --muted: #6b6390;
  --accent: #7c5fe0; --accent-dim: #e0d6f7;
}
html[data-ui="plush"] button { background: #e8defb; }
html[data-ui="plush"] button:hover { background: #ddd0f7; }
html[data-ui="plush"] input[type="number"],
html[data-ui="plush"] input[type="text"],
html[data-ui="plush"] .setrow select,
html[data-ui="plush"] .snaprow input { background: #f3edfc; }
html[data-ui="plush"] button.mode.active,
html[data-ui="plush"] button.tool.active { color: #5a3fc0; box-shadow: 0 0 10px -3px var(--accent); }
html[data-ui="plush"] button,
html[data-ui="plush"] .panel,
html[data-ui="plush"] .setrow select { border-radius: 14px; }
html[data-ui="plush"] .group-label { color: #7c5fe0; }
html[data-ui="plush"] kbd { background: #ece5fb; }

/* ---------------------------------------------------------------- shortcuts overlay */
#shortcuts-overlay {
  position: absolute; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px);
}
#shortcuts-overlay[hidden] { display: none; }
.shortcuts-card {
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 20px; max-width: 620px;
  box-shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.6);
}
.shortcuts-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.shortcuts-head span { font-size: 15px; font-weight: 600; }
#shortcuts-close { width: 28px; height: 28px; margin: 0; padding: 0; text-align: center; }
.shortcuts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; }
.sc-col > div { font-size: 12.5px; color: var(--text); margin: 4px 0; }
.sc-sec { font-size: 11px !important; text-transform: uppercase; letter-spacing: .5px; color: var(--muted) !important; margin-top: 12px !important; }
.sc-col > .sc-sec:first-child { margin-top: 0 !important; }
kbd {
  display: inline-block; min-width: 16px; padding: 1px 5px; margin: 0 1px;
  font: 11px/1.5 inherit; text-align: center;
  background: #1f262f; border: 1px solid var(--border); border-radius: 4px;
}
html[data-ui="paper"] kbd { background: #eef0f3; }

/* ---------------------------------------------------------------- Recipe Timeline */
/* The multiverse history strip: docked along the bottom, between the side panels,
   above the status bar. Time → right, branches → down. */
#timeline {
  position: absolute;
  left: calc(12px + var(--toolbar-w, 200px) + 14px);
  right: calc(12px + var(--side-w, 200px) + 14px);
  bottom: 28px;
  z-index: 20;
  padding: 8px 10px 10px;
  max-height: 44vh;
}
/* Keep the [hidden] attribute authoritative so the closed panel can't intercept
   clicks; only lay it out when actually toggled on. */
#timeline:not([hidden]) { display: flex; flex-direction: column; }
.tl-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tl-head .group-label { margin: 0; }
.tl-hint { font-size: 11px; color: var(--muted); flex: 1; }
#tl-close {
  flex: none; width: 22px; height: 22px; padding: 0; line-height: 1;
  background: transparent; border: 1px solid var(--border); border-radius: 5px;
  color: var(--muted); cursor: pointer;
}
#tl-close:hover { color: var(--text); border-color: var(--accent); }
.tl-scroll { overflow: auto; flex: 1; min-height: 96px; }
.tl-canvas { position: relative; }
.tl-svg { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tl-edge { fill: none; stroke: var(--border); stroke-width: 2; }
.tl-edge.active { stroke: var(--accent); stroke-width: 2.5; }

.tl-node {
  position: absolute; width: 72px; padding: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 3px;
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 7px; cursor: pointer; overflow: hidden;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.tl-node:hover { transform: translateY(-2px); border-color: var(--accent-dim); }
.tl-node.on-path { border-color: var(--accent-dim); }
.tl-node.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim), 0 4px 14px #0008;
}
.tl-thumb { width: 100%; height: 44px; object-fit: cover; display: block; background: var(--bg); }
.tl-thumb.empty {
  background: repeating-linear-gradient(45deg, #1b212a, #1b212a 6px, #161b22 6px, #161b22 12px);
}
.tl-label {
  font-size: 10px; color: var(--muted); text-align: center;
  padding: 0 4px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tl-node.current .tl-label { color: #fff; }

/* ---------------------------------------------------------------- dimension chips */
/* Editable dimension pills that float on the selected part in the viewport. The
   layer is anchored at the object's top-centre (JS sets left/top each frame). */
#dimchips {
  position: absolute; z-index: 8;
  transform: translate(-50%, -100%);
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center;
  max-width: 280px; pointer-events: none;
}
.dimchip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px; font-size: 11px; line-height: 1.6;
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text); cursor: pointer;
  box-shadow: 0 2px 6px #0006; white-space: nowrap;
}
.dimchip:hover { border-color: var(--accent); }
.dimchip .dc-k { color: var(--accent); font-weight: 600; }
.dimchip .dc-v { color: var(--text); }
.dimchip .dc-in {
  width: 52px; padding: 0 2px; font-size: 11px;
  background: var(--bg); border: 1px solid var(--accent); border-radius: 4px; color: #fff;
}

/* Group "Parts" editor in the Inspector (parametric re-bake) */
.part { border: 1px solid var(--border); border-radius: 6px; padding: 6px 7px; margin-bottom: 6px; }
.part-nm { font-size: 12px; color: var(--text); margin-bottom: 4px; }

/* ============================================================
   Empty-state prompt + one-time onboarding hint (all screens)
   ============================================================ */
/* Centered "Add a shape to begin" card, shown only when the scene is empty.
   pointer-events stay off the wrapper so it never blocks orbiting; only the
   button is interactive. */
#empty-state {
  position: absolute; inset: 0; z-index: 7;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; pointer-events: none; text-align: center; padding: 0 16px;
}
#empty-state[hidden] { display: none; }
#empty-state .es-title { font-size: 17px; font-weight: 600; color: var(--text); }
#empty-state .es-sub { font-size: 12.5px; color: var(--muted); max-width: 280px; }
#empty-state .es-add {
  pointer-events: auto; width: auto; margin-top: 4px;
  padding: 11px 20px; font-size: 14px; text-align: center;
  background: var(--accent-dim); border-color: var(--accent); color: #fff;
}

/* First-run tip toast (auto-dismisses; remembered in localStorage). */
#onboard-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  z-index: 90; max-width: min(92vw, 460px);
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; font-size: 12.5px; line-height: 1.5;
  background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--accent-dim); border-radius: 10px;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.6);
}
#onboard-hint[hidden] { display: none; }
#onboard-hint .oh-x {
  width: 24px; height: 24px; flex: none; margin: 0; padding: 0;
  text-align: center; line-height: 1; font-size: 15px; color: var(--muted);
}

/* ============================================================
   Coachmark tour: non-blocking, anchored callouts that point at
   real controls (first run + the Tips button). The page stays
   fully interactive behind them — no modal scrim.
   ============================================================ */
#cm-ring {
  position: fixed; z-index: 95; pointer-events: none; border-radius: 10px;
  border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(8,11,16,.34), 0 0 16px -2px var(--accent);
  transition: left .22s ease, top .22s ease, width .22s ease, height .22s ease;
}
#cm-ring[hidden] { display: none; }
#cm-card {
  position: fixed; z-index: 96; max-width: min(88vw, 320px);
  padding: 13px 14px; background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--accent-dim); border-radius: 12px;
  box-shadow: 0 14px 38px -10px rgba(0,0,0,.7); font-size: 13px; line-height: 1.5;
}
#cm-card .cm-text { margin-bottom: 11px; }
#cm-card .cm-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#cm-card .cm-count { font-size: 11px; color: var(--muted); }
#cm-card .cm-btns { display: flex; gap: 6px; }
#cm-card .cm-btns button {
  font-size: 12px; padding: 6px 11px; margin: 0; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: none; color: var(--muted);
}
#cm-card .cm-btns .cm-next { background: var(--accent); color: #0c1108; border-color: var(--accent); font-weight: 600; }
#cm-card .cm-btns button:hover { color: var(--text); }
#cm-card .cm-btns .cm-next:hover { color: #0c1108; filter: brightness(1.08); }
/* Bottom-center, clear of the toolbar (left), inspector (top-right) and outliner
   (bottom-right). Sits just above the status bar. */
#tips-btn {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 38px; z-index: 80;
  width: max-content; max-width: calc(100% - 32px);
  font-size: 11px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--muted); cursor: pointer;
  opacity: .55; transition: opacity .2s ease, color .2s ease;
}
#tips-btn:hover { opacity: 1; color: var(--text); border-color: var(--accent); }
@media (pointer: coarse) { #tips-btn { padding: 9px 14px; font-size: 12px; bottom: 78px; } }
/* a drawer slides up over the bottom on mobile, so hide the Tips button while one is open */
body.drawer-active #tips-btn { opacity: 0; pointer-events: none; }

/* ============================================================
   Mini transparent quick-tools bar, top-center. Icon-only; the
   label shows on hover (desktop) or press (touch). Buttons proxy
   their clicks to the real toolbar buttons (see main.js).
   ============================================================ */
#topbar {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 80;
  display: flex; gap: 2px; padding: 3px;
  border-radius: 12px; background: transparent;
}
#topbar button {
  position: relative; width: 36px; height: 34px; padding: 0;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  border-radius: 9px; transition: color .15s ease, background .15s ease;
}
#topbar svg {
  width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.55)); /* legible over a bright scene */
}
#topbar button:hover, #topbar button:focus-visible { color: var(--text); background: rgba(127,127,127,.16); }
#topbar button:active { background: rgba(127,127,127,.26); }
#topbar button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
/* label tooltip: appears below the icon on hover (desktop) / press (touch) */
#topbar button::after {
  content: attr(data-label); position: absolute; top: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); white-space: nowrap;
  font-size: 11px; padding: 4px 8px; border-radius: 7px;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  opacity: 0; pointer-events: none; transition: opacity .12s ease; z-index: 1;
}
#topbar button:hover::after, #topbar button:focus-visible::after, #topbar button:active::after { opacity: 1; }
body.drawer-active #topbar { opacity: 0; pointer-events: none; }
@media (pointer: coarse) { #topbar { top: 8px; gap: 1px; } #topbar button { width: 40px; height: 38px; } }

/* ============================================================
   Mobile bottom bar + drawer scrim — created by JS, hidden on
   desktop. The drawer layout itself is in the media query below.
   ============================================================ */
#mobile-bar { display: none; }
#mobile-scrim { display: none; }

/* ============================================================
   Phone layout: panels become off-canvas drawers driven by a
   fixed bottom bar. Triggers under 640px wide. Desktop & tablet
   (>=640px, e.g. 768) keep the original floating-panel layout.
   ============================================================ */
@media (max-width: 640px) {
  /* Resize handles make no sense for full-width drawers. */
  .resize-handle { display: none !important; }
  /* The per-panel collapse chevron is replaced by the bar + scrim. */
  .panel .collapse-btn { display: none; }

  /* Common drawer chrome */
  #toolbar, #inspector, #outliner {
    position: fixed; z-index: 70;
    width: auto; max-height: none;
    backdrop-filter: blur(12px);
    transition: transform .22s ease;
  }

  /* Toolbar slides in from the left, full height, scrollable. */
  #toolbar {
    top: 0; left: 0; bottom: 0; right: auto;
    width: min(86vw, 330px);
    border-radius: 0 14px 14px 0;
    overflow-y: auto;
    transform: translateX(-105%);
  }
  #toolbar.drawer-open { transform: none; }

  /* Inspector & Objects rise as bottom sheets, above the bottom bar. */
  #inspector, #outliner {
    left: 0; right: 0; bottom: 52px; top: auto;
    border-radius: 16px 16px 0 0;
    max-height: 68vh; overflow-y: auto;
    transform: translateY(115%);
  }
  #inspector.drawer-open, #outliner.drawer-open { transform: none; }

  /* Timeline as a full-width bottom sheet (its desktop edges use panel-width
     vars that collapse to negative width on a phone). */
  #timeline {
    left: 8px; right: 8px;
    bottom: 56px; max-height: 50vh;
  }

  /* Dimension chips can overflow a narrow screen; keep them in bounds. */
  #dimchips { max-width: 92vw; }

  /* Roomier tap targets across the touch UI. */
  .panel button { min-height: 44px; }
  button.mode { min-height: 44px; }
  button.mini { width: 38px; min-height: 40px; }
  .setrow select, .btnmap select { min-height: 38px; }
  .snaprow input, input[type="number"], input[type="text"] { min-height: 38px; }
  .orow { padding: 9px 6px; }

  /* Status bar sits just above the bottom bar. */
  #statusbar { bottom: 52px; }

  /* The bottom action bar: always-visible drawer toggles + Frame. */
  #mobile-bar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 52px;
    z-index: 80; align-items: stretch;
    background: var(--panel-solid); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #mobile-bar button {
    flex: 1; width: auto; margin: 0; border: none; border-radius: 0;
    background: transparent; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 10px; min-height: 52px; text-align: center;
  }
  #mobile-bar button .mb-ico { font-size: 18px; line-height: 1; }
  #mobile-bar button:active { background: #ffffff14; }
  #mobile-bar button.active { color: var(--accent); }

  /* Scrim behind an open drawer; tap it to dismiss. */
  #mobile-scrim {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  #mobile-scrim.show { opacity: 1; pointer-events: auto; }

  /* On a phone the shape grid breathes a little wider. */
  button[data-add] { padding: 9px 4px; }
}

@media (prefers-reduced-motion: reduce) {
  #toolbar, #inspector, #outliner, #mobile-scrim { transition: none !important; }
}

/* ============================ RENDER VIEW ============================ */
/* Toggle lives in the topbar but reads as a mode switch (icon + label pill). */
#rv-toggle {
  width: auto !important; padding: 0 11px !important; gap: 7px;
  display: inline-flex !important; align-items: center;
  color: var(--text); background: rgba(127,127,127,.14);
  border: 1px solid var(--border) !important; font: inherit; font-size: 12px; font-weight: 600;
  letter-spacing: .02em;
}
#rv-toggle .rv-lbl { line-height: 1; }
#rv-toggle.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)) !important; }
#rv-toggle::after { content: none; }  /* it has its own label */

/* In render view, hide the editing chrome; keep the scene + topbar toggle. */
body.render-view #toolbar,
body.render-view #inspector,
body.render-view #outliner,
body.render-view #timeline,
body.render-view #dimchips,
body.render-view #statusbar { display: none !important; }
body.render-view #topbar button[data-proxy] { display: none; }  /* hide edit tools, keep the toggle */

/* Floating render bar: presets + camera. Mobile-first (bottom, thumb-reachable). */
#rv-bar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 85;
  display: flex; gap: 10px; align-items: center; max-width: calc(100vw - 24px);
  padding: 7px; border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,.4);
  backdrop-filter: blur(8px);
}
#rv-bar .rv-group { display: flex; gap: 4px; }
#rv-bar .rv-presets { padding: 2px; border-radius: 10px; background: rgba(127,127,127,.12); }
#rv-bar button {
  font: inherit; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
  border: 0; background: transparent; padding: 8px 12px; border-radius: 8px;
  transition: color .15s ease, background .15s ease; white-space: nowrap;
}
#rv-bar button:hover { color: var(--text); background: rgba(127,127,127,.14); }
#rv-bar .rv-preset.active { color: #fff; background: var(--accent); }
#rv-bar .rv-cam button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
#rv-bar[hidden] { display: none; }

@media (pointer: coarse), (max-width: 640px) {
  #rv-bar { bottom: 12px; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 6px; }
  #rv-bar button { padding: 10px 12px; }
}
/* hide onboarding/tour + tips in render view (belt-and-suspenders to the JS guard) */
body.render-view #cm-card,
body.render-view #cm-ring,
body.render-view #tips-btn { display: none !important; }
