/* =========================================================
   koakuma.quest — The Folio of Small Mischiefs
   light-academia · f-pattern · sunset-warm · scale-hover
   ========================================================= */

:root {
    --paper:        #f4ead7;  /* aged ivory paper */
    --paper-warm:   #e8d3a8;  /* sun-stained margin */
    --amber:        #c97f3a;  /* amber sun / lantern */
    --terracotta:   #8a4a22;  /* terracotta-rust subheads */
    --sepia:        #6b4a2a;  /* sepia ink, body text */
    --walnut:       #3a2a1a;  /* shadow-walnut, secondary */
    --rose:         #a85234;  /* pressed-rose highlight */
    --tape:         #d8c39a;  /* gum-tape strip */
    --seal-light:   #c46044;
    --seal-dark:    #7a2a18;

    --deckle-bottom: polygon(
        0% 0%, 100% 0%, 100% 86%,
        96% 92%, 92% 87%, 88% 95%, 84% 88%, 80% 96%, 76% 89%,
        72% 97%, 68% 90%, 64% 98%, 60% 91%, 56% 99%, 52% 90%,
        48% 97%, 44% 89%, 40% 96%, 36% 88%, 32% 97%, 28% 90%,
        24% 98%, 20% 89%, 16% 96%, 12% 87%, 8% 95%, 4% 88%, 0% 93%
    );
    --deckle-all: polygon(
        2% 3%, 8% 1%, 16% 4%, 24% 1%, 33% 3%, 42% 1%, 52% 4%, 61% 1%,
        70% 3%, 79% 1%, 88% 4%, 96% 2%, 99% 8%, 97% 18%, 99% 28%, 96% 38%,
        99% 48%, 97% 58%, 99% 68%, 96% 78%, 99% 88%, 97% 96%, 90% 99%,
        80% 97%, 70% 99%, 60% 96%, 50% 99%, 40% 97%, 30% 99%, 20% 96%,
        11% 99%, 3% 97%, 1% 90%, 3% 80%, 1% 70%, 4% 60%, 1% 50%, 3% 40%,
        1% 30%, 4% 20%, 1% 11%
    );
}

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

html { scroll-behavior: smooth; }

body {
    background-color: var(--paper);
    color: var(--sepia);
    font-family: "Nunito", system-ui, sans-serif;
    font-weight: 400;
    font-size: 1.0625rem;
    line-height: 1.78;
    letter-spacing: 0.005em;
    position: relative;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ---------- paper grain (svg turbulence) ---------- */
.paper-grain {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    background-size: 220px 220px;
    mix-blend-mode: multiply;
    opacity: 0.08;
}

/* ---------- uneven light pooling ---------- */
.sun-pools {
    position: fixed; inset: 0; z-index: 0; pointer-events: none;
    background:
        radial-gradient(40vw 50vh at 78% 8%,  rgba(201,127,58,0.07), transparent 70%),
        radial-gradient(48vw 40vh at 12% 42%, rgba(201,127,58,0.06), transparent 70%),
        radial-gradient(36vw 44vh at 88% 70%, rgba(201,127,58,0.06), transparent 70%),
        radial-gradient(52vw 50vh at 30% 96%, rgba(201,127,58,0.05), transparent 70%);
}

/* ---------- dust-mote field ---------- */
.dust-field {
    position: fixed; inset: 0; width: 100%; height: 100%;
    z-index: 1; pointer-events: none;
    will-change: transform;
}

/* ---------- foxing marks ---------- */
.foxing { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.fox {
    position: absolute; border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, rgba(168,82,52,0.22), rgba(168,82,52,0.05) 70%, transparent);
    filter: blur(1px);
}
.fox-1 { width: 38px; height: 30px; left: 6%;  top: 24%; transform: rotate(18deg); }
.fox-2 { width: 22px; height: 26px; left: 21%; top: 61%; transform: rotate(-12deg); }
.fox-3 { width: 30px; height: 22px; right: 9%; top: 12%; transform: rotate(33deg); }
.fox-4 { width: 26px; height: 30px; right: 14%; top: 78%; transform: rotate(-22deg); }

/* ---------- the folio: literal F-pattern grid ---------- */
.folio {
    position: relative; z-index: 2;
    display: grid;
    grid-template-columns: 28% 1fr;
    grid-template-rows: auto auto 1fr auto;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 3vw, 3rem) 4rem;
}

