/* ============================================================
   diplomatic.wiki - Styles
   A late-19th-century diplomatic archive codex
   ============================================================ */

/* ----- CSS Custom Properties ----- */
:root {
    /* Palette */
    --aged-parchment: #F2E8D5;
    --deep-parchment: #EAE0CE;
    --walnut-dark: #2A1A10;
    --archive-burgundy: #6B1D2A;
    --folio-gold: #B8965A;
    --ink-sepia: #3A2E28;
    --manuscript-umber: #5C4033;
    --catalog-gray: #7A7062;
    --wax-seal-red: #8B2218;
    --brass-rule: #C4A265;
    --card-parchment: #F5EEE0;
    --card-shadow: #D8CFC0;

    /* Typography */
    --font-display: 'Cormorant Garamond', 'Georgia', serif;
    --font-subheading: 'EB Garamond', 'Georgia', serif;
    --font-body: 'Crimson Pro', 'Georgia', serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    --font-decorative: 'Cinzel Decorative', 'Georgia', serif;

    /* Spacing */
    --sidebar-width: 220px;
    --content-max: 900px;

    /* Foxing spot positions */
    --fox1-x: 15%;
    --fox1-y: 23%;
    --fox2-x: 72%;
    --fox2-y: 8%;
    --fox3-x: 88%;
    --fox3-y: 45%;
    --fox4-x: 34%;
    --fox4-y: 67%;
    --fox5-x: 58%;
    --fox5-y: 31%;
    --fox6-x: 91%;
    --fox6-y: 78%;
    --fox7-x: 7%;
    --fox7-y: 55%;
    --fox8-x: 45%;
    --fox8-y: 89%;
    --fox9-x: 78%;
    --fox9-y: 62%;
    --fox10-x: 22%;
    --fox10-y: 41%;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    color: var(--ink-sepia);
    background-color: var(--walnut-dark);
    overflow-x: hidden;
}

/* ----- Paper Grain Texture (applied to parchment areas) ----- */
.parchment-bg {
    background-color: var(--aged-parchment);
}

/* ----- Foxing Spots ----- */
#reading-table::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(circle 8px at var(--fox1-x) var(--fox1-y), rgba(92, 64, 51, 0.04) 0%, transparent 100%),
        radial-gradient(circle 12px at var(--fox2-x) var(--fox2-y), rgba(92, 64, 51, 0.03) 0%, transparent 100%),
        radial-gradient(circle 6px at var(--fox3-x) var(--fox3-y), rgba(92, 64, 51, 0.05) 0%, transparent 100%),
        radial-gradient(circle 14px at var(--fox4-x) var(--fox4-y), rgba(92, 64, 51, 0.03) 0%, transparent 100%),
        radial-gradient(circle 9px at var(--fox5-x) var(--fox5-y), rgba(92, 64, 51, 0.04) 0%, transparent 100%),
        radial-gradient(circle 7px at var(--fox6-x) var(--fox6-y), rgba(92, 64, 51, 0.05) 0%, transparent 100%),
        radial-gradient(circle 16px at var(--fox7-x) var(--fox7-y), rgba(92, 64, 51, 0.03) 0%, transparent 100%),
        radial-gradient(circle 10px at var(--fox8-x) var(--fox8-y), rgba(92, 64, 51, 0.04) 0%, transparent 100%),
        radial-gradient(circle 8px at var(--fox9-x) var(--fox9-y), rgba(92, 64, 51, 0.035) 0%, transparent 100%),
        radial-gradient(circle 11px at var(--fox10-x) var(--fox10-y), rgba(92, 64, 51, 0.04) 0%, transparent 100%);
}

/* ----- Diplomatic Seal Watermark ----- */
#watermark-seal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vh;
    height: 60vh;
    opacity: 0.06;
    z-index: 0;
    pointer-events: none;
    animation: sealRotate 180s linear infinite;
}

