/* ============================================
   aiice.quest - Light Academia Reading Room
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Colors from DESIGN.md */
    --aged-parchment: #FCF8F1;
    --warm-linen: #F5EDE0;
    --scholarly-ink: #2C2420;
    --faded-notation: #6B5E52;
    --dusty-rose: #C4A28A;
    --pressed-lavender: #B8A9C9;
    --sage-leaf: #A8B5A0;
    --amber-inkwell: #D4A853;
    --whisper-grey: #E2DCD4;

    /* Typography scale (modular 1.25, base 8px) */
    --base-unit: 8px;
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-annotation: 'Caveat', cursive;
    --font-smallcaps: 'Cormorant Garamond', Georgia, serif;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    scroll-snap-type: y proximity;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.125rem);
    line-height: 1.75;
    color: var(--scholarly-ink);
    background-color: var(--aged-parchment);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Paper Grain Texture Overlay --- */
.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.02;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
}

/* --- Header --- */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 clamp(16px, 3vw, 48px);
    background: rgba(252, 248, 241, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--whisper-grey);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.site-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.header-title {
    font-family: var(--font-smallcaps);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-variant: small-caps;
    color: var(--scholarly-ink);
}

.header-nav {
    display: flex;
    gap: 24px;
}

.nav-link {
    font-family: var(--font-smallcaps);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-variant: small-caps;
    color: var(--faded-notation);
    text-decoration: none;
    transition: letter-spacing 0.25s ease, color 0.25s ease;
    position: relative;
}

.nav-link::after {
    display: none;
}

.nav-link:hover {
    letter-spacing: 0.25em;
    color: var(--dusty-rose);
}

.nav-link:visited {
    color: var(--amber-inkwell);
}

/* --- Section Base --- */
.section {
    scroll-snap-align: start;
    scroll-snap-stop: normal;
}

/* --- Opening Section --- */
.section-opening {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 48px 24px;
    text-align: center;
}

.opening-content {
    max-width: 700px;
    opacity: 0;
}

.opening-content.animate-in {
    opacity: 1;
}

.opening-content.animate-in .opening-title {
    animation: inkFadeIn 1.2s ease-out forwards;
}

.opening-content.animate-in .opening-subtitle {
    animation: inkFadeIn 1.0s ease-out 0.4s forwards;
    opacity: 0;
}

.opening-content.animate-in .opening-ornament {
    animation: inkFadeIn 0.8s ease-out 0.8s forwards;
    opacity: 0;
}

@keyframes inkFadeIn {
    from {
        opacity: 0;
        filter: blur(4px);
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

.opening-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.8rem);
    letter-spacing: -0.02em;
    color: var(--scholarly-ink);
    margin-bottom: calc(var(--base-unit) * 3);
    opacity: 0;
}

.opening-subtitle {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    letter-spacing: 0.01em;
    color: var(--faded-notation);
    margin-bottom: calc(var(--base-unit) * 4);
    line-height: 1.6;
}

.opening-ornament {
    width: 300px;
    max-width: 80%;
    height: 40px;
    margin: 0 auto;
    display: block;
}

.opening-ornament .flowing-curve {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}

.opening-content.animate-in .opening-ornament .flowing-curve {
    animation: drawCurve 2s ease-out 1.0s forwards;
}

@keyframes drawCurve {
    to {
        stroke-dashoffset: 0;
    }
}

