/* ============================================
   aiice.io — Digital Library
   Terracotta-warm palette / Book-scholarly motifs
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --parchment-cream: #f5ebe0;
    --terracotta-sand: #ddb892;
    --burnt-sienna: #b07d4f;
    --library-oak: #8B6914;
    --scholar-ink: #3d2b1f;
    --margin-note: #7a6652;
    --foxed-page: #e8d5b7;
    --deep-binding: #2c1810;
    --oxidized-terracotta: #a85032;
    --library-moss: #6b7c3f;
    --warm-gold: #c4a882;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-variation-settings: 'wght' 380, 'opsz' 16;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.78;
    letter-spacing: 0.005em;
    color: var(--scholar-ink);
    background-color: var(--parchment-cream);
    overflow-x: hidden;
}

::selection {
    background-color: var(--foxed-page);
    color: var(--scholar-ink);
}

/* --- Noise Texture Overlay --- */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    opacity: 0.03;
    filter: url(#noise);
    background: var(--parchment-cream);
}

/* --- Reading Progress Bar --- */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: var(--burnt-sienna);
    box-shadow: 0 0 8px rgba(176, 125, 79, 0.4);
    z-index: 100;
    transition: width 100ms linear;
}

/* --- Generative Art Canvas --- */
#flowFieldCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
}

/* --- Wordmark Overlay (Opening Sequence) --- */
.wordmark-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--parchment-cream);
    z-index: 200;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

.wordmark-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.wordmark {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 3.5vw, 4rem);
    color: var(--library-oak);
    letter-spacing: -0.02em;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

.wordmark-letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(8px);
}

.wordmark-letter.visible {
    animation: letterReveal 0.4s ease forwards;
}

@keyframes letterReveal {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Site Container --- */
.site-container {
    display: flex;
    min-height: 100vh;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.site-container.visible {
    opacity: 1;
}

/* --- Sidebar --- */
.sidebar {
    flex: 0 0 280px;
    background: linear-gradient(175deg, #f5ebe0 0%, #ede0d0 100%);
    border-right: 1px solid var(--warm-gold);
    box-shadow: 4px 0 24px rgba(139, 105, 20, 0.08);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    z-index: 10;
    transform: translateX(-280px);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar.visible {
    transform: translateX(0);
}

/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--warm-gold);
    border-radius: 2px;
}

.sidebar-header {
    padding: 40px 24px 24px;
    border-bottom: 1px solid var(--warm-gold);
}

.sidebar-wordmark {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--library-oak);
    letter-spacing: -0.02em;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

.sidebar-subtitle {
    display: block;
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--margin-note);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-top: 4px;
}

.sidebar-entries {
    flex: 1;
    padding: 16px 0;
}

.catalog-card {
    display: block;
    padding: 16px 24px;
    text-decoration: none;
    color: var(--scholar-ink);
    border-left: 2px solid transparent;
    transition: border-color 0.3s ease-out, transform 0.3s ease-out, background 0.3s ease;
    position: relative;
}

.catalog-card::after {
    content: '';
    display: block;
    height: 1px;
    background: var(--warm-gold);
    margin-top: 16px;
    opacity: 0.5;
}

.catalog-card:last-child::after {
    display: none;
}

.catalog-card:hover {
    border-left-color: var(--burnt-sienna);
    transform: translateX(4px);
    background: rgba(228, 213, 183, 0.2);
}

.catalog-card.active {
    border-left-color: var(--burnt-sienna);
    background: rgba(228, 213, 183, 0.3);
}

.catalog-title {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: 1rem;
    font-variant: small-caps;
    letter-spacing: 0.02em;
    color: var(--scholar-ink);
}

.catalog-date {
    display: block;
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--margin-note);
    margin-top: 2px;
    letter-spacing: 0.01em;
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--warm-gold);
}

.sidebar-meta {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--margin-note);
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-y: auto;
    padding: 80px 48px 120px;
}

/* --- Folio Sections --- */
.folio-section {
    max-width: 860px;
    margin: 0 auto 60px;
    position: relative;
}

.folio-number {
    position: absolute;
    top: 0;
    right: 0;
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--margin-note);
    opacity: 0.5;
}

/* --- Folio Spread (Two-Page Layout) --- */
.folio-spread {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

/* --- Folio Page (Index Card) --- */
.folio-page {
    background: var(--parchment-cream);
    border: 1px solid var(--warm-gold);
    border-radius: 0 6px 0 0;
    padding: 32px 28px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(60, 43, 31, 0.08), 0 1px 3px rgba(60, 43, 31, 0.06);
    transition: transform 0.8s cubic-bezier(0.23, 1, 0.32, 1), box-shadow 0.4s ease;
    will-change: transform;
}

.folio-page:hover {
    box-shadow: 0 8px 32px rgba(60, 43, 31, 0.12), 0 2px 8px rgba(60, 43, 31, 0.08);
}

/* Ruled lines pattern */
.ruled-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 23px,
        var(--foxed-page) 23px,
        var(--foxed-page) 24px
    );
    opacity: 0.5;
    pointer-events: none;
    z-index: 0;
}

