/* ============================================
   rational.quest — Fairycore Rationalism
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --deep-burgundy: #4A0E1B;
    --midnight-thorn: #2B0A12;
    --aged-vellum: #F0E6D4;
    --foxed-parchment: #D9C8A9;
    --ink-shadow: #2E1A0E;
    --faded-sage: #7A6B5D;
    --gilded-edge: #C4963A;
    --moss-whisper: #4A5E3C;
    --firefly-glow: #E8C87A;

    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Alegreya', Georgia, serif;
    --font-accent: 'Barlow Condensed', Helvetica, sans-serif;

    --hero-scale: clamp(2.8rem, 7vw, 5.6rem);
    --section-heading-scale: clamp(1.6rem, 3.5vw, 2.8rem);
    --card-title-scale: clamp(1.1rem, 2vw, 1.5rem);
    --body-size: clamp(0.95rem, 1.1vw, 1.1rem);
    --accent-size: clamp(0.7rem, 0.9vw, 0.85rem);

    --masonry-gap: clamp(16px, 2.5vw, 32px);
}

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

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    font-size: var(--body-size);
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--ink-shadow);
    background-color: var(--aged-vellum);
    overflow-x: hidden;
    position: relative;
}

/* --- Particle Canvas --- */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* --- Ambient Background --- */
#ambient-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

#ambient-bg::before,
#ambient-bg::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(217, 200, 169, 0.3), transparent 70%);
    will-change: transform;
}

#ambient-bg::before {
    width: 60vw;
    height: 60vw;
    top: 10%;
    left: -10%;
}

#ambient-bg::after {
    width: 50vw;
    height: 50vw;
    bottom: 20%;
    right: -15%;
}

/* --- Navigation --- */
#main-nav {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 100;
}

#nav-monogram {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--deep-burgundy);
    color: var(--aged-vellum);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-radius 400ms cubic-bezier(0.34, 1.56, 0.64, 1),
                width 400ms cubic-bezier(0.34, 1.56, 0.64, 1),
                background-color 300ms ease;
    letter-spacing: 0.05em;
    user-select: none;
}

#nav-monogram:hover {
    background: var(--gilded-edge);
    color: var(--midnight-thorn);
}

#nav-list {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 400ms ease, opacity 300ms ease, padding 300ms ease;
    background: rgba(240, 230, 212, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 4px;
    margin-top: 8px;
    padding: 0;
}

#main-nav.open #nav-list {
    max-height: 300px;
    opacity: 1;
    padding: 12px 16px;
}

#nav-list li {
    margin-bottom: 6px;
}

#nav-list li:last-child {
    margin-bottom: 0;
}

#nav-list a {
    text-decoration: none;
    color: var(--ink-shadow);
    font-family: var(--font-accent);
    font-size: var(--accent-size);
    font-weight: 400;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    transition: color 200ms ease;
}

#nav-list a:hover {
    color: var(--deep-burgundy);
}

.dot-leader {
    flex: 1;
    border-bottom: 1px dotted var(--faded-sage);
    margin: 0 6px;
    opacity: 0.5;
}

/* --- Hero Section --- */
#hero {
    position: relative;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--midnight-thorn);
    overflow: hidden;
    z-index: 1;
}

.hero-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--midnight-thorn);
    opacity: 0;
    transition: opacity 600ms ease;
    filter: url(#paper-noise);
}

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

.hero-content {
    position: relative;
    z-index: 3;
    text-align: center;
    padding: 0 24px;
}

.hero-title {
    font-family: var(--font-display);
    font-size: var(--hero-scale);
    font-weight: 500;
    color: var(--aged-vellum);
    letter-spacing: 0.03em;
    line-height: 1.15;
    font-feature-settings: 'liga' 1, 'kern' 1, 'onum' 1;
    min-height: 1.2em;
}

.hero-title .char {
    display: inline-block;
    opacity: 0;
    clip-path: circle(3px at 50% 50%);
    transition: clip-path 200ms ease-out, opacity 100ms ease;
}

