/* ==========================================================================
   Grand Finale Section & Fireworks Animation (css/finale.css)
   ========================================================================== */

/* Grand Ending Section Base Layout & Background Guarantee */
body.is-ending-mode .scenery-bg {
  background-image: url('../assets/ending_bg_sp.jpg') !important;
}

@media (min-width: 769px) {
  body.is-ending-mode .scenery-bg {
    background-image: url('../assets/ending_bg.png') !important;
  }
}

/* Force show ending section in ending mode */
body.is-ending-mode .ending-section,
body.is-ending-mode #ending {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Force hide non-ending components in ending mode */
body.is-ending-mode .attraction-selector,
body.is-ending-mode .countdown-widget,
body.is-ending-mode .site-footer,
body.is-ending-mode .gate-texts,
body.is-ending-mode .balloons-overlay,
body.is-ending-mode .balloon {
  display: none !important;
}

.ending-section {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding-top: max(75px, 14vh);
  box-sizing: border-box;
  overflow: visible;
  z-index: 100;
  pointer-events: none;
}

.ending-section.active {
  display: flex;
  pointer-events: auto;
}

.ending-container {
  position: relative;
  z-index: 20;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  text-align: center;
}

.ending-content {
  position: relative;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: endingContentFade 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes endingContentFade {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Soft Yellow Title & Simple White Subtext */
.ending-main-title {
  font-family: var(--font-eng);
  font-size: clamp(30px, 6.5vw, 50px);
  font-weight: 900;
  background: linear-gradient(180deg, #ffffff 0%, #fef9c3 35%, #fde047 70%, #eab308 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 18px rgba(254, 240, 138, 0.5));
  margin: 0 0 10px 0;
  letter-spacing: 1.8px;
  line-height: 1.15;
}

.ending-main-title .title-line {
  display: inline-block;
}

.ending-sub-text {
  font-family: var(--font-jap);
  font-size: clamp(13px, 2.8vw, 17px);
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 1.2px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65), 0 0 12px rgba(255, 255, 255, 0.4);
  margin: 6px 0 0 0;
  white-space: nowrap;
}

/* Fireworks Engine Container & Particles */
.fireworks-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.firework-rocket {
  position: absolute;
  width: 3px;
  height: 14px;
  background: linear-gradient(to top, rgba(255, 255, 255, 0), #fffdf0);
  border-radius: 2px;
  box-shadow: 0 0 8px #fde047;
  animation: launchRocket 0.8s ease-out forwards;
}

@keyframes launchRocket {
  0% {
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateY(-160px);
  }
}

.spark-particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  animation: explodeSpark 1.4s ease-out forwards;
}

@keyframes explodeSpark {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }

  80% {
    opacity: 0.9;
  }

  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
  }
}

.spark-particle.willow {
  animation: explodeWillow 2.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes explodeWillow {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }

  60% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(var(--dx), calc(var(--dy) + 90px)) scale(0.1);
  }
}

/* Gate Overlays Hiding & Crown Chibi Scaling */
.illustration-area.is-ending .gate-texts,
.illustration-area.is-ending .balloons-overlay,
.illustration-area.is-ending .balloon {
  display: none !important;
}

/* Parade Trolley Animation (Right to Left Seamless Loop with Minimal Delay) */
@keyframes paradeMoveSP {
  0% {
    transform: translate3d(100vw, 0, 0);
  }
  100% {
    transform: translate3d(-230px, 0, 0);
  }
}

@keyframes paradeMovePC {
  0% {
    transform: translate3d(100vw, 0, 0);
  }
  100% {
    transform: translate3d(-350px, 0, 0);
  }
}

@keyframes paradeBobbing {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-6px) rotate(-1.5deg);
  }
  50% {
    transform: translateY(0) rotate(0deg);
  }
  75% {
    transform: translateY(-6px) rotate(1.5deg);
  }
}

body.is-ending-mode .character-bubble {
  display: none !important;
}

