/* ============================================
   IDUL FITRI 1447 H - GREETING LETTER
   ============================================ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Caveat', cursive;
}

body {
  background: #030510;
}

/* ============================================
   THREE.JS CANVAS (global background)
   ============================================ */
#three-stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ============================================
   SHARED
   ============================================ */
.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: transparent;
}

/* ============================================
   CSS STARS (fallback layer on top of Three.js)
   ============================================ */
.env-stars,
.loading-stars,
.letter-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: twinkle var(--dur, 3s) var(--del, 0s) ease-in-out infinite alternate;
}

.star--shape {
  background: none;
}

.star--shape::before {
  content: '\2726';
  color: rgba(255, 215, 100, var(--op, 0.7));
  font-size: var(--sz, 12px);
  animation: starRotate 6s linear infinite;
}

@keyframes twinkle {
  0%   { opacity: 0.2; transform: scale(0.8); }
  100% { opacity: 1; transform: scale(1.2); }
}

@keyframes starRotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.shooting-star {
  position: absolute;
  width: 3px;
  height: 3px;
  background: #fff;
  border-radius: 50%;
  opacity: 0;
  animation: shoot 4s ease-in-out infinite;
}

.shooting-star::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 60px;
  height: 2px;
  background: linear-gradient(to right, rgba(255,255,255,0.6), transparent);
  transform: rotate(-10deg);
  transform-origin: right center;
}

@keyframes shoot {
  0%   { opacity: 0; transform: translate(0, 0); }
  5%   { opacity: 1; }
  15%  { opacity: 0; transform: translate(-300px, 150px); }
  100% { opacity: 0; }
}

/* ============================================
   SCREEN 1: ENVELOPE
   ============================================ */
#envelope-screen {
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#envelope-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#particle-canvas {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.envelope-wrapper {
  position: relative;
  z-index: 10;
  text-align: center;
  animation: gentleFloat 3s ease-in-out infinite;
}

.envelope-wrapper.exploded .envelope {
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.envelope {
  position: relative;
  width: min(55vw, 300px);
  aspect-ratio: 1.5 / 1;
  margin: 0 auto;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.envelope-body {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #f5d99a 0%, #f1cfa0 50%, #e8c674 100%);
  border-radius: 6px;
  box-shadow:
    8px 8px 0 rgba(0, 0, 0, 0.3),
    0 0 40px rgba(245, 200, 66, 0.1);
}

.envelope-flap {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 55%;
  z-index: 2;
  overflow: hidden;
}

.envelope-flap-triangle {
  width: 0;
  height: 0;
  border-left: calc(min(55vw, 300px) / 2) solid transparent;
  border-right: calc(min(55vw, 300px) / 2) solid transparent;
  border-top: calc(min(55vw, 300px) * 0.35) solid #f2a71e;
}

.envelope-stamp {
  position: absolute;
  z-index: 5;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid #93321a;
  background: radial-gradient(circle, #d34f27 0%, #93321a 100%);
  color: #f2a71e;
  cursor: pointer;
  outline: none;
  box-shadow: 2px 3px #93321a;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.envelope-stamp:hover {
  animation: hvr-buzz 0.4s linear infinite;
}

@keyframes hvr-buzz {
  50%  { transform: translateX(calc(-50% + 3px)) rotate(2deg); }
  100% { transform: translateX(calc(-50% - 3px)) rotate(-2deg); }
}

.envelope-hint {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.3rem, 5vh, 2rem);
  color: rgba(245, 200, 66, 0.85);
  margin-top: 1rem;
  animation: fadeInOut 2.5s ease-in-out infinite;
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

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

/* ============================================
   SCREEN 2: LOADING (CRESCENT + ORBITING STARS)
   ============================================ */
#loading-screen {
  z-index: 90;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}

#loading-screen.active {
  opacity: 1;
  visibility: visible;
}

#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}

/* Moon loader container */
.moon-loader {
  position: relative;
  width: 180px;
  height: 180px;
  margin-bottom: 2.5rem;
}

/* Crescent moon */
.moon-loader__crescent {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: transparent;
  box-shadow: 10px -4px 0 0 #f5dc82;
  filter: drop-shadow(0 0 8px rgba(245, 200, 66, 0.4));
  animation: moonPulse 3s ease-in-out infinite alternate;
}

@keyframes moonPulse {
  0%   { filter: drop-shadow(0 0 8px rgba(245, 200, 66, 0.3));
         box-shadow: 10px -4px 0 0 #f5dc82; }
  100% { filter: drop-shadow(0 0 20px rgba(245, 200, 66, 0.7));
         box-shadow: 10px -4px 0 2px #f5e8a0; }
}

/* Glow behind moon */
.moon-loader__glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  transform: translate(-40%, -55%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 220, 130, 0.12) 0%, transparent 70%);
  animation: glowPulse 3s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  0%   { transform: translate(-40%, -55%) scale(1); opacity: 0.6; }
  100% { transform: translate(-40%, -55%) scale(1.4); opacity: 1; }
}

/* Orbit rings */
.moon-loader__orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  border: 1px solid rgba(245, 200, 66, 0.06);
}

