/* Paper Grain Background */
.paper-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(44, 24, 16, 0.03) 1px, transparent 1px),
        radial-gradient(ellipse at 80% 70%, rgba(44, 24, 16, 0.03) 1px, transparent 1px),
        radial-gradient(ellipse at 50% 50%, rgba(44, 24, 16, 0.02) 1px, transparent 1px),
        radial-gradient(ellipse at 10% 90%, rgba(44, 24, 16, 0.03) 1px, transparent 1px),
        radial-gradient(ellipse at 90% 10%, rgba(44, 24, 16, 0.02) 1px, transparent 1px),
        radial-gradient(ellipse at 35% 65%, rgba(44, 24, 16, 0.03) 1px, transparent 1px),
        radial-gradient(ellipse at 65% 35%, rgba(44, 24, 16, 0.02) 1px, transparent 1px),
        radial-gradient(ellipse at 45% 15%, rgba(44, 24, 16, 0.03) 1px, transparent 1px),
        radial-gradient(ellipse at 75% 85%, rgba(44, 24, 16, 0.02) 1px, transparent 1px),
        radial-gradient(ellipse at 25% 45%, rgba(44, 24, 16, 0.03) 1px, transparent 1px);
    background-size: 7px 7px, 11px 11px, 13px 13px, 9px 9px, 15px 15px, 8px 8px, 12px 12px, 10px 10px, 14px 14px, 6px 6px;
}

