/* Site shell: the header and footer on every page. Style them here only.
   Markup for the main pages comes from src/shell/ (npm run shell); Resources and
   Pitch Decks keep their own .site-header markup but take their styling from here. */

:root {
  --shell-max: 1120px;
  /* full-bleed bars whose content lines up with the 1120px page column */
  --shell-gutter: max(24px, calc((100% - var(--shell-max)) / 2 + 24px));
  /* the site bar's height with the menu closed: 16px padding around the 38px theme
     button, 13px around the 44px menu button. main steps down by it and in-page jumps
     offset by it; keep it in step. */
  --shell-header-height: 70px;
}

body > header,
body > footer {
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.55;
}

/* ---------- header ---------- */
/* site.js opens the menu and dropdown via [hidden]; class display rules must not beat it */
body > header [hidden] {
  display: none !important;
}

body > header {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 16px var(--shell-gutter);
  background: var(--paper);
}

/* The site bar is fixed, not sticky. scroll-padding keeps the bar's strip clear for focus
   and in-page jumps, and Chrome scrolled the page some 400px trying to reveal a sticky
   bar's own controls whenever they took focus (web.dev issue 5413); a fixed bar is not
   part of the scrolled page. main steps down by the bar's height instead. */
body > header:not(.site-header) {
  position: fixed;
  left: 0;
  right: 0;
}

body > header:not(.site-header) + main {
  margin-top: var(--shell-header-height);
}

/* printed, the bar heads the first page only */
@media print {
  body > header:not(.site-header) {
    position: static;
  }

  body > header:not(.site-header) + main {
    margin-top: 0;
  }
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 28px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  width: max-content;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.brand img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

:root[data-theme="dark"] .brand img {
  filter: invert(1);
}

nav.primary,
.site-header nav {
  display: flex;
  align-items: center;
}

.site-header nav {
  gap: 26px;
}

.navlink,
.site-header nav > a {
  color: var(--ink);
  text-decoration: none;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 0;
  cursor: pointer;
}

.navlink {
  margin-left: 26px;
}

.navlink:hover,
.navlink[aria-current="page"],
.site-header nav > a:hover,
.site-header nav > a[aria-current="page"] {
  border-bottom-color: var(--ink);
}

.navlink.demo {
  color: var(--muted);
}

.navlink.demo:hover {
  color: var(--ink);
}

.dropdown {
  position: relative;
  margin-left: 28px;
}

.dropdown .navlink {
  margin-left: 0;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 16px);
  right: 0;
  min-width: 250px;
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 6px;
  display: grid;
}

.dropdown-panel a {
  display: block;
  padding: 11px 14px;
  text-decoration: none;
  color: var(--ink);
}

.dropdown-panel a:hover {
  background: color-mix(in srgb, var(--ink) 6%, var(--paper));
}

.dropdown-panel strong {
  display: block;
  font-size: 14px;
}

.dropdown-panel span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

#theme-toggle {
  margin-left: 28px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.site-header #theme-toggle {
  margin-left: 0;
}

/* the icon follows data-theme, which is set before first paint */
.theme-icon {
  width: 18px;
  height: 18px;
  background-color: var(--ink);
  -webkit-mask: url("theme-moon.png") center / contain no-repeat;
  mask: url("theme-moon.png") center / contain no-repeat;
  transition: transform 0.15s ease;
}

:root[data-theme="dark"] .theme-icon {
  -webkit-mask-image: url("theme-sun.png");
  mask-image: url("theme-sun.png");
}

#theme-toggle:hover .theme-icon {
  transform: scale(1.1);
}

.nav-toggle {
  display: none;
}

/* ---------- footer ---------- */
body > footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
  padding: 26px var(--shell-gutter) 38px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

body > footer a {
  color: var(--muted);
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  /* 13px around the 44px menu button keeps the bar at --shell-header-height */
  body > header:not(.site-header) {
    padding-block: 13px;
  }

  /* the open menu covers the page, which stays where it was underneath */
  :root.nav-open {
    overflow: hidden;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    padding: 0;
    margin-left: auto;
  }

  /* open, the three bars turn into a cross */
  .nav-toggle[aria-expanded="true"] svg {
    display: none;
  }

  .nav-toggle[aria-expanded="true"]::before,
  .nav-toggle[aria-expanded="true"]::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 1.6px;
    background: currentColor;
    transform: rotate(45deg);
  }

  .nav-toggle[aria-expanded="true"]::after {
    transform: rotate(-45deg);
  }

  /* the open menu is a sheet over the page, from under the bar to the foot of the screen,
     its last row clear of the cookie banner; the page underneath neither moves nor scrolls */
  nav.primary {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: calc(100vh - var(--shell-header-height));
    height: calc(100dvh - var(--shell-header-height));
    padding: 8px var(--shell-gutter) max(16px, var(--cookie-banner-space, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-direction: column;
    align-items: stretch;
    background: var(--paper);
    border-top: 1px solid var(--line);
  }

  nav.primary .navlink {
    margin-left: 0;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
  }

  /* in the menu Demo is a destination like the rest, not a quiet aside */
  nav.primary .navlink.demo {
    color: var(--ink);
  }

  .dropdown {
    position: static;
    margin-left: 0;
  }

  /* the Resources row spans the menu like its siblings, its arrow at the far edge */
  .dropdown .navlink {
    display: flex;
    justify-content: space-between;
    width: 100%;
  }

  .dropdown .navlink[aria-expanded="true"] span {
    transform: rotate(180deg);
  }

  .dropdown-panel {
    position: static;
    min-width: 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 4px 0 8px 16px;
  }

  /* the theme switch closes the menu at the foot of the screen */
  nav.primary #theme-toggle {
    width: 44px;
    height: 44px;
    margin: auto 0 0;
  }
}

@media (max-width: 680px) {
  .site-header {
    grid-template-columns: 1fr auto;
    row-gap: 10px;
  }

  /* the short Resources / Pitch Decks nav fits as its own row, so no menu toggle is needed */
  .site-header nav {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    gap: 6px 22px;
  }

  .site-header nav > a {
    padding: 6px 0;
  }

  body > footer {
    flex-direction: column;
    align-items: flex-start;
  }

  /* wrapped footer links stack closely on phones; give each a 24px target (WCAG 2.5.8) */
  body > footer a {
    display: inline-block;
    padding-block: 5px;
  }
}
