.paper-gallery {
  --paper-gallery-accent: #ff6c00;
  --paper-gallery-muted: rgba(0, 0, 0, 0.58);
  --paper-gallery-page-height: clamp(240px, 32vw, 360px);
  width: 100%;
  margin: 3rem auto;
}

/* Override the article template's narrower section-child layout. */
.paper-gallery > .paper-gallery__list {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  gap: 4.5rem;
}

.paper-gallery__slide {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  margin: 0;
  text-align: center;
}

.paper-gallery__viewport {
  width: 100%;
  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;
}

.paper-gallery__viewport::-webkit-scrollbar {
  display: none;
}

.paper-gallery__track,
.paper-gallery__pages {
  display: flex;
  width: max-content;
  align-items: center;
}

.paper-gallery__track {
  min-height: calc(var(--paper-gallery-page-height) + 3rem);
  padding: 1.5rem 0;
  box-sizing: border-box;
}

.paper-gallery__pages {
  flex: none;
  gap: 1.25rem;
  /* Include the seam's gap in the measured width of every repeated group. */
  padding-right: 1.25rem;
}

.paper-gallery .paper-gallery__page {
  position: relative;
  display: block;
  flex: none;
  border: 0;
  border-radius: 0.25rem;
  color: inherit;
  text-decoration: none;
  box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.15);
}

.paper-gallery__preview {
  display: block;
  height: var(--paper-gallery-page-height);
  width: auto;
  border-radius: inherit;
  background: #fff;
}

.paper-gallery__page-indicator {
  position: absolute;
  right: 0.65rem;
  bottom: 0.65rem;
  padding: 0.3rem 0.5rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.68);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1;
}

.paper-gallery__preview-status {
  margin: 0.5rem 0;
  color: var(--paper-gallery-muted);
  font-size: 0.9rem;
  text-align: center !important;
}

.paper-gallery__preview-status.is-error,
.paper-gallery > .paper-gallery__status.is-error {
  color: #9d1c1c;
}

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

.paper-gallery__viewport:focus-visible {
  outline-offset: -3px;
}

.paper-gallery__viewport.is-dragging {
  cursor: grabbing;
}

.paper-gallery .paper-gallery__card-title {
  display: block;
  width: auto;
  max-width: none;
  margin: 1rem 24px 0;
  border: 0;
  font-size: clamp(0.9rem, 1.4vw, 1.1rem);
  font-weight: 600;
  line-height: 1.3;
  color: #FF6C00 !important;
  text-align: center;
}

.paper-gallery__card-hint {
  margin: 0;
  padding: 0 0.5rem;
  color: var(--paper-gallery-muted);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center !important;
}

/* Reuse .l-body width and article typography; only adjust vertical spacing. */
.paper-gallery__description {
  margin-top: 1.25rem;
  margin-bottom: 0;
}

.paper-gallery__card-title:hover {
  text-decoration: underline;
}

.paper-gallery > .paper-gallery__status {
  width: 100%;
  margin: 2rem 0 0;
  color: var(--paper-gallery-muted);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center !important;
}

.paper-gallery [hidden] {
  display: none;
}

@media (min-width: 768px) {
  .paper-gallery .paper-gallery__card-title {
    margin-left: 72px;
    margin-right: 72px;
  }
}

@media (min-width: 1080px) {
  .paper-gallery .paper-gallery__card-title {
    width: 70%;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 680px) {
  .paper-gallery > .paper-gallery__list {
    gap: 3.5rem;
  }
}

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

.paper-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;
}

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

.paper-viewer::backdrop {
  background: rgba(17, 17, 27, 0.86);
}

.paper-viewer__stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* Center small pages inside the surface, not oversized pages inside the scroll
   viewport: negative overflow would make their top/left edges unreachable. */
.paper-viewer__surface {
  display: grid;
  place-items: center;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
}

.paper-viewer__surface > * {
  grid-area: 1 / 1;
}

.paper-viewer canvas {
  display: block;
  max-width: none;
  max-height: none;
  object-fit: contain;
  background: #fff;
}

.paper-viewer__status {
  box-sizing: border-box;
  max-width: min(30rem, calc(100vw - 64px));
  margin: 0;
  padding: 1rem;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center !important;
}

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

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

.paper-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;
}

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

.paper-viewer__button:disabled {
  opacity: 0.3;
  cursor: default;
}

.paper-viewer__button:focus-visible {
  outline: 2px solid #b4befe;
  outline-offset: 2px;
}

.paper-viewer__stage:focus-visible {
  outline: 2px solid #b4befe;
  outline-offset: -2px;
}

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

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