/* ============================================================
   The Pendragon Chronicle — Manuscript theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@400;700;900&family=Cinzel:wght@400;600&family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400&display=swap');

:root {
  --parchment-1: #ecdfc0;
  --parchment-2: #e4d3a8;
  --parchment-edge: #c9a86a;
  --ink: #3a2c1a;
  --ink-soft: #5b4630;
  --ink-red: #7a1f1f;
  --gold: #9c7a2e;
  --gold-bright: #b8912f;
  --border-shadow: rgba(58, 44, 26, 0.35);
  --page-max-width: 900px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'EB Garamond', Georgia, serif;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.65;
  background-color: #d8c497;
  background-image:
    radial-gradient(ellipse at top left, rgba(255,255,255,0.10), transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(0,0,0,0.12), transparent 55%),
    repeating-linear-gradient(0deg, rgba(120,95,45,0.035) 0px, rgba(120,95,45,0.035) 1px, transparent 1px, transparent 3px),
    linear-gradient(160deg, var(--parchment-1), var(--parchment-2) 60%, var(--parchment-1));
  background-attachment: fixed;
  perspective: 1600px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(ellipse at 20% 30%, rgba(90,60,20,0.06), transparent 40%),
                     radial-gradient(ellipse at 80% 75%, rgba(90,60,20,0.08), transparent 45%),
                     radial-gradient(ellipse at 50% 95%, rgba(90,60,20,0.10), transparent 50%);
}

.manuscript-frame {
  position: relative;
  z-index: 1;
  max-width: var(--page-max-width);
  margin: 2.5rem auto 4rem;
  padding: 3.2rem 3.6rem 3rem;
  background: linear-gradient(170deg, #f4e9cc, #ecdcae 55%, #e6d4a6);
  border: 1px solid var(--parchment-edge);
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(156,122,46,0.35),
    0 0 0 9px transparent,
    inset 0 0 40px rgba(120,90,40,0.18),
    0 18px 45px var(--border-shadow);
  transform-origin: left center;
  animation: pageTurnIn 0.55s cubic-bezier(.22,.61,.36,1) both;
}

.manuscript-frame::before {
  content: "";
  position: absolute;
  inset: 12px;
  pointer-events: none;
  border: 2px solid var(--gold);
  border-radius: 1px;
  opacity: 0.55;
}

.manuscript-frame::after {
  content: "";
  position: absolute;
  inset: 18px;
  pointer-events: none;
  border: 1px solid var(--ink-red);
  opacity: 0.25;
}

@keyframes pageTurnIn {
  0% {
    opacity: 0;
    transform: rotateY(-22deg) translateX(-30px) scale(0.98);
    box-shadow: -36px 10px 46px rgba(58,44,26,0.4), 0 18px 45px var(--border-shadow);
  }
  100% { opacity: 1; transform: rotateY(0deg) translateX(0) scale(1); }
}

@keyframes pageTurnOutNext {
  0% { opacity: 1; transform: rotateY(0deg); }
  100% { opacity: 0; transform: rotateY(-78deg) translateX(-50px); }
}

@keyframes pageTurnOutPrev {
  0% { opacity: 1; transform: rotateY(0deg); }
  100% { opacity: 0; transform: rotateY(78deg) translateX(50px); }
}

.manuscript-frame.leaving-next {
  animation: pageTurnOutNext 0.36s ease-in forwards;
  transform-origin: left center;
}

.manuscript-frame.leaving-prev {
  animation: pageTurnOutPrev 0.36s ease-in forwards;
  transform-origin: right center;
}

@media (prefers-reduced-motion: reduce) {
  .manuscript-frame,
  .manuscript-frame.leaving-next,
  .manuscript-frame.leaving-prev {
    animation: none;
  }
}

/* Set by an inline head script when this load followed our own page-turn
   click, so the incoming page sits static under the outgoing page's lift
   instead of playing its own entrance animation on top of it. The :not()s
   keep this from also winning (via higher specificity) over the leaving-*
   rules above when the user turns another page from here. */
