/* 水月 続編 〜残月の約束〜 UI */

@import url('https://fonts.googleapis.com/css2?family=Shippori+Mincho:wght@400;500;700&display=swap');

:root {
  --paper: rgba(16, 14, 24, 0.78);
  --accent: #9db8d2;
  --gold: #cdb98a;
  --text: #f2efe9;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  background: #0a0a12;
  font-family: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  color: var(--text);
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  user-select: none;
}

.hidden { display: none !important; }

/* ---------- 背景（クロスフェード2層 + 視差） ---------- */

.bg-layer {
  position: absolute;
  inset: -2.5%;
  width: 105%;
  height: 105%;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 1.4s ease;
  will-change: transform, opacity;
}
.bg-layer.visible { opacity: 1; }

/* CG・タイトル絵は一枚絵。スマホ縦でも全体が見えるよう cover ではなく contain で表示する。
   余白(上下/左右)は #bg-blur が透けるよう背景色は透明にする。視差オーバースキャンも無効化。 */
.bg-layer.cg-fit {
  inset: 0;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-color: transparent;
}

/* CG表示時の余白を、同じ画像をぼかして cover で敷いて自然に埋める背景レイヤー */
#bg-blur {
  position: absolute;
  inset: 0;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  filter: blur(26px) brightness(0.5) saturate(1.1);
  transform: scale(1.12);          /* blurの縁が透けないよう少し拡大 */
  opacity: 0;
  transition: opacity 1.0s ease;
  will-change: opacity;
  pointer-events: none;
}
#bg-blur.visible { opacity: 1; }

#bg-dim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5,5,12,0.12) 0%, rgba(5,5,12,0) 35%, rgba(5,5,12,0.34) 100%);
  pointer-events: none;
}

/* 浮遊パーティクル */
#particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.particle {
  position: absolute;
  bottom: -4vh;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  animation: rise linear infinite;
}
@keyframes rise {
  from { transform: translateY(0) translateX(0); opacity: 0; }
  12%  { opacity: 0.7; }
  88%  { opacity: 0.5; }
  to   { transform: translateY(-110vh) translateX(6vw); opacity: 0; }
}

/* 降雪（真夏の雪・タイトル用） */
.particle.snow {
  top: -4vh;
  bottom: auto;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
  animation: fall linear infinite;
}
@keyframes fall {
  from { transform: translateY(0) translateX(0); opacity: 0; }
  10%  { opacity: 0.95; }
  90%  { opacity: 0.8; }
  to   { transform: translateY(112vh) translateX(-5vw); opacity: 0; }
}

/* ---------- 立ち絵（疑似Live2D） ---------- */

#char-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#char-wrap {
  position: absolute;
  left: 50%;
  bottom: -12vh;            /* バストアップ素材の裾はメッセージ窓の下に隠す */
  height: 112vh;
  aspect-ratio: 10 / 7;     /* PS2立ち絵キャンバス 640x448 */
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.7s ease;
  will-change: transform, opacity;
  animation: breath 4.6s ease-in-out infinite;
}
#char-wrap.visible { opacity: 1; }

@keyframes breath {
  0%, 100% { margin-bottom: 0; }
  50%      { margin-bottom: 10px; }
}

.sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  opacity: 0;
  transition: opacity 0.45s ease;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.45));
  will-change: transform, opacity;
}
.sprite.visible { opacity: 1; }

/* 消えかけ演出（雪さんの「揺らぎ」用） */
#char-wrap.fading .sprite.visible {
  opacity: 0.62;
  filter: drop-shadow(0 18px 28px rgba(0,0,0,0.3)) blur(0.6px) brightness(1.12);
}

/* ---------- タイトル画面 ---------- */

#title-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
}

.title-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 42%, rgba(8, 10, 26, 0) 30%, rgba(8, 10, 26, 0.66) 100%);
}

.title-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#game-title {
  font-size: 96px;
  font-weight: 500;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  text-shadow: 0 2px 36px rgba(10, 14, 40, 0.9), 0 0 60px rgba(205, 217, 240, 0.5);
}

#game-subtitle {
  margin-top: 10px;
  font-size: 24px;
  letter-spacing: 0.22em;
  color: #dce6f2;
  text-shadow: 0 2px 18px rgba(10, 14, 40, 0.9);
}

.title-caption {
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: rgba(242, 239, 233, 0.7);
  text-shadow: 0 1px 10px rgba(10, 14, 40, 0.9);
}

