/* public/styles/night-banner.css */

/*
 * Fonts are served from this site: the CSP allows `font-src 'self'` only. The Dancing Script faces of the
 * title and the film headings stand in `brand-font.css`, which the app frame links on every page. Quicksand
 * carries latin and latin-ext, because the subtitle holds Polish letters.
 */
@font-face {
  font-family: 'Quicksand';
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url('/public/fonts/quicksand-700-latin-ext.woff2') format('woff2');
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Quicksand';
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url('/public/fonts/quicksand-700-latin.woff2') format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC,
    U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/*
 * One hundredth of the design frame: a 2:1 frame (3:4 when the box stands upright) fitted inside the
 * box. Every size is a multiple of it, so a box wider or flatter than the design never crops the
 * objects or crowds them together. Registered as a length so it resolves against the banner where it
 * is declared and reaches the text column, a container of its own, already in pixels.
 */
@property --u {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}

/*
 * At most half the window high, so the feed below shows on the first screen. How its foot meets the page is up
 * to the stylesheet of the look. The colours are the night tokens of `src/tailwind.css`.
 */
.night-banner {
  --night-banner-night: var(--color-night-navy);
  --night-banner-white: var(--color-night-white);
  --night-banner-yellow: var(--color-night-gold);
  /*
   * The one switch of the glow on the banner's title and subtitle, the only text on the site that glows:
   * 1 lights it, 0 puts it out. It scales the strength of their text shadows.
   */
  --night-banner-glow: 1;
  /* Ease-in-out sine: alternating between two values with it traces a sine wave. */
  --night-banner-sine: cubic-bezier(0.37, 0, 0.63, 1);

  position: relative;
  flex-shrink: 0;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 50svh;
  overflow: hidden;
  container-type: size;
  background: var(--night-banner-night);

  /* Object placement: positions in percent of the box, sizes in `--u`. The star rests on the left edge, so its flight clears the title. */
  --moon-x: 72%;
  --moon-y: 9%;
  --moon-w: 19;
  --star-x: 0%;
  --star-y: 22%;
  --star-w: 24;
  --text-y: 52%;
}
@media (min-width: 48rem) {
  .night-banner {
    aspect-ratio: 2 / 1;
  }
}
/*
 * `--frame-ratio` is the width over height of the design frame, and `--v` one hundredth of its height:
 * vertical motion follows the frame's height, as horizontal motion follows its width.
 */
.night-banner > * {
  --u: min(1cqw, 2cqh);
  --frame-ratio: 2;
  --v: calc(var(--u) / var(--frame-ratio));
}

.night-banner-background {
  position: absolute;
  inset: -3%;
  background: url('/public/media/banner/background.webp') center / cover no-repeat;
  will-change: translate, transform;
}

.night-banner-sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.night-banner-object {
  position: absolute;
  pointer-events: none;
  user-select: none;
}
.night-banner-object img {
  display: block;
  width: 100%;
  height: auto;
  will-change: translate, rotate;
}
.night-banner-moon {
  left: var(--moon-x);
  top: var(--moon-y);
  width: calc(var(--moon-w) * var(--u));
}
.night-banner-star {
  left: var(--star-x);
  top: var(--star-y);
  width: calc(var(--star-w) * var(--u));
}
/* The star flies right, so its tail trails on the left. */
.night-banner-star img {
  scale: -1 1;
}
.night-banner-glow {
  position: absolute;
  inset: -30%;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 214, 140, 0.3) 0%,
    rgba(255, 214, 140, 0.1) 38%,
    rgba(255, 214, 140, 0) 65%
  );
}

