/* ==========================================================================
   Star Letter — Base scenes
   The original four-act layouts, letter components and music toggle.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Act I — Prologue
   -------------------------------------------------------------------------- */

.scene--prologue {
  display: flex;
  align-items: center;
  padding: clamp(110px, 16vh, 160px) var(--pad-x) clamp(96px, 14vh, 130px);
  overflow: hidden;
}

.prologue-inner {
  width: min(1020px, 100%);
  margin-top: clamp(0px, 3vh, 34px);
}

.poem-wrap {
  position: relative;
  padding-left: clamp(22px, 3vw, 42px);
  max-width: 880px;
}

.poem-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 0;
  width: 1px;
  background: linear-gradient(180deg, rgba(255, 217, 160, 0.68), rgba(255, 217, 160, 0.14) 72%, transparent);
}

.poem-wrap::after {
  content: "✦";
  position: absolute;
  left: -4.5px;
  top: -17px;
  font-size: 9px;
  color: rgba(255, 217, 160, 0.8);
  text-shadow: 0 0 12px rgba(255, 217, 160, 0.5);
}

.poem {
  margin: 0;
  max-width: 860px;
  font-weight: 400;
  color: var(--text);
}

.poem-line {
  display: block;
  min-height: 1.9em;
  margin: 0;
  font-size: clamp(22px, 3.15vw, 42px);
  font-weight: 400;
  line-height: 1.9;
  letter-spacing: 0.07em;
  transition: opacity 1.2s ease, color 1.2s ease, text-shadow 1.2s ease;
}

.poem-line:nth-child(2) { padding-left: 1.15em; }
.poem-line:nth-child(4) { padding-left: 0.5em; }

.poem-line.is-past { opacity: 0.28; }

.poem-line:nth-child(4) .typed {
  color: #ffe8c8;
}

.poem-line:nth-child(4).is-done .typed {
  text-shadow: 0 0 38px rgba(255, 200, 150, 0.28);
}

.poem-line.is-typing .typed::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 0.94em;
  margin-left: 0.13em;
  vertical-align: -0.08em;
  background: rgba(255, 217, 160, 0.9);
  animation: caretBlink 1s steps(1) infinite;
}

.poem-actions {
  margin-top: clamp(26px, 4.6vh, 46px);
  margin-left: clamp(22px, 3vw, 42px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 1.1s ease, transform 1.1s var(--ease-out), visibility 0s linear 1.1s;
}

.poem-actions.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity 1.1s ease, transform 1.1s var(--ease-out), visibility 0s linear 0s;
}

.prologue-foot {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + clamp(18px, 3vh, 30px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  width: max-content;
  max-width: calc(100vw - 140px);
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: rgba(230, 220, 255, 0.36);
  line-height: 1.7;
}

.prologue-foot .foot-dot {
  font-size: 7px;
  color: rgba(255, 217, 160, 0.4);
}

.prologue-foot .foot-alt { color: rgba(230, 220, 255, 0.26); }

/* --------------------------------------------------------------------------
   Act II — Heart
   -------------------------------------------------------------------------- */

.scene--heart {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.heart-copy {
  position: relative;
  z-index: 2;
  margin-top: clamp(116px, 17vh, 178px);
  padding: 0 24px;
  text-align: center;
}

.heart-title {
  margin: clamp(16px, 2.2vh, 24px) 0 0;
  font-size: clamp(22px, 3vw, 38px);
  font-weight: 400;
  letter-spacing: 0.1em;
  color: rgba(255, 247, 240, 0.96);
  text-shadow: 0 0 44px rgba(255, 170, 190, 0.18);
}

.heart-sub {
  margin: clamp(14px, 2vh, 20px) 0 0;
  font-size: 11px;
  letter-spacing: 0.54em;
  padding-left: 0.54em;
  color: rgba(255, 178, 198, 0.62);
  animation: heartSub 1.25s ease-in-out infinite;
}

.heart-glow {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 55%;
  width: min(74vw, 680px);
  aspect-ratio: 1.05;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 122, 168, 0.16) 0%, rgba(255, 122, 168, 0.06) 34%, rgba(109, 93, 246, 0.05) 56%, transparent 72%);
  animation: heartGlow 1.25s ease-in-out infinite;
  pointer-events: none;
}

