/* Contact sheet, loupe and lightbox.
   The sheet is a 35 mm contact print on its paper ground: film cells sit side by side like one strip,
   sprocket holes show the paper through the film, edge print and frame numbers are in the film's amber,
   and a circled frame gets a grease-pencil loop. The lightbox is a dark full-screen viewer. */

.section--sheet { background: var(--paper-2); }

/* ---------- filter toolbar ---------- */

.sheet-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.sheet-filter,
.loupe-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid color-mix(in srgb, var(--ink) 50%, var(--paper-2));
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}
.sheet-filter[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.loupe-toggle { margin-left: auto; }
.loupe-toggle::before {
  content: "";
  width: 0.625rem;
  height: 0.625rem;
  border: 1px solid currentColor;
  border-radius: 50%;
}
.loupe-toggle[aria-pressed="true"]::before { background: currentColor; }
@media (hover: hover) and (pointer: fine) {
  .sheet-filter:hover,
  .loupe-toggle:hover { border-color: var(--ink); }
}

.sheet-count {
  font-size: var(--step--1);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}
.sheet-hint {
  margin: var(--space-1) 0 var(--space-5);
  color: var(--ink-2);
  font-size: var(--step--1);
}

/* ---------- the sheet: 2 frames a row on phones, 3 on tablets, 6 on desktop ---------- */

.sheet {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 0;              /* film cells touch, like one strip */
  row-gap: var(--space-5);    /* paper between the strips */
  margin: 0;
  padding: 0;
  list-style: none;
}
@media (min-width: 700px) {
  .sheet { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .sheet { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
/* during a filter change the sheet holds its new height; frames move and fade inside it */
.sheet.is-flipping { overflow: hidden; overflow: clip; }

/* quick taps on small buttons never turn into a double-tap zoom; pinch-zoom still works */
.sheet-filter,
.loupe-toggle,
.frame__mark,
.lightbox__btn,
.lightbox__nav { touch-action: manipulation; }

/* one film cell, top to bottom: edge print, sprocket holes, photo, sprocket holes, frame number.
   Eight holes per frame, as on 35 mm film, so the holes line up across touching cells. */
.frame {
  --edge-h: 18px;
  --holes-h: 12px;
  --hole: 6px;
  --num-h: 28px;
  --gutter: 6px;
  --holes: repeating-linear-gradient(90deg, transparent 0 3%, var(--paper-2) 3% 9.5%, transparent 9.5% 12.5%);
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--edge-h) var(--holes-h) auto var(--holes-h) var(--num-h);
  background-color: var(--film);
  background-image: var(--holes), var(--holes);
  background-size: 100% var(--hole);
  background-repeat: no-repeat;
  background-position:
    left 0 top calc(var(--edge-h) + (var(--holes-h) - var(--hole)) / 2),
    left 0 bottom calc(var(--num-h) + (var(--holes-h) - var(--hole)) / 2);
}
/* a frame leaving during a filter change; gallery.js sets `hidden` once Flip has faded it out */
.frame.is-out { display: none; }

.frame__edge {
  grid-row: 1;
  align-self: center;
  overflow: hidden;
  padding: 0 var(--space-2);
  color: var(--edgeprint);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  line-height: 1;
  white-space: nowrap;
}

.frame__open {
  grid-row: 3;
  position: relative;
  display: block;
  margin: 0 var(--gutter);
  padding: 0;
  border: 0;
  border-radius: 1px;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--film);
  cursor: zoom-in;
}
.frame__open:focus-visible { outline: 2px solid var(--edgeprint); outline-offset: 2px; }
.frame__img { width: 100%; height: 100%; object-fit: cover; }
/* a vertical photo stands whole in the frame, with film either side */
.frame--portrait .frame__img { width: auto; max-width: 100%; margin-inline: auto; object-fit: contain; }

/* the grease-pencil loop over a circled frame (paper halo under the red so it reads on any photo) */
.frame__circle {
  position: absolute;
  top: calc(var(--edge-h) + var(--holes-h));
  left: var(--gutter);
  z-index: 1;
  width: calc(100% - 2 * var(--gutter));
  height: auto;
  aspect-ratio: 3 / 2;
  overflow: visible;
  pointer-events: none;
  visibility: hidden;
  transform: rotate(var(--tilt, -2deg));
}
.frame.has-circle .frame__circle { visibility: visible; }
.frame__circle path { fill: none; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 2; }
/* widths are in the loop's own units (150 across the photo), set per layout so the red line
   stays close to 3 px on screen with about 2 px of paper on each side */
.frame { --ink-w: 2.6px; --halo-w: 6.2px; }
@media (min-width: 500px) {
  .frame { --ink-w: 1.7px; --halo-w: 4.6px; }
}
@media (min-width: 1100px) {
  .frame { --ink-w: 2.4px; --halo-w: 5.6px; }
}
.frame__halo { stroke: var(--paper); stroke-width: var(--halo-w); }
.frame__ink { stroke: var(--grease); stroke-width: var(--ink-w); }

.frame__base {
  grid-row: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gutter);
}
/* the frame number is the circle button */
.frame__mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: var(--num-h);
  padding: 0 var(--space-3);
  border: 0;
  background: none;
  color: var(--edgeprint);
  font-size: var(--step--1);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  line-height: 1;
  cursor: pointer;
}
/* 44 px to tap: the hit area reaches up over the sprocket band and a little into the paper below */
.frame__mark::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(-1 * var(--holes-h));
  bottom: -6px;
}
/* a grease ring around a circled number */
.frame__mark::after {
  content: "";
  position: absolute;
  inset: 3px 2px;
  border: 2px solid var(--grease);
  border-radius: 50%;
  opacity: 0;
  transform: rotate(-8deg) scale(0.7);
  transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
  pointer-events: none;
}
.frame__mark[aria-pressed="true"] { color: var(--paper); }
.frame__mark[aria-pressed="true"]::after { opacity: 1; transform: rotate(-8deg) scale(1); }
.frame__mark:focus-visible { outline: 2px solid var(--edgeprint); outline-offset: 0; }
@media (hover: hover) and (pointer: fine) {
  .frame__mark:not([aria-pressed="true"]):hover::after {
    border-style: dashed;
    border-color: var(--edgeprint);
    opacity: 0.8;
    transform: rotate(-8deg) scale(1);
  }
}
.frame__half {
  padding-right: var(--space-2);
  color: var(--edgeprint);
  font-size: 0.625rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2em;
}
.frame__half::before { content: "\25B8\00A0"; }

