:root {
  --gap: 12px;
  --radius: 14px;
  --bg: #fff;
  --fg: #111;
  --muted: #6b6b6b;
  --tile: #ececec;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #eee;
    --muted: #9a9a9a;
    --tile: #232323;
  }
}

@media (max-width: 600px) {
  :root {
    --gap: 6px;
    --radius: 10px;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Stop the page scrolling behind the open viewer. */
body:has(dialog[open]) { overflow: hidden; }

header {
  padding: calc(20px + env(safe-area-inset-top)) var(--gap) 14px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
}

#empty {
  text-align: center;
  color: var(--muted);
  padding: 0 16px;
}

/* ---------- Masonry grid (columns are filled by gallery.js) ---------- */

#grid {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  max-width: 1800px;
  margin: 0 auto;
  padding: 0 var(--gap) calc(var(--gap) + env(safe-area-inset-bottom));
}

.col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--tile);
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.tile img,
.tile video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.tile:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
}

/* Date label, shown on hover with a mouse. */
.tile .date {
  position: absolute;
  inset: auto 0 0 0;
  padding: 24px 10px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  color: #fff;
  font-size: 0.8rem;
  text-align: left;
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .tile:hover img,
  .tile:hover video { transform: scale(1.03); }
  .tile:hover .date,
  .tile:focus-visible .date { opacity: 1; }
}

/* Play badge on video tiles. */
.tile .play {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
}

.tile .play::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 8px;
  border-style: solid;
  border-width: 7px 0 7px 11px;
  border-color: transparent transparent transparent #fff;
}

/* ---------- Full-screen viewer ---------- */

#lightbox {
  margin: 0;
  padding: 0;
  border: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  background: rgba(0, 0, 0, 0.95);
  color: #fff;
  overflow: hidden;
}

#lightbox::backdrop { background: rgba(0, 0, 0, 0.95); }

.lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(56px + env(safe-area-inset-top))
    calc(64px + env(safe-area-inset-right))
    calc(44px + env(safe-area-inset-bottom))
    calc(64px + env(safe-area-inset-left));
}

.lb-stage img,
.lb-stage video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lb-caption {
  position: absolute;
  inset: auto 0 0 0;
  margin: 0;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.9rem;
  color: #bbb;
  pointer-events: none;
}

.lb-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.lb-btn:hover { background: rgba(255, 255, 255, 0.26); }
.lb-btn[hidden] { display: none; }

.lb-close {
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
}

.lb-prev,
.lb-next {
  top: 50%;
  transform: translateY(-50%);
}

.lb-prev { left: calc(10px + env(safe-area-inset-left)); }
.lb-next { right: calc(10px + env(safe-area-inset-right)); }

/* On phones the media uses the full width; swipe to move, buttons sit low. */
@media (max-width: 600px) {
  .lb-stage {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .lb-prev,
  .lb-next {
    top: auto;
    bottom: calc(4px + env(safe-area-inset-bottom));
    transform: none;
  }
}
