/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  background: #1a0a2e;
  color: #e0d0ff;
}

/* ===== Splash screen ===== */
.splash {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #2a1a4e 0%, #0d0520 100%);
  z-index: 200;
  cursor: pointer;
  transition: opacity 0.4s ease-out;
}
.splash--hidden { opacity: 0; pointer-events: none; }
.splash__content { text-align: center; }
.splash__icon { font-size: 5rem; animation: float 2.5s ease-in-out infinite; }
.splash__title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 2.8rem;
  color: #e0d0ff;
  letter-spacing: 0.05em;
  margin-top: 0.3em;
  text-shadow: 0 0 20px rgba(160, 100, 255, 0.4);
}

/* ===== Top bar ===== */
#top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  background: rgba(10, 5, 20, 0.85);
  z-index: 50;
  font-size: 0.9rem;
}
#score-display, #wave-display { min-width: 70px; }
#score-display { font-weight: 600; }
.visitor-count { font-size: 0.75rem; opacity: 0.7; margin-left: 4px; }
#wave-display { text-align: center; opacity: 0.8; }
#sound-btn, #reset-btn {
  background: none; border: none; color: #e0d0ff;
  font-size: 1.2rem; cursor: pointer; padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
#sound-btn:hover, #reset-btn:hover { background: rgba(255,255,255,0.1); }

/* ===== House container ===== */
#house-container {
  position: fixed;
  top: 36px; bottom: 130px; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
}
#house-container svg {
  max-width: 100%; max-height: 100%;
  filter: drop-shadow(0 4px 20px rgba(80, 40, 120, 0.3));
}

