/* Cover page: cosmic vortex canvas + a 3D hardcover book that opens on hover / tap. */
:root {
  --pw: min(340px, 46vw, 45vh);           /* one page width; the open spread is 2 × --pw */
  --ph: calc(var(--pw) * 1.42);
  --gold: #e8c46a;
  --gold-hi: #fff1bf;
  --gold-lo: #a87a28;
  --ink: #33240f;
  --ease: cubic-bezier(.2, .75, .2, 1);
  color-scheme: dark;
}
@supports (height: 1dvh) {
  :root { --pw: min(340px, 46vw, 45dvh); }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #05040d; color: #efe6d2; overflow: hidden; }
body {
  font-family: 'Cormorant Garamond', 'EB Garamond', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#cosmos { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.stage {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(18px, 4.5vh, 44px);
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

/* ---- the book ------------------------------------------------------------------------- */
.book-anchor { position: relative; width: var(--pw); height: var(--ph); animation: float 7s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(-5px); } 50% { transform: translateY(5px); } }

.book {
  position: absolute; inset: 0;
  perspective: 2400px;
  transform: scale(1.06);
  transition: transform 1s var(--ease);
}
.book.is-open { transform: translateX(calc(var(--pw) / 2)) scale(1); }

.board-back {
  position: absolute; inset: -2.4% -3.2% -2.4% 0;
  border-radius: 3px 10px 10px 3px;
  background: linear-gradient(160deg, #241a52, #140f33 55%, #0b0920);
  box-shadow: 0 30px 60px -10px rgba(0, 0, 0, .8), 0 0 0 1px rgba(232, 196, 106, .15);
}
.page-block {
  position: absolute; inset: .7% -1.7% .7% 0;
  border-radius: 0 5px 5px 0;
  background: repeating-linear-gradient(90deg, #efe3c2 0 1px, #cdb98d 1px 2px);
  box-shadow: inset 0 0 5px rgba(0, 0, 0, .3);
}

.page {
  position: absolute; inset: 0; overflow: hidden;
  color: var(--ink);
  font-size: clamp(11px, calc(var(--pw) * .05), 16.5px);
  background:
    radial-gradient(120% 90% at 50% 40%, rgba(255, 255, 255, .35), transparent 70%),
    linear-gradient(90deg, #e1d0a6 0%, #f4e9cd 7%, #f8f0da 55%, #efe2c0 100%);
}
.page::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-radial-gradient(circle at 30% 20%, rgba(120, 90, 40, .035) 0 1px, transparent 1px 3px);
}
.page-right { border-radius: 0 5px 5px 0; box-shadow: inset 16px 0 22px -14px rgba(90, 60, 15, .55); }
.page-left {
  border-radius: 5px 0 0 5px;
  background:
    radial-gradient(120% 90% at 50% 40%, rgba(255, 255, 255, .35), transparent 70%),
    linear-gradient(270deg, #e1d0a6 0%, #f4e9cd 7%, #f8f0da 55%, #efe2c0 100%);
  box-shadow: inset -16px 0 22px -14px rgba(90, 60, 15, .55);
}
.page-inner { position: absolute; inset: 8% 9% 7% 11%; display: flex; flex-direction: column; z-index: 1; }
.page-left .page-inner { inset: 8% 11% 7% 9%; align-items: center; justify-content: center; text-align: center; gap: .8em; }

/* the cover: front board; its back carries the left-hand (title) page */
.cover {
  position: absolute; inset: 0; z-index: 3;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform 1.25s var(--ease);
  outline: none;
}
.book.is-open .cover { transform: rotateY(-180deg); }
.cover-front, .cover-back { position: absolute; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.cover-back { inset: 0; transform: rotateY(180deg); }
.cover-back::before { /* board edge around the pasted-down page */
  content: ''; position: absolute; inset: -2.4% 0 -2.4% -3.2%; z-index: -1;
  border-radius: 10px 3px 3px 10px;
  background: linear-gradient(200deg, #241a52, #140f33 55%, #0b0920);
  box-shadow: 0 30px 60px -10px rgba(0, 0, 0, .8);
}

.cover-front {
  inset: -2.4% -3.2% -2.4% 0;
  border-radius: 3px 10px 10px 3px;
  overflow: hidden;
  font-size: calc(var(--pw) * .05);
  background:
    radial-gradient(130% 80% at 25% 10%, rgba(130, 95, 235, .38), transparent 60%),
    radial-gradient(90% 60% at 85% 100%, rgba(40, 120, 210, .28), transparent 60%),
    repeating-linear-gradient(118deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, #261b57 0%, #150f36 55%, #0b0920 100%);
  box-shadow:
    inset 0 0 0 1px rgba(232, 196, 106, .18), inset 0 0 40px rgba(0, 0, 0, .55),
    0 30px 60px -12px rgba(0, 0, 0, .85), 0 0 90px rgba(150, 110, 255, .3);
  transition: box-shadow .6s ease;
}
.cover:hover .cover-front, .cover:focus-visible .cover-front {
  box-shadow:
    inset 0 0 0 1px rgba(232, 196, 106, .3), inset 0 0 40px rgba(0, 0, 0, .55),
    0 30px 60px -12px rgba(0, 0, 0, .85), 0 0 120px rgba(255, 210, 140, .4);
}
.cover-front::before { /* hinge */
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 7%; z-index: 1;
  background: linear-gradient(90deg, rgba(0, 0, 0, .6), rgba(255, 255, 255, .07) 55%, rgba(0, 0, 0, .35));
}
.cover-front::after { /* slow gold sheen */
  content: ''; position: absolute; inset: -50%; pointer-events: none;
  background: linear-gradient(115deg, transparent 44%, rgba(255, 236, 180, .13) 50%, transparent 56%);
  animation: sheen 8s ease-in-out infinite;
}
@keyframes sheen { 0%, 55% { transform: translateX(-45%); } 100% { transform: translateX(45%); } }

.cover-frame {
  position: absolute; inset: 7% 8% 7% 14%;
  border: 1px solid rgba(232, 196, 106, .75);
  outline: 1px solid rgba(232, 196, 106, .3); outline-offset: .45em;
  border-radius: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .55em; padding: 1em .5em; text-align: center;
}
.emblem { width: 48%; filter: drop-shadow(0 0 10px rgba(232, 196, 106, .45)); }
.em-orbits { transform-origin: 60px 60px; animation: orbit 60s linear infinite; }
@keyframes orbit { to { transform: rotate(360deg); } }
.cover-title {
  margin: .15em 0 0; padding-left: .14em;
  font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: 2.2em; line-height: 1.05;
  letter-spacing: .14em; text-transform: uppercase; overflow-wrap: anywhere;
  background: linear-gradient(180deg, #fff6d6 0%, #f0d27e 45%, #b8862e 62%, #f6dc8c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .65)) drop-shadow(0 0 12px rgba(232, 196, 106, .35));
}
.cover-title.is-long { font-size: 1.5em; letter-spacing: .08em; }
.cover-sub { margin: 0; max-width: 13em; font-style: italic; font-size: 1.05em; line-height: 1.25; color: #e9dcbc; }
.cover-stars { margin: 0; color: var(--gold); letter-spacing: .5em; font-size: .8em; opacity: .8; }

/* left page: title page */
.tp-name { margin: 0; font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: 1.35em; letter-spacing: .22em; color: #4a3212; text-transform: uppercase; }
.tp-rule { color: var(--gold-lo); font-size: 1.4em; line-height: 1; }
.epigraph { margin: 0; font-style: italic; font-size: 1.14em; line-height: 1.5; color: #4b3a22; white-space: pre-line; }
.edition {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0;
  font-family: 'Cinzel', Georgia, serif; font-size: .6em; letter-spacing: .25em; text-transform: uppercase; color: #8c6a33;
}

/* right page: contents */
.toc-title {
  margin: 0 0 .2em; text-align: center;
  font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: 1.12em; letter-spacing: .3em; text-transform: uppercase; color: #5a3d12;
}
.toc-title::after { content: '— ✦ —'; display: block; margin-top: .2em; font-size: .7em; letter-spacing: .3em; color: var(--gold-lo); }
.toc { list-style: none; margin: .4em 0; padding: 0 .1em 0 0; flex: 1 1 auto; overflow-y: auto; scrollbar-width: thin; }
.toc li {
  opacity: 0; transform: translateY(6px);
  transition: opacity .5s ease, transform .5s ease;
  transition-delay: calc(.5s + var(--i, 0) * .07s);
}
.book.is-open .toc li { opacity: 1; transform: none; }
.toc a {
  display: flex; align-items: baseline; gap: .35em;
  padding: .3em .25em; border-radius: 3px;
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 1.06em; line-height: 1.2;
}
.toc a::after { content: ''; flex: 1 1 1.2em; min-width: .8em; border-bottom: 1px dotted rgba(80, 55, 20, .45); transform: translateY(-.25em); }
.toc .depth-1 a { padding-left: 1.1em; font-weight: 500; font-size: .96em; font-style: italic; }
.toc a:hover, .toc a:focus-visible { outline: none; color: #7a4c0c; background: linear-gradient(90deg, rgba(232, 196, 106, .38), rgba(232, 196, 106, 0)); }
.toc-empty { font-style: italic; color: #7d6440; }
.toc-extra {
  display: flex; align-items: center; justify-content: space-between; gap: .6em; flex-wrap: wrap;
  padding-top: .6em; border-top: 1px solid rgba(120, 85, 30, .25);
  opacity: 0; transition: opacity .5s ease .85s;
}
.book.is-open .toc-extra { opacity: 1; }
.toc-read { font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: .74em; letter-spacing: .12em; text-transform: uppercase; color: #6b4a14; text-decoration: none; }
.toc-read:hover, .toc-read:focus-visible { color: #9a6514; }
.toc-edit {
  display: inline-flex; align-items: center; gap: .35em;
  padding: .5em .95em; border-radius: 999px;
  font-family: 'Cinzel', Georgia, serif; font-weight: 700; font-size: .78em; letter-spacing: .14em; text-transform: uppercase;
  color: #fff1d6; text-decoration: none;
  background: radial-gradient(circle at 35% 30%, #d2464e, #8e1621 60%, #5c0b13);
  box-shadow: 0 2px 0 #3d070c, 0 4px 12px rgba(120, 15, 25, .45), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .2s ease, box-shadow .2s ease;
}
.toc-edit svg { width: 1.25em; height: 1.25em; }
.toc-edit:hover, .toc-edit:focus-visible { outline: none; transform: translateY(-1px) scale(1.05); box-shadow: 0 3px 0 #3d070c, 0 6px 18px rgba(200, 40, 50, .55), inset 0 1px 0 rgba(255, 255, 255, .3); }

/* ---- hint + footer ------------------------------------------------------------------- */
.hint {
  margin: 0; text-align: center;
  font-family: 'Cinzel', Georgia, serif; font-size: clamp(10.5px, 1.5vw, 13px); letter-spacing: .3em; text-transform: uppercase;
  color: rgba(240, 225, 190, .78); text-shadow: 0 0 12px rgba(150, 110, 255, .7);
  animation: breathe 3.2s ease-in-out infinite;
  transition: opacity .6s ease;
}
@keyframes breathe { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.hint-tap { display: none; }
@media (hover: none), (pointer: coarse) {
  .hint-hover { display: none; }
  .hint-tap { display: inline; }
}
body.book-open .hint { opacity: 0; animation: none; }
.foot {
  position: fixed; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom)); text-align: center; pointer-events: none;
  font-family: 'Cinzel', Georgia, serif; font-size: 10px; letter-spacing: .3em; text-transform: uppercase; color: rgba(230, 215, 180, .38);
}
.noscript { position: fixed; left: 16px; right: 16px; bottom: 40px; text-align: center; color: #efe6d2; }
.noscript a { color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  .book-anchor, .cover-front::after, .em-orbits, .hint { animation: none; }
  .book, .cover { transition-duration: .4s; }
}
