:root {
  --bg: #121212;
  --panel: #1e1e1e;
  --accent: #00c853;
  --edge: #3a4a40;   /* muted resting border; green is for active states */
  --text: #e0e0e0;
  --border: #333;
  --fs-label: .78rem; --fs-body: .85rem; --fs-head: .92rem;   /* type scale */
  --bg-deep: #0a0a0a; --surface: #222; --surface-2: #2e2e2e; --surface-3: #444; --glass: rgba(25,25,25,.95);
  --text-hi: #fff; --text-2: #bbb; --muted: #888;
  --line-1: #2a2a2a; --line-3: #444; --line-4: #555;
  --link: #4fc3f7; --warn: #ffd600; --warn-bg: #3a3300; --warn-line: #8a6d1a; --err: #ff6b6b; --err-bg: #3a1d1d; --ok: #81c784;
  --mono: ui-monospace, Consolas, "Cascadia Mono", monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tab-content {
  flex: 1;
  overflow: hidden;
  display: none;
  background: var(--bg-deep);
}
.tab-content.active { display: flex; flex-direction: column; }

/* Top Menu Bar inside Free Create */
.menu-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  gap: 4px;
  flex-shrink: 0;
  z-index: 30;
}
#bedName { margin-left: auto; align-self: center; padding: 0 8px; font-size: var(--fs-body); white-space: nowrap; }
.menu-dropdown {
  position: relative;
  display: inline-block;
}
.menu-btn {
  background: transparent;
  color: var(--text);
  padding: 6px 12px;
  font-size: var(--fs-body);
  border-radius: 4px;
  cursor: pointer;
  margin: 0;
  width: auto;
}
.menu-btn:hover { background: var(--surface-2); }
.menu-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  min-width: 180px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 100;
  padding: 4px 0;
}
.menu-content.show { display: block; }
.menu-item {
  color: var(--text);
  padding: 8px 16px;
  text-decoration: none;
  display: block;
  font-size: var(--fs-body);
  cursor: pointer;
  background: transparent;
  border: none;
  text-align: left;
  width: 100%;
  margin: 0;
}
.menu-item:hover { background: var(--surface-2); color: var(--accent); }
.menu-sep { height: 1px; background: var(--surface-3); margin: 4px 0; }
.menu-item.has-key { display: flex; justify-content: space-between; align-items: center; gap: 24px; white-space: nowrap; }
.menu-item.menu-check.has-key { justify-content: flex-start; gap: 4px; }
.menu-item.menu-check.has-key input { margin-right: 4px; }
.menu-key { color: var(--muted); font-size: var(--fs-label); margin-left: auto; padding-left: 24px; }
.menu-item.has-key:hover .menu-key { color: var(--accent); }
.menu-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: default; }
.menu-head:hover { background: transparent; color: var(--text); }
.menu-sub { white-space: nowrap; }
.menu-group-label { padding: 6px 16px 2px; font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); cursor: default; user-select: none; }

/* Submenu styling */
.submenu-container {
  position: relative;
}
.submenu-content {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: var(--surface);
  min-width: 150px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  z-index: 105;
}
.submenu-container:hover .submenu-content { display: block; }
#toolsMenu .submenu-content { white-space: nowrap; min-width: 200px; }

/* Free Create Full Viewport */
#freecreate-tab {
  position: relative;
  flex: 1;
  display: none;
}
#freecreate-tab.active {
  display: flex;
  flex-direction: column;
}
#fc-viewport {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  background: var(--bg-deep);
  overflow: hidden;
}
#fc-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Box generator settings (ported) */
.bed-msg { font-size: var(--fs-label); margin: 6px 0 10px; padding: 6px 8px; border-radius: 6px; }
.bed-msg:empty { display: none; }
.bed-msg.ok { color: var(--ok); background: rgba(0,200,83,0.08); }
.bed-msg.bad { color: var(--err); background: rgba(244,67,54,0.15); border: 1px solid #f44336; }
.sub-options { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.sub-options.show { display: block; }
input[type="color"] { height: 34px; padding: 2px; }
.hole-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 8px;
  font-size: var(--fs-label);
}
.spin { display: flex; align-items: center; gap: 2px; }
.spin input { flex: 1; min-width: 0; }
.spin button {
  width: 26px;
  padding: 4px 0;
  margin: 0;
  font-size: var(--fs-head);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-3);
  border-radius: 4px;
}
.spin button:hover { background: var(--surface-3); }
.hole-item button { padding: 4px 8px; font-size: var(--fs-label); }
.hole-item .controls { display: flex; gap: 6px; margin-top: 4px; }

/* Top-left stack: status text + docked box options */
#top-left-stack {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100% - 16px);
  pointer-events: none;
}
#obj-wrap { position: relative; width: 220px; flex-shrink: 0; }
#obj-wrap #obj-tab { width: 100%; }
#status-row { position: absolute; left: calc(100% + 6px); top: 0; display: flex; align-items: flex-start; gap: 6px; }
/* Toast messages ("Cube added...") dock beside the status text */
#status-row .toast-msg {
  position: static; transform: none; bottom: auto; left: auto;
  white-space: nowrap; padding: 4px 10px; font-size: var(--fs-label); align-self: flex-start;
}

/* Parent panel: Objects + Selected Object as children, same width */
#left-panel {
  pointer-events: auto;
  width: 100%;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
#left-panel #obj-tab,
#left-panel #coords-tab {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}
#left-panel #top-right-tabs { display: block; width: 100%; max-width: none; border-top: 1px solid var(--edge); }

