/* ───────────────────────────────────────────────────────────────────
   RESET + BASELINE
   ─────────────────────────────────────────────────────────────────── */

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

html {
    background: var(--bg);
    color-scheme: dark;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    margin: 0;
    background: var(--bg);
    background-image: var(--bg-glow);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: 1.6;
    overflow-x: hidden;
}

img { max-width: 100%; display: block; }

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

ul, ol { list-style: none; padding: 0; margin: 0; }

h1, h2, h3, h4, p { margin: 0; }

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

/* Focus ring */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
    border-radius: 2px;
}

/* ───────────────────────────────────────────────────────────────────
   FILM-GRAIN OVERLAY (subtle paper texture for the dark editorial feel)
   ─────────────────────────────────────────────────────────────────── */
.grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.06;
    mix-blend-mode: overlay;
    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 values='0 0 0 0 1   0 0 0 0 1   0 0 0 0 1   0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ───────────────────────────────────────────────────────────────────
   TOP NAVIGATION (single fixed bar, anchor links)
   ─────────────────────────────────────────────────────────────────── */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem var(--gutter);
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
    background: linear-gradient(to bottom, rgba(12, 11, 9, 0.9), rgba(12, 11, 9, 0.55) 70%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.topnav .mark {
    color: var(--ink);
    font-weight: 500;
    letter-spacing: 0.18em;
    transition: color 0.3s var(--ease-out);
}

.topnav .mark:hover { color: var(--accent); }

.topnav ul {
    display: flex;
    gap: clamp(1.25rem, 3vw, 2.5rem);
}

.topnav ul a {
    position: relative;
    padding: 0.25rem 0;
    transition: color 0.3s var(--ease-out);
}

.topnav ul a::before {
    content: "·";
    margin-right: 0.5rem;
    color: var(--ink-faint);
}

.topnav ul a::after {
    content: "";
    position: absolute;
    left: 0.85rem;
    right: 0;
    bottom: 0;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s var(--ease-out);
}

.topnav ul a:hover { color: var(--ink); }
.topnav ul a:hover::after { transform: scaleX(1); }

.topnav ul a.is-active { color: var(--accent); }
.topnav ul a.is-active::before { color: var(--accent); }
.topnav ul a.is-active::after { transform: scaleX(1); }

/* Mobile: collapse to a 2-line strip */
@media (max-width: 640px) {
    .topnav { padding: 0.85rem 1.25rem; }
    .topnav ul { gap: 1rem; font-size: var(--step--2); }
    .topnav ul a::before { display: none; }
}

/* ───────────────────────────────────────────────────────────────────
   SHARED ATOMS
   ─────────────────────────────────────────────────────────────────── */

.shell {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 var(--gutter);
    position: relative;
    z-index: 2;
}

/* Anchor targets clear the fixed topnav when scrolled to */
section[id], header[id] {
    scroll-margin-top: clamp(60px, 10vh, 100px);
}

.mono {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-muted);
}

.rule { border-top: 1px solid var(--rule); }

/* Section heading: §0X · TITLE · subtitle */
.section-head {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: end;
    gap: clamp(1rem, 3vw, 2rem);
    padding-bottom: 1.75rem;
    margin-bottom: clamp(2.5rem, 5vw, 4rem);
    border-bottom: 1px solid var(--rule);
}

.section-head .section-num {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    color: var(--accent);
    letter-spacing: 0.05em;
    align-self: end;
    padding-bottom: 0.4rem;
}

.section-head h2 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: var(--step-3);
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.section-head .section-sub {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    color: var(--ink-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: right;
    align-self: end;
    padding-bottom: 0.4rem;
    max-width: 18rem;
}

@media (max-width: 720px) {
    .section-head {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
    }
    .section-head .section-sub {
        grid-column: 1 / -1;
        text-align: left;
        padding: 0.5rem 0 0;
        max-width: none;
    }
}

/* Reveal-on-scroll (set on <body> until JS upgrades) */
.reveal {
    opacity: 0;
    transform: translateY(18px);
    transition:
        opacity 0.9s var(--ease-out),
        transform 0.9s var(--ease-out);
    transition-delay: var(--reveal-delay, 0ms);
}

.reveal.is-visible {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .reveal { opacity: 1; transform: none; transition: none; }
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