#watermark-seal svg {
    width: 100%;
    height: 100%;
}

@keyframes sealRotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ----- Book Cover Overlay (Opening Animation) ----- */
#book-cover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--walnut-dark);
    z-index: 1000;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.8s ease-out;
}

#book-cover-overlay.fade-out {
    opacity: 0;
}

#spine-light {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 0;
    background: linear-gradient(to bottom, transparent, rgba(184, 150, 90, 0.3), transparent);
    z-index: 1001;
    pointer-events: none;
    transition: height 0.6s ease-out, opacity 0.4s ease-out 0.6s;
}

#spine-light.active {
    height: 100vh;
}

#spine-light.fade-out {
    opacity: 0;
}

/* ----- Title Page (Hero) ----- */
#title-page {
    position: relative;
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--aged-parchment);
    /* Paper grain texture via layered gradients */
    background-image:
        radial-gradient(ellipse at center, var(--aged-parchment) 0%, rgba(226, 215, 194, 1) 100%),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(92, 64, 51, 0.008) 2px,
            rgba(92, 64, 51, 0.008) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(92, 64, 51, 0.006) 3px,
            rgba(92, 64, 51, 0.006) 6px
        );
    z-index: 1;
    overflow: hidden;
}

.fold-line {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 100%;
    background: linear-gradient(
        to bottom,
        transparent 5%,
        rgba(184, 150, 90, 0.12) 20%,
        rgba(184, 150, 90, 0.18) 50%,
        rgba(184, 150, 90, 0.12) 80%,
        transparent 95%
    );
    z-index: 1;
}

.title-page-content {
    text-align: center;
    max-width: 600px;
    padding: 2rem;
    position: relative;
    z-index: 2;
}

.title-rule {
    border: none;
    height: 1px;
    background-color: var(--brass-rule);
    opacity: 0.5;
    margin: 0 auto 2.5rem;
    width: 0;
    transition: width 0.8s ease-out;
}

.title-rule.animate {
    width: 200px;
}

.site-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5vw, 4.5rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--archive-burgundy);
    line-height: 1.1;
    margin-bottom: 1.5rem;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

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

.arabesque-hero {
    margin: 0 auto 1.5rem;
    opacity: 0;
    transition: opacity 0.6s ease-out;
}

.arabesque-hero.animate {
    opacity: 1;
}

.subtitle {
    font-family: var(--font-subheading);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: var(--manuscript-umber);
    letter-spacing: 0.04em;
    margin-bottom: 2rem;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

.subtitle.animate {
    opacity: 1;
}

.intro-text {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: clamp(0.95rem, 1.6vw, 1.05rem);
    line-height: 1.72;
    color: var(--ink-sepia);
    max-width: 50ch;
    margin: 0 auto 2rem;
    text-align: justify;
    hyphens: auto;
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

.intro-text.animate {
    opacity: 1;
}

.date-roman {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1rem;
    letter-spacing: 0.2em;
    color: var(--catalog-gray);
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

.date-roman.animate {
    opacity: 1;
}

/* ----- Arabesque Dividers ----- */
.arabesque-divider {
    width: 100%;
    max-width: 400px;
    margin: 0 auto 1.5rem;
    height: 60px;
}

.arabesque-divider svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.arabesque-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    transition: stroke-dashoffset 1.2s ease-out;
}

.arabesque-path.draw {
    stroke-dashoffset: 0;
}

/* ----- Index Drawer (Sidebar Navigation) ----- */
#index-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--walnut-dark);
    /* Leather texture via CSS gradients */
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 1px,
            rgba(184, 150, 90, 0.03) 1px,
            rgba(184, 150, 90, 0.03) 2px
        ),
        repeating-radial-gradient(
            circle at 50% 50%,
            transparent 0%,
            transparent 1px,
            rgba(0, 0, 0, 0.02) 1px,
            rgba(0, 0, 0, 0.02) 2px
        );
    border-right: 1px solid var(--folio-gold);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.4s ease-out;
    overflow-y: auto;
    padding-top: 2rem;
}

