/* =====================================================================
   Light in CWXU — 光影锡院
   Scroll-driven narrative · GSAP ScrollTrigger
   ---------------------------------------------------------------------
   0  tokens
   1  reset & base
   2  page chrome (loader / bg / mark / hud / rail / flash)
   3  hero  — per-character entrance + light-sweep wipe
   4  stage — frame, text column, accents
   5  outro — epilogue lines + button
   6  responsive
   ===================================================================== */

/* ── 0  tokens ─────────────────────────────────────────────────────── */
:root {
  /* brand */
  --plum:        #811d98;
  --plum-lit:    #a83cc4;
  --plum-glow:   #cf7ce6;

  /* live values, written by main.js */
  --acc:  #3b5185;        /* accent taken from the current photograph */
  --acc2: #d9deeb;        /* a deeper tint of the same hue            */
  --ink:  #212c45;        /* heading ink for the current chapter      */

  /* stage geometry — plain numbers so JS can read them back.
     frame box and poem box are each described by their own left/top/size,
     which lets the hand-over ("the frame walks over the poem") run
     sideways on a wide screen and downwards on a tall one. */
  --fx: 6;   --fw: 36;  --ft: 15;  --fh: 70;   /* the framed photograph */
  --tx: 54;  --tw: 40;  --tt: 15;  --th: 70;   /* the poem column       */

  /* type */
  --serif-en: "Cormorant Garamond", "Georgia", "Times New Roman", "Songti SC", "SimSun", serif;
  --serif-cn: "Songti SC", "SimSun", "STSong", "Noto Serif CJK SC", "Source Han Serif SC",
              "Cormorant Garamond", "Georgia", serif;

  --ease-soft: cubic-bezier(.22, .61, .36, 1);
}

/* ── 1  reset & base ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--plum);
  color: var(--ink);
  font-family: var(--serif-cn);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.is-loading { overflow: hidden; }

h1, h2, p, ul, li, figure { margin: 0; padding: 0; }
ul { list-style: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* shown only when scripting is unavailable */
.noscript { display: none; }
.noscript {
  position: fixed; inset: 0; z-index: 1;
  place-content: center; justify-items: center; gap: 3vh;
  background: var(--plum); color: #fff; text-align: center; padding: 8vw;
}
.ns-en {
  font-family: var(--serif-en); font-weight: 300;
  font-size: clamp(1.4rem, 4.5vw, 3rem); letter-spacing: .08em;
}
.ns-zh {
  font-family: var(--serif-cn); font-weight: 400;
  font-size: clamp(1.8rem, 6vw, 4rem); letter-spacing: .12em;
}
.ns-note {
  max-width: 34em;
  font-size: clamp(.82rem, 1.5vw, 1.05rem);
  line-height: 1.9; letter-spacing: .08em;
  color: rgba(255, 255, 255, .68);
}

/* every glyph that gets split out for a staggered entrance */
.ch { display: inline-block; will-change: transform, opacity; }
.ch--sp { width: .34em; }

/* ── 2  page chrome ────────────────────────────────────────────────── */
.bg {
  position: fixed; inset: 0; z-index: 0;
  background-color: var(--plum);
  will-change: background-color;
}

/* faint university watermark, bottom right, always present */
.mark {
  position: fixed; z-index: 4;
  right: 3.4vw; bottom: 4.5vh;
  height: clamp(64px, 12vh, 132px);
  pointer-events: none;
}
.mark img { height: 100%; width: auto; }
.mark-ink   { opacity: 0; }      /* on the pale chapter grounds */
.mark-white { opacity: .16; }    /* on the plum bookends       */

