/* ============================================================
   style.css - 放課後のステラ UI スタイル
   ゲームウィンドウ: 1280 × 720px (16:9)
============================================================ */

/* ---- Fonts ---- */
:root {
  --vn-serif-font: 'Shippori Mincho B1', 'Noto Serif JP', 'Yu Mincho', 'YuMincho',
                   'Hiragino Mincho ProN', serif;
}

html.is-firefox {
  --vn-serif-font: 'Yu Mincho', 'YuMincho', 'Hiragino Mincho ProN', 'Noto Serif JP', serif;
}

/* ---- リセット ---- */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  height: -webkit-fill-available;
}

body {
  background: #0d0520;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  height: -webkit-fill-available;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Yu Gothic UI', 'YuGothic', 'Hiragino Sans', 'Noto Sans JP',
               'Meiryo', sans-serif;
}

/* ---- ゲームコンテナ (1280×720 固定) ---- */
#game-container {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1280px;
  height: 720px;
  overflow: hidden;
  box-shadow: 0 0 80px rgba(200, 100, 180, 0.25),
              0 0 160px rgba(100, 80, 200, 0.12);
  transform-origin: center center;
}

/* ============================================================
   タイトル画面
============================================================ */
#title-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#title-bg {
  position: absolute;
  inset: 0;
  background:
    url('assets/images/bg/title_bg.webp') center center / cover no-repeat,
    radial-gradient(ellipse at 40% 40%, #2a0050 0%, #0d0020 50%, #0a0818 100%);
  animation: titlePulse 10s ease-in-out infinite alternate;
}
#title-screen.all-good-ends-cleared #title-bg {
  background:
    linear-gradient(180deg, rgba(255, 244, 225, 0.05) 0%, rgba(255, 210, 236, 0.08) 48%, rgba(255, 255, 255, 0.02) 100%),
    url('assets/images/bg/title_end.webp') center center / cover no-repeat,
    linear-gradient(180deg, #8fd3ff 0%, #ffe7c8 100%);
  animation: titleEndPulse 12s ease-in-out infinite alternate;
}
@keyframes titlePulse {
  0%   { filter: brightness(1) hue-rotate(0deg); }
  100% { filter: brightness(1.08) hue-rotate(12deg); }
}
@keyframes titleEndPulse {
  0%   { filter: brightness(1.02) saturate(1.02); }
  100% { filter: brightness(1.1) saturate(1.08); }
}

/* 星パーティクル */
#title-stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at  8%  12%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 15%  65%, rgba(255,220,255,.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at 22%  40%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 35%  80%, rgba(200,200,255,.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 42%  25%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 50%  55%, rgba(255,200,255,.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at 58%  10%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 65%  70%, rgba(200,220,255,.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 72%  45%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 80%  20%, rgba(255,200,255,.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at 88%  60%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 93%  85%, rgba(220,200,255,.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at  5%  90%, #fff 0%, transparent 100%),
    radial-gradient(1px   1px   at 30%   5%, rgba(255,240,255,.7) 0%, transparent 100%),
    radial-gradient(1px   1px   at 75%  95%, rgba(200,200,255,.7) 0%, transparent 100%);
  animation: starTwinkle 6s ease-in-out infinite alternate;
}
#title-screen.all-good-ends-cleared #title-stars {
  opacity: 0.38;
  mix-blend-mode: screen;
}
@keyframes starTwinkle {
  0%   { opacity: 0.55; }
  100% { opacity: 1; }
}

/* タイトルCanvasエフェクトレイヤー (星個別瞬き・雲流れ) */
#title-canvas {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
  z-index: 0;
}

#title-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: #fff;
}

#title-logo {
  margin-bottom: 72px;
}

#title-logo-wrapper {
  position: relative;
  display: inline-block;
  overflow: hidden;
  opacity: 0;
}

#title-logo-wrapper.logo-entering {
  animation: titleLogoFadeIn 1.4s cubic-bezier(.22,.61,.36,1) forwards;
}

@keyframes titleLogoFadeIn {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}


#title-logo-img {
  display: block;
  max-width: 700px;
  width: 90%;
  filter: drop-shadow(0 0 10px rgba(255,130,195,.35)) drop-shadow(0 0 25px rgba(220,60,175,.2));
  animation: titleGlow 3.5s ease-in-out infinite alternate;
}

#title-main {
  font-family: var(--vn-serif-font);
  font-size: 72px;
  font-weight: 400;
  letter-spacing: 0.42em;
  color: #fff6fa;
  text-shadow:
    0 0  3px rgba(255,255,255,.98),
    0 0 10px rgba(255,210,235,.95),
    0 0 24px rgba(255,130,195,.9),
    0 0 52px rgba(255, 60,175,.7),
    0 0 90px rgba(220, 35,155,.5),
    0 0 145px rgba(180, 15,130,.28);
  animation: titleGlow 3.5s ease-in-out infinite alternate;
  line-height: 1.2;
}
@keyframes titleGlow {
  0% {
    text-shadow:
      0 0  3px rgba(255,255,255,.95),
      0 0 10px rgba(255,200,230,.88),
      0 0 22px rgba(255,120,190,.82),
      0 0 48px rgba(255, 55,170,.62),
      0 0 82px rgba(215, 30,150,.44),
      0 0 135px rgba(175, 10,125,.22);
    letter-spacing: 0.42em;
  }
  100% {
    text-shadow:
      0 0  5px rgba(255,255,255,1),
      0 0 16px rgba(255,225,245,1),
      0 0 36px rgba(255,150,210,.98),
      0 0 72px rgba(255, 85,190,.8),
      0 0 115px rgba(235, 50,168,.6),
      0 0 180px rgba(200, 25,145,.38);
    letter-spacing: 0.44em;
  }
}

/* タイトル下グロービームライン */
#title-main::after {
  content: '';
  display: block;
  width: 360px;
  height: 2px;
  background: rgba(255, 228, 245, 0.88);
  margin: 18px auto 0;
  box-shadow:
    0 0  6px 1px rgba(255, 180, 220, .9),
    0 0 14px 2px rgba(255, 100, 190, .65),
    0 0 30px 4px rgba(220,  50, 160, .4);
  animation: beamPulse 3.5s ease-in-out infinite alternate;
}
@keyframes beamPulse {
  0%   { opacity: .75; width: 340px; }
  100% { opacity:  1;  width: 380px; }
}


#title-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
#title-screen.all-good-ends-cleared #title-menu {
  padding: 0;
}

