/* Exswaping M4 — PWA install & update experience */
:root {
  --ex-m4-bg: #050b08;
  --ex-m4-surface: rgba(12, 18, 16, 0.96);
  --ex-m4-border: rgba(139, 92, 246, 0.35);
  --ex-m4-purple-1: #8b5cf6;
  --ex-m4-purple-2: #7b62ff;
  --ex-m4-purple-3: #6346f0;
  --ex-m4-text: #f4f0ff;
  --ex-m4-muted: rgba(220, 210, 255, 0.72);
  --ex-m4-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(139, 92, 246, 0.12);
  --ex-m4-safe-bottom: max(16px, env(safe-area-inset-bottom, 0px));
}

#exswaping-pwa-m4-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99990;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

#exswaping-pwa-m4-root[hidden] {
  display: block;
  visibility: hidden;
}

#exswaping-pwa-m4-root:not([hidden]) {
  visibility: visible;
}

.ex-m4-hidden {
  display: none !important;
}

/* Update chip — bottom-right toast, non-blocking */
.ex-m4-chip {
  position: fixed;
  right: 12px;
  bottom: calc(72px + var(--ex-m4-safe-bottom));
  z-index: 99991;
  max-width: min(320px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(12, 18, 16, 0.94);
  border: 1px solid var(--ex-m4-border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform: translateY(16px);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
  pointer-events: auto;
}

.ex-m4-chip.ex-m4-visible {
  transform: translateY(0);
  opacity: 1;
}

.ex-m4-chip__text {
  color: var(--ex-m4-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.ex-m4-chip__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ex-m4-chip__refresh {
  padding: 8px 12px;
  font-size: 12px;
}

.ex-m4-chip__later {
  padding: 8px 10px;
  font-size: 12px;
}

.ex-m4-btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.ex-m4-btn:active {
  transform: scale(0.97);
}

.ex-m4-btn--primary {
  color: #fff;
  background: linear-gradient(135deg, var(--ex-m4-purple-1), var(--ex-m4-purple-2) 55%, var(--ex-m4-purple-3));
  box-shadow: 0 4px 16px rgba(123, 98, 255, 0.35);
}

.ex-m4-btn--ghost {
  color: var(--ex-m4-muted);
  background: transparent;
  padding: 8px;
}

/* Install card — bottom sheet style, not modal popup */
.ex-m4-install {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--ex-m4-safe-bottom));
  z-index: 99992;
  max-width: 420px;
  margin: 0 auto;
  background: var(--ex-m4-surface);
  border: 1px solid var(--ex-m4-border);
  border-radius: 18px;
  box-shadow: var(--ex-m4-shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateY(calc(100% + 24px));
  opacity: 0;
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.32s ease;
  pointer-events: auto;
  overflow: hidden;
}

.ex-m4-install::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(139, 92, 246, 0.14), transparent 70%);
  pointer-events: none;
}

.ex-m4-install.ex-m4-visible {
  transform: translateY(0);
  opacity: 1;
}

.ex-m4-install__body {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 16px 12px;
}

.ex-m4-install__icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(99, 70, 240, 0.35);
  object-fit: cover;
}

.ex-m4-install__copy {
  flex: 1;
  min-width: 0;
}

.ex-m4-install__title {
  margin: 0 0 4px;
  color: var(--ex-m4-text);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.ex-m4-install__desc {
  margin: 0;
  color: var(--ex-m4-muted);
  font-size: 12px;
  line-height: 1.45;
}

.ex-m4-install__actions {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 0 16px 16px;
}

.ex-m4-install__actions .ex-m4-btn--primary {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
}

.ex-m4-install__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ex-m4-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

/* Installed pill — subtle, non-intrusive */
.ex-m4-installed {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--ex-m4-safe-bottom));
  z-index: 99989;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 18, 16, 0.92);
  border: 1px solid rgba(139, 92, 246, 0.28);
  color: var(--ex-m4-muted);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.ex-m4-installed.ex-m4-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.ex-m4-installed__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ex-m4-purple-1), var(--ex-m4-purple-3));
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.6);
}

@media (min-width: 768px) {
  #exswaping-pwa-m4-root {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ex-m4-install,
  .ex-m4-chip,
  .ex-m4-installed {
    transition: none;
  }
}
