/* =============================================================
   xbom.wiki — Surreal Dreamscape Archive of Frozen Detonations
   Palette: Ash, Ember, and Vellum
   ============================================================= */

:root {
    --vellum: #f2ebdc;
    --vellum-shadow: #e3d8be;
    --pale-ghost: #faf6ee;
    --deep-ink: #1f1912;
    --midnight: #2d2822;
    --midnight-alt: #2d2822;
    --burgundy: #6a1e1a;
    --copper: #b7722d;
    --ash: #8b847a;

    --serif-display: 'Cormorant Garamond', 'Lora', Georgia, serif;
    --serif-body: 'EB Garamond', 'Cormorant Garamond', 'Lora', Georgia, serif;
    --mono: 'JetBrains Mono', 'Space Mono', 'Courier New', monospace;

    --ease: cubic-bezier(0.33, 1, 0.68, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--vellum);
    color: var(--deep-ink);
    font-family: var(--serif-body);
    font-size: 1.15rem;
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
    cursor: none;
}

/* Paper noise overlay */
.paper-noise {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
    opacity: 0.08;
    mix-blend-mode: multiply;
}

/* Ink-drop cursor companion */
.cursor-companion {
    position: fixed;
    top: 0;
    left: 0;
    width: 16px;
    height: 16px;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    transition: opacity 400ms var(--ease);
    mix-blend-mode: multiply;
}

/* Scroll progress on right margin */
.scroll-progress {
    position: fixed;
    top: 0;
    right: 2vw;
    width: 24px;
    height: 100vh;
    pointer-events: none;
    z-index: 50;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

.scroll-progress svg {
    width: 100%;
    height: 100%;
}

.progress-nodes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.progress-node {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--vellum);
    border: 1px solid var(--ash);
    transition: all 400ms var(--ease);
}

.progress-node.active {
    background: var(--copper);
    border-color: var(--burgundy);
    box-shadow: 0 0 0 3px var(--vellum), 0 0 0 4px var(--copper);
}

/* =============================================================
   LAYOUT — The Archive
   ============================================================= */

.archive {
    position: relative;
    z-index: 2;
    padding: 0 0 8vh 0;
    max-width: 100vw;
    overflow-x: hidden;
}

.act {
    position: relative;
    padding: 8vh 6vw;
}

/* =============================================================
   ACT I — THRESHOLD
   ============================================================= */

.threshold {
    min-height: 110vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 14vh;
    padding-left: 14vw;
    padding-right: 14vw;
}

.threshold-stage {
    position: relative;
    max-width: 60ch;
    margin-top: 6vh;
}

.illuminated-letter {
    position: relative;
    width: 320px;
    height: 320px;
    margin-bottom: 2.5rem;
}

.filigree-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.filigree-path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawFiligree 1.8s var(--ease) forwards;
}

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

.letter-x {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--serif-display);
    font-style: italic;
    font-weight: 500;
    font-size: 12rem;
    color: var(--burgundy);
    line-height: 1;
    letter-spacing: -0.04em;
    opacity: 0;
    animation: fadeIn 1.8s 0.8s var(--ease) forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.threshold-subtitle {
    font-family: var(--serif-body);
    font-style: italic;
    font-size: 1.1rem;
    color: var(--deep-ink);
    opacity: 0;
    animation: fadeIn 1.4s 1.4s var(--ease) forwards;
}

.threshold-underline {
    width: 120px;
    height: 1px;
    background: var(--copper);
    margin-top: 0.8rem;
    margin-bottom: 1.6rem;
    transform: scaleX(0);
    transform-origin: left;
    animation: drawLine 1.2s 1.8s var(--ease) forwards;
}

@keyframes drawLine {
    to { transform: scaleX(1); }
}

.threshold-curator {
    font-family: var(--mono);
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    color: var(--ash);
    opacity: 0;
    animation: fadeIn 1.4s 2.2s var(--ease) forwards;
}

/* =============================================================
   DEBRIS — floating tiny shapes
   ============================================================= */

.debris-layer, .interplate-debris {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}