/* Mode panel: top section of the left panel (current modal tool + axis) */
#mode-panel { padding: 6px 12px; border-bottom: 1px solid var(--edge); font-size: var(--fs-label); background: var(--surface); }
.mode-row { display: flex; justify-content: space-between; align-items: center; padding: 1px 0; }
.mode-title { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
#modeVal, #axisVal { font-weight: 600; font-family: ui-monospace, monospace; color: var(--accent); }
#snapQuick { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
#snapQuick[hidden] { display: none; }
#snapQuick label { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 0.7rem; color: var(--muted); padding: 1px 0; }
#snapQuick input { width: 56px; padding: 1px 4px; }

/* Selected Object rows wrap to fit the panel width */
#left-panel #coords-tab { white-space: normal; }
#left-panel .coords-row { flex-wrap: wrap; gap: 4px 6px; }
#left-panel .coords-title { flex: 0 0 100%; min-width: 0; }
#left-panel #coords-tab label { flex: 1 1 0; min-width: 0; }
#left-panel #coords-tab input[type="number"] { width: 100%; min-width: 0; padding: 3px 2px; text-overflow: clip; }
#left-panel #coords-tab input[type="range"] { width: auto; flex: 1 1 0; min-width: 0; }
#left-panel #coords-tab select { flex: 1; width: 100%; }
#left-panel #coordsTitle { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Overlap fix: units/values keep their natural width, checkbox labels + buttons wrap instead of squeezing */
#left-panel #coords-tab .coords-unit { flex: 0 0 auto; white-space: nowrap; }
#left-panel #coords-tab .coords-actions { gap: 6px 10px; }
#left-panel #coords-tab .coords-actions label { flex: 0 0 auto; white-space: nowrap; }
#left-panel #coords-tab .coords-actions button { flex: 1 1 auto; white-space: nowrap; }
#left-panel #coords-tab .coords-row > label > input[type="checkbox"] { flex: 0 0 auto; }
/* Objects tab (left) */
#obj-tab {
  pointer-events: auto;
  width: 220px;
  flex-shrink: 0;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
#obj-tab-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--surface);
  font-weight: 600; font-size: var(--fs-head);
  cursor: pointer; user-select: none;
}
#obj-tab-header:hover { background: var(--surface-2); }
.obj-arrow { font-size: var(--fs-label); color: var(--muted); transition: transform 0.2s; }
#obj-tab.collapsed .obj-arrow { transform: rotate(-90deg); }
#obj-tab.collapsed #obj-list { display: none; }
#obj-list { max-height: 40vh; overflow-y: auto; padding: 4px; }
.obj-empty { padding: 8px; font-size: var(--fs-label); color: var(--muted); }
.obj-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: 6px;
  font-size: var(--fs-body); cursor: pointer;
}
.obj-row:hover { background: var(--surface-2); }
.obj-row.selected { background: var(--warn-bg); color: var(--warn); }
.obj-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obj-row button.obj-focus {
  width: 26px; margin: 0; padding: 2px 0;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-4); border-radius: 4px;
}
.obj-row button.obj-focus:hover { background: var(--accent); color: #000; }
.obj-row button.obj-toggle {
  width: auto; margin: 0; padding: 0 3px;
  background: none; border: none; font-size: var(--fs-body); line-height: 1;
  color: var(--text); cursor: pointer;
}
.obj-row button.obj-toggle:hover { background: none; filter: brightness(1.4); }
.obj-row button.obj-toggle.off { opacity: 0.35; }
.obj-row.hidden-obj .obj-name { opacity: 0.45; }
.float-panel {
  position: relative;
  display: none;
  flex-direction: column;
  min-height: 0;
  width: 360px;
  max-width: calc(100vw - 16px);
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  pointer-events: auto;
}
.float-panel.show { display: flex; }
#opt-panel { width: 320px; }
.float-panel-header {
  padding: 8px 12px;
  font-weight: 600;
  font-size: var(--fs-head);
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#gen-modal-body, #opt-panel-body, #grid-panel-body, #hotkeys-panel-body, #gear-body, .part-body {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
/* Floating panels: any element with class "float-panel" that has a child
   ".float-panel-header" automatically gets Move and Resize toggles. */
.float-panel-header { user-select: none; }
.float-panel.fp-moving .float-panel-header { cursor: move; box-shadow: inset 0 -2px 0 var(--accent); }
.fp-controls { display: flex; gap: 4px; margin-left: auto; margin-right: 8px; flex-shrink: 0; }
.fp-toggle { position: relative; display: inline-block; margin: 0; cursor: pointer; }
.fp-toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; padding: 0; cursor: pointer; }
.fp-toggle span {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  text-align: center;
  font-size: var(--fs-label);
  line-height: 1.2;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line-4);
  border-radius: 4px;
}
.float-panel-header > span:first-child { flex-shrink: 0; white-space: nowrap; }
.fp-controls button.fp-icon {
  width: auto;
  min-width: 22px;
  margin: 0;
  padding: 2px 5px;
  font-size: var(--fs-label);
  line-height: 1.2;
  font-weight: 400;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line-4);
  border-radius: 4px;
  cursor: pointer;
}
.fp-controls button.fp-icon:hover { background: var(--surface-3); }
.fp-controls button.fp-icon.dirty { border-color: var(--accent); color: var(--accent); }
.fp-font-pop {
  display: none;
  position: absolute;
  right: 8px;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line-4);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  z-index: 8;
  font-size: var(--fs-label);
}
.fp-font-pop button {
  width: auto;
  margin: 0;
  padding: 2px 8px;
  font-size: var(--fs-label);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--line-4);
  border-radius: 4px;
}
.fp-font-pop button:hover { background: var(--surface-3); }
.fp-font-pop .fp-font-val { min-width: 38px; text-align: center; color: var(--text); }
/* Text size: everything in the panel except the header scales */
.float-panel > :not(.float-panel-header):not(.fp-resize-handle):not(.fp-font-pop) { zoom: var(--fp-scale, 1); }
/* Minimized: shrink to the header so the tab name and buttons always show in full */
.float-panel.fp-minimized { height: auto !important; min-height: 0; width: max-content !important; max-width: none !important; }
.float-panel.fp-minimized > :not(.float-panel-header) { display: none !important; }
.float-panel.fp-maximized .fp-resize-handle { display: none !important; }
.float-panel.fp-maximized .float-panel-header { cursor: default; box-shadow: none; }
.fp-toggle input:checked + span { background: var(--accent); color: #000; border-color: var(--accent); }
.fp-toggle input:focus-visible + span { outline: 2px solid #fff; }
.fp-resize-handle {
  display: none;
  position: absolute;
  touch-action: none;
  z-index: 5;
}
.fp-resize-handle:hover { background: rgba(0, 200, 83, 0.35); }
.fp-resize-handle[data-dir="n"]  { top: 0;    left: 14px; right: 14px; height: 7px; cursor: ns-resize; }
.fp-resize-handle[data-dir="s"]  { bottom: 0; left: 14px; right: 14px; height: 7px; cursor: ns-resize; }
.fp-resize-handle[data-dir="e"]  { right: 0;  top: 14px; bottom: 14px; width: 7px;  cursor: ew-resize; }
.fp-resize-handle[data-dir="w"]  { left: 0;   top: 14px; bottom: 14px; width: 7px;  cursor: ew-resize; }
.fp-resize-handle[data-dir="ne"] { top: 0;    right: 0;  width: 14px; height: 14px; cursor: nesw-resize; }
.fp-resize-handle[data-dir="nw"] { top: 0;    left: 0;   width: 14px; height: 14px; cursor: nwse-resize; }
.fp-resize-handle[data-dir="sw"] { bottom: 0; left: 0;   width: 14px; height: 14px; cursor: nesw-resize; }
.fp-resize-handle[data-dir="se"] {
  bottom: 0; right: 0; width: 20px; height: 20px; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--accent) 50%);
}
.float-panel.fp-resizing .fp-resize-handle { display: block; }
.menu-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.menu-check input { width: auto; margin: 0; }

