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

:root {
  --bg-dark: #0a0a12;
  --panel-bg: rgba(12, 12, 22, 0.82);
  --panel-border: rgba(255,255,255,0.08);
  --text-primary: #c0c8d8;
  --text-heading: #e0e4ec;
  --text-muted: #606878;
  --text-dim: #404858;
  --accent: #40c8c0;
  --accent-gold: #e8b830;
  --bone-color: #e8e0d4;
  --tendon-color: #f5f0e0;
  --muscle-color: #c41e3a;
  --vein-color: #4455bb;
  --artery-color: #cc2233;
  --sensory-color: #e8b830;
  --motor-color: #f0e040;
}

body {
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#scene-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* Glass morphism base */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

/* HUD Panel - Top Left */
#hud-panel {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 100;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  max-width: 260px;
}

.hud-row {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #a0b0c8;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.hud-row:last-child { margin-bottom: 0; }
.hud-row span:not(.hud-icon) {
  color: var(--accent);
  font-weight: 500;
}
.hud-icon { font-size: 12px; }

/* Title Panel - Top Right */
#title-panel {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 100;
  text-align: right;
  padding: 10px 14px;
  background: rgba(12, 12, 22, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
}

.title-main {
  font-size: 16px;
  font-weight: 100;
  letter-spacing: 6px;
  color: #8090b0;
  font-variant: small-caps;
}
.title-sub {
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-top: 2px;
}
#info-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: #8090b0;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 5px;
  transition: all 0.2s;
  min-width: 32px;
  min-height: 32px;
}
#info-btn:hover { background: rgba(64,200,192,0.15); color: var(--accent); }

/* Layer Panel - Left */
#layer-panel {
  position: fixed;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  z-index: 100;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 8px;
  width: 54px;
  transition: width 0.3s ease;
  overflow: hidden;
}
#layer-panel:hover, #layer-panel.expanded {
  width: 200px;
}
.layer-title {
  font-size: 7px;
  letter-spacing: 3px;
  color: #505868;
  text-align: center;
  margin-bottom: 8px;
  white-space: nowrap;
}

.layer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  margin-bottom: 2px;
  border-left: 3px solid transparent;
  min-height: 36px;
}
.layer-btn.active {
  border-left-color: var(--accent);
  background: rgba(64,200,192,0.06);
}
.layer-btn:not(.active) { opacity: 0.45; }
.layer-btn:hover { background: rgba(255,255,255,0.04); }

.layer-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.layer-label {
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
}

.layer-slider {
  width: 55px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  outline: none;
  margin-left: auto;
  flex-shrink: 0;
  display: none;
}
#layer-panel:hover .layer-slider, #layer-panel.expanded .layer-slider { display: block; }
.layer-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

/* Inspector Panel - Right */
#inspector-panel {
  position: fixed;
  top: 70px;
  right: 0;
  width: 260px;
  max-height: calc(100vh - 150px);
  z-index: 100;
  background: rgba(17, 17, 24, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px 0 0 10px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
}
#inspector-panel.collapsed {
  transform: translateX(240px);
}
#inspector-toggle {
  position: absolute;
  left: 0; top: 50%;
  transform: translate(-100%, -50%);
  background: rgba(17,17,24,0.9);
  border: 1px solid rgba(255,255,255,0.08);
  border-right: none;
  color: var(--text-muted);
  padding: 14px 5px;
  border-radius: 6px 0 0 6px;
  cursor: pointer;
  font-size: 11px;
  z-index: 101;
  transition: color 0.2s;
  min-width: 20px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#inspector-toggle:hover { color: var(--accent); }
#inspector-content { padding: 12px; }

.inspector-section {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.inspector-section:last-child { border-bottom: none; }
.section-title {
  font-size: 8px;
  letter-spacing: 3px;
  color: #505868;
  margin-bottom: 8px;
}
#inspector-empty {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 6px 0;
}
.insp-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 5px;
  word-wrap: break-word;
}
.insp-badge {
  display: inline-block;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(64,200,192,0.15);
  color: var(--accent);
  margin-bottom: 8px;
}
.insp-field {
  font-size: 11px;
  margin-bottom: 4px;
  line-height: 1.4;
  word-wrap: break-word;
}
.insp-field label {
  color: var(--text-muted);
  font-size: 10px;
  display: block;
}
.gauge-bar {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  margin: 4px 0 2px;
}
.gauge-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #30e8a0);
  border-radius: 2px;
  width: 96%;
  transition: width 0.5s ease;
}

/* Sim controls */
.sim-control {
  margin-bottom: 8px;
}
.sim-control label {
  font-size: 11px;
  color: #808898;
  display: block;
  margin-bottom: 3px;
}
.sim-control input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  outline: none;
}
.sim-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 32px;
}
.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Pathology */
#pathology-select {
  width: 100%;
  background: rgba(20,20,30,0.9);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-primary);
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-family: 'IBM Plex Sans', sans-serif;
  cursor: pointer;
  min-height: 36px;
}
#pathology-select option { background: #111118; }
.pathology-card {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(232,184,48,0.08);
  border-left: 3px solid var(--accent-gold);
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.5;
  color: #c0b880;
}

