:root,
:root[data-theme="light"] {
  color-scheme: light;
  --theme-page: #f3f0e8;
  --theme-surface: #f7f4ed;
  --theme-surface-raised: #ffffff;
  --theme-surface-muted: #eef1f4;
  --theme-control: #e5eaf0;
  --theme-text: #17283a;
  --theme-text-muted: #62758a;
  --theme-border: rgba(19, 45, 70, 0.18);
  --theme-border-strong: rgba(19, 45, 70, 0.34);
  --theme-accent: #1f4e79;
  --theme-accent-strong: #00274c;
  --theme-accent-contrast: #ffffff;
  --theme-focus: #d2ad52;
  --theme-focus-soft: #f2e6bc;
  --theme-danger: #9d3030;
  --theme-danger-surface: #fae7e7;
  --theme-danger-border: #dca5a5;
  --theme-shadow: 0 14px 38px rgba(0, 39, 76, 0.09);
  --theme-shadow-strong: 0 18px 40px rgba(0, 39, 76, 0.16);
  --theme-navy-950: #0b2033;
  --theme-navy-900: #132d46;
  --theme-navy-800: #1d3c59;
  --theme-maize: #d2ad52;
  --theme-maize-bright: #ffcb05;
  --theme-maize-pale: #eee2bd;
  --theme-rail-background: #132d46;
  --theme-rail-text: #ffffff;
  --theme-rail-muted: rgba(255, 255, 255, 0.58);
  --theme-rail-border: rgba(255, 255, 255, 0.12);
  --theme-rail-hover: rgba(255, 255, 255, 0.07);
  --theme-eval-black: #202936;
  --theme-eval-white: #f5f7f8;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --theme-page: #0f1723;
  --theme-surface: #131e2d;
  --theme-surface-raised: #172233;
  --theme-surface-muted: #1c293c;
  --theme-control: #23334a;
  --theme-text: #eef4ff;
  --theme-text-muted: #aab7c8;
  --theme-border: #2d3a4d;
  --theme-border-strong: #46566d;
  --theme-accent: #ffcb05;
  --theme-accent-strong: #ffdb4d;
  --theme-accent-contrast: #0f1723;
  --theme-focus: #ffcb05;
  --theme-focus-soft: #40371d;
  --theme-danger: #ff9f9f;
  --theme-danger-surface: #3a2026;
  --theme-danger-border: #71414a;
  --theme-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  --theme-shadow-strong: 0 20px 46px rgba(0, 0, 0, 0.36);
  --theme-navy-950: #08131f;
  --theme-navy-900: #0d2033;
  --theme-navy-800: #17314a;
  --theme-maize: #ffcb05;
  --theme-maize-bright: #ffdb4d;
  --theme-maize-pale: #f4e5a5;
  --theme-rail-background: #0d2033;
  --theme-rail-text: #f7f9fc;
  --theme-rail-muted: rgba(247, 249, 252, 0.62);
  --theme-rail-border: rgba(255, 255, 255, 0.13);
  --theme-rail-hover: rgba(255, 255, 255, 0.08);
  --theme-eval-black: #0b111a;
  --theme-eval-white: #e8edf3;
}

/* Palette is independent of the System / Light / Dark appearance preference. */
:root[data-palette="halloween"][data-theme="light"] {
  --theme-page: #f5f5f5;
  --theme-surface: #ffffff;
  --theme-surface-raised: #ffffff;
  --theme-surface-muted: #eeeeee;
  --theme-control: #eeeeee;
  --theme-text: #000000;
  --theme-text-muted: #555555;
  --theme-border: #b5b5b5;
  --theme-border-strong: #777777;
  --theme-accent: #b34400;
  --theme-accent-strong: #963900;
  --theme-accent-contrast: #ffffff;
  --theme-focus: #ff7900;
  --theme-focus-soft: #ffe0c2;
  --theme-shadow: 0 14px 38px rgba(56, 28, 5, 0.10);
  --theme-shadow-strong: 0 18px 40px rgba(56, 28, 5, 0.18);
  --theme-navy-950: #000000;
  --theme-navy-900: #000000;
  --theme-navy-800: #101010;
  --theme-maize: #ff7900;
  --theme-maize-bright: #ff7900;
  --theme-maize-pale: #ffb000;
  --theme-rail-background: #000000;
  --theme-rail-text: #f5f5f5;
  --theme-rail-muted: #cccccc;
  --theme-rail-border: #444444;
  --theme-rail-hover: #202020;
}

:root[data-palette="halloween"][data-theme="dark"] {
  --theme-page: #000000;
  --theme-surface: #0a0a0a;
  --theme-surface-raised: #151515;
  --theme-surface-muted: #1b1b1b;
  --theme-control: #222222;
  --theme-text: #ffffff;
  --theme-text-muted: #cccccc;
  --theme-border: #484848;
  --theme-border-strong: #777777;
  --theme-accent: #ff7900;
  --theme-accent-strong: #ff9500;
  --theme-accent-contrast: #000000;
  --theme-focus: #ff7900;
  --theme-focus-soft: #302000;
  --theme-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  --theme-shadow-strong: 0 20px 46px rgba(0, 0, 0, 0.40);
  --theme-navy-950: #000000;
  --theme-navy-900: #000000;
  --theme-navy-800: #101010;
  --theme-maize: #ff7900;
  --theme-maize-bright: #ff7900;
  --theme-maize-pale: #ffb000;
  --theme-rail-background: #000000;
  --theme-rail-text: #ffffff;
  --theme-rail-muted: #cccccc;
  --theme-rail-border: #444444;
  --theme-rail-hover: #202020;
}