/* accession stamp running header */
.accession {
    grid-column: 1 / -1;
    font-family: "Nunito", sans-serif;
    font-weight: 600;
    font-size: 0.66rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--walnut);
    opacity: 0.55;
    padding: 1.4rem 0 0.6rem;
}

/* ===================== TITLE PLATE ===================== */
.title-plate {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: clamp(1.5rem, 4vw, 4rem);
    background:
        linear-gradient(115deg, rgba(232,211,168,0.45), rgba(244,234,215,0) 55%),
        var(--paper);
    padding: clamp(2rem, 5vw, 4.2rem) clamp(1.5rem, 4vw, 3.5rem) clamp(3rem, 6vw, 5rem);
    margin: 0 calc(-1 * clamp(1rem, 3vw, 3rem));
    -webkit-clip-path: var(--deckle-bottom);
    clip-path: var(--deckle-bottom);
    box-shadow: inset 0 -28px 40px -28px rgba(58,42,26,0.18);
}

.title-text { flex: 1 1 auto; min-width: 0; }

.overline {
    font-family: "Nunito", sans-serif;
    font-weight: 600;
    font-size: 0.74rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--terracotta);
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.title-plate h1 {
    font-family: "Fraunces", Georgia, serif;
    font-optical-sizing: auto;
    font-weight: 300;
    font-size: clamp(2.4rem, 5.6vw, 4.6rem);
    line-height: 1.05;
    letter-spacing: -0.01em;
    color: var(--sepia);
    text-transform: lowercase;
    word-spacing: 0.06em;
}

.byline {
    font-family: "Caveat", cursive;
    font-weight: 500;
    font-size: 1.18rem;
    color: var(--terracotta);
    opacity: 0.85;
    margin-top: 0.9rem;
    transform: rotate(-0.5deg);
    max-width: 38ch;
}

/* taped pressed leaf on the right of the title */
.title-plate-leaf { flex: 0 0 auto; }
.taped-leaf {
    position: relative;
    padding: 1.4rem;
    transform: rotate(-2.4deg);
    filter: drop-shadow(3px 5px 3px rgba(58,42,26,0.14));
}
.pressed-leaf { display: block; }
.maple-big { width: clamp(110px, 14vw, 190px); height: auto; }
.leaf-body {
    fill: rgba(138,74,34,0.22);
    stroke: var(--terracotta);
    stroke-width: 1.1;
}
.leaf-vein {
    fill: none;
    stroke: var(--sepia);
    stroke-width: 0.9;
    opacity: 0.55;
}

/* gum-tape strips (shared) */
.gum-tape {
    position: absolute;
    width: 64px; height: 22px;
    background: linear-gradient(120deg,
        transparent 38%,
        rgba(216,195,154,0.7) 38%,
        rgba(216,195,154,0.85) 62%,
        transparent 62%);
    background-color: rgba(216,195,154,0.42);
    box-shadow: 0 1px 2px rgba(58,42,26,0.1);
    transition: opacity 480ms cubic-bezier(0.2,0.7,0.2,1);
}
.tape-tl { top: -8px; left: 8%; transform: rotate(-38deg); }
.tape-br { bottom: -8px; right: 8%; transform: rotate(-38deg); }

