/*
 * The site's look, shared by every page. Load it first in <head>, right after /theme.js:
 *   <script src="/theme.js"></script>
 *   <link rel="stylesheet" href="/theme.css">
 *
 * Three styles (set by theme.js on <html data-style="...">):
 *   chapel  deep navy, thin brass accent, serif headings and pulpit words (the default)
 *   clear   white and light grey, one blue, one clean sans face
 *   easy    calm teal, a typeface made for low vision, larger text and roomier controls
 * Each has a light and a dark palette. Mode: <html data-theme="light|dark">, or nothing to
 * follow the device. Text size: <html data-text="normal|large|xlarge"> scales the root font
 * size, so pages must size text in rem/em (not px) for it to work.
 *
 * Pages use ONLY these tokens for color (never a hex value that only works in one mode):
 *   --bg          page background            --surface     cards, panels, inputs' container
 *   --surface-2   subtle fill (table heads, hover, quiet boxes)
 *   --ink         main text                  --muted       secondary text (still AA on --bg/--surface)
 *   --line        hairline borders           --line-strong form-field borders
 *   --primary     buttons, links, headings accent    --on-primary  text on --primary
 *   --primary-soft  tinted background for selected/primary-light things
 *   --primary-ink   strong text in the primary hue (headings, names to read)
 *   --link        links                      --accent      small decorative accent (rules, marks)
 *   --focus       keyboard focus ring        --field       form field background
 *   --ok / --ok-bg / --ok-line     success    --warn / --warn-bg / --warn-line   warning
 *   --err / --err-bg / --err-line  error      --info / --info-bg / --info-line   information
 *   --nav-bg / --nav-ink / --nav-line / --nav-on / --nav-on-ink / --nav-mark   top bar
 *   --hero-a / --hero-b   the two ends of a header band (gradient or flat)
 *   --on-hero     text on the header band
 *   --shadow / --shadow-lg   elevation      --radius / --radius-sm / --radius-lg
 *   --font-body / --font-head / --font-read (words read aloud at the pulpit) / --font-mono
 */

@font-face { font-family: 'Source Serif 4'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(/fonts/source-serif-4.woff2) format('woff2'); }
@font-face { font-family: 'Source Sans 3'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(/fonts/source-sans-3.woff2) format('woff2'); }
@font-face { font-family: 'Public Sans'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(/fonts/public-sans.woff2) format('woff2'); }
@font-face { font-family: 'Lexend'; font-style: normal; font-weight: 400 700; font-display: swap; src: url(/fonts/lexend.woff2) format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible'; font-style: normal; font-weight: 400; font-display: swap; src: url(/fonts/atkinson-400.woff2) format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible'; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/atkinson-700.woff2) format('woff2'); }

/* ---------- Chapel (default), light ---------- */
:root {
    --font-body: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-head: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-read: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
    --style-scale: 1;
    --text-scale: 1;

    --bg: #f4f5f3;
    --surface: #ffffff;
    --surface-2: #eef0ec;
    --ink: #1c2433;
    --muted: #535d6d;
    --line: #dcded8;
    --line-strong: #9aa1ad;
    --primary: #1f3a5f;
    --on-primary: #ffffff;
    --primary-soft: #e6ecf4;
    --primary-ink: #1f3a5f;
    --link: #1f4f8a;
    --accent: #a8843c;
    --focus: #9a6b00;
    --field: #ffffff;
    --ok: #1f6b3d;  --ok-bg: #e4f2e8;  --ok-line: #9fd0b0;
    --warn: #7a4f00; --warn-bg: #fdf3da; --warn-line: #e8c870;
    --err: #a3261b; --err-bg: #fbe9e7; --err-line: #eba59d;
    --info: #1f4f8a; --info-bg: #e8f0fa; --info-line: #a9c4e6;
    --nav-bg: #1f3a5f; --nav-ink: #f2f4f7; --nav-line: rgba(255,255,255,.2);
    --nav-on: rgba(255,255,255,.14); --nav-on-ink: #ffffff; --nav-mark: #c7a45a;
    --hero-a: #1f3a5f; --hero-b: #2c4f7c; --on-hero: #ffffff;
    --shadow: 0 1px 2px rgba(28,36,51,.07), 0 1px 1px rgba(28,36,51,.04);
    --shadow-lg: 0 8px 24px rgba(28,36,51,.10);
    --radius: 10px; --radius-sm: 7px; --radius-lg: 14px;
    color-scheme: light;
}