#index-drawer.visible {
    transform: translateX(0);
}

#index-drawer.hidden {
    transform: translateX(-100%);
}

.drawer-header {
    padding: 0.5rem 1rem 1.5rem;
    border-bottom: 1px solid rgba(184, 150, 90, 0.2);
    margin-bottom: 1rem;
}

.drawer-label {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--folio-gold);
}

.card-stack {
    list-style: none;
    padding: 0 0.5rem;
}

.index-card {
    position: relative;
    background-color: var(--card-parchment);
    margin-bottom: 4px;
    padding: 0.65rem 0.8rem 0.65rem 1rem;
    border-radius: 2px;
    box-shadow:
        1px 1px 0 var(--card-shadow),
        2px 2px 0 rgba(216, 207, 192, 0.5);
    cursor: pointer;
    transform: translateX(0);
    transition: transform 0.25s ease-out, box-shadow 0.25s ease-out, border-left-color 0.25s ease-out;
    border-left: 3px solid transparent;
}

.index-card:hover {
    transform: translateX(12px);
    box-shadow:
        1px 1px 0 var(--card-shadow),
        3px 3px 2px rgba(216, 207, 192, 0.6);
}

.index-card.active {
    border-left-color: var(--wax-seal-red);
    transform: translateX(6px) rotate(0.5deg);
    box-shadow:
        2px 2px 1px var(--card-shadow),
        4px 4px 3px rgba(216, 207, 192, 0.5);
}

.card-tab {
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 20px;
    background-color: var(--card-parchment);
    border-radius: 0 2px 2px 0;
    box-shadow: 1px 1px 0 var(--card-shadow);
}

.card-label {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    color: var(--ink-sepia);
    line-height: 1.4;
}

/* ----- Mobile Navigation Toggle ----- */
#mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 101;
    background: var(--walnut-dark);
    border: 1px solid var(--folio-gold);
    border-radius: 3px;
    padding: 0.5rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

#mobile-nav-toggle.visible {
    opacity: 1;
}

/* ----- Main Content (Reading Table) ----- */
#reading-table {
    position: relative;
    background-color: var(--aged-parchment);
    /* Paper grain texture */
    background-image:
        radial-gradient(ellipse at center, var(--aged-parchment) 0%, rgba(226, 215, 194, 1) 100%),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(92, 64, 51, 0.008) 2px,
            rgba(92, 64, 51, 0.008) 4px
        );
    z-index: 1;
    padding-left: 0;
    transition: padding-left 0.4s ease-out;
}

#reading-table.sidebar-active {
    padding-left: var(--sidebar-width);
}

/* ----- Codex Sections ----- */
.codex-section {
    padding: 4rem 2rem;
    max-width: 1100px;
    margin: 0 auto;
}

.section-content {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 3rem;
    align-items: start;
}

.primary-column {
    max-width: 62ch;
}

.primary-column h2 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.8rem, 4vw, 3rem);
    letter-spacing: 0.08em;
    color: var(--archive-burgundy);
    line-height: 1.1;
    margin-bottom: 1.5rem;
}

.primary-column p {
    margin-bottom: 1.2rem;
    text-align: justify;
    hyphens: auto;
    max-width: 62ch;
}

/* ----- Drop Caps ----- */
.drop-cap {
    font-family: var(--font-decorative);
    font-weight: 400;
    font-size: 4.5em;
    float: left;
    line-height: 0.75;
    margin-right: 0.15em;
    margin-top: 0.05em;
    color: var(--folio-gold);
    text-shadow: 0 0 8px rgba(184, 150, 90, 0.15);
    transform: scale(0.8);
    transition: transform 0.4s ease-out 0.2s;
}

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