body.is-ending-mode .character-wrapper,
body.is-ending-mode .character-wrapper.is-ending-char,
body.is-ending-mode .character-wrapper.fade-in-up,
body.is-ending-mode .character-wrapper.fade-in-up.animate {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
  position: fixed !important;
  left: 0 !important;
  right: auto !important;
  top: auto !important;
  bottom: 12% !important;
  width: 320px;
  z-index: 120 !important;
  pointer-events: none !important;
  animation: paradeMovePC 28s linear infinite !important;
  will-change: transform;
}

body.is-ending-mode .character-wrapper .chibi-character {
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
  width: 100% !important;
  height: auto !important;
  animation: paradeBobbing 2.2s ease-in-out infinite !important;
}

/* --- Night Parade Magic Ribbon & Star Trail SVG Effect --- */
.parade-trail-svg-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 119;
  overflow: visible;
  transition: opacity 2.8s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: opacity;
}

.parade-trail-svg-container.is-fading-out {
  opacity: 0 !important;
}

/* Primary Wavy Light Stroke */
.trail-path-primary {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.62;
  filter: drop-shadow(0 0 6px rgba(253, 224, 71, 0.7)) drop-shadow(0 0 12px rgba(234, 179, 8, 0.4));
}

/* Secondary Offset Light Ribbon */
.trail-path-secondary {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.45;
  filter: drop-shadow(0 0 5px rgba(125, 211, 252, 0.6)) drop-shadow(0 0 10px rgba(253, 224, 71, 0.3));
}

/* Stars along the magic curve line */
.parade-line-star {
  position: fixed;
  pointer-events: none;
  z-index: 120;
  transform: translate(-50%, -50%);
  font-size: var(--star-size, 18px);
  color: var(--star-color, #fde047);
  text-shadow: 0 0 8px var(--star-glow, rgba(253, 224, 71, 0.9)), 0 0 16px rgba(253, 224, 71, 0.5);
  line-height: 1;
  animation: lineStarTwinkle 2.4s ease-in-out infinite;
  will-change: transform, opacity;
  transition: opacity 2.8s cubic-bezier(0.25, 1, 0.5, 1);
}

.parade-line-star.is-fading-out {
  opacity: 0 !important;
}

/* Tiny stardust light dots between stars */
.parade-line-dust {
  position: fixed;
  pointer-events: none;
  z-index: 120;
  transform: translate(-50%, -50%);
  width: var(--dust-size, 4px);
  height: var(--dust-size, 4px);
  border-radius: 50%;
  background: var(--dust-color, #fde047);
  box-shadow: 0 0 8px var(--dust-glow, rgba(253, 224, 71, 0.9)), 0 0 12px var(--dust-color, #fde047);
  animation: lineDustPulse 2.0s ease-in-out infinite;
  will-change: transform, opacity;
  transition: opacity 2.8s cubic-bezier(0.25, 1, 0.5, 1);
}

.parade-line-dust.is-fading-out {
  opacity: 0 !important;
}

@keyframes lineStarTwinkle {
  0%, 100% {
    opacity: 0.75;
    transform: translate(-50%, -50%) scale(0.85) rotate(0deg);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.18) rotate(12deg);
  }
}

@keyframes lineDustPulse {
  0%, 100% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(0.8);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.25);
  }
}

/* ==========================================================================
   Responsive Media Queries
   ========================================================================== */
@media (max-width: 768px) {
  .ending-main-title .title-line {
    display: block;
  }

  .ending-main-title {
    font-size: clamp(32px, 8.8vw, 42px);
    line-height: 1.12;
    margin-bottom: 8px;
  }

  .ending-sub-text {
    font-size: 13px;
    letter-spacing: 0.8px;
  }

  body.is-ending-mode .character-wrapper,
  body.is-ending-mode .character-wrapper.is-ending-char,
  body.is-ending-mode .character-wrapper.fade-in-up,
  body.is-ending-mode .character-wrapper.fade-in-up.animate {
    width: 220px !important;
    bottom: 15% !important;
    animation: paradeMoveSP 22s linear infinite !important;
  }
}

@media (min-width: 769px) {
  body.is-ending-mode .character-wrapper,
  body.is-ending-mode .character-wrapper.is-ending-char,
  body.is-ending-mode .character-wrapper.fade-in-up,
  body.is-ending-mode .character-wrapper.fade-in-up.animate {
    width: 340px !important;
    bottom: 12% !important;
    animation: paradeMovePC 28s linear infinite !important;
  }
}

