:root { --theme-switch-width: 44px }
button.theme-switch {
  --switch-bg: #fff;
  --switch-line: #cbd5df;
  --switch-ink: #24364a;
  --switch-focus: #195fc6;
  display: inline-grid;
  box-sizing: border-box;
  place-items: center;
  justify-self: end;
  flex: none;
  width: var(--theme-switch-width);
  height: var(--theme-switch-width);
  padding: 0;
  margin: 0;
  border: 1px solid var(--switch-line);
  border-radius: 12px;
  background: var(--switch-bg);
  color: var(--switch-ink);
  cursor: pointer;
  touch-action: manipulation;
}
:root[data-theme="dark"] .theme-switch {
  --switch-bg: #25303e;
  --switch-line: #4e6178;
  --switch-ink: #ecf3ff;
  --switch-focus: #9dc7ff;
}
.theme-switch:empty { visibility: hidden }
button.theme-switch:focus-visible { outline: 2px solid var(--switch-focus); outline-offset: 2px }
@media (hover: hover) {
  button.theme-switch:hover { border-color: var(--switch-focus); color: var(--switch-focus) }
}
.theme-switch svg {
  grid-area: 1 / 1;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.theme-switch .theme-sun,
:root[data-theme="dark"] .theme-switch .theme-moon { opacity: 1; transform: none }
.theme-switch .theme-moon { opacity: 0; transform: translateY(3px) rotate(-45deg) scale(.55) }
:root[data-theme="dark"] .theme-switch .theme-sun { opacity: 0; transform: translateY(-3px) rotate(45deg) scale(.55) }
@media (prefers-reduced-motion: no-preference) {
  .theme-switch svg { transition: transform 260ms cubic-bezier(.2,.75,.25,1), opacity 180ms ease }
}
@media (any-hover: hover) and (prefers-reduced-motion: no-preference) {
  /* Keep hover motion independent of the transition that changes the actual theme. */
  button.theme-switch:hover svg { animation: theme-tilt .46s ease-out }
  @keyframes theme-tilt {
    0%, 100% { rotate: 0deg; scale: 1 }
    40% { rotate: 22deg; scale: 1.09 }
    73% { rotate: -6deg; scale: 1.02 }
  }
}
.header { grid-template-areas: "brand search theme actions"; grid-template-columns: auto minmax(12rem,40rem) auto auto }
.header > .brand { grid-area: brand }
.header > .search-wrap { grid-area: search }
.header > .header-actions { grid-area: actions }
.header > .theme-switch { grid-area: theme }
.guide-header .theme-switch { margin-inline-start: auto }
@media (max-width: 1120px) {
  .header { grid-template-areas: "brand actions" "search theme"; grid-template-columns: minmax(0,1fr) auto }
}
@media (max-width: 640px) {
  .header { grid-template-areas: none; display: flex; flex-wrap: wrap; gap: .55rem }
  .header > .brand { order: 0; flex: 1; min-width: 0 }
  .header > .header-actions { order: 1 }
  .header > .search-wrap { order: 2; width: calc(100% - var(--theme-switch-width) - .55rem); flex: 1 0 calc(100% - var(--theme-switch-width) - .55rem); padding-inline: .75rem; gap: .4rem }
  .header > .theme-switch { order: 3 }
  .header .search-results { width: calc(100vw - 1.8rem); max-width: calc(100vw - 1.8rem); inset-inline-start: 0 }
  .guide-header { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .5rem; padding-block: .65rem }
  .guide-header .wordmark { line-height: 1.1 }
  .guide-header .map-link { grid-column: 1 / -1; width: fit-content }
}