/* The column of the page under the banner; its width and side padding come from the page classes on it. */
.night-banner-column {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
/* The column inside its padding: what the text is placed in and what its size follows. */
.night-banner-column-content {
  position: relative;
  height: 100%;
  container-type: inline-size;
}
/*
 * As wide as its text and centred by auto margins. Anchoring both edges gives the text the whole column
 * to wrap in, which a `left: 50%` anchor would halve.
 */
.night-banner-text {
  position: absolute;
  top: var(--text-y);
  left: 0;
  right: 0;
  width: fit-content;
  margin-inline: auto;
  transform: translateY(-50%);
  isolation: isolate;
  text-align: center;
  color: var(--night-banner-white);
  pointer-events: auto;
}
/* Soft dark halo behind the text, so it reads over the stars. */
.night-banner-text::before {
  content: '';
  position: absolute;
  inset: -70% -45%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(8, 11, 46, 0.62), rgba(8, 11, 46, 0));
}

/* The design size, or smaller where the column is narrow: the divisor is the title's width per unit of font size, plus a little air. */
.night-banner-title {
  margin: 0;
  color: var(--night-banner-white);
  font-family: 'Dancing Script', cursive;
  font-weight: 700;
  font-size: min(calc(9.6 * var(--u)), calc(100cqi / 4.65));
  line-height: 0.95;
  letter-spacing: 0.005em;
  white-space: nowrap;
  text-shadow:
    0 0 calc(1.6 * var(--u)) rgba(255, 210, 140, calc(0.45 * var(--night-banner-glow))),
    0 calc(0.2 * var(--u)) calc(0.9 * var(--u)) rgba(6, 8, 36, calc(0.6 * var(--night-banner-glow)));
  /* Dancing Script has nothing heavier than 700, so a stroke in the letter colour, under the fill, thickens it. */
  -webkit-text-stroke: 0.03em currentColor;
  paint-order: stroke fill;
}
.night-banner-title-light {
  font-weight: 400;
  -webkit-text-stroke: 0;
}

/* Never under 12 px: the floor for text set in capitals. */
.night-banner-subtitle {
  margin: calc(1.3 * var(--u)) 0 0;
  /* Letter-spacing adds space after the last letter; pull it back so centring stays true. */
  margin-right: -0.26em;
  font-family: 'Quicksand', system-ui, sans-serif;
  font-weight: 700;
  font-size: max(0.75rem, calc(1.55 * var(--u)));
  line-height: normal;
  letter-spacing: 0.26em;
  text-wrap: balance;
  color: var(--night-banner-yellow);
  text-shadow:
    0 0 calc(0.9 * var(--u)) rgba(6, 8, 36, calc(0.9 * var(--night-banner-glow))),
    0 0 calc(0.3 * var(--u)) rgba(6, 8, 36, calc(0.7 * var(--night-banner-glow)));
}

