/* ============================================================
   SANCTUARY — CAIN'S TOME (the lore wiki)
   An illuminated grimoire: parchment pages on a dark, candlelit table.
   Builds on styles.css (cursor, nav, loader, embers, vars).
   ============================================================ */

:root {
  --ink:       #4a3724;
  --ink-soft:  #6f5a3e;
  --parch:     #e6dabd;
  --parch-2:   #d8c7a0;
  --rubric:    #8a1410;   /* illuminated red */
  --gilt:      #9a6b1e;   /* gold leaf */
}

/* ---------- page header (dark, like the rest of the site) ---------- */
.tome-hero {
  position: relative; z-index: 5;
  min-height: 52vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: clamp(7rem,16vh,11rem) clamp(1.2rem,6vw,6rem) clamp(2rem,5vh,3rem);
  overflow: hidden;
}
.tome-hero__glow {
  position: absolute; inset: -20% 0 auto 0; height: 90%; z-index: -1;
  background: radial-gradient(50% 60% at 50% 25%, rgba(224,165,46,.22), transparent 65%);
  animation: breathe 7s ease-in-out infinite;
}
.tome-hero__eyebrow { font-family: var(--display); letter-spacing: .5em; font-size: clamp(.6rem,1.4vw,.82rem); text-transform: uppercase; color: var(--gold); }
.tome-hero__title {
  font-family: var(--decor); font-weight: 900; font-size: clamp(2.8rem,9vw,6rem); line-height: .9; margin: 1rem 0 .6rem;
  color: transparent; background: linear-gradient(180deg, #e8d9b0, #9a6b1e 95%);
  -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 4px 26px rgba(224,165,46,.28));
}
.tome-hero__quote { font-family: var(--display); font-style: italic; color: var(--ember-soft); font-size: clamp(1rem,2vw,1.4rem); }
.tome-hero__quote::before, .tome-hero__quote::after { content: "“"; }
.tome-hero__quote::after { content: "”"; }
.tome-hero__attr { margin-top: .6rem; font-family: var(--display); letter-spacing: .25em; font-size: .7rem; text-transform: uppercase; color: var(--bone-dim); }

/* ============================================================
   THE BOOK
   ============================================================ */
