/* Reader engine layout. Generic: series.css supplies colours, type flavour and plate animation. */

@property --mood { syntax: '<color>'; inherits: true; initial-value: #d9954a; }

:root {
  --dockW: 0px; --bandH: 300px; --stageW: 100vw; --dock: 0; --vh: 100vh;
  --measure: 34rem;
  --noteW: 12.5rem; --noteGap: 2.4rem;
  --gut: 20px;
  --mood: #d9954a; --mood-a: .14; --mood-t: 4s;
  --display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --text: 'Literata', 'Iowan Old Style', Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  overflow-x: hidden;
  transition: background-color 1.2s ease, color 1.2s ease;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ the stage */
.stage {
  position: fixed; left: 0; top: 0;
  width: 100vw; height: 100vh;
  overflow: hidden;
  z-index: 1;
  background: #120f0c;
  contain: layout paint size;
}
.stage-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.stage-world canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-world .fx { z-index: 3; pointer-events: none; }
.stage-shade { position: absolute; inset: 0; pointer-events: none; z-index: 4; }

/* ------------------------------------------------------------------ hero */
.hero {
  position: relative; z-index: 3;
  height: var(--vh, 100vh);
  pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  text-align: center;
  padding: max(7vh, 40px) 20px 0;
  opacity: calc(1 - var(--dock) * 1.8);
}
.hero-inner { max-width: 60rem; }
.hero-scroll {
  position: absolute; bottom: 150px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: .78rem; letter-spacing: .14em; text-transform: uppercase;
}

/* ------------------------------------------------------------------ player */
.player {
  position: fixed; z-index: 6; left: 0; bottom: 0;
  width: var(--stageW);
  padding: 34px clamp(16px, 2.2vw, 30px) calc(16px + env(safe-area-inset-bottom));
}
.player-row { display: flex; align-items: center; gap: 12px; }
.pbtn {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid transparent; background: transparent; cursor: pointer; padding: 0;
}
.pbtn svg { width: 28px; height: 28px; }
.pbtn.play { width: 54px; height: 54px; }
.pbtn.play svg { width: 30px; height: 30px; }
.pbtn .i-pause, body.playing .pbtn .i-play { display: none; }
body.playing .pbtn .i-pause { display: block; }
.theme-day .pbtn .i-moon, .theme-night .pbtn .i-sun { display: none; }
.progress { flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; }
.progress-toast { grid-row: 1 / span 2; width: 40px; height: 40px; }
.progress-toast svg { width: 100%; height: 100%; display: block; overflow: visible; }
.progress-track { position: relative; height: 22px; cursor: pointer; outline-offset: 4px; }
.track-line, .track-fill { position: absolute; left: 0; right: 0; top: 10px; height: 2px; border-radius: 2px; }
.track-fill { transform-origin: 0 50%; transform: scaleX(0); transition: transform .6s linear; }
.track-ticks span { position: absolute; top: 6px; width: 1px; height: 10px; }
.progress-time { margin: 0; font-size: .78rem; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.progress-time .sep { margin: 0 .45em; }
.player-caption {
  margin: 0 0 8px 2px; min-height: 1.3em;
  font-style: italic; font-size: .9rem; line-height: 1.3;
  opacity: 0; transform: translateY(4px);
  transition: opacity 1.2s ease, transform 1.4s ease;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-caption.show { opacity: 1; transform: none; }

.follow-chip {
  position: fixed; z-index: 7; right: 20px; bottom: 96px;
  border-radius: 999px; padding: 10px 16px; cursor: pointer;
  font-size: .85rem; letter-spacing: .02em;
  opacity: 0; transform: translateY(8px); transition: opacity .6s, transform .6s;
}
.follow-chip.show { opacity: 1; transform: none; }

/* ------------------------------------------------------------------ the page */
.reader {
  position: relative; z-index: 2;
  background: var(--paper);
  transition: background-color 1.2s ease;
  padding: 10vh var(--gut) 40vh;
}
.reader > .loading { text-align: center; opacity: .6; }
.chapter, .colophon { max-width: var(--measure); margin: 0 auto; position: relative; }

.para {
  font-size: 1.14rem; line-height: 1.72;
  margin: 0 -.55em 1.02em; padding: .05em .55em;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  hanging-punctuation: first;
  text-wrap: pretty;
  transition: background-color 1.4s ease;
}
.para em { font-style: italic; }

.fx-rise .para, .fx-rise .pull, .fx-rise .plate, .fx-rise .note, .fx-rise .chapter-head, .fx-rise .scene-break, .fx-rise .dateline, .fx-rise .chapter-end, .fx-rise .colophon {
  opacity: 0; transform: translateY(14px);
  transition: opacity 1.3s ease, transform 1.6s cubic-bezier(.2,.6,.2,1), background-color 1.4s ease;
}
.fx-rise .seen { opacity: 1; transform: none; }

.listen-here {
  position: absolute; z-index: 3; right: .4em; top: -1.9em;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 6px 12px 6px 9px; cursor: pointer;
  font-size: .8rem; font-style: normal; letter-spacing: .01em; white-space: nowrap;
  animation: pop-in .5s ease both;
}
.listen-here svg { width: 13px; height: 13px; }
.listen-here span { opacity: .75; font-variant-numeric: tabular-nums; }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.gloss {
  display: inline; padding: 0; margin: 0; border: 0; background: none; cursor: help;
  font: inherit; color: inherit; text-decoration: underline dotted; text-underline-offset: .22em; text-decoration-thickness: 1px;
}
.gloss-pop {
  position: fixed; z-index: 9;
  padding: 12px 14px; border-radius: 10px;
  font-size: .86rem; line-height: 1.45;
}
.gloss-pop strong { font-weight: 600; margin-right: .25em; }

/* margin notes: inline cards on narrow screens, true side notes on wide ones */
.note { display: flex; gap: 12px; align-items: flex-start; margin: .2em 0 1.1em; font-size: .86rem; line-height: 1.45; }
.note-portrait { flex: none; width: 46px; height: 46px; }
.note-portrait svg { width: 100%; height: 100%; display: block; }
.note-name { display: block; font-variant-caps: all-small-caps; letter-spacing: .08em; font-size: 1.08em; margin-bottom: 1px; }
.margin-notes .note {
  float: right; clear: right;
  width: var(--noteW);
  margin: .35em calc(-1 * (var(--noteW) + var(--noteGap))) 1em 0;
  flex-direction: column; gap: 6px;
}
.margin-notes .note-portrait { width: 54px; height: 54px; }

/* pull quotes break out of the column */
.pull { margin: 2.1em -.4em 2.3em; padding: 0; position: relative; }
.pull p { margin: 0; }
.margin-notes .pull { margin-right: calc(-1 * (var(--noteW) + var(--noteGap) * .6)); margin-left: -2.2rem; }

.plate { margin: 2.4em 0 2.6em; text-align: center; }
.plate svg { display: block; margin: 0 auto; width: 100%; max-width: 30rem; height: auto; overflow: visible; }
.plate figcaption { margin: .9em auto 0; max-width: 26rem; font-style: italic; font-size: .9rem; line-height: 1.45; }
.plate .fig { font-style: normal; font-variant-caps: all-small-caps; letter-spacing: .1em; margin-right: .3em; }
.margin-notes .plate.wide svg { max-width: none; width: calc(100% + var(--noteW) * .5); margin-left: calc(var(--noteW) * -.25); }

/* ------------------------------------------------------------------ wide layout: the stage docks left */
@media (min-width: 960px), (orientation: landscape) and (max-height: 500px) and (min-width: 560px) {
  :root { --gut: clamp(28px, 4vw, 64px); }
  .reader { margin-left: var(--dockW); padding-top: 14vh; }
  .margin-notes .reader { padding-right: calc(var(--noteW) + var(--noteGap) + 24px); }
  .chapter, .colophon { margin-left: auto; margin-right: auto; }
  .para { font-size: 1.19rem; }
  .follow-chip { right: 32px; bottom: 32px; }
  .hero { align-items: center; justify-content: center; padding-top: 0; padding-bottom: 12vh; }
  .hero-scroll { bottom: 150px; }
}

/* ------------------------------------------------------------------ narrow layout: the stage becomes a band */
@media (max-width: 959.98px) and (orientation: portrait), (max-width: 959.98px) and (min-height: 500.02px), (max-width: 559.98px) {
  .stage { z-index: 4; }
  .player {
    width: 100vw; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  }
  .player-caption {
    position: fixed; left: 14px; right: 14px;
    top: calc(var(--bandH) * var(--dock) + var(--vh) * (1 - var(--dock)) - 30px);
    margin: 0; font-size: .82rem;
    pointer-events: none;
  }
  .in-hero .player-caption { opacity: 0 !important; }
  .progress-time { font-size: .74rem; }
  .reader { padding-top: 7vh; padding-bottom: 50vh; }
  .para { font-size: 1.08rem; line-height: 1.7; }
  .follow-chip { bottom: 84px; right: 12px; }
  .hero-scroll { bottom: 110px; }
}
/* short landscape phones: side by side like desktop, but everything a size smaller so it fits the height */
@media (max-width: 959.98px) and (orientation: landscape) and (max-height: 500px) and (min-width: 560px) {
  :root { --gut: clamp(20px, 4vw, 40px); }
  .reader { padding-top: 12vh; padding-bottom: 45vh; }
  .para { font-size: 1.08rem; line-height: 1.66; }
  .player { padding: 22px 10px calc(8px + env(safe-area-inset-bottom)); }
  .player-row { gap: 6px; }
  .pbtn { width: 38px; height: 38px; }
  .pbtn svg { width: 24px; height: 24px; }
  .pbtn.play { width: 46px; height: 46px; }
  .pbtn.play svg { width: 26px; height: 26px; }
  .progress { column-gap: 7px; }
  .progress-toast { width: 30px; height: 30px; }
  .progress-time { font-size: .72rem; }
  .player-caption { font-size: .8rem; margin-bottom: 4px; }
  .follow-chip { right: 16px; bottom: 16px; }
  .hero { padding-bottom: 20vh; }
  .hero-scroll { bottom: 96px; }
}
@media (max-width: 420px) {
  .pbtn { width: 40px; height: 40px; }
  .pbtn.play { width: 48px; height: 48px; }
  .progress { column-gap: 8px; }
  .progress-toast { width: 34px; height: 34px; }
}

/* after the story: the page goes to sleep too (any touch brings it back) */
.lights-out-veil {
  position: fixed; inset: 0; z-index: 20; pointer-events: none;
  background: #050403; opacity: 0; transition: opacity 45s ease-in-out;
}
body.lights-out .lights-out-veil { opacity: .72; }
body.lights-waking .lights-out-veil { transition: opacity 1.2s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
  .para, .player-caption { transition: none; }
}

/* Host promotion (STAGE_CONFIG.promo): calm, in the series' own colours, never over the story. */
.hero-promo { max-width: 30rem; margin: 1rem auto 0; font: 500 .95rem/1.5 var(--text); color: var(--ink); opacity: .92; text-shadow: 0 1px 14px rgba(10,8,6,.75); }
.hero-promo a { color: var(--accent-soft, #e7b27a); text-decoration: underline; text-underline-offset: 3px; pointer-events: auto; }
.promo-end { max-width: var(--measure); margin: 3.5rem auto 0; padding: 1.4rem 1.5rem; border: 1px solid var(--rule, rgba(255,255,255,.15)); border-radius: 14px; background: var(--note-bg, rgba(0,0,0,.2)); text-align: center; font-family: var(--text); color: var(--ink); }
.promo-end h2 { font: 600 1.35rem/1.25 var(--display); margin: 0 0 .5rem; }
.promo-end p { margin: .4rem 0; color: var(--ink-soft, inherit); line-height: 1.55; }
.promo-end .promo-actions { display: flex; flex-wrap: wrap; gap: .7rem; justify-content: center; margin-top: 1rem; }
.promo-end a.promo-btn { display: inline-block; padding: .65rem 1.2rem; border-radius: 999px; font-weight: 600; text-decoration: none; background: var(--accent, #e1a05a); color: var(--paper, #17130f); }
.promo-end a.promo-btn.quiet { background: transparent; color: var(--accent, #e1a05a); border: 1px solid var(--accent, #e1a05a); }
