/* ============================================================
 * MuirWave: the sea surface (muirwave-sea.js)
 * ------------------------------------------------------------
 * One sea, shared by every MuirWave page that shows it. This is
 * the master copy (MuirwaveHome, site/home/sea/); other sites
 * carry it unchanged, with muirwave-sea.js and surface.svg.
 *
 * A page puts <div class="mw-sea"></div> where the sea goes: its
 * top edge at the top of the sea's window, as wide as the sea is
 * to be. The script gives it a canvas, and sets on it and on
 * <html> the properties below. Without the script the element
 * shows one still frame of the surface: a tile thirty skies wide
 * that repeats, opaque above its waterline (it is sky) and clear
 * below it, as the canvas is.
 * ============================================================ */

:root {
  /* Where the sea sits. The script sets the same numbers in whole pixels.
       --sea-sky    the depth of the sky's picture, which sets the size of everything in it
       --sea-line   the row of the resting surface, from the top of .mw-sea
       --sea-below  how much water .mw-sea keeps under that row */
  --sea-sky: clamp(36px, 7.4vh, 84px);
  --sea-line: var(--sea-sky);
  --sea-below: calc(var(--sea-sky) * 2);

  /* The light the weather sends down, for the page's own water to use. These
     are `breeze`, the weather of the still surface; the script keeps them at
     the weather being drawn. */
  --sea-wash-rgb: 30 48 70;
  --sea-wash-a: 0.38;
  --sea-pool-rgb: 181 170 127;
  --sea-pool-a: 0;
  --sea-bloom-x: 50%;
  --sea-shafts: 0.85;
  --sea-top-rgb: 16 28 44;
}

.mw-sea {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(var(--sea-line) + var(--sea-below));
  overflow: hidden;
  pointer-events: none;
}
.mw-sea > canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  visibility: hidden;
}
.mw-sea--live > canvas { visibility: visible; }

/* The still: the surface's picture, and flat sky above it where the waterline
   sits lower than the picture is deep. */
.mw-sea::before,
.mw-sea::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
}
.mw-sea::before {
  top: calc(var(--sea-line) - var(--sea-sky));
  height: calc(var(--sea-sky) * 2);
  background: url("surface.svg") 50% 0 / calc(var(--sea-sky) * 30) 100% repeat-x;
}
.mw-sea::after {
  top: 0;
  height: max(0px, calc(var(--sea-line) - var(--sea-sky)));
  background: rgb(var(--sea-top-rgb));
}
.mw-sea--live::before,
.mw-sea--live::after { display: none; }

/* A thin strip (a tool's top bar) lets its water fade out along its bottom
   edge: add this class and set --sea-fade to the depth of the fade. */
.mw-sea--fade > canvas {
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - var(--sea-fade, 12px)), transparent);
  mask-image: linear-gradient(180deg, #000 calc(100% - var(--sea-fade, 12px)), transparent);
}
