/* ==========================================================================
   Retina Tomography Workbench — dark clinical instrument-panel UI
   (design language adapted from the Stratum Volumetric Workbench handoff)
   ========================================================================== */
:root {
  --ac: #34d399;                 /* emerald accent */
  --bg: #0b0e12;                 /* app background */
  --rail: #0c0f14;               /* rails / bars */
  --inset: rgba(255,255,255,.025);
  --inset-2: rgba(255,255,255,.045);
  --line: rgba(255,255,255,.06);
  --line-soft: rgba(255,255,255,.05);
  --line-strong: rgba(255,255,255,.09);
  --t-primary: #e7ebf0;
  --t-body: #dce2e9;
  --t-2: #9aa4b0;
  --t-label: #6b7682;
  --t-muted: #5b6671;
  --mono-v: #cdd5df;
  --plane-x: #7bd88f;            /* sagittal (green) */
  --plane-y: #ebb46e;            /* axial (amber) */
  --plane-z: #78aaeb;            /* coronal (blue) */
  --topbar-h: 46px;
  --status-h: 34px;
  --rail-l: 274px;
  --rail-r: 308px;
  font-family: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--t-body); -webkit-font-smoothing: antialiased; }

.ms {
  font-family: 'Material Symbols Outlined';
  font-weight: normal; font-style: normal; line-height: 1; letter-spacing: normal;
  text-transform: none; display: inline-block; white-space: nowrap; direction: ltr;
  font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased; font-size: 18px;
}
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; }

/* ----------------------------- App grid ---------------------------------- */
#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--status-h);
}
#work {
  display: grid;
  grid-template-columns: var(--rail-l) 1fr var(--rail-r);
  grid-template-rows: minmax(0, 1fr);   /* pin the row height so tall rails scroll instead of stretching the viewport */
  min-height: 0;
}
body.no-left  #work { grid-template-columns: 0 1fr var(--rail-r); }
body.no-right #work { grid-template-columns: var(--rail-l) 1fr 0; }

/* ----------------------------- Buttons ----------------------------------- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  background: transparent; border: none; border-radius: 7px;
  color: var(--t-2); cursor: pointer; transition: background .15s, color .15s;
  text-decoration: none;
}
.icon-btn .ms { font-size: 19px; }
.icon-btn:hover { background: rgba(255,255,255,.05); color: var(--t-primary); }
.icon-btn[aria-pressed="true"] { color: var(--ac); background: color-mix(in oklab, var(--ac) 13%, transparent); }
.link-btn { background: none; border: none; color: var(--t-muted); font-size: 11.5px; cursor: pointer; padding: 0; }
.link-btn:hover { color: var(--t-2); text-decoration: underline; text-underline-offset: 2px; }

.bar-div { width: 1px; height: 22px; background: rgba(255,255,255,.07); flex-shrink: 0; }

/* Prominent Sync-views toggle */
.sync-toggle {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px;
  border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--t-2); background: var(--inset-2); border: 1px solid var(--line-strong);
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.sync-toggle .ms { font-size: 17px; }
.sync-toggle:hover { background: rgba(255,255,255,.06); color: var(--t-primary); }
.sync-toggle[aria-pressed="true"] {
  color: var(--ac); background: color-mix(in oklab, var(--ac) 15%, transparent);
  border-color: var(--ac); box-shadow: 0 0 0 1px color-mix(in oklab, var(--ac) 35%, transparent);
}
body.overlay-layout #btn-sync { display: none; }   /* only one view in overlay */

