/* style.css — PuniBeats */

:root {
  --bg1: #1a1035;
  --bg2: #2d1b5e;
  --panel: rgba(255, 255, 255, 0.06);
  --text: #f3ecff;
  --c-beat: #ff6b6b;
  --c-bass: #4d96ff;
  --c-melody: #6bcb77;
  --c-voice: #c77dff;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: radial-gradient(circle at 50% -10%, var(--bg2), var(--bg1) 70%);
  background-size: cover;
  background-position: center;
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ---------- ヘッダー ---------- */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

header h1 {
  font-size: 20px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff, #c77dff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  flex: 1;
}

header button {
  border: none;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 16px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}
header button:hover { background: rgba(255, 255, 255, 0.14); }
header button:active { transform: scale(0.93); }

/* ---------- モード切り替えバー ---------- */
#modes { display: flex; gap: 6px; flex-wrap: wrap; }
#modes button {
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 999px;
}
#modes button.on {
  background: rgba(255, 255, 255, 0.25);
  outline: 2px solid #ffe9a8;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 233, 168, 0.9);
  animation: mode-glow 1.6s ease-in-out infinite;
}
@keyframes mode-glow {
  0%, 100% { box-shadow: 0 0 8px 2px rgba(255, 220, 130, 0.45), 0 0 20px 5px rgba(255, 220, 130, 0.18); }
  50% { box-shadow: 0 0 14px 4px rgba(255, 220, 130, 0.8), 0 0 32px 9px rgba(255, 220, 130, 0.3); }
}
@media (max-width: 760px) { #modes .mode-label { display: none; } }

/* ---------- ステージ ---------- */
#stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 8px 18px;
  min-height: 0;
}

/* 影スロットの段（間隔ひろめの2段組） */
.stage-row {
  display: flex;
  justify-content: center;
  gap: clamp(28px, 5vw, 80px);
}

.slot {
  position: relative;
  width: clamp(70px, 10vw, 124px);
  cursor: pointer;
  transition: transform 0.15s;
  border-radius: 16px;
  padding: 4px;
}
.slot:hover { transform: translateY(-4px); }

.slot .char {
  width: 100%;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.4));
}

/* 画像キャラ（img 指定のキャラ） */
.img-char { position: relative; }
.img-char img { width: 100%; height: auto; display: block; pointer-events: none; }
.img-char .img-close,
.img-char .img-horror,
.img-char .img-glitch { position: absolute; inset: 0; }
/* 口パク: 待機中（トレイ・非演奏）は口閉じ、演奏中は口開き */
.img-char.has-close .img-open { visibility: hidden; }
.img-char.has-close .img-close { visibility: visible; }
.slot.active .img-char.has-close .img-open { visibility: visible; }
.slot.active .img-char.has-close .img-close { visibility: hidden; }
/* ホラーモード: 全部ホラー版画像に差し替え（トレイもステージも） */
.img-char .img-horror { visibility: hidden; }
body.mode-horror .img-char.has-horror .img-open,
body.mode-horror .img-char.has-horror .img-close,
body.mode-horror .slot.active .img-char.has-horror .img-open { visibility: hidden; }
body.mode-horror .img-char.has-horror .img-horror { visibility: visible; }
/* こわれたモード: 全部グロ版画像に差し替え */
.img-char .img-glitch { visibility: hidden; }
body.mode-glitch .img-char.has-glitch .img-open,
body.mode-glitch .img-char.has-glitch .img-close,
body.mode-glitch .slot.active .img-char.has-glitch .img-open { visibility: hidden; }
body.mode-glitch .img-char.has-glitch .img-glitch { visibility: visible; }
.slot.active .img-char {
  animation: dance 0.571s ease-in-out infinite;
  transform-origin: 50% 100%;
}
.slot:not(.active) .img-char {
  animation: idle 3.2s ease-in-out infinite;
  transform-origin: 50% 100%;
}
body.muted .slot.active .img-char { animation-play-state: paused; }
body.mode-horror #stage .slot.active .img-char { animation-duration: 0.733s; }
body.mode-speed #stage .slot.active .img-char { animation-duration: 0.44s; }

