:root {
  --bg: #04100d;
  --margin: 20px;
  : rgba(10, 26, 24, 0.92);
  --panel-border: rgba(110, 230, 200, 0.18);
  --text: #eafff8;
  --muted: #9fd1c2;
  --accent-1: #3fd9b6;
  --accent-2: #a8d94e;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 75% 15%, rgba(20, 120, 90, 0.28), transparent 60%),
    radial-gradient(900px 650px at 15% 85%, rgba(14, 80, 90, 0.25), transparent 60%),
    var(--bg);
}

h1, h2 { font-family: "Archivo", Georgia, serif; letter-spacing: -0.01em; margin: 0; }

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

/* ---------- glass panels ---------- */
.panel { position: fixed; z-index: 10; }
.glass {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 50px rgba(0, 0, 0, 0.45);
  padding: 18px 20px;
}

/* ---------- header ---------- */
#site-header { top: var(--margin); left: var(--margin); width: 340px; max-width: calc(100vw - 40px); }
#site-header h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo-dot {
  width: 16px; height: 16px; flex: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #eafff4, var(--accent-1) 45%, #14523f);
  box-shadow: 0 0 14px rgba(63, 217, 182, 0.8);
}
.subtitle { color: var(--muted); font-size: 0.92rem; line-height: 1.45; margin: 8px 0 0; }
.byline { color: #6fae9c; font-size: 0.78rem; margin: 10px 0 0; letter-spacing: 0.04em; text-transform: uppercase; }

/* ---------- sidebar ---------- */
#sidebar {
  top: var(--margin); right: var(--margin);
  width: 330px;
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
}
.sidebar-head h2 { font-size: 1.05rem; margin-bottom: 10px; }

/* type filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center;
  min-height: 34px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.chip:hover { background: rgba(110, 230, 200, 0.14); color: var(--text); border-color: var(--accent-1); transform: translateY(-1px); }
.chip.active {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border-color: transparent; color: #061712; font-weight: 600;
  box-shadow: 0 4px 18px rgba(63, 217, 182, 0.45);
}

#microbe-list {
  list-style: none;
  margin: 12px -6px 4px 0;
  padding: 0 6px 0 0;
  overflow-y: auto;
  flex: 1;
}
#microbe-list::-webkit-scrollbar { width: 6px; }
#microbe-list::-webkit-scrollbar-thumb { background: rgba(110, 230, 200, 0.3); border-radius: 3px; }
#microbe-list::-webkit-scrollbar-track { background: transparent; }

#microbe-list li {
  display: flex; align-items: center; gap: 9px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
#microbe-list li:hover { background: rgba(255, 255, 255, 0.05); transform: translateX(2px); }
#microbe-list li.active { background: rgba(63, 217, 182, 0.14); box-shadow: inset 3px 0 0 var(--accent-1); font-weight: 600; }
#microbe-list .dot {
  width: 11px; height: 11px; flex: none;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}
#microbe-list .size { margin-left: auto; color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
#no-results { color: var(--muted); font-size: 0.85rem; }

.note {
  margin: 10px 0 0;
  font-size: 0.8rem; line-height: 1.5; color: var(--muted);
  border: 1px dashed rgba(168, 217, 78, 0.45);
  border-radius: 12px;
  padding: 9px 12px;
  background: rgba(168, 217, 78, 0.06);
}
.note strong { color: var(--accent-2); }

.controls { border-top: 1px solid var(--panel-border); padding-top: 12px; margin-top: 12px; }
.control-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; font-size: 0.86rem; color: var(--muted);
}
.control-row:last-child { margin-bottom: 0; }
.btn-row { flex-wrap: wrap; justify-content: flex-start; }
.btn {
  font: inherit; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 34px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.btn:hover { background: rgba(110, 230, 200, 0.16); border-color: var(--accent-1); transform: translateY(-1px); }
.btn.accent {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none; color: #061712; font-weight: 600;
  box-shadow: 0 4px 18px rgba(63, 217, 182, 0.45);
}

/* ---------- info panel ---------- */
#info-panel { left: var(--margin); bottom: 56px; width: 360px; max-width: calc(100vw - 40px); }
.info-eyebrow {
  margin: 0 0 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
   color: var(--accent-1);
}
#info-name { font-size: 26px; letter-spacing: -0.01em; }
#info-meta { margin: 3px 0 0; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; }
#info-tagline { margin: 6px 0 0; color: var(--muted); font-weight: 500; font-style: italic; font-size: 0.95rem; }
#info-desc { color: #d9f5ec; font-size: 14px; line-height: 1.65; margin: 10px 0 0; }
#info-fact-wrap {
  margin: 12px 0 0; font-size: 0.86rem; line-height: 1.5; color: var(--muted);
  background: rgba(63, 217, 182, 0.08);
  border-left: 3px solid var(--accent-1); border-radius: 12px; padding: 12px 14px;
}
.fact-label { color: var(--text); font-weight: 600; }