.interplate-debris {
    position: relative;
    height: 18vh;
    width: 100%;
    pointer-events: none;
}

.debris {
    position: absolute;
    width: 40px;
    height: 40px;
    opacity: 0.55;
    will-change: transform;
}

.debris.feather { width: 28px; height: 60px; }
.debris.ember { width: 24px; height: 24px; }
.debris.shard { width: 32px; height: 32px; }
.debris.mothwing { width: 32px; height: 32px; }
.debris.quicksilver { width: 18px; height: 26px; }

/* =============================================================
   ACT II — INDEX CARD CATALOG
   ============================================================= */

.index-catalog {
    min-height: 80vh;
    padding: 10vh 6vw 6vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.catalog-epigraph {
    font-family: var(--serif-body);
    font-style: italic;
    color: var(--ash);
    font-size: 1rem;
    margin-bottom: 4rem;
    text-align: center;
}

.card-arc {
    display: flex;
    gap: 1.2rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    max-width: 1200px;
}

.index-card {
    width: 180px;
    height: 180px;
    background: var(--pale-ghost);
    border: 1px solid var(--burgundy);
    transform: rotate(var(--rot));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.8rem;
    cursor: none;
    position: relative;
    transition: transform 400ms var(--ease), border-color 400ms var(--ease), box-shadow 400ms var(--ease);
    font-family: inherit;
    color: inherit;
}

.index-card::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--burgundy);
    border-radius: 50%;
    box-shadow: 0 -3px 0 -1px var(--copper);
}

.index-card:hover {
    transform: rotate(var(--rot)) translateY(-8px);
    border-color: var(--copper);
    box-shadow: 0 10px 24px -12px rgba(31, 25, 18, 0.35);
}

.index-card svg {
    width: 110px;
    height: 110px;
    flex: 0 0 auto;
}

.card-label {
    font-family: var(--mono);
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    color: var(--burgundy);
    margin-top: 0.4rem;
    text-transform: uppercase;
}

/* =============================================================
   SPECIMEN PLATES
   ============================================================= */

.plate {
    position: relative;
    padding: 10vh 4vw;
    margin: 6vh auto;
    width: 100%;
    display: flex;
    justify-content: center;
    transition: filter 700ms var(--ease), opacity 700ms var(--ease);
}

.plate.far {
    filter: blur(1.5px) saturate(0.85);
    opacity: 0.85;
}

.plate-paper {
    width: 82vw;
    max-width: 1280px;
    background: var(--pale-ghost);
    border: 1px solid var(--burgundy);
    padding: 4rem 4.5rem;
    position: relative;
    box-shadow:
        0 20px 50px -30px rgba(31, 25, 18, 0.25),
        0 4px 12px -6px rgba(31, 25, 18, 0.1);
}

.plate-paper::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid var(--vellum-shadow);
    pointer-events: none;
}

.plate-paper::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at top, transparent 70%, rgba(227, 216, 190, 0.25) 100%);
    pointer-events: none;
}

.plate-paper.night {
    background: var(--midnight);
    border-color: var(--copper);
    color: var(--vellum-shadow);
}

.plate-paper.night::before {
    border-color: var(--burgundy);
}

/* Diagonal rotations per plate */
.plate-1 .plate-paper { transform: rotate(3deg); }
.plate-2 .plate-paper { transform: rotate(5deg); }
.plate-3 .plate-paper { transform: rotate(-4deg); }
.plate-4 .plate-paper { transform: rotate(6deg); }
.plate-5 .plate-paper { transform: rotate(-3deg); }
.plate-6 .plate-paper { transform: rotate(5deg); }
.plate-7 .plate-paper { transform: rotate(-6deg); }

/* reverse — tone down rotation against natural reading flow */

.plate-inner {
    display: grid;
    grid-template-columns: 38% 62%;
    gap: 3rem;
    align-items: start;
    position: relative;
    z-index: 2;
}

.plate-inner.reverse {
    grid-template-columns: 62% 38%;
}

.plate-inner.reverse .specimen-column {
    order: 2;
}