/* "Rotation synced" badge over the viewport */
#sync-badge {
  position: absolute; top: 46px; left: 50%; transform: translateX(-50%) translateY(-6px);
  z-index: 8; display: none; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; pointer-events: none;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  color: var(--ac); background: color-mix(in oklab, var(--ac) 16%, rgba(8,12,18,.82));
  border: 1px solid var(--ac); backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px -8px color-mix(in oklab, var(--ac) 60%, transparent);
  opacity: 0; transition: opacity .2s, transform .2s;
}
#sync-badge .ms { font-size: 14px; }
body.synced:not(.overlay-layout) #sync-badge { display: inline-flex; opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------- Top bar ----------------------------------- */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px 0 14px;
  background: var(--rail); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-mark {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(155deg, var(--ac), #0f7d52);
  box-shadow: 0 6px 18px -8px var(--ac);
}
.logo-mark .ms { font-size: 17px; color: #06140e; }
.wordmark { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-size: 13px; font-weight: 600; color: var(--t-primary); white-space: nowrap; }
.brand-eyebrow { font-size: 9px; font-weight: 600; letter-spacing: .2em; color: var(--t-muted); white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 28px; padding: 0 10px; border-radius: 11px;
  background: transparent; border: 1px solid rgba(255,255,255,.07);
  color: var(--t-2); cursor: pointer; transition: background .15s;
}
.pill:hover { background: rgba(255,255,255,.05); }
.pill .ms { font-size: 16px; }
.pill .mono { font-size: 11px; color: var(--mono-v); letter-spacing: .03em; }

/* Study selector dropdown */
#study-menu {
  position: fixed; z-index: 60; display: none; min-width: 210px;
  padding: 5px; border-radius: 10px;
  background: var(--rail); border: 1px solid var(--line-strong);
  box-shadow: 0 12px 34px -14px rgba(0,0,0,.85);
}
#study-menu.open { display: block; }
.study-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-family: inherit;
  background: none; border: none; color: var(--t-body); text-align: left;
}
.study-item:hover { background: rgba(255,255,255,.05); }
.study-item .ms { font-size: 16px; color: var(--t-2); }
.study-item-name { flex: 1; font-size: 13px; }
.study-item-meta { font-size: 10.5px; color: var(--t-muted); }

.live-status { display: flex; align-items: center; gap: 7px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ac); box-shadow: 0 0 8px 1px color-mix(in oklab, var(--ac) 70%, transparent); }
.live-status .mono { font-size: 10.5px; color: var(--t-muted); letter-spacing: .04em; }
.topbar-spacer { flex: 1; }
.avatar { width: 27px; height: 27px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--t-body); background: rgba(255,255,255,.06); border: 1px solid var(--line-strong); }

/* ----------------------------- Rails ------------------------------------- */
.rail { background: var(--rail); overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; min-height: 0; }
#rail-left  { border-right: 1px solid var(--line); }
#rail-right { border-left: 1px solid var(--line); }
.rail-sec { padding: 14px 15px; border-bottom: 1px solid var(--line-soft); flex-shrink: 0; }
.rail-grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.rail-grow #layer-tree { flex: 1; overflow-y: auto; margin: 0 -7px; }

.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase;
  color: var(--t-muted); margin-bottom: 12px;
}
.chip { font-size: 9.5px; font-weight: 600; letter-spacing: .08em; padding: 2px 7px; border-radius: 6px; color: var(--ac); background: color-mix(in oklab, var(--ac) 13%, transparent); }
.chip-count { font-size: 10px; font-weight: 600; color: var(--t-2); background: rgba(255,255,255,.06); border-radius: 6px; padding: 1px 7px; }

.meta-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; }
.meta-k { font-size: 11.5px; color: var(--t-label); }
.meta-v { font-size: 11.5px; color: var(--mono-v); text-align: right; }
.meta-v a { color: var(--ac); text-decoration: none; }
.meta-v a:hover { text-decoration: underline; }

/* ----------------------------- Layer tree -------------------------------- */
.sample { margin-bottom: 2px; }
.sample-head-row { display: flex; align-items: center; gap: 4px; padding-right: 6px; }
.sample-head {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  padding: 7px 9px; background: none; border: none; cursor: pointer;
  color: var(--t-body); font-size: 12.5px; font-weight: 600; text-align: left;
  font-family: inherit;
}
.sample-head:hover { background: rgba(255,255,255,.045); border-radius: 6px; }
.is-demo .sample-name { color: var(--t-2); }
.is-demo .sample-name::after { content: ' ◇'; color: var(--ac); font-size: 9px; }

