/* Theme Tokens */
/* ==================== */

:root {

  /* Colors - Text */

  --body-text-color: var(--text-color-darkmode);
  --body-text-faded: var(--text-secondary-color-darkmode);
  --bright-white-text: #fff;
  --orange-text: var(--accent-color);
  --orange-text-lighter: var(--accent-color-lighter);

  --gallery-card-hover-text: var(--accent-color);
  --gallery-card-hover-text-lighter: var(--accent-color-lighter);
  --gallery-text-color: var(--text-color-darkmode);
  --gallery-date-color: var(--text-secondary-color-darkmode);

  --modal-text-color: var(--text-color-darkmode);
  --modal-caption-color: var(--text-color-darkmode);
  --modal-date-color: var(--text-secondary-color-darkmode);

  /* Font Sizes */
  --gallery-album-title-font-size: var(--text-font-size-small);
  --gallery-caption-font-size: var(--text-font-size-small);
  --gallery-date-font-size: var(--text-font-size-extrasmall);

  --modal-caption-font-size: var(--text-font-size-small);
  --modal-control-font-size: var(--text-font-size-large);

  --gallery-caption-inset: 15px;
  

  /* Colors - UI Elements */
  --gallery-album-title-color: var(--text-color-darkmode);
  --gallery-card-bg: var(--background-secondary-color-darkmode);
  --gallery-card-hover-bg: var(--background-color-darkmode);
  --gallery-card-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --gallery-image-placeholder: #2a2a2a;

  --modal-overlay-bg: rgba(0, 0, 0, 0.95);
  --modal-content-bg: var(--background-color-darkmode);
  --modal-hover: rgba(255, 255, 255, 0.05);
  --modal-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --modal-close-bg: rgba(0, 0, 0, 0.7);
  --modal-close-hover-bg: rgba(255, 255, 255, 0.3);
  --modal-nav-bg: rgba(0, 0, 0, 0.7);
  --modal-nav-hover-bg: var(--orange-text-lighter);

}


/* Adjusting surrounding elements from blog design */
/* ============ */

article {
  grid-template-columns: 
    var(--gutter-size)
    1fr
    min( 1200px, calc(100% - 40px) )  /* Make the central column much wider and capped at 1200px in order to fit in more photo tiles in the gallery grid view. */
    1fr
    var(--gutter-size)
}

.credits {
  margin-top: 60px;
}

@media (max-width: 768px) {
  .credits {
    margin-top: 0;
    padding-top: 0;
  }
}



/* Photo page */
/* ============ */

.gallery-meta {
  margin-top: 10px;
  color: var(--gallery-date-color);
  line-height: 1.6;
}

.related-links {
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  color: rgba(255, 255, 255, 0.2);
  display: inline-block;
  font-family: var(--text-font-family-mono);
  font-size: var(--text-font-size-extrasmall);
  margin-top: 30px;
  margin-bottom: 0;
  padding: 10px;
  text-transform: uppercase;
}

@media (max-width: 768px) {
  .related-links {
    display: grid;
    grid-column: 1/-1;
    padding: 0;
  }

  .related-links a {
    box-sizing: border-box;
    justify-content: center;
    line-height: 1.25;
    margin: 0;
    min-height: 52px;
    padding: 12px 10px 8px; /* Sit just below the button's center. */
  }

  .related-links a svg {
    translate: 0 -0.5px; /* Align the drawn icon with the capital letters. */
  }
}

@media (min-width: 769px) {
  .related-links {
    justify-self: center;
    margin-inline: auto;
    padding: 7px 17px 0; /* Strange offsets to compensate for hidden padding, probably inherent to line-heights of app caps text. */
    width: max-content;
  }
}

.article-link, .related-links a {
  color: var(--orange-text-lighter);
  text-decoration: none;
  text-underline-offset: 4px;
}

