/* ============================================
   whitepapers.xyz — Enchanted Research Library
   ============================================ */

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

html {
    scroll-behavior: smooth;
}

body {
    background-color: #f4ede4;
    color: #2c3e2d;
    font-family: 'Quicksand', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.6vw, 1.1rem);
    line-height: 1.8;
    letter-spacing: 0.02em;
    overflow-x: hidden;
    position: relative;
}

/* Paper grain overlay */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.02;
    filter: url(#grain);
    width: 100%;
    height: 100%;
}

.grain-overlay {
    position: absolute;
    width: 0;
    height: 0;
}

/* --- Sidebar --- */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background-color: #e8e0d0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border-right: 1px solid #b8a99a;
}

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

.sidebar-header {
    padding: 2rem 1.5rem 1rem;
    border-bottom: 1px solid #b8a99a;
}

.sidebar-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: 1.4rem;
    color: #2c3e2d;
    letter-spacing: 0.04em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.sidebar-category {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.5rem;
    cursor: pointer;
    position: relative;
    font-family: 'Quicksand', sans-serif;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: #5a6e5c;
    transition: color 300ms ease, background-color 300ms ease;
}

.sidebar-category:hover {
    color: #2c3e2d;
    background-color: rgba(58, 125, 110, 0.06);
    border-color: #2a5e50;
}

/* Twilight Vine accent: #4a6670 */
.sidebar-category:active {
    color: #4a6670;
}

.sidebar-category.active {
    color: #3a7d6e;
}

.sidebar-category.active .vine-indicator {
    stroke-dashoffset: 0;
}

.vine-indicator {
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    transition: stroke-dashoffset 800ms ease;
}

.category-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #b8a99a;
}

.sidebar-note {
    font-family: 'Caveat', cursive;
    font-size: 1rem;
    color: #b8a99a;
}

/* --- Mobile Handle --- */
#mobile-handle {
    display: none;
}

/* --- Main Content --- */
#main-content {
    margin-left: 280px;
    position: relative;
    min-height: 100vh;
}

.candlelight {
    position: fixed;
    top: 0;
    left: 280px;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(201, 123, 90, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 10;
    transition: background 300ms ease;
}

/* --- Hero --- */
#hero {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

#hero-canvas {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    opacity: 0;
    transition: opacity 600ms ease;
}

#hero-canvas.visible {
    opacity: 1;
}

.hero-content {
    position: relative;
    z-index: 2;
    text-align: center;
}

#hero-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(2.5rem, 6vw, 5rem);
    line-height: 1.2;
    color: #2c3e2d;
    font-feature-settings: 'liga' 1, 'onum' 1;
    text-shadow: 1px 1px 0 rgba(244, 237, 228, 0.8), 2px 2px 2px rgba(184, 169, 154, 0.3);
}

#hero-title .char {
    display: inline-block;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 300ms ease, transform 300ms ease;
}

#hero-title .char.visible {
    opacity: 1;
    transform: scale(1);
}

.hero-subtitle {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1.1rem, 2vw, 1.6rem);
    color: #5a6e5c;
    margin-top: 1rem;
    opacity: 0;
    transform: rotate(-1deg);
    transition: opacity 600ms ease;
}

.hero-subtitle.visible {
    opacity: 1;
}

.scroll-prompt {
    position: absolute;
    bottom: 2rem;
    z-index: 2;
    animation: trembleArrow 2s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes trembleArrow {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(6px) rotate(1deg); }
}

/* --- Section Headings --- */
.section-heading {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    line-height: 1.2;
    color: #2c3e2d;
    margin-bottom: 2rem;
    padding: 2rem 4vw 0;
    font-feature-settings: 'liga' 1, 'onum' 1;
}

/* --- Paper Cards --- */
#archive, #archive-continued {
    padding: 2rem 0 4rem;
}

.paper-card {
    max-width: 640px;
    background: #faf6f0;
    padding: 2rem 2rem 1.5rem;
    margin: 2.5rem 0;
    position: relative;
    border: 1px solid #b8a99a;
    box-shadow: 2px 2px 8px rgba(44, 62, 45, 0.08);
    cursor: pointer;
    opacity: 0;
    transition: transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 300ms ease,
                opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    clip-path: polygon(
        0% 2%, 4% 0%, 10% 1%, 20% 0%, 30% 0.5%, 45% 0%, 55% 0.8%, 65% 0%, 75% 0.3%, 85% 0%, 95% 1%, 100% 0%,
        100% 98%, 96% 100%, 90% 99%, 80% 100%, 70% 99.5%, 55% 100%, 45% 99.2%, 35% 100%, 25% 99.7%, 15% 100%, 5% 99%, 0% 100%
    );
}

.paper-card.card-visible {
    opacity: 1;
}

.paper-card:nth-child(odd) {
    margin-left: 2vw;
    transform: translateX(-40px) rotate(0.4deg);
}

