/* Minimal Sticky Overlay Reader — shared styles
 * Based on production/canon_bible_v2.md + reader_minimal_overlay_implementation_guide.md
 * The art is the main event. Text is a subtitle layer that slides over a sticky panel.
 */

:root {
  --overlay-bg: #050606;
  --overlay-ink: #f5efe6;
  --overlay-muted: #c8beb4;
  --overlay-line: rgba(245, 239, 230, 0.1);
  --overlay-glass: rgba(5, 7, 8, 0.34);
  --overlay-gold: #d69b59;
  --overlay-cyan: #7ea3b8;
  --overlay-red: rgba(220, 64, 64, 0.86);
}

body.overlay-reader {
  background: var(--overlay-bg);
  color: var(--overlay-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  min-height: 100%;
  overscroll-behavior-y: contain;
}

body.overlay-reader * {
  box-sizing: border-box;
}

/* Scroll progress thread */
.top-line {
  background: rgba(245, 239, 230, 0.045);
  height: 1px;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 20;
}

.top-line span {
  background: rgba(245, 239, 230, 0.52);
  display: block;
  height: 100%;
  transform: scaleX(var(--read-progress, 0));
  transform-origin: left center;
}

/* Reader header is intentionally minimal */
.overlay-top {
  align-items: center;
  background: rgba(5, 6, 6, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: rgba(245, 239, 230, 0.62);
  display: flex;
  font-size: 0.74rem;
  gap: 16px;
  justify-content: space-between;
  left: 0;
  letter-spacing: 0.04em;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  position: fixed;
  right: 0;
  text-transform: uppercase;
  top: 1px;
  z-index: 18;
}

.overlay-top a {
  color: rgba(245, 239, 230, 0.7);
  text-decoration: none;
}

.overlay-top a:hover {
  color: var(--overlay-gold);
}

main.overlay-stage {
  display: block;
  margin: 0;
  padding: 0;
}

/* COVER scene — full-bleed title card, no text-flow */
.scene.cover {
  --beats: 1;
  align-items: flex-end;
  background: #050606;
  display: grid;
  min-height: 100svh;
  padding: 0;
  position: relative;
}

.scene.cover .cover-art {
  height: 100svh;
  left: 0;
  object-fit: cover;
  position: absolute;
  top: 0;
  width: 100%;
  z-index: 0;
}

.scene.cover::after {
  background: linear-gradient(180deg, rgba(5, 6, 6, 0.2), transparent 30%, transparent 50%, rgba(5, 6, 6, 0.78));
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 1;
}

.scene.cover .cover-meta {
  padding: 36px max(20px, env(safe-area-inset-left)) calc(58px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-right));
  position: relative;
  z-index: 2;
}

.scene.cover .cover-meta .kicker {
  color: rgba(245, 239, 230, 0.62);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.scene.cover .cover-meta h1 {
  color: rgba(245, 239, 230, 0.96);
  font-family: "Cormorant Garamond", "Noto Serif KR", Georgia, serif;
  font-feature-settings: "kern", "liga", "dlig";
  font-size: clamp(2.4rem, 9vw, 4rem);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.02;
  margin: 0 0 14px;
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.6);
}

.scene.cover .cover-meta .lede {
  color: rgba(245, 239, 230, 0.82);
  font-family: "Lora", Georgia, "Times New Roman", serif;
  font-feature-settings: "kern", "liga";
  font-size: clamp(1.1rem, 3.8vw, 1.32rem);
  font-style: italic;
  font-weight: 500;
  letter-spacing: -0.003em;
  line-height: 1.42;
  margin: 0;
  max-width: 540px;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.66);
}

/* SCENE — sticky panel with overlay track
 * Per-beat scroll: 25svh (was 50svh; originally 72svh). Half the previous
 * runway so the sticky panel releases while text is still anchored in
 * the upper-middle of viewport — not after early lines have scrolled
 * off the top. Pairs with REVEAL_FRACTION = 1.0 in reader_overlay.js so
 * reveal-end and sticky-release coincide.
 *
 * Math (3-beat scene example):
 *   total height = 100svh + 3*25svh = 175svh
 *   sticky-release scroll = 75svh past scene.top
 *   text first line page-pos = scene.top + 100svh
 *   text first line viewport-pos at release = +25svh from top (in view)
 */