/* Christmas: velvet evergreen, snowy text, and red decorative/action accents.
   Dark links stay white so small text remains readable on green surfaces. */

:root[data-palette="christmas"][data-theme="light"] {
  --theme-page: #f7faf7;
  --theme-surface: #ffffff;
  --theme-surface-raised: #ffffff;
  --theme-surface-muted: #edf3ee;
  --theme-control: #e6eee8;
  --theme-text: #123b2b;
  --theme-text-muted: #456352;
  --theme-border: #a8bdae;
  --theme-border-strong: #638772;
  --theme-accent: #a7192c;
  --theme-accent-strong: #871526;
  --theme-accent-contrast: #ffffff;
  --theme-focus: #a7192c;
  --theme-focus-soft: #fbe8eb;
  --theme-christmas-red: #d92d3a;
  --theme-christmas-red-hover: #bc1f2d;
  --theme-christmas-bright: #f04452;
  --theme-navy-950: #062318;
  --theme-navy-900: #082d21;
  --theme-navy-800: #124734;
  --theme-maize: #f7faf7;
  --theme-maize-bright: #ffffff;
  --theme-maize-pale: #ffffff;
  --theme-rail-background: #082d21;
  --theme-rail-text: #f7faf7;
  --theme-rail-muted: #c2d8cb;
  --theme-rail-border: #46765c;
  --theme-rail-hover: #164832;
  --theme-shadow: 0 14px 38px rgba(3, 25, 16, 0.18);
  --theme-shadow-strong: 0 20px 46px rgba(3, 25, 16, 0.30);
}

:root[data-palette="christmas"][data-theme="dark"] {
  --theme-page: #082d21;
  --theme-surface: #0b3325;
  --theme-surface-raised: #103d2d;
  --theme-surface-muted: #0c3426;
  --theme-control: #164832;
  --theme-text: #f7faf7;
  --theme-text-muted: #c2d8cb;
  --theme-border: #46765c;
  --theme-border-strong: #779d85;
  --theme-accent: #f7faf7;
  --theme-accent-strong: #ffffff;
  --theme-accent-contrast: #082d21;
  --theme-focus: #ffffff;
  --theme-focus-soft: #234c3a;
  --theme-christmas-red: #d92d3a;
  --theme-christmas-red-hover: #bc1f2d;
  --theme-christmas-bright: #f04452;
  --theme-navy-950: #062318;
  --theme-navy-900: #082d21;
  --theme-navy-800: #124734;
  --theme-maize: #f7faf7;
  --theme-maize-bright: #ffffff;
  --theme-maize-pale: #ffffff;
  --theme-rail-background: #082d21;
  --theme-rail-text: #f7faf7;
  --theme-rail-muted: #c2d8cb;
  --theme-rail-border: #46765c;
  --theme-rail-hover: #164832;
  --theme-shadow: 0 14px 38px rgba(3, 25, 16, 0.18);
  --theme-shadow-strong: 0 20px 46px rgba(3, 25, 16, 0.30);
}

:root[data-mithrandir-theme="active"] {
  --navy-950: var(--theme-navy-950);
  --navy-900: var(--theme-navy-900);
  --navy-800: var(--theme-navy-800);
  --maize: var(--theme-maize);
  --maize-pale: var(--theme-maize-pale);
}

:root[data-mithrandir-theme="active"] .site-rail {
  background: var(--theme-rail-background);
  color: var(--theme-rail-text);
}

:root[data-mithrandir-theme="active"] .site-rail .nav-link {
  border-color: var(--theme-rail-border);
}

:root[data-mithrandir-theme="active"] .site-rail .nav-link:hover,
:root[data-mithrandir-theme="active"] .site-rail .nav-link:focus-visible,
:root[data-mithrandir-theme="active"] .site-rail .nav-link.is-current {
  border-color: var(--theme-rail-border);
  background: var(--theme-rail-hover);
  color: var(--theme-maize-pale);
}

:root[data-mithrandir-theme="active"] .site-rail .rail-note {
  color: var(--theme-rail-muted);
}

.site-theme-control {
  display: grid;
  gap: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.site-theme-control > span {
  color: var(--theme-maize);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.site-theme-control select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--theme-border-strong);
  border-radius: 6px;
  padding: 0 30px 0 10px;
  background: var(--theme-control);
  color: var(--theme-text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.site-theme-control select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--theme-focus) 32%, transparent);
  outline-offset: 2px;
}

