/* supp-fig-popup.css — Gwern-style hoverable supplementary figure popups */

/* --- Trigger link styling --- */
.supp-fig-ref {
  color: var(--link, #256);
  text-decoration: none;
  border-bottom: 1px dotted var(--link, #256);
  cursor: pointer;
}
.supp-fig-ref:hover {
  border-bottom-style: solid;
}

/* --- Popup container --- */
.supp-fig-popup {
  position: absolute;
  z-index: 1001;
  display: flex;
  flex-direction: column;

  width: 640px;
  max-width: calc(100vw - 32px);
  max-height: 85vh;

  background: var(--bg, #fcfcf8);
  border: 3px double #ccc;
  box-shadow: 1px 2px 8px 0 #ccc;

  opacity: 1;
  transition: none;

  font-family: 'Merriweather', Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.55;
}

/* Fade-out transition */
.supp-fig-popup.fading {
  opacity: 0;
  transition: opacity 0.25s ease-in 0.1s;
}

/* Focused state */
.supp-fig-popup.focused {
  border-color: #aaa;
  box-shadow: 1px 2px 8px 0 #aaa;
}

/* --- Title bar --- */
.supp-fig-popup-title-bar {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 1.6rem;
  padding: 0.2rem 0.5rem;
  border-bottom: 1px solid #ddd;
  background-color: #fff;
  background-image: radial-gradient(circle, #e6e6e6 1px, transparent 1px);
  background-size: 8px 8px;
  user-select: none;
}

.supp-fig-popup.focused .supp-fig-popup-title-bar {
  background-image: radial-gradient(circle, #fff 1px, transparent 1px);
  background-color: #e6e6e6;
}

.supp-fig-popup-title {
  flex: 1 1 auto;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: #aaa;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.supp-fig-popup.focused .supp-fig-popup-title {
  color: #1a1a1a;
}

/* Pin button */
.supp-fig-popup-pin {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  margin-right: 0.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.supp-fig-popup-pin:hover {
  color: #1a1a1a;
}
.supp-fig-popup.pinned .supp-fig-popup-pin {
  color: #1a1a1a;
}

/* Expand button */
.supp-fig-popup-expand {
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  margin-left: 0.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
  color: #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.supp-fig-popup-expand:hover {
  color: #1a1a1a;
}
.supp-fig-popup.focused .supp-fig-popup-expand {
  color: #777;
}

/* Close button */
.supp-fig-popup-close {
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  margin-left: 0.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  color: #bbb;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.supp-fig-popup-close:hover {
  color: #1a1a1a;
}
.supp-fig-popup.focused .supp-fig-popup-close {
  color: #777;
}

/* --- Scrollable content area --- */
.supp-fig-popup-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.6em 0.8em 0.8em 0.8em;
  color: var(--text, #1a1a1a);
}
.supp-fig-popup-content.has-scroll {
  overscroll-behavior: contain;
}

/* Image styling */
.supp-fig-popup-img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto 0.6em auto;
  border: 1px solid #e0e0e0;
  border-radius: 2px;
  background: #fff;
}

/* Caption styling */
.supp-fig-popup-caption {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.7;
  color: #444;
  text-indent: 0;
}

/* --- Custom scrollbar --- */
.supp-fig-popup-content::-webkit-scrollbar {
  width: 12px;
}
.supp-fig-popup-content::-webkit-scrollbar-track {
  background: transparent;
}
.supp-fig-popup-content::-webkit-scrollbar-thumb {
  background: #ddd;
  border: 3px solid var(--bg, #fcfcf8);
  border-radius: 6px;
}
.supp-fig-popup-content::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}
.supp-fig-popup-content {
  scrollbar-color: #ddd transparent;
  scrollbar-width: thin;
}

/* --- Code viewer links inside popup --- */
.supp-fig-popup-code-links {
  display: flex;
  flex-direction: column;
  margin: 0.8em 0 0;
  padding: 0.5em 0.7em;
  border: 1px solid #ddd;
  border-radius: 3px;
  background: #f8f8f5;
  font-family: 'IBM Plex Mono', 'Menlo', monospace;
  font-size: 0.72rem;
}
.code-links-label {
  color: #1a1a1a;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.code-links-toggle {
  display: inline;
  background: none;
  border: none;
  font-family: 'IBM Plex Mono', 'Menlo', monospace;
  font-size: 0.72rem;
  color: #256;
  cursor: pointer;
  margin-left: 0.6em;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  transition: color 0.12s;
}
.code-links-toggle:hover {
  color: #1a1a1a;
}
/* --- Merge links header with code viewer when open --- */
.supp-fig-popup-code-links + .code-viewer:not([hidden]) {
  margin-top: 0;
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.supp-fig-popup-code-links:has(+ .code-viewer:not([hidden])) {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
  margin-bottom: 0;
}

/* --- Expanded popup state (code viewer active) --- */
.supp-fig-popup.expanded {
  max-height: 90vh;
}

/* --- Fullscreen state --- */
.supp-fig-popup.fullscreen {
  position: fixed;
  top: 0 !important;
  left: var(--sidebar-width, 300px) !important;
  width: calc(100vw - var(--sidebar-width, 300px)) !important;
  max-width: calc(100vw - var(--sidebar-width, 300px));
  height: 100vh;
  max-height: 100vh;
  z-index: 10000;
  border: none;
  border-radius: 0;
}
.supp-fig-popup.fullscreen .supp-fig-popup-content {
  overflow: hidden;
}
/* When code viewer is open in fullscreen, allow scrolling past image to reach it */
.supp-fig-popup.fullscreen.expanded .supp-fig-popup-content {
  overflow-y: auto;
}

/* Code viewer inside popup: no fixed height, content flows in outer scroll */
.supp-fig-popup .code-viewer {
  margin-top: 0.75em;
}
/* Merge with links header in popup too */
.supp-fig-popup .supp-fig-popup-code-links + .code-viewer {
  margin-top: 0;
}
.supp-fig-popup .code-viewer .viewer-panel {
  max-height: none;
}
