/* ==========================================================
   秒針ピタ止め！金庫破り脱出 - style.css
   ========================================================== */

:root {
  --color-bg-top: #1a1408;
  --color-bg-bottom: #0a0704;
  --color-box: #201808;
  --color-box-border: #6b4e18;
  --color-primary: #ffd54f;
  --color-primary-2: #ff8f00;
  --color-accent: #ffd54f;
  --color-success: #2ed573;
  --color-danger: #ff4d6d;
  --color-text: #fff8e6;
  --color-text-muted: #c9b98a;
  --color-border: #4a3a14;
  --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, #241b0a, #100c04);
  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 {
  min-height: var(--score-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  flex-wrap: wrap;
  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__label {
  font-size: 0.7rem;
  font-weight: bold;
  color: var(--color-text-muted);
  white-space: nowrap;
}

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

.time-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;
  transition: border-color 0.15s ease;
}

.time-box__label {
  font-size: 0.7rem;
  font-weight: bold;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.time-bar-track {
  width: 76px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
  flex: 0 0 auto;
}

.time-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-success), var(--color-primary));
  transition: width 0.15s linear, background 0.2s ease;
}

.time-box__value {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--color-primary);
  min-width: 2.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.time-box.is-low {
  animation: time-box-blink 0.5s steps(1, end) infinite;
}

.time-box.is-low .time-box__value {
  color: var(--color-danger);
}

.time-box.is-low .time-bar-fill {
  background: var(--color-danger);
}

@keyframes time-box-blink {
  0%, 49% { border-color: var(--color-danger); }
  50%, 100% { border-color: var(--color-border); }
}

/* ---------- ゲームステージ ---------- */
.game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

.stage-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: linear-gradient(180deg, rgba(10, 7, 4, 0.55), rgba(10, 7, 4, 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.35s ease-out;
  background: var(--color-danger);
}

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

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

.vault-door {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.vault-door img {
  width: clamp(240px, 74vmin, 440px);
  height: auto;
  opacity: 0.3;
  filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.6));
  transition: opacity 0.5s ease;
}

.vault-door.is-open img {
  opacity: 0.55;
}

