/* ==========================================================
   じゅっ！とパズル - style.css
   ========================================================== */

:root {
  --color-bg-top: #f5f2ff;
  --color-bg-bottom: #eef2ff;
  --color-primary: #6c8cff;
  --color-primary-2: #4f6fe0;
  --color-accent: #bae1ff;
  --color-danger: #ff6b8b;
  --color-text: #3d3a52;
  --color-text-muted: #8a86a3;
  --color-border: #ffffff;
  --color-panel: #fffdfb;
  --header-h: 56px;
  --score-h: 56px;
  --ctrl-h: 64px;
  --ad-h: 64px;
  --ad-gap-h: 14px;
}

* {
  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.7rem;
  background: rgba(255, 255, 255, 0.6);
  border-bottom: 3px solid #fff;
  z-index: 20;
}

.back-link {
  color: var(--color-text);
  text-decoration: none;
  font-size: 1.3rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 0 rgba(61, 58, 82, 0.15);
  flex: 0 0 auto;
}

.back-link:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(61, 58, 82, 0.15);
}

.game-title {
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0.01em;
  margin: 0 0.4rem;
  color: var(--color-primary-2);
  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: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--color-text);
  font-size: 1.02rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 rgba(61, 58, 82, 0.15);
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(61, 58, 82, 0.15);
}

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

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

.stat-box {
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid #fff;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  box-shadow: 0 2px 0 rgba(61, 58, 82, 0.1);
}

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

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

.next-box {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid #fff;
  border-radius: 999px;
  padding: 0.2rem 0.6rem 0.2rem 0.7rem;
  box-shadow: 0 2px 0 rgba(61, 58, 82, 0.1);
}

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

.next-chip {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.85rem;
  color: #5a5470;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

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

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

/* ---------- 連鎖バッジ ---------- */
.chain-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  z-index: 6;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #ff9de2, #6c8cff);
  padding: 0.3rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chain-badge.is-visible {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ---------- 操作ボタン ---------- */
.control-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0 0.6rem;
}

.ctrl-btn {
  width: 20%;
  max-width: 68px;
  height: var(--ctrl-h);
  border-radius: 18px;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  color: var(--color-primary-2);
  font-size: 1.3rem;
  font-weight: 900;
  box-shadow: 0 4px 0 rgba(61, 58, 82, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(61, 58, 82, 0.15);
}

.ctrl-btn--drop {
  background: rgba(186, 225, 255, 0.9);
}

.ctrl-btn--hard {
  background: rgba(255, 173, 173, 0.85);
  font-size: 1.1rem;
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(61, 58, 82, 0.45);
  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: 4px solid #fff;
  border-radius: 26px;
  max-width: 85%;
  box-shadow: 0 20px 50px rgba(61, 58, 82, 0.35);
}

.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-primary-2);
}

.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), #8fa8ff);
  color: #fff;
  font-weight: 900;
  font-size: 0.95rem;
  padding: 0.8rem 1.8rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-primary-2);
}

.overlay__btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--color-primary-2);
}

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

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

/* ---------- 難易度選択 ---------- */
.difficulty-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

.difficulty-btn {
  flex: 1 1 0;
  border: none;
  background: linear-gradient(135deg, var(--color-primary), #8fa8ff);
  color: #fff;
  font-weight: 900;
  font-size: 0.82rem;
  padding: 0.75rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-primary-2);
}

.difficulty-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--color-primary-2);
}

#diff-easy { background: linear-gradient(135deg, #9be89b, #6bcb77); box-shadow: 0 4px 0 #4fa85b; }
#diff-normal { background: linear-gradient(135deg, #8fa8ff, var(--color-primary)); box-shadow: 0 4px 0 var(--color-primary-2); }
#diff-hard { background: linear-gradient(135deg, #ff9de2, #ff6b8b); box-shadow: 0 4px 0 #e0506e; }

/* ---------- ランキング ---------- */
.ranking-box {
  margin-top: 1.2rem;
  text-align: left;
}

.ranking-box__title {
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--color-primary-2);
  margin: 0 0 0.4rem;
  text-align: center;
}

.ranking-list {
  margin: 0;
  padding-left: 1.4rem;
  font-size: 0.8rem;
  color: var(--color-text);
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
}

.ranking-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.ranking-list .ranking-score {
  font-weight: 900;
  color: var(--color-primary-2);
}

.ranking-list .ranking-date {
  color: var(--color-text-muted);
  font-size: 0.72rem;
}

/* ---------- 広告スペース ---------- */
.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-primary);
  background: rgba(255, 255, 255, 0.6);
  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: 8px;
  }
  .control-bar {
    bottom: 6px;
  }
  .ctrl-btn {
    height: 52px;
  }
}

@media (max-width: 360px) {
  .game-title {
    font-size: 0.74rem;
  }
  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }
  .stat-box__label, .next-box__label {
    display: none;
  }
}
