/* ==========================================================
   バランス気球便 - style.css
   ========================================================== */

:root {
  --color-sky-top: #5fb2e6;
  --color-sky-bottom: #e8f4fb;
  --color-panel: #2c4a63;
  --color-panel-2: #375874;
  --color-accent: #ffb340;
  --color-accent-2: #ffe08a;
  --color-good: #6fd48a;
  --color-bad: #ff6b6b;
  --color-warn: #ffcc55;
  --color-text: #f4f8fb;
  --color-text-muted: #b9cbdb;
  --color-border: #4c7699;
  --header-h: 56px;
  --ad-h: 64px;
  --pad-h: 132px;
}

* {
  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: #1d3348;
  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;
  gap: 0.4rem;
  padding: 0 0.7rem;
  background: linear-gradient(180deg, #3a678d, #24405a);
  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: 10px;
  flex: 0 0 auto;
}
.back-link:hover { background: rgba(255, 255, 255, 0.12); }

.game-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-panel);
  color: var(--color-text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--color-panel-2); }
.icon-btn.is-muted { opacity: 0.65; }

/* ---------- ステージ ---------- */
.game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--color-sky-top) 0%, #9ed3f0 45%, var(--color-sky-bottom) 100%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 6px;
  z-index: 6;
  pointer-events: none;
}

.hud-box {
  background: rgba(20, 42, 61, 0.7);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  padding: 4px 9px;
  min-width: 58px;
  text-align: center;
  backdrop-filter: blur(3px);
}

.hud-box__label {
  display: block;
  font-size: 0.6rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.hud-box__value {
  display: block;
  font-size: 1.02rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-accent);
}

/* ---------- かたむきメーター ----------
   ゴンドラを真上から見た図。中心からのズレが重心のズレを表す。
   カメラの向きに合わせて点を回すので、画面で見える傾きの向きと一致する。 */
.hud-box--balance { padding-bottom: 6px; }

.balance-pad {
  position: relative;
  width: 38px;
  height: 38px;
  margin: 2px auto 0;
  border-radius: 9px;
  border: 1px solid var(--color-border);
  background: rgba(10, 26, 40, 0.6);
}

.balance-pad__ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 21px;
  height: 21px;
  margin: -10.5px 0 0 -10.5px;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  border-radius: 50%;
}

.balance-pad__dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-good);
  box-shadow: 0 0 6px rgba(111, 212, 138, 0.8);
  transform: translate(-50%, -50%);
}
.balance-pad[data-level="warn"] .balance-pad__dot {
  background: var(--color-warn);
  box-shadow: 0 0 7px rgba(255, 204, 85, 0.9);
}
.balance-pad[data-level="danger"] .balance-pad__dot {
  background: var(--color-bad);
  box-shadow: 0 0 9px rgba(255, 107, 107, 0.95);
  animation: dot-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes dot-pulse {
  from { transform: translate(-50%, -50%) scale(1); }
  to { transform: translate(-50%, -50%) scale(1.35); }
}

/* ---------- 傾きすぎ警告 ---------- */
.tilt-warn {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(180, 32, 40, 0.88);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 8;
  pointer-events: none;
}
.tilt-warn.is-visible {
  display: block;
  animation: warn-blink 0.7s ease-in-out infinite alternate;
}
@keyframes warn-blink {
  from { opacity: 0.72; }
  to { opacity: 1; }
}

/* ---------- NEXT ---------- */
.next-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(20, 42, 61, 0.7);
  border: 1px solid var(--color-border);
  border-radius: 9px;
  padding: 4px 7px 6px;
  z-index: 6;
  pointer-events: none;
  backdrop-filter: blur(3px);
}

.next-panel__label {
  display: block;
  font-size: 0.58rem;
  color: var(--color-text-muted);
  letter-spacing: 0.1em;
  text-align: center;
  margin-bottom: 3px;
}

.next-panel__list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}

.next-panel__list canvas {
  display: block;
  width: 44px;
  height: 39px;
}

