/* ========================================
   艺术馆私人信件 — 视觉系统 v3
   ======================================== */

:root {
  /* 纸张 */
  --paper: #f8f6f2;
  --paper-warm: #f2efe8;
  --paper-sheet: #faf8f4;
  --paper-texture: rgba(30, 58, 95, 0.03);

  /* 文字 */
  --ink: #1e3a5f;
  --ink-light: #4a6280;
  --ink-muted: #8a9bb0;

  /* 辅助蓝 */
  --blue: #6b8fae;
  --blue-wash: rgba(107, 143, 174, 0.12);
  --blue-brush: rgba(107, 143, 174, 0.08);

  /* 封蜡 */
  --seal: #8b3a3a;
  --seal-dark: #6b2d2d;

  /* 信封纸张（与信纸统一） */
  --envelope-paper: var(--paper-sheet);
  --envelope-shadow: rgba(30, 58, 95, 0.1);

  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-letter: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --transition-soft: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 1s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-paper: 0 2px 24px rgba(30, 58, 95, 0.07), 0 1px 4px rgba(30, 58, 95, 0.04);
  --shadow-paper-deep: 0 8px 40px rgba(30, 58, 95, 0.1), 0 2px 8px rgba(30, 58, 95, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  overflow: hidden;
  width: 100%;
  height: 100dvh;
  height: 100vh;
  position: fixed;
  inset: 0;
}

/* ---- 统一艺术纸背景 ---- */
#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 40% at 15% 10%, var(--blue-brush) 0%, transparent 70%),
    radial-gradient(ellipse 50% 35% at 85% 90%, var(--blue-brush) 0%, transparent 65%),
    linear-gradient(175deg, var(--paper) 0%, var(--paper-warm) 100%);
}

#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.45;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 180px 180px;
}

#app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 3px,
      var(--paper-texture) 3px,
      var(--paper-texture) 4px
    );
  opacity: 0.5;
}

/* ---- Scenes ---- */
.scene {
  position: absolute;
  inset: 0;
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
  padding: calc(20px + var(--safe-top)) calc(16px + var(--safe-right))
           calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

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

.scene-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* ---- 信纸组件 ---- */
.paper-sheet {
  background: var(--paper-sheet);
  box-shadow: var(--shadow-paper);
  border: 1px solid rgba(30, 58, 95, 0.07);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.paper-sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.5) 0%, transparent 50%),
    repeating-linear-gradient(0deg, transparent, transparent 28px, rgba(30,58,95,0.025) 28px, rgba(30,58,95,0.025) 29px);
}

.paper-sheet--quiz {
  width: min(420px, 92vw);
  padding: 36px 28px 32px;
  transform-origin: center center;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.6s ease;
}

