/* ============================================================
   The Style Codex — fancy book theme for mdBook
   Offline-first: system font stacks only, no remote assets.
   Works with mdBook light and dark themes via CSS variables.

   Spec-driven: font, size, line height, and the accent color come
   from spec/config.yaml via the generated src/custom.css, which is
   loaded BEFORE this file (see book.toml). This theme only refines
   that baseline; --codex-accent derives from --primary-color.

   Opt-in classes (authored as raw HTML in the Markdown):
     .lead .kicker .pullquote .epigraph .initial .finis
     .callout.note|.tip|.warn|.danger   .aside-note
     .timeline   .tag(.gold|.green|.blue|.red)
     .twocol .figrid   .compact (table wrapper)
   ============================================================ */

:root {
    --codex-accent: var(--primary-color, #b8860b);
    --codex-accent-soft: color-mix(in srgb, var(--codex-accent) 12%, transparent);
    --codex-red: #b0413e;
    --codex-red-soft: rgba(176, 65, 62, 0.1);
}

/* Dark themes lighten the spec accent for contrast on dark paper */
.coal, .navy, .ayu {
    --codex-accent: color-mix(in srgb, var(--primary-color, #b8860b) 55%, #ffdf80);
    --codex-accent-soft: color-mix(in srgb, var(--codex-accent) 14%, transparent);
    --codex-red: #e0706c;
    --codex-red-soft: rgba(224, 112, 108, 0.12);
}

/* ---- Body typography: classic book feel ---- */
.content main {
    text-rendering: optimizeLegibility;
    hyphens: auto;
}

.content main ::selection {
    background: var(--codex-accent);
    color: #fff;
}

/* ---- Book chrome (sidebar, links: styled by generated custom.css) ---- */
.content main a.header:hover {
    color: var(--codex-accent);
    text-decoration: none;
}

/* ---- Chapter headings ---- */
.content main h1 {
    font-weight: 700;
    font-size: 2.6em;
    letter-spacing: -0.01em;
    border-bottom: none;
    margin-bottom: 0.3em;
}

/* Gold rule + ornament under every chapter title */
.content main h1::after {
    content: "";
    display: block;
    width: 6rem;
    height: 3px;
    margin-top: 0.35em;
    background: linear-gradient(90deg, var(--codex-accent), transparent);
    border-radius: 2px;
}

.content main h2 {
    font-variant: small-caps;
    letter-spacing: 0.04em;
    color: var(--codex-accent);
    border-bottom: none;
    margin-top: 2.2em;
}

.content main h3 {
    font-style: italic;
    font-weight: 600;
}

/* ---- Drop caps: automatic after each chapter title, or manual ---- */
.content main h1 + p::first-letter,
.content main p.initial::first-letter {
    float: left;
    font-size: 3.4em;
    line-height: 0.82;
    font-weight: 700;
    padding: 0.08em 0.12em 0 0;
    color: var(--codex-accent);
}

/* ---- Lead paragraph (opt-in via <p class="lead">) ---- */
.content main .lead {
    font-size: 1.18em;
    font-style: italic;
    opacity: 0.9;
}

/* ---- Section kicker (small-caps intro label) ---- */
.content main .kicker {
    display: block;
    font-variant: small-caps;
    letter-spacing: 0.22em;
    font-size: 0.85em;
    color: var(--codex-accent);
    margin-bottom: -0.6em;
}

/* ---- Inline highlight ---- */
.content main mark {
    background: linear-gradient(transparent 45%, var(--codex-accent-soft) 45%);
    color: inherit;
    padding: 0 0.15em;
    border-bottom: 2px solid var(--codex-accent);
}

/* ---- Ornamental horizontal rules & chapter-end mark ---- */
.content main hr {
    border: none;
    text-align: center;
    margin: 2.5em auto;
}

.content main hr::after {
    content: "❦";
    font-size: 1.4em;
    color: var(--codex-accent);
    letter-spacing: 0.8em;
    padding-left: 0.8em;
}

.content main .finis {
    text-align: center;
    font-size: 1.3em;
    color: var(--codex-accent);
    letter-spacing: 0.6em;
    padding-left: 0.6em;
    margin: 3em 0 1em;
}

/* ---- Blockquotes with a hanging quote mark ---- */
.content main blockquote {
    position: relative;
    border: none;
    border-left: 3px solid var(--codex-accent);
    background: var(--codex-accent-soft);
    border-radius: 0 8px 8px 0;
    padding: 0.9em 1.4em 0.9em 2.6em;
    font-style: italic;
}

.content main blockquote::before {
    content: "\201C";
    position: absolute;
    left: 0.35em;
    top: 0.05em;
    font-size: 2.6em;
    line-height: 1;
    color: var(--codex-accent);
    font-family: Georgia, serif;
}

/* ---- Pull quotes (opt-in via <p class="pullquote">) ---- */
.content main .pullquote {
    font-size: 1.5em;
    font-style: italic;
    text-align: center;
    line-height: 1.4;
    margin: 1.6em 8%;
    padding: 0.6em 0;
    border-top: 1px solid var(--codex-accent);
    border-bottom: 1px solid var(--codex-accent);
    color: var(--codex-accent);
}

/* ---- Epigraph: chapter-opening quotation with attribution ---- */
.content main .epigraph {
    margin: 1.8em 12% 2.2em;
    font-style: italic;
    text-align: center;
    line-height: 1.6;
}

.content main .epigraph .attribution {
    display: block;
    margin-top: 0.6em;
    font-style: normal;
    font-variant: small-caps;
    letter-spacing: 0.12em;
    font-size: 0.85em;
    color: var(--codex-accent);
}

.content main .epigraph .attribution::before {
    content: "— ";
}

/* ---- Callout boxes (opt-in via <div class="callout note|tip|warn|danger">) ---- */
.content main .callout {
    border-radius: 10px;
    padding: 1em 1.3em 1em 3.2em;
    margin: 1.4em 0;
    position: relative;
    border: 1px solid transparent;
}

.content main .callout::before {
    position: absolute;
    left: 0.9em;
    top: 0.85em;
    font-size: 1.3em;
    font-style: normal;
}

.content main .callout > p:first-child strong:first-child {
    font-variant: small-caps;
    letter-spacing: 0.08em;
}

.content main .callout.note {
    background: rgba(88, 166, 255, 0.1);
    border-color: rgba(88, 166, 255, 0.4);
}
.content main .callout.note::before { content: "✒️"; }

.content main .callout.tip {
    background: rgba(63, 185, 80, 0.1);
    border-color: rgba(63, 185, 80, 0.4);
}
.content main .callout.tip::before { content: "🕯️"; }

.content main .callout.warn {
    background: rgba(210, 153, 34, 0.12);
    border-color: rgba(210, 153, 34, 0.5);
}
.content main .callout.warn::before { content: "⚠️"; }

.content main .callout.danger {
    background: var(--codex-red-soft);
    border-color: var(--codex-red);
    border-left-width: 4px;
}
.content main .callout.danger::before { content: "🔥"; }

/* ---- Margin asides: short notes floated into the right margin ---- */
.content main .aside-note {
    float: right;
    clear: right;
    width: 38%;
    margin: 0.3em 0 1em 1.6em;
    padding: 0.7em 1em;
    font-size: 0.88em;
    line-height: 1.5;
    font-style: italic;
    border-top: 2px solid var(--codex-accent);
    border-bottom: 1px solid var(--codex-accent);
    background: var(--codex-accent-soft);
}

.content main .aside-note .kicker {
    margin-bottom: 0.2em;
}

@media (max-width: 900px) {
    .content main .aside-note {
        float: none;
        width: auto;
        margin: 1.2em 0;
    }
}

/* ---- Timeline lists (opt-in via <ul class="timeline">) ---- */
.content main ul.timeline {
    list-style: none;
    margin: 1.6em 0 1.6em 0.4em;
    padding-left: 1.6em;
    border-left: 3px solid var(--codex-accent);
}

.content main ul.timeline > li {
    position: relative;
    margin-bottom: 1em;
}

.content main ul.timeline > li::before {
    content: "";
    position: absolute;
    left: -2.07em;
    top: 0.45em;
    width: 0.75em;
    height: 0.75em;
    border-radius: 50%;
    background: var(--codex-accent);
    box-shadow: 0 0 0 3px var(--codex-accent-soft);
}

.content main ul.timeline > li > strong:first-child {
    font-variant: small-caps;
    letter-spacing: 0.06em;
    color: var(--codex-accent);
    margin-right: 0.4em;
}

/* ---- Tags: inline pills for status and taxonomy ---- */
.content main .tag {
    display: inline-block;
    font-variant: small-caps;
    letter-spacing: 0.08em;
    font-size: 0.8em;
    line-height: 1.4;
    padding: 0.1em 0.75em;
    border-radius: 999px;
    border: 1px solid var(--codex-accent);
    background: var(--codex-accent-soft);
    color: inherit;
    vertical-align: 0.1em;
}

.content main .tag.green {
    border-color: rgba(63, 185, 80, 0.7);
    background: rgba(63, 185, 80, 0.12);
}

.content main .tag.blue {
    border-color: rgba(88, 166, 255, 0.7);
    background: rgba(88, 166, 255, 0.12);
}

.content main .tag.red {
    border-color: var(--codex-red);
    background: var(--codex-red-soft);
}

/* ---- Two-column prose (opt-in via <div class="twocol">) ---- */
.content main .twocol {
    column-count: 2;
    column-gap: 2.4em;
    column-rule: 1px solid var(--codex-accent-soft);
    margin: 1.4em 0;
    text-align: justify;
}

.content main .twocol p:first-child {
    margin-top: 0;
}

@media (max-width: 900px) {
    .content main .twocol { column-count: 1; }
}

/* ---- Tables: framed, striped, small-caps header ---- */
.content main .table-wrapper {
    overflow-x: auto;
    scrollbar-width: thin;
}

.content main table {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--codex-accent);
    border-radius: 10px;
    overflow: hidden;
    margin: 1.6em 0;
}

.content main table thead th {
    background: var(--codex-accent-soft);
    font-variant: small-caps;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--codex-accent);
}

.content main table tbody tr:nth-child(2n) {
    background: var(--codex-accent-soft);
}

.content main table td,
.content main table th {
    border: none;
    padding: 0.55em 1em;
}

/* Compact ledger variant (wrap the table in <div class="compact">) */
.content main .compact table {
    font-size: 0.9em;
    margin: 1.2em 0;
}

.content main .compact table td,
.content main .compact table th {
    padding: 0.3em 0.8em;
}

/* ---- Figures & captions ---- */
.content main figure {
    margin: 2em auto;
    text-align: center;
}

.content main figure img,
.content main figure svg {
    max-width: 100%;
    border-radius: 10px;
}

.content main figcaption {
    margin-top: 0.7em;
    font-size: 0.9em;
    font-style: italic;
    opacity: 0.75;
}

.content main figcaption::before {
    content: "— ";
    color: var(--codex-accent);
}

/* ---- Figure grids: plates side by side (opt-in via <div class="figrid">) ---- */
.content main .figrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.4em;
    align-items: start;
    margin: 2em 0;
}