.title-btn {
  width: 300px;
  padding: 15px 0;
  background: transparent;
  border: 1px solid rgba(255,150,210,.45);
  color: rgba(255,220,240,.9);
  font-size: 15px;
  letter-spacing: 0.4em;
  cursor: pointer;
  transition: all .35s ease;
  position: relative;
  overflow: hidden;
}
#title-screen.all-good-ends-cleared .title-btn {
  color: rgba(255, 250, 255, 0.98);
  background: rgba(25, 30, 58, 0.42);
  border-color: rgba(255, 242, 250, 0.62);
  text-shadow:
    0 2px 8px rgba(33, 24, 54, 0.9),
    0 0 18px rgba(120, 82, 130, 0.55);
  box-shadow:
    0 10px 30px rgba(45, 36, 72, 0.22),
    0 0 0 1px rgba(70, 48, 86, 0.18) inset;
}
.title-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,150,210,.12), transparent);
  transform: translateX(-100%);
  transition: transform .5s ease;
}
#title-screen.all-good-ends-cleared .title-btn::after {
  background: linear-gradient(90deg, transparent, rgba(255, 246, 250, 0.28), transparent);
}
.title-btn:hover {
  border-color: rgba(255,180,220,.9);
  color: #fff;
  letter-spacing: 0.6em;
  box-shadow: 0 0 24px rgba(255,100,180,.3);
}
#title-screen.all-good-ends-cleared .title-btn:hover {
  background: rgba(70, 52, 88, 0.54);
  border-color: rgba(255, 255, 255, 0.92);
  box-shadow:
    0 0 30px rgba(255, 230, 245, 0.36),
    0 12px 36px rgba(54, 42, 84, 0.28);
}
.title-btn:hover::after { transform: translateX(100%); }

/* ---- 流れ星 ---- */
#shooting-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

/*
 * .shooting-star
 *  細長い矩形を rotate(45deg) で斜めに傾け、
 *  translateY(+) でゲーム内座標の左下方向に飛ばす。
 *  グラデーション: 上(尾)→透明、下(頭)→白
 */
.shooting-star {
  position: absolute;
  width: 2px;
  height: 100px;           /* JSで上書き */
  border-radius: 0 0 2px 2px;
  background: linear-gradient(
    to bottom,
    transparent          0%,
    rgba(255,210,240,.25) 45%,
    rgba(255,255,255,.95) 100%
  );
  transform: rotate(45deg);
  transform-origin: top center;
  animation: shootingStarFly var(--dur, 0.9s) ease-out forwards;
}

/* 先端の輝き */
.shooting-star::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px 3px rgba(255, 200, 240, .85),
              0 0 12px 4px rgba(220, 160, 255, .45);
}

@keyframes shootingStarFly {
  0%   { opacity: 0;    transform: rotate(45deg) translateY(-20px); }
  8%   { opacity: 1; }
  78%  { opacity: .85; }
  100% { opacity: 0;    transform: rotate(45deg) translateY(380px); }
}

/* ============================================================
   ゲーム画面
============================================================ */
#game-screen {
  position: absolute;
  inset: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---- Canvasエフェクトレイヤー ---- */
#canvas-effects {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* ---- 背景 ---- */
#background {
  position: absolute;
  inset: 0;
  background: #1a1a2e;
  background-size: cover;
  background-position: center;
}

/* ---- シーン切り替えワイプ ---- */
#scene-wipe {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right,
    rgba(5, 2, 14, 0)    0%,
    #05020e             20%,
    #05020e             80%,
    rgba(5, 2, 14, 0)  100%
  );
  transform: translateX(-100%);
  z-index: 22;
  pointer-events: none;
  will-change: transform;
}

/* ---- トランジションCanvasレイヤー ---- */
#transition-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 35;
  pointer-events: none;
}

/* ---- キャラクターレイヤー ---- */
#characters {
  position: absolute;
  inset: 0;  /* 画面全体。テキストボックスの下にもキャラを配置 */
  pointer-events: none;
  z-index: 3;
}

/* 推奨画像サイズ: 512×900px 以上の透過PNG (アスペクト比 ~0.57:1)
   スロット縦720px = ゲーム画面フルハイト。下端を画面最下端に揃える */
.character-slot {
  position: absolute;
  bottom: 0;
  width: 420px;
  height: 720px;
  opacity: 0;
  transition: opacity .5s ease, filter .3s ease, transform .4s ease;
}
.character-slot.visible  { opacity: 1; }
.character-slot.dimmed   { filter: brightness(.55) saturate(.6); }
.character-slot.highlighted { filter: brightness(1) saturate(1.1); }

#char-left   { left: 60px; }
#char-center { left: 50%; transform: translateX(-50%); }
#char-right  { right: 60px; }

/* スロット表示中はcenter用のtransformを維持 */
#char-center.visible { transform: translateX(-50%); }
#char-center.dimmed  { transform: translateX(-50%); }
#char-center.highlighted { transform: translateX(-50%); }

/* キャラスプライト内の画像 */
.char-sprite {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.char-sprite img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: bottom;
  display: block;
}

/* プレースホルダー (画像なし時) */
.char-placeholder {
  width: 220px;
  height: 560px;
  border-radius: 110px 110px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 28px;
  gap: 8px;
}
.char-ph-icon  { font-size: 48px; opacity: .8; }
.char-ph-name  { font-size: 16px; color: rgba(255,255,255,.9); font-weight: bold; }
.char-ph-expr  { font-size: 12px; color: rgba(255,255,255,.55); }

/* ---- キャラ表示エフェクト (CSS アニメーション) ---- */
.anim-fade-in        { animation: animFadeIn     .5s ease forwards; }
.anim-slide-in-left  { animation: animSlideLeft  .45s ease forwards; }
.anim-slide-in-right { animation: animSlideRight .45s ease forwards; }
.anim-pop-in         { animation: animPopIn      .4s  cubic-bezier(.34,1.56,.64,1) forwards; }
.anim-fade-out       { animation: animFadeOut    .5s  ease forwards; }
.anim-slide-out-left { animation: animSlideOutL  .4s  ease forwards; }
.anim-slide-out-right{ animation: animSlideOutR  .4s  ease forwards; }

@keyframes animFadeIn      { from { opacity:0; }                 to { opacity:1; } }
@keyframes animSlideLeft   { from { opacity:0; transform:translateX(-70px); } to { opacity:1; transform:translateX(0); } }
@keyframes animSlideRight  { from { opacity:0; transform:translateX( 70px); } to { opacity:1; transform:translateX(0); } }
@keyframes animPopIn       { from { opacity:0; transform:scale(.78); }        to { opacity:1; transform:scale(1); } }
@keyframes animFadeOut     { from { opacity:1; }                 to { opacity:0; } }
@keyframes animSlideOutL   { from { opacity:1; transform:translateX(0); }    to { opacity:0; transform:translateX(-80px); } }
@keyframes animSlideOutR   { from { opacity:1; transform:translateX(0); }    to { opacity:0; transform:translateX( 80px); } }

/* center スロット用エフェクト (translateX(-50%) を維持) */
#char-center.anim-fade-in        { animation: animFadeIn          .5s ease forwards; }
#char-center.anim-slide-in-left  { animation: animSlideLeftCenter .45s ease forwards; }
#char-center.anim-slide-in-right { animation: animSlideRightCenter.45s ease forwards; }
#char-center.anim-pop-in         { animation: animPopInCenter     .4s  cubic-bezier(.34,1.56,.64,1) forwards; }
#char-center.anim-fade-out       { animation: animFadeOut         .5s  ease forwards; }
#char-center.anim-slide-out-left { animation: animSlideOutLCenter .4s  ease forwards; }
#char-center.anim-slide-out-right{ animation: animSlideOutRCenter .4s  ease forwards; }

