:root {
  --pink-deep: #d6668a;
  --pink-mid: #e79bb3;
  --pink-soft: #f6d9e2;
  --cream: #fdf1ec;
  --gold: #c8925a;
  --ink: #6b3f4a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #f3c9d4;
}

body {
  font-family: "Tajawal", sans-serif;
  color: var(--ink);
  overflow: hidden;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background-image: url("../assets/img/bg.png");
  background-size: cover;
  background-position: center;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.15);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(110px + var(--safe-bottom));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#screen-name,
#screen-mirror,
#screen-envelope {
  justify-content: space-between;
  padding-bottom: calc(20px + var(--safe-bottom));
}
#screen-name .content,
#screen-mirror .content,
#screen-envelope .content {
  margin-top: auto;
  margin-bottom: auto;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.content {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Floating CTA button, shared across screens */
.cta-floating {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  font-family: "Tajawal", sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-deep), #c1516f);
  box-shadow: 0 8px 20px rgba(198, 88, 122, 0.45);
  cursor: pointer;
  min-height: 48px;
  animation: pulse 2.2s ease-in-out infinite;
}
.cta-floating:active { transform: translateX(-50%) scale(0.96); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 8px 20px rgba(198, 88, 122, 0.45); }
  50% { box-shadow: 0 8px 26px rgba(198, 88, 122, 0.7); }
}

/* Same pill button, but sits in normal document flow instead of pinned to the screen bottom */
.cta-inline {
  position: static;
  transform: none;
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  margin-top: 22px;
  font-family: "Tajawal", sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-deep), #c1516f);
  box-shadow: 0 8px 20px rgba(198, 88, 122, 0.45);
  cursor: pointer;
  min-height: 48px;
  animation: pulse 2.2s ease-in-out infinite;
}
.cta-inline:active { transform: scale(0.96); }

.event-credit {
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
  opacity: 0.65;
  text-align: center;
  margin: 0;
}

/* --- Screen 1: Mirror --- */
.title {
  font-family: "Aref Ruqaa", serif;
  font-size: 44px;
  color: var(--pink-deep);
  text-shadow: 0 2px 0 rgba(255,255,255,0.6);
  margin: 0 0 8px;
  opacity: 0;
  animation: fadeSlideDown 0.9s ease forwards 0.15s;
}

.mirror-wrap {
  position: relative;
  width: 78%;
  max-width: 300px;
  margin: 4px auto 10px;
  opacity: 0;
  animation: fadeSlideUp 0.9s ease forwards 0.4s;
}

.mirror-img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 14px 20px rgba(120, 40, 70, 0.25));
}

.mirror-shine {
  /* Aligned to the reflective glass oval inside the mirror frame, not the whole image.
     Clips its ::before line to the oval; the line itself does the animating. */
  position: absolute;
  top: 18%;
  left: 44%;
  width: 41%;
  height: 62%;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
}

.mirror-shine::before {
  content: "";
  position: absolute;
  top: -30%;
  left: -45%;
  width: 190%;
  height: 20%;
  transform: rotate(-18deg);
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.85) 50%, transparent);
  mix-blend-mode: screen;
  animation: shimmer 3.2s ease-in-out infinite 1.2s;
}

@keyframes shimmer {
  0%   { top: -30%; opacity: 0; }
  12%  { opacity: 1; }
  88%  { opacity: 1; }
  100% { top: 130%; opacity: 0; }
}

.subtitle {
  font-size: 16px;
  color: var(--ink);
  opacity: 0;
  animation: fadeSlideUp 0.9s ease forwards 0.65s;
}

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Screen 0: Name entry --- */
.name-prompt {
  font-size: 17px;
  line-height: 1.8;
  color: var(--ink);
  margin: 8px 0 0;
  opacity: 0;
  animation: fadeSlideUp 0.9s ease forwards 0.4s;
}

.name-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 26px;
  opacity: 0;
  animation: fadeSlideUp 0.9s ease forwards 0.65s;
}

.name-input {
  width: 100%;
  max-width: 280px;
  font-family: "Tajawal", sans-serif;
  font-size: 17px;
  text-align: center;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid rgba(200, 146, 90, 0.45);
  border-radius: 999px;
  padding: 14px 20px;
  outline: none;
  box-shadow: 0 6px 16px rgba(120, 40, 70, 0.12);
}
.name-input::placeholder { color: rgba(107, 63, 74, 0.45); }
.name-input:focus { border-color: var(--pink-deep); }
.name-input + .name-input { margin-top: 12px; }

