/* River Power V3: home page.
   The source (heading, moorland photograph and the river's spring), then five
   reaches. Lane positions (--x0 to --x5) are set once on the walk, so each
   bend starts where the previous lane ended. The line thickens downstream
   (the source is finer than --river-1, then --river-1 to -5). */

/* The hero measures the page itself (cqw) so the photograph can bleed exactly
   to the right edge and the heading can scale with the walk. Home only. */
body {
  container-type: inline-size;
}

.walk {
  /* Lane centres, as a share of the walk's width: source, then reaches 1 to 5.
     --x0 is the source's lane, beside the moorland photograph: just wider
     than "from our" at the heading's size, so the two lines fit beside it. */
  --x0: 46%;
  --x1: 70%;
  --x2: 46%;
  --x3: 74%;
  --x4: 36%;
  --x5: 58%;
}

/* ---------- The source: the moor, where the river rises ----------
   A grid that shares the reaches' columns: [left bank] [lane] [right bank].
   Wide screens: "Renewable energy" runs across the top; "from our rivers"
   steps down the left bank; the photograph fills the right bank below the
   first line and bleeds off the page's right edge; the river rises in the
   lane between them, level with the photograph's top edge.
   Narrow screens (830px and below): the heading spans the walk, then the
   photograph bleeds right from a lane at the left edge, where the river
   rises beside it. */

.source {
  /* The walk's width, the space between it and the page edge, and the
     heading's size as a share of the walk ("Renewable energy" is 7.22em) */
  --walk-now: min(100cqw - 2 * var(--gutter), var(--walk-max));
  --bleed: calc((100cqw - var(--walk-now)) / 2);
  --title-size: calc(var(--walk-now) * 0.116);
  --title-leading: 0.9;
  /* The photograph's top: below the first line's descenders, level with the
     x-height of the second line */
  --title-step: calc(var(--title-size) * 1.2);
  position: relative;
  display: grid;
  grid-template-columns:
    [left-start] calc(var(--x0) - var(--lane) / 2)
    [left-end lane-start] var(--lane)
    [lane-end right-start] minmax(0, 1fr)
    [right-end];
  grid-template-rows: [title-start] var(--title-step) [moor-start] auto [moor-end];
  padding-top: var(--space-l);
}

.source__title {
  grid-column: left-start / right-end;
  grid-row: title-start / moor-end;
  align-self: start;
  font-size: var(--title-size);
  font-weight: var(--weight-bold);
  line-height: var(--title-leading);
  letter-spacing: -0.01em;
  text-wrap: wrap;
}

/* Line one runs over the lane and the photograph's column; the rest of the
   heading keeps to the left bank. */
.source__line {
  display: block;
  white-space: nowrap;
}

.source__line + .source__line {
  max-width: calc(var(--x0) - var(--lane) / 2);
  white-space: normal;
}

.source__figure {
  grid-column: left-start / right-end;
  grid-row: moor-start / moor-end;
  display: grid;
  grid-template-columns: subgrid;
  align-items: end;
}

.source__photo {
  grid-column: right;
  grid-row: 1;
  width: calc(100% + var(--bleed));
  max-width: none;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: 50% 58%;
}

.source__label {
  grid-column: left;
  grid-row: 1;
  justify-self: end;
  text-align: right;
}

/* The spring: the river rises in the source's lane, level with the top of
   the photograph, and runs on to the first reach's bend. Finer than the
   first reach: the line thickens downstream. */
