/* =========================================================================
   monopole.ai — Dark-Academia Algorithmic Library
   Palette (from DESIGN.md):
     #0D0B08  Obsidian Vellum     (deep ground)
     #1A1612  Charred Oak         (card surface)
     #2A241E  Smoked Parchment    (elevated surface)
     #1A1410  Shadow / overlay
     #C4A468  Oxidized Brass      (primary accent)
     #4A5B7A  Iron Gall Blue      (secondary accent)
     #D8D0C4  Aged Linen          (text primary)
     #8A7E6B  Tarnished Brass     (metadata)
     #9E8A5A  Theorem Gold        (diagram lines)
     #8B3A3A  Sealing Wax         (alert / pulse)
   Fonts: Libre Baskerville (italic display), Inter, JetBrains Mono, Space Grotesk
   ========================================================================= */

:root {
    --c-ground:        #0D0B08;
    --c-ground-2:      #0D0B08;
    --c-surface:       #1A1612;
    --c-surface-elev:  #2A241E;
    --c-shadow:        #1A1410;
    --c-brass:         #C4A468;
    --c-blue:          #4A5B7A;
    --c-linen:         #D8D0C4;
    --c-tarnish:       #8A7E6B;
    --c-theorem:       #9E8A5A;
    --c-wax:           #8B3A3A;

    --font-display:    'Libre Baskerville', 'Lora', Georgia, serif;
    --font-body:       'Inter', system-ui, sans-serif;
    --font-mono:       'JetBrains Mono', 'Menlo', monospace;
    --font-grotesk:    'Space Grotesk', 'Inter', sans-serif;

    --rail-w: 2px;
    --ease-scholar: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

html, body {
    background: var(--c-ground);
    color: var(--c-linen);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

body {
    /* Subtle vellum grain — radial of warm dust */
    background-color: var(--c-ground);
    background-image:
        radial-gradient(ellipse at 20% 10%, rgba(196, 164, 104, 0.018) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 80%, rgba(74, 91, 122, 0.015) 0%, transparent 60%),
        radial-gradient(circle at 50% 50%, rgba(196, 164, 104, 0.008) 0%, transparent 70%);
    min-height: 100vh;
    position: relative;
}

/* The Reading-Room aged paper texture, applied via main */
main {
    position: relative;
    z-index: 1;
}

/* =========================================================================
   GENERATIVE BACKGROUND LAYERS
   ========================================================================= */

.voronoi-bg {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.04;
    transition: opacity 1200ms var(--ease-scholar);
}

body.contemplating .voronoi-bg {
    opacity: 0.07;
}

.euler-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0.05;
    transition: opacity 800ms var(--ease-scholar);
}

body.contemplating .euler-bg {
    opacity: 0.10;
}

/* =========================================================================
   PROGRESS RAIL — the thin vertical scroll-position indicator
   ========================================================================= */

.progress-rail {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--rail-w);
    background: rgba(196, 164, 104, 0.08);
    z-index: 80;
    pointer-events: none;
}

.progress-bar {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 0%;
    background: var(--c-brass);
    box-shadow: 0 0 8px rgba(196, 164, 104, 0.35);
    transition: height 80ms linear;
}

/* =========================================================================
   MONOGRAM — appears after threshold
   ========================================================================= */

