/* Figures (pages/figure.js): inline in the transcript, and the lightbox. */

/* The overlay host (pages/overlay.js). Defined once here because all three
   viewers mount through it; it owns only stacking and scroll-lock, never
   appearance -- each viewer paints its own surface. */
.overlay-host { position: fixed; inset: 0; z-index: 100; }
body.overlay-open { overflow: hidden; }

/* ---------- inline ---------- */

.fig-wrap {
  display: block;
  width: 100%;
  margin-top: var(--space-md);
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
}
button.fig-wrap { cursor: pointer; }
button.fig-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.fig-frame {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  width: 100%;
  /* A frame narrowed to fit a tall figure is centred rather than left
     aligned, so a portrait figure sits under the middle of the text column
     instead of hugging one edge. */
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Never cropped: the aspect ratio of an MR slice carries meaning. */
.fig-img { width: 100%; height: 100%; object-fit: contain; display: block; }

.fig-placeholder {
  padding: var(--space-lg);
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
}

.fig-caption-row { display: flex; gap: var(--space-sm); margin-top: var(--space-sm); }

.fig-num {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  padding-top: 2px;
  flex: 0 0 auto;
}

.fig-caption {
  flex: 1;
  min-width: 0;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.3;
  /* Two lines: some corpus captions run long enough to push the next
     paragraph off the screen. The viewer shows it in full. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fig-provenance {
  color: var(--text-faint);
  font-size: 13px;
  margin-top: 2px;
  margin-left: 34px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- lightbox ---------- */

.figv-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
}


/* A centred dialog, not a takeover.
   `inset: 0` made the viewer edge-to-edge for figures that are often small
   diagrams, so a 400px chart sat in the middle of a 1280px void and the
   answer behind it was gone rather than merely backgrounded. It is now a
   panel that grows with its content up to a ceiling, with the transcript
   dimmed behind it -- the same relationship the citation sheet has. */
.figv-root {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 1000px);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
}

/* Full width on a phone, where a centred panel wastes the only screen there
   is; still not edge-to-edge vertically, so the dialog reads as a layer. */
@media (max-width: 720px) {
  .figv-root {
    width: 100vw;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
  }
}

.figv-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.figv-done {
  min-width: 52px;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.figv-done:hover { opacity: .75; }
.figv-done-spacer { min-width: 52px; flex: 0 0 auto; }
.figv-header-center { flex: 1; min-width: 0; text-align: center; }
.figv-title { color: var(--text); font-size: 14px; font-weight: 700; }
.figv-subtitle {
  color: var(--text-faint);
  font-size: 13px;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Dark stage: the neutral ground every image viewer uses, and it stops a
   figure with a white background bleeding into the panel. Softer than the
   former pure black now that it is a panel rather than the whole screen. */
.figv-stage {
  flex: 1;
  /* Both axes. A flex item's default min-size is its CONTENT, so without
     min-width the stage refused to shrink below the image's intrinsic width
     and a wide figure was clipped by the panel's edge -- the right-hand
     panels of a multi-panel figure simply cut off, which on a 2x2 clinical
     figure silently hides half the evidence. */
  min-height: 0;
  min-width: 0;
  /* Lighter than the figure's own dark ground. Most MRI figures are black
     plates, and on a near-black stage their edges vanish -- the image looked
     cropped by the panel when it was in fact complete, because there was no
     boundary between picture and background. A mid grey ends the image where
     it actually ends. */
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: var(--space-md);
  box-sizing: border-box;
}
.figv-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-in;
  display: block;
  /* A hairline so a black-bordered plate still reads as a bounded object,
     and a radius so nothing square bleeds into the panel's rounded corner. */
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #000;
}
/* Click-to-zoom: fit-to-screen stays the default, this is the opt-in. */
.figv-stage.zoom { align-items: flex-start; justify-content: flex-start; }
.figv-stage.zoom .figv-img { max-width: none; max-height: none; cursor: zoom-out; }

.figv-missing {
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  padding: var(--space-xl);
}

.figv-footer {
  flex: 0 0 auto;
  padding: var(--space-md) var(--space-lg) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.figv-caption-scroll { max-height: 120px; overflow-y: auto; }
.figv-caption { color: var(--text); font-size: 14px; line-height: 1.45; white-space: pre-wrap; }

.figv-open {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.figv-open:hover { opacity: .85; }

.figv-unavailable { color: var(--text-faint); font-size: 14px; line-height: 1.35; }