/* --- Slide-in animations for sidebar/main layout --- */
@keyframes slideFromLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideFromBelow {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Development Section: Sidebar Layout --- */
.section-development {
    min-height: 200vh;
    padding-top: 80px;
}

.layout-container {
    display: grid;
    grid-template-columns: 28% 10% 62%;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100%;
}

/* --- Sidebar --- */
.sidebar {
    position: relative;
    background-color: var(--warm-linen);
    padding: calc(var(--base-unit) * 4) calc(var(--base-unit) * 3);
    clip-path: polygon(0 0, 95% 0, 100% 2%, 98% 5%, 100% 8%, 97% 12%, 100% 16%, 98% 20%, 100% 24%, 97% 28%, 100% 32%, 98% 36%, 100% 40%, 97% 44%, 100% 48%, 98% 52%, 100% 56%, 97% 60%, 100% 64%, 98% 68%, 100% 72%, 97% 76%, 100% 80%, 98% 84%, 100% 88%, 97% 92%, 100% 96%, 98% 100%, 0 100%);
}

.sidebar--narrow {
    grid-column: 1;
}

.sidebar-inner {
    position: sticky;
    top: 80px;
    display: flex;
    flex-direction: column;
    gap: calc(var(--base-unit) * 4);
}

/* --- Annotation Cards --- */
.annotation-card {
    background: rgba(252, 248, 241, 0.6);
    border-left: 2px solid var(--dusty-rose);
    padding: calc(var(--base-unit) * 2) calc(var(--base-unit) * 2);
    border-radius: 2px;
    transition: box-shadow 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    transform: translateX(-20px);
    will-change: transform, opacity;
}

.annotation-card.visible {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.annotation-card:hover {
    box-shadow: 0 4px 20px rgba(196, 162, 138, 0.15);
    transform: translateY(-2px) scale(1.02);
}

.annotation-card:hover .annotation-text {
    transform: scale(0.98);
}

.annotation-text {
    font-family: var(--font-annotation);
    font-weight: 400;
    font-size: clamp(0.9rem, 1.1vw, 1.05rem);
    color: var(--faded-notation);
    line-height: 1.5;
    margin-bottom: calc(var(--base-unit) * 1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.annotation-ref {
    font-family: var(--font-smallcaps);
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--dusty-rose);
    display: block;
}

.elliptical-cluster {
    width: 100px;
    height: 60px;
    margin-bottom: calc(var(--base-unit) * 1);
}

.elliptical-cluster svg {
    width: 100%;
    height: 100%;
}

/* --- Sidebar Pull Quote --- */
.sidebar-pullquote {
    padding: calc(var(--base-unit) * 2) 0;
    opacity: 0;
    transform: translateX(-20px);
    will-change: transform, opacity;
}

.sidebar-pullquote.visible {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.sidebar-pullquote blockquote {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1rem, 1.4vw, 1.2rem);
    letter-spacing: 0.01em;
    color: var(--scholarly-ink);
    line-height: 1.55;
    border-left: 3px solid var(--pressed-lavender);
    padding-left: calc(var(--base-unit) * 2);
}

/* --- Gutter --- */
.gutter {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    padding: calc(var(--base-unit) * 8) 0;
    overflow: hidden;
}

.gutter-ornament {
    width: 20px;
    height: 200px;
    opacity: 0;
    will-change: opacity;
}

.gutter-ornament.visible {
    opacity: 1;
    transition: opacity 1s ease;
}

.gutter-ornament .flowing-curve {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
}

.gutter-ornament.visible .flowing-curve {
    animation: drawCurve 2.5s ease-out forwards;
}

/* --- Main Content --- */
.main-content {
    max-width: 680px;
    padding: calc(var(--base-unit) * 4) calc(var(--base-unit) * 4);
}

.main-content--wide {
    max-width: 780px;
}

/* --- Chapter Styling --- */
.chapter {
    margin-bottom: calc(var(--base-unit) * 8);
}

.chapter--culmination p {
    font-size: clamp(1.05rem, 1.25vw, 1.15rem);
}

.chapter-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.6rem, 3vw, 2.8rem);
    letter-spacing: -0.02em;
    color: var(--scholarly-ink);
    margin-bottom: calc(var(--base-unit) * 2);
    padding-top: calc(var(--base-unit) * 4);
    opacity: 0;
    transform: translateX(30px);
    will-change: transform, opacity;
}

.chapter-heading.visible {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}

.chapter p {
    margin-bottom: 1.5em;
    color: var(--scholarly-ink);
}

.chapter p em {
    font-style: italic;
    font-weight: 600;
}

/* --- Pull Quotes (Main Column) --- */
.pullquote-block {
    margin: calc(var(--base-unit) * 4) 0;
    padding: calc(var(--base-unit) * 3) 0;
}

.pullquote {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.2rem, 2.2vw, 1.8rem);
    letter-spacing: 0.01em;
    color: var(--scholarly-ink);
    line-height: 1.5;
    border-left: 3px solid var(--pressed-lavender);
    padding-left: calc(var(--base-unit) * 3);
    position: relative;
}

/* --- Wavy Dividers --- */
.wavy-divider {
    width: 100%;
    height: 20px;
    margin: calc(var(--base-unit) * 4) 0;
    display: block;
}

/* --- Dot Constellations --- */
.dot-constellation {
    margin: calc(var(--base-unit) * 3) 0;
    text-align: center;
}

.dot-constellation svg {
    width: 200px;
    max-width: 80%;
    height: 40px;
}

.dot-constellation--final svg {
    width: 300px;
}

.constellation-dot {
    opacity: 0;
    will-change: opacity;
}

.dot-constellation.visible .constellation-dot {
    animation: dotFadeIn 0.4s ease-out forwards;
}

.dot-constellation.visible .constellation-dot[data-delay="0"] { animation-delay: 0ms; }
.dot-constellation.visible .constellation-dot[data-delay="1"] { animation-delay: 50ms; }
.dot-constellation.visible .constellation-dot[data-delay="2"] { animation-delay: 100ms; }
.dot-constellation.visible .constellation-dot[data-delay="3"] { animation-delay: 150ms; }
.dot-constellation.visible .constellation-dot[data-delay="4"] { animation-delay: 200ms; }
.dot-constellation.visible .constellation-dot[data-delay="5"] { animation-delay: 250ms; }
.dot-constellation.visible .constellation-dot[data-delay="6"] { animation-delay: 300ms; }

@keyframes dotFadeIn {
    from {
        opacity: 0;
        transform: scale(0);
    }
    to {
        opacity: 0.25;
        transform: scale(1);
    }
}

