:root {
  --bg: #0b0d10;
  --bg-elevated: #14171c;
  --bg-hover: #1c2028;
  --border: #262b33;
  --text: #e9ebee;
  --text-dim: #9aa2ad;
  --text-faint: #626a76;
  --accent: #4fd1c5;
  --accent-dim: #2a5f5a;
  --focus-ring: #4fd1c5;
  --radius: 10px;
  --sidebar-w: 360px;
  --header-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* ---------- Header ---------- */

header.site-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  min-width: 0;
}

.site-back {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding-right: 16px;
  border-right: 1px solid var(--border);
  text-decoration: none;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.site-back:hover { color: var(--text); }
.site-back-logo {
  height: 60px;
  width: auto;
  background: #fff;
  border-radius: 3px;
  padding: 2px 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }

.brand-text { min-width: 0; }
.brand-text .lab-name {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}
.brand-text .species-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text .species-title em {
  font-style: italic;
  color: var(--text-dim);
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  margin-left: auto;
}

.lang-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
}
.lang-toggle button.active {
  background: var(--accent);
  color: #04211e;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover, .icon-btn.active { color: var(--text); border-color: var(--text-faint); }
.icon-btn svg { width: 17px; height: 17px; }

.settings-dropdown {
  flex: none;
  max-height: 80%;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.settings-dropdown.hidden { display: none; }

.settings-section {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }

.settings-section h4 {
  margin: 0 0 10px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  font-weight: 700;
}

.atlas-name {
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 6px;
}

.atlas-specs {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
  margin: 0 0 10px;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 4px 4px 0;
}
.atlas-specs p { margin: 0 0 8px; text-align: justify; text-justify: inter-word; }
.atlas-specs p:last-child { margin-bottom: 0; }

.atlas-desc {
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text-dim);
  margin: 0 0 10px;
  text-align: justify;
  text-justify: inter-word;
}

.atlas-references-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  margin: 0 0 6px;
}

.atlas-references {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 12px;
}
.atlas-references a {
  font-size: 11px;
  line-height: 1.4;
  color: var(--accent);
  text-decoration: none;
}
.atlas-references a:hover { text-decoration: underline; }
.atlas-reference-plain {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-faint);
}

.atlas-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.atlas-links a {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.atlas-links a:hover { text-decoration: underline; }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.settings-row:last-child { margin-bottom: 0; }
.settings-row .settings-label { font-size: 12.5px; color: var(--text); }

.settings-row select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  padding: 4px 6px;
  max-width: 150px;
}


.range-field { width: 100%; }
.range-field .range-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

/* switch */
.switch {
  position: relative;
  width: 34px;
  height: 19px;
  flex: none;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  left: 2px; top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.switch input:checked + .track { background: var(--accent-dim); }
.switch input:checked + .track::before { transform: translateX(15px); background: var(--accent); }

/* ---------- Layout ---------- */

main.layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  min-height: 0;
  min-width: 0;
}
main.layout.sidebar-hidden { grid-template-columns: 1fr; }
main.layout.sidebar-hidden aside.sidebar { display: none; }

.viewer-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #000;
}

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

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: opacity 0.35s ease;
  z-index: 5;
}
.viewer-loading.hidden { opacity: 0; pointer-events: none; }

.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* view-mode toolbar floating over canvas */
.view-toolbar {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  background: rgba(20, 23, 28, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  z-index: 4;
}
.view-toolbar button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.view-toolbar button:hover { color: var(--text); }
.view-toolbar button.active {
  background: var(--accent);
  color: #04211e;
}

.hover-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  background: rgba(20, 23, 28, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}
.hover-tooltip.hidden { display: none; }

/* ---------- Sidebar ---------- */

aside.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
}

.panel-block {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.panel-block .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: 8px;
  display: block;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.mini-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--text-faint); }

.search-box {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
}
.search-box:focus { outline: 2px solid var(--focus-ring); outline-offset: -1px; }

.region-list-wrap {
  flex: 1 1 auto;
  min-height: 80px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}

.region-list { list-style: none; margin: 0; padding: 4px 0; }

.region-list .letter-heading {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  padding: 8px 16px 2px;
  letter-spacing: 0.06em;
}

.region-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 16px;
  cursor: pointer;
}
.region-row:hover { background: var(--bg-hover); }
.region-row.selected { background: var(--bg-hover); box-shadow: inset 2px 0 0 var(--accent); }

.swatch {
  width: 10px; height: 10px;
  border-radius: 3px;
  flex: none;
  border: 1px solid rgba(255,255,255,0.15);
}

.region-row .name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-row .vis-toggle {
  flex: none;
  width: 15px; height: 15px;
  cursor: pointer;
}

.no-results {
  padding: 16px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
}

/* ---------- Info panel ---------- */

.info-panel {
  flex: none;
  max-height: 42%;
  overflow-y: auto;
  padding: 16px;
}

.info-placeholder {
  color: var(--text-faint);
  font-size: 13px;
  line-height: 1.5;
}

.info-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.info-title { font-size: 15px; font-weight: 700; line-height: 1.3; }
.info-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex: none;
}
.badge.pending { color: #d8ab4e; border-color: #4a3d24; }
.badge.documented { color: var(--accent); border-color: var(--accent-dim); }

.info-desc {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  margin: 8px 0 12px;
  text-align: justify;
  text-justify: inter-word;
}

.info-sources { font-size: 11.5px; }
.info-sources .label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 6px;
  display: block;
}
.info-sources ol { margin: 0; padding-left: 18px; }
.info-sources li { margin-bottom: 5px; }
.info-sources a { color: var(--accent); text-decoration: none; }
.info-sources a:hover { text-decoration: underline; }

.info-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- Scrollbars ---------- */

.region-list-wrap::-webkit-scrollbar, .info-panel::-webkit-scrollbar, .settings-dropdown::-webkit-scrollbar { width: 8px; }
.region-list-wrap::-webkit-scrollbar-thumb, .info-panel::-webkit-scrollbar-thumb, .settings-dropdown::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 4px;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  main.layout {
    grid-template-columns: 1fr;
    grid-template-rows: 52vh 1fr;
  }
  main.layout.sidebar-hidden {
    grid-template-rows: 1fr;
  }
  aside.sidebar { border-left: none; border-top: 1px solid var(--border); }
  :root { --sidebar-w: 100%; }
}

@media (max-width: 480px) {
  header.site-header { gap: 8px; padding: 0 10px; }
  .site-back { gap: 6px; padding-right: 8px; }
  .site-back-label { display: none; }
  .brand-text .lab-name { display: none; }
  .brand-text .species-title { font-size: 13px; }
  .header-actions { gap: 6px; }
  .lang-toggle button { padding: 6px 9px; }
}
