/*
  Summit Software Development — site styles.

  One screen: paper ground, a drawn ridge, and a sky that falls to night while the contact
  button is hovered. The design spec, including the drawing geometry and every timing value,
  is in docs/DESIGN.md. Keep this file and that document in step.
*/

@font-face {
  font-family: "Schibsted Grotesk";
  src: url("/fonts/schibsted-grotesk-latin.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
  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;
}

:root {
  /* Palette: cool paper and ink by day, a deep sky by night */
  --paper: #f4f6f7;
  --ink: #1b1f23;
  --muted: #5b646c;
  --night: #10151b;
  --night-ink: #eef1f3;
  --night-muted: #9aa6b1;

  /* Type */
  --font-sans:
    "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", "Roboto", "Helvetica Neue", "Arial",
    sans-serif;

  /* Layout: a generous gutter that also clears a phone's side bars */
  --gutter-left: max(16px, env(safe-area-inset-left, 0px), clamp(24px, 5vw, 72px));
  --gutter-right: max(16px, env(safe-area-inset-right, 0px), clamp(24px, 5vw, 72px));
  --gutter-y: clamp(24px, 4vh, 44px);

  /* Drawing: the box that holds the ridge, and how far it is cropped on narrow screens */
  --drawing-height: 64%;
  --crop-scale: 1;

  /* The star's point in ridge coordinates (the ridge spans 0 to 1440 by 120 to 840) */
  --star-x: 1118;
  --star-y: 92;

  /* Motion */
  --sweep-in: 1.6s;
  --sweep-out: 2.2s;
  --sweep-ease: cubic-bezier(0.45, 0.2, 0.2, 1);
  --draw-duration: 2.6s;
  --draw-ease: cubic-bezier(0.3, 0.6, 0.2, 1);
  --spread-duration: 1.8s;
  --spread-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  color-scheme: light;
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Stage ------------------------------------------------------------------ */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100vh;
  min-height: 100dvh;
  padding-block: var(--gutter-y);
  padding-left: var(--gutter-left);
  padding-right: var(--gutter-right);
  overflow: hidden;
}

.masthead,
.contact {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 32px;
}

.masthead__name {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.masthead__est,
.contact__line {
  margin: 0;
  color: var(--muted);
}

/* Drawing: geometry shared by the ridge and the sky fill ------------------ */

.drawing {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: var(--drawing-height);
  overflow: visible;
  transform: translateY(-50%) scaleX(var(--crop-scale));
  transform-origin: 100% 50%;
  pointer-events: none;
}

/* Ridge ------------------------------------------------------------------ */

.ridge {
  z-index: 0;
}

.ridge path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.25;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 2300;
  stroke-dashoffset: 2300;
  animation: ridge-draw var(--draw-duration) var(--draw-ease) both;
  transition: transform var(--spread-duration) var(--spread-ease);
}

.ridge__main {
  stroke-opacity: 0.92;
  animation-delay: 0.2s;
}

.ridge__echo--1 {
  stroke-opacity: 0.5;
  animation-delay: 0.38s;
}

.ridge__echo--2 {
  stroke-opacity: 0.32;
  animation-delay: 0.56s;
}

.ridge__echo--3 {
  stroke-opacity: 0.2;
  animation-delay: 0.74s;
}

.ridge__echo--4 {
  stroke-opacity: 0.12;
  animation-delay: 0.92s;
}

/* The echoes drift apart while the cursor is anywhere on the page (pointer devices only) */
@media (hover: hover) {
  .stage:hover .ridge__echo--1 {
    transform: translateY(7px);
  }

  .stage:hover .ridge__echo--2 {
    transform: translateY(14px);
  }

  .stage:hover .ridge__echo--3 {
    transform: translateY(21px);
  }

  .stage:hover .ridge__echo--4 {
    transform: translateY(28px);
  }
}

/* Sky -------------------------------------------------------------------- */

/*
  The sky layer is masked by a gradient three page-heights tall with a dark top third, a soft
  edge, and a transparent bottom third. Sliding the mask up brings night down from the top while
  the contact button is hovered or focused; releasing slides it back, so the day returns from the
  bottom up. Pure CSS: every interruption reverses smoothly from wherever it is, and nothing runs
  once the pointer has left.
*/
.sky {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 0% 36%, transparent 64% 100%);
  mask-image: linear-gradient(to bottom, #000 0% 36%, transparent 64% 100%);
  -webkit-mask-size: 100% 300%;
  mask-size: 100% 300%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: 0 100%;
  mask-position: 0 100%;
  transition:
    -webkit-mask-position var(--sweep-out) var(--sweep-ease),
    mask-position var(--sweep-out) var(--sweep-ease);
}

.sky__fill path {
  fill: var(--night);
}

.stage:has(.contact__button:focus-visible) .sky {
  -webkit-mask-position: 0 0;
  mask-position: 0 0;
  transition-duration: var(--sweep-in);
}

/* The masthead sits in the sky: light while the night is over it. It changes a beat after the
   sky arrives, and only once the sky has nearly gone on the way back. */
.masthead__name,
.masthead__est {
  transition: color 0.8s ease 1.3s;
}

.stage:has(.contact__button:focus-visible) .masthead__name {
  color: var(--night-ink);
  transition: color 0.9s ease 0.15s;
}

.stage:has(.contact__button:focus-visible) .masthead__est {
  color: var(--night-muted);
  transition: color 0.9s ease 0.15s;
}

@media (hover: hover) {
  .stage:has(.contact__button:hover) .sky {
    -webkit-mask-position: 0 0;
    mask-position: 0 0;
    transition-duration: var(--sweep-in);
  }

  .stage:has(.contact__button:hover) .masthead__name {
    color: var(--night-ink);
    transition: color 0.9s ease 0.15s;
  }

  .stage:has(.contact__button:hover) .masthead__est {
    color: var(--night-muted);
    transition: color 0.9s ease 0.15s;
  }
}

/* Star: fixed above the summit, revealed by the same sweep as the sky ------ */

.star {
  position: absolute;

  /* The drawing box is centred at 50% and --drawing-height tall; the star sits (120 - y) / 720 above its top */
  top: calc(50% - var(--drawing-height) * (0.5 + (120 - var(--star-y)) / 720));

  /* The box is scaled about its right edge, so measure from the right */
  left: calc(100% - ((1440 - var(--star-x)) / 1440) * 100% * var(--crop-scale));
  width: 44px;
  height: 44px;
  overflow: visible;
  transform: translate(-50%, -50%);
  opacity: 0;

  /* Out: dims across most of the sky's retreat, slow to start, gone just before the top clears */
  transition: opacity calc(var(--sweep-out) * 0.75) cubic-bezier(0.55, 0, 0.7, 0.2);
}

/* In: appears as the sky reaches it */
.stage:has(.contact__button:focus-visible) .star {
  opacity: 1;
  transition: opacity 0.6s ease 0.3s;
}

@media (hover: hover) {
  .stage:has(.contact__button:hover) .star {
    opacity: 1;
    transition: opacity 0.6s ease 0.3s;
  }
}

.star__core {
  fill: var(--night-ink);
}

.star__ray {
  stroke: var(--night-ink);
  stroke-width: 1;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.star__ray--long {
  stroke-opacity: 0.9;
  animation: twinkle-long 3.8s ease-in-out infinite alternate;
}

.star__ray--short {
  stroke-opacity: 0.55;
  animation: twinkle-short 4.7s ease-in-out infinite alternate-reverse;
}

/* Contact ---------------------------------------------------------------- */

.contact__button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 22px;
  border: 1px solid var(--ink);
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  transition:
    background-color 0.45s ease,
    color 0.45s ease;
}

.contact__button:hover,
.contact__button:focus-visible {
  color: var(--paper);
  background-color: var(--ink);
}

.contact__button:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

/* Keyframes -------------------------------------------------------------- */

@keyframes ridge-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes twinkle-long {
  from {
    stroke-opacity: 0.45;
  }

  to {
    stroke-opacity: 1;
  }
}

@keyframes twinkle-short {
  from {
    stroke-opacity: 0.25;
  }

  to {
    stroke-opacity: 0.7;
  }
}

/* Narrow screens: crop the drawing to the summit instead of squeezing it --- */

@media (width <= 900px) {
  :root {
    --drawing-height: 52%;
    --crop-scale: 1.3;
  }
}

@media (width <= 640px) {
  :root {
    --drawing-height: 40%;
    --crop-scale: 1.735;
  }

  .masthead__name {
    font-size: 18px;
  }

  .masthead,
  .contact {
    gap: 14px 32px;
  }
}

/* Reduced motion: everything in its resting state, sky as a plain crossfade - */

@media (prefers-reduced-motion: reduce) {
  .ridge path {
    animation: none;
    stroke-dashoffset: 0;
    transition: none;
  }

  .star__ray--long,
  .star__ray--short {
    animation: none;
  }

  .sky {
    -webkit-mask: none;
    mask: none;
    opacity: 0;
    transition: opacity 0.6s ease;
  }

  .stage:has(.contact__button:focus-visible) .sky {
    opacity: 1;
  }

  .contact__button,
  .masthead__name,
  .masthead__est,
  .star {
    transition-duration: 0.3s;
    transition-delay: 0s;
  }

  @media (hover: hover) {
    .stage:has(.contact__button:hover) .sky {
      opacity: 1;
    }
  }
}