/* ---------- "3 frames circled · Add to your message" ---------- */

.marked-pill { z-index: 26; }
html.has-dialog .marked-pill { display: none; }
.marked-pill__link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: 0 var(--space-5);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-decoration: none;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--film) 24%, transparent);
}
.marked-pill__icon { flex: none; width: 1.75rem; height: 1.125rem; overflow: visible; }
.marked-pill__icon ellipse { fill: none; stroke: var(--grease); stroke-width: 2.5px; }

@media (max-width: 699px) {
  /* phones: fixed above the home indicator; gallery.js hides it while the planner is on screen */
  .marked-pill {
    position: fixed;
    left: max(16px, env(safe-area-inset-left, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }
  .marked-pill.is-near-planner,
  .marked-pill.is-away { display: none; }
  /* keyboard focus never lands underneath the pill */
  html:has(.marked-pill:not([hidden]):not(.is-near-planner)) {
    scroll-padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}
@media (min-width: 700px) {
  /* sticky inside the section; zero height, so showing it never moves the page */
  .marked-pill {
    position: sticky;
    bottom: calc(48px + 2 * var(--space-5) + env(safe-area-inset-bottom, 0px));
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: 0;
  }
  .marked-pill__link { margin-top: var(--space-5); }
}

/* ---------- loupe: fine pointers only, never in the way of a click ---------- */

.loupe {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 25;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background-color: var(--film);
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 2px var(--paper), 0 0 0 1px var(--ink), 0 12px 32px color-mix(in srgb, var(--film) 30%, transparent);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 150ms var(--ease-out), visibility 0s linear 150ms;
}
.loupe.is-on {
  opacity: 1;
  visibility: visible;
  will-change: transform;
  transition: opacity 150ms var(--ease-out), visibility 0s;
}

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--film);
  color: var(--paper);
}
.lightbox :focus-visible { outline-color: var(--paper); }

.lightbox__top,
.lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.lightbox__top { padding-top: calc(var(--space-2) + env(safe-area-inset-top, 0px)); padding-bottom: var(--space-2); }
.lightbox__bar { padding-top: var(--space-2); padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px)); }

