/* Kael Tuor — digital mini-zine viewer.
   One booklet screen at a time on a quiet "exhibit" stage; the original
   printed panels are the content. No framework, no build step. */

:root {
  --bg: #15130f;                    /* warm near-black exhibit room */
  --bg-light: #221f1a;
  --ink: #e8e4dc;                   /* warm ivory */
  --ink-dim: #97917f;
  --panel-ratio: 0.7071;            /* panel width / height (900:1273) */
  --topbar-h: 3rem;
  --pager-h: 4.25rem;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 35%, var(--bg-light), var(--bg) 75%);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;                  /* the viewer pages, it doesn't scroll */
}

img { display: block; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  font-size: 0.85rem;
  z-index: 5;
}

.wordmark { margin: 0; font-weight: 700; letter-spacing: 0.02em; }
.wordmark span { font-weight: 400; color: var(--ink-dim); }

.pdf-link { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid transparent; }
.pdf-link:hover, .pdf-link:focus-visible { color: var(--ink); border-bottom-color: var(--ink-dim); }

/* ---------- Stage & screens ---------- */

.viewer { height: 100vh; height: 100dvh; }

.stage {
  height: 100%;
  padding: var(--topbar-h) 4.5rem var(--pager-h);
  display: grid;
  place-items: center;
  /* keep vertical panning native but let horizontal swipes reach JS */
  touch-action: pan-y;
}

.screen[hidden] { display: none; }

.screen {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: page-in 0.3s ease both;
}

@keyframes page-in {
  from { opacity: 0; transform: translateX(14px); }
  to   { opacity: 1; transform: none; }
}

.screen.from-next { animation-name: page-in-rev; }

@keyframes page-in-rev {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: none; }
}

/* Single-panel screens (cover, back cover) */
.single .panel-img {
  width: min(70vw, calc((100dvh - 8.5rem) * var(--panel-ratio)));
  height: auto;
  box-shadow: var(--shadow);
  border-radius: 3px;
}

/* Project spreads: original text panel | original image panel */
.spread {
  display: flex;
  align-items: center;
  gap: 8px;                          /* the booklet's spine gutter */
}

.spread .panel-img,
.spread .panel-btn img {
  width: min(40vw, calc((100dvh - 8.5rem) * var(--panel-ratio)));
  height: auto;
  border-radius: 3px;
}

.spread .panel-img { box-shadow: var(--shadow); }

/* Image panel = button opening the video modal */
.panel-btn {
  position: relative;
  display: block;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 3px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.panel-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }

/* "Watch video" call-to-action: always present (touch), intensified on hover */
.panel-btn .cta {
  position: absolute;
  left: 50%; bottom: 6%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: rgba(8, 8, 10, 0.72);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  transition: background 0.2s ease, transform 0.2s ease;
}

.panel-btn .cta::before {
  content: "";
  width: 0; height: 0;
  border-left: 9px solid currentColor;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

@media (hover: hover) {
  .panel-btn:hover { transform: translateY(-3px); box-shadow: 0 16px 50px rgba(0,0,0,0.65), 0 3px 10px rgba(0,0,0,0.45); }
  .panel-btn:hover .cta,
  .panel-btn:focus-visible .cta { background: rgba(20, 20, 26, 0.92); transform: translateX(-50%) scale(1.06); }
}

/* Single-panel screens: wrapper shrink-wraps the image so hotspot
   percentages map exactly onto the printed artwork */
.panel-wrap { position: relative; display: inline-block; line-height: 0; }

/* Transparent clickable regions over the back cover's QR / URL / icons */
.hotspot {
  position: absolute;
  display: block;
  cursor: pointer;
  border-radius: 6px;
}

.hotspot:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.75);
  outline-offset: 2px;
}

@media (hover: hover) {
  .hotspot:hover {
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
  }
}

/* Back cover: live links under the printed panel (its QR/socials are pixels) */
.back-screen { flex-direction: column; gap: 1.1rem; }

.back-links {
  display: flex;
  gap: 2rem;
  font-size: 0.9rem;
}

