:root {
  --bg: #111;
  --fg: #e8e6e3;
  --muted: #8d8a85;
  --accent: #fff;
  --gap: 6px;
  --row: 260px; /* a row of photos' height, before it's stretched to fill the width */
  --side: clamp(12px, 3vw, 40px);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

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

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 28px;
  padding: 28px var(--side) 20px;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

h1 a { color: inherit; text-decoration: none; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

.tabs a {
  color: var(--muted);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
}

.tabs a:hover { color: var(--fg); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: currentColor; }

main { padding: 0 var(--side) 48px; }

.note { color: var(--muted); }

/* Justified rows: each photo starts at the row's height and grows in
   proportion to its width, so every photo in a row ends up the same height.
   The filler at the end keeps the last row from being stretched. */
.grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.grid::after {
  content: "";
  flex-grow: 1000000;
}

.cell {
  flex: var(--ratio) 1 calc(var(--ratio) * var(--row));
  display: block;
  min-width: 0;
  background: #1c1c1c;
  overflow: hidden;
}

.cell img {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity 0.2s;
}

.cell:hover img { opacity: 0.85; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The viewer: one photo, as large as fits. */
.viewer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.96);
  color: var(--fg);
  overscroll-behavior: contain;
  touch-action: pan-y pinch-zoom;
}

.viewer::backdrop { background: rgba(0, 0, 0, 0.96); }

.viewer-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 64px;
}

@media (max-width: 600px) {
  .viewer-stage { padding: 44px 0; }
}

.viewer-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer button {
  position: absolute;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}

.viewer button:hover, .viewer button:focus-visible { color: var(--accent); }
.viewer button:focus-visible { outline: 1px solid currentColor; }

.viewer-prev, .viewer-next {
  top: 50%;
  translate: 0 -50%;
  width: 56px;
  height: 96px;
  font-size: 60px;
  line-height: 1;
}

.viewer-prev { left: 4px; }
.viewer-next { right: 4px; }

.viewer-close {
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  font-size: 20px;
}

.viewer-count {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* On a phone, swiping does the stepping; the arrows would cover the photo. */
@media (hover: none) and (max-width: 600px) {
  .viewer-prev, .viewer-next { display: none; }
}
