/* The Butterfly Dream: overlay typography and UI. System fonts only. */
:root {
  --zh: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", "Songti TC", serif;
  --en: "Iowan Old Style", "Palatino", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --ui: "Avenir Next", "Avenir", "Helvetica Neue", system-ui, sans-serif;
  --ink: #0a1411;
  --cream: #f1e8cf;
  --cream-2: rgba(236, 228, 204, 0.8);
  --cream-3: rgba(236, 228, 204, 0.5);
  --gold: #e8d39c;
  --glow: 0 0 18px rgba(4, 10, 9, 0.85), 0 0 42px rgba(4, 10, 9, 0.55), 0 1px 2px rgba(4, 10, 9, 0.9);
  --gutter: clamp(16px, 6vw, 96px);
  --slow: cubic-bezier(0.22, 0.61, 0.36, 1);
}

html, body { margin: 0; padding: 0; background: #08110f; color: var(--cream); }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body { overflow-x: hidden; font-family: var(--en); -webkit-font-smoothing: antialiased; }
html.locked, html.locked body { overflow: hidden; overscroll-behavior: none; }

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100lvh; display: block; z-index: 0; }
#scroll-spacer { position: relative; z-index: -1; width: 1px; pointer-events: none; }

.ui { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; overflow: clip; } /* clip: can't be scrolled sideways by focus */
.ui button { pointer-events: auto; font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ui button:focus-visible { outline: 1px solid var(--cream-3); outline-offset: 4px; }

.vignette {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(3, 8, 7, 0.55) 100%),
    linear-gradient(to bottom, rgba(3, 8, 7, 0.35), transparent 18%, transparent 82%, rgba(3, 8, 7, 0.35));
}

/* ------------------------------------------------------------------ gate */
.gate {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: flex-start;
  padding: clamp(56px, 13vh, 150px) 16px 0; text-align: center;
  transition: opacity 1.6s var(--slow), filter 1.6s var(--slow), transform 2.4s var(--slow);
}
.gate::before { /* soft scrim behind the title, no box */
  content: ""; position: absolute; left: 50%; top: 0; width: min(980px, 140vw); height: 70vh; transform: translateX(-50%);
  background: radial-gradient(50% 50% at 50% 48%, rgba(4, 10, 9, 0.62), rgba(4, 10, 9, 0.3) 55%, transparent 75%);
  pointer-events: none;
}
.gate-inner { position: relative; display: flex; flex-direction: column; align-items: center; }
html.entered .gate { opacity: 0; filter: blur(10px); transform: translateY(-3vh) scale(1.02); }
html.entered .gate * { pointer-events: none !important; }

