* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-secondary);
  color: var(--color-primary);
  font-family: var(--font-body);
  line-height: 1.6;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0 0 0.4em;
}

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

img {
  max-width: 100%;
  display: block;
  /* Discourage saving photos: no drag-out, no selection, no iOS
     long-press "Save Image" menu. (See also public/js/gallery.js.) */
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-header-bg);
}
.site-header .logo {
  font-family: var(--font-logo);
  font-size: 1.8rem;
  font-weight: 400;
  line-height: 1.2;
}
.site-header .logo-image {
  display: block;
  width: auto;
  max-width: 60vw;
}
.main-nav a {
  margin-left: 1.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  padding-bottom: 4px;
  border-bottom: 2px solid transparent;
}
.main-nav a:hover,
.main-nav a.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-accent);
}

/* ---------- Layout ---------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
}

.hero { text-align: center; margin-bottom: 2.5rem; }
.hero h1 {
  /* The page `heading:` text shares the gallery-title font. */
  font-family: var(--font-gallery-title);
  font-weight: 400;
  font-size: 3rem;
}
.hero-intro { max-width: 560px; margin: 0.75rem auto 0; color: var(--color-muted); }

.page-intro { margin-bottom: 2rem; }
/* Title on the left, action button (e.g. "Your Photos") top right. */
.page-intro-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-intro p { color: var(--color-muted); max-width: 620px; }

.back-link {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}
.back-link:hover { color: var(--color-accent); }

/* ---------- Gallery block (shared) ---------- */
.gallery-block {
  margin-bottom: 2rem;
  /* Optional per-gallery caps, set inline from YAML (maxWidth/maxHeight) */
  --gallery-max-width: none;
  --gallery-max-height: none;
}
.gallery-title {
  font-family: var(--font-gallery-title);
  font-weight: 400;
  font-size: 2rem;
}
.gallery-description { color: var(--color-muted); max-width: 620px; margin-bottom: 1.25rem; }
.gallery-empty { color: var(--color-muted); font-style: italic; }

/* ---------- Slideshow mode ---------- */
.gallery--slideshow {
  position: relative;
  /* Duration of each half of a slide change (fade out, then fade in). */
  --slide-fade: 0.3s;
}
.slideshow-viewport {
  position: relative;
  width: 100%;
  max-width: var(--gallery-max-width);
  max-height: var(--gallery-max-height);
  aspect-ratio: 3 / 2;
  overflow: hidden;
  /* Same as the page, so letterboxing around fitted photos is invisible. */
  background: var(--color-secondary);
  border-radius: 4px;
  margin-left: auto;
  margin-right: auto;
}
.slideshow-viewport .slide {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  /* Hidden slides are stacked on top of each other: keep them from
     catching clicks/focus meant for the visible one. The visibility
     change is delayed until the fade-out has finished. */
  visibility: hidden;
  pointer-events: none;
  /* Fade out: the outgoing slide fades over --slide-fade... */
  transition: opacity var(--slide-fade) ease-in, visibility 0s linear var(--slide-fade);
}
.slideshow-viewport .slide.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  /* ...then fade in: the incoming slide waits for the fade-out to end,
     so the two photos never overlap (out, then in - not a crossfade). */
  transition: opacity var(--slide-fade) ease-out var(--slide-fade), visibility 0s linear var(--slide-fade);
}
.slide-trigger {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
}
.slideshow-viewport .slide img {
  width: 100%;
  height: 100%;
  /* Fit the whole photo inside the box (bounded by maxWidth/maxHeight):
     its longer side touches the box edge, nothing is cropped. */
  object-fit: contain;
}
.slide-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
}
.slide-nav:hover { background: var(--color-accent); }
.slide-prev { left: 1rem; }
.slide-next { right: 1rem; }
.slide-dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}
.slide-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: none;
  background: var(--color-border);
  cursor: pointer;
}
.slide-dot.is-active { background: var(--color-accent); }
/* Big galleries: progress bar + counter instead of dots. */
.slide-progress {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  max-width: 480px;
  margin: 1rem auto 0;
}
.slide-progress-track {
  flex: 1;
  /* Tall invisible hit area around a thin visible bar. */
  padding: 8px 0;
  cursor: pointer;
  background: linear-gradient(var(--color-border), var(--color-border)) center / 100% 4px no-repeat;
  border-radius: 2px;
}
.slide-progress-track:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.slide-progress-fill {
  height: 4px;
  min-width: 4px;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}
.slide-counter {
  font-size: 0.85rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Thumbnails mode ---------- */
.thumbnail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.thumbnail {
  overflow: hidden;
  border-radius: 4px;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: none;
  background: none;
  cursor: zoom-in;
  max-width: var(--gallery-max-width);
  max-height: var(--gallery-max-height);
}
.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.35s ease;
}
.thumbnail:hover img { transform: scale(1.05); }

