/* The book's accessibility overrides.
 *
 * Two things live here, and both are additions to mdbook's own theme rather than a fork of
 * it: a skip link, and the color repairs that bring every theme to the WCAG AA contrast
 * floor. `book.toml` loads this after mdbook's palette, so these declarations win by
 * cascade order — which is also why `crates/book-a11y` reads the files in that order when
 * it measures the result.
 *
 * ⚠ Do not adjust a color here by eye. Every value below was chosen by
 * `cargo run -p book-a11y -- books/ikigai`, which reports the ratio it measured and the
 * nearest color that clears the floor, and the same command is a gate in CI.
 */

/* ── Skip to content ──────────────────────────────────────────────────────────
 *
 * With a full-book sidebar, a keyboard or screen-reader user traverses every chapter link
 * on every page before reaching the words. WCAG 2.2 SC 2.4.1 (Bypass Blocks) is the rule;
 * the reason it matters here is that this book's sidebar is longer than most of its pages.
 *
 * The link is off-screen until focused rather than hidden, because `display: none` and
 * `visibility: hidden` take an element out of the focus order entirely — a skip link that
 * cannot be reached by Tab is not a skip link. `js/a11y.js` puts it in the DOM; this
 * styles it.
 */
.skip-link {
    /* Fixed rather than absolute: a reader who tabs into the page while scrolled down
     * should see the link where their eyes are, not be thrown to the top of the document
     * to find it. */
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    padding: 0.6rem 1rem;
    background: var(--bg);
    color: var(--fg);
    border: 2px solid var(--links);
    border-radius: 0 0 4px 0;
    font-weight: 600;
    text-decoration: none;
    /* Off-screen, still focusable, still announced. */
    transform: translateY(-120%);
}

.skip-link:focus,
.skip-link:focus-visible {
    transform: translateY(0);
    outline: 3px solid var(--links);
    outline-offset: 2px;
}

/* Where the jump landed.
 *
 * `tabindex="-1"` makes the content take focus, and a sighted keyboard user needs to see
 * that it did — a skip link that moves focus invisibly is a link that appears to do
 * nothing. `:focus-visible` rather than `:focus` is what keeps the ring for the keyboard
 * and away from a mouse click, and it is deliberately drawn *inside* the box so it reads
 * as "you are here" rather than as a border on the page. */
#mdbook-content:focus-visible {
    outline: 2px solid var(--links);
    outline-offset: -4px;
}

/* ── Focus you can see ────────────────────────────────────────────────────────
 *
 * The exercises' hints are `<details><summary>`; a summary is focusable and mdbook
 * styles no focus state for it, so the ring is whatever the browser draws — usually
 * fine, and here made explicit and consistent with the skip link and the Run buttons,
 * so a keyboard reader gets the same ring everywhere in the book (WCAG 2.2 SC 2.4.7
 * Focus Visible). `:focus-visible` keeps it for the keyboard and away from a click. */
summary:focus-visible {
    outline: 3px solid var(--links);
    outline-offset: 2px;
}

/* ── Links in running text ────────────────────────────────────────────────────
 *
 * WCAG 2.2 SC 1.4.1 (Use of Color): a link inside a sentence must be told apart from the
 * words around it by something other than color, unless the two colors differ by at least
 * 3:1. mdbook draws such links in `--links` with no underline, and no theme's `--links`
 * clears 3:1 against its `--fg` (navy: 1.64:1, measured by axe-core in a real browser on
 * 2026-09-29). CI's axe runs in jsdom, which has no layout and skips every color rule, so
 * it never saw this. The repair is the underline, not a color: a color far enough from the
 * text to pass would fall below the 4.5:1 a link needs against the background. The sidebar,
 * the menu bar and the heading anchors are not running text, and keep the theme's look. */
#mdbook-content main p a,
#mdbook-content main li a,
#mdbook-content main td a,
#mdbook-content main blockquote a {
    text-decoration: underline;
}

/* ── Comments in ayu's code blocks ─────────────────────────────────────────────
 *
 * mdbook's ayu highlight theme draws comments #5c6773 on #191f26: 2.88:1, under the 4.5:1
 * floor (axe-core in a real browser, 2026-09-29). This is the one value in this file that
 * `book-a11y` did not choose, because it does not read the highlight themes: #7e8790 is the
 * original mixed toward white until the WCAG ratio clears the floor (4.55:1), by the same
 * formula book-a11y uses. No other highlight color failed that run, in any of the five themes,
 * until the listings below arrived. */
