/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --ink: #3f2a34;
  --muted: #8d6675;
  --rose-900: #67263f;
  --rose-700: #a63f62;
  --rose-500: #ef6d92;
  --rose-300: #ffc0cf;
  --rose-100: #fff1f5;
  --cream: #fffaf4;
  --paper: rgba(255, 252, 248, 0.88);
  --paper-strong: rgba(255, 252, 248, 0.96);
  --line: rgba(166, 63, 98, 0.13);
  --shadow: 0 28px 90px rgba(103, 38, 63, 0.16);
  --shadow-soft: 0 18px 46px rgba(103, 38, 63, 0.1);
  --display-font: "LemiXiaoxiong", "Ma Shan Zheng", "Noto Serif SC", serif;
}

@font-face {
  font-family: "LemiXiaoxiong";
  src: url("../font/乐米小熊日记体.ttf") format("truetype");
  font-display: swap;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: "Noto Serif SC", "PingFang SC", "Microsoft YaHei", serif;
  background:
    linear-gradient(rgba(255, 244, 248, 0.54), rgba(255, 244, 248, 0.54)),
    url("../images/romantic-paper-bg.png") center / cover fixed no-repeat,
    #fff3f7;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

img {
  display: block;
  max-width: 100%;
}

.svg-defs {
  position: absolute;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Page System ===== */
.page {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  isolation: isolate;
}

.page.active {
  display: flex;
  opacity: 1;
  z-index: 100;
}

.scene-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.opening-bg {
  background:
    linear-gradient(rgba(255, 244, 248, 0.42), rgba(255, 244, 248, 0.42)),
    url("../images/romantic-paper-bg.png") center / cover no-repeat;
}

.opening-bg::before,
.opening-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../images/petal-sprites.png");
  background-repeat: no-repeat;
  background-size: min(72vw, 760px) auto;
  opacity: 0.13;
  filter: blur(0.2px);
}

.opening-bg::before {
  background-position: -12vw 7vh;
}

.opening-bg::after {
  background-position: calc(100% + 16vw) calc(100% + 8vh);
  transform: rotate(180deg);
}

/* ===== Loading Heart ===== */
.loading-panel {
  width: min(92vw, 440px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.heart-container {
  position: relative;
  width: clamp(180px, 34vw, 250px);
  aspect-ratio: 1;
  color: var(--rose-500);
  cursor: default;
  filter: drop-shadow(0 26px 42px rgba(239, 109, 146, 0.24));
}

.heart {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: url(#heart-clip);
  background: rgba(255, 238, 244, 0.7);
}

.heart-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  overflow: hidden;
  background:
    linear-gradient(0deg, #d92b58 0%, #ef5d87 42%, #ff9daf 74%, #ffd9c8 100%);
  box-shadow: inset 0 14px 18px rgba(255, 255, 255, 0.12);
}

.heart-outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.wave-svg {
  position: absolute;
  top: -16px;
  left: 0;
  width: 200%;
  height: 36px;
  filter: saturate(1.06);
}

.wave-svg-1 {
  animation: wave-drift 2.9s linear infinite, wave-bob 2.1s ease-in-out infinite;
}

.wave-svg-2 {
  top: -10px;
  opacity: 0.72;
  animation: wave-drift 4.1s linear infinite reverse, wave-bob 2.8s ease-in-out infinite reverse;
}

.heart-container.pulse {
  cursor: pointer;
}

.heart-container.complete .heart-fill {
  height: calc(100% + 12px);
  bottom: -4px;
}

.heart-container.pulse .heart-outline,
.heart-container.pulse .heart {
  animation: heart-pulse 1.45s ease-in-out infinite;
}

.heart-container:focus-visible,
.password-heart:focus-visible,
.answer-slot:focus-visible,
.choice-grid button:focus-visible,
.play-btn:focus-visible,
.progress-bar:focus-visible {
  outline: 3px solid rgba(239, 109, 146, 0.34);
  outline-offset: 5px;
}

@keyframes wave-drift {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

@keyframes wave-bob {
  0%, 100% { transform: translateX(0) translateY(0); }
  50% { transform: translateX(0) translateY(-5px); }
}

@keyframes heart-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.055); }
}

/* ===== Password ===== */
.password-card {
  width: min(90vw, 500px);
  padding: clamp(28px, 7vw, 50px);
  display: grid;
  justify-items: center;
  gap: 22px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 253, 250, 0.88), rgba(255, 244, 248, 0.76));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  animation: fade-in-up 0.48s ease forwards;
}

