@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url("fonts/dm-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url("fonts/dm-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Browsers without light-dark() or :has() stay light and hide the switch, which would not work there. */
:root {
  color-scheme: light;
  --bg: #fff;
  --header-bg: #f5f7ff;
  --text: #212121;
  --accent: #0d47a1;
  --border: #6e7388;
  --margin: clamp(1rem, 5vw, 3rem);
}

fieldset {
  display: none;
}

@supports (color: light-dark(#000, #fff)) and selector(:has(a)) {
  :root {
    color-scheme: light dark;
    --bg: light-dark(#fff, #212121);
    --header-bg: light-dark(#f5f7ff, #2b2b2b);
    --text: light-dark(#212121, #dcdcdc);
    --accent: light-dark(#0d47a1, #ffb300);
    --border: light-dark(#6e7388, #898ea4);
  }

  :root:has(input[value="light"]:checked) {
    color-scheme: light;
  }

  :root:has(input[value="dark"]:checked) {
    color-scheme: dark;
  }

  fieldset {
    display: flex;
  }

  label:has(:checked) {
    background: var(--text);
    color: var(--bg);
  }

  /* Until a theme is chosen, the one from system settings looks selected. */
  @media (prefers-color-scheme: light) {
    :root:not(:has(input:checked)) label:has(input[value="light"]) {
      background: var(--text);
      color: var(--bg);
    }
  }

  @media (prefers-color-scheme: dark) {
    :root:not(:has(input:checked)) label:has(input[value="dark"]) {
      background: var(--text);
      color: var(--bg);
    }
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.15rem / 1.5 "DM Sans", system-ui, sans-serif;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem var(--margin) 2.5rem;
  background: var(--header-bg);
  border-block-end: 1px solid var(--border);
}

h1 {
  margin: 2rem 0 0;
  font-size: clamp(2.25rem, 1.75rem + 2.5vw, 3rem);
  line-height: 1.1;
  text-wrap: balance;
}

h2 {
  margin-block: 0 0.5rem;
  font-size: 1.75rem;
  line-height: 1.2;
}

main {
  padding: 3rem var(--margin);
}

footer {
  padding: 0 var(--margin) 3rem;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

a:focus-visible,
label:has(:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

fieldset {
  flex: none;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  border: 0;
}

/* The group name is for screen readers only. */
legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

label {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 5px;
}

input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
