/*
 * AMPERE web start-up splash: styles.
 * Framework-neutral; see docs/WEB_SPLASH.md. Works with splash.js.
 *
 * Geometry is proportional only: the logo is sized from the usable area
 * (container query units of the safe-area-padded splash), every effect is a
 * multiple of the logo, and nothing depends on device names or breakpoints.
 * Motion uses transform and opacity only.
 */

/* Theme tokens. Defaults = the app's default theme (Violet skin, Neon look);
   splash.js replaces them with the saved theme before the first frame.
   test/web_splash_test.dart checks these against lib/ui/theme/splash_tokens.dart. */
:root {
  --splash-bg: #15141f;
  --splash-accent: #8b4ecf;
  --splash-bright: #9f5ff0;
  --splash-soft: #b859db;
  --splash-deep: #c02a8e;
  --splash-glow: rgba(159, 95, 240, 0.42); /* bright at 42% (derived in splash.js) */
  --splash-backdrop: none;                 /* Glass look: its four lights */
  --splash-fg: #ffffff;                    /* text colour of the look (Pearl: dark) */
  --splash-text: rgba(255, 255, 255, 0.82); /* fg at 82% (derived in splash.js) */
  --splash-track: rgba(255, 255, 255, 0.14); /* fg at 14%: progress track */

  --splash-in: 640ms;      /* entrance */
  --splash-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --splash-idle: 2800ms;   /* one calm pulse while waiting */
}

html, body {
  margin: 0;
  background-color: var(--splash-bg);
}

#ampere-splash {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  box-sizing: border-box;
  /* Usable area only: notches, rounded corners and home indicators stay clear. */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: var(--splash-bg);
  background-image: var(--splash-backdrop);
  background-repeat: no-repeat;
  color: var(--splash-text);
  font: 500 1rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  container-type: size;
  /* Fail-safe if splash.js never runs: get out of the way after 20 s.
     splash.js turns this off (html.splash-js) and takes over. */
  animation: splash-failsafe 300ms ease 20s forwards;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
html.splash-js #ampere-splash { animation: none; }
/* Logo and status share the centre cell; the status hangs below the logo. */
#ampere-splash > * { grid-area: 1 / 1; }
.splash-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* The logo: about 30% of the shorter usable side, never tiny, never huge
   (10rem keeps the 512 px icon sharp up to 3x pixel density). */
.splash-stage {
  --logo: clamp(4.5rem, 30vmin, 10rem);
  position: relative;
  width: var(--logo);
  height: var(--logo);
}
@supports (width: 1cqmin) {
  .splash-stage { --logo: clamp(4.5rem, 30cqmin, 10rem); }
}

.splash-glow,
.splash-ring,
.splash-logo,
.splash-sweep {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

/* Soft light behind the disc (a gradient, no blur filter). */
.splash-glow {
  inset: -65%;
  background: radial-gradient(circle closest-side, var(--splash-glow), transparent);
  opacity: 0;
  animation: splash-glow-in calc(var(--splash-in) * 1.2) var(--splash-ease) forwards;
}

/* "Sound pulse": one ring leaves the disc like a speaker beat. */
.splash-ring {
  inset: 0;
  border: max(2px, calc(var(--logo) * 0.018)) solid var(--splash-bright);
  opacity: 0;
  transform: scale(0.94);
}
[data-effect="pulse"] .splash-ring {
  animation: splash-pulse 1100ms cubic-bezier(0.22, 0.61, 0.36, 1) calc(var(--splash-in) * 0.45) 1 both;
}

.splash-logo {
  inset: 0;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.86);
  animation: splash-in var(--splash-in) var(--splash-ease) forwards;
}
.splash-logo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

/* "Light sweep": one band of light crosses the disc. */
.splash-sweep {
  inset: 0;
  overflow: hidden;
  opacity: 0;
}
.splash-sweep::before {
  content: "";
  position: absolute;
  inset: -10% auto -10% 0;
  width: 45%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: translateX(-120%) skewX(-12deg);
}
[data-effect="sweep"] .splash-sweep { opacity: 1; }
[data-effect="sweep"] .splash-sweep::before {
  animation: splash-sweep 900ms ease-in-out calc(var(--splash-in) * 0.6) 1 both;
}

/* Waiting: the app isn't ready when the entrance ends. One slow pulse at a
   time and a gently breathing light; nothing flashes. */