/* current-chapter readout — takes over the corner the hero's label vacates */
.hud {
  position: fixed; z-index: 4;
  left: 4vw; top: 4.6vh;
  display: flex; align-items: center; gap: 1vw;
  font-size: clamp(.6rem, .74vw, .8rem);
  letter-spacing: .24em;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.hud-idx { font-family: var(--serif-en); letter-spacing: .12em; opacity: .6; }
.hud-idx b { font-weight: 500; }
.hud-idx i { font-style: normal; margin: 0 .3em; opacity: .5; }
.hud-rule {
  width: 3vw; height: 1px; background: var(--acc);
  transform-origin: left center; opacity: .85;
}
.hud-name { color: var(--ink); letter-spacing: .3em; }

/* chapter ticks down the right margin */
.rail {
  position: fixed; z-index: 4;
  right: 2.1vw; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-end; gap: 15px;
  opacity: 0; pointer-events: none;
}
.rail i {
  display: block; height: 1px; width: 11px;
  background: var(--ink); opacity: .28;
  transition: width .5s var(--ease-soft), opacity .5s var(--ease-soft), background-color .5s;
}
.rail i.on { width: 30px; opacity: .95; background: var(--acc); }

/* full-screen curtain used when returning to the top */
.flash {
  position: fixed; inset: 0; z-index: 998;
  background: var(--plum);
  opacity: 0; visibility: hidden; pointer-events: none;
}

/* ── 2a  loader ────────────────────────────────────────────────────── */
.loader {
  position: fixed; inset: 0; z-index: 999;
  background: var(--plum);
  display: grid; place-content: center; justify-items: center;
  gap: 3.4vh;
  transition: opacity .9s var(--ease-soft), visibility .9s;
}
.loader.is-done { opacity: 0; visibility: hidden; }

.loader-mark img {
  width: clamp(54px, 6vw, 92px); opacity: .82;
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: .58; transform: translateY(0); }
  50%      { opacity: .95; transform: translateY(-6px); }
}

.loader-track {
  width: min(34vw, 300px); height: 1px;
  background: rgba(255, 255, 255, .2);
  overflow: hidden;
}
.loader-track i {
  display: block; width: 0%; height: 100%;
  background: #fff;
}
.loader-pct {
  font-family: var(--serif-en);
  font-size: clamp(.8rem, 1vw, 1.05rem);
  letter-spacing: .3em;
  color: rgba(255, 255, 255, .8);
}
.loader-pct em { font-style: normal; font-size: .72em; margin-left: .4em; opacity: .6; }
.loader-note {
  font-size: clamp(.68rem, .82vw, .9rem);
  letter-spacing: .5em; text-indent: .5em;
  color: rgba(255, 255, 255, .5);
}

/* ── 3  the reel — one pin, three acts ─────────────────────────────── */
.reel {
  position: relative; z-index: 2;
  height: 100vh; height: 100svh;
  overflow: hidden;
}
.layer { position: absolute; inset: 0; }

/* ── 3a  hero ──────────────────────────────────────────────────────── */
.hero {
  z-index: 1;
  overflow: hidden;
  --p: 0;                         /* sweep progress 0 → 1 */
}

.hero-layer {
  position: absolute; inset: 0;
  display: grid; place-items: center;
}

