/* ============================================
   Image Library — Styles
   ============================================ */

:root {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #111111;
  --color-text-secondary: #666666;
  --color-border: #e0e0e0;
  --color-accent: #111111;
  --color-accent-hover: #333333;
  --color-tag-bg: #f0f0f0;
  --color-tag-bg-active: #111111;
  --color-tag-text: #444444;
  --color-tag-text-active: #ffffff;
  --color-overlay: rgba(0, 0, 0, 0.55);
  --font-stack: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --grid-gap: 12px;
  --radius: 6px;
  --transition-speed: 0.25s;
  --lightbox-duration: 0.5s;
  --lightbox-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --bottom-blur-height: min(22vh, 160px);
  --bottom-blur-strength: 12px;
}

/* ---- Reset & Base ---- */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-stack);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

body.lightbox-open {
  overflow: hidden;
}

body::after {
  content: "";
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* Extend through safe-area so backdrop blur reaches the physical bottom (no sharp strip above home indicator / gesture bar). */
  height: calc(var(--bottom-blur-height) + constant(safe-area-inset-bottom));
  height: calc(var(--bottom-blur-height) + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
  z-index: 10;
  background: rgba(250, 250, 250, 0.15);
  -webkit-backdrop-filter: blur(var(--bottom-blur-strength));
  backdrop-filter: blur(var(--bottom-blur-strength));
  -webkit-mask-image: linear-gradient(to top, black, transparent);
  mask-image: linear-gradient(to top, black, transparent);
  /* Avoid compositing gaps between fixed layers and the viewport edge on mobile WebKit. */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

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

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ---- Layout Wrapper ---- */

.image-library {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---- Site Header ---- */

.site-header {
  padding: 60px 0 40px;
  text-align: center;
}

.site-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

.site-subtitle {
  margin-top: 8px;
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  font-weight: 400;
}

/* ---- Name Hover Preview ---- */

.name-hover-wrap {
  position: relative;
  display: inline-block;
}

.name-link {
  font-weight: 500;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  transition: border-color var(--transition-speed);
}

.name-link:hover {
  border-color: var(--color-text);
}

.name-preview {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding-top: 12px;
  z-index: 50;
  pointer-events: none;
}

.name-hover-wrap:hover .name-preview {
  pointer-events: auto;
}

.name-preview-arrow {
  display: block;
  width: 10px;
  height: 10px;
  margin: 0 auto -5px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-right: none;
  transform: rotate(45deg);
  position: relative;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.name-hover-wrap:hover .name-preview-arrow {
  opacity: 1;
}

.name-preview-window {
  display: block;
  width: 280px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.04);
  background: var(--color-surface);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  text-decoration: none;
}

.name-hover-wrap:hover .name-preview-window {
  opacity: 1;
  transform: translateY(0);
}

.window-chrome {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.window-dots {
  display: flex;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-red { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green { background: #28c840; }

.window-url {
  flex: 1;
  text-align: center;
  font-size: 0.65rem;
  color: var(--color-text-secondary);
  font-weight: 400;
  letter-spacing: 0.01em;
}

.window-viewport {
  display: block;
  width: 280px;
  height: 175px;
  overflow: hidden;
  position: relative;
}

.window-viewport iframe {
  width: 1400px;
  height: 875px;
  border: none;
  transform: scale(0.2);
  transform-origin: top left;
  pointer-events: none;
}

/* ---- Tag Pills (cards + dropdown) ---- */

.tag-pill {
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  border-radius: 100px;
  background-color: var(--color-tag-bg);
  color: var(--color-tag-text);
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

.tag-pill:hover {
  background-color: var(--color-border);
}

.tag-pill.active {
  background-color: var(--color-tag-bg-active);
  color: var(--color-tag-text-active);
}

/* ---- Filter Dropdown ---- */

.filter-wrap {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 60;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.filter-toggle:hover {
  border-color: var(--color-text-secondary);
}

.filter-toggle.open {
  border-color: var(--color-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.filter-icon {
  flex-shrink: 0;
}

.filter-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.filter-toggle.open .filter-chevron {
  transform: rotate(180deg);
}

.filter-label {
  white-space: nowrap;
}

.filter-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 6px;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.filter-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.filter-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 450;
  color: var(--color-text);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  text-transform: lowercase;
  letter-spacing: 0.01em;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.filter-option:hover {
  background-color: var(--color-tag-bg);
}

.filter-option.active {
  font-weight: 600;
}

.filter-option-check {
  width: 16px;
  height: 16px;
  opacity: 0;
  flex-shrink: 0;
  stroke: var(--color-text);
}

.filter-option.active .filter-option-check {
  opacity: 1;
}

/* ---- Gallery Grid ---- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--grid-gap);
  padding-bottom: 60px;
}

.grid-item {
  position: relative;
  list-style: none;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background-color: var(--color-border);
  cursor: pointer;
  overflow: hidden;
}

.grid-item-entrance {
  position: relative;
  width: 100%;
  height: 100%;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.grid-item-entrance.visible {
  opacity: 1;
  transform: translateY(0);
}

.grid-item-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--transition-speed) ease;
}

.grid-item:hover .grid-item-thumb {
  opacity: 0.85;
}

/* ---- Carousel (Grid) ---- */

.carousel-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

.carousel-track .grid-item-thumb {
  flex: 0 0 100%;
}

.carousel-prev,
.carousel-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.88);
  color: var(--color-text);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background-color 0.15s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.carousel-prev { left: 6px; }
.carousel-next { right: 6px; }

.grid-item.has-carousel:hover .carousel-prev,
.grid-item.has-carousel:hover .carousel-next {
  opacity: 1;
}

.carousel-prev:hover,
.carousel-next:hover {
  background: rgba(255, 255, 255, 1);
}

.carousel-dots {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 5px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.grid-item.has-carousel:hover .carousel-dots {
  opacity: 1;
}

.carousel-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  transition: background 0.2s ease;
}

.carousel-dot.active {
  background: rgba(255, 255, 255, 0.95);
}

/* ---- Lightbox ---- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  perspective: 1200px;
  visibility: hidden;
  opacity: 0;
  transition:
    opacity var(--lightbox-duration) var(--lightbox-ease),
    visibility 0s linear var(--lightbox-duration);
  pointer-events: none;
}

.lightbox.is-open {
  visibility: visible;
  opacity: 1;
  transition:
    opacity var(--lightbox-duration) var(--lightbox-ease),
    visibility 0s;
  pointer-events: auto;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background-color: var(--color-overlay);
  cursor: pointer;
}

.lightbox-panel {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: min(90vh, 900px);
  max-height: min(90dvh, 900px);
  display: flex;
  flex-direction: column;
  background-color: var(--color-surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28), 0 8px 24px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--color-border);
  transform: rotateY(90deg) scale(0.92);
  transform-origin: center center;
  opacity: 0;
  transition:
    transform var(--lightbox-duration) var(--lightbox-ease),
    opacity var(--lightbox-duration) var(--lightbox-ease);
}

.lightbox.is-open .lightbox-panel {
  transform: rotateY(0deg) scale(1);
  opacity: 1;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 100px;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

.lightbox-close:hover {
  background-color: var(--color-tag-bg);
}

.lightbox-media {
  flex: 1;
  min-height: min(48vh, 420px);
  min-height: min(48dvh, 420px);
  min-width: 0;
  position: relative;
  overflow: hidden;
  display: block;
  background-color: #0a0a0a;
}

.lightbox-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.lightbox-media .carousel-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

.lightbox-media .carousel-track img {
  flex: 0 0 100%;
}

.lightbox-carousel-prev,
.lightbox-carousel-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.lightbox-carousel-prev { left: 12px; }
.lightbox-carousel-next { right: 12px; }

.lightbox-carousel-prev:hover,
.lightbox-carousel-next:hover {
  background: rgba(255, 255, 255, 1);
  transform: translateY(-50%) scale(1.06);
}

.lightbox-carousel-counter {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 2;
  padding: 4px 10px;
  font-size: 0.7rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 100px;
  letter-spacing: 0.04em;
}

.lightbox-content {
  flex-shrink: 0;
  padding: 24px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: 42vh;
  max-height: 42dvh;
}

.lightbox-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  padding-right: 44px;
}

.lightbox-description {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.lightbox-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lightbox-tags .tag-pill {
  font-size: 0.75rem;
}

.lightbox-date {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  padding-top: 4px;
  border-top: 1px solid var(--color-border);
}

@media (min-width: 768px) {
  .lightbox-panel {
    flex-direction: row;
    align-items: stretch;
    max-height: min(88vh, 720px);
    max-height: min(88dvh, 720px);
  }

  .lightbox-media {
    flex: 1.2;
    min-width: 0;
    min-height: 0;
  }

  .lightbox-content {
    flex: 0 0 min(340px, 38%);
    max-height: none;
    overflow-y: auto;
    padding: 28px 28px 32px;
  }

  .lightbox-title {
    padding-right: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lightbox,
  .lightbox.is-open {
    transition-duration: 0.01ms;
    transition-delay: 0s;
  }

  .lightbox-panel {
    transition-duration: 0.01ms;
  }

  .grid-item-entrance {
    transition-duration: 0.01ms;
  }

  .carousel-track,
  .lightbox-media .carousel-track {
    transition-duration: 0.01ms;
  }

  body::after {
    display: none;
  }
}

/* ---- Footer ---- */

.site-footer {
  padding: 40px 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  border-top: 1px solid var(--color-border);
}

/* ---- Empty State ---- */

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

/* ---- Responsive ---- */

@media (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 768px) {
  .image-library {
    padding: 0 16px;
  }

  .site-header {
    padding: 40px 0 24px;
  }

  .site-title {
    font-size: 1.5rem;
  }

  .filter-wrap {
    top: 16px;
    right: 16px;
  }

  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .name-preview {
    display: none;
  }

  .carousel-prev,
  .carousel-next {
    width: 22px;
    height: 22px;
  }

  .carousel-prev { left: 4px; }
  .carousel-next { right: 4px; }

  .lightbox-carousel-prev,
  .lightbox-carousel-next {
    width: 30px;
    height: 30px;
  }

  .lightbox-carousel-prev { left: 8px; }
  .lightbox-carousel-next { right: 8px; }
}

@media (max-width: 400px) {
  .gallery-grid {
    gap: 6px;
  }

  .tag-pill {
    padding: 5px 12px;
    font-size: 0.7rem;
  }
}