.sample-vis {
  appearance: none; -webkit-appearance: none; width: 15px; height: 15px; flex-shrink: 0;
  border: 1.5px solid var(--line-strong); border-radius: 4px; background: var(--inset-2);
  cursor: pointer; position: relative;
}
.sample-vis:checked { background: var(--ac); border-color: var(--ac); }
.sample-vis:checked::after { content: ''; position: absolute; left: 4px; top: 1px; width: 3.5px; height: 7px; border: solid #06140e; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.sample-gear { width: 26px; height: 26px; }
.sample-gear .ms { font-size: 16px; }
.sample-gear.active { color: var(--ac); background: color-mix(in oklab, var(--ac) 13%, transparent); }

.sample-ctl { padding: 6px 10px 10px; margin: 0 6px 4px; background: var(--inset); border-radius: 8px; }
.demo-badge { font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ac); margin-bottom: 8px; }
.ctl-line { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; }
.ctl-line > span { font-size: 11px; color: var(--t-label); }
.ctl-line .slider { margin: 6px 0; }
.sample-head .caret { color: var(--t-muted); font-size: 10px; transition: transform .2s; }
.sample-head.open .caret { transform: rotate(90deg); }
.sample-name { flex: 1; }
.sample-src { color: var(--t-muted); text-decoration: none; font-size: 12px; padding: 2px 4px; }
.sample-src:hover { color: var(--ac); }
.sample-body { display: none; padding: 2px 0 6px; }
.sample-body.open { display: block; }

.layer-row { border-radius: 7px; padding: 2px 6px; transition: background .14s; }
.layer-row:hover { background: rgba(255,255,255,.045); }
.layer-row[data-state="loading"] { background: color-mix(in oklab, var(--ac) 10%, transparent); }
.layer-row[data-state="error"] { background: rgba(248,113,113,.08); }
.layer-top { display: flex; align-items: center; gap: 9px; padding: 7px 4px; }

