/* ==========================================================================
   lovable.dev — De Re Amabili
   chrome-bright Renaissance studio for software craft

   Type stack (per DESIGN.md):
     - Bricolage Grotesque (display, weights 200/500/800)
     - `Inter` 400/500 (body running text)
     - `JetBrains Mono` 400 (mono caption / sigil)
   Animation contract uses `IntersectionObserver` for chapter waypoint and
   plate-tape pin-on-view, plus requestAnimationFrame for particle drift.
   ========================================================================== */

:root {
    --vellum: #F4F6F9;
    --brushed-cloud: #D7DCE3;
    --steel-mid: #A8B0BC;
    --graphite: #5C6470;
    --foundry-ink: #1F2126;
    --raking-amber: #FFD9A0;
    --minium-red: #FF4438;

    --font-display: "Bricolage Grotesque", system-ui, sans-serif;
    --font-body: "Inter", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, monospace;

    --margin-outer: 96px;
    --col-gap: 24px;
    --baseline: 8px;
}

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

html, body {
    background: var(--vellum);
    color: var(--graphite);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.6;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    position: relative;
}

/* --------------------------------------------------------------------------
   Brushed-cloud scanline tile (used as a CSS background-image, not a gradient)
   -------------------------------------------------------------------------- */

.brushed-cloud-bg {
    background-color: var(--brushed-cloud);
    background-image: repeating-linear-gradient(
        0deg,
        rgba(31, 33, 38, 0.025) 0px,
        rgba(31, 33, 38, 0.025) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* --------------------------------------------------------------------------
   Particle dust canvas + raking amber sun-light
   -------------------------------------------------------------------------- */

#dust-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    pointer-events: none;
}

.raking-light {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(
            ellipse 60vw 50vh at 78% 22%,
            rgba(255, 217, 160, 0.18) 0%,
            rgba(255, 217, 160, 0.08) 28%,
            rgba(255, 217, 160, 0.0) 60%
        );
}

/* --------------------------------------------------------------------------
   Chapter rule (left vertical chrome navigation rule)
   -------------------------------------------------------------------------- */

.chapter-rule {
    position: fixed;
    top: 0;
    left: 36px;
    height: 100vh;
    width: 28px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.rule-line {
    position: absolute;
    top: 8vh;
    bottom: 8vh;
    left: 50%;
    width: 1px;
    background: linear-gradient(
        180deg,
        rgba(168, 176, 188, 0) 0%,
        rgba(168, 176, 188, 0.7) 6%,
        rgba(168, 176, 188, 0.95) 50%,
        rgba(168, 176, 188, 0.7) 94%,
        rgba(168, 176, 188, 0) 100%
    );
    transform: translateX(-50%);
}

.rule-tick {
    position: absolute;
    top: 8vh;
    left: 50%;
    width: 9px;
    height: 1px;
    background: var(--foundry-ink);
    transform: translateX(-50%);
    transition: top 600ms cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 0 0.5px rgba(168, 176, 188, 0.6);
}

.waypoints {
    position: absolute;
    top: 8vh;
    bottom: 8vh;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    list-style: none;
    pointer-events: auto;
}

.waypoint {
    position: relative;
    width: 28px;
    text-align: center;
}

.waypoint a {
    display: block;
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-decoration: none;
    background: var(--vellum);
    padding: 4px 0;
    transition: color 240ms ease;
}

.waypoint.active a {
    color: var(--foundry-ink);
}

.waypoint a:hover {
    color: var(--foundry-ink);
}

/* --------------------------------------------------------------------------
   Folio mark (top right)
   -------------------------------------------------------------------------- */

.folio-mark {
    position: fixed;
    top: 36px;
    right: 48px;
    z-index: 10;
    text-align: right;
    pointer-events: none;
}

.folio-line {
    display: block;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-transform: uppercase;
    line-height: 1.6;
}

/* --------------------------------------------------------------------------
   Treatise container
   -------------------------------------------------------------------------- */

.treatise {
    position: relative;
    z-index: 2;
    padding: 0 var(--margin-outer);
    padding-left: 132px;
    max-width: 1600px;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Chapter base
   -------------------------------------------------------------------------- */

.chapter {
    position: relative;
    min-height: 100vh;
    padding: 14vh 0 10vh;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: var(--col-gap);
    align-items: start;
}

.chapter-numeral {
    position: absolute;
    top: 4vh;
    left: -2vw;
    font-family: var(--font-display);
    font-weight: 200;
    font-size: 26vw;
    line-height: 0.85;
    letter-spacing: -0.04em;
    color: var(--brushed-cloud);
    z-index: 0;
    user-select: none;
    pointer-events: none;
    font-variation-settings: "opsz" 96;
    text-shadow:
        1px 0 0 rgba(168, 176, 188, 0.4),
        -1px 0 0 rgba(244, 246, 249, 0.6);
}

.chapter-numeral-right {
    left: auto;
    right: -2vw;
    text-align: right;
}

.chapter-header {
    position: relative;
    z-index: 2;
    grid-column: 1 / span 7;
    margin-bottom: 6vh;
}

.chapter-header-right {
    grid-column: 6 / span 7;
    text-align: right;
}

.chapter-eyebrow {
    font-family: var(--font-mono);
    font-size: 11.5px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.chapter-display {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(3rem, 7vw, 6.4rem);
    line-height: 0.92;
    letter-spacing: -0.035em;
    color: var(--foundry-ink);
    font-variation-settings: "opsz" 96;
    margin-bottom: 8px;
}

.chapter-translation {
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: clamp(1.1rem, 1.6vw, 1.4rem);
    color: var(--graphite);
    margin-bottom: 16px;
    font-variation-settings: "opsz" 48;
}

/* --------------------------------------------------------------------------
   Hairline rule (1px specular)
   -------------------------------------------------------------------------- */

.rule-hairline {
    height: 1px;
    width: 220px;
    background: linear-gradient(
        90deg,
        rgba(31, 33, 38, 0) 0%,
        rgba(31, 33, 38, 0.95) 50%,
        rgba(31, 33, 38, 0) 100%
    );
    margin: 16px 0;
}

.rule-hairline-right {
    margin-left: auto;
}

/* --------------------------------------------------------------------------
   Plate (figure block, brushed-cloud, brad-pinned, micro-tilted)
   -------------------------------------------------------------------------- */

.plate {
    position: relative;
    background-color: var(--brushed-cloud);
    background-image: repeating-linear-gradient(
        0deg,
        rgba(31, 33, 38, 0.028) 0px,
        rgba(31, 33, 38, 0.028) 1px,
        transparent 1px,
        transparent 2px
    );
    padding: 32px 28px 24px;
    z-index: 2;
    box-shadow:
        2px 4px 10px rgba(31, 33, 38, 0.07),
        0 0 0 1px rgba(168, 176, 188, 0.35);
    transform-origin: bottom left;
    transform: rotate(0deg);
    transition: transform 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

.plate.is-pinned {
    /* Tilt is applied via inline style by JS using --target-tilt */
    transform: rotate(var(--target-tilt, 0deg));
}

@media (prefers-reduced-motion: reduce) {
    .plate {
        transition: none;
        transform: rotate(var(--target-tilt, 0deg));
    }
}

.plate-anchor-left {
    grid-column: 1 / span 8;
    margin-top: 6vh;
}

.plate-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-transform: uppercase;
    margin-bottom: 14px;
}

/* --------------------------------------------------------------------------
   Brad (chrome polished disc, top-left of each plate)
   -------------------------------------------------------------------------- */

.brad {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: radial-gradient(
        circle at 35% 35%,
        #f4f6f9 0%,
        #d7dce3 28%,
        #a8b0bc 70%,
        #5c6470 100%
    );
    box-shadow:
        0 1px 2px rgba(31, 33, 38, 0.18),
        inset 0 0 0 0.5px rgba(31, 33, 38, 0.3);
    z-index: 3;
}

.brad-spec {
    position: absolute;
    top: 1px;
    left: 1.5px;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    background: rgba(244, 246, 249, 0.95);
    transition: width 480ms cubic-bezier(0.22, 1, 0.36, 1),
                height 480ms cubic-bezier(0.22, 1, 0.36, 1),
                top 480ms cubic-bezier(0.22, 1, 0.36, 1),
                left 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

.brad.is-near .brad-spec {
    width: 4px;
    height: 4px;
    top: 0.5px;
    left: 1px;
    background: rgba(255, 217, 160, 0.95);
}

@media (prefers-reduced-motion: reduce) {
    .brad-spec {
        transition: none;
    }
    .brad.is-near .brad-spec {
        width: 2px;
        height: 2px;
        top: 1px;
        left: 1.5px;
        background: rgba(244, 246, 249, 0.95);
    }
}

/* --------------------------------------------------------------------------
   Tape (architect's amber tape, applied to one plate per chapter)
   -------------------------------------------------------------------------- */

.tape {
    position: absolute;
    top: -10px;
    right: 14px;
    width: 78px;
    height: 24px;
    background-color: rgba(255, 217, 160, 0.7);
    background-image: repeating-linear-gradient(
        90deg,
        rgba(92, 100, 112, 0.07) 0px,
        rgba(92, 100, 112, 0.07) 1px,
        transparent 1px,
        transparent 4px
    );
    transform: rotate(22deg);
    z-index: 4;
    box-shadow: 0 1px 1px rgba(31, 33, 38, 0.06);
}

/* --------------------------------------------------------------------------
   Chapter I — De Principiis (wordmark)
   -------------------------------------------------------------------------- */

#chap-1 .plate-anchor-left {
    grid-column: 1 / span 9;
    --target-tilt: -1.4deg;
    padding: 64px 56px 56px;
}

.wordmark {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(4rem, 9vw, 12rem);
    line-height: 0.92;
    letter-spacing: -0.035em;
    color: var(--foundry-ink);
    font-variation-settings: "opsz" 96;
    margin-bottom: 18px;
}

.wordmark .amp {
    color: var(--minium-red);
    font-style: italic;
    font-weight: 500;
    font-variation-settings: "opsz" 96;
    padding: 0 0.04em;
}

.epigraph {
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: clamp(1.4rem, 2.4vw, 2.4rem);
    line-height: 1.25;
    color: var(--graphite);
    font-variation-settings: "opsz" 48;
    max-width: 30ch;
    margin-bottom: 12px;
}

.chapter-title {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(1.4rem, 2.2vw, 2rem);
    letter-spacing: -0.03em;
    color: var(--foundry-ink);
    font-variation-settings: "opsz" 96;
    margin-top: 16px;
}

.chapter-subtitle {
    font-family: var(--font-mono);
    font-size: 11.5px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-transform: uppercase;
    margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Marginalia (right-hanging or left-hanging italic notes)
   -------------------------------------------------------------------------- */

.marginalia {
    grid-column: 9 / span 4;
    margin-top: 20vh;
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: 1.1rem;
    line-height: 1.5;
    color: var(--graphite);
    font-variation-settings: "opsz" 48;
    position: relative;
    z-index: 2;
    padding-left: 16px;
    border-left: 1px solid var(--steel-mid);
}

.marginalia em {
    color: var(--foundry-ink);
    font-style: italic;
    font-weight: 500;
}

.marginalia-right {
    grid-column: 9 / span 4;
    margin-top: 22vh;
}

.marginalia-left {
    grid-column: 1 / span 4;
    margin-top: 6vh;
    border-left: none;
    padding-left: 0;
    border-right: 1px solid var(--steel-mid);
    padding-right: 16px;
    text-align: right;
}

.manicule {
    display: inline-block;
    width: 28px;
    height: 14px;
    margin-right: 6px;
    vertical-align: middle;
}

.manicule svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* --------------------------------------------------------------------------
   Chapter II — De Instrumentis (4-up plate stagger)
   -------------------------------------------------------------------------- */

.instrumenta-grid {
    grid-column: 1 / span 12;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: var(--col-gap);
    row-gap: 9vh;
    margin-top: 4vh;
}

.plate-instrumentum:nth-child(1) {
    grid-column: 1 / span 5;
    --target-tilt: -2.1deg;
    margin-top: 0;
}

.plate-instrumentum:nth-child(2) {
    grid-column: 7 / span 5;
    --target-tilt: 1.6deg;
    margin-top: 8vh;
}

.plate-instrumentum:nth-child(3) {
    grid-column: 2 / span 5;
    --target-tilt: -1.8deg;
}

.plate-instrumentum:nth-child(4) {
    grid-column: 8 / span 5;
    --target-tilt: 2.2deg;
    margin-top: 4vh;
}

.plate-figure {
    width: 100%;
    aspect-ratio: 1 / 1;
    margin: 8px 0 16px;
    background: var(--vellum);
    padding: 12px;
    border: 1px solid rgba(168, 176, 188, 0.4);
}

.plate-figure svg.anatomical {
    width: 100%;
    height: 100%;
    display: block;
}

.plate-name {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.6rem;
    letter-spacing: -0.025em;
    color: var(--foundry-ink);
    margin-bottom: 6px;
    font-variation-settings: "opsz" 48;
}

.plate-caption {
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--graphite);
    font-variation-settings: "opsz" 48;
}

#chap-2 .marginalia-left {
    grid-column: 1 / span 5;
    margin-top: 6vh;
}

/* --------------------------------------------------------------------------
   Chapter III — De Lovabilitate (full-bleed pull-quote)
   -------------------------------------------------------------------------- */

.thesis {
    grid-column: 1 / span 9;
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: clamp(2.4rem, 5.4vw, 6rem);
    line-height: 1.05;
    letter-spacing: -0.025em;
    color: var(--foundry-ink);
    font-variation-settings: "opsz" 96;
    margin-top: 4vh;
}

.thesis em {
    font-style: italic;
    font-weight: 500;
    color: var(--foundry-ink);
}

.marginalia-thesis {
    grid-column: 10 / span 3;
    margin-top: 18vh;
    border-left: none;
    padding-left: 0;
    position: relative;
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--graphite);
    font-variation-settings: "opsz" 48;
}

.connector-line {
    position: absolute;
    top: -10vh;
    left: -60px;
    width: 80px;
    height: 12vh;
    pointer-events: none;
    color: var(--graphite);
}

.connector-line svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* --------------------------------------------------------------------------
   Chapter IV — De Opificio (numbered tenets, switchback stagger)
   -------------------------------------------------------------------------- */

.tenets {
    grid-column: 1 / span 12;
    list-style: none;
    margin-top: 6vh;
    counter-reset: tenet;
    padding: 0;
}

.tenet {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    column-gap: var(--col-gap);
    align-items: baseline;
    padding: 18px 0;
    border-bottom: 1px solid rgba(168, 176, 188, 0.45);
    position: relative;
}

.tenet:last-child {
    border-bottom: none;
}

.tenet-numeral {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: clamp(2rem, 3.2vw, 3.4rem);
    line-height: 1;
    letter-spacing: -0.03em;
    color: var(--steel-mid);
    font-variation-settings: "opsz" 96;
    text-shadow:
        1px 0 0 rgba(168, 176, 188, 0.5),
        -1px 0 0 rgba(244, 246, 249, 0.7);
}

.tenet-body {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: clamp(1.05rem, 1.4vw, 1.4rem);
    line-height: 1.45;
    color: var(--foundry-ink);
}

.tenet-odd .tenet-numeral {
    grid-column: 1 / span 1;
    text-align: right;
}

.tenet-odd .tenet-body {
    grid-column: 2 / span 6;
}

.tenet-even .tenet-numeral {
    grid-column: 12 / span 1;
    text-align: left;
}

.tenet-even .tenet-body {
    grid-column: 6 / span 6;
    text-align: right;
}

/* --------------------------------------------------------------------------
   Chapter V — De Cosis Amabilibus (herbarium index cards)
   -------------------------------------------------------------------------- */

.herbarium {
    grid-column: 1 / span 12;
    list-style: none;
    margin-top: 4vh;
    padding: 0;
}

.exemplum {
    display: grid;
    grid-template-columns: 64px 1fr 180px;
    align-items: center;
    column-gap: 32px;
    padding: 22px 28px;
    background-color: var(--brushed-cloud);
    background-image: repeating-linear-gradient(
        0deg,
        rgba(31, 33, 38, 0.022) 0px,
        rgba(31, 33, 38, 0.022) 1px,
        transparent 1px,
        transparent 2px
    );
    margin-bottom: 14px;
    border-bottom: 1px solid rgba(168, 176, 188, 0.55);
    position: relative;
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.exemplum:hover {
    transform: translateX(2px);
}

.exemplum-glyph {
    width: 48px;
    height: 48px;
    display: block;
}

.exemplum-glyph svg {
    width: 100%;
    height: 100%;
    display: block;
}

.exemplum-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.1rem, 1.5vw, 1.6rem);
    color: var(--foundry-ink);
    letter-spacing: -0.02em;
    font-variation-settings: "opsz" 48;
    position: relative;
    padding-bottom: 4px;
    align-self: center;
}

.exemplum-name::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 64px;
    background: var(--raking-amber);
}

