:root {
  --bg-glass: rgba(20, 24, 30, 0.80);
  --bg-glass-strong: rgba(16, 19, 24, 0.90);
  --bg-card: rgba(255, 255, 255, 0.055);
  --border-subtle: rgba(255, 255, 255, 0.13);
  --text-primary: #f5f2eb;
  --text-secondary: #b9b3a7;
  --accent-gold: #dfad67;
  --accent-gold-strong: #ecc07e;
  --accent-sage: #5d7463;
  --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.36);
  --radius-lg: 14px;
  --radius-md: 9px;
  --preset-top: 70px;
  --drawer-top: 106px;
}

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

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

#viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.label-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

/* 3D Dollhouse Floating Room Tags */
.room-tag-3d {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(236, 192, 126, 0.55);
  background: rgba(18, 22, 28, 0.84);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.room-tag-3d:hover {
  transform: translateY(-2px) scale(1.04);
  background: rgba(34, 41, 51, 0.95);
  border-color: var(--accent-gold-strong);
}

.room-tag-3d .tag-title {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.room-tag-3d .tag-dim {
  font-size: 9px;
  color: var(--accent-gold);
  white-space: nowrap;
}

/* 3D Architectural Measurement Overlay Inline CAD Callouts */
.dim-tag {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 14, 20, 0.92);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  cursor: default;
  transition: transform 0.14s ease, background 0.14s ease;
}

.dim-tag:hover {
  transform: scale(1.1);
  background: rgba(14, 19, 28, 0.98);
  z-index: 12;
}

.dim-tag .dim-val {
  font-size: 9.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.3;
}

.dim-tag .dim-lbl {
  font-size: 8.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  line-height: 1.2;
}

.dim-cat-walls {
  border-color: rgba(245, 158, 11, 0.78);
}
.dim-cat-walls .dim-val {
  color: #fbbf24;
}

.dim-cat-doors {
  border-color: rgba(16, 185, 129, 0.78);
}
.dim-cat-doors .dim-val {
  color: #34d399;
}

.dim-cat-windows {
  border-color: rgba(14, 165, 233, 0.78);
}
.dim-cat-windows .dim-val {
  color: #38bdf8;
}

.dim-cat-skylights {
  border-color: rgba(168, 85, 247, 0.78);
}
.dim-cat-skylights .dim-val {
  color: #c084fc;
}

/* Top Header Bar */
.top-bar {
  position: fixed;
  top: 12px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2d4c3b, #1d3126);
  border: 1px solid rgba(223, 173, 103, 0.55);
  color: var(--accent-gold-strong);
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  letter-spacing: 0.03em;
}

.brand-copy h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-copy p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented-group {
  display: inline-flex;
  padding: 3px;
  background: rgba(0, 0, 0, 0.34);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 550;
  padding: 6px 11px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.16s ease;
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.active {
  background: var(--accent-gold);
  color: #17181b;
  font-weight: 650;
  box-shadow: 0 2px 8px rgba(223, 173, 103, 0.3);
}

/* Guided Camera Presets Bar */
.preset-bar {
  position: fixed;
  top: var(--preset-top, 70px);
  left: 14px;
  right: 14px;
  z-index: 18;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.preset-bar::-webkit-scrollbar {
  display: none;
}

.preset-chip {
  flex: 0 0 auto;
  border: 1px solid var(--border-subtle);
  background: rgba(20, 24, 30, 0.74);
  backdrop-filter: blur(10px);
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-chip:hover {
  border-color: var(--accent-gold);
  background: rgba(35, 42, 52, 0.9);
  color: var(--accent-gold-strong);
}

/* Side Drawers */
.side-drawer {
  position: fixed;
  top: var(--drawer-top, 106px);
  bottom: 50px;
  width: 280px;
  z-index: 16;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
}

.left-drawer {
  left: 14px;
}

.left-drawer.collapsed {
  transform: translateX(calc(-100% - 4px));
}

.right-drawer {
  right: 14px;
  bottom: 204px;
  width: 300px;
}

.right-drawer.collapsed {
  transform: translateX(calc(100% + 4px));
}

.drawer-toggle {
  position: absolute;
  top: 14px;
  width: 24px;
  height: 40px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-glass-strong);
  color: var(--text-primary);
  border-radius: 7px;
  cursor: pointer;
  font-size: 16px;
  display: grid;
  place-items: center;
}

.left-drawer .drawer-toggle {
  right: -27px;
}

.right-drawer .drawer-toggle {
  left: -27px;
}

.drawer-scroll {
  overflow-y: auto;
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-gold);
}

.section-header small {
  font-size: 10px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-secondary);
}

.sun-readout {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

.quick-btn-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.mini-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 11px;
  padding: 5px 7px;
  border-radius: 6px;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold-strong);
}

