/* Colors and variables */
:root {
  --theme-blue: #b4d2ee;
  --theme-blue-dull: #d3eafd;
  --theme-white: #fff;
  --theme-black: #444;
  --theme-red: #c51803;
  --env-width: 300px;
  --env-height: 200px;
  --heart-width: 15px;
  --heart-height: 15px;
  --animation-duration: 0.5s;
  --card-animation-duration: 1s;
  --unlock-wrapper: 0.4s;
  --open-close-envelope: 0.75s;
  --show-note: 1s;
  --lock-wrapper: 0.7s;
}

/* Base styles */
body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--theme-black);
  font-family: Arial, sans-serif;
  overflow: hidden;
  position: fixed;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Main container */
.bg-wrapper {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--theme-black);
  overflow: hidden;
  position: fixed;
  width: 100%;
  left: 0;
  top: 0;
  padding-bottom: 60px; /* Add padding to prevent overlap */
}

.envelope-wrapper {
  position: relative;
  perspective: 1000px;
  margin: 0 auto;
  text-align: center;
  overflow: visible !important;
  width: 300px;
  height: 200px;
}

/* Envelope itself - using border technique */
.envelope {
  position: relative;
  width: 0;
  height: 0;
  border-top: 100px solid #fff;
  border-right: 150px solid #eee;
  border-bottom: 100px solid #ddd;
  border-left: 150px solid #eee;
  border-radius: 10px;
  cursor: not-allowed;
  transform-style: preserve-3d;
  perspective: 1000px;
  z-index: 1;
  transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Envelope flap - will be animated */
.envelope-flap {
  position: absolute;
  top: -100px;
  left: -150px;
  width: 0;
  height: 0;
  border-top: 100px solid #c9302c;
  border-right: 150px solid transparent;
  border-bottom: 100px solid transparent;
  border-left: 150px solid transparent;
  transform-origin: center top;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 2;
  transform: rotateX(0deg);
}

.envelope.open .envelope-flap {
  transform: rotateX(-180deg);
  z-index: 0;
}

/* Letter container */
.letter {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 400px;
  height: 400px;
  background: white;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  opacity: 0;
  transform: translate(-50%, 100%);
  padding: 30px;
  box-sizing: border-box;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  z-index: 4;
  pointer-events: none;
  visibility: hidden;
  overflow: hidden;
  background-color: #fff;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #ff3838 transparent;
  text-shadow: none;
}

/* Custom scrollbar for webkit browsers */
.letter::-webkit-scrollbar {
  width: 8px;
  background-color: transparent;
}

.letter::-webkit-scrollbar-thumb {
  background-color: #ff3838;
  border-radius: 4px;
}

.letter::-webkit-scrollbar-track {
  background-color: transparent;
}

/* Enable scrolling only when letter is open */
.envelope.open .letter {
  pointer-events: all;
  overflow-y: auto;
}

/* Media query for mobile devices */
@media screen and (max-width: 480px) {
  body {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .letter {
    width: 85vw;
    height: 70vh;
    padding: 20px;
    max-width: 400px;
    max-height: 500px;
  }

  .text {
    font-size: 14px;
  }

  .text h1 {
    font-size: 20px;
    margin-bottom: 15px;
  }

  .text p {
    font-size: 14px;
    margin-bottom: 15px;
  }

  .text .signature {
    margin-top: 20px;
    font-size: 14px;
  }

  /* Increase touch target size for mobile */
  .close-btn {
    width: 40px;
    height: 40px;
    top: 10px;
    right: 10px;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Improve input for mobile */
  .passcode-screen input {
    font-size: 18px;
    padding: 12px;
    width: 80%;
    max-width: 250px;
  }

  /* Improve button for mobile */
  .passcode-screen button {
    font-size: 18px;
    padding: 12px 20px;
    margin-top: 15px;
  }
}

/* Text content */
.text {
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  color: #000;
  line-height: 1.8;
  font-size: 16px;
  text-align: left;
  transform: scale(1);
  padding: 0;
}

.text h1 {
  font-size: 24px;
  margin-bottom: 25px;
  font-weight: bold;
  margin-top: 0;
  color: #000;
  width: 100%;
  text-align: left;
  letter-spacing: 0.5px;
}

.text p {
  margin: 0 0 20px 0;
  font-size: 16px;
  line-height: 1.8;
  font-weight: normal;
  width: 100%;
  text-align: left;
  color: #000;
  letter-spacing: 0.3px;
}

.text .signature {
  margin-top: 30px;
  font-size: 16px;
  font-style: italic;
  align-self: flex-end;
  margin-right: 20px;
  color: #000;
  font-weight: 500;
}

.heart {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  background: #ff3838;
  transform: translate(-50%, -50%) rotate(45deg);
  z-index: 3;
  animation: heartbeat 1.4s linear infinite;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.envelope.open .heart {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.heart::before,
.heart::after {
  content: "";
  position: absolute;
  width: 36px;
  height: 36px;
  background: #ff3838;
  border-radius: 50%;
  pointer-events: none;
}

.heart::before {
  top: -18px;
  left: 0;
}

.heart::after {
  left: -18px;
  top: 0;
}

@keyframes heartbeat {
  0% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1);
  }
  25% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1);
  }
  30% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.2);
  }
  50% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.4);
  }
  70% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.2);
  }
  100% {
    transform: translate(-50%, -50%) rotate(45deg) scale(1);
  }
}