/* 空きスロットの「影」 */
.slot.empty .sil { opacity: 0.9; transition: opacity 0.2s, transform 0.2s; }
.slot.empty:hover .sil { opacity: 1; transform: translateY(-2px); }
.slot .char-holder { min-height: 0; }

.char-name {
  text-align: center;
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

/* 割り当て中バッジ */
.badge[hidden] { display: none; } /* display:flex が hidden 属性に勝ってしまうのを防ぐ */
.badge {
  position: absolute;
  top: 0;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.badge.cat-beat { background: var(--c-beat); }
.badge.cat-bass { background: var(--c-bass); }
.badge.cat-melody { background: var(--c-melody); }
.badge.cat-voice { background: var(--c-voice); }

/* 口: 通常は閉じ、演奏中は開く */
.mouth-open { display: none; }
.slot.active .mouth-open { display: block; }
.slot.active .mouth-idle { display: none; }

/* 演奏中アニメーション（BPM105 → 1拍 ≈ 0.571s） */
.slot.active .body-group {
  animation: dance 0.571s ease-in-out infinite;
  transform-origin: 60px 150px;
}
.slot.active .arm-l { animation: wave-l 1.143s ease-in-out infinite; transform-origin: 37px 94px; }
.slot.active .arm-r { animation: wave-r 1.143s ease-in-out infinite; transform-origin: 83px 94px; }
.slot.active { filter: drop-shadow(0 0 14px rgba(255, 255, 255, 0.25)); }
body.muted .slot.active .body-group,
body.muted .slot.active .arm { animation-play-state: paused; }

@keyframes dance {
  0%, 100% { transform: scaleY(1) scaleX(1); }
  30% { transform: scaleY(0.93) scaleX(1.05); }
  60% { transform: scaleY(1.03) scaleX(0.98) translateY(-4px); }
}
@keyframes wave-l {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(28deg); }
}
@keyframes wave-r {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-28deg); }
}

/* アイドル時のゆらゆら（スロットごとに位相をずらす） */
.slot:not(.active) .body-group { animation: idle 3.2s ease-in-out infinite; transform-origin: 60px 150px; }
.slot:nth-child(2n) .body-group { animation-delay: -1.1s; }
.slot:nth-child(3n) .body-group { animation-delay: -2.2s; }
@keyframes idle {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(0.985); }
}

.slot.drop-hover {
  background: rgba(255, 255, 255, 0.1);
  outline: 2px dashed rgba(255, 255, 255, 0.5);
}

/* ---------- トレイ ---------- */
#tray {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 10px calc(14px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.28);
}

.icon {
  width: 76px;
  height: 96px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px 2px 5px;
  gap: 2px;
  transition: transform 0.12s, opacity 0.2s, border-color 0.12s;
  touch-action: none; /* Pointerドラッグのため */
}
.icon .char { width: 54px; height: auto; pointer-events: none; }
.icon .lbl { font-size: 10.5px; opacity: 0.95; display: flex; align-items: center; gap: 4px; }
.icon .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.icon:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.12); }
.icon.selected { border-color: #fff; transform: translateY(-5px) scale(1.06); }
.icon.in-use { opacity: 0.22; cursor: default; }

.icon.cat-beat { border-bottom-color: var(--c-beat); }
.icon.cat-bass { border-bottom-color: var(--c-bass); }
.icon.cat-melody { border-bottom-color: var(--c-melody); }
.icon.cat-voice { border-bottom-color: var(--c-voice); }
.icon.cat-beat .dot { background: var(--c-beat); }
.icon.cat-bass .dot { background: var(--c-bass); }
.icon.cat-melody .dot { background: var(--c-melody); }
.icon.cat-voice .dot { background: var(--c-voice); }
.icon.selected { border-color: #fff; }

/* ドラッグ中のゴースト */
.ghost {
  position: fixed;
  z-index: 100;
  transform: translate(-50%, -50%) scale(1.1);
  pointer-events: none;
  opacity: 0.85;
}

/* ---------- クレジット表示（ポリシーページへのリンク） ---------- */
#credit {
  position: fixed;
  right: 10px;
  bottom: 6px;
  z-index: 20;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.45);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
#credit:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.35);
}

