/* ============================================================
 * MuirWave home: one viewport of dark water
 * ------------------------------------------------------------
 * The page is a section through the sea. A sliver of sky runs
 * along the top of the window, the sea's surface under it, and
 * the row above the footer is the seabed. Light comes down from
 * the surface, sound paths hang in a bowl under the wordmark,
 * and now and then something swims by. The surface and its
 * weather are the sea every MuirWave page shares
 * (sea/muirwave-sea.js and .css), and the weather sets the light.
 *
 * Tokens are MuirWave's own (Muirwave/website/css/muirwave.css,
 * which mirrors the app's DesignSystem.swift): same names, same
 * hex. Only the ones this page uses are here.
 *
 * Layers, back to front (all inside .water, all decorative):
 *   .water            flat dark water
 *   .water__light     the surface's wash of light, and the pool under the sun or moon
 *   .water__shafts    two still frames of the light shafts
 *   #light            the live shafts (WebGL), over the stills
 *   .water__sound     the still sound paths (paths.svg)
 *   #paths            the live sound paths (canvas)
 *   #snow             marine snow, animals and tap pings (canvas)
 *   #sea (.mw-sea)    the sea surface and its weather: a canvas, and without scripts a still (sea/surface.svg)
 *   .water__grain     film grain
 * The waterline is the one edge between sky and water. The sky
 * is opaque down to it and no further; the light in the water
 * (wash, pool, shafts) runs under the sky to the top of the
 * window, so it reaches the line wherever the line is.
 *
 * What shows when:
 *   no script             the stills (the shafts breathe if motion is allowed)
 *   html.js               scripts are running: the sea's canvas replaces its still
 *   reduced motion        html.js alone: one frame of the weather and of the snow, the still shafts and paths
 *   html.moving           the live paths replace paths.svg
 *   html.moving.lit       the live shafts replace the still ones
 * ============================================================ */

@font-face {
  /* The display serif, for devices without New York: the wordmark, the doors,
     and the name carried to School (which has the same file). Source Serif 4
     (SIL Open Font License), weight 600, from Google Fonts' Latin file, cut
     down to the 52 letters A to Z and a to z. */
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 600;
  font-display: block;
  src: url("fonts/source-serif-4-600-letters.woff2") format("woff2");
}

:root {
  --abyss: #050A12;
  --water: #050810;
  --brass: #B08D57;
  --brass-hi: #D0A850;
  --squall: #4FD1E0;
  --ice: #E6F0F4;
  --foam: #C6E1EA;
  --fog: #7A8B97;

  --font-display: ui-serif, "New York", "Source Serif 4", Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* The depth of the sky (--sea-line, the row of the resting sea surface) and
     the light the weather sends down (--sea-wash-*, --sea-pool-*, --sea-bloom-x,
     --sea-shafts) come from sea/muirwave-sea.css, and the sea keeps them current. */

  /* The footer row. The seabed (the bottom of the sound box) sits on top of it. */
  --foot: calc(44px + env(safe-area-inset-bottom, 0px));

  /* One easing for everything that arrives: fast out of the dark, slow to rest. */
  --settle: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--water);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  cursor: url("cursors/cursor-default.svg") 2 2, url("cursors/cursor-default.png") 2 2, default;
}

body {
  display: grid;
  grid-template-rows: minmax(0, 1fr) var(--foot);
  height: 100vh;
  height: 100dvh;
  color: var(--foam);
  font-family: var(--font-ui);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: rgba(79, 209, 224, 0.25); color: var(--ice); }
:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 3px; border-radius: 2px; }

/* ---------- the water ---------- */

.water {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background: var(--water);
}

.water__light,
.water__shafts,
.water__layer,
.water__grain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Brightest at the surface, gone four fifths of the way down; and a pool of
   light in the water under the sun or the moon, when there is one. */