.monogram {
    position: fixed;
    top: 28px;
    left: 36px;
    z-index: 90;
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.65rem;
    color: var(--c-brass);
    text-decoration: none;
    letter-spacing: 0.04em;
    line-height: 1;
    padding: 6px 10px;
    border: 1px solid rgba(196, 164, 104, 0.22);
    background: rgba(13, 11, 8, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 600ms var(--ease-scholar), transform 600ms var(--ease-scholar);
    pointer-events: none;
}

body.past-threshold .monogram {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.monogram:hover {
    color: var(--c-linen);
    border-color: rgba(196, 164, 104, 0.5);
}

/* =========================================================================
   WATERMARK CANVAS — miniature monopole upper-left after threshold
   ========================================================================= */

.watermark-canvas {
    position: fixed;
    top: 70px;
    left: 18px;
    width: 130px;
    height: 130px;
    z-index: 70;
    opacity: 0;
    pointer-events: none;
    transition: opacity 900ms var(--ease-scholar);
}

body.past-threshold .watermark-canvas {
    opacity: 0.55;
}

/* =========================================================================
   SCENE BASE
   ========================================================================= */

.scene {
    position: relative;
    width: 100%;
    z-index: 2;
}

/* =========================================================================
   SCENE 1 — THRESHOLD / EMANATION
   ========================================================================= */

.threshold {
    height: 100vh;
    min-height: 720px;
    background: var(--c-ground);
    overflow: hidden;
}

.emanation-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.threshold-content {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    z-index: 2;
    pointer-events: none;
    text-align: center;
}

.threshold-eyebrow {
    font-family: var(--font-grotesk);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--c-tarnish);
    margin-bottom: 28px;
    opacity: 0;
    animation: fadeUp 1400ms var(--ease-scholar) 1800ms forwards;
}

.threshold-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    letter-spacing: 0.04em;
    color: var(--c-linen);
    line-height: 1.1;
    margin-bottom: 22px;
    opacity: 0;
    animation: fadeUp 1600ms var(--ease-scholar) 2000ms forwards;
    text-shadow:
        0 0 20px rgba(13, 11, 8, 0.9),
        0 0 60px rgba(13, 11, 8, 0.7);
}

.threshold-sub {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: 0.95rem;
    color: var(--c-tarnish);
    max-width: 38ch;
    margin-bottom: 56px;
    opacity: 0;
    animation: fadeUp 1600ms var(--ease-scholar) 2400ms forwards;
}

.threshold-meta {
    display: flex;
    gap: 14px;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--c-tarnish);
    letter-spacing: 0.08em;
    opacity: 0;
    animation: fadeUp 1600ms var(--ease-scholar) 2800ms forwards;
}

.meta-tag { color: var(--c-tarnish); }
.meta-dot { color: var(--c-brass); opacity: 0.6; }

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

/* =========================================================================
   SCENE 2 — EMERGENCE / EPIGRAPH
   ========================================================================= */

.emergence {
    padding: 200px 40px 120px;
    background:
        linear-gradient(to bottom, var(--c-ground) 0%, #100D0A 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.epigraph {
    max-width: 720px;
    text-align: center;
    position: relative;
    padding: 60px 30px;
}

.epigraph::before,
.epigraph::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 80px;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--c-brass), transparent);
    transform: translateX(-50%);
    opacity: 0.5;
}
.epigraph::before { top: 0; }
.epigraph::after  { bottom: 0; }

.epigraph-mark {
    font-family: var(--font-display);
    font-style: italic;
    color: var(--c-brass);
    font-size: 2rem;
    margin-bottom: 24px;
    opacity: 0.7;
}

.epigraph-text {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.6vw, 1.35rem);
    line-height: 1.75;
    color: var(--c-linen);
    margin-bottom: 28px;
    max-width: 58ch;
    margin-left: auto;
    margin-right: auto;
}

.epigraph-attr {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--c-tarnish);
    letter-spacing: 0.06em;
}

/* =========================================================================
   SCENE 3 — READING ROOM / CARD GRID
   ========================================================================= */

.reading-room {
    padding: 120px 48px 160px;
    background:
        linear-gradient(to bottom, #100D0A 0%, #121010 8%, #121010 92%, var(--c-ground) 100%),
        repeating-linear-gradient(
            45deg,
            rgba(196, 164, 104, 0.012) 0px,
            rgba(196, 164, 104, 0.012) 1px,
            transparent 1px,
            transparent 3px
        );
    position: relative;
}

.reading-room::before {
    /* faint paper-grain noise overlay */
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 30% 20%, rgba(196, 164, 104, 0.025) 0%, transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(74, 91, 122, 0.02) 0%, transparent 50%),
        radial-gradient(circle at 50% 90%, rgba(158, 138, 90, 0.02) 0%, transparent 45%);
    pointer-events: none;
    z-index: 0;
}

.room-header {
    max-width: 760px;
    margin: 0 auto 80px;
    text-align: left;
    position: relative;
    z-index: 2;
    padding-left: 18px;
    border-left: 1px solid rgba(196, 164, 104, 0.25);
}

.room-tag {
    font-family: var(--font-grotesk);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--c-brass);
    margin-bottom: 18px;
}

.room-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(1.8rem, 3.4vw, 2.8rem);
    line-height: 1.2;
    color: var(--c-linen);
    margin-bottom: 18px;
    letter-spacing: 0.02em;
}

