/* haskell.quest — illuminated grimoire of the lambda
   Palette
     #f3ead0 vellum cream  · #ebe1c4 darker cream  · #1c1612 iron-gall ink
     #a98c5a walnut umber  · #b78c2e gold leaf      · #7a1a1a vermilion
     #3d2f1f bistre        · #e8c478 candle warmth
   Fonts
     Cormorant Garamond / Cormorant SC (body, drop caps)
     IM FELL English SC (marginalia, incipits, folio numbers)
     JetBrains Mono (code, type signatures)
*/

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

html, body {
    background: #f3ead0;
    color: #1c1612;
    font-family: "Cormorant Garamond", Georgia, serif;
    font-size: 16px;
    line-height: 1.7;
    overflow-x: hidden;
    cursor: url("assets/quill.svg") 2 22, auto;
}

body {
    position: relative;
    min-height: 100vh;
    background-color: #f3ead0;
    background-image:
        radial-gradient(ellipse at 12% 8%, rgba(169, 140, 90, 0.05), transparent 32%),
        radial-gradient(ellipse at 88% 22%, rgba(169, 140, 90, 0.04), transparent 28%),
        radial-gradient(ellipse at 38% 64%, rgba(169, 140, 90, 0.045), transparent 30%),
        radial-gradient(ellipse at 76% 86%, rgba(169, 140, 90, 0.05), transparent 32%);
}

/* ---------- diagonals (lambda body) ---------- */
.diagonals {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 1;
}
.diagonals .diag {
    stroke-dasharray: 5000;
    stroke-dashoffset: 5000;
    animation: draw-diag 1.4s cubic-bezier(0.66, 0.01, 0.27, 0.99) forwards;
}
.diagonals .diag-a { animation-delay: 0.15s; }
.diagonals .diag-b { animation-delay: 0.45s; }
.diagonals .diag-c { animation-delay: 0.75s; }
.diagonals .diag-d { animation-delay: 1.05s; }
@keyframes draw-diag { to { stroke-dashoffset: 0; } }

/* ---------- candle stratum ---------- */
.candle {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 38vw;
    height: 56vh;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(circle at 14% 88%, rgba(232, 196, 120, 0.18) 0%, rgba(232, 196, 120, 0.10) 18%, rgba(232, 196, 120, 0.04) 32%, transparent 56%);
}

/* ---------- chapter rail ---------- */
.rail {
    position: fixed;
    left: 0;
    top: 0;
    width: 28px;
    height: 100vh;
    z-index: 12;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.4em;
    border-right: 1px solid rgba(169, 140, 90, 0.35);
    background: rgba(243, 234, 208, 0.4);
}
.rail a {
    font-family: "IM Fell English SC", "Cormorant SC", serif;
    font-size: 0.78rem;
    color: #a98c5a;
    text-decoration: none;
    letter-spacing: 0.04em;
    transition: color 250ms ease;
    position: relative;
}
.rail a:hover, .rail a.active {
    color: #7a1a1a;
}
.rail a:hover::after {
    content: attr(data-name);
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    background: #ebe1c4;
    padding: 0.2em 0.6em;
    border: 1px solid #a98c5a;
    color: #3d2f1f;
    font-family: "IM Fell English SC", serif;
    font-size: 0.74rem;
    pointer-events: none;
}

