:root {
  --ink: #ece4d6;
  --ink-soft: rgba(236, 228, 214, 0.74);
  --ink-faint: rgba(236, 228, 214, 0.42);
  --line: rgba(236, 228, 214, 0.16);
  --veil: rgba(8, 7, 10, 0.4);
  --shadow: 0 0 22px rgba(0, 0, 0, 0.7), 0 1px 2px rgba(0, 0, 0, 0.75);
  --ease-out: cubic-bezier(0.16, 0.84, 0.24, 1);
  --serif: 'EB Garamond', 'Cormorant Garamond', Garamond, Georgia, serif;
  --display: 'Cormorant Garamond', 'EB Garamond', Garamond, Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #08070a;
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { touch-action: none; transition: background-color 1.2s linear; }
button { font: inherit; color: inherit; }

#art {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#book { position: fixed; inset: 0; }

/* ------------------------------------------------------------ pages */

.page {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.9s ease, filter 0.7s ease, transform 0.9s var(--ease-out);
}
.page.in { opacity: 1; }
.page.leaving {
  opacity: 0;
  filter: blur(4px);
  transform: translateY(-10px);
  transition: opacity 0.6s ease, filter 0.6s ease, transform 0.7s ease;
  pointer-events: none;
}
.poster {
  position: absolute;
  pointer-events: none;
  user-select: none;
  -webkit-mask-image: radial-gradient(circle, #000 50%, transparent 70%);
  mask-image: radial-gradient(circle, #000 50%, transparent 70%);
}
.page-cover .poster { -webkit-mask-image: none; mask-image: none; }

.poem-text {
  position: absolute;
  font-size: var(--fs, 19px);
  line-height: 1.55;
  color: var(--ink);
  text-shadow: var(--shadow);
  max-height: var(--avail, 80vh);
  overflow: hidden;
}
.poem-text.scrolls {
  overflow-y: auto;
  touch-action: pan-y;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, #000 1.6em, #000 calc(100% - 2.2em), transparent);
  mask-image: linear-gradient(transparent, #000 1.6em, #000 calc(100% - 2.2em), transparent);
  padding: 1.2em 0 2.4em;
}
.poem-text.scrolls::-webkit-scrollbar { display: none; }

.layout-split .poem-text {
  left: 56vw;
  width: min(38vw, 620px);
  top: 50%;
  transform: translateY(-50%);
}
.layout-center .poem-text,
.layout-duo .poem-text {
  left: 50%;
  top: 50%;
  width: min(80vw, 560px);
  transform: translate(-50%, -50%);
}
@media (max-width: 759px), (max-aspect-ratio: 105/100) {
  .page-poem .poem-text {
    left: 50% !important;
    top: 50% !important;
    width: min(86vw, 520px) !important;
    transform: translate(-50%, -50%) !important;
  }
}

.numeral {
  font-size: 0.72em;
  letter-spacing: 0.34em;
  color: var(--ink-faint);
  margin: 0 0 0.5em;
}
.title {
  font-family: var(--display);
  font-weight: 500;
  font-size: calc(var(--fs, 19px) * 1.85);
  line-height: 1.08;
  letter-spacing: 0.005em;
  margin: 0 0 1em;
  text-wrap: balance;
}
.numeral, .title {
  opacity: 0;
  filter: blur(6px);
  transform: translateY(0.3em);
  transition: opacity 1.6s var(--ease-out), filter 1.4s var(--ease-out), transform 1.8s var(--ease-out);
}
.numeral.on, .title.on { opacity: 1; filter: none; transform: none; }
.title.on { transition-delay: 0.25s; }

.stanza { margin: 0 0 1em; }
.stanza:last-child { margin-bottom: 0; }
.ln {
  display: block;
  padding-left: 1.3em;
  text-indent: -1.3em; /* wrapped lines hang, as in a printed book */
}

/* line reveals ------------------------------------------------------ */

.ln {
  opacity: 0;
  transform: translateY(0.4em);
  filter: blur(5px);
  transition: opacity 1.5s var(--ease-out), transform 1.7s var(--ease-out), filter 1.3s var(--ease-out);
}
.ln.on { opacity: 1; transform: none; filter: none; }

.fx-drift .ln {
  transform: translateX(-0.8em);
  transition: opacity 2.4s var(--ease-out), transform 3.4s var(--ease-out), filter 2.4s var(--ease-out);
}
.fx-drift .ln.on { transform: none; }

.fx-flicker .ln { transition: none; transform: none; filter: none; }
.fx-flicker .ln.on { animation: flicker 1.8s linear both; }
@keyframes flicker {
  0% { opacity: 0; }
  15% { opacity: 0.7; }
  30% { opacity: 0.22; }
  55% { opacity: 0.85; }
  70% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* Missed the Bus: each line arrives late, trailed by its own earlier version */
.fx-ghost .ln { transition: none; transform: none; filter: none; }
.fx-ghost .ln.on { animation: lag 2.6s var(--ease-out) both; }
@keyframes lag {
  0% { opacity: 0; text-shadow: 0.6em 0 1px rgba(236, 228, 214, 0), var(--shadow); }
  30% { opacity: 0.5; text-shadow: 0.6em 0 1px rgba(236, 228, 214, 0.42), var(--shadow); }
  100% { opacity: 1; text-shadow: 0 0 0 rgba(236, 228, 214, 0), var(--shadow); }
}

.fx-bloom .ln, .ln.lfx-bloom {
  letter-spacing: 0.22em;
  transform: none;
  transition: opacity 2.2s var(--ease-out), letter-spacing 3s var(--ease-out), filter 2.2s var(--ease-out);
}
.fx-bloom .ln.on, .ln.lfx-bloom.on { letter-spacing: normal; }

.ln.lfx-cut { transition: none; transform: none; filter: none; }
.ln.lfx-cut.on { animation: cut 2s ease-out both; }
@keyframes cut {
  0% { opacity: 1; text-shadow: 0 0 16px rgba(255, 240, 222, 0.95), var(--shadow); color: #fff; }
  100% { opacity: 1; text-shadow: var(--shadow); color: var(--ink); }
}

.ln.resonate { animation: resonate 2.8s ease-in-out; }
@keyframes resonate {
  35% { color: #fff4e2; text-shadow: 0 0 14px rgba(255, 232, 196, 0.55), var(--shadow); }
}

/* ------------------------------------------------------------ cover */

.cover-text {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 1100px);
  text-align: center;
  text-shadow: 0 0 40px rgba(0, 0, 0, 0.7), 0 2px 3px rgba(0, 0, 0, 0.6);
}
.book-title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.5rem, 6.6vw, 6rem);
  line-height: 1.04;
  letter-spacing: 0.015em;
  margin: 0;
}
.book-title .tl { display: block; white-space: nowrap; }
.book-title .ch {
  display: inline-block;
  opacity: 0;
  filter: blur(10px);
  transform: translateY(0.12em);
  transition: opacity 1.8s var(--ease-out), filter 1.8s var(--ease-out), transform 2.4s var(--ease-out);
  transition-delay: calc(var(--o) * 1.5s);
}
.title-on .book-title .ch { opacity: 1; filter: none; transform: none; }
.book-title .ch.askew {
  transform: translateY(0.035em) rotate(4.5deg);
  transition: transform 3.5s var(--ease-out);
  transition-delay: 0s;
}
.author {
  font-style: italic;
  font-size: clamp(1.05rem, 1.7vw, 1.45rem);
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin: 1.4em 0 0;
  opacity: 0;
  transition: opacity 2s ease 2.2s;
}
.title-on .author { opacity: 1; }

/* ------------------------------------------------------------ constellation */

.page-map .map {
  position: absolute;
  inset: 7vh 8vw 36vh;
}
.map-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.map-lines polyline {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 2 5;
  vector-effect: non-scaling-stroke;
}
.star {
  position: absolute;
  transform: translate(-50%, -50%);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  animation: float 11s ease-in-out infinite;
  animation-delay: calc(var(--d) * -1);
  /* the animated button is the stacking context, so it must carry the blend */
  mix-blend-mode: screen;
}
.star img {
  display: block;
  width: clamp(44px, 5.4vw, 76px);
  aspect-ratio: 1;
  border-radius: 50%;
  -webkit-mask-image: radial-gradient(circle, #000 52%, transparent 71%);
  mask-image: radial-gradient(circle, #000 52%, transparent 71%);
  transition: transform 0.6s var(--ease-out), filter 0.6s ease;
  filter: brightness(0.85);
}
.star:hover img, .star:focus-visible img { transform: scale(1.35); filter: brightness(1.15); }
.star .lbl {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 0.3em);
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.star .lbl .num { letter-spacing: 0.2em; color: var(--ink-faint); margin-right: 0.3em; }
.star:hover .lbl, .star:focus-visible .lbl { opacity: 1; }
@media (max-width: 759px) { .star .lbl { display: none; } }
@keyframes float {
  50% { transform: translate(-50%, calc(-50% - 7px)); }
}
.page-map .colophon {
  position: absolute;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  width: min(88vw, 620px);
  max-height: none;
  font-size: 15.5px;
  line-height: 1.6;
  text-align: center;
  color: var(--ink-soft);
}
.colophon .lede {
  font-family: var(--display);
  font-size: 1.6em;
  color: var(--ink);
  margin: 0 0 0.5em;
}
.colophon .again {
  margin-top: 0.6em;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5em 1.3em;
  letter-spacing: 0.18em;
  font-size: 12px;
  text-transform: uppercase;
  cursor: pointer;
  color: var(--ink-soft);
  transition: color 0.3s, border-color 0.3s;
}
.colophon .again:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ------------------------------------------------------------ chrome */

.chrome {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 5;
}
.chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: var(--veil);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 0.62em 1.1em;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.3s, border-color 0.3s, opacity 1.2s ease;
}
.chip:hover, .chip:focus-visible { color: var(--ink); border-color: var(--ink-faint); }
.chip:focus-visible, .dot:focus-visible, .star:focus-visible, .toc button:focus-visible {
  outline: 1px solid var(--ink-soft);
  outline-offset: 3px;
}
#btn-sound .wave { opacity: 0.25; transition: opacity 0.4s; }
#btn-sound[aria-pressed='true'] .wave { opacity: 1; }

#rail {
  position: fixed;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  height: min(64vh, 580px);
  width: 44px;
  z-index: 4;
  transition: opacity 1.2s ease;
}
#rail svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#rail polyline {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.dot {
  position: absolute;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.dot::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ink-faint);
  transform: translate(-50%, -50%);
  transition: all 0.5s var(--ease-out);
}
.dot.end::before { background: none; border: 1px solid var(--ink-faint); width: 6px; height: 6px; }
.dot:hover::before { background: var(--ink); }
.dot.here::before {
  width: 8px;
  height: 8px;
  background: var(--ink);
  box-shadow: 0 0 10px rgba(255, 240, 220, 0.7);
}
.dot .tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translate(6px, -50%);
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.4s var(--ease-out);
}
.dot .tip em { font-style: normal; letter-spacing: 0.2em; color: var(--ink-faint); margin-right: 0.35em; }
.dot:hover .tip, .dot:focus-visible .tip { opacity: 1; transform: translate(0, -50%); }

.folio {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--ink-faint);
  display: none;
  transition: opacity 1.2s ease;
}
@media (max-width: 759px) {
  #rail { display: none; }
  .folio { display: block; }
}