/* ---------- hint bar ---------- */
#hint-bar {
  position: fixed; z-index: 10;
  bottom: 14px; left: 50%; transform: translateX(-50%);
  color: var(--muted); font-size: 0.82rem; letter-spacing: 0.03em;
  background: rgba(6, 20, 17, 0.92);
  padding: 6px 16px; border-radius: 999px;
  white-space: nowrap;
}

/* ---------- 3D labels & tooltip ---------- */
#labels { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.label3d {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text);
  background: rgba(5, 19, 15, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 2px 8px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  transform: translate(-50%, -160%);
  white-space: nowrap;
  transition: opacity 0.2s ease;
}
.label3d::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 8px currentColor;
}
#tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: rgba(5, 16, 14, 0.88);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 0.8rem; font-weight: 600;
  padding: 5px 12px; border-radius: 999px;
  transform: translate(12px, 14px);
  opacity: 0; transition: opacity 0.12s ease;
}

/* ---------- loading & fallback ---------- */
#loading {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg);
  transition: opacity 0.6s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.loader-ring {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid rgba(63, 217, 182, 0.2);
  border-top-color: var(--accent-1);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title { font-family: "Archivo", Georgia, serif; letter-spacing: -0.01em; font-size: 1.6rem; font-weight: 800; margin: 8px 0 0; }
.loader-sub { color: var(--muted); margin: 0; }

#webgl-fail {
  position: fixed; inset: auto 0 0 0; z-index: 40;
  display: flex; justify-content: center; padding: 18px;
}
#webgl-fail[hidden] { display: none; }
.fail-card {
  background: rgba(8, 22, 19, 0.88); border: 1px solid var(--panel-border);
  border-radius: 18px; padding: 28px 30px; max-width: 540px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 50px rgba(0, 0, 0, 0.45);
}
.fail-card h2 { font-size: 22px; margin-bottom: 8px; }
.fail-card p { margin: 0 0 6px; color: var(--muted); font-size: 0.9rem; line-height: 1.6; }
.fail-card p:last-child { margin-bottom: 0; }

/* ---------- tablet ---------- */
@media (max-width: 1023px) {
  #site-header { width: 300px; padding: 14px 16px; }
  #site-header h1 { font-size: 1.55rem; }
  .subtitle { font-size: 0.85rem; }
  #sidebar { width: 280px; }
  #info-panel { width: 320px; }
}

/* ---------- mobile: single scrolling column ----------
   header → canvas block (56vh, unobstructed) → explorer/controls → info.
   Panels leave the fixed layer and stack full-width with 12px margins. */
@media (max-width: 640px) {
  :root { --margin: 12px; }
  html, body { height: auto; overflow-y: auto; overflow-x: hidden; }
  body { display: flex; flex-direction: column; min-height: 100vh; }
  #site-header {
    order: 1; position: relative; top: auto; left: auto;
    width: auto; max-width: none; margin: 12px 12px 0; padding: 12px 16px;
  }
  #site-header h1 { font-size: 1.35rem; }
  .subtitle { display: none; }
  .byline { margin-top: 6px; }
  #scene {
    order: 2; position: relative; inset: auto;
    width: 100%; height: 56vh; flex: none; margin-top: 12px;
  }
  #sidebar {
    order: 3; position: relative; top: auto; right: auto; left: auto; bottom: auto;
    width: auto; max-height: none; margin: 12px 12px 0; padding: 14px 16px;
  }
  #microbe-list { flex: none; max-height: 32vh; }
  .btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex-wrap: nowrap; }
  .btn-row .btn { width: 100%; text-align: center; }
  #info-panel {
    order: 4; position: relative; left: auto; bottom: auto;
    width: auto; max-width: none; margin: 12px; padding: 14px 16px;
  }
  #info-desc, #info-fact-wrap { display: none; }
  #info-panel.expanded #info-desc, #info-panel.expanded #info-fact-wrap { display: block; }
  #hint-bar { display: none; }
}

