:root {
  color-scheme: light;
  --paper: #fff9f6;
  --paper-deep: #fdecea;
  --ink: #4a3640;
  --muted: #7d5964;
  --rose: #c84d70;
  --rose-dark: #873045;
  --peach: #f4c9be;
  --sage: #758f67;
  --lavender: #c9bfd9;
  --sky: #d9eaf2;
  --gold: #b88749;
  --shadow: rgba(83, 45, 57, 0.18);
  --soft-shadow: rgba(83, 45, 57, 0.1);
  --font-serif: Georgia, "Times New Roman", serif;
  --font-script: "Segoe Print", "Bradley Hand ITC", cursive;
  --font-ui: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  min-height: 100%;
  background: #f8eef2;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    linear-gradient(135deg, rgba(217, 234, 242, 0.78), transparent 36%),
    linear-gradient(225deg, rgba(201, 191, 217, 0.55), transparent 42%),
    #fff5f3;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

img,
svg,
canvas {
  max-width: 100%;
}

button,
a {
  font: inherit;
}

button {
  border: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 3px solid var(--sage);
  outline-offset: 4px;
}

.app {
  position: relative;
  height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
}

.scene {
  height: 100dvh;
  min-height: 100vh;
  padding: 32px;
  position: relative;
  overflow: hidden;
}

.intro {
  display: grid;
  place-items: center;
}

.intro-grid {
  width: min(1120px, 100%);
  min-height: min(680px, calc(100vh - 64px));
  display: grid;
  grid-template-columns: minmax(300px, 520px) minmax(280px, 1fr);
  align-items: center;
  gap: 56px;
}

.intro-copy {
  position: relative;
  z-index: 2;
}

.kicker {
  margin: 0 0 14px;
  color: var(--rose-dark);
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--rose-dark);
  font-family: var(--font-script);
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  max-width: 680px;
  font-size: 4.6rem;
  line-height: 0.98;
}

h2 {
  font-size: 2.7rem;
  line-height: 1.06;
}

.intro-line {
  max-width: 520px;
  margin: 26px 0 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  line-height: 1.55;
}

.primary-action,
.ghost-action,
.icon-action,
.download-link {
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 220ms ease,
    box-shadow 220ms ease,
    background 220ms ease,
    color 220ms ease;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 30px;
  padding: 13px 22px;
  color: #fff;
  background: var(--rose-dark);
  box-shadow: 0 16px 34px var(--shadow);
  font-weight: 800;
}

.ghost-action {
  padding: 12px 18px;
  color: var(--rose-dark);
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(135, 48, 69, 0.2);
  font-weight: 800;
}

.primary-action:hover,
.ghost-action:hover,
.icon-action:hover,
.download-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 32px var(--shadow);
}

.primary-action:active,
.ghost-action:active,
.icon-action:active,
.download-link:active {
  transform: translateY(1px) scale(0.98);
}

.envelope-wrap {
  display: grid;
  place-items: center;
  min-height: 420px;
  perspective: 1100px;
}

.envelope {
  position: relative;
  width: min(88vw, 470px);
  aspect-ratio: 1.42;
  filter: drop-shadow(0 28px 34px var(--shadow));
  transform-style: preserve-3d;
  transform: rotate(-2deg);
  transition: transform 900ms cubic-bezier(0.2, 1, 0.2, 1);
}

.envelope.is-open {
  transform: rotate(1deg) translateY(-16px);
}

.envelope-back,
.envelope-front,
.envelope-left,
.envelope-right,
.envelope-flap,
.letter-peek {
  position: absolute;
  inset: 0;
  border-radius: 8px;
}

.envelope-back {
  background: #ffdcd3;
  border: 2px solid rgba(135, 48, 69, 0.16);
}

.letter-peek {
  left: 9%;
  right: 9%;
  top: 12%;
  height: 70%;
  background: var(--paper);
  border: 2px solid rgba(200, 77, 112, 0.28);
  display: grid;
  place-items: start center;
  padding-top: 38px;
  font-family: var(--font-script);
  font-size: 2rem;
  color: var(--rose-dark);
  transform: translateY(42%);
  transition: transform 900ms cubic-bezier(0.2, 1, 0.2, 1);
}

