
/* Globals */

:root {
    --sidebar-target-width: 300px;
    --sidebar-width: min(var(--sidebar-target-width), 80vw);
    --sidebar-resize-indicator-width: 8px;
    --sidebar-resize-indicator-space: 2px;
    --page-padding: 15px;
    --content-max-width: 640px;
    --menu-bar-height: 50px;
    --mono-font: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace;
    --code-font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
}

/* Themes */

/* BARTLEY: `--rule` and `--whisper` are consumed by name across the graph
   surfaces (graph-panel, graph-timeline, graph, sot-document). No mdbook theme
   declares them, so every `var(--whisper, …)` fell back to a light-mode literal
   in all seven themes — muted text at #6e6354 is right on paper and nearly
   invisible on coal, navy, ayu, and Bartley Dark.

   Derive both from whatever `--fg` and `--bg` the active theme already sets, so
   a stock theme we do not art-direct still gets a legible muted tone and a
   visible hairline. The literals on the first line are the pre-`color-mix`
   fallback: an engine without it keeps exactly today's values rather than
   dropping the declaration and inheriting something arbitrary. Bartley Light
   and Bartley Dark override these with the brand palette further down.

   78% was chosen by measurement, not taste: it is the lowest blend that keeps
   muted text above WCAG AA (4.5:1) in every stock theme. Contrast of the
   resulting `--whisper` against each theme's own background —

     light 11.73 · rust 6.25 · coal 4.82 · navy 6.22 · ayu 6.89

   with coal the floor, because its own `--fg` (#98a3ad) is already low. At 66%
   coal fell to 3.80 and light to 4.42; at 74% coal was still 4.44. Re-measure
   before changing this number. */
.light, .rust, .coal, .navy, .ayu, .bartley-light, .bartley-dark, html:not(.js) {
    --rule: #c9b894;
    --whisper: #6e6354;
    --rule: color-mix(in srgb, var(--fg) 26%, var(--bg));
    --whisper: color-mix(in srgb, var(--fg) 78%, var(--bg));

    /* A raised surface — panel cards, admonitions, promo bars, the timeline
       plate. These borrowed `--sidebar-bg`, which means "the sidebar", not "a
       surface". The two coincide in six themes and invert in rust, the one
       mdbook theme pairing a dark sidebar (#3b2e2a) with a light body: every
       card there rendered as a dark block on a pale page. Tinting the theme's
       own `--bg` toward its own `--fg` is right in both directions — darker on
       light themes, lighter on dark ones — and needs no per-theme art
       direction. 9% keeps the lift close to what the stock themes already
       showed while giving rust a proper pale card (#d0d0cb). */
    --surface: #f5f5f5;
    --surface: color-mix(in srgb, var(--fg) 9%, var(--bg));
}

/* BARTLEY: `--notice-bg` and `--controls-bg` back the two reading-room surfaces
   that carry text inheriting each theme's own `--fg` — the notice callout
   (.reading-room-notice) and the filter bar (.reading-room-controls). Both used
   to borrow `--table-header-bg`, which on coal put #98a3ad on #42494c at
   ~3.6:1, under the AA 4.5:1 floor. That text is regular weight, so it cannot
   lean on the 3:1 large-text allowance a bold header cell can; and retuning
   `--table-header-bg` itself would restyle all eight of its consumers. Hence
   two dedicated tokens.

   The two are measured the same way but move differently. Every theme needed a
   raised notice surface; only coal's filter bar actually failed, so
   `--controls-bg` deliberately holds each other theme's existing header tone
   unchanged rather than restyling a surface that already conformed. The
   per-block comments carry the computed ratio against that theme's `--fg`;
   re-measure the pair, never the background alone, if either is retuned. */

