/* ===== リセット・基本 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --festival-red: #e63946;
  --festival-orange: #f4a261;
  --festival-yellow: #ffd60a;
  --festival-dark: #1a0a00;
  --festival-wood: #8b5e3c;
  --festival-wood-light: #c49a6c;
  --festival-gold: #ffd700;
  --festival-lantern: #ff6b35;
  --bg-night: #1a0a2e;
  --bg-night2: #16213e;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg-night);
  color: #fff;
  user-select: none;
}

/* ===== 画面管理 ===== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ===== タイトル画面 ===== */
#title-screen {
  background: linear-gradient(180deg, #1a0a2e 0%, #2d1b00 60%, #1a0800 100%);
  overflow-y: auto;
}

.title-container {
  text-align: center;
  padding: 20px;
  max-width: 500px;
  width: 100%;
}

.lanterns {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 10px;
  font-size: 2rem;
}

.lantern {
  display: inline-block;
  animation: sway 2s ease-in-out infinite;
}

.lantern:nth-child(1) { animation-delay: 0s; }
.lantern:nth-child(2) { animation-delay: 0.3s; }
.lantern:nth-child(3) { animation-delay: 0.6s; }
.lantern:nth-child(4) { animation-delay: 0.9s; }
.lantern:nth-child(5) { animation-delay: 1.2s; }

@keyframes sway {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.game-title {
  margin: 10px 0;
}

.title-kanji {
  display: block;
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 900;
  color: var(--festival-yellow);
  text-shadow:
    0 0 20px var(--festival-orange),
    0 0 40px var(--festival-red),
    3px 3px 0 var(--festival-wood);
  letter-spacing: 0.2em;
}

.title-sub {
  display: block;
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: var(--festival-orange);
  letter-spacing: 0.3em;
  margin-top: -5px;
}

.title-decoration {
  color: var(--festival-gold);
  font-size: 1.5rem;
  margin: 10px 0;
  letter-spacing: 0.5em;
}

.how-to-play {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid var(--festival-orange);
  border-radius: 12px;
  padding: 15px 20px;
  margin: 15px 0;
  backdrop-filter: blur(5px);
}

.how-to-play h3 {
  color: var(--festival-yellow);
  margin-bottom: 8px;
  font-size: 1.1rem;
}

.how-to-play p {
  font-size: 0.95rem;
  line-height: 1.8;
  color: #ffe8cc;
}

.score-table {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid var(--festival-gold);
  border-radius: 12px;
  padding: 15px 20px;
  margin: 15px 0;
}

.score-table h3 {
  color: var(--festival-yellow);
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.score-table table {
  width: 100%;
  border-collapse: collapse;
}

.score-table td {
  padding: 5px 10px;
  font-size: 0.9rem;
  color: #ffe8cc;
}

.score-table td:last-child {
  text-align: right;
  color: var(--festival-yellow);
  font-weight: bold;
}

/* ===== ボタン ===== */
.btn-primary {
  display: inline-block;
  margin-top: 15px;
  padding: 15px 40px;
  font-size: 1.3rem;
  font-weight: bold;
  font-family: inherit;
  color: var(--festival-dark);
  background: linear-gradient(135deg, var(--festival-yellow), var(--festival-orange));
  border: none;
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(255, 165, 0, 0.5);
  transition: all 0.2s ease;
  letter-spacing: 0.05em;
}

.btn-primary:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 30px rgba(255, 165, 0, 0.7);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary {
  display: inline-block;
  margin-top: 10px;
  margin-left: 10px;
  padding: 12px 30px;
  font-size: 1rem;
  font-weight: bold;
  font-family: inherit;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
}

/* ===== ゲーム画面 ===== */
#game-screen {
  background: #1a0a2e;
  flex-direction: column;
  cursor: none;
}

.game-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 20px;
  background: rgba(26, 10, 0, 0.85);
  border-bottom: 2px solid var(--festival-orange);
  backdrop-filter: blur(5px);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-label {
  font-size: 0.75rem;
  color: var(--festival-orange);
  letter-spacing: 0.1em;
}

.hud-value {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--festival-yellow);
  text-shadow: 0 0 10px var(--festival-orange);
  line-height: 1;
  transition: transform 0.1s ease;
}

.hud-value.bump {
  transform: scale(1.3);
}

#game-canvas {
  display: block;
  cursor: none;
}

/* ===== スコアポップアップ ===== */
.score-popup {
  position: fixed;
  font-size: 2rem;
  font-weight: 900;
  color: var(--festival-yellow);
  text-shadow:
    0 0 10px var(--festival-orange),
    2px 2px 0 #000;
  pointer-events: none;
  z-index: 200;
  animation: popup-float 1s ease-out forwards;
}

.score-popup.hidden {
  display: none;
}

@keyframes popup-float {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-30px) scale(1.3);
  }
  100% {
    opacity: 0;
    transform: translateY(-70px) scale(0.8);
  }
}

/* ===== 結果画面 ===== */
#result-screen {
  background: linear-gradient(180deg, #1a0a2e 0%, #2d1b00 60%, #1a0800 100%);
  overflow-y: auto;
}

.result-container {
  text-align: center;
  padding: 20px;
  max-width: 500px;
  width: 100%;
  position: relative;
}

.result-title {
  font-size: clamp(1.8rem, 6vw, 2.5rem);
  color: var(--festival-yellow);
  text-shadow: 0 0 20px var(--festival-orange);
  margin: 10px 0;
}

.result-score-box {
  background: rgba(255, 215, 0, 0.1);
  border: 3px solid var(--festival-gold);
  border-radius: 20px;
  padding: 20px;
  margin: 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}

.result-label {
  font-size: 1rem;
  color: var(--festival-orange);
}

.result-score {
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 900;
  color: var(--festival-yellow);
  text-shadow:
    0 0 20px var(--festival-orange),
    0 0 40px var(--festival-red);
  line-height: 1;
}

.result-comment {
  font-size: 1.3rem;
  color: #ffe8cc;
  margin: 15px 0;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.result-emoji {
  font-size: 3rem;
  margin: 10px 0;
  animation: bounce 0.5s ease infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

/* ===== 紙吹雪 ===== */
#confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -20px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* ===== レスポンシブ ===== */
@media (max-width: 480px) {
  .game-hud {
    padding: 6px 10px;
  }
  .hud-value {
    font-size: 1.4rem;
  }
  .score-popup {
    font-size: 1.5rem;
  }
}