/* ---------- ダイヤル ---------- */
.dial-wrap {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dial-face {
  position: relative;
  width: clamp(220px, 58vmin, 380px);
  height: clamp(220px, 58vmin, 380px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2e2410, #100c04 72%);
  border: 6px solid #5a4419;
  box-shadow: 0 0 0 3px #100c04, 0 20px 50px rgba(0, 0, 0, 0.6), inset 0 0 30px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dial-zone {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

/* ---------- デュアルニードル型: 針Bの内側ゾーン(小さいリング) ---------- */
.dial-zone--b {
  display: none;
  inset: 21%;
}

.dial-zone--b.is-visible {
  display: block;
}

/* ---------- 数字合算型: ゾーン上の数字ラベル ---------- */
.dial-numbers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.dial-number-wrap {
  position: absolute;
  inset: 0;
}

.dial-number {
  position: absolute;
  left: 50%;
  top: 19%;
  min-width: 26px;
  height: 26px;
  padding: 0 4px;
  border-radius: 50%;
  background: rgba(10, 7, 4, 0.6);
  border: 1.5px solid rgba(255, 213, 79, 0.65);
  color: #fff8e6;
  font-size: 0.85rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.dial-number.is-used {
  color: var(--color-text-muted);
  border-color: rgba(255, 213, 79, 0.25);
  opacity: 0.55;
}

.dial-ring {
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 213, 79, 0.22);
  pointer-events: none;
}

.dial-needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 44%;
  background: linear-gradient(180deg, #fff8e6 0%, var(--color-primary) 55%, transparent 100%);
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(0deg);
  border-radius: 4px;
  box-shadow: 0 0 12px rgba(255, 213, 79, 0.85);
  pointer-events: none;
  z-index: 2;
}

/* ---------- デュアルニードル型: 針B（内側の短い針、シアン系配色） ---------- */
.dial-needle--b {
  display: none;
  width: 6px;
  height: 30%;
  background: linear-gradient(180deg, #e3f7ff 0%, #4fc3f7 55%, transparent 100%);
  box-shadow: 0 0 12px rgba(79, 195, 247, 0.9);
}

.dial-needle--b.is-visible {
  display: block;
}

/* ---------- 逆回転ギミック: 予兆演出（針パルス・反転フラッシュ） ---------- */
.dial-needle.is-reverse-warn {
  animation: needle-warn-pulse 0.3s ease-in-out infinite;
}

@keyframes needle-warn-pulse {
  0%, 100% { filter: none; }
  50% { filter: brightness(1.7) drop-shadow(0 0 8px rgba(255, 77, 109, 0.9)); }
}

.dial-needle.is-reverse-flash {
  animation: needle-reverse-flash 0.4s ease-out;
}

@keyframes needle-reverse-flash {
  0% { filter: brightness(2.4); }
  100% { filter: brightness(1); }
}

/* ---------- 逆回転ギミック: 画面端の予兆アイコン（ダイヤルではなくステージ全体を基準に配置） ---------- */
.reverse-warn-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 9;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: rgba(10, 7, 4, 0.75);
  border: 2px solid var(--color-danger);
  color: var(--color-danger);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 10px rgba(255, 77, 109, 0.9);
  box-shadow: 0 0 14px rgba(255, 77, 109, 0.6);
  transition: opacity 0.15s ease;
}

.reverse-warn-icon.is-visible {
  opacity: 1;
  animation: reverse-warn-spin 0.6s linear infinite;
}

@keyframes reverse-warn-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.stop-btn {
  position: relative;
  z-index: 3;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  border: 4px solid #5a4419;
  background: radial-gradient(circle at 35% 30%, #4a3a14, #1a1408 82%);
  color: var(--color-accent);
  font-weight: 900;
  font-size: clamp(0.8rem, 3.2vmin, 1.05rem);
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}

.stop-btn:active {
  filter: brightness(1.25);
  transform: scale(0.96);
}

.dial-face.is-shake {
  animation: dial-shake 0.35s ease;
}

@keyframes dial-shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 0); }
  40% { transform: translate(6px, 0); }
  60% { transform: translate(-4px, 0); }
  80% { transform: translate(4px, 0); }
}

/* ---------- PERFECT演出 ---------- */
.perfect-popup {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  z-index: 6;
  font-size: clamp(1.1rem, 5vmin, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff8e6;
  text-shadow: 0 0 14px rgba(255, 213, 79, 0.95), 0 2px 4px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.perfect-popup.is-shown {
  animation: perfect-pop 0.65s ease-out;
}

@keyframes perfect-pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  28% { opacity: 1; transform: translate(-50%, -55%) scale(1.18); }
  70% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(0.92); }
}

/* ---------- ヒント表示エリア（カラーシーケンス型・数字合算型） ---------- */
.dial-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: rgba(10, 7, 4, 0.85);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  padding: 0.4rem 0.9rem;
  max-width: 92%;
}

.dial-hint.is-visible {
  display: flex;
}

.dial-hint__sequence,
.dial-hint__sum,
.dial-hint__dual {
  display: none;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.dial-hint__sequence.is-visible,
.dial-hint__sum.is-visible,
.dial-hint__dual.is-visible {
  display: flex;
}

.dial-hint__dual {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--color-text);
}

.dial-hint__dual-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2) inset;
  flex: 0 0 auto;
}

.dial-hint__dual-dot--a {
  background: var(--color-primary);
}

.dial-hint__dual-dot--b {
  background: #4fc3f7;
}

.hint-dot {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  flex: 0 0 auto;
}

.hint-dot.is-current {
  opacity: 1;
  animation: hint-dot-pulse 1s ease-in-out infinite;
  box-shadow: 0 0 0 2px #fff8e6 inset, 0 0 10px rgba(255, 255, 255, 0.85);
}

.hint-dot.is-done {
  opacity: 0.35;
}

.hint-dot__check {
  color: #fff;
  font-size: 0.7rem;
  font-weight: 900;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.hint-arrow {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  flex: 0 0 auto;
}

@keyframes hint-dot-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.dial-hint__sum {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- 操作ヒント ---------- */
.control-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: 0.78rem;
  font-weight: bold;
  color: var(--color-text-muted);
  background: rgba(10, 7, 4, 0.85);
  border: 1px dashed var(--color-border);
  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;
}

/* ---------- オーバーレイ ---------- */
.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 1.3rem;
  font-size: 0.95rem;
  font-weight: bold;
}

.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, 213, 79, 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;
  }
}
