*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sky-top: #8ec9f0;
  --sky-bottom: #d7f0fb;
  --grass: #6fbf5c;
  --grass-dark: #57a047;
  --ui-bg: #ffffff;
  --ui-border: #2f3b45;
  --accent: #ff8a3d;
  --danger: #e5484d;
  --success: #2fae60;
  --text: #2f3b45;
  --font-display: 'Jua', 'Malgun Gothic', sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #cdeafc, #f4fbe9);
  font-family: var(--font-display);
  color: var(--text);
  padding: 1rem;
}

.game-wrap {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ── HUD ── */
.hud {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--ui-bg);
  border: 3px solid var(--ui-border);
  border-radius: 14px;
  padding: 0.6rem 1rem;
  flex-wrap: wrap;
}

.hud-item {
  font-size: 1.1rem;
  white-space: nowrap;
}
.hud-item span { color: var(--accent); }

#timer.danger {
  color: var(--danger);
  font-weight: 700;
  animation: timer-pulse 0.6s ease-in-out infinite;
}
@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

#score.pop { animation: score-pop 0.28s ease-out; }
@keyframes score-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.5); color: var(--success); }
  100% { transform: scale(1); }
}

.anger-wrap {
  flex: 1;
  min-width: 140px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.anger-label { font-size: 0.85rem; flex-shrink: 0; }

.anger-bar-track {
  flex: 1;
  height: 14px;
  background: #eee;
  border: 2px solid var(--ui-border);
  border-radius: 999px;
  overflow: hidden;
}

.anger-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd166, var(--danger));
  transition: width 0.15s ease;
}
.anger-bar.full { animation: anger-pulse 0.5s ease-in-out infinite; }
.anger-bar.warm {
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.35) 0 6px, transparent 6px 12px),
    linear-gradient(90deg, #ffd166, var(--danger));
  background-size: 24px 100%, 100% 100%;
  animation: anger-shimmer 0.7s linear infinite;
}
@keyframes anger-shimmer {
  from { background-position: 0 0, 0 0; }
  to { background-position: 24px 0, 0 0; }
}

@keyframes anger-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.combo-badge, .golden-badge {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
}
.combo-badge {
  background: #fff1de;
  color: #c9601f;
  border: 2px solid #ffb066;
  animation: combo-pop 0.3s ease;
}
.golden-badge {
  background: #fff8dc;
  color: #a67c00;
  border: 2px solid #ffd166;
  animation: golden-pulse 0.7s ease-in-out infinite;
}
@keyframes combo-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes golden-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(255,209,102,0.6); }
  50% { box-shadow: 0 0 10px rgba(255,209,102,0.9); }
}

.sound-toggle {
  border: 2px solid var(--ui-border);
  background: #fff;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── 캔버스 영역 ── */
.canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  border: 3px solid var(--ui-border);
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
}

.canvas-container.shake { animation: shake 0.3s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-8px, 4px); }
  40% { transform: translate(6px, -4px); }
  60% { transform: translate(-5px, 3px); }
  80% { transform: translate(4px, -2px); }
}

.phaser-parent {
  display: block;
  width: 100%;
  height: 100%;
  line-height: 0; /* Phaser가 넣는 canvas 아래 생기는 인라인 여백 제거 */
}
.phaser-parent canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── 피드백(점수 팝업) ── */
.feedback-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.score-popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,0.15);
  opacity: 0;
  transition: transform 0.7s ease-out, opacity 0.7s ease-out;
}
.score-popup.positive { color: var(--success); }
.score-popup.negative { color: var(--danger); }
.score-popup.miss {
  color: #d8dde2;
  font-size: 1rem;
  -webkit-text-stroke: 1px rgba(0,0,0,0.3);
}
.score-popup.show {
  opacity: 1;
  transform: translate(-50%, -140%);
}

/* ── 오버레이 ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(60, 90, 130, 0.35), transparent 60%),
    rgba(12, 18, 26, 0.6);
  backdrop-filter: blur(3px);
  color: #fff;
  overflow-y: auto;
  padding: 1.25rem;
}

/* ── 메뉴 패널(타이틀/결과 카드) ── */
.menu-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  text-align: center;
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, #fffaf0, #fff1d6);
  border: 4px solid var(--ui-border);
  border-radius: 22px;
  padding: 1.6rem 1.4rem 1.4rem;
  box-shadow: 0 10px 0 rgba(0,0,0,0.25), 0 16px 30px rgba(0,0,0,0.35);
  color: var(--text);
  position: relative;
  animation: panel-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes panel-pop {
  0% { transform: scale(0.75) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.title-badge {
  position: absolute;
  top: -14px;
  right: -10px;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 2px solid #fff;
  transform: rotate(12deg);
  animation: badge-wiggle 1.6s ease-in-out infinite;
  box-shadow: 0 3px 0 rgba(0,0,0,0.2);
}
@keyframes badge-wiggle {
  0%, 100% { transform: rotate(12deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.08); }
}

.game-title {
  font-size: clamp(1.9rem, 7vw, 2.7rem);
  color: #c9601f;
  -webkit-text-stroke: 2px #4a2a10;
  text-shadow:
    0 2px 0 #4a2a10,
    0 4px 0 #4a2a10,
    0 6px 0 rgba(0,0,0,0.25),
    0 10px 14px rgba(0,0,0,0.25);
  letter-spacing: 0.02em;
  animation: title-float 2.6s ease-in-out infinite;
}
.game-title-sm { font-size: clamp(1.6rem, 6vw, 2.1rem); }

@keyframes title-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-1deg); }
}