/* the world as it was: plum ground, white serif */
.hero-base { background: var(--plum); }
.hero-base .hero-word--en { color: #fff; }
.hero-base .hero-chrome,
.hero-base .hero-hint { color: rgba(255, 255, 255, .74); }
.hero-base .hero-hint i { background: rgba(255, 255, 255, .5); }

/* the world after the light: white ground, plum 宋体, revealed left→right */
.hero-clip {
  background: #fff;
  clip-path: inset(0 calc(100% - var(--p) * 100%) 0 0);
  z-index: 2;
}
.hero-clip .hero-word--zh { color: var(--plum); }
.hero-clip .hero-chrome,
.hero-clip .hero-hint { color: rgba(129, 29, 152, .72); }
.hero-clip .hero-hint i { background: rgba(129, 29, 152, .5); }

.hero-word {
  font-weight: 400;
  line-height: 1.15;
  white-space: nowrap;
  text-align: center;
}
.hero-word--en {
  font-family: var(--serif-en);
  font-size: clamp(1.55rem, 6vw, 6.6rem);
  font-weight: 300;
  letter-spacing: .045em;
}
.hero-word--zh {
  font-family: var(--serif-cn);
  font-size: clamp(1.9rem, 8.2vw, 9rem);
  letter-spacing: .1em;
  text-indent: .1em;
}

.hero-chrome {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between;
  padding: 4.6vh 4vw;
  font-size: clamp(.6rem, .74vw, .8rem);
  letter-spacing: .3em;
}
.hero-chrome em { font-style: normal; margin: 0 .5em; opacity: .6; }
.hc-r { font-family: var(--serif-en); letter-spacing: .24em; text-transform: uppercase; }

.hero-hint {
  position: absolute; left: 50%; bottom: 5vh;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 1.1vh;
  font-size: clamp(.58rem, .7vw, .76rem);
  letter-spacing: .42em; text-indent: .42em;
  white-space: nowrap;
}
.hero-hint i {
  width: 1px; height: 5.6vh;
  transform-origin: top center;
  animation: drop 2.4s ease-in-out infinite;
}
@keyframes drop {
  0%       { transform: scaleY(0); opacity: 0; }
  35%      { transform: scaleY(1); opacity: 1; }
  100%     { transform: scaleY(1) translateY(2.2vh); opacity: 0; }
}

/* the light itself: a soft, wide, faintly tilted vertical beam */
.hero-beam {
  position: absolute; z-index: 3;
  left: 0; top: -14%; height: 128%;
  width: clamp(110px, 13vw, 260px);
  opacity: 0;
  transform: translateX(calc(var(--p) * 100vw - 50%)) rotate(1.8deg);
  background: linear-gradient(90deg,
      rgba(168, 60, 196, 0)    0%,
      rgba(168, 60, 196, .16) 26%,
      rgba(198, 104, 226, .52) 45%,
      rgba(240, 205, 250, .95) 50%,
      rgba(198, 104, 226, .52) 55%,
      rgba(168, 60, 196, .16) 74%,
      rgba(168, 60, 196, 0)  100%);
  filter: blur(22px);
  pointer-events: none;
}
.hero-beam i {
  position: absolute; left: 50%; top: 0; width: 2px; height: 100%;
  margin-left: -1px;
  background: linear-gradient(180deg,
      rgba(255, 240, 255, 0)  0%,
      rgba(255, 240, 255, .85) 18%,
      #fff                    50%,
      rgba(255, 240, 255, .85) 82%,
      rgba(255, 240, 255, 0) 100%);
  filter: blur(1.4px);
}

/* ── 4  stage ──────────────────────────────────────────────────────── */
.stage {
  z-index: 2;
  overflow: hidden;
}

/* 4a ── decorative accents, coloured by the current photograph ─────── */
.acc { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

.acc-glow {
  position: absolute;
  width: 62vw; height: 62vw; border-radius: 50%;
  right: -18vw; top: -24vw;
  background: var(--acc);
  opacity: .10;
  filter: blur(72px);
  will-change: transform;
}
.acc-rings {
  position: absolute;
  left: -17vw; top: -19vw;
  width: 44vw; height: 44vw;
  will-change: transform;
}
.acc-rings span {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--acc); opacity: .5;
}
.acc-rings span:nth-child(1) { transform: scale(.42); opacity: .34; }
.acc-rings span:nth-child(2) { transform: scale(.71); opacity: .22; }
.acc-rings span:nth-child(3) { transform: scale(1);   opacity: .14; }

.acc-num {
  position: absolute; right: 2.4vw; bottom: -6vh;
  font-family: var(--serif-cn);
  font-size: 32vh; line-height: 1;
  color: var(--acc); opacity: .07;
  will-change: transform;
}

/* a slow picket of light-rules in the gutter between photo and text */
.acc-bars {
  position: absolute;
  left: calc((var(--fx) + var(--fw) + var(--tx)) / 2 * 1vw);
  top: calc((var(--ft) + var(--fh) / 2) * 1vh);
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; gap: 1.5vh;
  width: clamp(40px, 6vw, 120px);
}
.acc-bars i {
  display: block; height: 1px; width: 100%;
  background: var(--acc);
  transform-origin: left center;
  opacity: .26;
}

/* the echo of the opening sweep — flares on every chapter change */
.acc-streak {
  position: absolute; z-index: 2;
  top: 21vh; left: 0;
  width: 26vw; height: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, var(--acc) 100%);
  filter: blur(1.5px);
  opacity: 0;
  will-change: transform, opacity;
}

/* 4b ── the framed photograph ──────────────────────────────────────── */
.frame {
  position: absolute; z-index: 6;
  left: calc(var(--fx) * 1vw);
  top: calc(var(--ft) * 1vh);
  width: calc(var(--fw) * 1vw);
  height: calc(var(--fh) * 1vh);
  will-change: transform;
}
.frame-mat {
  position: absolute; inset: 0;
  padding: 13px;
  background: rgba(255, 255, 255, .74);
  box-shadow:
    0 4.4vh 9vh -3.2vh rgba(28, 18, 42, .34),
    0 .4vh 1.2vh -0.4vh rgba(28, 18, 42, .18),
    0 1px 0 rgba(255, 255, 255, .9) inset;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.frame-view {
  position: relative; width: 100%; height: 100%;
  overflow: hidden;
  background: var(--acc2);
  outline: 1px solid rgba(30, 22, 40, .13);
  outline-offset: -1px;
}
.stack { position: absolute; inset: 0; }
.stack img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  will-change: transform;
}
/* a whisper of shading so the prints sit in the room rather than on it */
.frame-veil {
  position: absolute; inset: 0; z-index: 40; pointer-events: none;
  background: linear-gradient(180deg,
      rgba(20, 12, 30, .12) 0%,
      rgba(20, 12, 30, 0)   26%,
      rgba(20, 12, 30, 0)   72%,
      rgba(20, 12, 30, .17) 100%);
}

