/* ==============================================
 * DarkBytes — Theme Toggle Styles
 * Smooth light/dark mode toggle for the navbar
 * ============================================== */

/* -----------------------------------------------
 * 1. Global Smooth Theme Transitions
 * ----------------------------------------------- */
html {
  /* Smooth background and color transitions when switching themes */
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html body {
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html[color-scheme] body * {
  transition: background-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              fill 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              stroke 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* -----------------------------------------------
 * 2. Theme Toggle Container
 * ----------------------------------------------- */
.theme-toggle {
  --toggle-width: 52px;
  --toggle-height: 28px;
  --toggle-padding: 3px;
  --indicator-size: calc(var(--toggle-height) - var(--toggle-padding) * 2);

  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--toggle-width);
  height: var(--toggle-height);
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

/* -----------------------------------------------
 * 3. Track (the pill background)
 * ----------------------------------------------- */
.theme-toggle__track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: var(--toggle-padding);
  border-radius: 100px;
  background-color: #e8e5e3;
  border: 1.5px solid #d0cdcb;
  transition: background-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* Dark mode track */
html[color-scheme="dark"] .theme-toggle__track {
  background-color: #2a2a2a;
  border-color: #3d3d3d;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* -----------------------------------------------
 * 4. Sliding Indicator Circle
 * ----------------------------------------------- */
.theme-toggle__indicator {
  position: absolute;
  top: var(--toggle-padding);
  left: var(--toggle-padding);
  width: var(--indicator-size);
  height: var(--indicator-size);
  border-radius: 50%;
  background: linear-gradient(135deg, #ffffff 0%, #f0edf8 100%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18),
              0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: transform 0.4s cubic-bezier(0.68, -0.15, 0.27, 1.15),
              background 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
  pointer-events: none;
}

/* Dark mode: slide indicator to the right */
html[color-scheme="dark"] .theme-toggle__indicator {
  transform: translateX(calc(var(--toggle-width) - var(--toggle-height)));
  background: linear-gradient(135deg, #3a3830 0%, #2a2a22 100%);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4),
              0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* -----------------------------------------------
 * 5. Icons (Sun and Moon)
 * ----------------------------------------------- */
.theme-toggle__icon {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--indicator-size);
  height: var(--indicator-size);
  font-size: 13px;
  line-height: 1;
  pointer-events: none;
  transition: color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle__icon i {
  transition: color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sun icon — warm amber in light mode */
.theme-toggle__icon--sun {
  color: #b8860b;
}

html[color-scheme="dark"] .theme-toggle__icon--sun {
  color: #6b6b6b;
}

/* Moon icon — muted in light mode, bright in dark mode */
.theme-toggle__icon--moon {
  color: #9a9a9a;
}

html[color-scheme="dark"] .theme-toggle__icon--moon {
  color: #DDF160;
}

/* -----------------------------------------------
 * 6. Focus & Hover States
 * ----------------------------------------------- */
.theme-toggle:focus-visible .theme-toggle__track {
  outline: 2px solid #9F8BE7;
  outline-offset: 2px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08),
              0 0 0 4px rgba(159, 139, 231, 0.2);
}

html[color-scheme="dark"] .theme-toggle:focus-visible .theme-toggle__track {
  outline-color: #DDF160;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4),
              0 0 0 4px rgba(221, 241, 96, 0.2);
}

.theme-toggle:hover .theme-toggle__track {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12),
              0 0 0 3px rgba(159, 139, 231, 0.12);
}

html[color-scheme="dark"] .theme-toggle:hover .theme-toggle__track {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5),
              0 0 0 3px rgba(221, 241, 96, 0.12);
}

.theme-toggle:hover .theme-toggle__indicator {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22),
              0 0 0 1px rgba(0, 0, 0, 0.06);
}

html[color-scheme="dark"] .theme-toggle:hover .theme-toggle__indicator {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5),
              0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* -----------------------------------------------
 * 7. Active (pressed) State
 * ----------------------------------------------- */
.theme-toggle:active .theme-toggle__indicator {
  transform: scaleX(1.15);
}

html[color-scheme="dark"] .theme-toggle:active .theme-toggle__indicator {
  transform: translateX(calc(var(--toggle-width) - var(--toggle-height))) scaleX(1.15);
}

/* -----------------------------------------------
 * 8. Reduced Motion
 * ----------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html,
  html body,
  html[color-scheme] body * {
    transition-duration: 0.01ms !important;
  }

  .theme-toggle__track,
  .theme-toggle__indicator,
  .theme-toggle__icon,
  .theme-toggle__icon i {
    transition-duration: 0.01ms !important;
  }
}

/* -----------------------------------------------
 * 9. Mobile Adjustments
 * ----------------------------------------------- */
@media (max-width: 768px) {
  .theme-toggle {
    --toggle-width: 46px;
    --toggle-height: 26px;
  }

  .theme-toggle__icon {
    font-size: 11px;
  }
}
