/* Site Switcher — Infinity-themed dropdown */

.site-switcher {
  --sw-accent-a: #00d4ff;
  --sw-accent-b: #7b61ff;
  --sw-accent-c: #ff6ec7;
  --sw-bg: rgba(255, 255, 255, 0.92);
  --sw-bg-2: rgba(247, 249, 252, 0.96);
  --sw-border: rgba(0, 0, 0, 0.08);
  --sw-fg: #0d0f14;
  --sw-fg-soft: #5a6e85;
  --sw-shadow: 0 20px 60px rgba(0, 40, 120, 0.18), 0 4px 16px rgba(0, 0, 0, 0.08);
  --sw-glow: 0 0 24px rgba(0, 168, 255, 0.35);
  --sw-item-bg: rgba(255, 255, 255, 0.55);
  --sw-item-border: rgba(0, 0, 0, 0.06);
  --sw-item-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset, 0 2px 10px rgba(0, 40, 120, 0.05);
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Reserve vertical space so switcher does not overlap header content */
body:has(#site-switcher) {
  --sw-bar-height: 56px;
}

body:has(#site-switcher) .results-header-inner,
body:has(#site-switcher) .home-header {
  padding-top: var(--sw-bar-height);
}

/* Domain themes — direct header, lite results bar, searchenginely shell */
body:has(#site-switcher) > header,
body:has(#site-switcher) header.hd {
  padding-top: calc(var(--sw-bar-height) + 8px);
}

body:has(#site-switcher) .shell {
  padding-top: calc(var(--sw-bar-height) + 20px);
}

body:has(#site-switcher) .p {
  padding-top: calc(60px + var(--sw-bar-height));
}

[data-theme="dark"] .site-switcher,
.site-switcher--dark {
  --sw-bg: rgba(14, 19, 34, 0.94);
  --sw-bg-2: rgba(20, 26, 46, 0.98);
  --sw-border: rgba(255, 255, 255, 0.1);
  --sw-fg: #e6edf5;
  --sw-fg-soft: #8ea3bc;
  --sw-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 4px 20px rgba(0, 0, 0, 0.3);
  --sw-glow: 0 0 28px rgba(0, 212, 255, 0.22);
  --sw-item-bg: rgba(255, 255, 255, 0.05);
  --sw-item-border: rgba(255, 255, 255, 0.08);
  --sw-item-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 2px 12px rgba(0, 0, 0, 0.28);
}

/* Lite pages use prefers-color-scheme, not data-theme */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .site-switcher--lite {
    --sw-bg: rgba(14, 19, 34, 0.94);
    --sw-bg-2: rgba(20, 26, 46, 0.98);
    --sw-border: rgba(255, 255, 255, 0.1);
    --sw-fg: #e6edf5;
    --sw-fg-soft: #8ea3bc;
    --sw-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 4px 20px rgba(0, 0, 0, 0.3);
    --sw-glow: 0 0 28px rgba(0, 212, 255, 0.22);
    --sw-item-bg: rgba(255, 255, 255, 0.05);
    --sw-item-border: rgba(255, 255, 255, 0.08);
    --sw-item-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 2px 12px rgba(0, 0, 0, 0.28);
  }
}

/* Strip native button chrome inside the switcher (critical on lite pages) */
.site-switcher__trigger,
.site-switcher__item-main {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.site-switcher__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border: 1.5px solid var(--sw-border);
  border-radius: 999px;
  background: var(--sw-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--sw-fg);
  cursor: pointer;
  box-shadow: var(--sw-shadow);
  transition: border-color 0.2s, box-shadow 0.25s, transform 0.2s;
  position: relative;
  overflow: hidden;
}

.site-switcher__trigger::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: inherit;
  background: conic-gradient(from 0deg, var(--sw-accent-a), var(--sw-accent-b), var(--sw-accent-c), var(--sw-accent-a));
  opacity: 0;
  z-index: -1;
  transition: opacity 0.3s;
  animation: sw-spin 4s linear infinite;
}

.site-switcher__trigger:hover,
.site-switcher__trigger[aria-expanded="true"] {
  border-color: transparent;
  box-shadow: var(--sw-shadow), var(--sw-glow);
  transform: translateY(-1px);
}

.site-switcher__trigger:hover::before,
.site-switcher__trigger[aria-expanded="true"]::before {
  opacity: 1;
}

.site-switcher__trigger::after {
  content: '';
  position: absolute;
  inset: 1.5px;
  border-radius: inherit;
  background: var(--sw-bg);
  z-index: -1;
}

@keyframes sw-spin {
  to { transform: rotate(360deg); }
}

.site-switcher__infinity {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(123, 97, 255, 0.15));
  flex-shrink: 0;
}

.site-switcher__infinity svg {
  width: 20px;
  height: 20px;
  animation: sw-pulse 2.4s ease-in-out infinite;
}