/* ===================== INDEX BAR ===================== */
.index-bar {
    grid-column: 1 / -1;
    padding: clamp(1.6rem, 3vw, 2.6rem) 0 clamp(2rem, 4vw, 3rem);
    border-bottom: 1px dashed rgba(107,74,42,0.25);
    margin-bottom: clamp(1.4rem, 3vw, 2.4rem);
}
.index-label {
    font-family: "Nunito", sans-serif;
    font-weight: 600;
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #8a6a3e;
    margin-bottom: 1.1rem;
}
.specimen-tags {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: clamp(0.6rem, 1.6vw, 1.4rem) clamp(0.6rem, 1.4vw, 1.2rem);
    align-items: flex-start;
}
.tag {
    position: relative;
    background: linear-gradient(170deg, #fbf3e0, #ecdcb8);
    border: 1px solid rgba(138,106,62,0.4);
    border-radius: 3px 3px 3px 10px;
    padding: 0.55rem 0.85rem 0.6rem 1.1rem;
    max-width: 16.5rem;
    cursor: pointer;
    box-shadow: 1px 2px 3px rgba(58,42,26,0.12);
    transition: transform 480ms cubic-bezier(0.2,0.7,0.2,1),
                box-shadow 480ms cubic-bezier(0.2,0.7,0.2,1);
    transform-origin: left center;
}
/* hand-pinned vertical offsets */
.tag:nth-child(1) { transform: translateY(-4px) rotate(-0.6deg); }
.tag:nth-child(2) { transform: translateY( 2px) rotate( 0.4deg); }
.tag:nth-child(3) { transform: translateY(-6px) rotate(-0.3deg); }
.tag:nth-child(4) { transform: translateY( 1px) rotate( 0.7deg); }
.tag:nth-child(5) { transform: translateY(-3px) rotate(-0.5deg); }
.tag:nth-child(6) { transform: translateY( 5px) rotate( 0.3deg); }
.tag:nth-child(7) { transform: translateY( 0px) rotate(-0.4deg); }

.tag-thread {
    position: absolute;
    left: -1px; top: 50%;
    width: 60px; height: 60px;
    border-left: 1px solid var(--walnut);
    border-top: 1px solid var(--walnut);
    border-radius: 60px 0 0 0;
    transform: translate(-58px, -58px);
    opacity: 0.5;
    pointer-events: none;
}
.tag-no {
    display: block;
    font-family: "Nunito", sans-serif;
    font-weight: 700;
    font-size: 0.62rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--amber);
    margin-bottom: 0.15rem;
}
.tag-name {
    display: block;
    font-family: "Caveat", cursive;
    font-weight: 600;
    font-size: 1.08rem;
    line-height: 1.2;
    color: var(--sepia);
}

/* scale-hover: the only hover on the site */
.tag:hover {
    transform: translateY(-4px) rotate(-0.6deg) scale(1.035);
    box-shadow: 6px 12px 18px rgba(58,42,26,0.22);
}
.tag:nth-child(2):hover { transform: translateY( 2px) rotate( 0.4deg) scale(1.035); }
.tag:nth-child(3):hover { transform: translateY(-6px) rotate(-0.3deg) scale(1.035); }
.tag:nth-child(4):hover { transform: translateY( 1px) rotate( 0.7deg) scale(1.035); }
.tag:nth-child(5):hover { transform: translateY(-3px) rotate(-0.5deg) scale(1.035); }
.tag:nth-child(6):hover { transform: translateY( 5px) rotate( 0.3deg) scale(1.035); }
.tag:nth-child(7):hover { transform: translateY( 0px) rotate(-0.4deg) scale(1.035); }

