/*
 * Behavior styles for site.js: page fade, lightbox, image protection,
 * grid spacer. Static chrome lives in site.css.
 */

/* ---------------------------------------------------------------------- *
 * Page fade
 * ---------------------------------------------------------------------- */
body {
  opacity: 1;
  transition: opacity 0.25s ease;
}
body.is-loading {
  opacity: 0;
  /* If site.js never runs (blocked, fails), this reveals the page anyway. */
  animation: uw-reveal-fallback 0s 2.5s forwards;
}
body.is-leaving {
  opacity: 0;
}
@keyframes uw-reveal-fallback {
  to {
    opacity: 1;
  }
}

/* ---------------------------------------------------------------------- *
 * Image protection
 * ---------------------------------------------------------------------- */
img {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
}

/* ---------------------------------------------------------------------- *
 * Lightbox
 * ---------------------------------------------------------------------- */
html.lightbox-enabled {
  overflow: hidden;
}

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 1001;
  visibility: hidden;
  pointer-events: none;
}
#lightbox.is-open {
  visibility: visible;
  pointer-events: auto;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1001;
  background: #fff;
  opacity: 0.94;
}

.lightbox-stage {
  position: absolute;
  inset: 0;
  z-index: 1002;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.lightbox-stage.is-zoomed {
  overflow: auto;
  cursor: zoom-out;
  /* Centering would put the top and left of a picture larger than the
     screen out of reach. Start alignment with auto margins keeps all of it
     reachable and still centers a picture smaller than the screen. */
  align-items: flex-start;
  justify-content: flex-start;
}
.lightbox-stage.is-zoomed .lightbox-figure {
  flex: none;
  max-width: none;
  margin: auto;
}

.lightbox-figure {
  position: relative;
  margin: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.lightbox-figure.is-visible {
  opacity: 1;
}

.lightbox-image {
  display: block;
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-stage.is-zoomed .lightbox-image {
  cursor: zoom-out;
}

.lightbox-caption {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  box-sizing: border-box;
  width: 100%;
  max-width: 600px;
  padding: 20px 5px 15px;
  color: #fff;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.4) 25px, rgba(0, 0, 0, 0.5));
}
.lightbox-caption:empty {
  display: none;
}

.lightbox-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  z-index: 1002;
  display: none;
  animation: uw-spin 0.7s linear infinite;
}
#lightbox.is-busy .lightbox-spinner {
  display: block;
}
@keyframes uw-spin {
  to {
    transform: rotate(360deg);
  }
}

.lightbox-close {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1003;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(105, 105, 105, 0.2);
  color: #fff;
  cursor: pointer;
  transition: opacity 1s ease, background 0.2s ease;
}
.lightbox-close:hover {
  background: rgba(105, 105, 105, 0.4);
}
@media (max-width: 1024px) {
  .lightbox-close {
    top: 0;
    right: 0;
    background: transparent;
    color: #222;
  }
  .lightbox-close:hover {
    background: transparent;
  }
}

.lightbox-nav {
  position: fixed;
  top: 0;
  width: 30vw;
  height: 100vh;
  z-index: 1003;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transition: opacity 1s ease;
}
.lightbox-prev {
  left: 0;
}
.lightbox-next {
  right: 0;
}
.lightbox-nav:hover {
  opacity: 1;
  transition: opacity 0.2s ease;
}
@media (max-width: 1024px) {
  /* Prev/next hit zones are desktop-only; touch users swipe instead. */
  .lightbox-nav,
  .lightbox-nav:hover {
    opacity: 0;
    pointer-events: none;
  }
}

.lightbox-nav-icon {
  position: absolute;
  top: calc(50% - 30px);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(105, 105, 105, 0.2);
  color: #fff;
  transition: background 0.2s ease;
}
.lightbox-prev .lightbox-nav-icon {
  left: 20px;
}
.lightbox-next .lightbox-nav-icon {
  right: 20px;
}
.lightbox-nav:hover .lightbox-nav-icon {
  background: rgba(105, 105, 105, 0.4);
}

#lightbox.controls-idle .lightbox-close,
#lightbox.controls-idle .lightbox-nav {
  opacity: 0;
}
/* The close button keeps keyboard focus visible even while faded. */
#lightbox.controls-idle .lightbox-close:focus-visible {
  opacity: 1;
}
#lightbox.is-zoomed .lightbox-nav {
  opacity: 0;
  pointer-events: none;
}

/* Expand-to-view affordance on page thumbnails, desktop only. */
@media (min-width: 1024px) {
  .js-zoom {
    position: relative;
  }
  .js-zoom::after {
    content: "";
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(105, 105, 105, 0.2);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='none' stroke='white' stroke-width='2'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
  }
  .js-zoom:hover::after {
    opacity: 1;
  }
}

/* ---------------------------------------------------------------------- *
 * Grid spacer (keeps the last row from stretching). site.js shows it only
 * when the last row would otherwise become too tall.
 * ---------------------------------------------------------------------- */
.grid-spacer[hidden] {
  display: none;
}
.grid-spacer {
  height: 0;
  margin: 0;
  padding: 0;
  flex-grow: 90000000000;
  pointer-events: none;
}

/* ---------------------------------------------------------------------- *
 * Reduced motion: no fades, no spin, no idle-fade delay tricks
 * ---------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  body,
  body.is-loading,
  .lightbox-figure,
  .lightbox-close,
  .lightbox-nav,
  .js-zoom::after {
    transition: none !important;
    animation: none !important;
  }
  body.is-loading {
    opacity: 1;
  }
  .lightbox-figure {
    opacity: 1;
  }
  .lightbox-spinner {
    animation: none;
  }
}
