:root {
  --gold: #f5c842;
  --red:  #e84040;
  --teal: #00e5cc;
  --dark: #0a0a1a;
  --panel: rgba(10,10,30,0.0);
  --radius: 16px;
}
* { box-sizing: border-box; margin:0; padding:0; }

/* iPadなど幅広端末でも440px幅に固定して中央表示 */
html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;  /* iOS ラバーバンドスクロール防止 */
  touch-action: pan-y;        /* 横スワイプをスクロールとして解釈させない */
}

body {
  font-family: 'Nunito', sans-serif;
  background: #0a0a1a;
  color: #eee;
  /* position:fixed + transformでPC/iPhoneどちらでも正確に中央固定     */
  /* → 子のposition:fixed要素もbody基準になりずれが解消される          */
  /* overflow:hidden は html側で担保。body側に入れると left:50%+transform */
  /* の子要素がレイアウト位置でハーフクリップされる問題を防ぐため外す   */
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, 100vw);
  height: calc(var(--vh, 1vh) * 100);
  display: flex; flex-direction: column; align-items: center;
  justify-content: space-between;
}

/* ═══════════════════════════════
   BACKGROUND SCENE
═══════════════════════════════ */
#bg-scene {
  position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  z-index: 0;
  overflow: hidden;
}

/* stars */
.star {
  position: absolute; border-radius: 50%;
  background: white;
  animation: twinkle var(--d, 3s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes twinkle {
  0%,100%{ opacity: var(--min, 0.2); transform: scale(1); }
  50%    { opacity: 1;               transform: scale(1.4); }
}

/* moon */
.moon {
  position: absolute; top: 40px; right: 60px;
  width: 70px; height: 70px;
  background: radial-gradient(circle at 38% 38%, #fffbe0, #f5c842 60%, #c89a10);
  border-radius: 50%;
  animation: moonGlow 4s ease-in-out infinite;
}
@keyframes moonGlow {
  0%,100%{ }
  50%    { }
}
.moon-crater {
  position: absolute; border-radius: 50%;
  background: rgba(0,0,0,0.12);
}

/* mountains */
.mountains { position: absolute; bottom: 0; left: 0; right: 0; }

/* clouds */
.cloud {
  position: absolute;
  animation: driftCloud var(--dur, 60s) linear infinite;
  animation-delay: var(--cdelay, 0s);
  opacity: 0.18;
}
@keyframes driftCloud {
  from { transform: translateX(-200px); }
  to   { transform: translateX(110vw); }
}

/* fireflies */
.firefly {
  position: absolute; width: 4px; height: 4px;
  border-radius: 50%; background: #aaff88;
  animation: flyAround var(--fd, 8s) ease-in-out infinite;
  animation-delay: var(--fdelay, 0s);
}
@keyframes flyAround {
  0%  { transform: translate(0,0);        opacity: 0; }
  20% { opacity: 0.9; }
  50% { transform: translate(var(--fx, 40px), var(--fy, -30px)); opacity: 0.6; }
  80% { opacity: 0.9; }
  100%{ transform: translate(0,0);        opacity: 0; }
}

/* ground */
.ground {
  position: absolute; bottom: 0; left: 0; right: 0; height: 80px;
  background: linear-gradient(180deg, #0d1f0d 0%, #061006 100%);
  border-top: 2px solid #1a4a1a;
}
.grass-blade {
  position: absolute; bottom: 78px;
  width: 3px; border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, #4caf50, #1a4a1a);
  transform-origin: bottom center;
  animation: sway var(--gs, 2s) ease-in-out infinite alternate;
  animation-delay: var(--gd, 0s);
}
@keyframes sway {
  from { transform: rotate(-8deg); }
  to   { transform: rotate(8deg); }
}

/* ═══════════════════════════════
   STAGE HEADER
═══════════════════════════════ */
.stage-header {
  position: relative; z-index: 20;
  width: 100%; max-width: min(440px, 100vw);
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 6px;
}
.stage-badge {
  font-family: 'Cinzel', serif;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  color: #1a0a00; font-size: 0.85rem; font-weight: 900;
  padding: 5px 16px; border-radius: 20px;
  letter-spacing: 0.08em;
}
.score-badge { font-size: 0.82rem; color: #aaa; font-weight: 700; }

/* ═══════════════════════════════
   MONSTER STAGE AREA
═══════════════════════════════ */
.monster-stage {
  display: none;
}

/* monster-wrapはbodyの直接の子としてfixedで表示 */

/* platform */
.platform {
  position: fixed; bottom: 0px;
  left: 50%; transform: translateX(-50%);
  width: 220px; height: 24px;
  background: radial-gradient(ellipse, rgba(180,140,255,0.35) 0%, transparent 70%);
  border-radius: 50%;
  filter: blur(6px);
  z-index: 2;
}

/* monster SVG wrapper */
.monster-wrap {
  position: fixed; bottom: 10px;
  left: 50%; transform: translateX(-50%);
  z-index: 2;
  display: flex; flex-direction: column; align-items: center;
}
.monster-name-tag {
  font-family: 'Cinzel', serif;
  font-size: 0.9rem; font-weight: 700;
  color: var(--red); letter-spacing: 0.1em;
  text-shadow: 0 0 12px rgba(232,64,64,0.7);
  margin-bottom: 6px;
}
#monsterSvg {
  width: min(440px, 100vw); height: 700px;
  object-fit: contain;
  object-position: center bottom;
  display: block;
}
/* ホバーは外側divで常時かける */
#monsterAnim {
  animation: monsterHover 3s ease-in-out infinite;
  display: inline-block;
}
@keyframes monsterHover {
  0%,100%{ transform: translateY(0); }
  50%    { transform: translateY(-10px); }
}
/* ダメージを受けた時：ガタガタ震える */
#monsterAction.shake {
  animation: monsterShake 0.6s ease forwards;
}
@keyframes monsterShake {
  0%  {transform:translateX(0) rotate(0)}
  15% {transform:translateX(-14px) rotate(-6deg)}
  30% {transform:translateX(14px) rotate(6deg)}
  45% {transform:translateX(-10px) rotate(-3deg)}
  60% {transform:translateX(10px) rotate(3deg)}
  80% {transform:translateX(-4px)}
  100%{transform:translateX(0) rotate(0)}
}
/* ダメージを与えた時：小さく揺れて威張る */
#monsterAction.taunt {
  animation: monsterTaunt 0.8s ease forwards;
}
@keyframes monsterTaunt {
  0%  {transform:scale(1)    rotate(0)}
  20% {transform:scale(1.2) rotate(-8deg)}
  45% {transform:scale(1.18)  rotate(8deg)}
  65% {transform:scale(1.1)  rotate(-4deg)}
  85% {transform:scale(1.05)  rotate(2deg)}
  100%{transform:scale(1)    rotate(0)}
}
/* 勝利時：大きく迫ってくる */
#monsterAction.victory {
  animation: monsterVictory 1.0s cubic-bezier(.2,0,.4,1.4) forwards;
}
@keyframes monsterVictory {
  0%  {transform:scale(1)   translateY(0)}
  40% {transform:scale(1.8) translateY(-20px)}
  70% {transform:scale(1.7) translateY(-18px)}
  100%{transform:scale(1.75) translateY(-18px)}
}