/* Shift+A Add menu */
#add-menu {
  display: none;
  position: absolute;
  background: var(--surface);
  min-width: 160px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  padding: 4px 0;
  z-index: 60;
}
#add-menu.show { display: block; }
#add-menu .add-title {
  padding: 6px 16px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Shape right-click menu + selection badge */
#shape-menu {
  display: none;
  position: absolute;
  background: var(--surface);
  min-width: 175px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  padding: 4px 0;
  z-index: 60;
}
#shape-menu.show { display: block; }
#shape-menu .menu-item:hover { color: var(--accent); }
#shape-menu .menu-item.danger:hover { color: var(--err); }
#array-dialog, #lib-dialog, #text-dialog, #lic-dialog, #bug-dialog, #help-dialog {
  display: none;
  position: absolute;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  padding: 8px 14px 12px;
  z-index: 70;
  min-width: 250px;
}
#array-dialog.show, #lib-dialog.show, #text-dialog.show, #lic-dialog.show, #bug-dialog.show, #help-dialog.show { display: block; }
#text-dialog label, #array-dialog label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; font-size: var(--fs-body); }
#array-dialog input, #array-dialog select, #text-dialog input, #text-dialog select { width: 90px; }
#text-dialog textarea { width: 150px; resize: vertical; }
#array-dialog .arr-btns, #lib-dialog .arr-btns, #text-dialog .arr-btns, #lic-dialog .arr-btns, #bug-dialog .arr-btns, #help-dialog .arr-btns { display: flex; gap: 8px; margin-top: 10px; }
#array-dialog .arr-btns button, #lib-dialog .arr-btns button, #text-dialog .arr-btns button, #lic-dialog .arr-btns button, #bug-dialog .arr-btns button, #help-dialog .arr-btns button { flex: 1; }
#lib-dialog { min-width: 320px; max-width: 420px; }
#lib-list { max-height: 260px; overflow-y: auto; margin-top: 6px; }
#lib-list .lib-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: var(--fs-body); }
#lib-list .lib-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lib-list button { width: auto; margin: 0; padding: 2px 8px; font-size: var(--fs-label); }
#shape-menu .menu-sep { height: 1px; background: var(--surface-3); margin: 4px 0; }
#shape-menu .ctx-sub { position: relative; }
#shape-menu .ctx-flyout {
  display: none;
  position: absolute;
  left: 100%;
  top: -5px;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 6px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  padding: 4px 0;
}
#shape-menu .ctx-sub:hover .ctx-flyout { display: block; }
#shape-menu .ctx-sub.flip .ctx-flyout { left: auto; right: 100%; }
#sel-badge {
  display: none;
  position: absolute;
  bottom: 52px;                          /* just above the hotbar */
  left: 50%;                             /* true bottom-center, same as hotbar */
  transform: translateX(-50%);
  max-width: calc(100% - 16px);
  text-align: center;
  background: rgba(0,0,0,0.65);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--warn);
  pointer-events: none;
  z-index: 10;
}