.room-desc {
    font-family: var(--font-body);
    font-size: 0.98rem;
    color: var(--c-tarnish);
    max-width: 58ch;
    line-height: 1.7;
}

/* The grid */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-flow: dense;
    grid-auto-rows: minmax(200px, auto);
    gap: 28px;
    max-width: 1280px;
    margin: 0 auto;
    position: relative;
    z-index: 2;
}

/* Card variants */
.card-tall { grid-row: span 2; }
.card-wide { grid-column: span 2; }

@media (max-width: 880px) {
    .card-wide { grid-column: span 1; }
}

/* The card itself */
.card {
    --card-rotation: 0deg;
    position: relative;
    background: var(--c-surface);
    color: var(--c-linen);
    padding: 32px 28px 28px;
    /* irregular hand-torn edge via clip-path with deviations */
    clip-path: polygon(
        1.2% 0.6%, 22% 0.2%, 48% 1%, 73% 0.4%, 97% 1.1%, 99.6% 6%,
        99.2% 28%, 99.8% 51%, 99.4% 74%, 99.7% 95%, 96% 99.3%,
        72% 99.1%, 49% 99.7%, 25% 99%, 3% 99.5%, 0.4% 88%,
        0.7% 65%, 0.2% 42%, 0.6% 18%
    );
    transform: rotate(var(--card-rotation));
    transform-origin: center;
    transition:
        transform 320ms var(--ease-scholar),
        background-color 360ms var(--ease-scholar),
        box-shadow 320ms var(--ease-scholar);
    box-shadow: 0 2px 8px rgba(26, 20, 16, 0.3);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(196, 164, 104, 0.05);
}

/* Pulse-attention reveal animation */
.card.pulse-reveal {
    animation: pulseAttention 800ms ease-in-out forwards;
}

@keyframes pulseAttention {
    0%   { box-shadow: 0 2px 8px rgba(26, 20, 16, 0.3),
                       0 0 0 0 rgba(196, 164, 104, 0); }
    50%  { box-shadow: 0 2px 8px rgba(26, 20, 16, 0.3),
                       0 0 20px 2px rgba(196, 164, 104, 0.25); }
    100% { box-shadow: 0 2px 8px rgba(26, 20, 16, 0.3),
                       0 0 0 0 rgba(196, 164, 104, 0); }
}

/* Reveal entrance: cards drift up + fade in */
.card {
    opacity: 0;
    transform: rotate(var(--card-rotation)) translateY(24px);
}

.card[data-revealed="true"] {
    opacity: 1;
    transform: rotate(var(--card-rotation)) translateY(0);
    transition:
        opacity 600ms var(--ease-scholar),
        transform 600ms var(--ease-scholar),
        background-color 360ms var(--ease-scholar),
        box-shadow 320ms var(--ease-scholar);
}

/* Hover lift */
.card:hover {
    background: var(--c-surface-elev);
    transform: rotate(0deg) translateY(-4px) perspective(800px) translateZ(12px);
    box-shadow:
        0 8px 24px rgba(26, 20, 16, 0.55),
        0 0 0 1px rgba(196, 164, 104, 0.15);
    z-index: 5;
}

/* Contemplation-mode inner glow */
body.contemplating .card[data-revealed="true"] {
    box-shadow:
        0 2px 8px rgba(26, 20, 16, 0.3),
        inset 0 0 12px rgba(196, 164, 104, 0.04);
}

body.contemplating .card[data-revealed="true"]:hover {
    box-shadow:
        0 8px 24px rgba(26, 20, 16, 0.55),
        0 0 0 1px rgba(196, 164, 104, 0.18),
        inset 0 0 12px rgba(196, 164, 104, 0.06);
}

/* Card pin (decorative top-center brass tack) */
.card-pin {
    position: absolute;
    top: 9px;
    left: 50%;
    transform: translateX(-50%);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--c-brass);
    box-shadow:
        0 0 0 1px rgba(13, 11, 8, 0.6),
        0 2px 4px rgba(13, 11, 8, 0.6),
        inset 0 -1px 1px rgba(0, 0, 0, 0.3),
        inset 0 1px 1px rgba(255, 230, 180, 0.4);
    z-index: 3;
}

/* Card pattern svg (Penrose fragment) */
.card-pattern {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.03;
    z-index: 0;
}

