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

body {
  font-family: 'Playfair Display', serif;
  background-color: #f6ebd6; /* Warm beige */
  overflow: hidden;
}

.bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-image: url('assets/bg.png');
  background-size: cover;
  background-position: center;
  opacity: 0.8;
  z-index: -1;
}

/* Views */
.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 10;
}

.view.active {
  opacity: 1;
  pointer-events: auto;
}

/* Main View Specifics */
.title {
  font-family: 'Great Vibes', cursive;
  font-size: 5rem;
  color: #4a3320;
  margin-bottom: 20px;
  text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.8), 0 0 20px rgba(255, 255, 255, 0.4);
  letter-spacing: 2px;
}

.boxes-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 30px;
  min-height: 300px;
}

.opened-state-container {
  display: flex;
  gap: 20px;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideLidOff {
  0% { 
    transform: translateX(calc(100% + 20px)) translateY(0) rotate(0deg); 
  }
  100% { 
    transform: translateX(0) translateY(10px) rotate(-5deg); 
  }
}

.lid-wrapper {
  position: relative;
  z-index: 50; /* Ensure it stays above the items in the open box while sliding */
  animation: slideLidOff 2.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.box-wrapper {
  position: relative;
  width: 500px;
  height: 500px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.box-wrapper:hover {
  transform: scale(1.02);
}

.box-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Items inside the open box */
.item {
  position: absolute;
  cursor: pointer;
  transition: transform 0.3s ease, filter 0.3s ease;
}

.item:hover {
  transform: scale(1.1);
  filter: drop-shadow(4px 4px 8px rgba(0,0,0,0.3));
}

.item-letter {
  width: 210px;
  top: 95px;
  left: 100px;
  transform: rotate(-10deg);
  z-index: 2;
}

.item-letter:hover { transform: rotate(-10deg) scale(1.05); }

.item-rose {
  width: 170px;
  top: 95px;
  left: 245px;
  transform: rotate(25deg);
  z-index: 3;
}

.item-rose:hover { transform: rotate(25deg) scale(1.05); }

.item-camera {
  width: 200px;
  bottom: 100px;
  right: 90px;
  transform: rotate(35deg);
  z-index: 4;
}

.item-camera:hover { transform: rotate(35deg) scale(1.05); }

.item-cassette {
  width: 170px;
  bottom: 95px;
  left: 95px;
  transform: rotate(-12deg);
  z-index: 5;
}

.item-cassette:hover { transform: rotate(-12deg) scale(1.05); }

/* Scattered petals in the box's empty space */
.petal {
  position: absolute;
  width: 45px;
  height: 45px;
  background-image: url('assets/petal.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.95;
  filter: drop-shadow(2px 3px 4px rgba(0,0,0,0.4));
  pointer-events: none;
  z-index: 1;
}

.flower-lily .petal { filter: hue-rotate(300deg) drop-shadow(2px 3px 4px rgba(0,0,0,0.4)); }
.flower-sunflower .petal { filter: hue-rotate(60deg) saturate(2) drop-shadow(2px 3px 4px rgba(0,0,0,0.4)); }

.petal-1 { top: 225px; left: 235px; transform: rotate(20deg); width: 50px; height: 50px; }
.petal-2 { top: 280px; left: 210px; transform: rotate(95deg) scaleX(-1); width: 40px; height: 40px; }
.petal-3 { top: 210px; left: 285px; transform: rotate(160deg); width: 42px; height: 42px; }
.petal-4 { top: 310px; left: 260px; transform: rotate(240deg); }
.petal-5 { top: 180px; left: 200px; transform: rotate(310deg) scaleX(-1); width: 35px; height: 35px; }
.petal-6 { top: 250px; left: 160px; transform: rotate(60deg); width: 38px; height: 38px; }
.petal-7 { top: 260px; left: 320px; transform: rotate(130deg); width: 48px; height: 48px; }
.petal-8 { top: 160px; left: 280px; transform: rotate(200deg); width: 36px; height: 36px; }

.instruction-btn {
  padding: 12px 30px;
  background-color: #fdf3e1;
  border: 2px solid #d4b895;
  border-radius: 30px;
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  color: #4a3320;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.instruction-btn:hover {
  background-color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.customize-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background-color: #fdf3e1;
  border: 2px solid #d4b895;
  border-radius: 30px;
  padding: 10px 25px;
  font-family: 'Caveat', cursive;
  font-size: 1.6rem;
  color: #4a3320;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.customize-btn:hover {
  background-color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* Detail Views */
.detail-view {
  background-color: rgba(246, 235, 214, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  cursor: pointer; /* hints that clicking the background closes */
}

/* Keep the actual content non-closing and normal cursor */
.detail-view .content-wrapper {
  cursor: default;
}

.content-wrapper {
  position: relative;
  width: fit-content;
  max-width: 95vw;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.paper-bg {
  max-height: 90vh;
  width: auto;
  max-width: 90vw;
  display: block;
  /* drop-shadow follows the torn paper alpha so there's no square card behind it */
  filter: drop-shadow(0 12px 22px rgba(0,0,0,0.35));
}

.text-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 62%;
  max-width: 380px;
  max-height: 50%;
  overflow-y: auto;
  text-align: center;
  color: #3b2a1a;
  padding: 5px 10px;
  /* Hide scrollbar */
  scrollbar-width: none;
}

.text-content::-webkit-scrollbar {
  display: none;
}

.letter-text {
  font-family: 'Great Vibes', cursive;
  font-size: clamp(0.9rem, 3vw, 1.5rem);
  line-height: 1.35;
  width: 45%;
  max-width: 400px;
  max-height: 75%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  overflow: hidden;
  text-align: center;
  padding-top: 70px;
}

.salutation {
  font-size: 2rem;
  margin-bottom: 14px;
}

.signoff {
  margin-top: 20px;
  font-size: 2rem;
  text-align: right;
}

.polaroid-wrapper {
  background-color: #faf8f5;
  padding: 15px 15px 30px 15px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.4);
  transform: rotate(-3deg);
  border: 1px solid #eaeaea;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 85vw;
  max-width: 350px;
}

.polaroid-inner {
  background: #000;
  padding: 2px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
  width: 100%;
}

.polaroid-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  filter: sepia(0.3) contrast(1.1) brightness(0.95);
}

.polaroid-caption {
  font-family: 'Caveat', cursive;
  font-size: 2.5rem;
  color: #2b1e16;
  margin-top: 10px;
  z-index: 5;
}

.cassette-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.cassette-img {
  width: 400px;
  filter: drop-shadow(10px 10px 15px rgba(0,0,0,0.4));
  margin-bottom: 30px;
}

.cassette-text {
  font-family: 'Caveat', cursive;
  font-size: 2.5rem;
  color: #4a3320;
  margin-top: 20px;
  max-width: 90vw;
  text-align: center;
  word-wrap: break-word;
  line-height: 1.2;
  animation: pulse 2s infinite ease-in-out;
}

.rose-wrapper {
  gap: 40px; /* Add space between rose and text */
}

.big-rose {
  position: relative;
  height: 55vh;
  max-height: 500px;
  width: auto;
  transform: rotate(5deg);
  filter: drop-shadow(10px 10px 15px rgba(0,0,0,0.4));
}

.rose-text {
  position: relative;
  font-family: 'Great Vibes', cursive;
  font-size: 3.5rem;
  color: #4a3320;
  text-align: center;
  text-shadow: 2px 2px 4px rgba(255,255,255,0.8);
}

.final-text {
  font-family: 'Caveat', cursive;
  font-size: 4rem;
  color: #d12c2c;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.heart {
  font-size: 5rem;
}

.close-btn {
  position: fixed;
  top: 24px;
  right: 28px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fdf3e1;
  border: 2px solid #d4b895;
  border-radius: 50%;
  font-family: 'Playfair Display', serif;
  font-size: 1.8rem;
  line-height: 1;
  color: #4a3320;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  transition: all 0.25s ease;
  z-index: 210;
}

.close-btn:hover {
  background-color: #ffffff;
  transform: scale(1.08) rotate(90deg);
  box-shadow: 0 6px 14px rgba(0,0,0,0.25);
}

/* Hidden YouTube audio player */
#yt-player {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  pointer-events: none;
  opacity: 0;
}

/* The real cassette, once it has moved to the bottom-right corner */
.item.cassette-docked,
.item.cassette-docked:hover {
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.45));
  cursor: pointer;
  z-index: 300;
}

.pulse {
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 0px rgba(0,0,0,0)); }
  50% { transform: scale(1.03); filter: drop-shadow(0 10px 20px rgba(0,0,0,0.2)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0px rgba(0,0,0,0)); }
}