.site-switcher__infinity path {
  stroke: url(#sw-infinity-grad);
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
}

@keyframes sw-pulse {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

.site-switcher__label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-switcher__chevron {
  width: 14px;
  height: 14px;
  color: var(--sw-fg-soft);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.site-switcher__trigger[aria-expanded="true"] .site-switcher__chevron {
  transform: rotate(180deg);
}

.site-switcher__panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  width: min(340px, calc(100vw - 32px));
  border: 1px solid var(--sw-border);
  border-radius: 20px;
  background: var(--sw-bg-2);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--sw-shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-8px) scale(0.97);
  transform-origin: top center;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.site-switcher__panel[data-open="true"] {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
}

.site-switcher__panel-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  overflow: hidden;
}

.site-switcher__panel-bg svg {
  position: absolute;
  width: 280px;
  height: 140px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: sw-drift 12s ease-in-out infinite alternate;
}

@keyframes sw-drift {
  from { transform: translate(-50%, -50%) rotate(-4deg) scale(1); }
  to { transform: translate(-48%, -52%) rotate(4deg) scale(1.05); }
}

.site-switcher__header {
  position: relative;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--sw-border);
}

.site-switcher__title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sw-fg-soft);
  margin-bottom: 2px;
}

.site-switcher__subtitle {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--sw-fg);
}

.site-switcher__list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 8px;
  max-height: min(420px, calc(100vh - 120px));
  overflow-y: auto;
}

.site-switcher__list > li + li {
  margin-top: 6px;
}

.site-switcher__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--sw-item-border);
  border-radius: 14px;
  background: var(--sw-item-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--sw-item-shadow);
  color: var(--sw-fg);
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.site-switcher__item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  box-shadow: none;
  outline: none;
  transition: background 0.15s;
}

.site-switcher__item-main:disabled {
  cursor: default;
  opacity: 1;
  color: inherit;
  background: transparent;
}

.site-switcher__item-main:focus-visible {
  outline: 2px solid rgba(0, 168, 255, 0.45);
  outline-offset: 1px;
}

.site-switcher__item:hover,
.site-switcher__item:focus-within,
.site-switcher__item[data-active-index="true"] {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(123, 97, 255, 0.08)), var(--sw-item-bg);
  border-color: rgba(0, 168, 255, 0.28);
  transform: translateX(2px);
  box-shadow:
    var(--sw-item-shadow),
    0 0 0 1px rgba(0, 168, 255, 0.1),
    0 4px 16px rgba(0, 120, 220, 0.1);
  outline: none;
}

.site-switcher__item--current {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.14), rgba(123, 97, 255, 0.1)), var(--sw-item-bg);
  border-color: rgba(0, 168, 255, 0.38);
  box-shadow:
    var(--sw-item-shadow),
    inset 0 0 0 1px rgba(0, 168, 255, 0.1),
    0 0 18px rgba(0, 168, 255, 0.08);
}

.site-switcher__item:hover .site-switcher__item-main,
.site-switcher__item:focus-within .site-switcher__item-main,
.site-switcher__item[data-active-index="true"] .site-switcher__item-main,
.site-switcher__item--current .site-switcher__item-main {
  background: transparent;
  border-color: transparent;
  transform: none;
  outline: none;
  box-shadow: none;
}

.site-switcher__item-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(145deg, rgba(0, 212, 255, 0.18), rgba(123, 97, 255, 0.14));
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--sw-accent-a);
}

.site-switcher__item--current .site-switcher__item-icon {
  background: linear-gradient(145deg, var(--sw-accent-a), var(--sw-accent-b));
  color: #fff;
}

.site-switcher__item-body {
  flex: 1;
  min-width: 0;
}

.site-switcher__item-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
}

.site-switcher__item-tagline {
  display: block;
  font-size: 0.72rem;
  color: var(--sw-fg-soft);
  line-height: 1.3;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-switcher__item-check {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--sw-accent-a);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s, transform 0.2s;
}

.site-switcher__item--current .site-switcher__item-check {
  opacity: 1;
  transform: scale(1);
}

.site-switcher__footer {
  position: relative;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--sw-border);
  font-size: 0.68rem;
  color: var(--sw-fg-soft);
  text-align: center;
  letter-spacing: 0.03em;
}

@media (max-width: 740px) {
  body:has(#site-switcher) .shell {
    padding-top: calc(var(--sw-bar-height) + 12px);
  }
}

@media (max-width: 640px) {
  body:has(#site-switcher) {
    --sw-bar-height: 48px;
  }

  body:has(#site-switcher) > header {
    padding-top: calc(var(--sw-bar-height) + 4px);
    padding-bottom: 16px;
  }

  body:has(#site-switcher) header.hd {
    padding-top: calc(var(--sw-bar-height) + 6px);
  }

  body:has(#site-switcher) .p {
    padding-top: calc(48px + var(--sw-bar-height));
  }

  .site-switcher {
    top: 8px;
  }

  .site-switcher__label {
    max-width: 88px;
    font-size: 0.72rem;
  }

  .site-switcher__trigger {
    padding: 6px 10px 6px 8px;
    gap: 6px;
  }

  .site-switcher__infinity {
    width: 28px;
    height: 28px;
  }

  .site-switcher__infinity svg {
    width: 17px;
    height: 17px;
  }
}

@media (max-width: 360px) {
  .site-switcher__label {
    display: none;
  }

  .site-switcher__trigger {
    padding: 8px;
  }
}