/* Special VIP Passport Button & Modal Styling */
.passport-trigger-wrapper {
  position: fixed !important;
  bottom: max(20px, 3.5vh) !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 2500 !important;
  width: 100%;
  max-width: 340px;
  text-align: center;
  pointer-events: auto;
  display: none;
}

.ending-section.active .passport-trigger-wrapper,
#ending.active .passport-trigger-wrapper,
body.is-ending-mode .passport-trigger-wrapper {
  display: block !important;
}

.passport-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #fef08a 50%, #fde047 100%);
  border: 2.5px solid #ffffff;
  border-radius: 30px;
  padding: 12px 28px;
  font-family: var(--font-jap);
  font-size: 14px;
  font-weight: 800;
  color: #854d0e;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(234, 179, 8, 0.45), inset 0 2px 0 #ffffff;
  animation: passportGlowPulse 2.4s infinite ease-in-out;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes passportGlowPulse {

  0%,
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 6px 20px rgba(234, 179, 8, 0.4), inset 0 2px 0 #ffffff;
  }

  50% {
    transform: translateY(-5px) scale(1.04);
    box-shadow: 0 12px 30px rgba(254, 240, 138, 0.8), 0 0 20px rgba(254, 240, 138, 0.6), inset 0 2px 0 #ffffff;
  }
}

.passport-btn:hover,
.passport-btn:active {
  transform: scale(1.08) translateY(-4px) !important;
  box-shadow: 0 14px 32px rgba(234, 179, 8, 0.7), inset 0 2px 0 #ffffff !important;
}

.passport-btn-sparkle {
  color: #eab308;
  font-size: 12px;
  animation: pulseSparkle 1.8s infinite ease-in-out;
}

@keyframes pulseSparkle {

  0%,
  100% {
    opacity: 0.4;
    transform: scale(0.9);
  }

  50% {
    opacity: 1;
    transform: scale(1.3);
  }
}

/* Passport Modal Overlay */
.passport-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.passport-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.passport-modal-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(8px);
}

.passport-card-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: scale(0.85) rotateY(15deg);
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.passport-modal.is-open .passport-card-container {
  transform: scale(1) rotateY(0deg);
}

.passport-modal-close {
  position: absolute;
  top: -12px;
  right: -8px;
  background: #ffffff;
  border: 2px solid #eab308;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 20px;
  color: #854d0e;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

/* Gold Acrylic Passport Card */
.passport-card {
  width: 100%;
  background: linear-gradient(145deg, #fffef0 0%, #fef9c3 40%, #fef08a 80%, #fde047 100%);
  border: 3px solid #eab308;
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), inset 0 2px 4px #ffffff, 0 0 25px rgba(254, 240, 138, 0.5);
  box-sizing: border-box;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.passport-card::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent 45%, rgba(255, 255, 255, 0.35) 50%, transparent 55%);
  transform: rotate(25deg);
  pointer-events: none;
  animation: shineGlass 4s infinite linear;
}

@keyframes shineGlass {
  0% {
    transform: translateY(-100%) rotate(25deg);
  }

  100% {
    transform: translateY(100%) rotate(25deg);
  }
}

.passport-badge {
  display: inline-block;
  background: #78350f;
  color: #fde68a;
  font-family: var(--font-eng);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 3px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
}

.passport-park-name {
  font-family: var(--font-eng);
  font-size: 14px;
  font-weight: 900;
  color: #78350f;
  margin: 0 0 2px 0;
  letter-spacing: 0.8px;
}

.passport-pass-type {
  font-family: var(--font-eng);
  font-size: 11px;
  font-weight: 800;
  color: #b45309;
  letter-spacing: 1.5px;
  margin: 0 0 16px 0;
}

