/* ==================================================================
   お母さんへの誕生日サイト ― style.css
   テーマ：暖かいベージュ × くすみピンク × 絵本のような手紙
   ================================================================== */

/* ---------- カスタムプロパティ（テーマカラー） ---------- */
:root {
  --color-bg: #F8F4EA;          /* 背景：暖かいベージュ */
  --color-text: #5A4033;        /* 文字：濃いブラウン */
  --color-text-soft: #7A5C4B;   /* 文字：柔らかいブラウン */
  --color-accent: #C97B8C;      /* アクセント：くすみピンク */
  --color-accent-deep: #B76E79; /* アクセント（濃） */
  --color-gold: #E8B45C;        /* きらめき：ゴールド */
  --color-paper: #FFFDF8;       /* 紙の色 */
  --color-night: #1B1330;       /* 夜空 */
  --color-night-deep: #0E0A1C;  /* 夜空（深） */
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-inout: cubic-bezier(0.65, 0, 0.35, 1);
  --font-serif: "Shippori Mincho", serif;
  --font-hand: "Zen Kurenaido", "Yuji Syuku", sans-serif;
  --font-title: "Yuji Syuku", serif;
}

/* ---------- リセット ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  background: var(--color-bg);
}

body {
  font-family: var(--font-serif);
  color: var(--color-text);
  background: var(--color-bg);
  overflow-x: hidden;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* スクリーンリーダー専用テキスト */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* 背景の光の粒子キャンバス（全シーン共通で薄く漂う） */
#bg-particles {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  opacity: 0.6;
}

/* ==================================================================
   共通：シーン基本スタイル
   ================================================================== */
.scene {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
}

/* ==================================================================
   Scene1：暗闇 → 紙が破れる
   ================================================================== */
.scene--dark {
  /* Scene1は常に画面全体を覆う固定レイヤーとして表示し、
     破れた後にフェードして下のシーンへスクロールを解放する */
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--color-night-deep);
  height: 100vh;
  min-height: 100vh;
  cursor: pointer;
  transition: opacity 0.9s var(--ease-soft);
}

/* 破り終わったあとに完全に隠す */
.scene--dark.is-hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Scene1が表示されている間は、他のシーンへのスクロールを禁止 */
html.scroll-locked,
body.scroll-locked {
  overflow: hidden;
  height: 100%;
}

.scene1-inner {
  position: relative;
  z-index: 3;
  text-align: center;
  color: #F3E9DE;
  padding: 0 6vw;
  animation: fadeInSoft 1.8s var(--ease-soft) both;
}

.scene1-title {
  font-family: var(--font-title);
  font-size: clamp(2rem, 8vw, 3.2rem);
  letter-spacing: 0.12em;
  margin-bottom: 1.4rem;
  color: #FBF3EA;
}

.scene1-tap {
  font-family: var(--font-hand);
  font-size: clamp(1rem, 4vw, 1.25rem);
  letter-spacing: 0.06em;
  opacity: 0.9;
  margin-bottom: 0.6rem;
}

.scene1-note {
  font-family: var(--font-hand);
  font-size: clamp(0.75rem, 3vw, 0.9rem);
  opacity: 0.55;
}

/* タップを促す波紋アニメーション */
.tap-pulse {
  width: 70px;
  height: 70px;
  margin: 2.2rem auto 0;
  border-radius: 50%;
  border: 1.5px solid rgba(243, 233, 222, 0.55);
  animation: pulseRing 2.2s ease-out infinite;
}

@keyframes pulseRing {
  0%   { transform: scale(0.6); opacity: 0.9; }
  70%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}

@keyframes fadeInSoft {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 紙が破れるレイヤー（初期状態は完全に非表示。タップした瞬間にのみ現れて裂ける） */
.paper-tear {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0; /* 破る演出の直前まで見せない＝画面は暗闇のまま */
  transition: opacity 0.05s linear;
}

body.tearing .paper-tear {
  opacity: 1;
}

.paper-half {
  position: absolute;
  top: -5%;
  width: 55%;
  height: 110%;
  /* 紙自体も「暗闇の続き」に見えるよう、暗い色合いにしておき、
     裂けた切れ目からだけ内側の暖かい光（tear-light）が漏れるようにする */
  background: var(--color-night-deep);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(201,123,140,0.10), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(232,180,92,0.10), transparent 45%);
  will-change: transform, opacity;
}