.paper-sheet--letter {
  width: min(440px, 92vw);
  max-height: min(78vh, 640px);
  padding: 36px 32px;
  transform-origin: center center;
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.8s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.paper-sheet--letter.is-folding {
  animation: letter-fold 1.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes letter-fold {
  0% { transform: scale(1) rotateX(0deg); opacity: 1; }
  40% { transform: scale(0.85) rotateX(8deg); opacity: 0.9; }
  70% { transform: scale(0.35) rotateX(20deg) translateY(40px); opacity: 0.6; }
  100% { transform: scale(0.12) rotateX(30deg) translateY(80px); opacity: 0; }
}

/* ---- Music Toggle（保持不变） ---- */
.music-toggle {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  z-index: 1000;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(248, 246, 242, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--ink-light);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  transition: opacity 0.3s;
  box-shadow: 0 1px 6px rgba(30, 58, 95, 0.08);
}

.music-toggle.is-playing { opacity: 0.7; }

.music-icon--on { display: none; }

.music-toggle.is-playing .music-icon--off { display: none; }

.music-toggle.is-playing .music-icon--on {
  display: inline;
  animation: music-pulse 2s ease-in-out infinite;
}

@keyframes music-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ========================================
   Scene 1: Envelope
   ======================================== */
.envelope-scene {
  background: transparent;
}

.envelope-wrapper {
  perspective: 900px;
  perspective-origin: center 40%;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: opacity 0.6s ease;
}

.envelope-wrapper.is-disabled {
  pointer-events: none;
  cursor: default;
}

.envelope {
  position: relative;
  width: min(280px, 72vw);
  height: min(180px, 46vw);
  animation: envelope-float 3.5s ease-in-out infinite;
  transform-style: preserve-3d;
  transition: transform 0.8s ease, opacity 0.8s ease;
}

@keyframes envelope-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.envelope__back {
  position: absolute;
  inset: 0;
  background: var(--envelope-paper);
  border-radius: 3px;
  box-shadow: var(--shadow-paper-deep);
  border: 1px solid rgba(30, 58, 95, 0.08);
}

.envelope__front {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58%;
  background: linear-gradient(180deg, #ede9e1 0%, #e8e3da 100%);
  border-radius: 0 0 3px 3px;
  z-index: 3;
  box-shadow: inset 0 6px 10px -6px rgba(30, 58, 95, 0.07);
}

.envelope__flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 52%;
  background: var(--envelope-paper);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  z-index: 4;
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 6px var(--envelope-shadow);
  border-top: 1px solid rgba(30, 58, 95, 0.06);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.envelope__seal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  background: radial-gradient(circle at 35% 35%, #a04545, var(--seal));
  border-radius: 50%;
  z-index: 5;
  transition: opacity 0.5s, transform 0.5s;
  box-shadow: 0 2px 8px rgba(139, 58, 58, 0.25);
}

.envelope__letter {
  position: absolute;
  top: 10%;
  left: 9%;
  right: 9%;
  height: 72%;
  z-index: 2;
  transform: translateY(0);
  transition: transform 1.1s cubic-bezier(0.4, 0, 0.2, 1) 0.35s;
}

.envelope__letter-paper {
  width: 100%;
  height: 100%;
  background: var(--paper-sheet);
  border-radius: 1px;
  box-shadow: 0 1px 4px rgba(30, 58, 95, 0.06);
  border: 1px solid rgba(30, 58, 95, 0.05);
}

/* 打开 — 蜡封消失 → 顶部封口向上翻开 → 信纸升起 */
.envelope.is-opening .envelope__flap {
  transform: rotateX(-105deg);
  z-index: 1;
}

.envelope.is-opening .envelope__seal {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  transition-delay: 0s;
}

.envelope.is-opening .envelope__letter {
  transform: translateY(-120%);
}

.envelope.is-opened {
  transform: translateY(16px) scale(0.94);
  opacity: 0.5;
}

/* 收信时：静态打开状态 */
.envelope.is-open-static .envelope__flap {
  transform: rotateX(-105deg);
  z-index: 1;
  transition: none;
}

.envelope.is-open-static .envelope__seal {
  opacity: 0;
  transition: none;
}

.envelope.is-open-static .envelope__letter {
  transform: translateY(-120%);
  transition: none;
}

/* 关闭 — 信纸落入 → 封口盖下 → 蜡封恢复 */
.envelope.is-closing .envelope__flap {
  transform: rotateX(0deg);
  z-index: 4;
  transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1) 0.55s;
}

.envelope.is-closing .envelope__seal {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  transition: opacity 0.5s ease 1.3s, transform 0.5s ease 1.3s;
}

.envelope.is-closing .envelope__letter {
  transform: translateY(0);
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1) 0.15s;
}

.envelope.is-closed {
  animation: envelope-float 3.5s ease-in-out infinite;
  transform: translateY(0) scale(1);
  opacity: 1;
}

.envelope-hint {
  margin-top: 44px;
  font-family: var(--font-serif);
  font-size: 12px;
  letter-spacing: 0.4em;
  color: var(--ink-muted);
  animation: hint-pulse 2.5s ease-in-out infinite;
}

.envelope-closed-hint {
  margin-top: 44px;
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.15em;
  color: var(--ink-light);
  opacity: 0;
  transition: opacity 1s ease;
}

.envelope-closed-hint.is-visible {
  opacity: 0.7;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.7; }
}

.envelope-hint.is-hidden {
  opacity: 0;
  transition: opacity 0.4s;
}

/* ========================================
   Scene 2: Quiz
   ======================================== */
.quiz-scene {
  background: transparent;
}

.quiz-intro-block {
  text-align: center;
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.quiz-intro-block.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.quiz-intro-block.is-hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  position: absolute;
  inset: 0;
}

.quiz-intro-label {
  font-family: var(--font-serif);
  font-size: 11px;
  letter-spacing: 0.45em;
  color: var(--blue);
  margin-bottom: 20px;
}

.quiz-intro-text {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 2;
  color: var(--ink);
}

.quiz-body {
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.quiz-body.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.quiz-chapter {
  font-family: var(--font-serif);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--blue);
  text-align: center;
  margin-bottom: 16px;
}

