/* Palette bridge for the active encounter, editorial pages, paper reader and course.
   Load last. The original type, layout, SVG geometry and semantic states stay local. */
:root[data-ra-theme="dark"] {
  --ra-ground: #2d2631;
  --ra-paper: #2d2631;
  --ra-surface: #39313d;
  --ra-surface-deep: #453a48;
  --ra-ink: #f6eddf;
  --ra-secondary: #dfd2dc;
  --ra-muted: #cfc0cc;
  --ra-accent: #efbc9c;
  --ra-line: #746374;
  --ra-soft-line: #574a5a;
  --ra-teal: #accfc3;
  --ra-teal-wash: #35433f;
  --ra-pass: #b8d5b6;
  --ra-neutral: #b9cede;
  --ra-selection: #efbc9c;
  --ra-selection-ink: #302732;
  --ra-code-bg: #211b25;
  --ra-code-fg: #f6eddf;
}
:root[data-ra-theme="light"] {
  --ra-ground: #f2ede4;
  --ra-paper: #f7f2e9;
  --ra-surface: #ebe3d8;
  --ra-surface-deep: #e1d6c9;
  --ra-ink: #302d31;
  --ra-secondary: #514750;
  --ra-muted: #625863;
  --ra-accent: #914936;
  --ra-line: #b1a0aa;
  --ra-soft-line: #d7cbd0;
  --ra-teal: #285d53;
  --ra-teal-wash: #dfe8e1;
  --ra-pass: #35653f;
  --ra-neutral: #35576e;
  --ra-selection: #dbc7ad;
  --ra-selection-ink: #302d31;
  --ra-code-bg: #302732;
  --ra-code-fg: #f6eddf;
}
:root[data-ra-theme],
:root[data-ra-theme] dialog,
:root[data-ra-theme] #character-picker {
  --ground: var(--ra-ground);
  --paper: var(--ra-paper);
  --paper-2: var(--ra-surface);
  --paper-3: var(--ra-surface-deep);
  --bg: var(--ra-ground);
  --surface: var(--ra-surface);
  --surface-note: var(--ra-surface);
  --ink: var(--ra-ink);
  --ink-2: var(--ra-secondary);
  --ink-3: var(--ra-muted);
  --ink-4: var(--ra-muted);
  --muted: var(--ra-muted);
  --text-muted: var(--ra-muted);
  --red: var(--ra-accent);
  --accent: var(--ra-accent);
  --regression: var(--ra-accent);
  --pen-fail: var(--ra-accent);
  --pen-pass: var(--ra-pass);
  --pen-neutral: var(--ra-neutral);
  --pen-muted: var(--ra-muted);
  --pencil: var(--ra-accent);
  --line: var(--ra-line);
  --rule: var(--ra-line);
  --rule-strong: var(--ra-line);
  --rule-soft: var(--ra-soft-line);
  --teal: var(--ra-teal);
  --teal-wash: var(--ra-teal-wash);
  --atlas-ink: var(--ra-teal);
  --accent-reading: var(--ra-teal);
  --accent-reading-strong: var(--ra-teal);
  --reading-rule: var(--ra-line);
  --focus: var(--ra-accent);
  --accent-wash: color-mix(in srgb, var(--ra-accent) 10%, transparent);
  --accent-soft: color-mix(in srgb, var(--ra-accent) 18%, transparent);
  --accent-line: color-mix(in srgb, var(--ra-accent) 45%, transparent);
  --regression-wash: var(--accent-wash);
  --code-bg: var(--ra-code-bg);
  --code-fg: var(--ra-code-fg);
  --code-dim: #c9b8c8;
  --code-mark: #efbc9c;
  color-scheme: inherit;
}
:root[data-ra-theme][data-ra-surface="encounter"] { --paper: var(--ra-surface); }
:root[data-ra-theme] { background: var(--ground); scrollbar-color: var(--ra-line) var(--ground); }
:root[data-ra-theme] body { caret-color: var(--ra-accent); }
:root[data-ra-theme] ::selection { background: var(--ra-selection); color: var(--ra-selection-ink); }
:root[data-ra-theme] :focus-visible { outline: 2px solid var(--ra-accent); outline-offset: 4px; }
:root[data-ra-theme] dialog,
:root[data-ra-theme] #character-picker { background: var(--ra-surface); color: var(--ra-ink); }
:root[data-ra-theme] dialog::backdrop { background: #150f1db8; }
:root[data-ra-theme] input,
:root[data-ra-theme] textarea,
:root[data-ra-theme] select { accent-color: var(--ra-teal); }
:root[data-ra-theme] input::placeholder,
:root[data-ra-theme] textarea::placeholder { color: var(--ra-muted); opacity: 1; }
/* Preserve the supplied mark's strokes; the pale square blends into its surface. */
:root[data-ra-theme="dark"] .brand img[src$="mark.svg"] { filter: invert(1) grayscale(1); mix-blend-mode: screen; }
:root[data-ra-theme="light"] .brand img[src$="mark.svg"] { filter: none; mix-blend-mode: multiply; }
/* Shared control joins existing navigation rather than covering page content. */
.ra-theme-switch {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--ra-line);
  border-radius: 0;
  background: transparent;
  color: var(--ra-ink);
  font: 500 13px/1.3 var(--sans, Interface, Human, sans-serif);
  white-space: nowrap;
  cursor: pointer;
}
.ra-theme-switch:hover { color: var(--ra-accent); border-color: var(--ra-accent); }
.site-header .ra-theme-switch { margin-left: auto; }
.brand-line { flex-wrap: wrap; }
.ra-theme-switch-standalone { margin: 16px 24px; }
.ra-theme-switch-mobile { display: none; }
/* Explicit fixes for legacy hard-coded surfaces and status inks. */
:root[data-ra-theme] .tracediff__frame { background: var(--ra-surface); }
:root[data-ra-theme] .focus-note { color: var(--ra-accent); }
:root[data-ra-theme] pre { background: var(--ra-code-bg); color: var(--ra-code-fg); }
:root[data-ra-theme] pre code { color: inherit; background: transparent; }
:root[data-ra-theme] .sticky { background: var(--ra-surface-deep); }
:root[data-ra-theme] .home-experience { --paper:var(--ra-paper); --atlas-ink:var(--ra-teal); --atlas-accent:var(--ra-accent); }
:root[data-ra-theme] .arrangement-diagram circle,
:root[data-ra-theme] .arrangement-diagram rect { stroke: var(--ra-teal); }
:root[data-ra-theme] .arrangement-diagram .motor { fill: var(--ra-teal); }
:root[data-ra-theme] .status-badge { background: var(--ra-surface); }
:root[data-ra-theme="dark"] .status-badge.confirmed { color: var(--ra-pass); }
:root[data-ra-theme="dark"] .status-badge.preregistered,
:root[data-ra-theme="dark"] .status-badge.pending { color: #dfcd9d; }
:root[data-ra-theme="dark"] .status-badge.running { color: var(--ra-neutral); }
:root[data-ra-theme="dark"] .status-badge.heuristic,
:root[data-ra-theme="dark"] .status-badge.withdrawn { color: var(--ra-muted); }
:root[data-ra-theme="dark"] .status-badge.null { color: #e2b7d1; }
:root[data-ra-theme="dark"] .status-badge.overturned { color: #f4b2a6; }
:root[data-ra-theme] .btn-primary:hover,
:root[data-ra-theme] .subscribe-row button:hover { background: var(--ra-accent); color: var(--ra-ground); }
/* Refinement.css has intentional dark image treatment; restore graphite for light. */
:root[data-ra-theme="light"] body[data-figure] .person img,
:root[data-ra-theme="light"] .ai-model-object>img,
:root[data-ra-theme="light"] .peer-study { filter: grayscale(1); mix-blend-mode: multiply; }
:root[data-ra-theme="light"] .ground-plan .outer-floor { fill: #a998a31a; stroke: var(--line); }
:root[data-ra-theme="light"] .ground-plan .role-floor { fill: #d0c0c933; stroke: var(--line); }
:root[data-ra-theme="light"] .ground-plan .private-floor { fill: #f7f2e955; stroke: var(--line); }
:root[data-ra-theme="light"] .ground-plan .outer-second,
:root[data-ra-theme="light"] .ground-plan .role-second,
:root[data-ra-theme="light"] .ground-plan .private-second { stroke: var(--line); }
:root[data-ra-theme="light"] .table-one,
:root[data-ra-theme="light"] .table-two { background: var(--ra-surface-deep); }
:root[data-ra-theme="light"] .ai-agent-envelope .agent-wall { background: #b1a0aa20; }
@media(max-width:800px) {
  .site-header:has(.nav-hamburger) { grid-template-columns: minmax(0,1fr) auto auto; }
  .site-header:has(.nav-hamburger) .nav-hamburger { grid-column: 3; }
  .site-header .ra-theme-switch { grid-column: 2; grid-row: 1; justify-self: end; margin: 0; min-width: 72px; padding-inline: 6px; }
  .entry-links { flex-wrap: wrap; gap: 0 16px; align-items: center; }
  .entry-links .ra-theme-switch { min-width: 72px; padding-inline: 6px; font-size: 12px; }
}
@media(max-width:600px) {
  body.mobile-quiet header>.ra-theme-switch-mobile { display:inline-flex; pointer-events:auto; min-width:86px; }
}
@media(max-width:380px) {
  .site-header:has(.nav-hamburger) { grid-template-columns:minmax(0,1fr) auto; }
  .site-header:has(.nav-hamburger) .nav-hamburger { grid-column:2; }
  .site-header .ra-theme-switch { grid-column:1 / -1; grid-row:2; justify-self:start; }
  .site-header.nav-open .site-nav { grid-row:3; }
  .site-header.nav-open .site-cta { grid-row:4; }
}
@media print {
  .ra-theme-switch { display: none !important; }
  :root[data-ra-theme] { --ra-ground:#fff; --ra-paper:#fff; --ra-surface:#f4f1eb; --ra-surface-deep:#eee9df; --ra-ink:#302d31; --ra-secondary:#514750; --ra-muted:#625863; --ra-accent:#914936; --ra-line:#b1a0aa; --ra-teal:#285d53; color-scheme:light!important; }
}
