.stt-toggle,
.stt-toggle * {
  box-sizing: border-box;
}

.stt-toggle {
  --stt-bg: var(--stt-light-bg);
  --stt-border: var(--stt-light-border);
  --stt-icon: var(--stt-light-icon);
  --stt-hover-bg: var(--stt-light-hover-bg);
  --stt-tooltip-bg: #111827;
  --stt-tooltip-text: #ffffff;
  --stt-tooltip-muted: #cbd5e1;
  --stt-tooltip-border: rgba(255, 255, 255, .14);

  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--stt-size, 42px);
  height: var(--stt-size, 42px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  line-height: 1;
  isolation: isolate;
}

html[data-site-theme="dark"] .stt-toggle {
  --stt-bg: var(--stt-dark-bg);
  --stt-border: var(--stt-dark-border);
  --stt-icon: var(--stt-dark-icon);
  --stt-hover-bg: var(--stt-dark-hover-bg);
  --stt-tooltip-bg: #f8fafc;
  --stt-tooltip-text: #111827;
  --stt-tooltip-muted: #4b5563;
  --stt-tooltip-border: rgba(17, 24, 39, .14);
}

.stt-toggle__button {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  z-index: 2;
  display: inline-grid;
  place-items: center;
  width: var(--stt-size, 42px);
  height: var(--stt-size, 42px);
  min-width: var(--stt-size, 42px);
  min-height: var(--stt-size, 42px);
  margin: 0;
  padding: 0;
  border: var(--stt-border-width, 1px) solid var(--stt-border);
  border-radius: 50%;
  background: var(--stt-bg);
  box-shadow: var(--stt-shadow, none);
  color: var(--stt-icon);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  transition:
    background-color .18s ease,
    border-color .18s ease,
    color .18s ease,
    transform .18s ease,
    box-shadow .18s ease;
}

.stt-toggle__button:hover {
  background: var(--stt-hover-bg);
}

.stt-toggle__button:active {
  transform: scale(.94);
}

.stt-toggle__button:focus-visible {
  outline: 3px solid var(--stt-focus-color, #4f8cff);
  outline-offset: 3px;
}

.stt-toggle__icon {
  position: absolute;
  inset: 50% auto auto 50%;
  display: inline-grid;
  place-items: center;
  width: var(--stt-icon-size, 19px);
  height: var(--stt-icon-size, 19px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(.72) rotate(-12deg);
  transition: opacity .16s ease, transform .2s ease;
}

html[data-site-theme-preference="system"] .stt-toggle__icon--system,
html[data-site-theme-preference="light"] .stt-toggle__icon--light,
html[data-site-theme-preference="dark"] .stt-toggle__icon--dark,
.stt-toggle[data-stt-preference="system"] .stt-toggle__icon--system,
.stt-toggle[data-stt-preference="light"] .stt-toggle__icon--light,
.stt-toggle[data-stt-preference="dark"] .stt-toggle__icon--dark {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1) rotate(0);
}

.stt-toggle__icon svg,
.stt-toggle__icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* --------------------------------------------------------------------------
   Built-in tooltip
   -------------------------------------------------------------------------- */

.stt-toggle__tooltip {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 12px);

  width: max-content;
  max-width: min(220px, calc(100vw - 24px));
  padding: 7px 9px;

  color: var(--stt-tooltip-text);
  background: var(--stt-tooltip-bg);
  border: 1px solid var(--stt-tooltip-border);
  border-radius: 7px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);

  font-family: inherit;
  line-height: 1.25;
  text-align: left;
  white-space: normal;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px);
  transition:
    opacity .14s ease,
    visibility .14s ease,
    transform .14s ease;
}

.stt-toggle__tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%;
  right: calc((var(--stt-size, 42px) / 2) - 6px);
  width: 12px;
  height: 12px;
  background: var(--stt-tooltip-bg);
  border-right: 0;
  border-bottom: 0;
  border-left: 1px solid var(--stt-tooltip-border);
  border-top: 1px solid var(--stt-tooltip-border);
  transform: translateY(6px) rotate(45deg);
}

.stt-toggle__tooltip-title,
.stt-toggle__tooltip-detail {
  display: block;
}

.stt-toggle__tooltip-title {
  color: var(--stt-tooltip-text);
  font-size: 11.5px;
  font-weight: 700;
}

.stt-toggle__tooltip-detail {
  margin-top: 2px;
  color: var(--stt-tooltip-muted);
  font-size: 10.5px;
  font-weight: 500;
}

.stt-toggle__tooltip-detail:empty {
  display: none;
}

.stt-toggle__button:focus-visible + .stt-toggle__tooltip,
.stt-toggle.stt-toggle--feedback .stt-toggle__tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (hover: hover) and (pointer: fine) {
  .stt-toggle__button:hover + .stt-toggle__tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

/* Live status is announced to assistive tech without adding visible UI. */
.stt-toggle__status {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.stt-floating {
  position: fixed;
  z-index: 99998;
  margin: 0;
  pointer-events: none;
}

.stt-floating .stt-toggle {
  pointer-events: auto;
}

.stt-floating--top-left { top: 24px; left: 24px; }
.stt-floating--top-right { top: 24px; right: 24px; }
.stt-floating--bottom-left { bottom: 24px; left: 24px; }
.stt-floating--bottom-right { bottom: 24px; right: 24px; }

/* Bottom floating controls need the tooltip above the button. */
.stt-floating--bottom-left .stt-toggle__tooltip,
.stt-floating--bottom-right .stt-toggle__tooltip {
  top: auto;
  bottom: calc(100% + 12px);
}

.stt-floating--bottom-left .stt-toggle__tooltip::after,
.stt-floating--bottom-right .stt-toggle__tooltip::after {
  top: 100%;
  bottom: auto;
  border-left: 0;
  border-top: 0;
  border-right: 1px solid var(--stt-tooltip-border);
  border-bottom: 1px solid var(--stt-tooltip-border);
  transform: translateY(-6px) rotate(45deg);
}

@media (max-width: 640px) {
  .stt-floating--top-left { top: 16px; left: 16px; }
  .stt-floating--top-right { top: 16px; right: 16px; }
  .stt-floating--bottom-left { bottom: 16px; left: 16px; }
  .stt-floating--bottom-right { bottom: 16px; right: 16px; }

  .stt-toggle__tooltip {
    max-width: min(210px, calc(100vw - 20px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .stt-toggle__button,
  .stt-toggle__icon,
  .stt-toggle__tooltip {
    transition: none;
  }
}