.corner {
  position: absolute; width: 30px; height: 30px;
  border: 1px solid var(--acc); opacity: .6;
}
.corner.tl { left: -10px; top: -10px;    border-right: 0; border-bottom: 0; }
.corner.tr { right: -10px; top: -10px;   border-left: 0;  border-bottom: 0; }
.corner.bl { left: -10px; bottom: -10px; border-right: 0; border-top: 0; }
.corner.br { right: -10px; bottom: -10px; border-left: 0; border-top: 0; }

.frame-cap {
  position: absolute; left: 0; top: calc(100% + 1.9vh);
  display: flex; align-items: center; gap: .9vw;
  font-family: var(--serif-en);
  font-size: clamp(.66rem, .82vw, .88rem);
  letter-spacing: .2em;
  color: var(--ink);
}
.frame-cap b { font-weight: 500; }
.frame-cap i { display: block; width: 2.4vw; height: 1px; background: var(--acc); opacity: .7; }

/* 4c ── the poem column ────────────────────────────────────────────── */
.textside {
  position: absolute; z-index: 5;
  left: calc(var(--tx) * 1vw);
  top: calc(var(--tt) * 1vh);
  width: calc(var(--tw) * 1vw);
  height: calc(var(--th) * 1vh);
}
.ts-block {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: center;
}
.ts-head { position: relative; padding-left: 2.4vw; }
.ts-head::before {
  content: ""; position: absolute; left: 0; top: .42em;
  width: 1.5vw; height: 1px; background: var(--acc);
}
.ts-num {
  display: block;
  font-family: var(--serif-cn);
  font-size: clamp(.7rem, .92vw, 1rem);
  letter-spacing: .5em;
  color: var(--acc);
  margin-bottom: .9vh;
}
.ts-title {
  font-family: var(--serif-cn);
  font-size: clamp(1.35rem, 3vw, 3.3rem);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: .09em;
  color: var(--ink);
}
.ts-en {
  display: block; margin-top: .9vh;
  font-family: var(--serif-en);
  font-size: clamp(.62rem, .82vw, .92rem);
  letter-spacing: .34em; text-transform: uppercase;
  color: var(--acc);
}

.ts-lines {
  margin-top: 4.4vh; padding-left: 2.4vw;
  display: flex; flex-direction: column; gap: 1.7vh;
}
.ts-line {
  position: relative;
  font-family: var(--serif-cn);
  font-size: clamp(.86rem, 1.72vw, 1.9rem);
  line-height: 1.72;
  letter-spacing: .07em;
  color: var(--ink);
}
.ts-line::before {
  content: ""; position: absolute;
  left: -2.4vw; top: .96em;
  width: .9vw; height: 1px;
  background: var(--acc); opacity: .55;
}

/* ── 5  outro ──────────────────────────────────────────────────────── */
.outro {
  z-index: 3;
  overflow: hidden;
  display: grid; place-items: center;
  opacity: 0; visibility: hidden;   /* revealed by the master timeline */
}
.outro-halo {
  position: absolute; z-index: 0;
  width: 96vw; height: 96vw; border-radius: 50%;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--plum-lit);
  opacity: 0;
  filter: blur(90px);
}
.outro-rings {
  position: absolute; z-index: 0;
  left: 50%; top: 50%;
  width: 44vw; height: 44vw;
  transform: translate(-50%, -50%);
}
.outro-rings span {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .3);
}
.outro-rings span:nth-child(1) { transform: scale(.5);  opacity: .55; }
.outro-rings span:nth-child(2) { transform: scale(.75); opacity: .35; }
.outro-rings span:nth-child(3) { transform: scale(1);   opacity: .2; }

.outro-inner {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
}
.epi {
  position: relative;
  width: min(76vw, 1000px); height: 17vh;
}
/* kept out of flow so the epilogue itself stays optically centred */
.btn-slot {
  position: absolute; left: 50%; top: calc(100% + 6vh);
  transform: translateX(-50%);
  display: flex;
}
.epi-line {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
  font-family: var(--serif-cn);
  font-size: clamp(1.05rem, 2.4vw, 2.6rem);
  line-height: 1.75;
  letter-spacing: .16em; text-indent: .16em;
  color: #fff;
  opacity: 0;
}

