/* ============================================================
   historical.day - Light-Academia Antiquarian Design
   ============================================================ */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
    /* Palette */
    --aged-vellum: #f5f0e8;
    --warm-parchment: #ede4d3;
    --library-walnut: #2c2418;
    --annotation-brown: #6b5b4a;
    --manuscript-sepia: #c4a882;
    --gilt-edge: #b8963e;
    --binding-leather: #5a3e28;
    --archive-ink: #1a1408;
    --foxing-spot: #d4c0a0;
    --margin-red: #8b4532;

    /* Typography */
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-body: 'Lora', 'Georgia', serif;
    --font-accent: 'EB Garamond', 'Georgia', serif;

    /* Spacing */
    --cell-padding: clamp(1.5rem, 3vw, 3rem);
    --section-gap: 4rem;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--library-walnut);
    background-color: var(--aged-vellum);
    overflow-x: hidden;
    position: relative;
}

/* --- Paper Grain Texture Overlay --- */
#paper-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.025;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence baseFrequency='0.65' numOctaves='4' type='fractalNoise' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
}

/* --- Navigation Drawer --- */
.nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    background-color: var(--warm-parchment);
    border-bottom: 1px solid var(--manuscript-sepia);
    z-index: 1000;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 350ms cubic-bezier(0.4, 0, 0.2, 1),
                opacity 350ms cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-drawer.visible {
    transform: translateY(0);
    opacity: 1;
}

.nav-inner {
    display: flex;
    gap: 2.5rem;
    align-items: center;
}

.nav-item {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.75rem, 1vw, 0.9rem);
    letter-spacing: 0.12em;
    color: var(--annotation-brown);
    cursor: pointer;
    text-decoration: none;
    background-image: linear-gradient(var(--gilt-edge), var(--gilt-edge));
    background-size: 0% 1px;
    background-position: left bottom;
    background-repeat: no-repeat;
    transition: color 300ms ease, background-size 300ms ease;
    padding-bottom: 2px;
}

.nav-item:hover {
    color: var(--gilt-edge);
    background-size: 100% 1px;
}

#nav-hover-zone {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 999;
}

/* --- Section Base --- */
.section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: var(--cell-padding);
}

/* --- Section Dividers --- */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--section-gap);
    position: relative;
}

.section-divider::before {
    content: '';
    position: absolute;
    left: 20%;
    right: 20%;
    top: 50%;
    height: 1px;
    background-color: var(--manuscript-sepia);
}

.divider-ornament {
    position: relative;
    z-index: 1;
    font-size: 1rem;
    color: var(--manuscript-sepia);
    opacity: 0.7;
    background-color: var(--aged-vellum);
    padding: 0 1rem;
}

/* --- Title Page (Hero) --- */
.title-section {
    flex-direction: column;
    background-color: var(--aged-vellum);
}

.title-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.title-rule {
    width: 30vw;
    height: 1px;
    background-color: var(--manuscript-sepia);
    opacity: 0;
    transition: opacity 600ms ease;
}

.title-rule.animate {
    opacity: 1;
}

.site-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(3rem, 8vw, 7rem);
    color: var(--library-walnut);
    letter-spacing: -0.01em;
    line-height: 1.15;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 900ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 900ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.site-title.animate {
    opacity: 1;
    transform: translateY(0);
}

.site-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(0.9rem, 1.3vw, 1.1rem);
    color: var(--annotation-brown);
    opacity: 0;
    transition: opacity 700ms ease;
}

.site-subtitle.animate {
    opacity: 1;
}

.scroll-indicator {
    position: absolute;
    bottom: 2rem;
    font-size: 1.5rem;
    color: var(--manuscript-sepia);
    opacity: 0;
    animation: pulse-scroll 2.5s infinite ease-in-out;
    transition: opacity 600ms ease;
}

.scroll-indicator.animate {
    opacity: 1;
}

