/* --------- Page skeleton --------- */

/* Sticky footer lives on .site, never on body: theme.json styles body too, and
   a flex context there silently flips the axes for anyone laying it out later. */
.site {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.wrapper,
.has-global-padding {
  padding-left: var(--wp--style--root--padding-left);
  padding-right: var(--wp--style--root--padding-right);
}

.container {
  margin-left: auto;
  margin-right: auto;
  max-width: var(--wp--style--global--content-size);
}

.container-secondary {
  margin-left: auto;
  margin-right: auto;
  max-width: var(--wp--style--global--wide-size);
}

.site-main {
  flex-grow: 1;
}

/* Less air between the header and the first section than between two
   sections. A page that opens with a Cover banner sits flush instead. */
.site-main > .is-style-section:first-child {
  padding-top: var(--wp--preset--spacing--50);
}

/* Lets .not-found-section centre itself vertically with margin auto. */
body.error404 .site-main {
  display: flex;
  flex-direction: column;
}

.common-section {
  padding-top: var(--wp--preset--spacing--60);
  padding-bottom: var(--wp--preset--spacing--50);
}

.entry-content {
  padding-top: var(--wp--preset--spacing--40);
}

/* --------- Header --------- */

/* The fixed .quick-exit is not part of the header but has to line up with
   its row and have room kept free for it — both read these. */
:root {
  --header-row-height: 72px;
  /* The part of the tucked Quick Exit that shows on screen. */
  --quick-exit-width: 140px;
}

@media screen and (max-width: 1199px) {
  :root {
    --header-row-height: 44px;
    --quick-exit-width: 112px;
  }
}

.header {
  position: relative;
  padding-top: var(--wp--preset--spacing--30);
  padding-bottom: var(--wp--preset--spacing--30);
  z-index: var(--z-header);
  background-color: var(--wp--preset--color--base);
}

/* Narrower side padding than the page content: the menus spread out towards
   the screen edges, where the Quick Exit and Donate tabs sit. */
.header .wrapper {
  padding-left: var(--wp--preset--spacing--40);
  padding-right: var(--wp--preset--spacing--40);
}

/* Full width, not .container: the menus sit out by the screen edges. Side
   columns share the free space equally, which centres the logo, but never
   shrink below their content — when it gets tight the logo drifts off-centre
   instead of a menu wrapping onto a second line. */
.header-container {
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: var(--wp--preset--spacing--30);
  min-height: var(--header-row-height);
}

.header-desktop-nav--left {
  justify-self: start;
}

.header-logo {
  justify-self: center;
}

/* Sized by height: the logo is a stacked mark + two-line name (~2.1:1), so a
   width would let the header grow taller than its row. */
.custom-logo {
  display: block;
  width: auto;
  height: 64px;
}

/* padding-right keeps the spot under the fixed Quick Exit free. */
.header-end {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: var(--wp--preset--spacing--30);
  /* The Quick Exit is measured from the screen edge, the header content from
     the header's own padding — hence the subtraction. */
  padding-right: calc(var(--quick-exit-width) + var(--wp--preset--spacing--30) - var(--wp--preset--spacing--40));
}

/* --------- Header menu --------- */

.header-menu {
  display: flex;
  align-items: center;
  gap: 0 var(--wp--preset--spacing--20);
}

.header-menu a,
.header-menu .submenu-toggle {
  color: var(--wp--preset--color--contrast);
  font-family: var(--wp--preset--font-family--accent);
  font-size: var(--wp--preset--font-size--small);
  font-weight: 700;
  letter-spacing: 2px;
  text-decoration: none;
}

.header-menu a:hover,
.header-menu a:focus-visible,
.header-menu .submenu-toggle:hover,
.header-menu .submenu-toggle:focus-visible {
  color: var(--wp--preset--color--primary);
}

.header-menu .current-menu-item > a::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 2px;
  margin-right: 8px;
  background-color: currentColor;
  vertical-align: middle;
}

/* A background, not a ::before like the links above: inside the flex button a
   pseudo-element becomes the baseline and drops the label below the others. */
.header-menu .current-menu-ancestor > .submenu-toggle {
  padding-left: 18px;
  background: linear-gradient(currentColor, currentColor) no-repeat left center / 10px 2px;
}

.submenu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.submenu-toggle::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-top: -4px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.submenu-toggle[aria-expanded="true"]::after {
  margin-top: 3px;
  transform: rotate(-135deg);
}

/* --------- Menu toggle (hamburger) --------- */

.menu-toggle {
  display: none;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  z-index: var(--z-toggle);
  position: relative;
}

.hamburger {
  display: inline-block;
  width: 30px;
  height: 22px;
  position: relative;
}

.hamburger span {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--wp--preset--color--contrast);
  transition:
    transform 0.35s ease,
    opacity 0.25s ease,
    top 0.35s ease;
}

.hamburger span:nth-child(1) {
  top: 0;
}

.hamburger span:nth-child(2) {
  top: 10px;
}

.hamburger span:nth-child(3) {
  top: 20px;
}

.menu-toggle.is-open .hamburger span {
  background: var(--wp--preset--color--primary);
}

