/* =========================================================
   ゲピミニファイト - レイアウト / UI
   スマホ縦持ち前提。上半分がゲーム画面、下半分が携帯ゲーム機ふうの操作盤。
   ========================================================= */

:root {
  color-scheme: dark;
  --bg: #07090b;
  --ink: #f2f6f8;
  --muted: #9fb0ba;
  --line: #2c3740;
  --accent: #5fc3e4;
  --danger: #e2483f;
  --good: #6fd07a;
  --warn: #f2c14e;

  /* 画面の 1%（JS が実寸から設定する）。
     vh / vw は端末やアドレスバーで値がぶれるうえ、
     回転モードでは縦横が入れ替わってしまうため使わない。 */
  --vw: 1vw;
  --vh: 1vh;

  /* ゲーム画面（上）と操作盤（下）それぞれの 1%。
     HUD は画面の高さ、ボタンは操作盤の高さを基準にすると、
     どちらも端末の縦横比に振り回されずに収まる。 */
  --sw: 1vw;
  --sh: 1vh;
  --dw: 1vw;
  --dh: 1vh;

  /* セーフエリア（ノッチ対応）。生の値と、ゲームから見た向きを分けて持つ。 */
  --raw-t: env(safe-area-inset-top, 0px);
  --raw-r: env(safe-area-inset-right, 0px);
  --raw-b: env(safe-area-inset-bottom, 0px);
  --raw-l: env(safe-area-inset-left, 0px);
  --safe-l: var(--raw-l);
  --safe-r: var(--raw-r);
  --safe-t: var(--raw-t);
  --safe-b: var(--raw-b);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  /* ページごと引っぱられるのを止める（iOS の引っぱって更新・ゴムのような跳ね返り） */
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  /* 横向きにしたときに iOS が文字を勝手に大きくするのを止める */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* touch-action は親から受け継がれない。
   body にだけ書いても、ゲーム画面の上を指でなぞると
   iOS がページを動かしてしまう。中の箱ぜんぶに当てておく。
   スクロールさせたい所（LOG）は、あとで pan-y に戻している。 */
#app,
#app * {
  touch-action: none;
  overscroll-behavior: none;
}

/* 指でなぞって動かしたいのは、これまでの会話（LOG）だけ */
#app .story-log-list {
  touch-action: pan-y;
}

/* body を画面に貼り付けて、ページ自体が動かないようにする。

   上ではなく「下」を基準にする。
   iOS はバーの出入りで見えている高さが変わるので、上を固定すると
   足りないぶんが下から削れて、操作盤が画面外へ逃げてしまう。
   下を基準にしておけば、操作盤は必ず指の届く位置に残り、
   はみ出すとしてもゲーム画面の上端だけになる。

   高さは dvh を基準にしつつ、実寸は viewport.js が px で入れ直す。 */
body {
  margin: 0;
  padding: 0;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  /* ゲーム内の文字はすべてドット風フォントで統一する */
  font-family: "DotGothic16", "Press Start 2P", "MS Gothic", monospace;
  /* ゲーム中のスクロール・ピンチズームを抑止 */
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  /* 長押しのメニュー、タップ時の青い反転、画像のドラッグを止める */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 中の要素にも同じ扱いを行き渡らせる。
   文字も絵も「選べない・つかめない」ようにしておく。 */
*,
*::before,
*::after {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

img,
canvas {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------------------------------------------------------
   読み物（はじまり／おわり）
   上に絵、下に文章。タップで先へ進む。
   --------------------------------------------------------- */
/* .full-screen が後ろのほうで justify-content と padding を当ててくるので、
   セレクタを一段強くして、こちらの指定を通す。 */
.full-screen.story-screen {
  /* ほかの全画面表示より前に出す */
  z-index: 60;
  justify-content: flex-end;
  padding: 0;
  gap: 0;
  background: #05070a;
  cursor: pointer;
}

/* 場面の絵。無い場面は下地だけになる。 */
.story-screen .story-bg {
  position: absolute;
  inset: 0;
  background: #0a0e13 center / cover no-repeat;
  filter: brightness(0.62) saturate(0.85);
  transition: opacity 0.25s linear;
}

/* --- 場面の見せ場 ---
   絵は横長、画面は縦長なので、ふだんは左右が切れている。
   ここぞという行だけ、切れている端までなぞって見せる。 */
@keyframes story-sweep {
  0% { background-position: 0% 50%; }
  40% { background-position: 100% 50%; }
  58% { background-position: 100% 50%; }
  100% { background-position: 50% 50%; }
}

.story-screen .story-bg.sweep {
  animation: story-sweep 3.6s ease-in-out both;
}

/* 見せ場のあいだは、ふだんより明るくして絵を見せる */
.story-screen .story-bg.sweep {
  filter: brightness(0.88) saturate(0.95);
}

/* --- 驚いて飛び跳ねる ---
   置き場所（translate / scale）とは別の性質なので、
   ここは動きぶんだけを書けばよい。 */
@keyframes story-hop {
  0% { transform: translateY(0); }
  16% { transform: translateY(-7%); }
  34% { transform: translateY(0); }
  50% { transform: translateY(-4%); }
  68% { transform: translateY(0); }
  100% { transform: translateY(0); }
}

.story-screen .story-actor.hop {
  animation: story-hop 0.85s ease-out 2;
}

/* --- 焦って走っている絵は、上下に弾ませ続ける --- */
@keyframes story-bob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-2.2%); }
  100% { transform: translateY(0); }
}

.story-screen .story-actor.bob {
  animation: story-bob 0.62s ease-in-out infinite;
}

/* 跳ねる動きのほうが強いので、そちらを優先する */
.story-screen .story-actor.bob.hop {
  animation: story-hop 0.85s ease-out 2;
}

/* --- 相手役が画面の外から突っ込んでくる ---
   相手役は scale: -1 で裏返してあるので、
   transform の translateX も向きが裏返る（＋で画面の左）。 */
@keyframes story-rush {
  0% { transform: translateX(125%); }
  52% { transform: translateX(-7%); }
  68% { transform: translateX(3%); }
  100% { transform: translateX(0); }
}

.story-screen .story-actor.rush {
  animation: story-rush 0.62s cubic-bezier(0.2, 0.75, 0.3, 1) both;
}

/* --- ぶつかられた主人公は、右へのけぞってから戻る --- */
@keyframes story-knock {
  0%, 46% { transform: translateX(0) rotate(0); }
  56% { transform: translateX(7%) rotate(4deg); }
  72% { transform: translateX(2%) rotate(-1deg); }
  100% { transform: translateX(0) rotate(0); }
}

.story-screen .story-actor.knock {
  animation: story-knock 0.85s ease-out;
}

/* --- ぶつかった瞬間に画面ごと揺らす --- */
@keyframes story-shake {
  0% { transform: translate(0, 0); }
  12% { transform: translate(-9px, 5px); }
  26% { transform: translate(8px, -4px); }
  40% { transform: translate(-6px, -5px); }
  56% { transform: translate(5px, 4px); }
  72% { transform: translate(-3px, 2px); }
  100% { transform: translate(0, 0); }
}

.full-screen.story-screen.shake {
  animation: story-shake 0.5s ease-out 0.3s;
}

/* 動きを控えたい人の設定は尊重する */
@media (prefers-reduced-motion: reduce) {
  .story-screen .story-bg.sweep,
  .story-screen .story-actor.hop,
  .story-screen .story-actor.bob,
  .story-screen .story-actor.rush,
  .story-screen .story-actor.knock,
  .full-screen.story-screen.shake {
    animation: none;
  }
}

/* --- 立ち絵 ---
   主人公は画面の右、相手役は画面の左。

   置き場所と裏返しは translate / scale（個別の変換）で持ち、
   動き（跳ねる・突っ込む・のけぞる）は transform で持つ。
   この 2 つは掛け合わさるので、置き場所ごとに同じアニメを
   何本も書き分けなくて済む。 */
.story-screen .story-actor {
  position: absolute;
  top: 4%;
  bottom: 22%;
  width: 58%;
  background-repeat: no-repeat;
  background-size: contain;
  /* 前後の順番。喋っているほうを前に出す（.on で 2 に上がる）。
     これが無いと、あとに書いてあるほうがいつも前になってしまう。 */
  z-index: 1;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.8));
  transition: opacity 0.22s linear, transform 0.22s ease-out,
    filter 0.22s linear;
  opacity: 0;
}