.water__light {
  background:
    radial-gradient(ellipse 44% 58% at var(--sea-bloom-x) var(--sea-line),
      rgb(var(--sea-pool-rgb) / var(--sea-pool-a)) 0%,
      rgb(var(--sea-pool-rgb) / calc(var(--sea-pool-a) * 0.42)) 34%,
      rgb(var(--sea-pool-rgb) / 0) 100%),
    linear-gradient(180deg,
      rgb(var(--sea-wash-rgb) / var(--sea-wash-a)) 0%,
      rgb(var(--sea-wash-rgb) / calc(var(--sea-wash-a) * 0.26)) 45%,
      rgb(var(--sea-wash-rgb) / 0) 80%);
}

/* The waterline moves, so nothing that lights the water may start at a fixed
   row: the wash, the pool and the shafts all run to the top of the window,
   and the sky (which is opaque, and ends exactly at the waterline) covers
   what is above the water. Under a crest the water is lit right up to the
   line. Only the snow, the animals and the pings start at the resting
   surface: they are things in the water, and must not rise into a crest's
   place when it has gone. */
#snow {
  top: var(--home-line, var(--sea-line));
  height: calc(100% - var(--home-line, var(--sea-line)));
}

.water__shafts,
#light {
  mix-blend-mode: screen;
  opacity: var(--sea-shafts);
}
.water__shafts img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 0;
}
/* The second frame is only for water that moves without WebGL. */
.water__shafts img + img { display: none; }

#light { opacity: 0; }
#snow { mix-blend-mode: screen; }

/* The sound box: its width is the stretch of range rays.js traces (FROM to
   TO), its height the water from surface to seabed. On a wide window it is
   the window. On a narrower one it stays 1.5 times as wide as the window is
   tall, so the bowl keeps its shape and the edges crop it, and on a phone
   held upright it stops at 2.75 window widths, which leaves the bottom of
   the bowl under the wordmark. home.js reads this box and draws to it.
   It and the snow hang from this page's own waterline (--home-line, which
   home.js keeps), so they stay put while the sea goes to a door's shape. */
.water__sound {
  position: absolute;
  top: var(--home-line, var(--sea-line));
  bottom: var(--foot);
  left: 50%;
  width: clamp(100vw, 150vh, 275vw);
  width: clamp(100vw, 150dvh, 275vw);
  transform: translateX(-50%);
}
.water__sound img {
  display: block;
  width: 100%;
  height: 100%;
}

/* The sea surface (sea/muirwave-sea.css places it). With scripts on, its still
   steps aside before the first paint, and the canvas comes up with the brand. */
.js .mw-sea::before,
.js .mw-sea::after { display: none; }

.water__grain {
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.7'/></svg>");
}

/* Live water: the stills step aside. */
.moving .water__sound img { display: none; }
.moving .water__shafts,
.moving #light { transition: opacity 1.6s ease; }
.moving.lit .water__shafts { opacity: 0; }
.moving.lit #light { opacity: var(--sea-shafts); }

/* ---------- the brand ---------- */

.brand {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: clamp(8px, 1.8vh, 18px);
  min-height: 0;
  /* a little above the middle, with the doors under it: the bowl of sound hangs below */
  padding: 16px 20px clamp(12px, 3vh, 32px);
  text-align: center;
}

.brand__mark {
  display: block;
  width: clamp(92px, min(27vw, 14vh + 44px), 232px);
  height: auto;
  aspect-ratio: 1;
  /* the artwork keeps a fifth of its square empty above the M */
  margin-top: -3%;
  -webkit-user-select: none;
  user-select: none;
}

.brand__words { display: grid; justify-items: center; }

.brand__name {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(34px, min(9.4vw, 5vh + 17px), 84px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0;
  color: var(--brass-hi);
}

.brand__line {
  margin: clamp(12px, 2.2vh, 22px) 0 0;
  /* the tracking's trailing gap, taken back so the line centres on its letters */
  padding-left: 0.36em;
  font-size: clamp(10px, 0.55vh + 6px, 15px);
  font-weight: 500;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--fog);
}

