/* Shared appearance tokens. Theme thumbnails use the same palettes as the page. */
:root {
  --theme-font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  --theme-font-heading: Georgia, "Times New Roman", serif;
  --theme-font-code: ui-monospace, SFMono-Regular, Consolas, monospace;
  --theme-scheme: light;
  --theme-on-accent: #fff;
  --theme-shadow: #203e3312;
  --theme-code-keyword: #755199;
  --theme-code-string: #377052;
  --theme-code-number: #965222;
  --theme-danger: #a43e49;
  --theme-danger-soft: #f8e9ec;
  --theme-warning: #75613b;
  --theme-warning-soft: #f4f0e5;
}

:root, :root[data-theme="forest"], .theme-swatch[data-theme-choice="forest"] {
  --theme-page: #f8f9f5;
  --theme-surface: #ffffff;
  --theme-soft: #edf2e8;
  --theme-ink: #203e33;
  --theme-body: #40574a;
  --theme-muted: #607263;
  --theme-accent: #365f49;
  --theme-accent-hover: #284d39;
  --theme-line: #dce5d9;
  --theme-control: #acbda3;
  --theme-code: #edf2e8;
}

:root[data-theme="parchment"], .theme-swatch[data-theme-choice="parchment"] {
  --theme-page: #f6f0e5;
  --theme-surface: #fffdf8;
  --theme-soft: #eee4d3;
  --theme-ink: #3f342b;
  --theme-body: #645747;
  --theme-muted: #726352;
  --theme-accent: #9a5436;
  --theme-accent-hover: #784029;
  --theme-line: #ded2be;
  --theme-control: #baa78c;
  --theme-code: #eee4d3;
  --theme-font-heading: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --theme-code-keyword: #985035;
  --theme-code-string: #526443;
  --theme-code-number: #855380;
}

:root[data-theme="ocean"], .theme-swatch[data-theme-choice="ocean"] {
  --theme-page: #f0f5fa;
  --theme-surface: #ffffff;
  --theme-soft: #e3ecf5;
  --theme-ink: #21384f;
  --theme-body: #455b70;
  --theme-muted: #566b81;
  --theme-accent: #34658e;
  --theme-accent-hover: #254d70;
  --theme-line: #d6e1ec;
  --theme-control: #a4b9cd;
  --theme-code: #e3ecf5;
  --theme-code-keyword: #34658e;
  --theme-code-string: #32695c;
  --theme-code-number: #86588d;
}

:root[data-theme="lavender"], .theme-swatch[data-theme-choice="lavender"] {
  --theme-page: #f3f0f8;
  --theme-surface: #fdfbff;
  --theme-soft: #e9e2f2;
  --theme-ink: #352c49;
  --theme-body: #5b516c;
  --theme-muted: #6c5f7d;
  --theme-accent: #72539d;
  --theme-accent-hover: #583c7e;
  --theme-line: #ddd5e8;
  --theme-control: #b9a8cc;
  --theme-code: #e9e2f2;
  --theme-code-keyword: #72539d;
  --theme-code-string: #476c59;
  --theme-code-number: #98516e;
}

:root[data-theme="midnight"], .theme-swatch[data-theme-choice="midnight"] {
  --theme-page: #141b23;
  --theme-surface: #1d2733;
  --theme-soft: #283544;
  --theme-ink: #e2eaf2;
  --theme-body: #b9c6d3;
  --theme-muted: #92a4b6;
  --theme-accent: #9cc5e8;
  --theme-accent-hover: #c3ddf2;
  --theme-line: #344251;
  --theme-control: #647c93;
  --theme-code: #10161e;
  --theme-scheme: dark;
  --theme-on-accent: #141b23;
  --theme-shadow: #00000040;
  --theme-code-keyword: #9cc5e8;
  --theme-code-string: #b4d8c0;
  --theme-code-number: #e6c993;
  --theme-danger: #f0a5b0;
  --theme-danger-soft: #3b2833;
  --theme-warning: #e6c993;
  --theme-warning-soft: #352f24;
}

:root[data-theme="white"], .theme-swatch[data-theme-choice="white"] {
  --theme-page: #ffffff;
  --theme-surface: #ffffff;
  --theme-soft: #f2f4f6;
  --theme-ink: #242b33;
  --theme-body: #46515e;
  --theme-muted: #65707c;
  --theme-accent: #455e78;
  --theme-accent-hover: #2b435c;
  --theme-line: #dfe3e8;
  --theme-control: #aeb8c4;
  --theme-code: #f2f4f6;
}