.paper-left {
  left: 0;
  transform-origin: left center;
  clip-path: polygon(
    0% 0%, 100% 0%,
    92% 4%, 96% 9%, 90% 14%, 97% 19%, 89% 25%, 95% 31%,
    88% 37%, 96% 43%, 90% 49%, 97% 55%, 88% 61%, 95% 67%,
    90% 73%, 96% 79%, 89% 85%, 95% 91%, 91% 96%, 100% 100%,
    0% 100%
  );
}

.paper-right {
  right: 0;
  transform-origin: right center;
  clip-path: polygon(
    8% 0%, 100% 0%, 100% 100%, 8% 100%,
    12% 96%, 5% 91%, 11% 85%, 4% 79%, 10% 73%,
    3% 67%, 12% 61%, 4% 55%, 10% 49%, 3% 43%,
    11% 37%, 5% 31%, 12% 25%, 3% 19%, 10% 14%, 4% 9%, 8% 4%
  );
}

.tear-light {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 0;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(255, 231, 190, 0.95), rgba(255, 231, 190, 0) 70%);
  filter: blur(2px);
  opacity: 0;
}

/* 破る瞬間に付与されるクラス：JS制御 */
body.tearing .paper-left  { animation: tearLeft 1.1s var(--ease-inout) forwards; }
body.tearing .paper-right { animation: tearRight 1.1s var(--ease-inout) forwards; }
body.tearing .tear-light  { animation: tearLightIn 1.1s ease-out forwards; }
body.tearing .scene1-inner{ animation: fadeOutSoft 0.5s ease forwards; }

@keyframes tearLeft {
  0%   { transform: translateX(0) rotate(0deg); }
  100% { transform: translateX(-105%) rotate(-8deg); }
}
@keyframes tearRight {
  0%   { transform: translateX(0) rotate(0deg); }
  100% { transform: translateX(105%) rotate(8deg); }
}
@keyframes tearLightIn {
  0%   { width: 0; opacity: 0; }
  40%  { opacity: 1; }
  100% { width: 140vw; opacity: 0; }
}
@keyframes fadeOutSoft {
  to { opacity: 0; }
}

/* ==================================================================
   Scene2：タイトル
   ================================================================== */
.scene--title {
  background: linear-gradient(180deg, #FBF6EC 0%, var(--color-bg) 100%);
  flex-direction: column;
  text-align: center;
  padding: 8vh 6vw;
}

.deco-sky {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.title-block {
  position: relative;
  z-index: 2;
}

.title-sub {
  font-family: var(--font-title);
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  color: var(--color-accent);
  letter-spacing: 0.08em;
  opacity: 0;
  animation: dropIn 1s var(--ease-soft) 0.2s both;
}

.title-main {
  font-family: var(--font-title);
  font-size: clamp(2.6rem, 13vw, 5.5rem);
  color: var(--color-text);
  letter-spacing: 0.06em;
  margin-top: 0.4rem;
  opacity: 0;
  animation: dropIn 1.1s var(--ease-soft) 0.55s both;
  text-shadow: 0 6px 24px rgba(201,123,140,0.18);
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-26px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.scroll-hint {
  margin-top: 3.2rem;
  font-family: var(--font-hand);
  font-size: 0.95rem;
  color: var(--color-text-soft);
  opacity: 0;
  animation: dropIn 1s var(--ease-soft) 1.4s both, floatY 2.6s ease-in-out 2.4s infinite;
}

@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(8px); }
}

/* 花・風船・キラキラの共通ふわふわ揺れ */
.deco-item {
  position: absolute;
  will-change: transform;
  opacity: 0.9;
}

@keyframes swayFloat {
  0%   { transform: translate(0, 0) rotate(0deg); }
  50%  { transform: translate(var(--swayX, 8px), var(--swayY, -14px)) rotate(var(--swayR, 4deg)); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1.15); }
}

/* ==================================================================
   Scene3：手紙
   ================================================================== */
.scene--letter {
  background: var(--color-bg);
  align-items: flex-start;
  padding: 10vh 5vw 14vh;
}