@keyframes animSlideLeftCenter    { from { opacity:0; transform:translateX(calc(-50% - 70px)); } to { opacity:1; transform:translateX(-50%); } }
@keyframes animSlideRightCenter   { from { opacity:0; transform:translateX(calc(-50% + 70px)); } to { opacity:1; transform:translateX(-50%); } }
@keyframes animPopInCenter        { from { opacity:0; transform:translateX(-50%) scale(.78); }   to { opacity:1; transform:translateX(-50%) scale(1); } }
@keyframes animSlideOutLCenter    { from { opacity:1; transform:translateX(-50%); } to { opacity:0; transform:translateX(calc(-50% - 80px)); } }
@keyframes animSlideOutRCenter    { from { opacity:1; transform:translateX(-50%); } to { opacity:0; transform:translateX(calc(-50% + 80px)); } }

/* ---- スチルレイヤー ---- */
#still-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  background-color: rgba(0,0,0,.85);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .5s ease;
  overflow: hidden;
  isolation: isolate;
}
#still-layer.effect-fade-in         { animation: animFadeIn .6s ease forwards; }
#still-layer.effect-slide-in-bottom { animation: animStillSlideUp .5s ease forwards; }
#still-layer.ending-return-still {
  pointer-events: none;
  z-index: 29;
  animation: endingStillReturnFade 2.8s cubic-bezier(.24, .02, .16, 1) forwards !important;
}
@keyframes animStillSlideUp { from { opacity:0; transform:translateY(40px); } to { opacity:1; transform:translateY(0); } }
@keyframes endingStillReturnFade {
  0% {
    opacity: 1;
    filter: blur(0) brightness(1) saturate(1);
    transform: scale(1);
  }
  55% {
    opacity: 0.62;
    filter: blur(8px) brightness(0.68) saturate(0.8);
    transform: scale(1.025);
  }
  100% {
    opacity: 0;
    filter: blur(28px) brightness(0.22) saturate(0.45);
    transform: scale(1.06);
  }
}

#still-layer.ending-intro-still {
  z-index: 40;
  transform-origin: center center;
  will-change: transform, filter, opacity;
}
#still-layer.ending-intro-still::before,
#still-layer.ending-intro-still::after {
  content: '';
  position: absolute;
  inset: -8%;
  pointer-events: none;
}
#still-layer.ending-intro-still::before {
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 244, 218, 0.8) 0 0.3%, transparent 1.3%),
    radial-gradient(circle at 72% 28%, rgba(255, 226, 196, 0.62) 0 0.28%, transparent 1.1%),
    radial-gradient(circle at 36% 64%, rgba(255, 245, 235, 0.7) 0 0.22%, transparent 1.1%),
    radial-gradient(circle at 84% 70%, rgba(255, 228, 210, 0.62) 0 0.24%, transparent 1.2%),
    radial-gradient(circle at 58% 48%, rgba(255, 249, 240, 0.42) 0 0.16%, transparent 0.9%);
  mix-blend-mode: screen;
  opacity: 0.58;
  animation: endingSparkleFloat 7.2s linear infinite;
}
#still-layer.ending-intro-still::after {
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(255, 235, 215, 0.12) 0%, rgba(255, 235, 215, 0.04) 28%, rgba(0, 0, 0, 0) 56%),
    linear-gradient(180deg, rgba(255, 244, 230, 0.08) 0%, rgba(255, 255, 255, 0) 34%, rgba(8, 4, 14, 0.22) 100%);
  opacity: 0.9;
  animation: endingGlowPulse 4.8s ease-in-out infinite alternate;
}
#still-layer.ending-intro-kotoha {
  animation: endingStillPanKotoha 13s ease-in-out forwards;
}
#still-layer.ending-intro-sakura {
  animation: endingStillPanSakura 10s ease-in-out forwards;
}
#still-layer.ending-intro-mahiru {
  animation: endingStillPanMahiru 14s ease-in-out forwards;
}
#still-layer.ending-intro-out {
  animation: endingStillBlurOut .82s cubic-bezier(.3, .02, .18, 1) forwards !important;
}
#still-layer.ending-intro-out::before {
  animation: endingSparkleOut .82s ease forwards;
}
#still-layer.ending-intro-out::after {
  animation: endingGlowOut .82s ease forwards;
}
@keyframes endingStillPanKotoha {
  from {
    transform: scale(1.02) translate3d(0, 0, 0);
    filter: brightness(0.96) saturate(1.02);
  }
  45% {
    transform: scale(1.055) translate3d(-1.2%, -0.8%, 0);
    filter: brightness(1.01) saturate(1.05);
  }
  to {
    transform: scale(1.09) translate3d(-2.4%, -1.7%, 0);
    filter: brightness(1.05) saturate(1.08);
  }
}
@keyframes endingStillPanMahiru {
  from {
    transform: scale(1.018) translate3d(0, 0, 0);
    filter: brightness(0.97) saturate(1.01);
  }
  42% {
    transform: scale(1.05) translate3d(1.1%, -0.6%, 0);
    filter: brightness(1.01) saturate(1.04);
  }
  to {
    transform: scale(1.085) translate3d(2.2%, -1.4%, 0);
    filter: brightness(1.05) saturate(1.07);
  }
}
@keyframes endingStillPanSakura {
  from {
    transform: scale(1.022) translate3d(0, 0, 0);
    filter: brightness(0.98) saturate(1.03);
  }
  48% {
    transform: scale(1.058) translate3d(-0.8%, -1.1%, 0);
    filter: brightness(1.03) saturate(1.08);
  }
  to {
    transform: scale(1.094) translate3d(-1.6%, -2.1%, 0);
    filter: brightness(1.08) saturate(1.12);
  }
}
@keyframes endingSparkleFloat {
  0% {
    transform: translate3d(-1.5%, 1.2%, 0) scale(1);
    opacity: 0.32;
  }
  35% {
    transform: translate3d(1.1%, -0.8%, 0) scale(1.04);
    opacity: 0.62;
  }
  70% {
    transform: translate3d(-0.6%, -1.4%, 0) scale(1.08);
    opacity: 0.48;
  }
  100% {
    transform: translate3d(1.8%, 0.7%, 0) scale(1.03);
    opacity: 0.3;
  }
}
@keyframes endingGlowPulse {
  from {
    opacity: 0.66;
    transform: scale(1);
  }
  to {
    opacity: 0.96;
    transform: scale(1.03);
  }
}
@keyframes endingStillBlurOut {
  from {
    opacity: 1;
    filter: blur(0px) brightness(1.04) saturate(1.06);
  }
  to {
    opacity: 0;
    filter: blur(16px) brightness(1.18) saturate(1.12);
  }
}
@keyframes endingSparkleOut {
  from {
    opacity: 0.58;
  }
  to {
    opacity: 0;
    transform: scale(1.1);
  }
}
@keyframes endingGlowOut {
  from {
    opacity: 0.9;
  }
  to {
    opacity: 0;
  }
}

.still-placeholder {
  color: rgba(255,255,255,.4);
  font-size: 18px;
  letter-spacing: .2em;
  border: 1px dashed rgba(255,255,255,.2);
  padding: 30px 60px;
}

/* ---- UIレイヤー ---- */
#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#ui-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 84% 14%, rgba(255, 182, 216, 0.16), transparent 24%),
    rgba(6, 4, 14, 0.34);
  backdrop-filter: blur(6px) saturate(0.72) brightness(0.72);
  -webkit-backdrop-filter: blur(6px) saturate(0.72) brightness(0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
  z-index: 30;
}

