/* ============================================================
   historical.day -- Styles
   A Codex of Recorded Time
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #F5F0E8;
    --bg-alt: #EDE5D5;
    --bg-deckle: #DDD5C5;
    --text-primary: #2C2416;
    --text-secondary: #6B5B4A;
    --accent-leather: #8B7355;
    --accent-gilt: #C4A96A;
    --accent-wax: #9E4A3A;
    --accent-ribbon: #7A6A5A;

    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-secondary: 'Cormorant Garamond', Garamond, 'Times New Roman', serif;
    --font-body: 'Lora', Georgia, serif;
    --font-annotation: 'IM Fell English', Georgia, serif;

    --baseline: 8px;
    --spine-width: 1.5px;
    --content-max: 1100px;
    --entry-width: 38%;
}

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

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

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* --- Deckled Page Edge (right side) --- */
.deckle-edge {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 8px;
    background: repeating-linear-gradient(
        180deg,
        var(--bg-primary) 0px,
        var(--bg-deckle) 2px,
        var(--bg-primary) 3px,
        var(--bg-alt) 5px,
        var(--bg-primary) 7px,
        var(--bg-deckle) 8px
    );
    z-index: 100;
    pointer-events: none;
}

/* --- Central Spine Rule --- */
.spine-rule {
    position: fixed;
    left: 50%;
    top: 0;
    bottom: 0;
    width: var(--spine-width);
    background: linear-gradient(
        180deg,
        rgba(139, 115, 85, 0.15) 0%,
        rgba(139, 115, 85, 0.4) 30%,
        rgba(139, 115, 85, 0.55) 60%,
        rgba(139, 115, 85, 0.7) 100%
    );
    transform: translateX(-50%);
    z-index: 1;
    pointer-events: none;
}

/* Binding gutter shadow */
.spine-gutter-left,
.spine-gutter-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
}
.spine-gutter-left {
    right: 100%;
    background: linear-gradient(to left, rgba(44, 36, 22, 0.06), transparent);
}
.spine-gutter-right {
    left: 100%;
    background: linear-gradient(to right, rgba(44, 36, 22, 0.06), transparent);
}

/* --- Sticky Era Indicator --- */
.era-indicator {
    position: fixed;
    right: 32px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.era-indicator.active {
    opacity: 1;
}

.era-indicator-text {
    font-family: var(--font-secondary);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    color: var(--accent-leather);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* ============================================================
   FOLIO HEADER / TITLE PAGE
   ============================================================ */
.folio-header {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    padding: 2rem;
}

.folio-header-inner {
    text-align: center;
    max-width: 700px;
}

.folio-epigraph {
    font-family: var(--font-secondary);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    color: var(--accent-leather);
    letter-spacing: 0.08em;
    font-variant: small-caps;
    margin-bottom: calc(var(--baseline) * 4);
}

.folio-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    color: var(--text-primary);
    letter-spacing: 0.02em;
    line-height: 1.1;
    margin-bottom: calc(var(--baseline) * 3);
}

/* Ornamental Rule (title page) */
.ornamental-rule {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: calc(var(--baseline) * 3) auto;
    width: 200px;
}

.ornament-line {
    flex: 1;
    height: 1px;
    background-color: var(--accent-gilt);
}

.ornament-diamond {
    width: 8px;
    height: 8px;
    background-color: var(--accent-gilt);
    transform: rotate(45deg);
    flex-shrink: 0;
}

.folio-subtitle {
    font-family: var(--font-secondary);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(1rem, 2vw, 1.4rem);
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: calc(var(--baseline) * 5);
}

.folio-imprint {
    font-family: var(--font-annotation);
    font-size: clamp(0.7rem, 0.9vw, 0.8rem);
    color: var(--accent-ribbon);
    letter-spacing: 0.06em;
}

/* ============================================================
   MANUSCRIPT / MAIN TIMELINE
   ============================================================ */
.manuscript {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 2rem calc(var(--baseline) * 8);
    position: relative;
    z-index: 2;
}

/* --- Era Section --- */
.era-section {
    position: relative;
    padding: calc(var(--baseline) * 6) 0;
}

/* --- Watermark Date Numerals --- */
.era-watermark {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-display);
    font-weight: 900;
    font-size: clamp(5rem, 15vw, 12rem);
    color: var(--bg-alt);
    opacity: 0;
    z-index: 0;
    pointer-events: none;
    line-height: 1;
    letter-spacing: -0.02em;
    user-select: none;
    will-change: opacity;
    transition: opacity 1200ms ease;
}

.era-watermark.visible {
    opacity: 0.25;
}

/* --- Timeline Entry --- */
.entry {
    display: flex;
    position: relative;
    padding: calc(var(--baseline) * 4) 0;
    z-index: 2;
}

.entry-left .entry-content {
    width: var(--entry-width);
    margin-right: auto;
    text-align: right;
    padding-right: calc(var(--baseline) * 5);
}

.entry-right .entry-content {
    width: var(--entry-width);
    margin-left: auto;
    text-align: left;
    padding-left: calc(var(--baseline) * 5);
}

