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

:root {
  --parchment: #f4e4c1;
  --parchment-light: #faf3e0;
  --parchment-dark: #e8d5a8;
  --ink: #2c1e16;
  --ink-light: #5c4a3a;
  --ink-faint: #8a7a68;
  --red-header: #7a1e1e;
  --red-header-light: #a03030;
  --gold: #b8960c;
  --gold-light: #d4b436;
  --rule-red: #9b2d2d;
  --rule-gold: #c9a84c;
  --stat-bg: #faf3e0;
  --stat-border: #c9a84c;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  background: linear-gradient(135deg, #3a2e24 0%, #2a1e14 50%, #3a2e24 100%);
  min-height: 100vh;
  padding: 2rem 1rem;
}

body { margin: 0; }

.page {
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
  max-width: 860px;
  margin: 0 auto;
  background: var(--parchment);
  background-image:
    radial-gradient(ellipse at 15% 15%, rgba(255,255,255,0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 85%, rgba(0,0,0,0.04) 0%, transparent 50%),
    linear-gradient(180deg, var(--parchment-light) 0%, var(--parchment) 8%, var(--parchment) 92%, var(--parchment-dark) 100%);
  border: 1px solid var(--parchment-dark);
  box-shadow: 0 2px 20px rgba(0,0,0,0.25), 0 0 60px rgba(0,0,0,0.1), inset 0 0 80px rgba(139,90,43,0.08);
  position: relative;
  overflow: hidden;
}

.page::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23p)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.page > * { position: relative; z-index: 1; }

.page-frame {
  position: relative;
  padding: 2.5rem 3rem 3rem;
}

.page-frame::before {
  content: '';
  position: absolute;
  top: 12px; left: 12px; right: 12px; bottom: 12px;
  border: 2px solid var(--rule-gold);
  opacity: 0.5;
  pointer-events: none;
}

.page-frame::after {
  content: '';
  position: absolute;
  top: 16px; left: 16px; right: 16px; bottom: 16px;
  border: 1px solid var(--rule-red);
  opacity: 0.25;
  pointer-events: none;
}

#title-block-header { text-align: center; margin-bottom: 1rem; }
#title-block-header h1 {
  font-family: 'Uncial Antiqua', serif;
  font-size: 2.4rem;
  font-weight: 400;
  color: var(--red-header);
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
  line-height: 1.2;
  margin: 0;
}
#title-block-header::after {
  content: '';
  display: block;
  width: 60%;
  max-width: 400px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--rule-red), var(--rule-gold), var(--rule-red), transparent);
  margin: 1rem auto 0;
}

h1, h2, h3, h4 { page-break-after: avoid; }

h1 {
  font-family: 'Uncial Antiqua', serif;
  font-size: 2rem;
  color: var(--red-header);
  margin: 2rem 0 1rem;
}

h2 {
  font-family: 'Uncial Antiqua', serif;
  font-size: 1.6rem;
  color: var(--red-header);
  margin: 2rem 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
h2::before {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--rule-red), transparent);
}
h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(270deg, var(--rule-red), transparent);
}

h3 {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--red-header);
  margin: 1.8rem 0 0.8rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid rgba(122,30,30,0.2);
}

h4 {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
  font-style: italic;
  color: var(--ink-light);
  margin: 1.5rem 0 0.5rem;
}

a { color: var(--red-header); text-decoration: none; border-bottom: 1px dotted var(--rule-red); transition: all 0.15s ease; }
a:hover { color: var(--red-header-light); border-bottom-style: solid; }

