:root {
  --access-bg: #f1f1f1;
  --access-bg-glass: rgba(241, 241, 241, 0.35);
  --access-btn-bg: #ffffff;
  --access-btn-border: #b0b0b0;
  --access-btn-edge: var(--surface-edge, #a3927e);
}

html.theme-dark {
  --access-bg: #1c1c1c;
  --access-bg-glass: rgba(28, 28, 28, 0.35);
  --access-btn-bg: #0f0f0f;
  --access-btn-border: #262626;
  --access-btn-edge: var(--surface-edge, #262626);
}

@media (prefers-color-scheme: dark) {
  html.theme-system {
    --access-bg: #1c1c1c;
    --access-bg-glass: rgba(28, 28, 28, 0.35);
    --access-btn-bg: #0f0f0f;
    --access-btn-border: #262626;
    --access-btn-edge: var(--surface-edge, #262626);
  }
}

.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  background: var(--link, #0047cc);
  color: #fff;
  padding: 0.5rem 0.8rem;
  text-decoration: none;
  z-index: 100;
}
.skip-link:focus { left: 0.75rem; top: 0.75rem; }

.accessibility-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.8rem;
  background: transparent;
  border-radius: 0;
  margin-bottom: 0.75rem;
  border: 0;
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}
.page-scrolled .accessibility-bar {
  background: var(--access-bg-glass);
  box-shadow: var(--surface-inset-shadow, none), 0 0.4rem 1.2rem rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(0.45rem);
  -webkit-backdrop-filter: blur(0.45rem);
}
.accessibility-title {
  font-weight: 700;
  color: var(--text, #111111);
  text-align: left;
}
.accessibility-title a {
  color: inherit;
  text-decoration: none;
}
.accessibility-title a:hover {
  color: inherit;
  text-decoration: underline;
}
.accessibility-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  font-size: 0.9em;
}

.theme-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
  min-inline-size: 0;
}

.theme-switcher-label {
  margin: 0;
  font-weight: 600;
}

.theme-segments {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.theme-option {
  position: relative;
  display: inline-flex;
}

.theme-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
}

.theme-option span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.3rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--access-btn-edge);
  border-top-width: 0;
  border-left-width: 0;
  border-right-width: var(--surface-edge-width, 2px);
  border-bottom-width: var(--surface-edge-width, 2px);
  border-radius: 0.35rem;
  background: var(--access-btn-bg);
  color: var(--text, #111111);
  cursor: pointer;
  line-height: 1.2;
}

.theme-option input:checked + span {
  background: var(--link, #0047cc);
  border-color: var(--link, #0047cc);
  color: #ffffff;
}

.theme-option input:focus-visible + span {
  outline: 0.2rem solid var(--link, #0047cc);
  outline-offset: 0.2rem;
}
.accessibility-bar button {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--access-btn-edge);
  border-top-width: 0;
  border-left-width: 0;
  border-right-width: var(--surface-edge-width, 2px);
  border-bottom-width: var(--surface-edge-width, 2px);
  background: var(--access-btn-bg);
  color: var(--text, #111111);
  border-radius: 0.35rem;
  cursor: pointer;
  font-size: inherit;
}
.accessibility-bar button.active {
  border-color: var(--link, #0047cc);
  box-shadow: 0 0 0 0.1rem var(--link, #0047cc);
}
.accessibility-label { font-weight: 600; }

@media (max-width: 42rem) {
  .accessibility-title,
  .accessibility-controls {
    width: 100%;
  }

  .accessibility-subtitle,
  .theme-switcher-label,
  .accessibility-label {
    display: none;
  }

  .accessibility-controls {
    justify-content: flex-start;
    margin-left: 0;
  }

  .theme-switcher {
    width: auto;
    margin-right: auto;
  }

  .theme-segments {
    width: auto;
  }
}

:focus-visible {
  outline: 0.2rem solid var(--link, #0047cc);
  outline-offset: 0.2rem;
}

body.font-large { font-size: 1.2rem; }
body.high-contrast {
  --surface-inset-shadow: none;
  --control-inset-shadow: none;
  --shadow: none;
  --high-contrast-button-text: #000000;
  --sans: "OpenDyslexic", "Atkinson Hyperlegible", Arial, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

html.theme-light body.high-contrast,
html.theme-system body.high-contrast {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --text: #000000;
  --muted: #000000;
  --border: #000000;
  --surface-edge: #000000;
  --link: #000000;
  --link-hover: #000000;
  --button-edge: #000000;
  --high-contrast-button-text: #ffffff;
  --accent: #000000;
  --accent-soft: rgba(0, 0, 0, 0.14);
  --access-bg: #ffffff;
  --access-bg-glass: rgba(255, 255, 255, 0.72);
  --access-btn-bg: #ffffff;
  --access-btn-border: #000000;
  --access-btn-edge: #000000;
}

html.theme-dark body.high-contrast {
  --bg: #000000;
  --bg-elevated: #000000;
  --panel: #000000;
  --panel-strong: #000000;
  --text: #ffffff;
  --muted: #ffffff;
  --border: #ffffff;
  --surface-edge: #ffffff;
  --link: #ffffff;
  --link-hover: #ffffff;
  --button-edge: #ffffff;
  --high-contrast-button-text: #000000;
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.18);
  --access-bg: #000000;
  --access-bg-glass: rgba(0, 0, 0, 0.35);
  --access-btn-bg: #000000;
  --access-btn-border: #ffffff;
  --access-btn-edge: #ffffff;
}

@media (prefers-color-scheme: dark) {
  html.theme-system body.high-contrast {
    --bg: #000000;
    --bg-elevated: #000000;
    --panel: #000000;
    --panel-strong: #000000;
    --text: #ffffff;
    --muted: #ffffff;
    --border: #ffffff;
    --surface-edge: #ffffff;
    --link: #ffffff;
    --link-hover: #ffffff;
    --button-edge: #ffffff;
    --high-contrast-button-text: #000000;
    --accent: #ffffff;
    --accent-soft: rgba(255, 255, 255, 0.18);
    --access-bg: #000000;
    --access-bg-glass: rgba(0, 0, 0, 0.35);
    --access-btn-bg: #000000;
    --access-btn-border: #ffffff;
    --access-btn-edge: #ffffff;
  }
}

body.high-contrast .button {
  background: var(--link);
  color: var(--high-contrast-button-text);
  border: 1px solid var(--button-edge);
  border-top-width: 0;
  border-left-width: 0;
  border-right-width: var(--control-edge-width, 3px);
  border-bottom-width: var(--control-edge-width, 3px);
}

body.high-contrast .theme-option input:checked + span {
  color: var(--high-contrast-button-text);
}

body.high-contrast.page-scrolled .accessibility-bar {
  box-shadow: none;
}