.ayu {
    --bg: hsl(210, 25%, 8%);
    --fg: #c5c5c5;

    --sidebar-bg: #14191f;
    --sidebar-fg: #c8c9db;
    --sidebar-non-existant: #5c6773;
    --sidebar-active: #ffb454;
    --sidebar-spacer: #2d334f;

    --scrollbar: var(--sidebar-fg);

    --icons: #737480;
    --icons-hover: #b7b9cc;

    --links: #0096cf;

    --inline-code-color: #ffb454;

    --theme-popup-bg: #14191f;
    --theme-popup-border: #5c6773;
    --theme-hover: #191f26;

    --quote-bg: hsl(226, 15%, 17%);
    --quote-border: hsl(226, 15%, 22%);

    --warning-border: #ff8e00;

    --table-border-color: hsl(210, 25%, 13%);
    --table-header-bg: hsl(210, 25%, 28%);
    --table-alternate-bg: hsl(210, 25%, 11%);
    --notice-bg: #12171d; /* notice text #c5c5c5 → 10.43:1 */
    --controls-bg: hsl(210, 25%, 28%); /* label text #c5c5c5 → 5.52:1 */
    --reading-room-search-bg: hsl(210, 25%, 28%); /* search text #c5c5c5 on #364759 → 5.52:1 */

    --searchbar-border-color: #848484;
    --searchbar-bg: #424242;
    --searchbar-fg: #fff;
    --searchbar-shadow-color: #d4c89f;
    --searchresults-header-fg: #666;
    --searchresults-border-color: #888;
    --searchresults-li-bg: #252932;
    --search-mark-bg: #e3b171;

    --color-scheme: dark;

    /* Same as `--icons` */
    --copy-button-filter: invert(45%) sepia(6%) saturate(621%) hue-rotate(198deg) brightness(99%) contrast(85%);
    /* Same as `--sidebar-active` */
    --copy-button-filter-hover: invert(68%) sepia(55%) saturate(531%) hue-rotate(341deg) brightness(104%) contrast(101%);

    --footnote-highlight: #2668a6;

    --overlay-bg: rgba(33, 40, 48, 0.4);
}

.coal {
    --bg: hsl(200, 7%, 8%);
    --fg: #98a3ad;

    --sidebar-bg: #292c2f;
    --sidebar-fg: #a1adb8;
    --sidebar-non-existant: #505254;
    --sidebar-active: #3473ad;
    --sidebar-spacer: #393939;

    --scrollbar: var(--sidebar-fg);

    --icons: #43484d;
    --icons-hover: #b3c0cc;

    --links: #2b79a2;

    --inline-code-color: #c5c8c6;

    --theme-popup-bg: #141617;
    --theme-popup-border: #43484d;
    --theme-hover: #1f2124;

    --quote-bg: hsl(234, 21%, 18%);
    --quote-border: hsl(234, 21%, 23%);

    --warning-border: #ff8e00;

    --table-border-color: hsl(200, 7%, 13%);
    --table-header-bg: hsl(200, 7%, 28%);
    --table-alternate-bg: hsl(200, 7%, 11%);
    --notice-bg: #1c2024; /* notice text #98a3ad → 6.38:1 (was #42494c → 3.57:1) */
    --controls-bg: #2d3236; /* label text #98a3ad → 5.04:1 (was #42494c → 3.57:1) */
    --reading-room-search-bg: #2d3236; /* search text #98a3ad on #2d3236 → 5.04:1 (was #42494c → 3.57:1) */

    --searchbar-border-color: #aaa;
    --searchbar-bg: #b7b7b7;
    --searchbar-fg: #000;
    --searchbar-shadow-color: #aaa;
    --searchresults-header-fg: #666;
    --searchresults-border-color: #98a3ad;
    --searchresults-li-bg: #2b2b2f;
    --search-mark-bg: #355c7d;

    --color-scheme: dark;

    /* Same as `--icons` */
    --copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
    /* Same as `--sidebar-active` */
    --copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);

    --footnote-highlight: #4079ae;

    --overlay-bg: rgba(33, 40, 48, 0.4);
}

.light, html:not(.js) {
    --bg: hsl(0, 0%, 100%);
    --fg: hsl(0, 0%, 0%);

    --sidebar-bg: #fafafa;
    --sidebar-fg: hsl(0, 0%, 0%);
    --sidebar-non-existant: #aaaaaa;
    --sidebar-active: #1f1fff;
    --sidebar-spacer: #f4f4f4;

    --scrollbar: #8F8F8F;

    --icons: #747474;
    --icons-hover: #000000;

    --links: #20609f;

    --inline-code-color: #301900;

    --theme-popup-bg: #fafafa;
    --theme-popup-border: #cccccc;
    --theme-hover: #e6e6e6;

    --quote-bg: hsl(197, 37%, 96%);
    --quote-border: hsl(197, 37%, 91%);

    --warning-border: #ff8e00;

    --table-border-color: hsl(0, 0%, 95%);
    --table-header-bg: hsl(0, 0%, 80%);
    --table-alternate-bg: hsl(0, 0%, 97%);
    --notice-bg: #e6eef4; /* notice text #000 → 17.90:1 */
    --controls-bg: hsl(0, 0%, 80%); /* label text #000 → 13.08:1 */
    --reading-room-search-bg: hsl(0, 0%, 80%); /* search text #000000 on #cccccc → 13.08:1 */

    --searchbar-border-color: #aaa;
    --searchbar-bg: #fafafa;
    --searchbar-fg: #000;
    --searchbar-shadow-color: #aaa;
    --searchresults-header-fg: #666;
    --searchresults-border-color: #888;
    --searchresults-li-bg: #e4f2fe;
    --search-mark-bg: #a2cff5;

    --color-scheme: light;

    /* Same as `--icons` */
    --copy-button-filter: invert(45.49%);
    /* Same as `--sidebar-active` */
    --copy-button-filter-hover: invert(14%) sepia(93%) saturate(4250%) hue-rotate(243deg) brightness(99%) contrast(130%);

    --footnote-highlight: #7e7eff;

    --overlay-bg: rgba(200, 200, 205, 0.4);
}

