/* =========================================================================
   cbct.css — styling for the CBCT (3D) matching trainer.
   Standalone; mirrors the green Image Match RT theme but doesn't depend on
   the 2D app's styles.css.
   ========================================================================= */

:root {
  --bg: #0e141c;
  --surface: #161f2b;
  --surface-2: #1e2937;
  --border: #263241;
  --border-strong: #3a4759;
  --text: #e8edf2;
  --text-muted: #9aa7b5;
  --text-faint: #6b7888;
  --accent: #0d9488;         /* teal — matches the website */
  --accent-hover: #14b8a6;
  --accent-dim: #0891b2;     /* cyan — accent→dim gives the site gradient */
  --accent-rgb: 13,148,136;
  --grad: linear-gradient(135deg, #0d9488, #0891b2);
  --danger: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 52px;
  --panel-w: 380px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

/* Light mode — the chrome goes light like the website; the image viewer and the
   monospace readout panels stay dark (clinically correct for CT/CBCT greyscale). */
html[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #eceef1;
  --border: #e3e6ea;
  --border-strong: #cfd4dc;
  --text: #1d1d1f;
  --text-muted: #55606e;
  --text-faint: #8a929e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mobile-only { display: none; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent-hover); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }
.interaction-bar { display:flex; align-items:center; gap:16px; flex:0 0 auto; padding:6px 18px; border-bottom:1px solid var(--border); background:var(--surface); }
.interaction-modes { display:flex; gap:5px; flex-shrink:0; }
.slice-controls { display:flex; align-items:center; gap:7px; min-width:0; }
.slice-controls > button { min-width:36px; font-size:22px; line-height:1; }
.slice-slider-label { display:flex; min-width:60px; width:150px; }
.slice-slider-label input { width:100%; accent-color:var(--accent); margin:0; }
.slice-readout { font-size:12px; white-space:nowrap; min-width:90px; font-variant-numeric:tabular-nums; color:var(--text-muted); }
.interaction-hint { font-size:11px; line-height:1.4; color:var(--text-muted); }
.mobile-controls-dialog { display:none; }

/* Compact touch workspace: controls live in sheets, leaving the scan in view. */
body.mobile-ui { padding-top:env(safe-area-inset-top); }
body.mobile-ui .mobile-only { display:flex; }
body.mobile-ui .cbct-topbar { min-height:44px; height:44px; flex-wrap:nowrap; padding:0 max(12px,env(safe-area-inset-left)) 0 max(12px,env(safe-area-inset-left)); gap:8px; }
body.mobile-ui .cbct-topbar .brand { font-size:14px; gap:6px; min-width:0; }
body.mobile-ui .brand-mode { display:none; }
body.mobile-ui .brand-dot { width:8px; height:8px; }
body.mobile-ui .mobile-undo { align-items:center; gap:5px; height:40px; min-width:66px; padding:5px; border:0; background:transparent; color:var(--text-muted); font-size:24px; }
body.mobile-ui .mobile-undo span { font-size:11px; }
body.mobile-ui .cbct-workspace { display:flex; flex:1 1 0; min-height:0; }
body.mobile-ui .viewer-wrap { flex:1 1 0; min-width:0; min-height:0; width:100%; }
body.mobile-ui .rot-rail, body.mobile-ui .panel-toggle { display:none; }
body.mobile-ui .mobile-plane-bar { align-items:center; justify-content:space-between; gap:6px; min-height:44px; padding:0 max(8px,env(safe-area-inset-left)); background:var(--surface); border-bottom:1px solid var(--border); flex-shrink:0; }
body.mobile-ui .view-switch { border:0; border-radius:0; overflow:visible; gap:2px; }
body.mobile-ui .view-btn { min-width:40px; min-height:42px; padding:6px 7px; border:0; border-radius:6px; font-size:12px; }
body.mobile-ui .interaction-modes { gap:3px; }
body.mobile-ui .interaction-modes .btn { padding:5px 8px; min-height:40px; font-size:13px; }
body.mobile-ui .interaction-modes .btn span { font-size:11px; }
body.mobile-ui .interaction-bar { padding:2px max(8px,env(safe-area-inset-left)); gap:6px; min-height:42px; }
body.mobile-ui .interaction-hint { display:none; }
body.mobile-ui .slice-controls { width:100%; gap:7px; }
body.mobile-ui .slice-controls > button { min-width:40px; min-height:38px; padding:3px; }
body.mobile-ui .slice-slider-label { width:auto; flex:1; height:38px; align-items:center; }
body.mobile-ui .slice-readout { font-size:11px; min-width:82px; text-align:right; }
body.mobile-ui .mobile-fusion-bar { min-height:36px; padding:0 max(12px,env(safe-area-inset-left)); flex:0 0 auto; background:var(--surface-2); border-bottom:1px solid var(--border); }
body.mobile-ui .opacity-control { display:flex; align-items:center; gap:9px; width:100%; min-width:0; font-size:11px; color:var(--text-muted); }
body.mobile-ui .opacity-control input { flex:1; width:0; min-width:50px; accent-color:var(--accent); height:32px; }
body.mobile-ui .opacity-control .readout { min-width:30px; text-align:right; }
body.mobile-ui .status-banner { order:10; flex:0 0 auto; padding:5px max(12px,env(safe-area-inset-left)); font-size:11px; line-height:1.4; max-height:41px; overflow:auto; overscroll-behavior:contain; }
body.mobile-ui .mobile-dock { order:11; flex:0 0 auto; justify-content:space-around; background:var(--surface); border-top:1px solid var(--border); padding:2px max(5px,env(safe-area-inset-left)) calc(3px + env(safe-area-inset-bottom)); }
body.mobile-ui .mobile-dock button { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; min-width:52px; min-height:54px; padding:4px; border:0; border-radius:7px; background:transparent; color:var(--text-muted); font:600 11px var(--font); }
body.mobile-ui .mobile-dock button > span { font-size:23px; line-height:1; font-weight:400; }
body.mobile-ui .mobile-dock button[aria-expanded="true"], body.mobile-ui .mobile-dock button[aria-pressed="true"] { color:var(--accent-hover); background:var(--surface-2); }
body.mobile-ui .active-pane-badge { display:none; }
body.mobile-ui .pane-max-btn { width:40px; height:40px; opacity:.85; }
body.mobile-ui .viewer-hint { padding:18px; }
body.mobile-ui .viewer-hint-card { padding:20px; max-width:340px; }
body.mobile-ui .viewer-hint-icon { font-size:30px; }
body.mobile-ui .viewer-hint-card h3 { font-size:17px; }
body.mobile-ui .viewer-hint-card p { font-size:12px; }
body.mobile-ui .clip-box-resize { width:28px; height:28px; right:-13px; bottom:-13px; }
body.mobile-ui .mobile-controls-dialog[open] { display:block; }
.mobile-controls-dialog { position:fixed; inset:auto 0 0; margin:0; width:100%; max-width:none; max-height:78dvh; padding:0 16px calc(20px + env(safe-area-inset-bottom)); color:var(--text); background:var(--surface); border:1px solid var(--border-strong); border-bottom:0; border-radius:18px 18px 0 0; overflow-y:auto; overscroll-behavior:contain; box-shadow:0 -8px 50px rgba(0,0,0,.4); }
.mobile-controls-dialog::backdrop { background:rgba(0,0,0,.44); }
.mobile-sheet-heading { position:sticky; top:0; z-index:20; display:flex; align-items:center; justify-content:space-between; min-height:60px; gap:12px; background:var(--surface); border-bottom:1px solid var(--border); margin-bottom:15px; }
.mobile-sheet-heading h2 { font-size:17px; margin:0; }
.mobile-sheet-heading button { min-width:62px; min-height:44px; }
.mobile-controls-dialog [hidden] { display:none !important; }
.mobile-controls-dialog .cbct-panel { width:100%; padding:0; border:0; overflow:visible; }
.mobile-controls-dialog .cbct-panel > h3 { display:none; }
.mobile-controls-dialog .datasource-bar { display:block; padding:0; border:0; }
.mobile-controls-dialog .ds-group { display:flex; flex-wrap:wrap; align-items:center; gap:10px; }
.mobile-controls-dialog .ds-group:first-child .ds-label { width:100%; }
.mobile-controls-dialog .ds-select { min-width:0; width:100%; max-width:100%; min-height:44px; font-size:16px; }
.mobile-controls-dialog .ds-divider { width:100%; height:1px; margin:20px 0; }
.mobile-controls-dialog #uploadGroup > .ds-label { width:100%; }
.mobile-controls-dialog .ds-upload { display:flex; flex-direction:column; gap:10px; width:100%; }
.mobile-controls-dialog .upload-pick, .mobile-controls-dialog .upload-pick-sm { width:100%; min-height:44px; padding:8px; }
.mobile-controls-dialog .upload-pick input, .mobile-controls-dialog .upload-pick-sm input { max-width:100%; }
.mobile-controls-dialog .topbar-controls { display:flex; flex-wrap:wrap; flex-direction:column; gap:10px; align-items:stretch; width:100%; }
.mobile-controls-dialog .topbar-controls > * { width:100%; }
.mobile-controls-dialog .user-chip { white-space:normal; order:-1; font-size:13px; padding:6px 0; }
.mobile-controls-dialog #sharedAdminLink { width:100%; min-height:44px; justify-content:center; margin-top:10px; }
.mobile-controls-dialog .btn { min-height:44px; font-size:13px; text-align:center; }
.mobile-controls-dialog .fine-btn { min-width:42px; min-height:44px; padding:7px; font-size:13px; }
.mobile-controls-dialog .fine-controls { gap:5px; }
.mobile-controls-dialog .axis-label { width:62px; font-size:12px; }
.mobile-controls-dialog .axis-value { min-width:42px; font-size:17px; }
.mobile-controls-dialog .axis-row { gap:6px; }
.mobile-controls-dialog .window-btn { min-height:44px; }
.mobile-controls-dialog .threshold-row { min-height:38px; }
.mobile-controls-dialog .threshold-row input { min-width:0; }
.mobile-controls-dialog .struct-row { min-height:44px; }
.mobile-controls-dialog input[type="checkbox"] { min-width:20px; min-height:20px; accent-color:var(--accent); }
.mobile-controls-dialog input[type="text"], .mobile-controls-dialog input[type="password"], .mobile-controls-dialog select { font-size:16px; }
.mobile-display-tools { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:20px; }
.mobile-display-tools .display-toggle { width:100%; display:flex; align-items:center; justify-content:space-between; gap:8px; font-size:12px; }
.mobile-display-tools .display-toggle select { width:70%; min-width:0; min-height:44px; background:var(--surface-2); border:1px solid var(--border-strong); color:var(--text); border-radius:6px; }
.mobile-display-tools .zoom-group .btn { min-width:44px; }
.mobile-gesture-hint { font-size:12px; line-height:1.5; color:var(--text-muted); margin:0 0 14px; }
.mobile-adjust-tabs { display:flex; gap:5px; margin-bottom:12px; }
.mobile-adjust-tabs button { flex:1; min-height:42px; border:1px solid var(--border-strong); border-radius:6px; background:var(--surface-2); color:var(--text); font:600 12px var(--font); }
.mobile-adjust-tabs button[aria-pressed="true"] { background:var(--accent); color:white; border-color:var(--accent); }
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="shift"] .mobile-adjust-rotate,
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="shift"] .mobile-adjust-exercise,
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="rotate"] .mobile-adjust-shift,
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="rotate"] .mobile-adjust-exercise,
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="exercise"] .mobile-adjust-shift,
body.mobile-ui .mobile-controls-dialog[data-adjust-tab="exercise"] .mobile-adjust-rotate { display:none !important; }
@media (max-width:699px) and (min-height:501px) {
  body.mobile-ui .mobile-controls-dialog[data-sheet="adjust"] { max-height:49dvh; }
  body.mobile-ui .mobile-controls-dialog[data-sheet="adjust"]::backdrop { background:rgba(0,0,0,.12); }
  body.mobile-ui .mobile-controls-dialog[data-sheet="adjust"] .mobile-sheet-heading { min-height:54px; margin-bottom:10px; }
  body.mobile-ui .mobile-controls-dialog[data-sheet="adjust"] .control-block { margin-bottom:0; padding-bottom:0; border:0; }
}
body.mobile-ui .login-gate { padding:16px; overflow:auto; }
body.mobile-ui .login-gate .login-card { width:370px; max-width:100%; max-height:100%; overflow:auto; }
body.mobile-ui .login-gate .gate-field input, body.mobile-ui .login-gate .gate-field select { font-size:16px; min-height:44px; }
body.mobile-ui .login-gate .btn { min-height:44px; }
body.mobile-ui.mobile-focus .cbct-topbar, body.mobile-ui.mobile-focus .mobile-fusion-bar, body.mobile-ui.mobile-focus .status-banner { display:none; }
@media (min-width:700px) {
  body.mobile-ui .mobile-controls-dialog { inset:0 0 0 auto; width:390px; max-width:55vw; max-height:100dvh; height:100dvh; border-radius:14px 0 0 14px; padding-top:env(safe-area-inset-top); }
  body.mobile-ui .mobile-plane-bar { justify-content:flex-start; gap:24px; }
  body.mobile-ui .mobile-fusion-bar .opacity-control { max-width:540px; }
  body.mobile-ui .slice-slider-label { max-width:500px; }
}
@media (max-height:500px) and (orientation:landscape) {
  body.mobile-ui { padding-right:calc(62px + env(safe-area-inset-right)); }
  body.mobile-ui .cbct-topbar { display:none; }
  body.mobile-ui .mobile-dock { position:fixed; top:0; right:0; bottom:0; width:calc(62px + env(safe-area-inset-right)); padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0; flex-direction:column; border-top:0; border-left:1px solid var(--border); }
  body.mobile-ui .mobile-dock button { min-height:44px; flex:1; font-size:10px; }
  body.mobile-ui .mobile-dock button > span { font-size:21px; }
  body.mobile-ui .mobile-plane-bar { min-height:40px; }
  body.mobile-ui .view-btn { min-height:38px; }
  body.mobile-ui .interaction-bar { min-height:38px; }
  body.mobile-ui .slice-slider-label { height:34px; }
  body.mobile-ui .mobile-fusion-bar { min-height:30px; }
  body.mobile-ui .opacity-control input { height:27px; }
  body.mobile-ui .status-banner { max-height:25px; padding-top:3px; padding-bottom:3px; }
  body.mobile-ui .mobile-controls-dialog { inset:0 0 0 auto; width:390px; max-width:75vw; max-height:100dvh; height:100dvh; border-radius:12px 0 0 12px; }
}
@media (max-width:359px) {
  body.mobile-ui .view-btn { min-width:35px; padding:6px 5px; }
  body.mobile-ui .interaction-modes .btn { padding:4px 5px; }
  body.mobile-ui .interaction-modes .btn span { font-size:10px; }
  .mobile-controls-dialog { padding-left:10px; padding-right:10px; }
  .mobile-controls-dialog .fine-btn { min-width:38px; padding:5px; }
  .mobile-controls-dialog .fine-controls { gap:3px; }
  .mobile-controls-dialog .axis-label { width:49px; font-size:11px; }
}
@media (prefers-reduced-motion:reduce) {
  *, *::before, *::after { animation:none !important; transition:none !important; }
}
.cbct-topbar, .datasource-bar, .status-banner { flex: 0 0 auto; }

