/* The loading screen and the page transitions (see the "loader" in
   layouts/base.njk and assets/js/loader.js).

   First page of a visit: black screen, white logo, a small count to 100, then
   the screen lifts away like a curtain to show the page.
   Moving between pages: the same black and grey curtain rises over the old
   page, and lifts away again on the new one (no logo). */

@font-face {
  font-family: "DMTO Pixel";
  src: url("../fonts/DMTOPixel.woff2") format("woff2"),
       url("../fonts/DMTOPixel.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

/* Hidden unless the little script in the page head decided to play it. */
.loader {
  display: none;
}

html.is-loading {
  overflow: hidden; /* no scrolling while the screen is up */
}

html.is-loading .loader,
html.is-covering .loader {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

html.is-loading .loader {
  cursor: progress;
}

.loader.is-leaving {
  pointer-events: none;
}

/* Two layers, so the curtain lifts in two steps: the black one first, then a
   dark grey one right behind it. Change --loader-lift for a faster or slower
   lift, and the two colours below to restyle them. */
.loader {
  --loader-lift: 1.3s;   /* the curtain lifting off the page (first visit) */
  --loader-cover: 0.4s;  /* the curtain rising over the page, when you click a link */
  --loader-lift-fast: 0.5s; /* the curtain lifting on the next page */
  --loader-ease: cubic-bezier(0.77, 0, 0.18, 1);
}

.loader__layer {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 0 0 round 0);
  transition: clip-path var(--loader-lift) var(--loader-ease);
}

.loader__layer--back {
  background: #6e5980; /* the second colour */
}

.loader__layer--front {
  background: #000;
}

/* Moving to another page: the curtain starts hidden below the screen... */
html.is-covering .loader:not(.is-in) .loader__layer {
  clip-path: inset(100% 0 0 0 round 0); /* square corners */
  transition: none;
}

/* ...and rises over the page, grey layer first, then black. */
html.is-covering .loader.is-in .loader__layer {
  clip-path: inset(0 0 0 0 round 0);
  transition: clip-path var(--loader-cover) var(--loader-ease);
}

html.is-covering .loader.is-in .loader__layer--front {
  transition-delay: 0.07s;
}

/* The logo and the counter belong to the first-visit screen only. */
html.is-covering .loader__center,
html.is-transition .loader__center {
  display: none;
}

/* Lifting: the bottom edge rises to the top and curves as it goes. */
.loader.is-leaving .loader__layer {
  clip-path: inset(0 0 100% 0 round 0 0 50vw 50vw);
}

.loader.is-leaving .loader__layer--back {
  transition-delay: 0.14s;
}

/* On the next page after a click: a quicker lift, with square corners. */
html.is-transition .loader.is-leaving .loader__layer {
  clip-path: inset(0 0 100% 0 round 0);
  transition-duration: var(--loader-lift-fast);
}

html.is-transition .loader.is-leaving .loader__layer--back {
  transition-delay: 0.07s;
}

/* The logo, wiped in from the bottom up, with a small counter under it. */
.loader__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  transition: transform 0.7s var(--loader-ease), opacity 0.5s ease;
}

.loader.is-leaving .loader__center {
  transform: translateY(-3rem);
  opacity: 0;
}

.loader__logo {
  display: block;
  height: clamp(2.75rem, 7vw, 5rem);
  width: auto;
  max-width: 80vw;
  filter: brightness(0) invert(1); /* any logo colour becomes white */
  clip-path: inset(100% 0 0 0); /* hidden; wiped in from the bottom up */
  animation: loader-wipe 1s cubic-bezier(0.65, 0, 0.35, 1) 0.2s forwards;
}

.loader__logo--text {
  font-family: var(--font-display, "Poppins", sans-serif);
  font-weight: 700;
  font-size: clamp(1.75rem, 5vw, 3.25rem);
  line-height: 1;
  color: #fff;
  filter: none;
  white-space: nowrap;
}

@keyframes loader-wipe {
  to {
    clip-path: inset(0 0 0 0);
  }
}

/* The counter, in your pixel typeface, centred under the logo. */
.loader__count {
  min-width: 3ch;
  text-align: center;
  font-family: "DMTO Pixel", ui-monospace, monospace;
  font-size: clamp(1rem, 2vw, 1.4rem);
  line-height: 1;
  color: #fff;
  letter-spacing: 0.08em;
}

@media (prefers-reduced-motion: reduce) {
  .loader,
  html.is-covering .loader {
    display: none !important;
  }
}