.orn { width: 46px; height: 30px; fill: none; stroke: var(--gold); stroke-width: 1.1; opacity: 0.75; margin-bottom: 18px; animation: flutter 5.5s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes flutter { 0%, 100% { transform: scaleX(1); } 50% { transform: scaleX(0.82); } }

.eyebrow { font-family: var(--ui); font-weight: 300; text-transform: uppercase; font-size: 11.5px; letter-spacing: 0.38em; margin: 0 0 22px; padding-left: 0.38em; color: var(--cream-3); text-shadow: var(--glow); }
.title { margin: 0; font-weight: 400; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.t-main { font-family: var(--en); font-size: clamp(44px, 6.6vw, 88px); letter-spacing: 0.015em; line-height: 1.08; text-shadow: var(--glow); }
.wd { display: inline-block; white-space: nowrap; }
.gate .t-main .ch { animation-delay: calc(0.35s + var(--i) * 0.075s); }
.t-en { font-family: var(--en); font-style: italic; font-size: clamp(19px, 2.1vw, 26px); letter-spacing: 0.08em; color: var(--cream-2); text-shadow: var(--glow); }
.sub { font-family: var(--en); font-size: clamp(14.5px, 1.2vw, 16px); color: var(--cream-3); margin: 16px 0 0; max-width: 34em; line-height: 1.6; text-shadow: var(--glow); }

.gate .ch { display: inline-block; opacity: 0; filter: blur(8px); transform: translateY(0.2em);
  animation: chIn 2.4s var(--slow) forwards; animation-delay: calc(0.35s + var(--i) * 0.28s); }
@keyframes chIn { to { opacity: 1; filter: blur(0); transform: none; } }
.gate .orn, .gate .eyebrow, .gate .t-en, .gate .sub { opacity: 0; animation: fadeIn 2.6s var(--slow) forwards; }
.gate .orn { animation: fadeIn 2.6s var(--slow) 0.2s forwards, flutter 5.5s ease-in-out 2.8s infinite; }
.gate .eyebrow { animation-delay: 0.2s; }
.gate .t-en { animation-delay: 1.5s; }
.gate .sub { animation-delay: 2s; }
@keyframes fadeIn { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: blur(0); } }

.gate-actions { position: relative; margin-top: clamp(28px, 5vh, 46px); min-height: 92px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading { position: absolute; top: 14px; margin: 0; font-family: var(--ui); font-weight: 300; font-size: 12.5px; letter-spacing: 0.32em; color: var(--cream-3);
  text-shadow: var(--glow); animation: breathe 3.2s ease-in-out infinite; transition: opacity 0.8s; }
@keyframes breathe { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.85; } }
html.loaded .loading { opacity: 0 !important; animation: none; }
.gate-actions .btn, .gate-actions .link { opacity: 0; visibility: hidden; transform: translateY(6px); transition: opacity 1.4s var(--slow), transform 1.4s var(--slow), visibility 0s 1.4s, background-color .5s, border-color .5s; }
html.loaded .gate-actions .btn, html.loaded .gate-actions .link { opacity: 1; visibility: visible; transform: none; transition-delay: 0.4s, 0.4s, 0s, 0s, 0s; }
html.loaded .gate-actions .link { transition-delay: 0.9s, 0.9s, 0s, 0s, 0s; }

.btn {
  font-family: var(--ui) !important; font-weight: 400; font-size: 13px !important; letter-spacing: 0.22em; text-transform: uppercase;
  padding: 14px 28px 13px; border-radius: 999px; border: 1px solid rgba(236, 228, 204, 0.35) !important;
  background: rgba(8, 18, 15, 0.18) !important; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  text-shadow: 0 0 12px rgba(4, 10, 9, 0.8); transition: border-color .5s, background-color .5s, box-shadow .5s;
}
.btn.primary { border-color: rgba(232, 211, 156, 0.6) !important; color: var(--gold) !important; box-shadow: 0 0 30px rgba(232, 211, 156, 0.08); }
.btn:hover { border-color: rgba(232, 211, 156, 0.85) !important; background: rgba(232, 211, 156, 0.08) !important; box-shadow: 0 0 36px rgba(232, 211, 156, 0.16); }
.link { font-family: var(--ui) !important; font-weight: 300; font-size: 12px !important; letter-spacing: 0.18em; color: var(--cream-3) !important; padding: 6px 8px; text-shadow: var(--glow);
  text-decoration: underline; text-decoration-color: rgba(236, 228, 204, 0.2); text-underline-offset: 5px; }
.link:hover { color: var(--cream-2) !important; text-decoration-color: rgba(236, 228, 204, 0.5); }

/* ------------------------------------------------------------------ verses */
.verses { position: absolute; inset: 0; }
.verse {
  position: absolute; top: clamp(70px, 14vh, 150px); display: flex; gap: clamp(22px, 2.6vw, 44px); align-items: flex-start;
  opacity: 0; visibility: hidden; transition: opacity 1.2s var(--slow), visibility 0s 1.2s, filter 1.2s var(--slow);
  filter: blur(6px);
}
.verse::before { /* soft night-air scrim */
  content: ""; position: absolute; inset: -30% -40%; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(4, 10, 9, 0.5), rgba(4, 10, 9, 0.22) 55%, transparent);
}
.verse[data-side="left"] { left: var(--gutter); flex-direction: row; }
.verse[data-side="right"] { right: var(--gutter); flex-direction: row-reverse; }
.verse.is-on { opacity: 1; visibility: visible; filter: blur(0); transition: opacity 1.4s var(--slow), visibility 0s, filter 1.6s var(--slow); }

