/* BodyVerse — dark premium theme, glassmorphism panels */
:root {
  --bg: #05070f;
  --panel: rgba(13, 18, 34, 0.92);
  --panel-border: rgba(130, 170, 255, 0.18);
  --col-bg: #080d1a;
  --text: #e8edf7;
  --muted: #9aa7c2;
  --accent: #ff5a76;
  --accent2: #4db8ff;
  --radius: 16px;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 800px at 70% 20%, #101a36 0%, var(--bg) 55%) fixed;
  color: var(--text);
  overflow: hidden;
}

/* ---------- three-column layout ----------
   LEFT data · CENTER stage · RIGHT switcher/options.
   The side columns are real layout (not overlays), so the canvas
   fills the centre column only and the figure sits dead-centre. */
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 340px;
  height: 100vh;
  height: 100dvh;
}
.col-left, .col-right {
  display: flex; flex-direction: column; gap: 16px;
  padding: 20px; min-height: 0; overflow: hidden;
  background: var(--col-bg);
}
.col-left { border-right: 1px solid var(--panel-border); }
.col-right { border-left: 1px solid var(--panel-border); }
.col-center { position: relative; min-width: 0; overflow: hidden; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- glass panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

/* ---------- header (left column) ---------- */
#site-header { flex: none; padding: 14px 20px 16px; }
.back-link { color: var(--accent2); text-decoration: none; font-size: 0.82rem; font-weight: 600; letter-spacing: 0.02em; }
.back-link:hover { text-decoration: underline; }
#site-header h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: 0.01em; margin-top: 4px; }
#site-header h1 .accent { background: linear-gradient(92deg, var(--accent), #ff9d5c); -webkit-background-clip: text; background-clip: text; color: transparent; }
#site-header .subtitle { color: var(--muted); font-size: 0.88rem; margin-top: 4px; line-height: 1.4; }

/* ---------- explorer (right column) ---------- */
#explorer { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.explorer-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--panel-border); flex: none; }
.explorer-head h2 { font-size: 1rem; margin-bottom: 10px; }
#search {
  width: 100%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font-size: 0.88rem; outline: none;
}
#search:focus { border-color: var(--accent2); }
#system-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--panel-border); background: rgba(255, 255, 255, 0.04); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 0.74rem; cursor: pointer; transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: linear-gradient(92deg, rgba(255,90,118,.25), rgba(77,184,255,.25)); color: var(--text); border-color: rgba(255,255,255,.35); }
#organ-list { overflow-y: auto; padding: 8px 10px 14px; scrollbar-width: thin; flex: 1; min-height: 0; }
#organ-list::-webkit-scrollbar { width: 6px; }
#organ-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }
.system-group { margin-top: 10px; }
.system-group h3 { font-size: 0.72rem; letter-spacing: 0.01em; color: var(--muted); padding: 4px 6px; }
.organ-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); padding: 6px; border-radius: 9px;
  font-size: 0.9rem; cursor: pointer; transition: background .15s;
}
.organ-item:hover { background: rgba(255, 255, 255, 0.07); }
.organ-item.selected { background: rgba(255, 90, 118, 0.16); }
.organ-item .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; box-shadow: 0 0 8px rgba(0,0,0,.4) inset; }
.organ-item .empty-note { color: var(--muted); font-size: 0.85rem; padding: 6px; }