.exemplum-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.22em;
    color: var(--steel-mid);
    text-align: right;
    text-transform: uppercase;
}

#chap-5 .marginalia-right {
    grid-column: 9 / span 4;
    margin-top: 6vh;
}

/* --------------------------------------------------------------------------
   Chapter VI — Colophon
   -------------------------------------------------------------------------- */

.chapter-colophon {
    min-height: 90vh;
}

.colophon-body {
    grid-column: 4 / span 9;
    text-align: center;
    margin-top: 8vh;
}

.colophon-flourish {
    font-family: serif;
    font-size: 4rem;
    color: var(--minium-red);
    line-height: 1;
    margin-bottom: 24px;
}

.colofone-line {
    font-family: var(--font-mono);
    font-size: clamp(0.85rem, 1.1vw, 1.05rem);
    letter-spacing: 0.32em;
    color: var(--foundry-ink);
    text-transform: uppercase;
    margin-bottom: 18px;
}

.colofone-sub {
    font-family: var(--font-display);
    font-weight: 500;
    font-style: italic;
    font-size: 1.05rem;
    line-height: 1.5;
    color: var(--graphite);
    font-variation-settings: "opsz" 48;
    margin-bottom: 6px;
}

.colofone-foot {
    font-family: var(--font-mono);
    font-size: 10.5px;
    letter-spacing: 0.32em;
    color: var(--steel-mid);
    text-transform: uppercase;
    margin-top: 28px;
}