/* Bottom Bar */
#bottom-bar {
  position: fixed;
  bottom: 22px; left: 0; right: 0;
  height: 44px;
  z-index: 100;
  background: rgba(13,13,21,0.85);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
}
#poly-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
#search-container {
  flex: 1;
  max-width: 320px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  font-size: 11px;
  z-index: 1;
  pointer-events: none;
}
#search-input {
  width: 100%;
  background: rgba(20,20,30,0.8);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-primary);
  padding: 7px 10px 7px 30px;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  outline: none;
  transition: border-color 0.2s;
  min-height: 34px;
}
#search-input:focus { border-color: rgba(64,200,192,0.4); }
#search-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0; right: 0;
  background: rgba(17,17,24,0.95);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 4px;
}
.search-item {
  padding: 8px 12px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 36px;
  display: flex;
  align-items: center;
}
.search-item:hover { background: rgba(64,200,192,0.1); color: var(--accent); }

#bottom-right-btns { display: flex; gap: 6px; flex-shrink: 0; }
#bottom-right-btns button {
  background: rgba(20,20,30,0.8);
  border: 1px solid rgba(255,255,255,0.08);
  color: #808898;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  transition: all 0.2s;
  min-height: 34px;
  min-width: 34px;
  white-space: nowrap;
}
#bottom-right-btns button:hover { border-color: var(--accent); color: var(--accent); }

/* Tooltip */
#tooltip {
  position: fixed;
  z-index: 200;
  background: rgba(10,10,18,0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(64,200,192,0.3);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--accent);
  pointer-events: none;
  display: none;
  white-space: nowrap;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Zoom / Empty Warnings */
#zoom-warning, #empty-warning {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(12,12,22,0.8);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  text-align: center;
  max-width: 90%;
}

/* Footer */
#footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 20px;
  z-index: 99;
  background: rgba(8,8,14,0.9);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  font-size: 8px;
  color: #303840;
}
#footer a {
  color: #404858;
  text-decoration: none;
  transition: color 0.2s;
}
#footer a:hover { color: var(--accent); }

/* Info Modal */
#info-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 500;
  background: rgba(5,5,10,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-content {
  background: rgba(17,17,24,0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 420px;
  width: 100%;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-content h2 {
  font-weight: 100;
  letter-spacing: 5px;
  color: #8090b0;
  font-variant: small-caps;
  margin-bottom: 12px;
  font-size: 20px;
}
.modal-content p {
  font-size: 12px;
  line-height: 1.7;
  color: #808898;
  margin-bottom: 8px;
}
.modal-content ul {
  font-size: 12px;
  color: #808898;
  margin: 4px 0 8px 18px;
  line-height: 1.8;
}
.modal-content .disclaimer {
  font-size: 10px;
  color: #505060;
  font-style: italic;
  margin-top: 12px;
}
#modal-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#modal-close:hover { color: var(--accent); }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* ===== RESPONSIVE ===== */

/* Tablet */
@media (max-width: 1024px) {
  #inspector-panel { width: 230px; }
  #inspector-panel.collapsed { transform: translateX(210px); }
  #hud-panel { max-width: 220px; }
}

/* Mobile */
@media (max-width: 768px) {
  #hud-panel {
    top: auto;
    bottom: 72px;
    left: 12px;
    right: auto;
    padding: 8px 10px;
    max-width: 180px;
    font-size: 10px;
  }
  .hud-row { font-size: 9px; margin-bottom: 3px; }

  #title-panel {
    top: 8px;
    right: 8px;
    padding: 6px 10px;
  }
  .title-main { font-size: 12px; letter-spacing: 3px; }
  .title-sub { font-size: 8px; }

  /* Layer panel - horizontal at bottom */
  #layer-panel {
    top: auto;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    width: auto !important;
    max-width: calc(100vw - 24px);
    display: flex;
    flex-direction: row;
    gap: 2px;
    padding: 6px 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  #layer-panel:hover, #layer-panel.expanded { width: auto !important; }
  .layer-title { display: none; }
  #layer-list {
    display: flex;
    flex-direction: row;
    gap: 2px;
  }
  .layer-btn {
    min-height: 40px;
    min-width: 40px;
    padding: 6px;
    justify-content: center;
  }
  .layer-label { display: none !important; }
  .layer-slider { display: none !important; }
  .layer-dot { width: 18px; height: 18px; }

  /* Inspector panel */
  #inspector-panel {
    width: 220px;
    top: 50px;
    max-height: calc(100vh - 140px);
    font-size: 10px;
  }
  #inspector-panel.collapsed { transform: translateX(200px); }
  .insp-name { font-size: 13px; }
  .section-title { font-size: 7px; }

  /* Bottom bar */
  #bottom-bar {
    bottom: 20px;
    height: 40px;
    padding: 0 8px;
    gap: 4px;
  }
  #poly-count { display: none; }
  #search-container { max-width: 180px; }
  #search-input { font-size: 11px; padding: 5px 8px 5px 26px; min-height: 30px; }
  #bottom-right-btns button { font-size: 10px; padding: 4px 8px; min-height: 30px; }
  #reset-view-btn span.full-text { display: none; }

  /* Footer */
  #footer { height: 18px; font-size: 7px; }
}

@media (max-width: 400px) {
  #hud-panel { display: none; }
  #inspector-panel { width: 190px; }
  #inspector-panel.collapsed { transform: translateX(170px); }
}