/* ---- Top bar ---- */
.cbct-topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  min-height: var(--header-h);
  padding: 8px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.cbct-topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb),0.6);
}
.brand-rt {
  display: inline-block;
  margin-left: 2px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  background: var(--grad);
  border-radius: 5px;
}
.brand-mode {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.spacer { flex: 1; }

.topbar-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 18px;
}
.topbar-controls label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
}
.topbar-controls select,
.topbar-controls input[type="range"] {
  accent-color: var(--accent);
}
.topbar-controls select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 12px;
}
.opacity-control input[type="range"] { width: 90px; }
.readout {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 34px;
}

/* View-switch button group (4-up / maximise) */
.view-switch {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.view-btn {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.view-btn:last-child { border-right: none; }
.view-btn:hover { color: var(--text); background: var(--border); }
.view-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ---- Buttons ---- */
.btn {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.12s, transform 0.12s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.25);
}
.zoom-group { display: inline-flex; gap: 4px; align-items: center; }
.zoom-group .btn { min-width: 30px; font-size: 16px; font-weight: 700; padding: 5px 10px; }
.zoom-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 2px;
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--border); }

/* ---- Status banner ---- */
.status-banner {
  padding: 8px 18px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.status-banner.error { color: #fca5a5; background: #2a1618; }

/* ---- Data source bar ---- */
.datasource-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.ds-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ds-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  color: var(--accent);
}
.ds-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  font-size: 12px;
  min-width: 200px;
}
.ds-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 4px;
}
.ds-upload {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ds-upload-nifti { opacity: 0.95; }
.upload-or {
  font-size: 11px;
  color: var(--text-faint);
}
.upload-pick, .upload-pick-sm {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 10px;
  color: var(--text-muted);
}
.upload-pick > span:first-child,
.upload-pick-sm > span:first-child {
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.upload-pick input[type="file"],
.upload-pick-sm input[type="file"] {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 170px;
}
.upload-status {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
}
.upload-nifti-note {
  width: 100%;
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--warning);
}
#loadUploadBtn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .ds-divider { display: none; }
  .datasource-bar { gap: 10px; }
}

