.figure-strip {
  --figure-strip-accent: #ff6c00;
  --figure-strip-muted: rgba(0, 0, 0, 0.58);
  --figure-strip-height: clamp(150px, 18vw, 220px);
  --figure-strip-gap: 1.25rem;
  width: 100%;
  margin: 2rem auto;
}

/* Override the article template's narrower section-child layout. */
.figure-strip > .figure-strip__viewport,
.figure-strip > .figure-strip__hint {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
}

.figure-strip__viewport {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* Native smooth scrolling and scroll anchoring would fight the loop offset. */
  scroll-behavior: auto;
  overflow-anchor: none;
  cursor: grab;
  user-select: none;
}

.figure-strip__viewport::-webkit-scrollbar {
  display: none;
}

.figure-strip__viewport.is-dragging {
  cursor: grabbing;
}

.figure-strip__track {
  display: flex;
  width: max-content;
  min-height: calc(var(--figure-strip-height) + 3rem);
  padding: 1.5rem 0;
  box-sizing: border-box;
  align-items: flex-start;
}

.figure-strip .figure-strip__items {
  display: flex;
  flex: none;
  width: max-content;
  margin: 0;
  padding: 0;
  gap: var(--figure-strip-gap);
  /* Include the seam's gap in the measured width of every repeated group. */
  padding-right: var(--figure-strip-gap);
  list-style: none;
}

.figure-strip__item {
  flex: none;
  margin: 0;
  padding: 0;
}

.figure-strip__card {
  display: block;
  /* Center the thumbnail when a label is wider than the image (e.g. on phones). */
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0.25rem;
  background: #fff;
  color: inherit;
  font: inherit;
  cursor: pointer;
  box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.figure-strip__card:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.2);
}

.figure-strip__thumb {
  display: block;
  height: var(--figure-strip-height);
  width: auto;
  border-radius: inherit;
  pointer-events: none;
}

.figure-strip__label {
  display: block;
  margin: 0.6rem 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--figure-strip-accent);
  text-align: center;
}

.figure-strip__sublabel {
  display: block;
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  line-height: 1.3;
  color: var(--figure-strip-muted);
  text-align: center;
}

.figure-strip__sublabel a {
  color: var(--figure-strip-accent);
}

/* Citations: lighter than the title they follow, linked when a URL is known. */
.figure-strip__cite {
  font-weight: 400;
  white-space: nowrap;
}

.figure-strip__label .figure-strip__cite {
  color: var(--figure-strip-muted);
}

.figure-strip__cite a {
  color: inherit;
  text-decoration: underline;
}

.figure-viewer__title .figure-strip__cite {
  font-size: 0.9rem;
  color: rgba(205, 214, 244, 0.8);
}

.figure-strip > .figure-strip__hint {
  margin-top: 0;
  color: var(--figure-strip-muted);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center !important;
}

.figure-strip :focus-visible {
  outline: 2px solid var(--figure-strip-accent);
  outline-offset: 3px;
}

.figure-strip__viewport:focus-visible {
  outline-offset: -3px;
}

/* Captions stay in the page so the article template typesets their math;
   the viewer clones the rendered caption when a figure is opened. */
.figure-strip [data-strip-caption] {
  display: none;
}

html.figure-viewer-open {
  overflow: hidden;
}

.figure-viewer {
  box-sizing: border-box;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 48px 16px 16px;
  border: 0;
  background: transparent;
  color: #cdd6f4;
  overflow: hidden;
}

.figure-viewer[open] {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 12px;
}

/* Darker than the paper viewer: the caption text below sits on the backdrop. */
.figure-viewer::backdrop {
  background: rgba(17, 17, 27, 0.95);
}

.figure-viewer__stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  min-height: 0;
}

.figure-viewer__panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.figure-viewer__panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.25rem 1rem;
  font-size: 0.85rem;
  line-height: 1.4;
}

.figure-viewer__panel-title {
  font-weight: 600;
  color: #fff;
}

.figure-viewer__panel-header a {
  color: #ff8c33;
  text-decoration: underline;
}

.figure-viewer__frame {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.figure-viewer__editor {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0.25rem;
  background: #fff;
}

.figure-viewer__image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 0.25rem;
  background: #fff;
}

.figure-viewer__status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 1rem;
  border-radius: 0.25rem;
  background: rgba(17, 17, 27, 0.6);
  font-size: 0.95rem;
  line-height: 1.5;
  text-align: center !important;
  pointer-events: none;
}

.figure-viewer__caption {
  box-sizing: border-box;
  width: min(72rem, 100%);
  max-height: 22vh;
  margin: 0 auto;
  padding: 0 0.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 0.9rem;
  line-height: 1.55;
  text-align: left;
}

.figure-viewer__title {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #ff8c33;
  text-align: center;
}

.figure-viewer__subtitle {
  display: block;
  margin: -0.2rem 0 0.5rem;
  font-size: 0.9rem;
  color: rgba(205, 214, 244, 0.8);
  text-align: center;
}

.figure-viewer__caption strong {
  font-weight: 600;
  color: #fff;
}

.figure-viewer__caption a {
  color: #ff8c33;
  text-decoration: underline;
}

.figure-viewer__navigation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.figure-viewer__counter {
  min-width: 4rem;
  font: 14px/1.5 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.figure-viewer__button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: 30px/1 system-ui, sans-serif;
  cursor: pointer;
}

.figure-viewer__button:hover {
  background: rgba(205, 214, 244, 0.12);
}

.figure-viewer__button:focus-visible,
.figure-viewer__caption:focus-visible,
.figure-viewer__panel-header a:focus-visible {
  outline: 2px solid #b4befe;
  outline-offset: 2px;
}

.figure-viewer__close {
  position: absolute;
  top: 2px;
  right: 8px;
}

.figure-viewer [hidden] {
  display: none;
}

@media (max-width: 900px) {
  .figure-viewer__stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
}