/* --- Timeline Node --- */
.entry-node {
    position: absolute;
    left: 50%;
    top: calc(var(--baseline) * 5);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--accent-leather);
    background-color: var(--bg-primary);
    transform: translateX(-50%);
    z-index: 3;
    transition: background-color 400ms ease, border-color 400ms ease;
}

.entry-node.active {
    background-color: var(--accent-leather);
}

/* --- Connector Line (node to content) --- */
.entry-connector {
    position: absolute;
    top: calc(var(--baseline) * 5 + 5px);
    height: 1px;
    background-color: var(--accent-leather);
    opacity: 0.3;
    z-index: 2;
}

.entry-left .entry-connector {
    left: var(--entry-width);
    right: 50%;
    margin-right: 6px;
}

.entry-right .entry-connector {
    left: 50%;
    right: calc(100% - var(--entry-width) - var(--entry-width));
    margin-left: 6px;
    width: calc(50% - var(--entry-width) - 6px);
}

/* Recalculate connector for right entries */
.entry-right .entry-connector {
    left: calc(50% + 8px);
    width: calc(var(--entry-width) * 0.3);
}

.entry-left .entry-connector {
    right: calc(50% + 8px);
    left: auto;
    width: calc(var(--entry-width) * 0.3);
}

/* --- Era Label --- */
.era-label {
    font-family: var(--font-secondary);
    font-weight: 300;
    font-style: italic;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    color: var(--accent-gilt);
    display: block;
    margin-bottom: calc(var(--baseline) * 1);
    letter-spacing: 0.04em;
    font-variant: small-caps;
}

/* --- Entry Title --- */
.entry-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--text-primary);
    line-height: 1.25;
    margin-bottom: calc(var(--baseline) * 2);
}

/* --- Drop Capitals --- */
.drop-cap {
    float: left;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 3.5em;
    line-height: 0.8;
    padding-right: 0.08em;
    padding-top: 0.05em;
    color: var(--text-primary);
    text-shadow: 1px 1px 0 var(--accent-gilt), 2px 2px 4px rgba(196, 169, 106, 0.2);
}

.entry-left .drop-cap {
    float: right;
    padding-right: 0;
    padding-left: 0.08em;
}

/* Drop cap fade animation */
.drop-cap {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.fade-reveal.visible .drop-cap {
    opacity: 1;
    transform: translateY(0);
}

/* --- Entry Text --- */
.entry-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    font-weight: 400;
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: calc(var(--baseline) * 2);
}

.entry-text em {
    font-style: italic;
}

/* --- Endnote Markers --- */
.endnote-marker {
    display: inline-block;
    font-family: var(--font-annotation);
    font-size: 0.7rem;
    color: var(--accent-wax);
    vertical-align: super;
    line-height: 0;
    cursor: default;
    position: relative;
    margin-left: 2px;
}

.endnote-marker::before {
    content: '[';
    color: var(--accent-wax);
}

.endnote-marker::after {
    content: ']';
    color: var(--accent-wax);
}

/* Endnote tooltip */
.endnote-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    padding: 12px 14px;
    background-color: var(--bg-alt);
    border-top: 1px solid var(--accent-ribbon);
    font-family: var(--font-annotation);
    font-size: 0.78rem;
    font-style: italic;
    line-height: 1.5;
    color: var(--text-secondary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
    z-index: 20;
    box-shadow: 0 2px 12px rgba(44, 36, 22, 0.1);
}

.endnote-marker:hover .endnote-tooltip {
    opacity: 1;
    pointer-events: auto;
}

/* --- Marginal Annotations --- */
.marginal-note {
    position: absolute;
    font-family: var(--font-annotation);
    font-style: italic;
    font-size: clamp(0.65rem, 0.8vw, 0.75rem);
    color: var(--accent-ribbon);
    letter-spacing: 0.03em;
    opacity: 0;
    transition: opacity 600ms ease, transform 600ms ease;
    pointer-events: none;
    white-space: nowrap;
}

.marginal-note.marginal-right {
    right: -10%;
    top: calc(var(--baseline) * 8);
    transform: translateX(5px);
}

.marginal-note.marginal-left {
    left: -10%;
    top: calc(var(--baseline) * 8);
    transform: translateX(-5px);
}

.marginal-note.visible {
    opacity: 0.7;
}

.marginal-note.marginal-right.visible {
    transform: translateX(0);
}

.marginal-note.marginal-left.visible {
    transform: translateX(0);
}

/* --- Section Dividers (Printer's Ornaments) --- */
.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: calc(var(--baseline) * 3) 0;
    max-width: 180px;
    margin: 0 auto;
}

.divider-line {
    flex: 1;
    height: 1px;
    background-color: var(--accent-ribbon);
    opacity: 0.4;
}

.divider-diamond {
    width: 6px;
    height: 6px;
    background-color: var(--accent-ribbon);
    transform: rotate(45deg);
    flex-shrink: 0;
    opacity: 0.6;
}

.divider-asterism {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--accent-ribbon);
    opacity: 0.6;
    flex-shrink: 0;
    line-height: 1;
}