/* A phone on its side: the mark beside the words, as on the share card. */
@media (max-height: 440px) and (min-aspect-ratio: 3/2) {
  .brand {
    /* the mark and the words side by side, and the doors across both under them */
    grid-template-columns: auto auto;
    justify-content: center;
    align-items: center;
    gap: 0 16px;
    /* higher than the middle, where the bowl's sides are still far apart, but clear of the surface */
    padding-top: calc(var(--home-line, var(--sea-line)) + 4px);
    padding-bottom: clamp(8px, 8vh, 48px);
    text-align: left;
  }
  .brand__mark { width: clamp(72px, 26vh, 100px); margin-top: -8%; }
  .brand__words { justify-items: start; }
  .brand__name { font-size: clamp(28px, 10vh, 40px); }
  .brand__line { margin-top: 8px; padding-left: 0.1em; }
}

/* ---------- the doors ----------
   Two words under the brand, each the way in to another site's sign-in
   page: School (school.muirwave.com) and the Web Console (web.muirwave.com).
   In the wordmark's own serif, in the page's pale blue-grey a step back
   from full strength, so the wordmark stays the loudest thing on the page.
   No panels, borders, buttons or glass, as everywhere on this page. */

.doors {
  display: grid;
  justify-items: center;
  gap: clamp(2px, 0.6vh, 8px);
  margin-top: clamp(18px, 4.2vh, 44px);
}

/* "Sign in", in the voice of the line above it, between two hairlines that fade outward. */
.doors__label {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0;
  font-size: clamp(10px, 0.55vh + 6px, 15px);   /* the line's own size (.brand__line) */
  font-weight: 500;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--fog);
}
/* the tracking's trailing gap, taken back so the words centre on their letters */
.doors__label span { margin-right: -0.36em; }
.doors__label::before,
.doors__label::after {
  content: "";
  width: clamp(24px, 8vw, 44px);
  height: 1px;
  background: linear-gradient(90deg, rgb(198 225 234 / 0), rgb(198 225 234 / 0.2));
}
.doors__label::after { transform: scaleX(-1); }

/* The pair is centred as one line of type, so its two ends are as far from the page's axis as each other.
   (The hairline between the words is then a little off the axis, as the words differ in length. Putting the
   hairline on the axis instead leaves the longer word hanging out to one side.) */
.doors__list {
  display: flex;
  align-items: center;
  justify-content: center;
}
.doors__rule {
  flex: none;
  width: 1px;
  height: 18px;
  background: rgb(198 225 234 / 0.24);
}

.doorway {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 4px clamp(10px, 3.4vw, 28px);
  color: rgb(198 225 234 / 0.82);   /* --foam, a step back */
  text-decoration: none;
  cursor: url("cursors/cursor-crosshair-simple.svg") 12 12, url("cursors/cursor-crosshair-simple.png") 12 12, pointer;
  transition: color 0.2s ease;
}
.doorway__name {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(18px, min(4.9vw, 1.6vh + 9px), 28px);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.004em;
  white-space: nowrap;
}
/* a waterline under the word, drawn out from its middle, and drawn back in */
.doorway__name::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 1px;
  background: currentColor;
  opacity: 0;
  transform: scaleX(0.2);
  transition: transform 0.36s var(--settle), opacity 0.2s ease;
}

/* A pointer on a door lifts it to white and draws the waterline. With scripts, home.js sets .is-pointed from
   the pointer's own events, so the lift comes and goes with the pointer and is never left behind (a page
   brought back by the Back button keeps a stale :hover until the pointer moves). Without them, :hover. */
.doorway.is-pointed,
.doorway.is-chosen,
.doorway:active { color: var(--ice); }
.doorway.is-pointed .doorway__name::after,
.doorway.is-chosen .doorway__name::after { opacity: 0.5; transform: none; }
@media (hover: hover) {
  :root:not(.doors-live) .doorway:hover { color: var(--ice); }
  :root:not(.doors-live) .doorway:hover .doorway__name::after { opacity: 0.5; transform: none; }
}