.btn {
  padding: 1.7vh 3.2vw;
  display: flex; flex-direction: column; align-items: center; gap: .7vh;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 999px;
  background: rgba(255, 255, 255, .04);
  color: #fff;
  cursor: pointer;
  opacity: 0;
  transition: background-color .55s var(--ease-soft), border-color .55s var(--ease-soft),
              color .55s var(--ease-soft), transform .55s var(--ease-soft);
}
/* a slow lantern-flicker so the invitation reads as live, not decorative */
.btn.is-live { animation: lantern 3.6s ease-in-out infinite; }
@keyframes lantern {
  0%, 100% { box-shadow: 0 0 0 0 rgba(207, 124, 230, .30); }
  50%      { box-shadow: 0 0 5vh 0 rgba(207, 124, 230, .16); }
}
.btn:hover, .btn:focus-visible {
  background: #fff; border-color: #fff; color: var(--plum);
  transform: translateY(-2px);
  outline: none;
}
.btn-txt {
  font-size: clamp(.82rem, 1.05vw, 1.1rem);
  letter-spacing: .34em; text-indent: .34em;
}
.btn-en {
  font-family: var(--serif-en);
  font-size: clamp(.58rem, .74vw, .82rem);
  letter-spacing: .22em; text-transform: uppercase;
  opacity: .72;
}

/* ── 6  responsive ─────────────────────────────────────────────────── */
/* portrait: the photograph takes the upper field, the poem reads beneath
   it, and the hand-over therefore travels downwards instead of across */
@media (max-aspect-ratio: 1/1) {
  :root {
    --fx: 12; --fw: 76; --ft: 8;  --fh: 42;
    --tx: 6;  --tw: 88; --tt: 53; --th: 42;
  }
  .rail, .acc-bars { display: none; }
  .mark { height: 7vh; right: 4vw; bottom: 2.4vh; }
  .acc-num { font-size: 20vh; bottom: -2vh; right: 3vw; }
  .acc-rings { left: -24vw; top: -12vw; width: 52vw; height: 52vw; }

  .hud { font-size: .56rem; letter-spacing: .12em; gap: .5rem; left: 4vw; top: 2.8vh; }
  .hud-rule { width: 12px; }

  .frame-mat { padding: 7px; }
  .frame-cap { font-size: .56rem; gap: .5rem; top: calc(100% + 1.2vh); }
  .frame-cap i { width: 16px; }
  .corner { width: 18px; height: 18px; }
  .corner.tl, .corner.bl { left: -6px; }
  .corner.tr, .corner.br { right: -6px; }
  .corner.tl, .corner.tr { top: -6px; }
  .corner.bl, .corner.br { bottom: -6px; }

  .ts-head { padding-left: 4vw; }
  .ts-head::before { width: 2.4vw; }
  .ts-num { font-size: .58rem; letter-spacing: .34em; margin-bottom: .4vh; }
  .ts-title { font-size: clamp(.95rem, 4.6vw, 1.7rem); letter-spacing: .04em; }
  .ts-en { font-size: .5rem; letter-spacing: .2em; margin-top: .5vh; }
  .ts-lines { margin-top: 2.2vh; padding-left: 4vw; gap: .9vh; }
  .ts-line { font-size: clamp(.68rem, 3vw, 1.1rem); line-height: 1.62; letter-spacing: .04em; }
  .ts-line::before { left: -4vw; width: 2.4vw; top: .9em; }

  .hero-word--en { letter-spacing: .02em; }
  .hero-chrome { padding: 3vh 5vw; font-size: .55rem; letter-spacing: .18em; }

  .epi { height: 26vh; width: 88vw; }
  .epi-line { font-size: clamp(1rem, 5.4vw, 1.6rem); letter-spacing: .1em; }
  .btn-slot { top: calc(100% + 4vh); }
  .btn { padding: 1.4vh 7vw; }
  .btn-txt { letter-spacing: .22em; text-indent: .22em; }
}

@media (prefers-reduced-motion: reduce) {
  .loader-mark img,
  .hero-hint i { animation: none; }
  .hero-hint i { opacity: .6; }
}

/* markers off in production; kept here so anyone editing can flip them on */