.hero-title .char.visible {
    opacity: 1;
    clip-path: inset(0);
}

.hero-title .char.dot {
    margin: 0 0.02em;
}

.hero-underline {
    width: clamp(200px, 40vw, 400px);
    height: 8px;
    margin: 12px auto 0;
    display: block;
}

.hero-underline path {
    transition: stroke-dashoffset 600ms ease-in-out;
}

.hero-underline.drawn path {
    stroke-dashoffset: 0;
}

.hero-subtitle {
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.8vw, 1.4rem);
    color: var(--foxed-parchment);
    margin-top: 20px;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 500ms ease, transform 500ms ease;
    line-height: 1.5;
}

.hero-subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

.hero-chevron {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    z-index: 3;
}

.hero-chevron.visible {
    animation: chevronPulse 2s ease-in-out infinite;
}

@keyframes chevronPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.9; }
}

/* --- Section Headings --- */
.section-heading {
    font-family: var(--font-display);
    font-size: var(--section-heading-scale);
    font-weight: 600;
    color: var(--midnight-thorn);
    letter-spacing: 0.02em;
    line-height: 1.15;
    text-align: center;
    margin-bottom: clamp(24px, 3vw, 48px);
    font-feature-settings: 'liga' 1, 'kern' 1, 'onum' 1;
}

/* --- Masonry Sections --- */
.masonry-section {
    position: relative;
    z-index: 1;
    padding: clamp(24px, 4vw, 64px) clamp(16px, 4vw, 64px);
    max-width: 1200px;
    margin: 0 auto;
}

/* --- Masonry Grid --- */
.masonry-grid {
    columns: 3;
    column-gap: var(--masonry-gap);
}

@media (max-width: 900px) {
    .masonry-grid {
        columns: 2;
    }
}

@media (max-width: 560px) {
    .masonry-grid {
        columns: 1;
    }
}

/* --- Masonry Cards --- */
.masonry-card {
    position: relative;
    break-inside: avoid;
    margin-bottom: var(--card-offset, 16px);
    padding: 24px 20px 20px;
    background: var(--foxed-parchment);
    border: 1px solid rgba(196, 150, 58, 0.15);
    border-radius: var(--corner-variance, 3px);
    transform: rotate(var(--card-tilt, 0deg));
    transition: transform 300ms ease-out,
                box-shadow 300ms ease-out,
                border-color 300ms ease-out,
                clip-path 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
    cursor: pointer;
    overflow: hidden;

    /* Paper texture via vignette */
    background-image:
        radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(46, 26, 14, 0.08) 100%);
    background-color: var(--foxed-parchment);

    /* Card reveal initial state */
    opacity: 0;
    transform: rotate(var(--card-tilt, 0deg)) translateY(20px);
}

.masonry-card.revealed {
    opacity: 1;
    transform: rotate(var(--card-tilt, 0deg)) translateY(0);
    transition: transform 500ms ease-out,
                opacity 500ms ease-out,
                box-shadow 300ms ease-out,
                border-color 300ms ease-out,
                clip-path 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.masonry-card:hover {
    transform: rotate(var(--card-tilt, 0deg)) translateY(-3px);
    box-shadow: 0 6px 20px rgba(43, 10, 18, 0.12);
    border-color: rgba(196, 150, 58, 0.4);
    clip-path: polygon(2% 1%, 98% 0%, 99% 98%, 1% 99%);
}

/* Journal card: ruled lines */
.card-journal {
    background-image:
        radial-gradient(ellipse at 50% 50%, transparent 40%, rgba(46, 26, 14, 0.08) 100%),
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent 27px,
            rgba(74, 14, 27, 0.02) 27px,
            rgba(74, 14, 27, 0.02) 28px
        );
}