/* モンスターフラッシュ */
@keyframes monsterFlash {
  0%   { filter: brightness(1); }
  20%  { filter: brightness(4); }
  50%  { filter: brightness(3); }
  100% { filter: brightness(1); }
}
.monster-flash {
  animation: monsterFlash 0.5s ease forwards;
}

/* ステージ突破演出 — translateX(-50%)をscaleと併記して位置ずれを防ぐ */
@keyframes bgZoomBlur {
  0%   { transform: translateX(-50%) scale(1);    filter: blur(0px);   opacity: 1; }
  100% { transform: translateX(-50%) scale(2.2);  filter: blur(24px);  opacity: 0; }
}
.bg-rush {
  animation: bgZoomBlur 1.2s cubic-bezier(.4,0,1,1) forwards;
}

/* モンスター撃破演出 */
@keyframes monsterDefeat {
  0%   { transform: translateY(0)   rotate(0deg)   scale(1);    opacity: 1; filter: brightness(1); }
  15%  { transform: translateY(-20px) rotate(-8deg) scale(1.05); opacity: 1; filter: brightness(5); }
  35%  { transform: translateY(10px)  rotate(12deg) scale(0.95); opacity: 0.8; filter: brightness(2); }
  55%  { transform: translateY(30px)  rotate(-6deg) scale(0.8);  opacity: 0.5; filter: brightness(1); }
  80%  { transform: translateY(60px)  rotate(4deg)  scale(0.5);  opacity: 0.2; }
  100% { transform: translateY(100px) rotate(0deg)  scale(0.2);  opacity: 0; }
}
.monster-defeat {
  animation: monsterDefeat 1.2s cubic-bezier(.4,0,.6,1) forwards;
}

/* 画面フラッシュ（プレイヤーダメージ） */
#screen-flash {
  position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  z-index: 100;
  background: white;
  pointer-events: none;
  opacity: 0;
}
@keyframes screenFlash {
  0%   { opacity: 0.7; }
  100% { opacity: 0; }
}
.screen-flash-anim {
  animation: screenFlash 0.5s ease forwards;
}

