/* story.css — 会話オーバーレイ・ひとりごと吹き出し・「おはなし」アイコン・日記パネル（story 担当）。
   共通の変数・部品は style.css（docs/engine_api.md §8）。クラスは .story- 接頭辞。 */

/* ================================================================== 会話オーバーレイ */
.story-root {
  position: absolute; inset: 0; overflow: hidden;
  opacity: 0; transition: opacity .4s ease;
  cursor: pointer;
  --box-bottom: calc(var(--safe-bottom) + 16px);
  --box-h: 172px;
  --box-overlap: 46px;
}
.story-root.show { opacity: 1; }
.story-root.leaving { opacity: 0; pointer-events: none; }
.story-root.is-day { background: #05061a; }

/* 背景 */
.story-stage { position: absolute; inset: 0; pointer-events: none; }
.story-bg {
  position: absolute; inset: -2%;
  background: #0b0d24 center 58% / cover no-repeat;
  image-rendering: pixelated;
  transform-origin: 50% 60%;
  animation: storyKen 46s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes storyKen {
  0% { transform: scale(1.02) translate(-.8%, .4%); }
  100% { transform: scale(1.09) translate(1.2%, -.8%); }
}
.story-band { position: absolute; inset: 0; }
.is-night .story-band {
  background:
    linear-gradient(to top, rgba(6, 8, 28, .94) 0, rgba(6, 8, 28, .78) 30%, rgba(8, 10, 34, .34) 60%, rgba(8, 10, 34, 0) 82%),
    radial-gradient(120% 70% at 50% 110%, rgba(255, 191, 94, .10), transparent 60%);
  animation: storyBandIn .6s ease-out;
}
.is-day .story-band {
  background:
    linear-gradient(to top, rgba(6, 8, 28, .78) 0, rgba(6, 8, 28, .32) 28%, rgba(6, 8, 28, 0) 50%),
    radial-gradient(140% 100% at 50% 40%, transparent 55%, rgba(4, 4, 18, .45) 100%);
}
@keyframes storyBandIn { from { opacity: 0; } to { opacity: 1; } }

/* タイトルカード */
.story-titlecard {
  position: absolute; top: calc(var(--safe-top) + 22px); left: calc(var(--safe-left) + 22px);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 26px 8px 12px;
  background: linear-gradient(90deg, rgba(8, 10, 34, .88) 0, rgba(8, 10, 34, .72) 70%, rgba(8, 10, 34, 0) 100%);
  border-left: 3px solid var(--honey);
  opacity: 0; pointer-events: none;
}
.story-titlecard.show { animation: storyTitle 4.2s ease-in-out forwards; }
@keyframes storyTitle {
  0% { opacity: 0; transform: translateX(-14px); }
  12% { opacity: 1; transform: none; }
  78% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateX(-6px); }
}
.story-tc-moon { line-height: 0; filter: drop-shadow(0 0 6px rgba(255, 217, 138, .6)); }
.story-tc-text { display: flex; flex-direction: column; line-height: 1.25; }
.story-tc-sub { font-family: var(--font-dot); font-size: 12px; color: var(--muted); letter-spacing: .08em; }
.story-tc-title { font-family: var(--font-dot); font-size: 20px; color: var(--cream); text-shadow: 0 0 10px rgba(255, 191, 94, .55), 0 2px 0 #10072a; }

/* 立ち絵 */
.story-cast {
  position: absolute; left: 0; right: 0; top: 0;
  bottom: calc(var(--box-bottom) + var(--box-h) - var(--box-overlap));
  pointer-events: none;
  max-width: 1180px; margin: 0 auto;
}
.story-chara {
  position: absolute; bottom: 0; transform: translateX(-50%);
  transition: left .45s cubic-bezier(.2, .8, .2, 1), filter .3s, opacity .35s;
  filter: drop-shadow(0 0 1px rgba(16, 7, 42, .9));
}
.story-chara.quiet { filter: brightness(.52) saturate(.75) drop-shadow(0 0 1px rgba(16, 7, 42, .9)); }
.story-chara.speaking { filter: drop-shadow(0 0 10px rgba(255, 228, 170, .22)) drop-shadow(0 0 1px rgba(16, 7, 42, .9)); }
.story-chara.gone { opacity: 0; }
.story-chara.enter { animation: storyEnter .4s ease-out; }
@keyframes storyEnter { from { opacity: 0; margin-bottom: -16px; } to { opacity: 1; margin-bottom: 0; } }
.story-face {
  background-repeat: no-repeat;
  image-rendering: pixelated;
}
.story-chara.speaking .story-face { animation: storyBreathe 2.8s steps(1, end) infinite; }
.story-chara.hop .story-face { animation: storyHop .28s ease-out; }
@keyframes storyBreathe { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }
@keyframes storyHop { 0% { transform: translateY(0); } 40% { transform: translateY(-8px); } 100% { transform: translateY(0); } }

/* 会話ウィンドウ */
.story-box {
  position: absolute; left: 50%; bottom: var(--box-bottom);
  width: min(980px, calc(100% - 32px)); height: var(--box-h);
  transform: translateX(-50%);
  padding: 30px 44px 22px;
  /* dialog.webp が無いときの近い見た目 */
  background:
    radial-gradient(1px 1px at 12% 30%, rgba(160, 190, 255, .45), transparent 60%),
    radial-gradient(1px 1px at 63% 72%, rgba(160, 190, 255, .35), transparent 60%),
    radial-gradient(1px 1px at 86% 22%, rgba(160, 190, 255, .4), transparent 60%),
    radial-gradient(90% 120% at 20% 0%, rgba(40, 90, 190, .22), transparent 60%),
    linear-gradient(180deg, rgba(5, 34, 88, .96), rgba(3, 26, 72, .96));
  border: 4px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 0 0 3px #0a0c26, inset 0 0 0 3px #0a0c26, inset 0 0 0 4px rgba(255, 217, 138, .25), 0 12px 30px rgba(0, 0, 0, .55);
  animation: storyBoxIn .45s cubic-bezier(.2, .8, .2, 1);
  --who: var(--lavender);
}
@keyframes storyBoxIn { from { opacity: 0; transform: translate(-50%, 18px); } to { opacity: 1; transform: translate(-50%, 0); } }
/* ui/dialog.webp が読めたとき（9スライス。中の地は CSS で塗る） */
.has-dialog .story-box {
  border: 32px solid transparent;
  border-radius: 0;
  border-image: url(../assets/img/ui/dialog.webp) 16 / 32px / 0 stretch;
  image-rendering: pixelated;
  background-clip: padding-box;
  background-color: rgb(4, 31, 80);
  background-image:
    radial-gradient(1px 1px at 12% 30%, rgba(160, 190, 255, .45), transparent 60%),
    radial-gradient(1px 1px at 63% 72%, rgba(160, 190, 255, .35), transparent 60%),
    radial-gradient(1px 1px at 86% 22%, rgba(160, 190, 255, .4), transparent 60%),
    linear-gradient(160deg, rgba(30, 70, 150, .25), transparent 45%, rgba(30, 70, 150, .18));
  box-shadow: none;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .55));
  padding: 6px 14px 0;
}