/* 主人公。画面の右。絵はそのまま出す。
   縦長（2:3）なので大きさは横幅で決まる。幅を広げ、
   足元が文章の箱に少しかかるところまで下げる。 */
.story-screen .story-actor.hero {
  right: 1%;
  bottom: 14%;
  width: 68%;
  background-position: right bottom;
}

/* 相手役。画面の左。
   絵は左を向いて描いてあるので、裏返して主人公と向かい合わせる。 */
.story-screen .story-actor.foe {
  left: 1%;
  background-position: left bottom;
  scale: -1 1;
}

/* 1 人だけのときは真ん中へ寄せる */
.story-screen .story-actor.solo {
  left: 50%;
  right: auto;
  bottom: 13%;
  width: 78%;
  background-position: center bottom;
  translate: -50% 0;
}

/* 喋っているほうを前に出す */
.story-screen .story-actor.on {
  z-index: 2;
  opacity: 1;
}

/* 喋っていないほうは、少し下げて暗くする */
.story-screen .story-actor.off {
  opacity: 0.72;
  translate: 0 2%;
  filter: brightness(0.5) drop-shadow(0 8px 18px rgba(0, 0, 0, 0.8));
}

.story-screen .story-actor.solo.off {
  translate: -50% 2%;
}

/* 絵が無い場面でも寂しくならないよう、薄い光を敷いておく */
.story-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 34%,
    rgba(60, 78, 100, 0.35) 0%,
    rgba(10, 14, 19, 0) 62%);
  pointer-events: none;
}

.story-box {
  position: relative;
  /* 立ち絵（1〜2）と暗転の幕（3）より前。腰から下が箱に隠れる。 */
  z-index: 4;
  width: 90%;
  margin: 0 0 calc(var(--vh) * 3);
  min-height: 26%;
  box-sizing: border-box;
  padding: calc(var(--vh) * 3.2) 5% calc(var(--vh) * 3);
  text-align: left;
  /* 平らな一色。白い線で、角だけ丸く囲う。 */
  background: rgba(9, 12, 16, 0.92);
  border: 2px solid #ffffff;
  border-radius: 12px;
}

/* 名前の板。箱と同じ作りで、上のふちにまたがって置く。 */
.story-name {
  position: absolute;
  /* 箱の角丸にかからないよう、左端から少し内側に置く */
  /* 少し左へ寄せる（箱の角丸ぎりぎりまで） */
  left: calc(7% - 10px);
  top: 0;
  transform: translateY(-50%);
  display: inline-block;
  padding: 0.3em 1.5em;
  /* 白い板に黒い文字。話している人の名前をはっきり出す */
  background: #ffffff;
  border: 2px solid #0a0d11;
  border-radius: 10px;
}

.story-name > i {
  display: block;
  font-style: normal;
  font-family: "DotGothic16", "MS Gothic", monospace;
  font-size: clamp(13px, calc(var(--vh) * 2.5), 22px);
  font-weight: 700;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: #0a0d11;
}

/* 名前が無い行では板ごと消す */
.story-name.empty {
  display: none;
}

.story-text {
  margin: calc(var(--vh) * 0.6) 0 0;
  font-size: clamp(13px, calc(var(--vh) * 2.5), 22px);
  line-height: 1.7;
  color: #ffffff;
  white-space: pre-line;
  min-height: 3.4em;
}

/* 次へ進む合図 */
.story-next {
  position: absolute;
  right: 7%;
  bottom: calc(var(--vh) * 1.4);
  font-size: clamp(12px, calc(var(--vh) * 2.2), 20px);
  color: #ffffff;
  opacity: 0;
  transition: opacity 0.15s linear;
  animation: story-tap 0.9s ease-in-out infinite;
}

.story-next.on {
  opacity: 1;
}

@keyframes story-tap {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

.story-menu {
  position: absolute;
  right: calc(4% + var(--safe-r, 0px));
  top: calc(var(--vh) * 2);
  z-index: 5;
  display: flex;
  gap: 6px;
}

.story-btn {
  padding: 0.4em 0.9em;
  border: 2px solid #ffffff;
  border-radius: 10px;
  background: rgba(9, 12, 16, 0.85);
  color: #ffffff;
  font-family: inherit;
  font-size: clamp(10px, calc(var(--vh) * 1.9), 15px);
  letter-spacing: 0.1em;
  cursor: pointer;
  touch-action: manipulation;
}

/* AUTO が入っているあいだは、白と黒を入れ替える */
.story-btn.on {
  background: #ffffff;
  color: #0b0e12;
}

/* --- これまでの会話（LOG） --- */
.story-logbox {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  padding: calc(var(--vh) * 8) 6% calc(var(--vh) * 3);
  box-sizing: border-box;
  background: rgba(4, 6, 9, 0.97);
}

.story-logbox.hidden {
  display: none;
}

.story-log-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  text-align: left;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.story-log-list p {
  margin: 0 0 calc(var(--vh) * 1.6);
  font-size: clamp(12px, calc(var(--vh) * 2.2), 19px);
  line-height: 1.65;
  color: #e6edf3;
  white-space: pre-line;
}

.story-log-list b {
  display: block;
  margin-bottom: 0.2em;
  font-size: 0.86em;
  letter-spacing: 0.08em;
  color: #ffffff;
}

.story-btn.close {
  align-self: center;
  margin-top: calc(var(--vh) * 2);
  padding: 0.5em 2.2em;
}





/* ---------------------------------------------------------
   読み込み中の画面
   絵と音がそろうまでのあいだ、画面ぜんぶを覆っておく。
   演出は、下のほうを小さなゲピミニが走っていくだけにしてある。
   走りの絵（assets/boot-run.webp）は 7 コマを横に並べた軽い 1 枚で、
   CSS だけでコマを送るので、JS の読み込みを待たずに動き出す。
   --------------------------------------------------------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 900;
  /* タイトルの絵をモノクロにしたものを敷き、その上を暗く落として文字を読ませる。
     絵が届く前でも下地の色で成り立つよう、最後に無地を置いておく。 */
  background:
    linear-gradient(rgba(10, 13, 18, 0.58), rgba(10, 13, 18, 0.78)),
    url("assets/load-bg.webp") center / cover no-repeat,
    #0d1014;
  transition: opacity 0.35s linear;
}

.boot[hidden] {
  display: none;
}

.boot.done {
  opacity: 0;
  pointer-events: none;
}

/* 走る道。画面の下のほうに、うすい線を 1 本だけ引く */
.boot-run {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12vh);
  height: 44px;
  border-bottom: 2px solid rgba(159, 176, 191, 0.22);
}

/* 1 コマ 83x96 の絵を、高さ 44px（幅 38px）で出す。
   background-size を 7 倍にして、steps(7) で 1 コマずつずらす。
   位置を 0% → 116.667%（= 7/6）まで送ると、ちょうど 7 コマぶん回る。 */
.boot-run > i {
  position: absolute;
  bottom: 2px;
  left: 0;
  width: 38px;
  height: 44px;
  background: url("assets/boot-run.webp") 0 0 / 700% 100% no-repeat;
  animation:
    boot-legs 0.62s steps(7) infinite,
    boot-travel 3.4s linear infinite;
}

@keyframes boot-legs {
  to { background-position: 116.667% 0; }
}

@keyframes boot-travel {
  from { left: -38px; }
  to { left: 100%; }
}

.boot-note {
  position: absolute;
  right: 8%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12vh - 24px);
  font-size: clamp(9px, 2.8vw, 12px);
  letter-spacing: 0.18em;
  color: #7f909e;
}

@media (prefers-reduced-motion: reduce) {
  .boot-run > i {
    animation: boot-legs 0.62s steps(7) infinite;
    left: calc(50% - 19px);
  }
}

/* ---------------------------------------------------------
   ステージ：上にゲーム画面、下に操作盤の縦積み
   --------------------------------------------------------- */
/* position:fixed を使わない。
   iOS Safari の fixed は URL バーの下まで伸びる「大きいビューポート」を指すため、
   中に置いた箱を中央寄せすると上下がブラウザの UI に隠れてしまう。
   通常フローの height:100% なら、実際に見えている範囲だけが割り当たる。 */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070a;
}

#stage {
  position: relative;
  /* 高さは #app（＝実際に見えている範囲）にぴったり合わせる */
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #05070a;
}

/* --- 上：ゲーム画面のパネル（本体に埋まった液晶に見せる） --- */
#screenPanel {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* 余った高さは液晶まわりのベゼルとして上下に振り分ける */
  justify-content: center;
  padding: calc(var(--safe-t) + 6px) calc(3% + var(--safe-r)) 6px calc(3% + var(--safe-l));
  background:
    linear-gradient(180deg, #23272d 0%, #191d22 62%, #12161a 100%);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.05);
}