.moon-loader__orbit--1 {
  width: 100px;
  height: 100px;
  margin-left: -50px;
  margin-top: -50px;
  animation: orbit 3s linear infinite;
}

.moon-loader__orbit--2 {
  width: 130px;
  height: 130px;
  margin-left: -65px;
  margin-top: -65px;
  animation: orbit 4.5s linear infinite reverse;
}

.moon-loader__orbit--3 {
  width: 160px;
  height: 160px;
  margin-left: -80px;
  margin-top: -80px;
  animation: orbit 6s linear infinite;
}

.moon-loader__orbit--4 {
  width: 115px;
  height: 115px;
  margin-left: -57.5px;
  margin-top: -57.5px;
  animation: orbit 3.8s linear infinite reverse;
  border: none;
}

.moon-loader__orbit--5 {
  width: 145px;
  height: 145px;
  margin-left: -72.5px;
  margin-top: -72.5px;
  animation: orbit 5.2s linear infinite;
  border: none;
}

/* Stars on orbits */
.moon-loader__star {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  line-height: 1;
  color: #f5c842;
  filter: drop-shadow(0 0 4px rgba(245, 200, 66, 0.8));
  animation: starTwinkle 1.5s ease-in-out infinite alternate;
}

.moon-loader__orbit--2 .moon-loader__star {
  top: auto;
  bottom: -6px;
  font-size: 10px;
  color: #ffeaa0;
  animation-duration: 2s;
}

.moon-loader__orbit--3 .moon-loader__star {
  top: 50%;
  left: -6px;
  transform: translateY(-50%);
  font-size: 12px;
  color: #ffe4a0;
  animation-duration: 1.8s;
}

.moon-loader__orbit--4 .moon-loader__star {
  top: auto;
  bottom: -5px;
  left: 20%;
  font-size: 8px;
  color: #fff;
  animation-duration: 1.2s;
}

.moon-loader__orbit--5 .moon-loader__star {
  top: 30%;
  left: -5px;
  font-size: 9px;
  color: #ffd866;
  animation-duration: 2.2s;
}

@keyframes orbit {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes starTwinkle {
  0%   { opacity: 0.4; transform: translateX(-50%) scale(0.8); }
  100% { opacity: 1; transform: translateX(-50%) scale(1.3); }
}

.loading-text {
  font-family: 'Caveat', cursive;
  font-size: 1.4rem;
  color: rgba(245, 200, 66, 0.85);
  letter-spacing: 1px;
}

.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

/* ============================================
   SCREEN 3: THE LETTER (GALAXY THEME)
   ============================================ */
#letter-screen {
  z-index: 80;
  opacity: 0;
  visibility: hidden;
  transition: opacity 1s ease, visibility 1s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

#letter-screen.active {
  opacity: 1;
  visibility: visible;
}

.letter-container {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 4vh 1rem;
  min-height: 100vh;
}

/* Glass card */
.letter-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  padding: 2rem clamp(1.5rem, 5vw, 2.5rem);
  background: linear-gradient(
    165deg,
    rgba(15, 20, 55, 0.85) 0%,
    rgba(8, 12, 35, 0.92) 50%,
    rgba(5, 8, 25, 0.95) 100%
  );
  border: 1px solid rgba(245, 200, 66, 0.15);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  box-shadow:
    0 0 40px rgba(245, 200, 66, 0.06),
    0 20px 60px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(245, 200, 66, 0.1);
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

#letter-screen.active .letter-card {
  opacity: 1;
  transform: translateY(0);
}