/* ---------- 🌕 つきみの月明かり ---------- */
#moonlight-layer {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 3;
  background: radial-gradient(ellipse 70% 55% at 50% 10%, rgba(255, 248, 214, 0.17), transparent 70%);
  opacity: 0;
  transition: opacity 1.2s ease;
}
body.moonlight #moonlight-layer { opacity: 1; }

/* ---------- スタートオーバーレイ ---------- */
#start-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(16, 8, 40, 0.92);
  cursor: pointer;
}
#start-overlay .logo { font-size: 42px; }
#start-overlay .start-text {
  font-size: 18px;
  padding: 12px 32px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  animation: pulse-btn 1.6s ease-in-out infinite;
}
#start-overlay .hint { font-size: 12px; opacity: 0.6; max-width: 340px; text-align: center; line-height: 1.7; }
#start-overlay.loading .start-text { animation: none; opacity: 0.6; }
@keyframes pulse-btn {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.8; }
}

/* ---------- モードテーマ ---------- */

/* バツ目はホラーモード専用（通常は隠す） */
.eyes-x { display: none; }

/* 👻 ホラー */
body.mode-horror { --bg1: #160303; --bg2: #3d0808; }
body.mode-horror header h1 {
  background: linear-gradient(90deg, #ff4040, #8a0f0f, #ff4040);
  -webkit-background-clip: text; background-clip: text;
}
body.mode-horror #modes { display: none; } /* 裏モード中はモード一覧を消す（帰還はギミックのみ） */
body.mode-horror #stage .char:not(.img-char) { filter: saturate(0.35) brightness(0.72) contrast(1.15); }
body.mode-horror #stage .slot.active { filter: drop-shadow(0 0 16px rgba(255, 30, 30, 0.5)); }
body.mode-horror #stage .eyes-n { display: none; }
body.mode-horror #stage .eyes-x { display: block; }
body.mode-horror #stage .slot.active .body-group { animation-duration: 0.733s; } /* 0.78倍速に同期 */
body.mode-horror #stage .slot.active .arm-l,
body.mode-horror #stage .slot.active .arm-r { animation-duration: 1.465s; }
body.mode-horror .sil path {
  fill: rgba(0, 0, 0, 0.5);
  stroke: rgba(255, 110, 110, 0.6);
}
body.mode-horror .sil text { fill: rgba(255, 150, 150, 0.35); }

/* 📺 こわれた */
body.mode-glitch { --bg1: #06060a; --bg2: #16161f; }
body.mode-glitch #modes { display: none; } /* 裏モード中はモード一覧を消す（帰還はリセットのみ） */
body.mode-glitch::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 6;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, 0.28) 2px 4px);
  animation: glitch-flicker 0.14s steps(2) infinite;
}
@keyframes glitch-flicker {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}
body.mode-glitch header h1 {
  background: none;
  -webkit-background-clip: initial;
  background-clip: initial;
  color: #e8f6ff;
  text-shadow: -2px 0 rgba(255, 40, 90, 0.8), 2px 0 rgba(40, 230, 255, 0.8);
}
body.mode-glitch #stage .slot { animation: glitch-jit 2.4s steps(1) infinite; }
body.mode-glitch #stage .slot:nth-child(2n) { animation-delay: -1.1s; }
body.mode-glitch #stage .slot:nth-child(3n) { animation-delay: -1.9s; }
@keyframes glitch-jit {
  0%, 91%, 100% { transform: none; filter: none; }
  92% { transform: translateX(-4px) skewX(-3deg); filter: hue-rotate(120deg) saturate(2.5); }
  94% { transform: translateX(4px); filter: hue-rotate(-90deg) contrast(1.5); }
  96% { transform: translateX(-2px); filter: invert(0.9); }
  97% { transform: none; filter: none; }
}
body.mode-glitch .sil path { fill: rgba(0, 0, 0, 0.5); stroke: rgba(80, 255, 240, 0.45); }
body.mode-glitch .sil text { fill: rgba(80, 255, 240, 0.3); }
body.mode-glitch #stage .slot.active { filter: drop-shadow(0 0 12px rgba(80, 255, 240, 0.35)); }

