/* ============================================
   PWA INSTALL GATE — Fullscreen overlay
   Prompts mobile visitors to install the app.
   Uses existing design tokens from global.css.
   ============================================ */

/* ── Overlay container ──────────────────── */
#pwa-install-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  opacity: 0;
  animation: pwaFadeIn 0.6s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)) forwards;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ambient glow */
#pwa-install-overlay::before {
  content: '';
  position: fixed;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 120%;
  height: 50%;
  background: radial-gradient(ellipse at center, rgba(99, 102, 241, 0.07) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* Noise/grain texture */
#pwa-install-overlay::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.018;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 300px 300px;
}

#pwa-install-overlay.pwa-dismiss {
  animation: pwaFadeOut 0.35s var(--ease-in-out, cubic-bezier(0.4, 0, 0.2, 1)) forwards;
  pointer-events: none;
}

@keyframes pwaFadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes pwaFadeOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-12px); }
}

/* ── Inner content wrapper ──────────────── */
.pwa-install-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 340px;
  width: 100%;
  position: relative;
  z-index: 1;
  margin-top: -8vh;
}

/* ── Brand section ──────────────────────── */
.pwa-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}

.pwa-brand-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  overflow: hidden;
  margin-bottom: 14px;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.25),
    0 0 40px rgba(99, 102, 241, 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.pwa-brand-icon img {
  width: 100%;
  height: 100%;
  display: block;
}

.pwa-brand-name {
  font-family: var(--font-display, 'Inter', sans-serif);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ── Compact brand (iOS flow) ───────────── */
.pwa-brand-compact {
  margin-bottom: 16px;
}

.pwa-brand-compact .pwa-brand-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 12px;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.3),
    0 0 48px rgba(99, 102, 241, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

.pwa-brand-compact .pwa-brand-name {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ── Phone mockup (Android Chrome) ──────── */
.pwa-phone-mockup {
  position: relative;
  width: 200px;
  height: 380px;
  margin-bottom: 36px;
  flex-shrink: 0;
}

.pwa-phone-frame {
  position: absolute;
  inset: 0;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-radius: 36px;
  background: var(--bg-card, #1C1C20);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.pwa-phone-frame::before {
  content: '';
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 24px;
  background: var(--bg-page, #09090B);
  border-radius: 14px;
  z-index: 2;
}

.pwa-phone-screen {
  position: absolute;
  top: 44px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  background: var(--bg-page, #09090B);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
}

.pwa-phone-app-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pwa-phone-app-icon img {
  width: 100%;
  height: 100%;
  display: block;
}

.pwa-phone-app-name {
  font-family: var(--font-display, 'Inter', sans-serif);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.pwa-phone-skeleton {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-top: 8px;
  padding: 0 8px;
}

.pwa-phone-skeleton-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
}

.pwa-phone-skeleton-bar:nth-child(1) { width: 70%; }
.pwa-phone-skeleton-bar:nth-child(2) { width: 100%; }
.pwa-phone-skeleton-bar:nth-child(3) { width: 55%; }

.pwa-phone-frame::after {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  z-index: 2;
}

/* ── Copy ───────────────────────────────── */
.pwa-headline {
  font-family: var(--font-display, 'Inter', sans-serif);
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.pwa-subtext {
  font-size: var(--text-sm, 0.8125rem);
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 36px;
  max-width: 280px;
}

/* ── Steps card (iOS flow) ──────────────── */
.pwa-steps-card {
  width: 100%;
  max-width: 320px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xl, 16px);
  padding: 28px 22px 24px;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 8px 32px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* Accent gradient line at top of card */
.pwa-steps-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 5%, #4338CA 30%, #818CF8 50%, #4338CA 70%, transparent 95%);
  opacity: 0.6;
}

/* ── Numbered step guide ────────────────── */
.pwa-guide {
  width: 100%;
  max-width: 300px;
}

.pwa-guide-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.pwa-guide-step {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  text-align: left;
  position: relative;
  padding-bottom: 20px;
}

.pwa-guide-step:last-child {
  padding-bottom: 0;
}

/* Solid connecting line between step numbers */
.pwa-guide-step:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 14px;
  top: 34px;
  bottom: 6px;
  width: 1px;
  background: rgba(99, 102, 241, 0.3);
}

.pwa-guide-step-num {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  background: var(--gradient-brand-primary);
  color: #fff;
  font-family: var(--font-mono, monospace);
  font-size: 0.8125rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.pwa-guide-step-text {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.5;
  padding-top: 4px;
}

.pwa-guide-step-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Inline icons inside step text */
.pwa-step-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-right: 1px;
  color: var(--text-primary);
  flex-shrink: 0;
}

/* ── Install button (Android Chrome) ────── */
.pwa-install-btn {
  width: 100%;
  max-width: 300px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display, 'Inter', sans-serif);
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--gradient-brand-primary);
  border: none;
  border-radius: var(--radius-lg, 12px);
  cursor: pointer;
  transition: box-shadow var(--motion-layout) var(--ease-out), transform var(--motion-press) var(--ease-out);
  letter-spacing: -0.01em;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.pwa-install-btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  transition: none;
  pointer-events: none;
}

.pwa-install-btn:hover::after {
  left: 130%;
  transition: left 0.6s ease;
}

.pwa-install-btn:hover {
  box-shadow: 0 0 24px rgba(99, 102, 241, 0.35), 0 0 48px rgba(99, 102, 241, 0.15);
}

.pwa-install-btn:active {
  transform: scale(0.97);
}

/* ── Skip link ──────────────────────────── */
.pwa-skip {
  margin-top: 24px;
  padding: 10px 20px;
  font-size: var(--text-sm, 0.8125rem);
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
  letter-spacing: 0.01em;
  opacity: 0.4;
}

.pwa-skip:hover {
  opacity: 0.6;
}

/* ── Fixed edge arrow (chevron) ─────────── */
.pwa-edge-arrow {
  position: fixed;
  z-index: var(--z-panel);
  pointer-events: none;
}

/* Safari iPhone — bottom right, aligned with ⋯ button */
.pwa-edge-arrow--bottom-right {
  bottom: 10px;
  right: 34px;
}

/* Chrome iOS / iPad / Android — top right */
.pwa-edge-arrow--top-right {
  top: 10px;
  right: 14px;
}

.pwa-edge-chevron {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 0 12px rgba(129, 140, 248, 0.7));
  animation: pwaChevronPulse 2s ease-in-out infinite;
}

@keyframes pwaChevronPulse {
  0%, 100% { opacity: 0.75; filter: drop-shadow(0 0 10px rgba(129, 140, 248, 0.5)); }
  50%      { opacity: 1; filter: drop-shadow(0 0 18px rgba(129, 140, 248, 0.8)); }
}

/* ── Light theme overrides ──────────────── */
[data-theme="light"] .pwa-phone-frame {
  border-color: rgba(0, 0, 0, 0.08);
  background: var(--bg-card);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .pwa-phone-frame::before {
  background: var(--bg-page);
}

[data-theme="light"] .pwa-phone-screen {
  background: var(--bg-page);
}

[data-theme="light"] .pwa-phone-skeleton-bar {
  background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .pwa-phone-frame::after {
  background: rgba(0, 0, 0, 0.1);
}

[data-theme="light"] #pwa-install-overlay::before {
  background: radial-gradient(ellipse at center, rgba(99, 102, 241, 0.04) 0%, transparent 60%);
}

[data-theme="light"] .pwa-steps-card {
  background: var(--bg-card);
  border-color: var(--border);
  border-top-color: var(--border);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.04),
    0 8px 32px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .pwa-steps-card::before {
  opacity: 0.35;
}

[data-theme="light"] .pwa-brand-compact .pwa-brand-icon {
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.1),
    0 0 48px rgba(99, 102, 241, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .pwa-brand-icon {
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.1),
    0 0 40px rgba(99, 102, 241, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .pwa-guide-step:not(:last-child)::after {
  background: rgba(99, 102, 241, 0.2);
}

/* ── Reduced motion ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #pwa-install-overlay {
    animation: none;
    opacity: 1;
  }

  #pwa-install-overlay.pwa-dismiss {
    animation: none;
    display: none;
  }

  .pwa-edge-chevron {
    animation: none;
    opacity: 1;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.5));
  }
}