/* ===================== MARGIN SPINE ===================== */
.margin-spine {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    padding: 1rem clamp(0.6rem, 1.6vw, 1.6rem) 2rem 0.2rem;
    background: linear-gradient(100deg, rgba(232,211,168,0.5), rgba(232,211,168,0) 80%);
    border-right: 1px solid rgba(107,74,42,0.18);
    display: flex;
    flex-direction: column;
    gap: clamp(3.2rem, 8vw, 6rem);
}
.marginalia {
    font-family: "Caveat", cursive;
    color: var(--sepia);
    opacity: 0.85;
    line-height: 1.5;
}
.marginalia.m-a { transform: rotate(-0.4deg) translateX(2px); }
.marginalia.m-b { transform: rotate( 0.6deg) translateX(10px); margin-top: 1.4rem; }
.marginalia.m-c { transform: rotate(-0.6deg) translateX(-2px); margin-top: 2.6rem; }
.marginalia.m-d { transform: rotate( 0.5deg) translateX(8px); margin-top: 3.4rem; }
.marginalia.m-e { transform: rotate(-0.5deg) translateX(4px); margin-top: 2rem; }
.marginalia.m-f { transform: rotate( 0.7deg) translateX(12px); margin-top: 3.2rem; }
.marginalia.m-g { transform: rotate(-0.4deg) translateX(0); margin-top: 2.4rem; }
.marginalia.m-h { transform: rotate( 0.5deg) translateX(6px); margin-top: 3rem; }

.m-date {
    font-weight: 600; font-size: 1.02rem; color: var(--terracotta);
}
.m-weather { font-size: 0.95rem; opacity: 0.9; }
.m-note { font-size: 0.98rem; max-width: 22ch; }

.m-leaf {
    width: 46px; height: auto; margin-top: 0.5rem;
    filter: drop-shadow(2px 3px 1px rgba(58,42,26,0.18));
}
.m-leaf-fern { width: 40px; }
.m-leaf .leaf-body { fill: rgba(138,74,34,0.18); stroke: var(--terracotta); stroke-width: 1; }
.m-leaf .leaf-vein { stroke: var(--sepia); stroke-width: 0.8; opacity: 0.5; fill: none; }

.sigil-mini { display: inline-block; width: 26px; margin-top: 0.4rem; }
.sigil-mini svg, .sigil-head svg, .seal-sigil { display: block; }
.sigil-line {
    fill: none; stroke: var(--sepia); stroke-width: 1; stroke-linecap: round;
}

/* ===================== MAIN FOLIO ===================== */
.main-folio {
    grid-column: 2 / 3;
    grid-row: 3 / 4;
    padding: 1rem clamp(0.5rem, 2vw, 2rem) 2rem clamp(1.4rem, 3vw, 3rem);
    display: flex;
    flex-direction: column;
    gap: clamp(3.5rem, 7vw, 6.5rem);
}

.quest { max-width: 64ch; }
.quest.indent-left { margin-left: 18%; }
.quest.full-width  { width: 100%; max-width: 70ch; }
.quest.half-strip  { width: 100%; max-width: 50ch; }

.chapter-head {
    font-family: "Fraunces", Georgia, serif;
    font-optical-sizing: auto;
    font-weight: 300;
    font-size: clamp(1.5rem, 2.6vw, 2.1rem);
    line-height: 1.18;
    letter-spacing: -0.01em;
    color: var(--terracotta);
    margin-bottom: 1.1rem;
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
}
.sigil-head {
    flex: 0 0 auto;
    width: 22px;
    transform: translateY(2px) rotate(-3deg);
}
.sigil-head .sigil-line { stroke: var(--terracotta); }

.quest p {
    color: var(--sepia);
    font-size: 1.0625rem;
    line-height: 1.78;
}
.quest p::first-letter {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 400;
    font-size: 1.05em;
    color: var(--terracotta);
}

/* ---------- tipped-in photographic plates ---------- */
.plate {
    position: relative;
    align-self: flex-end;
    width: min(560px, 78%);
    margin-right: 8%;
    background: var(--paper);
    padding: 0.9rem 0.9rem 0.4rem;
    box-shadow:
        2px 4px 10px rgba(58,42,26,0.16),
        0 18px 24px -18px rgba(58,42,26,0.3);
    -webkit-clip-path: var(--deckle-all);
    clip-path: var(--deckle-all);
    transition: transform 480ms cubic-bezier(0.2,0.7,0.2,1),
                box-shadow 480ms cubic-bezier(0.2,0.7,0.2,1);
}
.plate-rot-neg { transform: rotate(-0.7deg); }
.plate-rot-pos { transform: rotate( 0.5deg); }