.folio-page p,
.folio-page h2 {
    position: relative;
    z-index: 1;
}

.folio-page p {
    margin-bottom: 1em;
}

.folio-page p:last-child {
    margin-bottom: 0;
}

/* Entrance animations */
.folio-page {
    opacity: 0;
    transform: translateX(-16px);
}

.folio-page:nth-child(2) {
    transform: translateX(16px);
}

.folio-page.animate-in {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.folio-page:nth-child(2).animate-in {
    transition-delay: 150ms;
}

/* --- Dropcap --- */
.dropcap::first-letter {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: 4.5rem;
    float: left;
    line-height: 0.8;
    padding-right: 12px;
    color: var(--library-oak);
    border-bottom: 2px solid var(--burnt-sienna);
}

/* --- Section Headings --- */
.section-heading {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: clamp(1.5rem, 3vw, 2rem);
    color: var(--library-oak);
    letter-spacing: -0.02em;
    line-height: 1.15;
    margin-bottom: 1.2em;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

/* --- Folio Divider --- */
.folio-divider {
    max-width: 860px;
    margin: 40px auto;
    text-align: center;
    position: relative;
    height: 1px;
    background: var(--warm-gold);
}

.hedera {
    display: inline-block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 1.2rem;
    color: var(--burnt-sienna);
    background: var(--parchment-cream);
    padding: 0 12px;
    position: relative;
    top: -0.6em;
    animation: hederaSpin 30s linear infinite;
}

@keyframes hederaSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* --- Marginalia SVG Strokes --- */
.marginalia-stroke {
    position: absolute;
    top: 0;
    left: -60px;
    width: 80px;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.marginalia-stroke.right {
    left: auto;
    right: -60px;
}

.calligraphic-stroke {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 12s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.calligraphic-stroke.animate {
    stroke-dashoffset: 0;
}

/* --- Dot Constellation --- */
.dot-constellation {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 1;
}

.dot-constellation .dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.dot-constellation .dot.even {
    background: var(--terracotta-sand);
}

.dot-constellation .dot.odd {
    background: var(--burnt-sienna);
}

.dot-constellation.animate .dot {
    opacity: 1;
    transform: scale(1);
}

.dot-constellation.animate .dot {
    animation: dotPulse 6s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.5; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* --- Colophon --- */
.colophon-section {
    text-align: center;
}

.colophon-content {
    max-width: 560px;
    margin: 0 auto;
    padding: 48px 32px;
}

.colophon-content .section-heading {
    margin-bottom: 1.5em;
}

.colophon-content p {
    margin-bottom: 1em;
    font-variation-settings: 'wght' 350, 'opsz' 14;
    color: var(--margin-note);
}

.colophon-note {
    font-style: italic;
}

.colophon-mark {
    margin-top: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.hedera-static {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-size: 1.5rem;
    color: var(--burnt-sienna);
}

.colophon-domain {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--library-oak);
    letter-spacing: -0.02em;
}

.colophon-year {
    font-family: 'DM Sans', sans-serif;
    font-weight: 300;
    font-size: 0.7rem;
    color: var(--margin-note);
    letter-spacing: 0.12em;
}

/* --- Mobile Sidebar Toggle --- */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--deep-binding);
    color: var(--parchment-cream);
    border: none;
    padding: 12px 24px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: 24px;
    cursor: pointer;
    z-index: 60;
    box-shadow: 0 4px 16px rgba(44, 24, 16, 0.3);
    transition: transform 0.3s ease, background 0.3s ease;
}

.sidebar-toggle:hover {
    background: var(--scholar-ink);
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .site-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        height: 56px;
        flex: none;
        width: 100%;
        transform: translateY(0);
        transition: height 0.4s cubic-bezier(0.16, 1, 0.3, 1);
        border-right: none;
        border-top: 1px solid var(--warm-gold);
        box-shadow: 0 -4px 24px rgba(139, 105, 20, 0.08);
        overflow: hidden;
        z-index: 80;
    }

    .sidebar.visible {
        transform: translateY(0);
    }

    .sidebar.expanded {
        height: 60vh;
        overflow-y: auto;
    }

    .sidebar-header {
        padding: 16px 24px;
    }

    .sidebar-toggle {
        display: block;
    }

    .main-content {
        padding: 60px 20px 100px;
    }

    .folio-spread {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .folio-page {
        transform: translateY(16px);
    }

    .folio-page:nth-child(2) {
        transform: translateY(16px);
    }

    .folio-page.animate-in {
        transform: translateY(0);
    }

    .marginalia-stroke {
        display: none;
    }

    .folio-number {
        position: relative;
        display: block;
        text-align: right;
        margin-bottom: 12px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 40px 16px 100px;
    }

    .folio-page {
        padding: 24px 20px;
    }

    .dropcap::first-letter {
        font-size: 3.5rem;
    }
}
