/* Ram Labs theme layer. Load after every shared and refinement stylesheet.
   The palette remains black, white and orange; dividers use alpha only.
   Images, the orange wordmark and the favicon are never filtered or inverted. */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --ink: #000000;
  --muted: #000000;
  --paper: #ffffff;
  --wash: #ffffff;
  --line: rgba(0, 0, 0, 0.18);
  --dark: #000000;
  --orange: #f15b2a;
  --accent: #f15b2a;
  --theme-moon-display: block;
  --theme-sun-display: none;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #ffffff;
  --muted: #ffffff;
  --paper: #000000;
  --wash: #000000;
  --line: rgba(255, 255, 255, 0.24);
  --theme-moon-display: none;
  --theme-sun-display: block;
}

/* The default also works without JavaScript. An explicit data-theme wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --ink: #ffffff;
    --muted: #ffffff;
    --paper: #000000;
    --wash: #000000;
    --line: rgba(255, 255, 255, 0.24);
    --theme-moon-display: none;
    --theme-sun-display: block;
  }
}

html,
body {
  background-color: var(--paper);
  color: var(--ink);
}

html {
  scrollbar-color: var(--ink) var(--paper);
}

/* Legacy fixed-white surfaces in site.css. Keep their layout untouched. */
.site-header,
.mega,
.mobile-nav,
.mobile-nav.is-open,
.stage-bar,
.source-banner,
.search-dialog {
  background-color: var(--paper);
  color: var(--ink);
}

.skip {
  background-color: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
}

.menu-toggle,
.dialog-close {
  background-color: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
}

.search-dialog {
  border-color: var(--ink);
}

/* Permanent dark contexts retain the existing visual hierarchy in either mode. */
.dark,
.hero,
.site-footer,
.utility {
  color-scheme: dark;
  --ink: #ffffff;
  --muted: #ffffff;
  --paper: #000000;
  --wash: #000000;
  --line: rgba(255, 255, 255, 0.24);
}

/* The orange invitation bands need their own black-text context. */
.join-band {
  color-scheme: light;
  --ink: #000000;
  --muted: #000000;
  --paper: #f15b2a;
  --wash: #f15b2a;
  --line: #000000;
  background-color: #f15b2a;
  color: #000000;
}

.join-band .button {
  background-color: #000000;
  border-color: #000000;
  color: #ffffff;
}

.join-band .button:hover {
  background-color: #ffffff;
  border-color: #000000;
  color: #000000;
}

.join-band .button.outline {
  background-color: transparent;
  border-color: #000000;
  color: #000000;
}

.join-band .button.outline:hover {
  background-color: #000000;
  color: #ffffff;
}

/* The normal orange button stays distinguishable from a black page on hover. */
.button.orange:hover {
  background-color: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

/* Fixed black details in extension.css. Accent borders remain orange. */
.focus-action {
  color: var(--ink);
}

.focus-card,
.collection-card,
.publication-card,
.page-section-nav {
  border-bottom-color: var(--line);
}

.impact-section,
.collections-section,
.research-questions-section {
  border-color: var(--line);
}

.topic-link {
  border-color: var(--ink);
  color: var(--ink);
}

.topic-link:hover {
  background-color: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.topic-reading-list {
  border-block-color: var(--line);
}

.topic-reading-list a + a {
  border-top-color: var(--line);
}

/* Native widgets follow the selected palette, including autofilled fields. */
input,
select,
textarea {
  caret-color: var(--ink);
}

option,
optgroup {
  background-color: var(--paper);
  color: var(--ink);
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--paper) inset;
}

/* The interactive control's background shorthand resets the shared arrow.
   Restore a currentColor arrow so it remains visible in either theme. */
.rlx-control select {
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 19px) 24px, calc(100% - 14px) 24px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

/* A 44px control with a stable accessible name and pressed state.
   The moon offers dark mode; the sun offers a return to light mode. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  line-height: 1;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.theme-toggle[aria-pressed="true"] {
  border-color: var(--orange);
}

.theme-toggle:hover {
  background-color: var(--orange);
  color: #000000;
  border-color: var(--orange);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--orange);
  outline-offset: 4px;
}

.theme-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  pointer-events: none;
}

.theme-icon-moon {
  display: var(--theme-moon-display, block);
}

.theme-icon-sun {
  display: var(--theme-sun-display, none);
}

.theme-toggle-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle {
    transition: none;
  }
}

/* Print never inherits a saved dark preference or its native form colour. */
@media print {
  :root,
  :root[data-theme],
  :root:not([data-theme]),
  .dark,
  .hero,
  .site-footer,
  .utility,
  .join-band {
    color-scheme: light !important;
    --ink: #000000;
    --muted: #000000;
    --paper: #ffffff;
    --wash: #ffffff;
    --line: #000000;
    background-color: #ffffff;
    color: #000000;
  }

  .theme-toggle {
    display: none !important;
  }

  .dark p,
  .hero p,
  .join-band p {
    color: #000000;
  }
}

