/* ==========================================================================
   Brain atlas viewer
   ========================================================================== */

.atlas {
  --sidebar-w: 300px;
  --panel-w: 330px;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w);
  gap: 1px;
  height: calc(100vh - var(--header-h));
  min-height: 560px;
  background: var(--color-divider);
  border-block: 1px solid var(--color-divider);
}

.atlas-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-bg);
}

.atlas-col-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.atlas-col-head h2,
.atlas-col-head h3 {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 60%, transparent);
}

.atlas-col-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* --- Parcellation picker --------------------------------------------------- */

.atlas-picker {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.atlas-picker .seg { width: 100%; }

.atlas-picker .seg-opt {
  flex: 1;
  justify-content: center;
  padding: 6px 8px;
  font-size: 0.75rem;
}

.atlas-note {
  margin: var(--space-2) 0 0;
  font-size: 0.6875rem;
  line-height: 1.4;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

/* --- Search --------------------------------------------------------------- */

.atlas-search {
  position: relative;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.atlas-search .input { padding-left: 30px; }

.atlas-search svg {
  position: absolute;
  top: 50%;
  left: calc(var(--space-4) + 8px);
  transform: translateY(-50%);
  color: color-mix(in srgb, var(--color-text) 45%, transparent);
  pointer-events: none;
}

/* --- Structure list ------------------------------------------------------- */

.atlas-group { border-bottom: 1px solid var(--color-divider); }

.atlas-group > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: 0.8125rem;
  list-style: none;
  user-select: none;
}

.atlas-group > summary::-webkit-details-marker { display: none; }

.atlas-group > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-block: 3.5px solid transparent;
  opacity: 0.55;
  transition: transform var(--dur-fast) var(--ease);
}

.atlas-group[open] > summary::before { transform: rotate(90deg); }

.atlas-group > summary .count {
  margin-left: auto;
  font-family: var(--font-body);
  font-size: 0.6875rem;
  opacity: 0.5;
}

.atlas-group > summary:hover { background: color-mix(in srgb, var(--color-text) 5%, transparent); }

.atlas-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 5px var(--space-4) 5px calc(var(--space-4) + 14px);
  border: 0;
  background: transparent;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

.atlas-item:hover { background: color-mix(in srgb, var(--color-accent) 10%, transparent); }

.atlas-item[aria-selected="true"] {
  background: color-mix(in srgb, var(--color-accent) 18%, transparent);
  color: var(--color-accent-800);
  font-weight: 500;
}

.atlas-item .swatch {
  width: 9px;
  height: 9px;
  flex: none;
  border: 1px solid color-mix(in srgb, var(--color-text) 25%, transparent);
}

.atlas-item .side {
  margin-left: auto;
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  opacity: 0.5;
}

.atlas-empty {
  padding: var(--space-8) var(--space-4);
  font-size: 0.8125rem;
  text-align: center;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

/* --- Canvas --------------------------------------------------------------- */

.atlas-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #ecebe7;
}

/* The GL canvas clears to an opaque colour, so the vignette is layered over
   the top rather than showing through from behind. */
.atlas-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(
    ellipse 70% 70% at 50% 44%,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.04) 62%,
    rgba(0, 0, 0, 0.13) 100%
  );
}

.atlas-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.atlas-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  color: color-mix(in srgb, var(--color-text) 65%, transparent);
  font-size: 0.8125rem;
  transition: opacity var(--dur-slow) var(--ease);
}

.atlas-loading[hidden] {
  display: grid;
  opacity: 0;
  pointer-events: none;
}

.atlas-spinner {
  width: 26px;
  height: 26px;
  border: 1px solid var(--color-divider);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: atlas-spin 0.9s linear infinite;
}

@keyframes atlas-spin {
  to { transform: rotate(360deg); }
}

.atlas-error {
  max-width: 52ch;
  padding: var(--space-6);
  border: 1px solid var(--color-divider);
  border-left: 3px solid var(--color-highlight);
  background: var(--color-bg);
  font-size: 0.8125rem;
  line-height: 1.6;
  text-align: left;
}

/* Recovery steps, shown when the browser will not give us WebGL2. */
.atlas-error-steps {
  margin: var(--space-3) 0 0;
  padding-left: 1.3em;
}

.atlas-error-steps li {
  margin-bottom: var(--space-2);
  text-align: left;
  hyphens: manual;
}

.atlas-error-steps li:last-child { margin-bottom: 0; }

/* Hover tooltip */

.atlas-tip {
  position: absolute;
  z-index: 3;
  transform: translate(14px, -50%);
  max-width: 26ch;
  padding: 4px 9px;
  background: color-mix(in srgb, var(--color-neutral-900) 92%, transparent);
  color: #f4f4f5;
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.atlas-tip[hidden] { display: none; }

/* Pinned to a corner when the name comes from the sidebar rather than the
   pointer, since there is no cursor position to anchor to. */
.atlas-tip.is-pinned {
  left: 50% !important;
  top: auto !important;
  bottom: var(--space-8);
  transform: translateX(-50%);
}

/* Crosshair readout */

.atlas-readout:empty { display: none; }

.atlas-readout {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  display: flex;
  gap: var(--space-3);
  padding: 5px 10px;
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--color-divider);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  pointer-events: none;
}