/* ----- Marginalia Column ----- */
.marginalia-column {
    padding-top: 4rem;
    opacity: 0;
    transform: translateX(15px);
    transition: opacity 0.6s ease-out 0.3s, transform 0.6s ease-out 0.3s;
}

.marginalia-column.animate {
    opacity: 1;
    transform: translateX(0);
}

.annotation {
    margin-bottom: 1.8rem;
    padding-left: 0.5rem;
    border-left: 1px solid rgba(184, 150, 90, 0.2);
    position: relative;
}

.caret {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--wax-seal-red);
    opacity: 0.5;
    margin-right: 0.3rem;
}

.annotation-text {
    font-family: var(--font-mono);
    font-weight: 300;
    font-style: italic;
    font-size: clamp(0.72rem, 1.2vw, 0.85rem);
    letter-spacing: 0.02em;
    color: var(--catalog-gray);
    line-height: 1.55;
    display: inline;
}

.annotation::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0.5rem;
    right: 0;
    height: 2px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='4'%3E%3Cpath d='M0,2 Q10,0 20,2 Q30,4 40,2 Q50,0 60,2 Q70,4 80,2 Q90,0 100,2' fill='none' stroke='%238B2218' stroke-width='0.5' opacity='0.2'/%3E%3C/svg%3E") repeat-x;
    transition: opacity 0.3s ease-out;
}

.annotation:hover::after {
    opacity: 1;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='4'%3E%3Cpath d='M0,2 Q10,0 20,2 Q30,4 40,2 Q50,0 60,2 Q70,4 80,2 Q90,0 100,2' fill='none' stroke='%238B2218' stroke-width='0.5' opacity='0.5'/%3E%3C/svg%3E") repeat-x;
}

/* Marginalia pulse animation */
@keyframes marginaliaPulse {
    0%, 100% { opacity: 0.18; }
    50% { opacity: 0.22; }
}

.annotation {
    animation: marginaliaPulse 4s ease-in-out infinite;
}

.annotation:hover {
    animation: none;
    opacity: 1;
}

/* ----- Appendix Folds ----- */
.appendix-fold {
    position: relative;
    width: 90vw;
    max-width: 1200px;
    margin: 3rem auto;
    padding: 4rem 3rem;
    background-color: var(--deep-parchment);
    /* Slightly different grain texture */
    background-image:
        radial-gradient(ellipse at center, var(--deep-parchment) 0%, rgba(218, 206, 186, 1) 100%),
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 3px,
            rgba(92, 64, 51, 0.006) 3px,
            rgba(92, 64, 51, 0.006) 6px
        );
    z-index: 1;
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.appendix-fold.animate {
    opacity: 1;
    transform: scale(1);
}

.fold-center-line {
    position: absolute;
    top: 1rem;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    border-left: 1px dashed rgba(196, 162, 101, 0.15);
}

.treaty-excerpt {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.treaty-excerpt p {
    font-family: var(--font-subheading);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.05rem, 2vw, 1.25rem);
    line-height: 1.65;
    color: var(--ink-sepia);
    padding-left: 2rem;
    border-left: 3px solid var(--brass-rule);
    text-align: left;
    margin-bottom: 1.2rem;
}

.treaty-excerpt cite {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.72rem, 1.1vw, 0.82rem);
    color: var(--catalog-gray);
    letter-spacing: 0.02em;
    display: block;
    text-align: right;
}

/* ----- Glossary ----- */
.glossary-list {
    margin-top: 1.5rem;
}

.glossary-list dt {
    font-family: var(--font-subheading);
    font-weight: 600;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: var(--archive-burgundy);
    margin-bottom: 0.3rem;
    font-feature-settings: "smcp";
    letter-spacing: 0.04em;
}

.glossary-list dd {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.95rem, 1.6vw, 1.05rem);
    color: var(--ink-sepia);
    margin-bottom: 1.5rem;
    padding-left: 1.2rem;
    border-left: 2px solid rgba(196, 162, 101, 0.2);
    line-height: 1.65;
    text-align: justify;
    hyphens: auto;
}

