.theme-switcher {
  position: relative;
  flex: 0 0 auto;
}

.theme-switcher__toggle {
  position: relative;
}

.theme-switcher__icon,
.theme-switcher__option-icon,
.theme-switcher__check {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-switcher__icon {
  width: 1.5rem;
  height: 1.5rem;
  stroke-width: 1.65;
}

.theme-switcher__icon--dark {
  display: none;
}

.theme-switcher.is-dark .theme-switcher__icon--light {
  display: none;
}

.theme-switcher.is-dark .theme-switcher__icon--dark {
  display: block;
}

.theme-switcher__panel {
  position: absolute;
  z-index: 11;
  top: calc(100% + 0.75rem);
  right: 0;
  width: min(17rem, calc(100vw - 1.5rem));
  max-height: min(25rem, calc(100svh - 6.5rem - env(safe-area-inset-top)));
  padding: 0.75rem;
  border: 1px solid var(--color-border-overlay);
  border-radius: 1rem;
  background-color: var(--color-surface-overlay);
  box-shadow: 0 14px 32px var(--color-shadow-overlay);
  color: var(--color-text-default);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .theme-switcher__panel {
    -webkit-backdrop-filter: blur(24px) saturate(135%);
    backdrop-filter: blur(24px) saturate(135%);
  }
}

/* INLINE */
/* In page content the choices sit in an ordinary panel, not a floating menu. */
.theme-switcher--inline .theme-switcher__panel {
  position: static;
  width: auto;
  max-height: none;
  padding: 1rem;
  box-shadow: none;
  overflow: visible;
}

.theme-switcher__fieldset {
  min-width: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.theme-switcher--inline .theme-switcher__fieldset {
  display: grid;
  gap: 0.5rem;
}

/* Tablet Portrait Up - Min 600px */
@media (min-width: 600px) {
  .theme-switcher--inline .theme-switcher__fieldset {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.theme-switcher__legend {
  padding: 0 0.25rem;
  color: var(--color-text-heading);
  font-size: 1rem;
  font-weight: 700;
}

.theme-switcher__description {
  margin: 0.125rem 0 0.625rem;
  padding-inline: 0.25rem;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  line-height: 1.35;
}

.theme-switcher--inline .theme-switcher__description {
  margin-bottom: 0.125rem;
  grid-column: 1 / -1;
}

.theme-switcher__option {
  position: relative;
  display: block;
  cursor: pointer;
}

.theme-switcher__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  opacity: 0;
  pointer-events: none;
}

.theme-switcher__option-content {
  display: grid;
  min-height: 3.5rem;
  align-items: center;
  padding: 0.5rem 0.625rem;
  border: 1px solid transparent;
  border-radius: 0.75rem;
  color: var(--color-text-default);
  gap: 0.625rem;
  grid-template-columns: 1.5rem minmax(0, 1fr) 1.25rem;
}

@media (hover: hover) {
  .theme-switcher__option:hover .theme-switcher__option-content {
    background-color: var(--color-surface-interactive-hover);
  }
}

.theme-switcher__input:focus-visible + .theme-switcher__option-content {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: -1px;
}

.theme-switcher__input:checked + .theme-switcher__option-content {
  border-color: var(--color-border-interactive);
  background-color: var(--color-surface-interactive);
}

.theme-switcher__option-icon {
  width: 1.375rem;
  height: 1.375rem;
  color: var(--color-icon-default);
  stroke-width: 1.6;
}

.theme-switcher__option-copy {
  display: grid;
  min-width: 0;
  gap: 0.0625rem;
}

.theme-switcher__option-copy strong {
  color: var(--color-text-heading);
  font-size: 0.9375rem;
  line-height: 1.2;
}

.theme-switcher__option-copy small {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  line-height: 1.3;
}

.theme-switcher__input:checked + .theme-switcher__option-content .theme-switcher__option-copy small {
  color: var(--color-text-default);
}

.theme-switcher__check {
  display: none;
  width: 1.125rem;
  height: 1.125rem;
  color: var(--color-interactive);
  stroke-width: 2.25;
}

.theme-switcher__input:checked + .theme-switcher__option-content .theme-switcher__check {
  display: block;
}

@media (prefers-reduced-transparency: reduce) {
  .theme-switcher__panel {
    background-color: var(--color-surface-raised);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (forced-colors: active) {
  .theme-switcher__panel {
    border: 1px solid CanvasText;
    background: Canvas;
    box-shadow: none;
    color: CanvasText;
    forced-color-adjust: auto;
  }
}

@media (forced-colors: active) {
  .theme-switcher__input:checked + .theme-switcher__option-content {
    border-color: Highlight;
  }
}