.content main .figrid figure {
    margin: 0;
}

/* ---- Footnotes ---- */
.content main .footnote-definition {
    font-size: 0.9em;
    line-height: 1.55;
    margin: 0.6em 0;
    padding-top: 0.4em;
}

.content main .footnote-definition:first-of-type {
    border-top: 1px solid var(--codex-accent);
    margin-top: 2.5em;
    padding-top: 1em;
}

.content main .footnote-definition .footnote-definition-label {
    color: var(--codex-accent);
    font-weight: 700;
}

.content main sup a {
    text-decoration: none;
    color: var(--codex-accent);
    font-weight: 700;
}

/* ---- Keyboard keys ---- */
.content main kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
    padding: 0.15em 0.5em;
    border-radius: 6px;
    border: 1px solid var(--codex-accent);
    border-bottom-width: 3px;
    background: var(--codex-accent-soft);
}

/* ---- Mermaid diagrams: center them like plates ---- */
.content main pre:has(> code.mermaid),
.content main pre .mermaid {
    display: flex;
    justify-content: center;
    background: transparent;
}

/* ---- Print: keep the codex elegant on paper ---- */
@media print {
    .content main h1::after { background: var(--codex-accent); }
    .content main .callout { border: 1px solid #999; }
    .content main .table-wrapper { overflow: visible; }
    /* Paper is narrower than the 900px collapse breakpoint: restore the
       full float geometry, not just the float itself. */
    .content main .aside-note {
        float: right;
        width: 38%;
        margin: 0.3em 0 1em 1.6em;
    }
    .content main .twocol { column-count: 2; }
    .content main .epigraph,
    .content main .pullquote,
    .content main .finis { break-inside: avoid; }
}