.article-link:hover, .related-links a:hover {
  color: var(--bright-white-text);
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.gallery-article-preview {
  display: none;
}

@media (max-width: 768px) {
  body > header {
    padding-left: 20px;
    padding-right: 20px;
  }

  a.gallery-article-preview,
  a.gallery-article-preview:visited {
    --preview-padding: 10px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    box-sizing: border-box;
    color: var(--body-text-color);
    display: grid;
    font: var(--text-font-size-extrasmall) / 1.4 var(--text-font-family-sans);
    gap: var(--preview-padding);
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
    margin: 8px var(--gallery-caption-inset) 36px;
    padding: var(--preview-padding);
    text-decoration: none;
  }

  a.gallery-article-preview:hover {
    border: 1px solid var(--orange-text-lighter);
  }

  .gallery-article-preview:focus-visible {
    outline: 2px solid var(--orange-text-lighter);
    outline-offset: 3px;
  }

  .gallery-article-preview img {
    aspect-ratio: 3 / 2;
    height: auto;
    object-fit: cover;
    border-radius: 6px;
  }

  .gallery-article-copy {
    display: grid;
    gap: 4px;
    overflow-wrap: anywhere;
  }

  .gallery-article-copy strong {
    font-family: var(--text-font-family-serif);
    font-size: var(--text-font-size-small);
  }

  .gallery-article-label {
    color: var(--orange-text-lighter);
    font-family: var(--text-font-family-mono);
  }

  .gallery-article-preview:hover .gallery-article-label {
    text-decoration: underline;
    text-underline-offset: 4px;
  }
}




/* Gallery Grid - Desktop only */
/* ============ */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

/* Mobile: Single column, no grid */
@media (max-width: 768px) {
  .gallery {
    display: block;
  }
  
  .photo-card {
    margin-bottom: 20px;
  }
}

/* Photo Card */
.photo-card {
  background: var(--gallery-card-bg);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--gallery-card-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  display: block;
}

.albums .photo-card {
  margin-bottom: 20px;
}

.gallery a.photo-card,
.gallery a.photo-card:visited {
  padding-bottom: 0;
  border-bottom: none;
  -webkit-tap-highlight-color: transparent;
}

.gallery a.photo-card:hover,
.gallery a.photo-card:focus,
.gallery a.photo-card:active {
  padding-bottom: 0;
  border-bottom: none;
}

.gallery a.photo-card:focus-visible {
  outline: 2px solid var(--orange-text-lighter);
  outline-offset: 3px;
}

/* Desktop: Clickable cards with hover */
@media (min-width: 769px) {
  @media (hover: hover) {
    .photo-card:hover {
      background-color: var(--modal-hover);
      border-bottom: none;

      & img {
      transform: scale(1.04);
      transition: transform 0.2s;
      }
    }
  }
}

/* Mobile: Not clickable for non-link cards (album pages with modals), but allow links to work */
@media (max-width: 768px) {
  .photo-card:not(a) {
    pointer-events: none;
    cursor: default;
  }
  
  /* Make photo cards full width on mobile */
  a.photo-card {
    background: none;
    border-radius: 0;
    cursor: pointer;
    margin-left: calc(var(--gutter-size) * -1);
    pointer-events: auto; /* Ensure links are always clickable */
    width: 100vw;
  }
}

.photo-card img {
  border-radius: 8px 8px 0 0;
  
  width: 100%;
  height: 250px;
  object-fit: var(--thumbnail-fit, cover);
  object-position: var(--thumbnail-position, center);
  display: block;
  background-color: var(--gallery-image-placeholder);
}

.photo-focus-top {
  --thumbnail-position: center top;
}

/* Mobile: Full aspect ratio, no cropping */
@media (max-width: 768px) {
  .photo-card img {
    border-radius: 0; /* Make images square on mobile */
    height: auto;
    object-fit: contain;
  }

  article[data-gallery="css-album"] .photo-card img {
    background-color: transparent; /* Let the page show around height-capped photos. */
  }
}

/* Photo Info */
.photo-info {
  color: var(--gallery-text-color);
  padding: 15px var(--gallery-caption-inset);
}

.albums .photo-info {
  padding: 20px 15px 15px;
}

/* Hide grid captions on desktop, show on mobile */
/* Only apply to gallery grid view, not album tiles on index page */
article:not(.albums) .gallery .photo-info {
  /* Default: visible (mobile-first) */
  display: block;
}

@media (min-width: 769px) {
  article:not(.albums) .gallery .photo-info {
    display: none;
  }
}

.photo-info .album-title {
  color: var(--gallery-album-title-color);
  font-size: var(--gallery-album-title-font-size);
  line-height: 110%;
}

.photo-info .caption {
  font-size: var(--gallery-caption-font-size);

  margin-bottom: 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.photo-info .date {
  color: var(--gallery-date-color);
  font-family: var(--text-font-family-mono);
  font-size: var(--gallery-date-font-size);
  line-height: 100%;
  text-transform: uppercase;
}

/* Truncate long captions in gallery */
.photo-info .caption {
  margin-top: 10px;
  
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 769px) {
  .photo-info .caption {
    -webkit-line-clamp: 5;
    line-clamp: 5;
  }
}

@media (max-width: 768px) {
  .photo-info .caption {
    display: block;
    -webkit-line-clamp: unset;
    line-clamp: unset;
    overflow: visible;
  }
}

/* Modal Styles - Desktop only */
/* ============ */
/*
 * ARCHITECTURAL NOTE: CSS-FIRST DESIGN
 * 
 * This gallery is designed to work COMPLETELY without JavaScript.
 * All modal display, centering, and body scroll locking is handled
 * by CSS using the :target pseudo-class.
 * 
 * JavaScript (photo-gallery.js) is ONLY for progressive enhancement:
 * - Keyboard navigation
 * - Scroll position restoration
 * - History management
 * 
 * If JavaScript is disabled, modals still work perfectly via CSS :target.
 * Never add JavaScript dependencies to these modal styles.
 */

/* Hide modal by default */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--modal-overlay-bg);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
  align-items: center;
  justify-content: center;
  overscroll-behavior: contain;
}