/* --- Passport Stamps & Seal Stagger Animation (Pop-in Sequenced) --- */
@keyframes stampPopIn {
  0% {
    opacity: 0;
    transform: scale(0.3) translateY(15px);
  }
  70% {
    opacity: 1;
    transform: scale(1.18) translateY(-2px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes sealCompletePop {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-6deg);
    box-shadow: 0 0 0 rgba(217, 119, 6, 0);
  }
  65% {
    opacity: 1;
    transform: scale(1.22) rotate(3deg);
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.7);
  }
  85% {
    transform: scale(0.95) rotate(-1deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    box-shadow: 0 4px 14px rgba(217, 119, 6, 0.25);
  }
}

.passport-stamps-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.passport-stamp-item {
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #d97706;
  border-radius: 8px;
  padding: 5px 4px;
  font-family: var(--font-eng);
  font-size: 10.5px;
  font-weight: 700;
  color: #78350f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  opacity: 0;
  transform: scale(0.4);
  will-change: transform, opacity;
}

.passport-modal.is-open .passport-stamp-item {
  animation: stampPopIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Stagger delay for 8 stamp items (Profile -> Countdown -> Cheer Ad -> History -> Theater -> Coffee Cup -> Share -> Finale) */
.passport-modal.is-open .passport-stamp-item:nth-child(1) { animation-delay: 0.30s; }
.passport-modal.is-open .passport-stamp-item:nth-child(2) { animation-delay: 0.45s; }
.passport-modal.is-open .passport-stamp-item:nth-child(3) { animation-delay: 0.60s; }
.passport-modal.is-open .passport-stamp-item:nth-child(4) { animation-delay: 0.75s; }
.passport-modal.is-open .passport-stamp-item:nth-child(5) { animation-delay: 0.90s; }
.passport-modal.is-open .passport-stamp-item:nth-child(6) { animation-delay: 1.05s; }
.passport-modal.is-open .passport-stamp-item:nth-child(7) { animation-delay: 1.20s; }
.passport-modal.is-open .passport-stamp-item:nth-child(8) { animation-delay: 1.35s; }

.passport-stamp-item:last-child {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-color: #f59e0b;
  color: #92400e;
  font-weight: 800;
}

.passport-seal-complete {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 2px dashed #d97706;
  border-radius: 20px;
  padding: 6px 18px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(217, 119, 6, 0.2);
  opacity: 0;
  transform: scale(0.4);
  will-change: transform, opacity;
}

.passport-modal.is-open .passport-seal-complete {
  animation: sealCompletePop 0.65s cubic-bezier(0.34, 1.56, 0.64, 1) 1.60s forwards;
}

.passport-seal-star {
  font-size: 18px;
}

.passport-seal-text {
  font-family: var(--font-eng);
  font-size: 13px;
  font-weight: 900;
  color: #b45309;
  letter-spacing: 1px;
}

.passport-card-footer {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(180, 83, 9, 0.3);
  padding-top: 12px;
  font-family: var(--font-eng);
  font-size: 11px;
}

.passport-info {
  display: flex;
  gap: 4px;
}

.passport-info-label {
  color: #92400e;
  font-weight: 700;
}

.passport-info-val {
  color: #78350f;
  font-weight: 900;
}

.passport-gift-btn {
  margin-top: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #ffffff 0%, #fef08a 50%, #fde047 100%);
  border: 2.5px solid #ffffff;
  border-radius: 25px;
  padding: 11px 24px;
  font-family: var(--font-jap);
  font-size: 13.5px;
  font-weight: 800;
  color: #854d0e;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(234, 179, 8, 0.45), inset 0 2px 0 #ffffff;
  animation: passportGlowPulse 2.4s infinite ease-in-out;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.passport-gift-btn:hover,
.passport-gift-btn:active {
  transform: scale(1.08) translateY(-4px) !important;
  box-shadow: 0 14px 32px rgba(234, 179, 8, 0.7), inset 0 2px 0 #ffffff !important;
}

.passport-close-btn {
  margin-top: 16px;
  background: #ffffff;
  color: #78350f;
  border: 2px solid #ffffff;
  border-radius: 20px;
  padding: 8px 24px;
  font-family: var(--font-jap);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   MEDIA QUERIES (Grouped at Bottom per AGENTS.md rules)
   ========================================================================== */
@media (max-width: 480px) {
  .passport-stamps-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .passport-stamp-item {
    font-size: 10px;
    padding: 5px 2px;
  }
}