.theme-toggle {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-bg-subtle);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 150ms ease;
}

.theme-toggle:hover {
  border-color: var(--color-border-brand);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.theme-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface-raised);
  box-shadow: 0 0 0 1px var(--color-border);
  transition: transform 350ms cubic-bezier(0.45, 0, 0.2, 1);
}

.theme-toggle[aria-checked="true"] .theme-knob {
  transform: translateX(16px);
}

.theme-knob svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.theme-toggle .icon-moon,
.theme-toggle[aria-checked="true"] .icon-sun {
  display: none;
}

.theme-toggle[aria-checked="true"] .icon-moon {
  display: block;
}

/* Opacity only: blur or scale on a full-page snapshot drops frames. */
::view-transition-old(root) {
  animation: none;
}

::view-transition-new(root) {
  animation: 500ms cubic-bezier(0.45, 0, 0.2, 1) both theme-settle;
}

@keyframes theme-settle {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-knob {
    transition: none;
  }

  ::view-transition-new(root) {
    animation: none;
  }
}