/* ---------- info panel (left column, under header) ---------- */
#info-panel { flex: 1; min-height: 0; overflow-y: auto; position: relative; padding: 18px 20px; }
#info-panel::-webkit-scrollbar { width: 6px; }
#info-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 3px; }
#info-close { position: absolute; top: 8px; right: 12px; background: none; border: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
#info-close:hover { color: var(--text); }
.info-system { font-size: 0.72rem; letter-spacing: 0.01em; color: var(--accent2); font-weight: 700; }
#info-name { font-size: 1.45rem; margin: 4px 0 2px; }
#info-tagline { color: #ffc4cd; font-style: italic; font-size: 0.92rem; margin-bottom: 8px; }
#info-desc { color: #cfd8ea; font-size: 0.9rem; line-height: 1.55; }
#info-fact-wrap { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgba(77, 184, 255, 0.09); border: 1px solid rgba(77, 184, 255, 0.22); }
#info-fact-wrap[hidden] { display: none; }
#info-fact-wrap h3 { font-size: 0.75rem; letter-spacing: 0.01em; color: var(--accent2); margin-bottom: 4px; }
#info-fact { font-size: 0.87rem; line-height: 1.5; color: #dbe9f7; }

/* ---------- controls (right column, under the list) ---------- */
#controls { flex: none; padding: 14px 16px; }
.control-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.control-row:last-child { margin-bottom: 0; }
.control-row label { width: 58px; font-size: 0.82rem; color: var(--muted); flex: none; }
.control-row input[type="range"] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.control-row.buttons { flex-wrap: wrap; }
.control-row.buttons button {
  border: 1px solid var(--panel-border); background: rgba(255,255,255,.05); color: var(--muted);
  border-radius: 9px; padding: 6px 11px; font-size: 0.8rem; cursor: pointer; transition: all .15s;
}
.control-row.buttons button:hover { color: var(--text); }
.control-row.buttons button.toggle.active { color: #fff; background: linear-gradient(92deg, rgba(255,90,118,.35), rgba(77,184,255,.35)); border-color: rgba(255,255,255,.35); }
#reset-view { color: var(--text) !important; }

/* ---------- labels & tooltip ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.label {
  position: absolute; transform: translate(-50%, -140%); white-space: nowrap;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; color: #fff;
  background: rgba(8, 12, 24, 0.72); border: 1px solid rgba(255,255,255,.22);
  padding: 2px 8px; border-radius: 999px; transition: opacity .2s;
}
.label::after {
  content: ""; position: absolute; left: 50%; top: 100%; width: 5px; height: 5px;
  background: #fff; border-radius: 50%; transform: translate(-50%, 3px);
}
#tooltip {
  position: fixed; z-index: 20; pointer-events: none; display: none;
  background: rgba(8, 12, 24, 0.9); border: 1px solid var(--panel-border);
  color: var(--text); font-size: 0.82rem; font-weight: 600;
  padding: 5px 10px; border-radius: 8px; transform: translate(14px, 14px);
}

/* ---------- hint (stage bottom) / loader / error ---------- */
#hint {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  color: var(--muted); font-size: 0.82rem; z-index: 9; text-align: center;
  background: rgba(5, 7, 15, 0.92); padding: 6px 14px; border-radius: 999px;
  max-width: calc(100% - 24px);
}
#loader {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center; background: var(--bg); color: var(--muted);
  transition: opacity .5s;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-ring {
  width: 52px; height: 52px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.12); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#webgl-error {
  position: fixed; inset: 0; z-index: 60; background: var(--bg); color: var(--text);
  padding: 20vh 24px 0; text-align: center;
}
#webgl-error p { color: var(--muted); margin-top: 8px; }

/* ---------- tablet ---------- */
@media (max-width: 1023px) {
  .layout { grid-template-columns: 272px minmax(0, 1fr) 272px; }
  .col-left, .col-right { padding: 14px; gap: 12px; }
  #site-header { padding: 12px 16px 14px; }
  #site-header h1 { font-size: 1.6rem; }
  #info-panel { padding: 14px 16px; }
}

/* ---------- mobile: single scrolling column ----------
   header → stage block (56vh, unobstructed) → explorer → controls → info.
   The side columns dissolve (display:contents) so their cards join
   this single flow in the established order. */
