:root {
  --bg: #faf9f7;
  --ink: #171614;
  --muted: #8a857c;
  --gap: 22px;
  --viewer-bg: rgba(250, 249, 247, 0.985);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --ink: #eceae5;
    --muted: #8a857c;
    --viewer-bg: rgba(12, 12, 11, 0.985);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.locked { overflow: hidden; }

/* ---------- Masthead ---------- */

.masthead {
  padding: clamp(48px, 9vw, 110px) clamp(20px, 5vw, 64px) clamp(34px, 6vw, 70px);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(21px, 2.4vw, 27px);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

main {
  padding: 0 clamp(20px, 5vw, 64px) clamp(60px, 10vw, 130px);
}

/* ---------- Grid (masonry via CSS columns — no cropping) ---------- */

.grid {
  columns: 3;
  column-gap: var(--gap);
}

@media (max-width: 1000px) { .grid { columns: 2; } }
@media (max-width: 600px)  { .grid { columns: 1; --gap: 16px; } }

.tile {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  margin: 0 0 var(--gap);
  background: none;
  cursor: zoom-in;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  line-height: 0;
  border-radius: 2px;
  overflow: hidden;
}

.tile img {
  width: 100%;
  height: auto;
  display: block;
  opacity: 0;
  transition: opacity .5s ease, transform .5s cubic-bezier(.2,.7,.3,1);
}

.tile img.ready { opacity: 1; }

@media (hover: hover) {
  .tile:hover img.ready { transform: scale(1.018); }
}

.tile:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 5px;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  max-width: 46ch;
}

.empty a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.empty code {
  font-size: .92em;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ---------- Viewer ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--viewer-bg);
  -webkit-backdrop-filter: blur(22px);
  backdrop-filter: blur(22px);
  opacity: 0;
  transition: opacity .25s ease;
}

.viewer.open { opacity: 1; }
.viewer[hidden] { display: none; }

/* Horizontal scroll-snap rail: swipe, trackpad, or arrow keys */
.track {
  height: 100%;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
}

.track::-webkit-scrollbar { display: none; }

/* While zoomed in, lock the rail so dragging pans instead of paging */
.viewer.zoomed .track {
  overflow-x: hidden;
  scroll-snap-type: none;
}

.slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  /* Flex (not grid) so the image's max-height:100% has a definite box to
     resolve against — an auto grid row would just grow to the image. */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(28px, 6vh, 76px) clamp(16px, 7vw, 104px);
  overflow: hidden;
}

.slide img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  cursor: zoom-in;
  transform-origin: center center;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.slide.is-zoomed img { cursor: grab; }
.slide.is-zoomed img.grabbing { cursor: grabbing; }

/* ---------- Viewer chrome ---------- */

.nav, .close {
  position: fixed;
  border: 0;
  background: none;
  color: var(--ink);
  padding: 12px;
  cursor: pointer;
  opacity: .42;
  transition: opacity .2s ease;
  line-height: 0;
}

.nav:hover, .close:hover, .nav:focus-visible, .close:focus-visible { opacity: 1; }

.nav svg, .close svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav { top: 50%; transform: translateY(-50%); }
.prev { left: max(8px, env(safe-area-inset-left)); }
.next { right: max(8px, env(safe-area-inset-right)); }
.nav[disabled] { opacity: .1; cursor: default; }

.close {
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
}

.chrome {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 14px;
  pointer-events: none;
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 16px;
}

.caption { color: var(--ink); opacity: .72; }

/* Hide side arrows on touch — swiping is the gesture there */
@media (hover: none) {
  .nav { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .track { scroll-behavior: auto; }
}