.heart-action {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + clamp(62px, 9vh, 104px));
  transform: translate(-50%, 10px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 1.1s ease,
    transform 1.1s var(--ease-out),
    visibility 0s linear 1.1s;
}

.heart-action.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition:
    opacity 1.1s ease,
    transform 1.1s var(--ease-out),
    visibility 0s linear 0s;
}

.scene--heart.is-active .heart-copy {
  animation: sceneRise 1.4s var(--ease-out) 0.25s both;
}

/* --------------------------------------------------------------------------
   Act III — The Question
   -------------------------------------------------------------------------- */

.scene--question {
  display: grid;
  place-items: center;
  padding: clamp(120px, 16vh, 170px) 22px clamp(96px, 12vh, 130px);
}

.question-halo {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 50%;
  width: min(78vw, 900px);
  aspect-ratio: 1.5;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(ellipse at 50% 50%, rgba(255, 122, 168, 0.11), transparent 62%),
    radial-gradient(ellipse at 42% 60%, rgba(109, 93, 246, 0.11), transparent 68%);
  animation: haloBreathe 9s ease-in-out infinite;
  pointer-events: none;
}

.question-inner {
  position: relative;
  z-index: 2;
  width: min(900px, 100%);
  text-align: center;
}

.scene--question.is-active .question-inner > * {
  animation: sceneRise 1.25s var(--ease-out) both;
}

.scene--question.is-active .question-inner > *:nth-child(1) { animation-delay: 0.18s; }
.scene--question.is-active .question-inner > *:nth-child(2) { animation-delay: 0.3s; }
.scene--question.is-active .question-inner > *:nth-child(3) { animation-delay: 0.42s; }
.scene--question.is-active .question-inner > *:nth-child(4) { animation-delay: 0.54s; }
.scene--question.is-active .question-inner > *:nth-child(5) { animation-delay: 0.72s; }
.scene--question.is-active .question-inner > *:nth-child(6) { animation-delay: 0.86s; }

.question-inner .ornament { margin-top: clamp(16px, 2.6vh, 26px); }

.question-lead {
  margin: clamp(15px, 2.4vh, 22px) 0 0;
  font-size: clamp(12px, 1.2vw, 14px);
  letter-spacing: 0.22em;
  padding-left: 0.22em;
  color: var(--text-dim);
}

.question-title {
  margin: clamp(20px, 3.2vh, 32px) 0 0;
  font-size: clamp(38px, 5vw, 66px);
  font-weight: 600;
  line-height: 1.22;
  letter-spacing: 0.05em;
  color: #ffe3bc;
}

.question-title span { display: block; }
.question-title span:last-child {
  font-size: 1.06em;
  letter-spacing: 0.11em;
  padding-left: 0.11em;
  margin-top: 0.04em;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .question-title {
    background: linear-gradient(100deg, #fff2da 0%, #ffd9a0 24%, #ffb2ca 58%, #ffe8c6 88%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    filter: drop-shadow(0 0 30px rgba(255, 160, 190, 0.22));
    animation: titleShimmer 11s ease-in-out infinite;
  }
}

.question-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(14px, 2vw, 22px);
  margin-top: clamp(30px, 5vh, 50px);
}

.dodge-slot {
  width: 156px;
  height: 54px;
  flex: 0 0 auto;
}

.dodge-hint {
  margin: clamp(16px, 2.6vh, 22px) 0 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: rgba(230, 220, 255, 0.36);
  transition: color 0.3s ease;
}

/* --------------------------------------------------------------------------
   Act IV — Dawn & the letter
   -------------------------------------------------------------------------- */

.scene--dawn {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(90, 40, 50, 0.35) transparent;
  -webkit-overflow-scrolling: touch;
}

.scene--dawn::-webkit-scrollbar { width: 6px; }
.scene--dawn::-webkit-scrollbar-track { background: transparent; }
.scene--dawn::-webkit-scrollbar-thumb {
  background: rgba(90, 40, 50, 0.28);
  border-radius: 10px;
}

