/* ==========================================================
   スカイタイムアタック - style.css
   ========================================================== */

:root {
  --color-bg: #0b1a2c;
  --color-stage-top: #1c3a5c;
  --color-accent: #ff4d4d;
  --color-accent-2: #ffd93d;
  --color-cyan: #4fd6ff;
  --color-good: #2ecc71;
  --color-text: #f5f8fc;
  --color-text-muted: #9db2c9;
  --color-border: #2c4b6b;
  --header-h: 56px;
  --ad-h: 64px;
}

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

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

body {
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  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, #10233a, var(--color-bg));
  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: 1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  margin: 0;
  color: var(--color-cyan);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}

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

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

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

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

.icon-btn.is-active {
  color: var(--color-cyan);
  background: rgba(79, 214, 255, 0.18);
}

/* ---------- レースステージ（Three.jsキャンバス） ---------- */
.race-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    var(--stage-bg-top, var(--color-stage-top)),
    var(--stage-bg-bottom, var(--color-bg)) 85%
  );
  touch-action: none;
  transition: background 0.6s ease;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  pointer-events: none;
}

.hud-box {
  background: rgba(8, 18, 30, 0.55);
  border: 1px solid var(--stage-accent-border, rgba(255, 255, 255, 0.15));
  border-radius: 10px;
  padding: 0.25rem 0.7rem;
  text-align: center;
  backdrop-filter: blur(2px);
  line-height: 1.2;
}

.hud-box__label {
  display: block;
  font-size: 0.58rem;
  font-weight: 800;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
}

.hud-box__value {
  display: block;
  font-size: 1.15rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.hud-box--time .hud-box__value { color: var(--color-accent-2); }
.hud-box--speed .hud-box__value { color: var(--color-cyan); }

/* ---------- 操作ヒント ---------- */
.control-hint {
  position: absolute;
  bottom: 124px; /* BOOSTボタンと重ならない高さ */
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  font-size: 0.75rem;
  font-weight: bold;
  color: #fff;
  background: rgba(8, 18, 30, 0.6);
  border: 1px dashed rgba(255, 255, 255, 0.35);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.control-hint.is-hidden {
  opacity: 0;
}

/* ---------- ステージ通知トースト ---------- */
.stage-toast {
  position: absolute;
  top: 66px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 8;
  text-align: center;
  padding: 0.5rem 1.2rem;
  border-radius: 12px;
  background: rgba(8, 18, 30, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  white-space: nowrap;
}

.stage-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.stage-toast__name {
  display: block;
  font-size: 1rem;
  font-weight: 900;
  color: var(--stage-accent, var(--color-cyan));
}

.stage-toast__subtitle {
  display: block;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-top: 0.1rem;
}

/* ---------- BOOST発動中のエフェクト（放射状のスピードライン＋周辺光） ---------- */
.boost-fx {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
  background:
    radial-gradient(ellipse 62% 58% at 50% 50%, rgba(79, 214, 255, 0) 52%, rgba(79, 214, 255, 0.3) 100%),
    repeating-conic-gradient(from 0deg at 50% 50%,
      rgba(255, 255, 255, 0.2) 0deg 0.5deg,
      rgba(255, 255, 255, 0) 0.5deg 4.5deg);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 24%, #000 70%);
  mask-image: radial-gradient(circle at 50% 50%, transparent 24%, #000 70%);
}

.boost-fx.is-active {
  opacity: 1;
  animation: boost-fx-spin 7s linear infinite;
}

@keyframes boost-fx-spin {
  from { transform: rotate(0deg) scale(1.5); }
  to { transform: rotate(360deg) scale(1.5); }
}

/* ---------- ゲート通過時のBOOST回復ポップ ---------- */
.boost-popup {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, 0);
  z-index: 9;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--color-cyan);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.boost-popup.is-perfect {
  color: var(--color-accent-2);
  font-size: 1.4rem;
}

.boost-popup.is-visible {
  animation: boost-popup-anim 0.85s ease-out;
}

@keyframes boost-popup-anim {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.85); }
  22% { opacity: 1; transform: translate(-50%, -4px) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -16px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(1); }
}

/* ---------- BOOSTボタン ---------- */
.boost-btn {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 12;
  width: 96px;
  height: 96px;
  padding: 5px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  touch-action: none;
  background: conic-gradient(
    var(--boost-color, #4fd6ff) calc(var(--boost, 0) * 1%),
    rgba(255, 255, 255, 0.12) 0
  );
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s ease, transform 0.12s ease;
}

.boost-btn__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #16324a, #08131f 75%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.boost-btn__label {
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--color-cyan);
}