/* ---- Workspace ---- */
.cbct-workspace {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  flex: 1 1 auto;
  min-height: 0;
}

/* Viewer + rotation rails. The viewer is ALWAYS dark; overlays inside it
   (hint, rotation rails, badges, pane controls) keep the dark palette in both
   themes by locally pinning the tokens they use. */
.viewer-wrap {
  position: relative;
  background: #000;
  overflow: hidden;
  --surface: #161f2b;
  --surface-2: #1e2937;
  --border: #263241;
  --border-strong: #3a4759;
  --text: #e8edf2;
  --text-muted: #9aa7b5;
  --text-faint: #6b7888;
}
#gl1 {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;   /* our pointer-drag owns touch; no page scroll/zoom hijack */
}
.viewer-wrap { touch-action: none; }

/* Mobile-only "hide/show controls" toggle at the top of the panel. */
.panel-toggle {
  display: none;
  position: sticky;
  top: 0;
  z-index: 4;
  width: 100%;
  padding: 11px;
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* Empty-state hint over the viewer (hidden once a dataset loads). */
.viewer-hint {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;   /* never blocks the canvas once it's interactive */
  background: radial-gradient(ellipse at center, rgba(var(--accent-rgb),0.06), transparent 60%);
}
.viewer-hint-card {
  max-width: 380px;
  padding: 26px 30px;
  background: rgba(15, 22, 32, 0.78);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.viewer-hint-icon {
  font-size: 40px;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 12px;
}
.viewer-hint-card h3 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}
.viewer-hint-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-muted);
}
.viewer-hint-card b { color: var(--text); font-weight: 600; }