.back-links a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid transparent; }
.back-links a:hover, .back-links a:focus-visible { color: var(--ink); border-bottom-color: var(--ink-dim); }

/* ---------- Prev / Next arrows ---------- */

.nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 3rem; height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  z-index: 6;                        /* above the pager strip on mobile */
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-arrow svg { width: 1.7rem; height: 1.7rem; }
.nav-prev { left: 0.6rem; }
.nav-next { right: 0.6rem; }

.nav-arrow:hover:not(:disabled),
.nav-arrow:focus-visible { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.nav-arrow:disabled { opacity: 0.25; cursor: default; }

/* ---------- Pager ---------- */

.pager {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--pager-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  z-index: 5;
  /* the full-width strip must not swallow taps meant for the arrows
     beneath it (mobile layout) — only the dots are interactive */
  pointer-events: none;
}

.pager-dots .dot { pointer-events: auto; }

.pager-dots {
  display: flex;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pager-dots .dot {
  width: 0.62rem; height: 0.62rem;
  padding: 0;
  border: 1px solid var(--ink-dim);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.pager-dots .dot:hover, .pager-dots .dot:focus-visible { transform: scale(1.3); }
.pager-dots .dot[aria-current="page"] { background: var(--ink); border-color: var(--ink); }

.pager-count { margin: 0; font-size: 0.78rem; color: var(--ink-dim); letter-spacing: 0.06em; }

/* ---------- Video modal ---------- */

.modal { position: fixed; inset: 0; z-index: 20; }
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 7, 0.82);
  backdrop-filter: blur(3px);
}

.modal-box {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  /* --video-ar is set per project by main.js (width / height) */
  aspect-ratio: var(--video-ar, 16 / 9);
  width: min(90vw, calc(85dvh * var(--video-ar, 1.7777)));
  background: #000;
  border-radius: 6px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.8);
  animation: modal-in 0.22s ease both;
}

@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, -48%) scale(0.97); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.modal-player, .modal-player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 6px;
}

.modal-close {
  position: absolute;
  top: -2.6rem; right: -0.4rem;
  width: 2.2rem; height: 2.2rem;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  z-index: 1;
  transition: background 0.15s ease;
}

.modal-close:hover, .modal-close:focus-visible { background: rgba(255, 255, 255, 0.28); }

/* ---------- Noscript ---------- */

.noscript-msg {
  position: fixed;
  top: 40%; left: 50%;
  transform: translateX(-50%);
  max-width: 28rem;
  padding: 1.25rem;
  background: var(--bg-light);
  border: 1px solid var(--ink-dim);
  border-radius: 6px;
  text-align: center;
}

.noscript-msg a { color: var(--ink); }

/* ---------- Mobile: stacked spreads, bottom controls ---------- */

@media (max-width: 600px) {
  .stage {
    padding: var(--topbar-h) 1rem var(--pager-h);
    overflow-y: auto;               /* a stacked spread may exceed the viewport */
    place-items: start center;
  }

  .screen { min-height: 100%; }

  .spread {
    flex-direction: column;
    gap: 14px;
    padding: 0.75rem 0 1rem;
  }

  /* image panel first on phones: the visual leads, printed text follows */
  .spread .panel-btn { order: -1; }

  .spread .panel-img,
  .spread .panel-btn img,
  .single .panel-img {
    width: min(88vw, calc((100dvh - 9rem) * var(--panel-ratio)));
  }

  .nav-arrow {
    top: auto;
    bottom: 0.55rem;
    transform: none;
    height: 3rem;
    background: rgba(255, 255, 255, 0.05);
  }

  .pager { height: 4rem; }
  .topbar { font-size: 0.78rem; padding: 0 0.85rem; }

  .modal-close { top: 0.5rem; right: 0.5rem; background: rgba(0, 0, 0, 0.55); }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .screen, .modal-box { animation: none; }
  .panel-btn, .panel-btn .cta, .pager-dots .dot { transition: none; }
}
