/* parade.css — ぷにパレード専用スタイル（PuniBeats 本体の style.css とは独立） */
:root {
  --bg: #1a1035;
  --panel: #2a1d52;
  --text: #fff7e8;
  --accent: #ffcf4a;
  --pink: #ff8fb8;
  --cell: 32px;           /* JS がウィンドウサイズから計算して上書き */
  --squash: 0;            /* JS が拍ごとに 1→0 で更新（ぷにっと伸び縮み） */
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  flex-wrap: wrap;
}
header h1 { font-size: 1.2rem; margin: 0; color: var(--accent); white-space: nowrap; }
#hud { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; font-size: 0.95rem; }
#hud b { color: var(--accent); font-size: 1.1rem; }
#hud .best b { color: var(--pink); }
header button, header a {
  background: var(--panel); color: var(--text); border: 2px solid #4a3a80;
  border-radius: 999px; padding: 4px 12px; font-size: 0.9rem; text-decoration: none; cursor: pointer;
}

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 16px 12px;
}

/* フィールド（24×14マス）。背景は PuniBeats のノーマル背景を流用・無ければグラデーション */
#board {
  position: relative;
  width: calc(var(--cell) * 24);
  height: calc(var(--cell) * 14);
  border-radius: 14px;
  border: 3px solid #4a3a80;
  /* うっすらマス目＋暗幕＋背景画像（無ければ最後のグラデーション） */
  background-image:
    linear-gradient(rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(rgba(26, 16, 53, 0.35), rgba(26, 16, 53, 0.35)),
    url("../assets/bg/normal.webp"),
    linear-gradient(160deg, #3b2a78, #6a3f8f 60%, #2a1d52);
  background-size: var(--cell) var(--cell), var(--cell) var(--cell), cover, cover, cover;
  background-position: 0 0, 0 0, center, center, center;
  overflow: hidden;
}
body.dead #board { animation: shake 0.35s; }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}

/* 行列の1匹（＝1マス）。キャラ絵は縦長なので、マスの下端に足元を合わせて少しはみ出させる */
.seg {
  position: absolute;
  left: 0; top: 0;
  width: var(--cell);
  height: var(--cell);
  transition: transform 0.12s linear;
  will-change: transform;
}
.seg .char {
  position: absolute;
  left: -15%;
  bottom: -4%;
  width: 130%;
  transform-origin: 50% 100%;
  transform: scale(calc(1 + var(--squash) * 0.10), calc(1 - var(--squash) * 0.12));
}
.seg.head .char { width: 145%; left: -22.5%; }
.seg.head { z-index: 2; }

/* 拾える子（フィールドに出ている）: ふわふわ浮く＋光る */
.seg.item { z-index: 1; }
.seg.item .char { animation: float 0.57s ease-in-out infinite alternate; filter: drop-shadow(0 0 6px #fff6); }
@keyframes float { to { translate: 0 -10%; } }
.seg.item.spawn { animation: pop-in 0.25s ease-out; }
@keyframes pop-in { from { scale: 0; } }

/* 口パク: 画像キャラは「閉じ口」が基本、鳴っている子だけ拍の前半で口を開く */
.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 .img-horror, .img-char .img-glitch { visibility: hidden; }
.img-char.has-close .img-open { visibility: hidden; }
.img-char.has-close .img-close { visibility: visible; }
body.beat-on .seg.singing .img-char.has-close .img-open { visibility: visible; }
body.beat-on .seg.singing .img-char.has-close .img-close { visibility: hidden; }
/* SVGキャラ（画像なし環境のフォールバック）の口 */
svg.char .mouth-open, svg.char .eyes-x { display: none; }
body.beat-on .seg.singing svg.char .mouth-open { display: inline; }
body.beat-on .seg.singing svg.char .mouth-idle { display: none; }

/* ゲームオーバー: 全員 _horror 顔 */
body.dead #board .img-char.has-horror img { visibility: hidden !important; }
body.dead #board .img-char.has-horror .img-horror { visibility: visible !important; }
body.dead #board svg.char .eyes-n { display: none; }
body.dead #board svg.char .eyes-x { display: inline; }
body.dead .seg .char { transform: none; }

/* 拾ったときの吹き出し（＋点数・ぴったり！・アップ顔） */
#popup {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
.pop {
  position: absolute;
  transform: translate(-50%, -100%);
  font-weight: bold;
  font-size: calc(var(--cell) * 0.55);
  color: var(--accent);
  text-shadow: 0 2px 0 #0008;
  white-space: nowrap;
  animation: rise 0.9s ease-out forwards;
}
.pop.pink { color: var(--pink); }
@keyframes rise { to { translate: 0 -120%; opacity: 0; } }
.closeup {
  position: absolute;
  right: 3%;
  bottom: 4%;
  width: calc(var(--cell) * 4);
  animation: closeup 1.1s ease-out forwards;
}
.closeup img { width: 100%; display: block; }
@keyframes closeup {
  0% { scale: 0.3; opacity: 0; } 15% { scale: 1.1; opacity: 1; }
  25% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; }
}

/* タッチ端末むけ十字ボタン（右下） */
#dpad {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 150px;
  height: 150px;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  z-index: 10;
  opacity: 0.75;
}
#dpad[hidden] { display: none; }
#dpad button {
  border: none; border-radius: 12px; background: #fff3; color: var(--text); font-size: 1.3rem;
}
#dpad [data-dir="up"] { grid-area: 1 / 2; }
#dpad [data-dir="left"] { grid-area: 2 / 1; }
#dpad [data-dir="right"] { grid-area: 2 / 3; }
#dpad [data-dir="down"] { grid-area: 3 / 2; }

/* スタート・結果画面 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 25, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.panel {
  background: var(--panel);
  border: 3px solid #4a3a80;
  border-radius: 20px;
  padding: 20px 28px;
  text-align: center;
  max-width: 560px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
}
.panel h2 { margin: 0 0 8px; color: var(--accent); }
.panel .small { font-size: 0.85rem; opacity: 0.85; }
.result-score { font-size: 1.4rem; }
.result-score b { color: var(--accent); font-size: 2rem; }
#res-best-badge { color: var(--pink); font-size: 1rem; }
#res-faces { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin: 10px 0; }
#res-faces .face { width: 48px; }
.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; align-items: center; }
.big-btn {
  background: var(--accent); color: #3a2a10; border: none; border-radius: 999px;
  font-size: 1.15rem; font-weight: bold; padding: 10px 28px; cursor: pointer;
}
.big-btn:disabled { opacity: 0.5; }
.sub-btn { color: var(--text); font-size: 0.95rem; }