.password-heart {
  width: 118px;
  height: 118px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--rose-500);
  background: rgba(255, 255, 255, 0.54);
  box-shadow: 0 18px 40px rgba(239, 109, 146, 0.22);
  transition: color 0.18s ease, transform 0.22s ease;
}

.password-heart path {
  fill: currentColor;
}

.password-heart.shake {
  color: #dc244f;
  animation: shake-anim 0.48s ease;
}

.password-heart.zoom {
  animation: zoom-heart 0.72s ease forwards;
}

.password-heart.center-expand {
  position: fixed;
  left: 50%;
  top: 50%;
  margin: 0;
  z-index: 220;
  pointer-events: none;
  transform-origin: center center;
  animation: heart-center-expand 3.8s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.password-heart.center-expand path {
  fill: currentColor;
}

.password-content {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 18px;
}

.password-content h2 {
  color: var(--rose-900);
  font-family: var(--display-font);
  font-size: clamp(1.45rem, 5vw, 2rem);
  font-weight: 600;
  line-height: 1.35;
}

.answer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 2px;
}

.answer-slots {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  justify-content: center;
  gap: 12px;
  margin-top: 0;
}

.answer-slot {
  width: 54px;
  height: 58px;
  border: 0;
  border-bottom: 2px solid rgba(166, 63, 98, 0.45);
  border-radius: 12px 12px 6px 6px;
  display: grid;
  place-items: center;
  color: var(--rose-900);
  background: rgba(255, 255, 255, 0.42);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.answer-slot.filled {
  border-color: var(--rose-500);
  background: rgba(255, 255, 255, 0.78);
}

.back-btn {
  width: 46px;
  min-width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(166, 63, 98, 0.16);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--rose-700);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 22px rgba(103, 38, 63, 0.08);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.back-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 24px rgba(103, 38, 63, 0.1);
}

.back-btn:disabled {
  opacity: 0.42;
}

