/* =========================================================
   PZZ.lu — The Pzz Codex
   dark-academia × dopamine-neon · card-grid grimoire ·
   eclectic-hybrid type · glitch · organic-blobs · circuit
   ========================================================= */

:root {
    --ink: #0a0612;            /* Library Ink */
    --velvet: #1a1424;         /* Lecture Hall Velvet */
    --vellum: #f3ead8;         /* Foxed Vellum */
    --neon-magenta: #ff2d92;   /* Neon Magenta Highlighter */
    --cathode-mint: #39ffd4;   /* Cathode Mint */
    --sodium-yellow: #fef156;  /* Sodium-Lamp Yellow */
    --uv-lectern: #7c3aff;     /* Ultraviolet Lectern */
    --brass: #c79b58;          /* Tarnished Brass */
    --pale-citron: #fef9c3;    /* pale citron — faint highlighter wash */
}

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

html {
    scroll-behavior: smooth;
}

body.codex {
    font-family: "EB Garamond", Georgia, serif;
    font-feature-settings: "onum";
    background:
        radial-gradient(circle at 22% 12%, rgba(124,58,255,0.10), transparent 42%),
        radial-gradient(circle at 80% 70%, rgba(57,255,212,0.06), transparent 40%),
        var(--ink);
    color: var(--vellum);
    overflow-x: hidden;
    line-height: 1.62;
    min-height: 100vh;
    position: relative;
}

/* Pre-scroll "full darkness" — lifted on first scroll */
body.codex::after {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--ink);
    z-index: 90;
    pointer-events: none;
    opacity: 0.92;
    transition: opacity 1.2s ease;
}
body.codex.lit::after {
    opacity: 0;
}

/* ---------- Cursor candle glow ---------- */
#candle-glow {
    position: fixed;
    width: 160px;
    height: 160px;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,45,146,0.18) 0%, rgba(254,241,86,0.08) 35%, transparent 70%);
    pointer-events: none;
    z-index: 80;
    mix-blend-mode: screen;
    transition: opacity 0.4s ease;
}
body.codex.lit #candle-glow { opacity: 0.7; }

/* ---------- Ex Libris stamp ---------- */
#ex-libris {
    position: absolute;
    top: 120px;
    right: 24px;
    width: 168px;
    height: 168px;
    opacity: 0.30;
    mix-blend-mode: screen;
    z-index: 5;
    pointer-events: none;
    transform: rotate(9deg);
}
#ex-libris svg { width: 100%; height: 100%; }

/* ---------- Library furniture ---------- */
#furniture {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}
.furn { position: absolute; opacity: 0.08; }
.furn-lamp   { width: 140px; top: 540px;  left: 3%; }
.furn-orrery { width: 260px; top: 1180px; right: 2%; }
.furn-books  { width: 240px; top: 1860px; left: 4%; transform: rotate(-3deg); }
.furn-tube   { width: 120px; top: 2280px; right: 8%; }

/* ---------- Library-stamp ribbon header ---------- */
.library-stamp {
    position: relative;
    z-index: 6;
    padding-bottom: 2.2rem;
}
.stamp-ribbon {
    height: 96px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 2.4rem;
    padding: 0 1.5rem;
    overflow: hidden;
    border-bottom: 2px solid rgba(199,155,88,0.45);
    border-top: 2px solid rgba(199,155,88,0.25);
    background:
        repeating-linear-gradient(135deg, rgba(199,155,88,0.05) 0 8px, transparent 8px 16px),
        var(--velvet);
    box-shadow: 0 12px 24px -16px rgba(0,0,0,0.8) inset;
}
.stamp {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--neon-magenta);
    white-space: nowrap;
    opacity: 0.62;
    flex: 0 0 auto;
    transform: rotate(-1.5deg);
}
.stamp:nth-child(even) { transform: rotate(1.2deg); color: var(--cathode-mint); opacity: 0.5; }
.stamp-box {
    border: 1.5px solid currentColor;
    padding: 4px 10px;
    border-radius: 2px;
}
.stamp-circ {
    border: 1.5px solid currentColor;
    border-radius: 999px;
    padding: 4px 14px;
}
.stamp-thumb { font-size: 1.05rem; letter-spacing: 0.1em; color: var(--brass); opacity: 0.4; }