.title-menu {
  margin-top: 52px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.title-menu button {
  font-family: inherit;
  font-size: 18px;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  padding: 12px 64px;
  color: var(--text);
  background: rgba(8, 10, 22, 0.55);
  border: 1px solid rgba(205, 185, 138, 0.5);
  cursor: pointer;
  transition: background 0.25s, box-shadow 0.25s;
}
.title-menu button:hover:not(:disabled) {
  background: rgba(205, 185, 138, 0.22);
  box-shadow: 0 0 22px rgba(205, 185, 138, 0.3);
}
.title-menu button:disabled { opacity: 0.35; cursor: default; }

.title-note {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  font-size: 11px;
  color: rgba(242, 239, 233, 0.55);
  letter-spacing: 0.1em;
}

/* ---------- ゲーム画面 ---------- */

#game-screen { position: absolute; inset: 0; z-index: 10; }

#scene-label {
  position: absolute;
  top: 22px;
  left: 28px;
  font-size: 14px;
  letter-spacing: 0.22em;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(10, 10, 20, 0.45);
  padding: 6px 16px;
  border-left: 3px solid var(--gold);
  backdrop-filter: blur(4px);
}

#message-window {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 56px;
  width: min(960px, 93vw);
  min-height: 172px;
  background: var(--paper);
  border: 1px solid rgba(205, 185, 138, 0.35);
  border-radius: 6px;
  padding: 40px 36px 28px;
  backdrop-filter: blur(8px);
  cursor: pointer;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  z-index: 12;
}

#name-plate {
  position: absolute;
  top: -18px;
  left: 24px;
  padding: 6px 26px;
  font-size: 17px;
  letter-spacing: 0.2em;
  background: linear-gradient(135deg, #3d4a66, #232a40);
  border: 1px solid rgba(157, 184, 210, 0.5);
  border-radius: 4px;
  color: #e8eef5;
}

#message-text {
  font-size: 19px;
  line-height: 2;
  letter-spacing: 0.05em;
  min-height: 76px;
  white-space: pre-wrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#next-indicator {
  position: absolute;
  right: 22px;
  bottom: 12px;
  font-size: 13px;
  color: var(--gold);
  animation: blink 1.1s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 0.15; } 50% { opacity: 0.9; } }

/* ---------- 選択肢 ---------- */

#choice-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: rgba(8, 8, 16, 0.5);
  z-index: 20;
  backdrop-filter: blur(2px);
}

#choice-overlay button {
  font-family: inherit;
  font-size: 19px;
  letter-spacing: 0.08em;
  line-height: 1.6;
  padding: 16px 48px;
  min-width: min(640px, 84vw);
  color: var(--text);
  background: rgba(20, 18, 30, 0.88);
  border: 1px solid rgba(157, 184, 210, 0.5);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
#choice-overlay button:hover {
  background: rgba(61, 74, 102, 0.92);
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
}

/* ---------- コントロールバー ---------- */

#control-bar {
  position: absolute;
  right: 18px;
  bottom: 14px;
  display: flex;
  gap: 8px;
  z-index: 25;
}

#control-bar button {
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.15em;
  padding: 6px 14px;
  color: rgba(242, 239, 233, 0.85);
  background: rgba(15, 15, 25, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 3px;
  cursor: pointer;
}
#control-bar button:hover { background: rgba(61, 74, 102, 0.8); }
#control-bar button.active {
  background: rgba(205, 185, 138, 0.3);
  border-color: var(--gold);
  color: #fff;
}

/* ---------- バックログ ---------- */

#backlog {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 14, 0.92);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

#backlog-inner {
  width: min(820px, 90vw);
  height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 28px;
  border: 1px solid rgba(205, 185, 138, 0.3);
  background: rgba(18, 16, 26, 0.9);
}

#backlog-inner h2 {
  font-size: 18px;
  letter-spacing: 0.3em;
  color: var(--gold);
  margin-bottom: 16px;
}

#backlog-list { flex: 1; overflow-y: auto; padding-right: 12px; }

.log-entry { margin-bottom: 14px; line-height: 1.8; font-size: 15px; }
.log-name { color: var(--accent); margin-right: 12px; }

#btn-close-log {
  margin-top: 16px;
  align-self: flex-end;
  font-family: inherit;
  font-size: 14px;
  padding: 8px 32px;
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(157, 184, 210, 0.5);
  cursor: pointer;
}

/* ---------- エンディング ---------- */

#ending-card {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: radial-gradient(ellipse at 50% 40%, rgba(20, 24, 40, 0.88), rgba(5, 5, 10, 0.97));
  animation: fadein 2.4s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

#ending-label {
  font-size: 34px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--text);
  text-shadow: 0 0 30px rgba(157, 184, 210, 0.5);
}

.ending-thanks { font-size: 16px; letter-spacing: 0.5em; color: var(--gold); }

#btn-to-title {
  margin-top: 24px;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0.3em;
  padding: 10px 44px;
  color: var(--text);
  background: transparent;
  border: 1px solid rgba(205, 185, 138, 0.45);
  cursor: pointer;
}
#btn-to-title:hover { background: rgba(205, 185, 138, 0.18); }