/* ----- Horizontal Rule Hover ----- */
hr {
    border: none;
    height: 1px;
    background-color: var(--brass-rule);
    opacity: 0.4;
    transition: opacity 0.3s ease-out;
}

hr:hover {
    opacity: 0.7;
}

/* ----- Section Animation (fade-and-rise) ----- */
.codex-section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.codex-section.animate {
    opacity: 1;
    transform: translateY(0);
}

/* ----- Colophon (Footer) ----- */
#colophon {
    background-color: var(--walnut-dark);
    padding: 5rem 2rem;
    text-align: center;
    position: relative;
    z-index: 1;
}

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

.printers-mark {
    width: 80px;
    height: 100px;
    margin: 0 auto 2rem;
}

.printers-mark svg {
    width: 100%;
    height: 100%;
}

.draw-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.5s ease-out;
}

.draw-path.animate {
    stroke-dashoffset: 0;
}

.colophon-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.5rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--folio-gold);
    margin-bottom: 1rem;
    font-variant: small-caps;
}

.colophon-meta {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: 0.78rem;
    color: var(--catalog-gray);
    letter-spacing: 0.03em;
    margin-bottom: 0.5rem;
}

.arabesque-tailpiece {
    margin: 2rem auto;
}

.colophon-date {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 0.9rem;
    letter-spacing: 0.2em;
    color: var(--catalog-gray);
    margin-top: 1rem;
}

/* ----- Subheadings (h3, h4) ----- */
h3, h4 {
    font-family: var(--font-subheading);
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    font-feature-settings: "smcp", "onum";
    letter-spacing: 0.06em;
    color: var(--manuscript-umber);
    line-height: 1.35;
}

h3 {
    font-weight: 500;
    margin-bottom: 1rem;
}

h4 {
    font-weight: 400;
    font-style: italic;
    margin-bottom: 0.8rem;
}

/* ----- Links ----- */
a {
    color: var(--archive-burgundy);
    text-decoration: none;
    transition: color 0.2s ease-out;
}

a:hover {
    color: var(--wax-seal-red);
}

a:visited {
    color: var(--wax-seal-red);
}

/* ----- Responsive: Below 1024px ----- */
@media (max-width: 1024px) {
    #index-drawer {
        display: none;
    }

    #index-drawer.mobile-open {
        display: block;
        transform: translateX(0);
    }

    #mobile-nav-toggle {
        display: block;
    }

    #reading-table.sidebar-active {
        padding-left: 0;
    }

    .section-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .marginalia-column {
        padding-top: 0;
        border-top: 1px solid rgba(184, 150, 90, 0.2);
        padding-top: 1.5rem;
    }

    .appendix-fold {
        width: 95vw;
        padding: 3rem 2rem;
    }

    .codex-section {
        padding: 3rem 1.5rem;
    }
}

/* ----- Responsive: Below 768px ----- */
@media (max-width: 768px) {
    .site-title {
        letter-spacing: 0.06em;
    }

    .title-page-content {
        padding: 1.5rem;
    }

    .intro-text {
        text-align: left;
        hyphens: none;
    }

    .primary-column p {
        text-align: left;
        hyphens: none;
    }

    .treaty-excerpt p {
        font-size: 1rem;
    }

    .appendix-fold {
        padding: 2.5rem 1.5rem;
    }

    .codex-section {
        padding: 2.5rem 1rem;
    }

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

    #colophon {
        padding: 3rem 1.5rem;
    }
}

/* ----- Utility ----- */
.hidden {
    /* Used by JS to toggle visibility */
}

/* ----- Scrollbar Styling ----- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--walnut-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--folio-gold);
    border-radius: 4px;
    opacity: 0.6;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--brass-rule);
}

/* ----- Selection Styling ----- */
::selection {
    background-color: rgba(107, 29, 42, 0.15);
    color: var(--ink-sepia);
}