/* Keep existing passcode styles */
.passcode-screen {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
  text-align: center;
  z-index: 50;
  width: 250px;
}

.passcode-screen h2 {
  margin: 0 0 10px 0;
  font-size: 1.1em;
  color: #333;
}

.passcode-screen input {
  width: 180px;
  padding: 8px;
  margin: 8px 0;
  border: 1px solid #ccc;
  border-radius: 5px;
  text-align: center;
  font-size: 14px;
  outline: none;
}

.passcode-screen button {
  background: #ff5757;
  color: white;
  border: none;
  padding: 12px 30px;
  margin: 8px 0;
  cursor: pointer;
  border-radius: 5px;
  font-size: 16px;
  transition: background 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  min-width: 100px;
}

.passcode-screen button:active {
  background: #ff3838;
  transform: scale(0.98);
}

.error-container {
  height: 0;
  overflow: hidden;
  transition: height 0.3s ease;
}

.error-container.show {
  height: 40px;
  padding: 10px 0;
}

#error-msg {
  color: red;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#error-msg.show {
  opacity: 1;
}

/* Content visibility */
.content {
  display: none;
}

.wrapper.show-envelope .content {
  display: flex;
}

.wrapper.show-envelope .passcode-screen {
  display: none;
}

/* Input styling */
input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

@keyframes flip {
  100% {
    transform: rotateX(180deg);
    z-index: 1;
  }
}

@keyframes remove {
  50% {
    top: -120px;
  }
  100% {
    top: 8px;
    z-index: 3;
  }
}

@keyframes fold-up {
  from {
  }
  to {
    transform: rotateX(140deg);
  }
}

@keyframes fold-down {
  from {
  }
  to {
    transform: rotateX(-140deg);
  }
}

/* Animation keyframes */
@keyframes letterReveal {
  0% {
    transform: translate(-50%, 100%);
    opacity: 0;
    visibility: visible;
  }
  50% {
    transform: translate(-50%, -80%);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, 30%);
    opacity: 1;
  }
}

@keyframes letterClose {
  0% {
    transform: translate(-50%, 30%);
    opacity: 1;
    visibility: visible;
  }
  100% {
    transform: translate(-50%, 100%);
    opacity: 0;
    visibility: hidden;
  }
}

/* Animation classes */
.envelope.open .letter {
  animation: letterReveal 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  visibility: visible;
  pointer-events: all;
  overflow-y: auto;
}

.letter.closing {
  animation: letterClose 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Close button */
.close-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  cursor: pointer;
  z-index: 5;
  padding: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* Improve touch area for mobile */
@media (max-width: 768px) {
  .heart {
    width: 32px;
    height: 32px;
  }

  .heart::before,
  .heart::after {
    width: 32px;
    height: 32px;
  }

  .heart::before {
    top: -16px;
  }

  .heart::after {
    left: -16px;
  }

  .close-btn {
    width: 40px;
    height: 40px;
    padding: 10px;
    top: 10px;
    right: 10px;
  }

  .letter {
    width: 85vw;
    max-width: 400px;
    height: 70vh;
    max-height: 500px;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
  }

  .text {
    font-size: 16px;
    line-height: 1.6;
  }

  .text h1 {
    font-size: 22px;
    margin-bottom: 20px;
  }

  .passcode-screen button {
    padding: 15px 35px;
    font-size: 18px;
    min-width: 120px;
  }

  .passcode-screen input {
    font-size: 16px;
    padding: 12px;
    width: 200px;
  }
}

@media (max-width: 480px) {
  .heart {
    width: 28px;
    height: 28px;
  }

  .heart::before,
  .heart::after {
    width: 28px;
    height: 28px;
  }

  .heart::before {
    top: -14px;
  }

  .heart::after {
    left: -14px;
  }

  .close-btn {
    width: 40px;
    height: 40px;
    padding: 10px;
    top: 10px;
    right: 10px;
  }

  .letter {
    width: 85vw;
    max-width: 400px;
    height: 70vh;
    max-height: 500px;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
  }

  .text {
    font-size: 16px;
    line-height: 1.6;
  }

  .text h1 {
    font-size: 22px;
    margin-bottom: 20px;
  }

  .passcode-screen button {
    padding: 15px 35px;
    font-size: 18px;
    min-width: 120px;
  }

  .passcode-screen input {
    font-size: 16px;
    padding: 12px;
    width: 200px;
  }
}

/* Footer */
.copyright {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  color: #000;
  z-index: 999;
  text-align: center;
  width: 100%;
  cursor: default;
  user-select: none;
}

.copyright a {
  color: #ff3838;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease;
}

.copyright a:hover {
  color: #ff2020;
  transform: scale(1.05);
  text-decoration: none;
}
