:root {
    --bg-fresh: #f5efe5;
    --bg-aged: #c8b898;
    --ink-fresh: #3d3020;
    --ink-faded: #6b604a;
    --margin-ink: #7a6b52;
    --margin-faded: #9b8c72;
    --foxing: #c4a86b;
    --foxing-dark: #b89858;
    --water-stain: #d8c8a8;
    --water-stain-dark: #c4b490;
    --border-frame: #8b7355;
    --border-faded: #a89470;
    --tear-edge: #b8a480;
    --age-factor: 0;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.1vw, 1.08rem);
    line-height: 1.8;
    color: var(--ink-fresh);
    position: relative;
    min-height: 520vh;
}

/* Continuous aging background gradient */
.page-aging-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    background: var(--bg-fresh);
    pointer-events: none;
}

/* Foxing spots layer */
.foxing-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.foxing-spot {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(196, 168, 107, var(--spot-opacity, 0.02)) 0%, transparent 70%);
}

/* Water stains */
.water-stain {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

.stain-1 {
    top: 52%;
    left: 25%;
    width: 200px;
    height: 180px;
    border-radius: 43% 57% 62% 38% / 55% 45% 52% 48%;
    background: rgba(216, 200, 168, 0.06);
}

.stain-2 {
    top: 68%;
    left: 45%;
    width: 240px;
    height: 200px;
    border-radius: 52% 48% 44% 56% / 60% 40% 58% 42%;
    background: rgba(216, 200, 168, 0.1);
}

.stain-3 {
    top: 82%;
    left: 15%;
    width: 280px;
    height: 220px;
    border-radius: 38% 62% 55% 45% / 48% 52% 45% 55%;
    background: rgba(196, 180, 144, 0.15);
}

/* Title Page */
.title-page {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    padding-top: 30vh;
    padding-left: 15%;
    position: relative;
    z-index: 2;
}

.title-frame {
    border: 1px solid var(--border-frame);
    padding: 80px;
    max-width: 520px;
}

.journal-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    letter-spacing: 0.02em;
    color: var(--ink-fresh);
    margin-bottom: 24px;
}

.subtitle {
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.2vw, 1.1rem);
    line-height: 1.7;
    color: var(--ink-fresh);
}

/* Journal Entries */
.journal-entry {
    position: relative;
    max-width: 580px;
    margin-left: 15%;
    padding: 60px 0 40px 0;
    z-index: 2;
}

.entry-header {
    margin-bottom: 20px;
}

.entry-date {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 600;
    font-size: clamp(1rem, 1.4vw, 1.3rem);
    letter-spacing: 0.02em;
    color: var(--ink-fresh);
}

.entry-body p {
    margin-bottom: 16px;
    text-indent: 30px;
}

.entry-body p:first-child {
    text-indent: 0;
}

/* Margin Notes */
.margin-note {
    position: absolute;
    right: -200px;
    top: 80px;
    width: 120px;
    font-family: 'Lora', Georgia, serif;
    font-style: italic;
    font-weight: 400;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--margin-ink);
}

.note-prefix {
    display: none;
}

/* Margin note overflow in middle entries */
.note-overflow {
    width: 140px;
    right: -180px;
}

/* Fading margin notes in later entries */
.note-fading {
    opacity: 0.4;
}

/* Entry age progression */
.entry-early {
    color: var(--ink-fresh);
}

.entry-early .entry-date {
    color: var(--ink-fresh);
}

.entry-middle {
    line-height: 1.65;
}

.entry-middle .entry-date {
    color: #4d4030;
}

.entry-middle .entry-body {
    color: #4d4030;
}

.entry-later {
    line-height: 1.65;
}

.entry-later .entry-date {
    color: var(--ink-faded);
}

.entry-later .entry-body {
    color: var(--ink-faded);
}

/* Struck-through text */
.struck-text {
    text-decoration: line-through;
    text-decoration-color: var(--ink-faded);
}

/* The tear */
.torn-entry {
    clip-path: polygon(
        0 0, 100% 0, 100% 48%,
        92% 50%, 85% 47%, 78% 52%, 70% 49%,
        62% 51%, 55% 48%, 48% 53%, 40% 49%,
        32% 52%, 25% 48%, 18% 51%, 10% 49%, 0 52%
    );
}

/* Final entry */
.entry-final {
    line-height: 1.65;
}

.entry-final .entry-date {
    color: var(--ink-faded);
    opacity: 0.5;
}

.entry-final .entry-body {
    color: var(--ink-faded);
    opacity: 0.35;
}

/* Empty page at the end */
.empty-page {
    height: 200px;
    position: relative;
    z-index: 2;
}

/* Progressive background aging via data attributes on body */
body[data-scroll-pct="10"] .page-aging-bg { background: #f3ece0; }
body[data-scroll-pct="20"] .page-aging-bg { background: #f0e8d8; }
body[data-scroll-pct="30"] .page-aging-bg { background: #ede3d0; }
body[data-scroll-pct="40"] .page-aging-bg { background: #e8dcc8; }
body[data-scroll-pct="50"] .page-aging-bg { background: #e4d6c0; }
body[data-scroll-pct="60"] .page-aging-bg { background: #ddd0b8; }
body[data-scroll-pct="70"] .page-aging-bg { background: #d8cab0; }
body[data-scroll-pct="80"] .page-aging-bg { background: #d2c4a8; }
body[data-scroll-pct="90"] .page-aging-bg { background: #cdbea0; }
body[data-scroll-pct="100"] .page-aging-bg { background: var(--bg-aged); }

/* Mobile: collapse margin notes inline */
@media (max-width: 768px) {
    .journal-entry {
        margin-left: 8%;
        margin-right: 8%;
        max-width: none;
    }

    .title-page {
        padding-left: 8%;
    }

    .title-frame {
        padding: 40px;
        max-width: 100%;
    }

    .margin-note {
        position: relative;
        right: auto;
        top: auto;
        width: 100%;
        margin-top: 16px;
        padding: 12px 0;
        border-top: 1px solid var(--border-faded);
        font-size: 0.78rem;
        color: var(--margin-ink);
    }

    .note-prefix {
        display: inline;
        font-style: normal;
        font-weight: 600;
    }

    .note-overflow {
        width: 100%;
        right: auto;
    }

    .water-stain {
        display: none;
    }
}