/* Rotation rails flanking the viewer */
.rot-rail {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 12px 10px;
  background: rgba(15, 22, 32, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.rot-rail-left { left: 0; border-right: 1px solid var(--border); }

.rot-slider-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 0;
  flex: 1 1 0;
}
.rot-slider-group label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}
/* Vertical rotation sliders, Elekta-style */
.rot-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 8px;
  height: auto;
  min-height: 24px;
  flex: 1 1 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.rot-readout {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  min-width: 36px;
  text-align: center;
}
.rot-zero {
  margin-top: 4px;
  width: 22px;
  height: 18px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
}
.rot-zero:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Active-pane indicator badge */
.active-pane-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 5;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(15, 22, 32, 0.82);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.active-pane-badge b { color: var(--accent); }

/* Clip (comparison) canvas — layered exactly over the base canvas */
.clip-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;   /* the box handles interaction, not the canvas */
  z-index: 3;
}

/* Pane overlays layer — sits above canvases, holds maximise boxes/highlight */
.pane-overlays {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;   /* individual tiles re-enable pointer events */
}
.pane-tile {
  position: absolute;
  pointer-events: none;   /* pass right-drag through to the canvas */
  box-sizing: border-box;
  border: 2px solid transparent;
  transition: border-color 0.12s;
}
.pane-tile.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 12px rgba(var(--accent-rgb),0.25);
}
.pane-max-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  font-size: 15px;
  line-height: 1;
  color: #fff;
  background: rgba(15, 22, 32, 0.78);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
  pointer-events: auto;    /* the button is clickable even though tile isn't */
  opacity: 0.55;
  transition: opacity 0.12s, background 0.12s;
}
.pane-max-btn:hover { opacity: 1; background: var(--accent); border-color: var(--accent); }
.pane-active-chip {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #fff;
  background: var(--accent);
  border-radius: 4px;
  pointer-events: none;
}