.plate:hover { box-shadow:
        8px 16px 26px rgba(58,42,26,0.26),
        0 30px 40px -22px rgba(58,42,26,0.36); }
.plate-rot-neg:hover { transform: rotate(-0.7deg) scale(1.035); }
.plate-rot-pos:hover { transform: rotate( 0.5deg) scale(1.035); }
.plate:hover .gum-tape { opacity: 0.95; }

.plate .gum-tape { z-index: 3; }

.plate-image {
    width: 100%;
    aspect-ratio: 16 / 10;
    border: 1px solid rgba(138,74,34,0.3);
    background-blend-mode: multiply, normal, normal, normal;
    box-shadow: inset 0 0 30px rgba(58,42,26,0.2);
}

/* CSS-painted "sepia contact print" scenes */
.plate-img-leaf {
    background-image:
        linear-gradient(rgba(244,234,215,0.45), rgba(201,127,58,0.4)),
        radial-gradient(60% 70% at 50% 55%, rgba(138,74,34,0.55), transparent 70%),
        radial-gradient(28% 50% at 38% 40%, rgba(58,42,26,0.5), transparent),
        radial-gradient(36% 24% at 64% 62%, rgba(58,42,26,0.4), transparent),
        linear-gradient(135deg, #d8b888, #b07c3e);
}
.plate-img-track {
    background-image:
        linear-gradient(rgba(244,234,215,0.4), rgba(201,127,58,0.42)),
        radial-gradient(22% 40% at 50% 48%, rgba(58,42,26,0.7), transparent 75%),
        radial-gradient(14% 26% at 44% 36%, rgba(58,42,26,0.5), transparent),
        radial-gradient(14% 26% at 56% 38%, rgba(58,42,26,0.5), transparent),
        radial-gradient(80% 80% at 50% 70%, rgba(141,106,62,0.4), transparent),
        linear-gradient(120deg, #cbb085, #9d7b4f);
}
.plate-img-shell {
    background-image:
        linear-gradient(rgba(244,234,215,0.45), rgba(201,127,58,0.4)),
        radial-gradient(34% 44% at 52% 52%, rgba(138,74,34,0.6), transparent 72%),
        radial-gradient(20% 26% at 48% 46%, rgba(58,42,26,0.45), transparent),
        radial-gradient(10% 14% at 60% 58%, rgba(244,234,215,0.6), transparent),
        linear-gradient(140deg, #dbbf90, #b78a4c);
}
.plate-img-twig {
    background-image:
        linear-gradient(rgba(244,234,215,0.42), rgba(201,127,58,0.42)),
        linear-gradient(112deg, transparent 44%, rgba(58,42,26,0.6) 47%, rgba(244,234,215,0.7) 50%, rgba(58,42,26,0.6) 53%, transparent 56%),
        radial-gradient(70% 60% at 50% 60%, rgba(141,106,62,0.45), transparent),
        linear-gradient(125deg, #d4b888, #a3814f);
}

.plate figcaption {
    font-family: "Caveat", cursive;
    font-weight: 500;
    font-size: 1.05rem;
    color: var(--sepia);
    opacity: 0.85;
    text-align: center;
    padding: 0.55rem 0.5rem 0.2rem;
    transform: rotate(0.4deg);
}

/* quest + side plate mid-page strip */
.quest-with-plate {
    display: flex;
    align-items: flex-start;
    gap: clamp(1.4rem, 3vw, 2.6rem);
    flex-wrap: wrap;
}
.quest-with-plate .quest.half-strip { flex: 1 1 24rem; }
.plate-side {
    flex: 1 1 20rem;
    align-self: flex-start;
    width: auto;
    margin-right: 0;
    max-width: 24rem;
}

/* ===================== CLOSING ENDPAPER ===================== */
.endpaper {
    grid-column: 1 / -1;
    grid-row: 4 / 5;
    position: relative;
    margin: clamp(3rem, 7vw, 6rem) calc(-1 * clamp(1rem, 3vw, 3rem)) 0;
    padding: clamp(4rem, 9vw, 7rem) clamp(1.5rem, 4vw, 3.5rem) clamp(4rem, 9vw, 7rem);
    text-align: center;
    overflow: hidden;
    background:
        radial-gradient(40% 50% at 20% 30%, rgba(201,127,58,0.16), transparent 70%),
        radial-gradient(46% 60% at 78% 64%, rgba(168,82,52,0.12), transparent 70%),
        radial-gradient(30% 40% at 55% 18%, rgba(232,211,168,0.5), transparent 70%),
        linear-gradient(160deg, #efe0c2, #e3cda0);
    -webkit-clip-path: polygon(
        0% 6%, 8% 2%, 18% 5%, 30% 1%, 42% 4%, 54% 1%, 66% 5%, 78% 1%, 90% 4%, 100% 1%,
        100% 100%, 0% 100%
    );
    clip-path: polygon(
        0% 6%, 8% 2%, 18% 5%, 30% 1%, 42% 4%, 54% 1%, 66% 5%, 78% 1%, 90% 4%, 100% 1%,
        100% 100%, 0% 100%
    );
}
.endpaper-cloud {
    position: absolute; inset: -10%;
    background:
        radial-gradient(circle at 30% 30%, rgba(201,127,58,0.08), transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(168,82,52,0.07), transparent 45%),
        radial-gradient(circle at 50% 80%, rgba(201,127,58,0.06), transparent 40%);
    pointer-events: none;
}
.wax-seal {
    position: relative;
    width: 92px; height: 92px;
    margin: 0 auto 1.6rem;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, var(--seal-light), var(--seal-dark));
    box-shadow:
        0 6px 14px rgba(58,42,26,0.3),
        inset 0 2px 6px rgba(255,255,255,0.18),
        inset 0 -6px 12px rgba(0,0,0,0.25);
    display: flex; align-items: center; justify-content: center;
    animation: heartbeat 6s ease-in-out infinite;
}
.seal-sigil { width: 40px; height: 40px; position: absolute; }
.seal-line { fill: none; stroke: rgba(255,236,224,0.7); stroke-width: 1.4; stroke-linecap: round; }
.seal-initials {
    position: absolute; bottom: 12px;
    font-family: "Fraunces", serif; font-weight: 400; font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: rgba(255,236,224,0.85);
}
@keyframes heartbeat {
    0%, 70%, 100% { transform: scale(1); }
    82% { transform: scale(1.015); }
}
.endpaper-line {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 300;
    font-size: clamp(1.1rem, 2.2vw, 1.6rem);
    color: var(--terracotta);
    letter-spacing: 0.01em;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 880px) {
    .folio {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto;
    }
    .margin-spine {
        grid-column: 1 / -1; grid-row: auto;
        flex-direction: row; flex-wrap: wrap;
        gap: 1.6rem 2.4rem;
        border-right: none;
        border-bottom: 1px dashed rgba(107,74,42,0.2);
        padding: 1.4rem 0 2rem;
    }
    .marginalia { margin-top: 0 !important; transform: none !important; max-width: 18rem; }
    .main-folio { grid-column: 1 / -1; grid-row: auto; padding-left: 0; }
    .quest.indent-left { margin-left: 0; }
    .plate { width: 92%; margin-right: 0; align-self: center; }
    .title-plate { flex-direction: column; align-items: flex-start; gap: 2rem; }
}

@media (max-width: 520px) {
    body { font-size: 1rem; }
    .specimen-tags { gap: 1rem; }
    .tag, .tag:hover { transform: none !important; }
    .tag:hover { box-shadow: 6px 12px 18px rgba(58,42,26,0.22); }
}