/* Foxing Spots */
.foxing-spots {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    background-image:
        radial-gradient(ellipse at 15% 25%, rgba(107, 76, 59, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 60%, rgba(107, 76, 59, 0.06) 0%, transparent 40%),
        radial-gradient(ellipse at 45% 80%, rgba(107, 76, 59, 0.07) 0%, transparent 45%),
        radial-gradient(ellipse at 70% 15%, rgba(107, 76, 59, 0.05) 0%, transparent 35%),
        radial-gradient(ellipse at 30% 55%, rgba(107, 76, 59, 0.06) 0%, transparent 30%);
    background-size: 200px 200px, 150px 150px, 180px 180px, 120px 120px, 160px 160px;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #f4ede4;
    color: #2c1810;
    font-family: 'Lora', serif;
    font-size: 16px;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Typography */
h1, h2 {
    font-family: 'Caveat', cursive;
    font-weight: 700;
}

h1 {
    font-size: clamp(3rem, 8vw, 7rem);
    color: #2c1810;
}

h2 {
    font-size: clamp(2rem, 5vw, 4rem);
    color: #1b3a5c;
    margin-bottom: 1rem;
}

.handwritten {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    line-height: 1.8;
    color: #2c1810;
}

.mono-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    font-weight: 300;
    letter-spacing: 0.05em;
    color: #6b4c3b;
    text-transform: uppercase;
}

/* Sections */
.section {
    position: relative;
    min-height: 100vh;
    padding: 4rem 2rem;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Cover Section */
#cover {
    flex-direction: column;
    text-align: center;
}

.cover-content {
    position: relative;
    z-index: 3;
}

.title {
    margin-bottom: 0.5rem;
    opacity: 0;
    animation: fadeInUp 1.5s ease forwards;
}

.subtitle {
    font-family: 'Lora', serif;
    font-style: italic;
    font-size: 1.2rem;
    color: #6b4c3b;
    opacity: 0;
    animation: fadeInUp 1.5s ease 0.3s forwards;
}

.instruction {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #3d8b7a;
    margin-top: 3rem;
    opacity: 0;
    animation: fadeInUp 1.5s ease 0.8s forwards;
}

.ink-blot {
    width: 60px;
    height: 60px;
    background: radial-gradient(ellipse at 40% 40%, #2c1810 0%, rgba(44, 24, 16, 0.8) 30%, transparent 70%);
    border-radius: 50% 40% 60% 45%;
    margin: 2rem auto;
    opacity: 0;
    animation: inkSpread 2s ease 0.5s forwards;
}

.ink-blot-small {
    width: 30px;
    height: 30px;
    margin: 1.5rem auto;
}

.cover-marginalia {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.margin-note {
    position: absolute;
    font-family: 'Caveat', cursive;
    font-size: 0.9rem;
    color: #3d8b7a;
    opacity: 0.6;
}

/* Broken Grid */
.broken-grid {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 1rem;
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
}

.grid-block {
    background: rgba(244, 237, 228, 0.8);
    padding: 2rem;
    border: 1px solid rgba(44, 24, 16, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.grid-block:hover {
    box-shadow: 4px 4px 0 rgba(44, 24, 16, 0.1);
}

/* Index Page Grid Placement */
.block-1 {
    grid-column: 1 / 10;
    grid-row: 1 / 3;
}

.block-2 {
    grid-column: 11 / 17;
    grid-row: 1 / 2;
}

.block-3 {
    grid-column: 10 / 17;
    grid-row: 2 / 3;
}

/* Diagrams Grid Placement */
.diagram-block {
    grid-column: 1 / 11;
    grid-row: 1 / 3;
}

.note-block {
    grid-column: 11 / 17;
    grid-row: 1 / 2;
}

.formula-block {
    grid-column: 11 / 17;
    grid-row: 2 / 3;
}

/* Letters Grid Placement */
.letter-block {
    grid-column: 2 / 13;
    grid-row: 1 / 3;
}

.stamp-block {
    grid-column: 13 / 17;
    grid-row: 1 / 2;
}

/* Garden Grid Placement */
.garden-text {
    grid-column: 1 / 9;
    grid-row: 1 / 2;
}

.garden-diagram {
    grid-column: 9 / 17;
    grid-row: 1 / 3;
}

.botanical-note {
    grid-column: 1 / 8;
    grid-row: 2 / 3;
}

/* Index List */
.index-list {
    list-style: none;
    padding: 1rem 0;
}

.index-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px dotted rgba(44, 24, 16, 0.2);
}

.entry {
    font-family: 'Lora', serif;
    font-style: italic;
}

.page-num {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.8rem;
    color: #d4a03c;
}

/* Notebook Quote */
.notebook-quote {
    font-family: 'Caveat', cursive;
    font-size: 1.6rem;
    color: #1b3a5c;
    border-left: 3px solid #d4a03c;
    padding-left: 1.5rem;
    margin: 1rem 0;
}

.attribution {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.7rem;
    color: #6b4c3b;
    text-align: right;
}

/* SVG Diagrams */
.thought-diagram, .garden-svg {
    width: 100%;
    max-width: 400px;
    height: auto;
    margin: 1rem auto;
    display: block;
}

/* Letter Styles */
.letter {
    padding: 1.5rem;
    border: 1px solid rgba(44, 24, 16, 0.15);
    background: rgba(232, 223, 210, 0.5); /* #e8dfd2 */
    margin-top: 1rem;
}

.letter-date {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    color: #6b4c3b;
    margin-bottom: 1rem;
}

.letter-body {
    font-family: 'Lora', serif;
    font-style: italic;
    margin-bottom: 0.8rem;
    line-height: 1.8;
}

.letter-sign {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    margin-top: 1.5rem;
    color: #1b3a5c;
}

/* Postmark */
.postmark {
    width: 120px;
    height: 120px;
    border: 3px solid #d4a03c;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transform: rotate(15deg);
    opacity: 0.7;
}

.postmark-text {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: #d4a03c;
}

.postmark-date {
    font-family: 'Caveat', cursive;
    font-size: 1.4rem;
    color: #d4a03c;
}

/* Formula */
.formula {
    margin: 0.5rem 0;
    font-size: 0.9rem;
    color: #1b3a5c;
}

/* Colophon */
#colophon {
    flex-direction: column;
    text-align: center;
}

.colophon-content {
    max-width: 500px;
}

.colophon-content h2 {
    font-size: 3rem;
    color: #2c1810;
    margin-bottom: 1.5rem;
}

.closing-note {
    margin-top: 2rem;
    color: #3d8b7a;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes inkSpread {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 0.8;
        transform: scale(1);
    }
}

/* Scroll-triggered reveal */
.grid-block {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.grid-block.visible {
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
    .broken-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .grid-block {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
    }

    .section {
        padding: 3rem 1rem;
    }
}
