:root {
  color-scheme: light dark;
  --paper: #faf7f2;
  --ink: #1f1a17;
  --muted: #6f6660;
  --accent: #a3202c;
  --tile: #ece6dd;
  --gap: 8px;
  --row: 300px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141210;
    --ink: #f4efe8;
    --muted: #a59c94;
    --accent: #e8737c;
    --tile: #26221f;
  }
}

@media (max-width: 640px) {
  :root {
    --gap: 4px;
    --row: 180px;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 Inter, system-ui, sans-serif;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.intro {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(48px, 9vw, 104px) 20px clamp(32px, 5vw, 56px);
  text-align: center;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font: 400 clamp(44px, 9vw, 84px)/1.05 Fraunces, Georgia, serif;
  letter-spacing: -.02em;
}

.summary {
  margin: 20px auto 0;
  max-width: 44ch;
  color: var(--muted);
}

/* Justified rows: each tile grows in proportion to its aspect ratio, so rows stay level. */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  padding: 0 var(--gap) 48px;
}

.grid::after {
  content: "";
  flex: 9999 0 0;
}

.tile {
  position: relative;
  flex: var(--ratio) 0 calc(var(--ratio) * var(--row));
  align-self: flex-start;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  background: var(--tile);
}

.tile-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}

.tile-open:focus-visible {
  outline-offset: -4px;
}

.tile img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: var(--ratio);
  object-fit: cover;
  opacity: 0;
  transition: opacity .4s ease, transform .6s ease;
}

.tile img.loaded { opacity: 1; }

.tile-save {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgb(20 18 16 / .62);
  color: #fff;
  backdrop-filter: blur(6px);
  transition: opacity .2s ease, background .2s ease;
}

.tile-save:hover { background: var(--accent); }

@media (hover: hover) {
  .tile:hover img { transform: scale(1.025); }
  .tile-save { opacity: 0; }
  .tile:hover .tile-save,
  .tile-save:focus-visible { opacity: 1; }
}

html:has(.viewer[open]) { overflow: hidden; }

.viewer button,
.viewer a { touch-action: manipulation; }

.viewer {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  height: 100dvh; /* The visible area, excluding a phone browser's toolbars. */
  max-height: none;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  margin: 0;
  padding: 0;
  border: 0;
  background: #0d0c0b;
  color: #f4efe8;
  color-scheme: dark;
  --accent: #e8737c;
}

.viewer:focus { outline: none; }

.viewer[open] {
  display: flex;
  flex-direction: column;
}

.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}

.position {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: #c9c1b9;
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  background: #f4efe8;
  color: #1f1a17;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background .2s ease;
}

.pill:hover { background: #fff; }

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / .1);
  color: inherit;
  cursor: pointer;
  transition: background .2s ease;
}

.icon-button:hover { background: rgb(255 255 255 / .22); }
.icon-button:disabled { visibility: hidden; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 0 16px;
  overflow: hidden;
}

.viewer-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

#viewer-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: zoom-in;
}

#viewer-image.zoomed { cursor: grab; }
#viewer-image.dragging { cursor: grabbing; }
#viewer-image.smooth { transition: transform .22s ease; }

.zoom {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 999px;
  background: rgb(255 255 255 / .1);
}

.zoom .icon-button { background: none; }
.zoom .icon-button:hover { background: rgb(255 255 255 / .16); }
.zoom .icon-button:disabled {
  visibility: visible;
  opacity: .35;
  cursor: default;
}

.zoom-level {
  min-width: 56px;
  height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: inherit;
  font: 500 14px/1 Inter, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* Short screens, such as a phone on its side: give the photo as much height as possible. */
@media (max-height: 480px) {
  .viewer-bar { padding: 4px 12px; }
  .viewer-tools { padding: 4px 12px calc(4px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  .stage { padding: 0; }
  .tile-save {
    right: 6px;
    bottom: 6px;
    width: 34px;
    height: 34px;
  }
  .tile-save svg {
    width: 17px;
    height: 17px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .eyebrow,
  h1,
  .summary {
    animation: rise .9s cubic-bezier(.22, 1, .36, 1) backwards;
  }

  h1 { animation-delay: .1s; }
  .summary { animation-delay: .22s; }

  .tile {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity .7s ease var(--delay, 0s), transform .9s cubic-bezier(.22, 1, .36, 1) var(--delay, 0s);
  }

  .tile.revealed {
    opacity: 1;
    transform: none;
  }

  /* A soft sweep shows a photo is on its way; it stops once the image arrives. */
  .tile:not(:has(img.loaded)) {
    background-image: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .28) 50%, transparent 70%);
    background-size: 220% 100%;
    animation: shimmer 1.6s linear infinite;
  }

  .tile-save svg { transition: transform .25s ease; }
  .tile-save:hover svg { transform: translateY(2px); }
  .pill,
  .icon-button { transition: background .2s ease, transform .15s ease; }
  .pill:active,
  .icon-button:active { transform: scale(.94); }

  .viewer[open] { animation: fade-in .25s ease; }
  .viewer.closing { animation: fade-out .2s ease forwards; }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes fade-out {
  to { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
