/* Title sequence: the Post World ident on black, a terminal-style bar and log
   under the globe while the lot loads, Enter, the warp-off, then "Wake up...".
   Colours are taken from the ident: deep teal glow, teal, and the pale line. */
@font-face { font-family: 'PW Mono'; font-weight: 400; font-display: swap; src: url('assets/identity/dm-mono1.woff2'); }
@font-face { font-family: 'PW Mono'; font-weight: 300; font-display: swap; src: url('assets/identity/dm-mono0.woff2'); }

.loader, .wake {
  --pw-black: #03070a;  /* the ident's black as browsers draw it */
  --pw-deep: #067f82;
  --pw-teal: #39a7a1;
  --pw-line: #a6dacb;
  --pw-glow: 0 0 10px #39a7a173, 0 0 2px #a6dacb80;
  --pw-mono: 'PW Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --pw-ease: cubic-bezier(.45, 0, .2, 1);
}
.loader {
  /* The ident is drawn wider than the screen needs: its frame is mostly black,
     so only the globe reads, at a useful size. */
  --ident-width: min(920px, 150vw, 150vh * 16 / 9);
  --ident-height: calc(var(--ident-width) * 9 / 16);
  --ident-centre: 43%;
  position: fixed;
  inset: 0;
  z-index: 80;
  overflow: hidden;
  color: var(--pw-line);
  background: var(--pw-black);
  transition: opacity .9s var(--pw-ease), filter .9s var(--pw-ease);
}
.loader[hidden] { display: none; }
.loader.is-leaving { opacity: 0; pointer-events: none; }

.loader-window {
  position: absolute;
  left: 50%;
  top: var(--ident-centre);
  width: var(--ident-width);
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity .3s linear;
}
.loader-window video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--pw-black);
  /* Feather the frame away so no edge of the video ever shows, whatever black a browser draws. */
  -webkit-mask-image: radial-gradient(ellipse 48% 46% at 50% 50%, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse 48% 46% at 50% 50%, #000 62%, transparent 100%);
}
.loader.is-gone .loader-window { opacity: 0; }

/* The terminal sits just under the globe and comes in once the logo is lit. */
.loader-terminal {
  position: absolute;
  left: 50%;
  top: calc(var(--ident-centre) + var(--ident-height) * .25);
  width: min(400px, calc(100vw - 2 * var(--cinema-gutter, 20px)));
  transform: translateX(-50%);
  display: grid;
  justify-items: stretch;
  font: 400 clamp(12px, .9vw, 13px)/1.55 var(--pw-mono);
  letter-spacing: .02em;
  opacity: 0;
  filter: blur(6px);
  transition: opacity .7s var(--pw-ease), filter .7s var(--pw-ease);
}
.loader.is-holding .loader-terminal { opacity: 1; filter: none; }
.loader.is-entering .loader-terminal { opacity: 0; filter: blur(6px); transition-duration: .35s; }

.loader-meter-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px; }
.loader-meter { height: 2px; overflow: hidden; background: #39a7a12e; }
.loader-fill {
  display: block;
  height: 100%;
  background: var(--pw-line);
  box-shadow: 0 0 8px var(--pw-teal);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform .45s cubic-bezier(.33, 0, .15, 1);
}
#loader-percent { color: var(--pw-line); text-shadow: var(--pw-glow); font-variant-numeric: tabular-nums; white-space: pre; }

/* Four lines, newest at the bottom, older ones dimming upward. */
.loader-log {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  height: calc(4 * 1.55em);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  color: var(--pw-teal);
}
.loader-log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .32; }
.loader-log li:nth-last-child(2) { opacity: .5; }
.loader-log li:nth-last-child(3) { opacity: .4; }
.loader-log li:last-child { opacity: 1; color: var(--pw-line); text-shadow: var(--pw-glow); }
.loader-log li.is-typing::after, .wake.is-typing .wake-cursor {
  content: '';
  display: inline-block;
  width: .62em;
  height: 1.08em;
  margin-left: .12em;
  vertical-align: -.18em;
  background: currentColor;
  box-shadow: 0 0 8px #39a7a199;
  animation: pw-cursor 1.06s steps(1) infinite;
}
@keyframes pw-cursor { 50% { opacity: 0; } }

