/* ==========================================================================
   luminary.dev — a quiet scholar's almanac
   muji + book-scholarly + layered-depth (paper-stack lithography)
   ========================================================================== */

:root {
    /* Palette — warm muji + burnt-orange ember */
    --paper:        #F4EFE6;   /* primary paper, unbleached muslin */
    --paper-2:      #EAE2D2;   /* secondary paper for depth-shift */
    --ink:          #1F1A14;   /* primary iron-gall ink */
    --ink-2:        #3D3328;   /* graphite secondary ink */
    --ember:        #B85A1E;   /* burnt-orange ember accent */
    --ember-deep:   #7A3812;   /* deeper ember, lit-lamp underside */
    --mid:          #6B6356;   /* mid-tone, skeleton placeholders, rules */

    /* Type */
    --mono:         "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --mono-margin:  "DM Mono", "JetBrains Mono", ui-monospace, monospace;
    --serif-guest:  "Cormorant Garamond", "EB Garamond", Georgia, serif;

    /* Sizes */
    --body-size:    15.5px;
    --body-leading: 1.85;

    /* Page-turn easing */
    --ease-quarto:  cubic-bezier(0.22, 0.61, 0.36, 1);

    /* Stagger var, set per child via JS */
    --stagger: 0ms;
}

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

html, body {
    background: var(--paper);
    color: var(--ink);
    font-family: var(--mono);
    font-size: var(--body-size);
    line-height: var(--body-leading);
    letter-spacing: 0.005em;
    /* prevent pure black/white shimmer; keep edge tone warm */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: geometricPrecision;
}

