/* Page-only styles layered on top of styles.css (luxury silver × gold × yellow) */
:root {
  --modal-max: 1200px;
  --grid-line: #ffffff;
  /* thin white divider lines */
  --grid-gap: 2px;
  /* divider thickness */

  /* Make the gallery wider on this page so each tile is larger in width */
  --container: 1440px;

  /* Single crossfade timing */
  --xfade-dur: 420ms;
  --xfade-ease: cubic-bezier(.22, .61, .36, 1);
}

/* === Page-wide overflow guard (fixes horizontal scrolling) === */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Ensure container total width (content + padding) never exceeds viewport */
.container {
  /* content box is the smaller of the target container or the viewport minus its padding */
  max-width: min(var(--container), calc(100vw - 2 * clamp(16px, 2.5vw, 28px)));
}

/* Optional: make sure grids never leak layout horizontally */
.portfolio-grid {
  overflow-x: clip;
}

@media (min-width: 1600px) {
  :root {
    --container: 1680px;
  }
}

/* ====== PHOTO WALL GRID: 4 per row on desktop ====== */
.portfolio-grid {
  display: grid;
  gap: var(--grid-gap);
  background: var(--grid-line);
  padding: var(--grid-gap);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1200px) {
  .portfolio-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .portfolio-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .portfolio-grid {
    grid-template-columns: 1fr;
  }
}

/* ====== IMAGE TILE (images only) ====== */
.project {
  cursor: pointer;
  outline: none;
  background: transparent;
  border: 0;
  padding: 0;
  box-shadow: none;
  border-radius: 0;
  position: relative;
  transition: transform .2s ease, filter .2s ease;
}

.project:hover {
  transform: translateY(-1px);
  filter: saturate(1.02);
}

.project:focus-visible {
  outline: 3px solid rgba(239, 210, 106, .55);
  outline-offset: 4px;
}

.project-media {
  margin: 0;
}

.project-media img {
  display: block;
  width: 100%;
  height: clamp(240px, 30vw, 460px);
  object-fit: cover;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: #fff;
  transition: transform .25s ease, filter .25s ease;
}

.project:hover .project-media img,
.project:focus-visible .project-media img {
  transform: scale(1.01);
}

/* Title overlay ON the image */
.project::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(36px, 6vw, 56px);
  pointer-events: none;
  background: linear-gradient(180deg, rgba(7, 12, 24, 0) 0%, rgba(7, 12, 24, 0.55) 100%);
}

.project::after {
  content: attr(data-title);
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 1;
  pointer-events: none;
  font-weight: 800;
  font-size: clamp(0.9rem, 1.8vw, 1.05rem);
  line-height: 1.1;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ====== MODAL ====== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 12, 24, .50);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  -webkit-backdrop-filter: saturate(160%) blur(2px);
  backdrop-filter: saturate(160%) blur(2px);
}

/* Show the backdrop whenever it's not hidden (works with your JS toggling [hidden]) */
.modal-backdrop:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

/* Use calc() inside min() to avoid edge cases in some browsers */
.modal {
  width: min(calc(100% - 24px), var(--modal-max));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0;
  margin: auto;
  background: #fff;
  color: var(--text);
  box-shadow: 0 30px 60px rgba(0, 0, 0, .25);
  max-height: calc(100dvh - 24px);

  /* Sticky header + scrollable body */
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  /* (replaces overflow: clip) */
  animation: modal-in .22s ease-out;
}

@keyframes modal-in {
  from {
    transform: translateY(6px);
    opacity: .96;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

@media (max-width:700px) {
  .modal {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border: 0;
  }
}

/* Header */
.modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, .96);
  -webkit-backdrop-filter: saturate(140%) blur(6px);
  backdrop-filter: saturate(140%) blur(6px);
}

.modal-titlegroup h2 {
  margin: .1rem 0 .15rem;
  font-size: clamp(18px, 2.2vw, 22px);
}

.modal-titlegroup p {
  margin: 0;
}

.modal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Body layout (now the scrollable area) */
.modal-body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto 320px;
  grid-template-areas: "prev frame next aside";
  gap: 12px;
  padding: 12px;

  overflow: auto;
  /* scroll when content is tall */
  min-height: 0;
  /* allow grid child to shrink */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;

  /* Anchor for mobile absolute nav buttons */
  position: relative;
}

@media (max-width:980px) {
  .modal-body {
    grid-template-columns: 1fr;
    grid-template-areas: "frame" "aside";
  }
}