/* Setup View */
.setup-container {
  background-color: rgba(253, 243, 225, 0.9);
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1);
  width: 90%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  backdrop-filter: blur(5px);
  border: 2px solid #d4b895;
  z-index: 100;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 1.2rem;
  color: #4a3320;
  font-weight: bold;
}

.input-group input[type="text"],
.input-group select,
.input-group textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #d4b895;
  border-radius: 10px;
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  background-color: #fffaf0;
  color: #4a3320;
  box-sizing: border-box;
}

/* Autocomplete styling */
.autocomplete-wrapper {
  position: relative;
  width: 100%;
}

.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #d4b895;
  border-radius: 8px;
  margin-top: 5px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  list-style: none;
  padding: 0;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.autocomplete-results li {
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-family: 'Playfair Display', serif;
  font-size: 0.95rem;
  color: #4a3320;
  display: flex;
  flex-direction: column;
}

.autocomplete-results li:last-child {
  border-bottom: none;
}

.autocomplete-results li:hover {
  background-color: #fffaf0;
}

.autocomplete-results li .artist {
  font-size: 0.8rem;
  color: #8b7355;
  margin-top: 2px;
}

.input-group textarea {
  resize: vertical;
}

.input-group input[type="file"] {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
}

.input-group small {
  font-size: 0.85rem;
  color: #7b624c;
}

.status-msg {
  text-align: center;
  color: #4CAF50;
  font-weight: bold;
  margin-top: -10px;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
  body {
    overflow-y: auto;
    overflow-x: hidden;
  }
  
  .boxes-container {
    transform: scale(0.6);
    margin-bottom: -20px;
  }
  
  .title {
    font-size: 3.5rem;
    margin-top: 50px;
  }
  
  .setup-container {
    width: 90vw;
    padding: 15px;
    margin-top: 50px;
  }
  
  .customize-btn {
    font-size: 0.9rem;
    padding: 8px 12px;
    top: 10px;
    right: 10px;
  }
  
  .instruction-btn {
    font-size: 1.1rem;
    padding: 10px 20px;
    bottom: 20px;
  }
  
  .opened-state-container {
    flex-direction: column;
    gap: 0;
  }
  
  @keyframes slideLidOff {
    0% { 
      transform: translateY(100%) rotate(0deg); 
    }
    100% { 
      transform: translateY(0) rotate(-5deg); 
    }
  }
}