/* ================= THREE-SECTION LAYOUT =================
   Desktop: LEFT data column (header + info) · CENTER stage ·
   RIGHT switcher column (explorer list + controls). Side columns
   are solid dark panels divided from the stage by 1px rules. */
.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 340px;
  height: 100vh;
  height: 100dvh;
}
.col-left, .col-right {
  background: #05130f;
  display: flex; flex-direction: column;
  gap: 16px;
  padding: 20px;
  min-height: 0;
  min-width: 0;
}
.col-left { border-right: 1px solid var(--panel-border); }
.col-right { border-left: 1px solid var(--panel-border); }
.layout .panel { position: static; }
#site-header { width: auto; max-width: none; flex: none; }
#info-panel {
  width: auto; max-width: none;
  flex: 1; min-height: 0;
  overflow-y: auto;
}
#stage { position: relative; min-width: 0; min-height: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; }
#labels { position: absolute; inset: 0; }
#hint-bar { position: absolute; }
#sidebar { width: auto; max-height: none; flex: 1; min-height: 0; }

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

/* ---------- mobile: single-column stack ----------
   header -> stage (56vh) -> switcher -> data -> controls */
@media (max-width: 640px) {
  .layout { display: flex; flex-direction: column; height: auto; width: 100%; }
  .col-left, .col-right { display: contents; }
  #sidebar { display: contents; }
  #site-header { order: 1; margin: 12px 12px 0; width: auto; }
  #stage { order: 2; height: 56vh; flex: none; margin: 12px 12px 0; }
  .sidebar-head, #no-results, .note {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 12px 12px 0;
  }
  .sidebar-head { order: 3; }
  #microbe-list {
    order: 3;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 8px 10px;
    margin: 12px 12px 0;
    flex: none; max-height: 32vh; overflow-y: auto;
  }
  #no-results { order: 3; }
  .note { order: 3; }
  #info-panel { order: 4; margin: 12px 12px 0; width: auto; flex: none; overflow: visible; }
  #sidebar .controls {
    order: 5;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 12px;
  }
  #hint-bar { display: none; }
}

/* ================= PREMIUM UI PASS ================= */
::selection { background: var(--accent-1); color: #061712; }
:focus-visible { outline: 2px solid var(--accent-1); outline-offset: 2px; }
#stage::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.38) 100%);
}
#scene { cursor: grab; }
#scene:active { cursor: grabbing; }
#microbe-list::-webkit-scrollbar, #info-panel::-webkit-scrollbar { width: 8px; }
#microbe-list::-webkit-scrollbar-thumb, #info-panel::-webkit-scrollbar-thumb { background: rgba(63, 217, 182, 0.35); border-radius: 99px; }
#info-panel { scrollbar-width: thin; scrollbar-color: rgba(63, 217, 182, 0.35) transparent; }
@keyframes panelIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.panel-in { animation: panelIn 0.45s cubic-bezier(0.22, 0.8, 0.32, 1); }
.loader-wordmark { font-family: "Inter", sans-serif; font-size: 11px; font-weight: 600; letter-spacing: 0.01em; color: var(--muted); margin: 10px 0 0; }
.loader-bar { width: 160px; height: 3px; border-radius: 99px; background: rgba(255, 255, 255, 0.10); overflow: hidden; margin-top: 6px; }
.loader-bar span { display: block; height: 100%; width: 40%; border-radius: 99px; background: var(--accent-1); animation: loadslide 1.2s ease-in-out infinite; }
@keyframes loadslide { 0% { transform: translateX(-110%); } 100% { transform: translateX(280%); } }
@media (prefers-reduced-motion: reduce) {
  .panel-in { animation: none; }
  .loader-bar span { animation: none; transform: none; width: 60%; }
}
