:root {
  --bg: #ffffff;
  --bg-elev: #f3f3f3;
  --fg: #111111;
  --fg-dim: #6b6b6b;
  --border: #e5e5e5;
  --accent: #111111;
  --gap: 8px;
  --row-radius: 4px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main#grid {
  flex: 1 0 auto;
}

.footer {
  flex-shrink: 0;
  margin-top: 40px;
  padding: 24px 16px;
  text-align: center;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
  border-top: 1px solid var(--border);
}

.footer p { margin: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 20px 24px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#grid {
  padding: 18px 16px 0;
}

@media (max-width: 700px) {
  #grid { padding: 12px 10px 0; }
}

.row {
  display: flex;
  flex-direction: row;
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.tile {
  position: relative;
  margin: 0;
  background: var(--bg-elev);
  border-radius: var(--row-radius);
  overflow: hidden;
  cursor: zoom-in;
  flex-shrink: 0;
  transition: transform 160ms ease, box-shadow 160ms ease;
  outline: none;
}

.tile:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 320ms ease;
}

.tile.loaded img { opacity: 1; }

@media (hover: hover) {
  .tile:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
  .tile:hover .dl { opacity: 1; transform: scale(1); }
}

.dl {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  text-decoration: none;
  opacity: 0.92;
  transform: scale(0.96);
  transition: opacity 140ms ease, transform 140ms ease, background-color 140ms ease;
  cursor: pointer;
  z-index: 1;
}
.dl:hover, .dl:focus-visible {
  opacity: 1;
  transform: scale(1);
  background: #fff;
  outline: none;
}
.dl:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.dl svg { width: 18px; height: 18px; pointer-events: none; }

@media (hover: none) {
  .dl { opacity: 1; transform: scale(1); }
}

/* Lightbox stays dark for distraction-free viewing.
   Layout note: the image is position:fixed and sized explicitly by JS.
   This lets us change the actual rendered dimensions when zooming so the
   browser re-rasterizes from the original source (sharp, real pixels)
   instead of stretching a cached downscaled raster (which looks pixelated). */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.96);
  opacity: 0;
  transition: opacity 180ms ease;
  color: #fff;
  overflow: hidden;
}
.lightbox[hidden] { display: none; }
.lightbox.open { opacity: 1; }

/* The stage wrapper is no longer doing layout work - just a semantic group. */
.lb-stage {
  margin: 0;
}

.lb-img {
  position: fixed;
  /* width, height, left, top are set by JS (both "fit" and "zoomed" states) */
  max-width: none;
  max-height: none;
  background: #111;
  opacity: 0;
  transition: opacity 220ms ease;
  cursor: zoom-in;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  z-index: 51;
}
.lb-img.loaded { opacity: 1; }
.lb-img.smooth {
  transition:
    opacity 220ms ease,
    transform 240ms cubic-bezier(.2,.7,.2,1),
    width 280ms cubic-bezier(.2,.7,.2,1),
    height 280ms cubic-bezier(.2,.7,.2,1),
    left 280ms cubic-bezier(.2,.7,.2,1),
    top 280ms cubic-bezier(.2,.7,.2,1);
}
.lb-img.zoomed { cursor: grab; }
.lb-img.dragging {
  cursor: grabbing;
  /* Disable all transitions while the finger is dragging so the image
     tracks the touch instantly. */
  transition: none;
}
.lb-img:not(.loaded) { cursor: default; }

.lb-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  margin: -18px 0 0 -18px;
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 52;
}
.lb-spinner.visible { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.lb-caption {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 52;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.lb-btn {
  position: fixed;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 140ms ease, transform 140ms ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 53;
}
.lb-btn:hover, .lb-btn:focus-visible {
  background: rgba(255, 255, 255, 0.22);
  outline: none;
}
.lb-btn:focus-visible { box-shadow: 0 0 0 2px #fff; }
.lb-btn svg { width: 22px; height: 22px; }

.lb-close    { top: 18px; right: 18px; }
.lb-download { top: 18px; right: 72px; }
.lb-prev     { left: 18px; top: 50%; transform: translateY(-50%); }
.lb-next     { right: 18px; top: 50%; transform: translateY(-50%); }
.lb-prev:hover, .lb-prev:focus-visible { transform: translateY(-50%) scale(1.04); }
.lb-next:hover, .lb-next:focus-visible { transform: translateY(-50%) scale(1.04); }

/* "Denoised Image" pill - sits at the bottom-center of the lightbox, just
   above the (#/total) caption. Only shown when the current photo's manifest
   entry has denoised:true (set by JS). Clicking opens the archived previous-
   version original (the "denoised" file) in a new tab. */
.lb-denoised {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.04em;
  font-weight: 500;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color 140ms ease, transform 140ms ease;
  z-index: 53;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.lb-denoised:hover,
.lb-denoised:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  outline: none;
  transform: translateX(-50%) scale(1.03);
}
.lb-denoised:focus-visible { box-shadow: 0 0 0 2px #fff; }
.lb-denoised svg { width: 14px; height: 14px; }
.lb-denoised[hidden] { display: none; }

@media (max-width: 540px) {
  .lb-btn { width: 40px; height: 40px; }
  .lb-close    { top: 12px; right: 12px; }
  .lb-download { top: 12px; right: 60px; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
  .lb-denoised {
    bottom: 48px;
    padding: 9px 14px;
    font-size: 12px;
  }
}

body.lb-open { overflow: hidden; }
