/* A place's story, as a picture book (js/storybook.js). The pictures for the
   Village's story are in js/village-intro.js. */

.sb { z-index: 80; padding: 12px; }
.sb.out { opacity: 0; transition: opacity 0.3s; }
.sb-book {
  position: relative;
  width: min(920px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: grid; gap: 10px;
  padding: 14px 16px 12px;
  border: 6px solid #fff; border-radius: var(--radius);
  background: linear-gradient(#fffaf2, #fff1e2);
  box-shadow: 0 18px 50px rgba(74, 42, 92, 0.3);
}
.sb-book.turn .sb-picture > * { animation: sb-in 0.45s ease-out both; }
@keyframes sb-in { from { opacity: 0; transform: translateX(18px); } }

.sb-title { margin: 0; padding-right: 92px; font-size: clamp(20px, 3.4vw, 30px); font-weight: 700; color: var(--lilac-deep); }
.sb-skip { position: absolute; top: 12px; right: 14px; }

/* The picture: the village's own shape, as big as fits. */
.sb-picture {
  position: relative;
  width: min(100%, calc((100dvh - 270px) * 1.6667));
  justify-self: center;
  aspect-ratio: 1200 / 720;
  overflow: hidden;
  border: 4px solid #fff; border-radius: 20px;
  background: #bfe2ff;
  box-shadow: 0 6px 18px rgba(74, 42, 92, 0.15);
  cursor: pointer;
}
.sb-scene { position: absolute; inset: 0; }
.sb-scene .vg-scene, .sb-scene .vg-skylayer { position: absolute; inset: 0; width: 100%; height: 100%; }

/* 1. Long ago: an old photo on the table. */
.sb-old { background: radial-gradient(circle at 30% 30%, #f7e7c9, #e6cfa6); }
.sb-photo {
  position: absolute; inset: 7% 13% 6%;
  padding: 2.2% 2.2% 9%;
  background: #fffdf6; border-radius: 6px;
  box-shadow: 0 10px 24px rgba(90, 60, 20, 0.3);
  rotate: -3deg;
  animation: sb-photo 0.8s var(--bounce) both;
}
@keyframes sb-photo { from { rotate: 8deg; scale: 0.8; opacity: 0; } }
.sb-photo .sb-scene { inset: 3% 3% 13%; overflow: hidden; border-radius: 3px; filter: sepia(0.65) saturate(0.9) brightness(1.04); }
.sb-photo-cap {
  position: absolute; left: 0; right: 0; bottom: 2.5%;
  text-align: center; font-size: clamp(13px, 2.4vw, 22px); font-style: italic; color: #8a6a44;
}

/* 2. The storm: dark, rain, a flash, and the bridge is gone. */
.sb-storm { background: #2b2f55; }
.sb-storm .sb-scene { filter: brightness(0.45) saturate(0.45) hue-rotate(-10deg); }
.sb-storm::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(rgba(20, 22, 60, 0.55), rgba(20, 22, 60, 0.15) 60%); }
.sb-storm .sb-scene.after { opacity: 0; transition: opacity 1s; }
.sb-storm.gone .sb-scene.after { opacity: 1; }
.sb-rain {
  position: absolute; inset: -20% 0 0;
  background: repeating-linear-gradient(100deg, transparent 0 22px, rgba(220, 230, 255, 0.45) 22px 24px);
  background-size: 120px 100%;
  animation: sb-rain 0.45s linear infinite;
}
@keyframes sb-rain { to { transform: translate(-18px, 20%); } }
.sb-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.sb-storm.flash .sb-flash { animation: sb-flash 0.7s ease-out; }
@keyframes sb-flash { 0%, 30% { opacity: 0.85; } 15% { opacity: 0.2; } 100% { opacity: 0; } }

/* 3. Today: gray, foggy, asleep. */
.sb-fog {
  position: absolute; inset: 0 -30%;
  background:
    radial-gradient(ellipse 30% 22% at 20% 60%, rgba(255, 255, 255, 0.8), transparent 70%),
    radial-gradient(ellipse 34% 20% at 60% 45%, rgba(255, 255, 255, 0.7), transparent 70%),
    radial-gradient(ellipse 30% 24% at 90% 70%, rgba(255, 255, 255, 0.75), transparent 70%);
  animation: sb-fog 9s ease-in-out infinite alternate;
}
@keyframes sb-fog { to { transform: translateX(14%); } }
.sb-zzz { position: absolute; left: 55%; top: 22%; font-size: clamp(22px, 4vw, 40px); font-weight: 700; color: #7f86a8; }
.sb-zzz, .sb-zzz i, .sb-zzz b { font-style: normal; display: inline-block; animation: sb-z 2.4s ease-in-out infinite; }
.sb-zzz i { font-size: 0.8em; animation-delay: 0.4s; }
.sb-zzz b { font-size: 0.6em; animation-delay: 0.8s; }
@keyframes sb-z { 50% { transform: translateY(-10px); opacity: 0.5; } }

/* 4. Why you: you, and how helping fixes the village. */
.sb-you { background: linear-gradient(160deg, #ffe9f4, #efe6ff 60%, #e2f4ff); }
.sb-you-row { position: absolute; inset: 0; display: flex; align-items: center; gap: 3%; padding: 3% 5%; }
.sb-hero { flex: 0 0 24%; animation: sb-hop 1.6s ease-in-out infinite; }
.sb-hero svg { display: block; width: 100%; height: auto; }
.sb-avatar { font-size: clamp(60px, 12vw, 120px); }
@keyframes sb-hop { 50% { transform: translateY(-4%); } }
.sb-chain { flex: 1; display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 0; list-style: none; }
.sb-chain li { display: grid; justify-items: center; gap: 6px; text-align: center; animation: sb-pop 0.5s var(--bounce) both; animation-delay: calc(0.35s + var(--i) * 0.45s); }
.sb-chain li > span { font-size: clamp(34px, 7vw, 68px); line-height: 1.1; filter: drop-shadow(0 4px 4px rgba(74, 42, 92, 0.15)); }
.sb-chain .sb-arrow { align-self: flex-start; margin-top: clamp(8px, 2vw, 22px); font-size: clamp(18px, 3.4vw, 32px); font-weight: 700; color: var(--lilac); }
.sb-chain .sb-chip {
  font-size: clamp(16px, 3vw, 28px); font-weight: 700;
  padding: 0.3em 0.55em; border: 4px solid var(--outline); border-radius: 14px; background: #fff;
}
.sb-chain small { font-size: clamp(11px, 1.9vw, 17px); font-weight: 600; color: var(--ink-soft); max-width: 8em; }
@keyframes sb-pop { from { opacity: 0; transform: scale(0.4); } }

/* 5. What it could be: day one wipes into the village finished. */
.sb-wipe { position: absolute; inset: 0; clip-path: inset(0 100% 0 0); transition: clip-path 1.2s ease-in-out; }
.sb-could.wipe .sb-wipe { clip-path: inset(0 0 0 0); }
.sb-wipe::after { content: ''; position: absolute; top: 0; bottom: 0; right: 0; width: 6px; background: #fff; box-shadow: 0 0 20px #fff; }

/* The narrator, and what they say. */
.sb-talk { display: flex; align-items: center; gap: 10px; }
.sb-narrator { flex: 0 0 clamp(58px, 10vw, 92px); }
.sb-narrator svg { display: block; width: 100%; height: auto; }
.sb-narrator.talk { animation: sb-talk 0.5s ease-in-out 3; }
@keyframes sb-talk { 50% { transform: translateY(-6px) rotate(-3deg); } }
.sb-bubble {
  position: relative; flex: 1;
  padding: 10px 16px; border: 4px solid var(--outline); border-radius: 20px; background: #fff;
}
.sb-bubble::before {
  content: ''; position: absolute; left: -14px; top: 50%; translate: 0 -50%;
  border: 10px solid transparent; border-right: 12px solid var(--outline); border-left: 0;
}
.sb-name { font-size: 14px; color: var(--pink-deep); }
.sb-line { margin: 2px 0 0; font-size: clamp(16px, 2.6vw, 22px); line-height: 1.3; font-weight: 600; }

.sb-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sb-back:disabled { visibility: hidden; }
.sb-dots { display: flex; gap: 8px; }
.sb-dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--lilac-soft); border: 2px solid var(--lilac); }
.sb-dots i.on { background: var(--lilac); }
.sb-next { min-width: 8em; }
.sb-next.sb-done { animation: sb-glow 1.4s ease-in-out infinite; }
@keyframes sb-glow { 50% { transform: scale(1.06); } }

/* Short windows (phones on their side): a tighter book. */
@media (max-height: 520px) {
  .sb { padding: 6px; }
  .sb-book { gap: 6px; padding: 8px 12px; }
  .sb-picture { width: min(100%, calc((100dvh - 230px) * 1.6667)); }
  .sb-title { font-size: 18px; }
  .sb-skip { top: 6px; }
  .sb-bubble { padding: 6px 12px; }
  .sb-nav .btn { padding-block: 6px; font-size: 17px; }
  .sb-nav .round-btn { width: 38px; height: 38px; }
  .sb-narrator { flex-basis: 48px; }
  .sb-line { font-size: 15px; }
}

/* Speedy Town's colors. */
html[data-theme='town'] .sb-book { background: linear-gradient(#f6f9ff, #e8f0ff); }
html[data-theme='town'] .sb-title { color: #2f6ad6; }
html[data-theme='town'] .sb-name { color: #2f6ad6; }
html[data-theme='town'] .sb-you { background: linear-gradient(160deg, #e2f4ff, #fff6d6 60%, #e4f8e8); }
html[data-theme='town'] .sb-dots i { background: #dbe7ff; border-color: #4b8df0; }
html[data-theme='town'] .sb-dots i.on { background: #4b8df0; }

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