/* ===== House rooms ===== */
.house__room { cursor: pointer; }
.house__room--locked rect.house__room-bg { fill: #111 !important; }
.house__room--locked .house__planks { opacity: 1; transition: opacity 0.4s; }

.house__room--targetable rect.house__room-bg {
  stroke: #ffcc00; stroke-width: 3;
  stroke-dasharray: 6 3;
  animation: room-pulse 0.8s ease-in-out infinite;
}
.house__room--flash-red rect.house__room-bg {
  stroke: #ff4444 !important; stroke-width: 3;
}

.house__room--unlocking rect.house__room-bg { transition: fill 0.6s ease-out; }
.house__room--unlocking .house__planks { opacity: 0; transition: opacity 0.4s; }

/* ===== Train & track ===== */
.train__rail { stroke-linecap: round; }
.train__cart { transition: none; }

/* ===== Visitors ===== */
.visitor {
  pointer-events: none;
}
.visitor--walking .visitor__leg-l { animation: visitor-walk-l 0.4s steps(2) infinite; }
.visitor--walking .visitor__leg-r { animation: visitor-walk-r 0.4s steps(2) infinite; }
.visitor--scared { animation: visitor-scare 0.7s ease-out; }  /* on inner wrapper, won't clobber position */
.visitor--hugging { animation: visitor-hug 1.2s ease-in-out; }
.visitor--exiting .visitor__leg-l { animation: visitor-walk-l 0.3s steps(2) infinite; }
.visitor--exiting .visitor__leg-r { animation: visitor-walk-r 0.3s steps(2) infinite; }

.visitor__bubble--fear, .visitor__bubble--love {
  pointer-events: none;
  animation: bubble-bob 2s ease-in-out infinite;
}
.visitor__bubble--love { animation-delay: 0.5s; }

/* ===== Creatures ===== */
.creature { transition: opacity 0.3s; }
.creature__pose { transition: opacity 0.3s ease-in-out; }

/* Idle animations (subtle, adds life) */
.creature--cat .creature__pose--idle { animation: none; }
/* Tail swish handled by CSS if the tail has a class, or via creature structure */
.creature--spider .creature__pose--idle { animation: spider-sway 2.5s ease-in-out infinite; transform-origin: 0 -40px; }
.creature--bat .creature__pose--idle { animation: none; }

/* ===== Monster type colour overrides ===== */
.creature--zombie { filter: sepia(0.6) hue-rotate(70deg) saturate(1.5) brightness(0.8); }
.creature--witch .monster-overlay--witch { opacity: 1; }
.creature--skeleton { filter: saturate(0.05) brightness(1.5) contrast(1.1); }
.creature--vampire { filter: brightness(0.85) saturate(0.6) hue-rotate(320deg); }
.creature--astronaut { filter: brightness(1.1) saturate(0.7); }
.creature--ghost { filter: brightness(1.4) saturate(0.3); opacity: 0.65; }
.creature--ghost .creature__inner { animation: ghost-hover 2s ease-in-out infinite; }
@keyframes ghost-hover {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ===== Action keyframes ===== */
.action--jump-out { animation: action-jump-out 0.6s ease-out; }
@keyframes action-jump-out {
  0% { opacity: 0; transform: scale(0.3); }
  60% { opacity: 1; transform: scale(1.2); }
  100% { transform: scale(1); }
}

.action--grab-hat { animation: action-grab-hat 0.8s ease-in-out; }
@keyframes action-grab-hat {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(15px) translateY(-5px); }
}

.action--drop-ceiling { animation: action-drop-ceiling 0.7s ease-in; }
@keyframes action-drop-ceiling {
  0% { transform: translateY(-80px); opacity: 0.5; }
  100% { transform: translateY(0); opacity: 1; }
}

/* ===== Scare panel ===== */
#scare-panel {
  position: fixed; bottom: 40px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 10px;
  z-index: 50;
  padding: 0 8px;
}
.scare-panel__slot {
  width: 58px; height: 68px;
  border-radius: 12px;
  background: rgba(80, 50, 110, 0.95);
  border: 2px solid #b898e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.scare-panel__slot:active { transform: scale(0.95); }
.scare-panel__slot--selected {
  border-color: #ffcc00;
  box-shadow: 0 0 12px rgba(255, 204, 0, 0.5);
}
.scare-panel__slot--cooldown {
  opacity: 0.5;
  pointer-events: none;
}
.scare-panel__cooldown {
  position: absolute; inset: 0;
  border-radius: 12px;
  background: conic-gradient(
    transparent calc(var(--cd-pct, 0) * 360deg),
    rgba(0, 0, 0, 0.6) calc(var(--cd-pct, 0) * 360deg)
  );
  pointer-events: none;
}
.scare-panel__icon {
  font-size: 2rem; line-height: 1; margin-top: 2px;
  text-shadow: 0 0 8px rgba(255,255,255,0.9), 0 0 16px rgba(255,255,255,0.5);
}
.scare-panel__label {
  font-size: 0.6rem; color: #fff;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ===== Monster type sub-panel ===== */
#monster-panel {
  position: fixed; bottom: 114px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 8px;
  z-index: 50;
  padding: 0 8px;
  animation: monster-panel-in 0.2s ease-out;
}
@keyframes monster-panel-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.monster-panel__slot {
  width: 50px; height: 56px;
  border-radius: 10px;
  background: rgba(40, 60, 80, 0.95);
  border: 2px solid #7ab8e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.monster-panel__slot:active { transform: scale(0.95); }
.monster-panel__slot--selected {
  border-color: #ffcc00;
  box-shadow: 0 0 12px rgba(255, 204, 0, 0.5);
}
.monster-panel__icon {
  font-size: 1.6rem; line-height: 1; margin-top: 2px;
}
.monster-panel__label {
  font-size: 0.5rem; color: #cde;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ===== Progress bar ===== */
#progress-bar {
  position: fixed; bottom: 12px; left: 15%; right: 15%;
  height: 18px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 9px;
  overflow: hidden;
  z-index: 50;
}
#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6a4c93, #c084fc);
  border-radius: 9px;
  transition: width 0.4s ease-out;
  width: 0%;
}
#progress-count {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.65rem; font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  pointer-events: none;
}

/* ===== Unlock preview ===== */
#unlock-preview {
  position: fixed; bottom: 12px; right: calc(15% - 50px);
  display: flex; align-items: center; gap: 4px;
  z-index: 50;
  font-size: 0.7rem;
}
.unlock-preview__icon { font-size: 1.2rem; }
.unlock-preview__bar {
  width: 40px; height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px; overflow: hidden;
}
.unlock-preview__fill {
  height: 100%;
  background: #c084fc;
  border-radius: 3px;
  transition: width 0.3s;
}
.unlock-preview__target { opacity: 0.6; }