.zh { font-family: var(--zh); writing-mode: vertical-rl; font-size: clamp(28px, min(3vw, 5.4vh), 54px); line-height: 1.75; letter-spacing: 0.3em; color: var(--cream); text-shadow: var(--glow); display: flex; flex-direction: column; }
.verse[data-side="left"] .zh { flex-direction: column; }
.zh .col { display: block; }
.zh .ch { display: inline-block; opacity: 0; filter: blur(10px); transform: translateY(-0.35em); letter-spacing: 0.6em;
  transition: opacity 1.4s var(--slow), filter 1.6s var(--slow), transform 1.8s var(--slow), letter-spacing 2.4s var(--slow); transition-delay: 0s; }
.zh .ch.p { color: var(--cream-3); }
.verse.is-on .zh .ch { opacity: 1; filter: blur(0); transform: none; letter-spacing: 0.3em; transition-delay: calc(0.2s + var(--i) * 0.13s); }

.en { position: relative; margin: 0; max-width: 15em; font-family: var(--en); font-size: clamp(22px, 2.15vw, 34px); line-height: 1.42; letter-spacing: 0.005em; color: var(--cream); text-shadow: var(--glow); }
.verse[data-side="right"] .en { text-align: right; }
.en .num { display: block; font-family: var(--en); font-size: 13px; letter-spacing: 0.4em; color: var(--gold); opacity: 0; margin-bottom: 14px; transition: opacity 1.2s var(--slow); }
.en .num::after { content: ""; display: inline-block; vertical-align: middle; width: 36px; height: 1px; margin-left: 4px; background: linear-gradient(90deg, rgba(232, 211, 156, .6), transparent); }
.verse[data-side="right"] .en .num::after { background: linear-gradient(270deg, rgba(232, 211, 156, .6), transparent); }
.verse.is-on .en .num { opacity: 0.7; transition-delay: 0.5s; }
.en .w { display: inline-block; opacity: 0; filter: blur(5px); transform: translateY(4px);
  transition: opacity 1.2s var(--slow), filter 1.4s var(--slow), transform 1.4s var(--slow); }
.verse.is-on .en .w { opacity: 1; filter: blur(0); transform: none; transition-delay: calc(0.6s + var(--n) * 0.07s + var(--j) * 0.055s); }

