/* ===== シュールキューブ - 3D回転パズル ===== */

body {
  margin: 0;
  padding: 0;
  background: var(--sg-bg-dark);
  color: var(--sg-text-light);
  font-family: var(--sg-font-body);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

/* --- 画面切り替え --- */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active {
  display: flex;
}

/* --- トップ戻りリンク --- */
.back-to-top-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 5000;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--sg-radius-sm);
  backdrop-filter: blur(4px);
  transition: color 0.2s;
}
.back-to-top-link:hover {
  color: #fff;
}

/* --- タイトル画面 --- */
#title-screen {
  background: radial-gradient(ellipse at center, #1a0a3e 0%, #0d0221 70%);
}
.title-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.game-title {
  font-family: var(--sg-font-heading);
  font-size: 2.2rem;
  background: linear-gradient(90deg, var(--sg-brand-pink), var(--sg-brand-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 12px rgba(255, 110, 199, 0.5));
}
.game-subtitle {
  font-size: 0.95rem;
  color: var(--sg-text-muted);
}

#preview-canvas {
  border-radius: var(--sg-radius-md);
  background: transparent;
}

/* --- 共通ボタン --- */
.btn-primary, .btn-secondary {
  padding: 14px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--sg-font-body);
  border: none;
  border-radius: var(--sg-radius-pill);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--sg-brand-pink), #a855f7);
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 110, 199, 0.4);
}
.btn-primary:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(255, 110, 199, 0.6);
}
.btn-primary:active {
  transform: scale(0.97);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--sg-text-light);
  box-shadow: none;
  font-size: 1rem;
  padding: 10px 32px;
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- ステージ選択画面 --- */
#stage-select-screen {
  background: radial-gradient(ellipse at center, #1a0a3e 0%, #0d0221 70%);
}
.stage-select-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
  max-height: 100vh;
  overflow-y: auto;
}
.screen-heading {
  font-family: var(--sg-font-heading);
  font-size: 1.8rem;
  color: var(--sg-brand-cyan);
}
.stage-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}
.stage-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--sg-radius-md);
  color: var(--sg-text-light);
  font-family: var(--sg-font-body);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  text-align: left;
}
.stage-btn:hover:not(.locked) {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--sg-brand-cyan);
}
.stage-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}
.stage-btn.cleared {
  border-color: var(--sg-brand-green);
}
.stage-num {
  font-weight: 700;
  font-size: 1.3rem;
  width: 36px;
  text-align: center;
  color: var(--sg-brand-pink);
}
.stage-info {
  flex: 1;
}
.stage-name {
  font-weight: 700;
}
.stage-desc {
  font-size: 0.75rem;
  color: var(--sg-text-muted);
  margin-top: 2px;
}
.stage-star {
  font-size: 1.2rem;
}

/* --- ゲーム画面 --- */
#game-screen {
  background: #0d0221;
}
.game-hud {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: var(--sg-radius-md);
  backdrop-filter: blur(4px);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 280px;
}
.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.hud-item {
  display: flex;
  gap: 4px;
  align-items: center;
}
.hud-item span:first-child {
  color: var(--sg-brand-cyan);
  font-size: 0.75rem;
}
.hud-item span:last-child {
  color: #fff;
  font-size: 1rem;
}
.hud-quest {
  flex: 1;
  justify-content: center;
}
#hud-quest-emoji {
  font-size: 1.4rem;
}
#hud-quest-text {
  color: var(--sg-brand-yellow) !important;
  font-size: 0.9rem !important;
}
.hud-timer-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  overflow: hidden;
}
.hud-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sg-brand-green), var(--sg-brand-cyan));
  border-radius: 3px;
  transition: width 0.1s linear;
  width: 100%;
}
.hud-timer-fill.danger {
  background: linear-gradient(90deg, #ff4444, #ff6ec7);
}

#game-canvas {
  max-width: 400px;
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  margin-top: 80px;
}

.hint-text {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--sg-text-muted);
  text-align: center;
}

/* --- クリア画面 --- */
#clear-screen {
  background: radial-gradient(ellipse at center, #0a1a3e 0%, #0d0221 70%);
}
.clear-content, .result-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px;
}
.clear-title {
  font-family: var(--sg-font-heading);
  font-size: 2rem;
  color: var(--sg-brand-green);
  text-shadow: 0 0 20px rgba(57, 255, 20, 0.5);
}

/* --- ゲームオーバー・リザルト画面 --- */
#gameover-screen, #result-screen {
  background: radial-gradient(ellipse at center, #1a0a3e 0%, #0d0221 70%);
}
.result-title {
  font-family: var(--sg-font-heading);
  font-size: 2rem;
  color: var(--sg-brand-pink);
}

/* --- 統計行 --- */
.clear-stats, .result-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 200px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 1rem;
}
.stat-row span:first-child {
  color: var(--sg-brand-cyan);
  font-size: 0.85rem;
}
.stat-row span:last-child {
  font-size: 1.3rem;
  font-weight: 700;
}
.stat-total {
  border-bottom: none;
  border-top: 2px solid var(--sg-brand-pink);
  padding-top: 10px;
}
.stat-total span:last-child {
  color: var(--sg-brand-yellow);
  font-size: 1.5rem;
}

#title-highscore {
  margin-top: 4px;
}

/* --- レスポンシブ --- */
@media (min-width: 700px) {
  #stage-select-screen.active,
  #clear-screen.active,
  #gameover-screen.active,
  #result-screen.active {
    justify-content: flex-start;
    padding-top: clamp(84px, 11vh, 128px);
  }

  .title-content {
    width: min(100%, 560px);
    gap: 16px;
  }

  .game-title {
    font-size: 2.8rem;
  }

  .game-subtitle {
    font-size: 1rem;
    max-width: 30ch;
  }

  #preview-canvas {
    width: 240px;
    height: 240px;
  }

  .stage-select-content {
    width: min(100%, 560px);
    gap: 20px;
    padding-inline: 24px;
  }

  .screen-heading {
    font-size: 2.1rem;
  }

  .stage-list {
    max-width: 440px;
  }

  .stage-btn {
    padding: 14px 18px;
  }

  .game-hud {
    min-width: 320px;
    padding: 10px 18px;
  }

  #game-canvas {
    max-width: 440px;
    margin-top: 92px;
  }

  .clear-content,
  .result-content {
    width: min(100%, 460px);
    gap: 18px;
  }

  .clear-title,
  .result-title {
    font-size: 2.2rem;
  }

  .clear-stats,
  .result-stats {
    min-width: 280px;
  }
}

@media (max-width: 480px) {
  .game-title {
    font-size: 1.6rem;
  }
  .game-subtitle {
    font-size: 0.8rem;
  }
  .btn-primary {
    padding: 12px 36px;
    font-size: 1rem;
  }
  .game-hud {
    min-width: 240px;
    padding: 6px 12px;
  }
  #game-canvas {
    margin-top: 70px;
  }
  .screen-heading {
    font-size: 1.4rem;
  }
}