.title-emoji {
  display: inline-block;
  margin-right: 0.3rem;
  animation: title-emoji-bounce 1.1s ease-in-out infinite;
}
@keyframes title-emoji-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(-12deg); }
}

.overlay .subtitle {
  width: 100%;
  font-size: clamp(1rem, 3.2vw, 1.3rem);
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-top: -0.4rem;
}

.rules-text {
  font-size: 0.88rem;
  line-height: 1.6;
  max-width: 320px;
  color: var(--text);
  opacity: 0.85;
}

.final-score {
  font-size: 1.6rem !important;
  color: var(--text);
}
.final-score span { color: var(--accent); }

.rank-title {
  font-size: 1.1rem !important;
  font-weight: 700;
  color: var(--text);
}

.new-best-label {
  color: #c9601f;
  min-height: 1.4em;
  font-weight: 700;
}

/* ── 스코어 기록 폼 ── */
.record-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 320px;
}

.record-name-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  padding: 0.55rem 0.8rem;
  border: 3px solid var(--ui-border);
  border-radius: 999px;
  outline: none;
}
.record-name-input:focus { border-color: var(--accent); }

.btn-record {
  font-family: var(--font-display);
  font-size: 0.95rem;
  padding: 0.55rem 1.1rem;
  border: 3px solid var(--ui-border);
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn-record:disabled { opacity: 0.6; cursor: not-allowed; }

.record-alert {
  font-size: 0.9rem;
  color: #c9601f;
  min-height: 1.3em;
  font-weight: 700;
}

/* ── 랭킹 리스트 ── */
.leaderboard-box {
  width: 100%;
  max-width: 320px;
  background: rgba(255,255,255,0.55);
  border: 2px solid rgba(74, 42, 16, 0.18);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
}

.leaderboard-title {
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
  color: #c9601f;
  font-weight: 700;
}

.leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 140px;
  overflow-y: auto;
  counter-reset: rank;
}

.leaderboard-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.15rem 0;
  color: var(--text);
}
.leaderboard-list li::before {
  content: counter(rank) '.';
  color: #c9601f;
  flex-shrink: 0;
  width: 1.4em;
  text-align: right;
}
.leaderboard-list li:nth-child(1)::before { content: '🥇'; }
.leaderboard-list li:nth-child(2)::before { content: '🥈'; }
.leaderboard-list li:nth-child(3)::before { content: '🥉'; }
.leaderboard-list li:nth-child(1) .lb-score { color: #c9601f; font-size: 0.95rem; }
.leaderboard-list .lb-name {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leaderboard-list .lb-score {
  flex-shrink: 0;
  color: #c9601f;
  font-weight: 700;
}
.leaderboard-empty {
  font-size: 0.85rem;
  opacity: 0.6;
  list-style: none;
  color: var(--text);
}

.btn-play {
  font-family: var(--font-display);
  font-size: 1.3rem;
  padding: 0.75rem 2.6rem;
  border: 3px solid var(--ui-border);
  border-radius: 999px;
  background: linear-gradient(180deg, #ffb066, var(--accent));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 #c9601f, 0 8px 16px rgba(201,96,31,0.35);
  transition: transform 0.1s, box-shadow 0.1s;
  animation: play-btn-pulse 1.4s ease-in-out infinite;
  position: relative;
}
.btn-play:hover { filter: brightness(1.06); }
.btn-play:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c9601f;
  animation: none;
}
@keyframes play-btn-pulse {
  0%, 100% { box-shadow: 0 5px 0 #c9601f, 0 8px 16px rgba(201,96,31,0.35); }
  50% { box-shadow: 0 5px 0 #c9601f, 0 8px 24px rgba(255,176,102,0.7); }
}

.hidden { display: none !important; }

.footer-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text);
  opacity: 0.75;
}

@media (max-width: 480px) {
  .hud { font-size: 0.9rem; padding: 0.5rem 0.7rem; gap: 0.6rem; }
  .hud-item { font-size: 0.95rem; }
  .anger-wrap { min-width: 100%; order: 5; }
  .rules-text { font-size: 0.82rem; }
  .menu-panel { padding: 1.3rem 1.1rem 1.2rem; }
}