.envelope.is-open .letter-peek {
  transform: translateY(-32%);
}

.envelope-front {
  top: 33%;
  background: #f9bfb6;
  clip-path: polygon(0 0, 50% 62%, 100% 0, 100% 100%, 0 100%);
}

.envelope-left {
  top: 33%;
  background: #f5aba7;
  clip-path: polygon(0 0, 50% 62%, 0 100%);
}

.envelope-right {
  top: 33%;
  background: #f6b5af;
  clip-path: polygon(100% 0, 50% 62%, 100% 100%);
}

.envelope-flap {
  top: 0;
  height: 54%;
  background: #ffc8c0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0%;
  transition: transform 900ms cubic-bezier(0.2, 1, 0.2, 1);
  z-index: 5;
}

.envelope.is-open .envelope-flap {
  transform: rotateX(170deg);
}

.wax {
  position: absolute;
  left: 50%;
  top: 58%;
  z-index: 6;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--rose);
  color: #fff;
  font-family: var(--font-script);
  font-size: 1.6rem;
  font-weight: 800;
  transform: translate(-50%, -50%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.28);
}

.panel {
  display: none;
}

.reader {
  height: 100dvh;
  padding: 28px;
  overflow: hidden;
}

.reader.is-visible {
  display: block;
}

.reader-layout {
  width: min(1080px, 100%);
  height: calc(100dvh - 56px);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 22px;
}

.panel.is-current {
  display: grid;
  min-height: 0;
  animation: panelIn 520ms ease both;
}

.progress-shell {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: 6px;
  background: rgba(255, 255, 255, 0.58);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--rose);
  transition: width 280ms ease;
}

.chapter-list {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.chapter-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(135, 48, 69, 0.24);
  cursor: pointer;
  transition: transform 220ms ease, background 220ms ease;
}

.chapter-dot.is-active {
  background: var(--rose-dark);
  transform: scale(1.22);
}

.paper,
.final-copy {
  width: min(820px, 100%);
  height: min(660px, calc(100dvh - 88px));
  min-height: 0;
  margin: 0 auto;
  padding: 54px;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(90deg, rgba(184, 135, 73, 0.08) 0 1px, transparent 1px),
    var(--paper);
  background-size: 34px 100%;
  border: 2px solid rgba(200, 77, 112, 0.23);
  border-radius: 8px;
  box-shadow: 0 24px 60px var(--soft-shadow);
}

.paper h2,
.final-copy h2 {
  margin-bottom: 28px;
}

.letter-text {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.letter-text p,
.final-copy p {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-size: 1.16rem;
  line-height: 1.64;
}

.letter-text p {
  opacity: 0;
  transform: translateY(10px);
  animation: textIn 420ms ease both;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  gap: 12px;
  margin-top: 18px;
}

.reader-actions.centered {
  justify-content: center;
}

.deck-shell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
}

.deck-shadow {
  position: absolute;
  width: min(390px, 78vw);
  aspect-ratio: 0.67;
  border-radius: 8px;
  background: rgba(135, 48, 69, 0.08);
  transform: rotate(4deg) translate(14px, 12px);
  box-shadow: 0 32px 72px var(--shadow);
}

.love-card {
  position: relative;
  width: min(390px, 78vw);
  aspect-ratio: 0.67;
  padding: 34px 32px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  align-items: center;
  overflow: hidden;
  background: var(--paper);
  border: 4px solid var(--rose);
  border-radius: 8px;
  box-shadow: 0 26px 66px var(--shadow);
  transform-origin: center;
}

.love-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px solid var(--peach);
  border-radius: 8px;
  pointer-events: none;
}

.love-card.is-flipping {
  animation: cardFlip 520ms cubic-bezier(0.2, 1, 0.2, 1);
}

.card-heading {
  margin: 0;
  text-align: center;
  color: var(--rose-dark);
  font-family: var(--font-script);
  font-size: 1.7rem;
  font-weight: 800;
}

.card-number {
  position: absolute;
  top: 30px;
  right: 30px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--rose);
  font-weight: 900;
  box-shadow: inset 0 0 0 2px rgba(135, 48, 69, 0.4);
}