/* ---------- silk ribbon ---------- */
.ribbon {
    position: fixed;
    top: 0;
    right: 28px;
    width: 6px;
    z-index: 11;
    pointer-events: none;
}
.ribbon .ribbon-tail {
    width: 6px;
    height: 0;
    background: linear-gradient(to bottom, #7a1a1a 0%, #951f1f 60%, #7a1a1a 100%);
    box-shadow: 0 0 1px rgba(122, 26, 26, 0.6);
    transition: none;
}
.ribbon-tassel {
    position: absolute;
    width: 22px;
    height: 22px;
    left: -8px;
    top: 0;
    transform: translateY(-2px);
}

/* ---------- folio ---------- */
.folio {
    position: relative;
    z-index: 5;
    width: min(64ch, 92vw);
    margin: 0 auto;
    padding: 8vh 0 6vh;
}

.endpaper {
    width: 100%;
    height: 110px;
    margin: 0 auto 4vh;
    opacity: 0.6;
}
.endpaper svg { width: 100%; height: 100%; display: block; }
.endpaper-bottom { margin: 8vh auto 0; }

/* ---------- frontispiece ---------- */
.incipit-page {
    text-align: center;
    padding: 6vh 0 10vh;
    border-bottom: 1px solid rgba(169, 140, 90, 0.35);
    margin-bottom: 8vh;
    position: relative;
}
.incipit-page::before, .incipit-page::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 32%;
    height: 1px;
    background: #a98c5a;
}
.incipit-page::before { top: 18%; }
.incipit-page::after { bottom: 28%; }

.frontispiece-title {
    font-family: "Cormorant SC", "Cormorant Garamond", serif;
    font-weight: 500;
    font-size: 2.6rem;
    color: #1c1612;
    letter-spacing: 0.06em;
    margin: 0.6em 0 0.2em;
}
.frontispiece-sub {
    font-family: "IM Fell English SC", serif;
    font-size: 1.05rem;
    color: #7a1a1a;
    letter-spacing: 0.04em;
    margin-bottom: 1.6em;
}
.frontispiece-byline {
    font-family: "IM Fell English SC", serif;
    color: #a98c5a;
    font-size: 0.86rem;
    letter-spacing: 0.06em;
}
.rubric {
    font-family: "IM Fell English SC", serif;
    color: #7a1a1a;
    font-size: 0.84em;
    letter-spacing: 0.04em;
}

/* ---------- leaf (chapter) ---------- */
.leaf {
    position: relative;
    padding: 7vh 0 6vh;
    border-bottom: 1px solid rgba(169, 140, 90, 0.25);
    scroll-margin-top: 2vh;
}
.leaf:last-of-type { border-bottom: none; }

.leaf .incipit {
    font-family: "Cormorant Garamond", serif;
    font-weight: 400;
    font-size: 1.6rem;
    color: #1c1612;
    margin-bottom: 1.6em;
    text-transform: none;
    letter-spacing: 0.01em;
    font-variant: small-caps;
}
.leaf .incipit .rubric {
    display: block;
    font-size: 0.62em;
    margin-bottom: 0.4em;
    font-variant: normal;
}
.leaf .incipit .gloss {
    font-family: "IM Fell English SC", serif;
    font-style: normal;
    color: #a98c5a;
    font-size: 0.5em;
    margin-left: 0.6em;
    letter-spacing: 0.04em;
    font-variant: normal;
}

.prose {
    font-size: 1.06rem;
    line-height: 1.7;
    margin-bottom: 1.6em;
    text-align: left;
    hyphens: none;
    color: #1c1612;
}
.prose em {
    font-style: italic;
    font-weight: 500;
}
.prose code {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.92em;
    background: rgba(235, 225, 196, 0.5);
    padding: 0.05em 0.35em;
    color: #3d2f1f;
    border-radius: 0;
}

/* ---------- drop cap ---------- */
.has-dropcap {
    position: relative;
}
.dropcap {
    float: left;
    width: 4.4em;
    height: 4.4em;
    margin: 0.05em 0.45em -0.2em -0.2em;
    position: relative;
    shape-outside: margin-box;
}
.dropcap svg {
    width: 100%;
    height: 100%;
    display: block;
}
.dropcap::after {
    content: attr(data-letter);
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Cormorant SC", "Cormorant Garamond", serif;
    font-weight: 500;
    color: #b78c2e;
    font-size: 3.2em;
    line-height: 1;
    text-shadow: 0 0 1px rgba(183, 140, 46, 0.6);
}
.dropcap .filigree, .dropcap .filigree-vine {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
}
.dropcap.drawn .filigree, .dropcap.drawn .filigree-vine {
    animation: draw-filigree 2.8s cubic-bezier(0.66, 0.01, 0.27, 0.99) forwards;
}
.dropcap.drawn .filigree-vine { animation-delay: 1.1s; animation-duration: 1.8s; }
@keyframes draw-filigree { to { stroke-dashoffset: 0; } }