#ui-layer.menu-open::before {
  opacity: 1;
}

/* ---- メッセージ統合メニュー（D案） ---- */
#menu-bar {
  position: absolute;
  top: 18px;
  right: 12px;
  width: 56px;
  height: 56px;
  pointer-events: all;
  overflow: visible;
  z-index: 35;
}

#menu-bar::before {
  content: "";
  position: absolute;
  left: -58px;
  top: -32px;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 167, 205, 0.1) 0%, rgba(255, 167, 205, 0.04) 38%, transparent 72%);
  opacity: 0;
  transform: scale(0.72);
  filter: blur(14px);
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(.2,.8,.2,1), opacity 0.35s ease;
}

.radial-tab {
  position: absolute;
  right: 0;
  top: 0;
  transform: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  border: 1px solid rgba(255, 186, 213, 0.12);
  border-radius: 50%;
  color: rgba(255, 238, 244, 0.56);
  background: linear-gradient(180deg, rgba(23, 14, 39, 0.34), rgba(13, 9, 24, 0.26));
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
  font-size: 7px;
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  overflow: hidden;
  z-index: 4;
  opacity: 0.58;
  pointer-events: auto;
  transition: transform 0.32s cubic-bezier(.2,.8,.2,1), box-shadow 0.32s ease, border-color 0.32s ease, background 0.25s ease, color 0.25s ease, opacity 0.25s ease;
}

.menu-icon {
  position: relative;
  width: 14px;
  height: 10px;
  display: block;
}
.menu-icon::before,
.menu-icon::after,
.menu-icon span {
  content: "";
  position: absolute;
  left: 0;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 240, 246, 0.68);
  box-shadow: 0 0 8px rgba(255, 163, 204, 0.1);
}
.menu-icon::before { top: 0; }
.menu-icon span { top: 4px; }
.menu-icon::after { top: 8px; }
.menu-label {
  display: block;
  font-size: 7px;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: rgba(255, 234, 242, 0.5);
}

.radial-tab::before {
  content: "";
  position: absolute;
  inset: -10%;
  background: linear-gradient(180deg, transparent 0%, rgba(255, 255, 255, 0.16) 48%, transparent 100%);
  transform: translateY(-120%);
  opacity: 0;
  transition: transform 0.45s ease, opacity 0.35s ease;
}

.radial-list {
  position: absolute;
  inset: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.menu-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 186, 213, 0.18);
  color: rgba(255, 236, 244, 0.84);
  font-size: 11px;
  letter-spacing: .12em;
  text-indent: .12em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.22s ease, color 0.22s ease, box-shadow 0.24s ease, transform 0.22s ease, opacity 0.22s ease, border-color 0.22s ease;
}

.menu-btn:hover,
.menu-btn:focus-visible {
  background: linear-gradient(180deg, rgba(28, 16, 48, 0.94), rgba(14, 9, 27, 0.9));
  color: rgba(255, 247, 251, 0.98);
  border-color: rgba(255, 188, 219, 0.32);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.26), 0 0 18px rgba(255, 151, 196, 0.16);
  outline: none;
}

.menu-key {
  display: inline-block;
  margin-left: 6px;
  color: rgba(255, 203, 223, 0.45);
  font-size: 10px;
  letter-spacing: 0;
  text-indent: 0;
}

.menu-btn.active,
.menu-btn.is-primary {
  color: #fff;
  background: rgba(255, 147, 188, 0.72);
  border-color: rgba(255, 218, 234, 0.78);
}

.radial-item {
  position: absolute;
  left: 34px;
  top: 24px;
  min-width: 104px;
  min-height: 42px;
  padding: 0 14px;
  background: rgba(16, 10, 30, 0.82);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.22);
  border-color: rgba(255, 202, 225, 0.26);
  color: rgba(255, 244, 249, 0.9);
  opacity: 0;
  pointer-events: none;
  transform:
    translate(-50%, -50%)
    rotate(0deg)
    translateX(0)
    rotate(0deg)
    scale(0.36);
  transform-origin: center center;
  transition:
    transform 0.42s cubic-bezier(.16,.84,.24,1),
    opacity 0.24s ease,
    box-shadow 0.3s ease,
    background 0.3s ease,
    border-color 0.25s ease,
    color 0.25s ease;
}

#menu-bar.is-open .radial-list {
  pointer-events: auto;
}
#menu-bar.is-open .radial-item {
  opacity: 1;
  pointer-events: auto;
  transform:
    translate(-50%, -50%)
    rotate(var(--open-angle, 0deg))
    translateX(var(--open-radius, 0px))
    rotate(calc(var(--open-angle, 0deg) * -1))
    scale(1);
  background: linear-gradient(180deg, rgba(28, 17, 48, 0.94), rgba(13, 8, 27, 0.9));
  border-color: rgba(255, 211, 231, 0.46);
  color: rgba(255, 248, 251, 0.98);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.36), 0 0 20px rgba(255, 151, 196, 0.2);
}
#menu-bar.is-open::before {
  opacity: 1;
  transform: scale(1);
}
#menu-bar.is-open .radial-tab,
.radial-tab:hover,
.radial-tab:focus-visible {
  background: linear-gradient(180deg, rgba(23, 14, 39, 0.94), rgba(13, 9, 24, 0.9));
  transform: translateX(-2px) scale(1.03);
  border-color: rgba(255, 202, 225, 0.42);
  color: rgba(255, 238, 244, 0.92);
  opacity: 1;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.34), 0 0 22px rgba(255, 151, 196, 0.16);
  outline: none;
}

#menu-bar.is-open .radial-tab::before {
  opacity: 1;
  transform: translateY(120%);
}

.radial-tab:hover .menu-label,
.radial-tab:focus-visible .menu-label {
  color: rgba(255, 234, 242, 0.88);
}

.radial-item:hover,
.radial-item:focus-visible {
  background: linear-gradient(180deg, rgba(43, 25, 68, 0.98), rgba(19, 11, 34, 0.96));
  color: #fff;
  border-color: rgba(255, 226, 240, 0.64);
  box-shadow: 0 20px 38px rgba(0, 0, 0, 0.4), 0 0 24px rgba(255, 151, 196, 0.3);
  outline: none;
}

.radial-item:nth-child(1) { --open-angle: 102deg; --open-radius: 128px; transition-delay: 0.03s; }
.radial-item:nth-child(2) { --open-angle: 136deg; --open-radius: 148px; transition-delay: 0.07s; }
.radial-item:nth-child(3) { --open-angle: 156deg; --open-radius: 150px; transition-delay: 0.11s; }
.radial-item:nth-child(4) { --open-angle: 172deg; --open-radius: 138px; transition-delay: 0.15s; }
.radial-item:nth-child(5) { --open-angle: 192deg; --open-radius: 94px; transition-delay: 0.19s; }

/* ---- テキストエリア ---- */
#text-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 44px 28px;
  pointer-events: all;
  cursor: pointer;
  user-select: none;
}

#window-top {
  position: absolute;
  left: 0;
  right: 0;
  top: -42px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}

