/**
 * Shared image viewer — template-parts/viewer.php, assets/js/viewer.js.
 *
 * The image is what people open this for, so it gets the whole screen:
 * controls float over it, the filmstrip overlays its bottom edge, and the
 * info is a collapsible side column on desktop and a bottom sheet on mobile
 * (title + CTA collapsed). A single tap hides every control.
 */

.eray-vr {
  --vr-ink: #050505;
  --vr-surface: #0c0d10;
  --vr-line: rgba(255, 255, 255, 0.1);
  --vr-text: #ecebe6;
  --vr-muted: rgba(236, 235, 230, 0.6);
  --vr-gold: #c9a86a;
  --vr-gold-hi: #dcc08a;
  --vr-glass: rgba(5, 5, 5, 0.55);
  --vr-plate: 340px;

  position: fixed;
  inset: 0;
  z-index: 100000; /* above #wpadminbar (99999): the image gets the whole screen */
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--vr-plate);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "stage info";
  background: var(--vr-ink);
  color: var(--vr-text);
  font-family: var(--font-sans, system-ui, sans-serif);
  overscroll-behavior: contain;
}

.eray-vr[hidden] { display: none; }

.eray-vr *,
.eray-vr *::before,
.eray-vr *::after { box-sizing: border-box; }

/* Entrance only: the resting state is fully opaque, so a paused animation
   (background tab) can never leave the viewer half-transparent. */
.eray-vr.is-open { animation: eray-vr-fade 0.22s ease backwards; }
@keyframes eray-vr-fade { from { opacity: 0; } }

/* Desktop: info column collapsed via the (i) button */
.eray-vr.is-info-toggled { grid-template-columns: minmax(0, 1fr) 0; }
.eray-vr.is-info-toggled .eray-vr-info { visibility: hidden; }

/* ── Stage ─────────────────────────────────────────────────────────────── */
.eray-vr-stage {
  grid-area: stage;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.eray-vr-canvas {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  touch-action: none;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.eray-vr.is-zoomed .eray-vr-canvas { cursor: grab; }
.eray-vr.is-zoomed.is-gesturing .eray-vr-canvas { cursor: grabbing; }

.eray-vr-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  margin: 0;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  will-change: transform;
  -webkit-user-drag: none;
}

/* Follow the fingers 1:1 while a gesture is in progress */
.eray-vr.is-gesturing .eray-vr-img { transition: opacity 0.2s ease; }

.eray-vr.is-loading .eray-vr-img { opacity: 0.35; }

/* Loading hairline across the top of the stage */
.eray-vr-stage::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 1px;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--vr-gold), transparent);
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.eray-vr.is-loading .eray-vr-stage::after {
  opacity: 1;
  animation: eray-vr-load 1.1s ease-in-out infinite;
}

@keyframes eray-vr-load {
  to { transform: translateX(100%); }
}

/* ── Floating chrome (hidden together by a single tap) ─────────────────── */
.eray-vr-bar,
.eray-vr-nav,
.eray-vr-zoom,
.eray-vr-strip {
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.eray-vr.is-chrome-hidden .eray-vr-bar,
.eray-vr.is-chrome-hidden .eray-vr-nav,
.eray-vr.is-chrome-hidden .eray-vr-zoom,
.eray-vr.is-chrome-hidden .eray-vr-strip {
  opacity: 0;
  visibility: hidden;
}

.eray-vr-bar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.75rem 1.5rem 1.25rem;
  background: linear-gradient(to bottom, rgba(5, 5, 5, 0.55), transparent);
  pointer-events: none;
}

.eray-vr-bar > * { pointer-events: auto; }

.eray-vr-bar-end {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.eray-vr-count {
  margin: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.eray-vr-count[hidden] { display: none; }

.eray-vr-count-i {
  font-size: 1.25rem;
  font-weight: 300;
  color: var(--vr-text);
}

.eray-vr-count-n {
  font-size: 0.8125rem;
  color: var(--vr-muted);
}

/* Shared round icon button */
.eray-vr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--vr-line);
  border-radius: 999px;
  background: var(--vr-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--vr-text);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.eray-vr-icon-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
}

.eray-vr-icon-btn:disabled { opacity: 0.35; cursor: default; }
.eray-vr-icon-btn[hidden] { display: none; }

.eray-vr-info-btn[aria-expanded="true"] {
  border-color: rgba(201, 168, 106, 0.6);
  color: var(--vr-gold-hi);
}

.eray-vr :focus-visible {
  outline: 2px solid var(--vr-gold);
  outline-offset: 2px;
}

.eray-vr-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 52px;
  height: 52px;
  transform: translateY(-50%);
}

.eray-vr-nav--prev { left: 1rem; }
.eray-vr-nav--next { right: 1rem; }