/* ---------- Clear, light ---------- */
html[data-style="clear"] {
    --font-body: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-head: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-read: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --ink: #111827;
    --muted: #4b5563;
    --line: #e2e5ea;
    --line-strong: #a3abb7;
    --primary: #2456c8;
    --on-primary: #ffffff;
    --primary-soft: #eaf0fd;
    --primary-ink: #1d47a8;
    --link: #1f4fc0;
    --accent: #2456c8;
    --focus: #b37400;
    --field: #ffffff;
    --ok: #166534;  --ok-bg: #e6f4ea;  --ok-line: #a7d9b5;
    --warn: #7c4a03; --warn-bg: #fdf4dc; --warn-line: #ecc56a;
    --err: #b42318; --err-bg: #fdecea; --err-line: #f1a9a0;
    --info: #1d47a8; --info-bg: #eaf0fd; --info-line: #b3c8f5;
    --nav-bg: #ffffff; --nav-ink: #1f2937; --nav-line: #e2e5ea;
    --nav-on: #eaf0fd; --nav-on-ink: #1d47a8; --nav-mark: transparent;
    --hero-a: #2456c8; --hero-b: #2456c8; --on-hero: #ffffff;
    --shadow: 0 1px 3px rgba(17,24,39,.06), 0 1px 2px rgba(17,24,39,.04);
    --shadow-lg: 0 10px 28px rgba(17,24,39,.10);
    --radius: 10px; --radius-sm: 8px; --radius-lg: 14px;
}

/* ---------- Easy Read, light ---------- */
html[data-style="easy"] {
    --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-head: 'Lexend', 'Atkinson Hyperlegible', system-ui, sans-serif;
    --font-read: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --style-scale: 1.08;
    --bg: #eef3f1;
    --surface: #ffffff;
    --surface-2: #e4ede9;
    --ink: #13302a;
    --muted: #425a54;
    --line: #cbdad4;
    --line-strong: #7f9a92;
    --primary: #1d6b5c;
    --on-primary: #ffffff;
    --primary-soft: #dcefe8;
    --primary-ink: #165447;
    --link: #165f51;
    --accent: #1d6b5c;
    --focus: #a85a00;
    --field: #ffffff;
    --ok: #165447;  --ok-bg: #dcefe8;  --ok-line: #93c9b8;
    --warn: #744600; --warn-bg: #fbf0d6; --warn-line: #e2bd62;
    --err: #a1251a; --err-bg: #fbe8e5; --err-line: #e8a198;
    --info: #1f4f7a; --info-bg: #e5eff7; --info-line: #a6c3dc;
    --nav-bg: #13302a; --nav-ink: #eef6f3; --nav-line: rgba(255,255,255,.2);
    --nav-on: #eef6f3; --nav-on-ink: #13302a; --nav-mark: transparent;
    --hero-a: #1d6b5c; --hero-b: #1d6b5c; --on-hero: #ffffff;
    --shadow: none;
    --shadow-lg: 0 6px 20px rgba(19,48,42,.10);
    --radius: 14px; --radius-sm: 10px; --radius-lg: 18px;
}

