/* ---------------------------------------------------------------
   Digital Storybook  ·  styles
   No frameworks. Pure CSS.
   Pages are stacked full-screen and cross-fade as you scroll.
------------------------------------------------------------------ */

:root {
  --ink:        #2b2320;
  --paper:      #f4ecdd;
  --paper-2:    #ece0c8;
  --text-max:   min(90vw, 46ch);   /* roomy measure; avoids cramped wrapping */
  --fade-ease:  cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "Playfair Display", Cambria, serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* The scroll track: its height is set by JS to (pages * 100vh),
   giving us room to scroll while pages stay fixed and fade. */
#story {
  position: relative;
  width: 100%;
}

/* Every page is pinned to the viewport and full-screen. */
.page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 3vh, 2.5rem);
  padding: clamp(1.5rem, 5vw, 4rem);
  overflow: hidden;   /* never let content spill past the screen */
  opacity: 0;
  will-change: opacity, transform;
  transform-origin: center center;
  transition: opacity 120ms linear;
  pointer-events: none;   /* page bg is click-through (scroll/pager work) */
}

/* The active page rises above the pager buttons; its text catches clicks
   so links are clickable, while the page background stays click-through. */
.page.is-active { z-index: 20; }
.page.is-active .page-text { pointer-events: auto; }

/* Alternate the paper tint very subtly, page to page. */
.page:nth-child(even) { background: var(--paper-2); }
.page:nth-child(odd)  { background: var(--paper); }

/* ---- Imagery ---- */
.page-image {
  max-width: min(80vw, 900px);
  max-height: 70vh;
  width: auto;
  height: auto;
  min-height: 0;        /* allow the image to shrink inside the flex column */
  flex-shrink: 1;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 18px 50px rgba(43, 35, 32, 0.28);
}

/* When a page has only an image, let it breathe larger. */
.page--image-only .page-image {
  max-height: 82vh;
  max-width: min(90vw, 1100px);
}

/* On combined image + text pages the two must share one screen,
   so cap the image well under full height to leave room for the words. */
.page--image-text .page-image {
  max-height: 52vh;
}

/* ---- Text ---- */
.page-text {
  max-width: var(--text-max);
  text-align: center;
  line-height: 1.7;
  font-size: clamp(0.8rem, 2.1vw, 1.7rem);
  font-weight: 400;
  letter-spacing: 0.01em;
}

.page-text p + p { margin-top: 1.2em; }

/* Each source line is its own block and never wraps; the fit-to-screen
   script scales the whole passage down until every line fits the width. */
.page-text .line {
  display: block;
  white-space: nowrap;
}
.page-text .line--blank { height: 0.7em; }

/* Inline links from the markdown. */
.page-text a {
  color: inherit;
  text-decoration: none;
  border-bottom: 0.08em solid rgba(43, 35, 32, 0.4);
  padding-bottom: 0.02em;
  transition: border-color 200ms ease, color 200ms ease;
}
.page-text a:hover,
.page-text a:focus-visible {
  color: #7a4a1e;
  border-bottom-color: #7a4a1e;
}

.page-text p { margin: 0 0 0.6em; }
.page-text p:last-child { margin-bottom: 0; }

/* Text-only pages get a touch more presence. */
.page--text-only .page-text {
  font-size: clamp(0.95rem, 2.6vw, 2rem);
  max-width: min(90vw, 52ch);
}

/* First letter flourish on text-only pages. */
.page--text-only .page-text p:first-child::first-letter {
  font-size: 1.35em;
  line-height: 1;
}

/* ---- Scroll hint on the first page ---- */
.scroll-hint {
  position: fixed;
  left: 50%;
  bottom: 2.2rem;
  transform: translateX(-50%);
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  opacity: 0.55;
  animation: bob 2.4s var(--fade-ease) infinite;
  transition: opacity 400ms ease;
}
.scroll-hint.is-hidden { opacity: 0; }

/* ---- Portrait / narrow screens (phones) ----
   Give images far more room, since a 3:2 picture looks tiny when it's
   height-limited on a tall, narrow screen. Also give text the full width
   (the fit-to-screen script scales it to match). */
@media (max-aspect-ratio: 3/4) {
  :root { --text-max: 92vw; }

  .page { padding: clamp(1rem, 4vw, 2rem); }

  .page-image {
    max-width: 92vw;
    max-height: 62vh;
  }
  .page--image-only .page-image {
    max-width: 96vw;
    max-height: 80vh;
  }
  .page--image-text .page-image {
    max-width: 92vw;
    max-height: 48vh;
  }

  .page--text-only .page-text { max-width: 92vw; }

  /* Keep the pager handles from crowding the content on small screens. */
  .pager-btn { width: clamp(48px, 16vw, 88px); }
}

/* ---- Transparent manual pager buttons ---- */
.pager-btn {
  position: fixed;
  top: 0;
  height: 100vh;
  width: clamp(64px, 12vw, 160px);
  border: 0;
  margin: 0;
  padding: 0;
  background: transparent;      /* fully see-through click zones */
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 300ms ease;
}
.pager-prev { left: 0;  justify-content: flex-start; padding-left: clamp(0.5rem, 2vw, 1.5rem); }
.pager-next { right: 0; justify-content: flex-end;  padding-right: clamp(0.5rem, 2vw, 1.5rem); }

/* The chevron sits quietly until you approach the edge. */
.pager-chevron {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1;
  opacity: 0.22;
  transition: opacity 220ms ease, transform 220ms var(--fade-ease);
  user-select: none;
}
.pager-btn:hover .pager-chevron,
.pager-btn:focus-visible .pager-chevron { opacity: 0.75; }
.pager-prev:hover .pager-chevron { transform: translateX(-4px); }
.pager-next:hover .pager-chevron { transform: translateX(4px); }
.pager-btn:focus-visible { outline: none; }

/* Hide a button when there's nowhere to go in that direction. */
.pager-btn[disabled] { opacity: 0; pointer-events: none; }

@keyframes bob {
  0%, 100% { transform: translate(-50%, 0); }
  50%      { transform: translate(-50%, 8px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .scroll-hint { animation: none; }
  .page { transition: none; }
}