.lightbox__count {
  color: var(--edgeprint);
  font-size: var(--step--1);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
/* only the visible "3 of 12" is set in caps; the hidden description keeps normal case for screen readers */
.lightbox__pos { letter-spacing: var(--track-caps); text-transform: uppercase; }

.lightbox__btn,
.lightbox__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid color-mix(in srgb, var(--paper) 40%, var(--film));
  border-radius: var(--radius);
  background: transparent;
  color: var(--paper);
  font-size: var(--step--1);
  font-weight: 500;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color var(--dur-ui) var(--ease-out), opacity var(--dur-ui) var(--ease-out);
}
.lightbox__nav { width: 48px; height: 48px; padding: 0; border-radius: 50%; }
.lightbox__nav[aria-disabled="true"] { opacity: 0.35; cursor: default; }
.lightbox__arrow { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5px; stroke-linecap: round; stroke-linejoin: round; }
.lightbox__ring { width: 22px; height: 14px; overflow: visible; }
.lightbox__ring ellipse { fill: none; stroke: currentColor; stroke-width: 1.5px; }
.lightbox__mark[aria-pressed="true"] { border-color: var(--grease); }
.lightbox__mark[aria-pressed="true"] .lightbox__ring ellipse { stroke: var(--grease); stroke-width: 3px; }
@media (hover: hover) and (pointer: fine) {
  .lightbox__btn:not([aria-pressed="true"]):hover,
  .lightbox__nav:not([aria-disabled="true"]):hover { border-color: var(--paper); }
}

/* the track: native horizontal scroll with snapping, one frame per swipe; pinch-zoom stays on */
.lightbox__track {
  position: relative;
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.lightbox__track::-webkit-scrollbar { display: none; }
.lightbox__slide {
  --lb-cap: 3.5rem;
  flex: 0 0 100%;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: var(--space-3) max(16px, env(safe-area-inset-right, 0px)) var(--space-2) max(16px, env(safe-area-inset-left, 0px));
  scroll-snap-align: center;
  scroll-snap-stop: always;
  container-type: size;
}
.lightbox__figure { display: grid; justify-items: center; max-width: 100%; margin: 0; }
/* the photo box takes the photo's own proportions before it loads, so nothing jumps */
.lightbox__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 14rem);
  object-fit: contain;
}
@supports (width: 1cqh) {
  .lightbox__img {
    width: min(100cqw, calc((100cqh - var(--lb-cap)) * var(--ar, 1.5)));
    max-width: none;
    max-height: none;
    aspect-ratio: var(--ar, 1.5);
  }
}
.lightbox__cap {
  max-width: 60ch;
  margin-top: var(--space-3);
  color: color-mix(in srgb, var(--paper) 82%, var(--film));
  font-size: var(--step--1);
  letter-spacing: 0.04em;
  line-height: 1.4;
  text-align: center;
}
.lightbox__no { position: relative; display: inline-block; font-variant-numeric: tabular-nums; }
.lightbox__no::after {
  content: "";
  position: absolute;
  inset: -0.35em -0.6em;
  border: 2px solid var(--grease);
  border-radius: 50%;
  opacity: 0;
  transform: rotate(-6deg) scale(0.8);
  transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
}
.lightbox__slide.is-circled .lightbox__no::after { opacity: 1; transform: rotate(-6deg) scale(1); }
.lightbox__keys {
  display: none;
  color: color-mix(in srgb, var(--paper) 70%, var(--film));
  font-size: var(--step--2);
  letter-spacing: 0.06em;
}

@media (min-width: 900px) {
  .lightbox__slide {
    padding-left: calc(48px + 2 * var(--space-5));
    padding-right: calc(48px + 2 * var(--space-5));
  }
  .lightbox__nav { position: absolute; top: 50%; margin-top: -24px; }
  .lightbox__nav--prev { left: max(var(--space-5), env(safe-area-inset-left, 0px)); }
  .lightbox__nav--next { right: max(var(--space-5), env(safe-area-inset-right, 0px)); }
  /* the bar is not positioned, so Prev and Next centre on the photo against the fixed lightbox */
  .lightbox__bar { justify-content: center; }
}
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .lightbox__keys { display: block; position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); pointer-events: none; }
}
