/* Saint Paul gift preview: "Then and now" collection page (collection.html).
   Uses the tokens of css/base.css only. Class prefix: .co-
   Layout: a dark gallery stage (intro + one large viewer), then a light strip of thumbnails. */

/* 1. Stage */
.co-stage {
  padding-block: clamp(var(--sp-space-6), 6vw, var(--sp-space-8)) clamp(var(--sp-space-7), 7vw, var(--sp-space-9));
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(246, 183, 91, .22), transparent 60%),
    radial-gradient(80% 50% at 50% 100%, rgba(222, 191, 142, .35), transparent 70%),
    linear-gradient(180deg, var(--sp-ivory) 0%, var(--sp-paper) 100%);
}
/* Light gallery wall: the grain stays still paper. */
.co-stage.sp-grain::after { opacity: .05; mix-blend-mode: multiply; animation: none; }
.co-stage::before {
  /* thin gold rule across the top of the stage */
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--sp-gold-500) 20%, var(--sp-gold-300) 50%, var(--sp-gold-500) 80%, transparent);
  opacity: .7;
}
.co-intro { position: relative; z-index: 6; max-width: 46rem; margin-bottom: clamp(var(--sp-space-5), 4vw, var(--sp-space-7)); text-align: center; }
.co-intro .sp-eyebrow { justify-content: center; }
.co-intro .sp-eyebrow::after {
  content: "";
  flex: none;
  width: 28px;
  height: 7px;
  transform: scaleX(-1);
  background:
    linear-gradient(var(--sp-gold-500), var(--sp-gold-500)) left center / 20px 1px no-repeat,
    linear-gradient(45deg, transparent 35%, var(--sp-gold-500) 35% 65%, transparent 65%) right center / 7px 7px no-repeat,
    linear-gradient(-45deg, transparent 35%, var(--sp-gold-500) 35% 65%, transparent 65%) right center / 7px 7px no-repeat;
}
.co-intro__title {
  margin-bottom: var(--sp-space-3);
  font-family: var(--sp-font-display);
  font-size: var(--sp-fs-h1);
  font-weight: 600;
  line-height: var(--sp-lh-tight);
  color: var(--sp-ink);
  text-wrap: balance;
  letter-spacing: .01em;
}
.co-intro__lede {
  margin-inline: auto;
  max-width: 38rem;
  color: var(--sp-ink-soft);
  opacity: 1;
  font-size: clamp(1.0625rem, 1rem + .35vw, 1.2rem);
  line-height: 1.6;
  text-wrap: pretty;
}

/* 2. Viewer */
.co-viewer {
  position: relative;
  z-index: 6;
  display: grid;
  gap: var(--sp-space-5);
  border-radius: var(--sp-radius-m);
  scroll-margin-top: calc(var(--sp-header-h) + var(--sp-space-3));
}
.co-viewer:focus-visible { outline: 3px solid var(--sp-sky); outline-offset: 8px; }
.co-viewer__media { display: flex; flex-direction: column; align-items: center; gap: var(--sp-space-3); min-width: 0; }

/* The frame takes the picture's own shape: width is capped so a tall picture fits the screen. */
.co-stage .co-frame.sp-frame {
  --w: 4;
  --h: 3;
  width: min(100%, calc(70svh * var(--w) / var(--h)));
  padding: 8px;
  background: var(--sp-paper);
  border-color: var(--sp-gold-500);
  box-shadow:
    0 0 0 1px rgba(112, 57, 18, .35),
    0 0 0 6px #fffdf8,
    0 0 0 7px rgba(214, 140, 59, .55),
    0 30px 60px -28px rgba(45, 21, 4, .45);
}
.co-stage .co-frame.sp-frame::after { inset: 8px; border-color: var(--sp-bronze); }
.co-frame .sp-compare, .co-frame > img { width: 100%; aspect-ratio: var(--w) / var(--h); background: var(--sp-paper); }
.co-frame > img { object-fit: cover; }
/* Holds the picture shape until the script draws the slider, so nothing below it moves. */
.co-frame__ph { aspect-ratio: var(--w) / var(--h); background: var(--sp-paper); }
.co-compare--portrait > img { object-position: center 18%; }
/* A source scan saved sideways is turned upright inside a wrapper that keeps the slider clip. */
.sp-compare > .co-rotated { position: absolute; inset: 0; display: block; overflow: hidden; container-type: size; background: var(--sp-paper); }
.co-rotated__img { position: absolute; left: 50%; top: 50%; width: 100cqh; height: 100cqw; max-width: none; object-fit: cover; transform: translate(-50%, -50%) rotate(90deg); }
/* The double-tap hint: one small gold line with a thin rule on each side. */
.co-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  color: var(--sp-muted);
  font: 600 .8125rem/1.35 var(--sp-font-label);
  letter-spacing: .06em;
  text-align: center;
}
.co-hint[hidden] { display: none; }
.co-hint::before, .co-hint::after { content: ""; flex: 1 1 24px; min-width: 16px; height: 1px; background: linear-gradient(90deg, transparent, rgba(246, 183, 91, .6)); }
.co-hint::after { transform: scaleX(-1); }
/* The large picture opens full screen on a double tap. */
.co-frame--viewer { cursor: zoom-in; }
.co-frame--viewer .sp-compare { cursor: ew-resize; }