.layer-check {
  appearance: none; -webkit-appearance: none; width: 16px; height: 16px; flex-shrink: 0;
  border: 1.5px solid var(--line-strong); border-radius: 5px; background: var(--inset-2);
  cursor: pointer; position: relative; transition: background .14s, border-color .14s;
}
.layer-check:hover { border-color: var(--ac); }
.layer-check:checked { background: var(--ac); border-color: var(--ac); }
.layer-check:checked::after { content: ''; position: absolute; left: 4.5px; top: 1px; width: 4px; height: 8px; border: solid #06140e; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.layer-swatch { width: 14px; height: 14px; flex-shrink: 0; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); cursor: pointer; padding: 0; transition: transform .12s; }
.layer-swatch:hover { transform: scale(1.15); }
.layer-color-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

.layer-label { flex: 1; min-width: 0; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.layer-name { font-size: 12.5px; color: var(--t-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-size { font-size: 10px; color: var(--t-muted); font-family: 'IBM Plex Mono', monospace; }
.layer-size.heavy { color: var(--plane-y); }
.layer-opacity { width: 58px; flex-shrink: 0; }

.layer-progress { height: 3px; margin: 1px 6px 0; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; }
.layer-bar { height: 100%; width: 0%; background: var(--ac); transition: width .2s; }
.layer-status { font-size: 10px; color: var(--t-2); padding: 2px 6px 3px; font-family: 'IBM Plex Mono', monospace; }
.layer-row[data-state="error"] .layer-status { color: #f87171; }
.layer-row[data-state="loaded"] .layer-status { color: var(--ac); }
.tree-error { padding: 16px; color: #f87171; font-size: 12.5px; line-height: 1.5; }

/* ----------------------------- Sliders ----------------------------------- */
.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 3px; cursor: pointer;
  background: linear-gradient(to right, var(--ac) var(--fill,50%), rgba(255,255,255,.1) var(--fill,50%));
  margin: 9px 0;
}
.slice-row .slider { background: linear-gradient(to right, var(--pc) var(--fill,50%), rgba(255,255,255,.1) var(--fill,50%)); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); border: 1px solid rgba(0,0,0,.35); }
.slider::-moz-range-thumb { width: 12px; height: 12px; border: 1px solid rgba(0,0,0,.35); border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.layer-opacity { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 3px; background: linear-gradient(to right, var(--ac) var(--fill,100%), rgba(255,255,255,.1) var(--fill,100%)); cursor: pointer; }
.layer-opacity::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.5); }
.layer-opacity::-moz-range-thumb { width: 11px; height: 11px; border: none; border-radius: 50%; background: #fff; }

/* ----------------------------- Anatomy panel ----------------------------- */
.model-picker { position: relative; }
.pill-wide { width: 100%; justify-content: flex-start; gap: 7px; }
.pill-wide #model-label { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#model-menu {
  display: none; position: absolute; z-index: 60; top: calc(100% + 5px); left: 0; right: 0;
  background: var(--panel, #10161c); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 16px 40px rgba(0,0,0,.55); padding: 5px; max-height: 58vh; overflow-y: auto;
}
#model-menu.open { display: block; }
.model-item {
  display: grid; grid-template-columns: 1fr auto; gap: 1px 8px; width: 100%; text-align: left;
  padding: 8px 9px; border-radius: 7px; border: 0; background: transparent; cursor: pointer;
  font-family: inherit; color: var(--t-body);
}
.model-item:hover:not(:disabled) { background: rgba(255,255,255,.055); }
.model-item.active { background: color-mix(in oklab, var(--ac) 13%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ac) 30%, transparent); }
.model-item.active .model-name { color: var(--ac); }
.model-item:disabled { cursor: not-allowed; opacity: .42; }
.model-name { font-size: 12.5px; }
.model-sub { grid-column: 1 / -1; font-size: 10px; color: var(--t-muted); line-height: 1.35; }
.model-lic { font-size: 9px; color: var(--t-muted); align-self: center; }
.model-source { font-size: 10px; color: var(--t-muted); margin-top: 8px; line-height: 1.4; }
.model-source a { color: var(--t-2); }

/* Cap the anatomy list so it never squeezes the LAYERS tree below it. */
#anatomy-tree { margin: 2px -7px 0; max-height: 32vh; overflow-y: auto; }
.anat-group {
  font-size: 9.5px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--t-muted); padding: 11px 10px 4px; font-family: var(--mono, inherit);
}
.anat-group:first-child { padding-top: 4px; }
.anat-row .layer-top { padding: 5px 4px; }
.anat-row.is-off .layer-name { color: var(--t-muted); }
.anat-row.is-off .layer-swatch { opacity: .38; }
/* Marks a structure the µCT segmentation also resolves, so the two panes pair up. */
.coat-tag {
  align-self: flex-start; margin-top: 2px; font-size: 8.5px; letter-spacing: .07em;
  padding: 1px 5px; border-radius: 4px; color: var(--ac);
  background: color-mix(in oklab, var(--ac) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ac) 28%, transparent);
}
/* Inline µCT tag used in the Help / About prose. */
.cite-tag {
  font-size: 9px; letter-spacing: .06em; padding: 1px 5px; border-radius: 4px;
  color: var(--ac); background: color-mix(in oklab, var(--ac) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ac) 28%, transparent);
}
#anatomy-tree::-webkit-scrollbar { width: 9px; }
#anatomy-tree::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }

/* ----------------------------- Segmented control ------------------------- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
/* Text-only segmented buttons (anatomy presets) have no icon row to align. */
#anatomy-preset .seg-btn { padding: 7px 4px; font-size: 11px; }
.seg.seg-2 { grid-template-columns: repeat(2, 1fr); }
#overlay-ctl { margin-top: 12px; }
.seg-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 4px; border-radius: 7px; cursor: pointer; font-family: inherit;
  background: rgba(255,255,255,.02); border: 1px solid var(--line-soft);
  color: var(--t-2); transition: background .15s, color .15s, border-color .15s;
}
.seg-btn .ms { font-size: 19px; }
.seg-btn span:last-child { font-size: 11px; }
.seg-btn:hover { background: rgba(255,255,255,.045); }
.seg-btn.active { color: var(--ac); background: color-mix(in oklab, var(--ac) 13%, transparent); border-color: transparent; box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ac) 32%, transparent); }
.seg-desc { font-size: 10.5px; color: var(--t-muted); margin-top: 10px; }

/* ----------------------------- Slice rows -------------------------------- */
.slice-row { display: grid; grid-template-columns: 86px 1fr 34px; align-items: center; gap: 8px; margin-bottom: 4px; }
.slice-toggle { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--t-2); cursor: pointer; }
.slice-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.slice-toggle .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--pc); opacity: .35; transition: opacity .14s, box-shadow .14s; flex-shrink: 0; }
.slice-toggle input:checked ~ .dot { opacity: 1; box-shadow: 0 0 7px 0 var(--pc); }
.slice-toggle input:checked + .dot { } /* (dot follows text in markup) */
.slice-row .slider { margin: 5px 0; }
.slice-val { font-size: 10.5px; color: var(--t-muted); text-align: right; }

