/* ---------- Tokens ---------- */
:root {
  --bg: #07090f;
  --bg-glow: rgba(214, 140, 60, 0.20);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(232, 193, 112, 0.14);
  --line: rgba(232, 193, 112, 0.28);
  --gold: #e8c170;
  --gold-bright: #f6dca0;
  --gold-deep: #b98a3e;
  --text: #f3ead7;
  --text-dim: rgba(243, 234, 215, 0.62);

  --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;

  --masthead-h: clamp(64px, 10vh, 92px);
  --controls-h: 76px;
  --gutter: 16px;

  --duration-fast: 160ms;
  --duration-normal: 320ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-display);
  background:
    radial-gradient(120% 70% at 50% 108%, var(--bg-glow), transparent 62%),
    radial-gradient(60% 50% at 8% 0%, rgba(120, 30, 40, 0.20), transparent 70%),
    radial-gradient(60% 50% at 92% 0%, rgba(30, 60, 90, 0.22), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* film grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Masthead ---------- */
.masthead {
  position: relative;
  z-index: 2;
  flex: 0 0 var(--masthead-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 var(--gutter);
  text-align: center;
}

.masthead__name {
  margin: 0;
  font-weight: 600;
  font-size: clamp(0.8rem, 0.7rem + 0.55vw, 1.15rem);
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--text);
}

.masthead__name span[aria-hidden] { color: var(--gold); padding: 0 0.15em; }

.masthead__sub {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(1.05rem, 0.9rem + 0.8vw, 1.55rem);
  color: var(--gold);
}

.masthead__sub::before,
.masthead__sub::after {
  content: "";
  width: clamp(28px, 8vw, 90px);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-deep));
}
.masthead__sub::after { transform: scaleX(-1); }

/* ---------- Stage / book ---------- */
.stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 0 var(--gutter);
}

.book-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1500px;
  padding-bottom: 28px; /* room for hint */
}

.book {
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 600ms ease;
}
.book.is-ready { opacity: 1; }

/* floor shadow under the open book */
.book-wrap::after {
  content: "";
  position: absolute;
  left: 12%; right: 12%;
  bottom: 22px;
  height: 22px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.75), transparent);
  filter: blur(8px);
}

.page {
  background: #0b0d14;
  overflow: hidden;
}

.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
}

/* spine highlight */
.page.--left  { box-shadow: inset -14px 0 18px -14px rgba(0, 0, 0, 0.55); }
.page.--right { box-shadow: inset  14px 0 18px -14px rgba(0, 0, 0, 0.55); }

/* hint */
.hint {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--gold);
  background: rgba(7, 9, 15, 0.6);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  transition: opacity var(--duration-normal) ease, transform var(--duration-normal) var(--ease-out);
}
.hint svg { width: 16px; height: 16px; }
.hint.is-hidden { opacity: 0; transform: translateX(-50%) translateY(6px); pointer-events: none; }

/* side arrows (wide screens only) */
.side-nav {
  flex: 0 0 auto;
  align-self: center;
  display: none;
  place-items: center;
  width: 52px; height: 52px;
  margin: 0 8px 28px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--gold);
  transition: background var(--duration-fast), transform var(--duration-fast) var(--ease-out), opacity var(--duration-fast);
}
.side-nav svg { width: 22px; height: 22px; }
.side-nav:hover { background: var(--surface-hover); transform: scale(1.06); }
.side-nav:active { transform: scale(0.96); }
.side-nav[disabled] { opacity: 0.25; pointer-events: none; }

@media (min-width: 900px) {
  .side-nav { display: grid; }
}

/* ---------- Controls ---------- */
.controls {
  position: relative;
  z-index: 3;
  flex: 0 0 var(--controls-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 var(--gutter) env(safe-area-inset-bottom);
}

.counter {
  min-width: 11ch;
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--gold);
  transition: background var(--duration-fast), border-color var(--duration-fast),
              transform var(--duration-fast) var(--ease-out), color var(--duration-fast);
}
.btn:hover { background: var(--surface-hover); border-color: var(--gold); color: var(--gold-bright); }
.btn:active { transform: scale(0.95); }
.btn[disabled] { opacity: 0.28; pointer-events: none; }
.btn svg { width: 20px; height: 20px; }