.co-story {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-space-3);
  min-width: 0;
  padding: clamp(var(--sp-space-4), 3vw, var(--sp-space-6));
  border: 1px solid var(--sp-sand);
  border-radius: var(--sp-radius-m);
  background: #fffdf8;
  color: var(--sp-ink);
  box-shadow: var(--sp-shadow-1), inset 0 0 0 4px var(--sp-ivory), inset 0 0 0 5px rgba(214, 140, 59, .3);
}
.co-story::before {
  /* small gold corner marks */
  content: "";
  position: absolute;
  inset: 8px;
  pointer-events: none;
  --c: var(--sp-gold-500);
  background:
    linear-gradient(var(--c), var(--c)) left top / 14px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left top / 2px 14px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 14px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 2px 14px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 14px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 2px 14px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 14px 2px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 2px 14px no-repeat;
  opacity: .8;
}
.co-era {
  color: var(--sp-bronze);
  font: 600 var(--sp-fs-label)/1.35 var(--sp-font-label);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.co-title {
  font-family: var(--sp-font-display);
  font-size: var(--sp-fs-h2);
  font-weight: 600;
  line-height: var(--sp-lh-tight);
  color: var(--sp-ink);
  text-wrap: balance;
}
.co-note { color: var(--sp-ink-soft); opacity: 1; font-size: var(--sp-fs-small); line-height: 1.55; max-width: 60ch; }

.co-versions__title { margin-bottom: var(--sp-space-2); color: var(--sp-bronze); font: 600 var(--sp-fs-label)/1.3 var(--sp-font-label); letter-spacing: .06em; text-transform: uppercase; }

.co-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-space-2) var(--sp-space-3); }

.co-details { border-color: rgba(112, 57, 18, .2); }
.co-details summary { font-size: 1.125rem; color: var(--sp-ink); }
.co-details summary::after { border-color: var(--sp-bronze); background:
  linear-gradient(var(--sp-bronze), var(--sp-bronze)) center / 10px 1.5px no-repeat,
  linear-gradient(var(--sp-bronze), var(--sp-bronze)) center / 1.5px 10px no-repeat; }
.co-details p { font-size: var(--sp-fs-small); line-height: 1.55; margin-bottom: var(--sp-space-2); color: var(--sp-ink); }
.co-details q { font-style: italic; }
.co-details__label { color: var(--sp-bronze); font: 600 var(--sp-fs-label)/1.3 var(--sp-font-label); letter-spacing: .06em; text-transform: uppercase; }

/* Previous and Next */
.co-step {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-space-3);
  margin-top: auto;
  padding-top: var(--sp-space-3);
  border-top: var(--sp-line) solid rgba(112, 57, 18, .2);
}
.co-step__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: var(--sp-tap);
  min-height: var(--sp-tap);
  padding: 8px 16px;
  border: var(--sp-line) solid var(--sp-bronze);
  border-radius: var(--sp-radius-round);
  background: transparent;
  color: var(--sp-ink);
  font: 600 .9375rem/1.2 var(--sp-font-label);
  position: relative;
  isolation: isolate;
}
/* Hover: a gold layer fades in (opacity only). */
.co-step__btn::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: var(--sp-gold-100); opacity: 0; transition: opacity var(--sp-dur-1) var(--sp-ease-out); }
@media (hover: hover) {
  .co-step__btn:hover::before { opacity: 1; }
  .co-step__btn:hover { color: var(--sp-ink); }
}
.co-step__arrow { width: 9px; height: 9px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: 3px; }
.co-step__btn--next .co-step__arrow { transform: rotate(-135deg); margin: 0 3px 0 0; }
.co-step__count {
  color: var(--sp-bronze);
  font-family: var(--sp-font-display);
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: .04em;
  white-space: nowrap;
}