.info { font-size: var(--fs-label); color: var(--muted); margin-top: 4px; }
.section { background: var(--surface); border-radius: 8px; padding: 0; margin-bottom: 10px; overflow: hidden; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: var(--fs-head);
  color: var(--text-2);
}
.section-header:hover { background: var(--surface-2); }
.section-header .arrow { font-size: var(--fs-label); color: var(--muted); transition: transform 0.2s; }
.section.collapsed .arrow { transform: rotate(-90deg); }
.section-body { padding: 0 12px 12px; }
.section.collapsed .section-body { display: none; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: var(--fs-head); }
.check input { width: auto; }
label { display: block; font-size: var(--fs-body); margin-bottom: 2px; }
input, select, button, textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-head);
}
button {
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border: none;
  cursor: pointer;
  margin-top: 4px;
}
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--surface-3); color: var(--text); }
.row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-end; }
.row:last-child { margin-bottom: 0; }
label[data-u]::after { content: " (" attr(data-u) ")"; color: var(--muted); font-size: 0.75em; }
.row > * { flex: 1; }
.shape-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 6px; }
.shape-row label { font-size: 0.7rem; white-space: nowrap; }
.shape-row input { min-width: 0; padding: 8px 6px; }
#top-right-stack {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  max-height: calc(100% - 16px);
  max-width: calc(100% - 16px);
  pointer-events: none;
}
#top-right-tabs {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: stretch;
  gap: 6px;
  max-width: calc(100% - 16px);
}
#coords-tab {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  width: 100%;
  max-width: 100%;
  padding: 0;
  font-size: var(--fs-label);
  background: var(--glass);
  color: var(--warn);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  overflow: hidden;
  white-space: nowrap;
}
#coords-tab label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: var(--fs-label);
  font-family: ui-monospace, monospace;
}
#coords-tab input {
  width: 64px;
  padding: 3px 5px;
  font-size: var(--fs-label);
  font-family: ui-monospace, monospace;
  background: var(--surface);
  color: var(--warn);
  border: 1px solid var(--line-4);
  border-radius: 4px;
  -moz-appearance: textfield;
}
#coords-tab input:focus { outline: none; border-color: var(--warn); }
#coords-tab input::-webkit-outer-spin-button,
#coords-tab input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#coords-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  background: var(--surface);
  font-size: var(--fs-head);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
#coords-header:hover { background: var(--surface-2); }
#coords-body { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px; }
#coords-tab .coords-arrow { font-size: var(--fs-label); color: var(--muted); transition: transform 0.2s; }
#coords-tab.collapsed .coords-arrow { transform: rotate(-90deg); }
#coords-tab.collapsed #coords-body { display: none; }
#coords-tab input:disabled, #coords-tab button:disabled { opacity: 0.4; cursor: not-allowed; }
#coords-tab input[type="range"] { width: 110px; padding: 0; }
#coords-tab input[type="checkbox"] { width: auto; margin: 0; }
#coords-tab select {
  width: auto;
  padding: 3px 5px;
  font-size: var(--fs-label);
  background: var(--surface);
  color: var(--warn);
  border: 1px solid var(--line-4);
  border-radius: 4px;
}
.coords-actions { flex-wrap: wrap; }
#coords-tab .coords-actions button {
  width: auto;
  margin: 0;
  padding: 3px 10px;
  font-size: var(--fs-label);
  background: var(--surface-3);
  color: var(--text);
}
#coords-tab .coords-actions button:hover { background: var(--accent); color: #000; }
#coords-tab .coords-actions button.danger { background: #7a2020; color: #fff; }
#coords-tab .coords-actions button.danger:hover { background: #ff5252; }
#coords-tab .coords-unit { color: var(--muted); }
.coords-row { display: flex; align-items: center; gap: 6px 8px; }
.coords-title { min-width: 80px; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
/* Narrow screens: drop the tabs below the status box so nothing overlaps or clips */
@media (max-width: 700px) {
  #top-right-stack { top: 70px; max-height: calc(100% - 78px); }
}
.cam-pos {
  position: absolute;
  bottom: 8px;
  right: 8px;     /* fallback only; normally docked in the Master panel title */
  background: rgba(0,0,0,0.65);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  color: var(--text-2);
  pointer-events: none;
  z-index: 10;
}
.cam-pos.in-title {
  position: static;
  margin-left: auto;
  padding: 2px 6px;
  white-space: nowrap;
}
.toast-msg {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text-hi);
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  font-size: var(--fs-body);
  z-index: 99999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transition: opacity 0.3s;
}
/* ===== Master Panel (right dock) ===== */
#master-panel {
  display: none;
  position: absolute;
  top: 8px; right: 8px; bottom: 8px;
  width: 340px;
  max-width: calc(100vw - 16px);
  z-index: 13;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