html { background: var(--theme-page); color-scheme: var(--theme-scheme); }
html body { background: var(--theme-page); color: var(--theme-body); font-family: var(--theme-font-body); }
::selection { background: var(--theme-accent); color: var(--theme-on-accent); }

/* The appearance control is outside #site-nav so the existing priority-menu
   script never moves its buttons into the collapsed navigation. */
.masthead .masthead__menu { display: flex; align-items: center; gap: 22px; }
.masthead #site-nav { flex: 1; min-width: 0; }
.masthead { background: var(--theme-page); border-color: var(--theme-line); }
.masthead .greedy-nav { background: transparent; }
.masthead .greedy-nav a { color: var(--theme-body); }
.masthead .greedy-nav a:hover { color: var(--theme-accent); }
.masthead .greedy-nav button { background: var(--theme-accent); color: var(--theme-on-accent); }
.masthead .navicon, .masthead .navicon::before, .masthead .navicon::after { background: var(--theme-on-accent); }
.masthead .greedy-nav .visible-links a::before { background: var(--theme-accent); }
.masthead .greedy-nav .hidden-links { background: var(--theme-surface); border-color: var(--theme-line); }
.masthead .greedy-nav .hidden-links::before { border-color: var(--theme-line) transparent; }
.masthead .greedy-nav .hidden-links::after { border-color: var(--theme-surface) transparent; }
.masthead .greedy-nav .hidden-links a:hover { background: var(--theme-soft); }
body:has(.appearance__panel:not([hidden])) .masthead { z-index: 100; }