.plate-inner.reverse .text-column {
    order: 1;
}

.specimen-column {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.specimen-frame {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid var(--burgundy);
    background: var(--vellum);
    padding: 1.2rem;
    position: relative;
    max-width: 400px;
}

.plate-paper.night .specimen-frame {
    background: var(--midnight);
    border-color: var(--copper);
}

.specimen-frame::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px dashed var(--vellum-shadow);
    pointer-events: none;
    opacity: 0.6;
}

.specimen-sketch {
    width: 100%;
    height: 100%;
    display: block;
}

.specimen-caption {
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ash);
    margin-top: 0.9rem;
    text-align: center;
    max-width: 360px;
}

.text-column {
    padding-top: 1rem;
}

.text-column.night {
    color: var(--vellum-shadow);
}

.entry-meta {
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ash);
    margin-bottom: 1.4rem;
    position: relative;
    padding-left: 1rem;
}

.entry-meta::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 0.5rem;
    height: 1px;
    background: var(--copper);
}

.entry-title {
    font-family: var(--serif-display);
    font-weight: 500;
    font-size: clamp(2.8rem, 6.5vw, 5.2rem);
    line-height: 0.98;
    letter-spacing: -0.015em;
    color: var(--burgundy);
    margin-bottom: 0.4rem;
}

.plate-paper.night .entry-title {
    color: var(--copper);
}

.dropcap {
    display: inline-block;
    font-family: var(--serif-display);
    font-style: italic;
    font-weight: 700;
    font-size: 1.4em;
    line-height: 1;
    color: var(--burgundy);
    margin-right: 0.12em;
}

.plate-paper.night .dropcap {
    color: var(--copper);
}

.entry-latin {
    font-family: var(--serif-display);
    font-style: italic;
    font-size: 1.35rem;
    color: var(--ash);
    margin-bottom: 2rem;
    letter-spacing: 0.01em;
}

.entry-body {
    font-family: var(--serif-body);
    font-size: 1.15rem;
    line-height: 1.75;
    max-width: 58ch;
    color: var(--deep-ink);
    margin-bottom: 2rem;
}

.text-column.night .entry-body {
    color: var(--vellum-shadow);
}

.marginalia {
    font-family: var(--serif-body);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ash);
    padding-top: 1rem;
    border-top: 1px dashed var(--vellum-shadow);
    max-width: 58ch;
}

.marginalia a {
    color: var(--burgundy);
    text-decoration: none;
    background-image: linear-gradient(to right, var(--burgundy), var(--burgundy));
    background-size: 0% 1px;
    background-repeat: no-repeat;
    background-position: left bottom;
    transition: background-size 500ms var(--ease);
    padding-bottom: 2px;
}

.marginalia a:hover {
    background-size: 100% 1px;
}

.plate-paper.night .marginalia {
    color: var(--vellum-shadow);
    border-top-color: var(--ash);
}

.plate-paper.night .marginalia a {
    color: var(--copper);
    background-image: linear-gradient(to right, var(--copper), var(--copper));
}

/* =============================================================
   SVG PATH-DRAW ANIMATION
   ============================================================= */