/* split verse (paradox): one half above the waterline, its twin below */
.verse.split { inset: 0; top: 0; display: block; }
.verse.split::before { display: none; }
.split .half { position: absolute; left: 16px; right: 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.split .half::before { content: ""; position: absolute; left: 50%; top: 50%; width: min(1100px, 130vw); height: 260%; transform: translate(-50%, -50%); z-index: -1;
  background: radial-gradient(closest-side, rgba(4, 10, 9, 0.5), rgba(4, 10, 9, 0.2) 60%, transparent); pointer-events: none; }
.split .above { top: clamp(28px, 5.5vh, 64px); }
.split .below { bottom: clamp(28px, 5.5vh, 64px); flex-direction: column-reverse; }
.split .zh { writing-mode: horizontal-tb; font-size: clamp(24px, min(2.5vw, 4.4vh), 40px); line-height: 1.3; letter-spacing: 0.32em; padding-left: 0.32em; }
.split .en { margin: 0; max-width: 26em; font-size: clamp(20px, 1.9vw, 30px); text-align: center !important; }
.split .below .en { color: var(--cream-2); font-style: italic; }
.split .below .zh .ch { transform: translateY(0.35em); }
.split .below .zh { opacity: 0.86; }

/* ------------------------------------------------------------------ finale */
.finale { position: absolute; inset: 0; display: flex; justify-content: center; align-items: flex-start; padding: clamp(60px, 12vh, 140px) 16px 0; text-align: center;
  opacity: 0; visibility: hidden; filter: blur(8px); transition: opacity 1.4s var(--slow), filter 1.6s var(--slow), visibility 0s 1.4s; }
.finale::before { content: ""; position: absolute; left: 50%; top: 0; width: min(1000px, 150vw); height: 76vh; transform: translateX(-50%); pointer-events: none;
  background: radial-gradient(50% 50% at 50% 46%, rgba(4, 10, 9, 0.62), rgba(4, 10, 9, 0.28) 55%, transparent 76%); }
.finale.is-on { opacity: 1; visibility: visible; filter: none; transition: opacity 1.8s var(--slow), filter 2s var(--slow), visibility 0s; }
.finale-inner { position: relative; max-width: 560px; display: flex; flex-direction: column; align-items: center; }
.finale h2 { margin: 0 0 22px; font-weight: 400; display: flex; flex-direction: column; gap: 12px; }
.finale h2 .f-main { font-family: var(--en); font-size: clamp(32px, 3.8vw, 48px); letter-spacing: 0.01em; text-shadow: var(--glow); }
.finale h2 .f-en { font-family: var(--en); font-style: italic; font-size: 18px; letter-spacing: 0.06em; color: var(--cream-2); text-shadow: var(--glow); }
.credit { margin: 0 0 10px; font-family: var(--en); font-size: 14.5px; line-height: 1.7; color: var(--cream-3); text-shadow: var(--glow); }
.finale-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 24px; }
.finale:not(.is-on) * { pointer-events: none !important; }
html.wandering .finale { opacity: 0; visibility: hidden; }
html.wandering .finale * { pointer-events: none !important; }

.unwander { position: absolute; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translate(-50%, 10px); opacity: 0; visibility: hidden; transition: opacity 1s var(--slow), transform 1s var(--slow), visibility 0s 1s; }
html.wandering .unwander { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0.6s, 0.6s, 0s; }

/* ------------------------------------------------------------------ chrome */
.chapters { position: absolute; right: clamp(14px, 2.2vw, 30px); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: 0; transition: opacity 1.6s var(--slow) 1.2s; }
html.entered .chapters { opacity: 1; }
html.wandering .chapters, html.locked .chapters, html.finale-on .chapters { opacity: 0; pointer-events: none; transition-delay: 0s; }
html.locked .chapters button, html.wandering .chapters button, html.finale-on .chapters button { pointer-events: none; }
.chapters button { position: relative; font-family: var(--en) !important; font-size: 11.5px !important; letter-spacing: 0.04em; width: 28px; height: 28px; line-height: 28px; color: rgba(236, 228, 204, 0.32) !important; transition: color .8s, transform .8s var(--slow); text-shadow: var(--glow); }
.chapters button:hover { color: var(--cream-2) !important; }
.chapters button.past { color: rgba(236, 228, 204, 0.5) !important; }
.chapters button.on { color: var(--gold) !important; transform: scale(1.18); }
.rail { position: absolute; top: 14px; bottom: 14px; left: -6px; width: 1px; background: rgba(236, 228, 204, 0.12); }
.rail-fill { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(232, 211, 156, 0.2), rgba(232, 211, 156, 0.7)); transform-origin: top; transform: scaleY(0); }