/* ---------- Galleries list ---------- */
.gallery-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 2rem;
}
.gallery-card-thumb {
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 4px;
  margin-bottom: 0.85rem;
  /* Same as the page, so letterboxing around fitted photos is invisible. */
  background: var(--color-secondary);
}
.gallery-card-thumb-empty {
  width: 100%;
  height: 100%;
  background: var(--color-border);
}
.gallery-card-thumb img {
  width: 100%;
  height: 100%;
  /* Show the whole cover photo, never crop it. */
  object-fit: contain;
  transition: transform 0.35s ease;
}
.gallery-card:hover .gallery-card-thumb img { transform: scale(1.06); }
.gallery-card-title {
  font-family: var(--font-gallery-title);
  font-weight: 400;
  font-size: 1.6rem;
}
.gallery-card-description { color: var(--color-muted); font-size: 0.95rem; }

/* ---------- Buttons ---------- */
.button {
  display: inline-block;
  background: var(--color-primary);
  color: var(--color-secondary);
  border: none;
  padding: 0.6rem 1.3rem;
  border-radius: 4px;
  font: inherit;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.button:hover { background: var(--color-accent); }
.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.9rem;
  color: var(--color-muted);
  cursor: pointer;
}
.link-button:hover { color: var(--color-accent); }

/* ---------- "Your Photos" (private galleries) ---------- */
.private-login { max-width: 360px; }
.private-login form { display: flex; flex-direction: column; gap: 0.4rem; }
.private-login label { font-size: 0.95rem; margin-top: 0.5rem; }
.private-login input {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font: inherit;
  background: #fff;
}
.private-login-check {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}
.private-login-error { color: #b3261e; font-size: 0.9rem; }
.private-gallery-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 1.5rem;
}
.private-gallery-bar .back-link { margin-bottom: 0; }
.private-gallery-actions { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; justify-content: flex-end; }
.private-gallery-actions form { margin: 0; }
.private-gallery-actions .button { text-decoration: none; }

/* ---------- Human check (self-hosted captcha) ---------- */
.human-check {
  max-width: 420px;
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  margin-bottom: 1.5rem;
}
.human-check-label { margin-top: 0; font-weight: 500; }
.human-check-error { color: #b3261e; font-size: 0.9rem; margin-top: -0.25rem; }
.human-check-form label { display: block; margin-bottom: 0.5rem; font-size: 0.95rem; }
.human-check-row { display: flex; gap: 0.5rem; }
.human-check-row input[type="text"] {
  width: 70px;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
}
.human-check-row button {
  background: var(--color-primary);
  color: var(--color-secondary);
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}
.human-check-row button:hover { background: var(--color-accent); }
.human-check-row button:disabled { opacity: 0.5; cursor: not-allowed; }
/* Spinner shown while the button waits for the proof-of-work to finish. */
.human-check-row button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.human-check-row button:disabled::before {
  content: "";
  width: 0.9em;
  height: 0.9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: button-spin 0.8s linear infinite;
}
@keyframes button-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .human-check-row button:disabled::before { animation-duration: 2.4s; }
}
.human-check-image {
  display: block;
  margin-bottom: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #f4f1ea;
  user-select: none;
}
.pow-status { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--color-muted); }

/* ---------- Contact ---------- */
.contact-details ul { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.contact-details li { margin-bottom: 0.5rem; }
.contact-socials a {
  margin-right: 1.25rem;
  color: var(--color-accent);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-muted);
  font-size: 0.85rem;
  background: var(--color-footer-bg);
}
.site-footer .socials a { margin-left: 1rem; }
.site-footer .socials a:hover { color: var(--color-accent); }

@media (max-width: 640px) {
  .site-header, .site-footer { flex-direction: column; gap: 0.75rem; text-align: center; }
  .main-nav a { margin: 0 0.6rem; }
}

/* ---------- Lightbox overlay ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 8, 0.55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
}
.lightbox[hidden] { display: none; }
.lightbox-figure {
  margin: 0;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.lightbox-image {
  max-width: 90vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 2px;
}
.lightbox-caption {
  color: #f5f3ef;
  margin-top: 0.85rem;
  font-size: 0.9rem;
  text-align: center;
  max-width: 60ch;
}
.lightbox-title {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 600;
}
.lightbox-title:empty { display: none; }
.lightbox-counter {
  color: rgba(245, 243, 239, 0.7);
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.lightbox-close {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { color: var(--color-accent); }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.6rem;
  cursor: pointer;
}
.lightbox-nav:hover { background: var(--color-accent); }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }

body.lightbox-open { overflow: hidden; }

@media (max-width: 640px) {
  .lightbox-nav { width: 40px; height: 40px; font-size: 1.3rem; }
  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }
  .lightbox-close { top: 0.75rem; right: 0.75rem; }
}
