/* Reading aids. Everything that changes existing content is scoped under
   html.ra-on, which reading-aids.js sets only on pages that carry aid markup
   and only while the reader has the aids on. Elements the script creates
   (markers, buttons, the card, the switch) are hidden without it.
   The one unscoped rule is .drawer-meta: a drawer's second line is page text. */

:root {
  --ra-accent: #235f9e;
  --ra-accent-soft: #dce8f5;
  --ra-ink: #18212f;
  --ra-muted: #5d6877;
  --ra-line: #d8dde6;
  --ra-line-strong: #b4bcc8;
  --ra-panel: #ffffff;
  --ra-note-bg: #f1f4f8;
  --ra-shadow: 0 14px 34px rgba(24, 33, 47, 0.16);
  --ra-note-width: 15.5rem;

  /* Series and equation palette: --ra-c-KEY, --ra-c-KEY-soft, --ra-c-KEY-text. */
  --ra-c-sig: #886214;
  --ra-c-sig-soft: #fff1bd;
  --ra-c-sig-text: #886214;
  --ra-c-nui: #2b6f99;
  --ra-c-nui-soft: #e1f0f9;
  --ra-c-nui-text: #2b6f99;
  --ra-c-opt: #367d51;
  --ra-c-opt-soft: #e1efe4;
  --ra-c-zeroGap: #167c88;
  --ra-c-zeroGap-soft: #d9eeee;
  --ra-c-interp: #18212f;
  --ra-c-interp-soft: #e6e9ee;
  --ra-c-train: #b05f3b;
  --ra-c-train-soft: #f6e3d9;
  --ra-c-sgd: #7862b2;
  --ra-c-sgd-soft: #ebe7f6;
  --ra-c-target: #235f9e;
  --ra-c-target-soft: #dfe9f5;
  --ra-c-baseline: #687587;
  --ra-c-baseline-soft: #f0f3f6;
  --ra-c-baselineCap: #b43468;
  --ra-c-baselineCap-soft: #f7e0ea;
  --ra-c-capped: #7862b2;
  --ra-c-capped-soft: #ebe7f6;
  --ra-c-fresh: #367d51;
  --ra-c-fresh-soft: #e1efe4;
}

/* Drawer second lines: static page text, shown with or without the aids. */
summary > .drawer-meta {
  display: block;
  margin-top: 3px;
  color: var(--series-muted, #5d6877);
  font-size: 0.85em;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.45;
  text-transform: none;
}

/* Elements the script creates stay hidden unless the aids are on. */
.ra-sn-ref,
.ra-sn-num,
.ra-symbols-button,
.ra-steps-nav { display: none; }

/* ---------------- glosses ---------------- */
html.ra-on .ra-gloss {
  cursor: help;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: #6f7b8b;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  border-radius: 3px;
}
html.ra-on .ra-gloss[aria-expanded="true"] {
  background: var(--ra-accent-soft);
  text-decoration-color: var(--ra-accent);
}
html.ra-on .ra-gloss:focus-visible,
html.ra-on .ra-hl-term:focus-visible {
  outline: 2.5px solid var(--ra-accent);
  outline-offset: 2px;
}

/* ---------------- the card ---------------- */
.ra-card {
  position: absolute;
  z-index: 29;
  box-sizing: border-box;
  width: max-content;
  max-width: min(22rem, calc(100vw - 24px));
  max-height: 60vh;
  overflow: auto;
  padding: 11px 14px 12px;
  border: 1px solid var(--ra-line-strong);
  border-radius: 9px;
  background: var(--ra-panel);
  box-shadow: var(--ra-shadow);
  color: var(--ra-ink);
  font: 400 0.87rem/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: left;
  overflow-wrap: break-word;
}
.ra-card[hidden] { display: none; }
html:not(.ra-on) .ra-card { display: none; }
.ra-card p { margin: 0 0 6px; }
.ra-card p:last-child { margin-bottom: 0; }
.ra-card-pinned { padding-right: 36px; }
.ra-card-kicker {
  color: var(--ra-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ra-card .ra-card-kicker { margin-bottom: 3px; }
.ra-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
}
.ra-card-title:focus { outline: none; }
.ra-card-title:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 2px; border-radius: 3px; }
.ra-card-source,
.ra-card-settings { color: var(--ra-muted); font-size: 0.78rem; }
.ra-card a { color: var(--ra-accent); font-weight: 650; text-underline-offset: 2px; }
.ra-card-open a { display: inline-block; margin-top: 2px; padding: 4px 0; }
.ra-card-symbol + .ra-card-symbol { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--ra-line); }
.ra-card .ra-card-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ra-muted);
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.ra-card .ra-card-close:hover { border: 0; background: #eef1f5; color: var(--ra-ink); }
.ra-card .ra-card-close:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 0; }
.ra-card [data-tex] .katex { font-size: 1.04em; }