.btn--round { width: 46px; height: 46px; border-radius: 50%; }

.btn--pill {
  height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.btn--pill svg { width: 16px; height: 16px; transition: transform var(--duration-fast); }
.btn--pill[aria-expanded="true"] svg { transform: rotate(180deg); }
.btn--pill[aria-pressed="true"] { background: var(--gold); color: #1a1206; border-color: var(--gold); }

/* contents popover */
.contents { position: relative; margin-left: 10px; }

.contents__menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 10;
  width: min(86vw, 320px);
  max-height: min(60vh, 460px);
  overflow-y: auto;
  margin: 0;
  padding: 8px;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(12, 14, 22, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.contents__menu[hidden] { display: none; }

.contents__item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 1.1rem;
  color: var(--text);
  transition: background var(--duration-fast);
}
.contents__item:hover, .contents__item:focus-visible { background: var(--surface-hover); }
.contents__item[aria-current="true"] { color: var(--gold-bright); }
.contents__num {
  flex: 0 0 2ch;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: var(--gold-deep);
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr;
  background: rgba(4, 5, 9, 0.95);
  backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity var(--duration-normal) ease;
}
.lightbox[hidden] { display: none; }
.lightbox.is-open { opacity: 1; }

.lightbox__bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 10px;
}

.lightbox__title {
  margin: 0;
  font-size: clamp(1rem, 0.9rem + 0.5vw, 1.3rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
}
.lightbox__title small { margin-left: 10px; font-weight: 500; font-size: 0.9em; color: var(--text-dim); }

.lightbox__tools { display: flex; align-items: center; gap: 10px; }

.lightbox__scroller {
  grid-row: 2;
  grid-column: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 0 var(--gutter) max(var(--gutter), env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.lightbox__img {
  display: block;
  margin: auto;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--line);
  cursor: zoom-in;
  user-select: none;
  transition: opacity 180ms ease;
}
.lightbox__img.is-swapping { opacity: 0; }

/* "Full size" = native resolution, scroll to explore */
.lightbox.is-zoomed .lightbox__img {
  max-width: none;
  max-height: none;
  width: min(762px, 200vw);
  height: auto;
  margin: 0 auto;
  cursor: zoom-out;
}
.lightbox.is-zoomed .lightbox__scroller { align-items: flex-start; }

.lightbox__nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  transform: translateY(-50%);
  background: rgba(7, 9, 15, 0.7);
  backdrop-filter: blur(6px);
}
.lightbox__nav:active { transform: translateY(-50%) scale(0.95); }
.lightbox__nav--prev { left: var(--gutter); }
.lightbox__nav--next { right: var(--gutter); }

body.is-locked { overflow: hidden; }

/* ---------- Small screens ---------- */
@media (max-width: 899px) {
  :root { --controls-h: 70px; --gutter: 12px; }
  .stage { padding: 0 4px; }
  .hint { font-size: 0.85rem; }
  .lightbox__nav { width: 40px; height: 40px; opacity: 0.85; }
  .lightbox__nav--prev { left: 6px; }
  .lightbox__nav--next { right: 6px; }
}

@media (max-width: 520px) {
  .masthead__name { letter-spacing: 0.16em; font-size: 0.78rem; white-space: nowrap; }
  .counter { min-width: 0; font-size: 1.02rem; letter-spacing: 0.03em; white-space: nowrap; }
  .controls { gap: 8px; }
  .btn--round { width: 42px; height: 42px; }
  .btn--pill { padding: 0 14px; font-size: 0.95rem; letter-spacing: 0.06em; }
  .contents { margin-left: 2px; }
}

/* ---------- Motion / no-JS ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

.noscript { position: relative; z-index: 5; padding: 24px; color: var(--text); overflow: auto; }
.noscript a { color: var(--gold); }
