/* Minigame HUD */
.minigame-hud {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: 1000;
}

.minigame-stat {
  font-family: "VT323", monospace;
  font-size: 2rem;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  margin: 5px 0;
  background: rgba(0, 0, 0, 0.5);
  padding: 5px 15px;
  border-radius: 4px;
  border: 2px solid #fff;
}

.minigame-message {
  font-family: "VT323", monospace;
  font-size: 4rem;
  color: #ffcc00;
  text-shadow: 4px 4px 0 #000;
  margin: 20px 0;
  animation: pulse 0.5s infinite alternate;
  background: rgba(0, 0, 0, 0.7);
  padding: 10px 30px;
  border-radius: 8px;
  border: 4px solid #fff;
  text-align: center;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.1);
  }
}

/* Elements with their own fade rules stay rendered so opacity can transition;
   everything else is simply removed. */
.hidden:not(.modal):not(#loading-screen):not(#splash-screen):not(#opening-story):not(.gesture-info) {
  display: none !important;
}

/* Hidden faders: invisible and non-interactive once their fade-out ends. */
.modal.hidden,
#loading-screen.hidden,
#splash-screen.hidden,
#opening-story.hidden,
.gesture-info.hidden {
  visibility: hidden;
  pointer-events: none;
  transition-property: opacity, transform, visibility;
}

/* Hidden faders stay rendered: stop their infinite animations (spinner, glitch, pulse). */
.modal.hidden *,
#loading-screen.hidden * {
  animation-play-state: paused;
}

/* Exit Minigame Button */
.exit-minigame-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  font-family: "VT323", monospace;
  font-size: 1.2rem;
  padding: 8px 16px;
  background: rgba(231, 76, 60, 0.9);
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  z-index: 1500;
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  transition: all 0.2s;
  pointer-events: auto;
}

.exit-minigame-btn.hidden {
  display: none !important;
  pointer-events: none;
}

.exit-minigame-btn:hover {
  background: rgba(192, 57, 43, 1);
  transform: scale(1.05);
}

.exit-minigame-btn:active {
  transform: scale(0.95);
}

/* Minigame Start Modal */
.minigame-start-content {
  max-width: 450px;
}

.minigame-icon {
  font-size: 4rem;
  text-align: center;
  margin-bottom: 15px;
  animation: bounceVertical 1s infinite;
}

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

.minigame-rules {
  background: rgba(0, 0, 0, 0.3);
  padding: 15px;
  border-radius: 8px;
  margin-top: 10px;
}

.minigame-rules h4 {
  margin: 0 0 10px 0;
  color: #ffcc00;
}

.minigame-rules ul {
  margin: 0;
  padding-left: 20px;
}

.minigame-rules li {
  margin-bottom: 8px;
  line-height: 1.4;
}

/* NPC Badge */
.npc-badge {
  position: absolute;
  font-size: 1.5rem;
  text-align: center;
  animation: float 2s ease-in-out infinite;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

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

/* Minigame Intro Overlay */
.minigame-intro {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.minigame-intro-content {
  max-width: 600px;
  padding: 40px;
  text-align: center;
}

/* Fade Transition Overlay */
.fade-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 3000;
  transition: opacity 1s ease-in-out;
}

.intro-line {
  font-family: "VT323", monospace;
  font-size: 1.8rem;
  color: #fff;
  margin: 15px 0;
  opacity: 0;
  transform: translateY(20px);
  animation: slideUp 0.5s ease-out forwards;
}

.intro-line:nth-child(1) {
  font-size: 2.5rem;
  color: #ffcc00;
  text-shadow: 3px 3px 0 #000;
  animation-delay: 0.2s;
}

.intro-line:nth-child(2) {
  font-style: italic;
  color: #aaa;
  animation-delay: 0.6s;
}

.intro-line:nth-child(3) {
  animation-delay: 1s;
}

.intro-line:nth-child(4) {
  color: #ff6b6b;
  font-weight: bold;
  animation-delay: 1.4s;
}

@keyframes slideUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Minigame result card (P6): this run's time, the course record and the two buttons. */
.result-line {
  font-size: 1.1rem;
  margin: 0 0 6px;
}

.result-line.is-new {
  color: #ffe135; /* the VICTORY gold */
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

/* Landscape phones (85vh is ~319 px at 667x375): the trophy repeats the title; dropping it
   keeps the time, the record and both buttons on screen without scrolling. */
@media (max-height: 500px) {
  #result-icon {
    display: none;
  }
}

/* P7: VICTORY confetti (js/minigames.js playConfetti). Inside #minigame-result-modal, before
   its panel: over the backdrop, behind the text, never clickable. One fall per win. */
.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -16px;
  left: var(--x);
  width: 8px;
  height: 12px;
  background: #ffe135;
  opacity: 0;
}

/* Three colours on a period of 3, so hiding every other piece keeps all three. */
.confetti i:nth-child(3n + 2) {
  background: #38b764;
}

.confetti i:nth-child(3n + 3) {
  background: #f77622;
}

.confetti.is-on i {
  animation: confetti-fall var(--t) linear var(--d) both;
}

@keyframes confetti-fall {
  from {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg);
  }
  to {
    opacity: 1;
    transform: translate(var(--dx), 110vh) rotate(540deg);
  }
}

/* Reduced motion: half the pieces (P7 row); the fall itself stays one short burst. */
@media (prefers-reduced-motion: reduce) {
  .confetti i:nth-child(even) {
    display: none;
  }
}