.ayu .hljs-comment,
.ayu .hljs-quote {
    color: #7e8790;
}

/* ── Markup and script in the dark themes' code blocks ──────────────────────────
 *
 * The first HTML and JavaScript listings (the spreadsheet's part VII) brought token classes no
 * Rust listing uses, and two of them fall under the floor (axe-core in a real browser,
 * 2026-09-29, with the page's sheet pushing): tomorrow-night's red, #cc6666 on #1d1f21, is
 * 4.46:1 in coal and navy (tags, attributes, regular expressions, variables all share it), and
 * ayu's tag punctuation, #00568d on #191f26, is 2.15:1. Each is the original mixed toward white
 * until it clears 4.5:1, by the formula above: #cd6969 (4.58:1) and #538db2 (4.60:1). */
.coal .hljs-variable,
.coal .hljs-attribute,
.coal .hljs-attr,
.coal .hljs-tag,
.coal .hljs-regexp,
.navy .hljs-variable,
.navy .hljs-attribute,
.navy .hljs-attr,
.navy .hljs-tag,
.navy .hljs-regexp {
    color: #cd6969;
}

.ayu .hljs-tag {
    color: #538db2;
}

/* ── Motion ───────────────────────────────────────────────────────────────────
 *
 * mdbook already guards its footnote highlight with `prefers-reduced-motion`; the
 * search box's loading spinner (`#fa-spin`, a 2s infinite rotation) it does not. Beyond
 * what AA asks — SC 2.3.3 Animation from Interactions is AAA — but a spinner that keeps
 * turning for a reader who asked for less motion is a cheap thing to get right. */
@media (prefers-reduced-motion: reduce) {
    #fa-spin {
        animation: none;
    }
}

/* ── Contrast repairs ─────────────────────────────────────────────────────────
 *
 * Measured with `ikigai-a11y`, the ecosystem's own WCAG crate. Body text is held to 4.5:1
 * (SC 1.4.3) and a non-text UI component to 3:1 (SC 1.4.11). Each comment records what the
 * theme shipped and what it measured, because the next person to look at one of these
 * values deserves to know it was not arbitrary.
 */

.light {
    /* draft chapter in the sidebar: #aaaaaa on #fafafa was 2.23:1 */
    --sidebar-non-existant: #6f6f6f;
}

.rust {
    /* link: #2b79a2 was 3.67:1 on the page and 2.69:1 in a blockquote */
    --links: #1e5571;
    /* inline code: #6e6b5e was 4.07:1 on the page and 2.99:1 in a blockquote */
    --inline-code-color: #4f4c44;
    /* search results header: #666666 was 4.37:1 — a miss no eye would catch */
    --searchresults-header-fg: #5c5c5c;
    /* draft chapter in the sidebar: #505254 on #3b2e2a was 1.66:1 */
    --sidebar-non-existant: #9d9e9f;
}

.coal {
    /* link: #2b79a2 was 3.80:1 on the page and 3.09:1 in a blockquote */
    --links: #5f9abb;
    /* table header: #98a3ad on #42494c was 3.57:1 — the ground moved, not the text,
     * because that foreground is the theme's body color and clears everywhere else */
    --table-header-bg: #31373a;
    /* current chapter in the sidebar: #3473ad was 2.81:1 */
    --sidebar-active: #6f9dc7;
    /* draft chapter in the sidebar: #505254 was 1.79:1 */
    --sidebar-non-existant: #97989a;
    /* search results header: #666666 was 3.19:1 */
    --searchresults-header-fg: #848484;
    /* theme and search buttons: #43484d was 1.98:1 against a 3:1 floor */
    --icons: #767b80;
}

.navy {
    /* link: #2b79a2 was 3.64:1 on the page and 3.05:1 in a blockquote */
    --links: #609bbb;
    /* current chapter in the sidebar: #2b79a2 was 2.84:1 */
    --sidebar-active: #68a1bf;
    /* draft chapter in the sidebar: #505274 was 1.82:1 */
    --sidebar-non-existant: #9899ad;
    /* search results header: #5f5f71 was 2.81:1 */
    --searchresults-header-fg: #878795;
}

.ayu {
    /* link: #0096cf cleared the page at 5.52:1 and missed a blockquote at 4.39:1 */
    --links: #21a4dc;
    /* draft chapter in the sidebar: #5c6773 was 3.06:1 */
    --sidebar-non-existant: #7e8791;
    /* search results header: #666666 was 3.22:1 */
    --searchresults-header-fg: #838383;
}
