/* ══════════════════════════════════════════════════════════════════════════
   NAME IT: the reader types what they want to build, and the water writes it.

     .write          the section: the sheet of water, and the words over it
     .write__water   the canvas the ridges are drawn on (scripts/studio/write.js)
     .write__copy    the kicker, the heading, the field and the control
     .write__field   where the reader types: one line, in the display face

   The section is `hidden` in the markup and shown by the script: without
   scripts there is nothing to type into that would do anything. In forced
   colours the canvas is taken out and the field and the control stand alone.
   ══════════════════════════════════════════════════════════════════════════ */

/* On the sections' own layer, after THE NEXT. The stage is the screen the
   reader sees: the water and the words over it. */
.write {
  position: relative;
  z-index: 5;
  background: var(--ink);
}
/* The top padding is never less than the header's band over content: where
   the stage is held (the run, below) it is one screen, centred, and whatever
   the padding does not keep clear the band stands on. Measured at 1280×620:
   "Your turn" was under the band and the heading touched its edge. */
.write__stage {
  position: relative;
  overflow: clip;
  padding: clamp(56px, 9vh, 110px) var(--pad-section);
  padding-top: max(clamp(56px, 9vh, 110px), var(--header-over) + 12px);
}

/* ── the run ─────────────────────────────────────────────────────────────
   Where the water pours into the walk (scripts/studio/stream.js sets
   `water-run` on the root once it can), the stage is held in the window for
   WATER_RUN screens while HOW IT WAS MADE comes up UNDER it: the words over
   the water go, the whole sheet empties into Omry as he walks at the
   reader, and only when he has arrived does his section say anything. So
   the two are never two sections passing each other; they are one screen
   becoming another.

   The section is that much taller, its stage pinned in it, and over the
   one after it (z-index); its ground stops where the next section begins
   under it, so there the reader sees that section through the stage. When
   the run is over the stage is empty and takes no press. */
@media screen and (scripting: enabled) and (forced-colors: none) and (prefers-reduced-motion: no-preference) {
  html.water-run .write {
    z-index: 6;
    height: calc(100svh + 230svh);
    background: linear-gradient(to bottom, var(--ink) calc(100% - 100svh), transparent calc(100% - 100svh));
  }
  html.water-run .write__stage {
    position: sticky;
    top: 0;
    height: 100svh;
    display: grid;
    align-content: center;
  }
  html.water-run .write__copy { opacity: calc(var(--write-in, 1) * (1 - var(--write-out, 0))); }
  html.water-run .write.is-gone { pointer-events: none; }
  html.water-run .write.is-gone .write__copy { visibility: hidden; }
  html.water-run .studio { margin-top: -100svh; }
  html.water-run .studio > .static-section__inner { opacity: var(--studio-in, 1); }
  /* While it runs, the portrait is held in the middle of the window, out of
     its section's box and over the water's stage: so its section is over
     this one, lets the stage show through, and clips nothing above itself.
     When the run is over it is a section again, under the empty stage. */
  html.water-run .studio.is-running { z-index: 7; background: transparent; overflow: visible; overflow-x: clip; }
}

.write__water {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The way in: THE NEXT's app comes apart and its points fall into this
   water (scripts/studio/next.js). They are drawn in flight on `.write__pour`,
   fixed over the window, and here, in the later of the two sections, so it
   is over both. The words come in as the points land (`--write-in`, 0..1,
   written by scripts/studio/write.js). Only where things move. */
.write__pour, .write__stream { display: none; }
@media screen and (scripting: enabled) and (forced-colors: none) and (prefers-reduced-motion: no-preference) {
  /* ...and `.write__stream` is the same for the way out: the water's points
     on their way into the walk (scripts/studio/stream.js). */
  .write__pour, .write__stream {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: 100%;
    max-width: none;
    pointer-events: none;
  }
  .write__copy { opacity: var(--write-in, 1); }
}

.write__copy {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
}

.write__kicker {
  margin: 0 0 18px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--signal-hot);
}

.write__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2.2rem, 5.2vw, 4rem);
  line-height: .92;
  letter-spacing: -.01em;
  text-transform: uppercase;
  color: var(--text-1);
  text-wrap: balance;
}

.write__label {
  display: block;
  margin: 26px 0 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-2);
}

.write__field {
  display: block;
  width: min(100%, 460px);
  margin: 0 auto;
  padding: 10px 4px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4.4vw, 2.5rem);
  line-height: 1.1;
  letter-spacing: .04em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text-1);
  caret-color: var(--cyan-3);
  transition: border-color var(--t-micro) var(--ease-ui);
}
.write__field::placeholder { color: var(--text-3); opacity: 1; }
.write__field:hover { border-bottom-color: var(--line-cyan); }
.write__field:focus-visible { outline: none; border-bottom-color: var(--cyan-3); }

/* The control stands under the water: the gap above it is the band the
   sheet lies in (the script reads it off the field and the control).

   The band is what gives when the window is short. Held, the stage is one
   screen, and the heading, the field and the control are about 430px of it
   with its padding; a band that never went under 250px made the whole taller
   than any window under 700, the stage is centred, and so the heading went up
   under the header and the control down under the fold, and stayed there for
   as long as the stage was held. The band takes what the window has left. */
.write__send { margin-top: clamp(64px, min(42svh, 100svh - 430px), 360px); }

/* A phone held sideways has under 400px, and the header's band is 64 of
   them. The kicker goes, the label is kept for a screen reader and for the
   field's name and taken off the screen (the placeholder says the same), and
   the type is fitted to the height. Measured at 844×390, 667×375 and
   568×320: the heading clear of the band, the control above the fold. */
@media (max-height: 500px) {
  .write__stage { padding-block: calc(var(--header-over) + 8px) 12px; }
  .write__kicker { display: none; }
  .write__title { font-size: clamp(1.5rem, 9svh, 4rem); }
  .write__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .write__field { margin-top: 8px; padding-block: 4px; font-size: clamp(1.4rem, 8svh, 2.5rem); }
  .write__send { margin-top: clamp(64px, 30svh, 250px); }
}

@media (forced-colors: active) {
  .write__water { display: none; }
  .write__send { margin-top: 28px; }
  .write__field { border-bottom-color: CanvasText; }
}

@media print {
  .write { display: none; }
}