/* --- Links --- */
a {
    color: var(--dusty-rose);
    text-decoration: none;
    position: relative;
    transition: color 0.25s ease;
}

a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 1.5px;
    background: var(--dusty-rose);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

a:hover::after {
    transform: scaleX(1);
}

a:hover {
    color: var(--pressed-lavender);
}

a:visited {
    color: var(--amber-inkwell);
}

/* --- Interlude Section --- */
.section-interlude {
    min-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--base-unit) * 8) 24px;
    background: linear-gradient(
        180deg,
        var(--aged-parchment) 0%,
        var(--warm-linen) 40%,
        rgba(184, 169, 201, 0.08) 70%,
        var(--warm-linen) 100%
    );
    position: relative;
    overflow: hidden;
}

.interlude-content {
    position: relative;
    max-width: 700px;
    text-align: center;
    z-index: 1;
}

.interlude-shapes {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    height: 300px;
    pointer-events: none;
}

.interlude-ellipse {
    position: absolute;
    width: 200px;
    height: 140px;
}

.interlude-ellipse-1 {
    top: 20%;
    left: 10%;
    will-change: transform;
}

.interlude-ellipse-2 {
    top: 30%;
    right: 10%;
    will-change: transform;
}

.interlude-quote {
    font-family: var(--font-display);
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.3rem, 2.5vw, 2rem);
    letter-spacing: 0.01em;
    color: var(--scholarly-ink);
    line-height: 1.55;
    position: relative;
    z-index: 2;
    opacity: 0;
    will-change: opacity;
}

.interlude-quote.visible {
    opacity: 1;
    transition: opacity 1.2s ease-out;
}

/* --- Culmination Section --- */
.section-culmination {
    min-height: 100vh;
    padding-top: 80px;
    padding-bottom: calc(var(--base-unit) * 8);
}

.layout-container--wide {
    grid-template-columns: 20% 8% 72%;
}

/* --- Colophon / Footer --- */
.colophon {
    margin-top: calc(var(--base-unit) * 8);
    padding-top: calc(var(--base-unit) * 4);
}

.colophon-text {
    font-family: var(--font-smallcaps);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-variant: small-caps;
    color: var(--faded-notation);
    text-align: center;
    margin-top: calc(var(--base-unit) * 3);
}

/* ============================================
   Responsive: Mobile < 768px
   ============================================ */
@media (max-width: 768px) {
    .site-header {
        padding: 0 16px;
    }

    .header-nav {
        gap: 12px;
    }

    .nav-link {
        font-size: 0.75rem;
    }

    .layout-container,
    .layout-container--wide {
        display: block;
    }

    .sidebar,
    .sidebar--narrow {
        clip-path: none;
        background: transparent;
        padding: 0 16px;
        margin-bottom: calc(var(--base-unit) * 4);
    }

    .sidebar-inner {
        position: relative;
        top: 0;
    }

    .annotation-card {
        background: var(--warm-linen);
        margin-left: 16px;
        border-left: 3px solid var(--dusty-rose);
        padding: 12px 16px;
        margin-bottom: 16px;
        opacity: 1;
        transform: none;
    }

    .sidebar-pullquote {
        opacity: 1;
        transform: none;
        margin-left: 16px;
    }

    .gutter {
        display: none;
    }

    .main-content,
    .main-content--wide {
        padding: 0 16px;
        max-width: 100%;
    }

    .chapter-heading {
        opacity: 1;
        transform: none;
    }

    .section-development {
        padding-top: 60px;
    }

    .section-culmination {
        padding-top: 60px;
    }

    .interlude-shapes {
        width: 250px;
        height: 180px;
    }

    .interlude-ellipse {
        width: 140px;
        height: 100px;
    }
}

/* ============================================
   Responsive: Small mobile < 480px
   ============================================ */
@media (max-width: 480px) {
    .header-nav {
        gap: 8px;
    }

    .nav-link {
        font-size: 0.7rem;
        letter-spacing: 0.1em;
    }

    .opening-title {
        font-size: clamp(1.4rem, 5vw, 1.8rem);
    }

    .opening-subtitle {
        font-size: clamp(0.95rem, 3.5vw, 1.2rem);
    }

    .pullquote {
        font-size: clamp(1rem, 3.5vw, 1.3rem);
    }

    .interlude-quote {
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }

    .interlude-shapes {
        width: 180px;
        height: 130px;
    }
}

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

    .opening-title,
    .opening-subtitle,
    .opening-ornament,
    .chapter-heading,
    .annotation-card,
    .sidebar-pullquote,
    .gutter-ornament,
    .interlude-quote {
        opacity: 1 !important;
        transform: none !important;
    }

    .constellation-dot {
        opacity: 0.25 !important;
    }

    .opening-ornament .flowing-curve,
    .gutter-ornament .flowing-curve {
        stroke-dashoffset: 0 !important;
    }
}
