:root {
  --canvas-bg: radial-gradient(circle at 50% 44%, #1d242d 0%, #11161c 72%, #0c1014 100%);
  --surface: rgba(25, 31, 39, 0.88);
  --surface-solid: #1a2129;
  --surface-hover: rgba(184, 155, 105, 0.14);
  --border: rgba(217, 200, 167, 0.16);
  --border-strong: rgba(184, 155, 105, 0.45);
  --text: #f4f1ea;
  --text-muted: #98a2ad;
  --gold: #b89b69;
  --gold-bright: #d9c8a7;
  --gold-deep: #816838;
  --gold-glow: rgba(184, 155, 105, 0.28);
  --emerald: #14b8a6;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.48), 0 2px 8px rgba(0, 0, 0, 0.32);
  --rail-w: 58px;
}

[data-theme="light"] {
  --canvas-bg: radial-gradient(circle at 50% 44%, #fcfbf8 0%, #f1ede3 70%, #e6e0d4 100%);
  --surface: rgba(252, 251, 248, 0.92);
  --surface-solid: #fcfbf8;
  --surface-hover: rgba(184, 155, 105, 0.15);
  --border: rgba(30, 37, 43, 0.11);
  --border-strong: rgba(184, 155, 105, 0.65);
  --text: #1e252b;
  --text-muted: #61686e;
  --gold: #b89b69;
  --gold-bright: #816838;
  --gold-deep: #816838;
  --gold-glow: rgba(184, 155, 105, 0.22);
  --emerald: #0f766e;
  --shadow: 0 10px 28px rgba(30, 37, 43, 0.12), 0 2px 6px rgba(30, 37, 43, 0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--canvas-bg); color: var(--text);
  -webkit-font-smoothing: antialiased; user-select: none;
}

#viewport { position: fixed; inset: 0; z-index: 1; }
#viewport canvas { display: block; width: 100%; height: 100%; outline: none; }

.glass {
  background: var(--surface);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}

/* Split / Multi-view dividers */
#split-guides { position: fixed; inset: 0; z-index: 2; pointer-events: none; display: none; }
#split-guides.mode-occlus { display: block; }
#split-guides.mode-occlus::before {
  content: ''; position: absolute; left: calc(50% + var(--rail-w) * 0.5); top: 76px; bottom: 132px; width: 1px; background: var(--border-strong); opacity: .55;
}
#split-guides.mode-multi { display: block; }
#split-guides.mode-multi::before {
  content: ''; position: absolute; left: calc(50% + var(--rail-w) * 0.5); top: 0; bottom: 0; width: 1px; background: var(--border); opacity: .7;
}
#split-guides.mode-multi::after {
  content: ''; position: absolute; top: 50%; left: var(--rail-w); right: 0; height: 1px; background: var(--border); opacity: .7;
}
.split-lbl {
  position: fixed; z-index: 3; pointer-events: none; font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; display: none;
}

/* Left Vertical Tool Rail */
.tool-rail {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w); z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 14px 0; border-radius: 0; border-top: 0; border-bottom: 0; border-left: 0;
}
.rail-group { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.rail-mark {
  width: 34px; height: 34px; border-radius: 10px; object-fit: contain; margin-bottom: 6px;
  border: 1px solid var(--border); padding: 3px; background: rgba(184, 155, 105, 0.08);
}
.rail-btn {
  position: relative; width: 40px; height: 40px; border-radius: 11px; border: 1px solid transparent;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; transition: 160ms ease;
}
.rail-btn svg { width: 20px; height: 20px; }
.rail-btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border); }
.rail-btn.active { color: var(--gold-bright); background: rgba(184, 155, 105, 0.2); border-color: var(--border-strong); box-shadow: 0 0 14px var(--gold-glow); }
.rail-btn .badge-dot {
  position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); display: none;
}
.rail-btn.has-state .badge-dot { display: block; }
.rail-btn[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: 52px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; font-size: 11.5px; font-weight: 500; padding: 5px 10px; border-radius: 8px;
  background: var(--surface-solid); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); pointer-events: none;
}