p { margin-bottom: 1rem; text-align: justify; hyphens: auto; }
.page-frame > p:first-of-type::first-letter {
  font-family: 'Uncial Antiqua', serif;
  float: left;
  font-size: 4.5rem;
  line-height: 0.8;
  padding-right: 0.15em;
  padding-top: 0.08em;
  color: var(--red-header);
  text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

ul, ol { margin: 1rem 0 1.5rem 0.5rem; padding-left: 1rem; }
li { margin-bottom: 0.5rem; }
ul li { list-style: none; padding-left: 1.2rem; position: relative; }
ul li::before { content: '❧'; position: absolute; left: -0.3rem; color: var(--red-header); font-size: 0.85rem; }

blockquote {
  border-left: 4px solid var(--rule-red);
  padding: 1.2rem 1.5rem;
  margin: 1.5rem 0;
  font-style: italic;
  background: linear-gradient(135deg, #f0e6cc 0%, #e8d8b4 100%);
  border: 1px solid var(--parchment-dark);
  position: relative;
}
blockquote::before {
  content: '"';
  position: absolute;
  top: -0.3rem; left: 0.5rem;
  font-family: 'Uncial Antiqua', serif;
  font-size: 3rem;
  color: var(--rule-red);
  opacity: 0.2;
}

table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; }
th, td { border: 1px solid var(--stat-border); padding: 0.5em 1em; text-align: left; }
th {
  background: linear-gradient(135deg, var(--stat-bg) 0%, #f0e6cc 100%);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--red-header);
}
tr:nth-child(even) { background: rgba(240,230,204,0.5); }

code { background: var(--parchment-dark); padding: 0.2em 0.4em; border-radius: 3px; font-family: 'Courier New', monospace; font-size: 0.9em; }
pre { background: var(--parchment-dark); padding: 1em; border: 1px solid var(--stat-border); overflow-x: auto; margin: 1em 0; }
pre code { background: none; padding: 0; }

hr { border: none; height: 1px; background: linear-gradient(90deg, transparent, var(--rule-gold), var(--rule-red), var(--rule-gold), transparent); margin: 2rem 0; opacity: 0.5; }

#TOC {
  background: var(--parchment-dark);
  border: 2px solid var(--stat-border);
  border-radius: 4px;
  padding: 1rem 1.5rem;
  margin: 1.5rem 0;
}
#TOC h2 { font-family: 'Cinzel', serif; font-size: 1rem; font-weight: 700; color: var(--ink-faint); letter-spacing: 0.2em; text-transform: uppercase; text-align: center; margin-top: 0; border: none; display: block; }
#TOC h2::before, #TOC h2::after { display: none; }
#TOC ul { list-style: none; margin-left: 0; padding-left: 0; }
#TOC li { margin: 0.6rem 0; padding: 0.6rem 0; border-bottom: 1px dotted rgba(122,30,30,0.15); }
#TOC li:last-child { border-bottom: none; }
#TOC a { font-family: 'Cinzel', serif; font-weight: 700; font-size: 1rem; color: var(--red-header); text-decoration: none; letter-spacing: 0.03em; }
#TOC a:hover { color: var(--red-header-light); text-decoration: underline; text-decoration-color: var(--rule-red); text-underline-offset: 3px; }

img { max-width: 100%; height: auto; border: 3px double var(--parchment-dark); margin: 1em 0; }

strong { font-weight: 700; color: var(--ink); }
em { font-style: italic; }

footer { text-align: center; padding-top: 1.5rem; margin-top: 2rem; font-size: 0.8rem; color: var(--ink-faint); font-style: italic; letter-spacing: 0.1em; position: relative; }
footer::before {
  content: '';
  position: absolute;
  top: 0; left: 15%; right: 15%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule-gold), var(--rule-red), var(--rule-gold), transparent);
  opacity: 0.4;
}

/* Navigation */
.book-nav {
  text-align: center;
  padding: 0.8rem 0 1.2rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid rgba(122,30,30,0.15);
}
.book-nav a {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--red-header);
  text-decoration: none;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.5rem 1rem;
  position: relative;
  transition: color 0.2s ease;
}
.book-nav a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: var(--rule-red);
  transition: width 0.2s ease;
}
.book-nav a:hover { color: var(--red-header-light); }
.book-nav a:hover::after { width: 70%; }
.book-nav a + a::before {
  content: '·';
  position: absolute;
  left: -0.2rem;
  color: var(--ink-faint);
  font-weight: 400;
}
.book-nav a.active { color: var(--red-header-light); }

/* Corner ornaments */
.corner-ornament {
  position: absolute;
  width: 40px;
  height: 40px;
  color: var(--gold);
  opacity: 0.6;
  font-size: 1.5rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.corner-ornament.tl { top: 4px; left: 4px; }
.corner-ornament.tr { top: 4px; right: 4px; transform: scaleX(-1); }
.corner-ornament.bl { bottom: 4px; left: 4px; transform: scaleY(-1); }
.corner-ornament.br { bottom: 4px; right: 4px; transform: scale(-1, -1); }

@media (max-width: 768px) {
  html { padding: 1rem 0.5rem; }
  .page-frame { padding: 2rem 1.5rem 2.5rem; }
  .page-frame::before, .page-frame::after { display: none; }
  .corner-ornament { display: none; }
  #title-block-header h1 { font-size: 1.8rem; }
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.3rem; }
  h2::before, h2::after { display: none; }
  p:first-of-type::first-letter { font-size: 3.5rem; }
}

@media (max-width: 480px) {
  #title-block-header h1 { font-size: 1.5rem; }
  h1 { font-size: 1.5rem; }
}
