/* Lore, Thesis, Unit */
#lore { background: var(--paper); position: relative; }
#lore .folio-note {
  font-family: var(--serif); font-style: italic; font-size: clamp(21px, 2.4vw, 26px); color: var(--ink-soft);
  text-align: center; max-width: 36ch; margin: -16px auto 56px; line-height: 1.4;
}
#lore .folio-note::before, #lore .folio-note::after { content: "✦"; display: block; font-style: normal; font-size: 13px; color: var(--gold); margin: 12px 0; }

/* Frontispiece: banner split into two halves that meet */
.spark-stage { --p: 1; --cx: 0; --cw: 1500; margin: 0 0 96px; }
.stage-frame {
  position: relative; overflow: hidden; background: var(--paper-deep);
  aspect-ratio: calc(var(--cw) / 500); border: 1px solid var(--ink);
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 7px var(--gold), 0 30px 60px -30px rgba(28, 23, 18, .45);
}
.spark-stage .half {
  position: absolute; top: 0; bottom: 0; width: 50%;
  background-image: url("../assets/banner.png"); background-repeat: no-repeat;
  background-size: calc(1500 / (var(--cw) / 2) * 100%) 100%;
  opacity: calc(.45 + .55 * var(--p)); will-change: transform;
}
.spark-stage .half-l {
  left: 0; background-position: calc(var(--cx) / (1500 - var(--cw) / 2) * 100%) 0;
  transform: translateX(calc((1 - var(--p)) * -22%));
}
.spark-stage .half-r {
  right: 0; background-position: calc(750 / (1500 - var(--cw) / 2) * 100%) 0;
  transform: translateX(calc((1 - var(--p)) * 22%));
}
.spark-stage .half-l::after, .spark-stage .half-r::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 1px; background: var(--gold);
  opacity: calc(1 - var(--p));
}
.spark-stage .half-l::after { right: 0; } .spark-stage .half-r::after { left: 0; }
.spark { position: absolute; left: 50%; top: 40%; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity .5s; }
.spark i {
  position: absolute; width: 220px; height: 220px; margin: -110px 0 0 -110px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0, rgba(255, 238, 190, .95) 8%, rgba(226, 183, 90, .55) 24%, transparent 62%);
  mix-blend-mode: screen; transform: scale(.2); transition: transform .8s cubic-bezier(.2, .8, .2, 1);
}
.spark b {
  position: absolute; width: 340px; height: 340px; margin: -170px 0 0 -170px; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 236, 180, .55) 0 2deg, transparent 2deg 15deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 68%); mask: radial-gradient(circle, #000 0, transparent 68%);
  mix-blend-mode: screen; transform: scale(.2) rotate(0deg); transition: transform 1.2s ease;
}
.spark-stage.met .spark { opacity: 1; }
.spark-stage.met .spark i { transform: scale(1); animation: spark-pulse 3.4s ease-in-out .8s infinite; }
.spark-stage.met .spark b { transform: scale(1) rotate(30deg); }
@keyframes spark-pulse { 50% { transform: scale(1.18); } }
.spark-stage figcaption, .plate figcaption {
  margin-top: 18px; text-align: center; font-family: var(--serif); font-size: 18px; color: var(--ink-soft);
}
.spark-stage figcaption span, .plate figcaption span { font-style: italic; color: var(--gold); margin-right: 4px; }
.spark-stage figcaption em { display: block; font-size: 14px; margin-top: 4px; opacity: .8; }
.spark-stage.met figcaption em { visibility: hidden; }