.paper-card:nth-child(even) {
    margin-left: 8vw;
    transform: translateX(40px) rotate(-0.3deg);
}

.paper-card.card-visible:nth-child(odd) {
    transform: translateX(0) rotate(0.4deg);
}

.paper-card.card-visible:nth-child(even) {
    transform: translateX(0) rotate(-0.3deg);
}

.paper-card:hover {
    transform: translateY(-3px) rotate(0deg) !important;
    box-shadow: 4px 6px 16px rgba(44, 62, 45, 0.14);
}

.paper-card:hover .wax-seal {
    transform: rotate(8deg) scale(1.05);
}

/* --- Wax Seal --- */
.wax-seal {
    position: absolute;
    top: -10px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #d4896a, #c97b5a, #a86544);
    box-shadow: inset 2px 2px 4px rgba(0,0,0,0.3), 2px 3px 6px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: 20px;
    color: #faf6f0;
    z-index: 3;
    transition: transform 200ms ease;
    animation: sealStamp 200ms ease-out;
}

@keyframes sealStamp {
    from { transform: scale(1.3); opacity: 0.5; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Card Content --- */
.card-title {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 600;
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    line-height: 1.3;
    color: #2c3e2d;
    margin-bottom: 0.5rem;
    padding-right: 3rem;
}

.card-author {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    color: #c97b5a;
    display: inline-block;
    transform: rotate(-1deg);
}

.card-date {
    font-family: 'Quicksand', sans-serif;
    font-weight: 500;
    font-size: 0.85rem;
    color: #b8a99a;
    margin-left: 1rem;
}

.card-abstract {
    margin-top: 1rem;
    color: #5a6e5c;
    line-height: 1.7;
}

.card-expanded {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 600ms ease, opacity 400ms ease 200ms;
}

.paper-card.expanded .card-expanded {
    max-height: 500px;
    opacity: 1;
}

.card-expanded p {
    margin-top: 1rem;
    color: #2c3e2d;
    line-height: 1.8;
    padding-top: 1rem;
    border-top: 1px solid #b8a99a;
}

.card-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.tag {
    font-family: 'Caveat', cursive;
    font-size: 0.85rem;
    color: #3a7d6e;
    background: rgba(58, 125, 110, 0.08);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    border: 1px solid rgba(58, 125, 110, 0.15);
}

.card-botanical {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 120px;
    height: 120px;
    opacity: 0.12;
    pointer-events: none;
}

/* --- Garden Path --- */
#garden-path {
    height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#garden-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.garden-quote {
    position: relative;
    z-index: 2;
    font-family: 'Caveat', cursive;
    font-weight: 700;
    font-size: clamp(1.3rem, 3vw, 2rem);
    color: #faf6f0;
    text-shadow: 0 2px 8px rgba(44, 62, 45, 0.4);
    opacity: 0.8;
}

/* --- Reading Room --- */
#reading-room {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 4vw;
}

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

.reading-room-text {
    font-family: 'Quicksand', sans-serif;
    color: #5a6e5c;
    margin-bottom: 2rem;
    line-height: 1.8;
}

.reading-room-decoration {
    display: flex;
    justify-content: center;
}

#reading-room-canvas {
    opacity: 0.3;
}

/* --- Celtic Knot Divider --- */
.section-heading::after {
    content: '';
    display: block;
    width: 80px;
    height: 2px;
    background: linear-gradient(to right, transparent, #b8a99a, transparent);
    margin-top: 0.75rem;
}

/* --- Mobile --- */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        height: 60vh;
        transform: translateY(100%);
        border-right: none;
        border-top: 1px solid #b8a99a;
        border-radius: 16px 16px 0 0;
        z-index: 200;
    }

    #sidebar.visible {
        transform: translateY(100%);
    }

    #sidebar.drawer-open {
        transform: translateY(0);
    }

    #mobile-handle {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 40px;
        background: #e8e0d0;
        z-index: 199;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top: 1px solid #b8a99a;
        cursor: pointer;
    }

    .rope-handle {
        width: 40px;
        height: 4px;
        background: #b8a99a;
        border-radius: 2px;
    }

    #main-content {
        margin-left: 0;
        padding-bottom: 40px;
    }

    .candlelight {
        left: 0;
    }

    .paper-card {
        max-width: 100%;
        margin-left: 1rem !important;
        margin-right: 1rem;
        clip-path: none;
        border-radius: 4px;
    }

    .paper-card:nth-child(odd),
    .paper-card:nth-child(even) {
        transform: translateY(20px);
    }

    .paper-card.card-visible:nth-child(odd),
    .paper-card.card-visible:nth-child(even) {
        transform: translateY(0);
    }

    .wax-seal {
        position: relative;
        top: 0;
        right: 0;
        display: inline-flex;
        margin-bottom: 0.75rem;
    }
}
