/* ============================================================
   七夕 · Qixi Interactive Card — Stylesheet
   Palette: ink indigo night / magpie blue / gold foil / peach
   ============================================================ */

:root {
  --ink:        #05070f;
  --ink-2:      #0b1023;
  --indigo:     #131a3a;
  --gold:       #e8c37a;
  --gold-soft:  #f5e0b0;
  --peach:      #ff9fb5;
  --rose:       #ff6f9c;
  --paper:      #f7f1e4;
  --paper-2:    #efe4cf;
  --seal:       #b5222b;

  --serif-cn: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  --kai-cn:   "Kaiti SC", "STKaiti", "KaiTi", "Noto Serif SC", serif;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io:  cubic-bezier(.65, .05, .36, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--gold-soft);
  font-family: var(--serif-cn);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { position: fixed; inset: 0; touch-action: none; }

#scene { position: fixed; inset: 0; z-index: 0; }
#scene canvas { display: block; width: 100% !important; height: 100% !important; }

/* Cinematic vignette + film grain overlay ------------------- */
.vignette {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background:
    radial-gradient(ellipse 112% 80% at 54% 42%,
      rgba(3,4,10,.06) 30%, rgba(3,4,10,.48) 72%, rgba(2,3,8,.9) 100%);
  mix-blend-mode: multiply;
}
.vignette::after {
  content: ""; position: absolute; inset: -50%;
  background-image: var(--grain);
  opacity: .05; animation: grain 1.1s steps(4) infinite;
}
@keyframes grain {
  0%   { transform: translate(0,0); }
  25%  { transform: translate(-3%, 2%); }
  50%  { transform: translate(2%, -3%); }
  75%  { transform: translate(-2%, -2%); }
  100% { transform: translate(0,0); }
}
/* ── Top bar: vertical-seal kicker + big title ─────────────── */
.topbar {
  position: fixed; top: 0; left: 0; z-index: 5;
  width: min(48vw, 680px);
  padding: clamp(28px, 5vh, 58px) 0 0 clamp(32px, 5.2vw, 84px);
  text-align: left; pointer-events: none;
  opacity: 0; transform: translateY(-14px);
  transition: opacity 1.5s var(--ease-out), transform 1.5s var(--ease-out);
}
.topbar.in { opacity: 1; transform: none; }

.kicker {
  font-family: var(--kai-cn);
  font-size: clamp(11px, 1.15vw, 14px);
  letter-spacing: .4em;
  color: rgba(232,195,122,.62);
  margin-bottom: clamp(6px, 1vh, 12px);
}

.title {
  font-family: var(--serif-cn);
  font-weight: 400;
  font-size: clamp(48px, 6.2vw, 88px);
  line-height: 1;
  letter-spacing: .08em;
  background: linear-gradient(178deg, #fffaf0 4%, var(--gold) 46%, #b98f42 96%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(232,195,122,.4))
          drop-shadow(0 3px 2px rgba(0,0,0,.6));
}
.title .ink { position: relative; }
.title .ink::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 1.42em; height: 1.42em; transform: translate(-50%,-50%);
  border: 1px solid rgba(232,195,122,.3); border-radius: 50%;
  animation: haloSpin 15s linear infinite;
}
@keyframes haloSpin {
  from { transform: translate(-50%,-50%) rotate(0) scale(1); }
  50%  { transform: translate(-50%,-50%) rotate(180deg) scale(1.045); }
  to   { transform: translate(-50%,-50%) rotate(360deg) scale(1); }
}

.dedication {
  margin-top: clamp(8px, 1.4vh, 16px);
  font-family: var(--kai-cn);
  font-size: clamp(13px, 1.55vw, 20px);
  letter-spacing: .16em;
  color: rgba(247,241,228,.74);
}
.dedication em {
  font-style: normal; color: var(--peach);
  padding: 0 .1em;
  text-shadow: 0 0 16px rgba(255,159,181,.75);
}
/* ── Entry gate (needed: audio requires a user gesture) ────── */
.gate {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 50%, #0a0f22 0%, #04060e 70%);
  cursor: pointer;
  transition: opacity 1.1s var(--ease-out), visibility 1.1s;
}
.gate.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.gate-inner { text-align: center; }

.gate-heart { width: clamp(64px, 11vw, 104px); margin: 0 auto clamp(20px, 3vh, 34px); }
.gate-heart svg { width: 100%; display: block; overflow: visible; }
.gate-heart path {
  fill: none; stroke: var(--gold); stroke-width: 1.15;
  stroke-linecap: round;
  stroke-dasharray: 96; stroke-dashoffset: 96;
  filter: drop-shadow(0 0 12px rgba(232,195,122,.8));
  animation: drawHeart 2.6s var(--ease-io) .3s forwards,
             beat 1.5s ease-in-out 3s infinite;
  transform-origin: 50% 60%;
}
@keyframes drawHeart { to { stroke-dashoffset: 0; } }
@keyframes beat {
  0%,100% { transform: scale(1); }
  14%     { transform: scale(1.11); }
  28%     { transform: scale(1); }
  42%     { transform: scale(1.07); }
}

.gate-label {
  font-family: var(--kai-cn);
  font-size: clamp(15px, 1.9vw, 23px);
  letter-spacing: .4em; text-indent: .4em;
  color: var(--gold-soft);
  animation: breathe 2.8s ease-in-out infinite;
}
.gate-sub {
  margin-top: 12px; font-size: clamp(10px, 1.1vw, 13px);
  letter-spacing: .26em; color: rgba(247,241,228,.4);
}
@keyframes breathe { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
/* ── Bottom control dock ───────────────────────────────────── */
.dock {
  position: fixed; z-index: 6;
  left: 50%; bottom: clamp(18px, 3.4vh, 40px);
  transform: translateX(-50%) translateY(22px);
  display: flex; gap: clamp(6px, 1vw, 12px);
  padding: 7px; border-radius: 999px;
  background: rgba(6,9,22,.72);
  border: 1px solid rgba(232,195,122,.2);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 12px 40px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.07);
  opacity: 0; transition: opacity 1s var(--ease-out) .3s, transform 1s var(--ease-out) .3s;
}
.dock.in { opacity: 1; transform: translateX(-50%); }

.btn {
  display: inline-flex; align-items: center; gap: .5em;
  padding: clamp(8px,1.3vh,11px) clamp(13px,1.7vw,20px);
  border: 0; border-radius: 999px;
  background: transparent; color: rgba(247,241,228,.72);
  font-family: var(--kai-cn);
  font-size: clamp(12px, 1.25vw, 15px);
  letter-spacing: .14em; white-space: nowrap;
  cursor: pointer; position: relative; overflow: hidden;
  transition: color .35s, background .35s, transform .35s var(--ease-out);
}
.btn::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(135deg, rgba(232,195,122,.22), rgba(255,111,156,.16));
  opacity: 0; transition: opacity .35s;
}
.btn:hover { color: #fff; transform: translateY(-2px); }
.btn:hover::before { opacity: 1; }
.btn:active { transform: translateY(0) scale(.97); }
.btn > * { position: relative; }
.btn .ico { font-size: 1.08em; color: var(--gold); line-height: 1; }
.btn[aria-pressed="false"] { color: rgba(247,241,228,.34); }
.btn[aria-pressed="false"] .ico { color: rgba(232,195,122,.34); }

/* Tiny audio equalizer icon */
.ico.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 1em; }
.ico.eq i {
  width: 2px; background: currentColor; border-radius: 1px;
  animation: eqBar .9s ease-in-out infinite;
}
.ico.eq i:nth-child(1) { height: 55%; animation-delay: 0s; }
.ico.eq i:nth-child(2) { height: 100%; animation-delay: .18s; }
.ico.eq i:nth-child(3) { height: 70%; animation-delay: .36s; }
@keyframes eqBar { 0%,100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
.btn[aria-pressed="false"] .ico.eq i { animation-play-state: paused; transform: scaleY(.3); }

.hint {
  position: fixed; z-index: 5; left: 50%; bottom: clamp(4px, .9vh, 10px);
  transform: translateX(-50%);
  font-size: clamp(9px, .95vw, 12px);
  letter-spacing: .2em; color: rgba(247,241,228,.26);
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 1.2s 1.4s;
}
.hint.in { opacity: 1; }
.hint.fade { opacity: 0; transition: opacity .6s; }
/* ── Greeting card: real 3D fold-open in CSS space ─────────── */
.card-layer {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  background: rgba(4,6,14,.72);
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
  opacity: 0; visibility: hidden;
  transition: opacity .75s var(--ease-out), visibility .75s;
}
.card-layer.open { opacity: 1; visibility: visible; }

.card-stage {
  perspective: 2100px; perspective-origin: 50% 44%;
  transform: scale(.9); transition: transform .95s var(--ease-out);
}
.card-layer.open .card-stage { transform: scale(1); }

/* Card = right page fixed, cover flips left on the shared spine */
.card {
  position: relative;
  width: clamp(268px, 41vw, 430px);
  height: clamp(376px, 57vw, 596px);
  transform-style: preserve-3d;
  transform: rotateX(6deg) rotateY(-13deg);
  transition: transform 1.15s var(--ease-out);
}
.card.spread { transform: rotateX(3deg) rotateY(0deg) translateX(26%); }

.card-page, .card-cover {
  position: absolute; inset: 0; border-radius: 4px 12px 12px 4px;
  transform-style: preserve-3d;
}

/* Inner right-hand page (the letter) */
.card-page {
  background:
    radial-gradient(140% 100% at 12% 0%, #fffdf8 0%, var(--paper) 42%, var(--paper-2) 100%);
  box-shadow: inset 14px 0 26px -14px rgba(90,66,36,.42),
              0 26px 60px rgba(0,0,0,.55);
  overflow: hidden;
}
.card-page::after { /* paper fibre */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--grain); opacity: .3; mix-blend-mode: multiply;
}

/* Cover leaf that swings open */
.card-cover {
  transform-origin: left center;
  transform: rotateY(0deg);
  transition: transform 1.35s var(--ease-io);
  cursor: pointer;
  z-index: 3;
}
.card.spread .card-cover { transform: rotateY(-172deg); }

.cover-face {
  position: absolute; inset: 0; border-radius: inherit;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
}
/* Cover — outside: lacquer red-black with gold foil frame */
.cover-outside {
  background:
    radial-gradient(120% 90% at 26% 12%, #2a1230 0%, #14091c 46%, #0a0510 100%);
  box-shadow: 0 30px 70px rgba(0,0,0,.7), inset 0 0 60px rgba(0,0,0,.5);
  display: grid; place-items: center;
}
.cover-outside::before { /* foil sheen sweep */
  content: ""; position: absolute; inset: -40%;
  background: linear-gradient(72deg, transparent 40%, rgba(255,240,205,.14) 50%, transparent 60%);
  animation: sheen 5.5s ease-in-out infinite;
}
@keyframes sheen {
  0%, 62%  { transform: translateX(-64%); }
  100%     { transform: translateX(64%); }
}

.cover-frame {
  position: relative; z-index: 1;
  width: 78%; height: 84%;
  border: 1px solid rgba(232,195,122,.42);
  outline: 3px solid rgba(232,195,122,.1); outline-offset: 5px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .85em;
  text-align: center;
}
.cover-frame::before, .cover-frame::after { /* corner ticks */
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 1px solid var(--gold); opacity: .65;
}
.cover-frame::before { top: -5px; left: -5px; border-right: 0; border-bottom: 0; }
.cover-frame::after  { bottom: -5px; right: -5px; border-left: 0; border-top: 0; }

.cover-seal {
  width: 2.6em; height: 2.6em; display: grid; place-items: center;
  font-family: var(--serif-cn); font-size: clamp(17px, 2.1vw, 24px);
  color: #fff2ea; background: var(--seal);
  border-radius: 4px; letter-spacing: 0;
  box-shadow: 0 0 22px rgba(181,34,43,.6), inset 0 0 12px rgba(0,0,0,.3);
  transform: rotate(-4deg);
}
.cover-title {
  font-family: var(--kai-cn);
  font-size: clamp(26px, 3.6vw, 42px);
  letter-spacing: .16em; text-indent: .16em;
  background: linear-gradient(176deg, #fff8e8, var(--gold) 55%, #a97f34);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.cover-line {
  width: 44%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(232,195,122,.7), transparent);
}
.cover-sub {
  font-size: clamp(10px, 1.15vw, 13px);
  letter-spacing: .42em; text-indent: .42em;
  color: rgba(232,195,122,.6);
}
.cover-open {
  margin-top: .5em; font-family: var(--kai-cn);
  font-size: clamp(10px, 1.1vw, 12px);
  letter-spacing: .3em; text-indent: .3em;
  color: rgba(255,159,181,.72);
  animation: breathe 2.4s ease-in-out infinite;
}
.card.spread .cover-open { opacity: 0; transition: opacity .3s; }

/* Cover — inside: the poem, pre-mirrored so it reads correctly */
.cover-inside {
  transform: rotateY(180deg);
  background: radial-gradient(130% 100% at 80% 0%, #fffdf8, var(--paper) 48%, #e6d9c0);
  box-shadow: inset -14px 0 26px -14px rgba(90,66,36,.4);
  display: grid; place-items: center;
}
.cover-inside::after {
  content: ""; position: absolute; inset: 0;
  background-image: var(--grain); opacity: .3; mix-blend-mode: multiply;
}
/* Poem on the cover's inner face — vertical, right-to-left */
.poem {
  position: relative; z-index: 1;
  display: flex; flex-direction: row-reverse; gap: 1.1em;
  align-items: flex-start; justify-content: center;
  height: 78%; color: #2c2317;
}
.poem p {
  writing-mode: vertical-rl; text-orientation: upright;
  font-family: var(--kai-cn);
  font-size: clamp(19px, 2.5vw, 30px);
  letter-spacing: .3em; line-height: 1.5;
  opacity: 0; transform: translateY(-16px);
}
.card.spread .poem p { animation: dropIn .9s var(--ease-out) forwards; }
.card.spread .poem p:nth-child(1) { animation-delay: .95s; }
.card.spread .poem p:nth-child(2) { animation-delay: 1.2s; }
.poem-src {
  writing-mode: vertical-rl;
  align-self: flex-end; margin-top: auto;
  font-size: clamp(9px, 1.05vw, 12px);
  letter-spacing: .18em; color: #8a7355;
  opacity: 0;
}
.card.spread .poem-src { animation: dropIn .8s var(--ease-out) 1.55s forwards; }
@keyframes dropIn { to { opacity: 1; transform: none; } }

/* The letter on the right page */
.letter {
  position: relative; z-index: 1;
  height: 100%; padding: clamp(26px, 4.4vw, 46px) clamp(22px, 3.6vw, 40px);
  display: flex; flex-direction: column; gap: .95em;
  color: #33291b; font-family: var(--kai-cn);
  font-size: clamp(12.5px, 1.42vw, 16.5px);
  line-height: 2.05; letter-spacing: .06em;
}
.letter p { opacity: 0; transform: translateY(12px); }
.card.spread .letter p { animation: dropIn .85s var(--ease-out) forwards; }
.card.spread .letter p:nth-child(1) { animation-delay: 1.05s; }
.card.spread .letter p:nth-child(2) { animation-delay: 1.28s; }
.card.spread .letter p:nth-child(3) { animation-delay: 1.51s; }
.card.spread .letter p:nth-child(4) { animation-delay: 1.74s; }
.card.spread .letter p:nth-child(5) { animation-delay: 1.97s; }

.letter .salut {
  font-size: 1.16em; letter-spacing: .12em;
  color: #1f1810; border-bottom: 1px solid rgba(120,96,60,.22);
  padding-bottom: .5em;
}
.letter .sign {
  margin-top: auto; text-align: right; line-height: 1.85;
  color: #5d4a30;
}
.letter .sign span {
  display: block; font-size: .82em;
  letter-spacing: .16em; color: #93805f;
}

.card-close {
  position: fixed; top: clamp(16px, 2.6vh, 28px); right: clamp(16px, 2.6vw, 30px);
  z-index: 32; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid rgba(232,195,122,.3);
  background: rgba(10,14,32,.6); color: var(--gold-soft);
  font-size: 15px; cursor: pointer;
  transition: transform .3s var(--ease-out), background .3s, border-color .3s;
}
.card-close:hover {
  transform: rotate(90deg) scale(1.1);
  background: rgba(181,34,43,.5); border-color: rgba(232,195,122,.7);
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-aspect-ratio: 3/4) {
  .topbar {
    left: 0; right: 0; width: auto;
    padding: clamp(18px, 3.2vh, 30px) 18px 0;
    text-align: center;
  }
  .title { font-size: clamp(40px, 13vw, 62px); }
  .kicker { font-size: 11px; }
  .dedication {
    margin-top: 7px;
    font-size: clamp(12px, 3.6vw, 15px);
  }

  .card { width: min(76vw, 340px); height: min(106vw, 476px); }
  .card.spread { transform: rotateX(2deg) translateX(0) translateY(-3%) scale(.94); }
  .letter { line-height: 1.9; }

  /* Two-up dock so it never stacks into a tall column */
  .dock {
    flex-wrap: wrap; justify-content: center;
    width: min(92vw, 420px); gap: 4px;
  }
  .dock .btn {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
    padding: 9px 8px;
    font-size: 12px; letter-spacing: .08em;
  }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .vignette::after, .ico.eq i, .cover-outside::before,
  .title .ink::after, .gate-heart path { animation: none !important; }
}