/* Codex chapters */
.codex { border-top: 1px solid var(--ink); }
.chapter {
  display: grid; grid-template-columns: 120px minmax(0, 1fr) 300px; gap: 40px; align-items: start;
  padding: 56px 0; border-bottom: 1px solid var(--rule);
}
.ch-num { font-family: var(--serif); font-style: italic; font-size: clamp(64px, 8vw, 96px); line-height: .9; color: var(--gold); }
.ch-num span { display: block; font-family: var(--sans); font-style: normal; font-size: 11px; letter-spacing: .24em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 14px; }
.ch-kind { font-size: 11px; letter-spacing: .24em; text-transform: uppercase; color: var(--ink-soft); display: flex; align-items: center; gap: 12px; }
.ch-kind::before { content: ""; width: 28px; height: 1px; background: var(--gold); }
.ch-body h3 { font-family: var(--serif); font-weight: 500; font-size: clamp(32px, 4vw, 44px); line-height: 1.05; margin: 10px 0 22px; }
.ch-body p { font-family: var(--serif); font-size: 21px; line-height: 1.55; max-width: 60ch; }
.ch-body p + p { margin-top: .9em; }
.ch-body > p:first-of-type::first-letter {
  float: left; font-size: 78px; line-height: .78; padding: 7px 10px 0 0; color: var(--gold); font-weight: 500;
}
.ch-body .ch-quote { font-style: italic; font-size: clamp(26px, 3vw, 34px); line-height: 1.2; margin-top: 1.1em; padding-top: 1em; border-top: 1px solid currentColor; color: var(--gold-bright); }
.ch-body .ch-quote::first-letter { all: unset; }
.ch-orn { font-family: var(--serif); font-style: italic; font-size: 220px; line-height: .8; color: var(--gold); opacity: .5; text-align: center; border: 1px solid var(--rule); padding: 36px 0 20px; }
.chapter:nth-child(even) { grid-template-columns: 300px minmax(0, 1fr) 120px; }
.chapter:nth-child(even) .ch-num { order: 3; text-align: right; }
.chapter:nth-child(even) .plate, .chapter:nth-child(even) .ch-orn { order: 1; }
.chapter:nth-child(even) .ch-body { order: 2; }

/* Prophecy chapters: navy night panels */
.chapter.prophecy {
  background: radial-gradient(ellipse at 80% 0%, var(--night-2), var(--night) 75%); color: var(--night-ink);
  padding: 56px 40px; border-bottom: 0; margin-top: 32px; border: 1px solid var(--gold);
  box-shadow: inset 0 0 0 5px var(--night), inset 0 0 0 6px rgba(226, 183, 90, .5);
}
.chapter.prophecy .ch-num { color: var(--gold-bright); }
.chapter.prophecy .ch-num span, .chapter.prophecy .ch-kind { color: var(--night-soft); }
.chapter.prophecy .ch-kind::before { background: var(--electric); }
.chapter.prophecy .ch-body > p:first-of-type::first-letter { color: var(--gold-bright); }
.chapter.prophecy .plate figcaption { color: var(--night-soft); }
.chapter.prophecy .plate figcaption span { color: var(--gold-bright); }
.chapter.wide { grid-template-columns: 120px minmax(0, 1fr); }
.chapter.wide .plate { grid-column: 2; max-width: 620px; }
.chapter.wide:nth-child(even) .ch-num { order: 0; text-align: left; }
.chapter.wide:nth-child(even) .ch-body, .chapter.wide:nth-child(even) .plate { order: 0; }
.chapter.wide:nth-child(even) { grid-template-columns: 120px minmax(0, 1fr); }

/* Plates: framed engraving crops of the banner, region set by --x --y --w --h (banner px) */
.plate { margin: 0; }
.plate-img {
  background: url("../assets/banner.png") no-repeat;
  background-size: calc(1500 / var(--w) * 100%) auto;
  background-position: calc(var(--x) / (1500 - var(--w)) * 100%) calc(var(--y) / (500 - var(--h)) * 100%);
  aspect-ratio: calc(var(--w) / var(--h));
  border: 1px solid var(--ink); outline: 1px solid var(--gold); outline-offset: -9px;
  box-shadow: 0 0 0 9px #fbf7ef, 0 0 0 10px var(--ink), 0 24px 40px -24px rgba(0, 0, 0, .5);
  margin: 10px;
}
.plate-img.sepia { filter: sepia(.55) contrast(1.05); }
.prophecy .plate-img { box-shadow: 0 0 0 9px var(--night), 0 0 0 10px var(--gold), 0 24px 40px -24px #000; border-color: var(--gold); outline-color: rgba(226, 183, 90, .5); }

/* Laws */
.laws { margin-top: 96px; max-width: 820px; margin-left: auto; margin-right: auto; text-align: center; }
.laws-head .orn { color: var(--gold); font-size: 18px; }
.laws-head h3 { font-family: var(--serif); font-weight: 500; font-size: clamp(34px, 5vw, 52px); line-height: 1.05; margin: 8px 0; }
.laws-head p { font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink-soft); }
.laws ol { list-style: none; margin-top: 40px; border-top: 1px solid var(--ink); text-align: left; }
.laws li { display: grid; grid-template-columns: 64px 1fr; align-items: baseline; padding: 20px 0; border-bottom: 1px solid var(--rule); font-family: var(--serif); font-size: clamp(21px, 2.6vw, 28px); line-height: 1.3; }
.laws li b { font-style: italic; font-weight: 500; color: var(--gold); }