/* Zoom pill (desktop) */
.eray-vr-zoom {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--vr-line);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.6);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.eray-vr-zoom .eray-vr-icon-btn {
  width: 36px;
  height: 36px;
  border-color: transparent;
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.eray-vr-zoom-pct {
  min-width: 3.25rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--vr-muted);
}

/* One-time touch hint */
.eray-vr-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  margin: 0;
  padding: 0.625rem 1rem;
  max-width: calc(100% - 3rem);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 0.8125rem;
  line-height: 1.4;
  text-align: center;
  color: var(--vr-text);
  transform: translate(-50%, -50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.eray-vr.is-hinting .eray-vr-hint { opacity: 1; visibility: visible; }

/* ── Filmstrip: overlays the bottom edge of the image ──────────────────── */
.eray-vr-strip {
  grid-area: stage;
  align-self: end;
  z-index: 3;
  display: flex;
  gap: 6px;
  max-width: calc(100% - 16rem); /* clear of the zoom pill */
  padding: 1.5rem 1.25rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
  background: linear-gradient(to top, rgba(5, 5, 5, 0.6), transparent);
}

.eray-vr-strip::-webkit-scrollbar { display: none; }
.eray-vr-strip[hidden] { display: none; }

/* Out of the way while inspecting a detail */
.eray-vr.is-zoomed .eray-vr-strip { opacity: 0; visibility: hidden; }

.eray-vr-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: #15161a;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.eray-vr-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  object-fit: cover;
}

.eray-vr-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.eray-vr-thumb:hover { opacity: 0.85; }
.eray-vr-thumb.is-active { opacity: 1; }
.eray-vr-thumb.is-active::after { box-shadow: inset 0 0 0 2px var(--vr-gold); }

/* ── Spec plate ────────────────────────────────────────────────────────── */
.eray-vr-info {
  grid-area: info;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  background: var(--vr-surface);
  border-left: 1px solid var(--vr-line);
}

.eray-vr-plate {
  flex: 1 0 auto;
  padding: 4.75rem 1.75rem 1.75rem;
}

/* Desktop: the sheet head is just the heading block */
.eray-vr-sheet-head {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: default;
}

.eray-vr-sheet-grip,
.eray-vr-sheet-more { display: none; }

.eray-vr-kicker {
  display: block;
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--vr-gold);
}

.eray-vr-title {
  display: block;
  margin: 0;
  font-size: clamp(1.5rem, 1.15rem + 0.8vw, 1.875rem);
  font-weight: 300;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--vr-text);
  text-wrap: balance;
}

.eray-vr-specs {
  margin: 1.5rem 0 0;
  padding: 0;
  border-top: 1px solid var(--vr-gold);
}

.eray-vr-specs > div {
  display: grid;
  grid-template-columns: 6.75rem minmax(0, 1fr);
  gap: 0.875rem;
  padding: 0.8125rem 0;
  border-bottom: 1px solid var(--vr-line);
}

.eray-vr-specs dt {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--vr-muted);
}

.eray-vr-specs dd {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--vr-text);
}

.eray-vr-desc {
  margin: 1.25rem 0 0;
  max-width: 36ch;
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--vr-muted);
}

.eray-vr-specs[hidden],
.eray-vr-plate [hidden] { display: none; }

.eray-vr-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem 1.75rem 1.5rem;
  background: var(--vr-surface);
  border-top: 1px solid var(--vr-line);
}

.eray-vr-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  min-height: 52px;
  padding: 0 1.25rem;
  border-radius: 999px;
  background: var(--vr-gold);
  color: #050505;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.eray-vr-cta:hover { background: var(--vr-gold-hi); color: #050505; }
.eray-vr-cta:active { transform: scale(0.98); }
.eray-vr-cta[hidden] { display: none; }

.eray-vr-link {
  align-self: center;
  padding: 0.375rem 0.25rem;
  font-size: 0.875rem;
  color: var(--vr-text);
  text-decoration: underline;
  text-decoration-color: rgba(236, 235, 230, 0.35);
  text-underline-offset: 4px;
}

.eray-vr-link:hover { color: var(--vr-gold-hi); text-decoration-color: currentColor; }

.eray-vr-note {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  text-align: center;
  color: var(--vr-muted);
}

@media (prefers-reduced-motion: reduce) {
  .eray-vr.is-open { animation: none; }
  .eray-vr-img { transition: none; }
  .eray-vr.is-loading .eray-vr-stage::after { animation: none; }
}

@media (hover: hover) and (min-width: 960px) {
  .eray-vr-nav { opacity: 0.6; transition: opacity 0.15s ease, background-color 0.15s ease, visibility 0.2s ease; }
  .eray-vr-stage:hover .eray-vr-nav { opacity: 1; }
}