#char-name-box {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  position: relative;
  background: rgba(12, 4, 24, .8);
  border: none;
  border-radius: 14px 14px 0 0;
  padding: 0 22px 0 18px;
  margin-bottom: 0;
  min-width: 136px;
  min-height: 42px;
  overflow: hidden;
  pointer-events: auto;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.7s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
/* キャラカラーの上アクセントライン */
#char-name-box::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 2px;
  background: linear-gradient(90deg,
    var(--accent-color, #ff99bb) 0%,
    rgba(255,153,187,.3) 75%,
    transparent 100%);
  border-radius: 10px 10px 0 0;
  box-shadow: 0 0 8px 1px var(--accent-color, #ff99bb);
}
#char-name-box.no-speaker #char-name {
  opacity: 0;
}
#char-name-box.no-speaker::after {
  content: "";
  display: block;
  width: 90px;
  height: 1px;
  background: rgba(255, 170, 204, 0.28);
}
#char-name {
  font-family: var(--vn-serif-font);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: .12em;
  color: #ff99bb;  /* キャラ色はJSで上書き */
}

#quick-command-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 6px;
  padding: 0 56px 0 0;
  pointer-events: auto;
}

.quick-menu-btn {
  position: relative;
  top: 1px;
  height: 34px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, rgba(17, 9, 31, 0.9), rgba(11, 6, 22, 0.82));
  border: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.quick-menu-btn:hover,
.quick-menu-btn:focus-visible {
  transform: none;
}

.quick-menu-btn.is-primary {
  background: linear-gradient(180deg, rgba(255, 147, 188, 0.2), rgba(138, 74, 118, 0.16));
}

.quick-menu-btn.active {
  background: linear-gradient(180deg, rgba(255, 147, 188, 0.88), rgba(156, 73, 124, 0.82));
  border-color: rgba(255, 225, 239, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 0 18px rgba(255, 151, 196, 0.34);
}

#text-box {
  background: rgba(8, 3, 20, .8);
  border: none;
  border-radius: 0 18px 18px 18px;
  padding: 18px 26px 28px;
  /* フォントサイズに連動：2行分(×1.85 line-height)＋上下パディング32px */
  min-height: calc(var(--vn-font-size, 26px) * 3.7 + 32px);
  position: relative;
  backdrop-filter: blur(8px);
  transition: background 0.7s ease, box-shadow 0.7s ease;
}

#menu-dim {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(6, 5, 14, 0.20), rgba(6, 5, 14, 0.48));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.22s ease;
}


#dialog-text {
  font-family: var(--vn-serif-font);
  font-size: var(--vn-font-size, 26px);
  line-height: 1.85;
  color: #f5eaf0;
  letter-spacing: .06em;
  /* 常に2行分の高さを確保してレイアウトシフトを防ぐ */
  min-height: calc(var(--vn-font-size, 26px) * 3.7);
  white-space: pre-line;
}

/* 内心ナレーション（*text*） */
#dialog-text.narrate-inner {
  color: rgba(210, 190, 230, 0.72);
}
#dialog-text.narrate-inner em {
  font-style: italic;
  letter-spacing: .10em;
}

/* 締めナレーション（**text**） */
#dialog-text.narrate-climax {
  text-align: center;
  font-size: calc(var(--vn-font-size, 26px) + 6px);
  color: #ffffff;
  letter-spacing: .18em;
  text-shadow: 0 0 18px rgba(255, 200, 240, 0.5);
  animation: climax-fadein 1.2s ease forwards;
}
@keyframes climax-fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#next-arrow {
  position: absolute;
  right: 22px;
  bottom: 14px;
  color: rgba(255,160,210,.7);
  font-size: 13px;
  display: none;
  animation: arrowBounce 1.1s ease-in-out infinite;
}
@keyframes arrowBounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-5px); }
}

/* ---- 選択肢 ---- */
#choices-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  z-index: 9; /* ui-layer(z-index:10)より下にしてmenu-barを常にクリック可能にする */
}
#choices-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 720px;
}
.choice-btn {
  padding: 20px 44px;
  background: rgba(8, 3, 22, .92);
  border: 1px solid rgba(220,140,190,.5);
  color: #f5eaf0;
  font-size: 19px;
  letter-spacing: .08em;
  cursor: pointer;
  transition: all .3s ease;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.choice-btn::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: 0;
  background: rgba(220,80,160,.18);
  transition: width .3s ease;
}
.choice-btn:hover {
  border-color: rgba(255,170,220,.9);
  color: #fff;
  box-shadow: 0 0 24px rgba(220,80,160,.2);
}
.choice-btn:hover::before { width: 100%; }
@media (hover: none) {
  .choice-btn:hover {
    border-color: rgba(220,140,190,.5);
    color: #f5eaf0;
    box-shadow: none;
  }
  .choice-btn:hover::before {
    width: 0;
  }
}

/* ---- エンディング画面 ---- */
#ending-screen {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #08040e 0%, #12062a 50%, #08040e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  animation: animFadeIn .8s ease forwards;
}
#ending-screen.ending-exit {
  pointer-events: none;
  animation: endingReturnFade 2.8s cubic-bezier(.24, .02, .16, 1) forwards;
}
#ending-screen.ending-exit::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #05020e;
  animation: endingReturnVeil 2.8s cubic-bezier(.24, .02, .16, 1) forwards;
}
#ending-screen.ending-exit #ending-content {
  animation: endingContentDrift 2.8s cubic-bezier(.24, .02, .16, 1) forwards;
}
@keyframes endingReturnFade {
  0% {
    opacity: 1;
    filter: blur(0) brightness(1);
  }
  45% {
    opacity: 0.78;
    filter: blur(5px) brightness(0.82);
  }
  100% {
    opacity: 1;
    filter: blur(0) brightness(0.72);
  }
}
@keyframes endingReturnVeil {
  0% {
    opacity: 0;
  }
  54% {
    opacity: 0.24;
  }
  100% {
    opacity: 1;
  }
}
@keyframes endingContentDrift {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-18px) scale(1.04);
  }
}
#title-screen.title-return-reveal {
  animation: titleReturnReveal 1.6s cubic-bezier(.24, .02, .16, 1) forwards;
}
@keyframes titleReturnReveal {
  0% {
    opacity: 0;
    filter: blur(18px) brightness(0.48);
  }
  100% {
    opacity: 1;
    filter: blur(0) brightness(1);
  }
}
#ending-screen.has-still.good-end-epilogue-bg {
  background: linear-gradient(180deg, rgba(8, 4, 14, 0.42) 0%, rgba(18, 6, 42, 0.52) 52%, rgba(8, 4, 14, 0.68) 100%);
  backdrop-filter: blur(6px) saturate(1.06);
}
#ending-content {
  text-align: center;
  position: relative;
  z-index: 1;
  padding: 40px 56px;
}
#ending-screen.has-still.good-end-epilogue-bg #ending-content {
  background: rgba(10, 6, 18, 0.22);
  border: 1px solid rgba(255, 215, 235, 0.18);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(10px);
  border-radius: 24px;
}
#ending-title {
  font-size: 28px;
  font-weight: 300;
  letter-spacing: .2em;
  color: #ffd0e8;
  text-shadow: 0 0 30px rgba(255,120,180,.6), 0 0 60px rgba(255,80,160,.3);
  margin-bottom: 48px;
  white-space: pre-wrap;
  max-width: 80vw;
  line-height: 1.8;
  word-break: break-all;
}
#btn-ending-title {
  padding: 14px 48px;
  background: transparent;
  border: 1px solid rgba(220,140,190,.5);
  color: rgba(240,200,220,.9);
  font-size: 16px;
  letter-spacing: .3em;
  cursor: pointer;
  transition: all .3s;
}
#btn-ending-title:hover {
  border-color: rgba(255,180,220,.9);
  color: #fff;
  box-shadow: 0 0 20px rgba(220,80,160,.3);
}