.menu-toggle.is-open .hamburger span:nth-child(1) {
  transform: translateY(10px) rotate(45deg);
}

.menu-toggle.is-open .hamburger span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.is-open .hamburger span:nth-child(3) {
  transform: translateY(-10px) rotate(-45deg);
}

@media screen and (max-width: 640px) {
  .menu-toggle {
    width: 22px;
    height: 22px;
  }

  .hamburger {
    width: 22px;
    height: 16px;
  }

  .hamburger span {
    height: 2px;
  }

  .hamburger span:nth-child(2) {
    top: 7px;
  }

  .hamburger span:nth-child(3) {
    top: 14px;
  }

  .menu-toggle.is-open .hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }

  .menu-toggle.is-open .hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }
}

/* --------- Scroll lock while the drawer is open --------- */

.is-menu-open {
  overflow: hidden;
}

/* --------- Desktop: menus beside the logo, dropdown submenus --------- */

@media screen and (min-width: 1200px) {
  .header-nav {
    display: none;
  }

  .header-menu .menu-item {
    position: relative;
    padding: 16px 8px;
  }

  .header-menu .sub-menu {
    display: block;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 240px;
    padding: 12px 0;
    background-color: var(--wp--preset--color--base);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      opacity 0.2s ease,
      visibility 0.2s ease;
    z-index: var(--z-dropdown);
  }

  .header-menu .menu-item:hover > .sub-menu,
  .header-menu .menu-item:focus-within > .sub-menu,
  .header-menu .submenu-toggle[aria-expanded="true"] + .sub-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .header-menu .sub-menu .menu-item {
    padding: 0;
  }

  .header-menu .sub-menu a {
    display: block;
    padding: 8px 24px;
    font-family: var(--wp--preset--font-family--body);
    font-weight: 400;
    letter-spacing: 0.5px;
  }
}

/* --------- Below 1200px: logo + toggle, slide-in drawer --------- */

/* 1200, not the usual 1024: six items, a centred logo and the room for the
   Quick Exit do not fit on one line any narrower. */
@media screen and (max-width: 1199px) {
  .header-container {
    display: flex;
    justify-content: space-between;
  }

  .header-desktop-nav {
    display: none;
  }

  .custom-logo {
    height: var(--header-row-height);
  }

  /* The Quick Exit hangs below the toggle here (components.css), so the row
     keeps no room for it. */
  .header-end {
    padding-right: 0;
  }

  .menu-toggle {
    display: inline-flex;
  }

  /* visibility too: a transform-only drawer stays focusable off-screen. */
  .header-nav {
    position: fixed;
    top: 0;
    right: 0;
    height: 100dvh;
    width: min(380px, 90vw);
    background: var(--wp--preset--color--base);
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.15);
    transform: translateX(110%);
    visibility: hidden;
    transition:
      transform 0.35s cubic-bezier(0.2, 0.9, 0.2, 1),
      visibility 0s linear 0.35s;
    z-index: var(--z-drawer);
    /* Clears the toggle and the Quick Exit under it. */
    padding: 150px 24px 24px;
    overflow-y: auto;
  }

  .header-nav.is-open {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
  }

  .header-menu {
    flex-direction: column;
    align-items: start;
  }

  .header-menu .menu-item {
    padding: 12px 6px;
  }

  .header-nav .sub-menu {
    display: none;
    margin-top: 10px;
    padding-left: 16px;
  }

  .header-nav .submenu-toggle[aria-expanded="true"] + .sub-menu {
    display: block;
  }

  .header-nav .browse-safely-link {
    display: inline-block;
    margin: var(--wp--preset--spacing--40) 6px 0;
  }

  .menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    visibility: hidden;
    transition:
      opacity 0.25s ease,
      visibility 0s linear 0.25s;
    z-index: var(--z-backdrop);
  }

  .menu-backdrop.is-open {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
  }
}

/* --------- Footer --------- */

.footer {
  border-top: 1px solid var(--wp--preset--color--border);
  padding-top: var(--wp--preset--spacing--40);
  padding-bottom: var(--wp--preset--spacing--20);
}


.footer-container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--wp--preset--spacing--30);
  font-size: var(--wp--preset--font-size--small);
  margin-bottom: var(--wp--preset--spacing--30);
}
.footer-legal {
  font-size: var(--wp--preset--font-size--normal);
  font-weight: 500;
}
.footer-logo {
  max-width: clamp(80px, 6vw + 40px, 120px);
  flex-shrink: 0;
}

.footer-copyright {
  margin: 0;
}
.footer-sponsored {
  margin: 0;
  margin-left: auto;
}
.footer-link {
  color: var(--wp--preset--color--contrast);
}

.footer-link:hover,
.footer-link:focus-visible {
  color: var(--wp--preset--color--primary);
}

.footer .social-links {
  margin-left: auto;
}

@media screen and (max-width: 640px) {
  .footer-container {
    flex-direction: column;
    justify-content: center;
    text-align: center;
  }

  .footer .social-links,
  .footer-sponsored {
    margin-left: 0;
  }
}
