/* =========================================================================
   Concepts — editorial scrollytelling, academic treatment.

   Serif headings on warm off-white paper, numbered sections, and a
   restrained hairline rule system. Footnotes are click-to-open, recursively
   nestable popovers that tint deeper with each level.
   ========================================================================= */

:root {
    --paper: #faf8f2;        /* warm off-white "paper" */
    --ink: #1a1715;          /* warm near-black */
    --ink-body: #2b2622;     /* slightly softened body ink */
    --ink-soft: #6b6258;     /* warm grey for secondary / chrome text */
    --line: #e4ded1;         /* the single hairline colour */
    --placeholder: #ede8dd;  /* warm neutral image-panel fallback */

    /* Footnote accent — a muted sienna that sits on warm paper */
    --accent: #9c4a2f;
    --accent-strong: #7d3a23;
    --accent-weak: rgba(156, 74, 47, 0.10);
    --highlight: #f6e6a8;    /* ==highlight== ground */

    /* Popover depth tints: white card stepping progressively warmer */
    --fn-1: #ffffff;
    --fn-2: #fdf8f1;
    --fn-3: #faf2e6;
    --fn-4: #f5ebdb;
    --fn-5: #efe2cf;
    --fn-6: #e8d9c2;

    --serif: Georgia, "Iowan Old Style", "Palatino Linotype",
             "Times New Roman", serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

    --reading-measure: 34rem;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--paper);
    color: var(--ink-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

/* ---------- Shared scholarly chrome ------------------------------------- */

.site-byline {
    margin: 0.85rem 0 0;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--ink-soft);
}

/* ---------- Landing page ------------------------------------------------ */

.site-header {
    max-width: 52rem;
    margin: 0 auto;
    padding: 7rem 2rem 2rem;
    border-bottom: 1px solid var(--line);
}

.site-title {
    font-family: var(--serif);
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 0.5rem;
    color: var(--ink);
}

.site-subtitle {
    font-size: 1.15rem;
    color: var(--ink-soft);
    margin: 0.85rem 0 0;
}

.landing {
    max-width: 52rem;
    margin: 0 auto;
    padding: 0.5rem 2rem 8rem;
}

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

.concept-card {
    border-bottom: 1px solid var(--line);
}

.concept-card-link {
    display: grid;
    grid-template-columns: 2.5rem 1fr;
    grid-template-areas:
        "num title"
        "num meta";
    column-gap: 1.5rem;
    align-items: baseline;

    padding: 1.6rem 0.25rem;
    text-decoration: none;
    color: var(--ink);
    transition: padding-left 0.25s ease;
}

.concept-card-link:hover,
.concept-card-link:focus {
    padding-left: 0.9rem;
}

.card-number {
    grid-area: num;
    font-family: var(--serif);
    font-size: 1.1rem;
    color: var(--ink-soft);
    letter-spacing: 0.02em;
}