.co-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 3. Browse: filters and the thumbnail strip */
.co-browse { padding-block: clamp(var(--sp-space-6), 6vw, var(--sp-space-8)) var(--sp-space-5); background: linear-gradient(180deg, var(--sp-paper), var(--sp-ivory) 240px); }
.co-browse__head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--sp-space-4); margin-bottom: var(--sp-space-3); }
.co-browse__title { font-family: var(--sp-font-display); font-size: var(--sp-fs-h2); font-weight: 600; line-height: var(--sp-lh-tight); text-wrap: balance; }
.co-filter__n {
  min-width: 26px;
  padding: 1px 7px;
  border-radius: var(--sp-radius-round);
  background: var(--sp-paper);
  color: var(--sp-bronze);
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.sp-filter button[aria-pressed="true"] .co-filter__n { background: var(--sp-gold-100); color: var(--sp-ink); }
.co-browse__note { color: var(--sp-muted); font-size: var(--sp-fs-small); font-style: italic; margin-bottom: var(--sp-space-4); }

.co-strip { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
/* Phones: two columns of large tiles. Larger screens: as many columns as fit. */
.co-strip__list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(100% - 2 * var(--sp-gutter), var(--sp-wrap));
  margin: 0 auto;
  padding: 6px 0;
  list-style: none;
}
.co-thumb { min-width: 0; }
.co-thumb__btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: var(--sp-tap);
  padding: 5px 5px 8px;
  border: var(--sp-line) solid var(--sp-sand);
  border-radius: 3px;
  background: #fffdf8;
  color: var(--sp-ink);
  text-align: left;
  box-shadow: var(--sp-shadow-1);
  position: relative;
  transition: transform var(--sp-dur-1) var(--sp-ease-out);
}
/* Hover: the tile lifts (transform) and a deeper shadow fades in (opacity). */
.co-thumb__btn::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: var(--sp-shadow-2); opacity: 0; pointer-events: none; transition: opacity var(--sp-dur-1) var(--sp-ease-out); }
@media (hover: hover) {
  .co-thumb__btn:hover { border-color: var(--sp-gold-500); transform: translateY(-2px); }
  .co-thumb__btn:hover::after { opacity: 1; }
}
.co-thumb__btn[aria-current="true"] {
  border-color: var(--sp-bronze);
  background: var(--sp-paper);
  box-shadow: 0 0 0 2px var(--sp-gold-300), 0 0 0 3px var(--sp-bronze), var(--sp-shadow-2);
}
.co-thumb__pic { position: relative; display: block; aspect-ratio: 4 / 3; overflow: hidden; overflow: clip; min-height: 0; background: var(--sp-paper); outline: 1px solid rgba(112, 57, 18, .25); outline-offset: -1px; }
.co-thumb__pic img { width: 100%; height: 100%; object-fit: cover; }
/* A tile picture waits to load until it comes near; until then only the paper color shows. */
.co-thumb__pic img:not([src]) { visibility: hidden; }
.co-thumb__img--top { object-position: center 18%; }
.co-thumb__btn[aria-current="true"] .co-thumb__pic::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 2px solid var(--sp-gold-300);
  pointer-events: none;
}
.co-thumb__era { color: var(--sp-bronze); font: 600 .8125rem/1.3 var(--sp-font-label); letter-spacing: .05em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.co-thumb__cap {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--sp-font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
}

/* 4. Closing row: links to the archive and the clergy portraits */
.co-close { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-space-3); padding-block: var(--sp-space-5) clamp(var(--sp-space-7), 7vw, var(--sp-space-9)); }
/* Phones: room for the bottom action bar (56 px plus the safe area). */
@media (max-width: 767px) {
  .co-close { padding-bottom: calc(var(--sp-space-7) + 56px + env(safe-area-inset-bottom)); }
  /* The filters sit in one sideways row that snaps to each button. */
  .co-browse__head { display: block; }
  .co-browse__head .co-filter {
    flex-wrap: nowrap;
    width: calc(100% + 2 * var(--sp-gutter));
    margin: var(--sp-space-3) calc(-1 * var(--sp-gutter)) 0;
    padding: 2px var(--sp-gutter) 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--sp-gutter);
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
  }
  .co-browse__head .co-filter::-webkit-scrollbar { display: none; }
  .co-filter button { flex: none; white-space: nowrap; scroll-snap-align: start; }
}