/* ── Mobile: full-screen image, info as a bottom sheet ─────────────────── */
@media (max-width: 959px) {
  .eray-vr {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "stage"
      "info";
  }

  .eray-vr.is-info-toggled { grid-template-columns: minmax(0, 1fr); }
  .eray-vr.is-info-toggled .eray-vr-info { visibility: visible; }

  .eray-vr-canvas { padding: 0; }

  /* Swipe on touch; the (i) button is replaced by the sheet head */
  .eray-vr-nav,
  .eray-vr-info-btn,
  .eray-vr-zoom { display: none; }

  /* Pinch replaces the zoom pill; offer a reset only once zoomed in */
  .eray-vr.is-zoomed .eray-vr-zoom {
    display: flex;
    right: 0.75rem;
    bottom: 0.75rem;
  }
  .eray-vr.is-zoomed .eray-vr-zoom [data-vr-zoom="-1"],
  .eray-vr.is-zoomed .eray-vr-zoom [data-vr-zoom="1"] { display: none; }

  .eray-vr-bar { padding: 0.5rem 0.5rem 1.5rem 1rem; }

  .eray-vr-strip {
    max-width: 100%;
    padding: 1.25rem 0.75rem 0.75rem;
  }

  .eray-vr-thumb { width: 44px; height: 44px; }

  /* Collapsed sheet: title row + CTA, sits under the image */
  .eray-vr-info {
    position: relative;
    z-index: 5;
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--vr-line);
    transition: none;
  }

  .eray-vr-plate { padding: 0; }

  .eray-vr-sheet-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "grip grip"
      "kicker more"
      "title more";
    column-gap: 0.75rem;
    padding: 0.375rem 1rem 0.625rem;
    cursor: pointer;
  }

  .eray-vr-sheet-grip {
    grid-area: grip;
    display: block;
    justify-self: center;
    width: 36px;
    height: 4px;
    margin-bottom: 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
  }

  .eray-vr-kicker { grid-area: kicker; margin: 0 0 0.125rem; font-size: 0.75rem; }

  .eray-vr-title {
    grid-area: title;
    font-size: 1.125rem;
    line-height: 1.3;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .eray-vr-sheet-more {
    grid-area: more;
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: var(--vr-muted);
  }

  .eray-vr-sheet-more svg { transition: transform 0.2s ease; }
  .eray-vr-sheet-more-close { display: none; }

  .eray-vr-specs,
  .eray-vr-desc,
  .eray-vr-link,
  .eray-vr-note { display: none; }

  .eray-vr-actions {
    position: static;
    flex-direction: row;
    padding: 0 1rem calc(0.75rem + env(safe-area-inset-bottom));
    border-top: 0;
  }

  .eray-vr-cta { flex: 1; min-height: 48px; }

  /* Expanded sheet: slides over the lower part of the image */
  .eray-vr.is-info-toggled .eray-vr-info {
    position: absolute;
    inset: auto 0 0 0;
    max-height: 78svh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
  }

  .eray-vr.is-info-toggled .eray-vr-title { white-space: normal; font-size: 1.375rem; }
  .eray-vr.is-info-toggled .eray-vr-sheet-more svg { transform: rotate(180deg); }
  .eray-vr.is-info-toggled .eray-vr-sheet-more-open { display: none; }
  .eray-vr.is-info-toggled .eray-vr-sheet-more-close { display: inline; }

  .eray-vr.is-info-toggled .eray-vr-specs { display: block; margin: 0.75rem 1rem 0; }
  .eray-vr.is-info-toggled .eray-vr-specs[hidden] { display: none; }
  .eray-vr.is-info-toggled .eray-vr-desc { display: block; margin: 1rem 1rem 0; }
  .eray-vr.is-info-toggled .eray-vr-desc[hidden] { display: none; }
  .eray-vr.is-info-toggled .eray-vr-plate { padding-bottom: 1rem; }

  .eray-vr.is-info-toggled .eray-vr-actions {
    position: sticky;
    bottom: 0;
    flex-direction: column;
    padding-top: 0.75rem;
    background: var(--vr-surface);
    border-top: 1px solid var(--vr-line);
  }

  .eray-vr.is-info-toggled .eray-vr-link,
  .eray-vr.is-info-toggled .eray-vr-note { display: block; }
  .eray-vr.is-info-toggled .eray-vr-link { align-self: center; }

  .eray-vr-specs > div { grid-template-columns: 6.25rem minmax(0, 1fr); }

  /* Single tap: image only */
  .eray-vr.is-chrome-hidden .eray-vr-info { display: none; }
  .eray-vr.is-chrome-hidden { grid-template-rows: minmax(0, 1fr); }
}
