/* The goodnight button: a pill of sky on a white page, with a small drawn portrait in its round left end. The sky is a
   tall gradient from day to night that script.js slides up and down; the portrait, the sun, the moon, the stars and
   the drawn z letters are SVG, moved by GSAP. */
:root {
  --page: #ffffff;          /* the page */
  --day-top: #8cc6ec;       /* the sky by day, at the top of the pill */
  --day-low: #e4f2f4;       /* the sky by day, at its foot */
  --dusk: #ffcf9e;          /* the sunset, as it runs through */
  --dusk-deep: #b97aa3;     /* the dusk after it */
  --night-top: #252b62;     /* the sky by night, at the top */
  --night-low: #10142f;     /* the sky by night, at its foot */
  --word-day: #1a2a4b;      /* the words by day */
  --word-night: #f2ead6;    /* the words by night */
  --sun: #ffd76e;           /* the sun and its rays */
  --moon: #f6ecca;          /* the moon and the stars */
  --skin: #f1c7a3;          /* the face */
  --skin-shade: #dda482;    /* the neck and the line of the nose */
  --hair: #3a2924;          /* the hair, the brows and the eyes */
  --sweater: #e2774f;       /* the sweater */
  --cheek: #f19a86;         /* the cheeks */
  --ring: #ffffff;          /* the ring round the portrait */
  --focus: #1a2a4b;         /* the ring of the keyboard's focus */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--word-day);
  font-family: 'Mona Sans Variable', 'Mona Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 72px 16px;
}

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

/* ---------------------------------------------------------------- the pill */
.night__btn {
  position: relative;
  display: block;
  /* the script sets the width from the words; this is the width before it does */
  width: 186px;
  max-width: calc(100vw - 32px);
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--word, var(--word-day));
  font: inherit;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.night__btn[aria-disabled='true'] {
  cursor: progress;
}

/* the fill holds the sky, so it can swell past the pill with a bounce and take the sky with it */
.night__fill {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: 999px;
  overflow: hidden;
  box-shadow:
    0 1px 2px rgba(26, 42, 75, 0.16),
    0 14px 28px -14px rgba(26, 42, 75, 0.5);
  transition:
    inset 0.6s cubic-bezier(0.34, 1.9, 0.45, 1),
    box-shadow 0.4s ease;
}

/* the sky: four pills tall, day at the top and night at the foot; it slides up as the evening comes */
.night__sky {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 400%;
  background: linear-gradient(
    180deg,
    var(--day-top) 0%,
    var(--day-low) 24%,
    var(--dusk) 36%,
    var(--dusk-deep) 50%,
    var(--night-top) 72%,
    var(--night-top) 75%,
    var(--night-low) 100%
  );
}

/* the night all at once, for reduced motion: it fades in instead of the sky sliding */
.night__dark {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--night-top), var(--night-low));
  opacity: 0;
}

/* a thread of light along the top of the pill, over the sky */
.night__fill::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(10, 16, 40, 0.18);
}

.night__btn:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 5px;
}

html[data-using='pointer'] .night__btn:focus-visible {
  outline: none;
}

.night__clip {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  overflow: hidden;
  pointer-events: none;
}

/* the sun, the moon and the stars live in the right end of the pill */
.night__heavens {
  position: absolute;
  right: 10px;
  top: 0;
  width: 40px;
  height: 60px;
  overflow: visible;
}

.night__rays path {
  fill: none;
  stroke: var(--sun);
  stroke-width: 2;
  stroke-linecap: round;
}

.night__sun {
  fill: var(--sun);
}

.night__moon {
  fill: var(--moon);
}

.night__stars path {
  fill: var(--moon);
}

/* the drawn z letters that float up from the sleeper */
.night__zs {
  position: absolute;
  left: 43px;
  top: 0;
  width: 22px;
  height: 33px;
  overflow: visible;
}

