:root {
  --pwa-launch-background:
    radial-gradient(ellipse at 50% 44%, rgba(28, 143, 82, 0.42), transparent 43%),
    linear-gradient(155deg, #07552e 0%, #043b26 48%, #031f19 100%);
  --pwa-app-background:
    linear-gradient(rgba(0, 128, 0, 0.5), rgba(0, 128, 0, 0.5)),
    url(https://static.vecteezy.com/system/resources/thumbnails/003/396/140/small_2x/soccer-ball-in-net-with-spotlight-or-stadium-light-background-free-photo.jpg);
}

.pwa-action {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 1090;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  color: #fff;
  background: rgba(6, 83, 40, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.38);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.pwa-action[hidden] { display: none; }
.pwa-action:hover { background: #087f3e; }

.pwa-status {
  position: fixed;
  right: 16px;
  bottom: max(76px, calc(60px + env(safe-area-inset-bottom)));
  left: 16px;
  z-index: 1090;
  max-width: 430px;
  margin: 0 auto;
  padding: 12px 16px;
  color: #fff;
  background: rgba(25, 31, 28, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.36);
  font-size: 0.88rem;
  text-align: center;
}

.pwa-status[hidden] { display: none; }

.pwa-launch-splash[hidden] { display: none !important; }

html.pwa-standalone-mobile .pwa-launch-splash.pwa-launch-splash--pending {
  opacity: 1;
  visibility: visible;
}

/* En una PWA instalada se cubre la página desde el primer renderizado, antes
   de que se ejecute el JavaScript que anima el logo. */
@media (display-mode: standalone) and (max-width: 991.98px) {
  .pwa-launch-splash.pwa-launch-splash--pending {
    opacity: 1;
    visibility: visible;
  }
}

.pwa-launch-splash {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  height: 100lvh;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100lvh;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  overflow: hidden;
  color: #e5ffe9;
  background: var(--pwa-launch-background);
  background-color: #031f19;
  opacity: 0;
  visibility: hidden;
  transition: opacity 360ms ease, visibility 360ms ease;
}

.pwa-launch-splash.is-visible {
  opacity: 1;
  visibility: visible;
}

.pwa-launch-splash.is-hiding {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.pwa-launch-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 340px);
  transform: translateY(-2vh);
}

.pwa-launch-mark {
  position: relative;
  display: grid;
  width: min(64vw, 248px);
  aspect-ratio: 1;
  place-items: center;
}

.pwa-launch-orbit {
  position: absolute;
  inset: 10%;
  border: 1px solid rgba(145, 255, 179, 0.52);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.72) rotate(-30deg);
}

.pwa-launch-splash.is-visible .pwa-launch-orbit {
  animation: pwa-orbit-build 1.25s cubic-bezier(0.18, 0.72, 0.24, 1) both;
}

.pwa-launch-logo {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  clip-path: inset(100% 0 0 0);
  opacity: 0;
  transform: translateY(12px) scale(0.94);
  filter: drop-shadow(0 0 0 rgba(129, 255, 161, 0));
}

.pwa-launch-splash.is-visible .pwa-launch-logo {
  animation: pwa-logo-build 1.15s cubic-bezier(0.2, 0.76, 0.2, 1) 120ms both;
}

.pwa-launch-caption {
  margin: 18px 0 16px;
  color: rgba(231, 255, 237, 0.88);
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.045em;
  opacity: 0;
  transform: translateY(8px);
}

.pwa-launch-splash.is-visible .pwa-launch-caption {
  animation: pwa-caption-appear 420ms ease-out 650ms both;
}

.pwa-launch-progress {
  width: 112px;
  height: 3px;
  overflow: hidden;
  background: rgba(210, 255, 223, 0.18);
  border-radius: 999px;
  opacity: 0;
}

.pwa-launch-splash.is-visible .pwa-launch-progress {
  animation: pwa-caption-appear 300ms ease-out 800ms both;
}

.pwa-launch-progress span {
  display: block;
  width: 42%;
  height: 100%;
  background: #8ff0b5;
  border-radius: inherit;
  box-shadow: 0 0 12px rgba(143, 240, 181, 0.9);
  animation: pwa-progress-run 1.35s ease-in-out infinite;
}

@keyframes pwa-orbit-build {
  0% { opacity: 0; transform: scale(0.72) rotate(-30deg); }
  55% { opacity: 0.85; }
  100% { opacity: 0.48; transform: scale(1.08) rotate(0); }
}

@keyframes pwa-logo-build {
  0% {
    clip-path: inset(100% 0 0 0);
    opacity: 0;
    transform: translateY(12px) scale(0.94);
    filter: drop-shadow(0 0 0 rgba(129, 255, 161, 0));
  }
  72% {
    clip-path: inset(0);
    opacity: 1;
    transform: translateY(-2px) scale(1.015);
    filter: drop-shadow(0 0 18px rgba(129, 255, 161, 0.26));
  }
  100% {
    clip-path: inset(0);
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: drop-shadow(0 10px 24px rgba(0, 20, 12, 0.2));
  }
}

@keyframes pwa-caption-appear {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pwa-progress-run {
  from { transform: translateX(-115%); }
  to { transform: translateX(255%); }
}

@media (prefers-reduced-motion: reduce) {
  .pwa-launch-splash,
  .pwa-launch-splash * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* El panel lateral ocupa toda la pantalla. Su cabecera necesita reservar la
   zona del notch/Dynamic Island para que el botón de cierre siga siendo
   accesible en iPhone. */
#panelNotificaciones .offcanvas-header {
  padding-top: calc(var(--bs-offcanvas-padding-y) + env(safe-area-inset-top));
  padding-right: max(var(--bs-offcanvas-padding-x), env(safe-area-inset-right));
  padding-left: max(var(--bs-offcanvas-padding-x), env(safe-area-inset-left));
}

@media (max-width: 991.98px) {
  html.pwa-standalone-mobile,
  html.pwa-standalone-mobile body {
    min-height: 100lvh;
  }

  html.pwa-standalone-mobile {
    position: relative;
    isolation: isolate;
    background: #031f19 !important;
  }

  html.pwa-standalone-mobile body {
    position: relative;
    isolation: isolate;
    background: transparent !important;
  }

  /* Un único plano de fondo fijo detrás de toda la interfaz. No se vuelve a
     dibujar el degradado en la barra: en iOS eso duplica el tinte y vela el
     saldo y los botones. */
  html.pwa-standalone-mobile body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: var(--pwa-app-background);
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
  }

  html.pwa-standalone-mobile #sideNav.navbar.bg-primary,
  html.pwa-standalone-mobile #sideNavEstadisticas.navbar.bg-primary {
    /* La barra crea un contexto propio: fondo abajo y controles encima. */
    --bs-bg-opacity: 0 !important;
    background-color: transparent !important;
    background-image: none !important;
    isolation: isolate;
    opacity: 1 !important;
    filter: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    z-index: 1030;
  }

  html.pwa-standalone-mobile #sideNav::before,
  html.pwa-standalone-mobile #sideNavEstadisticas::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    /* Opaco para que la foto/degradado del fondo no transparente visualmente
       el saldo ni los controles. Los elementos reales se pintan en z-index 2. */
    background: linear-gradient(155deg, #07552e 0%, #043b26 55%, #031f19 100%);
  }

  html.pwa-standalone-mobile #sideNav > *,
  html.pwa-standalone-mobile #sideNavEstadisticas > * {
    position: relative;
    z-index: 2;
    background-color: transparent;
    opacity: 1 !important;
    filter: none !important;
  }

  html.pwa-standalone-mobile #sideNav,
  html.pwa-standalone-mobile #sideNavEstadisticas {
    top: 0;
    min-height: calc(3.375rem + env(safe-area-inset-top));
    padding-top: calc(0.5rem + env(safe-area-inset-top));
  }

  /* La navegación fija se desplaza bajo la barra de estado. Compensamos el
     mismo espacio en el contenido para que la primera sección no quede debajo. */
  html.pwa-standalone-mobile body > main.container-fluid {
    position: relative;
    z-index: 1;
    padding-top: env(safe-area-inset-top) !important;
  }
}