/* ---------- equation slab ---------- */
.slab {
    position: relative;
    width: 100vw;
    margin: 2.8em calc(50% - 50vw);
    padding: 1.6em 6vw 1.4em;
    background: #ebe1c4;
    border-top: 1px solid #a98c5a;
    border-bottom: 1px solid #a98c5a;
    transform: rotate(0deg);
    transition: background 220ms ease;
    box-shadow: 0 1px 0 rgba(169, 140, 90, 0.2);
}
.slab[data-tilt="0.1"] { transform: rotate(0.1deg); }
.slab[data-tilt="0.2"] { transform: rotate(0.2deg); }
.slab[data-tilt="0.3"] { transform: rotate(0.3deg); }
.slab[data-tilt="0.4"] { transform: rotate(0.4deg); }
.slab[data-tilt="-0.1"] { transform: rotate(-0.1deg); }
.slab[data-tilt="-0.2"] { transform: rotate(-0.2deg); }
.slab[data-tilt="-0.3"] { transform: rotate(-0.3deg); }
.slab[data-tilt="-0.4"] { transform: rotate(-0.4deg); }

.slab-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: min(58ch, 92%);
    margin: 0 auto 0.8em;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.86rem;
    color: #7a1a1a;
    border-bottom: 1px dotted #a98c5a;
    padding-bottom: 0.4em;
    font-feature-settings: "calt" on;
}
.slab .sig {
    letter-spacing: 0.01em;
}
.slab .run {
    background: transparent;
    border: 1px solid #a98c5a;
    color: #3d2f1f;
    cursor: pointer;
    font-size: 0.78rem;
    padding: 0.2em 0.7em;
    font-family: "IM Fell English SC", serif;
    transition: background 200ms ease, color 200ms ease;
}
.slab .run:hover { background: #b78c2e; color: #f3ead0; }

.slab pre {
    width: min(58ch, 92%);
    margin: 0.4em auto 0.6em;
    background: transparent;
    overflow-x: auto;
}
.slab code.expr {
    display: block;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.94rem;
    color: #1c1612;
    line-height: 1.6;
    padding: 0.4em 0.6em;
    border: 1px solid transparent;
    outline: none;
    white-space: pre-wrap;
    font-feature-settings: "calt" on;
    cursor: text;
    min-height: 1.6em;
}
.slab code.expr:focus {
    border-color: rgba(169, 140, 90, 0.5);
    background: rgba(243, 234, 208, 0.4);
}
.slab .result {
    width: min(58ch, 92%);
    margin: 0.6em auto 0;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.92rem;
    color: #3d2f1f;
    min-height: 1.4em;
    padding: 0.3em 0.6em;
    border-top: 1px dotted #a98c5a;
    font-feature-settings: "calt" on;
}
.slab .result[data-empty="true"] { display: none; }
.slab .result.error {
    color: #7a1a1a;
}
.slab .result .ink-cursor {
    color: #a98c5a;
    opacity: 0.5;
}

/* ---------- manicule ---------- */
.manicule {
    color: #b78c2e;
    font-size: 1.4em;
    margin: 0 0.18em;
    line-height: 1;
    vertical-align: -0.08em;
}

/* ---------- folio numbers ---------- */
.folio-num {
    position: absolute;
    bottom: 1.6em;
    right: 0;
    font-family: "IM Fell English SC", serif;
    font-size: 0.78rem;
    color: #a98c5a;
    letter-spacing: 0.18em;
}
.leaf:nth-child(odd) .folio-num { right: 0; }
.leaf:nth-child(even) .folio-num { right: auto; left: 0; }

/* ---------- marginalia ---------- */
.margin {
    position: fixed;
    right: 36px;
    top: 6vh;
    width: 14ch;
    max-height: 70vh;
    overflow-y: auto;
    padding: 0.8em 1em 0.8em 1.2em;
    border-left: 1px solid rgba(169, 140, 90, 0.5);
    z-index: 6;
    color: #3d2f1f;
    font-family: "IM Fell English SC", serif;
    font-size: 0.78rem;
    line-height: 1.5;
}
.margin-empty {
    color: #a98c5a;
    font-style: italic;
}
.margin .gloss-entry {
    margin-bottom: 1.2em;
    opacity: 0;
    transform: translateY(4px);
    animation: gloss-in 600ms ease forwards;
}
.margin .gloss-entry em { font-family: "JetBrains Mono", monospace; font-size: 0.86em; color: #7a1a1a; font-style: normal; }
.margin .gloss-entry .demon {
    color: #3d2f1f;
    font-size: 1.1em;
    margin-right: 0.4em;
    display: inline-block;
}
.margin .gloss-entry.correction { color: #7a1a1a; }
.margin .gloss-entry.correction .demon { color: #7a1a1a; }
@keyframes gloss-in { to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
    .margin {
        position: static;
        width: min(64ch, 92vw);
        margin: 4vh auto 6vh;
        max-height: none;
        border-left: none;
        border-top: 1px solid rgba(169, 140, 90, 0.5);
        padding-top: 1.2em;
    }
    .ribbon { right: 14px; }
}

/* ---------- colophon ---------- */
.colophon {
    text-align: center;
    margin-top: 8vh;
    padding: 4vh 0;
    border-top: 1px solid rgba(169, 140, 90, 0.35);
    color: #3d2f1f;
    font-family: "IM Fell English SC", serif;
    font-size: 0.88rem;
    line-height: 1.7;
    letter-spacing: 0.02em;
}
.colophon .rubric { display: block; margin-bottom: 1.2em; font-size: 0.96rem; }
.colo-line { margin: 0.4em 0; }
.quill-mark {
    width: 60px;
    height: 60px;
    margin: 1.6em auto 0;
    display: block;
    opacity: 0.85;
}

/* ---------- imp easter egg ---------- */
.imp {
    position: fixed;
    bottom: 14px;
    left: -80px;
    width: 60px;
    height: 60px;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 180ms ease;
}
.imp.walking {
    opacity: 1;
    animation: imp-walk 4s linear forwards;
}
@keyframes imp-walk {
    0%   { left: -80px; transform: translateY(0); }
    8%   { transform: translateY(-3px); }
    16%  { transform: translateY(0); }
    24%  { transform: translateY(-3px); }
    32%  { transform: translateY(0); }
    40%  { transform: translateY(-3px); }
    48%  { transform: translateY(0); }
    56%  { transform: translateY(-3px); }
    64%  { transform: translateY(0); }
    72%  { transform: translateY(-3px); }
    80%  { transform: translateY(0); }
    88%  { transform: translateY(-3px); }
    100% { left: 110vw; transform: translateY(0); }
}

/* ---------- anchor marks (invisible) ---------- */
.anchor-mark {
    display: inline-block;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* small-screen folio padding */
@media (max-width: 700px) {
    .folio { padding: 6vh 1.2em 4vh; }
    .frontispiece-title { font-size: 2rem; }
    .leaf .incipit { font-size: 1.3rem; }
    .prose { font-size: 1rem; }
    .slab { padding: 1.2em 4vw 1em; }
    .rail { display: none; }
    .ribbon { right: 6px; }
    .dropcap { width: 3.6em; height: 3.6em; }
}
