/* -------------------------------------
 * ベーススタイルとリセット
 * ------------------------------------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Shippori Mincho', 'Noto Serif JP', 'Yu Mincho', 'MS PMincho', serif;
  background-color: #050b14;
  color: #fff;
  overflow: hidden;
  /* 初期状態では意図しないズームを防ぐ */
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
}

/* 背景と星空のラッパー */
#sky-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: hidden;
  z-index: 1;
  /* iOS等でタッチを確実に拾うためプラス値に設定 */
  -webkit-overflow-scrolling: touch;
  /* iOSでの滑らかなスクロール用 */
  display: flex;
  align-items: center;
  /* 縦方向の中央寄せ（全景表示時に上下黒帯を作るため） */
  justify-content: flex-start;
  /* 初期は左詰め */
}

#sky-inner {
  position: relative;
  height: 100vh;
  display: inline-block;
  flex-shrink: 0;
  /* Flexbox内で縮小されないようにする */
  transform-origin: 50% 50%;
  /* スケールの基準を中央に */
  transform: translateX(calc(50vw - 50%));
  /* 画像の中央を表示 */
  transition: transform 1s ease-in-out;
}

#background-img {
  height: 100vh;
  width: auto;
  /* 縦幅に合わせて横幅は成り行き（左右にはみ出す） */
  display: block;
  filter: brightness(10%);
  /* 初期状態：暗い夜空 */
  transition: filter 3s ease-in-out;
}

#milky-way-stars {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 2s ease-in-out;
  z-index: 2;
  /* 星を画像の手前に明示的に配置 */
}

/* -------------------------------------
 * UI コンポーネント (グラスモーフィズム)
 * ------------------------------------- */
.glass-panel {
  background: rgba(10, 15, 30, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.btn {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.8), rgba(218, 165, 32, 0.8));
  color: #1a1a1a;
  border: none;
  padding: 15px 30px;
  font-size: 1.1rem;
  font-family: inherit;
  font-weight: bold;
  border-radius: 30px;
  cursor: pointer;
  margin: 10px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
  pointer-events: auto;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: none;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
}

/* -------------------------------------
 * フェーズ管理
 * ------------------------------------- */
.phase {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  /* UI自体は1画面分に収める */
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 1s ease, visibility 1s;
  z-index: 10;
}

.phase.active {
  opacity: 1;
  visibility: visible;
  /* 背景の星やスクロールを操作できるよう、ここは pointer-events を透過させたままにする */
}

h1,
h2,
p {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
  line-height: 1.6;
}

/* --- フェーズ1: 初期画面 --- */
#phase1 h1 {
  font-size: 1.5rem;
  margin-bottom: 30px;
  letter-spacing: 0.1em;
}

/* --- フェーズ2: カメラ撮影 --- */
#camera-container {
  position: relative;
  width: 300px;
  height: 400px;
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#canvas {
  display: none;
}

#preview-container {
  display: none;
  position: relative;
  width: 300px;
  height: 400px;
  margin-bottom: 20px;
  border-radius: 12px;
  overflow: hidden;
}

#preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- フェーズ3: 魔法の発動 (アニメーション) --- */
.magic-animation {
  animation: magicAscend 4s forwards ease-in-out;
}

@keyframes magicAscend {
  0% {
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 0 0 rgba(255, 215, 0, 0));
    opacity: 1;
  }

  30% {
    filter: drop-shadow(0 0 30px rgba(255, 215, 0, 1)) brightness(1.5);
    transform: translateY(-20px) scale(1.05);
  }

  70% {
    filter: drop-shadow(0 0 50px rgba(255, 215, 0, 1)) brightness(2);
    transform: translateY(-150px) scale(0.5);
    opacity: 1;
  }

  100% {
    filter: drop-shadow(0 0 100px rgba(255, 215, 0, 1)) brightness(3);
    transform: translateY(-300px) scale(0);
    opacity: 0;
  }
}

.star-birth {
  position: absolute;
  width: 4px;
  height: 4px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 10px 5px rgba(255, 215, 0, 0.8), 0 0 20px 10px rgba(255, 255, 255, 0.5);
  animation: birthFlash 2s forwards;
  pointer-events: none;
}

@keyframes birthFlash {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  50% {
    transform: scale(5);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --- フェーズ4: みんなの天の川 --- */
#milky-way-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.star-element {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  transition: transform 0.2s;
}

.star-element:hover {
  transform: translate(-50%, -50%) scale(2);
}

.star-normal {
  width: 3px;
  height: 3px;
  background: #e0eaff;
  box-shadow: 0 0 5px #e0eaff;
}

.star-my {
  width: 6px;
  height: 6px;
  background: #ffd700;
  box-shadow: 0 0 10px #ffd700, 0 0 20px #ffaa00;
  animation: pulse 2s infinite;
  z-index: 5;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 10px #ffd700, 0 0 20px #ffaa00;
    transform: translate(-50%, -50%) scale(1);
  }

  50% {
    box-shadow: 0 0 20px #ffd700, 0 0 40px #ffaa00;
    transform: translate(-50%, -50%) scale(1.2);
  }

  100% {
    box-shadow: 0 0 10px #ffd700, 0 0 20px #ffaa00;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* 星クリック時のモーダル */
#modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  overflow-y: auto;
}

#modal.active {
  display: flex;
}

#kdp-modal.active {
  display: flex !important;
}

#modal-img {
  max-width: 80%;
  max-height: 50vh;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.4);
  margin-bottom: 20px;
  flex-shrink: 0;
}

.close-btn {
  margin-top: 0px;
}