@keyframes pulse-scroll {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* --- Bento Grid Base --- */
.bento-section {
    padding: 2rem var(--cell-padding);
}

.bento-grid {
    display: grid;
    gap: 2px;
    width: 100%;
    max-width: 1400px;
    min-height: 80vh;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 800ms ease, transform 800ms ease;
}

.bento-grid.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* --- Bento Cells --- */
.bento-cell {
    background-color: var(--warm-parchment);
    padding: var(--cell-padding);
    border: 2px solid var(--manuscript-sepia);
    position: relative;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 600ms ease-out,
                transform 600ms ease-out,
                border-color 250ms ease,
                box-shadow 250ms ease;
}

.bento-cell.revealed {
    opacity: 1;
    transform: translateY(0);
}

.bento-cell:hover {
    border-color: var(--gilt-edge);
    box-shadow: 2px 3px 12px rgba(44, 36, 24, 0.12);
}

.bento-cell:hover .section-heading,
.bento-cell:hover .cell-heading {
    color: var(--binding-leather);
}

/* --- Contents Grid (Section 2) --- */
.contents-grid {
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 1fr 1fr auto;
}

.contents-grid .cell-dominant {
    grid-column: 1 / 8;
    grid-row: 1 / 3;
}

.contents-grid .cell-medium:nth-child(2) {
    grid-column: 8 / 13;
    grid-row: 1 / 2;
}

.contents-grid .cell-medium:nth-child(3) {
    grid-column: 8 / 13;
    grid-row: 2 / 3;
}

.contents-grid .cell-accent:nth-child(4) {
    grid-column: 1 / 7;
    grid-row: 3 / 4;
}

.contents-grid .cell-accent:nth-child(5) {
    grid-column: 7 / 13;
    grid-row: 3 / 4;
}

/* --- Spread 3 Grid (Section 3) - 3x2 with spanning --- */
.spread-3-grid {
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 1fr 1fr;
}

.spread-3-grid .cell-feature {
    grid-column: 1 / 7;
    grid-row: 1 / 3;
}

.spread-3-grid .cell-medium:nth-child(2) {
    grid-column: 7 / 13;
    grid-row: 1 / 2;
}

.spread-3-grid .cell-small:nth-child(3) {
    grid-column: 7 / 9;
    grid-row: 2 / 3;
}

.spread-3-grid .cell-small:nth-child(4) {
    grid-column: 9 / 11;
    grid-row: 2 / 3;
}

.spread-3-grid .cell-small:nth-child(5) {
    grid-column: 11 / 13;
    grid-row: 2 / 3;
}

/* --- Spread 4 Grid (Section 4) - 2x3 with panoramic bottom --- */
.spread-4-grid {
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: 1fr 1fr auto;
}

.spread-4-grid .cell-medium:nth-child(1) {
    grid-column: 1 / 7;
    grid-row: 1 / 2;
}

.spread-4-grid .cell-medium:nth-child(2) {
    grid-column: 7 / 13;
    grid-row: 1 / 2;
}

.spread-4-grid .cell-medium:nth-child(3) {
    grid-column: 1 / 7;
    grid-row: 2 / 3;
}

.spread-4-grid .cell-small:nth-child(4) {
    grid-column: 7 / 13;
    grid-row: 2 / 3;
}

.spread-4-grid .cell-panoramic {
    grid-column: 1 / 13;
    grid-row: 3 / 4;
}

/* --- Spread 5 Grid (Section 5) - 4-cell generous --- */
.spread-5-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* --- Typography --- */
.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.8rem, 3.5vw, 2.8rem);
    color: var(--library-walnut);
    letter-spacing: -0.01em;
    line-height: 1.15;
    margin-bottom: 1em;
    transition: color 200ms ease;
}

.section-heading::after {
    content: '';
    display: block;
    width: 60px;
    height: 1px;
    background-color: var(--manuscript-sepia);
    margin-top: 0.8em;
}

