:root {
  --ink: #3a1d12;
  --bg: #1c0f2b;
  --momonga: #9fdcff;
  --usagi: #ffdc5c;
  --ningyo: #ff8a8a;
  --fill: #4dff6a;
  --font: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  font-weight: 800;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ---------- ステージ ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #2a1640 url(haikei.png) center / cover no-repeat;
}

.chars { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

.char {
  position: absolute;
  bottom: 3%;
  opacity: 0;
  transform: translateY(30%) scale(0.6);
  transition: opacity 0.25s, transform 0.25s;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}
.char.on { opacity: 1; transform: none; transition: opacity 0.08s; }
.char.pop { animation: pop 0.32s cubic-bezier(.2, 1.6, .4, 1); }

.char.momonga { left: 0; width: 40%; transform-origin: 50% 100%; }
.char.usagi { right: 0; width: 36%; transform-origin: 50% 100%; }
/* ningyo.png は右寄りに余白があるので切り抜いて表示 */
.char.ningyo {
  left: 34%;
  bottom: 16%;
  width: 31%;
  aspect-ratio: 462 / 463;
  overflow: hidden;
  transform-origin: 50% 100%;
}
.char.ningyo img { position: absolute; width: 281.4%; left: -149.8%; top: -34.3%; }

@keyframes pop {
  0% { transform: translateY(18%) scale(0.75, 1.15); }
  45% { transform: translateY(-6%) scale(1.12, 0.92); }
  100% { transform: none; }
}

/* ---------- 歌詞 ---------- */
.lyrics {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  top: 7%;
  padding: 0 4%;
  font-size: min(6.4vw, 32px);
  pointer-events: none;
}

.line {
  position: absolute;
  left: 4%;
  right: 4%;
  white-space: nowrap;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 0.25s;
}
.line.show { opacity: 1; }
.line.r0 { top: 0; text-align: left; }
.line.r1 { top: 1.6em; text-align: left; padding-left: 8%; }
.line.r2 { top: 3.2em; text-align: right; }

.w { position: relative; display: inline-block; }
.w + .w { margin-left: 0.45em; }
.w .base,
.w .fill {
  text-shadow:
    0 0 0 var(--ink),
    2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink),
    0 3px 0 var(--ink), 0 -3px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink),
    0 5px 6px rgba(0, 0, 0, 0.4);
}
.w .base { color: #fff; }
.w .fill {
  position: absolute;
  left: 0;
  top: 0;
  color: var(--fill);
  clip-path: inset(-0.5em 100% -0.5em -0.5em);
}

/* ---------- 判定 ---------- */
.judge {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 46%;
  text-align: center;
  font-size: min(7vw, 34px);
  pointer-events: none;
}
.judge span {
  display: inline-block;
  animation: judge 0.6s ease-out forwards;
  -webkit-text-stroke: 1px var(--ink);
  text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(255, 255, 255, 0.6);
}
.judge .perfect { color: #ffe95c; }
.judge .great { color: #7dff9a; }
.judge .good { color: #8fd8ff; }
.judge .free { color: #ff9ad5; }
@keyframes judge {
  0% { transform: scale(1.5); opacity: 0; }
  20% { transform: scale(1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translateY(-40%); opacity: 0; }
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  z-index: 4;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 0;
}
.progress {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.bar { height: 100%; width: 0; background: linear-gradient(90deg, #ff7bc8, #ffe066); }
.score {
  min-width: 4.5em;
  text-align: right;
  font-size: 15px;
  text-shadow: 0 2px 0 var(--ink), 0 0 4px var(--ink);
}
.score small { display: block; font-size: 11px; color: #ffe066; min-height: 1em; }
.stop {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  padding: 0;
}

/* ---------- スタート / リザルト ---------- */
.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: radial-gradient(ellipse at center, rgba(28, 15, 43, 0.45), rgba(28, 15, 43, 0.8));
  transition: opacity 0.3s;
}
.overlay.hide { opacity: 0; pointer-events: none; }
.title {
  font-size: min(11vw, 52px);
  color: #ffe066;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-4deg);
}
.sub { font-size: 14px; text-shadow: 0 2px 0 var(--ink); }
.play {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding: 14px 30px 14px 24px;
  border: 4px solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(#ff8fcf, #ff5fae);
  color: #fff;
  font: inherit;
  font-size: 22px;
  text-shadow: 0 2px 0 var(--ink);
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
}
.play:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.play:disabled { filter: grayscale(0.7); opacity: 0.8; }
.tri {
  width: 0;
  height: 0;
  border-left: 18px solid #fff;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  filter: drop-shadow(0 2px 0 var(--ink));
}
.rec {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  text-shadow: 0 2px 0 var(--ink);
}
.rec input { width: 20px; height: 20px; accent-color: #ff5fae; margin: 0; }
.result {
  text-align: center;
  font-size: 15px;
  line-height: 1.6;
  text-shadow: 0 2px 0 var(--ink);
}
.result .rank {
  font-size: 56px;
  line-height: 1.1;
  color: #ffe066;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 5px 0 var(--ink);
}

/* ---------- ボタン ---------- */
.pad {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  padding: 11px 11px calc(11px + env(safe-area-inset-bottom));
  background: linear-gradient(#3b1f55, #24123a);
  border-top: 4px solid var(--ink);
  touch-action: manipulation;
}

.btn {
  position: relative;
  height: min(19vw, 84px);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 4px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--c);
  color: var(--ink);
  font: inherit;
  font-size: min(3.3vw, 15px);
  line-height: 1.15;
  text-align: left;
  white-space: pre-line;
  box-shadow: 0 5px 0 var(--ink);
  touch-action: manipulation;
  cursor: pointer;
  transition: transform 0.05s, box-shadow 0.05s;
}
.btn.momonga { --c: var(--momonga); }
.btn.usagi { --c: var(--usagi); }
.btn.ningyo { --c: var(--ningyo); }
.btn.momonga.usagi { background: linear-gradient(120deg, var(--momonga) 50%, var(--usagi) 50%); }
.btn.down { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); filter: brightness(1.12); }

.btn .icon {
  flex: 0 0 auto;
  width: min(8vw, 38px);
  height: min(8vw, 38px);
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff center 30% / 150% no-repeat;
}
.btn .icon.momonga { background-image: url(momonga.png); }
.btn .icon.usagi { background-image: url(usagi.png); background-position: center 25%; }
.btn .icon.ningyo { background-image: url(ningyo.png); background-size: 380%; background-position: 80% 35%; }
.btn .txt { flex: 1; min-width: 0; overflow: hidden; }

/* タイミングを知らせるリング */
.btn .ring {
  position: absolute;
  inset: -4px;
  border-radius: 21px;
  border: 4px solid #fff;
  box-shadow: 0 0 12px #fff, inset 0 0 8px #fff;
  opacity: 0;
  pointer-events: none;
}
.btn.now { animation: now 0.25s ease-out; }
@keyframes now {
  0% { filter: brightness(1.6); }
  100% { filter: none; }
}
