/* ============================================================
   リファーラルの館 — スタイル
   ============================================================ */
:root {
  --bg: #07050a;
  --ink: #efe6d6;
  --muted: #a99db4;
  --gold: #c9a85c;
  --gold-hi: #f0d48e;
  --blood: #8e1f33;
  --panel: rgba(20, 13, 26, 0.94);
  --panel-line: rgba(201, 168, 92, 0.45);
  --flame: #ffcf5a;
  --font-display: 'Kaisei Decol', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --font-body: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

#app { position: fixed; inset: 0; overflow: hidden; }

.screen {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.8s ease, visibility 0s linear 0.8s;
}
.screen.active {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.8s ease;
}

#fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  z-index: 50;
}
#fade.on { opacity: 1; pointer-events: auto; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #2b1d10;
  border: 1px solid var(--gold);
  color: var(--gold-hi);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 26px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 3px; }
.btn-primary {
  color: #2a1606;
  background: linear-gradient(180deg, #f6dc98, #c99a45);
  border-color: #fbe7b5;
  box-shadow: 0 0 0 1px #5a3a12 inset, 0 6px 24px rgba(255, 190, 90, 0.25);
}
.btn-primary:hover { box-shadow: 0 0 0 1px #5a3a12 inset, 0 6px 30px rgba(255, 190, 90, 0.45); }
.btn-ghost {
  color: var(--gold-hi);
  background: rgba(40, 26, 14, 0.6);
  border-color: var(--panel-line);
}
.btn-text {
  min-height: 44px;
  color: var(--muted);
  background: none;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ---------- 月・霧・コウモリ ---------- */
.moon {
  position: absolute;
  top: 9%;
  right: 12%;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fff8e0, #e9dcb4 60%, #cbbd92);
  box-shadow: 0 0 40px 10px rgba(240, 225, 180, 0.25), 0 0 120px 40px rgba(160, 140, 200, 0.12);
}
.moon::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 60% 60%, rgba(0, 0, 0, 0.12) 0 8px, transparent 9px),
    radial-gradient(circle at 30% 64%, rgba(0, 0, 0, 0.08) 0 5px, transparent 6px);
}

.fog {
  position: absolute;
  left: -50%;
  width: 200%;
  pointer-events: none;
  background:
    radial-gradient(ellipse 20% 50% at 10% 60%, rgba(190, 180, 215, 0.22), transparent 70%),
    radial-gradient(ellipse 25% 45% at 35% 50%, rgba(190, 180, 215, 0.18), transparent 70%),
    radial-gradient(ellipse 18% 55% at 60% 65%, rgba(190, 180, 215, 0.2), transparent 70%),
    radial-gradient(ellipse 22% 50% at 85% 55%, rgba(190, 180, 215, 0.18), transparent 70%);
  animation: fog-drift 38s linear infinite;
}
.fog-a { bottom: -8%; height: 45%; }
.fog-b { bottom: 8%; height: 40%; opacity: 0.7; animation-duration: 55s; animation-direction: reverse; }
.fog-c { bottom: 30%; height: 45%; opacity: 0.5; animation-duration: 70s; }
@keyframes fog-drift {
  from { transform: translateX(0); }
  to { transform: translateX(25%); }
}

.bats i {
  position: absolute;
  width: 26px;
  height: 12px;
  background: #0b0710;
  clip-path: polygon(0 20%, 20% 0, 35% 35%, 50% 20%, 65% 35%, 80% 0, 100% 20%, 80% 60%, 60% 50%, 50% 100%, 40% 50%, 20% 60%);
  animation: bat-fly 11s linear infinite, bat-flap 0.35s ease-in-out infinite alternate;
}
.bats i:nth-child(1) { top: 18%; animation-delay: 0s, 0s; }
.bats i:nth-child(2) { top: 26%; animation-delay: 3.6s, 0.1s; transform: scale(0.7); }
.bats i:nth-child(3) { top: 12%; animation-delay: 7s, 0.2s; transform: scale(0.55); }
@keyframes bat-fly {
  from { left: -10%; translate: 0 0; }
  50% { translate: 0 -30px; }
  to { left: 110%; translate: 0 10px; }
}
@keyframes bat-flap {
  from { scale: 1 1; }
  to { scale: 0.8 0.5; }
}

/* ---------- 1. タイトル ---------- */
#scene-title {
  background: radial-gradient(ellipse at 50% 20%, #241a38 0%, #110b1a 45%, var(--bg) 80%);
}
.title-body {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 18vh;
  text-align: center;
  z-index: 2;
}
.title-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.12em;
}
.title-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 44px;
  font-family: var(--font-display);
  font-size: clamp(30px, 8.6vw, 54px);
  line-height: 1.2;
  letter-spacing: 0.08em;
  color: #f3e3c0;
  text-shadow: 0 0 18px rgba(255, 190, 110, 0.45), 0 0 2px #fff3d6, 0 4px 0 #3a1f10;
  animation: title-flicker 7s infinite;
}
.logo-pre { white-space: nowrap; }
.logo-last { font-size: 2.6em; line-height: 1.1; margin-top: 0.05em; }
@keyframes title-flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.55; }
  94% { opacity: 1; }
  96% { opacity: 0.7; }
}