/* ---- 次のチャプターへボタン ---- */
#btn-next-chapter {
  display: block;
  margin: 0 auto 20px;
  padding: 14px 48px;
  background: transparent;
  border: 1px solid rgba(140,200,255,.5);
  color: rgba(180,220,255,.9);
  font-size: 16px;
  letter-spacing: .3em;
  cursor: pointer;
  transition: all .3s;
}
#btn-next-chapter:hover {
  border-color: rgba(180,220,255,.9);
  color: #fff;
  box-shadow: 0 0 20px rgba(80,160,255,.3);
}

/* ---- クレジットロール ---- */
#credits-screen {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 35;
  overflow: hidden;
}
#credits-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(255, 240, 220, 0.08) 0%, rgba(0, 0, 0, 0) 52%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.8) 0%, rgba(10, 7, 4, 0.3) 24%, rgba(0, 0, 0, 0.58) 100%);
  pointer-events: none;
  z-index: 0;
}
#credits-memory-stage {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.credits-memory-card {
  position: absolute;
  inset: 11% 17%;
  opacity: 0;
  transform: scale(1.045);
  transition:
    opacity 1.3s ease,
    transform 7.8s ease,
    filter 1.3s ease;
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: sepia(0.75) saturate(0.8) brightness(0.48) contrast(1.1) grayscale(0.12);
}
.credits-memory-card::before {
  content: '';
  position: absolute;
  inset: -3%;
  background:
    linear-gradient(180deg, rgba(24, 15, 10, 0.08) 0%, rgba(0, 0, 0, 0.35) 100%),
    radial-gradient(circle at center, rgba(0, 0, 0, 0) 38%, rgba(0, 0, 0, 0.68) 100%);
  box-shadow:
    inset 0 0 100px rgba(0, 0, 0, 0.72),
    0 0 60px rgba(0, 0, 0, 0.45);
}
.credits-memory-card.active {
  opacity: 0.72;
  transform: scale(1);
  filter: sepia(0.92) saturate(0.74) brightness(0.58) contrast(1.08) grayscale(0.08);
}
.credits-memory-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 34px;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: rgba(255, 242, 225, 0.62);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.9);
}
#credits-lyrics {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  text-align: right;
  color: rgba(255, 244, 232, 0.78);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.95);
}
#credits-lyrics {
  right: 38px;
  bottom: 76px;
  width: min(340px, 28vw);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.75;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.7s ease;
  white-space: pre-line;
  background: linear-gradient(180deg, rgba(18, 10, 8, 0.52) 0%, rgba(0, 0, 0, 0.18) 100%);
  backdrop-filter: blur(3px);
}
#credits-lyrics.visible {
  opacity: 1;
}
#credits-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 4;
}
#credits-roll {
  position: absolute;
  width: 100%;
  text-align: center;
  padding: 0 60px;
  box-sizing: border-box;
  will-change: transform;
  z-index: 4;
}
.credits-game-title {
  font-size: 32px;
  font-weight: 300;
  letter-spacing: .5em;
  color: #ffd0e8;
  text-shadow: 0 0 30px rgba(255,120,180,.7), 0 0 70px rgba(255,80,160,.4);
  margin-bottom: 12px;
  padding-top: 8px;
}
.credits-heading {
  font-size: 11px;
  letter-spacing: .4em;
  color: rgba(255,255,255,.4);
  text-transform: uppercase;
  margin-bottom: 10px;
  margin-top: 56px;
}
.credits-name {
  font-size: 20px;
  font-weight: 300;
  letter-spacing: .25em;
  color: rgba(255,255,255,.88);
  margin-bottom: 6px;
}
.credits-sub {
  font-size: 12px;
  letter-spacing: .15em;
  color: rgba(255,255,255,.35);
  margin-bottom: 4px;
}
.credits-thanks {
  font-size: 22px;
  font-weight: 300;
  letter-spacing: .5em;
  color: rgba(255,220,240,.7);
  margin-top: 32px;
}
.credits-spacer {
  height: 32px;
}
.credits-logo {
  text-align: center;
  padding: 20px 0;
}
.credits-logo img {
  max-width: 260px;
  width: 60%;
  opacity: 0.9;
}
#btn-credits-skip {
  position: absolute;
  bottom: 28px;
  right: 32px;
  padding: 8px 24px;
  background: transparent;
  border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.4);
  font-size: 12px;
  letter-spacing: .3em;
  cursor: pointer;
  transition: all .25s;
  z-index: 5;
}
#btn-credits-skip:hover {
  border-color: rgba(255,255,255,.5);
  color: rgba(255,255,255,.8);
}
@keyframes creditsScroll {
  from { transform: translateY(var(--credits-start)); }
  to   { transform: translateY(var(--credits-end)); }
}

/* ---- モーダル共通 ---- */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}
.modal-inner {
  background: linear-gradient(180deg, rgba(14, 8, 30, .985), rgba(6, 4, 16, .985));
  border: 1px solid rgba(245,180,215,.62);
  padding: 32px 36px;
  width: 640px;
  max-height: 80%;
  overflow-y: auto;
  box-shadow: 0 28px 90px rgba(0,0,0,.58), inset 0 1px 0 rgba(255,255,255,.06);
}
.modal-inner h2 {
  color: #ffaac8;
  font-size: 18px;
  letter-spacing: .35em;
  margin-bottom: 24px;
  text-align: center;
  border-bottom: 1px solid rgba(220,140,190,.3);
  padding-bottom: 14px;
}
.modal-close-btn {
  display: block;
  margin: 24px auto 0;
  padding: 10px 36px;
  background: transparent;
  border: 1px solid rgba(220,140,190,.45);
  color: rgba(240,190,220,.85);
  font-size: 14px;
  letter-spacing: .25em;
  cursor: pointer;
  transition: all .2s;
}
.modal-close-btn:hover {
  background: rgba(220,80,160,.2);
  border-color: rgba(255,180,220,.9);
  color: #fff;
}