.hint {
  position: fixed;
  left: 50%;
  bottom: max(44px, calc(env(safe-area-inset-bottom) + 30px));
  transform: translate(-50%, 6px);
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity 1.4s ease, transform 1.4s var(--ease-out);
  pointer-events: none;
}
.hint::after {
  content: '';
  display: block;
  width: 1px;
  height: 26px;
  margin: 10px auto 0;
  background: linear-gradient(var(--ink-faint), transparent);
  animation: drip 2.6s ease-in-out infinite;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }
@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; }
}

body.idle .chrome .chip, body.idle #rail, body.idle .folio { opacity: 0.16; }
body.idle #rail:hover, body.idle .chrome .chip:hover { opacity: 1; }

/* ------------------------------------------------------------ contents */

.contents {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(6, 5, 8, 0.8);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  opacity: 0;
  transition: opacity 0.45s ease;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.contents.open { opacity: 1; }
.contents-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: max(11vh, 76px) 24px 10vh;
}
.contents-title {
  font-size: 12px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 2em;
}
.toc { list-style: none; margin: 0; padding: 0; }
.toc li {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.6s ease, transform 0.8s var(--ease-out);
}
.contents.open .toc li { opacity: 1; transform: none; }
.contents.open .toc li:nth-child(n) { transition-delay: calc(var(--k, 0) * 1ms); }
.toc button {
  display: grid;
  grid-template-columns: 3.4em 34px 1fr;
  align-items: center;
  gap: 0.9em;
  width: 100%;
  background: none;
  border: 0;
  padding: 0.42em 0;
  text-align: left;
  cursor: pointer;
  font-size: 19px;
  color: var(--ink-soft);
  transition: color 0.3s;
}
.toc button:hover, .toc button[aria-current] { color: var(--ink); }
.toc .num { font-size: 12px; letter-spacing: 0.26em; color: var(--ink-faint); text-align: right; }
.toc img, .toc .thumb-blank {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(circle, #000 50%, transparent 71%);
  mask-image: radial-gradient(circle, #000 50%, transparent 71%);
}
.toc .t { font-family: var(--display); font-size: 1.15em; }
.toc button[aria-current] .t::after { content: '  ·  here'; font-family: var(--serif); font-size: 0.6em; letter-spacing: 0.2em; color: var(--ink-faint); }
.contents .close { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; }

/* ------------------------------------------------------------ misc */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) {
  .ln, .numeral, .title, .book-title .ch, .page, .toc li {
    transition: opacity 0.6s ease !important;
    transform: none !important;
    filter: none !important;
    animation: none !important;
    letter-spacing: inherit;
  }
  .book-title .ch { transition-delay: 0s !important; }
  .star { animation: none; }
}