/* ---------- Dark palettes: when the device is dark (unless Light was chosen), or Dark was chosen ---------- */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --bg: #11151c; --surface: #19202a; --surface-2: #212a36; --ink: #e8eaee; --muted: #a8b1be;
        --line: #2d3644; --line-strong: #5b6676; --primary: #8fb4e3; --on-primary: #0e1a2b; --primary-soft: #1f2d42;
        --primary-ink: #c3d7f1; --link: #9cc0ee; --accent: #d1b06a; --focus: #f2c14e; --field: #10151c;
        --ok: #8fd3a6; --ok-bg: #16301f; --ok-line: #2f6a44; --warn: #f0cd7a; --warn-bg: #362a10; --warn-line: #7a5f1f;
        --err: #f3a59b; --err-bg: #3a1815; --err-line: #7c3028; --info: #9cc0ee; --info-bg: #182638; --info-line: #2f4c72;
        --nav-bg: #0c1420; --nav-ink: #dfe5ee; --nav-line: #253041; --nav-on: #1c2839; --nav-on-ink: #ffffff; --nav-mark: #d1b06a;
        --hero-a: #16253a; --hero-b: #1d3352; --on-hero: #f2f4f7;
        --shadow: none; --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
        color-scheme: dark;
    }
    html[data-style="clear"]:not([data-theme="light"]) {
        --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --ink: #e6edf3; --muted: #9ea8b4;
        --line: #2a313b; --line-strong: #56606d; --primary: #6ea2ff; --on-primary: #0b1730; --primary-soft: #1a2742;
        --primary-ink: #b4ceff; --link: #84b0ff; --accent: #6ea2ff; --focus: #f5b301; --field: #0d1117;
        --ok: #7ee2a0; --ok-bg: #12301d; --ok-line: #2c6b41; --warn: #f2cc75; --warn-bg: #33270d; --warn-line: #77601f;
        --err: #ff9f94; --err-bg: #3a1513; --err-line: #7d2c25; --info: #84b0ff; --info-bg: #15233b; --info-line: #2c4775;
        --nav-bg: #161b22; --nav-ink: #dbe2ea; --nav-line: #2a313b; --nav-on: #1d2a44; --nav-on-ink: #b4ceff; --nav-mark: transparent;
        --hero-a: #1a2742; --hero-b: #1a2742; --on-hero: #e6edf3;
    }
    html[data-style="easy"]:not([data-theme="light"]) {
        --bg: #0f1a18; --surface: #172422; --surface-2: #1e2f2c; --ink: #e5f0ec; --muted: #a6bdb6;
        --line: #2a3a37; --line-strong: #567069; --primary: #72d2b9; --on-primary: #0b201b; --primary-soft: #183530;
        --primary-ink: #a6e6d4; --link: #86dcc5; --accent: #72d2b9; --focus: #ffb547; --field: #0f1a18;
        --ok: #8fe0c6; --ok-bg: #163029; --ok-line: #2f6656; --warn: #f2cc75; --warn-bg: #33290f; --warn-line: #77601f;
        --err: #ffa59a; --err-bg: #3a1714; --err-line: #7d2e27; --info: #9cc6ea; --info-bg: #15283a; --info-line: #2d4f70;
        --nav-bg: #0a1311; --nav-ink: #e5f0ec; --nav-line: #24332f; --nav-on: #e5f0ec; --nav-on-ink: #0a1311; --nav-mark: transparent;
        --hero-a: #183530; --hero-b: #183530; --on-hero: #e5f0ec;
    }
}
html[data-theme="dark"] {
    --bg: #11151c; --surface: #19202a; --surface-2: #212a36; --ink: #e8eaee; --muted: #a8b1be;
    --line: #2d3644; --line-strong: #5b6676; --primary: #8fb4e3; --on-primary: #0e1a2b; --primary-soft: #1f2d42;
    --primary-ink: #c3d7f1; --link: #9cc0ee; --accent: #d1b06a; --focus: #f2c14e; --field: #10151c;
    --ok: #8fd3a6; --ok-bg: #16301f; --ok-line: #2f6a44; --warn: #f0cd7a; --warn-bg: #362a10; --warn-line: #7a5f1f;
    --err: #f3a59b; --err-bg: #3a1815; --err-line: #7c3028; --info: #9cc0ee; --info-bg: #182638; --info-line: #2f4c72;
    --nav-bg: #0c1420; --nav-ink: #dfe5ee; --nav-line: #253041; --nav-on: #1c2839; --nav-on-ink: #ffffff; --nav-mark: #d1b06a;
    --hero-a: #16253a; --hero-b: #1d3352; --on-hero: #f2f4f7;
    --shadow: none; --shadow-lg: 0 8px 24px rgba(0,0,0,.4);
    color-scheme: dark;
}
html[data-style="clear"][data-theme="dark"] {
    --bg: #0d1117; --surface: #161b22; --surface-2: #1f2630; --ink: #e6edf3; --muted: #9ea8b4;
    --line: #2a313b; --line-strong: #56606d; --primary: #6ea2ff; --on-primary: #0b1730; --primary-soft: #1a2742;
    --primary-ink: #b4ceff; --link: #84b0ff; --accent: #6ea2ff; --focus: #f5b301; --field: #0d1117;
    --ok: #7ee2a0; --ok-bg: #12301d; --ok-line: #2c6b41; --warn: #f2cc75; --warn-bg: #33270d; --warn-line: #77601f;
    --err: #ff9f94; --err-bg: #3a1513; --err-line: #7d2c25; --info: #84b0ff; --info-bg: #15233b; --info-line: #2c4775;
    --nav-bg: #161b22; --nav-ink: #dbe2ea; --nav-line: #2a313b; --nav-on: #1d2a44; --nav-on-ink: #b4ceff; --nav-mark: transparent;
    --hero-a: #1a2742; --hero-b: #1a2742; --on-hero: #e6edf3;
}
html[data-style="easy"][data-theme="dark"] {
    --bg: #0f1a18; --surface: #172422; --surface-2: #1e2f2c; --ink: #e5f0ec; --muted: #a6bdb6;
    --line: #2a3a37; --line-strong: #567069; --primary: #72d2b9; --on-primary: #0b201b; --primary-soft: #183530;
    --primary-ink: #a6e6d4; --link: #86dcc5; --accent: #72d2b9; --focus: #ffb547; --field: #0f1a18;
    --ok: #8fe0c6; --ok-bg: #163029; --ok-line: #2f6656; --warn: #f2cc75; --warn-bg: #33290f; --warn-line: #77601f;
    --err: #ffa59a; --err-bg: #3a1714; --err-line: #7d2e27; --info: #9cc6ea; --info-bg: #15283a; --info-line: #2d4f70;
    --nav-bg: #0a1311; --nav-ink: #e5f0ec; --nav-line: #24332f; --nav-on: #e5f0ec; --nav-on-ink: #0a1311; --nav-mark: transparent;
    --hero-a: #183530; --hero-b: #183530; --on-hero: #e5f0ec;
}

