/**
 * Component: Header Scroll Logo Swap
 * Version: 1.0.0
 * Repository: wordpress-code-library
 */

/* =========================
   Design tokens
========================= */

:root {
  --wpcl-header-dark: #313737;
  --wpcl-header-light: #f1ece6;

  --wpcl-header-text-dark: #313737;
  --wpcl-header-text-light: #f1ece6;

  --wpcl-header-border-dark: rgba(241, 236, 230, 0.16);
  --wpcl-header-border-light: rgba(49, 55, 55, 0.14);

  --wpcl-header-max-width: 75rem;
  --wpcl-header-height: 5.5rem;
  --wpcl-header-height-mobile: 5rem;
  --wpcl-header-padding-inline: clamp(1rem, 3vw, 2rem);

  --wpcl-header-shadow:
    0 0.75rem 2rem rgba(49, 55, 55, 0.12);

  --wpcl-header-transition: 220ms ease;
}

/* =========================
   Header shell
========================= */

.wpcl-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 999;
  width: 100%;

  color: var(--wpcl-header-text-light);
  background-color: var(--wpcl-header-dark);
  border-bottom: 1px solid var(--wpcl-header-border-dark);

  transition:
    color var(--wpcl-header-transition),
    background-color var(--wpcl-header-transition),
    border-color var(--wpcl-header-transition),
    box-shadow var(--wpcl-header-transition);
}

.wpcl-header.is-scrolled {
  color: var(--wpcl-header-text-dark);
  background-color: var(--wpcl-header-light);
  border-bottom-color: var(--wpcl-header-border-light);
  box-shadow: var(--wpcl-header-shadow);
}

/* WordPress admin bar offset */

.admin-bar .wpcl-header {
  top: 32px;
}

@media (max-width: 782px) {
  .admin-bar .wpcl-header {
    top: 46px;
  }
}

/* =========================
   Inner layout
========================= */

.wpcl-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(1rem, 3vw, 2.5rem);

  width: min(
    var(--wpcl-header-max-width),
    calc(100% - (var(--wpcl-header-padding-inline) * 2))
  );
  min-height: var(--wpcl-header-height);
  margin-inline: auto;
}

/* =========================
   Logo
========================= */

.wpcl-header__logo {
  display: grid;
  flex: 0 0 auto;
  width: 3.75rem;
  aspect-ratio: 1;
  line-height: 0;
}

.wpcl-header__logo-image {
  grid-area: 1 / 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;

  transition:
    opacity var(--wpcl-header-transition),
    visibility var(--wpcl-header-transition);
}

.wpcl-header__logo-image--dark-bg {
  opacity: 1;
  visibility: visible;
}

.wpcl-header__logo-image--light-bg {
  opacity: 0;
  visibility: hidden;
}

.wpcl-header.is-scrolled
  .wpcl-header__logo-image--dark-bg {
  opacity: 0;
  visibility: hidden;
}

.wpcl-header.is-scrolled
  .wpcl-header__logo-image--light-bg {
  opacity: 1;
  visibility: visible;
}

/* =========================
   Navigation
========================= */

.wpcl-header__nav {
  display: flex;
  align-items: center;
  gap: clamp(1.25rem, 3vw, 2.25rem);
  margin-left: auto;
}

.wpcl-header__menu {
  display: flex;
  align-items: center;
  gap: clamp(1.25rem, 2.5vw, 2rem);
  margin: 0;
  padding: 0;
  list-style: none;
}

.wpcl-header__menu a {
  color: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  text-underline-offset: 0.3em;

  transition:
    opacity var(--wpcl-header-transition),
    text-decoration-color var(--wpcl-header-transition);
}

.wpcl-header__menu a:hover,
.wpcl-header__menu a:focus-visible {
  opacity: 0.72;
  text-decoration: underline;
}

.wpcl-header__menu .current-menu-item > a,
.wpcl-header__menu .current_page_item > a,
.wpcl-header__menu .current-menu-ancestor > a {
  text-decoration: underline;
}