/* Comparison clip box */
.clip-box {
  position: absolute;
  z-index: 7;
  border: 2px solid #ffd166;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.001);  /* keep pointer target tidy */
  cursor: move;
  background: transparent;
}
.clip-box-tag {
  position: absolute;
  top: -20px;
  left: -2px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  color: #1a1a1a;
  background: #ffd166;
  border-radius: 3px;
  white-space: nowrap;
}
.clip-box-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: #ffd166;
  border: 2px solid #1a1a1a;
  border-radius: 3px;
  cursor: nwse-resize;
}

/* ---- Control panel ---- */
.cbct-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
}
.cbct-panel h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}
.panel-hint {
  margin: 0 0 16px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.control-block {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.control-block h4 {
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent);
  font-weight: 700;
}

.axis-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.axis-label {
  font-size: 13px;
  color: var(--text-muted);
  width: 64px;
  flex-shrink: 0;
  font-weight: 600;
}
.fine-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.fine-btn {
  padding: 6px 9px;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
  min-width: 34px;
}
.fine-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.fine-btn:active { transform: translateY(1px); }
.axis-value {
  min-width: 48px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.control-block h4 { font-size: 12px; }

/* Live transform readout */
.readout-block pre {
  margin: 0;
  padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: #5eead4;
  background: #0c1119;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
}

/* Large 6-DOF transform display */
.xform-big {
  background: #0c1119;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.xform-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 4px 0;
}
.xform-line + .xform-line { border-top: 1px solid rgba(255,255,255,0.05); }
.xform-tag {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  width: 18px;
  flex-shrink: 0;
}
.xform-vals {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  color: #5eead4;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  flex: 1;
}
.xform-unit {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Imaging tools */
.tool-sublabel {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  font-weight: 700;
  margin: 14px 0 6px;
}
.tool-sublabel:first-child { margin-top: 0; }
.window-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}
.window-btn {
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}
.window-btn:hover { background: var(--border); }
.window-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.threshold-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.threshold-row label {
  font-size: 11px;
  color: var(--text-muted);
  width: 78px;
  flex-shrink: 0;
}
.threshold-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.thr-readout {
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  width: 44px;
  text-align: right;
}
.apply-to-row {
  margin: 4px 0 2px;
}
.apply-to-row label {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.hu-readout {
  background: #0c1119;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.hu-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-muted);
}
.hu-line b {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 15px;
  color: #5eead4;
  font-variant-numeric: tabular-nums;
}
.ruler-row { display: flex; }
.ruler-row .btn { flex: 1; }

/* RT Structures list */
.structures-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.struct-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.struct-row:hover { background: var(--surface-2); }
.struct-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.2);
}
.struct-name { flex: 1; }

/* Window/level groups — visually separate reference vs CBCT */
.wl-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}
.wl-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.wl-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
}