.cell-heading {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(1.3rem, 2.2vw, 1.8rem);
    color: var(--library-walnut);
    letter-spacing: -0.01em;
    line-height: 1.15;
    margin-bottom: 0.8em;
    transition: color 200ms ease;
}

.body-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: var(--library-walnut);
    margin-bottom: 1.4em;
}

.body-text-small {
    font-family: var(--font-body);
    font-size: clamp(0.85rem, 1vw, 0.95rem);
    line-height: 1.6;
    color: var(--annotation-brown);
}

/* --- Drop Caps --- */
.drop-cap {
    float: left;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 4.2em;
    line-height: 0.85;
    color: var(--archive-ink);
    margin-right: 0.15em;
    margin-top: 0.05em;
    opacity: 0;
    transform: scale(1.4);
    transition: opacity 500ms ease, transform 500ms ease;
}

.drop-cap.animate {
    opacity: 1;
    transform: scale(1);
}

/* --- Marginalia --- */
.marginalia {
    position: absolute;
    right: 0;
    top: var(--cell-padding);
    width: 15%;
    min-width: 100px;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-right: var(--cell-padding);
    opacity: 0;
    transform: translateX(10px);
    transition: opacity 400ms ease, transform 400ms ease;
}

.marginalia.revealed {
    opacity: 1;
    transform: translateX(0);
}

.margin-note {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.65rem, 0.8vw, 0.78rem);
    letter-spacing: 0.12em;
    color: var(--annotation-brown);
    line-height: 1.4;
    display: block;
}

.margin-red {
    color: var(--margin-red);
}

/* --- Catalog Labels (Accent Cells) --- */
.cell-accent {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: clamp(0.8rem, 1.5vw, 1.2rem);
}

.catalog-label {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.75rem, 1vw, 0.9rem);
    letter-spacing: 0.12em;
    color: var(--annotation-brown);
}

.catalog-date {
    font-family: var(--font-body);
    font-size: clamp(0.8rem, 0.9vw, 0.9rem);
    color: var(--annotation-brown);
    line-height: 1.5;
}

/* --- Image Placeholders --- */
.cell-image {
    padding: 0;
    overflow: hidden;
}

.image-placeholder {
    width: 100%;
    height: 100%;
    min-height: 180px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 1rem;
    filter: sepia(35%) contrast(1.05) brightness(0.98);
    position: relative;
}

.image-placeholder::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 4px solid var(--manuscript-sepia);
    pointer-events: none;
}

.image-caption {
    font-family: var(--font-accent);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    color: var(--warm-parchment);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    font-style: italic;
}

/* --- Pull Quotes --- */
.pull-quote {
    font-family: var(--font-display);
    font-style: italic;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--binding-leather);
    line-height: 1.35;
    margin: 1.5em 0 0.5em;
    padding-left: 1.5em;
    border-left: 3px solid var(--manuscript-sepia);
}

.pull-quote-attribution {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.75rem, 0.9vw, 0.85rem);
    letter-spacing: 0.12em;
    color: var(--annotation-brown);
    padding-left: 1.5em;
}

/* --- Timeline (Spread 4) --- */
.timeline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 1rem 0;
}

.timeline-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
}

.timeline-date {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.1rem, 1.6vw, 1.4rem);
    color: var(--library-walnut);
}

.timeline-label {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.65rem, 0.8vw, 0.78rem);
    letter-spacing: 0.1em;
    color: var(--annotation-brown);
    text-align: center;
    max-width: 120px;
}

.timeline-line {
    flex: 1;
    height: 1px;
    background-color: var(--manuscript-sepia);
    margin: 0 0.5rem;
}

/* --- Colophon (Footer) --- */
.colophon-section {
    background-color: var(--binding-leather);
    padding: clamp(3rem, 6vw, 6rem) var(--cell-padding);
    display: flex;
    align-items: center;
    justify-content: center;
}

.colophon-content {
    text-align: center;
    max-width: 600px;
}