.boost-btn__value {
  font-size: 0.7rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

.boost-btn.is-active {
  --boost-color: #ffd93d;
  transform: scale(1.06);
  box-shadow: 0 0 26px rgba(255, 217, 61, 0.65), 0 8px 20px rgba(0, 0, 0, 0.5);
}

.boost-btn.is-active .boost-btn__inner {
  background: radial-gradient(circle at 50% 30%, #4a3a10, #1a1305 75%);
}

.boost-btn.is-active .boost-btn__label {
  color: var(--color-accent-2);
}

.boost-btn.is-empty {
  --boost-color: #6a7a8c;
  opacity: 0.72;
}

.boost-btn.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---------- クラッシュ時の赤フラッシュ ---------- */
.crash-flash {
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgba(255, 40, 40, 0.001);
  pointer-events: none;
}

.crash-flash.is-flashing {
  animation: crash-flash-anim 0.4s ease-out;
}

@keyframes crash-flash-anim {
  0% { background: rgba(255, 40, 40, 0.55); }
  100% { background: rgba(255, 40, 40, 0.001); }
}

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

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

.overlay__box {
  text-align: center;
  padding: 1.6rem 2rem;
  background: #122236;
  border: 2px solid var(--color-border);
  border-radius: 18px;
  max-width: 85%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

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

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

.overlay__desc {
  color: var(--color-text-muted);
  margin: 0 0 1.3rem;
  font-size: 0.9rem;
}

.overlay__result-emoji {
  font-size: 2.6rem;
  margin: 0 0 0.2rem;
}

.overlay__time {
  font-size: 2.1rem;
  font-weight: 900;
  color: #fff;
  margin: 0 0 0.3rem;
}

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

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

.overlay__btn.is-hidden {
  display: none;
}

.overlay__btn--secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  margin-top: 0.6rem;
  font-size: 0.82rem;
  padding: 0.6rem 1.1rem;
}

.overlay__btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.overlay__desc--boost {
  color: var(--color-cyan);
  font-weight: bold;
  margin-bottom: 0.4rem;
}

/* ---------- ガイド画面 ---------- */
.guide-section {
  text-align: left;
  margin: 1rem 0;
}

.guide-section__title {
  font-size: 0.92rem;
  color: var(--color-cyan);
  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;
}

/* ---------- 難易度選択画面 ---------- */
.diff-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin: 1.1rem 0 1.3rem;
}

@media (min-width: 460px) {
  .diff-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.diff-card {
  position: relative;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid var(--color-border);
  border-radius: 14px;
  padding: 0.7rem 0.7rem 0.6rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.diff-card__icon {
  display: block;
  font-size: 1.5rem;
  line-height: 1.1;
}

.diff-card__name {
  font-size: 0.95rem;
  font-weight: 900;
  margin: 0.15rem 0 0.3rem;
  color: #fff;
}

.diff-card__desc {
  font-size: 0.68rem;
  color: var(--color-text-muted);
  line-height: 1.45;
  margin: 0 0 0.4rem;
}

.diff-card__stage {
  font-size: 0.64rem;
  font-weight: bold;
  margin: 0;
  color: var(--color-text-muted);
  border-top: 1px dashed rgba(255, 255, 255, 0.14);
  padding-top: 0.35rem;
}

.diff-card--easy.is-selected { border-color: #5fd98a; background: rgba(95, 217, 138, 0.14); }
.diff-card--easy.is-selected .diff-card__name { color: #7ee8a4; }
.diff-card--normal.is-selected { border-color: #ffbe5c; background: rgba(255, 190, 92, 0.14); }
.diff-card--normal.is-selected .diff-card__name { color: #ffcf85; }
.diff-card--hard.is-selected { border-color: #ff7a9a; background: rgba(255, 122, 154, 0.14); }
.diff-card--hard.is-selected .diff-card__name { color: #ff9db5; }

/* ---------- ステージ選択画面 ---------- */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin: 1.1rem 0 1.3rem;
}

@media (min-width: 460px) {
  .stage-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.stage-card {
  position: relative;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid var(--color-border);
  border-radius: 14px;
  padding: 0.7rem 0.6rem 0.6rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.stage-card__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  font-weight: 900;
  color: #fff;
  margin: 0 0 0.35rem;
}

.stage-card__name {
  font-size: 0.8rem;
  font-weight: 900;
  margin: 0 0 0.3rem;
  color: #fff;
}

.stage-card__desc {
  font-size: 0.64rem;
  color: var(--color-text-muted);
  line-height: 1.45;
  margin: 0;
}

.stage-card.is-selected {
  border-color: var(--color-cyan);
  background: rgba(79, 214, 255, 0.12);
}

.stage-card.is-selected .stage-card__num {
  background: var(--color-cyan);
  color: #04202f;
}

/* ---------- 機体選択画面 ---------- */
.plane-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.8rem;
  margin: 1.2rem 0 1.4rem;
}

@media (min-width: 420px) {
  .plane-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.plane-card {
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid var(--color-border);
  border-radius: 14px;
  padding: 0.7rem 0.5rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.plane-card.is-selected {
  border-color: var(--color-cyan);
  background: rgba(79, 214, 255, 0.12);
}

/* 機体のシルエットをそのまま見せる3Dプレビュー枠 */
.plane-card__view {
  position: relative;
  width: 100%;
  aspect-ratio: 15 / 11;
  border-radius: 10px;
  margin: 0 auto 0.45rem;
  overflow: hidden;
  background: linear-gradient(180deg, #16283d, #0a1725);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 機体カラーをうっすら敷いて、機種ごとの色味をカードにも出す */
.plane-card__view::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 70% 55% at 50% 62%, var(--plane-color, #4fd6ff), transparent 70%);
  opacity: 0.34;
  pointer-events: none;
}

.plane-card.is-selected .plane-card__view {
  border-color: rgba(79, 214, 255, 0.55);
}

.plane-card__view-img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.5));
}

.plane-card__name {
  font-size: 0.78rem;
  font-weight: bold;
  margin: 0 0 0.3rem;
}

.plane-card__desc {
  font-size: 0.64rem;
  color: var(--color-text-muted);
  margin: 0 0 0.5rem;
  line-height: 1.4;
  min-height: 3.9em;
}

.plane-card__stats {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.plane-stat {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.6rem;
  color: var(--color-text-muted);
}

.plane-stat__label {
  flex: 0 0 38px;
  text-align: left;
}

.plane-stat__bar {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.plane-stat__bar-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--color-cyan), var(--color-accent-2));
  border-radius: 999px;
}

/* ---------- 広告スペース ---------- */
.ad-slot {
  flex: 0 0 var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 2px dashed var(--color-border);
  background: #0e1d30;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  z-index: 20;
  overflow: hidden;
}

@media (max-height: 620px) {
  .ad-slot {
    --ad-h: 44px;
    font-size: 0.65rem;
  }
  .hud-box__value {
    font-size: 1rem;
  }
  .boost-btn {
    width: 74px;
    height: 74px;
    right: 12px;
    bottom: 12px;
  }
  .boost-btn__label { font-size: 0.6rem; }
  .boost-btn__value { font-size: 0.6rem; }
  .control-hint { bottom: 98px; }
}