.atlas-readout .name { color: var(--color-accent-700); font-weight: 500; }

/* --- Toolbar -------------------------------------------------------------- */

.atlas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-divider);
  background: var(--color-bg);
}

.atlas-toolbar .spacer { margin-left: auto; }

.atlas-toolbar .seg-opt { padding: 5px 10px; font-size: 0.75rem; }

.seg-opt.boxed { border: 1px solid var(--color-divider); }

.slider {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 190px;
}

.slider label {
  flex: none;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 60%, transparent);
}

.slider output {
  flex: none;
  min-width: 3ch;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-align: right;
  opacity: 0.7;
}

.atlas-credit {
  margin: 0;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-top: 1px solid var(--color-divider);
  background: var(--color-bg);
  font-size: 0.625rem;
  line-height: 1.5;
  color: color-mix(in srgb, var(--color-text) 52%, transparent);
}

.atlas-credit a { color: inherit; text-decoration: underline; }
.atlas-credit a:hover { color: var(--color-accent); }

/* --- Pinhole: the selected region on its own ------------------------------- */

.detail-pin {
  position: relative;
  margin: var(--space-3) 0 var(--space-4);
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.detail-pin canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 320 / 220;
}

.detail-pin .pin-caption {
  position: absolute;
  left: 6px;
  bottom: 5px;
  padding: 2px 7px;
  background: color-mix(in srgb, var(--color-bg) 86%, transparent);
  border: 1px solid var(--color-divider);
  font-size: 0.625rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 60%, transparent);
  pointer-events: none;
}

/* --- Source references ----------------------------------------------------- */

.detail-refs {
  margin-top: var(--space-8);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
}

.detail-refs h6 {
  margin-bottom: var(--space-2);
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

.refs-lic {
  margin: 0 0 var(--space-2);
  font-size: 0.75rem;
}

.refs-list {
  margin: 0;
  padding-left: 1.1em;
  font-size: 0.6875rem;
  line-height: 1.55;
  color: color-mix(in srgb, var(--color-text) 68%, transparent);
}

.refs-list li { margin-bottom: var(--space-2); }
.refs-list a { word-break: break-all; }

.refs-more {
  margin: var(--space-3) 0 0;
  font-size: 0.6875rem;
}

/* --- Detail panel --------------------------------------------------------- */

.atlas-detail { padding: var(--space-6) var(--space-4); }

.atlas-detail .placeholder {
  padding-block: var(--space-8);
  font-size: 0.875rem;
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}

.atlas-detail h3 {
  margin-bottom: var(--space-1);
  font-size: 1.375rem;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-4);
}

.detail-aka {
  margin-top: calc(var(--space-2) * -1);
  font-size: 0.8125rem;
}

.detail-desc {
  font-size: 0.875rem;
  line-height: 1.62;
}

.detail-facts {
  width: 100%;
  margin-top: var(--space-6);
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.detail-facts th {
  width: 45%;
  padding: 5px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-text) 8%, transparent);
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
  font-weight: 400;
  text-align: left;
}

.detail-facts td {
  padding: 5px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-text) 8%, transparent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

/* --- Home page preview ---------------------------------------------------- */

.atlas-preview {
  position: relative;
  aspect-ratio: 16 / 11;
  overflow: hidden;
  background: #ecebe7;
}

.atlas-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse 72% 72% at 50% 46%,
    rgba(0, 0, 0, 0) 0%,
    rgba(0, 0, 0, 0.05) 62%,
    rgba(0, 0, 0, 0.14) 100%
  );
}

.atlas-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.atlas-preview .hint {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  padding: 4px 9px;
  background: color-mix(in srgb, var(--color-bg) 85%, transparent);
  border: 1px solid var(--color-divider);
  color: color-mix(in srgb, var(--color-text) 70%, transparent);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  pointer-events: none;
}

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

@media (max-width: 1080px) {
  .atlas {
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    height: auto;
  }

  .atlas-col-main { grid-row: 1; }

  .atlas-col-list { grid-row: 1; max-height: 70vh; }

  .atlas-col-detail {
    grid-column: 1 / -1;
    grid-row: 2;
    max-height: none;
  }

  .atlas-stage { min-height: 60vh; }
}

@media (max-width: 760px) {
  .atlas {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .atlas-col-main { grid-row: 1; }
  .atlas-col-detail { grid-column: 1; grid-row: 2; }
  .atlas-col-list { grid-column: 1; grid-row: 3; max-height: 60vh; }

  .atlas-stage { min-height: 52vh; }

  .atlas-toolbar { gap: var(--space-2); }
  .slider { min-width: 140px; }
}
