:root {
  --bg: #fbfbfa;
  --fg: #171717;
  --muted: #8a8a85;
  --line: #e7e7e3;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --fg: #ececea;
    --muted: #85857f;
    --line: #262626;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.wrap {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
}

/* header */

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-top: 28px;
  padding-bottom: 28px;
}

.top .name { font-weight: 500; }

.top nav { display: flex; gap: 20px; }

.top nav a { color: var(--muted); transition: color .15s; }

.top nav a:hover,
.top nav a[aria-current="page"] { color: var(--fg); }

main { flex: 1; }

/* about */

.about {
  max-width: 560px;
  margin: 0;
  padding-top: 14vh;
  padding-bottom: 14vh;
}

.about p { margin: 0 0 1.1em; }

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

/* photos: masonry columns (viewer.js deals photos into --cols columns) */

.grid {
  --cols: 2;
  --gap: 8px;
  columns: var(--cols);
  column-gap: var(--gap);
  padding-top: 4px;
  padding-bottom: 40px;
}

@media (min-width: 700px) {
  .grid { --cols: 3; --gap: 12px; }
}

@media (min-width: 1024px) {
  .grid { --cols: 4; --gap: 16px; }
}

.grid.masonry {
  display: flex;
  align-items: flex-start;
  gap: var(--gap);
  columns: auto;
}

.grid .col { flex: 1 1 0; min-width: 0; }

.grid figure {
  position: relative;
  margin: 0 0 var(--gap);
  break-inside: avoid;
}

.grid a {
  display: block;
  background: var(--line);
  cursor: pointer;
  outline: none;
}

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

.grid a:hover img { opacity: .9; }

.grid a:focus-visible img { opacity: .7; }

/* Captions sit on the photo and fade in on hover (or keyboard focus),
   so they never change the spacing of the grid. */
.grid figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 32px 12px 10px;
  font-size: 13px;
  line-height: 1.45;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  background: linear-gradient(to top, rgba(0, 0, 0, .62), rgba(0, 0, 0, 0));
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.grid figure:hover figcaption,
.grid a:focus-visible + figcaption { opacity: 1; }

/* viewer */

.viewer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  overflow: hidden;
}

/* The photo grid stays faintly visible behind the viewer, darkened and blurred,
   so the open photo stands out. Same in light and dark mode. Plain colours here:
   older browsers don't pass CSS variables into ::backdrop. */
.viewer::backdrop {
  background: rgba(10, 10, 10, .88);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

/* light text on the dark backdrop */
.viewer { --fg: #ececea; --muted: #9b9b96; }

.viewer img {
  position: absolute;
  top: 64px;
  left: 24px;
  width: calc(100% - 48px);
  height: calc(100% - 136px);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.viewer .prev,
.viewer .next {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  padding: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

.viewer .prev { left: 0; cursor: pointer; }
.viewer .next { right: 0; cursor: pointer; }

.viewer .close,
.viewer .count {
  position: absolute;
  top: 0;
  margin: 0;
  padding: 22px 24px;
  font: inherit;
  color: var(--muted);
}

.viewer .close {
  right: 0;
  border: 0;
  background: none;
  cursor: pointer;
  z-index: 1;
  transition: color .15s;
}

.viewer .close:hover { color: var(--fg); }

.viewer .count { left: 0; font-variant-numeric: tabular-nums; }

.viewer .caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0 24px 18px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.viewer:focus,
.viewer .prev,
.viewer .next { outline: none; }

.viewer .close:focus-visible {
  outline: none;
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* footer */

.foot {
  padding-top: 28px;
  padding-bottom: 28px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 480px) {
  .wrap { padding: 0 16px; }
  .top { padding-top: 20px; padding-bottom: 20px; }
  .viewer img { left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