body.contemplating .card-pattern {
    opacity: 0.05;
}

.card-body {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card-meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--c-tarnish);
    margin-bottom: 14px;
    text-transform: uppercase;
}

.card-title {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: clamp(1.05rem, 1.6vw, 1.3rem);
    line-height: 1.3;
    color: var(--c-linen);
    margin-bottom: 12px;
    letter-spacing: -0.005em;
}

.card-excerpt {
    font-family: var(--font-body);
    font-size: 0.92rem;
    line-height: 1.65;
    color: rgba(216, 208, 196, 0.78);
    flex-grow: 1;
}

.card-foot {
    margin-top: 22px;
    padding-top: 14px;
    border-top: 1px dashed rgba(196, 164, 104, 0.18);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-grotesk);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.card-rune {
    color: var(--c-brass);
    font-family: var(--font-display);
    font-style: italic;
    font-size: 1.15rem;
}

.card-link {
    color: var(--c-brass);
    transition: color 220ms var(--ease-scholar), letter-spacing 220ms var(--ease-scholar);
}

.card:hover .card-link {
    color: var(--c-linen);
    letter-spacing: 0.22em;
}

.room-footnote {
    max-width: 760px;
    margin: 80px auto 0;
    padding-left: 18px;
    border-left: 1px solid rgba(196, 164, 104, 0.18);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--c-tarnish);
    position: relative;
    z-index: 2;
}

.footnote-mark {
    color: var(--c-brass);
    margin-right: 6px;
}

/* =========================================================================
   SCENE 4 — ARCHIVE / CONVERGENCE
   ========================================================================= */

.archive {
    height: 100vh;
    min-height: 760px;
    padding: 80px 40px;
    background: var(--c-ground);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.convergence-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.archive-content {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 640px;
    pointer-events: none;
}

.archive-tag {
    font-family: var(--font-grotesk);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--c-tarnish);
    margin-bottom: 26px;
}

.archive-title {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2rem, 4.2vw, 3.6rem);
    line-height: 1.15;
    color: var(--c-linen);
    margin-bottom: 22px;
    letter-spacing: 0.03em;
    text-shadow:
        0 0 20px rgba(13, 11, 8, 0.85),
        0 0 60px rgba(13, 11, 8, 0.6);
}

.archive-sub {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--c-tarnish);
    margin-bottom: 56px;
    max-width: 38ch;
    margin-left: auto;
    margin-right: auto;
}

.colophon {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 520px;
    margin: 0 auto 48px;
    padding: 24px 28px;
    border-top: 1px solid rgba(196, 164, 104, 0.22);
    border-bottom: 1px solid rgba(196, 164, 104, 0.22);
    pointer-events: auto;
}

.colophon-row {
    display: flex;
    gap: 18px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    line-height: 1.6;
    text-align: left;
}

.colophon-key {
    flex: 0 0 100px;
    color: var(--c-brass);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 0.68rem;
}

.colophon-val {
    flex: 1;
    color: var(--c-linen);
    opacity: 0.78;
}

.archive-fin {
    font-family: var(--font-grotesk);
    font-weight: 300;
    font-size: 0.7rem;
    letter-spacing: 0.4em;
    color: var(--c-brass);
    text-transform: uppercase;
    opacity: 0.65;
}

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

@media (max-width: 720px) {
    .reading-room { padding: 80px 22px 100px; }
    .room-header  { margin-bottom: 48px; }
    .card         { padding: 26px 22px 22px; }
    .threshold-content { padding: 24px; }
    .archive      { padding: 60px 22px; }
    .colophon-row { flex-direction: column; gap: 2px; }
    .colophon-key { flex: 0; }
    .monogram     { font-size: 1.3rem; top: 18px; left: 18px; }
    .watermark-canvas { width: 90px; height: 90px; top: 56px; left: 12px; }
}

/* Reduced motion: disable card entrance + canvas emanation breathing
   (canvas still draws, but staggered intro is shortened).  */
@media (prefers-reduced-motion: reduce) {
    .card,
    .card[data-revealed="true"] {
        transition: none;
        opacity: 1;
        transform: rotate(var(--card-rotation));
    }
    .threshold-eyebrow,
    .threshold-title,
    .threshold-sub,
    .threshold-meta {
        animation-duration: 400ms;
        animation-delay: 0ms;
    }
}