/* 名前欄 */
.story-name {
  position: absolute; left: 30px; top: -22px;
  padding: 3px 18px 4px;
  font-family: var(--font-dot); font-size: 19px; line-height: 1.3; letter-spacing: .06em;
  color: var(--who, var(--cream));
  background: linear-gradient(180deg, #16123a, #0a0b26);
  border: 2px solid var(--who, var(--honey));
  border-radius: 4px;
  box-shadow: 0 0 0 2px #07071c, 0 0 12px color-mix(in srgb, var(--who, #ffd98a) 40%, transparent);
  text-shadow: 0 0 8px color-mix(in srgb, var(--who, #ffd98a) 55%, transparent);
  animation: storyNameIn .25s ease-out;
}
.has-dialog .story-name { left: -6px; top: -50px; }
@keyframes storyNameIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* 本文 */
.story-text {
  height: 100%; overflow: hidden;
  font-family: var(--font-body); font-weight: 500;
  font-size: 19px; line-height: 1.78; letter-spacing: .03em;
  color: var(--cream);
  white-space: pre-wrap; word-break: normal; overflow-wrap: anywhere; line-break: strict;
  text-shadow: 0 2px 0 rgba(6, 6, 24, .8);
  cursor: pointer;
}
.story-rest { color: transparent; text-shadow: none; }
.story-box.narration .story-text {
  text-align: center; font-style: oblique 9deg; color: #e3d9ff;
  display: flex; align-items: center; justify-content: center;
}
.story-box.narration .story-text-in { max-width: 100%; }
/* 送りマーク */
.story-next {
  position: absolute; right: 22px; bottom: 12px; width: 0; height: 0;
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid var(--honey);
  filter: drop-shadow(0 0 4px var(--amber));
  opacity: 0;
}
.has-dialog .story-next { right: -2px; bottom: -6px; }
.story-box.done .story-next { opacity: 1; animation: storyNext .9s steps(2, end) infinite; }
@keyframes storyNext { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(3px); } }

/* 操作ボタン（オート・スキップ・ログ） */
.story-ctrls {
  position: absolute; right: 26px; top: -19px;
  display: flex; gap: 6px;
}
.has-dialog .story-ctrls { right: -4px; top: -48px; }
.story-ctrl {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 30px; padding: 2px 10px;
  font-family: var(--font-dot); font-size: 13px; line-height: 1;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(22, 20, 58, .95), rgba(10, 11, 38, .95));
  border: 2px solid rgba(183, 162, 255, .45);
  border-radius: 4px;
  box-shadow: 0 0 0 2px #07071c;
  cursor: pointer;
  transition: color .15s, border-color .15s, filter .15s;
}
.story-ctrl:hover { color: var(--text); border-color: var(--lavender); }
.story-ctrl.on { color: #2a1606; background: linear-gradient(180deg, #ffe7a8, var(--amber)); border-color: #fff3c4; }
.story-ctrl.on .story-ctrl-ic { animation: storyBlink 1s steps(2, end) infinite; }
.story-ctrl.disabled { opacity: .45; }
.story-ctrl-ic { font-size: 12px; }
@keyframes storyBlink { 50% { opacity: .35; } }

/* バックログ */
.story-log {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  background: rgba(4, 5, 18, .72); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  cursor: default; animation: storyBandIn .2s ease-out;
}
.story-log-card { width: min(760px, 100%); max-height: 100%; display: flex; flex-direction: column; padding: 12px 16px 14px; }
.story-log-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 8px; }
.story-log-title { font-family: var(--font-dot); font-size: 18px; color: var(--honey); text-shadow: 0 0 8px rgba(255, 191, 94, .45); }
.story-log-close { background: transparent; border: 0; padding: 4px; cursor: pointer; line-height: 0; border-radius: 6px; }
.story-log-close:hover { background: rgba(255, 255, 255, .08); }
.story-log-list { overflow-y: auto; min-height: 0; flex: 1 1 auto; padding-right: 6px; user-select: text; }
.story-log-row { padding: 8px 4px 10px; border-bottom: 1px dashed rgba(183, 162, 255, .2); }
.story-log-row:last-child { border-bottom: 0; }
.story-log-name { font-family: var(--font-dot); font-size: 13px; margin-bottom: 2px; }
.story-log-text { white-space: pre-wrap; color: var(--cream); line-height: 1.7; }
.story-log-row.narr .story-log-text { color: #d8ccff; font-style: oblique 9deg; text-align: center; }

/* ================================================================== 夜空の上（吹き出し・おはなし） */
.layer > .story-world { position: absolute; inset: 0; pointer-events: none; }
.story-world > * { position: absolute; left: 0; top: 0; }

/* ひとりごと吹き出し */
.story-bubble {
  max-width: min(270px, calc(100vw - 24px));
  padding: 6px 12px 7px;
  background: #fff6e2;
  color: #2b2350;
  border: 2px solid #2b2350;
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(255, 246, 226, .35), 0 6px 14px rgba(0, 0, 0, .45);
  font-size: 14px; line-height: 1.55; font-weight: 500;
  pointer-events: none;
  opacity: 0; scale: .85; translate: 0 6px;
  transition: opacity .25s ease, scale .25s cubic-bezier(.3, 1.6, .5, 1), translate .25s ease;
  transform-origin: var(--tail, 50%) 100%;
  will-change: transform;
}
.story-bubble.show { opacity: 1; scale: 1; translate: 0 0; }
.story-bubble.hide { opacity: 0; translate: 0 -4px; transition-duration: .35s; }
.story-bubble::after, .story-bubble::before {
  content: ''; position: absolute; left: var(--tail, 50%); width: 0; height: 0; transform: translateX(-50%);
}
.story-bubble::before { bottom: -11px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 10px solid #2b2350; }
.story-bubble::after { bottom: -7px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid #fff6e2; }
.story-bubble-name {
  display: inline-block; margin-right: 6px; padding: 0 6px; vertical-align: 1px;
  font-family: var(--font-dot); font-size: 11px; line-height: 16px;
  color: #fff !important; background: #2b2350; border-radius: 3px;
}
.story-bubble[data-who="cat"] .story-bubble-name { background: #3b2e4f; }
.story-bubble-text { display: inline; white-space: pre-line; }
.story-bubble.kind-welcome { background: #fff1c9; border-color: #6b3d10; color: #3d2408; }
.story-bubble.kind-welcome::before { border-top-color: #6b3d10; }
.story-bubble.kind-welcome::after { border-top-color: #fff1c9; }
.story-bubble.kind-welcome .story-bubble-name { background: #6b3d10; }

/* 「おはなし」アイコン（主人公の頭上） */
.story-world > .story-talk {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px 3px 5px;
  font-family: var(--font-dot); font-size: 13px; line-height: 1; color: #2a1606;
  background: linear-gradient(180deg, #fff1c4, var(--honey) 60%, #f3b45a);
  border: 2px solid #3a1d06;
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(255, 241, 196, .45), 0 0 16px rgba(255, 191, 94, .65), 0 4px 10px rgba(0, 0, 0, .4);
  cursor: pointer;
  animation: storyBob 2.4s ease-in-out infinite;
}
.story-world > .story-talk::after, .story-world > .story-talk::before {
  content: ''; position: absolute; left: var(--tail, 50%); width: 0; height: 0; transform: translateX(-50%);
}
.story-world > .story-talk::before { bottom: -10px; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 9px solid #3a1d06; }
.story-world > .story-talk::after { bottom: -6px; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid #f3b45a; }
.story-world > .story-talk:hover { filter: brightness(1.08); }
.story-world > .story-talk:active { filter: brightness(.95); }
.story-world > .story-talk.pop { animation: storyPop .6s cubic-bezier(.3, 1.6, .5, 1), storyBob 2.4s ease-in-out .6s infinite; }
.story-talk-icon img { width: 24px; height: 24px; display: block; }
.story-talk-label { padding-top: 1px; }
.story-talk-count {
  position: absolute; top: -9px; right: -9px; min-width: 18px; height: 18px; padding: 0 4px;
  font-size: 11px; line-height: 16px; text-align: center; color: var(--cream);
  background: #c2456b; border: 1px solid #fff3dc; border-radius: 9px;
}
.story-talk-count:empty { display: none; }
@keyframes storyBob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
@keyframes storyPop { 0% { scale: .2; opacity: 0; } 60% { scale: 1.15; opacity: 1; } 100% { scale: 1; } }

/* ================================================================== 日記パネル */
.story-diary { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; user-select: none; }

.story-pend-card {
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, rgba(255, 217, 138, .16), rgba(255, 191, 94, .06));
  border: 2px solid rgba(255, 217, 138, .55);
  border-radius: 8px;
  box-shadow: 0 0 14px rgba(255, 191, 94, .18);
}
.story-pend-head { font-family: var(--font-dot); color: var(--honey); font-size: 15px; margin-bottom: 6px; text-shadow: 0 0 8px rgba(255, 191, 94, .5); }
.story-pend-list { display: flex; flex-direction: column; gap: 6px; }
.story-pend {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; text-align: left;
  background: rgba(11, 13, 36, .55); border: 1px solid rgba(255, 217, 138, .35); border-radius: 6px;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.story-pend:hover { background: rgba(255, 217, 138, .12); border-color: var(--honey); }
.story-pend-dot { width: 8px; height: 8px; flex: none; background: var(--amber); box-shadow: 0 0 6px var(--amber); transform: rotate(45deg); }
.story-pend-title { flex: 1 1 auto; min-width: 0; color: var(--cream); }
.story-pend-go { font-family: var(--font-dot); font-size: 13px; color: var(--honey); white-space: nowrap; }

/* 手帳 */
.story-book { display: flex; flex-direction: column; gap: 14px; }
.story-book-cover {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #5a3a6e, #3e2550);
  border: 2px solid #c9a35f; border-radius: 6px 10px 10px 6px;
  box-shadow: inset 6px 0 0 #2b1838, inset 8px 0 0 rgba(255, 217, 138, .25), 0 4px 10px rgba(0, 0, 0, .35);
}
.story-book-title { font-family: var(--font-dot); font-size: 18px; color: #ffe7b0; letter-spacing: .08em; text-shadow: 0 0 6px rgba(255, 191, 94, .5); }
.story-book-owner { font-family: var(--font-dot); font-size: 12px; color: #e8cfa0; }
.story-chapter-sep {
  display: flex; align-items: center; gap: 8px; margin: 2px 2px -4px;
  font-family: var(--font-dot); font-size: 13px; color: var(--lavender);
}
.story-chapter-sep::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(183, 162, 255, .5), transparent); }
.story-page {
  position: relative;
  padding: 16px 16px 10px 30px;
  color: #4a3a5c;
  background-color: #fbf2dd;
  background-image:
    linear-gradient(90deg, transparent 21px, rgba(220, 120, 130, .45) 21px, rgba(220, 120, 130, .45) 22px, transparent 22px),
    repeating-linear-gradient(180deg, transparent 0, transparent 27px, rgba(120, 140, 200, .22) 27px, rgba(120, 140, 200, .22) 28px);
  background-position: 0 0, 0 12px;
  border-radius: 3px 8px 8px 3px;
  box-shadow: 0 1px 0 #e5d6b4, 0 3px 0 #d9c7a0, 0 6px 14px rgba(0, 0, 0, .35);
  user-select: text;
}
.story-page:nth-child(even) { rotate: .25deg; }
.story-page:nth-child(odd) { rotate: -.2deg; }
.story-page-tape {
  position: absolute; top: -7px; left: 50%; width: 64px; height: 16px; margin-left: -32px;
  background: rgba(183, 162, 255, .55); rotate: -3deg;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
}
.story-page:nth-child(3n) .story-page-tape { background: rgba(255, 191, 94, .55); rotate: 2deg; }
.story-page:nth-child(3n+1) .story-page-tape { background: rgba(130, 205, 190, .55); rotate: -1deg; }
.story-page-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.story-page-day { font-family: var(--font-dot); font-size: 13px; color: #8a5a3a; white-space: nowrap; }
.story-page-title { font-family: var(--font-dot); font-size: 15px; color: #3e2f55; flex: 1 1 auto; min-width: 0; }
.story-page-new {
  font-family: var(--font-dot); font-size: 10px; line-height: 16px; padding: 0 6px;
  color: #fff; background: #d0587a; border-radius: 3px; rotate: 6deg;
}
.story-page-text { margin: 0; font-size: 14px; line-height: 28px; white-space: pre-line; font-weight: 500; }
.story-page.empty .story-page-text { color: #8b7d96; text-align: center; padding: 10px 0; }
.story-page-foot { display: flex; justify-content: flex-end; margin-top: 4px; }
.story-replay {
  padding: 3px 10px; font-family: var(--font-dot); font-size: 12px;
  color: #5b3f78; background: transparent; border: 1px dashed rgba(91, 63, 120, .55); border-radius: 12px;
  cursor: pointer; transition: background .15s, color .15s;
}
.story-replay:hover { background: rgba(183, 162, 255, .22); color: #3e2f55; }
.story-page.new { box-shadow: 0 1px 0 #e5d6b4, 0 3px 0 #d9c7a0, 0 0 0 2px rgba(255, 191, 94, .55), 0 6px 16px rgba(255, 191, 94, .25); }

/* ================================================================== スマホ縦 */
@media (max-width: 600px), (orientation: portrait) and (max-width: 820px) {
  .story-root { --box-bottom: calc(var(--safe-bottom) + 10px); --box-h: 170px; --box-overlap: 40px; }
  .story-box { width: calc(100% - 16px); padding: 26px 20px 18px; }
  .has-dialog .story-box { border-width: 24px; border-image-width: 24px; padding: 6px 4px 0; }
  .story-text { font-size: 16px; line-height: 1.72; }
  .story-name { font-size: 16px; left: 14px; padding: 2px 12px 3px; }
  .has-dialog .story-name { left: -8px; top: -42px; }
  .story-ctrls { right: 10px; gap: 4px; }
  .has-dialog .story-ctrls { right: -8px; top: -41px; }
  .story-ctrl { min-height: 28px; padding: 2px 7px; font-size: 12px; }
  .story-titlecard { top: calc(var(--safe-top) + 14px); left: calc(var(--safe-left) + 10px); padding-right: 18px; }
  .story-tc-title { font-size: 17px; }
  .story-bg { background-position: 50% 50%; }
  .story-bubble { font-size: 13px; max-width: min(240px, calc(100vw - 20px)); }
}

/* ナレーション中は全員を少しだけ落とす */
.story-root .story-chara.quiet.narr { filter: brightness(.78) saturate(.9) drop-shadow(0 0 1px rgba(16, 7, 42, .9)); }
/* 吹き出しが押し上げられたときはしっぽを消す */
.story-bubble.stacked::before, .story-bubble.stacked::after { display: none; }

/* ================================================================== 時間帯の色調（昼の背景しかない場所での夜・夕方） */
.story-tone { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s ease; }
.story-tone > div { position: absolute; inset: 0; }
.story-root[data-time="night"].is-day .story-tone,
.story-root[data-time="dusk"].is-day .story-tone { opacity: 1; }
/* 夜：絵そのものを暗く青く → 藍のオーバーレイ → 窓明かりのような暖色のビネット */
.story-root[data-time="night"].is-day .story-bg { filter: brightness(.6) saturate(.72) contrast(1.06) hue-rotate(-6deg); }
.story-root[data-time="night"] .story-tone {
  background:
    linear-gradient(180deg, rgba(10, 14, 58, .62) 0%, rgba(14, 18, 66, .42) 45%, rgba(8, 8, 32, .58) 100%);
  mix-blend-mode: multiply;
}
.story-root[data-time="night"] .story-tone-glow {
  mix-blend-mode: screen;
  background:
    radial-gradient(50% 42% at 16% 70%, rgba(255, 170, 80, .38), transparent 70%),
    radial-gradient(44% 38% at 85% 62%, rgba(255, 192, 104, .32), transparent 70%),
    radial-gradient(70% 30% at 50% 100%, rgba(255, 150, 70, .22), transparent 75%),
    radial-gradient(90% 50% at 50% -10%, rgba(90, 110, 230, .22), transparent 70%);
  animation: storyCandle 5.5s ease-in-out infinite alternate;
}
.story-root[data-time="night"] .story-tone-dust {
  background: radial-gradient(130% 110% at 50% 45%, transparent 48%, rgba(4, 4, 22, .62) 100%);
}
@keyframes storyCandle { 0% { opacity: .82; } 40% { opacity: 1; } 70% { opacity: .9; } 100% { opacity: 1; } }
/* もともと夜の絵（屋根裏・星祭り）は軽く。夕暮れの丘は夜の色をしっかり */
.story-root[data-time="night"][data-bg="attic"].is-day .story-bg,
.story-root[data-time="night"][data-bg="festival"].is-day .story-bg { filter: brightness(.86) saturate(.92); }
.story-root[data-time="night"][data-bg="attic"] .story-tone,
.story-root[data-time="night"][data-bg="festival"] .story-tone { background: linear-gradient(180deg, rgba(20, 22, 70, .28), rgba(10, 10, 40, .3)); }
.story-root[data-time="night"][data-bg="hill"].is-day .story-bg { filter: brightness(.55) saturate(.6) hue-rotate(-14deg); }
/* 夕暮れ：茜と藤色 */
.story-root[data-time="dusk"].is-day .story-bg { filter: brightness(.82) saturate(.88) contrast(1.04); }
.story-root[data-time="dusk"] .story-tone {
  background: linear-gradient(180deg, rgba(150, 110, 220, .9) 0%, rgba(255, 170, 130, .9) 50%, rgba(120, 80, 150, .95) 100%);
  mix-blend-mode: multiply;
}
.story-root[data-time="dusk"] .story-tone-glow {
  background:
    radial-gradient(90% 55% at 70% 28%, rgba(255, 150, 90, .32), transparent 70%),
    radial-gradient(60% 40% at 20% 75%, rgba(255, 190, 110, .2), transparent 70%);
  mix-blend-mode: screen;
}
.story-root[data-time="dusk"] .story-tone-dust { background: radial-gradient(130% 110% at 50% 45%, transparent 55%, rgba(30, 10, 40, .45) 100%); }
.story-root[data-time="dusk"][data-bg="hill"] .story-tone,
.story-root[data-time="dusk"][data-bg="attic"] .story-tone { opacity: .35; }
.story-root[data-time="dusk"][data-bg="hill"].is-day .story-bg,
.story-root[data-time="dusk"][data-bg="attic"].is-day .story-bg { filter: none; }

/* ================================================================== イベントCG（全画面の1枚絵。フェードイン → ゆっくりパン） */
.story-cg {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  background: #05061a;
  opacity: 0; visibility: hidden;
  transition: opacity 1.2s ease, visibility 0s linear 1.2s;
}
.story-cg.show { opacity: 1; visibility: visible; transition: opacity 1.2s ease, visibility 0s; }
.story-cg.gone { transition-duration: .7s, 0s; transition-delay: 0s, .7s; }
.story-cg-img {
  position: absolute; inset: -3%;
  background: center 40% / cover no-repeat;
  image-rendering: pixelated;
  transform-origin: 50% 45%;
  will-change: transform;
}
.story-cg.show .story-cg-img { animation: storyCgIn 1.6s cubic-bezier(.2, .7, .2, 1) both, storyCgKen 38s ease-in-out 1.6s infinite alternate; }
@keyframes storyCgIn { from { transform: scale(1.08); filter: brightness(1.8) saturate(.6) blur(3px); } to { transform: scale(1.03); filter: none; } }
@keyframes storyCgKen {
  0% { transform: scale(1.03) translate(0, 0); }
  100% { transform: scale(1.1) translate(-1.6%, -1.2%); }
}
/* 下の会話窓が読めるように、足もとだけ少し暗く */
.story-cg-shade { position: absolute; inset: 0; background: linear-gradient(to top, rgba(5, 6, 26, .72) 0, rgba(5, 6, 26, .28) 22%, transparent 40%); }
.story-root.has-cg .story-cast { opacity: 0; transition: opacity .5s ease; }
.story-root.has-cg .story-titlecard { opacity: 0 !important; animation: none; }
.reduce-motion .story-cg.show .story-cg-img { animation: none; transform: none; }

/* 後ろのぼかし（スマホ縦で、絵の上下の余白を埋める） */
.story-cg-back { position: absolute; inset: -6%; background: center / cover no-repeat; filter: blur(14px) brightness(.42) saturate(1.1); display: none; }
/* スマホ縦：16:9 の絵を画面幅の 1.6 倍にして会話窓の上の中央に置き、横にゆっくりパンして全体を見せる */
@media (max-width: 600px), (orientation: portrait) and (max-width: 820px) {
  .story-cg-back { display: block; }
  .story-cg-img {
    inset: auto; left: 0;
    width: 160vw; height: auto; aspect-ratio: 16 / 9;
    top: calc((100% - var(--box-bottom) - var(--box-h) + 20px - 90vw) / 2);
    background-position: center; background-size: cover;
    box-shadow: 0 0 0 2px rgba(255, 217, 138, .35), 0 10px 30px rgba(0, 0, 0, .6);
  }
  .story-name-sub { display: none; }
  .story-cg.show .story-cg-img { animation: storyCgInM 1.4s ease-out both, storyCgPan 26s ease-in-out 1.4s infinite alternate; }
  .story-cg-shade { background: linear-gradient(to top, rgba(5, 6, 26, .95) 0, rgba(5, 6, 26, .9) calc(var(--box-bottom) + var(--box-h) - 40px), transparent calc(var(--box-bottom) + var(--box-h) + 30px)); }
}
@keyframes storyCgInM {
  from { opacity: 0; transform: translateX(calc(-50% + 50vw)) scale(1.06); filter: brightness(1.8) blur(3px); }
  to { opacity: 1; transform: translateX(calc(-50% + 50vw)); filter: none; }
}
@keyframes storyCgPan {
  0% { transform: translateX(calc(-50% + 50vw)); }
  50% { transform: translateX(0); }
  100% { transform: translateX(calc(-100% + 100vw)); }
}

/* ================================================================== 町の人（立ち絵なし。名前欄は落ち着いた色） */
.story-name { display: inline-flex; align-items: baseline; gap: 8px; }
.story-name-sub { font-family: var(--font-body); font-size: 11px; letter-spacing: .04em; opacity: .75; }
.story-name.town {
  color: color-mix(in srgb, var(--who, #e9dfc8) 45%, #e8e1d4);
  background: linear-gradient(180deg, #2a2536, #1a1724);
  border-color: color-mix(in srgb, var(--who, #e9dfc8) 35%, #8a8296);
  box-shadow: 0 0 0 2px #07071c;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55);
}
.story-name.town .story-name-sub { color: #b8b0c4; opacity: 1; }
.story-log-name.town { filter: saturate(.55) brightness(.95); }

/* 重なり順（背景 < 立ち絵 < CG < 窓 < タイトル < ログ） */
.story-stage { z-index: 0; }
.story-cast { z-index: 1; }
.story-cg { z-index: 2; }
.story-box { z-index: 3; }
.story-titlecard { z-index: 4; }
.story-log { z-index: 10; }

/* ================================================================== 修正（QA） */
/* 操作ボタン（オート・スキップ・ログ）は会話ウィンドウの枠の外に。枠の上の端をタップしても オートが切りかわらないように */
.has-dialog .story-ctrls { top: -68px; }
@media (max-width: 600px), (orientation: portrait) and (max-width: 820px) {
  .has-dialog .story-ctrls { top: -58px; }
}
.story-ctrl.on { color: var(--honey); border-color: var(--honey); }

/* 大きな画面（1920×1080 など）：会話ウィンドウと文字も大きく */
@media (min-width: 1700px) and (min-height: 950px) {
  .story-root { --box-bottom: calc(var(--safe-bottom) + 24px); --box-h: 228px; --box-overlap: 60px; }
  .story-box { width: min(1260px, 66vw); padding: 38px 56px 28px; }
  .has-dialog .story-box { padding: 8px 18px 0; }
  .story-text { font-size: 25px; }
  .story-name { font-size: 24px; }
  .story-ctrl { min-height: 36px; font-size: 16px; padding: 2px 12px; }
  .has-dialog .story-ctrls { top: -74px; }
}