/* Corner decorations */
.corner-deco {
  position: absolute;
  font-size: 14px;
  color: rgba(245, 200, 66, 0.25);
  line-height: 1;
  pointer-events: none;
}
.corner-deco--tl { top: 12px; left: 14px; }
.corner-deco--tr { top: 12px; right: 14px; }
.corner-deco--bl { bottom: 12px; left: 14px; }
.corner-deco--br { bottom: 12px; right: 14px; }

/* ─── Photo ─── */
.photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.photo-frame {
  position: relative;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(135deg, #f5c842, #f2a71e, #d4a84b, #f5e8a0, #f5c842);
  background-size: 300% 300%;
  animation: borderShimmer 4s ease infinite;
  box-shadow:
    0 0 20px rgba(245, 200, 66, 0.2),
    0 0 50px rgba(245, 200, 66, 0.08);
}

@keyframes borderShimmer {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

.photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  border-radius: 50%;
  display: block;
  border: 3px solid rgba(5, 8, 25, 0.9);
}

.photo-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 180px;
  height: 180px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 200, 66, 0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: -1;
}

/* ─── Greeting ─── */
.letter-greeting {
  text-align: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1.2rem;
}

.greeting-main {
  font-family: 'Great Vibes', cursive;
  font-size: clamp(2rem, 7vw, 2.8rem);
  color: #f5c842;
  line-height: 1.3;
  text-shadow: 0 0 20px rgba(245, 200, 66, 0.3);
}

.greeting-title {
  font-family: 'Amiri', serif;
  font-size: clamp(1.3rem, 4.5vw, 1.7rem);
  font-weight: 700;
  color: #ffd866;
  letter-spacing: 3px;
  margin-top: 0.1em;
  text-shadow: 0 0 12px rgba(255, 216, 102, 0.2);
}

.greeting-divider {
  margin: 0.8em 0;
  display: flex;
  align-items: center;
  gap: 0.8em;
}

.greeting-divider::before,
.greeting-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(245, 200, 66, 0.3), transparent);
}

.divider-star {
  color: rgba(245, 200, 66, 0.5);
  font-size: 10px;
}

.greeting-maaf {
  font-family: 'Great Vibes', cursive;
  font-size: clamp(1.3rem, 4.5vw, 1.7rem);
  color: #e8a040;
  text-shadow: 0 0 15px rgba(232, 160, 64, 0.2);
}

/* ─── Dear ─── */
.letter-dear {
  font-size: clamp(1.4rem, 4vw, 1.8rem);
  font-weight: 700;
  margin-bottom: 0.8em;
  color: #f5dc82;
}

.star-emoji { font-size: 1em; }

/* ─── Poem / Message ─── */
.letter-poem {
  margin-bottom: 1.5em;
}

.poem-stanza {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: rgba(230, 225, 215, 0.85);
  line-height: 1.9;
  margin-bottom: 1.2em;
  text-align: left;
}

.poem-stanza:last-child {
  margin-bottom: 0;
}

.poem-aside {
  display: block;
  font-size: 0.88em;
  color: rgba(245, 200, 66, 0.55);
  font-style: italic;
  margin-top: 0.3em;
}

.poem-ending {
  font-style: italic;
  color: rgba(245, 220, 130, 0.9);
  text-align: center;
  margin-top: 0.5em;
}

/* ─── Closing ─── */
.letter-bottom {
  padding-top: 1em;
  border-top: 1px solid rgba(245, 200, 66, 0.1);
}

.letter-closing {
  font-size: clamp(1.05rem, 3.2vw, 1.25rem);
  font-style: italic;
  margin-bottom: 0.6em;
  color: rgba(230, 225, 215, 0.7);
}

.letter-signature {
  font-size: clamp(1.3rem, 4vw, 1.6rem);
  font-weight: 700;
  color: #f5c842;
  margin-bottom: 0.2em;
}

.rose-emoji { font-size: 0.9em; }

/* ─── Floating Cats (CSS cat loader) ─── */
.floating-cat {
  position: fixed;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
}

#letter-screen.active .floating-cat {
  animation: catFadeIn 1s ease forwards;
}

.floating-cat--bl {
  bottom: 20px;
  left: 20px;
  animation-delay: 9s !important;
}

.floating-cat--br {
  bottom: 20px;
  right: 70px;
  animation-delay: 10s !important;
}

.floating-cat .cat {
  width: 55px;
  max-width: 55px;
  filter: drop-shadow(0 0 10px rgba(245, 200, 66, 0.15));
  animation: catBob 3s ease-in-out infinite;
}

