/* The South Downs hero (downs.js), the header over it, and the header on phones.
   Sits on top of styles.css. */

/* The header lies over the top of the hero, on the sky. */
.site-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: transparent;
  border-bottom-color: transparent;
}

/* The wordmark is the hero's now: the header keeps only the menu and "Tap in". */
.site-header .wordmark {
  display: none;
}

.site-header .site-nav {
  margin-left: auto;
}

/* The hero is as tall as the largest viewport (lvh): when a phone's address bar
   slides away the window grows, and the landscape must still reach its foot, so no
   gap can ever open under it. The words are placed from the top and do not move.
   Neither lvh nor svh changes while scrolling, so nothing jumps or resizes. */
.downs {
  --downs-top: #D7D2D4;     /* the golden frame's sky and land; downs.js keeps them in step on phones */
  --downs-bottom: #6B5B11;
  position: relative;
  height: 100vh;
  height: 100lvh;
  min-height: 560px;
  overflow: hidden;
  /* Under everything, the sky above and the land's own colour below, never the page white. */
  background: linear-gradient(var(--downs-top) 0 50%, var(--downs-bottom) 50% 100%);
  color: var(--navy);
}

.motion .downs {
  --downs-top: #D8E0EB;     /* the dawn frame */
  --downs-bottom: #526344;
}

/* Held while the scrub plays (also without GSAP), then covered by the Tap line. */
.motion #hero {
  position: sticky;
  top: 0;
}

/* The stretch of page that scrolls past under the held hero while the clip plays. */
.downs-scrub {
  display: none;
}

.motion .downs-scrub {
  display: block;
  height: 130vh;
  height: 130svh;
}

.downs__view {
  position: absolute;
  inset: 0;
  transform-origin: 60% 55%;
  will-change: transform;
  background: var(--downs-bottom);
}

/* The still: golden when nothing moves, the first frame (dawn) while frames load. */
.downs__still,
.downs__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.downs__still {
  background: url('assets/downs/golden-d.jpg') 60% 50% / cover no-repeat;
}

.motion .downs__still {
  background-image: url('assets/downs/dawn-d.jpg');
}

.downs__canvas {
  display: block;
}

/* The wordmark, headline and line, on the sky at the top left. The headline and
   the line under it are set in from the bar, so the line drawn down from the bar
   runs past the words rather than through them. */
.downs__head {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  column-gap: 0.14em;
  padding-top: clamp(96px, 14vh, 150px);
  font-size: clamp(64px, 7.2vw, 112px);   /* the wordmark's size; the columns follow it */
}

.downs__mark {
  display: contents;
  line-height: 0.8;
  color: var(--navy);
}

.downs__tap,
.downs__retail {
  line-height: 0.8;
}

.downs__tap {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.005em;
}

.downs__bar {
  display: block;
  width: 4px;
  height: 0.74em;
  border-radius: 2px;
  background: var(--accent);
}

.downs__retail {
  font-size: 0.46em;
  font-weight: 400;
}

.downs__title,
.downs__sub {
  grid-column: 3;
  padding-left: 10px;
}