.codex-wordmark {
    font-family: "UnifrakturCook", "Cormorant", serif;
    font-weight: 700;
    font-size: clamp(3rem, 7vw, 6rem);
    letter-spacing: -0.01em;
    line-height: 1;
    text-align: center;
    margin: 2.4rem auto 0.6rem;
    color: var(--pale-citron);
    text-shadow: 0 0 22px var(--neon-magenta), 0 0 1px var(--vellum);
    position: relative;
}
.codex-sub {
    font-family: "IM Fell English SC", "Georgia", serif;
    font-variant: small-caps;
    font-size: 1.05rem;
    letter-spacing: 0.14em;
    text-align: center;
    max-width: 720px;
    margin: 0 auto;
    color: rgba(243,234,216,0.75);
    padding: 0 1.5rem;
}

/* ---------- Full-page circuit bed ---------- */
.circuit-bed {
    position: absolute;
    top: 360px;
    left: 0;
    width: 100%;
    height: calc(100% - 360px);
    z-index: 2;
    pointer-events: none;
}
.trace {
    stroke-dasharray: 2 4;
    stroke-dashoffset: 1200;
    filter: drop-shadow(0 0 4px rgba(57,255,212,0.5));
    transition: stroke-dashoffset 0.88s linear;
}
.trace.drawn {
    stroke-dashoffset: 0;
    animation: trace-pulse 1.6s linear infinite;
}
@keyframes trace-pulse {
    0%   { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: -24; }
}
.pad { transition: filter 0.22s ease; }
.pad.flash {
    filter: drop-shadow(0 0 10px var(--neon-magenta)) drop-shadow(0 0 4px var(--neon-magenta));
}
.silk text { opacity: 0.55; }

/* ---------- Ink-spill blobs ---------- */
.ink-blobs {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    overflow: hidden;
}
.ink-blob {
    position: absolute;
    display: block;
    border-radius: 47% 53% 71% 29% / 38% 64% 36% 62%;
    background: radial-gradient(circle at 30% 20%, var(--neon-magenta) 0%, var(--uv-lectern) 45%, transparent 78%);
    filter: url(#paper-soak) blur(1px);
    mix-blend-mode: screen;
    opacity: 0.5;
    animation: blob-morph 8s ease-in-out infinite alternate;
}
@keyframes blob-morph {
    0%   { border-radius: 47% 53% 71% 29% / 38% 64% 36% 62%; }
    50%  { border-radius: 64% 36% 33% 67% / 57% 41% 59% 43%; }
    100% { border-radius: 38% 62% 58% 42% / 49% 60% 40% 51%; }
}
.ink-blob-1 { width: 320px; height: 280px; top: 480px;  left: 8%;  }
.ink-blob-2 { width: 240px; height: 260px; top: 920px;  right: 12%; animation-delay: -2s; background: radial-gradient(circle at 40% 30%, var(--cathode-mint) 0%, var(--uv-lectern) 50%, transparent 80%); }
.ink-blob-3 { width: 360px; height: 300px; top: 1480px; left: 4%;  animation-delay: -4s; }
.ink-blob-4 { width: 280px; height: 320px; top: 1900px; right: 6%; animation-delay: -1s; }
.ink-blob-5 { width: 220px; height: 240px; top: 2280px; left: 18%; animation-delay: -3s; background: radial-gradient(circle at 35% 25%, var(--neon-magenta) 0%, var(--cathode-mint) 55%, transparent 82%); }
.ink-blob-6 { width: 300px; height: 260px; top: 700px;  left: 42%; animation-delay: -5s; opacity: 0.35; }

/* ---------- Card grid (the grimoire) ---------- */
.card-grid {
    position: relative;
    z-index: 4;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 10px;
    gap: 28px 24px;
    max-width: 1200px;
    margin: 3.5rem auto 5rem;
    padding: 0 28px;
}

/* column spans */
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }

/* row spans (varied heights 180–540px range) */
.tall-sm { grid-row: span 22; }   /* ~220px */
.tall-md { grid-row: span 34; }   /* ~340px */
.tall-lg { grid-row: span 54; }   /* ~540px */

.card {
    position: relative;
    background:
        repeating-linear-gradient(0deg, rgba(10,6,18,0.02) 0 26px, rgba(10,6,18,0.05) 26px 27px),
        var(--vellum);
    color: var(--ink);
    border-radius: 3px;
    padding: 1.7rem 1.6rem 1.5rem;
    box-shadow: 0 18px 28px -12px rgba(8,7,18,0.62), 0 2px 0 rgba(255,255,255,0.04) inset;
    overflow: hidden;
    /* clip-path "unrolling" reveal — set visible by JS */
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0.54s ease;
}
.card.is-visible { clip-path: inset(0 0 0 0); }