/* The keyboard's focus is the page's own brass ring (:focus-visible, above), and nothing more. */
.doorway:focus-visible { outline-offset: -5px; border-radius: 4px; }

/* The press answers at once: one ring from the word, as the water answers a tap. */
.doorway::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  border: 1px solid rgb(198 225 234 / 0.6);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.doorway.is-chosen::before { animation: door-ring 520ms cubic-bezier(0.2, 0.6, 0.3, 1) both; }
@keyframes door-ring {
  from { opacity: 0.9; transform: scale(0.1); }
  to   { opacity: 0; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .doorway,
  .doorway__name::after { transition: none; }
  .doorway.is-chosen::before { animation: none; }
}

/* A phone on its side: the doors go under the mark and the words, across both, without "Sign in". */
@media (max-height: 440px) and (min-aspect-ratio: 3/2) {
  .doors { grid-column: 1 / -1; margin-top: 2px; }
  .doors__label { display: none; }
  .doorway { min-height: 44px; }
}

/* ---------- the footer ---------- */

.foot {
  position: relative;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 0 16px;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--fog);
}
.foot p {
  display: flex;
  align-items: center;
  height: 44px;
  margin: 0;
  white-space: nowrap;
}
.foot span { padding: 0 10px; }
.foot .foot__dot { padding: 0; opacity: 0.55; }
.foot a {
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 10px;
  color: inherit;
  text-decoration: none;
  cursor: url("cursors/cursor-crosshair-simple.svg") 12 12, url("cursors/cursor-crosshair-simple.png") 12 12, pointer;
  transition: color 0.2s ease;
}
.foot a:hover,
.foot a:focus-visible { color: var(--foam); }
.foot a:focus-visible { outline-offset: -9px; border-radius: 4px; }

/* ---------- arriving ---------- */

/* One entrance, played once: the brand comes up out of the dark in order,
   mark, name, line, footer. Everything is visible by default; these only
   describe where each piece comes from. The doors come up after the line. */