.form-error {
  font-size: 13px;
  color: #c0304f;
  margin: 10px 0 0;
}

.reset-link {
  display: inline-block;
  background: none;
  border: none;
  padding: 0;
  font-family: "Tajawal", sans-serif;
  font-size: 13px;
  color: var(--ink);
  opacity: 0.55;
  text-decoration: underline;
  cursor: pointer;
  margin: 10px 0 0;
}
.reset-link:active { opacity: 0.8; }

/* --- Screen 2: Envelope --- */
.envelope-hint {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 24px;
  color: var(--ink);
}

.envelope-wrap {
  width: 82%;
  max-width: 320px;
  animation: breathe 3s ease-in-out infinite;
}

.envelope-img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 16px 22px rgba(120, 40, 70, 0.28));
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}

.envelope-wrap.shaking {
  animation: shake 0.45s ease;
}
@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-2.5deg) scale(1.02); }
  40% { transform: rotate(2.5deg) scale(1.02); }
  60% { transform: rotate(-1.5deg) scale(1.03); }
  80% { transform: rotate(1.5deg) scale(1.03); }
}

/* --- Screen 3: Letter --- */
.letter-content { justify-content: center; }

.letter-card {
  width: 100%;
  background: linear-gradient(180deg, var(--cream), #fbe6de);
  border: 1px solid rgba(200, 146, 90, 0.4);
  border-radius: 14px;
  padding: 34px 24px 30px;
  box-shadow: 0 18px 30px rgba(120, 40, 70, 0.22);
  opacity: 0;
  transform: translateY(24px) scale(0.96);
  animation: letterRise 0.7s cubic-bezier(.2,.8,.3,1) forwards 0.2s;
  position: relative;
}

.letter-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(200, 146, 90, 0.35);
  border-radius: 8px;
  pointer-events: none;
}

@keyframes letterRise {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.letter-flourish {
  color: var(--gold);
  font-size: 22px;
  margin-bottom: 14px;
}

.letter-title {
  font-family: "Aref Ruqaa", serif;
  font-size: 24px;
  color: var(--pink-deep);
  margin: 0 0 20px;
}

.letter-body p {
  font-size: 16.5px;
  line-height: 1.9;
  color: var(--ink);
  margin: 0 0 18px;
}
.letter-body p:last-child { margin-bottom: 0; }

/* --- Screen 3b: Magic wand reveal --- */
.reveal-content { justify-content: center; }

.reveal-text {
  font-family: "Aref Ruqaa", serif;
  font-size: 26px;
  color: var(--pink-deep);
  margin: 0 0 30px;
  opacity: 0;
}
#screen-reveal.active .reveal-text {
  animation: fadeSlideDown 0.6s ease forwards 0.05s;
}

.wand-wrap {
  position: relative;
  width: 46%;
  max-width: 170px;
}

.wand-img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 14px 20px rgba(120, 40, 70, 0.3));
  opacity: 0;
  transform-origin: 50% 94%;
}
#screen-reveal.active .wand-img {
  animation: wandAppear 1.7s cubic-bezier(.34,1.4,.4,1) forwards;
}