/* ----------------------------- Inline toggles / control rows ------------- */
.inline-toggle { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--t-2); margin-top: 12px; cursor: pointer; }
.switch { position: relative; width: 34px; height: 19px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .knob { position: absolute; inset: 0; border-radius: 11px; background: rgba(255,255,255,.1); transition: background .16s; }
.switch .knob::after { content: ''; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #e7ebf0; transition: transform .16s; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.switch input:checked + .knob { background: var(--ac); }
.switch input:checked + .knob::after { transform: translateX(15px); }

.ctl-row { display: flex; align-items: center; justify-content: space-between; }
.ctl-k { font-size: 12px; color: var(--t-2); }
.ctl-v { font-size: 11px; color: var(--mono-v); }

/* ----------------------------- Viewport ---------------------------------- */
#viewport { display: flex; min-width: 0; min-height: 0; position: relative; background: #07090c; }
.pane {
  position: relative; flex: 1 1 50%; min-width: 0; min-height: 0; overflow: hidden;
  background: radial-gradient(125% 120% at 50% 36%, #0f141b, #0a0d12 56%, #06090c);
}
.pane canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.pane canvas:active { cursor: grabbing; }

/* HUD: corner brackets */
.hud-bracket { position: absolute; width: 15px; height: 15px; border: 0 solid rgba(255,255,255,.16); pointer-events: none; z-index: 4; }
.hud-bracket.tl { top: 10px; left: 10px; border-top-width: 1px; border-left-width: 1px; }
.hud-bracket.tr { top: 10px; right: 10px; border-top-width: 1px; border-right-width: 1px; }
.hud-bracket.bl { bottom: 10px; left: 10px; border-bottom-width: 1px; border-left-width: 1px; }
.hud-bracket.br { bottom: 10px; right: 10px; border-bottom-width: 1px; border-right-width: 1px; }

/* HUD: orientation letters */
.hud-orient { position: absolute; font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: rgba(231,235,240,.34); pointer-events: none; z-index: 4; }
.hud-orient.t { top: 7px; left: 50%; transform: translateX(-50%); }
.hud-orient.b { bottom: 7px; left: 50%; transform: translateX(-50%); }
.hud-orient.l { left: 7px; top: 50%; transform: translateY(-50%); }
.hud-orient.r { right: 7px; top: 50%; transform: translateY(-50%); }

.pane-label {
  position: absolute; top: 11px; left: 28px; z-index: 6; max-width: calc(50% - 64px);
  padding: 4px 11px; border-radius: 999px;
  background: rgba(8,12,18,.72); backdrop-filter: blur(6px); border: 1px solid var(--line);
  font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; font-weight: 500; letter-spacing: .04em;
  color: var(--t-2); text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* HUD: floating glass toolbar */
.hud-toolbar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; gap: 2px; padding: 3px; border-radius: 9px;
  background: rgba(10,13,18,.72); backdrop-filter: blur(9px);
  border: 1px solid var(--line); box-shadow: 0 10px 30px -14px rgba(0,0,0,.85);
}
.hud-toolbar .icon-btn { width: 28px; height: 28px; }
.hud-toolbar .icon-btn .ms { font-size: 16px; }

/* HUD: scale bar */
.hud-scale { position: absolute; bottom: 12px; left: 12px; z-index: 4; pointer-events: none; color: rgba(231,235,240,.46); font-family: 'IBM Plex Mono', monospace; font-size: 9.5px; }
.hud-scale .bar { height: 5px; border-left: 1px solid rgba(231,235,240,.4); border-right: 1px solid rgba(231,235,240,.4); border-bottom: 1px solid rgba(231,235,240,.4); margin-bottom: 3px; }

/* Overlay layout: the STL pane becomes the single combined viewport. */
body.overlay-layout #pane-glb, body.overlay-layout #divider { display: none; }

#divider { flex: 0 0 5px; align-self: stretch; background: var(--line); cursor: col-resize; position: relative; z-index: 7; transition: background .15s; }
#divider::after { content: ''; position: absolute; inset: 0 -4px; }
#divider:hover, body.dragging #divider { background: var(--ac); }

/* Overlay (GLB loader) + empty state */
.pane-overlay, .pane-empty { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 20px; text-align: center; }
.pane-overlay.hidden, .pane-empty.hidden { display: none; }
.overlay-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 26px 28px; max-width: 300px; background: rgba(12,15,20,.92); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px -14px rgba(0,0,0,.85); }
.overlay-icon { font-size: 36px; color: var(--ac); }
.overlay-title { font-size: 15px; font-weight: 600; color: var(--t-primary); }
.overlay-sub { font-size: 12px; color: var(--t-2); line-height: 1.4; }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 14px; font-size: 12.5px; font-weight: 600; font-family: inherit; border-radius: 7px; cursor: pointer; border: 1px solid var(--line); background: var(--inset-2); color: var(--t-body); transition: background .15s; }
.btn:hover { background: rgba(255,255,255,.08); }
.btn-primary { background: var(--ac); color: #06140e; border-color: transparent; }
.btn-primary:hover { background: #2bbd87; }
.btn-ghost { background: transparent; }
.progress { width: 230px; height: 6px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--ac); transition: width .2s; }
.empty-card { display: flex; flex-direction: column; align-items: center; gap: 11px; color: var(--t-muted); font-size: 12.5px; max-width: 220px; }
.empty-icon { font-size: 28px; opacity: .55; }

/* ----------------------------- Status bar -------------------------------- */
#statusbar { display: flex; align-items: center; gap: 12px; padding: 0 14px; background: var(--rail); border-top: 1px solid var(--line); }
#statusbar .stat { font-size: 10.5px; color: #7e8794; letter-spacing: .03em; }
.status-spacer { flex: 1; }

/* ----------------------------- Edge restore ------------------------------ */
.edge-restore { position: fixed; top: calc(var(--topbar-h) + 8px); z-index: 30; width: 24px; height: 30px; display: none; align-items: center; justify-content: center; background: var(--rail); border: 1px solid var(--line); color: var(--t-2); cursor: pointer; }
.edge-restore.left { left: 0; border-radius: 0 8px 8px 0; border-left: none; }
body.no-left .edge-restore.left { display: inline-flex; }

/* ----------------------------- Toasts ------------------------------------ */
#toast-host { position: fixed; bottom: calc(var(--status-h) + 14px); left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 10px 15px; border-radius: 9px; font-size: 12.5px; max-width: 90vw; background: #161d28; border: 1px solid var(--line-strong); color: var(--t-body); box-shadow: 0 10px 30px -14px rgba(0,0,0,.85); opacity: 0; transform: translateY(10px); transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: rgba(248,113,113,.5); }
.toast-error::before { content: '⚠ '; color: #f87171; }

/* ----------------------------- Modal / dialog ---------------------------- */
.modal-back { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.5); backdrop-filter: blur(2px); animation: fade .15s; }
.modal { width: min(420px, 92vw); background: var(--rail); border: 1px solid var(--line-strong); border-radius: 13px; padding: 22px; box-shadow: 0 10px 30px -14px rgba(0,0,0,.85); }
.modal-title { font-size: 15px; font-weight: 600; color: var(--t-primary); margin-bottom: 8px; }
.modal-msg { font-size: 13px; color: var(--t-2); line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

#help-dialog, #about-dialog { border: 1px solid var(--line-strong); border-radius: 14px; padding: 0; background: var(--rail); color: var(--t-body); max-width: 540px; width: 92vw; max-height: 88vh; box-shadow: 0 10px 40px -14px rgba(0,0,0,.85); }
#help-dialog::backdrop, #about-dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.dialog-card { position: relative; padding: 26px 28px; }
.dialog-close { position: absolute; top: 14px; right: 14px; }
.dialog-card h2 { margin: 0 0 12px; font-size: 18px; color: var(--t-primary); }
.dialog-card h3 { margin: 18px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .16em; color: var(--ac); }
.dialog-card p { margin: 0 0 10px; font-size: 13px; line-height: 1.6; color: var(--t-2); }
.dialog-card ul { margin: 0; padding-left: 18px; }
.dialog-card li { font-size: 13px; line-height: 1.8; color: var(--t-2); }
.dialog-card strong { color: var(--t-body); }
.dialog-card a { color: var(--ac); text-decoration: none; }
.dialog-card a:hover { text-decoration: underline; }
.about-line { line-height: 1.7; }
.cite { font-size: 12px; color: var(--t-2); padding-left: 11px; border-left: 2px solid var(--line-strong); line-height: 1.65; }
.dialog-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ----------------------------- Scrollbars -------------------------------- */
.rail::-webkit-scrollbar, #layer-tree::-webkit-scrollbar { width: 9px; }
.rail::-webkit-scrollbar-thumb, #layer-tree::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
.rail::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.16); background-clip: content-box; }

/* ----------------------------- Responsive -------------------------------- */
@media (max-width: 1080px) {
  :root { --rail-r: 264px; --rail-l: 248px; }
}
@media (max-width: 900px) {
  /* Right rail folds away first; left rail can be toggled. */
  body { --rail-r: 0px; }
  #work { grid-template-columns: var(--rail-l) 1fr 0 !important; }
  #rail-right { display: none; }
  #viewport { flex-direction: column; }
  #divider { flex-basis: 5px; height: 5px; cursor: row-resize; align-self: auto; }
  .brand-eyebrow { display: none; }
  #study-selector, .live-status { display: none; }
}
@media (max-width: 620px) {
  /* Left rail becomes a fixed overlay drawer; viewport fills the single track. */
  #work { grid-template-columns: 1fr !important; }
  #rail-left { position: fixed; top: var(--topbar-h); bottom: var(--status-h); left: 0; width: 248px; z-index: 25; box-shadow: 0 10px 30px -14px rgba(0,0,0,.85); }
  body.no-left #rail-left { display: none; }
  body:not(.no-left) .edge-restore.left { display: none; }
  #stat-tris, #stat-fps, #statusbar .bar-div { display: none; }  /* avoid status overflow */
  #topbar a.icon-btn, .avatar, #topbar .bar-div { display: none; }  /* declutter top bar */
}