.site-theme-control--card {
  margin: 20px 0 4px;
  padding: 14px;
  border: 1px solid var(--theme-border);
  border-radius: 10px;
  background: var(--theme-surface-muted);
  color: var(--theme-text);
}

.site-theme-control--card > span {
  color: var(--theme-text-muted);
}

.site-settings-shell {
  position: relative;
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--theme-rail-border);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.site-settings-button {
  width: 100%;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(210, 173, 82, 0.42);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--theme-rail-text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  text-align: left;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.site-settings-button:hover,
.site-settings-button:focus-visible,
.site-settings-button[aria-expanded="true"] {
  border-color: rgba(210, 173, 82, 0.72);
  background: var(--theme-rail-hover);
  color: var(--theme-maize-pale);
}

.site-settings-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--theme-focus) 38%, transparent);
  outline-offset: 2px;
}

.site-settings-button-icon,
.site-appearance-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.site-settings-button-icon {
  width: 23px;
  height: 23px;
  color: var(--theme-maize-bright);
}

.site-settings-button-icon svg,
.site-appearance-icon svg {
  width: 100%;
  height: 100%;
}

.site-settings-popover {
  position: fixed;
  z-index: 90000;
  box-sizing: border-box;
  padding: 16px;
  border: 1px solid var(--theme-border-strong);
  border-radius: 12px;
  background: var(--theme-surface-raised);
  color: var(--theme-text);
  box-shadow: var(--theme-shadow-strong);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.site-settings-popover[hidden] {
  display: none !important;
}

.site-settings-popover::after {
  content: "";
  position: absolute;
  left: 24px;
  width: 12px;
  height: 12px;
  border-right: 1px solid var(--theme-border-strong);
  border-bottom: 1px solid var(--theme-border-strong);
  background: var(--theme-surface-raised);
  transform: rotate(45deg);
}

.site-settings-popover[data-placement="top"]::after {
  bottom: -7px;
}

.site-settings-popover[data-placement="bottom"]::after {
  top: -7px;
  transform: rotate(225deg);
}

.site-settings-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.site-settings-heading strong {
  font-size: 16px;
  line-height: 1.2;
}

.site-settings-heading span {
  color: var(--theme-text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.site-appearance-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--theme-border-strong);
  border-radius: 9px;
  background: var(--theme-surface-muted);
}

.site-appearance-option {
  min-width: 0;
  min-height: 78px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  padding: 10px 6px;
  border: 0;
  border-right: 1px solid var(--theme-border-strong);
  background: transparent;
  color: var(--theme-text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.site-appearance-option:last-child {
  border-right: 0;
}

.site-appearance-option:hover,
.site-appearance-option:focus-visible {
  background: color-mix(in srgb, var(--theme-accent) 9%, transparent);
  color: var(--theme-text);
  outline: none;
}

.site-appearance-option.is-selected {
  background: color-mix(in srgb, var(--theme-accent) 14%, var(--theme-surface-raised));
  color: var(--theme-accent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--theme-accent) 64%, transparent);
}

.site-appearance-option:focus-visible {
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--theme-focus) 65%, transparent);
}

.site-appearance-icon {
  width: 24px;
  height: 24px;
}

@media (min-width: 1001px) {
  .site-rail.has-site-settings .session-nav-link {
    margin-top: 20px;
  }
}

@media (max-width: 1000px) {
  .site-settings-shell {
    display: none;
    margin-top: 14px;
    padding-top: 14px;
  }

  .site-rail.is-open .site-settings-shell {
    display: block;
  }

  .site-settings-button {
    max-width: 240px;
  }

  .site-theme-control--card {
    display: grid;
  }
}

.site-palette-control {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--theme-border);
  color: var(--theme-text);
  font: 600 14px/1.4 system-ui, sans-serif;
}
.site-palette-control select {
  width: 152px;
  max-width: 70%;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--theme-border-strong);
  border-radius: 6px;
  background: var(--theme-control);
  color: var(--theme-text);
  font: inherit;
  cursor: pointer;
}
.site-palette-control select:focus-visible {
  outline: 3px solid var(--theme-text);
  outline-offset: 3px;
}

/* Soft directional shading gives the rail a velvet finish without image assets. */
:root[data-mithrandir-theme="active"][data-palette="christmas"] .site-rail {
  background: radial-gradient(ellipse at 0 0, #1b513a, transparent 65%), var(--theme-rail-background);
  box-shadow: inset -3px 0 var(--theme-christmas-red);
}
:root[data-palette="christmas"] .site-rail .portrait {
  border-color: var(--theme-christmas-bright);
  box-shadow: 0 0 0 6px rgba(247, 250, 247, 0.08);
}
:root[data-palette="christmas"] .site-rail::after {
  border-color: var(--theme-rail-border);
}
:root[data-palette="christmas"] .site-settings-button {
  border-color: var(--theme-christmas-bright);
}
:root[data-palette="christmas"] .site-appearance-option.is-selected {
  box-shadow: inset 0 -3px var(--theme-christmas-red);
}
:root[data-palette="christmas"] .site-appearance-option:focus-visible {
  outline: 2px solid var(--theme-text);
  outline-offset: -4px;
}