/* 電源ランプと、液晶の上に入っている刻印 */
.screen-top {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-bottom: 5px;
  min-height: 0;
}

/* 液晶そのもの。ここにキャンバスと HUD とオーバーレイが入る。 */
#screenInner {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  background: #000;
  border-radius: 6px;
  /* 内側に落ちる影で「はめ込んである」感じを出す */
  box-shadow:
    0 0 0 3px #0b0e11,
    0 0 0 5px #2e343b,
    inset 0 0 22px rgba(0, 0, 0, 0.85);
  /* 実寸は JS が画面の空き幅・空き高さから決める。
     万一 JS の組み直しが遅れても、枠からはみ出さないよう上限を付けておく。 */
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.screen-brand {
  flex: 0 0 auto;
  padding-top: 6px;
  font-size: clamp(8px, calc(var(--vw) * 2.6), 14px);
  letter-spacing: 0.22em;
  color: #8b959d;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8);
}

#game {
  display: block;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* 実寸は JS が画面に合わせて設定する */
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------------------------------------------------------
   下：操作盤（携帯ゲーム機の下半分に見立てる）
   --------------------------------------------------------- */
#deck {
  position: relative;
  flex: 0 0 auto;
  /* 高さは JS が端末に合わせて決める */
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-b);
  background:
    /* 上端のハイライトと、下へ向かう樹脂の陰り */
    linear-gradient(180deg, #2b3037 0%, #21262c 26%, #171b20 74%, #0f1216 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.07);
}

/* 本体の丸みと、上端の合わせ目 */
#deck::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
}

/* ---------------------------------------------------------
   HUD
   --------------------------------------------------------- */
/* 必殺技のカットイン中だけ HUD を伏せる */
#hud.dimmed {
  opacity: 0;
  transition: opacity 0.12s linear;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2%;
  padding: calc(1.4% + 4px) 2% 0 2%;
  pointer-events: none;
  font-size: clamp(8px, calc(var(--sh) * 3.4), 15px);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.7);
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  /* 真ん中の残り時間に重ならないよう、左右は画面の 4 割までに抑える */
  max-width: 38%;
}

.hud-right {
  align-items: flex-end;
}

/* キャラ名と「HP」の文字は画面を狭くするだけなので出さない */
.name-plate,
.gauge-label {
  display: none;
}

/* HP ゲージ：装飾の枠（assets/ui/gauge-hp.webp）は中央が空洞なので、
   その穴の位置にゲージの中身を敷いて、枠を上から重ねる。
   穴の位置は tools/build_assets.py が切り出した画像から実測した値。 */
.gauge {
  position: relative;
  /* % だと親要素の幅が基準になってしまうので、画面基準の --vw を使う */
  width: min(calc(var(--vw) * 25), 240px);
  aspect-ratio: 1053 / 235;
}



/* 枠の空洞を上下に分け、上を青いチャージ、下を HP にする */
.charge-bar {
  position: absolute;
  left: 21.3%;
  top: 24.3%;
  width: 70.8%;
  height: 16%;
  background: #10161d;
  overflow: hidden;
  border-radius: 2px;
}

.charge-bar > i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(180deg, #a8e8ff, #35a7dd 60%, #1a5f8a);
  transition: width 0.1s linear;
}

/* 満タン＝回復中は光らせて、効いていることを分かるようにする */
.charge-bar > i.full {
  background: linear-gradient(180deg, #e6f9ff, #6fd8ff 60%, #2b8fc4);
  box-shadow: 0 0 8px rgba(120, 220, 255, 0.9);
  animation: charge-pulse 0.7s ease-in-out infinite;
}

@keyframes charge-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.45); }
}

@media (prefers-reduced-motion: reduce) {
  .charge-bar > i.full { animation: none; }
}

.gauge-bar {
  position: absolute;
  left: 21.3%;
  top: 42.5%;
  width: 70.8%;
  height: 29.5%;
  background: #14181d;
  overflow: hidden;
  border-radius: 3px;
}

.gauge::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("assets/ui/gauge-hp.webp") center / 100% 100% no-repeat;
  pointer-events: none;
}

.gauge-bar > i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #b6f5bd, var(--good) 60%, #3f9a4c);
  transition: width 0.15s linear;
}

.gauge-bar > i.low {
  background: linear-gradient(180deg, #ffb0a6, var(--danger) 60%, #9c2b23);
}

/* 残り時間は「画面のど真ん中」に置く。
   flex の余りに置くと、左（HPゲージ）と右（アイテム枠）の
   幅が違うぶんだけ中心がずれてしまう。 */
.hud-center {
  position: absolute;
  left: 50%;
  top: calc(1.4% + 4px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  z-index: 1;
}

/* --- 画面上部中央：残り時間（格闘ゲーム風） --- */
.time-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 1px;
}

.time-label {
  font-size: 0.72em;
  letter-spacing: 0.22em;
  color: var(--muted);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.8);
}

.time-value {
  font-size: clamp(20px, calc(var(--sh) * 10.92), 46px);
  font-variant-numeric: tabular-nums;
  color: #ffffff;
  -webkit-text-stroke: 4px #14100c;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
}

/* 残り 20 秒を切ったら赤く点滅させて煽る */
.time-value.hurry {
  color: #ff6b5a;
  animation: time-blink 0.5s steps(2, end) infinite;
}

@keyframes time-blink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0.4; }
}

@media (prefers-reduced-motion: reduce) {
  .time-value.hurry { animation: none; }
}

/* --- 画面上部中央：スコアとコンボ --- */
.score-block {
  display: flex;
  align-items: baseline;
  gap: 6px;
  line-height: 1;
  /* HP ゲージの左下に置く（枠の内側の位置に合わせる） */
  margin-top: -2%;
  padding-left: 3%;
}

.score-label {
  font-size: 0.78em;
  font-weight: 900;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.score-value {
  font-size: clamp(15px, calc(var(--sh) * 7.56), 32px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55), 0 0 14px rgba(255, 220, 120, 0.35);
}

.combo {
  display: flex;
  align-items: baseline;
  gap: 5px;
  line-height: 1;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.14s linear, transform 0.14s linear;
}

.combo.on {
  opacity: 1;
  transform: translateY(0);
}

.combo b {
  font-size: clamp(16px, calc(var(--sh) * 7.56), 32px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--warn);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

.combo-label {
  font-size: 0.76em;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--warn);
  opacity: 0.85;
}

/* 10 コンボ以上は色を変えて煽る */
/* --- コンボ倍率：繋ぐほど上がる威力 --- */
.combo-power {
  display: block;
  margin-top: 2px;
  font-size: 0.86em;
  color: #7fe0ff;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.85);
  font-variant-numeric: tabular-nums;
}

/* 上限に届いたら色を変えて「これ以上は上がらない」を伝える */
.combo-power.max {
  color: #ff6b4a;
}

.combo.hot b,
.combo.hot .combo-label {
  color: #ff8b5e;
}

.combo.hot b {
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6), 0 0 16px rgba(255, 140, 80, 0.7);
}

/* 数字が増えた瞬間だけ弾ませる */
.combo.pop b {
  animation: combo-pop 0.22s ease-out;
}

@keyframes combo-pop {
  0% {
    transform: scale(1.45);
  }
  100% {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .combo.pop b {
    animation: none;
  }
}

/* フェーズは画面中央のバナーで知らせるので、上部のラベルとバーは出さない */
#stageLabel,
#progressBar {
  display: none;
}

#progressBar {
  width: min(calc(var(--vw) * 28), 260px);
  height: 6px;
  background: #0b0f13;
  border: 2px solid #3a464f;
}

#progressBar > i {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--accent);
}

/* アイテムスロットも同じ要領で、枠の空洞に中身を置く */
.item-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

/* 持っていないときは枠ごと薄くする */
.item-slot.empty {
  opacity: 0.3;
}

.item-slot-icon {
  width: clamp(26px, calc(var(--sh) * 12), 48px);
  aspect-ratio: 1;
  background: center / contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.9));
}

/* 中身が無いときは、受け皿の枠だけ出しておく */
.item-slot.empty .item-slot-icon {
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: 8px;
}

.item-slot-uses {
  font-size: clamp(8px, calc(var(--sh) * 3), 14px);
  color: #ffd400;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.9);
}