.quiz-question {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  margin-bottom: 24px;
  text-align: center;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-option {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border: 1px solid rgba(30, 58, 95, 0.1);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.45);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background 0.25s, border-color 0.25s, transform 0.15s;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  z-index: 1;
}

.quiz-option:active { transform: scale(0.98); }

.quiz-option.is-selected,
.quiz-option.is-correct {
  border-color: var(--blue);
  background: var(--blue-wash);
}

.quiz-option.is-wrong {
  border-color: rgba(30, 58, 95, 0.15);
  background: rgba(30, 58, 95, 0.03);
  opacity: 0.55;
}

.quiz-option.is-hidden-option {
  animation: option-reveal 0.5s ease forwards;
  border-color: var(--seal);
  background: rgba(139, 58, 58, 0.05);
}

@keyframes option-reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.quiz-option:disabled { cursor: default; }

.quiz-feedback {
  margin-top: 20px;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.85;
  color: var(--ink);
  text-align: center;
  min-height: 1.85em;
  white-space: pre-line;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.quiz-feedback.is-visible { opacity: 1; }

.quiz-feedback.is-success { color: var(--blue); }

.quiz-feedback.is-neutral { color: var(--ink-light); }

.quiz-success-sparkle {
  position: fixed;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--blue);
  pointer-events: none;
  animation: sparkle 0.8s ease-out forwards;
}

@keyframes sparkle {
  0% { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(0) translateY(-24px); }
}

/* ========================================
   Scene 3: Letter (电子信)
   ======================================== */
.letter-scene {
  background: transparent;
}

.letter-content {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1;
  padding: 8px 4px;
}

.letter-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.letter-paragraph {
  font-family: var(--font-letter);
  font-size: 15px;
  line-height: 2.15;
  color: var(--ink);
  text-align: left;
  letter-spacing: 0.03em;
  white-space: pre-line;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.75s ease, transform 0.75s ease;
}

.letter-paragraph.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.letter-signature {
  font-family: var(--font-letter);
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-light);
  text-align: right;
  margin-top: 36px;
  padding-right: 4px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.75s ease, transform 0.75s ease;
}

.letter-signature.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.letter-final-message {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 120px;
  padding: 32px 16px;
  font-family: "Segoe Script", "Apple Chancery", "Snell Roundhand", "Brush Script MT", var(--font-letter), serif;
  font-size: clamp(28px, 7.5vw, 38px);
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-align: center;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1s ease, transform 1s ease;
}

.letter-final-message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* 上滑提示 */
.swipe-hint {
  position: fixed;
  bottom: calc(28px + var(--safe-bottom));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 10;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  pointer-events: none;
}

.swipe-hint.is-visible {
  opacity: 1;
  transform: translateY(0);
  animation: swipe-hint-bob 2s ease-in-out infinite;
  pointer-events: auto;
  cursor: pointer;
}

.swipe-hint__arrow {
  font-size: 16px;
  color: var(--ink-muted);
  line-height: 1;
}

.swipe-hint__text {
  font-family: var(--font-serif);
  font-size: 10px;
  letter-spacing: 0.25em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

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

/* ========================================
   Scene 4: Photo Unlock
   ======================================== */
.photos-scene {
  background: transparent;
}

.photo-unlock {
  width: min(340px, 88vw);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.photo-card--unlock {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.photo-card--unlock.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.photo-card__frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: min(52vh, 420px);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: var(--shadow-paper-deep);
  background: var(--paper-warm);
  border: 1px solid rgba(30, 58, 95, 0.08);
}

.photo-card__frame--tilt-left { transform: rotate(-1.5deg); }

.photo-card__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card__label {
  margin-top: 18px;
  font-family: var(--font-serif);
  font-size: 10px;
  letter-spacing: 0.3em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.photo-card__caption {
  margin-top: 6px;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  text-align: center;
  max-width: 90%;
}

/* ---- Utility ---- */
.is-hidden { display: none !important; }

[hidden] { display: none !important; }

/* ---- Responsive ---- */
@media (min-width: 768px) {
  .envelope { width: 310px; height: 200px; }
  .paper-sheet--quiz { padding: 44px 36px 36px; }
  .quiz-question { font-size: 18px; }
  .photo-unlock { width: 380px; }
}

@media (max-height: 600px) {
  .paper-sheet--letter { max-height: 70vh; padding: 16px; }
  .photo-card__frame { max-height: 45vh; }
  .envelope-hint { margin-top: 28px; }
}

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