/* ---------------- sidenotes ---------------- */
html.ra-on [data-ra-paren] { display: none; }
/* A raised number that leaves the line height alone; ::after widens the tap target. */
html.ra-on .ra-sn-ref {
  position: relative;
  top: -0.5em;
  display: inline-block;
  margin: 0;
  padding: 0 2px 0 1px;
  border: 0;
  border-radius: 3px;
  background: none;
  color: var(--ra-accent);
  font: inherit;
  font-size: 0.72em;
  font-weight: 750;
  line-height: 1;
  text-align: center;
  vertical-align: baseline;
  cursor: pointer;
}
html.ra-on .ra-sn-ref::after { content: ""; position: absolute; inset: -8px -7px; }
html.ra-on .ra-sn-ref:hover { border: 0; background: var(--ra-accent-soft); color: var(--ra-accent); }
html.ra-on .ra-sn-ref[aria-expanded="true"] { background: var(--ra-accent-soft); }
html.ra-on .ra-sn-ref[aria-hidden="true"]:hover { background: none; }
html.ra-on .ra-sn-ref:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 1px; }
html.ra-on .ra-sn-ref[aria-hidden="true"] { cursor: default; }
html.ra-on .ra-sn-num {
  display: inline;
  margin-right: 0.35em;
  color: var(--ra-accent);
  font-size: 0.9em;
  font-weight: 750;
}
html.ra-on .ra-sn.ra-sn-toggle { display: none; }
html.ra-on .ra-sn.ra-sn-toggle.ra-sn-open {
  display: block;
  margin: 0.5rem 0 0.7rem;
  padding: 0.55rem 0.8rem;
  border-left: 3px solid var(--ra-accent);
  border-radius: 0 6px 6px 0;
  background: var(--ra-note-bg);
  color: #333d4b;
  font-size: 0.88em;
  font-weight: 400;
  line-height: 1.5;
}
html.ra-on .ra-sn.ra-sn-measure,
html.ra-on .ra-sn.ra-sn-margin {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  box-sizing: border-box;
  width: var(--ra-note-width);
  padding: 0 0 0 10px;
  border-left: 2px solid var(--ra-line);
  color: #3a4452;
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  text-indent: 0;
  white-space: normal;
}
html.ra-on .ra-sn.ra-sn-measure { visibility: hidden; display: block; }
html.ra-on .ra-sn.ra-sn-margin { display: block; }