.specimen-sketch .draw-path,
.specimen-sketch .draw-path * {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

.plate.in-view .specimen-sketch .draw-path,
.plate.in-view .specimen-sketch .draw-path * {
    animation: drawSpecimen 2s var(--ease) forwards;
}

.plate.in-view .specimen-sketch .draw-path:nth-child(2),
.plate.in-view .specimen-sketch .draw-path:nth-child(2) * {
    animation-delay: 0.4s;
}

.plate.in-view .specimen-sketch .draw-path:nth-child(3),
.plate.in-view .specimen-sketch .draw-path:nth-child(3) * {
    animation-delay: 0.8s;
}

.plate.in-view .specimen-sketch .draw-path:nth-child(4),
.plate.in-view .specimen-sketch .draw-path:nth-child(4) * {
    animation-delay: 1.2s;
}

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

.plate .text-column {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1s 0.4s var(--ease), transform 1s 0.4s var(--ease);
}

.plate.in-view .text-column {
    opacity: 1;
    transform: translateY(0);
}

/* =============================================================
   ACT X — VISITOR'S SPECIMEN
   ============================================================= */

.visitor-specimen {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10vh 6vw;
}

.visitor-intro {
    max-width: 60ch;
    text-align: center;
    margin-bottom: 3rem;
}

.visitor-epigraph {
    font-family: var(--serif-body);
    font-style: italic;
    color: var(--ash);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

.visitor-title {
    font-family: var(--serif-display);
    font-weight: 500;
    font-style: italic;
    font-size: clamp(2rem, 4vw, 3.2rem);
    color: var(--burgundy);
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}

.visitor-note {
    font-family: var(--serif-body);
    font-style: italic;
    color: var(--ash);
    font-size: 1rem;
}

.canvas-frame {
    position: relative;
    padding: 1.2rem;
    background: var(--pale-ghost);
    border: 1px solid var(--burgundy);
    max-width: 920px;
    width: 95%;
}

.canvas-frame::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px dashed var(--vellum-shadow);
    pointer-events: none;
}

#visitorCanvas {
    display: block;
    width: 100%;
    height: auto;
    background: var(--vellum);
    cursor: none;
}

.canvas-caption {
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ash);
    margin-top: 1rem;
    text-align: center;
}

/* =============================================================
   ACT XI — COLOPHON
   ============================================================= */

.colophon {
    min-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10vh 8vw;
}

.colophon-block {
    max-width: 62ch;
    text-align: center;
    font-family: var(--serif-body);
}

.colophon-text {
    font-style: italic;
    font-size: 1.15rem;
    line-height: 1.85;
    color: var(--deep-ink);
    margin-bottom: 2.5rem;
}

.colophon-signoff {
    font-style: italic;
    font-family: var(--serif-display);
    font-size: 1.3rem;
    color: var(--burgundy);
    margin-bottom: 2rem;
    letter-spacing: 0.02em;
}

.burst-signature {
    width: 80px;
    height: 80px;
    margin: 1rem auto;
    display: block;
}

.colophon-end {
    font-family: var(--serif-display);
    font-style: italic;
    color: var(--ash);
    font-size: 1rem;
    letter-spacing: 0.3em;
    margin-top: 1.5rem;
    text-transform: lowercase;
}

/* =============================================================
   RESPONSIVE
   ============================================================= */

@media (max-width: 900px) {
    body { cursor: auto; font-size: 1.05rem; }
    .cursor-companion { display: none; }

    .scroll-progress { display: none; }

    .threshold {
        padding-left: 6vw;
        padding-right: 6vw;
    }

    .illuminated-letter {
        width: 220px;
        height: 220px;
    }

    .letter-x {
        font-size: 8rem;
    }

    .plate-paper {
        padding: 2.5rem 2rem;
        width: 92vw;
    }

    .plate-1 .plate-paper,
    .plate-2 .plate-paper,
    .plate-3 .plate-paper,
    .plate-4 .plate-paper,
    .plate-5 .plate-paper,
    .plate-6 .plate-paper,
    .plate-7 .plate-paper {
        transform: none;
    }

    .plate-inner,
    .plate-inner.reverse {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .plate-inner.reverse .specimen-column {
        order: 1;
    }

    .plate-inner.reverse .text-column {
        order: 2;
    }

    .card-arc {
        gap: 0.8rem;
    }

    .index-card {
        width: 130px;
        height: 130px;
    }

    .index-card svg {
        width: 80px;
        height: 80px;
    }

    .entry-title {
        font-size: clamp(2.2rem, 7vw, 3.4rem);
    }

    #visitorCanvas {
        height: 360px;
    }
}

@media (max-width: 500px) {
    .card-arc {
        flex-direction: row;
        overflow-x: auto;
        justify-content: flex-start;
        padding: 1rem;
        scroll-snap-type: x mandatory;
    }

    .index-card {
        flex: 0 0 auto;
        scroll-snap-align: center;
    }
}