.sub-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}

.sub-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.mini-seg {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 7px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.mini-seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
}

.mini-seg-btn.active {
  background: rgba(223, 173, 103, 0.9);
  color: #15171b;
  font-weight: 600;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 3px 0;
}

.toggle-row input[type='checkbox'] {
  accent-color: var(--accent-gold);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

kbd {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-secondary);
}

/* Measurement Overlay Filter Sub-Panel */
.measure-panel {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 9px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.measure-chips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
}

.measure-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.14s ease;
}

.measure-chip:hover {
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--text-primary);
}

.measure-chip.active {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.26);
  color: var(--text-primary);
}

.measure-chip .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.4;
}

.measure-chip.active .dot {
  opacity: 1;
}

.dot-walls { background: #f59e0b; }
.dot-doors { background: #10b981; }
.dot-windows { background: #0ea5e9; }
.dot-skylights { background: #a855f7; }

.measure-unit-row {
  margin-top: 0;
}

.action-btn {
  width: 100%;
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn.primary {
  border: none;
  background: linear-gradient(135deg, #e5b772, #cf984a);
  color: #15171a;
}

.action-btn.primary:hover {
  filter: brightness(1.06);
}

.action-btn.secondary {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--bg-card);
  color: var(--text-primary);
}

.action-btn.secondary:hover {
  border-color: var(--accent-gold);
}

/* Room Directory */
.room-directory {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dir-group-title {
  font-size: 10.5px;
  font-weight: 650;
  color: var(--text-secondary);
  margin-top: 6px;
  padding-bottom: 2px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}

.dir-room-row {
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.dir-room-btn {
  flex: 1;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.dir-room-btn span {
  font-size: 11.5px;
  font-weight: 550;
}

.dir-room-btn small {
  font-size: 10px;
  color: var(--text-secondary);
}

.dir-room-row.active .dir-room-btn,
.dir-room-btn:hover {
  border-color: rgba(223, 173, 103, 0.55);
  background: rgba(223, 173, 103, 0.14);
}

.dir-orbit-btn {
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  padding: 0 7px;
  border-radius: 7px;
  cursor: pointer;
}

.dir-orbit-btn:hover {
  color: var(--accent-gold-strong);
  border-color: var(--accent-gold);
}

/* Right Architectural Spec Inspector */
.spec-eyebrow {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent-gold);
}

.spec-title {
  margin: -6px 0 0;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.24;
}

.spec-dim {
  margin-top: -6px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.spec-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.spec-card {
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
}

.spec-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-gold);
  margin-bottom: 3px;
}

.spec-card p {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.38;
  color: var(--text-primary);
}

.spec-notes-wrap {
  padding-top: 2px;
}

.spec-notes {
  margin: 5px 0 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.spec-notes li {
  font-size: 11px;
  line-height: 1.38;
  color: var(--text-secondary);
}

/* Bottom-Right Minimap */
.minimap-card {
  position: fixed;
  right: 14px;
  bottom: 12px;
  width: 300px;
  z-index: 17;
  padding: 7px;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.minimap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  padding: 0 3px;
}

.minimap-header span {
  font-size: 10.5px;
  font-weight: 650;
  color: var(--text-secondary);
}

.minimap-tabs {
  display: flex;
  gap: 3px;
}

.map-tab {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.map-tab.active {
  background: var(--accent-gold);
  color: #16181c;
  border-color: var(--accent-gold);
}

#minimap-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: crosshair;
}

/* House Fly-Through Playback HUD */
.hidden {
  display: none !important;
}

.flythrough-hud {
  position: fixed;
  left: 308px;
  right: 326px;
  bottom: 52px;
  max-width: 680px;
  margin: 0 auto;
  z-index: 22;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 9px 13px 10px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(223, 173, 103, 0.38);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.ft-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.ft-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ft-transport,
.ft-right-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ft-stage {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.ft-time {
  flex: 0 0 auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
}

.ft-btn {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ft-btn:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold-strong);
}

.ft-btn.primary {
  border: none;
  background: linear-gradient(135deg, #e5b772, #cf984a);
  color: #15171a;
  min-width: 86px;
}

.ft-btn.primary:hover {
  filter: brightness(1.07);
  color: #15171a;
}

.ft-btn.highlight {
  border-color: var(--accent-gold);
  background: rgba(223, 173, 103, 0.22);
  color: var(--accent-gold-strong);
}

.ft-scrubber {
  width: 100%;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-gold);
  cursor: pointer;
  touch-action: pan-x;
}

/* Walk D-Pad & Bottom Status Bar */
.walk-dpad {
  position: fixed;
  left: 308px;
  bottom: 48px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  opacity: 0.78;
  transition: opacity 0.15s ease;
}

.walk-dpad:hover {
  opacity: 1;
}

.dpad-mid {
  display: flex;
  gap: 3px;
}

.dpad-btn {
  width: 30px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-glass);
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
}

.dpad-btn:active {
  background: var(--accent-gold);
  color: #15171a;
}

.bottom-hud {
  position: fixed;
  left: 14px;
  right: 326px;
  bottom: 12px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: rgba(16, 19, 24, 0.76);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
}

.hud-badge {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(223, 173, 103, 0.22);
  border: 1px solid rgba(223, 173, 103, 0.45);
  color: var(--accent-gold-strong);
  font-size: 11px;
  font-weight: 650;
}

.hud-hint {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast-banner {
  position: fixed;
  top: 112px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  z-index: 30;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(20, 25, 32, 0.92);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold-strong);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-banner.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== REFERENCE SCALE BAR HUD (3D Views) ==================== */
.scalebar-hud {
  position: fixed;
  right: 326px;
  bottom: 52px;
  z-index: 19;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 11px 6px;
  background: rgba(16, 19, 24, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(236, 192, 126, 0.42);
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
  pointer-events: none;
}

body.mode-flythrough .scalebar-hud {
  bottom: auto;
  top: var(--drawer-top, 106px);
}

.scalebar-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.scalebar-title {
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.08em;
  color: var(--accent-gold-strong);
}

.scalebar-depth {
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.scalebar-graphic {
  display: flex;
  width: 140px;
  height: 7px;
  border: 1px solid rgba(245, 242, 235, 0.85);
  border-radius: 2px;
  overflow: hidden;
}

.scalebar-graphic .sb-seg {
  flex: 1 1 25%;
  height: 100%;
}

.scalebar-graphic .sb-dark {
  background: var(--accent-gold-strong);
}

.scalebar-graphic .sb-light {
  background: #14181f;
}

.scalebar-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  line-height: 1.1;
}

/* ==================== KITCHEN & M&E 2D CAD WORKSPACES ==================== */
body.mode-cad .cutaway-group,
body.mode-cad .preset-bar,
body.mode-cad .side-drawer,
body.mode-cad .minimap-card,
body.mode-cad .walk-dpad,
body.mode-cad .bottom-hud,
body.mode-cad .scalebar-hud,
body.mode-cad .flythrough-hud,
body.mode-cad .label-layer,
body.mode-mep .cutaway-group,
body.mode-mep .preset-bar,
body.mode-mep .side-drawer,
body.mode-mep .minimap-card,
body.mode-mep .walk-dpad,
body.mode-mep .bottom-hud,
body.mode-mep .scalebar-hud,
body.mode-mep .flythrough-hud,
body.mode-mep .label-layer {
  display: none !important;
}

.cad-workspace {
  position: fixed;
  top: var(--preset-top, 70px);
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 18;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cad-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.cad-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.cad-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.cad-btn:hover {
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.cad-btn.active {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: #15171a;
  font-weight: 700;
}

.cad-btn.primary {
  border: none;
  background: linear-gradient(135deg, #e5b772, #cf984a);
  color: #15171a;
  font-weight: 700;
}

.cad-btn.primary:hover {
  filter: brightness(1.07);
}

.cad-chip {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 550;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.cad-chip.active {
  background: rgba(223, 173, 103, 0.22);
  border-color: rgba(223, 173, 103, 0.6);
  color: var(--accent-gold-strong);
}

.cad-canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-soft);
  background: #f8f7f3;
}

#cad-canvas,
#mep-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#cad-canvas:active,
#mep-canvas:active {
  cursor: grabbing;
}

@media (max-width: 1180px) {
  .brand-copy p {
    display: none;
  }
  .top-bar {
    padding: 7px 12px;
  }
  .seg-btn {
    padding: 5px 9px;
    font-size: 11.5px;
  }
}

@media (max-width: 1024px) {
  .right-drawer {
    display: none;
  }
  .bottom-hud {
    right: 256px;
  }
  .scalebar-hud {
    right: 256px;
  }
  .minimap-card {
    bottom: 12px;
    width: 232px;
  }
  .walk-dpad {
    left: 274px;
    bottom: 50px;
  }
  .flythrough-hud {
    left: 274px;
    right: 256px;
    bottom: 52px;
  }
  .left-drawer {
    bottom: 50px;
    width: 248px;
  }
}

/* Mobile & Narrow Tablet Responsive Layout */
@media (max-width: 768px) {
  .hide-sm {
    display: none;
  }

  .top-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    padding: 8px 10px;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
  }

  .brand-block {
    gap: 8px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    font-size: 12px;
    border-radius: 7px;
  }

  .brand-copy h1 {
    font-size: 14px;
    white-space: nowrap;
  }

  .top-controls {
    width: 100%;
    gap: 6px;
  }

  .segmented-group {
    width: 100%;
    display: flex;
  }

  .seg-btn {
    flex: 1 1 0;
    text-align: center;
    white-space: nowrap;
    padding: 7px 6px;
    font-size: 12px;
    min-height: 36px;
  }

  /* In mobile fly-through, hide cutaway strip & preset chips for a clean, immersive 3D view */
  body.mode-flythrough .cutaway-group,
  body.mode-flythrough .preset-bar,
  body.mode-flythrough .minimap-card,
  body.mode-flythrough .bottom-hud {
    display: none;
  }

  .preset-bar {
    left: 8px;
    right: 8px;
  }

  .left-drawer {
    left: 8px;
    width: min(272px, calc(100vw - 56px));
    bottom: 54px;
    z-index: 24;
  }

  .left-drawer.collapsed {
    transform: translateX(calc(-100% - 10px));
  }

  .left-drawer .drawer-toggle {
    width: 34px;
    height: 48px;
    right: -38px;
    font-size: 18px;
    border-radius: 9px;
  }

  .minimap-card {
    right: 8px;
    bottom: 50px;
    width: 176px;
    padding: 5px;
  }

  .bottom-hud {
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 6px 10px;
  }

  .hud-hint {
    display: none;
  }

  .walk-dpad {
    left: 12px;
    bottom: 52px;
  }

  .scalebar-hud {
    right: auto;
    left: 8px;
    bottom: 50px;
  }

  .cad-workspace {
    left: 8px;
    right: 8px;
    bottom: 8px;
  }

  /* Full-width, thumb-friendly Mobile Fly-Through Playback HUD */
  .flythrough-hud {
    left: 8px;
    right: 8px;
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: none;
    padding: 12px 13px 11px;
    gap: 10px;
    z-index: 23;
  }

  .ft-stage {
    font-size: 13px;
  }

  .ft-time {
    font-size: 12px;
  }

  .ft-scrubber {
    height: 28px;
  }

  .ft-scrubber::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  .ft-controls-row {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .ft-transport,
  .ft-right-controls {
    gap: 6px;
  }

  .ft-btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 9px;
  }

  .ft-btn.primary {
    min-width: 96px;
    padding: 0 14px;
  }

  .ft-btn.ft-icon-btn {
    min-width: 40px;
    padding: 0;
    font-size: 16px;
  }

  .ft-speed-seg {
    padding: 3px;
    border-radius: 9px;
  }

  .ft-speed-seg .mini-seg-btn {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
    border-radius: 6px;
  }

  #btn-ft-recenter {
    min-width: 40px;
    padding: 0 10px;
    font-size: 16px;
  }
}
