/* ================= PRELOADER (index page only) ================= */

.preloader {
  position: fixed;
  inset: 0;
  background: #0a0e2a;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease;
}

.preloader.done {
  opacity: 0;
  pointer-events: none;
}

.preloader-meteor {
  width: 100px;
  height: 100px;
  object-fit: contain;
  animation: meteor-spin 1.5s linear infinite;
}

@keyframes meteor-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ================= BASE ================= */

body {
  margin: 0;
  height: 200vh;
  font-family: Arial, sans-serif;
  background-color: #000;
  background-image: url("image/background2.jpg");
  background-repeat: no-repeat;
  background-position: center top;
  background-size: cover;
  --scroll-position: 0;
  overflow-x: hidden;
}

/* .bg-image is mobile-only — hidden on desktop where body bg handles it */
.bg-image {
  display: none;
}

/* Image protection — no long-press save on iOS, no drag, no select */
img {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  user-drag: none;
}

.toggle-button {
  position: fixed;
  top: 20px;
  right: 2%;
  width: 150px;
  height: 150px;
  cursor: pointer;
  z-index: 11;
}

.toggle-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.3s;
}

#menu-toggle {
  display: none;
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  z-index: 9;
  pointer-events: none;
  transition: background-color 0.5s ease;
}

#menu-toggle:checked ~ .overlay {
  background-color: rgba(0, 0, 0, 0.5);
  pointer-events: all;
}

.menu-item {
  position: fixed;
  transform: scale(0);
  opacity: 0;
  transition:
    transform 0.5s ease,
    opacity 0.5s ease;
  z-index: 10;
}

.menu-item img {
  width: 380px;
  height: 380px;
  cursor: pointer;
  transition: transform 0.3s;
}

#home {
  top: 50vh;
  left: 40vw;
}
#about {
  top: 30vh;
  left: 15vw;
}
#portfolio {
  top: 5vh;
  left: 35vw;
}
#contact {
  top: 20vh;
  left: 55vw;
}

#menu-toggle:checked ~ .menu-item {
  opacity: 1;
  transform: scale(1);
}

/* ================= DESKTOP HILLS — slide-out parallax ================= */

.land {
  position: fixed;
  top: 55%;
  left: -8%;
  width: 70%;
  height: 70%;
  background: url(image/hills.png) no-repeat center center;
  background-size: cover;
  z-index: -1;
  transition: transform 0.7s;
  transform: translate3d(calc(var(--scroll-position) * -300%), 0, 0);
  will-change: transform;
}

.hill2 {
  position: fixed;
  top: 48%;
  left: 39%;
  width: 80%;
  height: 100%;
  background: url(image/hills2.png) no-repeat center center;
  background-size: cover;
  z-index: -2;
  transition: transform 0.7s;
  transform: translate3d(calc(var(--scroll-position) * 300%), 0, 0);
  will-change: transform;
}

/* Repurposed as the UFO abduction flash overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0);
  pointer-events: none;
  z-index: 999;
  opacity: 0;
}

.moon {
  position: fixed;
  top: 15%;
  left: 23%;
  width: 35%;
  height: 35%;
  background: url("image/moon.png") no-repeat center center;
  background-size: contain;
  z-index: 5;
  opacity: 1;
  transition:
    opacity 0.7s,
    transform 0.7s ease-in-out;
  cursor: pointer;
}

/* Mobile-only fields — hidden on desktop */
.big-field,
.field-left,
.field-right {
  display: none;
}

#volumeButton {
  position: fixed;
  bottom: 30px;
  left: 30px;
  width: 100px;
  height: auto;
  cursor: pointer;
  z-index: 100;
  transition: transform 0.3s;
}

/* ================= CLICKABLE UFO TRIGGER ================= */

.ufo-trigger {
  position: absolute;
  bottom: -70%;
  left: 25%;
  transform: translateX(-50%);
  width: 180px;
  height: auto;
  cursor: pointer;
  z-index: 5;
  transition:
    opacity 1s ease,
    transform 0.3s ease;
}

.ufo-trigger.fading {
  opacity: 0 !important;
  pointer-events: none;
}

/* ================= UFO ABDUCTION (desktop + mobile) ================= */

.ufo {
  display: block;
  position: fixed;
  top: -30vh;
  left: 50%;
  transform: translateX(-50%);
  width: 30vw;
  max-width: 350px;
  z-index: 200;
  pointer-events: none;
}

.ufo-beam {
  display: block;
  position: fixed;
  top: 24vh;
  left: 50%;
  transform: translateX(-50%);
  width: 270vw;
  height: 100vh;
  clip-path: polygon(49% 0%, 51% 0%, 51% 100%, 49% 100%);
  background-color: rgba(136, 199, 107, 1);
  z-index: 199;
  pointer-events: none;
  opacity: 0;
  filter: blur(2px);
}

body.ufo-launch {
  overflow: hidden;
}

body.ufo-launch .toggle-button,
body.ufo-launch #volumeButton,
body.ufo-launch .menu-item,
body.ufo-launch .ufo-trigger {
  pointer-events: none;
}

body.ufo-launch .ufo {
  animation: ufo-descend 1.5s ease-out forwards;
}

body.ufo-launch .ufo-beam {
  animation: beam-cover 4s ease-in 1.5s forwards;
}

