/*
 * Artwork detail view (modal dialog).
 * Desktop: text panel on the left, the painting hung on a quiet "wall" on the
 * right. The wall is sticky inside the overlay's own scroller, so only the
 * panel moves if its text runs long. The painting is never cropped: the
 * frame takes the work's own aspect ratio (--ratio, set by overlay.js).
 */
.overlay {
  --wall-pad: max(2rem, calc(96 * var(--u)));
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
}
.overlay[hidden] { display: none; }
.overlay:focus { outline: none; }

.overlay__bg {
  position: absolute;
  inset: 0;
  background: var(--c-canvas);
}

.overlay__scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.overlay__inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 38fr) minmax(0, 62fr);
  min-height: 100%;
}

/* ---------- panel (left) ---------- */
.overlay__panel {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(var(--header-h) + var(--sp-24)) var(--sp-48) 0 var(--margin);
}
.overlay__content {
  display: grid;
  align-content: start;
  row-gap: var(--sp-48);
  padding-bottom: var(--sp-80);
}

.ov-index { font-weight: 500; }
.ov-index__num { color: var(--c-accent); font-variant-numeric: tabular-nums; }
.ov-index__cat { color: var(--c-muted); }

.ov-title {
  font-size: max(2.75rem, calc(92 * var(--u)));
  line-height: 0.92;
  font-weight: 700;
  letter-spacing: var(--tracking-display);
  overflow-wrap: break-word;
}

.ov-meta { border-bottom: 1px solid var(--c-line); }
.ov-meta li { border-top: 1px solid var(--c-line); }
.ov-meta__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-block: 0.7rem;
}
.ov-meta__label { color: var(--c-muted); }
.ov-meta__value { font-weight: 500; text-align: right; }

.ov-desc { max-width: 30em; white-space: pre-line; }

.ov-inquire { justify-self: start; font-size: var(--fs-body); }

/* ---------- previous / next ---------- */
.overlay__nav {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding-block: var(--sp-24);
  border-top: 1px solid var(--c-line);
  background: var(--c-canvas);
}
.overlay__nav[hidden] { display: none; }
.ov-step {
  display: grid;
  row-gap: 0.15rem;
  min-height: 2.75rem;
  min-width: 0;
  text-align: left;
}
.ov-step--next { text-align: right; justify-items: end; }
.ov-step__dir {
  font-size: var(--fs-small);
  color: var(--c-muted);
  transition: color var(--dur-dim) var(--ease-standard);
}
.ov-step__title {
  max-width: 100%;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (hover: hover) {
  .ov-step:hover .ov-step__dir { color: var(--c-accent); }
}
.ov-count { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- wall + painting (right) ---------- */
.overlay__wall {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  height: 100vh;
  height: 100dvh;
  padding: var(--wall-pad);
  background: var(--c-wall);
}
.overlay__frame {
  --ratio: 1;
  aspect-ratio: var(--ratio);
  width: min(100%, calc((100dvh - 2 * var(--wall-pad)) * var(--ratio)));
  /* a painting hangs on the wall: the faintest contact shadow, nothing more */
  box-shadow: 0 1px 2px rgba(32, 32, 29, 0.12), 0 24px 48px -28px rgba(32, 32, 29, 0.45);
}
.overlay__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.overlay.is-flipping .overlay__img { visibility: hidden; }

/* close floats above the wall */
.overlay__close {
  position: fixed;
  z-index: 3;
  top: max(0.75rem, calc(20 * var(--u)));
  right: max(0.75rem, calc(20 * var(--u)));
  width: max(3rem, calc(60 * var(--u)));
  height: max(3rem, calc(60 * var(--u)));
  display: grid;
  place-items: center;
  background: var(--c-canvas);
  color: var(--c-ink);
}
.overlay__close svg {
  width: 40%;
  height: 40%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  transition: transform var(--dur-btn) var(--ease-out-expo);
}
@media (hover: hover) {
  .overlay__close:hover svg { transform: rotate(90deg); }
}

/* FLIP clone */
.flip-clone {
  position: fixed;
  z-index: var(--z-flip);
  top: 0;
  left: 0;
  overflow: hidden;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
}
.flip-clone img {
  position: absolute;
  max-width: none;
  object-fit: cover;
}

/* ---------- tablet and below: painting first, text below ---------- */
@media (max-width: 991px) {
  .overlay { --wall-pad: 2rem; }
  .overlay__inner { grid-template-columns: 1fr; }
  .overlay__wall {
    order: -1;
    position: relative;
    height: auto;
    padding: calc(var(--wall-pad) + 2.5rem) var(--wall-pad) var(--wall-pad);
  }
  .overlay__frame { width: min(100%, calc(68svh * var(--ratio))); }
  .overlay__panel {
    min-height: 0;
    padding: var(--sp-48) var(--margin) 0;
  }
  .overlay__content { padding-bottom: var(--sp-48); max-width: 40rem; }
}

@media (max-width: 767px) {
  .overlay { --wall-pad: 1.25rem; }
  .overlay__frame { width: min(100%, calc(62svh * var(--ratio))); }
  .overlay__content { row-gap: 2rem; }
  .ov-title { font-size: clamp(2.5rem, 12vw, 3.5rem); }
  .ov-step__title { font-size: var(--fs-small); }
  .overlay__nav { padding-block: 0.75rem calc(0.75rem + env(safe-area-inset-bottom)); }
}

/* landscape phones: a short viewport, so keep the painting beside the text */
@media (max-width: 991px) and (orientation: landscape) and (max-height: 560px) {
  .overlay__inner { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .overlay__wall {
    order: 1;
    position: sticky;
    height: 100dvh;
    padding: 1.25rem;
  }
  .overlay__frame { width: min(100%, calc((100dvh - 2.5rem) * var(--ratio))); }
  .overlay__panel { min-height: 100dvh; padding-top: 1.5rem; }
}

/* optional detail image under the description */
.ov-detail { display: grid; row-gap: 0.5rem; max-width: 22rem; }
.ov-detail img { width: 100%; height: auto; }
