/* ==========================================================
   瞬感！フラッシュ四則暗算 - style.css
   ========================================================== */

:root {
  --color-bg-top: #161045;
  --color-bg-bottom: #06040f;
  --color-primary: #00e5ff;
  --color-primary-2: #ff2fd0;
  --color-accent: #ffe94d;
  --color-danger: #ff4d6d;
  --color-text: #eafcff;
  --color-text-muted: #8f9bd1;
  --color-border: #362a7a;
  --color-panel: #181240;
  --header-h: 56px;
  --score-h: 52px;
  --timer-h: 26px;
  --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: linear-gradient(180deg, var(--color-bg-top), 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: rgba(255, 255, 255, 0.06);
  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.25rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

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

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

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

.stat-box__value--next {
  color: var(--color-accent);
  font-size: 1.2rem;
}

/* ---------- タイマーバー ---------- */
.timer-bar {
  position: relative;
  height: var(--timer-h);
  flex: 0 0 auto;
  margin: 0 0.9rem 0.5rem;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  z-index: 15;
}

.timer-bar__fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-2));
  transition: width 0.2s linear, background 0.3s ease;
}

.timer-bar__label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ---------- ゲームステージ ---------- */
.game-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.stage-inner {
  position: relative;
  width: min(100%, 460px);
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 3vh, 1.4rem);
}

/* ---------- カウントダウン表示 ---------- */
.countdown-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 18;
  font-size: clamp(3rem, 22vw, 6rem);
  font-weight: 900;
  color: var(--color-accent);
  text-shadow: 0 0 18px rgba(255, 233, 77, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.countdown-display.is-visible {
  opacity: 1;
}

/* ---------- フラッシュパネル ---------- */
.flash-panel {
  position: relative;
  width: min(100%, 400px);
  aspect-ratio: 16 / 10;
  background-image: url("assets/panel.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.flash-panel__problem {
  position: relative;
  font-size: clamp(1.5rem, 9vw, 2.6rem);
  font-weight: 900;
  color: #eafcff;
  text-shadow: 0 0 14px rgba(0, 229, 255, 0.85), 0 0 3px #fff;
  letter-spacing: 0.02em;
  text-align: center;
  padding: 0 1rem;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.flash-panel__problem.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* れんぞくフラッシュ：演算記号ごとの色分け */
.flash-panel__problem.op-add {
  color: #3dffb0;
  text-shadow: 0 0 14px rgba(61, 255, 176, 0.85), 0 0 3px #fff;
}

.flash-panel__problem.op-sub {
  color: #ff6b8f;
  text-shadow: 0 0 14px rgba(255, 107, 143, 0.85), 0 0 3px #fff;
}

.flash-panel__problem.op-mul {
  color: #00e5ff;
  text-shadow: 0 0 14px rgba(0, 229, 255, 0.85), 0 0 3px #fff;
}

.flash-panel__problem.op-div {
  color: #ffe94d;
  text-shadow: 0 0 14px rgba(255, 233, 77, 0.85), 0 0 3px #fff;
}

.flash-panel__hint {
  position: absolute;
  bottom: 8%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: bold;
  color: var(--color-text-muted);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.flash-panel__hint.is-visible {
  opacity: 1;
}

/* ---------- 回答エリア ---------- */
.answer-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.answer-area.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.answer-area__label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--color-text-muted);
}

.answer-timer {
  width: min(100%, 340px);
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.answer-timer__fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--color-primary-2), var(--color-danger));
  transition: width 0.1s linear;
}

.choices-grid {
  width: min(100%, 400px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.choice-btn {
  border: 2px solid var(--color-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  border-radius: 16px;
  padding: 0.9rem 0.4rem;
  font-size: clamp(1.1rem, 6vw, 1.5rem);
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.choice-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.14);
}

.choice-btn:disabled {
  cursor: default;
}

.choice-btn.is-correct {
  border-color: #3dffb0;
  background: rgba(61, 255, 176, 0.3);
  color: #3dffb0;
  box-shadow: 0 0 0 3px rgba(61, 255, 176, 0.35), 0 0 26px rgba(61, 255, 176, 0.85);
  animation: choiceCorrectPop 0.5s cubic-bezier(.3, 1.6, .4, 1);
  z-index: 1;
}

.choice-btn.is-wrong {
  border-color: var(--color-danger);
  background: rgba(255, 77, 109, 0.3);
  color: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(255, 77, 109, 0.35), 0 0 26px rgba(255, 77, 109, 0.85);
  animation: choiceShake 0.45s ease;
}

@keyframes choiceCorrectPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.16); }
  60% { transform: scale(0.96); }
  100% { transform: scale(1.04); }
}