.dawn-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + clamp(70px, 11vh, 128px))
    clamp(16px, 5vw, 48px)
    calc(env(safe-area-inset-bottom) + clamp(38px, 6vh, 64px));
}

.dawn-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 8px;
}

.dawn-chapter {
  margin: 0 0 clamp(16px, 2.6vh, 24px);
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: rgba(255, 236, 214, 0.7);
}

.dawn-chapter .num {
  font-size: 13px;
  letter-spacing: 0.08em;
  color: rgba(255, 242, 220, 0.95);
}

.dawn-chapter .rule {
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 236, 214, 0.6), transparent);
  transform: rotate(180deg);
}

.dawn-chapter .lat {
  font-family: var(--font-latin);
  font-size: 9.5px;
  letter-spacing: 0.34em;
  color: rgba(255, 236, 214, 0.5);
}

.dawn-title {
  margin: 0;
  font-size: clamp(31px, 4.8vw, 58px);
  font-weight: 400;
  line-height: 1.28;
  letter-spacing: 0.06em;
  color: #fff5e6;
  text-shadow:
    0 0 46px rgba(255, 214, 168, 0.3),
    0 2px 2px rgba(60, 20, 30, 0.2);
}

.dawn-title .heart-sym {
  color: #ffd9b8;
  font-size: 0.88em;
  font-weight: 400;
}

.dawn-sub {
  margin: clamp(14px, 2.2vh, 20px) 0 0;
  font-size: clamp(12px, 1.3vw, 15px);
  letter-spacing: 0.2em;
  padding-left: 0.2em;
  color: rgba(255, 242, 230, 0.78);
}

.dawn-head .ornament {
  margin-top: clamp(20px, 3.2vh, 30px);
  color: rgba(255, 236, 208, 0.55);
}

.dawn-head .ornament span {
  background: linear-gradient(90deg, transparent, rgba(255, 236, 208, 0.42));
}

.dawn-head .ornament span:last-child {
  background: linear-gradient(270deg, transparent, rgba(255, 236, 208, 0.42));
}

.letter {
  position: relative;
  width: min(680px, calc(100vw - 32px));
  margin-top: clamp(34px, 5.6vh, 58px);
  padding:
    clamp(34px, 5vw, 52px)
    clamp(26px, 6vw, 64px)
    clamp(36px, 5vw, 56px);
  border-radius: 3px;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(255, 255, 255, 0.7), transparent 58%),
    linear-gradient(180deg, rgba(255, 242, 222, 0.6), rgba(246, 224, 200, 0.4));
  color: var(--paper-ink);
  box-shadow:
    0 34px 80px rgba(40, 10, 30, 0.36),
    0 6px 22px rgba(60, 20, 30, 0.2),
    inset 0 0 0 1px rgba(122, 74, 58, 0.08),
    inset 0 0 70px rgba(170, 120, 80, 0.08);
  isolation: isolate;
}

.letter::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background-image: var(--noise);
  background-size: 170px 170px;
  opacity: 0.65;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.letter::after {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: 0;
  border: 1px solid rgba(122, 74, 58, 0.09);
  border-radius: 1px;
  pointer-events: none;
}

.letter > * { position: relative; z-index: 1; }

.letter__mark {
  position: relative;
  width: min(232px, 72%);
  margin: -10px auto clamp(28px, 4vw, 38px);
  color: #7a4a3a;
}

.envelope-art {
  width: 100%;
  height: auto;
  opacity: 0.72;
}

.wax-seal {
  position: absolute;
  left: 50%;
  top: 73%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%) rotate(-5deg);
  border-radius: 47% 53% 49% 51% / 52% 47% 53% 48%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 36% 30%, #c9575f 0%, #ac323f 42%, #84212f 76%, #5f1523 100%);
  box-shadow:
    inset 0 2px 4px rgba(255, 184, 180, 0.4),
    inset 0 -5px 10px rgba(60, 8, 20, 0.5),
    0 7px 16px rgba(74, 24, 20, 0.35);
  color: rgba(255, 225, 208, 0.9);
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.38);
}