#master-panel.show { display: flex; }
#master-panel .mp-title {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: var(--fs-head);
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
#mp-tabs { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 0; padding-bottom: 8px; pointer-events: auto; }   /* auto so its scrollbar takes clicks; it is only as tall as its tabs */
.mp-tab {
  pointer-events: auto;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  flex-shrink: 0;
  font-size: var(--fs-body);
}
.mp-tab label { font-size: var(--fs-body); }
.mp-tab-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  font-weight: 600; font-size: var(--fs-head);
  cursor: pointer; user-select: none;
}
.mp-tab-header:hover { background: var(--surface-2); }
.mp-tab-title { flex: 1; }
.mp-arrow { font-size: var(--fs-label); color: var(--muted); transition: transform 0.2s; }
.mp-tab.collapsed .mp-arrow { transform: rotate(-90deg); }
.mp-tab.collapsed .mp-tab-body { display: none; }
.mp-tab-header .mp-close { width: auto; margin: 0; padding: 2px 8px; background: var(--surface-3); color: var(--text); }
/* Slim collapsed headers (Settings, Grid, etc.) */
.mp-tab.collapsed .mp-tab-header { padding: 3px 10px; font-size: 0.8rem; }
.mp-tab.collapsed .mp-tab-header .mp-close { padding: 0 6px; font-size: 0.75rem; }
.mp-tab.collapsed .mp-tab-header .mp-help { padding: 0 6px; font-size: 0.7rem; }

/* Panel while docked: drop floating behavior, header lives in the tab */
#master-panel .float-panel.in-master {
  position: static !important;
  left: auto !important; top: auto !important; transform: none !important;
  width: 100% !important; max-width: none !important;
  height: auto !important; max-height: none; overflow: visible;   /* one scroll area only: #mp-tabs (a second, inner scrollbar left the last control cut off) */
  border: none; border-radius: 0; box-shadow: none;
}
.float-panel.in-master > .float-panel-header,
.float-panel.in-master > .fp-resize-handle,
.float-panel.in-master > .fp-font-pop { display: none !important; }

/* Make room for the dock */
#fc-viewport.master-open #top-right-stack { right: 356px; }
/* ===== Bottom hotbar (center) + top view strip ===== */
#hotbar-wrap {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 16px);
  z-index: 14;
  pointer-events: none;
}
#hotbar, #view-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  pointer-events: auto;
  max-width: 100%;
  overflow-x: auto;
}
#view-strip {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 16px);
  z-index: 14;
}
#hotbar .hb-group { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
#hotbar .hb-sep, #view-strip .vs-sep { width: 1px; height: 18px; background: var(--surface-3); margin: 0 2px; flex-shrink: 0; }
#hotbar button { margin: 0; width: auto; }

#view-strip .vs-btn {
  width: 44px; height: 40px; margin: 0; padding: 2px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-3); border-radius: 4px;
}
#view-strip .vs-btn:hover { background: var(--surface-2); color: var(--accent); filter: none; }
#view-strip .vs-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
#view-strip .vs-btn span { font-size: 0.6rem; line-height: 1; }
#view-strip .vs-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }

/* Hotkeys panel list */
.hk-group { margin: 10px 0 4px; font-weight: 600; font-size: var(--fs-label); color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.hk-group:first-child { margin-top: 0; }
.hk-row { display: flex; gap: 10px; padding: 3px 0; font-size: var(--fs-label); border-bottom: 1px solid var(--line-1); }
.hk-keys { flex: 0 0 42%; font-family: ui-monospace, monospace; color: var(--warn); }

/* ===== Hotbar buttons (Center + Top/Front/Back/Left/Right/Iso, keys 1-6) ===== */
#hotbar .hb-view,
#hotbar .refresh-btn {
  width: 44px; height: 40px; margin: 0; padding: 2px 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line-3); border-radius: 4px;
  flex-shrink: 0; cursor: pointer;
}
#hotbar .hb-view span, #hotbar .refresh-btn span { font-size: 0.6rem; line-height: 1; font-weight: 600; }
#hotbar svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
#hotbar .hb-view:hover,
#hotbar .refresh-btn:hover { background: var(--surface-2); color: var(--accent); filter: none; }
#hotbar .hb-view.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ===== Part generators (Tools > Generator): one panel per part, built by geometry.js, docked by master.js ===== */
.part-body .row { margin-bottom: 6px; }
/* Measure tool label */
#measure-label { position: fixed; display: none; transform: translate(-50%, -130%); pointer-events: none; z-index: 60; background: rgba(20,20,20,.88); border: 1px solid var(--warn); border-radius: 4px; padding: 3px 8px; font-size: var(--fs-label); color: #fff; white-space: nowrap; text-align: center; }
#measure-label b { color: var(--warn); font-size: var(--fs-body); }
#measure-label span { color: var(--text-2); }

/* Check model + Help dialogs */
#help-dialog { min-width: 340px; max-width: 460px; max-height: 75vh; overflow-y: auto; font-size: var(--fs-body); }
#help-body p { margin: 6px 0; line-height: 1.35; }
.chk-row { margin: 4px 0; line-height: 1.3; }
.chk-ok { color: var(--ok); }
.chk-warn { color: var(--warn); }
.chk-info { color: var(--text-2); }
.chk-row button.chk-lay { width: auto; margin: 6px 0 2px; padding: 4px 10px; display: block; }
.chk-det { margin-top: 4px; color: var(--text-2); font-size: var(--fs-label); }
.chk-det summary { cursor: pointer; }
.chk-tab { border-collapse: collapse; margin-top: 4px; width: 100%; }
.chk-tab td { padding: 2px 6px 2px 0; border-bottom: 1px solid var(--edge); white-space: nowrap; }
.chk-tab .chk-bad { color: var(--warn); }
.chk-limit { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; color: var(--text-2); }
.chk-limit input { width: 70px; }