/* Specimen card: heavier vignette */
.card-specimen {
    background-image:
        radial-gradient(ellipse at 50% 50%, transparent 30%, rgba(46, 26, 14, 0.12) 100%);
}

/* Letter card: clean, no ruling */
.card-letter {
    background-image: none;
    background-color: var(--foxed-parchment);
    padding-bottom: 48px;
}

/* --- Card Elements --- */
.card-pin {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #D4A84B, #8B6914);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
    z-index: 5;
    opacity: 0;
    transition: opacity 300ms ease, transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.masonry-card.revealed .card-pin {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.card-tag {
    display: inline-block;
    font-family: var(--font-accent);
    font-size: var(--accent-size);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--deep-burgundy);
    margin-bottom: 8px;
    line-height: 1.4;
}

.card-title {
    font-family: var(--font-display);
    font-size: var(--card-title-scale);
    font-weight: 600;
    color: var(--deep-burgundy);
    letter-spacing: 0.02em;
    line-height: 1.3;
    margin-bottom: 10px;
    font-feature-settings: 'liga' 1, 'kern' 1, 'onum' 1;
}

.card-body {
    font-family: var(--font-body);
    font-size: var(--body-size);
    line-height: 1.72;
    color: var(--ink-shadow);
    letter-spacing: 0.01em;
    margin-bottom: 8px;
}

.card-expanded {
    max-height: 0;
    overflow: hidden;
    transition: max-height 500ms ease;
}

.masonry-card.expanded .card-expanded {
    max-height: 500px;
}

.card-expanded p {
    font-family: var(--font-body);
    font-size: var(--body-size);
    font-style: italic;
    line-height: 1.72;
    color: var(--ink-shadow);
    padding-top: 8px;
    border-top: 1px solid rgba(196, 150, 58, 0.2);
}

.card-meta {
    display: block;
    font-family: var(--font-accent);
    font-size: var(--accent-size);
    font-weight: 400;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--faded-sage);
    margin-top: 12px;
    line-height: 1.4;
}

/* --- Pressed Leaves --- */
.pressed-leaf {
    position: absolute;
    bottom: 8px;
    right: 12px;
    pointer-events: none;
    transition: opacity 300ms ease-out;
}

.masonry-card:hover .pressed-leaf {
    opacity: 0.35 !important;
}

/* --- Wax Seals --- */
.wax-seal {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--deep-burgundy);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.3),
        0 2px 4px rgba(43, 10, 18, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 700;
    color: rgba(196, 150, 58, 0.6);
    line-height: 1;
}

/* --- Quill Dividers --- */
.quill-divider {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    margin: clamp(16px, 3vw, 40px) auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.divider-line {
    width: 100%;
    height: 20px;
}

.divider-ornament {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--aged-vellum);
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ornament-shape {
    display: block;
}

.morph-path {
    transition: d 300ms ease;
}

/* --- Logic Gate Ornaments (decorative bullets) --- */
.logic-gate {
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}

/* --- SVG Filter Container --- */
#paper-filter {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

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

::-webkit-scrollbar-track {
    background: var(--aged-vellum);
}

::-webkit-scrollbar-thumb {
    background: var(--foxed-parchment);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--faded-sage);
}

/* --- Selection --- */
::selection {
    background: rgba(74, 14, 27, 0.15);
    color: var(--ink-shadow);
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hero-chevron.visible {
        animation: none;
        opacity: 0.7;
    }

    .masonry-card {
        opacity: 1;
        transform: rotate(var(--card-tilt, 0deg)) translateY(0);
    }

    .card-pin {
        opacity: 1;
    }
}

/* --- Responsive Adjustments --- */
@media (max-width: 560px) {
    #main-nav {
        top: 16px;
        left: 16px;
    }

    .masonry-section {
        padding: 24px 16px;
    }

    .masonry-card {
        transform: rotate(0deg);
    }

    .masonry-card:hover {
        transform: translateY(-3px);
    }

    .masonry-card.revealed {
        transform: translateY(0);
    }
}
