/* ============================================================
   Roseal — the front page.
   One continuous day-cycle: paper → warm charcoal night → rose-gold dawn → paper.
   Background and bloom are painted by home.js on #sky;
   this file owns typography, rhythm, and restraint.
   Tokens come from ../css/tokens.css (shared mirror).
   ============================================================ */

:root {
  /* surface-local extensions */
  --rs-night:     #15110E;                    /* warm charcoal before dawn */
  --rs-night-2:   #211713;                    /* soil-warm dawn shadow */
  --rs-light:     #F0ECE6;
  --rs-light-2:   rgba(240, 236, 230, 0.74);
  --rs-sky:       rgba(214, 165, 92, 0.86);   /* marigold labels in the night */
  --rs-real:      #3E97BE;                    /* the Real reading of the name */
  --rs-dim:       #C9C2B8;                    /* letters at rest during the other reading */
  --rs-serif: 'EB Garamond', 'Noto Serif SC', 'Songti SC', Georgia, serif;
  --rs-sans:  'Manrope', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

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

html {
  scroll-behavior: smooth;
  scroll-snap-type: y proximity;
}

body {
  background: var(--ev-bg-page);
  color: var(--ev-text-primary);
  font-family: var(--rs-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--ev-red-subtle); }

/* language: exactly one voice visible at a time */
.L { display: none; }
body[data-lang="zh"] .L.zh { display: inline; }
body[data-lang="en"] .L.en { display: inline; }

/* the sky — fixed canvas behind everything */
#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

main { position: relative; z-index: 1; }

/* ---- nav: a whisper, not a bar ------------------------------ */
.nav {
  position: fixed;
  z-index: 2;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 34px;
  color: var(--ev-text-primary);
  transition: color 0.8s ease;
  pointer-events: none;          /* children re-enable */
}

.nav > * { pointer-events: auto; }

body.night .nav { color: var(--rs-light); }

.brand {
  font: 500 1.1rem/1 var(--rs-serif);
  letter-spacing: 0.05em;
  color: inherit;
  text-decoration: none;
}

/* center menu — three dots that open into doors under the hand */
.menu {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

.menu:hover, .menu.open, .menu:focus-within {
  background: rgba(248, 246, 242, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 1px 14px rgba(26, 23, 20, 0.05);
}

body.night .menu:hover, body.night .menu.open, body.night .menu:focus-within {
  background: rgba(21, 17, 14, 0.54);
  box-shadow: none;
}

.menu-pip {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: 600 1rem/1 var(--rs-sans);
  letter-spacing: 0.18em;
  opacity: 0.45;
  max-width: 48px;
  overflow: hidden;
  padding: 4px 2px;
  transition: opacity 0.4s ease, max-width 0.5s ease;
}

.menu-links {
  display: flex;
  gap: 26px;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: max-width 0.6s ease, opacity 0.45s ease 0.1s;
}

.menu:hover .menu-pip, .menu.open .menu-pip, .menu:focus-within .menu-pip {
  opacity: 0;
  max-width: 0;
  padding-inline: 0;
}

.menu:hover .menu-links, .menu.open .menu-links, .menu:focus-within .menu-links {
  max-width: 520px;
  opacity: 1;
}

.menu-links a {
  color: inherit;
  text-decoration: none;
  font: 500 0.72rem/2.2 var(--rs-sans);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.72;
  transition: opacity 0.3s ease;
}

.menu-links a:hover { opacity: 1; }

.lang-toggle {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font: 500 0.8rem/1 var(--rs-sans);
  color: inherit;
}

.lang-toggle span { opacity: 0.35; }

.lang-toggle button {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  opacity: 0.45;
  padding: 6px 2px;
  transition: opacity 0.4s ease;
}

.lang-toggle button.on { opacity: 1; }
.lang-toggle button:hover { opacity: 0.8; }

/* ---- acts ---------------------------------------------------- */
.act {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-inline: 24px;
  scroll-snap-align: start;
  scroll-snap-stop: normal;
}

/* 扉页 */
.act--hero {
  min-height: 100svh;
  justify-content: center;
  padding-bottom: 12vh;
}

.wordmark {
  font: 500 0.78rem/1 var(--rs-sans);
  letter-spacing: 0.58em;
  text-indent: 0.58em;
  color: var(--ev-text-tertiary);
  margin-bottom: 3rem;
  animation: wordmark-breathe 9s ease-in-out infinite;
}

@keyframes wordmark-breathe {
  0%, 100% { letter-spacing: 0.58em; opacity: 0.9; }
  50%      { letter-spacing: 0.66em; opacity: 1; }
}

.creed {
  font-family: var(--rs-serif);
  font-weight: 500;
  font-size: clamp(1.85rem, 4.8vw, 3.3rem);
  line-height: 1.55;
  max-width: 22em;
}

.creed .en { font-style: italic; }
body[data-lang="zh"] .creed { line-height: 1.8; letter-spacing: 0.06em; }

.sub {
  margin-top: 2.4rem;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: var(--ev-text-secondary);
}

/* the flyleaf composes itself once, like a breath taken before speaking */
.js .rise { opacity: 0; animation: rise 1.5s cubic-bezier(0.22, 0.61, 0.21, 1) forwards; }
.js .rise-1 { animation-delay: 0.15s; }
.js .rise-2 { animation-delay: 0.5s; }
.js .rise-3 { animation-delay: 1.05s; }
.js .rise-4 { animation-delay: 1.8s; }
.js .rise-5 { animation-delay: 2.2s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}

/* wordmark carries two animations: arrival, then breathing */
.js .wordmark { animation: rise 1.5s cubic-bezier(0.22, 0.61, 0.21, 1) 0.15s forwards, wordmark-breathe 9s ease-in-out 2s infinite; }

.principle-mark {
  position: absolute;
  left: 50%;
  top: calc(50% + 208px);
  width: 112px;
  height: 38px;
  opacity: 0.86;
  transform: translateX(-50%);
}

.js .principle-mark {
  opacity: 0;
  animation:
    principle-mark-enter 1s cubic-bezier(0.22, 0.61, 0.21, 1) 1.65s forwards,
    principle-mark-breathe 6s ease-in-out 2.75s infinite;
}

@keyframes principle-mark-enter {
  from { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.94); }
  to   { opacity: 0.9; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes principle-mark-breathe {
  0%, 100% { opacity: 0.78; transform: translateX(-50%) translateY(0) scale(0.96); }
  50%      { opacity: 0.96; transform: translateX(-50%) translateY(-4px) scale(1.05); }
}

.principle-mark__thread,
.principle-mark__node,
.principle-mark__core {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  pointer-events: none;
}

.principle-mark__thread {
  width: 78px;
  height: 24px;
  border: 1px solid transparent;
  transform-origin: center;
}

.js .principle-mark__thread {
  clip-path: inset(0 50% 0 50%);
}

.principle-mark__thread--red {
  border-top-color: rgba(194, 48, 80, 0.52);
  border-left-color: rgba(194, 48, 80, 0.22);
  border-top-color: color-mix(in srgb, var(--ev-red) 62%, transparent);
  border-left-color: color-mix(in srgb, var(--ev-red) 26%, transparent);
  border-radius: 50% 50% 42% 58%;
  transform: translate(-50%, -50%) rotate(-13deg);
  animation:
    principle-thread-grow 1.15s cubic-bezier(0.16, 1, 0.3, 1) 1.85s forwards,
    principle-thread-red 6.5s ease-in-out 3s infinite;
}

.principle-mark__thread--blue {
  border-bottom-color: rgba(96, 184, 216, 0.58);
  border-right-color: rgba(96, 184, 216, 0.24);
  border-bottom-color: color-mix(in srgb, var(--ev-blue-hover) 70%, transparent);
  border-right-color: color-mix(in srgb, var(--ev-blue-hover) 28%, transparent);
  border-radius: 42% 58% 50% 50%;
  transform: translate(-50%, -50%) rotate(13deg);
  animation:
    principle-thread-grow 1.15s cubic-bezier(0.16, 1, 0.3, 1) 1.95s forwards,
    principle-thread-blue 6.5s ease-in-out 3.1s infinite;
}

@keyframes principle-thread-grow {
  from { clip-path: inset(0 50% 0 50%); }
  to   { clip-path: inset(-6px -6px -6px -6px); }
}

@keyframes principle-thread-red {
  0%, 100% { transform: translate(-50%, -50%) rotate(-15deg) scaleX(0.92); }
  50%      { transform: translate(-50%, -50%) rotate(-5deg) scaleX(1.1); }
}

@keyframes principle-thread-blue {
  0%, 100% { transform: translate(-50%, -50%) rotate(15deg) scaleX(1.1); }
  50%      { transform: translate(-50%, -50%) rotate(5deg) scaleX(0.92); }
}

.principle-mark__node {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  box-shadow: 0 0 12px currentColor;
}

.js .principle-mark__node,
.js .principle-mark__core {
  opacity: 0;
}

.principle-mark__node--red {
  color: var(--ev-red);
  background: currentColor;
  transform: translate(-42px, -5px);
  animation:
    principle-node-enter 0.55s ease-out 2.6s forwards,
    principle-node-red 6s ease-in-out 3.15s infinite;
}

.principle-mark__node--blue {
  color: var(--ev-blue-hover);
  background: currentColor;
  transform: translate(37px, 3px);
  animation:
    principle-node-enter 0.55s ease-out 2.7s forwards,
    principle-node-blue 6s ease-in-out 3.25s infinite;
}

.principle-mark__core {
  width: 10px;
  height: 10px;
  border: 1px solid rgba(156, 149, 141, 0.36);
  border: 1px solid color-mix(in srgb, var(--ev-text-tertiary) 42%, transparent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation:
    principle-node-enter 0.55s ease-out 2.45s forwards,
    principle-core 6s ease-in-out 3.05s infinite;
}

@keyframes principle-node-enter {
  from { opacity: 0; filter: blur(4px); }
  to   { opacity: 1; filter: blur(0); }
}

@keyframes principle-node-red {
  0%, 100% { opacity: 0.72; transform: translate(-43px, -5px) scale(0.86); box-shadow: 0 0 7px currentColor; }
  50%      { opacity: 1; transform: translate(-37px, -8px) scale(1.24); box-shadow: 0 0 18px currentColor; }
}

@keyframes principle-node-blue {
  0%, 100% { opacity: 1; transform: translate(39px, 3px) scale(1.24); box-shadow: 0 0 18px currentColor; }
  50%      { opacity: 0.72; transform: translate(33px, 6px) scale(0.86); box-shadow: 0 0 7px currentColor; }
}

@keyframes principle-core {
  0%, 100% { opacity: 0.58; transform: translate(-50%, -50%) scale(0.82); }
  50%      { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
}

.cue {
  position: absolute;
  bottom: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--ev-text-tertiary);
}

.cue-line {
  width: 1px;
  height: 52px;
  background: currentColor;
  opacity: 0.5;
  transform-origin: top;
  animation: cue-grow 3.4s cubic-bezier(0.45, 0, 0.3, 1) infinite;
}

@keyframes cue-grow {
  0%   { transform: scaleY(0); opacity: 0; }
  45%  { transform: scaleY(1); opacity: 0.5; }
  100% { transform: scaleY(1); opacity: 0; }
}

.cue-label {
  font: 500 0.7rem/1 var(--rs-sans);
  letter-spacing: 0.38em;
  text-indent: 0.38em;
}

/* 黑夜的两幕 — one waterfall, no hard cuts */
.act--dark {
  min-height: 115vh;
  padding-top: 58vh;
  padding-bottom: 24vh;
  color: var(--rs-light);
}

.act--bonds { min-height: 135vh; }

/* no-JS fallback: the night must still be night */
body:not(.js) #solitude { background: var(--rs-night); }
body:not(.js) #bonds { background: var(--rs-night-2); }
body:not(.js) #hero { opacity: 1 !important; }

.act-text {
  max-width: 34em;
  scroll-margin-top: 38vh;
  text-shadow: 0 0 28px rgba(15, 21, 34, 0.55);
}

/* on paper, a soft halo keeps words legible over the ink bloom */
.act--light .act-text,
.aphorism,
.margin-note {
  text-shadow: 0 0 14px var(--ev-bg-page), 0 0 28px var(--ev-bg-page);
}

.act-label {
  font: 500 0.72rem/1 var(--rs-sans);
  letter-spacing: 0.44em;
  text-indent: 0.44em;
  text-transform: uppercase;
  color: var(--rs-sky);
  margin-bottom: 1.8rem;
}

.act--light .act-label { color: var(--ev-red-text); }

.act h2 {
  font-family: var(--rs-serif);
  font-weight: 500;
  font-size: clamp(1.5rem, 3.4vw, 2.35rem);
  line-height: 1.5;
  margin-bottom: 1.6rem;
}

.act--dark h2 {
  color: #F3E9DC;
  text-shadow: 0 0 24px rgba(21, 17, 14, 0.72), 0 0 42px rgba(214, 165, 92, 0.08);
}

body[data-lang="zh"] .act h2 { letter-spacing: 0.05em; }

.act .body {
  font-family: var(--rs-serif);
  font-size: 1.08rem;
  line-height: 1.95;
  max-width: 30em;
  margin-inline: auto;
  color: var(--rs-light-2);
}

.act--dark .body { color: rgba(240, 236, 230, 0.68); }

body[data-lang="zh"] .act .body { line-height: 2.15; letter-spacing: 0.03em; }

.act--light .body { color: var(--ev-text-secondary); }

/* 白昼的一幕 */
.act--light {
  min-height: 110vh;
  padding-top: 44vh;
  padding-bottom: 14vh;
  justify-content: flex-start;
}

.aphorism {
  margin-top: 5rem;
  font-family: var(--rs-serif);
  font-size: 1.28rem;
  letter-spacing: 0.02em;
  color: var(--ev-text-primary);
}

.aphorism .en { font-style: italic; }
body[data-lang="zh"] .aphorism { letter-spacing: 0.08em; }

.margin-note {
  margin-top: 3.2rem;
  font: 400 0.8rem/1.6 var(--rs-sans);
  letter-spacing: 0.1em;
  color: var(--ev-text-tertiary);
}

/* ---- 肆 · 名字 — the name reads itself two ways --------------- */
.act--name {
  min-height: 95vh;
  padding-top: 24vh;
  padding-bottom: 14vh;
}

.roseal-word {
  font-family: var(--rs-serif);
  font-weight: 500;
  font-size: clamp(3rem, 9vw, 6.2rem);
  letter-spacing: 0.14em;
  line-height: 1.1;
  margin-bottom: 2.2rem;
}

.lt { transition: color 0.4s ease; }

/* one slow cycle: ink → ROSE in crimson → ink → R·E·A·L in blue → ink */
.lt-both { animation: lt-both 14s ease-in-out infinite; }
.lt-rose { animation: lt-rose 14s ease-in-out infinite; }
.lt-real { animation: lt-real 14s ease-in-out infinite; }

@keyframes lt-both {
  0%, 8%   { color: var(--ev-text-primary); }
  14%, 26% { color: var(--ev-red); }
  34%, 40% { color: var(--ev-text-primary); }
  46%, 58% { color: var(--rs-real); }
  66%, 100% { color: var(--ev-text-primary); }
}

@keyframes lt-rose {
  0%, 8%   { color: var(--ev-text-primary); }
  14%, 26% { color: var(--ev-red); }
  34%, 40% { color: var(--ev-text-primary); }
  46%, 58% { color: var(--rs-dim); }
  66%, 100% { color: var(--ev-text-primary); }
}

@keyframes lt-real {
  0%, 8%   { color: var(--ev-text-primary); }
  14%, 26% { color: var(--rs-dim); }
  34%, 40% { color: var(--ev-text-primary); }
  46%, 58% { color: var(--rs-real); }
  66%, 100% { color: var(--ev-text-primary); }
}

.name-words {
  font-family: var(--rs-serif);
  font-size: 0.98rem;
  letter-spacing: 0.06em;
  color: var(--ev-text-secondary);
  margin-bottom: 2.6rem;
}

.name-words i {
  font-style: normal;
  opacity: 0;
  transition: opacity 1.2s ease;
}

.reveal.in .name-words i { opacity: 1; }
.reveal.in .name-words i:nth-child(1) { transition-delay: 0.2s; }
.reveal.in .name-words i:nth-child(2) { transition-delay: 0.5s; }
.reveal.in .name-words i:nth-child(3) { transition-delay: 0.8s; }
.reveal.in .name-words i:nth-child(4) { transition-delay: 1.1s; }
.reveal.in .name-words i:nth-child(5) { transition-delay: 1.4s; }
.reveal.in .name-words i:nth-child(6) { transition-delay: 1.7s; }

.name-caption { font-size: 1rem; }

/* ---- the bridge, and three doors ---------------------------- */
.act--doors {
  padding-top: 10vh;
  padding-bottom: 8vh;
}

.bridge-label {
  font: 500 0.72rem/1 var(--rs-sans);
  letter-spacing: 0.44em;
  text-indent: 0.44em;
  text-transform: uppercase;
  color: var(--ev-text-tertiary);
  margin-bottom: 1.6rem;
}

/* the one gradient on the page — crimson to sky, crossed once */
.bridge {
  height: 1px;
  width: min(420px, 68vw);
  background: var(--ev-gradient-h);
  margin-bottom: 5.5rem;
  opacity: 0.9;
}

.doors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 3.4rem;
  width: min(880px, 100%);
  text-align: left;
}

.door {
  display: block;
  text-decoration: none;
  color: var(--ev-text-primary);
  border-top: 1px solid var(--ev-border-default);
  padding: 1.4rem 0 1.9rem;
  transition: color 0.45s ease, border-color 0.45s ease;
}

.door h3 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font: 600 1.02rem/1.3 var(--rs-sans);
  letter-spacing: 0.02em;
}

.door .arrow {
  color: var(--ev-text-tertiary);
  font-size: 0.9em;
  transition: transform 0.45s ease, color 0.45s ease;
}

.door p {
  margin-top: 0.6rem;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--ev-text-secondary);
}

.door:hover { color: var(--ev-red-text); border-top-color: var(--ev-border-strong); }
.door:hover .arrow { transform: translate(3px, -3px); color: var(--ev-red-text); }

/* ---- footer -------------------------------------------------- */
footer {
  position: relative;
  z-index: 1;
  padding: 9vh 24px 64px;
  text-align: center;
  scroll-snap-align: end;
}

.closing {
  font-family: var(--rs-serif);
  font-weight: 500;
  font-size: 1.5rem;
  margin-bottom: 2.4rem;
}

.closing .en { font-style: italic; }
body[data-lang="zh"] .closing { letter-spacing: 0.1em; }

.fine {
  font: 400 0.78rem/1 var(--rs-sans);
  letter-spacing: 0.06em;
  color: var(--ev-text-tertiary);
}

.fine a { color: inherit; text-decoration: none; }
.fine a:hover { color: var(--ev-text-secondary); }

/* ---- reveal: words arrive like remembering ------------------- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 1.6s ease, transform 1.6s cubic-bezier(0.22, 0.61, 0.21, 1);
}

.reveal.in { opacity: 1; transform: none; }

body:not(.js) .reveal { opacity: 1; transform: none; }
body:not(.js) .name-words i { opacity: 1; }

/* ---- small screens ------------------------------------------- */
@media (max-width: 720px) {
  .nav { padding: 16px 20px; }
  .menu { top: 8px; }
  .menu-links { gap: 16px; }
  .principle-mark { top: calc(50% + 168px); }
  .act--dark { padding-top: 52vh; min-height: 105vh; }
  .act--bonds { min-height: 120vh; }
  .doors { grid-template-columns: 1fr; gap: 0; }
  .door { padding: 1.2rem 0 1.5rem; }
}

/* ---- motion is a courtesy, never a requirement ---------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; scroll-snap-type: none; }
  .cue-line { animation: none; opacity: 0.4; transform: none; }
  .reveal, .js .rise { opacity: 1; transform: none; transition: none; animation: none; }
  .js .wordmark,
  .lt-both,
  .lt-rose,
  .lt-real,
  .principle-mark,
  .principle-mark__thread--red,
  .principle-mark__thread--blue,
  .principle-mark__node--red,
  .principle-mark__node--blue,
  .principle-mark__core {
    animation: none;
  }
  .js .principle-mark {
    opacity: 0.86;
    transform: translateX(-50%);
  }
  .js .principle-mark__thread { clip-path: none; }
  .js .principle-mark__node,
  .js .principle-mark__core {
    opacity: 1;
    filter: none;
  }
  .name-words i { opacity: 1 !important; transition: none; }
}