/* Top-Center Floating Case Banner */
.top-banner {
  position: fixed; top: 14px; left: 50%; transform: translateX(calc(-50% + var(--rail-w) * 0.4));
  z-index: 18; height: 50px; padding: 0 14px 0 12px; border-radius: 14px;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 92px);
}
.brand-logo { height: 28px; width: auto; display: block; }
.logo-light { display: none; }
[data-theme="light"] .logo-dark { display: none; }
[data-theme="light"] .logo-light { display: block; }
.banner-sep { width: 1px; height: 26px; background: var(--border); flex-shrink: 0; }
.case-meta { display: flex; flex-direction: column; min-width: 0; }
.case-title {
  font-family: 'Playfair Display', Georgia, serif; font-size: 14.5px; font-weight: 600;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px;
}
.case-sub { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.banner-actions { display: flex; align-items: center; gap: 6px; margin-left: 4px; }
.chip-btn {
  height: 28px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); font-size: 11.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: 150ms ease;
}
.chip-btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-strong); }
.chip-btn.active { color: var(--gold-bright); border-color: var(--border-strong); background: rgba(184, 155, 105, 0.18); }

/* Top-Left Clinical Views Strip */
.view-strip {
  position: fixed; top: 76px; left: calc(var(--rail-w) + 14px); z-index: 15;
  padding: 6px; border-radius: 14px; display: flex; align-items: center; gap: 4px;
  max-width: calc(100vw - var(--rail-w) - 28px); overflow-x: auto; scrollbar-width: none;
}
.view-strip::-webkit-scrollbar { display: none; }
.view-tile {
  width: 50px; height: 50px; flex: 0 0 auto; border-radius: 10px; border: 1px solid transparent;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  transition: 150ms ease;
}
.view-tile svg { width: 22px; height: 18px; }
.view-tile span { font-size: 9px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.view-tile:hover { color: var(--text); background: var(--surface-hover); }
.view-tile.active {
  color: var(--gold-bright); background: rgba(184, 155, 105, 0.2);
  border-color: var(--border-strong); box-shadow: inset 0 0 0 1px rgba(184, 155, 105, 0.2);
}

/* Bottom Stage Timeline Dock */
.stage-dock {
  position: fixed; bottom: 16px; left: calc(50% + var(--rail-w) * 0.5); transform: translateX(-50%);
  z-index: 18; width: min(740px, calc(100vw - var(--rail-w) - 28px));
  padding: 10px 14px 11px; border-radius: 16px; display: flex; flex-direction: column; gap: 8px;
}
.dock-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.transport { display: flex; align-items: center; gap: 4px; }
.t-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--text-muted); cursor: pointer; display: grid; place-items: center; transition: 140ms ease;
}
.t-btn svg { width: 16px; height: 16px; }
.t-btn:hover { color: var(--text); background: var(--surface-hover); }
.t-btn.active { color: var(--gold-bright); background: rgba(184, 155, 105, 0.18); border-color: var(--border-strong); }
.t-btn.play-btn {
  width: 36px; height: 36px; border-radius: 50%; margin: 0 4px;
  background: linear-gradient(135deg, #c6ab7a, #9e814e); color: #fff;
  box-shadow: 0 4px 14px var(--gold-glow);
}
.t-btn.play-btn:hover { filter: brightness(1.08); transform: scale(1.04); }
.dock-right { display: flex; align-items: center; gap: 8px; }
.speed-pills { display: flex; background: rgba(128, 128, 128, 0.1); border-radius: 8px; padding: 2px; border: 1px solid var(--border); }
.spd-btn {
  border: 0; background: transparent; color: var(--text-muted); font-size: 11px; font-weight: 600;
  padding: 4px 8px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.spd-btn.active { background: var(--gold); color: #fff; }
.step-readout { font-size: 12px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }

/* Segmented Dual-Arch Step Strip */
.stage-track {
  display: flex; gap: 4px; overflow-x: auto; padding: 2px 2px 4px;
  scrollbar-width: thin; scrollbar-color: var(--gold-deep) transparent;
}
.stage-cell {
  flex: 1 0 36px; max-width: 72px; border: 1px solid transparent; background: transparent;
  border-radius: 8px; padding: 4px 4px 5px; cursor: pointer; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; transition: 130ms ease;
}
.stage-cell:hover { background: var(--surface-hover); color: var(--text); }
.stage-cell.active { background: rgba(184, 155, 105, 0.18); border-color: var(--border-strong); color: var(--gold-bright); }
.stage-num { font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.stage-bars { width: 100%; display: flex; flex-direction: column; gap: 2px; }
.arch-bar { height: 3px; border-radius: 2px; background: rgba(128, 128, 128, 0.22); width: 100%; }
.arch-bar.on-u { background: var(--gold); }
.arch-bar.on-l { background: var(--emerald); }
.stage-cell.active .arch-bar.on-u { box-shadow: 0 0 6px var(--gold-glow); }

/* Floating Tool Popovers & Side Drawer */
.tool-popover {
  position: fixed; left: calc(var(--rail-w) + 14px); top: 144px; z-index: 22;
  width: 248px; padding: 12px 14px; border-radius: 14px; display: none; flex-direction: column; gap: 10px;
}
.tool-popover.open { display: flex; }
.pop-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--gold-bright); display: flex; justify-content: space-between; align-items: center; }
.seg-row { display: flex; gap: 4px; }
.seg-row button {
  flex: 1; height: 28px; border-radius: 7px; border: 1px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.seg-row button.active { background: var(--gold); border-color: var(--gold); color: #fff; }
input[type="range"].vc-range { width: 100%; accent-color: var(--gold); cursor: pointer; }

.caliper-pill {
  position: fixed; top: 76px; right: 16px; z-index: 18; padding: 8px 12px; border-radius: 12px;
  display: none; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.caliper-pill.open { display: flex; }
.caliper-val { color: var(--gold-bright); font-size: 14px; }

.inspector {
  position: fixed; top: 76px; right: 16px; bottom: 132px; width: 272px; z-index: 19;
  border-radius: 14px; padding: 12px; display: none; flex-direction: column; gap: 10px;
}
.inspector.open { display: flex; }
.insp-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 2px; }
.insp-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 8px; border-radius: 8px; font-size: 12px; color: var(--text); background: rgba(128, 128, 128, 0.06);
}
.insp-row label { display: flex; align-items: center; gap: 7px; cursor: pointer; flex: 1; min-width: 0; }
.insp-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-row input { accent-color: var(--gold); }

/* Modals & Loading Overlay */
.overlay-backdrop {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(10, 14, 18, 0.72); backdrop-filter: blur(8px); padding: 20px;
}
.overlay-backdrop.hidden { display: none; }
.modal-card {
  width: min(420px, 100%); padding: 26px 24px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
}
.modal-card h2 { font-family: 'Playfair Display', Georgia, serif; font-size: 20px; font-weight: 600; }
.modal-card p { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.prog-track { width: 100%; height: 6px; border-radius: 99px; background: rgba(128, 128, 128, 0.22); overflow: hidden; }
.prog-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); transition: width 120ms linear; }
.drop-zone {
  width: 100%; border: 1.5px dashed var(--border-strong); border-radius: 14px; padding: 24px 16px;
  background: rgba(184, 155, 105, 0.06); cursor: pointer; font-size: 13px; color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.drag { background: rgba(184, 155, 105, 0.16); color: var(--text); }
.pwd-input {
  width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(128, 128, 128, 0.08); color: var(--text); padding: 0 12px; font-size: 14px; outline: none;
}
.pwd-input:focus { border-color: var(--gold); }
.btn-gold {
  width: 100%; height: 40px; border-radius: 10px; border: 0; font-weight: 600; font-size: 13.5px;
  background: linear-gradient(135deg, #c6ab7a, #9a7c4d); color: #fff; cursor: pointer;
}
.err-text { color: #f87171; font-size: 12px; min-height: 16px; }

@media (max-width: 768px) {
  :root { --rail-w: 48px; }
  .top-banner { top: 8px; height: 44px; padding: 0 10px; gap: 8px; }
  .brand-logo { height: 22px; }
  .case-title { max-width: 125px; font-size: 13px; }
  .view-strip { top: 60px; left: calc(var(--rail-w) + 8px); }
  .view-tile { width: 44px; height: 44px; }
  .stage-dock { bottom: 8px; padding: 8px 10px; }
}