/* ---------------- linked highlighting ---------------- */
html.ra-on .ra-hl-term {
  border-radius: 2px;
  box-shadow: inset 0 -2px 0 var(--ra-k, var(--ra-accent));
  color: var(--ra-kt, inherit);
  cursor: pointer;
}
html.ra-on .ra-hl-term.ra-hl-pinned { outline: 1.5px solid var(--ra-k, var(--ra-accent)); outline-offset: 1px; }
html.ra-on [data-ra-hl-off] .ra-hl-term,
html.ra-on .ra-hl-term[aria-disabled="true"] {
  box-shadow: none;
  color: inherit;
  cursor: text;
}
html.ra-on [data-series] { transition: opacity 0.16s, fill-opacity 0.16s, stroke-opacity 0.16s; }
.ra-show-diagram { display: none; }
html.ra-on .ra-show-diagram:not([hidden]) {
  display: inline-block;
  margin-inline-start: .4em;
  padding: .15em .45em;
  border: 1px solid var(--ra-line-strong);
  border-radius: 5px;
  background: var(--ra-panel);
  color: var(--ra-accent);
  font: 600 .8em/1.4 system-ui, sans-serif;
  cursor: pointer;
}
html.ra-on .ra-show-diagram:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 2px; }
@media print { html.ra-on .ra-show-diagram { display: none !important; } }
.ra-diagram-visit { display: none; }
html.ra-on .ra-diagram-visit:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .65rem;
  margin: .5rem 0;
  padding: .45rem .6rem;
  border: 1px solid var(--ra-line-strong);
  border-radius: 6px;
  background: var(--ra-panel);
  color: var(--ra-ink);
  font: 500 .85rem/1.4 system-ui, sans-serif;
}
.ra-diagram-visit > span { flex: 1 1 12rem; overflow-wrap: anywhere; }
.ra-diagram-visit > button {
  min-height: 36px;
  padding: .2rem .45rem;
  border: 1px solid var(--ra-line-strong);
  border-radius: 4px;
  background: var(--ra-panel);
  color: var(--ra-accent);
  font: inherit;
  cursor: pointer;
}
.ra-diagram-visit > button:disabled { opacity: .6; cursor: default; }
.ra-diagram-visit:focus-visible, .ra-diagram-visit > button:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 2px; }
@media print { html.ra-on .ra-diagram-visit { display: none !important; } }

/* ---------------- coloured equations and symbols ---------------- */
html.ra-on .katex .ra-sig { color: var(--ra-c-sig); }
html.ra-on .katex .ra-nui { color: var(--ra-c-nui); }
html.ra-on .katex .ra-opt { color: var(--ra-c-opt); }
html.ra-on .katex .ra-interp { color: var(--ra-c-interp); }
html.ra-on .katex .ra-train { color: var(--ra-c-train); }
html.ra-on .katex .ra-target { color: var(--ra-c-target); }
html.ra-on .katex .enclosing[class*=" ra-"] { border-radius: 4px; transition: background-color 0.15s; }
html.ra-on .katex-html [class*="ra-sym-"] { cursor: help; border-radius: 3px; }
html.ra-on .katex-html [class*="ra-sym-"]:hover { background: rgba(35, 95, 158, 0.14); }
html.ra-on .ra-symbols-button {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0 0 0.6rem;
  padding: 2px 10px;
  border: 1px solid var(--ra-line-strong);
  border-radius: 999px;
  background: var(--ra-panel);
  color: var(--ra-accent);
  font: 650 0.78rem/1.2 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}
html.ra-on .ra-symbols-button:hover,
html.ra-on .ra-symbols-button[aria-expanded="true"] { border-color: var(--ra-accent); background: var(--ra-accent-soft); color: var(--ra-accent); }
html.ra-on .ra-symbols-button:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 2px; }

/* ---------------- stepped figures ---------------- */
/* Pin mode (D1): the figure slot stays while the step text scrolls. The page
   decides the grid; these rules pin the slot and scale its picture. */
