/* =========================================================
   PORTFOLIO GALLERY
   Site-modal window — two layers: grid → single artwork.
   Matches About / Contact window shell exactly.
   ========================================================= */

/* ── Backdrop ── */
#gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 9800;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 25, 23, 0.36);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity   0.34s cubic-bezier(0.22, 1, 0.36, 1),
              visibility 0.34s;
}

#gallery-overlay.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Panel (matches About/Contact shell exactly) ── */
#gallery-panel {
  position: relative;
  width: min(860px, calc(100vw - 32px));
  height: min(76vh, 680px);
  background: rgba(250, 248, 244, 0.94);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(28, 25, 23, 0.09);
  border-radius: 22px;
  box-shadow:
    0 32px 80px rgba(28, 25, 23, 0.16),
    0 4px  16px rgba(28, 25, 23, 0.08);
  overflow: hidden;
  transform: translateY(8px) scale(0.97);
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

#gallery-overlay.is-open #gallery-panel {
  transform: translateY(0) scale(1);
}

/* ── Close × icon (shared base styles) ── */
.gallery-close-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(28, 25, 23, 0.13);
  background: transparent;
  color: rgba(28, 25, 23, 0.46);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background   0.18s ease,
              color        0.18s ease,
              border-color 0.18s ease;
}

.gallery-close-btn:hover {
  background: rgba(28, 25, 23, 0.07);
  color: rgba(28, 25, 23, 0.88);
  border-color: rgba(28, 25, 23, 0.22);
}

.gallery-close-btn:focus-visible {
  outline: 2px solid rgba(217, 101, 53, 0.7);
  outline-offset: 2px;
}

/* ── View toggle ── */
.gal-hidden { display: none !important; }


/* ═══════════════════════════════════════════════════════
   LIST VIEW
═══════════════════════════════════════════════════════ */

#gallery-list-view {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* × floats over the header in list view */
#gallery-list-view > .gallery-close-btn {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 20;
}

/* Non-scrolling header — kept compact to maximise grid area */
.gallery-header {
  flex-shrink: 0;
  padding: 22px 44px 0;
  padding-right: 62px;   /* clear the × button */
}

.gallery-eyebrow {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.34em;
  color: rgba(28, 25, 23, 0.48);
  margin-bottom: 4px;
}

.gallery-cat-title {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: clamp(22px, 2.6vw, 28px);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #1C1917;
  margin: 0;
  line-height: 1.1;
}

.gallery-orange-rule {
  display: block;
  width: 48px;
  height: 2px;
  background: #D96535;
  border: none;
  margin: 10px 0 6px;
}

.gallery-count {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: rgba(28, 25, 23, 0.38);
  margin: 0;
}

/* ── Filter bar ── */
.gallery-filter-bar {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  padding: 10px 44px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.gallery-filter-bar::-webkit-scrollbar { display: none; }

.gallery-filter-pill {
  flex-shrink: 0;
  height: 27px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(28, 25, 23, 0.14);
  background: transparent;
  color: rgba(28, 25, 23, 0.50);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.gallery-filter-pill:hover {
  background: rgba(28, 25, 23, 0.06);
  color: rgba(28, 25, 23, 0.80);
  border-color: rgba(28, 25, 23, 0.22);
}

.gallery-filter-pill.is-active {
  background: #D96535;
  color: #FAF8F4;
  border-color: #D96535;
}

.gallery-filter-pill:focus-visible {
  outline: 2px solid rgba(217, 101, 53, 0.7);
  outline-offset: 2px;
}

.gallery-filter-count {
  font-size: 9px;
  font-weight: 500;
  opacity: 0.68;
  letter-spacing: 0;
}

.gallery-filter-pill.is-active .gallery-filter-count {
  opacity: 0.85;
}

/* Card entry animation — plays on grid rebuild (filter change or open) */
@keyframes gal-card-in {
  from { opacity: 0; transform: scale(0.95) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Scrollable grid — 4 columns, Instagram-style */
#gallery-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 28px 28px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: rgba(28, 25, 23, 0.14) transparent;
}

#gallery-grid::-webkit-scrollbar         { width: 5px; }
#gallery-grid::-webkit-scrollbar-track   { background: transparent; }
#gallery-grid::-webkit-scrollbar-thumb   {
  background: rgba(28, 25, 23, 0.14);
  border-radius: 3px;
}

/* Card = grid item. Square enforced via ::before padding-top trick —
   more reliable than aspect-ratio alone when images have large natural sizes. */
.gallery-card {
  position: relative;
  overflow: hidden;
  border-radius: 5px;
  cursor: pointer;
  outline: none;
  background: #EDE9E1;
  z-index: 1;
  min-width: 0;         /* prevent grid blowout */
  align-self: start;    /* don't let grid stretch cards taller than their square */
  animation: gal-card-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
              filter    0.22s ease;
}

/* Spacer that forces card height = card width (100% of own width) */
.gallery-card::before {
  content: '';
  display: block;
  padding-top: 100%;
}

.gallery-card:focus-visible {
  outline: 2px solid rgba(217, 101, 53, 0.65);
  outline-offset: 2px;
}

/* Wrap fills the entire card (absolute so it doesn't affect card height) */
.gallery-thumb-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.gallery-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (hover: hover) {
  .gallery-card:hover .gallery-thumb-img { transform: scale(1.05); }
}

/* ── Visit Project button in detail view ── */
.gallery-visit-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 14px;
  color: #D96535;
  text-decoration: none;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  transition: transform 0.18s ease, color 0.18s ease;
}

.gallery-visit-btn:hover {
  color: #c9664a;
  transform: translateX(4px);
}

/* YouTube play badge */
.gallery-thumb-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  background: rgba(250, 248, 244, 0.88);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1C1917;
  pointer-events: none;
  transition: transform 0.22s ease, background 0.22s ease;
}