#controls {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 calc(4% + var(--safe-l)) 0 calc(4% + var(--safe-r));
  pointer-events: none;
  transition: opacity 0.2s linear;
}

/* タイトル・ポーズ・結果のあいだは、十字キーとボタンを引っ込めて
   代わりに操作盤のメニューを出す。場所は空けたままにしたいので
   visibility で消す（display:none にすると配置が崩れる）。 */
#controls.hidden {
  visibility: hidden;
  pointer-events: none;
}

/* READY? のあいだは、まだ触れないことが分かるよう灰色にしておく */
#controls.waiting {
  filter: grayscale(1) brightness(0.62);
  pointer-events: none;
}

#controls.hidden .pad-zone,
#controls.hidden .pad,
#controls.hidden .btn {
  pointer-events: none;
}

/* --- 左：フローティングパッド ---
   操作盤の左半分すべてがタッチ受付エリア。触った場所にパッドが現れ、
   指を離すと定位置に戻る。親指の位置に関係なく操作できる。 */
.pad-zone {
  position: absolute;
  left: 0;
  top: 0;
  width: 46%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

.pad {
  position: absolute;
  /* 起点は JS が触れた位置に合わせて動かす */
  left: 0;
  top: 0;
  width: clamp(104px, min(calc(var(--dh) * 54), calc(var(--dw) * 40)), 196px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.62;
  transition: opacity 0.14s linear;
}

.pad.active {
  opacity: 1;
}

/* 十字キーが本体にはめ込まれて見えるよう、くぼみを敷く */
.pad::before {
  content: "";
  position: absolute;
  inset: -7%;
  border-radius: 22%;
  background: radial-gradient(circle at 50% 42%, #0b0e11 0%, #14181d 62%, #1d2228 100%);
  box-shadow:
    inset 0 3px 6px rgba(0, 0, 0, 0.85),
    0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ゲームボーイの十字キー。画像を使わず図形で描く。 */
.pad-ring {
  position: absolute;
  inset: 6%;
  border-radius: 12%;
  background: linear-gradient(160deg, #3a4149 0%, #262c33 46%, #171c21 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.16),
    inset 0 -3px 0 rgba(0, 0, 0, 0.6),
    0 3px 0 rgba(0, 0, 0, 0.7);
  clip-path: polygon(
    34% 0, 66% 0, 66% 34%, 100% 34%, 100% 66%,
    66% 66%, 66% 100%, 34% 100%, 34% 66%, 0 66%, 0 34%, 34% 34%
  );
}

/* まん中の小さな印。倒した向きへ動く。 */
.pad-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 40% 34%, #6b757f, #3a424a 70%, #232a31);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.7);
}

.pad.active .pad-knob {
  background: radial-gradient(circle at 40% 34%, #96a3ae, #5a646e 70%, #333b43);
}


/* --- 右下：A / B / C ボタン --- */
/* --- 右：アクションボタン ---
   小さいスマホでも押しやすく、タブレットで大きくなりすぎないよう、
   縦（vh）と横（vw）の小さいほうを基準にする。 */
.buttons {
  position: absolute;
  right: calc(4% + var(--safe-r));
  top: 50%;
  transform: translateY(-50%);
  /* 高さと幅の小さいほうに合わせる。どちらに当たっても盤からはみ出さない。 */
  width: clamp(132px, min(calc(var(--dh) * 66), calc(var(--dw) * 47)), 250px);
  aspect-ratio: 1;
  pointer-events: none;
}

.btn {
  position: absolute;
  /* 指の腹で押せるよう、最低でも 58px は確保する */
  width: 48%;
  min-width: 58px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  /* ゲームボーイの丸ボタン。画像を使わず、色と厚みだけで作る。 */
  background: var(--face, #b8324a);
  color: #fff;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.34),
    inset 0 -5px 0 rgba(0, 0, 0, 0.32),
    0 5px 0 var(--edge, #6d1a2c),
    0 7px 10px rgba(0, 0, 0, 0.55);
  transition: transform 0.05s linear, box-shadow 0.05s linear;
}

.btn.pressed,
.btn:active {
  transform: translateY(5px);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.34),
    inset 0 -5px 0 rgba(0, 0, 0, 0.32),
    0 0 0 var(--edge, #6d1a2c),
    0 2px 4px rgba(0, 0, 0, 0.55);
}

.btn-key {
  font-size: clamp(19px, calc(var(--dh) * 8), 40px);
  letter-spacing: 0.02em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.btn-sub {
  /* 役割の文字は A / B / C の真下、ボタンの中に置く */
  font-family: "DotGothic16", sans-serif;
  font-size: clamp(7px, calc(var(--dh) * 2.5), 12px);
  color: rgba(255, 255, 255, 0.94);
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* 親指の定位置（右下）にジャンプ（C・黄）。
   こうげき（A・赤）は左、とびどうぐ（B・青）は上。 */
.btn-c {
  right: 0;
  bottom: 4%;
  --face: #d99a20;
  --edge: #7d5308;
}

.btn-a {
  left: 0;
  bottom: 14%;
  --face: #c9364f;
  --edge: #71182b;
}

.btn-b {
  right: 10%;
  top: 0;
  --face: #2f74c8;
  --edge: #17406f;
}

/* ---------------------------------------------------------
   操作盤のメニュー
   遊んでいないあいだは、十字キーとボタンの代わりにここを出す。
   --------------------------------------------------------- */
.deck-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--dh) * 4);
  padding: 0 6%;
  z-index: 2;
}

.deck-menu.hidden {
  display: none;
}

.deck-menu-title {
  margin: 0;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(17px, calc(var(--dh) * 8), 32px);
  letter-spacing: 0.18em;
  color: #ffffff;
  /* 袋文字。縁を 8 方向に置いて、どこから見ても太さが揃うようにする。 */
  text-shadow:
    -2px -2px 0 #14100c, 0 -2px 0 #14100c, 2px -2px 0 #14100c,
    -2px 0 0 #14100c, 2px 0 0 #14100c,
    -2px 2px 0 #14100c, 0 2px 0 #14100c, 2px 2px 0 #14100c,
    0 4px 6px rgba(0, 0, 0, 0.6);
}

.deck-menu-title:empty {
  display: none;
}

/* 面と側面のある一枚のボタン。
   影を二重にすると「後ろに小さいボタンがある」ように見えるので、
   側面（縁）と落ち影を 1 本ずつに絞って厚みを出す。 */
.deck-key {
  position: relative;
  min-width: min(74%, 320px);
  padding: calc(var(--dh) * 5) 6%;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f2f4f6 52%, #d9dee3 100%);
  color: #14100c;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(17px, calc(var(--dh) * 9), 34px);
  font-weight: 400;
  letter-spacing: 0.10em;
  cursor: pointer;
  overflow: hidden;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18),
    0 6px 0 #14100c;
  touch-action: manipulation;
}

/* 押した瞬間に走る白い光 */
.deck-key::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
}

.deck-key.flash::after {
  animation: deck-flash 0.34s steps(1) 2;
}

@keyframes deck-flash {
  0%, 40% { opacity: 0.92; }
  41%, 100% { opacity: 0; }
}

.deck-key.primary {
  animation: deck-blink 1.6s ease-in-out infinite;
}

.deck-key:active {
  transform: translateY(6px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  animation: none;
}

.deck-key.hidden {
  display: none;
}

/* 二番目のボタンは控えめに。ただし文字は太いまま。 */
.deck-key:not(.primary) {
  min-width: min(56%, 240px);
  padding: calc(var(--dh) * 3.4) 5%;
  font-size: clamp(13px, calc(var(--dh) * 6), 24px);
  background: linear-gradient(180deg, #333b44 0%, #232a31 52%, #161b20 100%);
  color: #f2f6f8;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.16),
    inset 0 -3px 0 rgba(0, 0, 0, 0.5),
    0 5px 0 #05070a;
}

@keyframes deck-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .deck-key.primary {
    animation: none;
  }
}

/* --- 一時停止ボタン。操作盤のちょうどまんなかに置く。 --- */
.start-key {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dh) * 3);
  transform: translateX(-50%);
  width: clamp(38px, calc(var(--dw) * 12), 60px);
  aspect-ratio: 1.7;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #434b54, #23282e);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.45),
    0 3px 0 rgba(0, 0, 0, 0.75);
  cursor: pointer;
  touch-action: manipulation;
  z-index: 3;
}

/* 一時停止のマーク（縦棒 2 本） */
.pause-mark {
  display: flex;
  gap: 4px;
}

.pause-mark > i {
  display: block;
  width: 4px;
  height: clamp(12px, calc(var(--dh) * 4.5), 18px);
  border-radius: 1px;
  background: #dfe7ed;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
}

/* タイトルとキャラクター選択のあいだは一時停止できないので出さない */
.start-key.hidden {
  display: none;
}

.start-key:active {
  transform: translateX(-50%) translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.45);
}

/* ---------------------------------------------------------
   画面ぜんぶを使うオーバーレイ（タイトル・キャラクター選択）
   液晶の中だけだと窮屈なので、操作盤ごと覆う。
   --------------------------------------------------------- */
.full-screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--vh) * 1.4);
  padding: calc(var(--vh) * 3) 4%;
  text-align: center;
}