html.pc-no-entrance .manuscript-frame:not(.leaving-next):not(.leaving-prev) {
  animation: none;
  opacity: 1;
  transform: none;
}

/* Corner flourishes */
.corner {
  position: absolute;
  width: 46px;
  height: 46px;
  opacity: 0.7;
  color: var(--gold);
  z-index: 2;
}
.corner svg { width: 100%; height: 100%; fill: currentColor; }
.corner.tl { top: 4px; left: 4px; }
.corner.tr { top: 4px; right: 4px; transform: scaleX(-1); }
.corner.bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.corner.br { bottom: 4px; right: 4px; transform: scale(-1, -1); }

/* ---------- Site header / nav ---------- */
.site-header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2.6rem 1.5rem 0.5rem;
}

.site-title {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.9rem);
  color: var(--ink-red);
  text-shadow: 1px 1px 0 rgba(255,255,255,0.25);
  margin: 0;
  letter-spacing: 0.02em;
}

.site-title a { color: inherit; text-decoration: none; }

.site-subtitle {
  font-family: 'Cinzel', serif;
  font-size: 0.95rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0.4rem 0 1.4rem;
}

.site-nav {
  display: flex;
  justify-content: center;
  gap: 2.2rem;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-bottom: 1.2rem;
  flex-wrap: wrap;
}

.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 2px;
  transition: color 0.2s, border-color 0.2s;
}
.site-nav a:hover, .site-nav a.active { color: var(--ink-red); border-color: var(--gold); }

.divider {
  position: relative;
  z-index: 1;
  max-width: 420px;
  margin: 0 auto 0.5rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.divider::before {
  content: attr(data-glyph);
  position: relative;
  top: -0.75em;
  background: transparent;
  color: var(--gold);
  padding: 0 0.8em;
  display: inline-block;
  font-size: 1.1rem;
  left: 50%;
  transform: translateX(-50%);
}

/* ---------- Headings & body typography ---------- */
h1.page-title {
  font-family: 'Cinzel Decorative', serif;
  color: var(--ink-red);
  font-size: clamp(1.6rem, 3.4vw, 2.3rem);
  text-align: center;
  margin: 0 0 0.3rem;
}

.chapter-emblem {
  display: flex;
  justify-content: center;
  margin: 0.1rem 0 0.7rem;
  color: var(--gold);
  opacity: 0.8;
}
.chapter-emblem svg { width: 32px; height: 32px; }

.year-banner {
  text-align: center;
  font-family: 'Cinzel', serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-bright);
  font-size: 0.95rem;
  margin-bottom: 1.8rem;
}

.chapter-body p {
  margin: 0 0 1.15em;
  text-align: justify;
  hyphens: auto;
}

.chapter-body > p:first-of-type::first-letter {
  font-family: 'Cinzel Decorative', serif;
  font-weight: 900;
  font-size: 4.4rem;
  line-height: 0.78;
  float: left;
  margin: 0.03em 0.12em 0 -0.02em;
  padding: 0.08em 0.16em 0.05em;
  color: var(--ink-red);
  background: linear-gradient(160deg, #f8ecc8, #e3c980 70%);
  border: 2px solid var(--gold);
  box-shadow: inset 0 0 6px rgba(122,31,31,0.25), 0 2px 4px rgba(58,44,26,0.3);
  border-radius: 3px;
}

ul.sub-adventures {
  list-style: none;
  margin: 1.3rem 0;
  padding: 0;
  border-left: 3px solid var(--gold);
  background: rgba(156,122,46,0.08);
}
ul.sub-adventures li {
  padding: 0.55rem 1rem 0.55rem 1.2rem;
  border-bottom: 1px dotted rgba(122,90,40,0.35);
}
ul.sub-adventures li:last-child { border-bottom: none; }
ul.sub-adventures li strong { color: var(--ink-red); font-family: 'Cinzel', serif; font-size: 0.92em; }

.chapter-body em { color: var(--ink-soft); font-style: italic; }
.chapter-body strong { color: var(--ink-red); }

/* ---------- Tales of the Fellowship (player submissions) ---------- */
.fellowship-tales {
  margin-top: 2.4rem;
  padding-top: 1.6rem;
  border-top: 1px dashed rgba(122,90,40,0.4);
}
.tales-heading {
  font-family: 'Cinzel', serif;
  color: var(--ink-red);
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  margin: 0 0 0.2rem;
}
.tales-note {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin: 0 0 1.1rem;
}
.tale-card {
  background: rgba(156,122,46,0.07);
  border-left: 3px solid var(--gold);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  border-radius: 0 3px 3px 0;
}
.tale-card:last-child { margin-bottom: 0; }
.tale-byline {
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-bright);
  margin: 0 0 0.5rem;
}
.tale-card p:not(.tale-byline) { margin: 0 0 0.8em; text-align: left; }
.tale-card p:last-child { margin-bottom: 0; }