/* Show modal when :target matches */
.modal:target,
.modal.active {
  display: flex;
}

body:has(.modal:target) {
  overflow: hidden;
}

/* Modal Container */
.modal-content {
  position: relative;
  max-width: 90vw;
  margin: 20px auto;
  overflow: hidden;
  box-shadow: var(--modal-shadow);
  z-index: 1000;
  width: fit-content;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* Close Button */
.modal-close {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: var(--modal-close-bg);
  color: var(--modal-text-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--modal-control-font-size);
  z-index: 1001;
  transition: background 0.2s;
  text-decoration: none;
}

.modal-close:hover {
  background: var(--modal-close-hover-bg);
  text-decoration: none;
}

.modal-image {
  width: 100%;
  max-width: 90vw;
  max-height: 70vh;
  height: auto;
  display: block;
  object-fit: contain;
  background-color: var(--gallery-image-placeholder);
}

@media (max-width: 768px) {
  .modal {
    padding: 40px 0 20px;
    align-items: center;
    justify-content: center;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .modal-content picture,
  .modal-content img {
    background: none;
    width: 100%;
    max-width: 100%;
    height: auto;
  }

  .modal-image {
    max-width: 100%;
    max-height: 60vh;
  }

  .modal .modal-nav {
    display: none;
  }

  [data-gallery-visibility="public"] .modal {
    padding-bottom: 60px;
  }

  [data-gallery-visibility="public"] .modal .modal-nav {
    display: flex;
    top: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 44px;
    height: 44px;
    transform: none;
  }
}

/* Modal Info */
.modal-info {
  padding: 20px;
  color: var(--modal-text-color);
}

.modal-caption {
  font-size: var(--modal-caption-font-size);
  margin-bottom: 10px;
  line-height: 1.5;
  color: var(--modal-caption-color);
  overflow-wrap: anywhere;
  text-align: center;
  word-break: break-word;
}

.modal-date {
  color: var(--modal-date-color);
  font-family: var(--text-font-family-mono);
  font-size: var(--gallery-date-font-size);
  text-transform: uppercase;
}

.photo-info .caption a,
.modal-caption a {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Navigation Buttons */
.modal-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  background: var(--modal-nav-bg);
  color: var(--modal-text-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  z-index: 1001;
  transition: background 0.2s;
  font-size: var(--modal-control-font-size);
}

.modal-close:hover, .modal-nav:hover {
  background: var(--modal-nav-hover-bg);
  color: var(--background-color-darkmode);
  text-decoration: none;
}

.modal:hover, .modal-content:hover, .modal-overlay:hover, .modal-close:hover, .modal-nav:hover {
  border: none;
}

.modal-nav.prev {
  left: 20px;
}

.modal-nav.next {
  right: 20px;
}

/* Overlay Click to Close - invisible link covering entire modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: transparent;
}

/* Fade-in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.photo-card img {
  animation: fadeIn 0.4s ease-in;
}