/* 5. Larger screens */
@media (min-width: 1000px) {
  .co-stage { padding-top: var(--sp-space-6); }
  .co-intro { margin-bottom: var(--sp-space-5); }
  .co-viewer { grid-template-columns: auto minmax(320px, 400px); justify-content: center; align-items: center; gap: var(--sp-space-7); }
  .co-stage .co-frame.sp-frame { width: min(720px, calc(64svh * var(--w) / var(--h)), calc(min(var(--sp-wrap), 100vw - 2 * var(--sp-gutter)) - 320px - var(--sp-space-7))); }
  .co-story { position: sticky; top: calc(var(--sp-header-h) + var(--sp-space-4)); }
}
@media (min-width: 768px) {
  .co-strip__list { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-space-3); }
}

@media (prefers-reduced-motion: reduce) {
  .co-thumb__btn, .co-thumb__btn::after, .co-step__btn::before { transition: none; }
  .co-thumb__btn:hover { transform: none; }
}

/* Phones: centered (Coach 2026-10-06) */
@media (max-width: 699px) {
  .co-story { text-align: center; }
  .co-note { margin-inline: auto; }
  .co-versions .sp-filter, .co-actions { justify-content: center; }
  /* Previous and Next stay at the two sides; the counter sits in the middle. */
  .co-step { display: grid; grid-template-columns: 1fr auto 1fr; }
  .co-step__btn { justify-self: start; }
  .co-step__btn--next { justify-self: end; }
  /* The source notes are long reading text with a label: kept left. */
  .co-details { text-align: left; }
  .co-browse__head, .co-browse__note { text-align: center; }
  .co-browse__head .co-filter { justify-content: safe center; }
  .co-thumb__btn { text-align: center; }
}

/* Motion (all inside no-preference; the still page is the final state). */
@media (prefers-reduced-motion: no-preference) {
  /* Press */
  .co-thumb__btn:active { transform: scale(.98); transition-duration: 100ms; }
  .co-step__btn { transition: transform 100ms var(--sp-ease-out); }
  .co-step__btn:active { transform: scale(.97); }

  /* Turning to the next photograph: the label, title, and count arrive in turn. */
  .co-viewer--turn .co-era, .co-viewer--turn .co-title, .co-viewer--turn .co-step__count { animation: co-turn-in 360ms var(--sp-ease-out) both; }
  .co-viewer--turn .co-title { animation-delay: 50ms; }
  .co-viewer--turn .co-step__count { animation-delay: 100ms; }
  @keyframes co-turn-in { from { opacity: 0; transform: translateY(8px); } }

  /* Signature: the contact sheet develops with the scroll. The old print turns into today's color
     and settles, while a warm band of safelight passes down over it. */
  @supports (animation-timeline: view()) {
    .co-thumb__pic img {
      animation: co-develop linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 45%;
    }
    @keyframes co-develop {
      from { filter: grayscale(1) sepia(.45) contrast(.92) brightness(1.06); transform: scale(1.06); }
      to { filter: none; transform: none; }
    }
    .co-thumb__pic::before {
      content: "";
      position: absolute;
      inset: -40% 0 auto;
      height: 40%;
      z-index: 1;
      pointer-events: none;
      background: linear-gradient(180deg, transparent, rgba(250, 223, 162, .55), transparent);
      opacity: 0;
      animation: co-light linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 45%;
    }
    @keyframes co-light {
      0% { transform: translateY(0); opacity: 0; }
      20% { opacity: 1; }
      100% { transform: translateY(350%); opacity: 0; }
    }
  }
}