.scene {
  --beats: 3;
  min-height: calc(100svh + (var(--beats) * 25svh));
  position: relative;
}

.scene-frame {
  background: #050606;
  height: 100svh;
  overflow: hidden;
  position: sticky;
  top: 0;
}

.scene-frame img.panel {
  height: 100%;
  object-fit: cover;
  object-position: var(--focus, center center);
  position: absolute;
  transform: scale(calc(1.005 + var(--scene-progress, 0) * 0.012));
  transform-origin: var(--origin, 50% 50%);
  width: 100%;
}

.scene-frame::after {
  background: linear-gradient(180deg, rgba(5, 6, 6, 0.1), transparent 28%, transparent 70%, rgba(5, 6, 6, 0.28));
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
}

/* Scene title — small, recedes on read */
.scene-title {
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: max(14px, env(safe-area-inset-left));
  max-width: min(360px, calc(100vw - 28px));
  opacity: 0.48;
  pointer-events: none;
  position: absolute;
  transition: opacity 220ms ease, transform 260ms ease;
  z-index: 2;
}

.scene.is-reading .scene-title {
  opacity: 0;
  transform: translateY(14px);
}

.scene-title-inner {
  align-items: center;
  display: flex;
  gap: 6px;
  min-width: 0;
}

.scene-title span {
  color: rgba(245, 239, 230, 0.58);
  display: block;
  flex: 0 0 auto;
  font-size: 0.62rem;
  font-weight: 760;
  letter-spacing: 0;
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.78);
  text-transform: uppercase;
}

.scene-title h2 {
  color: rgba(245, 239, 230, 0.86);
  font-size: 0.78rem;
  font-weight: 690;
  line-height: 1.1;
  margin: 0;
  overflow: hidden;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.78);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Text flow — the sliding overlay track */
.text-flow {
  display: flex;
  flex-direction: column;
  gap: 7px;
  inset: 0;
  padding: calc(100svh + 8px) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  pointer-events: none;
  position: absolute;
  z-index: 3;
}

.line {
  position: relative;
}

/* Narration — editorial serif italic (Lora) */
.line.narration {
  align-self: center;
  color: rgba(245, 239, 230, 0.82);
  font-family: "Lora", Georgia, "Times New Roman", serif;
  font-feature-settings: "kern", "liga";
  font-size: clamp(1.2rem, 4.2vw, 1.46rem);
  font-style: italic;
  font-weight: 500;
  letter-spacing: -0.003em;
  line-height: 1.38;
  max-width: min(520px, calc(100vw - 58px));
  padding: 2px 8px;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.78);
}

/* Strong narration — cinematic payoff register (Cormorant Garamond) */
.line.narration.strong {
  color: rgba(255, 247, 237, 0.95);
  font-family: "Cormorant Garamond", "Noto Serif KR", Georgia, serif;
  font-feature-settings: "kern", "liga", "dlig";
  font-size: clamp(1.5rem, 5.8vw, 2rem);
  font-style: normal;
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.16;
  margin: 4px 0 2px;
}

.line.narration.fragment {
  color: rgba(255, 247, 237, 0.66);
  font-family: "Lora", Georgia, "Times New Roman", serif;
  font-size: clamp(0.88rem, 3.1vw, 1.08rem);
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0.005em;
  max-width: min(420px, calc(100vw - 64px));
}

/* Dialogue — chip with soft glass */
.line.dialogue {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(7, 16, 18, 0.32), rgba(6, 10, 12, 0.42));
  border: 1px solid rgba(245, 239, 230, 0.08);
  border-radius: 11px;
  color: var(--overlay-ink);
  display: grid;
  gap: 5px;
  max-width: min(420px, calc(100vw - 56px));
  padding: 9px 13px 11px;
  backdrop-filter: blur(12px) saturate(1.08);
  -webkit-backdrop-filter: blur(12px) saturate(1.08);
}

.line.dialogue.right {
  align-self: flex-end;
}