/* ---------- Text size ---------- */
html[data-text="large"] { --text-scale: 1.15; }
html[data-text="xlarge"] { --text-scale: 1.3; }
html { font-size: calc(100% * var(--text-scale) * var(--style-scale)); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* ---------- Base ---------- */
body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    line-height: 1.6;
}
h1, h2, h3 { font-family: var(--font-head); text-wrap: balance; }
a { color: var(--link); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--primary-soft); color: var(--ink); }
input, select, textarea, button { font-family: inherit; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea {
    background-color: var(--field);
    color: var(--ink);
}
::placeholder { color: var(--muted); opacity: .8; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Line icons (theme.js Theme.icon(name) returns the <svg>) ---------- */
.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.18em; }

/* ---------- The View button and its panel (theme.js) ---------- */
.view-switch { position: relative; display: inline-flex; }
.view-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: var(--radius-sm);
    border: 2px solid currentColor; background: transparent; color: inherit; font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer; }
.view-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.view-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 1000; width: min(340px, calc(100vw - 32px));
    background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: 14px 16px 16px; display: grid; gap: 14px; text-align: left; font-family: var(--font-body); }
.view-panel[hidden] { display: none; }
@media (max-width: 640px) {
    .view-panel { position: fixed; left: 16px; right: 16px; top: 72px; width: auto; max-height: calc(100vh - 88px); overflow-y: auto; }
}
.view-panel h2 { font: 700 1rem/1.3 var(--font-body); margin: 0; color: var(--ink); }
.view-panel fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.view-panel legend { font-size: .78rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: 6px; }
.view-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.view-opts label { position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 999px;
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: .95rem; font-weight: 600; cursor: pointer; }
.view-opts input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.view-opts label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.view-opts label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.view-opts .sample { font-family: var(--sample-font, inherit); }
.view-styles { display: grid; gap: 6px; }
.view-styles label { justify-content: space-between; border-radius: var(--radius-sm); padding: 8px 14px; gap: 10px; }
.view-styles small { font-weight: 400; font-size: .82rem; opacity: .85; }
.view-close { justify-self: end; min-height: 40px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
    background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }

/* ---------- Print: always plain light colors ---------- */
@media print {
    /* As specific as the strongest palette rule above, and later, so it always wins on paper. */
    :root, html[data-style][data-theme], html[data-style]:not([data-theme]), html[data-theme]:not([data-style]) {
        --bg: #ffffff; --surface: #ffffff; --surface-2: #f3f3f3; --ink: #000000; --muted: #333333;
        --line: #bbbbbb; --line-strong: #888888; --primary: #1f3a5f; --on-primary: #ffffff; --primary-soft: #eeeeee;
        --primary-ink: #1f3a5f; --link: #000000; --field: #ffffff;
        --ok: #1f6b3d; --ok-bg: #ffffff; --warn: #5a3a00; --warn-bg: #ffffff; --err: #8a1f16; --err-bg: #ffffff;
        --info: #1f3a5f; --info-bg: #ffffff; --nav-bg: #ffffff; --nav-ink: #000000;
        --ok-line: #999999; --warn-line: #999999; --err-line: #999999; --info-line: #999999; --accent: #888888;
        --hero-a: #ffffff; --hero-b: #ffffff; --on-hero: #000000;
        --shadow: none; --shadow-lg: none;
        color-scheme: light;
    }
    html { font-size: 100%; }
    .view-switch, .view-panel { display: none !important; }
}
