/* ============================================================
   Mark Lilley Photography — stylesheet
   Covers: landing page, 404 page, gallery page
   ============================================================ */

/* --- Custom properties --- */
:root {
  --bg:           #0d0d0d;
  --surface:      #1a1a1a;
  --border:       #2a2a2a;
  --accent:       #c8a96e;
  --accent-hover: #d9bc87;
  --text:         #e8e8e8;
  --text-muted:   #888888;
  --radius:       4px;
  --font-serif:   'Georgia', 'Times New Roman', serif;
  --font-sans:    system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  color: var(--accent-hover);
  text-decoration: underline;
}

img {
  display: block;
  max-width: 100%;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
}

/* ============================================================
   Landing page & 404
   ============================================================ */

.landing-page .hero {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.hero-content {
  max-width: 540px;
  text-align: center;
}

.hero-label {
  font-family: var(--font-serif);
  font-size: 0.875rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.hero-body {
  font-size: 1.0625rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.hero-contact {
  font-size: 0.9375rem;
  color: var(--text-muted);
}

/* ============================================================
   Gallery page
   ============================================================ */

.gallery-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header --- */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.gallery-header-left {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.site-logo {
  font-family: var(--font-serif);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
}

.site-logo:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

.gallery-name {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Colour/B&W toggle --- */
.colour-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.toggle-btn {
  padding: 0.45rem 0.9rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.toggle-btn + .toggle-btn {
  border-left: 1px solid var(--border);
}

.toggle-btn--active {
  background-color: var(--accent);
  color: #000;
  font-weight: 600;
}

.toggle-btn:hover:not(.toggle-btn--active) {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* --- Header actions group (Download Selected + Download All) --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* --- Download Selected button --- */
.btn-download-selected {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background-color: transparent;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-download-selected:hover:not(:disabled) {
  background-color: var(--accent);
  color: #000;
}

.btn-download-selected:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- Download All button --- */
.btn-download-all {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  background-color: var(--accent);
  color: #000;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  transition: background-color 0.15s;
  white-space: nowrap;
}

.btn-download-all:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

.btn-download-all:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* --- Expiry banner --- */
.gallery-expiry-banner {
  padding: 0.65rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 1px solid transparent;
}

.gallery-expiry-banner--expired {
  background-color: rgba(200, 60, 60, 0.12);
  border-color: rgba(200, 60, 60, 0.3);
  color: #e07070;
}

.gallery-expiry-banner--warning {
  background-color: rgba(200, 150, 50, 0.12);
  border-color: rgba(200, 150, 50, 0.3);
  color: #d4a84b;
}

.gallery-expiry-banner--info {
  background-color: rgba(100, 100, 100, 0.1);
  border-color: var(--border);
  color: var(--text-muted);
}

/* --- Client greeting --- */
.gallery-greeting {
  padding: 0.75rem 1.5rem 0;
  font-size: 0.9375rem;
  color: var(--text-muted);
  font-style: italic;
  max-width: 860px;
}

/* --- Photo count --- */
.gallery-photo-count {
  padding: 0.75rem 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* --- Photo grid --- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 6px;
  padding: 6px 1.5rem 2rem;
}

.gallery-grid-item {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background-color: var(--surface);
  cursor: pointer;
  border-radius: var(--radius);
}

.gallery-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s ease, opacity 0.2s, filter 0.35s ease;
}

/* Heart / favourite overlay on grid tiles */
.grid-fav-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: rgba(0, 0, 0, 0.45);
  border: none;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.7);
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background-color 0.15s;
  cursor: pointer;
}

.gallery-grid-item:hover .grid-fav-btn,
.gallery-grid-item:focus-within .grid-fav-btn,
.grid-fav-btn--active {
  opacity: 1;
}

.grid-fav-btn--active {
  color: #e05555;
  background: rgba(0, 0, 0, 0.55);
}

.grid-fav-btn:hover {
  background: rgba(0, 0, 0, 0.65);
  color: #e05555;
}

/* B&W mode: CSS grayscale applied via body class — colour originals always downloaded */
.gallery-bw .gallery-grid-item img,
.gallery-bw #lightbox-img {
  filter: grayscale(100%);
}

.gallery-grid-item:hover img,
.gallery-grid-item:focus-visible img {
  transform: scale(1.03);
  opacity: 0.85;
}

.gallery-grid-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Error notice --- */
.download-error {
  display: none;
  padding: 0.6rem 1.5rem;
  font-size: 0.875rem;
  color: #e07070;
  background-color: rgba(224, 112, 112, 0.08);
  border-top: 1px solid rgba(224, 112, 112, 0.2);
}

.download-error.visible {
  display: block;
}

/* ============================================================
   Lightbox
   ============================================================ */

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.96);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#lightbox.active {
  display: flex;
}

.lightbox-img-wrap {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
  user-select: none;
  transition: filter 0.35s ease;
}

/* LQIP: thumbnail shown blurred while full-res loads in the background */
#lightbox.lightbox--loading #lightbox-img {
  filter: blur(12px);
}

.gallery-bw #lightbox.lightbox--loading #lightbox-img {
  filter: grayscale(100%) blur(12px);
}

/* Ghost button base */
.lightbox-btn {
  position: fixed;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
  padding: 0.75rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.lightbox-btn:hover {
  opacity: 1;
}

.lightbox-btn:focus-visible {
  outline: 2px solid var(--accent);
  border-radius: var(--radius);
}

#lightbox-close {
  top: 1rem;
  right: 1rem;
  font-size: 1.75rem;
}

#lightbox-prev {
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.5rem;
}

#lightbox-next {
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.5rem;
}

/* Action buttons inside lightbox (favourite + download) */
.lightbox-actions {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#lightbox-download {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1.2rem;
  background-color: var(--accent);
  border: none;
  color: #000;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}

#lightbox-download:hover:not(:disabled) {
  background-color: var(--accent-hover);
}

#lightbox-download:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Favourite button inside lightbox */
.lightbox-fav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.6);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.lightbox-fav-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #e05555;
  border-color: rgba(224, 85, 85, 0.4);
}

.lightbox-fav-btn--active {
  color: #e05555;
  background: rgba(224, 85, 85, 0.15);
  border-color: rgba(224, 85, 85, 0.4);
}

.lightbox-fav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Photo counter inside lightbox */
#lightbox-counter {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8125rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 4px;
  }

  /* Two-row header:
     Row 1 — logo + gallery name (full width)
     Row 2 — colour toggle + download buttons */
  .gallery-header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    row-gap: 0.5rem;
  }

  .gallery-header-left {
    flex: 0 0 100%;
    min-width: 0;
  }

  .colour-toggle {
    flex-shrink: 0;
  }

  .header-actions {
    margin-left: auto;
  }

  .toggle-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }

  .btn-download-all,
  .btn-download-selected {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }

  /* Always show heart buttons on touch devices */
  .grid-fav-btn {
    opacity: 1;
  }

  /* Keep lightbox actions readable on small screens */
  .lightbox-actions {
    bottom: 1rem;
    right: 1rem;
  }

  .gallery-expiry-banner,
  .gallery-greeting {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

@media (max-width: 380px) {
  .gallery-grid {
    grid-template-columns: 1fr;
  }

  /* On very narrow screens abbreviate button text via content override */
  .btn-download-all {
    font-size: 0.6875rem;
    padding: 0.4rem 0.6rem;
  }

  .btn-download-selected {
    font-size: 0.6875rem;
    padding: 0.4rem 0.6rem;
  }
}