.river--source {
  --river-w: calc(var(--river-1) * 0.8);
  grid-column: lane;
  grid-row: moor-start / auto;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* ---------- The load moment: the river draws itself down from the spring ----------
   Each stretch in the first screen (the source, then the first reach's bend
   and run) is shown through a mask that traces it, so the line and its water
   appear together, once, in about two seconds; the water then flows on as
   everywhere else. The masks live in an unrendered SVG (svg.river-draw);
   reduced motion skips all of this and shows the finished river. */

.river-draw {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.river-draw mask {
  mask-type: alpha;
}

/* Timing: the spring starts slowly and gathers pace (ending at about twice
   its average speed), the bend keeps that pace, and the run sets off at it
   and slows to a stop: one gesture of about two seconds. */
.river-draw path {
  --draw-delay: 0.15s;
  --draw-time: 0.8s;
  --draw-ease: cubic-bezier(0.5, 0, 0.9, 0.8);
  fill: none;
  /* Any opaque colour reveals (alpha mask); a light one still reveals if a
     browser ignores mask-type and masks by luminance */
  stroke: var(--color-paper);
  stroke-width: 28;
  stroke-linecap: round;
  stroke-dasharray: 1 1.1;
  animation: river-draw var(--draw-time) var(--draw-ease) var(--draw-delay) both;
}

.river-draw .river-draw__bend {
  --draw-delay: 0.95s;
  --draw-time: 0.3s;
  --draw-ease: linear;
}

.river-draw .river-draw__run {
  --draw-delay: 1.25s;
  --draw-time: 1s;
  --draw-ease: cubic-bezier(0.25, 0.4, 0.5, 1);
}

@keyframes river-draw {
  from {
    stroke-dashoffset: 1.05;
  }

  to {
    stroke-dashoffset: 0;
  }
}

.river--source > path {
  mask: url(#river-draw-source);
}

.reach--woodland > .river--bend > .river__swing {
  mask: url(#river-draw-swing);
}

.reach--woodland > .river--bend > .river__wave {
  mask: url(#river-draw-wave);
}

.reach--woodland > .river--run > path {
  mask: url(#river-draw-run);
}

@media (prefers-reduced-motion: reduce) {
  .river-draw path {
    animation: none;
  }

  .river--source > path,
  .reach--woodland > .river--bend > path,
  .reach--woodland > .river--run > path {
    mask: none;
  }
}

/* ---------- The reaches ---------- */

.reach--woodland {
  --from: var(--x0);
  --at: var(--x1);
  --dir: 1;
  --bend: 9.5rem;
  --river-w: var(--river-1);
}

.reach--intake {
  --from: var(--x1);
  --at: var(--x2);
  --dir: -1;
  --bend: 7rem;
  --river-w: var(--river-2);
}

.reach--turbine {
  --from: var(--x2);
  --at: var(--x3);
  --dir: 1;
  --bend: 8rem;
  --river-w: var(--river-3);
}

.reach--return {
  --from: var(--x3);
  --at: var(--x4);
  --dir: -1;
  --bend: 10.5rem;
  --river-w: var(--river-4);
}

.reach--end {
  --from: var(--x4);
  --at: var(--x5);
  --dir: 1;
  --bend: 6.5rem;
  --river-w: var(--river-5);
}

/* Reach 1: woodland stream on the left bank, De Lank weir lower on the right */
.place--woodland {
  --photo-max: 21rem;
}

.place--spate-weir {
  max-width: 17rem;
  margin-top: var(--space-3xl);
}

/* Reach 2: the intake large on the left bank; text and the Trebartha weir on the right */
.reach--intake .text {
  padding-top: var(--space-2xs);
}

.place--intake {
  margin-top: var(--space-2xl);
}

.place--intake img {
  object-position: 50% 60%;
}

.place--weir {
  --photo-max: 20rem;
  margin-top: var(--space-xl);
}

/* Reach 3: turbine hall above its text on the left bank; footbridge on the right */
.reach--turbine .bank--left {
  display: flex;
  flex-direction: column;
}

.reach--turbine .text {
  margin-top: var(--space-l);
}

.place--hall {
  --photo-max: 38rem;
  order: -1;
}

/* Reach 4: questions on the left bank, the river in spate on the right */
.reach--return .text {
  margin-top: var(--space-2xl);
}

.place--spate {
  max-width: 40rem;
}

/* Reach 5: the two last places either side of the river */
.sites-link {
  justify-self: end;
  text-align: right;
}

.sites-link h2 {
  margin-bottom: var(--space-m);
}

.contact-call {
  margin-top: var(--space-2xl);
}

.contact-call__title {
  max-width: 7.5em;
  margin-bottom: var(--space-m);
  font-size: var(--text-h2-large);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
}

/* ---------- Tablet: tamer meander ---------- */

@media (max-width: 68.6875rem) {
  .walk {
    --x0: 47.5%;
    --x1: 64%;
    --x2: 48%;
    --x3: 70%;
    --x4: 46%;
    --x5: 62%;
  }

  /* The photograph's column is narrower here: crop it square to keep its height */
  .source__photo {
    aspect-ratio: 1;
  }

  .place--woodland {
    --label-column-min: 0rem;
    --photo-max: 15rem;
  }

  /* The weir and the turbine hall take their labels below */
  .place--weir,
  .place--hall {
    grid-template-columns: minmax(0, 1fr);
  }

  .place--weir > *,
  .place--hall > * {
    grid-column: 1;
    grid-row: auto;
  }

  .place--weir > .label {
    justify-self: start;
    text-align: left;
  }
}

/* ---------- Narrow tablet and phone: the heading spans the walk ----------
   The source's lane moves to the left edge; the photograph bleeds right
   from it, with its label below, and the river rises beside it. */

@media (max-width: 51.875rem) {
  .walk {
    --x0: calc(var(--lane) / 2);
  }

  .source {
    /* Two lines: "Renewable energy" / "from our rivers" */
    --title-size: calc(var(--walk-now) * 0.13);
    grid-template-rows: [title-start] auto [moor-start] auto [moor-end];
    row-gap: var(--space-l);
    padding-bottom: var(--space-2xs);
  }

  .source__title {
    grid-row: title-start / moor-start;
  }

  .source__line,
  .source__line + .source__line {
    display: inline;
    max-width: none;
    white-space: normal;
  }

  .source__figure {
    row-gap: var(--space-2xs);
  }

  .source__photo {
    aspect-ratio: 3 / 2;
  }

  .source__label {
    grid-column: right;
    grid-row: 2;
    justify-self: start;
    text-align: left;
  }
}

/* ---------- Phone: the river runs down the left edge ---------- */

@media (max-width: 44.9375rem) {
  .source {
    /* Three lines: "Renewable" / "energy from" / "our rivers" (4.79em) */
    --title-size: clamp(2.75rem, var(--walk-now) * 0.2, 6rem);
    row-gap: var(--space-m);
  }

  /* The bend is only a short wave here: pass through it quickly */
  .river-draw .river-draw__bend {
    --draw-time: 0.1s;
  }

  .river-draw .river-draw__run {
    --draw-delay: 1.05s;
  }

  /* Tall on a phone; no taller than about two-thirds of a large phone's screen */
  .source__photo {
    max-height: 34rem;
    aspect-ratio: 4 / 5;
  }

  .place--woodland {
    width: 78%;
  }

  .place--spate-weir {
    width: 64%;
    margin-top: var(--space-l);
    margin-left: auto;
  }

  .place--intake {
    margin-top: var(--space-l);
  }

  .place--intake .label {
    justify-self: start;
    text-align: left;
  }

  .place--weir {
    width: 80%;
    margin-left: auto;
  }

  .place--hall > .label {
    justify-self: end;
    text-align: right;
  }

  .place--leat {
    width: 72%;
    margin-top: var(--space-l);
    margin-left: auto;
  }

  .reach--return .text {
    margin-top: 0;
  }

  .place--spate {
    margin-top: var(--space-l);
  }

  .sites-link {
    justify-self: start;
    text-align: left;
  }

  .contact-call {
    margin-top: var(--space-xl);
  }
}