/* ---------- 得点トースト ---------- */
.score-toast {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(16, 34, 50, 0.55);
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.35;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.75);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 7;
  max-width: 84%;
  text-align: center;
}
.score-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
/* 文章のトーストは長くなるので小さめに。数字だけのときは大きく見せたい */
.score-toast.is-bad { color: #ffd6d6; font-size: 0.92rem; }
.score-toast.is-great { color: #d6ffe2; font-size: 1.05rem; }

/* ---------- 操作パネル ---------- */
.control-pad {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pad-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px 10px;
  background: linear-gradient(180deg, rgba(28, 52, 72, 0) 0%, rgba(28, 52, 72, 0.86) 26%, rgba(28, 52, 72, 0.96) 100%);
  z-index: 8;
}

.dpad {
  position: relative;
  width: 116px;
  height: 116px;
  flex: 0 0 auto;
}

.pad-btn {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 11px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.pad-btn:active { background: var(--color-accent); color: #2a1a06; }

/* ゴンドラを斜めから見ているので、4つの軸は画面上の斜め方向に伸びる。
   矢印もひし形（45度ずらし）に並べて、押した向きと荷物が動く向きを一致させる。 */
.dpad__up, .dpad__down, .dpad__left, .dpad__right {
  position: absolute;
  width: 44px;
  height: 44px;
}
.dpad__up    { top: 0;    right: 0; }
.dpad__right { bottom: 0; right: 0; }
.dpad__down  { bottom: 0; left: 0; }
.dpad__left  { top: 0;    left: 0; }

.action-cluster {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 260px;
}

.action-row {
  display: flex;
  gap: 7px;
}

.pad-btn--wide {
  flex: 1 1 0;
  height: 50px;
  flex-direction: column;
  gap: 1px;
}

.pad-btn__icon { font-size: 1.05rem; line-height: 1; }
.pad-btn__text { font-size: 0.62rem; color: var(--color-text-muted); }
.pad-btn:active .pad-btn__text { color: #2a1a06; }

.pad-btn--drop {
  background: linear-gradient(180deg, #ffbe55, #f08f1d);
  border-color: #ffd08a;
  color: #2a1a06;
  font-weight: 700;
}
.pad-btn--drop .pad-btn__text { color: #5a3a08; font-weight: 700; }
.pad-btn--drop:active { filter: brightness(1.15); }

.pad-btn--camera { background: var(--color-panel-2); }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 28, 42, 0.87);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 30;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay.is-visible { display: flex; }

.overlay__box {
  background: linear-gradient(180deg, #35597a, #22405a);
  border: 2px solid var(--color-border);
  border-radius: 16px;
  padding: 18px 16px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  margin: auto;
}
.overlay__box--wide { max-width: 520px; text-align: left; }

.overlay__title {
  margin: 0 0 12px;
  font-size: 1.16rem;
  font-weight: 700;
  text-align: center;
}

.overlay__result-emoji {
  margin: 0 0 4px;
  font-size: 2.6rem;
  text-align: center;
}

.overlay__score {
  margin: 4px 0 10px;
  font-size: 2.3rem;
  font-weight: 800;
  color: var(--color-accent);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.overlay__desc {
  margin: 4px 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
}

.guide-section { margin-bottom: 12px; }

.guide-section__title {
  margin: 0 0 5px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-accent-2);
}

.guide-section__text {
  margin: 0;
  font-size: 0.83rem;
  line-height: 1.65;
  color: #e2ecf4;
}

.guide-section__list {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.83rem;
  line-height: 1.6;
  color: #e2ecf4;
}
.guide-section__list li { margin-bottom: 3px; }

/* 重心と割れ物の決まりごとの注記 */
.guide-note {
  margin: 7px 0 0;
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--color-text-muted);
}

/* ---------- モード選択 ---------- */
.mode-select {
  margin: 14px 0 4px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

.mode-select__label {
  margin: 0 0 8px;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-accent-2);
}

.mode-select__options {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.mode-option {
  flex: 1 1 0;
  background: var(--color-panel);
  border: 2px solid var(--color-border);
  border-radius: 11px;
  padding: 9px 8px;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.mode-option.is-active {
  border-color: var(--color-accent);
  background: rgba(255, 179, 64, 0.16);
}
.mode-option__name { font-size: 0.85rem; font-weight: 700; }
.mode-option__desc { font-size: 0.68rem; line-height: 1.45; color: var(--color-text-muted); }

.overlay__btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  font-size: 0.98rem;
  font-weight: 700;
  color: #2a1a06;
  background: linear-gradient(180deg, #ffc86a, #f0951d);
  border: none;
  border-radius: 11px;
  cursor: pointer;
}
.overlay__btn:hover { filter: brightness(1.08); }

.overlay__btn--secondary {
  background: var(--color-panel-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

/* ---------- 広告 ---------- */
.ad-gap { height: 10px; flex: 0 0 auto; }

.ad-slot {
  flex: 0 0 var(--ad-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #16293a;
  border-top: 2px dashed var(--color-border);
  overflow: hidden;
  z-index: 20;
}
.ad-slot span { color: #7591aa; font-size: 0.75rem; }

/* ---------- 広い画面 ---------- */
@media (min-width: 720px) {
  .game-title { font-size: 1.15rem; }
  .hud-box__value { font-size: 1.14rem; }
  .control-pad { justify-content: center; gap: 32px; }
  .next-panel__list canvas { width: 54px; height: 48px; }
}

@media (max-height: 620px) {
  :root { --pad-h: 116px; }
  .pad-btn--wide { height: 44px; }
  .dpad { width: 100px; height: 100px; }
  .dpad__up, .dpad__down, .dpad__left, .dpad__right { width: 40px; height: 40px; }
}
