/* 滾動滑入動畫 */
.fade-in {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.fade-in.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* 回到頂部按鈕 */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background-color: var(--accent-color);
  color: #fff;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
  will-change: transform, opacity;
  box-shadow: 0 4px 15px rgba(104, 170, 198, 0.4);
  z-index: 1000;
}

.back-to-top.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  background-color: var(--heading-color);
  transform: translateY(-5px);
  box-shadow: 0 6px 20px rgba(55, 70, 76, 0.3);
}

@media screen and (max-width: 768px) {
  .back-to-top { bottom: 20px; right: 20px; width: 40px; height: 40px; }
}

/* 粒子特效 */
#bubble-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

main.container, main.hero-rpg {
  position: relative;
  z-index: 1; 
}

.particle {
  position: absolute;
  bottom: -50px;
  border-radius: 50%;
  background-color: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
  animation: cinematicDrift linear infinite;
  will-change: transform, opacity;
}

@keyframes cinematicDrift {
  0% { transform: translateY(0) translateX(0) scale(1); opacity: 0; }
  20% { opacity: var(--max-opacity); }
  80% { opacity: var(--max-opacity); }
  100% { transform: translateY(-110vh) translateX(var(--drift-x)) scale(var(--end-scale)); opacity: 0; }
}

/* 正弦波頁面過場 */
html::before, body::before, body::after {
  content: '';
  position: fixed;
  left: 0;
  width: 120vw;
  height: 150vh;
  pointer-events: none;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  will-change: transform;
  transform: translateY(-150vh) translateX(-10vw);
}

html::before {
  background-color:#abc4d0a4; 
  z-index: 9997;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,15 Q25,25 50,15 T100,15 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,15 Q25,25 50,15 T100,15 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
}

body::before {
  background-color:#688695d1; 
  z-index: 9998;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,15 Q25,5 50,15 T100,15 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,15 Q25,5 50,15 T100,15 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
}

body::after {
  background-color:#1d2b36;
  z-index: 9999;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,20 Q25,30 50,20 T100,20 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' preserveAspectRatio='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,20 Q25,30 50,20 T100,20 L100,100 L0,100 Z' fill='black'/%3E%3C/svg%3E");
}

html::before { animation: waveSlideReveal 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0.2s; }
body::before { animation: waveSlideReveal 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0.1s; }
body::after  { animation: waveSlideReveal 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0s; }

@keyframes waveSlideReveal {
  0% { transform: translateY(-40vh) translateX(-10vw); }
  100% { transform: translateY(-150vh) translateX(-5vw); }
}

html.is-leaving { overflow: hidden; }
html.is-leaving::before { animation: waveSlideCover 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0s; }
html.is-leaving body::before { animation: waveSlideCover 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0.1s; }
html.is-leaving body::after  { animation: waveSlideCover 1.2s cubic-bezier(0.64, 0.04, 0.35, 1) forwards; animation-delay: 0.2s; }

@keyframes waveSlideCover {
  0% { transform: translateY(100vh) translateX(-5vw); }
  100% { transform: translateY(-40vh) translateX(-10vw); }
}

@media screen and (max-width: 768px) {
  html::before, body::before, body::after {
    transform: translateY(-150vh) translateX(-10vw) scaleX(3);
    transform-origin: center top;
  }
}