.letter-paper {
  position: relative;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  background: var(--color-paper);
  border-radius: 6px;
  padding: 8vh 7vw;
  box-shadow:
    0 2px 4px rgba(90, 64, 51, 0.05),
    0 20px 50px rgba(90, 64, 51, 0.10);
  background-image:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 2.7em,
      rgba(201,123,140,0.08) 2.7em,
      rgba(201,123,140,0.08) calc(2.7em + 1px)
    );
}

.letter-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 3rem;
}

.letter-flower {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  animation: gentleSpin 8s linear infinite;
}

@keyframes gentleSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.letter-to {
  font-family: var(--font-hand);
  font-size: 1.15rem;
  color: var(--color-text-soft);
  letter-spacing: 0.04em;
}

.letter-body {
  display: flex;
  flex-direction: column;
  gap: 1.7rem;
}

.letter-line {
  font-family: var(--font-hand);
  font-size: clamp(1.05rem, 3.6vw, 1.4rem);
  color: var(--color-text);
  line-height: 2.1;
  position: relative;
  /* 手書き風：文字を1文字ずつ表示するための土台。JSでspanに分割し、
     clip-pathで「万年筆が滑る」ような表示にする */
  opacity: 0;
}

.letter-line.is-visible {
  opacity: 1;
}

.letter-line .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(6px);
  filter: blur(2px);
  transition: opacity 0.45s var(--ease-soft), transform 0.45s var(--ease-soft), filter 0.45s var(--ease-soft);
}

.letter-line .char.ink-in {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
}

.letter-line--big {
  font-family: var(--font-title);
  font-size: clamp(1.5rem, 5.4vw, 2.1rem);
  color: var(--color-accent-deep);
  margin-top: 1rem;
}

.letter-sign {
  margin-top: 4rem;
  text-align: right;
  font-family: var(--font-hand);
  color: var(--color-text-soft);
  font-size: 1rem;
  opacity: 0;
  transition: opacity 1.2s ease;
}

.letter-sign.is-visible { opacity: 0.85; }

/* ==================================================================
   Scene4：プレゼント
   ================================================================== */
