@import url(//fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100..900;1,100..900&display=swap);
@import url(//fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);

/* Light theme (default) */
:root {
  --bg: #ffffff;
  --text: #1a1a1a;
  --link: rgb(18, 60, 110);
  --link-hover: rgb(28, 80, 140);
  --link-outline: var(--link);
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --text: #e8e8e8;
  --link: #6eb3f7;
  --link-hover: #8fc7ff;
  --link-outline: white;
}

/* System preference: dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a1a;
    --text: #e8e8e8;
    --link: #6eb3f7;
    --link-hover: #8fc7ff;
    --link-outline: white;
  }
}

/* Light override (when user chooses light explicitly) */
[data-theme="light"] {
  --bg: #ffffff;
  --text: #1a1a1a;
  --link: rgb(18, 60, 110);
  --link-hover: rgb(28, 80, 140);
  --link-outline: var(--link);
}

/* WCG theme variants – SDR fallbacks */
[data-theme="wcg-cyan"] {
  --bg: #05080a;
  --text: #e0f0f4;
  --link: #00e5ff;
  --link-hover: #5cffff;
  --link-outline: white;
}
[data-theme="wcg-lime"] {
  --bg: #050a05;
  --text: #e0f4e0;
  --link: #00ff44;
  --link-hover: #5cff88;
  --link-outline: white;
}
[data-theme="wcg-magenta"] {
  --bg: #0a050a;
  --text: #f4e0f4;
  --link: #ff00e5;
  --link-hover: #ff5cff;
  --link-outline: white;
}
[data-theme="wcg-yellow"] {
  --bg: #0a0905;
  --text: #f4f0e0;
  --link: #ffe000;
  --link-hover: #ffff5c;
  --link-outline: white;
}
[data-theme="wcg-bubblegum"] {
  --bg: #0a0508;
  --text: #f4e0ec;
  --link: #ff0066;
  --link-hover: #ff5cab;
  --link-outline: white;
}

/* WCG – Display P3 colors (saturation beyond sRGB) */
@media (color-gamut: p3) {
  [data-theme="wcg-cyan"] {
    --bg: color(display-p3 0 0.05 0.05);
    --text: color(display-p3 0.9 0.96 0.96);
    --link: color(display-p3 0 1 1);
    --link-hover: color(display-p3 0.4 1 1);
  }
  [data-theme="wcg-lime"] {
    --bg: color(display-p3 0 0.05 0);
    --text: color(display-p3 0.9 0.96 0.9);
    --link: color(display-p3 0 1 0);
    --link-hover: color(display-p3 0.4 1 0.4);
  }
  [data-theme="wcg-magenta"] {
    --bg: color(display-p3 0.05 0 0.05);
    --text: color(display-p3 0.96 0.9 0.96);
    --link: color(display-p3 1 0 1);
    --link-hover: color(display-p3 1 0.45 1);
  }
  [data-theme="wcg-yellow"] {
    --bg: color(display-p3 0.05 0.05 0);
    --text: color(display-p3 0.96 0.96 0.9);
    --link: color(display-p3 1 1 0);
    --link-hover: color(display-p3 1 1 0.4);
  }
  [data-theme="wcg-bubblegum"] {
    --bg: color(display-p3 0.05 0 0.05);
    --text: color(display-p3 0.96 0.85 0.9);
    --link: color(display-p3 1 0 .5);
    --link-hover: color(display-p3 1 0.4 .5);
  }
}

body {
  font-family: "Barlow", sans-serif;
  font-weight: 400;
  line-height: 1.8em;
  font-size: 1em;
  margin: auto 10%;
  background-color: var(--bg);
  color: var(--text);
}

h1 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

a,
a:link,
a:visited {
  color: var(--link);
}

a:hover {
  color: var(--link-hover);
}

code,
pre {
  font-family: "Ubuntu Mono", monospace;
}

/* Screen reader only – modern clip approach */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
}

.theme-chooser {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.theme-chooser button {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--text);
  background: var(--bg);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.7;
}

.theme-chooser button:hover,
.theme-chooser button[aria-pressed="true"],
.theme-chooser button:focus-visible {
  opacity: 1;
}

/* Focused (keyboard focus): 2px outline using --link-outline for theme-aware visibility */
.theme-chooser button:focus-visible {
  outline: 2px solid var(--link-outline);
  outline-offset: 2px;
}

/* Dark modes: explicit white outline (fallback if --link-outline fails to resolve) */
[data-theme="dark"] .theme-chooser button:focus-visible,
[data-theme^="wcg-"] .theme-chooser button:focus-visible {
  outline: 2px solid white;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-chooser button:focus-visible {
    outline: 2px solid white;
  }
}

/* Selected (active theme): 2px border for clear distinction from focus */
.theme-chooser button[aria-pressed="true"] {
  border: 2px solid var(--link);
  border-color: var(--link);
  color: var(--link);
}

/* Selected + focused: keep 2px border, add focus ring outside */
.theme-chooser button[aria-pressed="true"]:focus-visible {
  outline: 2px solid var(--link-outline);
  outline-offset: 2px;
}

/* Dark modes: explicit white for selected+focused */
[data-theme="dark"] .theme-chooser button[aria-pressed="true"]:focus-visible,
[data-theme^="wcg-"] .theme-chooser button[aria-pressed="true"]:focus-visible {
  outline: 2px solid white;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-chooser button[aria-pressed="true"]:focus-visible {
    outline: 2px solid white;
  }
}

.theme-chooser button.is-unsupported {
  cursor: not-allowed;
  opacity: 0.4;
}

.theme-chooser button .btn-label-focus-unavailable {
  display: none;
}

.theme-chooser button.is-unsupported:focus-visible .btn-label-default {
  display: none;
}

.theme-chooser
  button.is-unsupported:focus-visible
  .btn-label-focus-unavailable {
  display: inline;
}