/* Structures master toggle */
.struct-master-row {
  margin-bottom: 8px;
}
.struct-master-row .btn {
  width: 100%;
}
/* Swatch colors approximating the NiiVue colormaps used for structures */
.struct-red     { background: #e63946; }
.struct-green   { background: #2a9d8f; }
.struct-blue    { background: #4361ee; }
.struct-cyan    { background: #4cc9f0; }
.struct-magenta { background: #d62898; }
.struct-yellow  { background: #ffd166; }
.struct-warm    { background: linear-gradient(135deg, #ff9e00, #ff0054); }
.struct-cool    { background: linear-gradient(135deg, #4cc9f0, #4361ee); }
.struct-hot     { background: linear-gradient(135deg, #ffd166, #e63946); }
.struct-winter  { background: linear-gradient(135deg, #0077b6, #00f5d4); }


.button-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.button-row .btn { flex: 1; }

/* Submit + score */
.btn-submit {
  width: 100%;
  margin-bottom: 14px;
  padding: 11px;
  font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
}

/* Randomise — the student's "start the exercise" action. Distinct blue so it
   reads as a separate step from Submit. */
.btn-randomise {
  width: 100%;
  margin-bottom: 10px;
  padding: 11px;
  font-size: 14px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

/* Expert / admin panel (only shown with ?admin=1). Amber framing marks it as a
   privileged control distinct from the student flow. */
.admin-panel {
  margin: 4px 0 16px;
  padding: 14px;
  background: rgba(180, 130, 20, 0.08);
  border: 1px solid #7a5a12;
  border-radius: var(--radius);
}
.admin-panel h4 {
  margin: 0 0 6px;
  font-size: 13px;
  color: #f0c25a;
  letter-spacing: 0.02em;
}
.admin-hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
}
.admin-answer {
  margin: 0 0 12px;
  padding: 8px 10px;
  background: rgba(13, 148, 136, 0.10);
  border: 1px solid rgba(13, 148, 136, 0.45);
  border-radius: var(--radius-sm);
}
.admin-answer-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.admin-answer-val {
  font-size: 12px;
  font-weight: 600;
  color: #5eead4;
  font-variant-numeric: tabular-nums;
}
.admin-pw-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.admin-pw {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.admin-pw:focus { outline: none; border-color: #f0c25a; }
.btn-save100 {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  background: linear-gradient(135deg, #d97706, #b45309);
}

/* Save-dataset panel (admin mode + upload right). Blue framing = a save-to-server
   action, distinct from the amber expert panel. */
.dataset-panel {
  margin: 4px 0 16px;
  padding: 14px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid #2d4a7a;
  border-radius: var(--radius);
}
.dataset-panel h4 {
  margin: 0 0 6px;
  font-size: 13px;
  color: #7fb0ff;
  letter-spacing: 0.02em;
}
.dataset-panel .structures-list { max-height: 168px; overflow-y: auto; margin: 4px 0 10px; }
.dataset-overwrite {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted); margin: 6px 0 12px; cursor: pointer;
}
.btn-savedataset {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}
.btn-savedataset:disabled { opacity: 0.55; cursor: wait; }

/* Delete preset (admin) */
.btn-delete { background: linear-gradient(135deg, #dc2626, #991b1b); }

/* Upload progress inside the dataset panel */
.save-progress {
  display: flex; align-items: center; gap: 10px;
  margin: 2px 0 12px;
}
.save-progress-track {
  flex: 1; height: 8px; border-radius: 999px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border-strong);
}
.save-progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  transition: width 0.15s linear;
}
.save-progress-text {
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #7fb0ff; min-width: 40px; text-align: right;
}

/* Toast notification */
.toast {
  position: fixed;
  top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 2000;
  max-width: min(92vw, 480px);
  padding: 12px 18px;
  font-size: 13.5px; font-weight: 600;
  color: #eafff2;
  background: rgba(15, 26, 20, 0.96);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  animation: toast-in 0.25s ease;
}
.toast.error { color: #ffe1e1; background: rgba(32, 14, 14, 0.96); border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Logged-in user chip in the top bar. */
.user-chip { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Login gate overlay (hard gate for the matcher). */
.login-gate {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 12, 18, 0.92); backdrop-filter: blur(3px);
}
.login-gate .login-card {
  width: 340px; max-width: 90vw; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-gate h2 { margin: 0 0 4px; font-size: 18px; }
.login-gate .gate-sub { margin: 0 0 14px; font-size: 12px; color: var(--text-muted); }
.login-gate .gate-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.login-gate .gate-field label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.login-gate .gate-field input, .login-gate .gate-field select {
  width: 100%; box-sizing: border-box; padding: 9px 10px; font-size: 13px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.login-gate .gate-err { color: #fca5a5; font-size: 12px; min-height: 16px; margin-bottom: 6px; }
.score-panel {
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: score-in 0.3s ease;
}
@keyframes score-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.score-tier {
  text-align: center;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  margin-bottom: 12px;
}
.score-tier.tier-perfect   { color: #ffd166; text-shadow: 0 0 16px rgba(255,209,102,0.5); }
.score-tier.tier-excellent { color: #06d6a0; }
.score-tier.tier-great     { color: #4cc9f0; }
.score-tier.tier-good      { color: #9aa7b5; }
.score-tier.tier-ok        { color: #6b7888; font-size: 15px; }
.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.score-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.score-cell-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 700;
}
.score-cell-err {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.score-cell-pts {
  font-size: 12px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.score-cell-pts b { font-size: 14px; }
.score-combined-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 700;
}
.score-combined {
  font-size: 24px;
  font-weight: 900;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.panel-note {
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--text-faint);
  padding: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
}

/* Precise mobile matching replaces the dock instead of covering the image. */
body.mobile-ui .mobile-adjust-bar { display:none; }
body.mobile-ui.mobile-adjusting .mobile-dock { display:none; }
body.mobile-ui.mobile-adjusting .mobile-adjust-bar { display:flex; }
.mobile-adjust-bar {
  order:11;
  flex:0 0 auto;
  flex-direction:column;
  gap:4px;
  padding:4px max(8px,env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left));
  border-top:1px solid var(--border-strong);
  background:var(--surface);
}
.mobile-direction-buttons { display:grid; grid-template-columns:repeat(6,minmax(44px,1fr)); gap:3px; }
.mobile-adjust-bar [hidden] { display:none !important; }
.mobile-adjust-bar button {
  min-width:44px;
  min-height:44px;
  padding:5px 4px;
  border:1px solid var(--border-strong);
  border-radius:6px;
  color:var(--text);
  background:var(--surface-2);
  font:600 12px var(--font);
  touch-action:manipulation;
}
.mobile-direction-buttons button:nth-child(2n) { margin-right:3px; }
.mobile-direction-buttons button:last-child { margin-right:0; }
.mobile-adjust-bar button:active:not(:disabled) { background:var(--accent); color:white; }
.mobile-adjust-options { display:flex; align-items:center; gap:4px; }
.mobile-adjust-options label { display:flex; align-items:center; gap:5px; flex:1; color:var(--text-muted); font-size:11px; white-space:nowrap; }
.mobile-adjust-options select {
  min-height:44px;
  width:83px;
  padding:5px 2px;
  border:1px solid var(--border-strong);
  border-radius:6px;
  background:var(--surface-2);
  color:var(--text);
  font-size:16px;
}
.mobile-adjust-bar #mobileAdjustBack { background:var(--accent); color:white; border-color:var(--accent); }
#mobileFullControlsBtn { width:100%; margin-bottom:12px; }
@media (min-width:640px) {
  body.mobile-ui .mobile-adjust-bar { flex-direction:row; align-items:center; gap:10px; }
  .mobile-direction-buttons { flex:1; }
  .mobile-adjust-options { flex:0 0 auto; }
  .mobile-adjust-options label { flex:none; }
}
@media (max-height:500px) and (orientation:landscape) {
  body.mobile-ui.mobile-adjusting { padding-right:0; }
}

/* Applied corrections stay visible without intercepting scan gestures. */
body.mobile-ui .mobile-match-hud[hidden], .mobile-match-hud [hidden] { display:none !important; }
.mobile-match-hud {
  position:absolute;
  bottom:6px;
  left:6px;
  right:6px;
  z-index:25;
  align-items:center;
  gap:8px;
  max-width:360px;
  padding:6px;
  border:1px solid rgba(145,164,182,.3);
  border-radius:8px;
  background:rgba(14,23,32,.88);
  color:#e8eef4;
  pointer-events:none;
}
.mobile-applied-correction { flex:1; min-width:0; font-size:10px; line-height:15px; }
.mobile-applied-correction > strong { display:block; color:#a7b7c6; font-size:10px; font-weight:600; }
.mobile-correction-values { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)) 17px; column-gap:3px; font-variant-numeric:tabular-nums; }
.mobile-correction-values > span { white-space:nowrap; }
.mobile-correction-values b { font-weight:600; }
.mobile-correction-values small { font-size:10px; text-align:right; color:#a7b7c6; }
#mobileRandomiseBtn {
  min-width:78px;
  min-height:44px;
  flex:0 0 auto;
  padding:6px;
  border:1px solid var(--accent);
  border-radius:6px;
  background:var(--accent);
  color:white;
  font:600 11px var(--font);
  pointer-events:auto;
  touch-action:manipulation;
}
.mobile-reference-context { flex:0 0 78px; color:#f0c25a; text-align:center; font-size:11px; line-height:15px; }


/* Desktop workspace controls reclaim space without changing image state. */
.workspace-controls { display:flex; align-items:center; gap:5px; margin-left:auto; flex:0 0 auto; }
.workspace-controls .btn { white-space:nowrap; }
body:not(.mobile-ui) .interaction-bar { gap:8px; flex-wrap:wrap; }
body:not(.mobile-ui) .interaction-hint { flex:1; min-width:160px; }
body:not(.mobile-ui).data-collapsed .datasource-bar,
body:not(.mobile-ui).desktop-focus .datasource-bar,
body:not(.mobile-ui).desktop-focus .cbct-topbar,
body:not(.mobile-ui).desktop-focus .status-banner { display:none; }
body:not(.mobile-ui) .cbct-workspace.panel-collapsed,
body:not(.mobile-ui).desktop-focus .cbct-workspace { grid-template-columns:minmax(0,1fr); }
body:not(.mobile-ui) .cbct-workspace.panel-collapsed > .cbct-panel,
body:not(.mobile-ui).desktop-focus .cbct-panel,
body:not(.mobile-ui).desktop-focus .rot-rail { display:none; }
body:not(.mobile-ui) .cbct-workspace { grid-template-columns:minmax(0,1fr) 350px; }
body:not(.mobile-ui) .datasource-bar { max-height:35dvh; overflow-y:auto; overscroll-behavior:contain; }
body.mobile-ui .workspace-controls { display:none; }
body.mobile-ui .mobile-plane-bar { gap:4px; }
body.mobile-ui .interaction-modes .btn { min-width:44px; min-height:44px; padding:5px; white-space:nowrap; }
body.mobile-ui .view-btn { min-width:38px; min-height:44px; }
body.mobile-ui .mobile-display-tools > .view-btn { border:1px solid var(--border-strong); }
body.mobile-ui #crosshairToggle { min-height:44px; }
@media (max-width:360px) {
    body.mobile-ui .mobile-plane-bar { padding-left:6px; padding-right:6px; }
    body.mobile-ui .interaction-modes .btn { min-width:44px; font-size:12px; }
}
@media (min-width:901px) and (max-width:1200px) {
    body:not(.mobile-ui) .interaction-hint { display:none; }
    body:not(.mobile-ui) .slice-slider-label { width:95px; }
    body:not(.mobile-ui) .slice-readout { min-width:75px; font-size:11px; }
}

.workspace-case-summary { display:block; max-width:clamp(80px,12vw,180px); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:11px; color:var(--accent-hover); }
.workspace-case-summary[hidden] { display:none; }
.workspace-case-summary.needs-review { color:#c78924; }

/* Let desktop controls wrap with the brand rather than as one oversized block. */
body:not(.mobile-ui) .cbct-topbar { gap:8px 10px; }
body:not(.mobile-ui) .cbct-topbar > .spacer { display:none; }
body:not(.mobile-ui) .topbar-controls { display:contents; }

/* Physical rotation hints are presentation-only and never intercept gestures. */
.rotation-guides { position:absolute; inset:0; z-index:24; pointer-events:none; overflow:hidden; }
.rotation-guides[hidden] { display:none; }
.rotation-guide {
  position:absolute; width:112px; height:40px; padding:4px 6px;
  color:#bbcad8; background:rgba(14,23,32,.66); border:1px solid rgba(145,164,182,.22);
  border-radius:6px; font-size:10px; line-height:14px; pointer-events:none;
  transition:color .14s,border-color .14s,background .14s;
}
.rotation-guide-heading { display:flex; align-items:center; justify-content:space-between; gap:4px; font-weight:600; }
.rotation-guide-value { color:#a3b3c2; font-variant-numeric:tabular-nums; font-weight:400; }
.rotation-guide-arrows { display:flex; justify-content:space-around; gap:6px; }
.rotation-guide-arrow { display:flex; align-items:center; gap:4px; min-width:36px; font-size:10px; }
.rotation-guide-arrow .rotation-curve { font-size:18px; line-height:14px; }
.rotation-guide.changing { color:#e8edf2; border-color:#14b8a6; background:rgba(14,37,42,.9); }
.rotation-guide-arrow.changing { color:#3de4d5; font-weight:800; }
body.mobile-ui .rotation-guide { width:104px; }
@media(prefers-reduced-motion:reduce){.rotation-guide{transition:none;}}