/* ---- セーブ/ロードスロット ---- */
.save-slot {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  border: 1px solid rgba(220,140,190,.25);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all .2s;
}
.save-slot:hover {
  background: rgba(220,80,160,.12);
  border-color: rgba(255,170,220,.7);
}
.slot-num {
  font-size: 11px;
  color: #cc88aa;
  min-width: 52px;
  letter-spacing: .1em;
}
.slot-info { flex: 1; }
.slot-label   { font-size: 14px; color: #f5eaf0; margin-bottom: 3px; }
.slot-preview { font-size: 12px; color: rgba(255,255,255,.45); }
.slot-date  { font-size: 11px; color: rgba(255,255,255,.35); }
.slot-empty { font-size: 13px; color: rgba(255,255,255,.25); }

.quick-save-slot {
  border-color: rgba(255, 196, 224, 0.52);
  background: linear-gradient(90deg, rgba(255, 147, 188, 0.14), rgba(255, 255, 255, 0.035));
  box-shadow: inset 3px 0 0 rgba(255, 147, 188, 0.72), 0 0 18px rgba(255, 151, 196, 0.1);
}
.quick-save-slot .slot-num {
  color: rgba(255, 210, 232, 0.96);
}
.quick-save-slot:hover {
  background: linear-gradient(90deg, rgba(255, 147, 188, 0.24), rgba(255, 255, 255, 0.06));
  border-color: rgba(255, 220, 238, 0.86);
}

/* ---- テキストログ ---- */
#log-content {
  max-height: 380px;
  overflow-y: auto;
  font-size: 15px;
  line-height: 2;
  color: #f0e0ea;
}
.log-entry {
  padding: 6px 0;
  border-bottom: 1px solid rgba(220,140,190,.1);
}
.log-name {
  font-weight: bold;
  margin-right: 12px;
}

/* ---- ギャラリー ---- */
#gallery-content {
  min-height: 200px;
}

.cg-total-count {
  font-size: 11px;
  letter-spacing: .1em;
  color: rgba(255,255,255,0.3);
  text-align: right;
  margin-bottom: 10px;
}

.cg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.cg-thumb {
  cursor: default;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
}

.cg-thumb.unlocked {
  cursor: pointer;
}

.cg-thumb.unlocked:hover .cg-thumb-img {
  filter: brightness(1.15);
}

.cg-thumb-img {
  width: 100%;
  aspect-ratio: 16/9;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: filter .2s;
}

.cg-thumb-locked {
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: rgba(255,255,255,0.15);
}

.cg-thumb-label {
  font-size: 10px;
  text-align: center;
  padding: 4px 4px 5px;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cg-label-locked {
  color: rgba(255,255,255,0.2);
}

/* ---- ギャラリービューア (フルスクリーン拡大) ---- */
#gallery-viewer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gallery-viewer-bg {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
  cursor: pointer;
}

#gallery-viewer-img {
  position: relative;
  width: 90vw;
  max-width: 1200px;
  aspect-ratio: 16/9;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

#gallery-viewer-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  line-height: 36px;
  text-align: center;
  transition: background .2s;
}

#gallery-viewer-close:hover {
  background: rgba(255,255,255,0.2);
}

/* ---- ユーティリティ ---- */
.hidden { display: none !important; }

/* ============================================================
   オープニング動画
============================================================ */
#intro-video-screen {
  position: absolute;
  inset: 0;
  z-index: 300;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.8s ease;
}
#intro-video-screen.fade-out {
  opacity: 0;
}
#intro-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#intro-skip-hint {
  position: absolute;
  bottom: 22px;
  right: 30px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 13px;
  font-family: 'Yu Gothic UI', sans-serif;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* ============================================================
   オープニングモノローグ
============================================================ */
#opening-screen {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.8s ease;
}
#opening-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
#opening-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.4;
}
#opening-text-area {
  position: relative;
  z-index: 1;
  max-width: 700px;
  width: 90%;
  text-align: center;
  /* 固定高さをここで確保することでレイアウトシフトを防ぐ */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  height: 160px;
}
#opening-text {
  color: rgba(255, 255, 255, 0.93);
  font-family: var(--vn-serif-font);
  font-size: 18px;
  line-height: 2.5;
  letter-spacing: 0.12em;
  text-shadow:
    0 0 32px rgba(160, 120, 220, 0.65),
    0 2px 10px rgba(0, 0, 0, 0.9);
  transition: opacity 0.45s ease;
  /* display: flex を外してインラインテキストの流れを正常に保つ */
}
#opening-text strong {
  color: #e8b8ff;
  font-weight: normal;
  white-space: nowrap;
}
#opening-arrow {
  color: rgba(255, 255, 255, 0.38);
  font-size: 15px;
  animation: opening-arrow-pulse 1.4s ease-in-out infinite;
  visibility: hidden; /* display ではなく visibility でレイアウトシフトを防ぐ */
}
@keyframes opening-arrow-pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50%       { opacity: 0.65; transform: translateY(5px); }
}
#opening-skip-hint {
  position: absolute;
  bottom: 22px;
  right: 30px;
  color: rgba(255, 255, 255, 0.28);
  font-size: 12px;
  font-family: 'Yu Gothic UI', sans-serif;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* ============================================================
   カスタムカーソル
============================================================ */
@media (hover: hover) and (pointer: fine) {
  * { cursor: none !important; }
}

@media (hover: none) and (pointer: coarse) {
  #game-screen,
  #game-screen * {
    cursor: none !important;
  }
}

#custom-cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 2000000; /* デバッグパネル(1000000)より常に上 */
}

/* 4芒星本体: top/left で中央寄せ (アニメーションに translate を混在させない) */
.cursor-core {
  position: absolute;
  width: 22px;
  height: 22px;
  top: -11px;   /* -(22 / 2) */
  left: -11px;
  clip-path: polygon(50% 0%, 59% 41%, 100% 50%, 59% 59%, 50% 100%, 41% 59%, 0% 50%, 41% 41%);
  background: linear-gradient(135deg, #fff9fc 0%, #ffb8e2 45%, #cc66ff 100%);
  filter:
    drop-shadow(0 0 5px rgba(255, 150, 225, 1))
    drop-shadow(0 0 12px rgba(200, 80, 255, 0.7));
  animation: cursorSpin 3.5s linear infinite;
}
@keyframes cursorSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* 外周リング */
.cursor-ring {
  position: absolute;
  width: 34px;
  height: 34px;
  top: -17px;   /* -(34 / 2) */
  left: -17px;
  border-radius: 50%;
  border: 1px solid rgba(255, 160, 225, 0.7);
  box-shadow: 0 0 6px rgba(200, 80, 255, 0.35);
  animation: cursorRingPulse 2.4s ease-in-out infinite;
}
@keyframes cursorRingPulse {
  0%, 100% { transform: scale(1);   opacity: 0.6; }
  50%       { transform: scale(1.6); opacity: 0.05; }
}

/* トレイルスパークル */
.cursor-sparkle {
  position: fixed;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1999999; /* カーソル(2000000)の直下 */
  transform: translate(-50%, -50%);
  animation: sparkleFloat 0.6s ease-out forwards;
}
@keyframes sparkleFloat {
  0%   { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0;   transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.1); }
}

/* ---- スクロールバー ---- */
.touch-star {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 45;
  pointer-events: none;
  line-height: 1;
  text-shadow:
    0 0 7px rgba(255, 255, 255, 0.95),
    0 0 16px rgba(255, 185, 225, 0.9);
  transform: translate(-50%, -50%);
  animation: touchStarBurst 0.82s ease-out forwards;
}
@keyframes touchStarBurst {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) scale(0.7) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2) rotate(var(--rot));
  }
}

::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.2); }
::-webkit-scrollbar-thumb { background: rgba(220,140,190,.45); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,160,210,.7); }

/* ============================================================
   レスポンシブ: 画面サイズに合わせてスケール
============================================================ */
@media screen {
  body { align-items: center; }
}

