@tailwind base;
@tailwind components;
@tailwind utilities;

/*
 * ── Anti-flicker: pause GPU-heavy animations when app is in background ──
 * Telegram WebView on older devices drops the GPU context when minimized.
 * Re-compositing large blur layers + CSS animations on restore causes a
 * visible flash. We hide the root while backgrounded and fade it back in.
 */
html.is-hidden #root {
  visibility: hidden;
}

html.is-hidden *,
html.is-hidden *::before,
html.is-hidden *::after {
  animation-play-state: paused !important;
  transition: none !important;
}

/* Promote heavy animated layers to their own compositor surface */
.starfield,
.starfield-twinkle,
.cosmic-stars,
.aurora-particles {
  will-change: opacity;
  contain: strict;
}

/* Космический градиентный фон */
@layer base {
  :root {
    --cosmic-gradient: linear-gradient(
      135deg,
      #0f0a1f 0%,
      #1a0f2e 25%,
      #0d1b2a 50%,
      #1a0f2e 75%,
      #0f0a1f 100%
    );
    --nebula-gradient:
      radial-gradient(
        ellipse at 30% 20%,
        rgba(124, 58, 237, 0.3) 0%,
        transparent 50%
      ),
      radial-gradient(
        ellipse at 70% 80%,
        rgba(236, 72, 153, 0.25) 0%,
        transparent 50%
      ),
      radial-gradient(
        ellipse at 60% 40%,
        rgba(6, 182, 212, 0.2) 0%,
        transparent 40%
      );

    /* Cosmic dark mode colors */
    --cosmic-bg-primary: rgba(15, 10, 31, 0.95);
    --cosmic-bg-secondary: rgba(15, 10, 31, 0.8);
    --cosmic-bg-card: rgba(15, 10, 31, 0.6);
    --cosmic-border: rgba(139, 92, 246, 0.2);
    --cosmic-border-hover: rgba(139, 92, 246, 0.4);

    /* Premium pearl light mode colors */
    --pearl-shell-bg:
      radial-gradient(
        circle at top left,
        rgba(191, 219, 254, 0.52) 0%,
        transparent 28%
      ),
      radial-gradient(
        circle at 82% 14%,
        rgba(196, 181, 253, 0.34) 0%,
        transparent 24%
      ),
      radial-gradient(
        circle at 50% 100%,
        rgba(226, 232, 240, 0.65) 0%,
        transparent 42%
      ),
      linear-gradient(
        180deg,
        rgba(250, 248, 255, 0.98) 0%,
        rgba(245, 247, 252, 0.97) 48%,
        rgba(237, 242, 247, 0.96) 100%
      );
    --pearl-surface:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.88) 0%,
        rgba(248, 250, 252, 0.84) 100%
      );
    --pearl-surface-strong:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.96) 0%,
        rgba(247, 249, 252, 0.92) 100%
      );
    --pearl-surface-inset:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.72) 0%,
        rgba(241, 245, 249, 0.84) 100%
      );
    --pearl-border: rgba(148, 163, 184, 0.22);
    --pearl-border-strong: rgba(129, 140, 248, 0.24);
    --pearl-text: #182132;
    --pearl-text-muted: #475569;
    --pearl-text-soft: #7b8798;
    --pearl-violet: #7c3aed;
    --pearl-violet-bright: #8b5cf6;
    --pearl-cyan: #0f9ab8;
    --pearl-danger: #be3455;
    --pearl-shadow:
      0 22px 60px rgba(148, 163, 184, 0.16),
      0 8px 24px rgba(99, 102, 241, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
    --pearl-shadow-strong:
      0 28px 90px rgba(148, 163, 184, 0.22),
      0 16px 40px rgba(99, 102, 241, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.96);

    /* Safe Area Variables */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
  }

  /* Тёмный космический фон для основного приложения */
  .dark body,
  .dark .cosmic-bg {
    background: var(--cosmic-gradient);
    background-size: 200% 200%;
    animation: cosmic-shift 20s ease-in-out infinite;
    position: relative;
  }

  .dark body::before,
  .dark .cosmic-bg::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--nebula-gradient);
    pointer-events: none;
    z-index: -1;
  }

  /* Telegram WebApp Specific Styles */
  .telegram-webapp {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
  }

  /* Плавный скролл и предотвращение рывков */
  html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
  }

  body {
    overscroll-behavior-y: none;
    overscroll-behavior-x: none;
  }

  /* Глобальное переопределение серых цветов в dark mode */
  .dark .bg-gray-800,
  .dark .dark\:bg-gray-800 {
    background-color: var(--cosmic-bg-secondary) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .dark .bg-gray-900,
  .dark .dark\:bg-gray-900 {
    background-color: var(--cosmic-bg-primary) !important;
  }

  .dark .bg-gray-700,
  .dark .dark\:bg-gray-700 {
    background-color: rgba(139, 92, 246, 0.15) !important;
  }

  /* Границы в dark mode */
  .dark .border-gray-700,
  .dark .dark\:border-gray-700 {
    border-color: var(--cosmic-border) !important;
  }

  .dark .border-gray-600,
  .dark .dark\:border-gray-600 {
    border-color: var(--cosmic-border) !important;
  }

  /* Звёздный эффект - Реалистичный космос */
  .cosmic-stars,
  .starfield {
    background-image:
      radial-gradient(1px 1px at 25% 10%, #fff, transparent),
      radial-gradient(1px 1px at 50% 40%, #fff, transparent),
      radial-gradient(1px 1px at 10% 80%, #fff, transparent),
      radial-gradient(1.5px 1.5px at 75% 65%, #fff, transparent),
      radial-gradient(1px 1px at 90% 30%, #fff, transparent),
      radial-gradient(1px 1px at 35% 85%, #fff, transparent),
      radial-gradient(1.5px 1.5px at 60% 15%, #fff, transparent),
      radial-gradient(1px 1px at 20% 50%, #fff, transparent);
    background-size: 400px 400px;
    animation: twinkle 6s ease-in-out infinite alternate;
    position: relative;
    opacity: 0.9 !important;
  }

  .cosmic-stars::before,
  .starfield::before,
  .cosmic-stars::after,
  .starfield::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-repeat: repeat;
  }

  /* Слой с цветными звездами */
  .cosmic-stars::before,
  .starfield::before {
    background-image:
      radial-gradient(1.5px 1.5px at 15% 15%, #a5f3fc, transparent),
      radial-gradient(2px 2px at 45% 45%, #f0abfc, transparent),
      radial-gradient(1.5px 1.5px at 75% 25%, #8b5cf6, transparent),
      radial-gradient(2.5px 2.5px at 85% 85%, #fff, transparent);
    background-size: 600px 600px;
    animation: twinkle 4s ease-in-out infinite alternate-reverse;
  }

  /* Слой с крупными редкими звездами */
  .cosmic-stars::after,
  .starfield::after {
    background-image:
      radial-gradient(2.5px 2.5px at 30% 70%, #fff, transparent),
      radial-gradient(3px 3px at 70% 30%, #fff, transparent),
      radial-gradient(2.5px 2.5px at 10% 10%, #fff, transparent);
    background-size: 900px 900px;
    animation: twinkle 8s ease-in-out infinite alternate;
  }
}

@layer components {
  /* Космическая карточка с глассморфизмом */
  .cosmic-card {
    background: rgba(15, 10, 31, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(139, 92, 246, 0.2);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.3),
      inset 0 1px 0 rgba(255, 255, 255, 0.05);
  }

  .cosmic-card:hover {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow:
      0 8px 32px rgba(139, 92, 246, 0.15),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }

  /* Космическая кнопка */
  .cosmic-button {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    box-shadow:
      0 4px 15px rgba(139, 92, 246, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
  }

  .cosmic-button:hover {
    background: linear-gradient(135deg, #a78bfa 0%, #8b5cf6 100%);
    box-shadow:
      0 6px 20px rgba(139, 92, 246, 0.6),
      inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
  }

  /* Светящийся текст */
  .cosmic-glow-text {
    text-shadow:
      0 0 10px rgba(139, 92, 246, 0.5),
      0 0 20px rgba(139, 92, 246, 0.3),
      0 0 30px rgba(139, 92, 246, 0.2);
  }

  /* Светящаяся граница */
  .cosmic-border-glow {
    box-shadow:
      0 0 5px rgba(139, 92, 246, 0.3),
      0 0 10px rgba(139, 92, 246, 0.2),
      0 0 15px rgba(139, 92, 246, 0.1);
  }

  /* Сайдбар с космическим стилем */
  .cosmic-sidebar {
    background: linear-gradient(
      180deg,
      rgba(15, 10, 31, 0.95) 0%,
      rgba(26, 15, 46, 0.9) 50%,
      rgba(15, 10, 31, 0.95) 100%
    );
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid rgba(139, 92, 246, 0.15);
  }

  .light-driver-shell {
    background: var(--pearl-shell-bg);
    color: var(--pearl-text);
  }

  .light-pearl-card {
    background: var(--pearl-surface);
    border: 1px solid var(--pearl-border);
    box-shadow: var(--pearl-shadow);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
  }

  .light-pearl-elevated {
    background: var(--pearl-surface-strong);
    border: 1px solid rgba(167, 139, 250, 0.2);
    box-shadow: var(--pearl-shadow-strong);
    backdrop-filter: blur(26px) saturate(160%);
    -webkit-backdrop-filter: blur(26px) saturate(160%);
  }

  .light-pearl-inset {
    background: var(--pearl-surface-inset);
    border: 1px solid rgba(203, 213, 225, 0.75);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.88),
      0 10px 24px rgba(148, 163, 184, 0.1);
    backdrop-filter: blur(14px) saturate(145%);
    -webkit-backdrop-filter: blur(14px) saturate(145%);
  }

  .light-pearl-chip {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(196, 181, 253, 0.34);
    box-shadow:
      0 10px 24px rgba(99, 102, 241, 0.08),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
    color: var(--pearl-violet);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
  }

  .light-pearl-icon-button {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.94) 0%,
        rgba(243, 246, 250, 0.94) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.82);
    box-shadow:
      0 14px 30px rgba(148, 163, 184, 0.16),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
    color: var(--pearl-text-muted);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .light-pearl-primary-btn {
    background: linear-gradient(
      135deg,
      #6d3df2 0%,
      #8b5cf6 58%,
      #6d7bff 100%
    );
    border: 1px solid rgba(139, 92, 246, 0.36);
    box-shadow:
      0 20px 36px rgba(109, 61, 242, 0.28),
      0 8px 18px rgba(129, 140, 248, 0.16),
      inset 0 1px 0 rgba(255, 255, 255, 0.24);
    color: #fff;
  }

  .light-pearl-primary-btn:hover {
    box-shadow:
      0 24px 44px rgba(109, 61, 242, 0.3),
      0 10px 22px rgba(129, 140, 248, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.28);
    transform: translateY(-1px);
  }

  .light-pearl-muted-btn {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.84) 0%,
        rgba(241, 245, 249, 0.95) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.92);
    box-shadow:
      0 12px 28px rgba(148, 163, 184, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.94);
    color: #64748b;
  }

  .light-pearl-danger-btn {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.82) 0%,
        rgba(255, 241, 243, 0.94) 100%
      );
    border: 1px solid rgba(251, 113, 133, 0.3);
    box-shadow:
      0 14px 30px rgba(251, 113, 133, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
    color: #be3455;
  }

  .light-pearl-map-btn {
    background:
      linear-gradient(
        135deg,
        rgba(233, 248, 255, 0.96) 0%,
        rgba(219, 234, 254, 0.9) 100%
      );
    border: 1px solid rgba(125, 211, 252, 0.48);
    box-shadow:
      0 18px 34px rgba(125, 211, 252, 0.18),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
    color: var(--pearl-cyan);
  }

  .light-pearl-price {
    background:
      linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.96) 0%,
        rgba(244, 247, 255, 0.92) 100%
      );
    border: 1px solid rgba(196, 181, 253, 0.38);
    box-shadow:
      0 16px 30px rgba(129, 140, 248, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.96);
    color: var(--pearl-text);
  }

  .light-pearl-overlay {
    background:
      linear-gradient(
        180deg,
        rgba(247, 244, 255, 0.84) 0%,
        rgba(239, 244, 251, 0.72) 100%
      );
    backdrop-filter: blur(18px) saturate(150%);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
  }

  .light-pearl-sidebar {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.88) 0%,
        rgba(245, 247, 252, 0.94) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.72);
    box-shadow:
      0 24px 64px rgba(148, 163, 184, 0.16),
      inset 0 1px 0 rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(24px) saturate(155%);
    -webkit-backdrop-filter: blur(24px) saturate(155%);
  }

  .light-pearl-header {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.82) 0%,
        rgba(244, 247, 252, 0.9) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.66);
    box-shadow:
      0 18px 40px rgba(148, 163, 184, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(150%);
    -webkit-backdrop-filter: blur(20px) saturate(150%);
  }

  .light-pearl-field {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.86) 0%,
        rgba(243, 246, 250, 0.94) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.84);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.94),
      0 10px 24px rgba(148, 163, 184, 0.1);
    color: var(--pearl-text);
  }

  .light-pearl-pill {
    background:
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.9) 0%,
        rgba(243, 246, 250, 0.96) 100%
      );
    border: 1px solid rgba(203, 213, 225, 0.84);
    box-shadow:
      0 10px 24px rgba(148, 163, 184, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.92);
  }

  .light-pearl-text {
    color: var(--pearl-text);
  }

  .light-pearl-text-muted {
    color: var(--pearl-text-muted);
  }

  .light-pearl-text-soft {
    color: var(--pearl-text-soft);
  }

  html:not(.dark) .profile-shell {
    background:
      radial-gradient(
        circle at top left,
        rgba(184, 230, 249, 0.42) 0%,
        transparent 28%
      ),
      radial-gradient(
        circle at top right,
        rgba(255, 181, 216, 0.2) 0%,
        transparent 26%
      ),
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.98) 0%,
        rgba(248, 250, 252, 0.97) 55%,
        rgba(241, 245, 249, 0.98) 100%
      );
    color: #0f172a;
  }

  html:not(.dark) .profile-panel {
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(148, 163, 184, 0.22);
    box-shadow:
      0 18px 48px rgba(148, 163, 184, 0.16),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  html:not(.dark) .profile-card {
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow:
      0 10px 30px rgba(148, 163, 184, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.85);
  }

  html:not(.dark) .profile-card:hover {
    background: rgba(255, 255, 255, 0.99);
    border-color: rgba(99, 102, 241, 0.22);
    box-shadow:
      0 16px 36px rgba(99, 102, 241, 0.12),
      inset 0 1px 0 rgba(255, 255, 255, 0.95);
  }

  html:not(.dark) .profile-icon-surface {
    background: linear-gradient(
      135deg,
      rgba(248, 250, 252, 0.98) 0%,
      rgba(241, 245, 249, 0.95) 100%
    );
    border: 1px solid rgba(148, 163, 184, 0.16);
    color: #334155;
  }

  html:not(.dark) .profile-chip {
    background: rgba(248, 250, 252, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95);
    color: #0f172a;
  }

  html:not(.dark) .profile-stat-success {
    background: linear-gradient(
      135deg,
      rgba(236, 253, 245, 0.98) 0%,
      rgba(220, 252, 231, 0.92) 100%
    );
    border: 1px solid rgba(34, 197, 94, 0.16);
    box-shadow: 0 10px 26px rgba(34, 197, 94, 0.08);
  }

  html:not(.dark) .profile-stat-violet {
    background: linear-gradient(
      135deg,
      rgba(250, 245, 255, 0.98) 0%,
      rgba(243, 232, 255, 0.92) 100%
    );
    border: 1px solid rgba(168, 85, 247, 0.16);
    box-shadow: 0 10px 26px rgba(168, 85, 247, 0.08);
  }

  html:not(.dark) .profile-strong {
    color: #0f172a !important;
  }

  html:not(.dark) .profile-quiet {
    color: #475569 !important;
  }

  html:not(.dark) .profile-subtle {
    color: #64748b !important;
  }

  html:not(.dark) .profile-soft-danger {
    background: rgba(254, 242, 242, 0.96);
    border: 1px solid rgba(248, 113, 113, 0.18);
    color: #b91c1c;
    box-shadow: 0 10px 24px rgba(248, 113, 113, 0.08);
  }
}