.card-message {
  position: relative;
  z-index: 2;
  display: grid;
  align-content: center;
  gap: 16px;
  min-height: 320px;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 1.45rem;
  line-height: 1.28;
}

.card-message p {
  margin: 0;
}

.card-message p:nth-child(1) {
  animation: lineReveal 360ms ease both;
}

.card-message p:nth-child(2) {
  animation: lineReveal 460ms ease 90ms both;
}

.card-message p:nth-child(3) {
  animation: lineReveal 520ms ease 160ms both;
}

.card-message p:nth-child(4) {
  animation: lineReveal 580ms ease 220ms both;
}

.card-footer {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.tiny-heart {
  position: absolute;
  left: 34px;
  bottom: 32px;
  color: var(--rose);
}

.card-flower {
  position: absolute;
  width: 62px;
  height: 72px;
  pointer-events: none;
}

.card-flower.top-left {
  top: 36px;
  left: 34px;
}

.card-flower.bottom-right {
  right: 34px;
  bottom: 28px;
  transform: rotate(180deg);
}

.card-flower::before,
.card-flower::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 20px;
  height: 34px;
  border-radius: 50%;
  background: var(--sage);
}

.card-flower::before {
  left: 8px;
  transform: rotate(9deg);
}

.card-flower::after {
  right: 4px;
  transform: rotate(-9deg);
}

.card-flower span {
  position: absolute;
  left: 17px;
  top: 1px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f3becd;
  border: 2px solid var(--rose-dark);
}

.card-flower span::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 8px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--rose);
}

.deck-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.icon-action {
  width: 54px;
  height: 54px;
  color: #fff;
  background: var(--rose-dark);
  font-size: 1.3rem;
  font-weight: 900;
  box-shadow: 0 14px 28px var(--shadow);
}

.card-counter {
  min-width: 92px;
  color: var(--rose-dark);
  text-align: center;
  font-weight: 900;
}

.final-stage {
  text-align: center;
}

