const RAYA = {
  color: {
    brand: '#0068FF',
    brandDark: '#0050C7',
    brandSoft: 'rgba(0,104,255,0.08)',
    brandTint: 'rgba(0,104,255,0.14)',

    ink: '#333333',
    ink80: '#4A4A4A',
    ink60: '#6B6B6B',
    ink40: '#9A9A9A',
    ink20: '#D4D4D4',
    ink10: '#EAEAEA',
    ink05: '#F5F5F5',

    paper: '#FFFFFF',
    cream: '#F7F8FB',
    sand: '#E8ECF3',

    gold: 'oklch(0.78 0.08 75)',
    goldSoft: 'oklch(0.95 0.04 75)',
    sea: 'oklch(0.78 0.10 210)',

    white: '#FFFFFF',
    success: '#1A8754',
    danger: '#D42B4E',
  },

  font: {
    displayEn: "'Alexandria', 'Inter', -apple-system, system-ui, sans-serif",
    displayAr: "'Cairo', 'Tajawal', 'Noto Kufi Arabic', sans-serif",
    bodyEn: "'Alexandria', 'Inter', -apple-system, system-ui, sans-serif",
    bodyAr: "'Tajawal', 'Cairo', -apple-system, sans-serif",
    mono: "'JetBrains Mono', ui-monospace, monospace",
  },

  type: {
    arLine: 1.55,
    enLine: 1.35,
    arDisplayLine: 1.25,
    enDisplayLine: 1.1,
    arTrack: 0,
    enTrack: -0.01,
    arDisplayTrack: 0,
    enDisplayTrack: -0.02,
    arDisplayWeight: 700,
    arBodyWeight: 500,
    arTitleWeight: 600,
  },

  r: {
    xs: 8,
    sm: 12,
    md: 16,
    lg: 22,
    xl: 28,
    pill: 9999,
  },

  s: (n) => n * 4,

  shadow: {
    card: '0 1px 2px rgba(10,22,40,0.04), 0 12px 32px rgba(10,22,40,0.06)',
    cardHover: '0 2px 6px rgba(10,22,40,0.05), 0 20px 48px rgba(10,22,40,0.10)',
    float: '0 2px 8px rgba(10,22,40,0.06), 0 22px 48px rgba(10,22,40,0.14)',
    dock: '0 -2px 6px rgba(10,22,40,0.04), 0 -18px 40px rgba(10,22,40,0.08)',
    pin: '0 1px 3px rgba(10,22,40,0.10), 0 6px 18px rgba(10,22,40,0.14)',
    pinActive: '0 2px 6px rgba(10,22,40,0.18), 0 10px 28px rgba(10,22,40,0.22)',
  },
};

if (typeof document !== 'undefined' && !document.getElementById('raya-base')) {
  const s = document.createElement('style');
  s.id = 'raya-base';
  s.textContent = `
    @import url('https://fonts.googleapis.com/css2?family=Alexandria:wght@300;400;500;600;700;800&family=Tajawal:wght@300;400;500;700;800;900&family=Cairo:wght@400;500;600;700;800;900&display=swap');

    [dir="rtl"] {
      font-feature-settings: "kern" on, "liga" on, "calt" on;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-rendering: optimizeLegibility;
    }
    [lang="ar"]  { font-feature-settings: "kern" on, "liga" on, "calt" on; }

    [dir="ltr"] {
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
      text-rendering: optimizeLegibility;
    }

    .raya-scroll::-webkit-scrollbar { display: none; }
    .raya-scroll { scrollbar-width: none; -ms-overflow-style: none; }

    .raya-btn:active { transform: scale(0.97); }
    .raya-btn { transition: transform 0.12s ease, background 0.12s ease; }

    .raya-card { transition: transform 0.2s ease, box-shadow 0.2s ease; }
    .raya-card:hover { transform: translateY(-2px); }

    .raya-tap { transition: background 0.12s ease, transform 0.12s ease; cursor: pointer; }
    .raya-tap:active { transform: scale(0.96); }

    @keyframes raya-fadein {
      from { opacity: 0; transform: translateY(8px); }
      to { opacity: 1; transform: translateY(0); }
    }
    .raya-fadein { animation: raya-fadein 0.35s cubic-bezier(.2,.7,.3,1) both; }

    @keyframes raya-slidein {
      from { opacity: 0; transform: translateX(var(--slide-dir, 20px)); }
      to { opacity: 1; transform: translateX(0); }
    }

    .raya-shimmer {
      background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
      background-size: 200% 100%;
      animation: raya-shimmer 1.5s infinite;
    }
    @keyframes raya-shimmer {
      0% { background-position: -200% 0; }
      100% { background-position: 200% 0; }
    }

    .raya-heart-pulse { animation: heart-pulse 0.5s cubic-bezier(.2,.7,.3,1); }
    @keyframes heart-pulse {
      0% { transform: scale(1); }
      40% { transform: scale(1.35); }
      100% { transform: scale(1); }
    }

    @keyframes raya-pulse {
      0%, 100% { opacity: 0.35; transform: scale(0.9); }
      50% { opacity: 1; transform: scale(1.15); }
    }
  `;
  document.head.appendChild(s);
}

window.RAYA = RAYA;

const CURRENCIES = {
  EGP: { code: 'EGP', symbol: 'ج.م', pos: 'after', rate: 1, name_ar: 'جنيه مصري', name_en: 'Egyptian Pound', flag: '🇪🇬' },
  USD: { code: 'USD', symbol: '$', pos: 'before', rate: 0.021, name_ar: 'دولار أمريكي', name_en: 'US Dollar', flag: '🇺🇸' },
  EUR: { code: 'EUR', symbol: '€', pos: 'before', rate: 0.019, name_ar: 'يورو', name_en: 'Euro', flag: '🇪🇺' },
  SAR: { code: 'SAR', symbol: 'ر.س', pos: 'after', rate: 0.079, name_ar: 'ريال سعودي', name_en: 'Saudi Riyal', flag: '🇸🇦' },
  AED: { code: 'AED', symbol: 'د.إ', pos: 'after', rate: 0.077, name_ar: 'درهم إماراتي', name_en: 'UAE Dirham', flag: '🇦🇪' },
  KWD: { code: 'KWD', symbol: 'د.ك', pos: 'after', rate: 0.0065, name_ar: 'دينار كويتي', name_en: 'Kuwaiti Dinar', flag: '🇰🇼' },
};

function formatPrice(amountEgp, currencyCode = 'EGP', opts = {}) {
  const c = CURRENCIES[currencyCode] || CURRENCIES.EGP;
  const converted = amountEgp * c.rate;
  const rounded = converted >= 100 ? Math.round(converted) : Math.round(converted * 10) / 10;
  const num = rounded.toLocaleString('en-US');
  return c.pos === 'before' ? `${c.symbol}${num}` : `${num} ${c.symbol}`;
}

window.RAYA_CURRENCY = { CURRENCIES, formatPrice };