.scene--gift {
  background: linear-gradient(180deg, var(--color-bg) 0%, #FBEFE3 100%);
  flex-direction: column;
  text-align: center;
}

.gift-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gift-box {
  position: relative;
  width: min(58vw, 260px);
  height: min(58vw, 260px);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(1);
  transition: transform 0.35s var(--ease-soft);
}

.gift-box:active { transform: scale(0.94); }

.gift-img { width: 100%; height: auto; position: absolute; inset: 0; }

.gift-img--lid {
  transform-origin: 50% 42%;
  transition: transform 0.7s var(--ease-inout), opacity 0.7s ease;
}

/* 箱が揺れて「開けて」とアピールする待機アニメーション */
.gift-box:not(.opened) {
  animation: giftWiggle 2.6s ease-in-out infinite;
}

@keyframes giftWiggle {
  0%, 100% { transform: rotate(0deg); }
  6%  { transform: rotate(-4deg); }
  12% { transform: rotate(4deg); }
  18% { transform: rotate(-2deg); }
  24% { transform: rotate(0deg); }
}

.gift-box.opened .gift-img--lid {
  transform: translateY(-140%) rotate(-25deg) scale(0.9);
  opacity: 0;
}

.gift-box.opened { animation: none; }

.gift-caption {
  margin-top: 2.4rem;
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: var(--color-text-soft);
  letter-spacing: 0.05em;
  animation: floatY 2.2s ease-in-out infinite;
}

.gift-burst {
  position: absolute;
  inset: -40vh -40vw;
  z-index: 5;
  pointer-events: none;
}

/* ==================================================================
   Scene5：夜空・花火・ケーキ・エンディング
   ================================================================== */
.scene--night {
  background: radial-gradient(ellipse at 50% 0%, #241a3f 0%, var(--color-night) 45%, var(--color-night-deep) 100%);
  flex-direction: column;
  min-height: 100vh;
  padding: 10vh 5vw;
  overflow: hidden;
}

#fireworks-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.night-title {
  position: relative;
  z-index: 2;
  text-align: center;
  color: #FBF3EA;
  opacity: 0;
  transition: opacity 1.4s ease;
  margin-bottom: 6vh;
}

.night-title.is-visible { opacity: 1; }

.night-sub {
  font-family: var(--font-title);
  font-size: clamp(1.3rem, 5vw, 2rem);
  color: var(--color-gold);
  letter-spacing: 0.1em;
}

.night-main {
  font-family: var(--font-title);
  font-size: clamp(2.6rem, 12vw, 5rem);
  letter-spacing: 0.06em;
  margin-top: 0.3rem;
  text-shadow: 0 0 30px rgba(232,180,92,0.35);
}

.cake-stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.candle-hit {
  position: relative;
  width: min(64vw, 280px);
}

.cake-img {
  width: 100%;
  filter: drop-shadow(0 10px 26px rgba(0,0,0,0.35));
}

/* ロウソクの火：ケーキSVG上の炎の位置に重ねる */
.candle-flame {
  position: absolute;
  left: 49%;
  top: 2%;
  width: 10px;
  height: 16px;
  background: radial-gradient(circle at 50% 30%, #FFE9B0, var(--color-gold) 60%, #C97B8C 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transform: translate(-50%, 0);
  transform-origin: 50% 90%;
  animation: flicker 1.4s ease-in-out infinite;
  box-shadow: 0 0 14px 4px rgba(232,180,92,0.55);
}

@keyframes flicker {
  0%, 100% { transform: translate(-50%, 0) scale(1) rotate(0deg); }
  25% { transform: translate(-50%, 0) scale(1.08, 0.94) rotate(-4deg); }
  50% { transform: translate(-50%, 0) scale(0.94, 1.08) rotate(3deg); }
  75% { transform: translate(-50%, 0) scale(1.05, 0.97) rotate(-2deg); }
}

.candle-flame.blown-out {
  animation: none;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.candle-smoke {
  position: absolute;
  left: 49%;
  top: 0%;
  width: 6px;
  height: 6px;
  transform: translate(-50%, 0);
  opacity: 0;
  pointer-events: none;
}

.candle-smoke.rising {
  animation: smokeRise 1.6s ease-out forwards;
}

@keyframes smokeRise {
  0%   { opacity: 0.5; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-30%, -60px) scale(4); }
}

.cake-caption {
  margin-top: 2rem;
  font-family: var(--font-hand);
  color: #EADFCB;
  font-size: 1rem;
  opacity: 0.85;
}

/* ラストメッセージ */
.final-message {
  position: relative;
  z-index: 2;
  text-align: center;
  margin-top: 8vh;
  min-height: 14vh;
}

.final-line {
  font-family: var(--font-title);
  color: #FBF3EA;
  font-size: clamp(1.3rem, 5vw, 2.1rem);
  opacity: 0;
  letter-spacing: 0.08em;
}

.final-line--1.show {
  animation: dropIn 1.6s var(--ease-soft) forwards;
}

.final-line--2 {
  margin-top: 1.2rem;
  color: var(--color-gold);
  font-size: clamp(1rem, 4vw, 1.5rem);
}

.final-line--2.show {
  animation: dropIn 1.6s var(--ease-soft) 0.6s forwards;
}

/* ==================================================================
   ミュートボタン（常設・全シーン共通）
   ================================================================== */
.mute-btn {
  position: fixed;
  right: max(4vw, 18px);
  bottom: max(4vh, 18px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.85);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(90,64,51,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.3s var(--ease-soft);
}

.mute-btn.visible { opacity: 1; pointer-events: auto; }
.mute-btn:active { transform: scale(0.9); }

.mute-icon {
  font-size: 1.3rem;
  color: var(--color-accent-deep);
}

.mute-btn[aria-pressed="true"] .mute-icon {
  opacity: 0.35;
}

/* ==================================================================
   紙吹雪・クラッカー・花びら等 汎用パーティクル
   ================================================================== */
.particle {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 40;
  will-change: transform, opacity;
}

/* ==================================================================
   レスポンシブ調整
   ================================================================== */
@media (max-width: 480px) {
  .letter-paper { padding: 7vh 6vw; }
  .letter-body { gap: 1.4rem; }
}

@media (min-width: 900px) {
  .letter-paper { padding: 9vh 8vw; }
  .letter-line { font-size: 1.5rem; }
}

/* 縦画面が極端に低い端末向けの余白調整 */
@media (max-height: 560px) {
  .scene { min-height: 100vh; padding-top: 4vh; padding-bottom: 4vh; }
}

/* prefers-reduced-motion 対応：アニメーションを減らす */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