.navy {
    --bg: hsl(226, 23%, 11%);
    --fg: #bcbdd0;

    --sidebar-bg: #282d3f;
    --sidebar-fg: #c8c9db;
    --sidebar-non-existant: #505274;
    --sidebar-active: #2b79a2;
    --sidebar-spacer: #2d334f;

    --scrollbar: var(--sidebar-fg);

    --icons: #737480;
    --icons-hover: #b7b9cc;

    --links: #2b79a2;

    --inline-code-color: #c5c8c6;

    --theme-popup-bg: #161923;
    --theme-popup-border: #737480;
    --theme-hover: #282e40;

    --quote-bg: hsl(226, 15%, 17%);
    --quote-border: hsl(226, 15%, 22%);

    --warning-border: #ff8e00;

    --table-border-color: hsl(226, 23%, 16%);
    --table-header-bg: hsl(226, 23%, 31%);
    --table-alternate-bg: hsl(226, 23%, 14%);
    --notice-bg: #1b1f2e; /* notice text #bcbdd0 → 8.84:1 */
    --controls-bg: hsl(226, 23%, 31%); /* label text #bcbdd0 → 5.10:1 */
    --reading-room-search-bg: hsl(226, 23%, 31%); /* search text #bcbdd0 on #3d4561 → 5.10:1 */

    --searchbar-border-color: #aaa;
    --searchbar-bg: #aeaec6;
    --searchbar-fg: #000;
    --searchbar-shadow-color: #aaa;
    --searchresults-header-fg: #5f5f71;
    --searchresults-border-color: #5c5c68;
    --searchresults-li-bg: #242430;
    --search-mark-bg: #a2cff5;

    --color-scheme: dark;

    /* Same as `--icons` */
    --copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
    /* Same as `--sidebar-active` */
    --copy-button-filter-hover: invert(46%) sepia(20%) saturate(1537%) hue-rotate(156deg) brightness(85%) contrast(90%);

    --footnote-highlight: #4079ae;

    --overlay-bg: rgba(33, 40, 48, 0.4);
}

.rust {
    --bg: hsl(60, 9%, 87%);
    --fg: #262625;

    --sidebar-bg: #3b2e2a;
    --sidebar-fg: #c8c9db;
    --sidebar-non-existant: #505254;
    --sidebar-active: #e69f67;
    --sidebar-spacer: #45373a;

    --scrollbar: var(--sidebar-fg);

    --icons: #737480;
    --icons-hover: #262625;

    --links: #2b79a2;

    --inline-code-color: #6e6b5e;

    --theme-popup-bg: #e1e1db;
    --theme-popup-border: #b38f6b;
    --theme-hover: #99908a;

    --quote-bg: hsl(60, 5%, 75%);
    --quote-border: hsl(60, 5%, 70%);

    --warning-border: #ff8e00;

    --table-border-color: hsl(60, 9%, 82%);
    --table-header-bg: #b3a497;
    --table-alternate-bg: hsl(60, 9%, 84%);
    --notice-bg: #cfcabc; /* notice text #262625 → 9.25:1 */
    --controls-bg: #b3a497; /* label text #262625 → 6.26:1 */
    --reading-room-search-bg: #b3a497; /* search text #262625 on #b3a497 → 6.26:1 */

    --searchbar-border-color: #aaa;
    --searchbar-bg: #fafafa;
    --searchbar-fg: #000;
    --searchbar-shadow-color: #aaa;
    --searchresults-header-fg: #666;
    --searchresults-border-color: #888;
    --searchresults-li-bg: #dec2a2;
    --search-mark-bg: #e69f67;

    /* Same as `--icons` */
    --copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
    /* Same as `--sidebar-active` */
    --copy-button-filter-hover: invert(77%) sepia(16%) saturate(1798%) hue-rotate(328deg) brightness(98%) contrast(83%);

    --footnote-highlight: #d3a17a;

    --overlay-bg: rgba(150, 150, 150, 0.25);
}