.downs__title {
  max-width: 20ch;
  margin: clamp(22px, 3.4vh, 34px) 0 0;
  font-size: clamp(34px, 3.6vw, 54px);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.downs__sub {
  max-width: 40ch;
  margin: 14px 0 0;
  font-size: clamp(17px, 1.3vw, 19px);
  line-height: 1.5;
  color: #3E4659;
}

/* The line from the foot of the bar to the bottom of the screen. It meets the Tap
   line at the same x. On wide screens it draws down as the clip plays, moved by a
   CSS scroll timeline (on the compositor, in step with the scroll; downs.js only
   sets its place and how long the scrub is, and moves it itself only where the
   browser has no scroll timelines). Phones use the same scroll timeline (never a
   script). Where there is none, or with ?drop=stub, phones get a short still line
   from the bar to just below the words, which never reaches the landscape; the Tap
   line then draws as usual when the page slides up. downs.js says which on <html>
   as data-drop. */
.downs__line {
  position: absolute;
  z-index: 31;           /* above the dimming as the Tap line covers the hero, so it stays one colour */
  width: 4px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top;
  will-change: transform;
}

.downs .downs__line {
  display: none;
}

.motion .downs .downs__line {
  display: block;
}

/* Wide screens: the line draws down, and the view pushes in from 1.00 to 1.03, across
   the scrub (--downs-scrub, set by downs.js), driven by the scroll itself. */
@supports (animation-timeline: scroll()) {
  /* Phones: only the line, only when downs.js has chosen the timeline (see below). */
  @media (max-width: 759px) {
    html[data-drop='timeline'].motion .downs .downs__line {
      animation: downs-line linear both;
      animation-timeline: scroll(root block);
      animation-range: 0px var(--downs-scrub, 100vh);
      will-change: transform;
    }
  }

  @media (min-width: 760px) {
    .motion .downs .downs__line {
      animation: downs-line linear both;
      animation-timeline: scroll(root block);
      animation-range: 0px var(--downs-scrub, 100vh);
    }

    .motion .downs__view {
      animation: downs-push linear both;
      animation-timeline: scroll(root block);
      animation-range: 0px var(--downs-scrub, 100vh);
    }
  }
}

@keyframes downs-line {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes downs-push {
  from { transform: scale(1); }
  to { transform: scale(1.03); }
}

/* Phones: the words on plain sky at the top, the landscape across the lower half.
   The sky colour is the colour of the top edge of the frame being shown, and the
   frame fades into it, so the two meet without a seam as the light changes. */
@media (max-width: 759px) {
  /* No push-in. The line is the short still stub (downs.js sets its length) unless
     the scroll timeline above draws it. */
  .downs .downs__line {
    transform: none;
    will-change: auto;
  }

  .downs__view {
    will-change: auto;
  }

  /* The landscape reaches the foot of the largest viewport. It is taller by the
     address bar's height (100lvh - 100svh), so while the bar shows, the part above
     it is the same 52svh, and when it slides away more of the land shows below. */
  .downs__view {
    top: auto;
    height: calc(52svh + 100lvh - 100svh);
    background: transparent;
  }

  .downs__still {
    background-image: url('assets/downs/golden-p.jpg');
    background-position: 55% 100%;
  }

  .motion .downs__still {
    background-image: url('assets/downs/dawn-p.jpg');
  }

  .downs__still,
  .downs__canvas {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 16%);
  }

  /* On phones the sky colour fills everything above the landscape. */
  .downs {
    background: linear-gradient(var(--downs-top) 0 70%, var(--downs-bottom) 70% 100%);
  }

  .downs__head {
    padding-top: 76px;
    font-size: 56px;
  }

  .downs__title,
  .downs__sub {
    padding-left: 6px;
  }

  .downs__bar {
    width: 4px;
  }

  .downs__title {
    margin-top: 20px;
    font-size: clamp(30px, 8.6vw, 37px);
  }

  .downs__sub {
    margin-top: 10px;
    font-size: 16px;
    line-height: 1.4;
  }
}

/* The header on phones (moved here with the hero) */
@media (max-width: 759px) {
  .site-header__inner {
    position: relative;
    gap: 0 16px;
    padding-top: 8px;
    padding-bottom: 4px;
  }

  /* Wordmark and "Tap in" share the first row, links take the second. */
  .site-nav {
    width: 100%;
  }

  .site-header .btn--nav {
    position: absolute;
    right: var(--gutter);
    top: 10px;
    min-height: 40px;
    padding: 0 16px;
    font-size: 15px;
  }

  .js .site-header__inner {
    flex-wrap: nowrap;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .js .site-nav {
    width: auto;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .js .site-header .btn--nav {
    position: static;
    min-height: 44px;
    padding: 0 14px;
    white-space: nowrap;
  }

  .menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 12px;
    border: 1.5px solid var(--navy);
    white-space: nowrap;
    border-radius: 6px;
    background: var(--white);
    color: var(--navy);
    font: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
  }

  .js .site-nav__links {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    display: none;
    flex-direction: column;
    padding: 4px var(--gutter) 12px;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--white);
    box-shadow: 0 18px 30px rgba(20, 33, 61, 0.12);
  }

  .js .site-nav__links.is-open {
    display: flex;
  }

  .js .site-nav__links .site-nav__link {
    min-height: 52px;
    border-bottom: 1px solid var(--line);
    font-size: 18px;
  }

  .js .site-nav__links .site-nav__link:last-child {
    border-bottom: 0;
  }

  .js .site-header .btn--nav {
    font-size: 16px;
  }
}