.sound { position: absolute; top: max(16px, env(safe-area-inset-top)); right: clamp(14px, 2.2vw, 30px); width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  opacity: 0; transition: opacity 1.4s var(--slow) 1s, background-color .4s; }
html.entered .sound { opacity: 0.8; }
.sound:hover { opacity: 1 !important; background: rgba(236, 228, 204, 0.06) !important; }
.sound svg { width: 20px; height: 20px; fill: none; stroke: var(--cream); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px rgba(4, 10, 9, 0.9)); }
.sound svg path:first-child { fill: rgba(236, 228, 204, 0.12); }
html:not(.entered) .sound { pointer-events: none; }

.hint { position: absolute; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-family: var(--ui); font-weight: 300; font-size: 11px; letter-spacing: 0.42em; padding-left: 0.42em; color: var(--cream-3); text-shadow: var(--glow);
  opacity: 0; transition: opacity 1.4s var(--slow); }
.hint i { display: block; width: 1px; height: 38px; background: linear-gradient(to bottom, rgba(236, 228, 204, 0.6), transparent); transform-origin: top; animation: drip 2.8s ease-in-out infinite; }
@keyframes drip { 0% { transform: scaleY(0); opacity: 1; } 60% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }
html.entered:not(.scrolled):not(.wandering) .hint { opacity: 1; transition-delay: 3.2s; }

/* ------------------------------------------------------------------ phones / narrow */
@media (max-width: 820px), (max-aspect-ratio: 1/1) {
  .verse { left: 16px !important; right: 16px !important; flex-direction: column !important; gap: 10px; align-items: flex-start; }
  .verse[data-m="top"] { top: max(62px, calc(env(safe-area-inset-top) + 56px)); }
  .verse[data-m="bottom"] { top: auto; bottom: max(36px, env(safe-area-inset-bottom)); }
  .verse::before { inset: -40% -20%; }
  .zh { writing-mode: horizontal-tb; font-size: clamp(24px, 7vw, 34px); line-height: 1.5; letter-spacing: 0.16em; }
  .verse.is-on .zh .ch { letter-spacing: 0.16em; }
  .en { max-width: 30em; font-size: clamp(19px, 5.4vw, 23px); line-height: 1.45; text-align: left !important; margin: 0; }
  .en .num { display: none; }
  .verse { padding-right: 34px; }
  .chapters { right: 4px; gap: 2px; }
  .chapters button { width: 24px; height: 24px; line-height: 24px; font-size: 11px !important; }
  .t-main { font-size: clamp(38px, 11vw, 56px); }
  .btn { padding: 13px 22px 12px; font-size: 12px !important; letter-spacing: 0.18em; }
  .sub { max-width: 22em; }
  .credit { font-size: 13.5px; }
}

/* ------------------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; transition-delay: 0s !important; }
  .loading { opacity: 0.7; }
}

/* ------------------------------------------------------------------ free look */
#scene { cursor: grab; }
.look-hint { position: absolute; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translate(-50%, 6px); max-width: calc(100vw - 32px);
  font-family: var(--ui); font-weight: 300; font-size: 11.5px; letter-spacing: 0.14em; color: var(--cream-3); text-align: center; text-shadow: var(--glow);
  opacity: 0; transition: opacity 1.2s var(--slow), transform 1.2s var(--slow); pointer-events: none; }
/* appears once the scroll hint has done its job, and leaves after the first drag */
html.entered.scrolled:not(.looked):not(.wandering):not(.finale-on) .look-hint { opacity: 0.85; transform: translate(-50%, 0); transition-delay: 1.5s; }

/* fade-through-dark for restarts and long chapter jumps */
.veil { position: absolute; inset: 0; background: #04080a; opacity: 0; pointer-events: none; transition: opacity 0.65s ease-in-out; z-index: 5; }
html.cut .veil { opacity: 1; }
/* keep the controls hint off text that also sits at the bottom edge */
html:has(.verse.split.is-on) .look-hint { opacity: 0 !important; }
@media (max-width: 820px), (max-aspect-ratio: 1/1) {
  html:has(.verse[data-m="bottom"].is-on) .look-hint { opacity: 0 !important; }
}