.tome {
  position: relative; z-index: 5;
  max-width: 1140px; margin: 0 auto clamp(4rem,10vh,7rem);
  padding: 0 clamp(1rem,4vw,2rem);
  display: grid; grid-template-columns: 320px 1fr;
  perspective: 2200px;
}
.tome__book {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 320px 1fr;
  height: min(78vh, 760px);
  border-radius: 4px;
  background:
    linear-gradient(90deg, #1a0f08, #2a1810 8%, #2a1810 92%, #1a0f08);
  padding: 14px;
  box-shadow: 0 50px 120px rgba(0,0,0,.7), 0 0 0 1px rgba(224,165,46,.15), 0 0 70px rgba(224,165,46,.08);
}
/* a parchment page */
.page {
  position: relative; overflow-y: auto; overflow-x: hidden;
  background:
    radial-gradient(120% 100% at 50% 0%, #efe4c8, transparent 60%),
    radial-gradient(90% 80% at 80% 100%, #cdbb91, transparent 55%),
    linear-gradient(180deg, var(--parch), var(--parch-2));
  color: var(--ink);
  padding: clamp(1.6rem,3vw,2.6rem) clamp(1.4rem,2.6vw,2.4rem);
}
.page::after {  /* aged blotch + edge darkening */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 60px rgba(74,55,36,.35), inset 0 0 14px rgba(74,55,36,.25);
  mix-blend-mode: multiply;
}
.page--index { border-right: 0; box-shadow: inset -22px 0 36px -22px rgba(0,0,0,.55); }
.page--content { box-shadow: inset 22px 0 36px -22px rgba(0,0,0,.55); }

/* parchment scrollbars */
.page::-webkit-scrollbar { width: 8px; }
.page::-webkit-scrollbar-thumb { background: rgba(74,55,36,.4); border-radius: 8px; }
.page::-webkit-scrollbar-track { background: transparent; }

/* ---------- left page: search + table of contents ---------- */
.codex-search { position: relative; margin-bottom: 1.4rem; }
.codex-search input {
  width: 100%; background: rgba(74,55,36,.08);
  border: 1px solid rgba(74,55,36,.3); border-radius: 2px;
  padding: .7rem .9rem; cursor: none;
  font-family: var(--serif); font-size: .95rem; color: var(--ink);
}
.codex-search input::placeholder { color: var(--ink-soft); font-style: italic; }
.codex-search input:focus { outline: none; border-color: var(--rubric); background: rgba(138,20,16,.06); }

.toc__cat {
  font-family: var(--display); letter-spacing: .25em; font-size: .64rem; text-transform: uppercase;
  color: var(--gilt); margin: 1.4rem 0 .5rem; padding-bottom: .3rem;
  border-bottom: 1px solid rgba(154,107,30,.35);
}
.toc__cat:first-child { margin-top: 0; }
.toc__cat.is-empty { display: none; }
.toc__link {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: none;
  font-family: var(--serif); font-size: 1rem; color: var(--ink);
  padding: .32rem .5rem; border-left: 2px solid transparent;
  transition: color .2s, background .2s, border-color .2s, padding .2s;
}
.toc__link:hover { color: var(--rubric); background: rgba(138,20,16,.06); padding-left: .8rem; }
.toc__link.is-active { color: var(--rubric); border-left-color: var(--rubric); background: rgba(138,20,16,.08); font-weight: 500; }
.toc__link.is-hidden { display: none; }
.toc__empty { color: var(--ink-soft); font-style: italic; font-size: .9rem; padding: .5rem; display: none; }
.toc__empty.show { display: block; }

/* ---------- right page: entries ---------- */
.entry { display: none; }
.entry.is-active { display: block; }
.page--content.is-turning .entry.is-active { animation: pageturn .5s var(--ease); transform-origin: left center; }
@keyframes pageturn {
  0%   { opacity: 0; transform: rotateY(-22deg) translateX(30px); }
  100% { opacity: 1; transform: none; }
}
.entry__cat { font-family: var(--display); letter-spacing: .3em; font-size: .62rem; text-transform: uppercase; color: var(--gilt); }
.entry__title {
  font-family: var(--decor); font-weight: 900; font-size: clamp(1.9rem,4.2vw,3rem); line-height: 1;
  color: var(--rubric); margin: .4rem 0 .2rem;
}
.entry__sub { font-family: var(--display); font-style: italic; color: var(--ink-soft); font-size: 1.05rem; margin-bottom: 1.4rem; }
.entry__rule { height: 1px; background: linear-gradient(90deg, rgba(154,107,30,.6), transparent); margin-bottom: 1.4rem; }
.entry__body p { font-size: 1.06rem; line-height: 1.85; margin-bottom: 1.1rem; }
.entry__body p:first-of-type::first-letter {
  float: left; font-family: var(--decor); font-weight: 900; font-size: 3.6em; line-height: .66;
  padding: .04em .12em 0 0; color: var(--rubric);
  text-shadow: 1px 1px 0 rgba(154,107,30,.4);
}
.entry__body a, .entry__related a {
  color: var(--rubric); text-decoration: none; cursor: none;
  border-bottom: 1px dotted rgba(138,20,16,.5); transition: color .2s, border-color .2s;
}
.entry__body a:hover, .entry__related a:hover { color: var(--gilt); border-color: var(--gilt); }
.entry__related { margin-top: 1.8rem; padding-top: 1.2rem; border-top: 1px solid rgba(74,55,36,.25); }
.entry__related b { font-family: var(--display); letter-spacing: .2em; font-size: .64rem; text-transform: uppercase; color: var(--gilt); display: block; margin-bottom: .6rem; }
.entry__related a { margin-right: 1rem; line-height: 2; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .tome__book { grid-template-columns: 1fr; height: auto; }
  .page--index { max-height: 42vh; box-shadow: inset 0 -22px 28px -22px rgba(0,0,0,.5); }
  .page--content { box-shadow: inset 0 22px 28px -22px rgba(0,0,0,.5); }
  .tome, .tome__book { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .page--content.is-turning .entry.is-active { animation: none; }
}

/* ---------- illuminated plates (entry illustrations) ---------- */
.entry__plate {
  float: right; width: clamp(150px, 38%, 280px);
  margin: .2rem 0 1.1rem 1.6rem; padding: 8px;
  background: linear-gradient(180deg, #efe6cc, #d6c39b);
  border: 1px solid rgba(74,55,36,.45);
  box-shadow: 0 8px 22px rgba(20,10,4,.45), inset 0 0 0 1px rgba(154,107,30,.45);
  transform: rotate(-0.7deg);
}
.entry__plate img {
  display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; object-position: center top;
  border: 1px solid rgba(74,55,36,.5);
  filter: sepia(.42) contrast(1.04) brightness(.97) saturate(.82);
}
.entry__plate figcaption {
  margin-top: .55rem; text-align: center;
  font-family: var(--display); font-style: italic; font-size: .64rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft);
}
@media (max-width: 560px) {
  .entry__plate { float: none; width: 100%; margin: 0 0 1.3rem; transform: none; }
}

/* ============================================================
   EXPERIMENTAL LAYER — plate entrance, candlelight, sound toggle
   ============================================================ */
@keyframes plateIn {
  0%   { opacity: 0; transform: rotate(-5deg) translateY(20px) scale(.95); }
  100% { opacity: 1; transform: rotate(-0.7deg); }
}
.page--content.is-turning .entry.is-active .entry__plate { animation: plateIn .7s var(--ease) .1s backwards; }

/* the book breathes with candlelight */
@keyframes candle {
  0%,100% { box-shadow: 0 50px 120px rgba(0,0,0,.7), 0 0 0 1px rgba(224,165,46,.15), 0 0 70px rgba(224,165,46,.08); }
  45%     { box-shadow: 0 50px 120px rgba(0,0,0,.7), 0 0 0 1px rgba(224,165,46,.20), 0 0 96px rgba(224,165,46,.15); }
  72%     { box-shadow: 0 50px 120px rgba(0,0,0,.7), 0 0 0 1px rgba(224,165,46,.12), 0 0 56px rgba(224,165,46,.05); }
}
.tome__book { animation: candle 5s ease-in-out infinite; }

/* floating sound toggle (paper sounds) */
.soundtoggle {
  position: fixed; right: clamp(1rem,3vw,2.2rem); bottom: clamp(1rem,3vw,2.2rem); z-index: 120; cursor: none;
  display: flex; align-items: center; gap: .7rem; padding: .65rem 1rem;
  background: rgba(7,6,10,.62); backdrop-filter: blur(8px);
  border: 1px solid rgba(224,165,46,.3); border-radius: 999px; color: var(--bone-dim);
  font-family: var(--display); letter-spacing: .18em; font-size: .6rem; text-transform: uppercase;
  transition: color .3s, border-color .3s, box-shadow .3s;
}
.soundtoggle:hover { color: var(--bone); border-color: var(--gold); }
.soundtoggle.is-on { color: var(--bone); border-color: var(--gold); box-shadow: 0 0 22px rgba(224,165,46,.3); }
.soundtoggle__wave { display: flex; align-items: center; gap: 2px; height: 14px; }
.soundtoggle__wave i { width: 2px; height: 4px; background: var(--gold); border-radius: 1px; }
.soundtoggle.is-on .soundtoggle__wave i { animation: eq 1s ease-in-out infinite; }
.soundtoggle.is-on .soundtoggle__wave i:nth-child(2){ animation-delay:.15s; }
.soundtoggle.is-on .soundtoggle__wave i:nth-child(3){ animation-delay:.3s; }
.soundtoggle.is-on .soundtoggle__wave i:nth-child(4){ animation-delay:.45s; }
@keyframes eq { 0%,100%{ height:4px; } 50%{ height:13px; } }

@media (prefers-reduced-motion: reduce) {
  .tome__book { animation: none; }
  .page--content.is-turning .entry.is-active .entry__plate { animation: none; }
  .soundtoggle.is-on .soundtoggle__wave i { animation: none; height: 9px; }
}

/* ---------- Tome -> Codex back-link ---------- */
.entry__codex {
  display: inline-block; margin-left: 1rem;
  font-family: var(--display); letter-spacing: .14em; font-size: .68rem; text-transform: uppercase;
  color: var(--gilt) !important; border-bottom: 1px solid rgba(154,107,30,.5) !important;
}
.entry__codex:hover { color: var(--rubric) !important; border-color: var(--rubric) !important; }

/* ---------- the eternal timeline (special entry) ---------- */
.tl { list-style: none; margin: 0; padding: 0 0 0 1.4rem; border-left: 2px solid rgba(154,107,30,.4); }
.tl li { position: relative; padding: 0 0 1.5rem 1.2rem; }
.tl li::before {
  content: ""; position: absolute; left: calc(-1.4rem - 6px); top: .35rem;
  width: 11px; height: 11px; border-radius: 50%; background: var(--rubric);
  box-shadow: 0 0 0 3px var(--parch), 0 0 10px rgba(138,20,16,.6);
}
.tl__era { display: block; font-family: var(--decor); font-weight: 700; font-size: 1.05rem; color: var(--rubric); margin-bottom: .3rem; }
.tl li p { font-size: .98rem; line-height: 1.65; margin: 0; color: var(--ink); }

/* ============================================================
   BOOK REALISM v2 — taller, bound, ribboned (overrides above)
   ============================================================ */
.tome { margin-bottom: clamp(4rem,10vh,8rem); }
.tome__book {
  position: relative;
  height: min(88vh, 1000px);
  padding: 16px;
  background:
    linear-gradient(90deg, #140b06, #2a1810 6%, #241510 50%, #2a1810 94%, #140b06);
  border-radius: 6px;
  box-shadow: 0 60px 130px rgba(0,0,0,.75), 0 0 0 1px rgba(224,165,46,.16),
              0 0 80px rgba(224,165,46,.08),
              inset 0 0 0 2px rgba(0,0,0,.5), inset 0 0 30px rgba(0,0,0,.6);
}
/* stacked page-edges peeking from the leather */
.tome__book::before, .tome__book::after {
  content: ""; position: absolute; top: 22px; bottom: 22px; width: 7px; z-index: 0;
  background: repeating-linear-gradient(0deg,#e7dcbe 0 2px,#cdbb91 2px 4px);
  box-shadow: 0 0 6px rgba(0,0,0,.5);
}
.tome__book::before { left: 9px; border-radius: 2px 0 0 2px; }
.tome__book::after  { right: 9px; border-radius: 0 2px 2px 0; }

/* the page becomes a framed column: sticky head, scrolling body, sticky folio */
.page {
  position: relative; z-index: 1;
  padding: 0 clamp(1.4rem,2.6vw,2.4rem);
  overflow-y: auto; overflow-x: hidden;
}
.page--index  { border-right: 1px solid rgba(0,0,0,.45); }
.page--content { border-left: 1px solid rgba(0,0,0,.45); }

.page__head {
  position: sticky; top: 0; z-index: 6;
  margin: 0 calc(-1 * clamp(1.4rem,2.6vw,2.4rem)) 1.4rem;
  padding: .9rem clamp(1.4rem,2.6vw,2.4rem);
  background: linear-gradient(180deg, #ece1c4, #e0d0aa);
  border-bottom: 1px solid rgba(154,107,30,.4);
  font-family: var(--decor); font-weight: 700; font-size: .92rem; letter-spacing: .04em;
  color: var(--rubric); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page__head span { color: var(--gilt); }
.page__folio {
  position: sticky; bottom: 0; z-index: 6;
  margin: 1.4rem calc(-1 * clamp(1.4rem,2.6vw,2.4rem)) 0;
  padding: .55rem; text-align: center;
  background: linear-gradient(0deg, #e0d0aa, transparent);
  font-family: var(--display); letter-spacing: .35em; font-size: .6rem; text-transform: uppercase; color: var(--ink-soft);
}
.codex-search { margin-top: .2rem; }

/* spine gutter (desktop two-page) */
.tome__spine {
  position: absolute; top: 16px; bottom: 16px; left: calc(16px + 320px);
  width: 30px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,.5) 45%, rgba(0,0,0,.55) 55%, transparent);
}
.tome__spine::before {
  content: ""; position: absolute; inset: 0 49%; border-left: 1px dashed rgba(224,165,46,.35);
}

/* ribbon bookmark hanging from the top */
.tome__ribbon {
  position: absolute; top: -6px; right: 12%; width: 26px; height: 165px; z-index: 3; pointer-events: none;
  background: linear-gradient(180deg, #7a0f0c, #b3261e 60%, #8a1410);
  box-shadow: 0 8px 18px rgba(0,0,0,.5), inset -3px 0 6px rgba(0,0,0,.35);
  clip-path: polygon(0 0,100% 0,100% 100%,50% 84%,0 100%);
}

/* folded aged corner on the content page */
.tome__corner {
  position: absolute; right: 16px; bottom: 16px; width: 42px; height: 42px; z-index: 4; pointer-events: none;
  background: linear-gradient(135deg, transparent 50%, #cdbb91 50%, #b9a577);
  box-shadow: -3px -3px 8px rgba(0,0,0,.3);
}

/* fleuron divider under each entry title */
.entry__rule {
  display: flex; align-items: center; gap: 1rem; height: auto; background: none;
  margin: .2rem 0 1.5rem; color: var(--gilt);
}
.entry__rule::before, .entry__rule::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(154,107,30,.6), transparent);
}
.entry__rule span { font-size: 1.1rem; opacity: .85; }

/* a touch more breathing room for the longer entries */
.entry__body p { margin-bottom: 1.2rem; }
.entry { padding-bottom: .5rem; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .tome__book { grid-template-columns: 1fr; height: auto; max-height: none; }
  .page--index { max-height: 44vh; border-right: 0; border-bottom: 1px solid rgba(0,0,0,.4); }
  .page--content { border-left: 0; }
  .tome__spine { display: none; }
  .tome__book::before, .tome__book::after { display: none; }
  .tome__ribbon { right: 8%; height: 130px; }
}
@media (max-width: 560px) {
  .tome__corner { display: none; }
  .page__head { font-size: .8rem; }
  .entry__plate { float: none; width: 100%; margin: 0 0 1.3rem; transform: none; }
}