@media (prefers-reduced-motion: no-preference) {
  .brand__mark { animation: surface 1.8s var(--settle) 0.1s backwards; }
  .brand__name { animation: surface 1.6s var(--settle) 0.32s backwards; }
  .brand__line { animation: settle 2.2s var(--settle) 0.7s backwards; }
  .doors { animation: appear 1.6s ease 1.05s backwards; }
  .foot { animation: appear 1.6s ease 1.3s backwards; }
  /* the sky comes up with the brand */
  .mw-sea--live > canvas { animation: appear 1.4s ease backwards; }

  /* Without WebGL the light still moves: the two still frames trade places. */
  .water__shafts img + img { display: block; animation: breathe 13s ease-in-out infinite alternate; }
  .moving.lit .water__shafts img + img { animation: none; }

  @keyframes surface {
    from { opacity: 0; transform: translateY(10px); filter: blur(6px); }
  }
  @keyframes settle {
    from { opacity: 0; letter-spacing: 0.56em; }
  }
  @keyframes appear {
    from { opacity: 0; }
  }
  @keyframes breathe {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

/* ---------- leaving by a door, and coming back ----------
   Choosing a door, the camera comes up to it. Everything that is only this
   page's sinks away and is gone in a fifth of a second; what the door's page
   also has stays, and goes to where that page keeps it (home.js, leave()).
   The timings are home.js's (MOVE, LEAVE, ARRIVE).

   On <html>, set by home.js:
     data-to      the door chosen, from the press until the page is back at rest
     data-lit     the same, until the way back starts: the light in the water is the door's
     data-away    the same, once everything has left: the frame the page holds while the browser
                  fetches the door's page, and the frame the Back button brings back
     is-settled   the entrance has played (or was cut short by a press), and is not played again */

:root.is-settled .brand__mark,
:root.is-settled .brand__name,
:root.is-settled .brand__line,
:root.is-settled .doors,
:root.is-settled .foot,
:root.is-settled .mw-sea--live > canvas { animation: none; }

:root[data-away] .brand__line,
:root[data-away] .doors,
:root[data-away] .foot,
:root[data-away] .brand__mark,
:root[data-away] .brand__name,
:root[data-to="school"] .brand__mark,
:root[data-to="school"] .brand__name { visibility: hidden; }

/* a sound pulse in the water goes out with the page */
#paths,
.water__sound { transition: opacity 200ms ease; }
:root[data-to] #paths,
:root[data-to] .water__sound { opacity: 0; }

/* The light in the water turns to School's wash (School's school.css, .stage::before) as the sea goes to School's. */
.water__light { transition: opacity 420ms ease; }
.water__light--school {
  opacity: 0;
  background:
    radial-gradient(ellipse 60% 46% at var(--sea-bloom-x) 0%,
      rgb(var(--sea-pool-rgb) / var(--sea-pool-a)) 0%,
      rgb(var(--sea-pool-rgb) / 0) 100%),
    linear-gradient(180deg,
      rgb(var(--sea-wash-rgb) / calc(var(--sea-wash-a) * 1.1)) 0%,
      rgb(var(--sea-wash-rgb) / calc(var(--sea-wash-a) * 0.3)) 45%,
      rgb(var(--sea-wash-rgb) / 0) 82%);
}
:root[data-lit="school"] .water__light { opacity: 0; }
:root[data-lit="school"] .water__light--school { opacity: 1; }

/* The light shafts are each page's own (they are not drawn from the clock), so they can't be carried across.
   They dim as the page leaves, and the door's page brings its own up. */
:root[data-lit] .water__shafts,
:root[data-lit] #light { opacity: 0; transition: opacity 320ms ease; }
:root.is-settled:not([data-lit]) .water__shafts,
:root.is-settled:not([data-lit]) #light { transition: opacity 700ms ease; }

/* ---------- carried through School's door ----------
   School's mark and name, laid out exactly as School's sign-in page lays them
   out (its school.css and login.css: .surface__mark, .login .surface,
   .door__column, .login .wordmark). The numbers here are School's, and
   test/doors.test.mjs fails if School's drift from them. This page's own
   mark and name are handed to these as the move starts, and these are
   where the move ends. */
.carry {
  --to-mark: 80px;
  --to-pad: 64px;
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
}
@media (max-width: 480px), (max-height: 700px) {
  .carry { --to-mark: 64px; --to-pad: 48px; }
}
:root[data-to="school"] .carry { visibility: visible; }

/* the mark's box on School's page: its own waterline, 46.8% down it, on the sea's. It rides the surface as
   School's does (home.js, rideMark()). */
.carry__ride {
  position: absolute;
  left: calc(50% - var(--to-mark) / 2);
  top: calc(var(--to-line, 0px) - var(--to-mark) * 0.468);
  width: var(--to-mark);
  height: var(--to-mark);
}
:root[data-to="school"] .carry__ride { will-change: transform; }
/* drawn at this page's size and scaled down to School's, so it is sharp from the first frame */
.carry__mark {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--from-mark, var(--to-mark));
  height: var(--from-mark, var(--to-mark));
  max-width: none;
  transform-origin: 0 0;
  transform: scale(var(--to-scale, 1));
  -webkit-user-select: none;
  user-select: none;
}
.carry__name {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--to-line, 0px) + var(--to-pad));
  width: fit-content;
  margin: 0 auto;
  font-family: var(--font-display);
  font-size: clamp(38px, 5vw + 18px, 50px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.012em;
  white-space: nowrap;
  color: var(--brass-hi);
  text-shadow: 0 2px 24px var(--abyss);
  transform-origin: 0 0;
}
/* the same markup as School's name (Muir<span>School</span>), so the letters fall where School's do; "Wave"
   lies over the start of "School" for the first moments of the move (home.js places it) */
.carry__school { color: var(--ice); }
.carry__wave { position: absolute; left: 0; top: 0; opacity: 0; }
