:root {
  --sky: #BFE6FF;
  --cream: #FFF8E7;
  --pink: #FFD6E5;
  --mint: #D8F3EC;
  --text: #5A6B7B;
  --sunset: #FFB6A3;
  --gold: #F5D58A;
  --blue: #6a9fcf;
  --round: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", sans-serif;
  --hand: "Klee One", "Zen Maru Gothic", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(#cfeaff, #eef8ff);
  color: var(--text);
  font-family: var(--round);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font-family: inherit; color: inherit; cursor: pointer; }

#app {
  position: fixed;
  inset: 0;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
}
@media (min-width: 520px) {
  #app { box-shadow: 0 0 60px rgba(90, 140, 190, .25); }
}

/* ---------- 空 ---------- */
#sky, .sky-layer, #stars, #clouds { position: absolute; inset: 0; }
#sky { z-index: 0; }
.sky-layer { opacity: 0; transition: opacity 2s ease; }
.sky-layer.sky    { background: linear-gradient(#9fd6ff, #BFE6FF 45%, #fbfdff); }
.sky-layer.cream  { background: linear-gradient(#fff8e7, #ffefd6); }
.sky-layer.sunset { background: linear-gradient(#ffb6a3, #ffd6e5 50%, #fff1e2); }
.sky-layer.night  { background: linear-gradient(#1d2753, #37467f 60%, #66699f); }
.sky-layer.dusk   { background: linear-gradient(#34427a, #8a7cb5 55%, #f0c4d6); }
.sky-layer.dawn   { background: linear-gradient(#ffd6e5, #ffe9d8 40%, #BFE6FF); }
#app[data-theme="sky"] .sky-layer.sky,
#app[data-theme="cream"] .sky-layer.cream,
#app[data-theme="sunset"] .sky-layer.sunset,
#app[data-theme="night"] .sky-layer.night,
#app[data-theme="dusk"] .sky-layer.dusk,
#app[data-theme="dawn"] .sky-layer.dawn { opacity: 1; }

#stars { z-index: 1; opacity: 0; transition: opacity 2s; }
#app[data-theme="night"] #stars, #app[data-theme="dusk"] #stars { opacity: 1; }
#stars i {
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: #fff;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle { 50% { opacity: .2; } }

#clouds { z-index: 2; transition: opacity 2s; }
#app[data-theme="night"] #clouds { opacity: .25; }
#app[data-theme="dusk"] #clouds { opacity: .45; }
#app[data-theme="cream"] #clouds { opacity: .5; }
.drift {
  position: absolute;
  left: -40%;
  animation: drift linear infinite;
  filter: drop-shadow(0 6px 10px rgba(120, 170, 210, .18));
}
.drift svg { display: block; width: 100%; }
@keyframes drift { from { left: -40%; } to { left: 110%; } }

#fuji {
  position: absolute;
  left: 0; bottom: 0;
  width: 100%;
  height: 26%;
  z-index: 3;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 1.6s, transform 1.6s;
}
#fuji.show { opacity: 1; transform: none; }

/* ---------- レイヤー ---------- */
#stage { position: absolute; inset: 0; z-index: 10; }
#bubble { z-index: 35; }
#cinna { z-index: 36; }
#hint { z-index: 37; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 45; pointer-events: none; }
#pocket { z-index: 48; }
#topbar { z-index: 50; }
#topbar { transition: opacity .6s; }
#app.reading #topbar { opacity: 0; pointer-events: none; }

/* ---------- 上部バー ---------- */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#topbar button {
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 2px 8px rgba(90, 107, 123, .15);
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#back { font-size: 22px !important; line-height: 1; padding-bottom: 3px !important; }
#back.hide { visibility: hidden; }
#dots { display: flex; gap: 7px; transition: opacity .6s; }
#topbar.no-dots #dots { opacity: 0; }
#dots i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(106, 159, 207, .3);
  box-shadow: 0 0 0 1px rgba(106, 159, 207, .45);
  transition: all .5s;
}
#dots i.done { background: #fff; }
#dots i.now { background: #fff; transform: scale(1.5); box-shadow: 0 0 8px rgba(255, 255, 255, .9); }

/* ---------- 雲のかけらポケット ---------- */
#pocket {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(106, 159, 207, .28);
  opacity: 0;
  transition: opacity .6s, box-shadow .8s;
}
#pocket.show { opacity: 1; }
#pocket.full { box-shadow: 0 0 18px rgba(255, 240, 180, .9); background: rgba(255, 255, 255, .6); }
.slot {
  width: 26px; height: 16px;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 70'%3E%3Cpath d='M30 62H96A20 20 0 0 0 98 22A26 26 0 0 0 50 16A20 20 0 0 0 22 32A16 16 0 0 0 30 62Z' fill='none' stroke='%23ffffff' stroke-width='6' stroke-dasharray='10 8'/%3E%3C/svg%3E");
  transition: transform .4s;
}
.slot.on {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 70'%3E%3Cpath d='M30 62H96A20 20 0 0 0 98 22A26 26 0 0 0 50 16A20 20 0 0 0 22 32A16 16 0 0 0 30 62Z' fill='%23ffffff' stroke='%23F5D58A' stroke-width='5'/%3E%3C/svg%3E");
  filter: drop-shadow(0 0 4px rgba(255, 230, 150, .9));
  transform: scale(1.1);
}

/* ---------- シナモン ---------- */
#cinna {
  --size: 112px;
  position: absolute;
  left: 0; top: 0;
  width: var(--size);
  opacity: 0;
  pointer-events: none;
  transition: transform 1.2s cubic-bezier(.45, .05, .35, 1), opacity .6s;
  will-change: transform;
}
#cinna.show { opacity: 1; }
.cinna-float { animation: float 3.2s ease-in-out infinite; }
.cinna-body img, .cinna-body svg {
  display: block;
  width: 100%;
  filter: drop-shadow(0 6px 10px rgba(90, 107, 123, .25));
}
.cinna-body.hop { animation: hop .75s ease; }
.cinna-body.wave { animation: wave 1.1s ease-in-out 2; }
.cinna-body.pop { animation: pop .9s cubic-bezier(.3, 1.5, .5, 1); }
@keyframes float { 0%, 100% { transform: translateY(-6px); } 50% { transform: translateY(6px); } }
@keyframes hop {
  30% { transform: translateY(-24px) rotate(-8deg); }
  60% { transform: translateY(0) rotate(6deg); }
  80% { transform: translateY(-6px) rotate(-3deg); }
}
@keyframes wave { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
@keyframes pop { from { transform: scale(.2); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 吹き出し・ヒント ---------- */
#bubble {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(62px + var(--safe-b));
  padding: 16px 20px;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(90, 107, 123, .18);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .4s, transform .4s;
  pointer-events: none;
}
#bubble.show { opacity: 1; transform: none; }
#bubble::after {
  content: "";
  position: absolute;
  right: 54px; top: -9px;
  border: 10px solid transparent;
  border-top: 0;
  border-bottom-color: #fff;
}
#bubble-text {
  margin: 0;
  font-size: 15.5px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.8em;
}
#bubble-text .ch { opacity: 0; transition: opacity .18s; }
#bubble-text .ch.on { opacity: 1; }

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 4px 14px rgba(90, 107, 123, .18);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  color: #4a82b8;
  opacity: 0;
  transition: opacity .4s;
  pointer-events: none;
}
#hint.show { opacity: 1; animation: nudge 1.8s ease-in-out infinite; }
/* 薄くせず、ふわっと上下に揺らして気づかせる */
@keyframes nudge { 0%, 100% { transform: translateX(-50%); } 50% { transform: translateX(-50%) translateY(-5px); } }

.tappable { cursor: pointer; animation: tapGlow 1.6s ease-in-out infinite; }
@keyframes tapGlow {
  50% { filter: drop-shadow(0 0 16px rgba(255, 255, 255, 1)) brightness(1.04); }
}

/* ---------- オープニング ---------- */
.opening {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding-bottom: 40px;
}
.title-cloud { position: relative; width: min(90vw, 390px); animation: float 4s ease-in-out infinite; }
.title-cloud svg { position: relative; display: block; width: 100%; filter: drop-shadow(0 10px 20px rgba(110, 160, 210, .3)); }
/* オープニング：雲のうしろからシナモンが顔を出す */
.title-cloud .peek {
  position: absolute;
  right: 8%; top: -11%;
  width: 34%;
  transform: translateY(48%) rotate(8deg);
  opacity: 0;
  filter: drop-shadow(0 6px 10px rgba(90, 107, 123, .2));
  animation: peek 1s .7s cubic-bezier(.3, 1.5, .5, 1) forwards, peekSway 3.6s 1.8s ease-in-out infinite;
}
@keyframes peek { to { transform: translateY(0) rotate(8deg); opacity: 1; } }
@keyframes peekSway { 0%, 100% { transform: rotate(8deg); opacity: 1; } 50% { transform: translateY(-5px) rotate(2deg); opacity: 1; } }
.title-cloud h1 {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10% 0 0 8%;
  display: grid;
  place-content: center;
  font-size: clamp(22px, 6.6vw, 31px);
  line-height: 1.45;
  font-weight: 700;
  color: #6a9fcf;
  letter-spacing: .04em;
}
.title-cloud h1 small { display: block; font-size: .5em; font-weight: 500; color: #9cbfdc; letter-spacing: .2em; }
.opening .for { margin: 4px 0 18px; font-family: var(--hand); font-size: 18px; color: #6f8aa3; }
.start-btn {
  position: relative;
  width: 172px;
  padding: 0;
  border: 0;
  background: none;
}
.start-btn svg { display: block; width: 100%; filter: drop-shadow(0 6px 12px rgba(110, 160, 210, .35)); }
.start-btn span {
  position: absolute;
  inset: 0;
  padding: 12% 0 0 9%;
  display: grid;
  place-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #5a90c4;
  letter-spacing: .1em;
}
.sound-note { margin: 10px 0 0; font-size: 12px; opacity: .7; }
.opening.leave { animation: leave 1.1s ease forwards; }
@keyframes leave { to { opacity: 0; transform: translateY(-40px) scale(1.05); filter: blur(6px); } }

/* ---------- プロローグの雲 ---------- */
.big-cloud {
  position: absolute;
  left: 50%; top: 40%;
  width: min(72vw, 310px);
  transform: translate(-50%, -50%);
}
.big-cloud svg { display: block; width: 100%; filter: drop-shadow(0 10px 20px rgba(110, 160, 210, .3)); animation: float 4s ease-in-out infinite; }
.big-cloud.wobble svg { animation: wobble .8s ease; }
.big-cloud.puff { transition: opacity 1.2s, transform 1.2s; opacity: 0; transform: translate(-50%, -50%) scale(1.4); filter: blur(6px); }
@keyframes wobble {
  20% { transform: scale(1.08, .92); }
  45% { transform: scale(.94, 1.06); }
  70% { transform: scale(1.03, .97); }
}

/* ---------- 章タイトル ---------- */
.chapter-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity .7s;
}
.chapter-card.in { opacity: 1; }
.cc-inner { position: relative; width: min(80vw, 330px); text-align: center; transform: translateY(14px); transition: transform 1.2s; }
.chapter-card.in .cc-inner { transform: none; }
.cc-inner svg { display: block; width: 100%; filter: drop-shadow(0 10px 20px rgba(110, 160, 210, .25)); }
.cc-text { position: absolute; inset: 0; padding: 12% 0 0 8%; display: grid; place-content: center; gap: 2px; }
.cc-num { margin: 0; font-size: 13px; letter-spacing: .3em; color: #9cbfdc; }
.cc-text h2 { margin: 0; font-size: clamp(18px, 5.4vw, 23px); color: #5a90c4; }

/* ---------- 写真（ポラロイド） ---------- */
.polaroid {
  --w: min(66vw, 290px, calc(100dvh - 340px));
  margin: 0;
  width: var(--w);
  padding: 10px 10px 0;
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 10px 24px rgba(70, 90, 110, .22);
}
.polaroid .ph { aspect-ratio: 1 / 1; overflow: hidden; background: #eef5fb; }
.polaroid .ph img { display: block; width: 100%; height: 100%; object-fit: cover; }
.polaroid .ph.empty svg { display: block; width: 100%; height: 100%; }
.polaroid figcaption {
  padding: 8px 4px 12px;
  font-family: var(--hand);
  font-size: 15px;
  text-align: center;
  color: #6b7a88;
}
.polaroid.no-cap { padding-bottom: 30px; }

.pile {
  position: absolute;
  left: 0; right: 0;
  top: 96px;
  bottom: calc(110px + var(--safe-b));
}
.pile .polaroid {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) translate(var(--dx), 0) rotate(var(--r));
  animation: drop 1.5s cubic-bezier(.25, .8, .3, 1) both;
}
@keyframes drop {
  0% { transform: translate(-50%, -50%) translate(var(--dx), -110vh) rotate(calc(var(--r) - 40deg)); }
  60% { transform: translate(-50%, -50%) translate(calc(var(--dx) + 18px), 8px) rotate(calc(var(--r) + 8deg)); }
  100% { transform: translate(-50%, -50%) translate(var(--dx), 0) rotate(var(--r)); }
}

/* ---------- 第2章：富士山 ---------- */
.fuji-view { position: absolute; inset: 0; overflow: hidden; }
.fuji-photo {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scale(1.18);
  transition: transform 4s cubic-bezier(.2, .6, .3, 1);
}
.fuji-photo svg { display: block; width: 100%; height: 100%; }
.fuji-view.open .fuji-photo { transform: none; }
.curtain {
  position: absolute;
  top: -6%; bottom: -6%;
  width: 64%;
  background: linear-gradient(#ffffff, #f2f8ff);
  transition: transform 2.8s cubic-bezier(.65, 0, .35, 1);
}
.curtain.left { left: 0; }
.curtain.right { right: 0; }
.curtain i {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 42% 38%, #ffffff 55%, #e8f3fd);
}
.fuji-view.open .curtain.left { transform: translateX(-135%); }
.fuji-view.open .curtain.right { transform: translateX(135%); }
.photo-chip {
  position: absolute;
  top: 96px; left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
  font-family: var(--hand);
  font-size: 15px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 1s;
}
.photo-chip.show { opacity: 1; }
.fuji-view .polaroid {
  position: absolute;
  left: 50%; top: 42%;
  --r: 3deg; --dx: 0px;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: drop 1.5s cubic-bezier(.25, .8, .3, 1) both;
}

/* ---------- 第3章：メニュー ---------- */
.menu {
  position: absolute;
  left: 18px; right: 18px;
  top: 92px;
  bottom: calc(196px + var(--safe-b));
  /* 看板の下の残りの高さを、写真4枚でちょうど埋める */
  display: flex;
  flex-direction: column;
  padding: 12px 14px 14px;
  background: #fffdf7;
  border: 2px solid #ecdcbc;
  border-radius: 20px;
  box-shadow: 0 10px 26px rgba(160, 120, 70, .14), inset 0 0 0 6px #fffdf7, inset 0 0 0 7px #f3e6cc;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .8s, transform .8s;
}
.menu.in { opacity: 1; transform: none; }
.menu-head { flex: none; text-align: center; margin-bottom: 8px; }
.menu-head small { display: block; font-family: var(--hand); font-size: 14px; color: #c49a6c; letter-spacing: .1em; }
.menu-head h2 { margin: 0; font-size: 22px; letter-spacing: .12em; color: #a77b52; }
.menu-head p { margin: 4px 0 0; font-size: 12px; color: #b7987a; }
.food-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
}
/* 画面が低いときは看板を小さくして、写真に高さを回す */
@media (max-height: 700px) {
  .menu { top: 84px; }
  .menu-head { margin-bottom: 6px; }
  .menu-head small, .menu-head p { display: none; }
  .menu-head h2 { font-size: 19px; }
}
.food {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  padding: 5px 5px 6px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(160, 120, 70, .16);
  text-align: center;
  opacity: 0;
  transform: scale(.7) rotate(var(--r));
  transition: opacity .5s, transform .6s cubic-bezier(.3, 1.5, .5, 1);
}
.food.in { opacity: 1; transform: rotate(var(--r)); }
.food .ph { flex: 1; min-height: 0; border-radius: 8px; overflow: hidden; background: #fff1dc; }
.food .ph img, .food .ph svg { display: block; width: 100%; height: 100%; object-fit: cover; }
.food figcaption { flex: none; display: flex; flex-direction: column; gap: 1px; margin-top: 5px; line-height: 1.3; }
.food .name { font-weight: 700; color: #8a6a4c; font-size: 14px; }
.food-grid.has-note figcaption { min-height: calc(14px * 1.3 + 12px * 1.3 + 1px); }
.food .note { font-family: var(--hand); font-size: 12px; color: #a8927c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 第4章：スライド ---------- */
.slideshow {
  position: absolute;
  left: 0; right: 0;
  top: 96px;
  bottom: calc(110px + var(--safe-b));
}
.slideshow .polaroid {
  --w: min(62vw, 272px, calc((100dvh - 330px) * .76));
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: slideIn 1.1s cubic-bezier(.3, .9, .3, 1) both;
}
.slideshow .polaroid .ph { aspect-ratio: 4 / 5; }
.slideshow .polaroid.out { animation: slideOut .9s ease-in both; }
@keyframes slideIn {
  from { opacity: 0; transform: translate(-50%, -50%) translateX(60px) rotate(calc(var(--r) + 10deg)) scale(.92); }
}
@keyframes slideOut {
  to { opacity: 0; transform: translate(-50%, -50%) translateX(-80px) rotate(calc(var(--r) - 14deg)) scale(.9); }
}
.floaty {
  position: absolute;
  bottom: -30px;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 150, 180, .8);
  animation: rise linear forwards;
  pointer-events: none;
}
@keyframes rise {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  15% { opacity: .95; }
  50% { transform: translateY(-50vh) translateX(16px); }
  100% { transform: translateY(-105vh) translateX(-10px); opacity: 0; }
}
.heart { position: absolute; left: 0; top: 0; pointer-events: none; text-shadow: 0 0 6px rgba(255, 255, 255, .9); }

/* ---------- 第5章：パーティー ---------- */
.party { position: absolute; inset: 0; }
.garland { position: absolute; left: 0; right: 0; top: 84px; width: 100%; height: 70px; }
.garland .flag { opacity: 0; transform: translateY(-16px); transition: opacity .5s, transform .6s cubic-bezier(.3, 1.6, .5, 1); transform-box: fill-box; }
.garland.show .flag { opacity: 1; transform: none; }
.garland .string { stroke-dasharray: 500; stroke-dashoffset: 500; transition: stroke-dashoffset 1s; }
.garland.show .string { stroke-dashoffset: 0; }
.balloon {
  position: absolute;
  width: 46px; height: 58px;
  border-radius: 50% 50% 48% 48%;
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, .06), inset 6px 6px 0 rgba(255, 255, 255, .35);
}
.balloon::after {
  content: "";
  position: absolute;
  left: 50%; top: 100%;
  width: 1.5px; height: 60px;
  background: rgba(255, 255, 255, .6);
}
.balloon.sway { animation: sway 4s ease-in-out infinite; }
.balloon { transition: opacity .8s; }
.balloon.away { opacity: 0; }
@keyframes sway { 50% { transform: translateY(-10px) rotate(4deg); } }
.cake {
  position: absolute;
  left: 50%; top: 60%;
  width: min(58vw, 236px);
  transform: translate(-50%, -50%) scale(.2);
  opacity: 0;
  transition: transform .9s cubic-bezier(.3, 1.5, .5, 1), opacity .5s;
}
.cake.in { transform: translate(-50%, -50%); opacity: 1; }
.cake svg { display: block; width: 100%; overflow: visible; }
.cake .flame { opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; transition: opacity .4s; }
.cake.lit .flame { opacity: 1; animation: flicker .5s ease-in-out infinite alternate; }
/* マイクで息を吹きかけている間は、強さに合わせて炎が小さく・薄くなる */
.cake.lit .flame { opacity: calc(1 - var(--blow, 0) * .7); }
.cake.out .flame { opacity: 0; animation: none; transform: scaleY(.2); transition: opacity .3s, transform .3s; }
.cake .smoke { opacity: 0; }
.cake.out .smoke { animation: smoke 1.6s ease-out forwards; transform-box: fill-box; }
@keyframes flicker { from { transform: scale(1, 1) rotate(-3deg); } to { transform: scale(.88, 1.1) rotate(3deg); } }
@keyframes smoke { 0% { opacity: .7; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-30px) scale(1.6); } }
.mic-btn {
  position: absolute;
  left: 50%;
  bottom: calc(60px + var(--safe-b));
  transform: translateX(-50%);
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, .5);
}
.blackout { position: absolute; inset: 0; background: #0b1030; opacity: 0; transition: opacity .5s; pointer-events: none; z-index: 5; }
.blackout.on { opacity: .82; }
.hb {
  position: absolute;
  left: 0; right: 0;
  top: 23%;
  text-align: center;
  color: #fff;
  z-index: 6;
}
.hb p { margin: 0; opacity: 0; transform: scale(.6); transition: opacity .8s, transform 1s cubic-bezier(.3, 1.6, .5, 1); }
.hb.in p { opacity: 1; transform: none; }
.hb .hb1 { opacity: 1; transform: none; }
.hb .hb1 span { display: inline-block; opacity: 0; transform: translateY(-40px) scale(.4); transition: opacity .4s, transform .8s cubic-bezier(.3, 1.8, .5, 1); }
.hb .hb1 .sp { width: .3em; }
.hb.in .hb1 span { opacity: 1; transform: none; }
.hb .hb1 { font-family: var(--hand); font-weight: 600; font-size: clamp(32px, 10vw, 44px); text-shadow: 0 0 18px rgba(255, 214, 229, .9), 0 0 4px #ffb6c9; }
.hb .hb2 { margin-top: 4px; font-size: 22px; font-weight: 700; transition-delay: 1s; text-shadow: 0 0 12px rgba(191, 230, 255, .9); }
.hb .hb3 { margin-top: 6px; font-family: var(--hand); font-size: 15px; letter-spacing: .2em; color: #ffd6e5; transition-delay: 1.4s; }
/* ろうそくの後：旅の写真を扇形に広げる */
.cake.away { opacity: 0; transform: translate(-50%, -30%) scale(.8); }
.memory-fan { position: absolute; left: 50%; top: min(61%, calc(100% - 330px)); width: 0; height: 0; z-index: 4; }
.memory-fan .polaroid.mini {
  --w: min(30vw, 120px);
  position: absolute; left: 0; top: 0;
  padding: 6px 6px 18px;
  opacity: 0;
  transform: translate(-50%, -50%) translateY(60px) scale(.5);
  transition: opacity .5s, transform .9s cubic-bezier(.3, 1.4, .5, 1);
}
.memory-fan.in .polaroid.mini { opacity: 1; transform: translate(-50%, -50%) translate(calc(var(--x) * 2.6), var(--y)) rotate(var(--r)); }

/* ---------- 第6章：雲のかけら → 封筒 ---------- */
.piece {
  position: absolute;
  left: 0; top: 0;
  width: 48px;
  pointer-events: none;
  filter: drop-shadow(0 0 8px rgba(255, 236, 170, .95)) drop-shadow(0 0 2px #fff);
}
.piece svg { display: block; width: 100%; }
.flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, #fff 0, rgba(255, 255, 255, .9) 25%, rgba(255, 255, 255, 0) 70%);
  opacity: 0;
  pointer-events: none;
}
.envelope {
  position: absolute;
  left: 50%; top: 46%;
  width: min(78vw, 320px);
  aspect-ratio: 3 / 2;
  transform: translate(-50%, -50%);
  perspective: 900px;
  transition: opacity .8s, transform .8s;
}
.envelope.appear { animation: envIn 1s cubic-bezier(.3, 1.4, .5, 1) backwards; }
@keyframes envIn { from { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-8deg); } }
.envelope.gone { opacity: 0; transform: translate(-50%, -30%) scale(.9); }
.env-back, .env-front, .env-flap, .env-paper { position: absolute; }
.env-back { inset: 0; background: #e9f2fa; border-radius: 8px; box-shadow: 0 16px 36px rgba(20, 30, 70, .35); }
.env-paper {
  left: 6%; right: 6%;
  top: 5%;
  height: 90%;
  background: var(--cream);
  border-radius: 4px;
  padding: 18% 12% 0;
  transition: transform 1.1s cubic-bezier(.4, 0, .2, 1);
  z-index: 2;
}
.env-paper i { display: block; height: 2px; margin-bottom: 12%; background: #eadfc8; border-radius: 2px; }
.envelope.pull .env-paper { transform: translateY(-72%); }
.env-front {
  inset: 0;
  background: linear-gradient(160deg, #ffffff, #eef5fc);
  border-radius: 8px;
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  z-index: 3;
}
.env-flap {
  left: 0; right: 0; top: 0;
  height: 100%;
  background: linear-gradient(#f7fbff, #e3eef8);
  clip-path: polygon(0 0, 100% 0, 50% 58%);
  transform-origin: 50% 0;
  transition: transform .9s ease-in-out;
  z-index: 4;
}
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.flap-back .env-flap { z-index: 1; }
.seal {
  position: absolute;
  left: 50%; top: 58%;
  width: 74px;
  aspect-ratio: 120 / 70;
  transform: translate(-50%, -50%);
  z-index: 5;
}
.seal .half { position: absolute; inset: 0; transition: transform .9s ease-in, opacity .9s ease-in; }
.seal .half svg { display: block; width: 100%; filter: drop-shadow(0 2px 3px rgba(40, 90, 140, .35)); }
.seal .half.l { clip-path: polygon(0 0, 54% 0, 47% 32%, 57% 56%, 48% 100%, 0 100%); }
.seal .half.r { clip-path: polygon(54% 0, 100% 0, 100% 100%, 48% 100%, 57% 56%, 47% 32%); }
.seal.cracked .half.l { transform: translate(-34px, 90px) rotate(-40deg); opacity: 0; }
.seal.cracked .half.r { transform: translate(34px, 90px) rotate(40deg); opacity: 0; }

/* ---------- 手紙 ---------- */
.letter-wrap {
  position: absolute;
  left: 0; right: 0;
  top: calc(54px + env(safe-area-inset-top, 0px));
  bottom: 0;
  padding: 6px 14px calc(16px + var(--safe-b));
  transition: top .6s;
  z-index: 20;
}
#app.reading .letter-wrap { top: calc(14px + env(safe-area-inset-top, 0px)); }
.letter-wrap.enter .letter-card { animation: letterIn 1.1s cubic-bezier(.3, 1, .4, 1) backwards; }
@keyframes letterIn { from { opacity: 0; transform: translateY(18%) scale(.55); } }
.letter-wrap.leave { animation: fadeOut .6s forwards; }
@keyframes fadeOut { to { opacity: 0; transform: translateY(20px); } }
/* 裏返しは3Dを使わず、横につぶして入れ替える（iPhone で3Dの中だとスクロールできなくなるため） */
.letter-card {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .32s cubic-bezier(.5, 0, .75, 0);
}
.letter-card.squash { transform: scaleX(0) rotate(-1.5deg); }
.letter-card.unsquash { transition-timing-function: cubic-bezier(.25, 1, .5, 1); }
.face {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: var(--cream);
  box-shadow: 0 18px 40px rgba(20, 30, 70, .35);
  overflow: hidden;
}
.face.front { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
.face.back { display: none; }
.letter-card.flipped .face.front { display: none; }
.letter-card.flipped .face.back { display: block; }
.paper {
  --lh: 34px;
  position: relative;
  min-height: 100%;
  padding: 40px 22px 30px;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--lh) - 1px), #eadfc6 calc(var(--lh) - 1px), #eadfc6 var(--lh));
  background-position: 0 39px;
  font-family: var(--hand);
  font-size: clamp(14.5px, 4.2vw, 17px);
  line-height: var(--lh);
  color: #4f5d6b;
  -webkit-user-select: text;
  user-select: text;
}
.paper-art { position: absolute; right: 12px; top: 8px; width: 92px; opacity: .9; pointer-events: none; }
.paper-art svg { display: block; width: 100%; }
.line { margin: 0; min-height: var(--lh); opacity: 0; filter: blur(5px); transform: translateY(3px); transition: opacity 1.6s, filter 1.8s, transform 1.6s; }
.line.ink, .sign.ink { opacity: 1; filter: none; transform: none; }
.sign { margin: var(--lh) 0 0; text-align: right; opacity: 0; filter: blur(5px); transition: opacity 1.2s, filter 1.4s; font-weight: 600; }
.letter-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; padding-top: 18px; opacity: 0; transition: opacity .8s; pointer-events: none; }
.letter-actions.show { opacity: 1; pointer-events: auto; }
.pill {
  padding: 10px 18px;
  border: 2px solid #BFE6FF;
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
  color: #5a90c4;
  box-shadow: 0 4px 10px rgba(90, 107, 123, .12);
}
.pill.primary { background: #BFE6FF; border-color: #BFE6FF; color: #3f74a6; }
.back-inner { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.back-photo .polaroid { --w: min(66vw, 300px, calc((100dvh - 300px) * .75)); --r: -2deg; transform: rotate(var(--r)); }
.back-photo .polaroid .ph { aspect-ratio: 4 / 5; }
.back-cap { margin: 0; font-family: var(--hand); font-size: 16px; color: #6b7a88; }

/* ---------- エピローグ ---------- */
.skywrite { position: absolute; left: 0; right: 0; top: 88px; transition: opacity 1s; }
.skywrite.fade { opacity: 0; }
.skywrite svg { display: block; width: 100%; overflow: visible; }
.skywrite text {
  font-family: var(--hand);
  font-weight: 600;
  font-size: 58px;
  fill: rgba(255, 255, 255, 0);
  stroke: #fff;
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
}
.skywrite.draw text { animation: write 3.4s ease-in-out forwards, fillin 1.4s 2.6s forwards; }
.skywrite.draw text + text { animation-delay: .9s, 3.3s; }
@keyframes write { to { stroke-dashoffset: 0; } }
@keyframes fillin { to { fill: #fff; } }
.choices {
  position: absolute;
  left: 16px; right: 16px;
  top: 40%;
  text-align: center;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .8s, transform .8s;
}
.choices.in { opacity: 1; transform: none; }
.choices .q { margin: 0 0 10px; font-size: 17px; font-weight: 700; color: #6a8fb3; }
.choices .opts { display: grid; grid-template-columns: repeat(3, minmax(0, 116px)); justify-content: center; gap: 6px 8px; }
.choices .opts[hidden] { display: none; }
.choices .cloud-btn span { font-size: 15px; }
/* 「その他」の入力欄 */
.other-form { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.other-form input {
  width: min(78vw, 280px);
  padding: 12px 16px;
  border: 2px solid #cfe3f5;
  border-radius: 999px;
  background: rgba(255, 255, 255, .95);
  font: inherit;
  font-size: 16px;   /* 16px 未満だと iPhone が勝手に拡大する */
  color: #4f6f8f;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
  outline: none;
}
.other-form input:focus { border-color: #8fc1ea; }
.other-form .row { display: flex; gap: 10px; }
.other-form.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.cloud-btn { position: relative; padding: 0; border: 0; background: none; }
.cloud-btn svg { display: block; width: 100%; filter: drop-shadow(0 6px 10px rgba(110, 160, 210, .35)); transition: transform .3s; }
.cloud-btn:active svg { transform: scale(.94); }
.cloud-btn span { position: absolute; inset: 0; padding: 12% 0 0 9%; display: grid; place-content: center; font-size: 17px; font-weight: 700; color: #5a90c4; }
/* ---------- エピローグ：新幹線のきっぷ風チケット ---------- */
.ticket-wrap {
  position: absolute;
  left: 50%; top: 54%;
  width: min(88vw, 340px);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 12px 22px rgba(90, 107, 123, .25));
  animation: ticketIn 1s cubic-bezier(.3, 1.4, .5, 1) both;
  z-index: 3;
}
/* 券売機から出てくるように、下からせり上がって少し弾む */
@keyframes ticketIn {
  from { opacity: 0; transform: translate(-50%, -50%) translateY(60px) scale(.8) rotate(-4deg); }
  60% { opacity: 1; }
}
.ticket {
  position: relative;
  padding: 14px 18px 12px;
  border-radius: 12px;
  color: #3f5f7c;
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .5) 0 6px, rgba(255, 255, 255, 0) 6px 12px),
    linear-gradient(135deg, #dff3ea, #e6f1fb 55%, #fbe6ee);
  /* 左右に切り欠き（きっぷっぽさ） */
  -webkit-mask: radial-gradient(circle 9px at left 66%, #0000 98%, #000) left / 51% 100% no-repeat,
                radial-gradient(circle 9px at right 66%, #0000 98%, #000) right / 51% 100% no-repeat;
          mask: radial-gradient(circle 9px at left 66%, #0000 98%, #000) left / 51% 100% no-repeat,
                radial-gradient(circle 9px at right 66%, #0000 98%, #000) right / 51% 100% no-repeat;
}
.tk-head { display: flex; gap: 8px; align-items: baseline; font-size: 11px; font-weight: 700; letter-spacing: .12em; color: #5b8f7a; }
.tk-head .tk-pax { padding: 1px 6px; border: 1.5px solid currentColor; border-radius: 4px; font-size: 10px; letter-spacing: .05em; }
.tk-route { display: flex; align-items: center; justify-content: space-between; margin: 8px 2px 4px; }
.tk-route .st { display: flex; flex-direction: column; align-items: center; min-width: 38%; }
.tk-route .st b { font-size: clamp(24px, 8vw, 30px); letter-spacing: .25em; padding-left: .25em; line-height: 1.2; color: #2f557a; }
.tk-route .st b.long { font-size: clamp(17px, 5.4vw, 21px); letter-spacing: .06em; padding-left: .06em; }
.tk-route .st b.xlong { font-size: clamp(13px, 4vw, 15px); letter-spacing: 0; padding-left: 0; word-break: break-all; text-align: center; }
.tk-route .st small { font-size: 9px; letter-spacing: .3em; color: #8aa6bf; }
.tk-route .arrow { font-size: 18px; color: #ff9db8; }
.tk-train { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; padding: 4px 2px 8px; }
.tk-train .train { color: #5a90c4; }
.tk-foot {
  display: flex; justify-content: space-between; align-items: baseline;
  padding-top: 8px;
  border-top: 2px dashed rgba(90, 144, 196, .35);
  font-size: 12px;
}
.tk-foot .tk-names { font-family: var(--hand); font-size: 13px; color: #6b7a88; }
.tk-foot b { color: #e0708f; font-size: 14px; }
.tk-stamp {
  position: absolute;
  /* 行き先の文字に重ならないよう、右上の角からはみ出させて押す */
  right: -12px; top: -30px;
  width: 74px; height: 74px;
  background: rgba(255, 255, 255, .55);
  display: grid; place-content: center;
  border: 3px solid rgba(232, 84, 112, .85);
  border-radius: 50%;
  color: rgba(232, 84, 112, .9);
  text-align: center;
  font-weight: 700;
  line-height: 1.05;
  transform: rotate(-14deg);
  opacity: 0;
  pointer-events: none;
}
.tk-stamp b { font-size: 22px; letter-spacing: .04em; }
.tk-stamp small { font-size: 9px; letter-spacing: .1em; }
.tk-stamp.on { animation: stampIn .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes stampIn { from { opacity: 0; transform: rotate(-14deg) scale(2.4); } to { opacity: 1; transform: rotate(-14deg) scale(1); } }
.final {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(40px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity .8s;
}
.final.in { opacity: 1; }
/* 最後の画面：シナモンからのひとこと */
.wish {
  position: absolute;
  left: 50%; top: calc(70px + env(safe-area-inset-top, 0px));
  width: min(84%, 320px);
  padding: 16px 18px 14px;
  background: rgba(255, 255, 255, .92);
  border-radius: 26px;
  box-shadow: 0 10px 26px rgba(90, 107, 123, .18), 0 0 0 6px rgba(255, 255, 255, .35);
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) translateY(12px) scale(.9);
  transition: opacity .8s, transform .9s cubic-bezier(.3, 1.4, .5, 1);
}
.wish::after {
  content: "";
  position: absolute;
  left: 22%; top: 100%;
  border: 10px solid transparent;
  border-top-color: rgba(255, 255, 255, .92);
  transform: translateX(-50%);
}
.wish.in { opacity: 1; transform: translateX(-50%); }
.wish p { margin: 0; white-space: pre-line; }
.wish-main { font-family: var(--hand); font-weight: 600; font-size: clamp(19px, 5.6vw, 23px); line-height: 1.6; color: #5a90c4; }
.wish-sub { margin-top: 6px !important; font-size: 12.5px; color: #8a9aab; }
.wish-sub:empty { display: none; }
@media (max-height: 700px) { .wish { top: 60px; padding: 10px 14px 8px; } .wish-main { font-size: 18px; } }

/* 「視差効果を減らす」がオンの端末でも演出は同じに見せる（ふわふわ揺れ続ける飾りの動きだけ止める） */
@media (prefers-reduced-motion: reduce) {
  .cinna-float, .title-cloud, .big-cloud svg, .balloon.sway { animation: none !important; }
}
