:root {
  --u: calc(min(100vw, 800px) / 800);
  --page: #ffffff;
  --ink: #26262a;
  --side: #ececee;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --side: #1b1b1e; }
}
:root[data-theme="dark"] { --side: #1b1b1e; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--side); }
body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
#ep {
  position: relative;
  width: min(100vw, 800px);
  margin: 0 auto;
  background: var(--page);
  overflow: hidden;
}
#ep > * { position: absolute; }
.band { z-index: 0; }
.panel, .space { z-index: 1; }
.panel { overflow: hidden; }
.panel > img:first-child { display: block; width: 100%; height: 100%; object-fit: cover; }
.panel.framed { box-shadow: 0 0 0 calc(var(--u) * 2.5) #1d1d20; }
.panel.fade-top { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22%); mask-image: linear-gradient(to bottom, transparent 0, #000 22%); }
.panel .missing { display: grid; place-items: center; height: 100%; background: #eee; color: #999; }
.balloon, .title { z-index: 3; display: block; height: auto; pointer-events: none; }
.hint { z-index: 2; text-align: center; font-size: calc(var(--u) * 22); color: #9a9aa0; letter-spacing: .1em; }

/* 吹き出し：見えたら出る */
[data-fx="pop"], [data-fx="pop-slow"] { opacity: 0; transform: scale(.82); transform-origin: 50% 70%; transition: opacity .28s ease-out, transform .38s cubic-bezier(.2, 1.4, .4, 1); }
[data-fx="pop-slow"] { transition: opacity .9s ease-out .7s, transform 1.1s cubic-bezier(.2, 1.2, .4, 1) .7s; }
[data-fx="fade"] { opacity: 0; transform: translateY(calc(var(--u) * 14)); transition: opacity .9s ease, transform .9s ease; }
.on[data-fx="pop"], .on[data-fx="pop-slow"], .on[data-fx="fade"] { opacity: 1; transform: none; }

/* 手書きメモ：1行ずつ書かれる */
.memo { position: absolute; display: block; clip-path: inset(0 100% 0 0); transition: clip-path .9s steps(14, end); }
.memo.static { clip-path: none; transition: none; }
.on .memo { clip-path: inset(0 0 0 0); }

/* ペットカメラ */
.cam { position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.05) 0 1px, transparent 1px 3px);
  animation: camflick 2.4s infinite steps(1); }
.cam .rec { position: absolute; left: 5%; top: 5%; color: #ff5a4f; font: 700 calc(var(--u) * 22) ui-monospace, Menlo, monospace; letter-spacing: .08em; animation: blink 1.2s infinite steps(1); }
.cam .time { position: absolute; right: 5%; top: 5%; color: #e8ecf2; font: 600 calc(var(--u) * 22) ui-monospace, Menlo, monospace; opacity: .85; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes camflick { 0% { opacity: .9; } 37% { opacity: 1; } 38% { opacity: .75; } 39% { opacity: 1; } }

/* 雨 */
canvas.rain { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* 蛍光灯のちらつき（1回だけ） */
.on[data-fx="flicker"] > img:first-child { animation: flicker 1.3s ease-out 1; }
@keyframes flicker { 0%, 100% { filter: none; } 8% { filter: brightness(.55); } 12% { filter: none; } 18% { filter: brightness(.7); } 22% { filter: none; } }

/* 暗闇の目：ゆっくり光ってまばたき */
[data-fx="eyes"] > img:first-child { opacity: 0; transition: opacity 1.6s ease .3s; }
.on[data-fx="eyes"] > img:first-child { opacity: 1; animation: eyes 5s ease-in-out 1.9s infinite; }
@keyframes eyes { 0%, 100% { filter: brightness(1); transform: scaleY(1); } 40% { filter: brightness(1.5); } 46% { transform: scaleY(1); } 48% { transform: scaleY(.15); } 50% { transform: scaleY(1); } }

/* 決めのコマ：スクロールに合わせてゆっくり寄る */
[data-fx="zoom"] > img:first-child { transform: scale(var(--z, 1)); transform-origin: 50% 70%; will-change: transform; }

.end { z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--u) * 36); }
.end .next { margin: 0; font-size: calc(var(--u) * 30); letter-spacing: .14em; color: #55555c; }
.end .share { display: inline-block; padding: calc(var(--u) * 18) calc(var(--u) * 44); border-radius: 999px; background: #111; color: #fff; text-decoration: none; font-weight: 700; font-size: calc(var(--u) * 26); }

/* 音のスタート */
#sound-gate { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  width: min(calc(100vw - 32px), 460px); padding: 16px 16px 14px; border-radius: 18px; background: rgba(20, 20, 24, .92); color: #fff; text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); transition: opacity .4s, transform .4s; }
#sound-gate p { margin: 0 0 12px; font-size: 14px; opacity: .85; }
#sound-gate .row { display: flex; gap: 10px; }
#sound-gate button { flex: 1; min-height: 48px; border: 0; border-radius: 12px; font-size: 16px; font-weight: 700; background: #fff; color: #111; cursor: pointer; }
#sound-gate button.ghost { flex: .6; background: transparent; color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }
#sound-gate.hide { opacity: 0; transform: translate(-50%, 20px); pointer-events: none; }
#snd-toggle { position: fixed; right: 12px; top: max(12px, env(safe-area-inset-top)); z-index: 20; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(20, 20, 24, .55); color: #fff; font-size: 18px; cursor: pointer; }
@media (prefers-reduced-motion: reduce) {
  [data-fx] , [data-fx] > img:first-child, .memo { transition: none !important; animation: none !important; }
}

/* 黒い背景の絵は、黒を透かして暗い帯になじませる */
.panel[data-fx="eyes"] { mix-blend-mode: screen; background: transparent; }