.night__zs path {
  fill: none;
  stroke: var(--word-night);
  stroke-width: 1.05;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

/* ---------------------------------------------------------------- the portrait */
.night__portrait {
  position: absolute;
  left: 5px;
  top: 5px;
  width: 50px;
  height: 50px;
  pointer-events: none;
}

.night__portrait svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pt-back {
  fill: #ffffff;
  opacity: 0.22;
}

.pt-sweater {
  fill: var(--sweater);
}

.pt-collar {
  fill: none;
  stroke: rgba(0, 0, 0, 0.16);
  stroke-width: 1;
  stroke-linecap: round;
}

.pt-neck {
  fill: var(--skin-shade);
}

.pt-hair {
  fill: var(--hair);
}

.pt-skin,
.pt-lid {
  fill: var(--skin);
}

.pt-cheek {
  fill: var(--cheek);
  opacity: 0.45;
}

.pt-white {
  fill: #ffffff;
}

.pt-iris {
  fill: var(--hair);
}

.pt-glint {
  fill: #ffffff;
}

.pt-lash,
.pt-brow {
  fill: none;
  stroke: var(--hair);
  stroke-linecap: round;
}

.pt-lash {
  stroke-width: 0.85;
}

.pt-brow {
  stroke-width: 0.95;
}

.pt-nose {
  fill: none;
  stroke: var(--skin-shade);
  stroke-width: 0.8;
  stroke-linecap: round;
}

.pt-smile {
  fill: none;
  stroke: #9b4a3c;
  stroke-width: 0.95;
  stroke-linecap: round;
}

.pt-yawn {
  fill: #7a3a33;
}

/* the moonlight on the sleeper: the warm colours go blue */
.pt-moonlight {
  fill: var(--night-top);
  opacity: 0;
}

.pt-ring {
  fill: none;
  stroke: var(--ring);
  stroke-width: 1.6;
  opacity: 0.85;
}

/* ---------------------------------------------------------------- the words */
.night__label {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 68px;
  display: flex;
  align-items: center;
  white-space: nowrap;
  pointer-events: none;
}

/* the words widen on the typeface's width axis under the pointer; the wide copy, invisible and zero high, holds their
   room, so the pill never changes size */
.night__word {
  display: inline-grid;
  padding-bottom: 1px;
  font-size: 17px;
  font-weight: 620;
  font-stretch: 100%;
  letter-spacing: -0.008em;
  line-height: 1;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.9, 0.45, 1), font-weight 0.6s cubic-bezier(0.34, 1.9, 0.45, 1);
}

.night__word::before {
  content: attr(data-wide);
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-stretch: 116%;
  font-weight: 680;
}

/* ---------------------------------------------------------------- under the pointer */
@media (hover: hover) and (pointer: fine) {
  .night__btn:not([aria-disabled='true']):hover .night__fill {
    inset: -2px -7px;
    box-shadow:
      0 1px 2px rgba(26, 42, 75, 0.16),
      0 18px 32px -14px rgba(26, 42, 75, 0.56);
  }

  .night__btn:not([aria-disabled='true']):hover .night__word {
    font-stretch: 116%;
    font-weight: 680;
  }
}

/* the keys bring the focus: the words widen as under the pointer */
html[data-using='keys'] .night__btn:focus-visible .night__word {
  font-stretch: 116%;
  font-weight: 680;
}

/* ---------------------------------------------------------------- reduced motion: no swelling, no widening */
@media (prefers-reduced-motion: reduce) {
  .night__fill,
  .night__word {
    transition: box-shadow 0.3s ease, filter 0.3s ease;
  }

  html[data-using='keys'] .night__btn:focus-visible .night__word {
    font-stretch: 100%;
    font-weight: 620;
  }
}

@media (prefers-reduced-motion: reduce) and (hover: hover) and (pointer: fine) {
  .night__btn:not([aria-disabled='true']):hover .night__fill {
    inset: 0;
    filter: brightness(1.08);
  }

  .night__btn:not([aria-disabled='true']):hover .night__word {
    font-stretch: 100%;
    font-weight: 620;
  }
}