#chap-6 .rule-hairline {
    margin: 32px auto;
    width: 200px;
}

#chap-6 .chapter-header-right {
    grid-column: 1 / span 12;
    text-align: center;
}

#chap-6 .rule-hairline-right {
    margin-left: auto;
    margin-right: auto;
}

/* --------------------------------------------------------------------------
   Responsive — viewports below 960px commit marginalia to block under plate
   -------------------------------------------------------------------------- */

@media (max-width: 960px) {
    :root {
        --margin-outer: 32px;
    }

    .treatise {
        padding-left: 76px;
        padding-right: 32px;
    }

    .chapter-rule {
        left: 16px;
        width: 24px;
    }

    .folio-mark {
        right: 24px;
        top: 16px;
    }

    .folio-line {
        font-size: 9px;
    }

    .chapter {
        grid-template-columns: 1fr;
        padding: 12vh 0 8vh;
    }

    .chapter-numeral {
        font-size: 38vw;
        opacity: 0.6;
    }

    .chapter-header,
    .chapter-header-right,
    .plate-anchor-left,
    .thesis,
    .marginalia,
    .marginalia-thesis,
    .tenets,
    .herbarium,
    .colophon-body,
    .instrumenta-grid {
        grid-column: 1 / -1;
    }

    .chapter-header-right,
    .marginalia-left {
        text-align: left;
        border: none;
        padding: 0;
    }

    .rule-hairline-right {
        margin-left: 0;
    }

    .marginalia,
    .marginalia-right,
    .marginalia-left,
    .marginalia-thesis {
        margin-top: 4vh;
        border-left: 1px solid var(--steel-mid);
        padding-left: 16px;
        text-align: left;
        border-right: none;
        padding-right: 0;
    }

    .connector-line {
        display: none;
    }

    .instrumenta-grid {
        grid-template-columns: 1fr;
        row-gap: 4vh;
    }

    .plate-instrumentum:nth-child(n) {
        grid-column: 1 / -1;
        margin-top: 0;
        --target-tilt: 0deg;
    }

    .plate {
        --target-tilt: 0deg;
    }

    .tenet,
    .tenet-odd,
    .tenet-even {
        grid-template-columns: 64px 1fr;
    }

    .tenet-odd .tenet-numeral,
    .tenet-even .tenet-numeral {
        grid-column: 1 / span 1;
        text-align: right;
    }

    .tenet-odd .tenet-body,
    .tenet-even .tenet-body {
        grid-column: 2 / span 1;
        text-align: left;
    }

    .exemplum {
        grid-template-columns: 48px 1fr;
        row-gap: 4px;
        column-gap: 16px;
    }

    .exemplum-meta {
        grid-column: 2 / span 1;
        text-align: left;
    }
}
