/*
 * Sitewide photo viewer (assets/js/photo-viewer.js).
 * Spec: docs/superpowers/specs/2026-12-02-photo-viewer-design.md §6.
 *
 * Self-contained: every class is pv- prefixed and every token reads the kit's
 * --k-* value with the kit's own value as the fallback, so pages without
 * app-kit.css (Pickture, Media Library) still get the Jiak Simi look.
 * Unlayered on purpose, so it beats Jiak Simi's @layer components and
 * Tailwind preflight. Dark only under :root[data-theme="dark"], like every
 * host: no prefers-color-scheme rules. Do not rename this file (the deploy
 * never deletes, so the old name would stay live).
 */

/* Same families and URLs as app-kit.css; a duplicate declaration is harmless. */
@font-face { font-family: "Bricolage Grotesque"; src: url("/assets/fonts/bricolage.ttf") format("truetype"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url("/assets/fonts/dmsans.ttf") format("truetype"); font-weight: 100 1000; font-display: swap; }

/* ---------- tokens (fallbacks copied from app-kit.css) ---------- */
.pv-root {
  --pv-primary: var(--k-primary, oklch(0.38 0.075 322));
  --pv-ink: var(--k-ink, oklch(0.32 0.046 320));
  --pv-muted: var(--k-muted, oklch(0.53 0.035 315));
  --pv-outline: var(--k-outline, oklch(0.43 0.05 315));
  --pv-rule: var(--k-rule, oklch(0.86 0.025 314));
  --pv-paper: var(--k-paper, oklch(0.996 0.006 80));
  --pv-lilac: var(--k-lilac, oklch(0.92 0.039 303));
  --pv-lilac-strong: var(--k-lilac-strong, oklch(0.79 0.078 303));
  --pv-pink: var(--k-pink, oklch(0.87 0.068 355));
  --pv-shadow: var(--k-shadow, oklch(0.58 0.06 313 / 0.14));
  --pv-font-display: var(--k-font-display, "Bricolage Grotesque", system-ui, sans-serif);
  --pv-font-sans: var(--k-font-sans, "DM Sans", system-ui, sans-serif);
  --pv-ease: var(--k-ease, cubic-bezier(0.32, 0.72, 0, 1));
  --pv-scrim: oklch(0.17 0.02 315 / 0.94); /* solid ink wash in both themes */
  --pv-btn: 38px;
  color-scheme: light;
}
:root[data-theme="dark"] .pv-root {
  --pv-primary: var(--k-primary, oklch(0.82 0.07 322));
  --pv-ink: var(--k-ink, oklch(0.93 0.015 320));
  --pv-muted: var(--k-muted, oklch(0.74 0.03 315));
  --pv-outline: var(--k-outline, oklch(0.72 0.05 315));
  --pv-rule: var(--k-rule, oklch(0.36 0.025 314));
  --pv-paper: var(--k-paper, oklch(0.26 0.022 315));
  --pv-lilac: var(--k-lilac, oklch(0.33 0.04 303));
  --pv-lilac-strong: var(--k-lilac-strong, oklch(0.5 0.07 303));
  --pv-pink: var(--k-pink, oklch(0.38 0.06 355));
  --pv-shadow: var(--k-shadow, oklch(0.1 0.02 313 / 0.4));
  color-scheme: dark;
}
@media (pointer: coarse) {
  .pv-root { --pv-btn: 44px; }
}

/* ---------- the dialog: fills the window, top layer ---------- */
dialog.pv-root {
  position: fixed; inset: 0;
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0;
  background: transparent; color: var(--pv-ink);
  overflow: hidden;
  pointer-events: auto;          /* beats Radix's body pointer-events:none */
  touch-action: none;
  overscroll-behavior: contain;
  font-family: var(--pv-font-sans); font-size: 14px; line-height: 1.5;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
dialog.pv-root[open] { display: block; animation: pv-in 200ms var(--pv-ease); }
dialog.pv-root::backdrop { background: transparent; }
.pv-root *, .pv-root *::before, .pv-root *::after { box-sizing: border-box; }
@keyframes pv-in { from { opacity: 0; } to { opacity: 1; } }

.pv-scrim { position: absolute; inset: 0; background: var(--pv-scrim); }

/* ---------- stage, track, slides ---------- */
.pv-stage { position: absolute; inset: 0; overflow: hidden; outline: none; touch-action: none; }
.pv-stage:focus-visible { box-shadow: inset 0 0 0 3px var(--pv-lilac-strong); }
.pv-track { position: absolute; inset: 0; will-change: transform; }
.pv-slide { position: absolute; inset: 0; }
.pv-slide[hidden] { display: none; }

.pv-root .pv-img, .pv-mat {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.pv-root .pv-img {
  display: block; max-width: none; max-height: none; margin: 0;
  border-radius: 8px;
  -webkit-user-drag: none; -webkit-touch-callout: none;
  cursor: zoom-in;
}
/* The paper mat: decoration behind the print, never a clipping window. */
.pv-mat {
  background: var(--pv-paper);
  border: 1.5px solid var(--pv-outline);
  border-radius: 14px;
  box-shadow: 6px 6px 0 var(--pv-lilac-strong);
  transition: opacity 200ms var(--pv-ease);
}
.pv-slide.is-zoomed .pv-mat { opacity: 0; }
.pv-slide.is-zoomed .pv-img { border-radius: 0; cursor: grab; }
.pv-slide.is-error .pv-img, .pv-slide.is-error .pv-mat { visibility: hidden; }

.pv-spin {
  position: absolute; left: 50%; top: 50%;
  width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border: 2.5px solid var(--pv-lilac-strong); border-top-color: var(--pv-primary); border-radius: 50%;
  animation: pv-spin 0.8s linear infinite;
}
@keyframes pv-spin { to { transform: rotate(360deg); } }

/* ---------- load error: the lilac kit placeholder ---------- */
.pv-error {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(320px, calc(100% - 32px));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px 20px;
  background: var(--pv-lilac); color: var(--pv-muted);
  border: 1.5px solid var(--pv-outline); border-radius: 14px;
  box-shadow: 6px 6px 0 var(--pv-lilac-strong);
  text-align: center;
}
.pv-error > svg { width: 44px; height: 44px; }
.pv-error p { margin: 0; color: var(--pv-ink); font-weight: 600; }
.pv-error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pv-spin[hidden], .pv-error[hidden] { display: none; }

/* ---------- chrome: always on paper, never straight on the photo ---------- */
.pv-chrome { position: absolute; inset: 0; pointer-events: none; transition: opacity 180ms var(--pv-ease); }
.pv-chrome > * { pointer-events: auto; }
.pv-root.is-chrome-hidden .pv-chrome { opacity: 0; }
.pv-root.is-chrome-hidden .pv-chrome, .pv-root.is-chrome-hidden .pv-chrome * { pointer-events: none; }

.pv-top {
  position: absolute; top: 12px; left: 12px; right: 12px;
  display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.pv-top > * { pointer-events: auto; }
.pv-counter {
  padding: 4px 12px;
  background: var(--pv-paper); color: var(--pv-ink);
  border: 1.5px solid var(--pv-outline); border-radius: 999px;
  box-shadow: 2px 3px 0 var(--pv-shadow);
  font-family: var(--pv-font-display); font-weight: 700; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.pv-counter[hidden] { display: none; }
.pv-close { margin-left: auto; }

/* .k-btn.is-icon.is-round, copied as .pv-btn */
.pv-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-width: var(--pv-btn); height: var(--pv-btn); padding: 0 12px; margin: 0;
  border: 1.5px solid var(--pv-outline); border-radius: 9px;
  background: var(--pv-paper); color: var(--pv-ink);
  font: 600 14px/1 var(--pv-font-sans);
  white-space: nowrap; text-decoration: none;
  box-shadow: 2px 3px 0 var(--pv-shadow);
  cursor: pointer;
  -webkit-appearance: none; appearance: none;
  transition: transform 180ms var(--pv-ease), box-shadow 180ms var(--pv-ease), background 180ms;
}
/* The dialog mounts in <body>, which is often .k-root: beat the kit's
   `.k-root button { font: inherit; color: inherit }` and `.k-root a { color }`. */
.pv-root .pv-btn { color: var(--pv-ink); font: 600 14px/1 var(--pv-font-sans); }
.pv-btn svg { width: 18px; height: 18px; flex: none; }
.pv-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 4px 0 var(--pv-shadow); }
.pv-btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--pv-shadow); }
.pv-btn:focus-visible { outline: 2px solid var(--pv-primary); outline-offset: 2px; }
.pv-btn.is-icon { width: var(--pv-btn); padding: 0; }
.pv-btn.is-round { width: var(--pv-btn); padding: 0; border-radius: 50%; }
.pv-btn[hidden] { display: none; }
.pv-btn:disabled { opacity: .35; cursor: default; pointer-events: none; box-shadow: none; transform: none; }

.pv-side { position: absolute; top: 50%; margin-top: calc(var(--pv-btn) / -2); }
.pv-side.pv-prev { left: 16px; }
.pv-side.pv-next { right: 16px; }

.pv-card {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  padding: 10px 12px;
  background: var(--pv-paper); color: var(--pv-ink);
  border: 1.5px solid var(--pv-outline); border-radius: 12px;
  box-shadow: 2px 3px 0 var(--pv-shadow);
}
/* .pv-root prefix: beats host resets like app-kit's .k-root p { margin; line-height } */
.pv-root .pv-caption {
  margin: 0;
  font-family: var(--pv-font-display); font-weight: 700; font-size: 15px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pv-root .pv-sub { margin: 2px 0 0; color: var(--pv-muted); font-size: 13px; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-root .pv-caption[hidden], .pv-root .pv-sub[hidden] { display: none; }
.pv-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.pv-caption[hidden] + .pv-sub[hidden] + .pv-actions { margin-top: 0; }
.pv-original { margin-left: auto; }
.pv-inline { display: none; }

/* Phones and coarse pointers: prev and next move into the card's button
   row and stay visible. */
@media (max-width: 639px), (pointer: coarse) {
  .pv-side { display: none; }
  .pv-inline { display: inline-flex; }
  .pv-card { left: 12px; right: 12px; bottom: 12px; width: auto; transform: none; }
  .pv-original > span { display: none; }
  .pv-original { width: var(--pv-btn); padding: 0; }
}

/* Visually hidden live region */
.pv-live {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* bind(): images that open the viewer */
.pv-zoomable { cursor: zoom-in; }

/* Its own block, because the viewer mounts outside .k-root. The JS animator
   also drops to 0 ms and skips inertia. */
@media (prefers-reduced-motion: reduce) {
  .pv-root, .pv-root *, .pv-root *::before, .pv-root *::after { animation: none !important; transition: none !important; }
}
