/* ==========================================================
   崩落回廊脱出 - style.css
   ========================================================== */

:root {
  --color-bg-top: #241d15;
  --color-bg-bottom: #0e0b07;
  --color-box: #221c14;
  --color-box-border: #5a4a2e;
  --color-primary: #ffab40;
  --color-primary-2: #e8621a;
  --color-accent: #ffc773;
  --color-success: #2ed573;
  --color-danger: #ff4d6d;
  --color-text: #fbf1e2;
  --color-text-muted: #cdb99a;
  --color-border: #4a3d26;
  --color-wobble: #ffd600;
  --header-h: 56px;
  --score-h: 52px;
  --ad-h: 64px;
  --ad-gap-h: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--color-bg-bottom);
  color: var(--color-text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ---------- ヘッダー ---------- */
.game-header {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.8rem;
  background: linear-gradient(180deg, #2a2114, #120e08);
  border-bottom: 2px solid var(--color-border);
  z-index: 20;
}

.back-link {
  color: var(--color-text);
  text-decoration: none;
  font-size: 1.3rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.back-link:active {
  background: rgba(255, 255, 255, 0.18);
}

.game-title {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn.is-muted {
  color: var(--color-text-muted);
}

/* ---------- スコアバー ---------- */
.score-bar {
  height: var(--score-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  z-index: 15;
}

.stat-box {
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid var(--color-border);
  border-radius: 999px;
  padding: 0.3rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-box--best {
  border-color: var(--color-accent);
}

.stat-box__label {
  font-size: 0.7rem;
  font-weight: bold;
  color: var(--color-text-muted);
}

.stat-box__value {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--color-primary);
}

.stat-box--best .stat-box__value {
  color: var(--color-accent);
}

/* ---------- ゲームステージ ---------- */
/* ハザードはトラック幅に対する%で移動するため、相対速度(=何秒でクリアできるか)自体は
   画面幅に依存せず一定だが、幅を無制限にするとPCの広いウィンドウほど絶対的な移動距離(px)・
   目の動きの量が際限なく増え、体感の速さ・難易度が上がってしまう。他ジャンルにはこの問題が
   ない(操作対象がトラック幅いっぱいを移動しない)ため前例が無いが、このゲームはハザードが
   トラック全幅を横断する横スクロール型なので、モバイル基準の幅に上限を設けて揃える。 */
.game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  width: 100%;
  max-width: 560px;
  align-self: center;
  margin: 0 auto;
}

.stage-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: linear-gradient(180deg, rgba(14, 11, 7, 0.5), rgba(14, 11, 7, 0.88)), url("assets/background.png");
  background-size: cover;
  background-position: center;
}

.stage-flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: var(--color-success);
}

.stage-flash.is-success {
  animation: stage-flash-pulse 0.35s ease-out;
  background: var(--color-success);
}

.stage-flash.is-fail {
  animation: stage-flash-pulse 0.5s ease-out;
  background: var(--color-danger);
}

.stage-flash.is-perfect {
  animation: stage-flash-pulse 0.45s ease-out;
  background: var(--color-wobble);
}

@keyframes stage-flash-pulse {
  0% { opacity: 0.32; }
  100% { opacity: 0; }
}

/* ---------- PERFECTポップアップ ---------- */
.perfect-popup {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  z-index: 8;
  font-size: clamp(1.6rem, 8vmin, 2.4rem);
  font-weight: 900;
  color: var(--color-wobble);
  text-shadow: 0 0 14px rgba(255, 214, 0, 0.85), 0 4px 10px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.06em;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.perfect-popup.is-active {
  animation: perfect-pop 0.7s cubic-bezier(0.22, 1.4, 0.4, 1) forwards;
}

@keyframes perfect-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  55% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(0.92) rotate(0deg); }
}

/* ---------- 崩落回廊ランナー ---------- */
.runner-arena {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0 0;
}

/* 奥の壁面レイヤー（低速スクロール、シームレスタイル画像） */
.runner-wall {
  flex: 0 0 26%;
  min-height: 40px;
  background-image:
    linear-gradient(180deg, rgba(14, 11, 7, 0.35), rgba(14, 11, 7, 0.7)),
    url("assets/corridor-wall-texture.png");
  background-repeat: repeat-x;
  /* タイル幅をvw(ビューポート幅)基準にする。高さ基準(auto <height%>)だと画面の縦横比が
     変わるだけでタイル幅が変わり、幅基準で計算しているスクロール速度(groundSpeedPxPerSec)と
     噛み合わずスマホ/PCで見た目の流れる速さが変わって見える原因になっていた。 */
  background-size: 70vw auto;
  background-position: 0 60%;
  opacity: 0.85;
  border-bottom: 2px solid rgba(0, 0, 0, 0.5);
}

/* プレイの主戦場: 手前の床レイヤー・ハザード・キャラクターを重ねる */
.runner-track {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.runner-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34%;
  background-image:
    linear-gradient(180deg, rgba(14, 11, 7, 0) 0%, rgba(14, 11, 7, 0.55) 100%),
    url("assets/corridor-floor-texture.png");
  background-repeat: repeat-x;
  /* 壁と同じ理由でvw基準に統一（groundSpeedPxPerSecの速度基準=トラック幅と揃える） */
  background-size: 55vw auto;
  background-position: 0 30%;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.5) inset;
  z-index: 1;
}