.appearance { position: relative; flex: 0 0 auto; color: var(--theme-ink); font: 400 14px/1.5 var(--theme-font-body); text-align: left; }
.appearance *, .appearance *::before, .appearance *::after { box-sizing: border-box; }
.appearance [hidden] { display: none !important; }
.appearance button { margin: 0; box-shadow: none; text-transform: none; font: inherit; cursor: pointer; }
.appearance button:focus-visible { outline: 2px solid var(--theme-accent); outline-offset: 4px; }
.appearance svg { display: block; flex: 0 0 auto; width: 20px; height: 20px; }
.appearance .appearance__trigger { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 40px; padding: 7px 13px; border: 1px solid var(--theme-control); border-radius: 9px; background: transparent; color: var(--theme-ink); font-size: 13px; font-weight: 550; white-space: nowrap; }
.appearance .appearance__trigger:hover, .appearance .appearance__trigger[aria-expanded="true"] { background: var(--theme-soft); border-color: var(--theme-accent); }
.appearance__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--theme-accent); }
.appearance__panel { position: absolute; top: calc(100% + 17px); right: 0; z-index: 50; width: 440px; max-width: calc(100vw - 32px); max-height: calc(100vh - 116px); max-height: calc(100dvh - 116px); overflow-y: auto; overscroll-behavior: contain; padding: 22px; border: 1px solid var(--theme-control); border-radius: 16px; background: var(--theme-surface); box-shadow: 0 12px 36px var(--theme-shadow), 0 3px 9px var(--theme-shadow); }
.appearance__panel :where(h2, h3, p) { margin: 0; padding: 0; }
.appearance__heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.appearance__heading h2 { color: var(--theme-ink); font: 650 22px/1.3 var(--theme-font-body); letter-spacing: -.5px; }
.appearance .appearance__close { display: grid; place-items: center; flex: 0 0 auto; width: 32px; height: 32px; padding: 5px; border: 0; border-radius: 6px; background: transparent; color: var(--theme-muted); }
.appearance .appearance__close:hover { background: var(--theme-soft); color: var(--theme-ink); }
.appearance__description { margin-top: 3px !important; color: var(--theme-body); font-size: 13px; }
.appearance__modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 19px; border: 1px solid var(--theme-control); border-radius: 8px; }
.appearance__modes button { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 41px; padding: 7px 4px; border: 0; border-radius: 7px; background: transparent; color: var(--theme-body); }
.appearance__modes button + button { border-left: 1px solid var(--theme-line); }
.appearance__modes button[aria-pressed="true"] { outline: 1px solid var(--theme-accent); outline-offset: -1px; background: var(--theme-soft); color: var(--theme-ink); font-weight: 600; }
.appearance__modes svg { width: 19px; height: 19px; }
.appearance__section-heading { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 5px 12px; margin: 20px 0 12px; padding-top: 17px; border-top: 1px solid var(--theme-line); }
.appearance__section-heading h3 { color: var(--theme-ink); font: 600 15px/1.4 var(--theme-font-body); }
.appearance__section-heading > span { color: var(--theme-accent); font-size: 12px; }
.appearance__themes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.appearance .theme-swatch { --theme-font-heading: Georgia, "Times New Roman", serif; position: relative; display: block; min-width: 0; padding: 12px 13px 10px; border: 1px solid var(--theme-line); border-radius: 9px; background: var(--theme-page); color: var(--theme-ink); text-align: left; }
.appearance .theme-swatch[data-theme-choice="parchment"] { --theme-font-heading: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif; }
.appearance .theme-swatch:hover { border-color: var(--theme-control); }
.appearance .theme-swatch[aria-pressed="true"] { border-color: var(--theme-accent); box-shadow: inset 0 0 0 1px var(--theme-accent); }
.theme-swatch__preview { display: block; height: 76px; overflow: hidden; }
.theme-swatch__masthead { display: flex; align-items: center; gap: 5px; color: var(--theme-ink); }
.theme-swatch__masthead b { flex: 1; font: 600 7px/1.3 var(--theme-font-heading); letter-spacing: -.1px; }
.theme-swatch__masthead > i { width: 10px; height: 2px; border-radius: 2px; background: var(--theme-muted); opacity: .5; }
.theme-swatch__masthead > i:first-of-type { background: var(--theme-accent); opacity: 1; }
.theme-swatch__type { display: block; margin: 6px 0 2px; font: 600 24px/1 var(--theme-font-heading); letter-spacing: -.5px; }
.theme-swatch__line { display: block; width: 72%; height: 2px; margin-top: 3px; border-radius: 2px; background: var(--theme-muted); opacity: .5; }
.theme-swatch__line--short { width: 58%; }
.theme-swatch__article { display: flex; align-items: center; gap: 7px; height: 24px; margin-top: 6px; padding: 4px 5px; border: 1px solid var(--theme-line); border-radius: 3px; background: var(--theme-surface); }
.theme-swatch__article > span:first-child { flex: 1; }
.theme-swatch__article i { display: block; width: 85%; height: 2px; margin: 2px 0; border-radius: 2px; background: var(--theme-muted); opacity: .5; }
.theme-swatch__article i:first-child { width: 46%; background: var(--theme-accent); opacity: 1; }
.theme-swatch__art { position: relative; width: 32px; height: 17px; overflow: hidden; border-radius: 2px; background: var(--theme-soft); }
.theme-swatch__art::before, .theme-swatch__art::after { content: ""; position: absolute; top: 8px; width: 21px; height: 21px; transform: rotate(45deg); background: var(--theme-muted); opacity: .35; }
.theme-swatch__art::after { left: 15px; top: 6px; opacity: .5; }
.theme-swatch__name { display: block; margin-top: 9px; font-size: 14px; font-weight: 600; line-height: 1.35; }
.theme-swatch__caption { display: block; margin-top: 2px; color: var(--theme-body); font-size: 11px; line-height: 1.4; }
.theme-swatch__check { position: absolute; top: 7px; right: 7px; display: none; place-items: center; width: 21px; height: 21px; border-radius: 50%; background: var(--theme-accent); color: var(--theme-on-accent); }
.theme-swatch[aria-pressed="true"] .theme-swatch__check { display: grid; }
.theme-swatch__check svg { width: 14px; height: 14px; }
.appearance__note { display: flex; align-items: center; gap: 12px; margin-top: 19px !important; padding: 15px 0; border-top: 1px solid var(--theme-line); color: var(--theme-body); font-size: 12px; }
.appearance__note > span { color: var(--theme-ink); font: 23px/1 var(--theme-font-heading); }
.appearance__footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding-top: 13px; border-top: 1px solid var(--theme-line); font-size: 11px; }
.appearance__saved { display: flex; align-items: center; gap: 7px; color: var(--theme-body); }
.appearance__saved svg { width: 16px; height: 16px; color: var(--theme-accent); }
.appearance .appearance__reset { min-height: 28px; padding: 0; border: 0; border-radius: 2px; background: transparent; color: var(--theme-accent); font-size: 11px; text-decoration: underline; text-underline-offset: 3px; }
.appearance__sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Shared reading components, including legacy article callouts and tables. */
html .page__content :is(.modern-deep-card, .qa-block, .custom-toc, .toc-container) { background: var(--theme-soft); border-color: var(--theme-control); color: var(--theme-body); }
html .page__content :is(.card-content, .math, .qa-block strong) { color: var(--theme-ink); }
html .page__content :is(.card-tag, .label-text, .hl-blue) { color: var(--theme-accent); }
html .page__content .hl-blue { background: var(--theme-soft); }
html .page__content .hl-red { background: var(--theme-danger-soft); color: var(--theme-danger); }
html .page__content .custom-toc :is(summary, .toc-header) { background: var(--theme-soft); color: var(--theme-ink); border-color: var(--theme-line); }
html .page__content .custom-toc a { color: var(--theme-accent); }
html .page__content .custom-toc .toc-content { background: var(--theme-surface); }
html .page__content .custom-toc .toc-title { color: var(--theme-ink); }
html .page__content .custom-toc .toc-arrow { color: var(--theme-accent); }
html .page__content .custom-toc .toc-link-main { background: var(--theme-soft); border-color: var(--theme-accent); color: var(--theme-ink); }
html .page__content .custom-toc .toc-link-main:hover { background: var(--theme-accent); color: var(--theme-on-accent); }
html :is(.forcing-toc, .article-toc) { color: var(--theme-body); }
html :is(.forcing-toc__panel, .article-toc__panel) { background: var(--theme-surface); border-color: var(--theme-line); }
html :is(.forcing-toc__header, .article-toc__header) { border-color: var(--theme-line); }
html :is(.forcing-toc__footer, .article-toc__footer) { border-color: var(--theme-line); }
html :is(.forcing-toc__footer, .article-toc__footer) a { color: var(--theme-muted); }
html :is(.forcing-toc__title, .article-toc__title) { color: var(--theme-ink); }
html :is(.forcing-toc__close, .article-toc__close) { background: var(--theme-soft); color: var(--theme-body); }
html :is(.forcing-toc__link, .article-toc__link) { color: var(--theme-muted); }
html :is(.forcing-toc, .article-toc) :is([class$="__link--level-1"], [class$="__link--level-2"]) { color: var(--theme-ink); }
html :is(.forcing-toc, .article-toc) a:is(:hover, [aria-current="location"]) { background: var(--theme-soft); color: var(--theme-accent); border-color: var(--theme-accent); }
html :is(.forcing-toc__toggle, .article-toc__toggle) { background: var(--theme-surface); color: var(--theme-accent); border-color: var(--theme-control) !important; }
html :is(.forcing-toc, .article-toc) :is(a, button, nav):focus-visible { outline-color: var(--theme-accent); }
:root[data-theme="midnight"] .author__urls :is(.fa, .fas, .fab) { color: var(--theme-muted); }
html .page__content .flash-table { background: var(--theme-surface); color: var(--theme-body); }
html .page__content .flash-table th { background: var(--theme-accent); color: var(--theme-on-accent); }
html .page__content .flash-table td { border-color: var(--theme-line); }
html .page__content .flash-table :is(.category, .hardware, .precision, .complexity, .streaming, .backprop, .core) { background: var(--theme-soft) !important; color: var(--theme-ink); border-color: var(--theme-control); }
html .page__content .flash-table tr:hover { background: var(--theme-soft); }
html .page__content .flash-table :is(.definition, .math) { color: var(--theme-body); }
html .page__content .flash-table .symbol { color: var(--theme-code-number); }
html .page__content .flash-table .highlight { background: var(--theme-soft); color: var(--theme-ink); }