@media (max-width: 640px) {
  html, body { height: auto; }
  body { overflow-y: auto; overflow-x: hidden; }
  .layout { display: flex; flex-direction: column; height: auto; min-height: 100vh; }
  .col-left, .col-right { display: contents; }
  #site-header {
    order: 1; margin: 12px 12px 0; padding: 10px 14px 12px;
  }
  #site-header h1 { font-size: 1.35rem; }
  #site-header .subtitle { display: none; }
  .col-center {
    order: 2; flex: none;
    width: 100%; height: 56vh; margin-top: 12px;
  }
  #explorer {
    order: 3; flex: none; margin: 12px 12px 0;
  }
  #organ-list { flex: none; max-height: 32vh; }
  #controls {
    order: 4; margin: 12px 12px 0;
  }
  .control-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .control-row label { width: auto; }
  .control-row input[type="range"] { width: 100%; }
  .control-row.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .control-row.buttons button { width: 100%; padding: 9px 11px; }
  #info-panel {
    order: 5; flex: none; margin: 12px; overflow: visible;
    padding: 14px 16px 18px;
  }
  #hint { display: none; }
}

/* ============================================================
   PREMIUM UI SYSTEM — visual + micro-interaction layer.
   Appended last so it refines (never restructures) the layout
   above. Accent identity: --acc = --accent (rose).
   ============================================================ */
:root { --acc: var(--accent); }

body { font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; }

/* ---------- fonts & type ---------- */
#site-header h1, #info-name, #webgl-error h2 {
  font-family: "Archivo", "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.01em;
}
#info-name { font-size: 26px; }
.info-system { font-size: 11px; font-weight: 600; letter-spacing: 0.01em; color: var(--acc); }

/* ---------- surfaces ---------- */
.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 18px 50px rgba(0, 0, 0, 0.45);
  border-radius: 18px;
}

/* ---------- controls ---------- */
#search {
  height: 38px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 13px;
}
#search:focus {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 22%, transparent);
}
.chip {
  min-height: 34px; padding: 6px 14px;
  display: inline-flex; align-items: center;
  font-size: 13px; font-weight: 500; color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  transition: all 0.18s ease-out;
}
.chip:hover { transform: translateY(-1px); border-color: var(--acc); color: var(--text); }
.chip.active {
  background: linear-gradient(135deg, var(--acc), color-mix(in srgb, var(--acc) 78%, #fff));
  color: #0b0e18; border-color: transparent; font-weight: 600;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--acc) 45%, transparent);
}
.control-row.buttons button {
  min-height: 34px; padding: 6px 14px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  transition: all 0.18s ease-out;
}
.control-row.buttons button:hover { transform: translateY(-1px); border-color: var(--acc); color: var(--text); }
.control-row.buttons button.toggle.active {
  background: linear-gradient(135deg, var(--acc), color-mix(in srgb, var(--acc) 78%, #fff));
  color: #0b0e18; border-color: transparent; font-weight: 600;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--acc) 45%, transparent);
}

/* range sliders */
.control-row input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 999px;
  background: transparent; cursor: pointer;
}
.control-row input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.14);
}
.control-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: #fff; border: 2px solid var(--acc);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); cursor: pointer;
}
.control-row input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.14);
}
.control-row input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--acc);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); cursor: pointer;
}

/* ---------- list ---------- */
.system-group h3 {
  font-size: 11px; font-weight: 600; letter-spacing: 0.14em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 6px; margin-bottom: 4px;
}
.organ-item {
  min-height: 40px; padding: 8px 12px; border-radius: 12px; font-size: 14px;
  transition: background 0.18s ease-out, transform 0.18s ease-out;
}
.organ-item:hover { background: rgba(255, 255, 255, 0.05); transform: translateX(2px); }
.organ-item.selected {
  background: color-mix(in srgb, var(--acc) 14%, transparent);
  box-shadow: inset 3px 0 0 var(--acc);
  font-weight: 600;
}