/* CAT (from reference) */
.cat {
  position: relative;
  width: 100%;
  max-width: 20em;
  overflow: hidden;
  border-radius: 8px;
}

.cat::before {
  content: "";
  display: block;
  padding-bottom: 100%;
}

.cat__body, .cat__tail, .cat__head {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  animation: rotating 2.79s cubic-bezier(0.65, 0.54, 0.12, 0.93) infinite;
}

.cat__body::before, .cat__tail::before, .cat__head::before {
  content: "";
  position: absolute;
  width: 50%;
  height: 50%;
  background-size: 200%;
  background-repeat: no-repeat;
  background-image: url("https://images.weserv.nl/?url=i.imgur.com/M1raXX3.png&il");
}

.cat__head::before {
  top: 0; right: 0;
  background-position: 100% 0%;
  transform-origin: 0% 100%;
  transform: rotate(90deg);
}

.cat__tail { animation-delay: 0.2s; }
.cat__tail::before {
  left: 0; bottom: 0;
  background-position: 0% 100%;
  transform-origin: 100% 0%;
  transform: rotate(-30deg);
}

.cat__body { animation-delay: 0.1s; }
.cat__body:nth-of-type(2) { animation-delay: 0.2s; }
.cat__body::before {
  right: 0; bottom: 0;
  background-position: 100% 100%;
  transform-origin: 0% 0%;
}

@keyframes rotating {
  from { transform: rotate(720deg); }
  to   { transform: none; }
}

@keyframes catFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* ─── Floating cat emojis ─── */
.cat-emoji {
  position: fixed;
  z-index: 5;
  font-size: 1.6rem;
  opacity: 0;
  pointer-events: none;
  animation: floatCat var(--dur, 12s) var(--del, 0s) ease-in-out infinite;
}

#letter-screen.active .cat-emoji {
  opacity: 1;
}

.cat-emoji--1 {
  top: 15%;
  left: 5%;
  --dur: 10s;
  --del: 2s;
  font-size: 1.4rem;
}

.cat-emoji--2 {
  top: 60%;
  right: 4%;
  --dur: 13s;
  --del: 4s;
  font-size: 1.2rem;
}

.cat-emoji--3 {
  top: 35%;
  left: 3%;
  --dur: 11s;
  --del: 6s;
  font-size: 1.8rem;
}

.cat-emoji--4 {
  top: 80%;
  left: 8%;
  --dur: 14s;
  --del: 3s;
  font-size: 1.1rem;
}

.cat-emoji--5 {
  top: 25%;
  right: 3%;
  --dur: 12s;
  --del: 5s;
  font-size: 1.3rem;
}

@keyframes floatCat {
  0%, 100% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 0.3;
  }
  25% {
    transform: translate(8px, -15px) rotate(5deg);
    opacity: 0.6;
  }
  50% {
    transform: translate(-5px, -25px) rotate(-3deg);
    opacity: 0.4;
  }
  75% {
    transform: translate(10px, -10px) rotate(4deg);
    opacity: 0.55;
  }
}

/* ─── Fade animation ─── */
.fade-line {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

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

/* ============================================
   AUDIO CONTROLS
   ============================================ */
.audio-control {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.audio-control.visible {
  opacity: 1;
}

.audio-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(245, 200, 66, 0.3);
  background: rgba(10, 14, 39, 0.7);
  color: rgba(245, 200, 66, 0.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.audio-btn:hover {
  background: rgba(245, 200, 66, 0.15);
  border-color: rgba(245, 200, 66, 0.5);
}

/* ============================================
   SCROLLBAR
   ============================================ */
#letter-screen::-webkit-scrollbar-track {
  background-color: rgba(3, 5, 16, 0.5);
}

#letter-screen::-webkit-scrollbar {
  width: 8px;
}

#letter-screen::-webkit-scrollbar-thumb {
  background-color: rgba(245, 200, 66, 0.2);
  border-radius: 4px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 500px) {
  .letter-card {
    max-width: 95%;
    padding: 1.5rem 1.2rem;
  }
  .photo-frame { width: 110px; height: 110px; }
  .photo-glow  { width: 140px; height: 140px; }
  .moon-loader { width: 140px; height: 140px; }
  .moon-loader__crescent { width: 45px; height: 45px; }
  .envelope-stamp { width: 48px; height: 48px; }
  .floating-cat .cat { width: 40px; max-width: 40px; }
  .floating-cat--br { right: 55px; }
  .cat-emoji { font-size: 1rem !important; }
}