/* ===== Overlays (fanfare, wave summary) ===== */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 150;
  background: rgba(10, 5, 20, 0.92);
  cursor: pointer;
}
.overlay--hidden { display: none; }

/* ===== Unlock fanfare ===== */
#unlock-fanfare { z-index: 180; }
.unlock-fanfare__content { text-align: center; }
.unlock-fanfare__icon {
  font-size: 4rem;
  animation: fanfare-bounce 0.6s ease-out;
}
.unlock-fanfare__label {
  font-family: Georgia, serif;
  font-size: 1.6rem;
  color: #ffd700;
  margin-top: 0.5em;
  text-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

/* ===== Wave summary ===== */
.wave-summary__content { text-align: center; }
.wave-summary__title {
  font-family: Georgia, serif;
  font-size: 1.8rem;
  color: #e0d0ff;
  margin-bottom: 0.6em;
}
.wave-summary__stat {
  font-size: 1rem;
  color: #bba8d8;
  margin: 0.3em 0;
}
.wave-summary__bonus {
  font-size: 1.2rem;
  color: #ffd700;
  font-weight: 600;
  margin-top: 0.5em;
  animation: fanfare-bounce 0.5s ease-out;
}

/* ===== Particles ===== */
.particle {
  position: fixed;
  pointer-events: none;
  font-size: 1rem;
  z-index: 200;
}
.particle--spooky { animation: particle-fly 0.7s ease-out forwards; }
.particle--heart { animation: particle-float 0.9s ease-out forwards; }
.particle--confetti { animation: particle-fly 1s ease-out forwards; font-size: 1.3rem; }
.particle--combo {
  animation: particle-float 1.2s ease-out forwards;
  font-size: 0.9rem; font-weight: bold; color: #ffcc00;
  text-shadow: 0 0 6px rgba(255, 170, 0, 0.8), 0 1px 2px rgba(0,0,0,0.6);
  white-space: nowrap;
}

/* ===== Keyframes ===== */

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes room-pulse {
  0%, 100% { stroke-opacity: 0.4; }
  50% { stroke-opacity: 1; }
}

@keyframes visitor-walk-l {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}
@keyframes visitor-walk-r {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

@keyframes visitor-scare {
  0% { transform: translateY(0) scale(1); }
  20% { transform: translateY(-20px) scale(1.15); }
  40% { transform: translateY(-5px) scale(0.95); }
  60% { transform: translateY(-12px) scale(1.05); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes visitor-hug {
  0% { transform: translate(0, 0) scale(1); }
  30% { transform: translate(12px, -4px) scale(1.15); }
  60% { transform: translate(10px, -2px) scale(1.1); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes bubble-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

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

@keyframes particle-fly {
  0% { transform: translate(0, 0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

@keyframes particle-float {
  0% { transform: translate(0, 0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)); opacity: 0; }
}

@keyframes fanfare-bounce {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .splash__icon { font-size: 3.5rem; }
  .splash__title { font-size: 2rem; }
  #house-container { top: 32px; bottom: 110px; }
  .scare-panel__slot { width: 48px; height: 58px; }
  .scare-panel__icon { font-size: 1.4rem; }
  .scare-panel__label { font-size: 0.5rem; }
  #scare-panel { bottom: 32px; gap: 6px; }
  #monster-panel { bottom: 96px; gap: 5px; }
  .monster-panel__slot { width: 42px; height: 48px; }
  .monster-panel__icon { font-size: 1.2rem; }
  #progress-bar { bottom: 8px; height: 14px; }
}

@media (max-width: 360px) {
  .scare-panel__slot { width: 42px; height: 52px; }
  .scare-panel__icon { font-size: 1.2rem; }
  .monster-panel__slot { width: 38px; height: 44px; }
  .monster-panel__icon { font-size: 1rem; }
}