/* Enter keeps its place from the start so nothing shifts when it arrives. */
#loader-enter {
  justify-self: center;
  min-width: 156px;
  min-height: 44px;
  margin-top: 18px;
  padding: 0 26px;
  font: 400 12px/1 var(--pw-mono);
  letter-spacing: .28em;
  text-indent: .28em;
  text-transform: uppercase;
  color: var(--pw-line);
  text-shadow: var(--pw-glow);
  background: transparent;
  border: 1px solid #39a7a199;
  border-radius: 0;
  box-shadow: 0 0 14px #067f8240, inset 0 0 10px #067f8226;
  visibility: hidden;
  opacity: 0;
  filter: blur(6px);
  transition: opacity .6s var(--pw-ease), filter .6s var(--pw-ease), background-color .2s, color .2s;
}
.loader.can-enter #loader-enter { visibility: visible; opacity: 1; filter: none; }
#loader-enter:hover, #loader-enter:focus-visible { color: var(--pw-black); text-shadow: none; background: var(--pw-line); }
#loader-enter:focus-visible { outline: 1px solid var(--pw-line); outline-offset: 4px; }

body:has(#loader:not([hidden])) .hud { visibility: hidden; }

/* "Wake up..." over black, staying while the car fades in. */
.wake {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  pointer-events: none;
  padding: 0 var(--cinema-gutter, 20px);
  font: 400 clamp(22px, 2.9vw, 42px)/1.3 var(--pw-mono);
  letter-spacing: .03em;
  color: var(--pw-line);
  text-shadow: var(--pw-glow);
  transition: opacity 1.2s var(--pw-ease);
}
.wake[hidden] { display: none; }
/* Centred on the finished line: the typing starts at its left edge and fills
   rightward, so the words never slide as they arrive. */
.wake-line { position: relative; display: block; white-space: pre; }
.wake-ghost { visibility: hidden; padding-right: .74em; }
.wake-typed { position: absolute; left: 0; top: 0; white-space: pre; }

/* Plain black, the line in glowing phosphor that flickers very slightly all the
   time, dips now and then, and flares as each letter lands. Two flickers run at
   unrelated rates on the line and the letters, so it never settles into a
   pattern. Then it simply fades. */
.wake-line { animation: pw-flicker 2.3s steps(1) infinite; }
.wake-typed {
  color: #d2f7ea;
  text-shadow: 0 0 2px #e8fff7, 0 0 9px #39a7a1e6, 0 0 26px #067f82cc, 0 0 60px #067f8266, -1px 0 #ff505040, 1px 0 #50a8ff40;
  filter: blur(.3px);
  transition: filter .14s linear;
  animation: pw-shimmer .11s steps(1) infinite;
}
.wake.is-strike .wake-typed { filter: blur(.4px) brightness(1.5); transition-duration: 0s; }
@keyframes pw-shimmer { 50% { opacity: .93; } }
@keyframes pw-flicker {
  0% { opacity: 1; }
  17% { opacity: .9; } 19% { opacity: 1; }
  44% { opacity: .96; } 46% { opacity: 1; }
  71% { opacity: .78; } 73% { opacity: .97; } 75% { opacity: 1; }
  92% { opacity: .94; } 93% { opacity: 1; }
}
.wake.is-leaving { opacity: 0; }

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

@media (max-height: 520px) {
  .loader { --ident-centre: 36%; }
  .loader-log { height: calc(2 * 1.55em); }
  #loader-enter { margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .loader, .loader-terminal, .loader-fill, #loader-enter, .wake { transition: none; }
  .loader-terminal, #loader-enter { filter: none; }
  .loader-log li.is-typing::after, .wake.is-typing .wake-cursor, .wake-line, .wake-typed { animation: none; }
}