/* Frame (double-buffered crossfade) */
.modal-frame {
  grid-area: frame;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  position: relative;
  /* ensures internal overlays (if any) anchor correctly */
  display: grid;
  grid-template-rows: minmax(40vh, min(70vh, 720px)) auto;
  gap: 6px;
  justify-items: center;
}

.img-stage {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
}

.modal-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  opacity: 0;
  transition: opacity var(--xfade-dur) var(--xfade-ease);
  will-change: opacity;
  pointer-events: none;
}

.modal-img.is-visible {
  opacity: 1;
}

.modal-img.is-top {
  z-index: 2;
}

/* Caption */
.modal-frame figcaption {
  font-size: .95rem;
  padding: 0 6px 10px;
  color: var(--muted);
}

/* Buttons */
.icon-btn {
  --ring: rgba(239, 210, 106, .45);
  --bg1: #ffffff;
  --bg2: #f3f5f9;
  --bd: var(--border);
  position: relative;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--bd);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--bg1), var(--bg2));
  box-shadow: 0 2px 0 rgba(16, 24, 40, .04), 0 6px 18px rgba(16, 24, 40, .08);
  color: #0b1220;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease, background .18s ease, opacity .18s ease;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn .icon {
  width: 22px;
  height: 22px;
  display: block;
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring), 0 6px 18px rgba(16, 24, 40, .12);
}

.icon-btn:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--bd) 30%, var(--accent-solid, #c19213) 70%);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .16);
}

.icon-btn[data-press] {
  transform: translateY(0);
  box-shadow: 0 2px 10px rgba(16, 24, 40, .1);
}

.icon-btn::after {
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(60% 60% at 20% 0%, rgba(233, 196, 87, .18), transparent 60%),
    radial-gradient(50% 50% at 80% 0%, rgba(255, 240, 168, .12), transparent 60%);
  opacity: 0;
  transition: opacity .25s ease;
}

.icon-btn:hover::after {
  opacity: 1;
}

/* Desktop placement via grid areas */
.icon-btn.nav {
  align-self: center;
}

.icon-btn.nav.prev {
  grid-area: prev;
}

.icon-btn.nav.next {
  grid-area: next;
}

/* MOBILE FIX: keep arrows inside the frame area and out of the grid auto-placement */
@media (max-width:980px) {
  .icon-btn.nav {
    /* Overlay inside the same frame area to avoid implicit tracks */
    grid-area: frame;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .92);
    z-index: 3;
    /* above image */
    pointer-events: auto;
  }

  .icon-btn.nav.prev {
    left: max(8px, env(safe-area-inset-left));
  }

  .icon-btn.nav.next {
    right: max(8px, env(safe-area-inset-right));
  }
}

.icon-btn.nav.prev .icon,
.icon-btn.nav.next .icon {
  transform: translateX(0);
  transition: transform .18s ease;
}

.icon-btn.nav.prev:hover .icon {
  transform: translateX(-2px);
}

.icon-btn.nav.next:hover .icon {
  transform: translateX(2px);
}

.close-btn .icon {
  transition: transform .25s ease, color .2s ease;
}

.close-btn:hover .icon {
  transform: rotate(90deg);
  color: var(--accent-solid, #c19213);
}

/* Sidebar */
.modal-aside {
  grid-area: aside;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 0;
}

.modal-desc {
  margin: 0;
  color: var(--muted);
}

/* Thumbs */
.modal-thumbs {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
  overflow: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  margin-top: 6px;
}

.modal-thumbs button {
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  line-height: 0;
  scroll-snap-align: start;
  transition: transform .15s ease, border-color .18s ease;
}

.modal-thumbs button:hover {
  transform: translateY(-2px);
}

.modal-thumbs img {
  display: block;
  height: 72px;
  width: auto;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 8px;
}

.modal-thumbs button[aria-current="true"] {
  border-color: var(--accent-solid, #c19213);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --xfade-dur: 1ms;
  }

  * {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}


/* prevent double backdrop (we use our own .modal-backdrop) */
.modal::backdrop {
  background: transparent !important;
}

/* smooth open/close driven by .show class */
.modal {
  opacity: 0;
  transform: translateY(6px) scale(.98);
  transition: opacity .22s ease, transform .22s ease;
  animation: none;
  /* avoid keyframe-only open that can't reverse on close */
}

/* when open + .show: fully visible (JS adds .show after showModal()) */
.modal[open].show {
  opacity: 1;
  transform: none;
}

/* fade backdrop via class instead of instant hidden flip */
.modal-backdrop {
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.modal-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* isolate painting so old pixels don't linger during crossfades */
.modal,
.img-stage {
  contain: paint;
}
