/**
 * Shared image viewer — template-parts/viewer.php, assets/js/viewer.js.
 *
 * Full-bleed obsidian stage for the image (glass and profiles read best on
 * black), a filmstrip under it and a "spec plate" column on the right.
 * Below 960px the plate stacks under the stage and the CTA sticks to the
 * bottom of the screen.
 */

.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-top: var(--wp-admin--admin-bar--height, 0px);
  --vr-plate: 380px;

  position: fixed;
  inset: var(--vr-top) 0 0 0;
  z-index: 99990; /* under #wpadminbar (99999), above site chrome */
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--vr-plate);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "stage info"
    "strip info";
  background: var(--vr-ink);
  color: var(--vr-text);
  font-family: var(--font-sans, system-ui, sans-serif);
}

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

/* 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; }
.eray-vr.is-open .eray-vr-stage { animation: eray-vr-settle 0.32s cubic-bezier(0.16, 1, 0.3, 1) backwards; }

@keyframes eray-vr-fade { from { opacity: 0; } }
@keyframes eray-vr-settle { from { transform: scale(0.985); } }

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

/* ── 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: 4.5rem 5.5rem 4.5rem;
  touch-action: none;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
}

.eray-vr.is-zoomed .eray-vr-canvas { cursor: grab; }
.eray-vr.is-zoomed .eray-vr-canvas:active { 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;
}

.eray-vr.is-dragging .eray-vr-img,
.eray-vr.is-zoomed .eray-vr-canvas:active .eray-vr-img { transition: none; }

.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%); }
}

/* Top bar: counter + close */
.eray-vr-bar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0 1.5rem;
  pointer-events: none;
}

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

.eray-vr-count {
  margin: 0;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
}

.eray-vr-count-i {
  font-size: 1.375rem;
  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: rgba(5, 5, 5, 0.55);
  -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.1);
  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 :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: 1.25rem; }
.eray-vr-nav--next { right: 1.25rem; }

/* Zoom pill */
.eray-vr-zoom {
  position: absolute;
  left: 50%;
  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);
  transform: translateX(-50%);
}

.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);
}

/* ── Filmstrip ─────────────────────────────────────────────────────────── */
.eray-vr-strip {
  grid-area: strip;
  display: flex;
  gap: 8px;
  padding: 12px 1.5rem 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--vr-line);
}

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

.eray-vr-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: #15161a;
  cursor: pointer;
  opacity: 0.45;
  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.08);
}

.eray-vr-thumb:hover { opacity: 0.8; }
.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;
  overflow-y: auto;
  background: var(--vr-surface);
  border-left: 1px solid var(--vr-line);
}

.eray-vr-plate {
  flex: 1 0 auto;
  padding: 5.25rem 2rem 2rem;
}

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

.eray-vr-title {
  margin: 0;
  font-size: clamp(1.625rem, 1.2rem + 1vw, 2.125rem);
  font-weight: 300;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--vr-text);
  text-wrap: balance;
}

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

.eray-vr-specs > div {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.875rem 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.5rem 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 2rem 1.75rem;
  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.5rem;
  border-radius: 999px;
  background: var(--vr-gold);
  color: #050505;
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  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,
  .eray-vr.is-open .eray-vr-stage { animation: none; }
  .eray-vr-img { transition: none; }
  .eray-vr.is-loading .eray-vr-stage::after { animation: none; }
}

/* ── Tablet / mobile: stacked ──────────────────────────────────────────── */
@media (max-width: 959px) {
  .eray-vr {
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .eray-vr-stage {
    /* leaves room for the strip, the title and the sticky CTA on first view */
    height: 52svh;
    min-height: 300px;
  }

  .eray-vr-canvas { padding: 3.75rem 0.75rem 3.75rem; }

  .eray-vr-nav { display: none; } /* swipe on touch; arrows on keyboards */

  .eray-vr-bar { padding: 0.75rem 0.75rem 0 1rem; }

  .eray-vr-zoom { bottom: 0.75rem; }

  .eray-vr-strip { padding: 10px 1rem 12px; }

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

  .eray-vr-info {
    overflow: visible;
    border-left: 0;
    border-top: 1px solid var(--vr-line);
  }

  .eray-vr-plate { padding: 1.25rem 1rem 1.5rem; }

  .eray-vr-kicker { margin-bottom: 0.5rem; }

  .eray-vr-actions { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }

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

@media (hover: hover) and (min-width: 960px) {
  /* Mouse users get arrows; keep them quiet until the stage is hovered */
  .eray-vr-nav { opacity: 0.6; transition: opacity 0.15s ease, background-color 0.15s ease; }
  .eray-vr-stage:hover .eray-vr-nav { opacity: 1; }
}
