@import url('https://fonts.googleapis.com/css2?family=Almendra:ital,wght@0,400;0,700;1,400;1,700&family=Crimson+Pro:ital,wght@0,200..900;1,200..900&family=MedievalSharp&display=swap');

:root {
    --parchment-bg: #f4e4bc;
    --parchment-dark: #e8d5a7;
    --medieval-blue: #1a3a5a;
    --medieval-gold: #b8860b;
    --medieval-red: #8b0000;
    --text-dark: #2c1e13;
    --border-color: #5d4037;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #1a1a1a; /* Dark background to make the parchment stand out */
    background-image: radial-gradient(circle, #2c2c2c 0%, #1a1a1a 100%);
    font-family: 'Crimson Pro', serif;
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    padding: 2rem;
    display: flex;
    justify-content: center;
}

.page-wrapper {
    background-color: var(--parchment-bg);
    background-image: 
        url("https://www.transparenttextures.com/patterns/paper-fibers.png"),
        radial-gradient(circle at center, transparent 0%, rgba(0,0,0,0.05) 100%);
    max-width: 900px;
    width: 100%;
    min-height: 80vh;
    padding: 4rem;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border: 30px solid transparent;
    border-image: url('https://i.imgur.com/7Y9XvXQ.png') 30 round; /* Fallback or specific border image if needed */
    border: 2px solid var(--border-color);
    outline: 10px solid var(--parchment-bg);
    outline-offset: -20px;
}

/* Medieval Decorative Border */
.page-wrapper::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 2px solid var(--medieval-gold);
    pointer-events: none;
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    border-bottom: 2px double var(--medieval-gold);
    padding-bottom: 1rem;
}

h1, h2, h3 {
    font-family: 'Almendra', serif;
    color: var(--medieval-red);
    text-shadow: 1px 1px 1px rgba(0,0,0,0.1);
}

h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 2rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--medieval-blue);
}

nav {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    font-family: 'MedievalSharp', cursive;
}

nav a {
    text-decoration: none;
    color: var(--medieval-blue);
    font-weight: bold;
    padding: 0.2rem 1rem;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

nav a:hover {
    color: var(--medieval-red);
    border-bottom: 1px solid var(--medieval-red);
}

.content {
    position: relative;
    z-index: 2;
}

p {
    margin-bottom: 1.5rem;
    font-size: 1.15rem;
    text-align: justify;
}

.portrait-frame {
    float: right;
    margin-left: 2rem;
    margin-bottom: 1rem;
    border: 5px solid var(--border-color);
    padding: 5px;
    background: white;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.2);
}

.portrait-frame img {
    display: block;
    max-width: 244px;
}

/* Footnotes */
.footnote-ref {
    color: var(--medieval-red);
    cursor: pointer;
    font-weight: bold;
    font-size: 0.8em;
    vertical-align: super;
    text-decoration: none;
    padding: 0 2px;
}

.footnote-ref:hover {
    background-color: rgba(139, 0, 0, 0.1);
}

.footnote-popup {
    position: absolute;
    background: #fffef0;
    border: 1px solid var(--medieval-gold);
    padding: 1rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    max-width: 300px;
    font-size: 0.9rem;
    z-index: 100;
    display: none;
    font-style: italic;
    border-radius: 4px;
}

.footnote-popup::before {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 20px;
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: var(--medieval-gold) transparent transparent;
}

/* Table of Contents Item */
.toc-list {
    list-style: none;
    margin-top: 2rem;
}

.toc-item {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: baseline;
}

.toc-item a {
    font-family: 'MedievalSharp', cursive;
    font-size: 1.3rem;
    color: var(--medieval-blue);
    text-decoration: none;
    white-space: nowrap;
}

.toc-item .dots {
    flex-grow: 1;
    border-bottom: 2px dotted var(--border-color);
    margin: 0 10px;
}

.toc-item .page-num {
    font-family: 'Almendra', serif;
    font-weight: bold;
}

footer {
    margin-top: 4rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--border-color);
    border-top: 1px solid var(--medieval-gold);
    padding-top: 1rem;
}

/* Footnote Container (Legacy/Scripting support) */
.footnotes-list {
    margin-top: 5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
}

.footnote-entry {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: #444;
}