/* ---------- Chapter navigation (prev / next) ---------- */
.folio-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 2.6rem;
  padding-top: 1.4rem;
  border-top: 1px solid rgba(156,122,46,0.4);
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
}
.folio-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  max-width: 40%;
}
.folio-nav a:hover { color: var(--ink-red); }
.folio-nav .dir { font-size: 0.7rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--gold); }
.folio-nav .next { text-align: right; margin-left: auto; }
.folio-nav .toc-link { text-align: center; }

/* ---------- Table of contents / Index of Folios ---------- */
.folio-index {
  list-style: none;
  margin: 0;
  padding: 0;
}
.folio-index li {
  border-bottom: 1px dotted rgba(122,90,40,0.4);
}
.folio-index li:last-child { border-bottom: none; }
.folio-index a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.95rem 0.2rem;
  text-decoration: none;
  color: var(--ink);
}
.folio-index a:hover .chapter-name { color: var(--ink-red); }
.folio-index .ad-year {
  font-family: 'Cinzel', serif;
  color: var(--gold-bright);
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 5.2em;
}
.folio-index .chapter-name {
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  flex: 1;
  transition: color 0.15s;
}

.chronicle-status {
  text-align: center;
  font-family: 'EB Garamond', serif;
  font-style: italic;
  color: var(--ink-soft);
  margin: 1.8rem 0 0.5rem;
  padding: 1rem;
  border-top: 1px dashed rgba(122,90,40,0.4);
}

/* ---------- Dramatis Personae ---------- */
.personae-search {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 2rem;
  padding: 0.6rem 1rem;
  font-family: 'EB Garamond', serif;
  font-size: 1rem;
  font-style: italic;
  color: var(--ink);
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--gold);
  border-radius: 3px;
}
.personae-search:focus { outline: none; border-color: var(--ink-red); background: rgba(255,255,255,0.55); }

.personae-category {
  margin-bottom: 2.2rem;
}
.personae-category h2 {
  font-family: 'Cinzel', serif;
  color: var(--ink-red);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--gold);
  padding-bottom: 0.4rem;
  margin-bottom: 0.2rem;
}
.personae-category .category-note {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 0 0.9rem;
}

.persona-card {
  padding: 0.8rem 0.2rem;
  border-bottom: 1px dotted rgba(122,90,40,0.35);
}
.persona-card:last-child { border-bottom: none; }
.persona-name {
  font-family: 'Cinzel', serif;
  font-size: 1.02rem;
  color: var(--ink);
}
.persona-name .honorific { color: var(--gold-bright); margin-right: 0.3em; }
.persona-role {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0.1rem 0 0.35rem;
}
.persona-desc {
  font-size: 0.96rem;
  margin: 0;
}
.persona-years {
  font-family: 'Cinzel', serif;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--gold);
  margin-top: 0.35rem;
}

/* ---------- Footer ---------- */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 1.5rem 1rem 3rem;
  font-family: 'Cinzel', serif;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  text-transform: uppercase;
  opacity: 0.75;
}

@media (max-width: 640px) {
  .manuscript-frame { padding: 2.2rem 1.4rem 2rem; margin: 1.2rem 0.6rem 2.5rem; }
  .chapter-body > p:first-of-type::first-letter { font-size: 3.2rem; }
  .site-nav { gap: 1.1rem; }
}