@media (hover: hover) {
  .gallery-card:hover .gallery-thumb-play {
    transform: translate(-50%, -50%) scale(1.12);
    background: rgba(250, 248, 244, 1);
  }
}

/* Title overlaid at bottom of card — revealed on hover */
.gallery-thumb-title {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 26px 8px 7px;
  background: linear-gradient(to top, rgba(0,0,0,0.70) 0%, transparent 100%);
  color: rgba(255,255,255,0.95);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.20s ease, transform 0.20s ease;
}

@media (hover: hover) {
  .gallery-card:hover .gallery-thumb-title {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Hover effect: hovered card gains saturation — no blur or desaturation on others. */
@media (hover: hover) {
  #gallery-grid:has(.gallery-card:hover) .gallery-card:hover {
    transform: scale(1.06);
    filter: saturate(1.55);
    z-index: 10;
  }
}


/* ═══════════════════════════════════════════════════════
   DETAIL VIEW
═══════════════════════════════════════════════════════ */

#gallery-detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* Topbar: breadcrumb left, × right */
.gallery-detail-topbar {
  flex-shrink: 0;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  border-bottom: 1px solid rgba(28, 25, 23, 0.07);
}

.gallery-detail-breadcrumb {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: rgba(28, 25, 23, 0.36);
  user-select: none;
}

/* Push × to the right side of topbar */
.gallery-detail-topbar > .gallery-close-btn {
  margin-left: auto;
}

/* Image area fills all remaining space */
.gallery-detail-img-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #F2EEE6;
  overflow: hidden;
}

/* Static image */
#gallery-detail-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

/* YouTube facade */
.gallery-yt-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-yt-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity 0.22s ease;
}

.gallery-yt-play {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(250, 248, 244, 0.90);
  border: none;
  color: #1C1917;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 3px;   /* optical: triangle needs a touch left */
  z-index: 5;
  transition: transform 0.22s ease, background 0.22s ease;
}

.gallery-yt-play:hover {
  transform: scale(1.10);
  background: rgba(250, 248, 244, 1);
}

.gallery-yt-play:focus-visible {
  outline: 2px solid rgba(217, 101, 53, 0.7);
  outline-offset: 3px;
}

.gallery-yt-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  opacity: 0;
  transition: opacity 0.30s ease;
}

/* Title scrim overlay at bottom of image */
.gallery-detail-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 60px 24px 14px;
  background: linear-gradient(to top, rgba(18, 16, 14, 0.65) 0%, transparent 100%);
  pointer-events: none;
}

.gallery-detail-title {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgba(250, 248, 244, 0.97);
  margin: 0;
  text-shadow: 0 1px 6px rgba(18, 16, 14, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Navigation arrows */
.gallery-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(18, 16, 14, 0.14);
  color: rgba(250, 248, 244, 0.82);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.18s ease,
              color      0.18s ease,
              transform  0.18s ease;
}

.gallery-nav-btn:hover {
  background: rgba(18, 16, 14, 0.32);
  color: rgba(250, 248, 244, 1);
  transform: translateY(-50%) scale(1.12);
}

.gallery-nav-btn:focus-visible {
  outline: 2px solid rgba(217, 101, 53, 0.7);
  outline-offset: 2px;
}

.gallery-nav-prev { left: 12px; }
.gallery-nav-next { right: 12px; }

/* Description strip below image */
.gallery-detail-desc-strip {
  flex-shrink: 0;
  padding: 12px 28px 13px;
  border-top: 1px solid rgba(28, 25, 23, 0.07);
}

.gallery-detail-desc {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.7;
  color: rgba(28, 25, 23, 0.54);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}


/* ═══════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════ */

@media (max-width: 720px) {
  #gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 4px 18px 20px;
  }

  .gallery-header {
    padding: 20px 20px 0;
    padding-right: 50px;
  }

  .gallery-filter-bar {
    padding: 8px 18px 10px;
  }
}

@media (max-width: 500px) {
  #gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 4px 12px 16px;
  }
}

@media (max-width: 360px) {
  #gallery-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Detail view responsive */
@media (max-width: 600px) {
  .gallery-detail-desc { -webkit-line-clamp: 3; }
  .gallery-detail-desc-strip { padding: 10px 18px 12px; }
}

/* Scroll lock while gallery is open */
body.gallery-open { overflow: hidden; }

/* ── Mobile: match .site-modal dimensions exactly ── */
@media (max-width: 736px) {
  #gallery-overlay {
    padding-top: 64px;
  }

  #gallery-panel {
    width: calc(100vw - 20px);
    height: min(82vh, 600px);
    border-radius: 18px;
  }
}