/* ---- カスタム確認ダイアログ ---- */
.confirm-inner {
  max-width: 400px !important;
  text-align: center;
}
#confirm-message {
  color: #f0e0ea;
  font-size: 15px;
  line-height: 2;
  letter-spacing: .08em;
  white-space: pre-line;
  margin-bottom: 28px;
}
.confirm-buttons {
  display: flex;
  justify-content: center;
  gap: 24px;
}
.confirm-btn {
  padding: 10px 40px;
  background: transparent;
  border: 1px solid rgba(220,140,190,.45);
  color: rgba(220,170,210,.9);
  font-size: 14px;
  letter-spacing: .25em;
  cursor: pointer;
  transition: all .2s;
}
.confirm-btn:hover {
  background: rgba(220,80,160,.18);
  border-color: rgba(255,170,220,.9);
  color: #fff;
}
.confirm-ok  { border-color: rgba(180,100,230,.6); }
.confirm-no  { border-color: rgba(160,120,180,.4); }

/* ---- 設定モーダル ---- */
.settings-list {
  padding: 10px 0 20px;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(220,140,190,.12);
}
.settings-label {
  font-size: 13px;
  color: #f0b9d3;
  letter-spacing: .1em;
  min-width: 90px;
  text-shadow: 0 1px 10px rgba(0,0,0,.75);
}
.settings-options {
  display: flex;
  gap: 10px;
}
.settings-opt {
  padding: 7px 18px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(245,180,215,.46);
  color: rgba(255,228,242,.88);
  font-size: 12px;
  letter-spacing: .12em;
  cursor: pointer;
  transition: all .2s;
}
.settings-opt:hover {
  background: rgba(220,80,160,.12);
  border-color: rgba(255,170,220,.7);
  color: #fff;
}
.settings-opt.active {
  background: rgba(236,110,178,.34);
  border-color: rgba(255,210,236,.86);
  color: #fff8fc;
  box-shadow: 0 0 14px rgba(236,110,178,.22);
}
.settings-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 180px;
  height: 4px;
  border-radius: 2px;
  background: rgba(245,180,215,.42);
  outline: none;
  cursor: pointer;
}
.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(200,120,255,.85);
  cursor: pointer;
  border: none;
}
.settings-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(200,120,255,.85);
  cursor: pointer;
  border: none;
}
.settings-slider-value {
  font-size: 12px;
  color: rgba(255,232,244,.86);
  min-width: 28px;
  text-align: right;
}
.settings-palette {
  display: flex;
  gap: 10px;
  align-items: center;
}
.palette-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.2);
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.palette-swatch:hover {
  transform: scale(1.15);
  border-color: rgba(255,255,255,.6);
}
.palette-swatch.active {
  border-color: rgba(200,120,255,.9);
  box-shadow: 0 0 8px rgba(180,80,255,.5);
  transform: scale(1.15);
}

@media (max-width: 768px) {
  .credits-memory-card {
    inset: 14% 7% 22%;
  }

  .credits-memory-label {
    bottom: 22px;
    font-size: 10px;
    letter-spacing: 0.16em;
  }

  #credits-lyrics {
    right: 16px;
    bottom: 84px;
    width: min(230px, calc(100% - 32px));
    padding: 10px 12px;
    font-size: 10px;
    line-height: 1.65;
    letter-spacing: 0.06em;
  }
}

@media (hover: none) and (pointer: coarse) {
  .menu-key {
    display: none;
  }

  #menu-bar {
    top: 14px;
    right: 10px;
    width: 72px;
    height: 72px;
  }

  .radial-tab {
    width: 62px;
    height: 62px;
    min-height: 62px;
    color: rgba(255, 246, 250, 0.94);
    background: linear-gradient(180deg, rgba(35, 21, 57, 0.96), rgba(13, 9, 24, 0.92));
    border-color: rgba(255, 216, 235, 0.52);
    opacity: 1;
  }

  .menu-icon {
    width: 20px;
    height: 14px;
  }

  .menu-icon::before,
  .menu-icon::after,
  .menu-icon span {
    width: 20px;
    height: 2.5px;
    background: rgba(255, 248, 251, 0.94);
  }

  .menu-icon span { top: 6px; }
  .menu-icon::after { top: 12px; }

  .menu-label {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 244, 249, 0.94);
  }

  .radial-item {
    min-width: 124px;
    min-height: 52px;
    font-size: 14px;
    background: rgba(18, 10, 32, 0.94);
  }

  .modal-inner {
    width: min(92vw, 680px);
    padding: 34px 38px;
    background: linear-gradient(180deg, rgba(18, 10, 36, .992), rgba(7, 4, 18, .992));
    border-color: rgba(255, 204, 232, .76);
  }

  .modal-inner h2 {
    font-size: 20px;
    color: #ffc4dc;
  }

  .save-slot {
    padding: 18px 20px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.045);
    border-color: rgba(255, 204, 232, 0.38);
  }

  .slot-num {
    font-size: 13px;
    color: rgba(255, 198, 226, 0.96);
  }

  .slot-label {
    font-size: 16px;
    color: #fff6fb;
  }

  .slot-preview {
    font-size: 14px;
    color: rgba(255, 255, 255, .68);
  }

  .slot-date {
    font-size: 12px;
    color: rgba(255, 230, 242, .58);
  }

  .slot-empty {
    font-size: 15px;
    color: rgba(255, 232, 244, .58);
  }

  .modal-close-btn {
    min-height: 44px;
    font-size: 16px;
    color: rgba(255, 226, 240, .94);
    border-color: rgba(255, 204, 232, .58);
  }

  .settings-row {
    gap: 16px;
    padding: 16px 0;
  }

  .settings-label {
    font-size: 14px;
  }

  .settings-opt {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 13px;
  }

  #title-bg,
  #title-stars,
  #title-logo-img,
  #title-main,
  #title-main::after {
    animation: none;
  }

  #title-main {
    text-shadow:
      0 0 4px rgba(255,255,255,.95),
      0 0 14px rgba(255,165,220,.52),
      0 0 34px rgba(230, 70,170,.28);
  }

  #title-main::after {
    width: 340px;
    opacity: 0.88;
    box-shadow:
      0 0 6px rgba(255, 180, 220, .7),
      0 0 18px rgba(220, 50, 160, .26);
  }

  #title-logo-img {
    filter: drop-shadow(0 0 8px rgba(255,130,195,.22));
  }

  #next-arrow {
    animation: arrowFadePulse 2.1s ease-in-out infinite;
  }

  #opening-arrow {
    animation-duration: 2.2s;
  }

  #scene-wipe,
  #credits-roll {
    will-change: auto;
  }

  #game-container {
    box-shadow: 0 0 40px rgba(200, 100, 180, 0.16);
  }
}

@media (prefers-reduced-motion: reduce) {
  #title-bg,
  #title-stars,
  #title-logo-img,
  #title-main,
  #title-main::after,
  #next-arrow,
  #opening-arrow,
  .cursor-core,
  .cursor-ring,
  .cursor-sparkle {
    animation: none !important;
  }

  #scene-wipe,
  #credits-roll {
    will-change: auto;
  }
}

@keyframes arrowFadePulse {
  0%, 100% { opacity: 0.24; }
  50% { opacity: 0.72; }
}
