/* Шапка сайта, меню и переключатель темы */

/* ===== Шапка ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 68px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 700 24px var(--font-head);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.logo__mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--gradient);
  color: var(--on-accent);
  font-size: 18px;
}

.nav {
  display: flex;
  gap: 20px;
}

.nav a {
  color: var(--muted);
  font-weight: 500;
  transition: color 0.2s;
}
.nav a:hover,
.nav a.is-active {
  color: var(--accent);
}

/* Пункт «Сравнение» в меню виден только на узких экранах, где значок не помещается в шапку */
.nav .nav__compare {
  display: none;
}
.nav__count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent-2);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
@media (max-width: 420px) {
  .header .compare-link {
    display: none;
  }
  .nav .nav__compare {
    display: block;
  }
}

.search {
  flex: 1;
  display: flex;
  max-width: 420px;
  margin-left: auto;
}

.search input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.search button {
  padding: 0 16px;
  border: none;
  border-radius: 0 10px 10px 0;
  background: var(--gradient);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
}

.cart-link {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s;
}
.cart-link:hover {
  border-color: var(--accent);
}

.cart-link__count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--gradient);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.burger {
  display: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

/* ===== Переключатель темы ===== */
.theme-toggle {
  position: relative;
  flex-shrink: 0;
  width: 70px;
  height: 38px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 19px;
  /* первый фон — «небо» внутри, второй — градиентная рамка */
  background:
    linear-gradient(120deg, #84ceeb, #fde68a) padding-box,
    var(--gradient) border-box;
  cursor: pointer;
  animation: theme-pulse 2.4s ease-out infinite;
  transition: transform 0.2s;
}

.theme-toggle:hover {
  transform: scale(1.08);
}
.theme-toggle:active {
  transform: scale(0.96);
}

/* Звёзды на «ночном небе» */
.theme-toggle::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 18% 30%, #fff 1.2px, transparent 1.8px),
    radial-gradient(circle at 34% 68%, #fff 1px, transparent 1.6px),
    radial-gradient(circle at 46% 26%, #fff 0.8px, transparent 1.4px);
  opacity: 0;
  transition: opacity 0.4s;
}

.theme-toggle__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition:
    transform 0.45s cubic-bezier(0.5, 1.6, 0.4, 1),
    background-color 0.4s;
}

.theme-toggle__icon {
  position: absolute;
  width: 20px;
  height: 20px;
  transition:
    opacity 0.3s,
    scale 0.4s;
}

.theme-toggle__icon--sun {
  color: #f59e0b;
  animation: theme-sun-spin 10s linear infinite;
}
.theme-toggle__icon--moon {
  color: #fde68a;
  opacity: 0;
  scale: 0.4;
  animation: theme-moon-swing 3s ease-in-out infinite alternate;
}

/* Состояние «тёмная тема» */
[data-theme='dark'] .theme-toggle {
  background:
    linear-gradient(120deg, #0b0c10, #1f2833) padding-box,
    var(--gradient) border-box;
}
[data-theme='dark'] .theme-toggle::before {
  opacity: 1;
  animation: theme-twinkle 2s ease-in-out infinite alternate;
}
[data-theme='dark'] .theme-toggle__knob {
  transform: translateX(32px);
  background: #2a3644;
}
[data-theme='dark'] .theme-toggle__icon--sun {
  opacity: 0;
  scale: 0.4;
}
[data-theme='dark'] .theme-toggle__icon--moon {
  opacity: 1;
  scale: 1;
}

@keyframes theme-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-2) 60%, transparent);
  }
  70%,
  100% {
    box-shadow: 0 0 0 10px transparent;
  }
}
@keyframes theme-sun-spin {
  to {
    rotate: 360deg;
  }
}
@keyframes theme-moon-swing {
  from {
    rotate: -14deg;
  }
  to {
    rotate: 14deg;
  }
}
@keyframes theme-twinkle {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

/* Смена темы (js/theme.js): браузер делает снимок страницы и открывает новую тему кругом
   от переключателя (View Transitions API). Страница перерисовывается один раз, а не каждый
   элемент по отдельности, поэтому смена не лагает даже на тяжёлой главной.
   Центр и радиус круга задаёт js/theme.js через --theme-x, --theme-y и --theme-r. */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-new(root) {
  animation: theme-reveal 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes theme-reveal {
  from {
    clip-path: circle(0 at var(--theme-x, 50%) var(--theme-y, 0));
  }
  to {
    clip-path: circle(var(--theme-r, 150vmax) at var(--theme-x, 50%) var(--theme-y, 0));
  }
}

/* Уважаем системную настройку «уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle::before,
  .theme-toggle__icon {
    animation: none !important;
  }
}