/* BARTLEY: house themes — Bartley Light (default) and Bartley Dark (preferred dark).
   Mirrors web/styles.css palette (paper / paper-deep / ink / gold / imprint / rule / whisper).
   See briefs/brand-standards.md for color-use rules: monogram is gold; logotype is ink (light)
   or paper (dark); imprint oxblood is a reading-experience accent only. */

.bartley-light {
    --bg: #f5ede0;                                   /* paper */
    --fg: #1a1612;                                   /* ink */

    /* BARTLEY: the palette tokens the graph surfaces consume by name. The block
       header above has always claimed to mirror web/styles.css including rule
       and whisper, but neither was ever declared here, so every
       var(--whisper, …) and var(--rule, …) in graph-panel/graph-timeline/
       graph/sot-document fell back to its light-mode literal in every theme —
       readable on paper, near-invisible on dark. */
    --rule: #c9b894;
    --whisper: #6e6354;
    --surface: #ebe1ce;                              /* paper-deep */

    --sidebar-bg: #ebe1ce;                           /* paper-deep */
    --sidebar-fg: #1a1612;                           /* ink */
    --sidebar-non-existant: #8a7a5a;                 /* rule, deepened */
    --sidebar-active: #6e1f1f;                       /* imprint */
    --sidebar-spacer: #c9b894;                       /* rule */

    --scrollbar: #c9b894;                            /* rule */

    --icons: #6e6354;                                /* whisper */
    --icons-hover: #6e1f1f;                          /* imprint */

    --links: #6e1f1f;                                /* imprint */

    --inline-code-color: #6e1f1f;                    /* imprint */

    --theme-popup-bg: #ebe1ce;                       /* paper-deep */
    --theme-popup-border: #c9b894;                   /* rule */
    --theme-hover: #dbcfb4;                          /* paper-deep / rule midpoint */

    --quote-bg: #ebe1ce;                             /* paper-deep */
    --quote-border: #a6894b;                         /* gold — sole place gold appears in body */

    --warning-border: #c0392b;                       /* matches existing antipattern admonition */

    --table-border-color: #c9b894;                   /* rule */
    --table-header-bg: #ebe1ce;                      /* paper-deep */
    --table-alternate-bg: #f0e6d3;                   /* paper / paper-deep midpoint */
    --notice-bg: #e4d8c0;                            /* notice text #1a1612 → 12.75:1 */
    --controls-bg: #ebe1ce;                          /* label text #1a1612 → 13.87:1 */
    --reading-room-search-bg: #ebe1ce;               /* search text #1a1612 on #ebe1ce → 13.87:1 */

    --searchbar-border-color: #c9b894;               /* rule */
    --searchbar-bg: #f5ede0;                         /* paper */
    --searchbar-fg: #1a1612;                         /* ink */
    --searchbar-shadow-color: rgba(110, 31, 31, 0.18); /* imprint, 18% */
    --searchresults-header-fg: #6e6354;              /* whisper */
    --searchresults-border-color: #c9b894;           /* rule */
    --searchresults-li-bg: #ebe1ce;                  /* paper-deep */
    --search-mark-bg: rgba(166, 137, 75, 0.35);      /* gold, 35% */

    --color-scheme: light;

    /* Tinted toward warm ink; tilts toward imprint on hover. */
    --copy-button-filter: invert(20%) sepia(30%) saturate(200%) hue-rotate(330deg);
    --copy-button-filter-hover: invert(20%) sepia(60%) saturate(800%) hue-rotate(335deg);

    --footnote-highlight: rgba(166, 137, 75, 0.35);  /* gold, 35% */

    --overlay-bg: rgba(26, 22, 18, 0.55);            /* ink, 55% */
}