.choice-grid {
  width: min(100%, 372px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.choice-grid button {
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(166, 63, 98, 0.12);
  border-radius: 16px;
  color: var(--rose-900);
  background: rgba(255, 255, 255, 0.64);
  box-shadow: 0 10px 22px rgba(103, 38, 63, 0.06);
  font-size: clamp(1.05rem, 5vw, 1.28rem);
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.choice-grid button:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 26px rgba(103, 38, 63, 0.1);
}

.choice-grid button.picked,
.choice-grid button:disabled {
  opacity: 0.42;
  transform: none;
}

.wrong-hint {
  min-height: 1.5em;
  color: #c7224b;
  font-size: 0.95rem;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.wrong-hint.show {
  opacity: 1;
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake-anim {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

@keyframes zoom-heart {
  0% { transform: scale(1); opacity: 1; }
  58% { transform: scale(2.55); opacity: 0.95; }
  100% { transform: scale(7.5); opacity: 0; }
}

@keyframes heart-center-expand {
  0% {
    transform: translate(-50%, -50%) scale(0.08);
    opacity: 0;
  }
  12% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  66% {
    transform: translate(-50%, -50%) scale(28);
    opacity: 1;
  }
  80% {
    transform: translate(-50%, -50%) scale(34);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(34);
    opacity: 0;
  }
}

/* ===== Letter Page ===== */
#content-page {
  align-items: stretch;
  justify-content: flex-start;
}

#petals-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.content-scroll {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(166, 63, 98, 0.28) transparent;
  scrollbar-width: thin;
}

.content-scroll::-webkit-scrollbar {
  width: 7px;
}

.content-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(166, 63, 98, 0.28);
}

.letter-stage {
  width: min(100% - 28px, 840px);
  margin: 0 auto;
  padding: clamp(30px, 7vw, 72px) 0 0;
}

.letter-hero {
  min-height: clamp(390px, 66svh, 620px);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

.letter-hero-art {
  width: clamp(160px, 30vw, 290px);
  filter: drop-shadow(0 24px 34px rgba(103, 38, 63, 0.15));
  animation: art-float 6.4s ease-in-out infinite;
}

.letter-hero h1 {
  color: var(--rose-900);
  font-family: var(--display-font);
  font-size: clamp(3.4rem, 12vw, 7rem);
  font-weight: 400;
  line-height: 1;
}

.letter-hero p {
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  font-weight: 500;
}

.letter-paper {
  position: relative;
  padding: clamp(30px, 7vw, 64px);
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 22px;
  background:
    linear-gradient(rgba(255, 252, 248, 0.9), rgba(255, 252, 248, 0.95)),
    repeating-linear-gradient(0deg, transparent 0, transparent 35px, rgba(166, 63, 98, 0.04) 36px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.letter-paper::before {
  content: "";
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(166, 63, 98, 0.08);
  border-radius: 16px;
  pointer-events: none;
}

.letter-paper .letter-p {
  position: relative;
  max-width: 700px;
  margin-inline: auto;
  color: #49323c;
  font-size: clamp(1.02rem, 1.8vw, 1.15rem);
  line-height: 2.15;
  text-align: left;
}

.letter-paper .letter-p + .letter-p {
  margin-top: 1.14em;
}

.letter-figure {
  width: min(310px, 74%);
  margin: clamp(24px, 6vw, 38px) auto;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.letter-figure img {
  width: 100%;
  filter: drop-shadow(0 20px 28px rgba(103, 38, 63, 0.12));
}

.letter-figure figcaption {
  color: rgba(141, 102, 117, 0.86);
  font-size: 0.86rem;
  line-height: 1.7;
  text-align: center;
}

.final-wish {
  margin-top: 30px !important;
  color: var(--rose-700) !important;
  font-family: var(--display-font);
  font-size: clamp(2.1rem, 7vw, 3.6rem) !important;
  line-height: 1.3 !important;
  text-align: center !important;
}

.letter-closing {
  position: relative;
  max-width: 700px;
  margin: 34px auto 0;
  color: var(--rose-700);
  line-height: 1.9;
  text-align: right;
}

.letter-closing strong {
  color: var(--rose-900);
  font-weight: 700;
}

.fade-in-p {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.62s ease, transform 0.62s ease;
}

.fade-in-p.visible {
  opacity: 1;
  transform: translateY(0);
}

.letter-footer-spacer {
  height: 110px;
}

@keyframes art-float {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50% { transform: translateY(-12px) rotate(1.2deg); }
}

/* ===== Audio Player ===== */
.audio-player {
  position: fixed;
  left: 50%;
  bottom: 16px;
  z-index: 140;
  width: min(560px, calc(100% - 28px));
  min-height: 54px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  background: rgba(255, 252, 248, 0.84);
  box-shadow: 0 16px 40px rgba(103, 38, 63, 0.13);
  backdrop-filter: blur(16px);
  opacity: 0;
  transform: translate(-50%, 110%);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.audio-player.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.play-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: #fff;
  background: var(--rose-500);
  box-shadow: 0 12px 22px rgba(239, 109, 146, 0.28);
  transition: transform 0.2s ease, background 0.2s ease;
}

.play-btn:hover {
  transform: translateY(-1px);
  background: var(--rose-700);
}

.time-current,
.time-total {
  min-width: 34px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  position: relative;
  flex: 1;
  height: 20px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: none;
}

.progress-bar::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 5px;
  border-radius: 999px;
  background: rgba(166, 63, 98, 0.16);
  transform: translateY(-50%);
}

.progress-fill {
  position: absolute;
  top: 50%;
  left: 0;
  width: 0%;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f4a3b9, var(--rose-500));
  transform: translateY(-50%);
  pointer-events: none;
}

.progress-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--rose-500);
  box-shadow: 0 4px 12px rgba(103, 38, 63, 0.2);
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.progress-bar:hover .progress-handle,
.progress-bar.dragging .progress-handle {
  opacity: 1;
}

/* ===== Responsive ===== */
@media (max-width: 680px) {
  .loading-panel {
    width: min(94vw, 340px);
  }

  .heart-container {
    width: clamp(170px, 54vw, 226px);
  }

  .password-card {
    border-radius: 24px;
  }

  .password-heart {
    width: 104px;
    height: 104px;
  }

  .answer-slots {
    grid-template-columns: repeat(3, 48px);
    gap: 10px;
  }

  .answer-slot {
    width: 48px;
    height: 54px;
  }

  .choice-grid {
    gap: 8px;
  }

  .choice-grid button {
    border-radius: 14px;
  }

  .letter-stage {
    width: min(100% - 20px, 840px);
    padding-top: 26px;
  }

  .letter-hero {
    min-height: 58svh;
  }

  .letter-paper {
    padding: 30px 20px;
    border-radius: 20px;
  }

  .letter-paper::before {
    inset: 12px;
  }

  .letter-paper .letter-p {
    line-height: 2.04;
  }

  .letter-figure {
    width: min(280px, 86%);
  }

  .audio-player {
    bottom: 10px;
    min-height: 52px;
    padding: 7px 9px;
    gap: 7px;
  }

  .time-current,
  .time-total {
    min-width: 30px;
    font-size: 0.72rem;
  }
}

@media (max-width: 380px) {
  .password-card {
    width: calc(100% - 20px);
    padding-inline: 20px;
  }

  .choice-grid {
    width: 100%;
  }

  .audio-player {
    border-radius: 20px;
  }
}

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