#ampere-splash.is-waiting .splash-ring {
  animation: splash-pulse var(--splash-idle) cubic-bezier(0.22, 0.61, 0.36, 1) 0s infinite both;
}
#ampere-splash.is-waiting .splash-glow {
  opacity: 1;
  animation: splash-breathe calc(var(--splash-idle) * 1.15) ease-in-out infinite alternate;
}

/* Status under the logo: a thin bar while it takes a while, words only when
   it's slow or failed. Sized from the logo, so it scales with it. */
.splash-status {
  position: absolute;
  left: 50%;
  top: calc(100% + var(--logo) * 0.26);
  width: max(9rem, calc(var(--logo) * 1.6));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}
.splash-bar {
  width: calc(var(--logo) * 0.7);
  height: max(2px, calc(var(--logo) * 0.02));
  border-radius: 999px;
  overflow: hidden;
  background: var(--splash-track);
  opacity: 0;
  transition: opacity 300ms ease;
}
.splash-bar::after {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  border-radius: inherit;
  background: var(--splash-bright);
  transform: translateX(-100%);
}
#ampere-splash.is-loading .splash-bar { opacity: 1; }
#ampere-splash.is-loading .splash-bar::after {
  animation: splash-progress 1300ms ease-in-out infinite;
}
.splash-message {
  margin: 0;
  font-size: 0.95rem;
}
.splash-message:empty { display: none; }
.splash-retry {
  display: none;
  appearance: none;
  border: 1.5px solid var(--splash-text);
  border-radius: 999px;
  padding: 0.6em 1.4em;
  background: transparent;
  color: var(--splash-fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.splash-retry:focus-visible { outline: 2px solid var(--splash-fg); outline-offset: 3px; }
#ampere-splash.is-slow .splash-retry,
#ampere-splash.is-failed .splash-retry { display: inline-block; }
#ampere-splash.is-failed .splash-bar { opacity: 0; }

/* Relaunched within the configured window: no entrance, logo already there. */
html.splash-quick .splash-logo,
html.splash-quick .splash-glow { animation: none; opacity: 1; transform: none; }
html.splash-quick .splash-ring,
html.splash-quick .splash-sweep::before { animation: none; }

@keyframes splash-in {
  to { opacity: 1; transform: none; }
}
@keyframes splash-glow-in {
  to { opacity: 1; }
}
@keyframes splash-pulse {
  0% { opacity: 0.55; transform: scale(0.94); }
  70% { opacity: 0; }
  100% { opacity: 0; transform: scale(1.8); }
}
@keyframes splash-breathe {
  from { opacity: 0.72; }
  to { opacity: 1; }
}
@keyframes splash-sweep {
  to { transform: translateX(340%) skewX(-12deg); }
}
@keyframes splash-progress {
  to { transform: translateX(250%); }
}
@keyframes splash-failsafe {
  to { opacity: 0; visibility: hidden; }
}

/* Reduced motion: a still logo with a short fade, no pulses or sweeps. */
@media (prefers-reduced-motion: reduce) {
  .splash-logo { transform: none; animation: splash-glow-in 180ms linear forwards; }
  .splash-glow { animation: splash-glow-in 180ms linear forwards; }
  .splash-ring,
  .splash-sweep::before,
  #ampere-splash.is-waiting .splash-ring,
  #ampere-splash.is-waiting .splash-glow,
  #ampere-splash.is-loading .splash-bar::after { animation: none; }
  #ampere-splash.is-loading .splash-bar::after { width: 100%; transform: none; opacity: 0.6; }
}

/* More contrast: no glow or backdrop, solid text. */
@media (prefers-contrast: more) {
  #ampere-splash { --splash-text: var(--splash-fg); background-image: none; }
  .splash-glow { display: none; }
}

/* Windows high contrast and other forced colours. */
@media (forced-colors: active) {
  #ampere-splash { background: Canvas; color: CanvasText; }
  .splash-glow, .splash-sweep { display: none; }
  .splash-ring { border-color: CanvasText; }
  .splash-bar { background: GrayText; }
  .splash-bar::after { background: Highlight; }
  .splash-retry { border-color: ButtonText; color: ButtonText; }
}

/* No JavaScript: AMPERE can't run, so say so instead of a spinning logo. */
.splash-noscript {
  position: fixed;
  inset: auto 0 calc(env(safe-area-inset-bottom, 0px) + 12%) 0;
  z-index: 2147483001;
  margin: 0;
  text-align: center;
  color: #fff;
  font: 500 1rem/1.4 system-ui, sans-serif;
}
