#story{
  display:flex;
  justify-content:center;
  align-items:center;

  width:100%;
  height:100vh;
  min-height:600px;
  box-sizing:border-box;
  padding:24px;

  background:radial-gradient(120% 80% at 50% 0%,
      rgba(74,6,125,.10) 0%,
      var(--layer0) 55%);
}

/* The book -------------------------------------------------------------- */
#story-book{
  position:relative;
  overflow:hidden;

  width:min(1920px, 80%);
  height:min(86vh, 900px);

  background:var(--layer1);
  border:1px solid rgba(255,255,255,.07);
  border-radius:28px;

  box-shadow:
      0 30px 80px rgba(0,0,0,.55),
      0 0 40px -12px var(--secondary-color),
      inset 0 1px 0 rgba(255,255,255,.05);
}

/* Reading progress bar, pinned to the very top of the book. */
.story-progress{
  position:absolute;
  top:0;
  left:0;
  z-index:12;

  width:0;
  height:3px;

  background:linear-gradient(90deg, var(--secondary-color), #2f6b4f);
  transition:width .1s linear;
}

/* Scroller -------------------------------------------------------------- */
.story-scroll{
  position:relative;
  height:100%;
  overflow-y:auto;

  /* Scrolling the book stays in the book: never chains to the page, so the
     reader leaves only by scrolling the page margins outside the book. */
  overscroll-behavior:contain;
}
.story-scroll.locked{
  overflow:hidden;
}

/* Sections & typography ------------------------------------------------- */
.story-section{
  padding:0 48px 40px;
}
.story-section + .story-section{
  border-top:1px solid rgba(255,255,255,.05);
}

/* Sticky section header: pins to the top of the book while its own section
   is being read; when the section ends, the next header pushes it up and
   takes its place (position:sticky is confined to the parent section). */
.story-section-header{
  position:sticky;
  top:0;
  z-index:6;

  display:flex;
  flex-direction:column;
  gap:8px;

  /* Full-bleed across the book so the pinned bar covers scrolling content
     edge to edge (cancels the section's side padding). */
  margin:0 -48px 26px;
  padding:22px 48px 16px;

  background:rgba(20,20,20,.85);
  border-bottom:1px solid rgba(255,255,255,.06);
  backdrop-filter:blur(8px);

  overflow:hidden;
}
/* Keep the title above the ornament layer. */
.story-section-header > *{
  position:relative;
  z-index:1;
}

/* Asanoha-star ornament (after patterns/123.jpeg): twelve-ray hemp-leaf star
   bursts on a hexagonal lattice. The mask runs the reference's dissolve
   horizontally - fully transparent behind the title, fully visible at the
   right edge. */
.story-section-header::after{
  content:"";
  position:absolute;
  inset:0;
  z-index:0;
  pointer-events:none;

  background-image:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='58'><defs><g id='a'><path fill='%23ffffff' d='M5 0 L26.8 -3.3 L26.8 3.3 ZM4.3 2.5 L24.9 10.5 L21.6 16.2 ZM2.5 4.3 L16.2 21.6 L10.5 24.9 ZM0 5 L3.3 26.8 L-3.3 26.8 ZM-2.5 4.3 L-10.5 24.9 L-16.2 21.6 ZM-4.3 2.5 L-21.6 16.2 L-24.9 10.5 ZM-5 0 L-26.8 3.3 L-26.8 -3.3 ZM-4.3 -2.5 L-24.9 -10.5 L-21.6 -16.2 ZM-2.5 -4.3 L-16.2 -21.6 L-10.5 -24.9 ZM0 -5 L-3.3 -26.8 L3.3 -26.8 ZM2.5 -4.3 L10.5 -24.9 L16.2 -21.6 ZM4.3 -2.5 L21.6 -16.2 L24.9 -10.5 Z'/></g></defs><use href='%23a' x='0' y='0'/><use href='%23a' x='100' y='0'/><use href='%23a' x='0' y='58'/><use href='%23a' x='100' y='58'/><use href='%23a' x='50' y='29'/></svg>");
  background-size:100px 58px;
  background-repeat:repeat;
  background-position:0 center;

  opacity:.35;

  /* The horizontal dissolve: transparent over the title, building steadily to
     fully visible at the right - the reference's fade, rotated. */
  mask-image:linear-gradient(to right, transparent 0%, transparent 20%, black 95%);
  -webkit-mask-image:linear-gradient(to right, transparent 0%, transparent 20%, black 95%);

  animation:story-ornament-drift 110s linear infinite;
}
/* The lattice glides horizontally, deliberately slow (~1px/s) so repaints are
   rare and cheap. Distance is one exact tile so the loop is seamless. */
@keyframes story-ornament-drift{
  from{ background-position:0 center; }
  to{ background-position:100px center; }
}
/* Color accents: the same star burst in the site's two main hues - %234A067D
   purple, and the green as %2312a35e (a lifted emerald of %23004225, which is
   too dark to read on the bar) - sitting steadily in the lattice gaps between
   the white stars. The drift matches the white layer's pace. */
.story-section-header::before{
  content:"";
  position:absolute;
  inset:0;
  z-index:0;
  pointer-events:none;

  background-image:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='58'><defs><g id='p'><path fill='%234A067D' d='M5 0 L26.8 -3.3 L26.8 3.3 ZM4.3 2.5 L24.9 10.5 L21.6 16.2 ZM2.5 4.3 L16.2 21.6 L10.5 24.9 ZM0 5 L3.3 26.8 L-3.3 26.8 ZM-2.5 4.3 L-10.5 24.9 L-16.2 21.6 ZM-4.3 2.5 L-21.6 16.2 L-24.9 10.5 ZM-5 0 L-26.8 3.3 L-26.8 -3.3 ZM-4.3 -2.5 L-24.9 -10.5 L-21.6 -16.2 ZM-2.5 -4.3 L-16.2 -21.6 L-10.5 -24.9 ZM0 -5 L-3.3 -26.8 L3.3 -26.8 ZM2.5 -4.3 L10.5 -24.9 L16.2 -21.6 ZM4.3 -2.5 L21.6 -16.2 L24.9 -10.5 Z'/></g><g id='g'><path fill='%2312a35e' d='M5 0 L26.8 -3.3 L26.8 3.3 ZM4.3 2.5 L24.9 10.5 L21.6 16.2 ZM2.5 4.3 L16.2 21.6 L10.5 24.9 ZM0 5 L3.3 26.8 L-3.3 26.8 ZM-2.5 4.3 L-10.5 24.9 L-16.2 21.6 ZM-4.3 2.5 L-21.6 16.2 L-24.9 10.5 ZM-5 0 L-26.8 3.3 L-26.8 -3.3 ZM-4.3 -2.5 L-24.9 -10.5 L-21.6 -16.2 ZM-2.5 -4.3 L-16.2 -21.6 L-10.5 -24.9 ZM0 -5 L-3.3 -26.8 L3.3 -26.8 ZM2.5 -4.3 L10.5 -24.9 L16.2 -21.6 ZM4.3 -2.5 L21.6 -16.2 L24.9 -10.5 Z'/></g></defs><use href='%23p' x='50' y='0'/><use href='%23p' x='50' y='58'/><use href='%23g' x='0' y='29'/><use href='%23g' x='100' y='29'/></svg>");
  background-size:100px 58px;
  background-repeat:repeat;
  /* Same origin as the white layer, with the colored stars drawn at the gap
     positions inside the tile: purple fills the top/bottom gaps, green the
     side gaps - so the two colors never cover each other or the white stars. */
  background-position:0 center;

  /* Steady, no pulse - the colors are just quietly present. */
  opacity:.3;

  mask-image:linear-gradient(to right, transparent 0%, transparent 20%, black 95%);
  -webkit-mask-image:linear-gradient(to right, transparent 0%, transparent 20%, black 95%);

  animation:story-ornament-drift 110s linear infinite;
}
.story-topic{
  margin:0;
  font-family:"Story Script", cursive;
  font-size:clamp(34px, 5vw, 52px);
  font-weight:400;
  line-height:1.1;
  color:#fff;
  text-shadow:0 0 24px rgba(74,6,125,.5);
}
/* Floating period badge: bottom-right corner of the book, always showing the
   period of the section currently under the sticky header. */
.story-period-badge{
  position:absolute;
  right:18px;
  bottom:16px;
  z-index:9;
  pointer-events:none;

  padding:6px 14px;

  background:rgba(20,20,20,.75);
  border:1px solid rgba(255,255,255,.08);
  border-radius:20px;

  font-family:Inter, sans-serif;
  font-size:14px;
  font-weight:600;
  letter-spacing:.08em;
  color:rgba(255,255,255,.6);

  backdrop-filter:blur(6px);
}

.story-body{
  display:flex;
  flex-direction:column;
  gap:24px;
}
.story-paragraph{
  margin:0;
  font-family:"Story Script", cursive;
  font-size:clamp(19px, 2.2vw, 23px);
  line-height:1.85;
  color:rgba(255,255,255,.88);
}

.story-quote{
  margin:6px 0;
  padding:6px 0 6px 24px;

  border-left:3px solid var(--secondary-color);

  font-family:"Story Script", cursive;
  font-size:clamp(24px, 3vw, 32px);
  line-height:1.5;
  color:#fff;
  text-shadow:0 0 20px rgba(74,6,125,.4);
}

/* Photos: column layout (centered) ------------------------------------- */
.story-figure{
  margin:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
}
.story-figure img{
  /* Fit any upload: shrink to the column/row width and never taller than
     ~half the book, keeping the aspect ratio (no stretch, no crop). Tall
     portrait photos scale down instead of filling screens. */
  max-width:100%;
  max-height:52vh;
  width:auto;
  height:auto;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.08);
  cursor:zoom-in;
  transition:transform .3s ease, box-shadow .3s ease;
}
.story-figure img:hover{
  transform:translateY(-3px);
  box-shadow:0 14px 34px rgba(0,0,0,.5);
}
.story-figure figcaption{
  font-family:Inter, sans-serif;
  font-size:14px;
  font-style:italic;
  color:rgba(255,255,255,.5);
  text-align:center;
}

