/* VOICE   restrained, stoic, a little stern; bilingual, Chinese first, English beneath
   IDEA    a flood of AI text breaking on a headland: words can only be read where the water is still
   PICTURE the live water itself — glyphs carried by a real fluid around the STAI mark and the visitor's stone
   COLOUR  night ink #0b0b0c, brand ink #191919 for the mark, warm white #F2EFE7 for every word; nothing else
   TYPE    Noto Serif SC + EB Garamond for what is said; JetBrains Mono + Noto Sans SC for what floods past */

@font-face { font-family: "STAI Serif SC"; src: url(../fonts/serif-sc.woff2) format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "STAI Sans SC"; src: url(../fonts/sans-sc.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "STAI Garamond"; src: url(../fonts/garamond.woff2) format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "STAI Garamond"; src: url(../fonts/garamond-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "STAI Mono"; src: url(../fonts/mono.woff2) format("woff2"); font-weight: 400; font-display: swap; }

:root { color-scheme: dark; --bg: #0b0b0c; --ink: #F2EFE7; --stone: #191919; }
:root[data-theme=light], :root[data-theme=dark] { color-scheme: dark; }
* { box-sizing: border-box; min-width: 0; }
html { background: var(--bg); scroll-behavior: smooth; scroll-snap-type: y mandatory; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.6 "STAI Garamond", "EB Garamond", Georgia, "STAI Serif SC", "Songti SC", serif;
  overflow-x: clip; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}

#gl { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; height: 100lvh; display: block; z-index: 0; }
.mark-big {
  position: fixed; left: 0; top: 0; width: 1000px; height: 405px; transform-origin: 0 0;
  color: var(--stone); z-index: 1; pointer-events: none; opacity: 0; will-change: transform;
}
.mark-big svg { width: 100%; height: 100%; display: block; overflow: visible; }
#caret { position: fixed; left: 0; top: 0; width: 3px; height: 40px; background: var(--ink); z-index: 2; opacity: 0; pointer-events: none; }
#caret.on { animation: blink 1.06s steps(1, end) infinite; }
@keyframes blink { 0%, 49% { opacity: .9; } 50%, 100% { opacity: 0; } }

main { position: relative; z-index: 2; pointer-events: none; }
/* one screen per chapter, and the page always comes to rest on one (never skipping one on a hard fling) */
section.ch { position: relative; height: 100vh; scroll-snap-align: start; scroll-snap-stop: always; }
.copy { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3; pointer-events: none;
  display: flex; justify-content: space-between; align-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(20px, 3vw) 0;
}
.bar > * { pointer-events: auto; }
/* hidden where the big mark stands: then it can't be clicked or tabbed to either (it fades out before it goes) */
.brand { display: block; width: 66px; color: var(--ink); opacity: 0; visibility: hidden; transition: opacity .8s, visibility .8s; }
.brand svg { display: block; width: 100%; height: auto; }
:root:not([data-ch=hero]):not([data-ch=about]):not([data-ch=end]) .brand { opacity: .82; visibility: visible; }
#sound {
  font: 14px/1 "STAI Garamond", Georgia, "STAI Serif SC", serif; color: var(--ink); background: rgba(11, 11, 12, .35);
  border: 1px solid rgba(242, 239, 231, .26); border-radius: 999px; padding: 0 16px; min-height: 44px;
  cursor: pointer; opacity: .82; transition: border-color .3s, opacity .3s; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#sound::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 9px; vertical-align: 1px;
  border: 1px solid currentColor; border-radius: 50%;
}
#sound[aria-pressed=true] { border-color: rgba(242, 239, 231, .7); opacity: 1; }
#sound[aria-pressed=true]::before { background: currentColor; }
/* on, but the browser has not let it sound yet (it waits for a first click, tap or key): the dot blinks */
#sound.wait::before { animation: wait 1.2s ease-in-out infinite; }
@keyframes wait { 50% { opacity: .15; } }
#sound:hover { opacity: 1; }

.nav { position: fixed; right: max(16px, 2.2vw); top: 50%; transform: translateY(-50%); z-index: 3; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  --tick: 14px; position: relative; display: flex; align-items: center; justify-content: flex-end; min-width: 44px; min-height: 30px;
  color: var(--ink); text-decoration: none; font-size: 13px; line-height: 1;
}
.nav a[aria-current] { --tick: 32px; }
.nav a::after { content: ""; width: var(--tick); height: 1px; background: currentColor; opacity: .32; transition: width .45s, opacity .45s; }
.nav a[aria-current]::after { opacity: .95; }
/* the names show beside the ticks but take no room: only the ticks answer the pointer, so the words and what is
   behind them can reach the right side of the screen */
.nav a span { position: absolute; top: 50%; right: calc(var(--tick) + 12px); opacity: 0; transform: translate(6px, -50%); transition: opacity .35s, transform .35s; white-space: nowrap; pointer-events: none; }
.nav a:hover span, .nav a:focus-visible span { opacity: .82; transform: translate(0, -50%); }

#hint {
  position: fixed; left: 50%; bottom: max(26px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 10px; width: max-content; max-width: 90vw;
  font-size: 13px; letter-spacing: .06em; opacity: 0; transition: opacity 1.4s; pointer-events: none; text-align: center;
}
#hint .h-shield { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 14px; opacity: .92; }
#hint .h-shield [lang=en] { font-size: 12px; font-style: italic; opacity: .72; }
#hint { text-shadow: 0 0 10px #0b0b0c, 0 0 4px #0b0b0c, 0 0 2px #0b0b0c; }
#hint .h-touch { display: none; }
@media (pointer: coarse) { #hint .h-mouse { display: none; } #hint .h-touch { display: flex; } }
.held #hint .h-touch { display: none; }
#hint.on { opacity: .62; }
#hint::after {
  content: ""; display: block; width: 1px; height: 36px; margin: 12px auto 0;
  background: linear-gradient(var(--ink), transparent); animation: drip 2.6s ease-in-out infinite;
}
@keyframes drip {
  0% { transform: scaleY(0); transform-origin: top; }
  50% { transform: scaleY(1); transform-origin: top; }
  51% { transform: scaleY(1); transform-origin: bottom; }
  100% { transform: scaleY(0); transform-origin: bottom; }
}

.foot { position: absolute; left: 0; right: 0; bottom: max(22px, env(safe-area-inset-bottom)); text-align: center; font-size: 13px; opacity: .42; }
.foot .credit { display: block; margin-top: 4px; font-size: 13px; }
.foot a { color: inherit; pointer-events: auto; text-underline-offset: 2px; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }

@media (max-width: 600px) {
  .nav { display: none; }
  .brand { width: 54px; }
  #sound { font-size: 13px; padding: 0 14px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  #caret.on { animation: none; opacity: .9; }
  #hint::after { animation: none; }
  #sound.wait::before { animation: none; opacity: .45; }
}

/* Without WebGL2 the words are shown as a plain page */
.nogl { scroll-snap-type: none; }
.nogl #gl, .nogl .mark-big, .nogl #hint, .nogl .nav, .nogl #caret { display: none; }
.nogl body { -webkit-user-select: text; user-select: text; }
.nogl main { pointer-events: auto; }
.nogl .brand { opacity: .82; visibility: visible; }
.nogl section.ch { height: auto; min-height: 70vh; display: grid; align-content: center; padding: 16vh max(8vw, 20px); }
.nogl .copy { position: static; width: auto; height: auto; overflow: visible; clip: auto; clip-path: none; white-space: normal; max-width: 40em; }
.nogl .copy h1, .nogl .copy h2, .nogl .copy [lang=zh] { font-family: "STAI Serif SC", "Songti SC", serif; font-weight: 600; }
.nogl .copy h1, .nogl .copy h2 { font-size: clamp(30px, 4.6vw, 64px); line-height: 1.2; margin: 0 0 .3em; text-wrap: balance; }
.nogl .copy p[lang=zh] { font-size: clamp(19px, 2vw, 28px); line-height: 1.6; margin: 0 0 .3em; font-weight: 500; }
.nogl .copy p[lang=en], .nogl .copy small, .nogl .copy cite { opacity: .7; }
.nogl .copy p[lang=en] { margin: 0 0 1.3em; }
.nogl .copy ul { list-style: none; padding: 0; margin: 1em 0; }
.nogl .copy blockquote { margin: 1.2em 0 0; }
.nogl .foot { position: static; padding: 0 0 4vh; }
.nogl .copy h1 small { display: block; font-size: .4em; font-weight: 400; font-style: italic; opacity: .7; margin-top: .3em; font-family: "STAI Garamond", Georgia, serif; }
.noscript { padding: 30vh 8vw; font-size: 24px; }
/* the visitor is the stone: no arrow over the water (links and buttons keep theirs) */
.gl body { cursor: none; }
.gl a, .gl button { cursor: pointer; }

/* The loading page, while <html> has .loading (set in index.html before the first paint): a hairline draws the mark
   where the hero's mark stands (S, T, A, I), then 进入 shows (.gate); that click is also the one that lets the piano
   play. Going in (.entering) the stone fills, the hairline fades and the flood arrives. main.js keeps the box exactly
   on the mark; these are the same sums as logoBox('hero'), so it is there before the script runs. */
#loader { display: none; }
.loading #loader, .entering #loader { display: block; position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.ld-box {
  position: absolute; left: 8.5vw;
  width: min(46vw, 120vh); top: calc(50vh - min(46vw, 120vh) * .2025);
  width: min(46vw, 120lvh); top: calc(50lvh - min(46vw, 120lvh) * .2025);
}
.ld-box svg { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 405; overflow: visible; transition: opacity 1s .15s; }
.ld-box path {
  fill: none; stroke: var(--ink); stroke-opacity: .62; stroke-width: var(--sw, 1.6); stroke-linejoin: round;
  stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: ld-draw 1.1s cubic-bezier(.45, 0, .25, 1) .4s forwards;
}
.ld-box path:nth-child(2) { animation-duration: 1.15s; animation-delay: .85s; }
.ld-box path:nth-child(3) { animation-duration: .7s; animation-delay: 1.45s; }
.ld-box path:nth-child(4) { animation-duration: .75s; animation-delay: 1.85s; }
@keyframes ld-draw { to { stroke-dashoffset: 0; } }
@media (max-aspect-ratio: 20/21) {
  .ld-box { left: 10vw; width: 80vw; top: 19vh; top: 19lvh; }
  .ld-box path { stroke-width: var(--sw, 3.4); }
}
#enter {
  position: absolute; left: 50%; top: calc(100% + clamp(28px, 7vh, 72px)); transform: translateX(-50%);
  font: 14px/1 "STAI Garamond", Georgia, "STAI Serif SC", serif; color: var(--ink); background: rgba(11, 11, 12, .35);
  border: 1px solid rgba(242, 239, 231, .26); border-radius: 999px; padding: 0 20px; min-height: 44px; white-space: nowrap;
  pointer-events: auto; opacity: 0; visibility: hidden; transition: opacity .6s, visibility .6s, border-color .3s;
}
#enter:hover { border-color: rgba(242, 239, 231, .7); }
.gate #enter { opacity: .9; visibility: visible; }
.entering #enter { transition: opacity .4s, visibility .4s; }
.entering .ld-box svg { opacity: 0; }
/* while it shows the page stays put (keeping the scrollbar's room, so nothing reflows on the way in), the pointer is an
   ordinary arrow, the chapter ticks wait, and the sound button comes with 进入 (its dot does not blink: the piano waits
   for that click anyway) */
html.loading { overflow: hidden; scrollbar-gutter: stable; }
.gl.loading body { cursor: auto; }
.nav { transition: opacity .8s .4s, visibility .8s .4s; }
.loading .nav { opacity: 0; visibility: hidden; }
.loading #sound { transition: opacity .6s, visibility .6s, border-color .3s; }
.loading:not(.gate) #sound { opacity: 0; visibility: hidden; }
.loading #sound.wait::before { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .ld-box path, .ld-box path:nth-child(n) { stroke-dashoffset: 0; animation: ld-fade .8s .3s both; }
  @keyframes ld-fade { from { opacity: 0; } }
}