/* every 4th card rotated, transform-origin at the visible thumbtack (top-left) */
.card[data-rotate] { transform-origin: 26px 16px; }
.card:nth-child(4n) { transform: rotate(var(--rot, 1.4deg)); }
.card--folio      { z-index: 2; }
.card--marginalia { z-index: 3; background:
        repeating-linear-gradient(90deg, rgba(124,58,255,0.03) 0 18px, transparent 18px 19px),
        var(--vellum); }

/* foxed-paper torn top edge on each card */
.card::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 14px;
    background: linear-gradient(180deg, transparent, rgba(10,6,18,0.08));
}

/* brass thumbtack */
.thumbtack {
    position: absolute;
    top: 10px;
    left: 18px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f0d49a 0%, var(--brass) 45%, #6e4e1f 100%);
    box-shadow: 0 3px 5px rgba(8,7,18,0.5), 0 0 0 2px rgba(199,155,88,0.25);
    z-index: 5;
}

.card-tag {
    display: inline-block;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.66rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--uv-lectern);
    background: rgba(124,58,255,0.10);
    border: 1px solid rgba(124,58,255,0.3);
    border-radius: 2px;
    padding: 2px 8px;
    margin: 0.2rem 0 0.9rem 1.6rem;
}

.card-title {
    font-family: "UnifrakturCook", "Cormorant", serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 2.4vw, 2.3rem);
    line-height: 1.05;
    letter-spacing: -0.01em;
    color: var(--ink);
    text-shadow: 0 0 16px rgba(255,45,146,0.45), 0 0 1px rgba(255,45,146,0.3);
    margin-bottom: 0.7rem;
    position: relative;
}
/* chromatic-aberration glitch pseudo-layers (fire on .glitch / hover) */
.card-title::before,
.card-title::after {
    content: attr(data-glitch);
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    pointer-events: none;
    opacity: 0;
    mix-blend-mode: screen;
}
.card-title::before { color: var(--neon-magenta); }
.card-title::after  { color: var(--cathode-mint); }
.card-title.glitch::before,
.card-title:hover::before { animation: glitch-r 0.38s ease-out 1; }
.card-title.glitch::after,
.card-title:hover::after  { animation: glitch-c 0.38s ease-out 1; }
@keyframes glitch-r {
    0%   { opacity: 0.9; transform: translate(2px, 0); clip-path: inset(0 0 70% 0); }
    30%  { transform: translate(2px, 0); clip-path: inset(40% 0 20% 0); }
    60%  { transform: translate(3px, -1px); clip-path: inset(70% 0 0 0); }
    100% { opacity: 0; transform: translate(0,0); clip-path: inset(0 0 0 0); }
}
@keyframes glitch-c {
    0%   { opacity: 0.9; transform: translate(-2px, 0); clip-path: inset(60% 0 0 0); }
    30%  { transform: translate(-2px, 0); clip-path: inset(10% 0 50% 0); }
    60%  { transform: translate(-3px, 1px); clip-path: inset(0 0 75% 0); }
    100% { opacity: 0; transform: translate(0,0); clip-path: inset(0 0 0 0); }
}