.hazard-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.character-wrap {
  position: absolute;
  left: var(--char-left, 20%);
  bottom: 34%;
  transform: translateX(-50%);
  z-index: 3;
  width: clamp(64px, 16vmin, 108px);
  pointer-events: none;
}

.character-img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 16px rgba(255, 171, 64, 0.35));
  transform-origin: 50% 100%;
  transform: translateY(0) scaleY(1) rotate(0deg);
  transition: transform 0.12s ease-out;
}

.character-wrap.is-airborne .character-img {
  transform: translateY(-52%) rotate(-10deg);
}

.character-wrap.is-ducking .character-img {
  transform: translateY(22%) scaleY(0.56) rotate(2deg);
}

@keyframes character-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(90px) rotate(60deg); opacity: 0; }
}

.character-wrap.is-falling .character-img {
  animation: character-fall 0.7s ease-in forwards;
}

/* ---------- ハザード（共通） ---------- */
/* left(%)はキャラクターと同じく「中心」を表す基準にする（キャラクターのtranslateX(-50%)と揃える）。
   これが無いと到達判定の瞬間、ハザードの絵がキャラクター中心より右にズレて見える不具合になる。 */
.hazard {
  position: absolute;
  transform: translateX(-50%);
  will-change: left;
}

.hazard.is-imminent .hazard__shape {
  filter: brightness(1.25);
}

/* 陥没穴・連続陥没・フェイント: 床レベルに出現、ジャンプで飛び越える */
.hazard--gap,
.hazard--feint {
  bottom: 0;
  width: clamp(46px, 10vmin, 84px);
  height: 40%;
}

.hazard--gap .hazard__shape,
.hazard--feint .hazard__shape {
  position: absolute;
  inset: 0;
  clip-path: polygon(6% 100%, 0% 30%, 30% 0%, 70% 8%, 100% 32%, 92% 100%);
  background: radial-gradient(ellipse at 50% 20%, #3a0f14, #0a0503 72%);
  box-shadow: 0 0 0 2px rgba(255, 77, 109, 0.35) inset, 0 -6px 14px rgba(255, 77, 109, 0.25);
}

.hazard--feint .hazard__shape {
  background: radial-gradient(ellipse at 50% 20%, #34281a, #0a0603 72%);
  box-shadow: 0 0 0 2px rgba(255, 171, 64, 0.28) inset, 0 -6px 14px rgba(255, 171, 64, 0.18);
}

/* 低い天井: 上から垂れ下がる、しゃがみで通過 */
.hazard--lowCeiling {
  top: 0;
  width: clamp(52px, 11vmin, 92px);
  height: 56%;
}

.hazard--lowCeiling .hazard__shape {
  position: absolute;
  inset: 0;
  clip-path: polygon(0% 0%, 100% 0%, 88% 62%, 62% 100%, 38% 84%, 12% 62%);
  background: linear-gradient(180deg, #3a3226, #16120c 82%);
  box-shadow: 0 0 0 2px rgba(255, 171, 64, 0.3) inset, 0 6px 14px rgba(0, 0, 0, 0.5);
}

/* 落下ガレキ: 着地地点の警告シャドウ＋落下する岩 */
.hazard--fallingDebris {
  bottom: 0;
  width: clamp(46px, 10vmin, 80px);
  height: 100%;
}

.hazard--fallingDebris .debris-shadow {
  position: absolute;
  left: 50%;
  /* 地面レイヤー(.runner-floor)は高さ34%分しかなく、その表面はキャラクターの足元と同じ
     bottom:34%の位置にある。ここが6%のままだと影が地面の表面より下＝地面の中に埋まって見える。 */
  bottom: 34%;
  width: 76%;
  height: 14%;
  transform: translateX(-50%) scale(var(--shadow-scale, 0.4));
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 77, 109, 0.55), rgba(255, 77, 109, 0) 72%);
  transition: transform 0.05s linear;
}

.hazard--fallingDebris .debris-rock {
  position: absolute;
  left: 50%;
  /* 影(地面レベル bottom:34%)とは別に、岩自体は「立った状態の頭〜胸の高さ」で止める。
     しゃがみ(is-ducking)はキャラクターの見た目を下げて縮める演出なので、岩が地面レベル(34%)
     まで落ちてしまうと、しゃがんでも同じ高さで重なって見えて「当たっているように見える」
     原因になっていた。立っていれば当たる高さ・しゃがめば頭上を通過する高さに調整する。 */
  bottom: 58%;
  width: 62%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, calc((1 - var(--drop-frac, 0)) * -320%));
  border-radius: 40% 45% 55% 40%;
  background: linear-gradient(160deg, #4a3a28, #14100a 80%);
  box-shadow: 0 0 0 2px rgba(255, 171, 64, 0.3) inset, 0 0 10px 2px rgba(255, 171, 64, 0.35);
  opacity: var(--rock-opacity, 1);
}

/* ---------- 進捗バー（出口までの距離） ---------- */
.progress-bar-wrap {
  position: relative;
  flex: 0 0 auto;
  height: 10px;
  margin: 0.5rem 0.9rem 0.6rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: visible;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-primary-2), var(--color-primary));
  transition: width 0.15s linear;
}