@keyframes choiceShake {
  0%, 100% { transform: translateX(0) scale(1); }
  15% { transform: translateX(-7px) scale(1.03); }
  30% { transform: translateX(7px) scale(1.03); }
  45% { transform: translateX(-6px) scale(1.02); }
  60% { transform: translateX(6px) scale(1.02); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
}

/* ---------- あたり/はずれ演出（画面フラッシュ・スタンプ・パーティクル） ---------- */
.fx-flash {
  position: absolute;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  opacity: 0;
}

.fx-flash.is-correct {
  background: radial-gradient(circle, rgba(61, 255, 176, 0.55) 0%, rgba(61, 255, 176, 0) 68%);
  animation: fxFlashPulse 0.55s ease-out;
}

.fx-flash.is-wrong {
  background: radial-gradient(circle, rgba(255, 77, 109, 0.55) 0%, rgba(255, 77, 109, 0) 68%);
  animation: fxFlashPulse 0.5s ease-out;
}

@keyframes fxFlashPulse {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

.fx-stamp {
  position: absolute;
  inset: 0;
  z-index: 26;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: clamp(1.4rem, 8vw, 2.4rem);
  font-weight: 900;
  opacity: 0;
  white-space: nowrap;
}

.fx-stamp.is-correct {
  color: #3dffb0;
  text-shadow: 0 0 10px rgba(61, 255, 176, 1), 0 0 34px rgba(61, 255, 176, 0.8);
  animation: fxStampCorrect 0.65s cubic-bezier(.25, 1.6, .4, 1) forwards;
}

.fx-stamp.is-wrong {
  color: #ff4d6d;
  text-shadow: 0 0 10px rgba(255, 77, 109, 1), 0 0 34px rgba(255, 77, 109, 0.8);
  animation: fxStampWrong 0.55s ease forwards;
}

@keyframes fxStampCorrect {
  0% { opacity: 0; transform: scale(0.3) rotate(-10deg); }
  30% { opacity: 1; transform: scale(1.3) rotate(5deg); }
  50% { transform: scale(0.98) rotate(0deg); }
  78% { opacity: 1; transform: scale(1.06); }
  100% { opacity: 0; transform: scale(1.15); }
}

@keyframes fxStampWrong {
  0% { opacity: 0; transform: scale(0.6) translateX(0); }
  15% { opacity: 1; transform: scale(1.1) translateX(0); }
  30% { transform: scale(1.1) translateX(-10px); }
  45% { transform: scale(1.1) translateX(10px); }
  60% { transform: scale(1.1) translateX(-6px); }
  75% { transform: scale(1.05) translateX(4px); opacity: 1; }
  100% { opacity: 0; transform: scale(1) translateX(0); }
}

.fx-particle {
  position: absolute;
  left: 0;
  top: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 27;
  animation: fxParticleFly 0.65s ease-out forwards;
}

@keyframes fxParticleFly {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(0.2); opacity: 0; }
}

.stage-inner.is-shaking {
  animation: stageShake 0.4s ease;
}

@keyframes stageShake {
  0%, 100% { transform: translateX(0); }
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 3, 16, 0.78);
  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-panel);
  border: 3px solid var(--color-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;
}

.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: 1rem;
  font-weight: bold;
}

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

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

/* ---------- ガイド画面 ---------- */
.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;
}

/* ---------- ルール選択画面 ---------- */
.rule-grid {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-top: 1rem;
}

.rule-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  border: 2px solid var(--color-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  border-radius: 18px;
  padding: 1.1rem 1rem;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.rule-btn:active {
  transform: scale(0.97);
  background: rgba(255, 255, 255, 0.14);
}

.rule-btn:nth-child(2) {
  border-color: var(--color-accent);
}

.rule-btn__icon {
  font-size: 2.1rem;
  line-height: 1;
}

.rule-btn__title {
  font-size: 1.02rem;
  font-weight: 900;
  color: var(--color-primary);
}

.rule-btn:nth-child(2) .rule-btn__title {
  color: var(--color-accent);
}

.rule-btn__desc {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--color-text-muted);
  line-height: 1.5;
}

/* ---------- 難易度選択画面 ---------- */
.difficulty-grid {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1rem;
}

.difficulty-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  border: 2px solid var(--color-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  border-radius: 16px;
  padding: 0.85rem 1.1rem;
  cursor: pointer;
  text-align: left;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.difficulty-btn:active {
  transform: scale(0.97);
  background: rgba(255, 255, 255, 0.14);
}

.difficulty-btn__label {
  font-size: 1.05rem;
  font-weight: 900;
  flex: 0 0 auto;
}

.difficulty-btn__desc {
  font-size: 0.72rem;
  font-weight: bold;
  color: var(--color-text-muted);
  text-align: right;
  line-height: 1.4;
}

.difficulty-btn--easy {
  border-color: #3dffb0;
}

.difficulty-btn--easy .difficulty-btn__label {
  color: #3dffb0;
}

.difficulty-btn--normal {
  border-color: var(--color-primary);
}

.difficulty-btn--normal .difficulty-btn__label {
  color: var(--color-primary);
}

.difficulty-btn--hard {
  border-color: var(--color-danger);
}

.difficulty-btn--hard .difficulty-btn__label {
  color: var(--color-danger);
}

/* ---------- モード選択画面 ---------- */
.mode-back-btn {
  display: block;
  margin: 0 0 0.6rem;
  border: none;
  background: none;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: bold;
  cursor: pointer;
  padding: 0.3rem 0;
}

.mode-back-btn:active {
  color: var(--color-text);
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-top: 1rem;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 2px solid var(--color-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
  border-radius: 16px;
  padding: 1rem 0.5rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.mode-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.14);
}

.mode-btn__sym {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--color-primary);
  text-shadow: 0 0 10px rgba(0, 229, 255, 0.6);
}

.mode-btn__label {
  font-size: 0.78rem;
  font-weight: bold;
  color: var(--color-text-muted);
}

.mode-btn--all {
  grid-column: 1 / -1;
  border-color: var(--color-accent);
}

.mode-btn--all .mode-btn__sym {
  color: var(--color-accent);
  text-shadow: 0 0 10px rgba(255, 233, 77, 0.6);
}

/* ---------- 広告スペース ---------- */
.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;
  }
}