.card-title {
    grid-area: title;
    font-family: var(--serif);
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.concept-card-link:hover .card-title,
.concept-card-link:focus .card-title {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.card-meta {
    grid-area: meta;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--ink-soft);
}

.concept-empty {
    padding: 1.6rem 0.25rem;
    color: var(--ink-soft);
    list-style: none;
}

/* ---------- Concept header ---------------------------------------------- */

.concept-header {
    max-width: 1400px;
    margin: 0 auto;
    padding: 3rem 4rem 1.5rem;
    border-bottom: 1px solid var(--line);
}

.back-link {
    display: inline-block;
    font-size: 0.95rem;
    color: var(--ink-soft);
    text-decoration: none;
    margin-bottom: 1.5rem;
    transition: color 0.2s ease;
}

.back-link:hover,
.back-link:focus {
    color: var(--ink);
}

.concept-title {
    font-family: var(--serif);
    font-size: clamp(2rem, 5vw, 3.25rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--ink);
}

.concept-meta {
    margin: 0.4rem 0 0;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

/* ---------- Scrolly layout (left text, right sticky image) -------------- */

#scrolly {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
}

.text {
    width: 45%;
    padding: 0 4rem;
}

.step {
    min-height: 100vh;

    display: flex;
    flex-direction: column;
    justify-content: center;

    max-width: var(--reading-measure);

    opacity: 0.3;
    transition: opacity 0.4s ease;
}

.step.is-active {
    opacity: 1;
}

/* Numbered section label with a short hairline above it. */
.step-number {
    font-family: var(--serif);
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    margin: 0 0 0.9rem;
}

.step-number::before {
    content: "";
    display: block;
    width: 2.5rem;
    height: 1px;
    background: var(--line);
    margin-bottom: 1.1rem;
}

.step h2 {
    font-family: var(--serif);
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 1.25rem;
    color: var(--ink);
}

/* ---------- Body rich text (shared inline styles) ----------------------- */

.step-body p {
    font-size: 1.15rem;
    line-height: 1.75;
    margin: 0 0 1.15rem;
    color: var(--ink-body);
}

.step-body p:last-child {
    margin-bottom: 0;
}

.step-body ul,
.step-body ol {
    font-size: 1.12rem;
    line-height: 1.7;
    margin: 0 0 1.15rem 1.4rem;
    padding: 0;
    color: var(--ink-body);
}

.step-body li {
    margin-bottom: 0.4rem;
}

.step-body a {
    color: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.step-body a:hover {
    color: var(--accent);
}

/* Inline marks shared by prose and popovers */
strong { font-weight: 700; }
em { font-style: italic; }
mark {
    background: var(--highlight);
    color: inherit;
    padding: 0 0.1em;
    border-radius: 2px;
}

/* ---------- Footnote references (clickable superscript numbers) --------- */

/* Shared interactive bits for both kinds of reference */
.fn-ref {
    cursor: pointer;
    border-radius: 3px;
}

.fn-ref:focus { outline: none; }
.fn-ref:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Bare reference: the superscript number is the whole target */
.fn-bare {
    font-family: var(--sans);
    font-size: 0.72em;
    font-weight: 700;
    vertical-align: super;
    line-height: 0;
    color: var(--accent);
    padding: 0 0.18em;
    display: inline-block;
    transition: color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.fn-bare:hover,
.fn-bare:focus-visible {
    color: var(--accent-strong);
    transform: scale(1.12);
}

.fn-bare.active {
    color: var(--accent-strong);
    background: var(--accent-weak);
}

/* Phrase-anchored reference: the phrase + its number form one hover/click
   unit. Hovering either part recolours the phrase and grows the number
   (the number scales, the phrase does not, so the line never reflows). */
.fn-anchored {
    color: inherit;
    transition: color 0.15s ease;
}

.fn-anchored:hover,
.fn-anchored:focus-visible {
    color: var(--accent-strong);
}

.fn-anchored.active {
    color: var(--accent-strong);
}

.fn-anchored .fn-num {
    font-family: var(--sans);
    font-size: 0.72em;
    font-weight: 700;
    vertical-align: super;
    line-height: 0;
    color: var(--accent);
    margin-left: 1px;
    display: inline-block;
    transition: color 0.15s ease, transform 0.15s ease;
}

.fn-anchored:hover .fn-num,
.fn-anchored:focus-visible .fn-num {
    color: var(--accent-strong);
    transform: scale(1.12);
}

.fn-anchored.active .fn-num {
    color: var(--accent-strong);
}

/* ---------- Footnote popovers ------------------------------------------- */

.fn-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(42, 32, 24, 0.06);
    z-index: 49;
}

.fn-scrim.active {
    display: block;
}

.fn-popover {
    position: absolute;
    width: 360px;
    max-width: min(360px, 90vw);
    max-height: 320px;

    display: flex;
    flex-direction: column;
    overflow: hidden;

    background: var(--fn-1);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(42, 32, 24, 0.16),
                0 2px 8px rgba(42, 32, 24, 0.08);

    animation: fnPop 0.16s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.fn-popover.closing {
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 0.14s ease, transform 0.14s ease;
    pointer-events: none;
}

.fn-popover.depth-1 { background: var(--fn-1); }
.fn-popover.depth-2 { background: var(--fn-2); }
.fn-popover.depth-3 { background: var(--fn-3); }
.fn-popover.depth-4 { background: var(--fn-4); }
.fn-popover.depth-5 { background: var(--fn-5); }
.fn-popover.depth-6 { background: var(--fn-6); }

@keyframes fnPop {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}

/* Pointer arrow (inherits the popover's depth tint) */
.fn-arrow {
    position: absolute;
    width: 14px;
    height: 14px;
    background: inherit;
    border: 1px solid var(--line);
    transform: rotate(45deg);
    z-index: -1;
}

.fn-arrow.arrow-down {
    bottom: -7px;
    border-top: none;
    border-left: none;
}

.fn-arrow.arrow-up {
    top: -7px;
    border-bottom: none;
    border-right: none;
}

.fn-pop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.7rem 0.4rem;
    border-bottom: 1px solid var(--line);
    background: inherit;
    flex-shrink: 0;
}

.fn-pop-num {
    font-family: var(--sans);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--accent);
    background: var(--accent-weak);
    padding: 0.08rem 0.42rem;
    border-radius: 3px;
}

.fn-close {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    transition: background 0.12s ease, color 0.12s ease;
}

.fn-close:hover,
.fn-close:focus-visible {
    background: var(--accent);
    color: #fff;
}

.fn-close:focus { outline: none; }
.fn-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.fn-pop-body {
    padding: 0.6rem 0.85rem 0.75rem;
    font-family: var(--serif);
    font-size: 0.92rem;
    line-height: 1.62;
    color: var(--ink-body);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    overscroll-behavior: contain;
}

.fn-pop-body p { margin: 0 0 0.6rem; }
.fn-pop-body p:last-child { margin-bottom: 0; }

.fn-pop-body ul,
.fn-pop-body ol {
    margin: 0.35rem 0 0.6rem 1.1rem;
    padding: 0;
}

.fn-pop-body li { margin-bottom: 0.25rem; }

.fn-pop-body a {
    color: var(--accent-strong);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.fn-pop-body a:hover { color: var(--accent); }

.fn-pop-body::-webkit-scrollbar { width: 6px; }
.fn-pop-body::-webkit-scrollbar-thumb {
    background: var(--accent-weak);
    border-radius: 3px;
}

/* One-time hint toast */
.fn-hint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 300px;
    background: var(--ink);
    color: #fff;
    font-family: var(--sans);
    font-size: 0.82rem;
    line-height: 1.5;
    text-align: center;
    padding: 0.8rem 1.3rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    z-index: 9000;
    animation: fnPop 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.fn-hint.out {
    opacity: 0;
    transition: opacity 0.4s ease;
}

/* ---------- Sticky graphic --------------------------------------------- */

.graphic {
    width: 55%;
    height: 100vh;

    position: sticky;
    top: 0;

    overflow: hidden;
    background: var(--placeholder);
}

.graphic-image {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;
    object-fit: cover;

    opacity: 0;
    transition: opacity 0.7s ease;
}

.graphic-image.active {
    opacity: 1;
}

/* A failed image leaves the neutral panel background visible. */
.graphic-image-missing {
    background: var(--placeholder);
}

/* ---------- Error page -------------------------------------------------- */

.error-page {
    max-width: 40rem;
    margin: 0 auto;
    padding: 8rem 2rem;
    text-align: center;
}

.error-page h2 {
    font-family: var(--serif);
    font-size: 1.8rem;
    margin: 0 0 1rem;
    color: var(--ink);
}

.error-page p {
    color: var(--ink-soft);
    margin: 0 0 2rem;
}

/* ---------- Mobile: image on top, text below --------------------------- */

@media (max-width: 900px) {
    .concept-header {
        padding: 2rem 1.5rem 1rem;
    }

    #scrolly {
        flex-direction: column;
    }

    .graphic {
        width: 100%;
        height: 55vh;
        order: 1;
        top: 0;
        z-index: 1; /* keep the image panel above text so faded steps never bleed over it during transitions */
    }

    .text {
        width: 100%;
        padding: 0 1.5rem;
        order: 2;
    }

    .step {
        min-height: 85vh;
        max-width: none;
    }
}

@media (max-width: 600px) {
    /* Larger tap target for the bare superscript ref on touch screens
       (anchored phrases are already large enough to tap). */
    .fn-bare {
        padding: 0.25em 0.3em;
    }
}
