/*
 * The temporary homepage: the login screen's look (client/src/styles.css, "login" section) cut down
 * to the space backdrop, the logo with its sweep of light, and one galaxy button out to Discord.
 * Everything is sized in em off one font size that grows with the window, as on the login screen.
 */
@font-face {
  font-family: 'Montserrat';
  src: url('fonts/Montserrat-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --text: #e9eef6;
  --muted: #8d97a8;
  --line: rgba(176, 196, 224, 0.32);
  /* The game's cursor (client/src/ui/cursor.ts), as on the login screen. */
  --cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><circle cx='16' cy='16' r='7.25' fill='none' stroke='%23071721' stroke-opacity='.85' stroke-width='3.25'/><circle cx='16' cy='16' r='7.25' fill='none' stroke='%23D9F6FA' stroke-width='1.35'/><circle cx='16' cy='16' r='2.25' fill='%23F5FEFF'/></svg>") 16 16;
  color-scheme: dark;
}

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

html,
body {
  height: 100%;
  margin: 0;
}

/* What shows under the canvas, and instead of it without WebGL. */
body {
  background:
    radial-gradient(ellipse at 0% 35%, rgba(150, 60, 200, 0.18), transparent 45%),
    radial-gradient(ellipse at 100% 85%, rgba(40, 170, 160, 0.16), transparent 45%),
    radial-gradient(ellipse at 10% 0%, rgba(40, 90, 220, 0.2), transparent 50%),
    #03050c;
  color: var(--text);
  font-family: 'Montserrat', system-ui, sans-serif;
  font-size: clamp(14px, calc(0.4vw + 0.6vh + 2px), 20px);
  font-weight: 500;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  cursor: var(--cursor), default;
}

.page {
  position: relative;
  min-height: 100%;
  overflow-x: hidden;
}

.cosmos {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.7s ease;
  pointer-events: none;
}

.cosmos.on {
  opacity: 1;
}

.stage {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2em;
  padding: max(1.5em, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(4em, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* ---- the logo, with a soft white sweep of light every 25 seconds */
.logo {
  position: relative;
  flex: none;
  width: clamp(220px, min(52em, 88vw, 62vh), 900px);
  margin: 0;
}

.logo img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 1.5em rgba(120, 170, 255, 0.22));
  user-select: none;
  -webkit-user-drag: none;
}

.glint-glow {
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 0 0.6em rgba(255, 255, 255, 0.55));
  pointer-events: none;
}

.glint {
  position: absolute;
  inset: 0;
  -webkit-mask: url('logo.png') center / 100% 100% no-repeat;
  mask: url('logo.png') center / 100% 100% no-repeat;
  background: linear-gradient(100deg, transparent 44%, rgba(255, 255, 255, 0.5) 48%, #fff 50%, rgba(255, 255, 255, 0.5) 52%, transparent 56%) no-repeat;
  background-size: 300% 100%;
  background-position: 100% 0;
  animation: logo-glint 25s ease-in-out 2s infinite;
}

@keyframes logo-glint {
  0% {
    background-position: 100% 0;
  }
  10%,
  100% {
    background-position: 0% 0;
  }
}

/* ---- the galaxy button (its picture is a canvas from cosmos.js, under the label) */
.galaxy {
  --cut: 0.45em;
  --ci: calc(var(--cut) - 0.41px);
  --c2: calc(var(--cut) - 0.4px);
  --edge: rgba(206, 222, 242, 0.6);
  /* What shows without WebGL. */
  --fill: linear-gradient(90deg, #12306a, #050a18 40%, #0a1a2a 70%, #2a1a4a);
  /* The 1px clipped-corner edge: the outline, then (even-odd) the same shape 1px inside cut back out. */
  --ring: polygon(
    evenodd,
    var(--cut) 0,
    calc(100% - var(--cut)) 0,
    100% var(--cut),
    100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%,
    var(--cut) 100%,
    0 calc(100% - var(--cut)),
    0 var(--cut),
    var(--cut) 0,
    calc(1px + var(--ci)) 1px,
    calc(100% - 1px - var(--ci)) 1px,
    calc(100% - 1px) calc(1px + var(--ci)),
    calc(100% - 1px) calc(100% - 1px - var(--ci)),
    calc(100% - 1px - var(--ci)) calc(100% - 1px),
    calc(1px + var(--ci)) calc(100% - 1px),
    1px calc(100% - 1px - var(--ci)),
    1px calc(1px + var(--ci)),
    calc(1px + var(--ci)) 1px
  );
  --inner: polygon(var(--c2) 0, calc(100% - var(--c2)) 0, 100% var(--c2), 100% calc(100% - var(--c2)), calc(100% - var(--c2)) 100%, var(--c2) 100%, 0 calc(100% - var(--c2)), 0 var(--c2));
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9em;
  width: min(25em, 100%);
  height: 3.6em;
  color: #fff;
  text-decoration: none;
  filter: drop-shadow(0 0 0.6em rgba(90, 140, 220, 0.2));
  cursor: var(--cursor), pointer;
  transition:
    transform 0.08s,
    filter 0.2s;
}

/* A border can't follow a clip-path, so the edge is ::before and the fill, 1px inside it, ::after. */
.galaxy::before,
.galaxy::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  clip-path: var(--ring);
  background: var(--edge);
  pointer-events: none;
  transition: background 0.15s;
}

.galaxy::after {
  inset: 1px;
  clip-path: var(--inner);
  background: var(--fill);
}

.galaxy .galaxy-fx {
  position: absolute;
  inset: 1px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  clip-path: var(--inner);
}

.galaxy .mark {
  position: relative;
  flex: none;
  width: 1.45em;
  height: 1.45em;
  filter: drop-shadow(0 0 0.5em rgba(150, 190, 255, 0.55)) drop-shadow(0 1px 1px rgba(0, 0, 20, 0.9));
}

.galaxy .label {
  position: relative;
  font-size: 1.05em;
  font-weight: 700;
  letter-spacing: 0.3em;
  /* Letter spacing trails after the last letter too; this keeps the word centred. */
  margin-right: -0.3em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow:
    0 0 0.7em rgba(150, 190, 255, 0.55),
    0 1px 2px rgba(0, 0, 20, 0.9);
}

.galaxy:hover {
  --edge: rgba(225, 236, 250, 0.9);
  filter: drop-shadow(0 0 0.8em rgba(100, 150, 230, 0.35));
}

.galaxy:active {
  transform: scale(0.985);
}

.galaxy:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

/* ---- the bottom line */
.foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(1em, env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  font-size: 0.72em;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/*
 * ---- coming in. Until the sky's first frame is drawn, .waiting keeps everything hidden; then the
 * page swaps in .entering and the logo, button and footer come in as one gentle move.
 */
.page.waiting .stage,
.page.waiting .foot {
  visibility: hidden;
}

.page.entering .logo {
  animation: rise 0.9s cubic-bezier(0.25, 0.7, 0.25, 1) both;
}

.page.entering .galaxy {
  animation: lift 0.8s 0.18s cubic-bezier(0.25, 0.7, 0.25, 1) both;
}

.page.entering .foot {
  animation: fade 0.6s 0.4s ease-out both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes lift {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .glint,
  .page.entering .logo,
  .page.entering .galaxy,
  .page.entering .foot {
    animation: none;
  }
}

/* ------------------------------------------------------------------ 404 */
/* The page is short on small screens, so the logo sits in the flow above everything else. */
#void .stage {
  gap: 0;
}

.mini-logo {
  display: block;
  width: clamp(130px, 12em, 210px);
  margin-bottom: clamp(1.5em, 6vh, 4em);
  cursor: var(--cursor), pointer;
}

.mini-logo img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 1em rgba(120, 170, 255, 0.22));
}

/* "404", its 0 the black hole: an empty slot the shader centres on (blackhole.js). */
.code {
  display: flex;
  align-items: baseline;
  justify-content: center;
  margin: 0;
  font-size: min(13em, 27vw);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 0.08em rgba(140, 190, 255, 0.55),
    0 0.02em 0.04em rgba(0, 0, 20, 0.9);
  user-select: none;
}

.hole {
  position: relative;
  display: inline-block;
  width: 1.2em;
  height: 0.72em;
}

/* Without WebGL: a plain black disc with a pale ring. */
.hole::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0.52em;
  height: 0.52em;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #000;
  box-shadow:
    0 0 0 0.01em rgba(220, 235, 255, 0.9),
    0 0 0.12em 0.03em rgba(90, 170, 255, 0.6),
    0 0 0.4em 0.08em rgba(140, 90, 255, 0.3);
}