/* Chess rows ------------------------------------------------------------ */
.story-row{
  display:flex;
  flex-direction:row;
  align-items:center;
  gap:28px;
}
.story-row.reversed{
  flex-direction:row-reverse;
}
.story-row .story-figure{
  flex:1 1 0;
  min-width:0;
}
.story-row-text{
  flex:1 1 0;
  min-width:0;
}

/* Time-travel reveal ---------------------------------------------------- */
.story-reveal{
  opacity:0;
  transform:translateY(22px);
  transition:opacity .6s ease, transform .6s ease;
}
.story-reveal.in{
  opacity:1;
  transform:none;
}

/* Cover ----------------------------------------------------------------- */
.story-cover{
  position:absolute;
  inset:0;
  z-index:10;

  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:18px;

  padding:40px;
  box-sizing:border-box;
  text-align:center;

  background:
      radial-gradient(90% 70% at 50% 40%, rgba(74,6,125,.18), transparent 70%),
      var(--layer1);

  transition:opacity .6s ease, transform .6s ease, visibility .6s;
}
.story-cover.open{
  opacity:0;
  visibility:hidden;
  transform:translateY(-30px) scale(.98);
  pointer-events:none;
}
.story-cover-title{
  margin:0;
  font-family:"Story Script", cursive;
  font-size:clamp(52px, 10vw, 84px);
  font-weight:400;
  color:#fff;
  text-shadow:0 0 34px rgba(74,6,125,.7);
}
.story-cover-subtitle{
  margin:0;
  font-family:Inter, sans-serif;
  font-size:clamp(15px, 2.4vw, 19px);
  letter-spacing:.04em;
  color:rgba(255,255,255,.6);
}
.story-cover-open{
  margin-top:10px;
  padding:12px 30px;

  background:transparent;
  border:1.5px solid var(--secondary-color);
  border-radius:26px;

  color:#fff;
  font-family:Inter, sans-serif;
  font-size:15px;
  font-weight:600;
  letter-spacing:.03em;

  cursor:pointer;
  box-shadow:0 0 20px -6px var(--secondary-color);
  transition:transform .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.story-cover-open:hover{
  transform:translateY(-2px);
  background:color-mix(in srgb, var(--secondary-color) 25%, transparent);
  box-shadow:0 0 26px -4px var(--secondary-color);
}
.story-cover-continue{
  padding:8px 20px;

  background:none;
  border:none;
  border-radius:16px;

  color:rgba(255,255,255,.55);
  font-family:Inter, sans-serif;
  font-size:14px;
  text-decoration:underline;
  text-underline-offset:3px;

  cursor:pointer;
  transition:color .2s ease;
}
.story-cover-continue:hover{
  color:#fff;
}

/* Lightbox -------------------------------------------------------------- */
.story-lightbox{
  position:fixed;
  inset:0;
  z-index:1000;

  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:16px;

  padding:40px;
  box-sizing:border-box;

  background:rgba(0,0,0,.85);
  backdrop-filter:blur(4px);

  opacity:0;
  visibility:hidden;
  transition:opacity .3s ease, visibility .3s;
  cursor:zoom-out;
}
.story-lightbox.open{
  opacity:1;
  visibility:visible;
}
.story-lightbox-img{
  max-width:90vw;
  max-height:82vh;
  border-radius:16px;
  box-shadow:0 30px 80px rgba(0,0,0,.6);
  cursor:default;
}
.story-lightbox-caption{
  font-family:Inter, sans-serif;
  font-size:15px;
  color:rgba(255,255,255,.75);
  text-align:center;
}
.story-lightbox-close{
  position:absolute;
  top:24px;
  right:28px;

  width:40px;
  height:40px;

  background:rgba(255,255,255,.08);
  border:none;
  border-radius:50%;

  color:#fff;
  font-size:18px;
  cursor:pointer;
  transition:background-color .2s ease;
}
.story-lightbox-close:hover{
  background:rgba(255,255,255,.18);
}

/* Tablet: same book, a little wider in the window ------------------------- */
@media (max-width:1024px){
  #story-book{
    width:90%;
  }
  .story-section{
    padding:0 32px 32px;
  }
  .story-section-header{
    margin:0 -32px 22px;
    padding:18px 32px 14px;
  }
}

/* Small screens: chess rows stack ---------------------------------------- */
@media (max-width:680px){
  #story{
    padding:12px;
  }
  #story-book{
    width:100%;
    height:min(88vh, 900px);
  }
  .story-section{
    padding:0 20px 30px;
  }
  /* Header's full-bleed margins must mirror the section's side padding. */
  .story-section-header{
    margin:0 -20px 18px;
    padding:14px 20px 12px;
  }
  .story-chips{
    padding:14px 24px;
  }
  .story-row,
  .story-row.reversed{
    flex-direction:column;
  }
  .story-period-badge{
    right:10px;
    bottom:10px;
    font-size:12px;
  }
  .story-cover{
    padding:24px;
  }
}
