/* Shared boot screen — the one source for every platform app (AirFone,
   LunaCam, …). It shows the instant the page loads, before Flutter's JS
   downloads, and stays up until Dart calls window.__boot.done()
   (BootOverlay.release). Its Flutter twin is BootLoader — keep them matching.

   This file holds the STRUCTURE only. Each app sets its brand through CSS
   custom properties on #app-loading (light and, under prefers-color-scheme,
   dark) and its words through window.__BOOT__ in index.html. Nothing here is
   per-app, so apps never copy this CSS — they sync it from the kit.

   The waveform animates transform only, so it runs on the compositor and
   stays smooth while the main thread compiles WebAssembly. */

:root {
  /* Fallbacks; apps override these on #app-loading. */
  --boot-bg: #ffffff;
  --boot-ink: #0a0a0a;
  --boot-muted: #4d545c;
  --boot-bar-1: #0a0a0a;
  --boot-bar-2: #8a8d8c;
  --boot-link: var(--boot-bar-1);
  --boot-doodle-size: 627px;
  --boot-doodle-opacity: 0.07;
}

html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }

#app-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--boot-bg);
  color: var(--boot-ink);
  font-family: var(--boot-font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  text-align: center;
  transition: opacity 240ms ease-out;
  z-index: 9999;
}

/* Logo as a CSS background so each app can swap it per theme (a dark mark on
   the light boot, a light mark on the dark boot) through --boot-logo. */
#boot-logo {
  width: 64px;
  height: 64px;
  background: var(--boot-logo) center / contain no-repeat;
}
#app-loading img { width: 64px; height: 64px; }

/* The doodle: fetched in the background and faded in once decoded, so the
   loader never waits for it. Clear behind the words, fading to full strength
   towards the edges — no box, no line where it stops. */
#boot-doodle {
  position: absolute;
  inset: 0;
  background-repeat: repeat;
  background-position: top left;
  background-size: var(--boot-doodle-size) auto;
  opacity: 0;
  transition: opacity 250ms ease-out;
  pointer-events: none;
  -webkit-mask-image: radial-gradient(closest-side, transparent 35%, #000 100%);
  mask-image: radial-gradient(closest-side, transparent 35%, #000 100%);
}
#app-loading > :not(#boot-doodle) { position: relative; }
#boot-doodle.boot-on { opacity: var(--boot-doodle-opacity); }

.boot-wave {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  margin: 32px 0 24px;
}
.boot-wave span {
  width: 6px;
  height: 40px;
  border-radius: 3px;
  background: var(--boot-bar-1);
  transform: scaleY(0.2);
  animation: boot-wave 1.1s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  will-change: transform;
}
.boot-wave span:nth-child(2) { animation-delay: -0.9s; background: var(--boot-bar-2); }
.boot-wave span:nth-child(3) { animation-delay: -0.7s; }
.boot-wave span:nth-child(4) { animation-delay: -0.5s; background: var(--boot-bar-2); }
.boot-wave span:nth-child(5) { animation-delay: -0.3s; }
@keyframes boot-wave {
  0%, 100% { transform: scaleY(0.2); }
  50% { transform: scaleY(1); }
}

#boot-stage {
  margin: 0;
  font-size: 16px;
  line-height: 24px;
  font-weight: 500;
  transition: opacity 150ms ease-out;
}
#boot-fact {
  margin: 8px 0 0;
  max-width: 340px;
  min-height: 42px; /* two lines reserved, so nothing shifts */
  font-size: 14px;
  line-height: 1.5;
  color: var(--boot-muted);
  opacity: 0;
  transition: opacity 300ms ease-out;
}

/* Two states beyond loading. Slow (45 s): still loading, one honest line with
   the way out inside it. Failed (the loader reported an error): the waveform
   and the rotating lines go, and a plain failure message takes their place. */
#boot-slow, #boot-failure { display: none; }
#boot-slow {
  margin: 8px 0 0;
  max-width: 340px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--boot-muted);
}
#boot-failure { margin-top: 24px; }
#boot-failure h1 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
}
#boot-failure p {
  margin: 0;
  max-width: 360px;
  font-size: 16px;
  line-height: 24px;
  color: var(--boot-muted);
}
#app-loading a {
  color: var(--boot-link);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  border-radius: 4px;
}
#app-loading a:hover { text-decoration-thickness: 2px; }
#app-loading a:focus-visible { outline: 2px solid var(--boot-link); outline-offset: 2px; }

#app-loading.boot-slow #boot-fact { display: none; }
#app-loading.boot-slow #boot-slow { display: block; }
#app-loading.boot-failed .boot-wave,
#app-loading.boot-failed #boot-stage,
#app-loading.boot-failed #boot-fact,
#app-loading.boot-failed #boot-slow { display: none; }
#app-loading.boot-failed #boot-failure { display: block; }

@media (prefers-reduced-motion: reduce) {
  .boot-wave span { animation-duration: 3s; }
  #boot-fact { transition: none; }
}