body.ufo-launch .moon {
  opacity: 0;
  pointer-events: none;
}

body.ufo-launch::after {
  background-color: rgba(136, 199, 107, 1);
  animation: flash-fadein 1.5s ease-in 4s forwards;
}

/* ================= HOVER (desktop / mouse-only) ================= */

@media (hover: hover) {
  .toggle-button img:hover {
    transform: rotate(40deg) scale(1.2);
  }
  .menu-item img:hover {
    transform: rotate(10deg) scale(1.1);
  }
  .moon:hover {
    transform: rotate(360deg);
    transition: transform 0.7s ease-in-out;
  }
  #volumeButton:hover {
    transform: rotate(20deg) scale(1.2);
  }
  .ufo-trigger:hover {
    transform: translateX(-50%) scale(1.1);
  }
}

/* ================= TOUCH (no hover) — persistent state-driven rotation ================= */

@media (hover: none) {
  #menu-toggle:checked ~ .toggle-button img {
    transform: rotate(40deg) scale(1.2);
  }
  #volumeButton.clicked {
    transform: rotate(20deg) scale(1.2);
  }
}

/* ================= MOBILE ================= */

@media (max-width: 768px) {
  body {
    background-color: #000;
    background-image: none; /* remove body bg on mobile, .bg-image takes over */
    height: 200vh;
  }

  /* .bg-image becomes visible on mobile — fixed to viewport to avoid iOS upscale bug */
  .bg-image {
    display: block;
    position: fixed;
    inset: 0;
    background-image: url("image/homepage-bg-mobile2.png");
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    z-index: -10;
    pointer-events: none;
  }

  .land,
  .hill2 {
    display: none;
  }

  /* Moon — fixed title at top */
  .moon {
    position: fixed;
    top: 5%;
    left: 5%;
    width: 90%;
    height: 25%;
    background-image: url("image/hallofries-moon.png");
    pointer-events: none;
    cursor: default;
    transition: opacity 0.8s ease;
  }
  .moon:hover {
    transform: none;
  }

  /* UFO and beam — sized for mobile */
  .ufo {
    width: 45vw;
    max-width: 250px;
  }

  .ufo-beam {
    top: 18vh;
  }

  /* Clickable UFO trigger — fixed to viewport, hidden until scrolled to bottom */
  .ufo-trigger {
    position: fixed;
    bottom: 16%;
    left: 26%;
    width: 20vw;
    max-width: 200px;
    opacity: 0;
    pointer-events: none;
  }

  .ufo-trigger.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile fields — translate3d + will-change + shorter transition for smoother mobile perf */
  .big-field {
    display: block;
    position: fixed;
    top: -59%;
    left: -156%;
    width: 290%;
    height: 290%;
    background: url("image/big-field.png") no-repeat center;
    background-size: contain;
    z-index: 1;
    transition: transform 0.3s ease-out;
    transform: translate3d(calc(var(--scroll-position) * -300%), 0, 0);
    will-change: transform;
  }

  .field-right {
    display: block;
    position: fixed;
    top: -24%;
    right: -80%;
    width: 150%;
    height: 150%;
    background: url("image/field-right.png") no-repeat right center;
    background-size: contain;
    z-index: 2;
    transition: transform 0.3s ease-out;
    transform: translate3d(calc(var(--scroll-position) * 300%), 0, 0);
    will-change: transform;
  }

  .field-left {
    display: block;
    position: fixed;
    top: -15%;
    left: -73%;
    width: 150%;
    height: 150%;
    background: url("image/field-left.png") no-repeat left center;
    background-size: contain;
    z-index: 3;
    transition: transform 0.3s ease-out;
    transform: translate3d(calc(var(--scroll-position) * -300%), 0, 0);
    will-change: transform;
  }

  /* Menu — matched to your other mobile pages */
  .toggle-button {
    top: 3%;
    right: 4%;
    width: 20vw;
    height: 20vw;
    max-width: 120px;
    max-height: 120px;
    min-width: 70px;
    min-height: 70px;
  }

  .menu-item img {
    width: 53vw;
    aspect-ratio: 9 / 10;
    height: auto;
    max-width: 380px;
    max-height: 422px;
  }

  #portfolio {
    top: 11vh;
    left: 40vw;
  }
  #about {
    top: 26vh;
    left: 4vw;
  }
  #contact {
    top: 35vh;
    left: 43vw;
  }
  #home {
    top: 53vh;
    left: 22vw;
  }

  /* Volume button — bottom-left, shrunk for mobile */
  #volumeButton {
    top: auto;
    bottom: 4%;
    left: 4%;
    width: 50px;
  }
}

/* ================= UFO ANIMATION KEYFRAMES ================= */

@keyframes ufo-descend {
  0% {
    top: -30vh;
  }
  100% {
    top: 8vh;
  }
}

@keyframes beam-cover {
  0% {
    opacity: 0;
    clip-path: polygon(49% 0%, 51% 0%, 51% 100%, 49% 100%);
  }
  10% {
    opacity: 1;
    clip-path: polygon(49% 0%, 51% 0%, 53% 100%, 47% 100%);
  }
  100% {
    opacity: 1;
    clip-path: polygon(49% 0%, 51% 0%, 100% 100%, 0% 100%);
  }
}

@keyframes flash-fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