.progress-bar__exit {
  position: absolute;
  right: -4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
}

/* ---------- 操作ボタン（ジャンプ／しゃがみ） ---------- */
.action-btns {
  position: relative;
  z-index: 6;
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  padding: 0 1rem 0.3rem;
}

.action-btn {
  flex: 1 1 0;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.7rem 0;
  border: none;
  border-radius: 18px;
  color: #1a1408;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.5);
}

.action-btn--jump {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
}

.action-btn--duck {
  background: linear-gradient(135deg, #7fd8a0, #2ed573);
}

.action-btn__icon {
  font-size: 1.3rem;
  line-height: 1;
}

.action-btn__label {
  font-size: 0.9rem;
}

.action-btn:active {
  filter: brightness(1.15);
  transform: scale(0.97);
}

/* ---------- 操作ヒント ---------- */
.control-hint {
  flex: 0 0 auto;
  align-self: center;
  margin-bottom: 0.4rem;
  z-index: 6;
  font-size: 0.78rem;
  font-weight: bold;
  color: var(--color-text-muted);
  background: rgba(14, 11, 7, 0.85);
  border: 1px dashed var(--color-border);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 1;
  max-height: 40px;
  transition: opacity 0.6s ease, max-height 0.4s ease, margin 0.4s ease, padding 0.4s ease;
  pointer-events: none;
  overflow: hidden;
}

.control-hint.is-hidden {
  opacity: 0;
  max-height: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 4, 1, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay__box {
  text-align: center;
  padding: 1.8rem 2rem;
  background: var(--color-box);
  border: 3px solid var(--color-box-border);
  border-radius: 22px;
  max-width: 85%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.overlay__box--wide {
  max-width: min(92%, 460px);
  max-height: 88%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.guide-section {
  text-align: left;
  margin: 1rem 0;
}

.guide-section__title {
  font-size: 0.92rem;
  color: var(--color-accent);
  margin: 0 0 0.4rem;
}

.guide-section__text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.6;
}

.guide-section__list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.7;
}

.guide-section__list li {
  margin-bottom: 0.3rem;
}

.overlay__title {
  font-size: 1.4rem;
  font-weight: 900;
  margin: 0 0 0.5rem;
  color: var(--color-accent);
}

.overlay__desc {
  color: var(--color-text-muted);
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  font-weight: bold;
}

.overlay__score {
  color: var(--color-accent);
  margin: 0 0 1.3rem;
  font-size: 1rem;
  font-weight: 900;
}

.overlay__btn {
  border: none;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-2));
  color: #1a1408;
  font-weight: bold;
  font-size: 0.95rem;
  padding: 0.8rem 1.8rem;
  border-radius: 999px;
  cursor: pointer;
}

.overlay__btn:active {
  filter: brightness(0.9);
}

/* ---------- 難易度選択 ---------- */
.difficulty-options {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin: 1.2rem 0 0.4rem;
}

.difficulty-btn {
  border: 2px solid var(--color-box-border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 0.7rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  color: var(--color-text);
}

.difficulty-btn:active {
  background: rgba(255, 199, 115, 0.15);
}

.difficulty-btn__label {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--color-accent);
}

.difficulty-btn__sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ---------- 広告スペース ---------- */
.ad-gap {
  flex: 0 0 var(--ad-gap-h);
  background: var(--color-bg-bottom);
}

.ad-slot {
  flex: 0 0 var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 2px dashed var(--color-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  z-index: 20;
  overflow: hidden;
}

@media (max-height: 640px) {
  .ad-slot {
    --ad-h: 44px;
    font-size: 0.65rem;
  }
  .ad-gap {
    --ad-gap-h: 10px;
  }
}