.line.dialogue .speaker {
  align-items: center;
  color: rgba(205, 227, 235, 0.78);
  display: inline-flex;
  font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
  font-size: 0.66rem;
  font-weight: 600;
  gap: 8px;
  justify-self: start;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.line.dialogue .speaker img {
  border: 1px solid rgba(245, 239, 230, 0.18);
  border-radius: 50%;
  flex: 0 0 auto;
  height: 24px;
  object-fit: cover;
  object-position: center 22%;
  width: 24px;
}

.line.dialogue p {
  font-family: "Lora", Georgia, "Times New Roman", serif;
  font-feature-settings: "kern", "liga";
  font-size: clamp(1.16rem, 4.2vw, 1.34rem);
  font-weight: 500;
  letter-spacing: -0.003em;
  line-height: 1.38;
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.62);
}

/* SFX — hangul mimetic */
.line.sfx {
  align-self: center;
  color: rgba(214, 155, 89, 0.78);
  font-family: "Noto Serif KR", Georgia, serif;
  font-size: clamp(2.4rem, 9vw, 5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0 24px rgba(214, 155, 89, 0.32);
}

.line.sfx.heartbeat {
  color: var(--overlay-red);
  text-shadow: 0 0 32px rgba(220, 64, 64, 0.36);
}

.line.sfx.muted {
  color: rgba(170, 180, 188, 0.6);
  font-size: clamp(1.6rem, 6vw, 3.2rem);
  text-shadow: none;
}

/* Stamp + message — monospace evidence (JetBrains Mono) */
.line.stamp {
  align-self: center;
  color: rgba(170, 180, 188, 0.72);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(0.76rem, 2.4vw, 0.88rem);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.62);
  text-transform: lowercase;
}

.line.message {
  align-self: center;
  background: rgba(8, 12, 18, 0.62);
  border: 1px solid rgba(126, 163, 184, 0.4);
  border-radius: 12px;
  color: #cce8f7;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(1.14rem, 4.4vw, 1.58rem);
  font-weight: 500;
  letter-spacing: -0.005em;
  padding: 16px 20px;
  text-align: center;
  text-shadow: 0 0 12px rgba(126, 163, 184, 0.45);
}

/* Pause classes */
.line.pause-sm {
  margin-top: clamp(10px, 3svh, 24px);
}

.line.pause-md {
  margin-top: clamp(18px, 6svh, 52px);
}

.line.pause-lg {
  margin-top: clamp(28px, 12svh, 96px);
}

.line.pause-xl {
  margin-top: clamp(40px, 22svh, 180px);
}

/* TRANSITION scene — text-only bridge between two image scenes */
.scene.transition {
  --beats: 1;
  align-items: center;
  background: linear-gradient(180deg, #050606 0%, #0a0b0d 50%, #050606 100%);
  display: grid;
  min-height: 70svh;
  padding: 60px max(20px, env(safe-area-inset-left)) 60px max(20px, env(safe-area-inset-right));
  position: relative;
  text-align: center;
}

.scene.transition .text-flow {
  align-items: center;
  inset: auto;
  padding: 0;
  pointer-events: none;
  position: relative;
}

.scene.transition .line.narration {
  color: rgba(245, 239, 230, 0.62);
  font-size: clamp(1rem, 3.8vw, 1.24rem);
  text-shadow: none;
}

/* End / cliffhanger / final card */
.scene.end {
  align-items: center;
  display: grid;
  min-height: 100svh;
  padding: 36px;
  text-align: center;
}

.scene.end h2 {
  color: rgba(245, 239, 230, 0.78);
  font-size: clamp(1.2rem, 4.8vw, 2.2rem);
  font-weight: 620;
  line-height: 1.18;
  margin: 0 auto;
  max-width: 760px;
}

/* Reader nav at bottom */
.overlay-nav {
  background: rgba(5, 6, 6, 0.85);
  border-top: 1px solid rgba(245, 239, 230, 0.08);
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 18px max(20px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-right));
}

.overlay-nav a {
  color: rgba(245, 239, 230, 0.72);
  font-size: 0.84rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
}

.overlay-nav a:hover {
  color: var(--overlay-gold);
}

/* Desktop */
@media (min-width: 760px) {
  .scene-frame img.panel {
    object-fit: contain;
  }
  .text-flow {
    margin: 0 auto;
    max-width: min(820px, calc(100vw - 56px));
    padding-left: 0;
    padding-right: 0;
  }
  .line.dialogue {
    width: min(360px, 38vw);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .scene-frame img.panel {
    transform: none;
  }
}
