/* Align the homepage and Matrix Live with the established article palette.
   Light is the article paper. Dark is the article near-black, not the older navy.
   An explicit data-theme wins. With no choice, the system preference is used.
   Storage key remains mrh-theme. */

html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
html:not([data-theme="dark"]) {
  --bg: #FBFAF6;
  --paper: #FBFAF6;
  --panel: #FFFFFF;
  --card: #FFFFFF;
  --surface: #FFFFFF;
  --fg: #1A1D1B;
  --text: #1A1D1B;
  --muted: #565D66;
  --line: #E2DED3;
  --border: #E2DED3;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) { color-scheme: dark; }
}

html[data-theme="dark"],
html[data-theme="dark"]:root {
  --bg: #0A0C0F;
  --paper: #0A0C0F;
  --card: #151A20;
  --surface: #151A20;
  --surface2: #1B2129;
  --fg: #F5F5F2;
  --text: #F5F5F2;
  --muted: #BAC3CC;
  --grey: #BAC3CC;
  --line: #2A323C;
  --border: #2A323C;
  --cyan: #33B5E5;
  --link-teal: #33B5E5;
  --accent: #33B5E5;
  --accent-text: #33B5E5;
  --mint: #102838;
  --panel: #151A20;
  --vote-grey: #1B2129;
  --copy-chip: #1B2129;
  --copy-ink: #F5F5F2;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0A0C0F;
    --paper: #0A0C0F;
    --card: #151A20;
    --surface: #151A20;
    --surface2: #1B2129;
    --fg: #F5F5F2;
    --text: #F5F5F2;
    --muted: #BAC3CC;
    --grey: #BAC3CC;
    --line: #2A323C;
    --border: #2A323C;
    --cyan: #33B5E5;
    --link-teal: #33B5E5;
    --accent: #33B5E5;
    --accent-text: #33B5E5;
    --mint: #102838;
    --panel: #151A20;
    --vote-grey: #1B2129;
    --copy-chip: #1B2129;
    --copy-ink: #F5F5F2;
  }
}

html[data-theme="dark"] .home-front .site-header,
html[data-theme="dark"] .home-front .welcome-strap {
  background: var(--bg);
  color: var(--fg);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .home-front .site-header,
  html:not([data-theme="light"]) .home-front .welcome-strap {
    background: var(--bg);
    color: var(--fg);
  }
}

/* Pill colours. The open rule in site-nav.css
   (html.js body nav.main#main-nav.open a, and the same with [class^="e-"])
   is stronger than a plain current-page rule, so an open light menu painted
   the current link pale. These beat that rule for both menus
   (.main-nav on the homepage, nav.main on articles and Live), open and
   closed, plain and section, and every link state. Current stays teal.
   Light rules are first. System dark, then an explicit dark choice, follow
   so they win when they apply. An explicit light choice is excluded from both. */
html.js:not([data-theme="dark"]) body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a:is(:link, :visited, :hover, :focus, :focus-visible, :active),
html.js:not([data-theme="dark"]) body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
  background: #E3F4FA;
  color: #005F80;
  box-shadow: none;
  border-bottom: 0;
}
html.js:not([data-theme="dark"]) body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a[aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active),
html.js:not([data-theme="dark"]) body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"][aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
  background: #00739A;
  color: #fff;
  box-shadow: none;
  border-bottom: 0;
}
@media (prefers-color-scheme: dark) {
  html.js:not([data-theme="light"]) body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a:is(:link, :visited, :hover, :focus, :focus-visible, :active),
  html.js:not([data-theme="light"]) body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
    background: #1B2129;
    color: #F5F5F2;
    box-shadow: none;
    border-bottom: 0;
  }
  html.js:not([data-theme="light"]) body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a[aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active),
  html.js:not([data-theme="light"]) body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"][aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
    background: #33B5E5;
    color: #0B0B0B;
    box-shadow: none;
    border-bottom: 0;
  }
}
html.js[data-theme="dark"] body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a:is(:link, :visited, :hover, :focus, :focus-visible, :active),
html.js[data-theme="dark"] body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
  background: #1B2129;
  color: #F5F5F2;
  box-shadow: none;
  border-bottom: 0;
}
html.js[data-theme="dark"] body :is(.home-front .main-nav, .home-front .main-nav.open, nav.main#main-nav, nav.main#main-nav.open) a[aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active),
html.js[data-theme="dark"] body :is(.home-front .main-nav.open, nav.main#main-nav.open) a[class^="e-"][aria-current="page"]:is(:link, :visited, :hover, :focus, :focus-visible, :active) {
  background: #33B5E5;
  color: #0B0B0B;
  box-shadow: none;
  border-bottom: 0;
}

/* Same switch as the older pages: a 44px moon/sun, not a text label. */
.home-front .theme-btn,
.mrh-live-nav .theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line, #d9d3c5);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.home-front .tb-ic,
.mrh-live-nav .tb-ic {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: inset -6px -3px 0 0 #F5A300;
  transform: rotate(-20deg);
}
.home-front .theme-btn[aria-pressed="true"] .tb-ic,
.mrh-live-nav .theme-btn[aria-pressed="true"] .tb-ic {
  background: #F5A300;
  box-shadow: 0 0 0 3px rgba(245, 163, 0, .3);
}

/* Matrix Live desk pages follow the same tokens. */
.mrh-live-nav { background: var(--bg, #FBFAF6); color: var(--fg, #1A1D1B); border-bottom-color: var(--line, #E2DED3); }
html[data-theme="dark"] .mrh-live-nav,
html[data-theme="dark"] .mrh-live-nav .menu-btn,
html[data-theme="dark"] .mrh-live-nav .theme-btn {
  background: var(--bg);
  color: var(--fg);
  border-color: var(--line);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .mrh-live-nav,
  html:not([data-theme="light"]) .mrh-live-nav .menu-btn,
  html:not([data-theme="light"]) .mrh-live-nav .theme-btn {
    background: var(--bg);
    color: var(--fg);
    border-color: var(--line);
  }
  html:not([data-theme="light"]) .mrh-live-nav nav.main.open { background: var(--bg); }
}
html[data-theme="dark"] .mrh-live-nav nav.main.open { background: var(--bg); }