.colophon-ornament {
    font-size: 1.5rem;
    color: var(--manuscript-sepia);
    opacity: 0.7;
    margin: 1rem 0;
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.4rem, 2.2vw, 1.8rem);
    color: var(--warm-parchment);
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}

.colophon-text {
    font-family: var(--font-body);
    font-size: clamp(0.85rem, 1vw, 0.95rem);
    line-height: 1.72;
    color: var(--manuscript-sepia);
    margin-bottom: 1.5rem;
}

.colophon-rule {
    width: 80px;
    height: 1px;
    background-color: var(--manuscript-sepia);
    opacity: 0.5;
    margin: 1.5rem auto;
}

.colophon-imprint {
    font-family: var(--font-accent);
    font-variant-caps: small-caps;
    font-feature-settings: "smcp";
    font-size: clamp(0.7rem, 0.85vw, 0.82rem);
    letter-spacing: 0.12em;
    line-height: 1.8;
    color: var(--foxing-spot);
}

/* --- Responsive: Below 768px --- */
@media (max-width: 768px) {
    .contents-grid,
    .spread-3-grid,
    .spread-4-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .contents-grid .cell-dominant,
    .contents-grid .cell-medium:nth-child(2),
    .contents-grid .cell-medium:nth-child(3),
    .contents-grid .cell-accent:nth-child(4),
    .contents-grid .cell-accent:nth-child(5),
    .spread-3-grid .cell-feature,
    .spread-3-grid .cell-medium:nth-child(2),
    .spread-3-grid .cell-small:nth-child(3),
    .spread-3-grid .cell-small:nth-child(4),
    .spread-3-grid .cell-small:nth-child(5),
    .spread-4-grid .cell-medium:nth-child(1),
    .spread-4-grid .cell-medium:nth-child(2),
    .spread-4-grid .cell-medium:nth-child(3),
    .spread-4-grid .cell-small:nth-child(4),
    .spread-4-grid .cell-panoramic {
        grid-column: 1 / -1;
        grid-row: auto;
    }

    .spread-5-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .bento-cell:nth-child(even) {
        background-color: var(--aged-vellum);
    }

    /* Marginalia: inline callout on mobile */
    .marginalia {
        position: relative;
        right: auto;
        top: auto;
        width: 100%;
        min-width: auto;
        padding-right: 0;
        padding: 0.8rem 1rem;
        margin-top: 1rem;
        border-left: 3px solid var(--margin-red);
        background-color: var(--warm-parchment);
    }

    /* Drop caps reduce to 3 lines */
    .drop-cap {
        font-size: 3em;
    }

    /* Navigation: fixed bottom bar */
    .nav-drawer {
        top: auto;
        bottom: 0;
        transform: translateY(100%);
        background-color: var(--binding-leather);
        border-bottom: none;
        border-top: 1px solid var(--manuscript-sepia);
    }

    .nav-drawer.visible {
        transform: translateY(0);
    }

    .nav-item {
        color: var(--manuscript-sepia);
        font-size: clamp(0.65rem, 2.5vw, 0.78rem);
    }

    .nav-item:hover {
        color: var(--gilt-edge);
    }

    #nav-hover-zone {
        top: auto;
        bottom: 0;
        height: 40px;
    }

    .nav-inner {
        gap: 1.2rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .section {
        min-height: auto;
        padding: 2rem 1rem;
    }

    .bento-grid {
        min-height: auto;
    }

    .timeline {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .timeline-line {
        width: 1px;
        height: 20px;
        margin: 0 0 0 1.5rem;
    }

    .timeline-item {
        flex-direction: row;
        gap: 0.8rem;
    }

    .title-rule {
        width: 50vw;
    }

    .section-divider::before {
        left: 10%;
        right: 10%;
    }
}

/* --- Foxing spot pattern background for cells --- */
.bento-cell::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='f'%3E%3CfeTurbulence baseFrequency='0.9' numOctaves='3' type='fractalNoise'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23f)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    opacity: 0.4;
    mix-blend-mode: multiply;
}
