/* ================================================
   まほうのステッキ — スタイル
   デザイントークンは :root と body[data-mode=...] に集約。
   生成画像を assets/ に置くと JS が --bg-img を設定して
   背景が差し替わる（無ければグラデーションのまま）。
   ================================================ */

:root {
  --gold: #ffd873;
  --cream: #fff6fa;
  --night: #35186b;
  --shadow-ink: rgba(32, 10, 64, 0.5);
  --font-round: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "BIZ UDGothic", system-ui, sans-serif;
}

/* モードごとの背景・アクセント色 */
body[data-mode="star"] {
  --bg-top: #ff9ad5;
  --bg-mid: #9a63ee;
  --bg-bottom: #4a2bb8;
  --accent: #ffd873;
  --accent-soft: #fff3b0;
}
body[data-mode="heart"] {
  --bg-top: #ffb1c9;
  --bg-mid: #f06fb8;
  --bg-bottom: #8a35b8;
  --accent: #ff87c3;
  --accent-soft: #ffd1e8;
}
body[data-mode="moon"] {
  --bg-top: #8e7be8;
  --bg-mid: #4a3aa8;
  --bg-bottom: #221856;
  --accent: #a8d8ff;
  --accent-soft: #e6f2ff;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-round);
  color: var(--cream);
  background: linear-gradient(172deg, var(--bg-top) 0%, var(--bg-mid) 52%, var(--bg-bottom) 100%);
  transition: background 0.6s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* 生成画像の背景レイヤー（JSが --bg-img を設定したときだけ見える） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: var(--bg-img, none);
  background-size: cover;
  background-position: center;
  transition: opacity 0.6s ease;
}

/* 下部のコントラスト確保レイヤー（ラベル・ボタンの可読性用） */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle 2px at 12% 18%, rgba(255,255,255,.9) 40%, transparent 60%),
    radial-gradient(circle 1.5px at 78% 12%, rgba(255,255,255,.8) 40%, transparent 60%),
    radial-gradient(circle 2px at 88% 42%, rgba(255,255,240,.7) 40%, transparent 60%),
    radial-gradient(circle 1.5px at 24% 62%, rgba(255,255,255,.6) 40%, transparent 60%),
    radial-gradient(circle 2.5px at 62% 78%, rgba(255,240,200,.7) 40%, transparent 60%),
    linear-gradient(to bottom, rgba(20, 8, 48, 0.18) 0%, transparent 18%, transparent 62%, rgba(20, 8, 48, 0.5) 100%);
}

/* ---- キャンバスとフラッシュ ---- */
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  background: radial-gradient(circle at 50% 42%, #ffffff 0%, var(--accent) 35%, transparent 75%);
}
#flash.is-flashing { animation: flash-out 0.55s ease-out; }
@keyframes flash-out {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---- ヘッダー（ワードマーク＋消音） ---- */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
}

.wordmark {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 8px var(--shadow-ink);
}
.wordmark span { color: var(--gold); }

#sound-toggle {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: rgba(30, 12, 60, 0.35);
  color: var(--cream);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
#sound-toggle:active { transform: scale(0.92); }
#sound-toggle svg { width: 22px; height: 22px; }

/* ---- メインステージ ---- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 64px 16px 148px;
}

#wand-area {
  position: relative;
  display: grid;
  place-items: center;
}

#wand-button {
  appearance: none;
  border: none;
  background: transparent;
  padding: 12px;
  cursor: pointer;
  touch-action: none;
  border-radius: 24px;
  position: relative;
  z-index: 2;
  animation: wand-sway 3.6s ease-in-out infinite;
}

#wand, #wand-img {
  display: block;
  height: min(46vh, 400px);
  width: auto;
  filter: drop-shadow(0 8px 20px var(--shadow-ink));
  pointer-events: none;
}
/* hidden属性を確実に効かせる（display:block等の上書き対策。SVGはUAスタイルが効かない） */
#wand-img[hidden],
#sound-toggle svg[hidden] {
  display: none;
}

@keyframes wand-sway {
  0%, 100% { transform: rotate(-2deg) translateY(0); }
  50% { transform: rotate(2deg) translateY(-6px); }
}

#wand-button.is-tapped { animation: wand-pop 0.28s ease-out; }
@keyframes wand-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.1) rotate(-3deg); }
  100% { transform: scale(1); }
}

#wand-button.is-charging { animation: wand-shiver 0.18s linear infinite; }
@keyframes wand-shiver {
  0% { transform: rotate(-1.4deg); }
  50% { transform: rotate(1.4deg); }
  100% { transform: rotate(-1.4deg); }
}