@layer utilities {
  /* Telegram viewport height — prefer stable-height to avoid
     layout jitter when the Mini App is minimized / restored */
  .h-tg-viewport {
    height: 100vh;
    height: 100dvh;
    height: var(--tg-viewport-stable-height, var(--tg-viewport-height, 100dvh));
  }

  .min-h-tg-viewport {
    min-height: 100vh;
    min-height: 100dvh;
    min-height: var(--tg-viewport-stable-height, var(--tg-viewport-height, 100dvh));
  }

  /* Анимация космического сдвига градиента */
  @keyframes cosmic-shift {
    0%,
    100% {
      background-position: 0% 50%;
    }

    50% {
      background-position: 100% 50%;
    }
  }

  /* Мерцание звёзд — очень мягкое, чтобы не вызывать видимый flicker */
  @keyframes twinkle {
    0%,
    100% {
      opacity: 1;
    }

    50% {
      opacity: 0.88;
    }
  }

  /* Анимация орбиты для декоративных элементов */
  @keyframes cosmic-orbit {
    from {
      transform: rotate(0deg) translateX(100px) rotate(0deg);
    }

    to {
      transform: rotate(360deg) translateX(100px) rotate(-360deg);
    }
  }
  /* Анимация пульсации маркера на карте */
  @keyframes marker-pulse {
    0% {
      box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.7);
    }
    70% {
      box-shadow: 0 0 0 15px rgba(0, 229, 255, 0);
    }
    100% {
      box-shadow: 0 0 0 0 rgba(0, 229, 255, 0);
    }
  }

  .pickup-marker-pulse {
    animation: marker-pulse 2s infinite;
  }
}

/* ===== FLUID TYPOGRAPHY (clamp) ===== */
.fluid-order-address {
  font-size: clamp(0.75rem, 2.5vw, 0.9375rem);
  line-height: 1.2;
}

.fluid-order-price {
  font-size: clamp(1rem, 4vw, 1.375rem);
}

.fluid-order-meta {
  font-size: clamp(0.5625rem, 1.8vw, 0.6875rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 900;
}

/* ===== ORDER CARD ENTER ANIMATION ===== */
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.order-card-anim {
  animation: card-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.order-card-anim:nth-child(1) {
  animation-delay: 0ms;
}

.order-card-anim:nth-child(2) {
  animation-delay: 55ms;
}

.order-card-anim:nth-child(3) {
  animation-delay: 110ms;
}

.order-card-anim:nth-child(4) {
  animation-delay: 165ms;
}

.order-card-anim:nth-child(5) {
  animation-delay: 220ms;
}

.order-card-anim:nth-child(n + 6) {
  animation-delay: 275ms;
}