/* ── MONSTER HP BAR（モンスターの上） ── */
.monster-hp-bar-wrap {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: 100%; max-width: min(440px, 100vw);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px 16px;
}
.monster-hp-label-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
  font-family: 'Cinzel', serif; font-size: 0.82rem; font-weight: 700;
  color: var(--red); letter-spacing: 0.06em;
}
.monster-hp-label-row span:last-child { color: #aaa; font-family: 'Nunito', sans-serif; }

/* ── HP BAR BASE ── */
.hp-bar-bg { flex:1; height: 14px; background: rgba(0,0,0,0.5); border-radius: 7px; overflow:hidden; border: 1px solid rgba(255,255,255,0.06); }
.hp-bar-fill { height:100%; border-radius:7px; transition: width 0.5s cubic-bezier(.4,0,.2,1); }
.monster-hp-fill { background: linear-gradient(90deg,#7b0000,#e84040,#ff8080); }
.player-hp-fill  { background: linear-gradient(90deg,#005c52,#00e5cc,#88ffee); }

/* ── INPUT AREA（モンスターの下） ── */
.input-area {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: 100%; max-width: min(440px, 100vw);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
}
.problem-row {
  display: flex; flex-direction: column;
  align-items: center;
  justify-content: center; gap: 10px; margin-bottom: 14px;
}
.shown-number {
  font-family: 'Cinzel', serif;
  font-size: 5rem; font-weight: 900; color: var(--gold); line-height: 1;
  text-shadow: 0 0 30px rgba(245,200,66,0.6);
  text-align: center;
  animation: numPulse 1.5s ease-in-out infinite;
}
@keyframes numPulse {
  0%,100%{ text-shadow: 0 0 30px rgba(245,200,66,0.6); }
  50%    { text-shadow: 0 0 50px rgba(245,200,66,0.9), 0 0 80px rgba(245,200,66,0.4); }
}
.answer-input {
  width: 60px; height: 52px;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 10px; text-align: center;
  font-size: 1.8rem; font-weight: 900;
  color: #fff; outline: none;
  font-family: 'Nunito', sans-serif;
  transition: border-color 0.2s, box-shadow 0.2s;
  -moz-appearance: textfield;
  ime-mode: disabled;
}
.answer-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.answer-input:focus {
  border-color: var(--gold);
}

/* ── PROBLEM ROW アニメーション ── */
.problem-row {
  position: relative;
}
.equation-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.6s cubic-bezier(.4,0,.2,1), opacity 0.6s ease;
}
.eq-num {
  font-family: 'Cinzel', serif;
  font-size: 3.2rem; font-weight: 900; color: var(--gold); line-height: 1;
  text-shadow: 0 0 20px rgba(245,200,66,0.6);
  min-width: 2ch; text-align: center;
  animation: numPulse 1.5s ease-in-out infinite;
}
.eq-op {
  font-family: 'Nunito', sans-serif;
  font-size: 2.2rem; font-weight: 900;
  color: #ffffff;
  line-height: 1;
  -webkit-text-stroke: 0.5px #ffffff;
  text-shadow: 0 0 10px rgba(255,255,255,0.5);
}
.eq-answer {
  font-family: 'Cinzel', serif;
  font-size: 3.2rem; font-weight: 900;
  color: var(--teal);
  line-height: 1;
  min-width: 2ch; text-align: center;
  transition: color 0.12s;
}
.eq-target {
  font-family: 'Cinzel', serif;
  font-size: 3.2rem; font-weight: 900;
  color: rgba(255,255,255,0.85);
  line-height: 1;
}
.sum-display {
  font-family: 'Cinzel', serif;
  font-size: 7rem; font-weight: 900; line-height: 1;
  text-align: center;
  position: absolute; left: 50%; transform: translateX(-50%) scale(0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(.34,1.56,.64,1);
}

/* ── NUMPAD ── */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px auto 0;
  width: 80%;
}
.numpad-btn {
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  color: #fff;
  font-family: 'Cinzel', serif;
  font-size: 1.45rem; font-weight: 900;
  padding: 10px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.08s, border-color 0.08s, transform 0.08s;
}
.numpad-btn:active {
  background: rgba(245,200,66,0.22);
  border-color: var(--gold);
  color: var(--gold);
  transform: scale(0.91);
}
.numpad.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ── RESULT AREA ── */
.result-area {
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: min-height 0.2s ease;
}
.result-area:not(:empty) {
  min-height: 36px;
}
.result-text { font-size: 0.95rem; font-weight: 800; line-height: 1.5; text-align: center; color: #aaa; }
.col-m { color: #ff6060; }
.col-p { color: var(--teal); }
.col-perfect { color: var(--gold); }
.col-wait { color: #ffffff; }
.answer-input::placeholder { color: rgba(255,255,255,0.8); }

/* ── RESULT SCREEN OVERLAY ── */
#result-overlay {
  display: none; position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  background: rgba(0,0,0,0.88);
  align-items: center; justify-content: center;
  z-index: 200;
}
#result-overlay.show { display: flex; }
.result-box {
  background: linear-gradient(160deg, #0e0e2e, #1a1040);
  border: 1px solid rgba(245,200,66,0.35);
  border-radius: 24px; padding: 28px 28px 24px;
  text-align: center; max-width: 340px; width: 92%;
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1);
}
.result-emoji { font-size: 3.2rem; margin-bottom: 8px; }
.result-title {
  font-family: 'Cinzel', serif; font-size: 1.5rem; font-weight: 900;
  color: var(--gold); text-shadow: 0 0 20px rgba(245,200,66,0.5);
  margin-bottom: 6px;
}
.result-player-name {
  font-family: 'Cinzel', serif; font-size: 1.4rem; font-weight: 900;
  color: var(--teal);
  text-shadow: 0 0 16px rgba(0,229,204,0.6), 0 0 32px rgba(0,229,204,0.3);
  letter-spacing: 0.12em;
  margin-bottom: 4px;
}
.result-subtitle {
  font-size: 0.82rem; color: #aaa; margin-bottom: 16px;
}
.result-breakdown {
  background: rgba(255,255,255,0.05);
  border-radius: 12px; padding: 12px 16px;
  margin-bottom: 14px; text-align: left;
}
.result-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; font-size: 0.88rem; font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.result-row:last-child { border-bottom: none; }
.result-row-label { color: #aaa; }
.result-row-val { color: var(--gold); font-family: 'Cinzel', serif; }
.result-row-val.zero { color: #555; }
.result-total-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 10px; padding: 8px 16px;
  background: rgba(245,200,66,0.08);
  border-radius: 8px; font-size: 1rem; font-weight: 900;
}
.result-total-label { color: #ccc; font-family: 'Cinzel', serif; }
.result-total-val { color: var(--gold); font-size: 1.3rem; font-family: 'Cinzel', serif; text-shadow: 0 0 12px rgba(245,200,66,0.6); }
.result-grand {
  margin-top: 8px; font-size: 0.8rem; color: #888; text-align: right;
}
.result-grand span { color: var(--teal); font-weight: 900; }
.result-btn {
  margin-top: 16px;
  padding: 13px 36px;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  border: none; border-radius: 12px;
  color: #1a0a00; font-family: 'Cinzel', serif;
  font-size: 1rem; font-weight: 900; cursor: pointer;
  letter-spacing: 0.08em;
  -webkit-tap-highlight-color: transparent;
}
/* ═══════════════════════════════
   STAGE INTRO SCREEN
═══════════════════════════════ */
#stage-intro {
  display: none; position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  z-index: 150;
  align-items: center; justify-content: center;
  pointer-events: none;
}
#stage-intro.show { display: flex; }

/* ── STAGE NO ── */
.intro-stage-block {
  position: absolute; text-align: center;
  opacity: 0;
}
@keyframes stageNumIn {
  0%   { opacity: 0; letter-spacing: 0.6em; filter: blur(12px); }
  50%  { opacity: 1; letter-spacing: 0.25em; filter: blur(0); }
  100% { opacity: 1; letter-spacing: 0.25em; filter: blur(0); }
}
@keyframes stageNumOut {
  0%   { opacity: 1; transform: scale(1);   filter: blur(0); }
  100% { opacity: 0; transform: scale(1.2); filter: blur(16px); }
}
.intro-stage-block.in  { animation: stageNumIn  0.7s ease forwards; }
.intro-stage-block.out { animation: stageNumOut 0.45s ease forwards; }

.intro-stage-label {
  font-family: 'Cinzel', serif; font-size: 0.9rem; font-weight: 700;
  color: var(--gold); letter-spacing: 0.4em;
  text-shadow: 0 0 16px rgba(245,200,66,0.6);
  margin-bottom: 6px;
}
.intro-stage-num {
  font-family: 'Cinzel', serif; font-size: 6rem; font-weight: 900;
  color: #fff; line-height: 1;
  text-shadow: 0 0 50px rgba(255,255,255,0.5), 0 4px 30px rgba(0,0,0,0.9);
}

/* ── MONSTER NAME ── */
.intro-name-block {
  position: absolute; text-align: center;
  opacity: 0;
}
@keyframes nameSlideIn {
  0%   { opacity: 0; transform: translateY(40px); filter: blur(8px); }
  55%  { opacity: 1; transform: translateY(-4px); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0);    filter: blur(0); }
}
@keyframes nameSlideOut {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-36px); filter: blur(6px); }
}
.intro-name-block.in  { animation: nameSlideIn  0.6s cubic-bezier(.2,0,.3,1) forwards; }
.intro-name-block.out { animation: nameSlideOut 0.45s ease forwards; }

.intro-name-sub {
  font-family: 'Cinzel', serif; font-size: 0.8rem; font-weight: 700;
  color: #888; letter-spacing: 0.35em; margin-bottom: 10px;
}
.intro-monster-name {
  font-family: 'Cinzel', serif; font-size: 3.2rem; font-weight: 900;
  letter-spacing: 0.15em; line-height: 1.1;
  -webkit-text-stroke: 1.5px rgba(255,255,255,0.25);
  paint-order: stroke fill;
}
/* ステージごとに異なるグラデーション＋グロー */
.intro-col-0 {
  background: linear-gradient(160deg, #a8ffb0, #4ecb6a, #1a8a30);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 18px rgba(78,203,106,0.9)) drop-shadow(0 0 40px rgba(78,203,106,0.5));
}
.intro-col-1 {
  background: linear-gradient(160deg, #f0aaff, #c060ff, #6a00cc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 18px rgba(192,96,255,0.9)) drop-shadow(0 0 40px rgba(192,96,255,0.5));
}
.intro-col-2 {
  background: linear-gradient(160deg, #ffffff, #88ccff, #2266cc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 18px rgba(136,204,255,0.9)) drop-shadow(0 0 40px rgba(136,204,255,0.5));
}
.intro-col-3 {
  background: linear-gradient(160deg, #ffe080, #ff6622, #cc2200);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 18px rgba(255,102,34,0.9)) drop-shadow(0 0 40px rgba(255,102,34,0.5));
}
.intro-col-4 {
  background: linear-gradient(160deg, #ffccff, #dd44ff, #7700aa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 22px rgba(221,68,255,1.0)) drop-shadow(0 0 50px rgba(221,68,255,0.6));
}
.intro-name-catch {
  font-family: 'Nunito', sans-serif; font-size: 0.82rem; font-weight: 800;
  color: rgba(255,255,255,0.5); letter-spacing: 0.12em;
  margin-top: 12px;
  text-shadow: 0 0 12px rgba(255,255,255,0.2);
}

/* ── MONSTER APPEAR ── */
@keyframes monsterAppear {
  0%   { opacity: 0; filter: blur(24px) brightness(4); }
  40%  { opacity: 1; filter: blur(4px)  brightness(2.5); }
  70%  { filter: blur(0) brightness(1.4); }
  100% { opacity: 1; filter: blur(0)   brightness(1); }
}
.monster-appear {
  animation: monsterAppear 0.9s cubic-bezier(.2,0,.3,1) forwards !important;
}


/* ゲームクリア専用（全ステージ） */
.result-gameclear {
  font-family: 'Cinzel', serif; font-size: 1.1rem; font-weight: 900;
  color: #ff88ff; text-shadow: 0 0 16px rgba(255,100,255,0.6);
  margin-bottom: 8px;
}
.result-finalscore {
  font-size: 2.2rem; font-family: 'Cinzel', serif; font-weight: 900;
  color: var(--gold); text-shadow: 0 0 24px rgba(245,200,66,0.7);
  margin-bottom: 4px;
}

/* ── PLAYER HP BAR（画面最下部） ── */
.player-hp-bar-wrap {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  z-index: 20;
  width: 100%; max-width: min(440px, 100vw);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.player-hp-label-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
  font-size: 0.8rem; font-weight: 800; color: var(--teal);
}
.player-hp-label-row span:last-child { color: #aaa; }

/* ═══════════════════════════════
   DAMAGE POPUP
═══════════════════════════════ */
.dmg-popup {
  position: fixed; font-family: 'Cinzel', serif;
  font-size: 2rem; font-weight: 900;
  pointer-events: none;
  animation: floatUp 1s ease forwards;
  z-index: 300;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7);
}
@keyframes floatUp {
  0%  { opacity:1; transform:translateY(0)   scale(1.2); }
  100%{ opacity:0; transform:translateY(-90px) scale(1.5); }
}

/* ═══════════════════════════════
   COMBO POPUP
═══════════════════════════════ */
.combo-popup {
  position: fixed;
  pointer-events: none;
  z-index: 310;
  text-align: center;
  width: min(440px, 100vw);
  left: 0;
}
.combo-popup-num {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  line-height: 1;
  animation: comboBurst var(--dur, 1.4s) cubic-bezier(.22,1,.36,1) forwards;
}
.combo-popup-label {
  font-family: 'Nunito', sans-serif;
  font-size: 1rem; font-weight: 900;
  letter-spacing: 0.12em;
  animation: comboLabel var(--dur, 1.4s) ease forwards;
  margin-top: -4px;
}
@keyframes comboBurst {
  0%   { opacity: 0;   transform: scale(0.3) rotate(-10deg); filter: brightness(3); }
  18%  { opacity: 1;   transform: scale(1.35) rotate(4deg);  filter: brightness(2.5); }
  35%  { transform: scale(1.05) rotate(-2deg); filter: brightness(1.5); }
  55%  { transform: scale(1.12) rotate(1deg);  filter: brightness(1.2); opacity: 1; }
  80%  { opacity: 1;   transform: scale(1.08) rotate(0deg);  filter: brightness(1); }
  100% { opacity: 0;   transform: scale(1.3) translateY(-40px); filter: brightness(1); }
}
@keyframes comboLabel {
  0%   { opacity: 0;   transform: translateY(8px) scale(0.8); }
  25%  { opacity: 1;   transform: translateY(0)   scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0;   transform: translateY(-30px); }
}

/* ═══════════════════════════════
   OVERLAY
═══════════════════════════════ */
.overlay {
  display:none; position:fixed;
  top:0; left:50%; transform:translateX(-50%);
  width:min(440px,100vw); height:100%;
  background: rgba(0,0,0,0.85);
  align-items:center; justify-content:center;
  z-index:200;
}
.overlay.show { display:flex; }
.overlay-box {
  background: linear-gradient(160deg, #0e0e2e, #1a1040);
  border: 1px solid rgba(245,200,66,0.3);
  border-radius: 24px; padding: 40px 32px;
  text-align:center; max-width:320px; width:90%;
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn {
  from{ transform:scale(0.5) rotate(-5deg); opacity:0; }
  to  { transform:scale(1)   rotate(0);     opacity:1; }
}
.overlay-emoji { font-size: 4rem; margin-bottom: 14px; }
.overlay-title { font-family:'Cinzel',serif; font-size:1.8rem; font-weight:900; margin-bottom:10px; }
.overlay-title.win  { color:var(--gold); text-shadow:0 0 20px rgba(245,200,66,0.5); }
.overlay-title.lose { color:var(--red);  text-shadow:0 0 20px rgba(232,64,64,0.5); }
.overlay-msg { font-size:0.88rem; color:#aaa; margin-bottom:24px; line-height:1.8; white-space:pre-line; }
.overlay-btn {
  padding:14px 36px;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  border:none; border-radius:12px;
  color:#1a0a00; font-family:'Cinzel',serif;
  font-size:1rem; font-weight:900; cursor:pointer;
  letter-spacing:0.08em;
  -webkit-tap-highlight-color:transparent;
}

/* ═══════════════════════════════
   TITLE SCREEN
═══════════════════════════════ */
#title-screen {
  display: flex; position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  z-index: 600;
  align-items: center; justify-content: center;
  flex-direction: column;
  background: linear-gradient(180deg, #020008 0%, #0a0018 50%, #050010 100%);
}
#title-screen.hidden { display: none; }

/* 背景パーティクルキャンバス */
#title-particles {
  position: absolute; inset: 0; pointer-events: none;
}

/* タイトルロゴ */
.title-logo-wrap {
  position: relative; z-index: 1; text-align: center;
  animation: titleFloat 3s ease-in-out infinite;
}
@keyframes titleFloat {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

.title-main {
  font-family: 'Cinzel', serif; font-weight: 900;
  font-size: clamp(2.4rem, 9vw, 4rem); line-height: 1;
  letter-spacing: 0.06em;
  background: linear-gradient(160deg, #ffffff 0%, #f5c842 40%, #ff8800 70%, #ff44ff 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  filter: drop-shadow(0 0 24px rgba(245,200,66,0.8)) drop-shadow(0 0 60px rgba(255,100,255,0.4));
  animation: titleGlow 2.5s ease-in-out infinite alternate;
}
@keyframes titleGlow {
  from { filter: drop-shadow(0 0 20px rgba(245,200,66,0.7)) drop-shadow(0 0 50px rgba(255,80,255,0.3)); }
  to   { filter: drop-shadow(0 0 36px rgba(245,200,66,1.0)) drop-shadow(0 0 80px rgba(255,80,255,0.6)); }
}

.title-sub {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: 1.1rem; letter-spacing: 0.2em;
  color: rgba(255,255,255,0.7);
  text-shadow: 0 0 12px rgba(255,255,255,0.4);
  margin-top: 10px;
}

/* 区切り装飾 */
.title-divider {
  width: 200px; height: 2px; margin: 24px auto;
  background: linear-gradient(90deg, transparent, var(--gold), #ff44ff, transparent);
  position: relative; z-index: 1;
}

/* スタートボタン */
.title-btn {
  position: relative; z-index: 1;
  padding: 16px 52px;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  border: none; border-radius: 14px;
  color: #1a0a00; font-family: 'Cinzel', serif;
  font-size: 1.1rem; font-weight: 900; cursor: pointer;
  letter-spacing: 0.1em;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 24px rgba(245,200,66,0.5), 0 4px 20px rgba(0,0,0,0.6);
  animation: btnPulse 2s ease-in-out infinite;
}
@keyframes btnPulse {
  0%,100% { box-shadow: 0 0 20px rgba(245,200,66,0.4), 0 4px 20px rgba(0,0,0,0.6); transform: scale(1); }
  50%      { box-shadow: 0 0 40px rgba(245,200,66,0.8), 0 4px 20px rgba(0,0,0,0.6); transform: scale(1.03); }
}

/* バージョン表記 */
.title-version {
  position: absolute; bottom: 16px;
  font-size: 0.7rem; color: rgba(255,255,255,0.2);
  letter-spacing: 0.1em; z-index: 1;
}

/* ═══════════════════════════════
   NAME ENTRY SCREEN
═══════════════════════════════ */
#name-screen {
  display: flex; position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  align-items: center; justify-content: center;
  z-index: 500;
  background: rgba(0,0,0,0.92);
}
#name-screen.hidden { display: none; }
.name-box {
  background: linear-gradient(160deg, #0e0e2e, #1a1040);
  border: 1px solid rgba(245,200,66,0.35);
  border-radius: 24px; padding: 36px 28px 30px;
  text-align: center; max-width: 320px; width: 90%;
  animation: popIn 0.5s cubic-bezier(.34,1.56,.64,1);
}
.name-title {
  font-family: 'Cinzel', serif; font-size: 1.6rem; font-weight: 900;
  color: var(--gold); text-shadow: 0 0 20px rgba(245,200,66,0.5);
  margin-bottom: 6px;
}
.name-sub { font-size: 0.82rem; color: #aaa; margin-bottom: 22px; }
.name-input {
  width: 100%; padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 12px; text-align: center;
  font-size: 1.4rem; font-weight: 900;
  color: #fff; outline: none;
  font-family: 'Nunito', sans-serif;
  letter-spacing: 0.08em;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}
.name-input:focus { border-color: var(--gold); }
.name-input::placeholder { color: rgba(255,255,255,0.3); font-size: 1rem; font-weight: 700; }
.name-btn {
  padding: 13px 40px;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  border: none; border-radius: 12px;
  color: #1a0a00; font-family: 'Cinzel', serif;
  font-size: 1rem; font-weight: 900; cursor: pointer;
  letter-spacing: 0.08em;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s;
}
.name-btn:disabled { opacity: 0.4; cursor: default; }

/* 確認パネル（name-box内に重ねて表示） */
.name-confirm {
  display: none;
  animation: popIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
.name-confirm.show { display: block; }
.name-confirm-label {
  font-size: 0.82rem; color: #aaa; margin-bottom: 10px;
}
.name-confirm-val {
  font-family: 'Cinzel', serif; font-size: 2rem; font-weight: 900;
  color: var(--gold); text-shadow: 0 0 16px rgba(245,200,66,0.5);
  margin-bottom: 20px; letter-spacing: 0.1em;
}
.name-confirm-btns {
  display: flex; gap: 10px; justify-content: center;
}
.name-confirm-btns .name-btn { padding: 12px 24px; font-size: 0.9rem; }
.name-confirm-btns .name-btn-back {
  padding: 12px 24px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  color: #aaa; font-family: 'Cinzel', serif;
  font-size: 0.9rem; font-weight: 900; cursor: pointer;
  letter-spacing: 0.05em;
  -webkit-tap-highlight-color: transparent;
}

/* ═══════════════════════════════
   RANKING SCREEN
═══════════════════════════════ */
#ranking-screen {
  display: none; position: fixed;
  top: 0; left: 50%; transform: translateX(-50%);
  width: min(440px, 100vw); height: calc(var(--vh, 1vh) * 100);
  align-items: center; justify-content: center;
  z-index: 400;
  background: rgba(0,0,0,0.92);
}
#ranking-screen.show { display: flex; }
.ranking-box {
  background: linear-gradient(160deg, #0e0e2e, #1a1040);
  border: 1px solid rgba(245,200,66,0.35);
  border-radius: 24px; padding: 24px 24px 20px;
  text-align: center; max-width: 340px; width: 92%;
  max-height: 88vh;
  display: flex; flex-direction: column;
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1);
}
.ranking-title {
  font-family: 'Cinzel', serif; font-size: 1.4rem; font-weight: 900;
  color: var(--gold); text-shadow: 0 0 16px rgba(245,200,66,0.5);
  margin-bottom: 4px; flex-shrink: 0;
}
.ranking-subtitle { font-size: 0.78rem; color: #888; margin-bottom: 14px; flex-shrink: 0; }
.ranking-list {
  overflow-y: auto; flex: 1;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(245,200,66,0.3) transparent;
}
.ranking-list::-webkit-scrollbar { width: 4px; }
.ranking-list::-webkit-scrollbar-track { background: transparent; }
.ranking-list::-webkit-scrollbar-thumb { background: rgba(245,200,66,0.3); border-radius: 2px; }
.ranking-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px;
  margin-bottom: 4px;
  background: rgba(255,255,255,0.04);
  transition: background 0.2s;
}
.ranking-row.top1 { background: rgba(245,200,66,0.12); border: 1px solid rgba(245,200,66,0.25); }
.ranking-row.top2 { background: rgba(200,200,220,0.08); border: 1px solid rgba(200,200,220,0.15); }
.ranking-row.top3 { background: rgba(200,120,50,0.10); border: 1px solid rgba(200,120,50,0.2); }
.ranking-row.new-entry { animation: newEntryGlow 1.5s ease-in-out infinite alternate; }
@keyframes newEntryGlow {
  from { box-shadow: 0 0 0px rgba(0,229,204,0.0); background: rgba(0,229,204,0.08); }
  to   { box-shadow: 0 0 12px rgba(0,229,204,0.4); background: rgba(0,229,204,0.14); }
}
.ranking-rank {
  font-family: 'Cinzel', serif; font-size: 0.95rem; font-weight: 900;
  width: 28px; text-align: center; flex-shrink: 0;
}
.rank-1 { color: #f5c842; }
.rank-2 { color: #c8c8dc; }
.rank-3 { color: #c87832; }
.rank-other { color: #666; }
.ranking-name {
  flex: 1; font-size: 0.9rem; font-weight: 800;
  color: #ddd; text-align: left; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
}
.ranking-name.new-name { color: var(--teal); }
.ranking-score {
  font-family: 'Cinzel', serif; font-size: 0.92rem; font-weight: 900;
  color: var(--gold); flex-shrink: 0;
}
.ranking-type {
  font-size: 0.68rem; color: #666; flex-shrink: 0;
}
.ranking-empty { color: #555; font-size: 0.85rem; padding: 20px 0; }
.ranking-loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 32px 0; gap: 12px; color: #888; font-size: 0.82rem;
}
.ranking-spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(245,200,66,0.15);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ranking-divider {
  border: none; border-top: 1px solid rgba(255,255,255,0.06);
  margin: 6px 0; flex-shrink: 0;
}
.ranking-btn {
  margin-top: 14px; flex-shrink: 0;
  padding: 12px 36px;
  background: linear-gradient(135deg, #7b4f00, var(--gold));
  border: none; border-radius: 12px;
  color: #1a0a00; font-family: 'Cinzel', serif;
  font-size: 0.95rem; font-weight: 900; cursor: pointer;
  letter-spacing: 0.08em;
  -webkit-tap-highlight-color: transparent;
}
.ranking-btn-sub {
  margin-top: 8px; flex-shrink: 0;
  padding: 10px 36px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  color: #888; font-family: 'Cinzel', serif;
  font-size: 0.82rem; font-weight: 700; cursor: pointer;
  letter-spacing: 0.05em;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, border-color 0.2s;
}
.ranking-btn-sub:hover { color: #bbb; border-color: rgba(255,255,255,0.35); }

/* ── TIMER ── */
.timer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.timer-bar-bg {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--teal);
  border-radius: 4px;
  transition: background 0.3s ease;
}
.timer-num {
  font-family: 'Cinzel', serif;
  font-size: 1rem; font-weight: 900;
  color: var(--teal);
  min-width: 1.4rem;
  text-align: right;
  transition: color 0.3s ease;
}
