/*
 * Launch splash (web and Android; see public/splash.js).
 *
 * Hidden unless splash.js adds `pm-splash` to <html> before first paint.
 * The background colour matches @color/splash_background in the
 * Android project so the native launch screen hands off without a seam.
 *
 * Design: one soft light, the icon, the wordmark and an ECG trace that is
 * also the loading indicator. Everything settles with the same easing and
 * nothing overshoots; the only continuous motion is the ECG sweep and a
 * slow breath in the light behind the icon.
 *
 * Performance rule: every animation here changes only `transform` and
 * `opacity`, which Chromium runs on the GPU compositor while the main thread
 * is busy starting the app bundle. Glows are baked into gradients, not filters.
 */

#pm-splash {
  display: none;
}

html.pm-splash,
html.pm-splash body {
  background: #061a30;
  overflow: hidden;
}

html.pm-splash #pm-splash,
#pm-splash.pm-splash-exit {
  --pm-bg: #061a30;
  --pm-ease: cubic-bezier(0.22, 1, 0.36, 1);

  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  contain: strict;
  background:
    radial-gradient(85% 55% at 50% 40%, #0c2f55 0%, rgba(12, 47, 85, 0) 70%),
    var(--pm-bg);
  color: #f8fafc;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Stage ---------- */

.pm-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -4vh;
}

.pm-logo-wrap {
  position: relative;
  width: 112px;
  height: 112px;
}

/* Soft light behind the icon. It fades in, then breathes slowly. */
.pm-halo {
  position: absolute;
  inset: -80%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.2) 0%, rgba(56, 189, 248, 0.06) 40%, rgba(56, 189, 248, 0) 68%);
  opacity: 0;
  animation:
    pm-fade-in 1.2s var(--pm-ease) 0.2s forwards,
    pm-breathe 3.6s ease-in-out 1.4s infinite;
}

@keyframes pm-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* The app icon: blue squircle with the book + stethoscope drawn in SVG. */
.pm-badge {
  position: absolute;
  inset: 0;
  border-radius: 26%;
  overflow: hidden;
  background: radial-gradient(75% 75% at 45% 40%, #1a74cf 0%, #0d4596 55%, #062a6e 100%);
  box-shadow: 0 16px 36px rgba(1, 12, 32, 0.5), inset 0 0 0 1px rgba(186, 230, 253, 0.16);
  opacity: 0;
  animation: pm-badge-in 0.9s var(--pm-ease) 0.1s forwards;
}

@keyframes pm-badge-in {
  from { transform: translateY(8px) scale(0.94); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.pm-art {
  position: absolute;
  inset: 7%;
}

.pm-layer,
.pm-steth-group {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ---------- Wordmark ---------- */

.pm-word {
  margin: 28px 0 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: #ffffff;
  opacity: 0;
  animation: pm-rise 0.9s var(--pm-ease) 0.35s forwards;
}

.pm-word span {
  color: #7dd3fc;
}

.pm-tag {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(186, 230, 253, 0.55);
  opacity: 0;
  animation: pm-rise 0.9s var(--pm-ease) 0.5s forwards;
}

@keyframes pm-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- ECG trace (the loading indicator) ----------
 * One fixed path. The bright copy is revealed through an SVG mask whose
 * gradient band is the only moving part, so it always sits exactly on the
 * dim trace.
 */

.pm-ecg {
  display: block;
  width: min(200px, 56vw);
  height: auto;
  margin-top: 40px;
  overflow: visible;
  opacity: 0;
  animation: pm-fade-in 0.8s ease-out 0.8s forwards;
}

/* The band travels from fully left of the trace (x = -96) to fully past its
   right end (x = 280), in viewBox units. */
.pm-ecg-sweep {
  transform: translateX(0);
  animation: pm-ecg-sweep 1.6s cubic-bezier(0.45, 0, 0.55, 1) 0.8s infinite;
}

@keyframes pm-ecg-sweep {
  from { transform: translateX(0); }
  to { transform: translateX(376px); }
}

@keyframes pm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Exit: a gentle fade into the app ---------- */

#pm-splash.pm-splash-exit {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  #pm-splash *,
  #pm-splash *::before,
  #pm-splash *::after {
    animation-duration: 1ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
  }

  #pm-splash .pm-ecg-beam {
    display: none;
  }

  #pm-splash.pm-splash-exit {
    transition-property: opacity;
    transform: none;
  }
}