/* Twinkles, each placed and timed by its inline custom properties. */
.night-banner-sparkle {
  position: absolute;
  width: calc(var(--sparkle-size) * var(--u));
  height: calc(var(--sparkle-size) * var(--u));
  pointer-events: none;
  opacity: 0.15;
  background:
    radial-gradient(circle, #fff 0 14%, rgba(255, 236, 190, 0.55) 26%, rgba(255, 236, 190, 0) 52%),
    linear-gradient(90deg, transparent 44%, rgba(255, 244, 214, 0.9) 50%, transparent 56%),
    linear-gradient(0deg, transparent 44%, rgba(255, 244, 214, 0.9) 50%, transparent 56%);
}
@keyframes night-banner-twinkle {
  0%,
  100% {
    opacity: 0.1;
    transform: scale(0.6);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}
.night-banner-shooting-star {
  position: absolute;
  width: calc(9 * var(--u));
  height: calc(0.14 * var(--u));
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, rgba(255, 240, 200, 0), rgba(255, 240, 200, 0.9) 85%, #fff);
  box-shadow: 0 0 calc(0.5 * var(--u)) rgba(255, 230, 170, 0.7);
}
/*
 * Three shooting stars in the upper sky, heading down-left, each on its own cycle of whole seconds that
 * share no factor. Each frame places them clear of the moon and the title; in the upright frame they cross
 * the strip above the flying star.
 */
.night-banner-shooting-star-a {
  left: 66%;
  top: 5%;
  --shoot-angle: 160deg;
  --shoot-length: calc(22 * var(--u));
}
.night-banner-shooting-star-b {
  left: 50%;
  top: 3%;
  --shoot-angle: 166deg;
  --shoot-length: calc(26 * var(--u));
}
.night-banner-shooting-star-c {
  left: 60%;
  top: 17%;
  --shoot-angle: 156deg;
  --shoot-length: calc(20 * var(--u));
}

@media (prefers-reduced-motion: reduce) {
  .night-banner-sky {
    display: none;
  }
}

/* All motion, left out where reduced motion is asked for: the banner then stands at rest. */
@media (prefers-reduced-motion: no-preference) {
  .night-banner-background {
    animation:
      night-banner-drift-x 20.5s var(--night-banner-sine) -10.25s infinite alternate,
      night-banner-drift-y 26.5s var(--night-banner-sine) -13.25s infinite alternate;
  }
  /* The bob moves the moon and its glow together; only the moon rocks. */
  .night-banner-moon {
    animation: night-banner-moon-bob 4s var(--night-banner-sine) -2s infinite alternate;
  }
  .night-banner-moon img {
    animation: night-banner-moon-rock 6.5s var(--night-banner-sine) -3.25s infinite alternate;
  }
  .night-banner-glow {
    animation: night-banner-glow-pulse 3s var(--night-banner-sine) -1.5s infinite alternate;
  }
  /*
   * The star glides on a slow wave into a breeze that holds it in place. Its pitch follows its climb against
   * that breeze: level at the crest and the trough, nose down halfway down, nose up halfway up.
   */
  .night-banner-star {
    animation: night-banner-star-sway 14.5s var(--night-banner-sine) -7.25s infinite alternate;
  }
  .night-banner-star img {
    animation:
      night-banner-star-rise-fall 6s var(--night-banner-sine) infinite alternate,
      night-banner-star-pitch 6s var(--night-banner-sine) -3s infinite alternate;
  }
  .night-banner-sparkle {
    animation: night-banner-twinkle var(--sparkle-duration) ease-in-out var(--sparkle-offset) infinite;
  }
  .night-banner-shooting-star-a {
    animation: night-banner-shooting-star-a 23s linear 3s infinite;
  }
  .night-banner-shooting-star-b {
    animation: night-banner-shooting-star-b 31s linear 8s infinite;
  }
  .night-banner-shooting-star-c {
    animation: night-banner-shooting-star-c 37s linear 14s infinite;
  }
}

/* The two drifts run on different clocks, so one takes `translate` and the other `transform`. */
@keyframes night-banner-drift-x {
  from {
    translate: -0.5% 0;
  }
  to {
    translate: 0.5% 0;
  }
}
@keyframes night-banner-drift-y {
  from {
    transform: translateY(-0.4%);
  }
  to {
    transform: translateY(0.4%);
  }
}
@keyframes night-banner-moon-bob {
  from {
    translate: 0 calc(-1.6 * var(--v));
  }
  to {
    translate: 0 calc(1.6 * var(--v));
  }
}
@keyframes night-banner-moon-rock {
  from {
    rotate: -3deg;
  }
  to {
    rotate: 3deg;
  }
}
@keyframes night-banner-glow-pulse {
  from {
    opacity: 0.4;
  }
  to {
    opacity: 1;
  }
}
@keyframes night-banner-star-rise-fall {
  from {
    translate: 0 calc(-5 * var(--v));
  }
  to {
    translate: 0 calc(5 * var(--v));
  }
}
@keyframes night-banner-star-pitch {
  from {
    rotate: -8deg;
  }
  to {
    rotate: 8deg;
  }
}
/* Centred a little left of the resting spot, so the star never reaches the title. */
@keyframes night-banner-star-sway {
  from {
    translate: calc(-3 * var(--u)) 0;
  }
  to {
    translate: calc(1 * var(--u)) 0;
  }
}

/* A flight takes the first stretch of the cycle: it fades in, then out as it reaches the end of its path. */
@keyframes night-banner-shooting-star-a {
  0% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(0);
    animation-timing-function: cubic-bezier(0.3, 0.1, 0.6, 1);
  }
  0.98% {
    opacity: 1;
  }
  6.52%,
  100% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(var(--shoot-length));
  }
}
@keyframes night-banner-shooting-star-b {
  0% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(0);
    animation-timing-function: cubic-bezier(0.3, 0.1, 0.6, 1);
  }
  0.82% {
    opacity: 1;
  }
  5.48%,
  100% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(var(--shoot-length));
  }
}
@keyframes night-banner-shooting-star-c {
  0% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(0);
    animation-timing-function: cubic-bezier(0.3, 0.1, 0.6, 1);
  }
  0.57% {
    opacity: 1;
  }
  3.78%,
  100% {
    opacity: 0;
    transform: rotate(var(--shoot-angle)) translateX(var(--shoot-length));
  }
}

