/* ===========================
   THERMITE — v5 TRANSMISSION
   
   Same signal as The Lobster Pot.
   Different carrier. Light instead of dark.
   Photographic negative.
   
   The music AND the math AND
   the phonograph instructions.
   =========================== */

/* === CASCADE ARCHITECTURE === */

@layer base, layout, tufte, components;

/* === TYPED CUSTOM PROPERTIES === */

@property --accent-l {
    syntax: '<number>';
    inherits: true;
    initial-value: 0.55;
}

/* === BASE === */

@layer base {
    :root {
        /* Inverted carrier — light ground */
        --bg: oklch(0.99 0.005 90);
        --fg: oklch(0.12 0.01 60);
        --dim: oklch(0.55 0.01 60);
        --rule: oklch(0.88 0.005 90);

        /* Thermite accent — fire */
        --accent: oklch(0.55 0.2 40);

        /* Two voices */
        --serif: Palatino, 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
        --mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', Consolas, monospace;

        /* Scale */
        --monument: clamp(2rem, 5vw, 4rem);
        --human: 1rem;
        --small: 0.75rem;

        /* Layout containment */
        --max-body: 1400px;
        --gutter: clamp(1.25rem, 3vw, 3rem);
        --content-measure: 65ch;
        --margin-width: 33%;

        --lh: 1.6;
    }

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

    html {
        overflow-x: hidden;
    }

    body {
        font-family: var(--serif);
        font-size: var(--human);
        background: var(--bg);
        color: var(--fg);
        line-height: var(--lh);
        -webkit-font-smoothing: antialiased;
        text-rendering: optimizeLegibility;
        overflow-x: hidden;
    }

    /* Machine voice */
    code, pre, .colophon, .site-nav,
    .home-inscription, .doc-header time {
        font-family: var(--mono);
    }

    ::selection { background: var(--accent); color: var(--bg); }

    a { color: inherit; }

    h1, h2, h3 { text-wrap: balance; }
}

/* === LAYOUT === */

@layer layout {
    /* Navigation — persistent strip */
    .site-nav {
        display: flex;
        align-items: baseline;
        gap: 2rem;
        padding: 1rem 0;
        border-bottom: 1px solid var(--rule);
        font-family: var(--mono);
        font-size: var(--small);
        text-transform: uppercase;
        letter-spacing: 0.1em;
        z-index: 100;
    }

    .nav-mark {
        font-weight: 700;
        text-decoration: none;
        color: var(--fg);
        white-space: nowrap;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 1.5rem;
        align-items: baseline;
    }

    .nav-links a {
        text-decoration: none;
        color: var(--fg-dim);
    }

    .nav-links a:hover {
        color: var(--fg);
    }

    /* Homepage — generative canvas */
    .home {
        position: relative;
        min-height: 100vh;
        overflow: hidden;
    }

    .home-canvas {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 0;
    }

    .home-canvas canvas {
        display: block;
        width: 100%;
        height: 100%;
    }

    /* body.home is display:flex centering container — inscription is a child */
    .home {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
    }

    .home-inscription {
        position: relative;
        z-index: 1;
        width: min(var(--max-body, 1400px), 100%);
        padding: 0 var(--gutter, 2rem) 3rem;
    }

    .home-inscription h1 {
        font-size: var(--small);
        font-weight: 400;
        text-transform: uppercase;
        letter-spacing: 0.15em;
        color: var(--fg);
        margin-bottom: 0.25rem;
    }

    .home-sub {
        font-family: var(--serif);
        font-size: var(--small);
        font-style: italic;
        color: var(--dim);
        margin-bottom: 1rem;
    }

    .home-inscription nav {
        display: flex;
        gap: 2rem;
    }

    .home-inscription nav a {
        font-size: var(--small);
        text-transform: uppercase;
        letter-spacing: 0.1em;
        text-decoration: none;
        color: var(--dim);
    }
}

/* === TUFTE LAYER === */