#wand-button.is-casting { animation: wand-cast 0.5s ease-out; }
@keyframes wand-cast {
  0% { transform: scale(1); }
  30% { transform: scale(1.22) rotate(6deg); }
  100% { transform: scale(1); }
}

/* ---- チャージリング（魔法陣。チャージ量のインジケーターを兼ねる） ---- */
#charge-ring {
  position: absolute;
  top: 15%;
  left: 50%;
  width: min(30vh, 250px);
  height: min(30vh, 250px);
  transform: translate(-50%, -50%) scale(0.7);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#charge-ring.is-on {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
#charge-ring .ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 2;
  stroke-dasharray: 3 9;
  stroke-linecap: round;
}
#charge-ring .ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 326.7; /* 2πr (r=52) */
  stroke-dashoffset: 326.7; /* JSがチャージ量に応じて減らす */
  transform: rotate(-90deg);
  transform-origin: 60px 60px;
  filter: drop-shadow(0 0 6px var(--accent));
}
#charge-ring .ring-deco { fill: var(--accent-soft); }
#charge-ring.is-on .ring-deco {
  animation: ring-spin 7s linear infinite;
  transform-origin: 60px 60px;
}
@keyframes ring-spin {
  to { transform: rotate(360deg); }
}

/* ステッキ先端のふわっと光るオーラ（チャージ中） */
#charge-glow {
  position: absolute;
  top: 15%;
  left: 50%;
  width: min(28vh, 230px);
  height: min(28vh, 230px);
  transform: translate(-50%, -50%) scale(0.4);
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 0%, rgba(255,255,255,0.4) 40%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#charge-glow.is-on {
  opacity: 0.8;
  animation: glow-pulse 0.7s ease-in-out infinite alternate;
}
@keyframes glow-pulse {
  from { transform: translate(-50%, -50%) scale(0.85); }
  to   { transform: translate(-50%, -50%) scale(1.1); }
}

/* ---- 操作ヒント（1行ずつ入れ替わる） ---- */
#hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(30, 12, 60, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
#hint::before {
  content: "✦";
  color: var(--gold);
}
#hint-text {
  transition: opacity 0.35s ease;
}
#hint-text.is-swapping { opacity: 0; }

/* ---- モード切り替え ---- */
#mode-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: 18px;
  padding: 8px 12px calc(14px + env(safe-area-inset-bottom));
}

.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  min-width: 76px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 18px;
  transition: transform 0.12s ease;
}
.mode-btn:active { transform: scale(0.93); }

.gem {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 4px 12px var(--shadow-ink), inset 0 -6px 10px rgba(60, 20, 100, 0.35);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}
/* 宝石のツヤ */
.gem::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 34%);
  pointer-events: none;
}
.gem-star  { background: radial-gradient(circle at 50% 60%, #ffe9a0 0%, #ffb943 70%, #e08a1e 100%); }
.gem-heart { background: radial-gradient(circle at 50% 60%, #ffc9e2 0%, #ff6fb0 70%, #d63f92 100%); }
.gem-moon  { background: radial-gradient(circle at 50% 60%, #cfe6ff 0%, #7f9df0 70%, #4a55c0 100%); }

.gem img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* 生成アイコン画像が読めたらSVGは隠す（読めなければimgがself-removeされてSVGが出る） */
.gem img ~ svg { display: none; }
.gem svg {
  width: 30px;
  height: 30px;
  fill: rgba(255, 255, 255, 0.95);
  filter: drop-shadow(0 1px 2px rgba(60, 20, 100, 0.4));
}

.mode-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 1px 6px var(--shadow-ink);
}

/* 選択中：宝石が光る＋少し浮く */
.mode-btn.is-active .gem {
  box-shadow: 0 0 0 3px var(--cream), 0 0 18px var(--accent), 0 4px 12px var(--shadow-ink);
  transform: translateY(-3px);
}
.mode-btn.is-active .mode-label { color: var(--gold); }

/* ---- トースト通知 ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%) translateY(8px);
  max-width: 88vw;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(30, 12, 60, 0.85);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- デバッグ表示（?debug 時のみ生成される） ---- */
#debug {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  z-index: 30;
  font-family: monospace;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.6);
  color: #0f0;
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none;
}

/* ---- ユーティリティ ---- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

/* ---- モーション低減設定を尊重 ---- */
@media (prefers-reduced-motion: reduce) {
  #wand-button,
  #wand-button.is-charging,
  #charge-glow.is-on,
  #charge-ring.is-on .ring-deco {
    animation: none;
  }
  #flash.is-flashing { animation: flash-out 0.3s ease-out; }
  body, body::before, #hint-text { transition: none; }
}