.full-screen.hidden {
  display: none;
}

/* --- タイトル --- */
.title-screen {
  background: url("assets/title-bg.webp") center / cover no-repeat;
}

/* 背景は画面ぜんぶに出す。
   下だけ濃く落とすと絵が切れて見えるので、全体に薄くかけるだけにする。 */
.title-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 42%,
    rgba(4, 7, 10, 0.12) 0%,
    rgba(4, 7, 10, 0.34) 58%,
    rgba(4, 7, 10, 0.5) 100%
  );
}

.title-screen > * {
  position: relative;
  z-index: 1;
}

.title-logo-img {
  max-width: 94%;
  max-height: 46%;
  width: auto;
  height: auto;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.75));
  /* ゆっくり息をするように、少しだけ大きく小さくし続ける */
  animation: logo-breathe 3.8s ease-in-out infinite;
}

@keyframes logo-breathe {
  0% { transform: scale(1); }
  50% { transform: scale(1.045); }
  100% { transform: scale(1); }
}

.title-screen .version {
  position: absolute;
  left: calc(4% + var(--safe-l));
  top: calc(var(--vh) * 2);
  font-size: clamp(9px, calc(var(--vh) * 1.8), 15px);
  color: #cfd8df;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

/* 運営者の表示（誰が運営しているかを画面内で示す）。
   社名は画面のいちばん下に真ん中寄せ、プライバシーポリシーは左下。
   .title-screen > * が position:relative を当ててくるので、クラスを 2 つ重ねて勝たせる。 */
.title-screen .title-company,
.title-screen .title-privacy {
  position: absolute;
  z-index: 2;
  margin: 0;
  font-size: clamp(9px, calc(var(--vh) * 1.5), 13px);
  line-height: 1.2;
  color: #cfd8df;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

.title-screen .title-company {
  left: 50%;
  bottom: calc(1.5% + var(--safe-b));
  transform: translateX(-50%);
  text-align: center;
}

.title-screen .title-privacy {
  left: calc(3.5% + var(--safe-l));
  bottom: calc(4% + var(--safe-b));
  text-decoration: underline;
}

.title-screen .studio-logo {
  position: absolute;
  right: calc(4% + var(--safe-r));
  bottom: calc(var(--vh) * 2.4);
  width: min(30%, 150px);
  opacity: 0.92;
}

/* ハイスコア */
.hi-score {
  margin: 0;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(12px, calc(var(--vh) * 2.4), 24px);
  letter-spacing: 0.14em;
  color: #ffd400;
  font-variant-numeric: tabular-nums;
  text-shadow:
    -2px -2px 0 #14100c, 0 -2px 0 #14100c, 2px -2px 0 #14100c,
    -2px 0 0 #14100c, 2px 0 0 #14100c,
    -2px 2px 0 #14100c, 0 2px 0 #14100c, 2px 2px 0 #14100c;
}

.hi-score.hidden {
  display: none;
}

/* PRESS START：ボタンではなく、白塗り黒フチの袋文字だけ */
/* タイトルの見せ方：ロゴが上から落ちてきて、あとから文字が出る */
.title-screen.intro .title-logo-img {
  /* 落ちてきたあと、そのまま息をする動きへ移る */
  animation:
    title-drop 0.62s cubic-bezier(0.3, 0.9, 0.35, 1) backwards,
    logo-breathe 3.8s ease-in-out 0.62s infinite;
}

.title-screen.intro .press-text,
.title-screen.intro .hi-score {
  animation: title-rise 0.4s ease-out backwards;
  animation-delay: 0.42s;
}

@keyframes title-drop {
  0% { transform: translateY(-150%) scale(0.86); opacity: 0; }
  58% { transform: translateY(5%) scale(1.05, 0.92); opacity: 1; }
  76% { transform: translateY(-4%) scale(0.98, 1.04); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes title-rise {
  from { transform: translateY(28%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* キャラクター選択：カードが上から順番に落ちてくる */
.char-card.drop {
  animation: card-in 0.54s cubic-bezier(0.2, 0.9, 0.3, 1.3) backwards;
  animation-delay: calc(var(--i, 0) * 0.12s);
}

/* 登場のときだけ、枠の電気をひと光りさせる */
.char-card.drop .char-spark {
  animation:
    spark-run 1.5s linear infinite,
    spark-flash 0.8s ease-out;
  animation-delay:
    calc(var(--i, 0) * 0.12s),
    calc(var(--i, 0) * 0.12s);
}

@keyframes card-in {
  0% { transform: translateX(-28%) scale(0.92) rotate(-1.4deg); opacity: 0; }
  62% { transform: translateX(3%) scale(1.02) rotate(0.4deg); opacity: 1; }
  100% { transform: translateX(0) scale(1) rotate(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .title-screen.intro .title-logo-img,
  .title-screen.intro .press-text,
  .title-screen.intro .hi-score,
  .char-card.drop { animation-duration: 0.01s; animation-delay: 0s; }
  .title-logo-img,
  .title-screen.intro .title-logo-img { animation: none; }
}

.press-text {
  margin: calc(var(--vh) * 1.6) 0 0;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(24px, calc(var(--vh) * 5.4), 54px);
  letter-spacing: 0.12em;
  color: #ffffff;
  -webkit-text-stroke: 1px #14100c;
  text-shadow:
    -3px -3px 0 #14100c, 0 -3px 0 #14100c, 3px -3px 0 #14100c,
    -3px 0 0 #14100c, 3px 0 0 #14100c,
    -3px 3px 0 #14100c, 0 3px 0 #14100c, 3px 3px 0 #14100c,
    0 6px 10px rgba(0, 0, 0, 0.75);
  /* うっすら薄くなるだけだと点滅に見えないので、消える点滅にする */
  animation: press-blink 1s steps(1) infinite;
}

.press-text.flash {
  animation: press-flash 0.3s steps(1) 2;
}

@keyframes press-blink {
  0% { opacity: 1; }
  62% { opacity: 0; }
  100% { opacity: 0; }
}

@keyframes press-flash {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: 0.1; }
}

@media (prefers-reduced-motion: reduce) {
  .press-text { animation: none; }
}

/* ---------------------------------------------------------
   キャラクター選択
   --------------------------------------------------------- */
.select-screen {
  background: radial-gradient(
    circle at 50% 38%,
    rgba(20, 29, 40, 0.97),
    rgba(4, 7, 10, 0.99)
  );
  gap: calc(var(--vh) * 1.8);
}

/* 見出しは絵。文字は alt に持たせてあるので、読み上げでも伝わる。 */
.select-title {
  margin: 0;
  display: flex;
  justify-content: center;
  line-height: 0;
}

.select-title-img {
  max-width: 92%;
  max-height: calc(var(--vh) * 8);
  width: auto;
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.7));
}

.char-list {
  display: flex;
  /* 横長のカードを縦に 3 枚。画面の高さをぜんぶ使う。 */
  flex-direction: column;
  gap: calc(var(--vh) * 1.2);
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  justify-content: stretch;
}

.char-card {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  border: 3px solid #333c46;
  border-radius: 14px;
  background: linear-gradient(100deg, #212a33 0%, #161c23 55%, #0d1217 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.1);
  overflow: hidden;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  text-align: left;
  touch-action: manipulation;
  transition: border-color 0.16s linear, transform 0.16s ease-out,
    box-shadow 0.16s linear;
}

.char-card.on {
  border-color: var(--pick, #ffd400);
  transform: translateX(4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.16),
    0 0 0 2px rgba(0, 0, 0, 0.65),
    0 0 22px 2px var(--pick, #ffd400);
}


/* 手前が見やすいよう、マップの上に暗い膜を一枚 */
.char-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(8, 11, 15, 0.88) 0%,
    rgba(8, 11, 15, 0.74) 44%,
    rgba(8, 11, 15, 0.34) 72%,
    rgba(8, 11, 15, 0.06) 100%);
  pointer-events: none;
}






@keyframes card-strike {
  0% { transform: scale(1) translateX(0); }
  35% { transform: scale(1.16) translateX(6%); }
  100% { transform: scale(1) translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .char-card.strike .char-art { animation: none; }
}

/* --- 右：名前とステータス --- */
/* --- カードの絵：そのキャラが戦っている一枚絵 ---
   顔は絵の右上にあるので、右寄り・やや上を見せるように切り取る。
   選んでいないあいだはモノクロで暗く、選ぶと色がつく。 */
.char-art {
  position: absolute;
  inset: 0;
  background: 64% 36% / cover no-repeat;
  filter: grayscale(1) brightness(0.58) contrast(1.05);
  transform: scale(1.02);
  transition: filter 0.24s linear, transform 0.4s ease-out;
}

.char-card.on .char-art {
  filter: none;
  transform: scale(1.07);
}

.char-card.strike .char-art {
  animation: card-strike 0.42s ease-out;
}

/* 決定したカードは白く 2 回、パッパッと点滅する（点滅は 2 回だけにして、1 秒に 3 回を超えない） */
.char-card.chosen {
  animation: card-chosen 0.36s step-end;
}

@keyframes card-chosen {
  0% { filter: brightness(3.4) saturate(0); }
  25% { filter: none; }
  50% { filter: brightness(3.4) saturate(0); }
  75% { filter: none; }
}

@media (prefers-reduced-motion: reduce) {
  .char-card.chosen { animation: none; filter: brightness(1.8) saturate(0.4); }
}

/* --- 枠を走る電気。選んでいるカードだけ光る。
   4 本の光の帯（上・下・左・右）を、位置だけずらして走らせている。 --- */
.char-spark {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s linear;
  background:
    linear-gradient(90deg, transparent, var(--pick, #ffd400), transparent) no-repeat,
    linear-gradient(90deg, transparent, var(--pick, #ffd400), transparent) no-repeat,
    linear-gradient(0deg, transparent, var(--pick, #ffd400), transparent) no-repeat,
    linear-gradient(0deg, transparent, var(--pick, #ffd400), transparent) no-repeat;
  background-size: 46% 3px, 46% 3px, 3px 52%, 3px 52%;
  filter: drop-shadow(0 0 5px var(--pick, #ffd400));
  animation: spark-run 1.5s linear infinite;
}

.char-card.on .char-spark {
  opacity: 1;
}

@keyframes spark-run {
  0% { background-position: -50% 0, 150% 100%, 0 150%, 100% -50%; }
  100% { background-position: 150% 0, -50% 100%, 0 -50%, 100% 150%; }
}

@keyframes spark-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .char-spark { animation: none; }
}

.char-info {
  position: relative;
  z-index: 3;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 0 4% 0 3%;
}

/* 上段：キャラクター名（大きく）。顔の上に乗るので袋文字にする。 */
.char-name {
  /* 名前はカタカナなので Bangers では出ない。太い日本語書体に袋文字と傾きで漫画の見出しにする */
  font-family: "Dela Gothic One", "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(16px, calc(var(--vh) * 3.6), 32px);
  letter-spacing: 0.005em;
  white-space: nowrap;
  color: #8b959d;
  transition: color 0.16s linear;
  transform: skewX(-7deg);
  transform-origin: left bottom;
  padding-right: 5px;
  -webkit-text-stroke: 5px #0a0d11;
  paint-order: stroke fill;
  text-shadow:
    -4px -4px 0 #0a0d11, 0 -4px 0 #0a0d11, 4px -4px 0 #0a0d11,
    -4px 0 0 #0a0d11, 4px 0 0 #0a0d11,
    -4px 4px 0 #0a0d11, 0 4px 0 #0a0d11, 4px 4px 0 #0a0d11,
    5px 6px 0 rgba(0, 0, 0, 0.5);
}

.char-card.on .char-name {
  color: var(--pick, #ffd400);
}

/* 下段：タイプ（小さく） */
.char-tag {
  font-size: clamp(9px, calc(var(--vh) * 1.8), 15px);
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: #aab4bd;
  text-shadow:
    -2px -2px 0 #0a0d11, 0 -2px 0 #0a0d11, 2px -2px 0 #0a0d11,
    -2px 0 0 #0a0d11, 2px 0 0 #0a0d11,
    -2px 2px 0 #0a0d11, 0 2px 0 #0a0d11, 2px 2px 0 #0a0d11;
}

.char-card.on .char-tag {
  color: #f2f6f8;
}

/* 特徴は文章ではなく棒グラフで見せる（折り返さないので崩れない） */
.char-stats {
  width: 100%;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: calc(var(--vh) * 0.5);
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat > i {
  flex: 0 0 auto;
  font-style: normal;
  font-size: clamp(7px, calc(var(--vh) * 1.3), 11px);
  color: #cbd8e0;
  white-space: nowrap;
  text-shadow:
    -1.5px -1.5px 0 #0a0d11, 0 -1.5px 0 #0a0d11, 1.5px -1.5px 0 #0a0d11,
    -1.5px 0 0 #0a0d11, 1.5px 0 0 #0a0d11,
    -1.5px 1.5px 0 #0a0d11, 0 1.5px 0 #0a0d11, 1.5px 1.5px 0 #0a0d11;
}

/* 5 マスで段階を見せる。棒の長さより、数のほうが差を読み取りやすい。 */
.stat > em {
  flex: 1 1 auto;
  max-width: 150px;
  display: flex;
  gap: 3px;
}

.stat > em > b {
  flex: 1 1 0;
  height: clamp(7px, calc(var(--vh) * 1.3), 12px);
  border-radius: 2px;
  background: rgba(4, 6, 9, 0.9);
  /* 空きマスにも輪郭。背景が何であってもマスの数を数えられる。 */
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.9);
  transition: background 0.16s linear, box-shadow 0.16s linear;
}

.stat > em > b.on {
  background: #59636d;
}

.char-card.on .stat > em > b.on {
  background: var(--pick, #ffd400);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.35),
    0 0 6px -1px var(--pick, #ffd400);
}

/* --- 決定ボタン --- */
/* ボタンも絵。枠や下地は描かず、絵そのものを押してもらう。 */
.fight-btn {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  line-height: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.fight-btn-img {
  display: block;
  width: min(62vw, 300px);
  height: auto;
  filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.6));
  /* 色の切り替えは一瞬で（filter をなめらかに変えるとスマホでは重く、遅れて見える） */
  transition: transform 0.12s ease-out;
}

/* キャラを選ぶまではモノクロ。選ぶと色がつく。
   モノクロ版の画像を上に重ねておき、選んだら消す。
   （filter でモノクロにすると、戻すときに絵を描き直すので、
     最初の読み込み中など手が塞がっていると色がつくのが遅れる） */
.fight-btn:disabled {
  cursor: default;
}

.fight-btn-img.off {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  opacity: 0;
}

.fight-btn:disabled .fight-btn-img.off {
  opacity: 1;
}

.fight-btn:not(:disabled):active .fight-btn-img {
  transform: translateY(5px) scale(0.985);
}

/* ---------------------------------------------------------
   READY?：バトルを止めたまま、タップを待つ
   --------------------------------------------------------- */
.ready-screen {
  position: absolute;
  inset: 0;
  z-index: 28;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--sh) * 1.5);
  background: rgba(5, 8, 12, 0.5);
  text-align: center;
  cursor: pointer;
}

.ready-screen.hidden {
  display: none;
}

.ready-loop,
.ready-text,
.ready-tap {
  margin: 0;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  color: #ffffff;
  text-shadow:
    -3px -3px 0 #14100c, 0 -3px 0 #14100c, 3px -3px 0 #14100c,
    -3px 0 0 #14100c, 3px 0 0 #14100c,
    -3px 3px 0 #14100c, 0 3px 0 #14100c, 3px 3px 0 #14100c,
    0 6px 12px rgba(0, 0, 0, 0.8);
}

.ready-loop {
  font-size: clamp(18px, calc(var(--sh) * 9), 40px);
  letter-spacing: 0.14em;
  color: #ff9a3c;
}

.ready-loop:empty {
  display: none;
}

.ready-text {
  font-size: clamp(34px, calc(var(--sh) * 17), 82px);
  letter-spacing: 0.08em;
  color: #ffd400;
}

.ready-tap {
  font-size: clamp(11px, calc(var(--sh) * 4.4), 22px);
  letter-spacing: 0.2em;
  animation: press-blink 1.3s ease-in-out infinite;
}

/* --- 右上のミュートボタン ---
   .title-screen > * が position:relative を当ててくるので、
   同じ強さでは負ける。セレクタを一段深くして絶対配置を通す。 */
.title-screen .mute-btn {
  position: absolute;
  right: calc(4% + var(--safe-r));
  top: calc(var(--vh) * 1.6);
  width: clamp(34px, calc(var(--vw) * 11), 54px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: rgba(10, 13, 17, 0.62);
  cursor: pointer;
  touch-action: manipulation;
  z-index: 5;
}

.mute-btn:active {
  transform: translateY(2px);
}

/* スピーカーの図。図形だけで描くので追加画像は要らない。 */
.mute-icon {
  position: relative;
  display: block;
  width: 34%;
  height: 40%;
  background: #ffffff;
  clip-path: polygon(0 30%, 34% 30%, 74% 0, 74% 100%, 34% 70%, 0 70%);
}

.mute-icon::after {
  content: "";
  position: absolute;
  left: 128%;
  top: 50%;
  width: 46%;
  height: 46%;
  transform: translateY(-50%);
  border: 2px solid #ffffff;
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  rotate: 45deg;
}

/* 消しているときは斜線 */
.mute-btn.off .mute-icon::after {
  border: 0;
  border-radius: 0;
  rotate: 0deg;
  left: -34%;
  top: -22%;
  width: 190%;
  height: 144%;
  transform: none;
  background: linear-gradient(
    to bottom right,
    transparent calc(50% - 1.6px),
    #ff6b4a calc(50% - 1.6px),
    #ff6b4a calc(50% + 1.6px),
    transparent calc(50% + 1.6px)
  );
}

@media (prefers-reduced-motion: reduce) {
  .ready-tap { animation: none; }
}

/* ---------------------------------------------------------
   必殺技ボタン（ボスにトドメを刺すとき、画面のまんなかに出る）
   --------------------------------------------------------- */
.finish-btn {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  /* 押す的として目立たせつつ、ボスが隠れきらない大きさ */
  width: min(44%, 184px);
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  /* ボタンの見た目は絵（assets/ui-finish-btn.webp）。まわりの赤い光だけ添える */
  background: none;
  padding: 0;
  filter: drop-shadow(0 0 16px rgba(255, 90, 60, 0.65));
  cursor: pointer;
  z-index: 30;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  animation: finish-pulse 0.7s ease-in-out infinite;
}

.finish-btn.hidden {
  display: none;
}

.finish-btn-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

/* 外へ広がる輪。押せることを目立たせる。 */
.finish-btn-ring {
  position: absolute;
  inset: -6%;
  border: 3px solid rgba(255, 212, 0, 0.85);
  border-radius: 50%;
  animation: finish-ring 0.9s ease-out infinite;
}

@keyframes finish-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.07); }
}

@keyframes finish-ring {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.5); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .finish-btn,
  .finish-btn-ring {
    animation: none;
  }
}

/* タイトル画面の案内文 */
/* --- 操作盤の足元：刻印とスピーカーの穴 --- */
.deck-foot {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 calc(5% + var(--safe-l)) calc(var(--dh) * 3) calc(5% + var(--safe-r));
  min-height: 0;
}

.deck-brand {
  font-size: clamp(8px, calc(var(--dw) * 3), 15px);
  letter-spacing: 0.24em;
  color: #767f88;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

/* 斜めに並んだスピーカーの穴 */
.deck-grille {
  width: clamp(46px, calc(var(--dw) * 17), 92px);
  height: clamp(14px, calc(var(--dh) * 5.5), 30px);
  background: repeating-linear-gradient(
    58deg,
    #0c0f13 0 3px,
    transparent 3px 8px
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transform: skewX(-14deg);
}

/* ---------------------------------------------------------
   タイトル / オーバーレイ画面
   --------------------------------------------------------- */
.overlay-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--sh) * 4.2);
  background: radial-gradient(
    circle at 50% 45%,
    rgba(12, 22, 30, 0.82),
    rgba(4, 7, 10, 0.94)
  );
  z-index: 20;
  text-align: center;
  padding: 4%;
}

.overlay-screen.hidden {
  display: none;
}

/* --- タイトル画面：キービジュアルを敷いてロゴを重ねる --- */
.title-screen {
  background: url("assets/title-bg.webp") center / cover no-repeat;
  /* 高さが足りない端末でもボタンが画面外へ出ないよう、中央そろえにする */
  justify-content: center;
  gap: 2%;
  padding: 12% 8% 10%;
  overflow: hidden;
}

/* 下側を暗く落として、ボタンと注記を読めるようにする */
.title-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(6, 8, 12, 0.15) 0%,
    rgba(6, 8, 12, 0.1) 42%,
    rgba(6, 8, 12, 0.82) 100%
  );
  pointer-events: none;
}

.title-screen > * {
  position: relative;
  z-index: 1;
}

.title-logo-img {
  /* 幅・高さの両方に上限を置き、どちらに当たっても比率を保って収める */
  max-width: 96%;
  max-height: 64%;
  width: auto;
  height: auto;
  filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.75));
}

/* 左上のバージョン表記 */
.title-screen .version {
  position: absolute;
  left: calc(3.5% + var(--safe-l));
  top: calc(3.5% + var(--safe-t));
  z-index: 2;
  font-size: clamp(9px, calc(var(--sh) * 3.99), 15px);
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* 右下のスタジオロゴ */
.title-screen .studio-logo {
  position: absolute;
  right: calc(3.5% + var(--safe-r));
  bottom: calc(4% + var(--safe-b));
  z-index: 2;
  width: clamp(72px, calc(var(--sw) * 15), 170px);
  height: auto;
  border-radius: 5px;
  opacity: 0.9;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* PRESS START：白抜き＋黒フチのドット文字をゆっくり点滅させる */
.press-start {
  margin-top: calc(var(--sh) * 2.1);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: "Press Start 2P", "DotGothic16", monospace;
  font-size: clamp(13px, calc(var(--sh) * 7.14), 30px);
  letter-spacing: 0.12em;
  color: #ffffff;
  -webkit-text-stroke: 5px #14100c;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.55);
  animation: press-blink 1.6s steps(1, end) infinite;
}

.press-start:active {
  transform: translateY(3px);
}

@keyframes press-blink {
  0%, 62% { opacity: 1; }
  63%, 100% { opacity: 0.18; }
}

@media (prefers-reduced-motion: reduce) {
  .press-start {
    animation: none;
  }
}

/* 全画面ボタン。白地に黒文字・黒フチ。 */
/* 全画面 API が使えない環境向けの案内 */
.title-hint {
  margin: 0;
  font-size: clamp(9px, calc(var(--sh) * 3.57), 14px);
  color: #b9c7d0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

/* --- ボスの体力ゲージ（戦闘中だけ右上に出す） --- */
.gauge.boss {
  width: min(calc(var(--sw) * 34), 300px);
  margin-top: calc(var(--sh) * 0.8);
  /* 出ていないときに場所を取ると、下のスコアが押し下げられてしまう */
  display: none;
}

.gauge.boss.on {
  display: block;
}

.gauge.boss::after {
  background-image: url("assets/ui/gauge-boss.webp");
}

.gauge.boss {
  aspect-ratio: 1013 / 210;
}

.gauge.boss .gauge-bar {
  left: 20.1%;
  top: 43.3%;
  width: 70%;
  height: 24.3%;
}

.gauge.boss .gauge-bar > i {
  background: linear-gradient(180deg, #ff9a8f, #d63b30 60%, #8d1d16);
}

/* --- アイテムの残り使用回数 --- */
.item-slot-uses {
  font-size: 0.8em;
  font-weight: 900;
  color: var(--warn);
  font-variant-numeric: tabular-nums;
}

/* 結果画面は、倒れた主人公が見えるように薄くかぶせる */
#overScreen {
  background: linear-gradient(
    180deg,
    rgba(6, 9, 13, 0.55) 0%,
    rgba(6, 9, 13, 0.2) 45%,
    rgba(6, 9, 13, 0.75) 100%
  );
  justify-content: flex-start;
  padding-top: 8%;
  gap: calc(var(--sh) * 2.94);
}

/* --- ゲームオーバー --- */
.over-title {
  margin: 0;
  /* 太い表示用の書体で、黒フチをぐるりと回して厚みを出す */
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(30px, calc(var(--sh) * 18), 76px);
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--danger);
  -webkit-text-stroke: 3px #14100c;
  paint-order: stroke fill;
  text-shadow:
    -3px -3px 0 #14100c, 0 -3px 0 #14100c, 3px -3px 0 #14100c,
    -3px 0 0 #14100c, 3px 0 0 #14100c,
    -3px 3px 0 #14100c, 0 3px 0 #14100c, 3px 3px 0 #14100c,
    0 7px 0 #5e1a15, 0 11px 24px rgba(0, 0, 0, 0.75);
}

/* ステージクリアのときは色を変える */
/* CONTINUE? の見出しと、残り秒数 */
.over-title.continue {
  color: var(--warn);
}

.continue-count {
  margin: 0;
  font-family: "Bangers", Impact, "Arial Black", "DotGothic16", sans-serif;
  font-size: clamp(48px, calc(var(--sh) * 30), 132px);
  line-height: 1;
  color: #ffffff;
  -webkit-text-stroke: 3px #14100c;
  paint-order: stroke fill;
  text-shadow:
    -3px -3px 0 #14100c, 0 -3px 0 #14100c, 3px -3px 0 #14100c,
    -3px 0 0 #14100c, 3px 0 0 #14100c,
    -3px 3px 0 #14100c, 0 3px 0 #14100c, 3px 3px 0 #14100c;
}

/* 残り 3 秒を切ったら赤くして、鼓動のように脈打たせる */
.continue-count.hurry {
  color: var(--danger);
  animation: continuePulse 0.5s steps(1, end) infinite;
}

@keyframes continuePulse {
  0% { transform: scale(1.14); }
  50% { transform: scale(1); }
  100% { transform: scale(1.14); }
}

.over-title.clear {
  color: var(--warn);
  text-shadow:
    -3px -3px 0 #14100c, 0 -3px 0 #14100c, 3px -3px 0 #14100c,
    -3px 0 0 #14100c, 3px 0 0 #14100c,
    -3px 3px 0 #14100c, 0 3px 0 #14100c, 3px 3px 0 #14100c,
    0 7px 0 #7a4f10, 0 11px 24px rgba(0, 0, 0, 0.75);
}

/* --- リザルトの内訳 ---
   数字はすべて白地に黒フチ。TOTAL だけ大きくして目線が行くようにする。 */
.result {
  display: grid;
  gap: calc(var(--sh) * 1.05);
  min-width: min(58%, 420px);
}

.result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 6%;
}

.result-label {
  font-size: clamp(9px, calc(var(--sh) * 3.99), 16px);
  letter-spacing: 0.14em;
  color: #b9c7d0;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.9);
}

.result-num {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  font-size: clamp(13px, calc(var(--sh) * 5.67), 24px);
  color: #ffffff;
  -webkit-text-stroke: 4px #14100c;
  paint-order: stroke fill;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5);
}

/* 合計は 2 倍以上の大きさにして、ひと目で分かるようにする */
.result-total {
  margin-top: calc(var(--sh) * 1.68);
  padding-top: calc(var(--sh) * 2.1);
  border-top: 2px solid rgba(255, 255, 255, 0.28);
}

.result-total .result-label {
  font-size: clamp(11px, calc(var(--sh) * 4.83), 20px);
  color: #ffffff;
}

.result-total .result-num {
  font-size: clamp(26px, calc(var(--sh) * 13.44), 58px);
  -webkit-text-stroke: 7px #14100c;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.55);
}

/* ---------------------------------------------------------
   デバッグ表示（Phase 1 入力検知の確認用）
   --------------------------------------------------------- */
.debug {
  position: absolute;
  left: calc(2% + var(--safe-l));
  top: 26%;
  font-size: clamp(8px, calc(var(--sh) * 2.94), 12px);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #7fe0a4;
  background: rgba(0, 0, 0, 0.42);
  padding: 4px 8px;
  line-height: 1.5;
  white-space: pre;
  pointer-events: none;
  display: none;
}

.debug.on {
  display: block;
}

/* ---------------------------------------------------------
   横向き警告（このゲームは縦持ち専用）
   --------------------------------------------------------- */
#rotateOverlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #06090c;
  text-align: center;
  padding: 6vh 8vw;
}

.rotate-icon {
  position: relative;
  display: grid;
  place-items: center;
}

/* 横向きの端末が、縦向きへ起き上がる動き */
.rotate-phone {
  width: 74px;
  height: 128px;
  border: 5px solid #ffffff;
  border-radius: 12px;
  animation: rotate-hint 2.4s ease-in-out infinite;
}

@keyframes rotate-hint {
  0%,
  30% {
    transform: rotate(90deg);
  }
  60%,
  100% {
    transform: rotate(0deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-phone {
    animation: none;
  }
}

.rotate-text {
  margin: 0;
  font-size: clamp(18px, 4.5vh, 30px);
  font-weight: 900;
}

.rotate-sub {
  margin: 0;
  font-size: clamp(11px, 2.6vh, 16px);
  color: var(--muted);
}

/* 横向き & タッチデバイスのときだけ案内を出す
   （PC の横長ウィンドウでは普通に遊べるので出さない） */
@media (orientation: landscape) and (pointer: coarse) {
  #rotateOverlay {
    display: flex;
  }
  #app {
    visibility: hidden;
  }
}

/* ---------------------------------------------------------
   遊び方の案内
   はじめの面だけ、数え始める前に操作盤を指して見せる。
   赤い角丸のわくの外側を、大きな影で一気に暗くしている
   （切り抜きを別に用意しなくて済む）。
   --------------------------------------------------------- */
.tutorial {
  position: absolute;
  inset: 0;
  z-index: 80;
  overflow: hidden;
  cursor: pointer;
}

.tutorial.hidden {
  display: none;
}

.tutor-ring {
  position: absolute;
  border: 3px solid var(--danger);
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(4, 6, 9, 0.72);
  transition: left 0.3s cubic-bezier(0.2, 0.75, 0.3, 1),
    top 0.3s cubic-bezier(0.2, 0.75, 0.3, 1),
    width 0.3s cubic-bezier(0.2, 0.75, 0.3, 1),
    height 0.3s cubic-bezier(0.2, 0.75, 0.3, 1);
  animation: tutor-pulse 1.1s ease-in-out infinite;
}

@keyframes tutor-pulse {
  0%, 100% { border-color: #e2483f; }
  50% { border-color: #ff9d94; }
}

.tutor-text {
  position: absolute;
  left: 6%;
  right: 6%;
  margin: 0;
  text-align: center;
  white-space: pre-line;
  font-size: clamp(14px, calc(var(--vh) * 2.6), 24px);
  line-height: 1.7;
  color: #ffffff;
  text-shadow:
    -2px -2px 0 #14100c, 0 -2px 0 #14100c, 2px -2px 0 #14100c,
    -2px 0 0 #14100c, 2px 0 0 #14100c,
    -2px 2px 0 #14100c, 0 2px 0 #14100c, 2px 2px 0 #14100c;
}

.tutor-tap {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--vh) * 3);
  margin: 0;
  text-align: center;
  font-size: clamp(11px, calc(var(--vh) * 1.9), 16px);
  letter-spacing: 0.12em;
  color: #cfd8df;
  animation: tutor-blink 1.2s steps(1, end) infinite;
}

@keyframes tutor-blink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .tutor-ring,
  .tutor-tap {
    animation: none;
  }
}

/* --- 暗転の幕 ---
   場面が切り替わる前のひと呼吸。台本に fade と書いた行で下ろす。
   文章と AUTO / SKIP は幕より前に残すので、読んだまま先へ進める。 */
.story-screen .story-veil {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: #000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.55s linear;
}

.story-screen.blackout .story-veil {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .story-screen .story-veil { transition-duration: 0.01s; }
}

/* --- GAME CLEAR の背景 ---
   黒一色の上に、ロゴのシルエットを薄く敷きつめる。
   タイルは端がつながるように作ってあるので、repeat でそのまま並ぶ。
   （GAME OVER のときは、これまでどおりの暗い下地のまま） */
#overScreen.clear {
  background:
    url("assets/logo-tile.webp") repeat 0 0 / 30% auto,
    #000000;
}

/* 文字と数字が沈まないよう、中身の後ろだけ少し暗く落とす */
#overScreen.clear .over-title,
#overScreen.clear .result {
  position: relative;
  z-index: 1;
}

#overScreen.clear::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(0, 0, 0, 0.62),
    rgba(0, 0, 0, 0.12) 66%,
    rgba(0, 0, 0, 0.5)
  );
}