.wax-seal::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1px solid rgba(255, 208, 190, 0.34);
}

.wax-seal::after {
  content: "";
  position: absolute;
  left: 17%;
  top: 18%;
  width: 22%;
  height: 14%;
  border-radius: 50%;
  background: rgba(255, 215, 200, 0.28);
  transform: rotate(-24deg);
  filter: blur(1px);
}

.letter__greeting {
  margin: 0 0 clamp(20px, 3.2vh, 28px);
  font-family: var(--font-hand);
  font-size: clamp(20px, 2.4vw, 23px);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #42251f;
}

.letter__body {
  font-family: var(--font-hand);
  font-size: clamp(17px, 2.4vw, 18.5px);
  line-height: 2.05;
  letter-spacing: 0.02em;
  color: #4a2f2a;
}

.letter__body p {
  margin: 0 0 1.15em;
}

.letter__body p:last-child { margin-bottom: 0; }

.letter__sign {
  margin-top: clamp(22px, 3.6vh, 34px);
  text-align: right;
  font-family: var(--font-hand);
  font-size: clamp(16.5px, 2.3vw, 18px);
  line-height: 2;
  color: #4a2f2a;
}

.letter__sign p { margin: 0; }
.letter__sign p:first-child { color: #3f241f; }

.letter__sign .seal-heart {
  display: inline-block;
  margin-left: 0.25em;
  color: #a83a46;
  font-size: 0.9em;
}

.dawn-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: clamp(28px, 4.4vh, 40px);
}

.dawn-footer {
  margin-top: clamp(22px, 3.6vh, 32px);
  text-align: center;
}

.dawn-footer p {
  margin: 0;
  font-family: var(--font-latin);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: rgba(65, 32, 39, 0.58);
}

.scene--dawn.is-active .dawn-head { animation: dawnRise 1.5s var(--ease-out) 0.2s both; }
.scene--dawn.is-active .letter { animation: letterRise 2.1s var(--ease-out) 1s both; }
.scene--dawn.is-active .dawn-actions { animation: dawnRise 1.5s var(--ease-out) 1.55s both; }
.scene--dawn.is-active .dawn-footer { animation: dawnRise 1.5s var(--ease-out) 1.8s both; }

/* --------------------------------------------------------------------------
   Music toggle
   -------------------------------------------------------------------------- */

.music-toggle {
  position: fixed;
  z-index: 9;
  right: calc(env(safe-area-inset-right) + clamp(14px, 2.2vw, 22px));
  bottom: calc(env(safe-area-inset-bottom) + clamp(14px, 2.4vh, 22px));
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 217, 160, 0.28);
  background: rgba(8, 10, 24, 0.4);
  color: var(--gold);
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: border-color 0.35s ease, background 0.35s ease, transform 0.35s ease;
}

.music-toggle:hover {
  border-color: rgba(255, 217, 160, 0.64);
  background: rgba(20, 16, 51, 0.55);
}

.music-toggle::after {
  content: "";
  position: absolute;
  width: 19px;
  height: 1px;
  background: rgba(255, 217, 160, 0.78);
  transform: rotate(-45deg);
  transition: opacity 0.3s ease;
}

.music-toggle.is-playing::after { opacity: 0; }

.music-bars {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 15px;
}

.music-bars i {
  display: block;
  width: 2px;
  height: 4px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.55;
  transition: height 0.35s ease, opacity 0.35s ease;
}

.music-toggle.is-playing .music-bars i {
  opacity: 0.95;
  animation: equalizer 1.15s ease-in-out infinite;
}

.music-toggle.is-playing .music-bars i:nth-child(1) { animation-delay: 0s; height: 9px; }
.music-toggle.is-playing .music-bars i:nth-child(2) { animation-delay: 0.18s; height: 14px; animation-duration: 0.93s; }
.music-toggle.is-playing .music-bars i:nth-child(3) { animation-delay: 0.34s; height: 7px; animation-duration: 1.28s; }
.music-toggle.is-playing .music-bars i:nth-child(4) { animation-delay: 0.1s; height: 11px; animation-duration: 1.05s; }