/* Thesis polish */
#thesis { background: var(--paper); border-top: 1px solid var(--rule); }
#thesis .essay aside { border-top: 1px solid var(--ink); padding-top: 12px; align-self: start; position: sticky; top: 100px; }
.marginalia .mn { display: block; font-family: var(--serif); font-style: italic; font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--gold); margin-bottom: 14px; }
.marginalia strong { font-family: var(--serif); font-size: 26px; letter-spacing: 0; font-weight: 500; }
.marginalia em { display: block; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--rule); font-family: var(--serif); font-size: 16px; line-height: 1.4; letter-spacing: 0; text-transform: none; }
#thesis .pull { position: relative; border-color: var(--ink); background: none; }
#thesis .pull::before { content: "❝"; position: absolute; left: 50%; top: -22px; transform: translateX(-50%); background: var(--paper); padding: 0 14px; color: var(--gold); font-style: normal; font-size: 30px; line-height: 40px; }
#thesis .pull.then { padding-top: 40px; }
#thesis .pull.then::before { content: "✦"; font-size: 18px; }
#thesis .costs li:hover { background: rgba(184, 137, 47, .08); }
#thesis .costs li span { color: var(--gold); }
#thesis .thesis-end { font-style: italic; font-size: 1.25em; margin-top: 1.4em; color: var(--ink); }
#thesis .thesis-end::after { content: " ✦"; color: var(--gold); font-style: normal; }

/* Unit polish */
#unit { border-top: 1px solid var(--rule); }
#unit .definition { padding-bottom: .14em; background: linear-gradient(100deg, var(--ink), #4a3b27 60%, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.apple { margin: 32px 0 0; color: var(--ink); max-width: 340px; }
.apple svg { width: 100%; height: auto; display: block; }
.apple .lbl { font-family: var(--mono); font-size: 11px; }
.apple .rule-v { stroke: var(--gold); }
.apple figcaption { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--ink-soft); margin-top: 6px; }
.apple figcaption span { color: var(--gold); }
.apple-low { animation: apple-lift 4.8s ease-in-out infinite; }
@keyframes apple-lift { 0%, 20% { transform: translate(160px, 150px); } 55%, 75% { transform: translate(160px, 40px); } 100% { transform: translate(160px, 150px); } }
.facts { list-style: none; margin-top: 28px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--ink); }
.facts li { padding: 16px 14px; font-size: 13px; line-height: 1.4; }
.facts li + li { border-left: 1px solid var(--rule); }
.facts b { display: block; font-family: var(--serif); font-size: 28px; font-weight: 500; color: var(--ink); margin-bottom: 4px; }

html.static .apple-low { animation: none; }
html.static .spark-stage .half { will-change: auto; }
html.static .spark-stage .spark { opacity: 1; }
html.static .spark-stage .spark i { transform: scale(1); animation: none; }
html.static .spark-stage .spark b { transform: scale(1) rotate(30deg); }
@media (prefers-reduced-motion: reduce) {
  .apple-low, .spark-stage.met .spark i { animation: none; }
}

@media (max-width: 960px) {
  .chapter, .chapter:nth-child(even), .chapter.wide, .chapter.wide:nth-child(even) { grid-template-columns: 1fr; gap: 20px; padding: 40px 0; }
  .chapter .ch-num, .chapter:nth-child(even) .ch-num { order: 0; text-align: left; font-size: 56px; display: flex; align-items: baseline; gap: 14px; }
  .ch-num span { margin: 0; }
  .chapter .ch-body, .chapter:nth-child(even) .ch-body { order: 1; }
  .chapter .plate, .chapter:nth-child(even) .plate, .chapter.wide .plate { order: 2; grid-column: auto; max-width: 420px; width: 100%; }
  .ch-orn { display: none; }
  .chapter.prophecy { padding: 36px 24px; }
}
@media (max-width: 860px) {
  .spark-stage { --cx: 420; --cw: 660; margin-bottom: 64px; }
  .spark i { width: 150px; height: 150px; margin: -75px 0 0 -75px; }
  .spark b { width: 240px; height: 240px; margin: -120px 0 0 -120px; }
  .ch-body p { font-size: 19px; }
  .laws { margin-top: 64px; }
  .laws li { grid-template-columns: 48px 1fr; }
  #thesis .essay aside { display: none; }
  #thesis .pull { margin: 48px 0; }
  #thesis .pull.then { margin-top: -48px; }
  .facts { grid-template-columns: 1fr; }
  .facts li + li { border-left: 0; border-top: 1px solid var(--rule); }
}
@media (max-width: 480px) {
  #lore .wrap, #thesis .wrap, #unit .wrap { padding: 0 16px; }
}