/* =========================
   CTA
========================= */

.wpcl-header__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.75rem 1.2rem;

  color: var(--wpcl-header-text-dark);
  background-color: var(--wpcl-header-light);
  border: 1px solid var(--wpcl-header-light);

  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;

  transition:
    color var(--wpcl-header-transition),
    background-color var(--wpcl-header-transition),
    border-color var(--wpcl-header-transition),
    transform var(--wpcl-header-transition);
}

.wpcl-header.is-scrolled .wpcl-header__cta {
  color: var(--wpcl-header-text-light);
  background-color: var(--wpcl-header-dark);
  border-color: var(--wpcl-header-dark);
}

.wpcl-header__cta:hover,
.wpcl-header__cta:focus-visible {
  transform: translateY(-2px);
}

/* =========================
   Mobile toggle
========================= */

.wpcl-header__toggle {
  display: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;

  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 0;

  cursor: pointer;
  appearance: none;
}

.wpcl-header__toggle-lines {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.3125rem;

  width: 1.375rem;
  height: 1rem;
  margin: auto;
}

.wpcl-header__toggle-line {
  display: block;
  flex: 0 0 2px;

  width: 100%;
  height: 2px;

  background-color: currentColor;
  transform-origin: center;

  transition:
    transform var(--wpcl-header-transition),
    opacity var(--wpcl-header-transition);
}

.wpcl-header.is-menu-open
  .wpcl-header__toggle-line:nth-child(1) {
  transform: translateY(0.4375rem) rotate(45deg);
}

.wpcl-header.is-menu-open
  .wpcl-header__toggle-line:nth-child(2) {
  opacity: 0;
}

.wpcl-header.is-menu-open
  .wpcl-header__toggle-line:nth-child(3) {
  transform: translateY(-0.4375rem) rotate(-45deg);
}

/* =========================
   Mobile navigation
========================= */

@media (max-width: 767px) {
  .wpcl-header__inner {
    min-height: var(--wpcl-header-height-mobile);
  }

  .wpcl-header__logo {
    width: 3.5rem;
  }

  .wpcl-header__toggle {
    display: inline-grid;
    place-items: center;
    margin-left: auto;
  }

  .wpcl-header__nav {
    position: absolute;
    inset: 100% 0 auto;
    display: grid;
    gap: 1.5rem;
    max-height: calc(100vh - var(--wpcl-header-height-mobile));
    padding:
      1.5rem
      var(--wpcl-header-padding-inline)
      2rem;
    overflow-y: auto;

    color: var(--wpcl-header-text-light);
    background-color: var(--wpcl-header-dark);
    border-top: 1px solid var(--wpcl-header-border-dark);

    opacity: 0;
    visibility: hidden;
    transform: translateY(-0.5rem);
    pointer-events: none;

    transition:
      color var(--wpcl-header-transition),
      background-color var(--wpcl-header-transition),
      border-color var(--wpcl-header-transition),
      opacity var(--wpcl-header-transition),
      visibility var(--wpcl-header-transition),
      transform var(--wpcl-header-transition);
  }

  .wpcl-header.is-scrolled .wpcl-header__nav {
    color: var(--wpcl-header-text-dark);
    background-color: var(--wpcl-header-light);
    border-top-color: var(--wpcl-header-border-light);
  }

  .wpcl-header.is-menu-open .wpcl-header__nav {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
  }

  .wpcl-header__menu {
    display: grid;
    gap: 0;
  }

  .wpcl-header__menu li {
    border-bottom: 1px solid currentColor;
  }

  .wpcl-header__menu a {
    display: block;
    padding-block: 1rem;
  }

  .wpcl-header__cta {
    width: 100%;
  }

  body.wpcl-menu-open {
    overflow: hidden;
  }
}

/* =========================
   Focus and motion
========================= */

.wpcl-header a:focus-visible,
.wpcl-header button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
}

@media (prefers-reduced-motion: reduce) {
  .wpcl-header,
  .wpcl-header *,
  .wpcl-header *::before,
  .wpcl-header *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