/* ===== Debug panel (bottom left) + error toasts (top center, below the view strip) ===== */
.toast-msg.toast-has-act, #status-row .toast-msg.toast-has-act { pointer-events: auto; display: inline-flex; align-items: center; gap: 10px; position: fixed; left: 50%; bottom: 84px; top: auto; transform: translateX(-50%); z-index: 99999; }   /* above the camera bar, clear of the top toolbar */
.toast-act { width: auto; margin: 0; padding: 2px 10px; font-size: var(--fs-label); background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 5px; cursor: pointer; }
.toast-act:hover { background: var(--accent); color: #000; }
.toast-msg.toast-err { bottom: auto; top: 92px; z-index: 100000; max-width: 70vw; background: var(--err-bg); }
#debug-panel { position: absolute; left: 8px; bottom: 8px; z-index: 15; width: 340px; max-width: calc(100% - 16px); display: flex; flex-direction: column; align-items: flex-start; gap: 4px; pointer-events: none; }
#dbg-toggle { pointer-events: auto; width: auto; margin: 0; padding: 4px 10px; background: var(--glass); color: var(--text); border: 1px solid var(--edge); border-radius: 8px; font-size: .75rem; }
#dbg-badge { display: none; background: #f44336; color: #fff; border-radius: 9px; padding: 0 6px; margin-left: 4px; font-size: .7rem; }
#dbg-body { display: none; pointer-events: auto; order: -1; width: 100%; height: 260px; flex-direction: column; background: var(--glass); border: 1px solid var(--edge); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.6); overflow: hidden; }
#debug-panel.open #dbg-body { display: flex; }
#dbg-bar { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-bottom: 1px solid var(--line-3); font-size: .72rem; flex-wrap: wrap; }
#dbg-bar label { display: flex; align-items: center; gap: 3px; margin: 0; }
#dbg-bar input[type=checkbox] { width: auto; margin: 0; }
#dbg-bar button { width: auto; margin: 0 0 0 auto; padding: 2px 8px; font-size: .72rem; }
#dbg-bar button + button { margin-left: 0; }
#dbg-stats { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 2px 10px; padding: 4px 8px; border-bottom: 1px solid var(--line-3); font: .7rem ui-monospace, monospace; }
#dbg-stats span { opacity: .65; }
#dbg-list { flex: 1; overflow-y: auto; padding: 4px 8px; font: .72rem ui-monospace, monospace; }
.dbg-row { padding: 2px 0; border-bottom: 1px solid var(--line-1); }
.dbg-error .dbg-head { color: var(--err); } .dbg-warn .dbg-head { color: var(--warn); } .dbg-info .dbg-head { color: var(--text-2); }
.dbg-head { white-space: pre-wrap; word-break: break-word; }
.dbg-detail { display: none; margin: 2px 0 0 8px; opacity: .7; white-space: pre-wrap; word-break: break-all; font-size: .66rem; }
.dbg-row.open .dbg-detail { display: block; }
.dbg-empty { opacity: .5; padding: 6px 0; }

/* ===== Tool panels (Measure / Check model / Cut) docked in the Master panel ===== */
.tool-panel-body { padding: 8px; font-size: var(--fs-body); }
#cut-body label, #check-panel-body label.chk-limit { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; font-size: var(--fs-body); }
#cut-body input[type=number], #cut-body select { width: 90px; }
#cut-body label.check { justify-content: flex-start; }
#cut-body input[type=checkbox] { width: auto; }
#cut-body .arr-btns, #check-panel-body .arr-btns, #measure-body .arr-btns { display: flex; gap: 8px; margin-top: 10px; }
#cut-body .arr-btns button, #check-panel-body .arr-btns button, #measure-body .arr-btns button { flex: 1; }
#check-panel-body #check-body { max-height: 40vh; overflow-y: auto; margin-top: 6px; }
#measure-readout { margin: 8px 0; padding: 6px 8px; background: var(--surface); border: 1px solid var(--line-3); border-radius: 4px; line-height: 1.5; }
#measure-readout b { color: var(--warn); }
#dbg-hover { display: flex; align-items: center; gap: 6px; margin: 0; padding: 4px 8px; border-bottom: 1px solid var(--line-3); font-size: .72rem; }
#dbg-hover input { width: auto; margin: 0; }

.expr-bad { outline: 1px solid #e57373 !important; background: rgba(229,115,115,0.12) !important; }
#cutters-list .cutter { border: 1px solid var(--border); border-radius: 6px; padding: 6px; margin-bottom: 6px; }
#cutters-list .cutter-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
#cutters-list .cutter-head button { width: auto; padding: 2px 8px; }
#cutters-list [hidden] { display: none !important; }
#cutters-list .cutter .check { display: flex; gap: 4px; align-items: center; }

/* ===== Settings icon rows ===== */
#set-icons { margin-bottom: 10px; }
#set-icons .set-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
#set-icons button { margin: 0; padding: 0; background: var(--surface-2); color: var(--text); border: 1px solid var(--line-3); border-radius: 4px; display: flex; align-items: center; justify-content: center; gap: 6px; }
#set-icons button:hover { background: var(--surface-2); color: var(--accent); filter: none; }
#set-icons .set-ico { flex: 1 1 0; min-width: 0; height: 44px; flex-direction: column; gap: 2px; }
#set-icons .set-ico span { font-size: 0.6rem; line-height: 1; font-weight: 600; white-space: nowrap; }
#set-icons .set-tab { height: 32px; padding: 0 10px; font-size: var(--fs-label); font-weight: 600; }
#set-icons .set-ico.active, #set-icons .set-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }
#set-icons svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linejoin: round; stroke-linecap: round; }
.set-page[hidden] { display: none; }
#set-icons .set-tab { width: auto; flex: 1 1 0; min-width: 0; }

/* ===== Section tabs (icon + label row, one section shown at a time) ===== */
.sec-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.sec-tabs .sec-tab { width: auto; min-width: 0; height: 32px; margin: 0; padding: 0 8px; display: flex; align-items: center; justify-content: center; gap: 5px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line-3); border-radius: 4px; font-size: var(--fs-label); font-weight: 600; white-space: nowrap; }
.sec-tabs .sec-tab:hover { background: var(--surface-2); color: var(--accent); filter: none; }
.sec-tabs .sec-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }
.sec-tabs svg { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linejoin: round; stroke-linecap: round; }
.sec-tabs.me-tabs { grid-template-columns: repeat(2, 1fr); }   /* Subdivide panel: four tabs in a 2 x 2 grid */
.sec-tabbed > .section:has(> .section-header):not(.tab-open) { display: none; }
.sec-tabbed > .section.tab-open > .section-body { display: block; }
.sec-tabbed > .section > .section-header { cursor: default; }
.sec-tabbed > .section > .section-header .arrow { display: none; }