.card p {
    font-size: 1.0625rem;
    line-height: 1.62;
    color: var(--ink);
    margin-bottom: 0.7rem;
}
.card p:last-child { margin-bottom: 0; }
.card em { font-style: italic; color: #4a2e0f; }

.card mark {
    background: linear-gradient(180deg, transparent 60%, var(--sodium-yellow) 60%);
    color: var(--ink);
    padding: 0 2px;
}

.margin-note {
    font-family: "Caveat", cursive;
    font-weight: 600;
    font-size: 1.25rem !important;
    color: rgba(255,45,146,0.85) !important;
    transform: rotate(-3deg);
    margin-top: 0.9rem;
    line-height: 1.2 !important;
}

/* ---------- Torn-paper section break ---------- */
.torn-edge {
    position: relative;
    z-index: 4;
    height: 60px;
    margin-top: -30px;
    background:
        radial-gradient(circle at 5% 100%, transparent 14px, var(--velvet) 15px) 0 0/40px 60px repeat-x,
        var(--velvet);
    filter: url(#paper-tear);
}

/* ---------- Brass slide-rule scroll marker ---------- */
#slide-rule {
    position: fixed;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 240px;
    z-index: 70;
    background: linear-gradient(90deg, #6e4e1f, var(--brass) 40%, #f0d49a 50%, var(--brass) 60%, #6e4e1f);
    border-radius: 4px;
    box-shadow: 0 6px 14px rgba(8,7,18,0.6), 0 0 0 1px rgba(199,155,88,0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: box-shadow 0.3s ease;
}
#slide-rule.glow {
    box-shadow: 0 6px 14px rgba(8,7,18,0.6), 0 0 14px rgba(255,45,146,0.7), 0 0 0 1px rgba(199,155,88,0.4);
}
.rule-tick {
    width: 14px;
    height: 1.5px;
    background: rgba(10,6,18,0.55);
    margin: 16px 0;
}
.rule-cursor {
    position: absolute;
    top: calc(var(--scroll, 0) * 100%);
    left: -4px;
    width: 34px;
    height: 12px;
    background: linear-gradient(180deg, #f0d49a, var(--brass));
    border-radius: 2px;
    box-shadow: 0 2px 6px rgba(8,7,18,0.6);
    transform: translateY(-50%);
}
.rule-label {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%) rotate(90deg);
    transform-origin: left center;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.18em;
    color: var(--brass);
    white-space: nowrap;
}

/* ---------- Errata footer ---------- */
.errata {
    position: relative;
    z-index: 4;
    background: var(--velvet);
    padding: 3rem 2rem 4rem;
    border-top: 1px solid rgba(199,155,88,0.25);
}
.errata-head {
    font-family: "IM Fell English SC", serif;
    font-variant: small-caps;
    font-size: 1rem;
    letter-spacing: 0.16em;
    color: rgba(243,234,216,0.7);
    margin-bottom: 1.4rem;
    text-align: center;
}
.errata-list {
    list-style: none;
    max-width: 760px;
    margin: 0 auto;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.9;
    color: rgba(243,234,216,0.55);
}
.errata-list li { margin-bottom: 0.4rem; }
.errata-list .strike {
    text-decoration: line-through;
    text-decoration-color: var(--neon-magenta);
    text-decoration-thickness: 1.5px;
    opacity: 0.7;
}
.errata-list li:last-child {
    color: var(--brass);
    text-decoration: none;
    margin-top: 1.2rem;
}

/* ---------- Daylight easter-egg mode ---------- */
body.codex.daylight {
    background: #faf6ec;
}
body.codex.daylight::after { opacity: 0; }
body.codex.daylight .codex-wordmark { text-shadow: none; color: #2a2018; }
body.codex.daylight .card-title { text-shadow: none; }
body.codex.daylight .card { box-shadow: 0 6px 14px -8px rgba(0,0,0,0.25); background: #fffdf5; }
body.codex.daylight .ink-blobs,
body.codex.daylight .circuit-bed,
body.codex.daylight #candle-glow { opacity: 0.04; }
body.codex.daylight .stamp { color: #9a8a72; }
body.codex.daylight .codex-sub { color: #5a5040; }
body.codex.daylight .stamp-ribbon { background: #f0ead8; }
body.codex.daylight .errata { background: #f0ead8; }
body.codex.daylight .errata-list { color: #6a604c; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .card-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 24px 16px;
        padding: 0 18px;
    }
    .span-3 { grid-column: span 3; }
    .span-4 { grid-column: span 6; }
    .span-5 { grid-column: span 6; }
    .span-7 { grid-column: span 6; }
    .tall-sm { grid-row: span 24; }
    .tall-md { grid-row: span 32; }
    .tall-lg { grid-row: span 42; }
    #slide-rule { display: none; }
    #ex-libris { width: 110px; height: 110px; top: 100px; right: 8px; }
}
@media (max-width: 560px) {
    .card-grid { grid-template-columns: 1fr; }
    .span-3, .span-4, .span-5, .span-7 { grid-column: span 1; }
    .tall-sm, .tall-md, .tall-lg { grid-row: auto; }
    .card { clip-path: none !important; }
    .codex-wordmark { font-size: clamp(2.6rem, 14vw, 4rem); }
    .stamp-ribbon { gap: 1.4rem; height: 72px; }
}