html.ra-on .ra-steps-pin [data-ra-steps-figure] {
  position: sticky;
  top: calc(var(--blog-sticky-stack-height, 0px) + 12px);
  align-self: start;
}
html.ra-on .ra-steps-pin [data-ra-steps-figure] svg {
  max-height: calc(100vh - var(--blog-sticky-stack-height, 0px) - 40px);
}
html.ra-on .ra-steps-pin [data-ra-step] { cursor: pointer; }
html.ra-on .ra-steps-pin:not(.ra-steps-detached) [data-ra-step] { opacity: 1; }
html.ra-on .ra-steps-pin:not(.ra-steps-detached) [data-ra-step].ra-step-active { box-shadow: -3px 0 var(--ra-accent); }
html.ra-on .ra-steps-pin [data-ra-step] a,
html.ra-on .ra-steps-pin [data-ra-step] button { cursor: pointer; }
/* Back/Next (D2): every step stays visible; the active one is marked. */
html.ra-on .ra-steps-buttons:not(.ra-steps-detached) [data-ra-step].ra-step-active {
  box-shadow: inset 3px 0 0 var(--ra-accent);
  padding-left: 0.75rem;
}
html.ra-on .ra-steps-buttons .ra-steps-nav,
html.ra-on .ra-steps-detached .ra-steps-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin: 8px 0 0;
}
html.ra-on .ra-steps-buttons .ra-steps-current { display: block; }
.ra-steps-current[hidden] { display: none !important; }
.ra-steps-current > .ra-steps-summary-heading { display: block; font-size: inherit; line-height: 1.4; }
.ra-steps-current > p { margin: .35em 0 0; font-size: inherit; line-height: inherit; }
/* These captions describe controls that exist only while the aids are active. */
html:not(.ra-on) .reader-guide-effect { display: none; }
html.ra-on .ra-steps-pin.ra-steps-detached .ra-steps-back,
html.ra-on .ra-steps-pin.ra-steps-detached .ra-steps-next,
html.ra-on .ra-steps-detached .ra-steps-count { display: none; }
html.ra-on .ra-steps-nav button {
  min-height: 40px;
  padding: 7px 14px;
  border: 1px solid var(--ra-line-strong);
  border-radius: 8px;
  background: var(--ra-panel);
  color: var(--ra-ink);
  font: 650 0.9rem/1.2 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  cursor: pointer;
}
html.ra-on .ra-steps-nav button:hover:not(:disabled):not([aria-disabled="true"]) { border-color: var(--ra-accent); background: var(--ra-accent-soft); color: var(--ra-ink); }
html.ra-on .ra-steps-nav button:disabled, html.ra-on .ra-steps-nav button[aria-disabled="true"] { opacity: 0.4; cursor: default; }
html.ra-on .ra-steps-nav button:focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 2px; }
html.ra-on .ra-steps-count { color: var(--ra-muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.ra-steps-nav [hidden] { display: none !important; }

/* ---------------- footer switch ---------------- */
/* Selectors outrank the site's global button rules (button:hover, button[aria-pressed="true"]). */
.ra-switch { flex: 0 0 auto; margin: 0; }
.ra-switch .ra-switch-button,
.ra-switch .ra-switch-button:hover,
.ra-switch .ra-switch-button[aria-pressed] {
  min-height: 32px;
  padding: 4px 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}
.ra-switch .ra-switch-button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* ---------------- reduced motion ---------------- */
@media (prefers-reduced-motion: reduce) {
  html.ra-on [data-series],
  html.ra-on .ra-steps-pin [data-ra-step],
  html.ra-on .katex .enclosing[class*=" ra-"] { transition: none; }
}

.ra-card .ra-card-line { display: block; }
.ra-card .ra-card-line + .ra-card-line { margin-top: 0.25em; }

/* ---------------- print: plain text ---------------- */
@media print {
  .ra-card,
  .ra-sn-ref,
  .ra-sn-num,
  .ra-symbols-button,
  .ra-steps-nav,
  .ra-steps-current,
  .ra-switch { display: none !important; }
  html.ra-on .reader-guide-effect { display: none !important; }
  html.ra-on [data-ra-paren] { display: inline; }
  html.ra-on .ra-sn.ra-sn-toggle,
  html.ra-on .ra-sn.ra-sn-toggle.ra-sn-open,
  html.ra-on .ra-sn.ra-sn-margin,
  html.ra-on .ra-sn.ra-sn-measure {
    position: static;
    display: inline;
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
    visibility: visible;
  }
  html.ra-on .ra-gloss,
  html.ra-on .ra-gloss[aria-expanded="true"],
  html.ra-on .ra-hl-term { text-decoration: none; box-shadow: none; background: none; outline: none; color: inherit; }
  html.ra-on .ra-steps-buttons:not(.ra-steps-detached) [data-ra-step].ra-step-active { box-shadow: none; padding-left: 0; }
  html.ra-on .ra-steps-pin [data-ra-steps-figure] { position: static; }
  html.ra-on .ra-steps-pin [data-ra-step],
  html.ra-on .ra-steps-pin:not(.ra-steps-detached) [data-ra-step]:not(.ra-step-active) { opacity: 1; }
}