/* ===== UI pass 2: mono numbers, focus ring, bigger tab icons, open-tab accent, empty hints, toolbar groups ===== */
input[type=number] { font-family: var(--mono); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#coords-tab input:focus-visible { outline: none; }
.sec-tabs svg { width: 18px; height: 18px; stroke-width: 2.3; }
.mp-tab:not(.collapsed) > .mp-tab-header { box-shadow: inset 3px 0 0 var(--accent); }
#cutters-list:empty::before, #holes-list:empty::before { display: block; padding: 8px; border: 1px dashed var(--edge); border-radius: 6px; font-size: var(--fs-label); color: var(--muted); text-align: center; }
#cutters-list:empty::before { content: "No cutters yet. Click + Add cutter."; }
#holes-list:empty::before { content: "No holes yet. Click + Add Hole."; }
#view-strip .vs-sep { height: 28px; margin: 0 4px; }

/* ===== Light interface theme (html.theme-light, set from Settings > View > Light interface; the 3D canvas has its own Light background setting) ===== */
html.theme-light {
  --bg: #f2f4f3; --panel: #ffffff; --accent: #00a846; --edge: #b3bcb7; --text: #1d2421; --border: #c9cfcc;
  --bg-deep: #e9ecea; --surface: #f6f7f6; --surface-2: #e6e9e7; --surface-3: #d5dad7; --glass: rgba(250,250,250,.96);
  --text-hi: #000; --text-2: #3a443f; --muted: #66706b;
  --line-1: #dde1df; --line-3: #b5bcb8; --line-4: #9aa39f;
  --link: #0277bd; --warn: #7a5f00; --warn-bg: #fff4c2; --warn-line: #c9a227; --err: #c62828; --err-bg: #fde0e0; --ok: #1b7a3a;
}
html.theme-light body { background: var(--bg-deep); }
html.theme-light .cam-pos, html.theme-light #sel-badge { background: rgba(255,255,255,.85); }

/* Narrow windows: toolbars go icon-only; the top toolbar wraps to 2 rows at top-left and the left stack drops below it */
/* ===== Command box (Ctrl+K) ===== */
#cmdk { position: fixed; inset: 0; z-index: 400; display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; background: rgba(0,0,0,.35); }
#cmdk.show { display: flex; }
#cmdk .cmdk-card { width: min(560px, 94vw); background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: hidden; font-size: var(--fs-body); }
#cmdk-in { width: 100%; box-sizing: border-box; border: 0; border-bottom: 1px solid var(--edge); border-radius: 0; background: var(--surface-2); color: var(--text-hi); padding: 12px 14px; font-size: var(--fs-head); outline: none; }
#cmdk-list { max-height: 50vh; overflow-y: auto; }
.cmdk-row { display: flex; align-items: baseline; gap: 8px; padding: 7px 12px; cursor: pointer; color: var(--text); border-left: 3px solid transparent; }
.cmdk-row.on, .cmdk-row:hover { background: var(--surface-3); border-left-color: var(--accent); color: var(--text-hi); }
.cmdk-tag { flex: 0 0 auto; min-width: 46px; font-size: var(--fs-label); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cmdk-t { flex: 0 1 auto; white-space: nowrap; }
.cmdk-d { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--fs-label); }
.cmdk-none { padding: 14px; color: var(--muted); text-align: center; }
#cmdk kbd { font-family: var(--mono); background: var(--surface-3); border: 1px solid var(--edge); border-radius: 4px; padding: 1px 5px; }

/* Sketch panel (Tools > Draw > Sketch) */
#sketch-body label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; font-size: var(--fs-body); }
#sketch-body label.check { justify-content: flex-start; }
#sketch-body { overflow-y: auto; flex: 1; min-height: 0; }
#sketch-body input[type=number] { width: 90px; }
#sketch-body select { width: 110px; }
#sketch-body .info { margin: 6px 0; }
.sk-canvas { display: block; width: 100%; aspect-ratio: 1 / 1; max-height: 260px; background: var(--surface-2); border: 1px solid var(--edge); border-radius: 6px; touch-action: none; cursor: crosshair; }
.sk-cursor { font-family: var(--mono); color: var(--muted); }
.sk-btns, #sketch-body .arr-btns { display: flex; gap: 6px; margin-top: 8px; }
.sk-btns button, #sketch-body .arr-btns button { flex: 1; width: auto; padding: 4px 6px; margin: 0; }
#fillet-body { overflow-y: auto; flex: 1; min-height: 0; }
#fillet-body label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; font-size: var(--fs-body); }
#fillet-body input[type=number] { width: 90px; }
#fillet-body select { width: 150px; }
#fillet-body .info { margin: 6px 0; }
#fillet-body .arr-btns { display: flex; gap: 6px; margin-top: 8px; }
#fillet-body .arr-btns button { flex: 1; width: auto; padding: 4px 6px; margin: 0; }
.sk-sub { margin: 12px 0 2px; padding-top: 8px; border-top: 1px solid var(--edge); font-size: var(--fs-label); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 900px) {
  #view-strip .vs-btn, #hotbar .hb-view, #hotbar .refresh-btn { width: 34px; height: 34px; }
  #view-strip .vs-btn span, #hotbar .hb-view span, #hotbar .refresh-btn span { display: none; }
  #view-strip, #hotbar { gap: 2px; padding: 3px 4px; }
  #view-strip { left: 8px; transform: none; flex-wrap: wrap; width: 192px; max-width: calc(100% - 16px); overflow: visible; }
  #view-strip .vs-sep { display: none; }
  #top-left-stack { top: 90px; }
  #master-panel { width: 300px; }
  #fc-viewport.master-open #top-right-stack { right: 316px; }
  #fc-viewport.master-open #status-row { flex-direction: column; }
  #fc-viewport.master-open #status-row .toast-msg { white-space: normal; width: max-content; max-width: calc(100vw - 568px); }
}

@media (max-width: 700px) {
  /* Master Panel becomes a bottom sheet so the 3D view stays visible above it */
  #master-panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-width: none; max-height: 56%; }
  #fc-viewport.master-open #top-right-stack { right: 8px; }
  #fc-viewport.master-open #left-panel { display: none; }
  #fc-viewport.master-open #hotbar-wrap { bottom: calc(56% + 16px); }
  #fc-viewport.master-open #debug-panel { display: none; }
  #fc-viewport.master-open #status-row { position: fixed; left: 8px; top: auto; bottom: calc(56% + 84px); flex-direction: row; }
  #fc-viewport.master-open #status-row .toast-msg { max-width: calc(100vw - 16px); }
}

/* ===== Sketch panel: tab row (same look as .sec-tabs) + one page shown at a time ===== */
#skTabs { margin-top: 10px; }
.sk-page[hidden] { display: none; }
@media (max-width: 700px) { #set-icons .set-ico span { display: none; } #set-icons .set-ico { height: 32px; } }

/* ===== Touch pass: bigger tap targets on touch screens and narrow windows (layout rules are in the 700px blocks above) ===== */
@media (pointer: coarse), (max-width: 700px) {
  .menu-btn { min-height: 40px; padding: 8px 12px; }
  .menu-item { min-height: 38px; display: flex; align-items: center; }
  .menu-item.has-key { justify-content: space-between; }
  #master-panel button, #master-panel select, #master-panel input[type=number], #master-panel input[type=text] { min-height: 36px; }
  #master-panel input[type=checkbox], #master-panel input[type=radio], .menu-check input { width: 20px; height: 20px; }
  .mp-tab-header .mp-close, .mp-tab-header .mp-help { min-height: 32px; min-width: 36px; display: inline-flex; align-items: center; justify-content: center; }
  .mp-tab.collapsed .mp-tab-header { padding: 6px 10px; }
  .mp-tab.collapsed .mp-tab-header .mp-close, .mp-tab.collapsed .mp-tab-header .mp-help { min-height: 30px; min-width: 34px; padding: 0 6px; }
  .sec-tabs button, #skTabs button { min-height: 38px; }
  #set-icons .set-ico { min-height: 38px; min-width: 38px; }
  .toast-act { min-height: 34px; padding: 4px 12px; }
}
@media (max-width: 700px) {
  /* bottom sheet: while a panel is open, hide the collapsed ones so it gets the room (close the open panel, or use the menus, to switch) */
  #master-panel:has(.mp-tab:not(.collapsed)) .mp-tab.collapsed { display: none; }
}
@media (max-width: 400px) { .menu-bar { padding: 4px 4px; gap: 0; } .menu-btn { padding: 8px 9px; } #bedName { display: none; } }

#bug-dialog, #lic-dialog { width: 300px; max-width: calc(100vw - 24px); }
#bug-dialog .bug-col, #lic-dialog .bug-col { display: flex; flex-direction: column; align-items: stretch; gap: 3px; margin: 6px 0; font-size: var(--fs-body); }
#bug-dialog .bug-col textarea, #bug-dialog .bug-col input, #lic-dialog .bug-col textarea { width: 100%; box-sizing: border-box; resize: vertical; }
#bug-dialog .bug-check { display: flex; align-items: flex-start; gap: 6px; margin: 6px 0; font-size: var(--fs-body); }
#bug-dialog .bug-check input { width: auto; margin-top: 2px; }
#bug-dialog .bug-note, #lic-dialog .bug-note { font-size: 11px; opacity: .75; margin: 4px 0; min-height: 1em; }

.pro-locked::after { content: "PRO"; font-size: 9px; font-weight: 700; letter-spacing: .5px; margin-left: 6px; padding: 1px 4px; border-radius: 3px; background: var(--accent); color: #000; vertical-align: middle; }
