/* ファミリールーツブックの導入（2026-11-19 作り直し、代表の指示）。
   ・最初はロゴだけをフェードインし、そのあと白い面に冊子だけを出す（細かい文字を置かない。「間違ったページ」と思わせない）。
   ・背景は白。その上を、桜・金・藍のごく淡い光がゆっくり流れる（贈り物の包みを開けるときの、柔らかい光）。
   ・ここだけは代表の指示で、ひとりでに動く背景を置く（トップの決まり「勝手に動くものなし」の例外。動きを減らす設定では止める）。
   本の中身はPDF（config.json の pdf）、場面ごとの一行は config.json の captions。 */
:root {
  color-scheme: light;
  --white: #ffffff;
  --ink: #2b2a28;
  --ink-mid: #5a5856;
  --ai: #213a63;
  --gold: #c9a84c;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  font-family: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 15px;
  background: var(--white);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---------- ゆっくり流れる光 ---------- */
.bg { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.glow {
  position: absolute;
  display: block;
  width: 70vmax;
  height: 70vmax;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  will-change: transform;
}
.g1 { left: -22vmax; top: -26vmax; background: radial-gradient(circle, rgba(232, 168, 186, 0.55), rgba(232, 168, 186, 0) 68%); animation: drift1 26s ease-in-out infinite alternate; }
.g2 { right: -24vmax; bottom: -30vmax; background: radial-gradient(circle, rgba(226, 200, 130, 0.5), rgba(226, 200, 130, 0) 68%); animation: drift2 32s ease-in-out infinite alternate; }
.g3 { right: -10vmax; top: -34vmax; width: 56vmax; height: 56vmax; background: radial-gradient(circle, rgba(150, 175, 215, 0.38), rgba(150, 175, 215, 0) 68%); animation: drift3 38s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(28vw, 22vh) scale(1.12); } }
@keyframes drift2 { to { transform: translate(-30vw, -18vh) scale(1.08); } }
@keyframes drift3 { to { transform: translate(-36vw, 26vh) scale(0.94); } }

/* ---------- 最初のロゴ ---------- */
.opening {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.9s ease, transform 1.2s ease;
}
.opening img { width: min(200px, 46vw); height: auto; }
body.is-intro .opening { opacity: 1; animation: logoIn 1.1s ease both; }
@keyframes logoIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* ロゴのあいだは冊子と操作を隠し、そのあとゆっくり出す */
.caption, main, footer { transition: opacity 1s ease 0.25s; }
body.is-intro .caption, body.is-intro main, body.is-intro footer { opacity: 0; transition-delay: 0s; }
body.is-intro #loading { opacity: 0; }

.caption {
  position: relative;
  flex: none;
  margin: 0;
  padding: 92px 20px 6px;
  min-height: calc(1.6em + 98px);
  text-align: center;
  font-family: "Zen Old Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 500;
  font-size: clamp(20px, 2.5vw, 28px);
  line-height: 1.6;
  letter-spacing: 0.12em;
  color: var(--ink);
}
.caption.is-changing { opacity: 0 !important; transform: translateY(6px); transition: opacity 0.4s ease, transform 0.4s ease; }
main {
  position: relative;
  flex: 1;
  min-height: 0;
  touch-action: none;
}
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}
main.dragging #stage { cursor: grabbing; }
.sr-only,
.sr-only-focusable:not(:focus) {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  color: var(--ink-mid);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-align: center;
  max-width: calc(100% - 32px);
}
#loading[hidden] { display: none; }
#loading.error { color: var(--ink); font-size: 15px; line-height: 1.8; opacity: 1; }
#loading.error a { color: var(--ai); }

/* 場面ごとの欄外の小さな注記（config.json の notes。家族写真の場面の「AIで作成した架空の家族」など）。本のページには入れない */
.scene-note {
  flex: none;
  margin: 0;
  min-height: 1.6em;
  padding: 4px 16px 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  letter-spacing: 0.04em;
  color: var(--ink-mid);
  transition: opacity 0.4s ease;
}
.scene-note:empty { opacity: 0; }
body.is-intro .scene-note { opacity: 0; }
footer {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px max(22px, env(safe-area-inset-bottom));
}
.controls { display: flex; align-items: center; gap: 18px; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; }
button:disabled { opacity: 0.3; cursor: default; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
.nav {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ai);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(33, 58, 99, 0.22);
}
.nav:not(:disabled):hover { border-color: var(--ai); }
.nav--next:not(:disabled) { border-color: rgba(33, 58, 99, 0.55); }
.nav svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dots { display: flex; gap: 10px; }
.dots i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(33, 58, 99, 0.18);
  transition: background 0.3s ease, transform 0.3s ease;
}
.dots i.on { background: var(--gold); transform: scale(1.15); }
.read:focus { position: absolute; right: 16px; bottom: 22px; font-size: 14px; color: var(--ai); text-decoration: underline; }
dialog {
  max-width: 720px;
  width: 90vw;
  max-height: 84dvh;
  background: #fff;
  color: var(--ink);
  padding: 24px 26px;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 30px 80px -20px rgba(33, 58, 99, 0.35);
}
dialog::backdrop { background: rgba(33, 58, 99, 0.25); }
dialog h2 { margin: 0 0 12px; font-size: 20px; font-weight: 500; }
dialog pre { margin: 0 0 16px; font: 16px/1.95 "BIZ UDPGothic", sans-serif; white-space: pre-wrap; user-select: text; }
dialog button { border: 1px solid var(--ai); color: var(--ai); border-radius: 999px; padding: 8px 18px; min-height: 40px; }
.noscript { position: fixed; inset: 40% 10% auto; text-align: center; }

/* スマホ：本は横幅で大きさが決まるので、言葉と操作を本に寄せて、間延びさせない */
@media (max-width: 600px) {
  .caption { padding: 17vh 16px 0; font-size: 17px; letter-spacing: 0.06em; }
  footer { padding-bottom: max(16vh, env(safe-area-inset-bottom)); }
  .controls { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .glow { animation: none; }
  body.is-intro .opening { animation: none; }
  .opening, .caption, main, footer { transition-duration: 0.2s; }
}