/* ---------- 1'. 入力画面 ---------- */
#scene-form {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 0%, #20172e 0%, var(--bg) 70%);
}
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 4px rgba(0, 0, 0, 0.3), inset 0 0 0 5px rgba(201, 168, 92, 0.15);
}
.form-panel {
  width: min(460px, 100%);
  margin: auto;
  padding: 26px 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.form-heading {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  text-align: center;
  color: var(--gold-hi);
}
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field-label { font-size: 14px; color: var(--muted); letter-spacing: 0.06em; padding: 0; }
.field-hint { font-size: 12px; color: #7f7488; }
.field input[type='text'] {
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  font-size: 17px; /* iOSでズームされない16px以上 */
  background: #120c18;
  border: 1px solid #4a3a5a;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input[type='text']:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201, 168, 92, 0.2); }
.field input::placeholder { color: #5f566a; }

.size-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 520px) { .size-options { grid-template-columns: repeat(4, 1fr); } }
.size-opt {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px 10px;
  border: 1px solid #4a3a5a;
  border-radius: 10px;
  background: #120c18;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}
.size-opt input { position: absolute; opacity: 0; pointer-events: none; }
.size-opt:has(input:checked) { border-color: var(--gold); background: #2a1c12; box-shadow: 0 0 0 3px rgba(201, 168, 92, 0.18); }
.size-opt:has(input:focus-visible) { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.size-icon { display: flex; align-items: flex-end; gap: 2px; height: 26px; }
.size-icon i {
  display: block;
  width: 12px;
  height: 18px;
  background: #6d5a80;
  clip-path: polygon(50% 0, 100% 35%, 100% 100%, 0 100%, 0 35%);
}
.size-icon i:nth-child(2) { height: 24px; }
.size-opt:has(input:checked) .size-icon i { background: var(--gold); }
.size-label { font-size: 15px; font-weight: 700; }
.size-mansion { font-size: 11px; color: var(--muted); }

.form-error { margin: -6px 0 0; min-height: 1.2em; color: #ff8f8f; font-size: 14px; text-align: center; }
.privacy-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: -4px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(120, 110, 150, 0.1);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.privacy-note svg { flex: none; width: 16px; height: 16px; margin-top: 3px; color: var(--gold); }

/* ---------- 2. 館の外観 ---------- */
#scene-exterior { background: var(--bg); }
.ext-sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #120c22 0%, #221839 45%, #2c2240 62%, #0b0810 78%);
}
.stars {
  position: absolute;
  inset: 0 0 40% 0;
  background-image:
    radial-gradient(1px 1px at 12% 20%, #fff, transparent),
    radial-gradient(1px 1px at 28% 8%, #ddd, transparent),
    radial-gradient(1.5px 1.5px at 44% 26%, #fff, transparent),
    radial-gradient(1px 1px at 63% 12%, #ccc, transparent),
    radial-gradient(1px 1px at 82% 30%, #fff, transparent),
    radial-gradient(1px 1px at 92% 6%, #eee, transparent),
    radial-gradient(1.5px 1.5px at 6% 40%, #ddd, transparent),
    radial-gradient(1px 1px at 54% 44%, #fff, transparent);
  opacity: 0.7;
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { to { opacity: 0.35; } }

.ext-stage {
  position: absolute;
  left: 50%;
  bottom: calc(26% + var(--safe-b));
  width: min(94vw, 560px);
  transform: translateX(-50%);
}
.mansion {
  display: flex;
  justify-content: center;
  opacity: 0;
  filter: blur(8px) brightness(0.5);
  transform: translateY(14px) scale(0.95);
  transform-origin: 50% 90%;
  transition: opacity 3s ease, filter 3s ease, transform 3s ease;
}
.mansion-sprite { width: 100%; }
.mansion.size-s .mansion-sprite { width: 70%; }
.mansion.size-m .mansion-sprite { width: 86%; }
.mansion-sprite svg, .mansion-sprite img { display: block; width: 100%; height: auto; }
#scene-exterior.revealed .mansion { opacity: 1; filter: none; transform: none; }
#scene-exterior.entering .mansion {
  transform: scale(7);
  opacity: 0;
  transition: transform 1.1s cubic-bezier(0.6, 0, 0.9, 0.4), opacity 0.6s ease 0.5s;
}

.win { fill: #2c2338; }
.win.lit { fill: #ffc86b; animation: win-flicker 5s infinite; }
@keyframes win-flicker {
  0%, 100% { opacity: 1; }
  45% { opacity: 0.8; }
  50% { opacity: 0.35; }
  55% { opacity: 0.9; }
}
.m-door-light { opacity: 0.05; transition: opacity 0.8s; }
.m-door-leaf { transform-box: fill-box; transform-origin: 0 50%; transition: transform 0.9s cubic-bezier(0.3, 0.1, 0.2, 1); }
.m-door-leaf.r { transform-origin: 100% 50%; }
#scene-exterior.opening .m-door-leaf { transform: scaleX(0.12); }
#scene-exterior.opening .m-door-light { opacity: 1; }

.fog-cover {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 70%, rgba(120, 112, 145, 0.95), rgba(40, 34, 55, 0.98));
  transition: opacity 3.5s ease;
}
#scene-exterior.revealed .fog-cover { opacity: 0.12; }

.ext-ui {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  width: min(520px, calc(100% - 32px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.ext-caption {
  min-height: 3.4em;
  margin: 0;
  font-size: 17px;
  line-height: 1.7;
  text-shadow: 0 2px 8px #000;
}
#btn-enter { opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 0.6s, transform 0.6s; }
#scene-exterior.ready #btn-enter { opacity: 1; transform: none; pointer-events: auto; }
#scene-exterior.opening #btn-enter { opacity: 0; pointer-events: none; }

/* ---------- 3. 館の中 ---------- */
#scene-house { background: var(--bg); }
#viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}
#camera {
  position: absolute;
  left: 50%;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  transition: transform 1.6s cubic-bezier(0.65, 0, 0.35, 1);
}
#camera.push { transition: transform 0.75s cubic-bezier(0.55, 0, 0.9, 0.45); }
#camera.no-anim { transition: none; }
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 80% 60% at 50% 34%, transparent 50%, rgba(0, 0, 0, 0.7) 100%);
}
#scene-house::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 35%, rgba(255, 244, 220, 0.95), rgba(255, 244, 220, 0) 60%);
  opacity: 0;
}
#scene-house.flash::after { animation: flash 1.6s ease-out; }
@keyframes flash {
  0% { opacity: 0; }
  18% { opacity: 1; }
  100% { opacity: 0; }
}

.room { position: absolute; z-index: 1; }
.room.current { z-index: 5; }
.room-body { position: absolute; inset: 0; }
.room-art { position: absolute; inset: 0; display: block; width: 100%; height: 100%; user-select: none; }
.room-art svg { display: block; width: 100%; height: 100%; }

/* 暗闇：燭台に火がつくと、その周りから見えてくる */
.shade {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: var(--bg);
  pointer-events: none;
  transition: opacity 1.8s ease;
}
.room.l0 .shade {
  -webkit-mask-image: radial-gradient(circle at var(--l0x) var(--l0y), transparent 0 60px, #000 250px);
  mask-image: radial-gradient(circle at var(--l0x) var(--l0y), transparent 0 60px, #000 250px);
}
.room.l0.l1 .shade {
  -webkit-mask-image:
    radial-gradient(circle at var(--l0x) var(--l0y), transparent 0 60px, #000 250px),
    radial-gradient(circle at var(--l1x) var(--l1y), transparent 0 60px, #000 250px);
  mask-image:
    radial-gradient(circle at var(--l0x) var(--l0y), transparent 0 60px, #000 250px),
    radial-gradient(circle at var(--l1x) var(--l1y), transparent 0 60px, #000 250px);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
.room.lit .shade { opacity: 0; }
.room.past .shade { opacity: 0.66; -webkit-mask-image: none; mask-image: none; }

/* 燭台の灯り */
.lights { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.light {
  position: absolute;
  width: 420px;
  height: 420px;
  margin: -210px 0 0 -210px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 196, 110, 0.5), rgba(255, 160, 70, 0.16) 45%, rgba(255, 150, 60, 0));
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.25s ease;
  animation: candle-glow 1.7s ease-in-out infinite alternate;
}
.light::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 90px;
  margin: -55px 0 0 -35px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 245, 210, 0.9), rgba(255, 200, 110, 0));
}
.light-1 { animation-duration: 2.1s; animation-delay: -0.8s; }
.room.l0 .light-0, .room.l1 .light-1 { opacity: 1; }
.room.past .light { opacity: 0.3; }
@keyframes candle-glow {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(0.94) translate(2px, 3px); filter: brightness(0.85); }
  60% { transform: scale(1.03) translate(-2px, -1px); filter: brightness(1.08); }
  100% { transform: scale(0.97); filter: brightness(0.92); }
}

/* 舞うホコリ */
.dust { position: absolute; inset: 0; z-index: 4; pointer-events: none; opacity: 0; transition: opacity 2.5s ease; }
.room.current.lit .dust { opacity: 1; }
.dust i {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 232, 190, 0.75);
  box-shadow: 0 0 8px rgba(255, 220, 160, 0.8);
  animation: mote linear infinite;
}
@keyframes mote {
  0% { transform: translate(0, 0); opacity: 0; }
  20% { opacity: 0.8; }
  50% { transform: translate(40px, -120px); }
  80% { opacity: 0.5; }
  100% { transform: translate(-20px, -260px); opacity: 0; }
}

/* 扉：絵に描かれた扉を切り抜いて開く */
.door {
  position: absolute;
  z-index: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: default;
  pointer-events: none;
  -webkit-tap-highlight-color: transparent;
}
.room.choosing .door { pointer-events: auto; cursor: pointer; }
.door-clip {
  position: absolute;
  inset: 0;
  clip-path: polygon(0 100%, 0 27%, 4% 17%, 11% 9%, 22% 3.5%, 36% 0.8%, 50% 0, 64% 0.8%, 78% 3.5%, 89% 9%, 96% 17%, 100% 27%, 100% 100%);
  perspective: 700px;
}
.door-back {
  position: absolute;
  inset: 0;
  background: #050306;
  transition: background 0.8s ease;
}
.door.open .door-back {
  background: radial-gradient(ellipse at 50% 88%, #fff0c8 0%, #f5aa55 32%, #6a3312 70%, #1a0a04 100%);
}
.door-leaf {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  transform-origin: 0 50%;
  transition: transform 1.1s cubic-bezier(0.3, 0.1, 0.2, 1), filter 1.1s ease;
}
.door.open .door-leaf { transform: rotateY(76deg); filter: brightness(0.55); }
.door-sprite, .door-sprite svg, .door-sprite img { display: block; width: 100%; height: 100%; }
.door::after {
  content: '';
  position: absolute;
  left: -30%;
  right: -30%;
  bottom: -70px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 196, 110, 0.55), rgba(255, 170, 80, 0));
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.9s ease 0.2s;
  pointer-events: none;
}
.door.open::after { opacity: 1; }
.room.choosing .door { animation: door-beckon 2.4s ease-in-out infinite; }
.room.choosing .door:nth-of-type(2) { animation-delay: 1.2s; }
@keyframes door-beckon {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 200, 120, 0)); }
  50% { filter: drop-shadow(0 0 16px rgba(255, 200, 120, 0.75)) brightness(1.12); }
}
.room.choosing .door.hint, .room.choosing .door:hover {
  animation: none;
  filter: drop-shadow(0 0 22px rgba(255, 214, 140, 0.95)) brightness(1.25);
}
.door.chosen { animation: none; filter: drop-shadow(0 0 20px rgba(255, 210, 130, 0.9)) brightness(1.15); }
.door-plate {
  position: absolute;
  left: 50%;
  top: 13%;
  width: 52px;
  height: 44px;
  transform: translateX(-50%);
  border-radius: 8px;
  background: linear-gradient(180deg, #f0d18a, #9c7a38);
  border: 2px solid #5a3a12;
  color: #2a1606;
  font: 700 30px/40px var(--font-display);
  text-align: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.room.choosing .door-plate { opacity: 1; }
.door.open .door-plate { opacity: 0; }

/* キャラクター */
.char {
  position: absolute;
  z-index: 2;
  transform: translateX(-50%);
  pointer-events: none;
}
.char::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: -16px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
}
.char .sprite { position: relative; width: 100%; height: 100%; transform-origin: 50% 100%; }
.char .sprite svg, .char .sprite img { display: block; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; }

.blink { transform-box: fill-box; transform-origin: 50% 50%; animation: blink 5s infinite; }
@keyframes blink {
  0%, 94%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(0.1); }
}
.char-butler .sprite { animation: breathe 4.5s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.015) translateY(-1px); }
}
.char-maid .sprite { animation: sway 3.4s ease-in-out infinite; }
@keyframes sway {
  0%, 100% { transform: rotate(-1.2deg); }
  50% { transform: rotate(1.2deg); }
}
/* ぬいぐるみ: ふだんは動かない…が、たまに一瞬だけ */
.char-plush.twitch .sprite { animation: plush-twitch 0.55s ease-out; }
@keyframes plush-twitch {
  0% { transform: none; }
  20% { transform: rotate(-9deg) translateY(-14px); }
  45% { transform: rotate(7deg) translateY(-4px); }
  70% { transform: rotate(-2deg); }
  100% { transform: none; }
}
.char-ghost .sprite { animation: ghost-float 3.6s ease-in-out infinite; }
.char-ghost::before { animation: ghost-shadow 3.6s ease-in-out infinite; }
@keyframes ghost-float {
  0%, 100% { transform: translateY(-10px) rotate(-2deg); opacity: 0.78; }
  50% { transform: translateY(-40px) rotate(2deg); opacity: 0.95; }
}
@keyframes ghost-shadow {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(0.75); opacity: 0.45; }
}

/* 結果の部屋 */
.mirror .sprite { transition: filter 1s ease, opacity 1.2s ease; }
.room.revealing .mirror .sprite { animation: mirror-flash 1.6s ease-out forwards; }
@keyframes mirror-flash {
  0% { filter: brightness(1); }
  20% { filter: brightness(2.6) drop-shadow(0 0 40px #fff3d0); }
  100% { filter: brightness(0.8); opacity: 0.35; }
}
.char.ending { z-index: 3; opacity: 0; }
.char.ending .sprite { transform: translateY(40px) scale(0.6); transition: transform 1.3s cubic-bezier(0.2, 1.4, 0.4, 1) 0.4s; }
.room.revealing .char.ending { opacity: 1; transition: opacity 1s ease 0.4s; }
.room.revealing .char.ending .sprite {
  transform: none;
  filter: drop-shadow(0 0 24px rgba(255, 230, 170, 0.75));
  animation: end-float 4s ease-in-out 1.8s infinite;
}
@keyframes end-float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -16px; }
}
/* 鏡の中に映るエンド */
.room.mirror-vision.revealing .mirror .sprite { animation: mirror-glow 1.6s ease-out forwards; }
@keyframes mirror-glow {
  0% { filter: brightness(1); }
  20% { filter: brightness(2.4) drop-shadow(0 0 40px #fff3d0); }
  100% { filter: brightness(1.1) drop-shadow(0 0 26px rgba(255, 220, 150, 0.7)); }
}
.char.in-mirror { z-index: 3; }
.char.in-mirror::before { display: none; }
.room.revealing .char.in-mirror .sprite {
  filter: sepia(0.35) saturate(1.2) drop-shadow(0 0 12px rgba(255, 236, 190, 0.95));
  animation: vision 3.2s ease-in-out 1.8s infinite;
}
@keyframes vision {
  0%, 100% { opacity: 0.95; translate: 0 0; }
  50% { opacity: 0.7; translate: 0 -6px; }
}
.char-taiyo .sun-rays { transform-box: fill-box; transform-origin: 50% 50%; animation: spin 16s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HUD ---------- */
#room-label {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, -6px);
  padding: 4px 18px;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.3em;
  color: var(--gold-hi);
  text-shadow: 0 0 10px rgba(255, 200, 120, 0.5);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
#room-label.show { animation: label-in 3.6s ease forwards; }
@keyframes label-in {
  0% { opacity: 0; transform: translate(-50%, -6px); }
  15% { opacity: 1; transform: translate(-50%, 0); }
  75% { opacity: 1; }
  100% { opacity: 0.55; transform: translate(-50%, 0); }
}
#progress {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.prog-candle {
  position: relative;
  width: 6px;
  height: 16px;
  background: #3c3346;
  border-radius: 1px;
}
.prog-candle::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -9px;
  width: 6px;
  height: 8px;
  margin-left: -3px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--flame);
  box-shadow: 0 0 8px var(--flame);
  opacity: 0;
  transition: opacity 0.5s;
}
.prog-candle.lit { background: #e9dfc6; }
.prog-candle.lit::before { opacity: 1; }

/* ---------- セリフ枠 ---------- */
#dialog {
  position: absolute;
  left: 50%;
  bottom: calc(12px + var(--safe-b));
  width: min(560px, calc(100% - 24px));
  min-height: 132px;
  padding: 26px 18px 18px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5), inset 0 0 0 4px rgba(0, 0, 0, 0.3), inset 0 0 0 5px rgba(201, 168, 92, 0.12);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  cursor: pointer;
}
#dialog.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.nameplate {
  position: absolute;
  top: -15px;
  left: 14px;
  padding: 3px 14px;
  border-radius: 6px;
  background: linear-gradient(180deg, #3a2412, #22150a);
  border: 1px solid var(--gold);
  color: var(--gold-hi);
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: 0.1em;
}
.dlg-text {
  margin: 0;
  min-height: 3.5em;
  font-size: 17px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: normal;
  line-break: strict;
}
.dlg-next {
  position: absolute;
  right: 16px;
  bottom: 10px;
  color: var(--gold);
  font-size: 12px;
  opacity: 0;
}
#dialog.waiting .dlg-next { opacity: 1; animation: bob 0.9s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(4px); } }

.choices { display: grid; gap: 10px; margin-top: 14px; }
.choices:empty { display: none; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  text-align: left;
  font-size: 16px;
  line-height: 1.45;
  background: linear-gradient(180deg, rgba(58, 36, 20, 0.9), rgba(36, 22, 14, 0.9));
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  animation: choice-in 0.4s ease forwards;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.choice:nth-child(2) { animation-delay: 0.12s; }
.choice:hover, .choice:focus-visible { border-color: var(--gold-hi); box-shadow: 0 0 16px rgba(255, 200, 120, 0.25); outline: none; }
@keyframes choice-in { to { opacity: 1; transform: none; } }
.choice-tag {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #e2c27a, #9c7a38);
  color: #2a1606;
  font: 700 14px/1 var(--font-display);
}

/* ---------- 結果 ---------- */
#result {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(560px, 100%);
  max-height: 64%;
  overflow-y: auto;
  padding: 24px 20px calc(18px + var(--safe-b));
  background: linear-gradient(180deg, rgba(30, 19, 36, 0.97), rgba(14, 9, 18, 0.99));
  border: 1px solid var(--panel-line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  text-align: center;
  transform: translate(-50%, 105%);
  transition: transform 0.9s cubic-bezier(0.2, 0.9, 0.3, 1);
}
#result.show { transform: translate(-50%, 0); }
.res-kicker { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: 0.2em; }
.res-title {
  margin: 4px 0 12px;
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--gold-hi);
  text-shadow: 0 0 14px rgba(255, 200, 120, 0.4);
}
.res-text { margin: 0 0 20px; font-size: 16px; line-height: 1.85; text-align: left; }
.res-actions { display: flex; flex-direction: column; gap: 14px; }
.res-cta { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.res-cta .btn { width: 100%; }
.trial-note {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #ffd98a;
}
.trial-note::before { content: '✦ '; }
.trial-note::after { content: ' ✦'; }
.res-sub { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.res-sub .btn-ghost { width: 100%; font-size: 15px; }

@media (min-width: 720px) {
  .dlg-text { font-size: 18px; }
  #result { bottom: 16px; border-radius: 20px; border-bottom: 1px solid var(--panel-line); }
}


/* ============================================================
   画像つきの演出
   ============================================================ */

/* タイトル背景（館の絵） */
.title-art {
  position: absolute;
  inset: -4%;
  background-size: cover;
  background-position: 50% 45%;
  opacity: 0;
  filter: brightness(0.42) saturate(0.85) blur(1.5px);
  transition: opacity 2.4s ease;
  animation: slow-zoom 32s ease-in-out infinite alternate;
}
.title-art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 45% at 50% 48%, rgba(7, 5, 10, 0.55), transparent 80%),
    linear-gradient(180deg, rgba(7, 5, 10, 0.3), transparent 30%, transparent 60%, rgba(7, 5, 10, 0.85));
}
#scene-title.has-art .title-art { opacity: 1; }
#scene-title.has-art .moon { display: none; }
@keyframes slow-zoom {
  from { transform: scale(1.02); }
  to { transform: scale(1.1) translateY(-1%); }
}
#scene-title.knocked .title-logo { animation: knock-shake 0.6s ease; }
@keyframes knock-shake {
  0%, 100% { transform: none; }
  10%, 43%, 76% { transform: translateX(-3px) rotate(-0.5deg); }
  22%, 55%, 88% { transform: translateX(3px) rotate(0.5deg); }
}

/* 外観（館の絵） */
.mansion { transform-origin: var(--door-x, 50%) var(--door-y, 90%); position: relative; }
.mansion > img { display: block; width: 100%; height: auto; user-select: none; }
#scene-exterior.has-art .ext-sky {
  background: linear-gradient(180deg, #171029 0%, #2a1f45 38%, #221938 62%, #0b0810 100%);
}
#scene-exterior.has-art .moon, #scene-exterior.has-art .stars { display: none; }
#scene-exterior.has-art .ext-stage {
  top: 43%;
  bottom: auto;
  width: clamp(100vw, 180vw, 200vh);
  transform: translate(-50%, -50%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 13%, #000 82%, transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 13%, #000 82%, transparent 100%);
}
@media (min-aspect-ratio: 3/2) {
  #scene-exterior.has-art .ext-stage { top: 42%; width: min(100vw, 190vh); }
}
.ext-door-glow {
  position: absolute;
  left: var(--door-x);
  top: var(--door-y);
  width: 5%;
  aspect-ratio: 0.6;
  transform: translate(-50%, -50%) scale(0.6);
  border-radius: 45% 45% 10% 10%;
  background: radial-gradient(ellipse at 50% 70%, #fff3cf, #ffb45a 45%, rgba(255, 150, 60, 0) 75%);
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 1s ease 0.4s, transform 1.4s ease 0.4s;
}
#scene-exterior.opening .ext-door-glow { opacity: 1; transform: translate(-50%, -50%) scale(2.4); }
.ext-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: #e6e2ff;
  mix-blend-mode: screen;
  opacity: 0;
}
#scene-exterior.flash .ext-flash { animation: lightning 1.4s ease-out; }
@keyframes lightning {
  0% { opacity: 0; }
  3% { opacity: 0.55; }
  7% { opacity: 0.05; }
  11% { opacity: 0.38; }
  30%, 100% { opacity: 0; }
}

/* サウンド切り替え */
.sound-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 10px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px 6px 9px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(20, 13, 26, 0.72);
  color: var(--gold-hi);
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.sound-btn svg { width: 18px; height: 18px; }
.sound-btn .snd-x { display: none; }
.sound-btn.off { color: var(--muted); }
.sound-btn.off .snd-x { display: inline; }
.sound-btn.off .snd-wave { display: none; }
.sound-btn:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  #camera { transition-duration: 0.3s; }
}
