/* The frame every page shares (written into the pages by tools/build-chrome.py):
   the tabs with SceneMill's playhead on the one that is open, the menu on a
   phone, the band with the download at the end of a page, and how one page
   gives way to the next. */

/* ---------- The tabs ---------- */

.site-nav {
  position: relative;
  z-index: 1; /* the playhead stands in front of the ruler */
}

.site-nav a {
  position: relative;
}

.site-nav a[aria-current="page"] {
  color: var(--text);
}

/* The playhead of the timeline, standing on the header's ruler under the open tab.
   It is one thing across pages (see "From page to page"): it travels from tab to tab. */
.site-nav__mark,
.site-nav a:not([aria-current="page"])::after {
  position: absolute;
  left: 50%;
  bottom: calc((var(--header-height) - 100%) / -2 - 1px);
  width: 11px;
  height: 12px;
  margin-left: -5.5px;
  clip-path: polygon(0 0, 100% 0, 100% 58%, 50% 100%, 0 58%);
}

.site-nav__mark {
  background: var(--accent);
  view-transition-name: playhead;
}

/* Where the playhead would go: its outline under the tab the pointer is on. */
.site-nav a:not([aria-current="page"])::after {
  content: "";
  background: var(--border-strong);
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity var(--duration-fast) ease, transform var(--duration) var(--ease-out);
}

.site-nav a:not([aria-current="page"]):hover::after,
.site-nav a:not([aria-current="page"]):focus-visible::after {
  opacity: 1;
  transform: none;
}

/* ---------- The menu on a phone ---------- */

.menu {
  display: none;
  flex: none;
}

.menu summary {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
}

.menu summary::-webkit-details-marker {
  display: none;
}

/* Three tracks, as in the timeline; opened, the two outer ones cross. */
.menu__icon,
.menu__icon::before,
.menu__icon::after {
  display: block;
  width: 1.1rem;
  height: 2px;
  border-radius: 1px;
  background: var(--text);
  transition: transform var(--duration) var(--ease-out), opacity var(--duration-fast) ease;
}

.menu__icon {
  position: relative;
}

.menu__icon::before,
.menu__icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.menu__icon::before {
  top: -6px;
  background: var(--accent);
}

.menu__icon::after {
  top: 6px;
}

.menu[open] .menu__icon {
  background: transparent;
}

.menu[open] .menu__icon::before {
  transform: translateY(6px) rotate(45deg);
}

.menu[open] .menu__icon::after {
  transform: translateY(-6px) rotate(-45deg);
}

.menu__panel {
  position: fixed;
  inset: var(--header-height) 0 auto 0;
  display: grid;
  padding: 0.5rem var(--gutter) 1.25rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--ink);
  box-shadow: 0 24px 40px -20px rgb(0 0 0 / 0.8);
}

.menu__panel a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 1.05rem;
  text-decoration: none;
}

.menu__panel a:last-child {
  border-bottom: 0;
}

.menu__panel a[aria-current="page"] {
  color: var(--text);
}

.menu__panel a[aria-current="page"]::before {
  content: "";
  width: 9px;
  height: 10px;
  background: var(--accent);
  clip-path: polygon(0 0, 58% 0, 100% 50%, 58% 100%, 0 100%);
}

@media (max-width: 900px) {
  .site-nav {
    display: none;
  }

  .menu {
    display: block;
  }

  .site-header__inner > .button {
    margin-left: auto;
  }
}

/* A phone's width holds the mark, the download, the languages and the menu only when they stand closer. */
@media (max-width: 480px) {
  .site-header__inner {
    gap: 0.6rem;
  }

  .brand img {
    height: 26px;
  }

  .site-header__inner > .button {
    padding-inline: 0.75rem;
  }
}

/* ---------- The end of a page ---------- */

/* What the page was about leads to the download, and to the tab that follows.
   No box: a line of the page, set off by the ruler of the timeline. */
.closing {
  margin-top: var(--space-section);
}

.closing + .site-footer {
  margin-top: 0;
  border-top: 0;
}

.closing__inner {
  display: grid;
  gap: 1.5rem 2.5rem;
  align-items: center;
  padding-block: clamp(2.25rem, 1.5rem + 3vw, 3.75rem);
  border-block: 1px solid var(--border);
  background-image: repeating-linear-gradient(90deg, var(--border-strong) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(90deg, var(--border) 0 1px, transparent 1px 16px);
  background-size: auto 7px, auto 3px;
  background-repeat: repeat-x;
}

.closing__title {
  max-width: 22ch;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.5rem);
  font-weight: 300;
  line-height: 1.05;
  color: var(--text);
}

.closing__fact {
  margin-top: 0.4rem;
  color: var(--text-soft);
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
}

.closing__next {
  justify-self: start;
  padding-block: 0.4rem;
  color: var(--text-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  transition: color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.closing__next::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-left: 0.6em;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg) translateY(-0.1em);
  transition: transform var(--duration) var(--ease-out);
}

.closing__next:hover {
  color: var(--text);
  border-color: var(--accent);
}

.closing__next:hover::after {
  transform: translateX(0.3em) rotate(45deg) translateY(-0.1em);
}

@media (min-width: 900px) {
  .closing__inner {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .closing__next {
    justify-self: end;
  }
}

/* ---------- Pictures that rise into place ---------- */

/* A picture comes up to its place as the page is scrolled to it: from a little below, a little
   smaller, out of the dark. The browser ties the movement to the scroll position itself
   (a scroll-driven animation), so it is drawn in step with the scrolling; a browser that does
   not know this shows the picture at rest. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .rise {
      transform-origin: 50% 100%;
      animation: rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 115%;
    }
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4.5rem) scale(0.93);
  }

  45% {
    opacity: 1;
  }
}

/* ---------- From page to page ---------- */

/* The header stays where it is, the playhead travels to the new tab, and the
   page below gives way to the next one. */
@view-transition {
  navigation: auto;
}

main {
  view-transition-name: page;
}

.site-header {
  view-transition-name: header;
}

::view-transition-group(playhead) {
  animation-duration: 460ms;
  animation-timing-function: var(--ease-out);
}

::view-transition-old(page) {
  animation: page-leaves 160ms ease both;
}

::view-transition-new(page) {
  animation: page-arrives 420ms var(--ease-out) both;
}

@keyframes page-leaves {
  to {
    opacity: 0;
  }
}

@keyframes page-arrives {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
}

.closing__title strong {
  font-weight: 700;
}