/* Boxes taller than wide (phones): larger objects and text over the title, in a 3:4 frame. */
@container (orientation: portrait) {
  /* A container query cannot restyle the container itself, so the placement goes on its children. */
  .night-banner > * {
    --u: min(1cqw, 0.75cqh);
    --frame-ratio: 0.75;
    --moon-x: 52%;
    --moon-y: 4%;
    --moon-w: 44;
    --star-y: 15%;
    --star-w: 52;
    --text-y: 58%;
  }
  .night-banner-title {
    font-size: min(calc(18 * var(--u)), calc(100cqi / 4.65));
  }
  .night-banner-subtitle {
    font-size: max(0.75rem, calc(3.4 * var(--u)));
    letter-spacing: 0.2em;
    margin-right: -0.2em;
    margin-top: calc(3 * var(--u));
  }
  /* The moon fills the upper right, so the shooting stars cross the upper left. */
  .night-banner-shooting-star-a {
    left: 42%;
    top: 4%;
  }
  .night-banner-shooting-star-b {
    left: 32%;
    top: 2%;
  }
  /* A short path, so it ends before the flying star's reach. */
  .night-banner-shooting-star-c {
    left: 38%;
    top: 4%;
    --shoot-length: calc(12 * var(--u));
  }
}

/*
 * Lying boxes not much wider than tall (small phones, where half the window is less than its width):
 * the same arrangement as the wide banner, star on the left and moon on the right, but drawn larger and
 * with the text lower, in a frame of the box's own shape, so the sky above it is not left empty.
 */
@container (orientation: landscape) and (max-aspect-ratio: 8 / 5) {
  .night-banner > * {
    --u: min(1cqw, 1.125cqh);
    --frame-ratio: 1.125;
    --moon-x: 64%;
    --moon-y: 5%;
    --moon-w: 30;
    /* About the wide banner's star height, well above the lowered text. */
    --star-y: 21%;
    --star-w: 36;
    --text-y: 66%;
  }
  .night-banner-title {
    font-size: min(calc(13 * var(--u)), calc(100cqi / 4.65));
  }
  .night-banner-subtitle {
    font-size: max(0.75rem, calc(3.2 * var(--u)));
    letter-spacing: 0.2em;
    margin-right: -0.2em;
    margin-top: calc(2 * var(--u));
  }
  /* The larger moon reaches further left, so the shooting stars start left of it. */
  .night-banner-shooting-star-a {
    left: 52%;
    top: 5%;
  }
  .night-banner-shooting-star-b {
    left: 44%;
    top: 2%;
  }
  .night-banner-shooting-star-c {
    left: 52%;
    top: 16%;
  }
}

/*
 * Film headings in the feed under the banner: the banner's typeface, in the navy of its sky, with no glow; the
 * night look lights them up in its text colour. Script letters are small for their size, so the heading goes up
 * a step. `--text-h2` is always emitted: the heading carries the `text-h2` class.
 */
.night-banner-feed h2 {
  color: var(--color-night-title-navy);
  font-family: 'Dancing Script', cursive;
  font-weight: 700;
  font-size: calc(var(--text-h2) * 1.3);
}
