:root {
  --bg: #f4f4f2;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --tile: #e2e2de;
  --accent: #c8102e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --fg: #ececea;
    --muted: #9a9a95;
    --tile: #262626;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
  padding: 32px 16px 20px;
  text-align: center;
}
header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.4rem, 4vw, 2.2rem);
  letter-spacing: .02em;
}
header h1::after {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  margin: 10px auto 0;
  background: var(--accent);
}
header p { margin: 0; color: var(--muted); }

/* justified rows: read left-to-right in file order, every photo keeps its
   aspect ratio (--r = width/height, set per tile) and rows share one height */
.grid {
  --row: 240px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 40px;
  max-width: 1600px;
  margin: 0 auto;
}
.grid::after { content: ""; flex-grow: 999999; } /* keeps the last row unstretched */
.tile {
  display: block;
  flex-grow: calc(var(--r) * 100);
  flex-basis: calc(var(--r) * var(--row));
  min-width: 0; /* else the 600px thumbnail sets the minimum */
  aspect-ratio: var(--r);
  background: var(--tile);
  border-radius: 4px;
  overflow: hidden;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .25s ease, opacity .25s ease;
}
.tile:hover img, .tile:focus-visible img { transform: scale(1.03); opacity: .92; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 48px; /* room for .lb-bar */
  background: rgba(0, 0, 0, .94);
  touch-action: pan-y pinch-zoom;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100vw;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  object-fit: contain;
  user-select: none;
}
.lightbox button {
  position: absolute;
  border: 0;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  font-size: 2.4rem;
  line-height: 1;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
}
.lightbox button:hover { background: rgba(255, 255, 255, .2); }
.lb-close { top: 12px; right: 12px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lb-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  color: #ccc;
  font-size: .95rem;
}
.lb-bar a { color: #fff; }

@media (max-width: 600px) {
  .grid { --row: 130px; gap: 6px; padding: 6px 6px 32px; }
  .lb-prev, .lb-next { display: none; } /* swipe instead */
}