/* --- Pull Quotes (Visual Blocks) --- */
.pull-quote-block {
    text-align: center;
    padding: calc(var(--baseline) * 5) calc(var(--baseline) * 4);
    margin: calc(var(--baseline) * 3) auto;
    max-width: 650px;
    position: relative;
    z-index: 2;
}

.pq-rule-top,
.pq-rule-bottom {
    height: 1px;
    background-color: var(--accent-ribbon);
    opacity: 0.35;
    margin: 0 auto;
    max-width: 400px;
}

.pull-quote {
    padding: calc(var(--baseline) * 3) 0;
}

.pull-quote p {
    font-family: var(--font-secondary);
    font-style: italic;
    font-weight: 300;
    font-size: clamp(1.5rem, 4vw, 3rem);
    line-height: 1.4;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.pq-citation {
    display: block;
    font-family: var(--font-annotation);
    font-size: clamp(0.75rem, 1vw, 0.875rem);
    font-style: normal;
    color: var(--text-secondary);
    margin-top: calc(var(--baseline) * 1);
    letter-spacing: 0.03em;
    padding-bottom: calc(var(--baseline) * 3);
}

.pq-citation em {
    font-style: italic;
}

/* ============================================================
   COLOPHON
   ============================================================ */
.colophon {
    text-align: center;
    padding: calc(var(--baseline) * 8) 2rem calc(var(--baseline) * 12);
    position: relative;
    z-index: 2;
}

.colophon .ornamental-rule {
    margin-bottom: calc(var(--baseline) * 5);
}

.colophon-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 0 auto calc(var(--baseline) * 4);
    width: 160px;
}

.colophon-text {
    font-family: var(--font-annotation);
    font-style: italic;
    font-size: clamp(0.75rem, 1vw, 0.85rem);
    color: var(--text-secondary);
    line-height: 1.8;
    letter-spacing: 0.02em;
}

.colophon-finis {
    font-size: 1.2rem;
    color: var(--accent-gilt);
    margin-top: calc(var(--baseline) * 4);
}

/* ============================================================
   FADE-REVEAL ANIMATIONS
   ============================================================ */
.fade-reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 800ms ease-out, transform 800ms ease-out;
}

.fade-reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Watermark-specific slow fade */
.fade-watermark {
    opacity: 0;
    will-change: opacity;
    transition: opacity 1200ms ease;
}

.fade-watermark.visible {
    opacity: 0.25;
}

/* Marginal note drift */
.fade-marginal {
    opacity: 0;
    transition: opacity 600ms ease, transform 600ms ease;
}

.fade-marginal.visible {
    opacity: 0.7;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
    .era-indicator {
        display: none;
    }

    .marginal-note {
        display: none;
    }

    .entry-left .entry-content,
    .entry-right .entry-content {
        width: 44%;
    }
}

@media (max-width: 768px) {
    .spine-rule {
        display: none;
    }

    .deckle-edge {
        display: none;
    }

    .entry-node {
        display: none;
    }

    .entry-connector {
        display: none;
    }

    .entry-left .entry-content,
    .entry-right .entry-content {
        width: 100%;
        text-align: left;
        padding: 0;
    }

    .entry-left .drop-cap {
        float: left;
        padding-left: 0;
        padding-right: 0.08em;
    }

    .manuscript {
        padding: 0 1.5rem calc(var(--baseline) * 6);
    }

    .era-watermark {
        font-size: clamp(3rem, 20vw, 6rem);
    }

    .pull-quote-block {
        padding: calc(var(--baseline) * 3) calc(var(--baseline) * 2);
    }
}

@media (max-width: 480px) {
    .folio-title {
        font-size: clamp(2rem, 10vw, 3rem);
    }

    .entry-title {
        font-size: clamp(1.2rem, 5vw, 1.6rem);
    }

    .entry-text {
        font-size: 1rem;
    }

    .pull-quote p {
        font-size: clamp(1.2rem, 5vw, 1.8rem);
    }

    .drop-cap {
        font-size: 2.5em;
    }
}

/* ============================================================
   PRINT STYLESHEET
   ============================================================ */
@media print {
    .spine-rule,
    .deckle-edge,
    .era-indicator,
    .entry-node,
    .entry-connector,
    .era-watermark,
    .marginal-note,
    .section-divider,
    .ornamental-rule,
    .colophon-ornament {
        display: none;
    }

    body {
        background: white;
        color: black;
        font-size: 11pt;
    }

    .folio-header {
        min-height: auto;
        padding: 2em 0;
        page-break-after: always;
    }

    .entry-left .entry-content,
    .entry-right .entry-content {
        width: 100%;
        text-align: left;
        padding: 0;
        margin: 0;
    }

    .entry {
        padding: 1em 0;
        border-bottom: 0.5pt solid #ccc;
    }

    .fade-reveal,
    .fade-watermark,
    .fade-marginal {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .drop-cap {
        opacity: 1;
        transform: none;
        transition: none;
        text-shadow: none;
    }

    .pull-quote-block {
        page-break-inside: avoid;
    }

    .era-label {
        color: #666;
    }

    .endnote-marker {
        color: #333;
    }
}