@media (max-width: 900px) {
  .masthead .masthead__menu { gap: 14px; }
  .appearance__trigger-label, .appearance__trigger .appearance__dot { display: none; }
  .appearance .appearance__trigger { width: 42px; min-height: 42px; padding: 9px; }
}
@media (max-width: 620px) {
  .masthead .masthead__menu { gap: 12px; }
  body .masthead #site-nav .visible-links li:first-child a { max-width: calc(100vw - 180px); margin-right: 0; font-size: 14px; line-height: 1.35; white-space: normal; }
  body .masthead #site-nav .masthead__menu-item--lg { padding-right: 0; }
  .appearance__panel { position: fixed; top: 83px; right: 12px; width: 440px; max-width: calc(100% - 24px); max-height: calc(100vh - 99px); max-height: calc(100dvh - 99px); padding: 18px; border-radius: 13px; }
  .appearance__modes button { min-height: 44px; }
  .appearance__themes { gap: 9px; }
  .appearance .theme-swatch { padding: 10px 11px; }
  .theme-swatch__name { font-size: 13px; }
  .appearance__close { min-width: 40px; min-height: 40px; }
  .appearance .appearance__reset { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .appearance *, .appearance *::before, .appearance *::after { transition: none !important; }
}
@media print {
  .appearance { display: none; }
}