body {
    /* warm tonal vignette, paper-on-paper */
    background:
        radial-gradient(1200px 800px at 22% 12%, #F8F3EB 0%, var(--paper) 58%),
        var(--paper);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Hide SVG <defs>-only blocks visually but keep accessible to <use> */
.grain-defs,
.icon-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ==========================================================================
   Almanac container — the tabletop seen from above
   ========================================================================== */

.almanac {
    width: 100%;
    /* generous outer padding so leaves do not kiss the viewport edge */
    padding: 56px 36px 96px 36px;
    position: relative;
    /* simulate desktop tone (slightly darker than paper) */
    background:
        linear-gradient(180deg, #ECE4D4 0%, #E6DDC8 100%);
}

/* ==========================================================================
   Leaf — a sheet of mulberry/muslin paper
   ========================================================================== */

.leaf {
    position: relative;
    margin: 0 auto 64px auto;
    max-width: 1280px;
    min-height: 95vh;
    background-color: var(--paper);
    background-image:
        linear-gradient(180deg, rgba(31, 26, 20, 0.012) 0%, rgba(31, 26, 20, 0.0) 30%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.122  0 0 0 0 0.102  0 0 0 0 0.078  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23g)'/></svg>");
    background-size: auto, 240px 240px;

    /* paper-stack lithography: each subsequent leaf nests at a different elevation
       expressed as a translateY of the *next* leaf, so the current sheet appears
       to sit atop the next. We also tone the paper slightly. */
    border: 1px solid rgba(31, 26, 20, 0.06);
    /* crisp, never-blurred paper-on-paper shadow (1-2px offsets, low opacity) */
    box-shadow:
        0 1px 0 rgba(31, 26, 20, 0.06),
        0 2px 0 rgba(31, 26, 20, 0.04);

    padding: 96px 88px 96px 88px;

    display: grid;
    grid-template-columns: 12rem minmax(0, 60rem) 12rem;
    grid-column-gap: 32px;
    align-items: start;

    transform-origin: 100% 100%;
    transition:
        transform 480ms var(--ease-quarto),
        opacity 480ms var(--ease-quarto),
        background-color 480ms var(--ease-quarto);
    will-change: transform, opacity;
}

/* tonal staircase: alternate leaves descend slightly in tone, conveying depth */
.leaf[data-leaf-z="1"] { background-color: #F2EDE3; }
.leaf[data-leaf-z="2"] { background-color: #EFE9DD; box-shadow: 0 1px 0 rgba(31,26,20,.07), 0 2px 0 rgba(31,26,20,.045); }
.leaf[data-leaf-z="3"] { background-color: #ECE4D6; }
.leaf[data-leaf-z="4"] { background-color: #EAE2D2; box-shadow: 0 1px 0 rgba(31,26,20,.08), 0 2px 0 rgba(31,26,20,.05); }
.leaf[data-leaf-z="5"] { background-color: #E7DECC; }
.leaf[data-leaf-z="6"] { background-color: #E5DBC6; box-shadow: 0 1px 0 rgba(31,26,20,.09), 0 2px 0 rgba(31,26,20,.055); }
.leaf[data-leaf-z="7"] { background-color: #E2D6BE; }

/* the page-turn state: applied via JS when leaf is past 60% scrolled */
.leaf.is-turned {
    transform: translateY(-16px) rotate(1.4deg);
    opacity: 0.36;
}

/* leaves enter slightly raised; come to rest when in view */
.leaf.is-resting {
    /* normal at-rest state, no transform */
}

/* ==========================================================================
   Leaf body (centre column) — typesetter's loupe cursor
   ========================================================================== */

.leaf-body {
    grid-column: 2 / 3;
    max-width: 56rem;
    color: var(--ink);
    /* simulate typesetter's loupe over the body (centre column only) */
    cursor: crosshair;
    position: relative;
}

.leaf-body p + p {
    margin-top: 1.2em;
}

.leaf-body p {
    text-wrap: pretty;
    hyphens: none;
}

.leaf-numeral {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    font-size: 11.5px;
    color: var(--ember);
    letter-spacing: 0.04em;
    text-transform: lowercase;
    display: inline-block;
    margin-bottom: 12px;
}

.leaf-title {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 28px;
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin-bottom: 18px;
    text-transform: lowercase;
}

/* ==========================================================================
   Pressed rule (typesetter's marker)
   ========================================================================== */

.pressed-rule {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 24px 0 28px 0;
    color: var(--ink-2);
}

.pressed-rule .rule-mark {
    font-family: var(--mono-margin);
    font-size: 10px;
    line-height: 1;
    color: var(--mid);
    user-select: none;
}

.pressed-rule .rule-line {
    flex: 1;
    height: 1px;
    background: var(--ink-2);
    opacity: 0.55;
}

.pressed-rule--short .rule-line {
    max-width: 220px;
}

.pressed-rule--ember .rule-line {
    background: var(--ember);
    opacity: 0.6;
}

.pressed-rule--ember .rule-mark {
    color: var(--ember);
}

/* ==========================================================================
   Marginalia (left/right scholarly columns)
   ========================================================================== */

.marginalia {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--ink-2);
    text-transform: lowercase;
    letter-spacing: 0.01em;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-self: start;
}

.marginalia--left {
    grid-column: 1 / 2;
    text-align: right;
    align-items: flex-end;
    padding-top: 8px;
}

.marginalia--right {
    grid-column: 3 / 4;
    text-align: left;
    align-items: flex-start;
    padding-top: 64px;
}

.marginalia .marg-icon {
    display: inline-block;
    width: 56px;
    height: 56px;
    line-height: 0;
    margin-bottom: 4px;
    color: var(--ink);
    /* before-revealed: dimmed */
    opacity: 0;
    transform: translateX(-6px);
    transition:
        opacity 460ms var(--ease-quarto) var(--stagger, 0ms),
        transform 460ms var(--ease-quarto) var(--stagger, 0ms);
}

.marginalia--left .marg-icon { transform: translateX(6px); }

.marginalia .marg-line {
    opacity: 0;
    transform: translateX(-6px);
    transition:
        opacity 460ms var(--ease-quarto) var(--stagger, 0ms),
        transform 460ms var(--ease-quarto) var(--stagger, 0ms);
    /* leaves room for hand-set look */
    max-width: 12rem;
    word-break: break-word;
}

.marginalia--left .marg-line { transform: translateX(6px); }

/* skeleton-state placeholders ("blocked-out copy") */
.marg-skeleton {
    --w: 70%;
    display: block;
    height: 10px;
    width: var(--w);
    background: linear-gradient(
        90deg,
        rgba(107, 99, 86, 0.35) 0%,
        rgba(107, 99, 86, 0.20) 60%,
        rgba(107, 99, 86, 0.30) 100%
    );
    border-radius: 0;
    margin-bottom: 6px;
    transition:
        opacity 540ms var(--ease-quarto) var(--stagger, 0ms),
        transform 540ms var(--ease-quarto) var(--stagger, 0ms);
}

.marginalia--left .marg-skeleton {
    margin-left: auto;
}

/* When the leaf is "read" (revealed), marginalia inks in and skeletons fade out. */
.leaf.is-revealed .marginalia .marg-icon,
.leaf.is-revealed .marginalia .marg-line {
    opacity: 1;
    transform: translateX(0);
}

.leaf.is-revealed .marginalia .marg-skeleton {
    opacity: 0;
    transform: translateX(-6px);
}

/* ==========================================================================
   Frontispiece leaf
   ========================================================================== */

.leaf--frontispiece {
    min-height: 100vh;
    padding-top: 132px;
    padding-bottom: 96px;
    background-color: var(--paper);
}

.leaf-body--center {
    grid-column: 2 / 3;
    text-align: center;
    position: relative;
    padding-top: 28px;
}

.wordmark {
    font-family: var(--mono);
    font-weight: 600;
    font-size: 56px;
    line-height: 1.1;
    letter-spacing: -0.012em;
    color: var(--ink);
    text-transform: lowercase;
    margin-top: 4px;
    margin-bottom: 24px;
    cursor: crosshair;
}

.frontispiece-quote {
    font-family: var(--serif-guest);
    font-style: italic;
    font-weight: 300;
    font-size: 32px;
    line-height: 1.4;
    color: var(--ink-2);
    margin-bottom: 28px;
}

.frontispiece-quote em {
    font-style: italic;
}

.frontispiece-sub {
    max-width: 36rem;
    margin: 0 auto;
    color: var(--ink-2);
    font-size: 15px;
    line-height: 1.85;
    letter-spacing: 0.005em;
}

.dropcap {
    position: absolute;
    top: -28px;
    left: -8px;
    font-family: var(--mono);
    font-weight: 600;
    font-size: 6.4em;
    line-height: 1;
    color: var(--ember);
    opacity: 0.92;
    pointer-events: none;
    user-select: none;
    text-transform: uppercase;
}

/* ==========================================================================
   Reading list — hanging indents, dotted leaders to year column
   ========================================================================== */

.reading-intro {
    margin-bottom: 28px;
    color: var(--ink-2);
}

.reading-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.reading-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    column-gap: 14px;
    align-items: baseline;
    padding: 10px 0;
    border-bottom: 1px dotted rgba(31, 26, 20, 0.18);
    position: relative;
}

.reading-list li:first-child {
    border-top: 1px dotted rgba(31, 26, 20, 0.18);
}

.r-title {
    color: var(--ink);
    padding-left: 22px;
    text-indent: -22px;
    text-transform: lowercase;
}

.r-leader {
    /* invisible spacer; the dotted bottom-border carries the leader */
    display: none;
}

.r-author {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    color: var(--ink-2);
    font-size: 13px;
    text-transform: lowercase;
    white-space: nowrap;
}

.r-year {
    font-family: var(--mono-margin);
    font-weight: 300;
    color: var(--mid);
    font-size: 13px;
    min-width: 4ch;
    text-align: right;
    letter-spacing: 0.03em;
}

.r-title-inline {
    text-decoration: none;
    color: var(--ink);
}

/* ==========================================================================
   Journal entries (§ 03)
   ========================================================================== */

.journal {
    margin-top: 32px;
}

.journal:first-of-type {
    margin-top: 12px;
}

.ornament {
    display: inline-block;
    font-family: var(--serif-guest);
    color: var(--ember);
    font-size: 18px;
    line-height: 1;
    margin-right: 10px;
    vertical-align: middle;
}

.entry-date {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    color: var(--mid);
    font-size: 12.5px;
    margin-bottom: 6px !important;
    text-transform: lowercase;
    letter-spacing: 0.02em;
    display: inline-block;
}

/* ==========================================================================
   Tools-of-the-desk stanzas (§ 04)
   ========================================================================== */

.stanza {
    margin-top: 28px;
}

.stanza:first-of-type {
    margin-top: 8px;
}

.stanza-name {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--ink);
    font-size: 14.5px;
    margin-bottom: 4px !important;
    letter-spacing: 0.01em;
    text-transform: lowercase;
}

/* ==========================================================================
   Letter (§ 05) — half-typed, fades into skeleton lines
   ========================================================================== */

.letter {
    background: rgba(255, 255, 255, 0.18);
    border-left: 1px solid rgba(31, 26, 20, 0.12);
    padding: 18px 26px;
    margin-top: 8px;
}

.letter-date {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    color: var(--mid);
    text-transform: lowercase;
    margin-bottom: 18px !important;
    font-size: 12.5px;
}

.salutation {
    font-style: italic;
    color: var(--ink);
    margin-bottom: 10px !important;
}

.fade-letter {
    margin-top: 1.2em;
    margin-bottom: 0;
}

.ghost-line {
    display: block;
    height: 11px;
    background: linear-gradient(
        90deg,
        rgba(107, 99, 86, 0.32) 0%,
        rgba(107, 99, 86, 0.18) 70%,
        rgba(107, 99, 86, 0.10) 100%
    );
}

.ghost-line--1 { width: 88%; }
.ghost-line--2 { width: 64%; opacity: 0.78; }
.ghost-line--3 { width: 42%; opacity: 0.58; }
.ghost-line--4 { width: 22%; opacity: 0.36; }

/* ==========================================================================
   Errata (§ 06)
   ========================================================================== */

.errata {
    color: var(--ink-2);
    font-style: normal;
}

.errata::before {
    content: "errata —";
    font-family: var(--mono-margin);
    font-style: italic;
    color: var(--ember);
    margin-right: 8px;
    text-transform: lowercase;
    font-size: 11.5px;
    vertical-align: 1px;
    letter-spacing: 0.03em;
}

/* ==========================================================================
   Colophon leaf — bottom-right corner only
   ========================================================================== */

.leaf--colophon {
    min-height: 70vh;
    background-color: var(--paper-2);
    padding-bottom: 64px;
}

.leaf-body--colophon {
    grid-column: 2 / 4;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    min-height: 50vh;
}

.colophon {
    max-width: 26rem;
    text-align: right;
    margin-top: auto;
    margin-left: auto;
    padding-top: 24px;
}

.colophon .pressed-rule {
    margin-bottom: 18px;
    justify-content: flex-end;
}

.colophon .pressed-rule .rule-line {
    max-width: 160px;
}

.colophon-text {
    font-family: var(--mono-margin);
    font-style: italic;
    font-weight: 300;
    color: var(--ink-2);
    font-size: 11.5px;
    line-height: 1.7;
    text-transform: lowercase;
    letter-spacing: 0.01em;
}

.colophon-text em {
    color: var(--ember);
    font-style: italic;
}

.colophon-mark {
    font-family: var(--mono-margin);
    color: var(--mid);
    font-size: 11px;
    margin-top: 14px;
    letter-spacing: 0.04em;
}

.marginalia--colophon {
    align-self: flex-start;
}

/* ==========================================================================
   Single-word ember underline — exactly one word per leaf
   ========================================================================== */

em[data-ember] {
    font-style: normal;
    color: var(--ink);
    position: relative;
    display: inline-block;
    padding-bottom: 1px;
    cursor: crosshair;
}

em[data-ember]::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -1px;
    width: 0;
    height: 2px;
    background: var(--ember);
    transition: width 220ms var(--ease-quarto);
    pointer-events: none;
}

em[data-ember]:hover::after,
em[data-ember].is-lit::after {
    width: 100%;
}

/* ==========================================================================
   Scroll-progress page-turn — applied via JS to the *previous* leaf
   ========================================================================== */

.leaf.is-flipping {
    transform: translateY(-16px) rotate(1.4deg);
    opacity: 0.36;
}

.leaf.is-back {
    /* leaf that the reader has scrolled well past — keeps subtle dimming */
    opacity: 0.5;
}

/* ==========================================================================
   Crosshair cursor only over body region
   ========================================================================== */

.almanac,
.leaf,
.marginalia {
    cursor: default;
}

/* ==========================================================================
   Responsive — collapse marginalia gracefully but keep the spirit
   ========================================================================== */

@media (max-width: 1024px) {
    .leaf {
        grid-template-columns: 8rem minmax(0, 1fr) 8rem;
        padding: 72px 56px;
    }
    .leaf-body { max-width: none; }
    .wordmark { font-size: 44px; }
    .frontispiece-quote { font-size: 26px; }
}

@media (max-width: 760px) {
    .almanac { padding: 28px 14px 64px 14px; }
    .leaf {
        grid-template-columns: 1fr;
        padding: 56px 24px;
        min-height: auto;
    }
    .leaf-body,
    .leaf-body--center,
    .leaf-body--colophon {
        grid-column: 1 / -1;
    }
    .marginalia {
        grid-column: 1 / -1;
        text-align: left;
        align-items: flex-start;
        padding-top: 0;
        margin-top: 24px;
        order: 2;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }
    .marginalia--left { text-align: left; align-items: flex-start; }
    .marginalia .marg-icon { margin-bottom: 0; }
    .marginalia .marg-line { max-width: 100%; }
    .marginalia--colophon { order: 0; }
    .leaf-body--colophon { justify-content: flex-start; }
    .colophon { text-align: left; max-width: 100%; }
    .colophon .pressed-rule { justify-content: flex-start; }
    .wordmark { font-size: 36px; }
    .frontispiece-quote { font-size: 22px; }
    .dropcap { font-size: 4.4em; top: -16px; left: -2px; }
    .reading-list li {
        grid-template-columns: 1fr;
        row-gap: 2px;
    }
    .r-author { font-size: 12px; }
    .r-year { text-align: left; }
}

/* ==========================================================================
   Reduced motion — page-turn becomes opacity dissolve only;
   skeletons resolve on viewport entry without stagger;
   ember underline appears instantly.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        --stagger: 0ms !important;
    }
    .leaf {
        transition: opacity 200ms linear, background-color 200ms linear;
    }
    .leaf.is-flipping,
    .leaf.is-turned {
        transform: none;
        opacity: 0.5;
    }
    .marginalia .marg-icon,
    .marginalia .marg-line,
    .marg-skeleton {
        transition: opacity 200ms linear, transform 200ms linear;
    }
    em[data-ember]::after {
        transition: width 0ms linear;
    }
}