#void.gl .hole::before {
  display: none;
}

.title {
  margin: clamp(1.4em, 5vh, 2.6em) 0 0;
  font-size: 1.15em;
  font-weight: 700;
  letter-spacing: 0.34em;
  margin-right: -0.34em;
  text-transform: uppercase;
  text-align: center;
  text-shadow: 0 0 0.8em rgba(120, 180, 255, 0.35);
}

.lede {
  max-width: 25em;
  margin: 0.9em 0 2em;
  font-size: 0.95em;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
}

#void .galaxy {
  width: min(19em, 100%);
}

.aside {
  margin: 1.3em 0 0;
  font-size: 0.85em;
  color: var(--muted);
}

.aside a {
  color: #33cdf0;
  text-decoration: none;
  cursor: var(--cursor), pointer;
}

.aside a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.page.entering .mini-logo {
  animation: rise 0.9s cubic-bezier(0.25, 0.7, 0.25, 1) both;
}

/* The 4s come in a beat after the black hole starts to form. */
.page.entering .code > span:not(.hole) {
  animation: fade 1.2s 0.5s ease-out both;
}

.page.entering .title,
.page.entering .lede {
  animation: fade 0.8s 0.8s ease-out both;
}

#void.entering .galaxy {
  animation: lift 0.8s 0.95s cubic-bezier(0.25, 0.7, 0.25, 1) both;
}

.page.entering .aside {
  animation: fade 0.6s 1.1s ease-out both;
}

@media (prefers-reduced-motion: reduce) {
  .page.entering .mini-logo,
  .page.entering .code > span,
  .page.entering .title,
  .page.entering .lede,
  #void.entering .galaxy,
  .page.entering .aside {
    animation: none;
  }
}