@keyframes wandAppear {
  0%   { opacity: 0; transform: scale(0.5) rotate(-35deg); }
  28%  { opacity: 1; transform: scale(1.08) rotate(10deg); }
  44%  { transform: scale(1) rotate(-16deg); }
  60%  { transform: scale(1) rotate(11deg); }
  76%  { transform: scale(1) rotate(-6deg); }
  90%  { transform: scale(1) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.wand-sparkle {
  position: absolute;
  color: var(--gold);
  font-size: 20px;
  opacity: 0;
}
.wand-sparkle-1 { top: 6%; left: -10%; font-size: 26px; }
.wand-sparkle-2 { top: 30%; right: -14%; font-size: 17px; }
.wand-sparkle-3 { top: 50%; left: -18%; font-size: 15px; }

#screen-reveal.active .wand-sparkle-1 { animation: sparkleTwinkle 1s ease forwards 0.55s; }
#screen-reveal.active .wand-sparkle-2 { animation: sparkleTwinkle 1s ease forwards 0.9s; }
#screen-reveal.active .wand-sparkle-3 { animation: sparkleTwinkle 1s ease forwards 1.15s; }

@keyframes sparkleTwinkle {
  0%   { opacity: 0; transform: scale(0.4) rotate(0deg); }
  35%  { opacity: 1; transform: scale(1.15) rotate(20deg); }
  70%  { opacity: 0.8; transform: scale(0.9) rotate(-10deg); }
  100% { opacity: 0; transform: scale(0.6) rotate(0deg); }
}

/* --- Screen 4: Story --- */
.portrait-img {
  width: 62%;
  max-width: 230px;
  filter: drop-shadow(0 14px 20px rgba(120, 40, 70, 0.28));
  margin-bottom: 16px;
}

.story-name {
  font-family: "Aref Ruqaa", serif;
  font-size: 30px;
  color: var(--pink-deep);
  margin: 0 0 14px;
}

.story-intro {
  font-size: 16px;
  line-height: 2;
  color: var(--ink);
  margin: 0;
}

/* --- Screen 5: Book --- */
.screen-book { padding-bottom: calc(24px + var(--safe-bottom)); }

.book-stage {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.book-flip {
  width: 100%;
  min-height: 420px;
  perspective: 1400px;
}

.book-card {
  width: 100%;
  min-height: 420px;
  background: linear-gradient(180deg, var(--cream), #fbe6de);
  border: 1px solid rgba(200, 146, 90, 0.4);
  border-radius: 14px;
  box-shadow: 0 18px 30px rgba(120, 40, 70, 0.22);
  position: relative;
  overflow: hidden;
  transition: transform 0.35s ease, opacity 0.35s ease;
  transform-style: preserve-3d;
  display: flex;
  flex-direction: column;
}

.book-card::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(200, 146, 90, 0.35);
  border-radius: 8px;
  pointer-events: none;
}

.book-banner {
  background: linear-gradient(135deg, var(--pink-mid), var(--pink-deep));
  padding: 22px 16px 16px;
  text-align: center;
  position: relative;
}

.book-crown { font-size: 22px; line-height: 1; margin-bottom: 4px; }

.book-title {
  font-family: "Aref Ruqaa", serif;
  font-size: 30px;
  color: #fff;
  margin: 0;
}

.book-subtitle {
  font-size: 13px;
  color: #fff;
  opacity: 0.9;
  margin: 4px 0 0;
}

.book-reference {
  font-size: 11px;
  color: var(--ink);
  opacity: 0.6;
  text-align: center;
  margin: 10px 0 0;
}

.book-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-refrain {
  font-family: "Aref Ruqaa", serif;
  font-size: 18px;
  line-height: 1.9;
  color: var(--pink-deep);
  text-align: center;
  white-space: pre-line;
  margin: 0;
}

.book-text {
  font-size: 15.5px;
  line-height: 1.95;
  color: var(--ink);
  white-space: pre-line;
  margin: 0;
}

.book-nav {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}

.nav-arrow {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  color: #fff;
  background: linear-gradient(135deg, var(--pink-deep), #c1516f);
  box-shadow: 0 8px 18px rgba(198, 88, 122, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.nav-arrow:active { transform: scale(0.94); }
.nav-arrow:disabled {
  opacity: 0.35;
  box-shadow: none;
  cursor: default;
}

.book-page-count {
  font-size: 13px;
  color: var(--ink);
  opacity: 0.7;
  direction: ltr;
  unicode-bidi: isolate;
}

.book-finish { margin-top: 18px; }

/* --- Screen 6: Final blessing --- */
.screen-final {
  justify-content: flex-end;
  padding: 0 22px calc(30px + var(--safe-bottom));
}

/* Hero image pinned to the top, its lower edge dissolving into the stage's
   pink so the scene melts into the page instead of sitting in a hard box. */
.final-img {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 70%;
  object-fit: cover;
  object-position: center top;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 66%, transparent 85%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 66%, transparent 85%);
  opacity: 0;
}
#screen-final.active .final-img {
  animation: finalImgIn 1.3s ease forwards;
}
@keyframes finalImgIn {
  from { opacity: 0; transform: translateX(-50%) scale(1.06); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

.final-content {
  position: relative;
  z-index: 1;
  max-width: 360px;
}

.final-message {
  opacity: 0;
}
#screen-final.active .final-message {
  animation: fadeSlideUp 0.9s ease forwards 0.5s;
}

.final-flourish {
  display: block;
  color: var(--gold);
  font-size: 18px;
  margin-bottom: 8px;
}

.final-message p {
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0 0 9px;
  text-shadow: 0 1px 6px rgba(253, 241, 236, 0.95);
}

.final-emph {
  font-family: "Aref Ruqaa", serif;
  font-size: 18px;
  margin: 4px 0 !important;
  color: var(--pink-deep) !important;
}

#restart-btn {
  opacity: 0;
  animation: fadeSlideUp 0.9s ease forwards 0.9s,
             pulse 2.2s ease-in-out infinite 0.9s;
}