/* ---------- info panel anatomy ---------- */
#info-tagline { color: var(--muted); }
#info-desc { font-size: 14px; line-height: 1.65; }
#info-fact-wrap {
  background: color-mix(in srgb, var(--acc) 8%, transparent);
  border: none; border-left: 3px solid var(--acc);
  border-radius: 12px; padding: 12px 14px;
}
#info-fact-wrap h3 { color: var(--acc); font-size: 11px; letter-spacing: 0.14em; }
#info-fact { font-size: 14px; line-height: 1.6; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
#info-panel.panel-in { animation: panelIn 0.38s ease-out; }

/* ---------- overlays ---------- */
#loader::before {
  content: "THE UNUSUAL MUSEUM";
  font-size: 11px; font-weight: 600; letter-spacing: 0.3em; color: var(--muted);
}
#loader::after {
  content: ""; width: 160px; height: 3px; border-radius: 3px;
  background:
    linear-gradient(90deg, transparent, var(--acc), transparent) 0 0 / 50% 100% no-repeat,
    rgba(255, 255, 255, 0.10);
  animation: loadSlide 1.2s ease-in-out infinite;
}
@keyframes loadSlide {
  from { background-position: -50% 0, 0 0; }
  to { background-position: 200% 0, 0 0; }
}
#webgl-error h2 { font-size: 22px; }
#webgl-error p { font-size: 14px; line-height: 1.6; }

/* ---------- tooltip / labels / hint ---------- */
#tooltip {
  background: rgba(10, 13, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 12px; font-weight: 500;
  padding: 5px 12px; border-radius: 999px;
}
.label {
  font-size: 11px; font-weight: 600;
  background: rgba(10, 13, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 3px 9px;
}
#hint {
  font-size: 12px;
  background: rgba(10, 13, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ---------- stage depth ---------- */
#stage::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.38));
}

/* ---------- micro ---------- */
::selection { background: var(--acc); color: #0b0e18; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
#scene { cursor: grab; }
#scene:active { cursor: grabbing; }
#organ-list, #info-panel { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.16) transparent; }
#organ-list::-webkit-scrollbar, #info-panel::-webkit-scrollbar { width: 10px; }
#organ-list::-webkit-scrollbar-thumb, #info-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16); border-radius: 8px;
}
#organ-list::-webkit-scrollbar-thumb:hover, #info-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #info-panel.panel-in { animation: none; }
  #loader::after { animation: none; }
  .loader-ring { animation: none; }
  .chip, .organ-item, .control-row.buttons button { transition: none; }
}

/* BodyParts3D attribution line (left column, under the info panel) */
.attribution { flex: none; margin: 0; padding: 0 6px; font-size: 11px; line-height: 1.55; color: var(--muted); }

/* ---------- atelier solo mode (light studio while an organ is selected) ---------- */
body.solo {
  --text: #3a2a22;
  --muted: #8a7163;
  --panel: rgba(253, 250, 246, 0.94);
  --panel-border: rgba(93, 64, 48, 0.14);
  --col-bg: #f8efe7;
  --accent: #e83e63;
  --accent2: #c2255c;
  background: radial-gradient(1200px 800px at 50% 28%, #fffdf9 0%, #f7ece2 58%, #efddcd 100%) fixed;
}
body.solo .panel { box-shadow: 0 18px 44px rgba(120, 84, 60, 0.14); }
body.solo .label { background: rgba(255, 255, 255, 0.92); color: #4a3428; border-color: rgba(93, 64, 48, 0.16); }
body.solo #hint { background: rgba(255, 255, 255, 0.85); color: #8a7163; border-color: rgba(93, 64, 48, 0.12); }
body.solo #tooltip { background: rgba(255, 255, 255, 0.94); color: #3a2a22; border-color: rgba(93, 64, 48, 0.14); }
body.solo #search { background: rgba(58, 42, 34, 0.05); border-color: rgba(93, 64, 48, 0.18); }
