/* <ad-theme-toggle>: one round button in the header row, the same height as the search and the
 * language switcher (44 px), switching between light and dark. */

/* The element is empty until the script fills it. When scripts run (data-js is set by
 * js-init.js before the first paint) the button's size is reserved, so the header does not
 * shift when it appears. Without JavaScript nothing is reserved and nothing is shown. */
[data-js] ad-theme-toggle {
  display: inline-flex;
  min-inline-size: var(--target-comfortable);
  min-block-size: var(--target-comfortable);
}

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--target-comfortable);
  block-size: var(--target-comfortable);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--bg-raised);
  color: var(--accent);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.theme-toggle:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--focus-halo);
}

.theme-toggle__icon {
  inline-size: 1.25em;
  block-size: 1.25em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The button's name (always in the accessibility tree): visually hidden, except as a small
 * label under the button while it is hovered or focused with the keyboard, because a sun and a
 * moon are not self-explanatory to everyone. Content on hover or focus (1.4.13): the
 * label touches the button, so the pointer can move onto it and it stays; Escape dismisses it
 * (data-label-dismissed, set by the script) without moving focus; there is no timer. It aligns
 * with the button's end edge, which sits at the header's right edge on wide screens. */
.theme-toggle__label {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.theme-toggle:not([data-label-dismissed]):is(:hover, :focus-visible) .theme-toggle__label {
  inset-block-start: calc(100% - 2px);
  inset-inline-end: 0;
  z-index: 50;
  inline-size: auto;
  block-size: auto;
  overflow: visible;
  clip-path: none;
  padding: 0.25em 0.6em;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-raised);
  color: var(--text);
  font-size: var(--text--1);
  font-weight: 600;
  line-height: 1.3;
  box-shadow: var(--shadow-md);
}

@media (forced-colors: active) {
  .theme-toggle {
    border-color: ButtonText;
  }
}