.bartley-dark {
    /* Bg lifts ~2% off pure ink (#1a1612 → #221d18) for less-fatiguing long-form reading.
       Imprint reads muddy on dark; links/active/code-accent shift to gold-lifted (#d6b370). */
    --bg: #221d18;                                   /* ink, lifted */
    --fg: #f0e6d3;                                   /* paper, gentler than full --paper for dark */

    /* BARTLEY: see the note in .bartley-light. Dark inverts the pair the same
       way web/styles.css does — the muted text lifts to rule, and the hairline
       drops to a tone that reads as a rule against a lifted-ink ground. */
    --rule: #4a4038;
    --whisper: #c9b894;
    --surface: #1a1612;                              /* true ink */

    --sidebar-bg: #1a1612;                           /* true ink — sidebar deeper than body */
    --sidebar-fg: #f0e6d3;
    --sidebar-non-existant: #6e6354;                 /* whisper */
    --sidebar-active: #d6b370;                       /* gold-lifted */
    --sidebar-spacer: #3a3128;                       /* rule, dark luminance */

    --scrollbar: #6e6354;                            /* whisper */

    --icons: #a6894b;                                /* gold — toolbar reinforces brand on dark */
    --icons-hover: #d6b370;                          /* gold-lifted */

    --links: #d6b370;                                /* gold-lifted (imprint reads muddy on dark) */

    --inline-code-color: #d6b370;

    --theme-popup-bg: #1a1612;
    --theme-popup-border: #3a3128;
    --theme-hover: #2a241e;

    --quote-bg: #1a1612;
    --quote-border: #a6894b;                         /* gold */

    --warning-border: #e06453;                       /* antipattern red, lifted for dark */

    --table-border-color: #3a3128;
    --table-header-bg: #1a1612;
    --table-alternate-bg: #1f1a14;
    --notice-bg: #171310;                            /* notice text #f0e6d3 → 14.92:1 */
    --controls-bg: #1a1612;                          /* label text #f0e6d3 → 14.53:1 */
    --reading-room-search-bg: #1a1612;               /* search text #f0e6d3 on #1a1612 → 14.53:1 */

    --searchbar-border-color: #3a3128;
    --searchbar-bg: #1a1612;
    --searchbar-fg: #f0e6d3;
    --searchbar-shadow-color: rgba(166, 137, 75, 0.25); /* gold, 25% */
    --searchresults-header-fg: #c9b894;               /* rule, used as quiet text on dark */
    --searchresults-border-color: #3a3128;
    --searchresults-li-bg: #1a1612;
    --search-mark-bg: rgba(214, 179, 112, 0.35);     /* gold-lifted, 35% */

    --color-scheme: dark;

    /* Tilts the bundled monochrome icon toward warm paper; hover toward gold. */
    --copy-button-filter: invert(85%) sepia(15%) saturate(300%) hue-rotate(15deg);
    --copy-button-filter-hover: invert(75%) sepia(50%) saturate(500%) hue-rotate(20deg);

    --footnote-highlight: rgba(214, 179, 112, 0.35);

    --overlay-bg: rgba(26, 22, 18, 0.75);
}

/* BARTLEY: learning-track filled-pill text contrast (briefs/learning-tracks.md
   §3). White pill text is the default (chrome.css). The three light palette
   indexes — gold (7), pink (8), slate (10) — read poorly with white text, so
   they get dark ink text. The pill fill hexes are fixed across every theme, so
   the contrast requirement is theme-independent: these overrides are UNSCOPED,
   matching the unscoped learning-tracks component rules in chrome.css. The per-
   pill `--track-pill-fg` is consumed by .track-pill-prev / .track-pill-next. */
.track-color-7,
.track-color-8,
.track-color-10 {
    --track-pill-fg: #1a1612;   /* ink */
}

@media (prefers-color-scheme: dark) {
    html:not(.js) {
        --bg: hsl(200, 7%, 8%);
        --fg: #98a3ad;

        --sidebar-bg: #292c2f;
        --sidebar-fg: #a1adb8;
        --sidebar-non-existant: #505254;
        --sidebar-active: #3473ad;
        --sidebar-spacer: #393939;

        --scrollbar: var(--sidebar-fg);

        --icons: #43484d;
        --icons-hover: #b3c0cc;

        --links: #2b79a2;

        --inline-code-color: #c5c8c6;

        --theme-popup-bg: #141617;
        --theme-popup-border: #43484d;
        --theme-hover: #1f2124;

        --quote-bg: hsl(234, 21%, 18%);
        --quote-border: hsl(234, 21%, 23%);

        --warning-border: #ff8e00;

        --table-border-color: hsl(200, 7%, 13%);
        --table-header-bg: hsl(200, 7%, 28%);
        --table-alternate-bg: hsl(200, 7%, 11%);
        --notice-bg: #1c2024; /* notice text #98a3ad → 6.38:1 (mirrors coal) */
        --controls-bg: #2d3236; /* label text #98a3ad → 5.04:1 (mirrors coal) */
        --reading-room-search-bg: #2d3236; /* search text #98a3ad on #2d3236 → 5.04:1 (mirrors coal) */

        --searchbar-border-color: #aaa;
        --searchbar-bg: #b7b7b7;
        --searchbar-fg: #000;
        --searchbar-shadow-color: #aaa;
        --searchresults-header-fg: #666;
        --searchresults-border-color: #98a3ad;
        --searchresults-li-bg: #2b2b2f;
        --search-mark-bg: #355c7d;

        --color-scheme: dark;

        /* Same as `--icons` */
        --copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
        /* Same as `--sidebar-active` */
        --copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
    }
}