@layer tufte {
    /* GRID LAYOUT ENGINE — body IS the layout component */
    body {
        display: grid;
        grid-template-columns:
            minmax(var(--gutter), 1fr)
            min(var(--max-body), 100% - var(--gutter) * 2)
            minmax(var(--gutter), 1fr);
        grid-template-rows: auto 1fr auto;
        min-height: 100vh;
    }

    body > * { grid-column: 2; }

    /* Homepage: override grid to flex — canvas is fixed, inscription centered */
    body.home {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        min-height: 100vh;
        overflow: hidden;
    }

    .doc-container {
        padding: 6rem 0 4rem;
    }

    .doc-header {
        max-width: var(--content-measure);
        margin-bottom: 3rem;
    }

    .doc-header h1 {
        font-family: var(--serif);
        font-size: var(--monument);
        font-weight: 400;
        font-style: italic;
        line-height: 1.15;
    }

    .doc-body {
        max-width: var(--content-measure);
        position: relative;
        counter-reset: sidenote;
    }

    .doc-body p { margin-bottom: 1.4rem; }

    .doc-body h2 {
        font-family: var(--mono);
        font-size: var(--human);
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin: 3rem 0 1rem;
        padding-top: 1rem;
        border-top: 1px solid var(--rule);
    }

    .doc-body h3 {
        font-family: var(--serif);
        font-size: var(--human);
        font-weight: 700;
        font-style: italic;
        margin: 2rem 0 0.5rem;
    }

    .doc-body a {
        color: var(--accent);
        text-decoration: underline;
        text-decoration-color: var(--dim);
        text-underline-offset: 0.15em;
    }

    .doc-body ul, .doc-body ol {
        margin: 1.4rem 0;
        padding-left: 1.5em;
    }

    .doc-body li { margin-bottom: 0.35rem; }

    .doc-body strong { font-weight: 700; }

    .doc-body em { font-style: italic; }

    .doc-body blockquote {
        border-left: 2px solid var(--accent);
        padding-left: 1.5rem;
        margin: 1.5rem 0;
        color: var(--dim);
        font-style: italic;
    }

    .doc-body blockquote p { margin: 0; }

    .doc-body code {
        font-family: var(--mono);
        font-size: 0.85em;
        background: oklch(0.95 0.005 90);
        padding: 0.1em 0.3em;
        border-radius: 2px;
    }

    .doc-body pre {
        font-family: var(--mono);
        padding: 1.2rem;
        overflow-x: auto;
        margin: 1.5rem 0;
        border: 1px solid var(--rule);
        font-size: 0.85rem;
        line-height: 1.5;
        background: oklch(0.97 0.003 90);
    }

    .doc-body pre code {
        background: none;
        padding: 0;
        border-radius: 0;
        font-size: inherit;
    }

    .doc-body img {
        max-width: 100%;
        margin: 1.5rem 0;
    }

    .doc-body hr {
        border: none;
        border-top: 1px solid var(--rule);
        margin: 2rem 0;
    }

    /* Sidenotes for docs — code examples, notes */
    .sidenote, .marginnote {
        float: right;
        clear: right;
        width: var(--margin-width);
        margin-right: calc(-1 * var(--margin-width) - 4%);
        font-family: var(--mono);
        font-size: var(--small);
        line-height: 1.5;
        color: var(--dim);
    }

    /* Colophon */
    .colophon {
        max-width: var(--content-measure);
        margin-top: 4rem;
        padding-top: 1rem;
        border-top: 1px solid var(--rule);
        font-family: var(--mono);
        font-size: var(--small);
        color: var(--dim);
        letter-spacing: 0.02em;
    }

    .colophon a {
        color: var(--accent);
        text-decoration: underline;
        text-decoration-color: var(--dim);
        text-underline-offset: 0.15em;
    }
}

/* === RESPONSIVE === */

@media (max-width: 900px) {
    :root {
        --margin-width: 0;
    }

    .sidenote, .marginnote {
        float: none;
        display: block;
        width: 100%;
        margin: 0.5rem 0 1rem;
        padding-left: 1.5rem;
        border-left: 1px solid var(--rule);
    }

    .home-inscription {
        padding: 0 1.5rem 2rem;
    }
}

@media (max-width: 640px) {
    :root {
        --human: 0.9375rem;
    }

    .home-inscription {
        padding: 0 1.25rem 1.5rem;
    }

    .home-inscription nav {
        flex-direction: column;
        gap: 0.5rem;
    }

    .site-nav {
        gap: 1rem;
        padding: 0.75rem 0;
    }

    .nav-links {
        gap: 1rem;
    }
}