/* 📺 こわれた遷移の砂嵐フラッシュ */
#tvbreak {
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.9) 0 2px, rgba(0, 0, 0, 0.9) 2px 4px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.35) 0 3px, transparent 3px 7px);
  animation: tvbreak 1.1s steps(3) forwards;
}
@keyframes tvbreak {
  0% { opacity: 0; }
  15% { opacity: 1; }
  40% { opacity: 0.6; transform: translateY(6px); }
  60% { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 0; transform: none; }
}

/* 🌕 つきみの「夜のとばり」演出 */
#nightfall {
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  background: linear-gradient(180deg, #060a18, #0d1730);
  animation: nightfall 1.5s ease-in-out forwards;
}
@keyframes nightfall {
  0% { opacity: 0; }
  30% { opacity: 1; }
  60% { opacity: 1; }
  100% { opacity: 0; }
}

/* 🌑 まっくろの暗転演出 */
#blackout {
  position: fixed; inset: 0;
  z-index: 60;
  pointer-events: none;
  background: #000;
  animation: blackout 1.4s ease-in-out forwards;
}
@keyframes blackout {
  0% { opacity: 0; }
  25% { opacity: 1; background: #000; }
  50% { opacity: 1; background: #1c0303; }
  65% { opacity: 1; background: #000; }
  100% { opacity: 0; }
}

/* 🚀 うちゅう */
body.mode-space { --bg1: #03031c; --bg2: #0a1140; }
body.mode-space {
  background-image:
    radial-gradient(1.5px 1.5px at 20% 25%, #fff, transparent),
    radial-gradient(1px 1px at 70% 15%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.2px 1.2px at 45% 60%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1px 1px at 85% 45%, rgba(255, 255, 255, 0.8), transparent),
    radial-gradient(1px 1px at 10% 70%, rgba(255, 255, 255, 0.6), transparent),
    radial-gradient(circle at 50% -10%, var(--bg2), var(--bg1) 70%);
}
body.mode-space #stage .slot { animation: float 4.6s ease-in-out infinite; }
body.mode-space #stage .slot:nth-child(2n) { animation-delay: -1.6s; }
body.mode-space #stage .slot:nth-child(3n) { animation-delay: -3.1s; }
body.mode-space #stage .slot.active { filter: drop-shadow(0 0 16px rgba(120, 180, 255, 0.45)); }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ⚡ はやまわし */
body.mode-speed { --bg1: #1c0326; --bg2: #4b0f54; }
body.mode-speed #stage .slot.active .body-group { animation-duration: 0.44s; } /* 1.3倍速に同期 */
body.mode-speed #stage .slot.active .arm-l,
body.mode-speed #stage .slot.active .arm-r { animation-duration: 0.88s; }
body.mode-speed #stage .slot.active { filter: drop-shadow(0 0 15px rgba(0, 255, 235, 0.4)); }

/* 📻 レコード */
body.mode-record { --bg1: #1f1710; --bg2: #3a2c1c; }
body.mode-record #stage .char { filter: sepia(0.55) saturate(0.7) contrast(0.95); }
body.mode-record #stage .slot.active { filter: drop-shadow(0 0 12px rgba(255, 210, 140, 0.35)); }

/* 🫧 すいちゅう */
body.mode-water { --bg1: #031f2c; --bg2: #07597a; }
body.mode-water::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 5;
  background-image:
    radial-gradient(circle, rgba(255, 255, 255, 0.28) 0 2px, transparent 3.5px),
    radial-gradient(circle, rgba(255, 255, 255, 0.16) 0 1.5px, transparent 2.5px);
  background-size: 90px 240px, 140px 320px;
  background-position: 20px 0, 70px 100px;
  animation: bubbles 9s linear infinite;
}
@keyframes bubbles {
  from { background-position: 20px 0, 70px 100px; }
  to { background-position: 20px -480px, 70px -540px; }
}
body.mode-water #stage .char { filter: hue-rotate(-15deg) brightness(0.92); }

/* 🏮 おまつり */
body.mode-festival { --bg1: #1e0a02; --bg2: #5c2708; }
body.mode-festival::before {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; height: 130px;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 8% 45%, rgba(255, 120, 40, 0.9) 0 9px, rgba(255, 120, 40, 0.18) 20px, transparent 32px),
    radial-gradient(circle at 28% 28%, rgba(255, 170, 60, 0.9) 0 8px, rgba(255, 170, 60, 0.18) 18px, transparent 30px),
    radial-gradient(circle at 50% 46%, rgba(255, 120, 40, 0.9) 0 9px, rgba(255, 120, 40, 0.18) 20px, transparent 32px),
    radial-gradient(circle at 72% 28%, rgba(255, 170, 60, 0.9) 0 8px, rgba(255, 170, 60, 0.18) 18px, transparent 30px),
    radial-gradient(circle at 92% 45%, rgba(255, 120, 40, 0.9) 0 9px, rgba(255, 120, 40, 0.18) 20px, transparent 32px);
}

/* 🌙 まよなか */
body.mode-night { --bg1: #04060f; --bg2: #0d1730; }
body.mode-night::before {
  content: '';
  position: fixed; top: 46px; right: 60px;
  width: 64px; height: 64px; border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at 40% 40%, #fff8dc, #f4e6a8 60%, transparent 72%);
  box-shadow: 0 0 44px 16px rgba(255, 244, 200, 0.3);
}
body.mode-night #stage .char { filter: brightness(0.78) saturate(0.8); }

/* 🌸 きせつがわり（1ループごとに季節が進む） */
body.mode-season.season-spring { --bg1: #2e0f22; --bg2: #96527a; }
body.mode-season.season-summer { --bg1: #03283c; --bg2: #0f7ca0; }
body.mode-season.season-autumn { --bg1: #2b1206; --bg2: #96541a; }
body.mode-season.season-winter { --bg1: #0e1c2e; --bg2: #6588ab; }
body.mode-season::after {
  position: fixed; top: 70px; left: 28px;
  font-size: 52px; opacity: 0.55;
  pointer-events: none;
}
body.mode-season.season-spring::after { content: '🌸'; }
body.mode-season.season-summer::after { content: '🌻'; }
body.mode-season.season-autumn::after { content: '🍁'; }
body.mode-season.season-winter::after { content: '⛄'; }

/* 🎲 おまかせDJ */
body.mode-dj { --bg1: #12031c; --bg2: #3c0a63; }
body.mode-dj #stage {
  background-image:
    conic-gradient(from 200deg at 30% -10%, transparent 0 12deg, rgba(255, 80, 220, 0.09) 12deg 24deg, transparent 24deg),
    conic-gradient(from 136deg at 70% -10%, transparent 0 12deg, rgba(80, 200, 255, 0.09) 12deg 24deg, transparent 24deg);
}

/* 🎯 クイズ */
body.mode-quiz { --bg1: #0a2013; --bg2: #1c5433; }
body.mode-quiz #stage .slot { opacity: 0.25; pointer-events: none; }

/* ---------- クイズバー ---------- */
#quiz-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 9px 12px;
  font-size: 15px;
  background: rgba(0, 0, 0, 0.28);
}
#quiz-bar[hidden] { display: none; }
#quiz-score { opacity: 0.75; font-size: 13px; }
.icon.quiz-right { border-color: #7dff9b; transform: translateY(-6px) scale(1.1); }
.icon.quiz-wrong { border-color: #ff6b6b; animation: shake 0.4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ---------- スマホ縦向け調整 ---------- */
@media (max-width: 600px) {
  header h1 { font-size: 16px; }
  .slot { width: 23vw; }
  .icon { width: 56px; height: 56px; }
}