.final-copy {
  display: grid;
  align-content: center;
  justify-items: center;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  color: var(--rose-dark);
  background: #fff;
  border: 1px solid rgba(135, 48, 69, 0.2);
  font-weight: 800;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.petal {
  position: absolute;
  width: 18px;
  height: 26px;
  border-radius: 70% 30% 70% 30%;
  background: rgba(200, 77, 112, 0.22);
  animation: floatPetal 14s linear infinite;
}

.p1 { left: 8%; animation-delay: -1s; animation-duration: 16s; }
.p2 { left: 24%; animation-delay: -7s; animation-duration: 18s; background: rgba(117, 143, 103, 0.2); }
.p3 { left: 44%; animation-delay: -3s; animation-duration: 15s; background: rgba(201, 191, 217, 0.34); }
.p4 { left: 63%; animation-delay: -9s; animation-duration: 19s; }
.p5 { left: 78%; animation-delay: -5s; animation-duration: 17s; background: rgba(217, 234, 242, 0.56); }
.p6 { left: 91%; animation-delay: -12s; animation-duration: 20s; background: rgba(117, 143, 103, 0.2); }

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

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

@keyframes lineReveal {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cardFlip {
  0% { transform: rotateY(0deg) translateY(0); }
  48% { transform: rotateY(82deg) translateY(-10px); }
  100% { transform: rotateY(0deg) translateY(0); }
}

@keyframes floatPetal {
  0% {
    transform: translate3d(0, -12vh, 0) rotate(0deg);
    opacity: 0;
  }
  12% { opacity: 1; }
  100% {
    transform: translate3d(22px, 112vh, 0) rotate(260deg);
    opacity: 0;
  }
}

@media (max-width: 760px) {
  .scene {
    height: 100dvh;
    padding: 18px 14px;
  }

  .intro-grid {
    width: 100%;
    max-width: 100%;
    min-height: auto;
    grid-template-columns: 1fr;
    gap: 10px;
    text-align: center;
    justify-items: center;
    overflow: hidden;
  }

  .envelope-wrap {
    width: 100%;
    min-height: 245px;
    overflow: hidden;
    align-items: end;
    justify-items: center;
  }

  .envelope {
    width: min(260px, 68vw);
    margin-inline: auto;
    transform: none;
  }

  .envelope.is-open {
    transform: translateY(-8px);
  }

  .letter-peek {
    font-size: 1.45rem;
    padding-top: 26px;
  }

  .wax {
    width: 48px;
    height: 48px;
    font-size: 1.35rem;
  }

  h1 {
    max-width: 330px;
    margin-inline: auto;
    font-size: 2.42rem;
    line-height: 1.04;
  }

  h2 {
    font-size: 1.82rem;
    line-height: 1.08;
  }

  .intro-line {
    max-width: 318px;
    margin-left: auto;
    margin-right: auto;
    font-size: 1.04rem;
    line-height: 1.45;
  }

  .primary-action {
    margin-top: 22px;
  }

  .reader {
    height: 100dvh;
    padding: 14px 12px 12px;
  }

  .reader-layout {
    position: relative;
    grid-template-columns: 1fr;
    gap: 0;
    height: calc(100dvh - 26px);
    min-height: 0;
    align-items: stretch;
  }

  .panel.is-current {
    width: 100%;
    animation: none;
    justify-items: center;
  }

  .letter-text p {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .chapter-list {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    grid-auto-flow: column;
    justify-content: center;
    z-index: 5;
  }

  .paper,
  .final-copy {
    width: min(300px, calc(100vw - 52px));
    height: calc(100dvh - 58px);
    min-height: 0;
    padding: 24px 18px 54px;
  }

  .paper h2,
  .final-copy h2 {
    max-width: 100%;
    margin-bottom: 14px;
    overflow-wrap: break-word;
  }

  .letter-text p,
  .final-copy p {
    font-size: 1rem;
    line-height: 1.48;
  }

  .reader-actions {
    justify-content: center;
    margin-top: 12px;
  }

  .ghost-action,
  .primary-action {
    min-height: 46px;
    padding: 11px 15px;
    font-size: 0.92rem;
  }

  .cards-stage.is-current {
    grid-template-rows: minmax(0, 1fr) auto auto;
    align-content: center;
    gap: 8px;
  }

  .deck-shell {
    min-height: 0;
    align-items: center;
  }

  .deck-shadow {
    width: min(326px, 84vw, calc((100dvh - 178px) * 0.67));
  }

  .love-card {
    width: min(326px, 84vw, calc((100dvh - 178px) * 0.67));
    padding: 28px 22px 22px;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .card-message {
    min-height: 0;
    align-self: center;
    font-size: 1.05rem;
    gap: 10px;
  }

  .card-heading {
    display: none;
  }

  .card-number {
    display: none;
    width: 34px;
    height: 34px;
    top: 18px;
    right: 18px;
    font-size: 0.92rem;
  }

  .card-flower {
    transform: scale(0.64);
    transform-origin: top left;
  }

  .card-flower.top-left {
    display: none;
  }

  .card-flower.bottom-right {
    transform: rotate(180deg) scale(0.64);
    transform-origin: center;
  }

  .deck-controls {
    margin-top: 0;
  }

  .icon-action {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 420px) {
  h1 {
    max-width: 300px;
    font-size: 2.2rem;
  }

  .paper,
  .final-copy {
    height: calc(100dvh - 54px);
    padding: 22px 16px 50px;
  }

  .envelope-wrap {
    min-height: 210px;
  }

  .envelope {
    width: min(238px, 64vw);
  }

  .card-message {
    font-size: 0.98rem;
  }

  .love-card {
    width: min(300px, 82vw, calc((100dvh - 166px) * 0.67));
  }
}

@media (max-height: 680px) and (max-width: 760px) {
  h2 {
    font-size: 1.58rem;
  }

  .paper,
  .final-copy {
    padding-top: 18px;
    padding-bottom: 44px;
  }

  .kicker {
    margin-bottom: 8px;
    font-size: 0.76rem;
  }

  .letter-text p,
  .final-copy p {
    font-size: 0.92rem;
    line-height: 1.42;
  }

  .reader-actions {
    margin-top: 8px;
  }

  .ghost-action,
  .primary-action {
    min-height: 42px;
    padding: 9px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
