/* ===========================================================
   راویار — Data layer + i18n  (exposed on window.OMID)
   Bilingual: every display string has a Persian (fa) value and
   an English (en / *En) counterpart. Components localize through
   the helpers  L(fa,en)  and  TX(obj, key).
   =========================================================== */
(function () {
  // ----- language state -----
  let LANG = 'fa';
  function applyDir(l) {
    try {
      document.documentElement.lang = l;
      document.documentElement.dir = (l === 'en') ? 'ltr' : 'rtl';
    } catch (e) {}
  }
  const getLang = () => LANG;
  const setLang = (l) => { LANG = (l === 'en') ? 'en' : 'fa'; applyDir(LANG); return LANG; };

  // pick fa/en literal
  const L = (fa, en) => (LANG === 'en' ? (en != null ? en : fa) : fa);
  // pick a localized field off an object: TX(o) → o.en|o.fa ; TX(o,'tagline') → o.taglineEn|o.tagline
  const TX = (o, key) => {
    if (!o) return '';
    const base = key || 'fa';
    const enKey = (base === 'fa') ? 'en' : (base + 'En');
    if (LANG === 'en') return (o[enKey] != null ? o[enKey] : o[base]);
    return o[base];
  };

  // Persian digits helper + a language-aware number formatter
  const numFa = (s) => String(s).replace(/[0-9]/g, d => '۰۱۲۳۴۵۶۷۸۹'[d]);
  const toLatin = (s) => String(s).replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d));
  const num = (s) => (LANG === 'en' ? toLatin(s) : numFa(s));

  // — Thematic categories (موضوعات) —
  const CATEGORIES = [
    { id: 'epic',    fa: 'حماسی',    en: 'Epic',        hue: '#c4703a', icon: 'sword',  count: 42 },
    { id: 'love',    fa: 'عاشقانه',  en: 'Romance',     hue: '#d98a52', icon: 'heart',  count: 31 },
    { id: 'myth',    fa: 'اساطیری',  en: 'Mythology',   hue: '#45d6c8', icon: 'bird',   count: 28 },
    { id: 'history', fa: 'تاریخی',   en: 'Historical',  hue: '#4d82dd', icon: 'tower',  count: 36 },
    { id: 'sufi',    fa: 'عرفانی',   en: 'Mystical',    hue: '#1cb7ac', icon: 'sun',    count: 19 },
  ];

  // — Poets & authors (شاعران و نویسندگان) —
  const POETS = [
    { id: 'ferdowsi', fa: 'فردوسی',  en: 'Ferdowsi', era: 'قرن ۴ هـ', eraEn: '10th c.', works: 18, tint: '#c4703a' },
    { id: 'nezami',   fa: 'نظامی',   en: 'Nezami',   era: 'قرن ۶ هـ', eraEn: '12th c.', works: 14, tint: '#d98a52' },
    { id: 'attar',    fa: 'عطار',    en: 'Attar',    era: 'قرن ۶ هـ', eraEn: '12th c.', works: 11, tint: '#1cb7ac' },
    { id: 'molavi',   fa: 'مولوی',   en: 'Rumi',     era: 'قرن ۷ هـ', eraEn: '13th c.', works: 22, tint: '#45d6c8' },
    { id: 'saadi',    fa: 'سعدی',    en: 'Saadi',    era: 'قرن ۷ هـ', eraEn: '13th c.', works: 16, tint: '#d4a94c' },
    { id: 'hafez',    fa: 'حافظ',    en: 'Hafez',    era: 'قرن ۸ هـ', eraEn: '14th c.', works: 9,  tint: '#4d82dd' },
  ];

  // — Heroes / characters (قهرمانان) —
  const HEROES = [
    { fa: 'رستم', en: 'Rostam' }, { fa: 'سهراب', en: 'Sohrab' }, { fa: 'کاوهٔ آهنگر', en: 'Kaveh the Blacksmith' },
    { fa: 'آرش کمانگیر', en: 'Arash the Archer' }, { fa: 'سیمرغ', en: 'Simorgh' }, { fa: 'لیلی', en: 'Leyli' },
    { fa: 'مجنون', en: 'Majnun' }, { fa: 'شیرین', en: 'Shirin' }, { fa: 'فرهاد', en: 'Farhad' }, { fa: 'اسفندیار', en: 'Esfandiar' },
  ];

  // — Historical periods (دوره‌های تاریخی) —
  const ERAS = [
    { fa: 'اساطیری', en: 'Mythical' }, { fa: 'پیشدادی', en: 'Pishdadian' }, { fa: 'کیانی', en: 'Kayanian' },
    { fa: 'هخامنشی', en: 'Achaemenid' }, { fa: 'ساسانی', en: 'Sassanid' }, { fa: 'اسلامی', en: 'Islamic' },
  ];

  const STYLES = [
    { fa: 'کلاسیک', en: 'Classic' }, { fa: 'حماسی', en: 'Epic' }, { fa: 'غنایی', en: 'Lyric' },
    { fa: 'محاوره‌ای', en: 'Colloquial' }, { fa: 'سینمایی', en: 'Cinematic' },
  ];

  // — Stories — (cat = category id, poet = poet id)
  const STORIES = [
    { id: 'rostam-sohrab', fa: 'رستم و سهراب', en: 'Rostam & Sohrab', poet: 'ferdowsi', cat: 'epic',
      era: 'پهلوانی', eraEn: 'Heroic Age', hero: 'رستم', heroEn: 'Rostam', rating: 4.9, mins: 21, views: '۸۴ هزار', viewsEn: '84K', status: 'published',
      grad: ['#3a1a0e', '#8a3c1c', '#c4703a'],
      tagline: 'نبرد پدر و پسر؛ تراژدی ناشناختگی و سرنوشت.',
      taglineEn: 'A father and son at war — a tragedy of mistaken identity and fate.',
      verse: 'به کشتی گرفتن نهادند سر / گرفتند هر دو دوال کمر',
      verseEn: 'They set to wrestling, locked and grim — / each gripped the other\u2019s belt of war.',
      body: 'سهراب، فرزند برومند رستم و تهمینه، در پی یافتن پدر راهی ایران می‌شود. اما چرخ گردون چنان می‌چرخد که پدر و پسر، ناشناخته، در میدان نبرد روبه‌روی هم می‌ایستند…',
      bodyEn: 'Sohrab, the noble son of Rostam and Tahmineh, sets out for Iran to find his father. But fate turns its wheel so cruelly that father and son, unknown to one another, meet face to face on the field of battle…' },
    { id: 'leyli-majnun', fa: 'لیلی و مجنون', en: 'Leyli & Majnun', poet: 'nezami', cat: 'love',
      era: 'کلاسیک', eraEn: 'Classical', hero: 'مجنون', heroEn: 'Majnun', rating: 4.8, mins: 18, views: '۶۲ هزار', viewsEn: '62K', status: 'published',
      grad: ['#2a0f24', '#7a2b52', '#d98a52'],
      tagline: 'عشقی که از زمین به افسانه پیوست.',
      taglineEn: 'A love that passed from earth into legend.',
      verse: 'مرا عشق تو دیوانه‌ای کرد / که عاقل ز کارم کناره گرفت',
      verseEn: 'Your love has made a madman out of me — / the wise have drawn away from all I do.',
      body: 'قیس، جوان بنی‌عامر، چنان دل‌باختهٔ لیلی می‌شود که مردمان او را «مجنون» می‌خوانند. فراق، او را به دشت و بیابان می‌کشاند…',
      bodyEn: 'Qays, a youth of the Bani Amir, falls so deeply for Leyli that people call him "Majnun" — the madman. Separation drives him out into the wilderness…' },
    { id: 'zahhak-kaveh', fa: 'ضحاک و کاوه', en: 'Zahhak & Kaveh', poet: 'ferdowsi', cat: 'myth',
      era: 'پیشدادی', eraEn: 'Pishdadian', hero: 'کاوهٔ آهنگر', heroEn: 'Kaveh', rating: 4.9, mins: 24, views: '۹۷ هزار', viewsEn: '97K', status: 'published',
      grad: ['#0e2a2a', '#11605a', '#45d6c8'],
      tagline: 'قیام آهنگر بر ضدّ ماردوش؛ زایش درفش کاویانی.',
      taglineEn: 'A blacksmith\u2019s revolt against the serpent-king — and the birth of the Kaviani banner.',
      verse: 'بیامد به درگاه ضحاک شاه / برآشفت و بشکست بند کلاه',
      verseEn: 'He came before the court of Zahhak the king, / and in his rage he broke the crown\u2019s own bond.',
      body: 'ضحاک ماردوش، هزار سال بر ایران ستم می‌راند و مغز جوانان را خوراک ماران دوشش می‌کند. تا آنکه کاوهٔ آهنگر، پیش‌بند چرمین خویش را بر نیزه می‌کند…',
      bodyEn: 'Zahhak, the serpent-shouldered tyrant, ruled Iran for a thousand years, feeding the brains of its youths to the snakes on his shoulders — until Kaveh the blacksmith raised his leather apron upon a spear…' },
    { id: 'siavash', fa: 'گذر سیاوش از آتش', en: 'Siavash Through Fire', poet: 'ferdowsi', cat: 'myth',
      era: 'کیانی', eraEn: 'Kayanian', hero: 'سیاوش', heroEn: 'Siavash', rating: 4.9, mins: 22, views: '۸۹ هزار', viewsEn: '89K', status: 'published',
      grad: ['#06182c', '#11605a', '#45d6c8'],
      tagline: 'شاهزاده‌ای پاک‌دامن که برای اثبات بی‌گناهی از دل آتش گذشت.',
      taglineEn: 'A pure-hearted prince who rode through fire to prove his innocence.',
      verse: 'به‌سان سواری بر آتش گذشت / چو از کوهِ آتش سیاوش بِرَست',
      verseEn: 'Like a rider he passed straight through the flame — / and out of that mountain of fire, Siavash came free.',
      body: 'سیاوش، شاهزادهٔ آرمانی شاهنامه، آماج تهمت سودابه می‌شود. برای اثبات پاکی خویش، تن به آزمونِ آتش می‌سپارد و سوار بر اسبی سیاه، خرامان از کوهی از شعله می‌گذرد…',
      bodyEn: 'Siavash, the ideal prince of the Shahnameh, is falsely accused by Sudabeh. To prove his purity he submits to the ordeal of fire and, mounted on a black steed, rides calmly through a mountain of flame…' },
    { id: 'khosrow-shirin', fa: 'خسرو و شیرین', en: 'Khosrow & Shirin', poet: 'nezami', cat: 'love',
      era: 'ساسانی', eraEn: 'Sassanid', hero: 'شیرین', heroEn: 'Shirin', rating: 4.7, mins: 19, views: '۵۱ هزار', viewsEn: '51K', status: 'published',
      grad: ['#241033', '#5a2b7a', '#d98a52'],
      tagline: 'عشق شاهانه و تیشهٔ فرهاد بر بیستون.',
      taglineEn: 'A royal love — and Farhad\u2019s chisel upon Mount Bisotun.',
      verse: 'فلک جز عشق محرابی ندارد / جهان بی‌خاک عشق آبی ندارد',
      verseEn: 'The heavens hold no altar but for love; / without love\u2019s dust the world has not a drop of life.',
      body: 'خسرو پرویز، شاه ساسانی، دل به شیرینِ ارمنی می‌بازد. در این میان فرهادِ سنگ‌تراش نیز…',
      bodyEn: 'Khosrow Parviz, the Sassanid king, loses his heart to Shirin the Armenian. Meanwhile Farhad the stonecutter also falls for her…' },
    { id: 'simorgh-zal', fa: 'سیمرغ و زال', en: 'Simorgh & Zal', poet: 'ferdowsi', cat: 'myth',
      era: 'پیشدادی', eraEn: 'Pishdadian', hero: 'سیمرغ', heroEn: 'Simorgh', rating: 4.8, mins: 16, views: '۴۷ هزار', viewsEn: '47K', status: 'published',
      grad: ['#0e1c3a', '#1c4392', '#45d6c8'],
      tagline: 'کودکِ سپیدمو که سیمرغ او را پروراند.',
      taglineEn: 'The white-haired child raised by the mythical Simorgh.',
      verse: 'بدو گفت سیمرغ کای پهلوان / تو را پروراندم به جان و روان',
      verseEn: 'The Simorgh said: "O hero mine, / I raised you with my very soul and life."',
      body: 'زال، فرزند سام، با موهای سپید زاده می‌شود و در البرزکوه رها می‌گردد. سیمرغ او را می‌یابد و می‌پرورد…',
      bodyEn: 'Zal, son of Sam, is born with white hair and abandoned on Mount Alborz. The Simorgh finds him and raises him as her own…' },
    { id: 'sheikh-sanan', fa: 'شیخ صنعان', en: 'Sheikh San\u2019an', poet: 'attar', cat: 'sufi',
      era: 'کلاسیک', eraEn: 'Classical', hero: 'شیخ صنعان', heroEn: 'Sheikh San\u2019an', rating: 4.6, mins: 17, views: '۳۳ هزار', viewsEn: '33K', status: 'published',
      grad: ['#0e2626', '#11605a', '#1cb7ac'],
      tagline: 'پیرِ پارسا که عشق، ایمانش را به آزمون کشید.',
      taglineEn: 'A pious elder whose faith was tested by love.',
      verse: 'هر که را اسرار حق آموختند / مُهر کردند و دهانش دوختند',
      verseEn: 'Whoever was taught the secrets of the Truth — / their lips were sealed, their mouths were sewn in silence.',
      body: 'شیخ صنعان، پیرِ نام‌آور حرم، در خواب می‌بیند که در روم بت می‌پرستد. سفر او به دیار ترسایان…',
      bodyEn: 'Sheikh San\u2019an, a renowned elder of the sanctuary, dreams that he worships idols in Anatolia. His journey to the land of the Christians…' },
    { id: 'arash', fa: 'آرش کمانگیر', en: 'Arash the Archer', poet: 'ferdowsi', cat: 'epic',
      era: 'کیانی', eraEn: 'Kayanian', hero: 'آرش کمانگیر', heroEn: 'Arash', rating: 4.8, mins: 14, views: '۷۱ هزار', viewsEn: '71K', status: 'draft',
      grad: ['#2a1a0e', '#8a5c1c', '#e7c673'],
      tagline: 'پرتاب تیری که مرز ایران را تا جیحون کشید.',
      taglineEn: 'The arrow-shot that drew Iran\u2019s border all the way to the Oxus.',
      verse: 'برآمد ز البرز تیر و کمان / به جان آرش اندر، مرز ایران',
      verseEn: 'From Alborz rose the bow and arrow\u2019s flight — / and in Arash\u2019s life was set the bound of Iran.',
      body: 'برای پایان جنگ ایران و توران، آرش جان خویش را در تیر می‌نهد و از فراز دماوند آن را رها می‌کند…',
      bodyEn: 'To end the war between Iran and Turan, Arash pours his very life into a single arrow and looses it from the peak of Mount Damavand…' },
  ];

  // — Collections / rails —
  const COLLECTIONS = [
    { id: 'tonight', fa: 'برای امشب', en: 'For Tonight', ids: ['rostam-sohrab', 'leyli-majnun', 'siavash', 'khosrow-shirin', 'simorgh-zal'] },
    { id: 'epic',    fa: 'حماسه‌های شاهنامه', en: 'Epics of the Shahnameh', ids: ['rostam-sohrab', 'zahhak-kaveh', 'arash', 'simorgh-zal'] },
    { id: 'love',    fa: 'داستان‌های عاشقانه', en: 'Romances', ids: ['leyli-majnun', 'khosrow-shirin'] },
  ];

  // — AI services —
  const TEXT_MODELS = [
    { id: 'claude', name: 'Claude · Anthropic', tint: '#c4703a', note: 'روایت ادبی و منسجم', noteEn: 'Literary, coherent storytelling' },
    { id: 'gpt',    name: 'GPT-4o · OpenAI',    tint: '#1cb7ac', note: 'سریع و انعطاف‌پذیر', noteEn: 'Fast and flexible' },
    { id: 'gemini', name: 'Gemini · Google',    tint: '#4d82dd', note: 'چندوجهی و تحلیلی', noteEn: 'Multimodal and analytical' },
  ];
  const IMAGE_MODELS = [
    { id: 'dalle',    name: 'DALL·E 3',        sub: 'OpenAI',           tint: '#d4a94c', note: 'مفهومی و سریع', noteEn: 'Conceptual and fast' },
    { id: 'mj',       name: 'Midjourney',      sub: 'Replicate',        tint: '#45d6c8', note: 'کیفیت هنری بالا', noteEn: 'High artistic quality' },
    { id: 'sd',       name: 'Stable Diffusion',sub: 'Hugging Face',     tint: '#4d82dd', note: 'منعطف و قابل fine-tune', noteEn: 'Flexible and fine-tunable' },
    { id: 'firefly',  name: 'Adobe Firefly',   sub: 'Adobe',            tint: '#c4703a', note: 'سبک ایرانی/اسلامی کنترل‌شده', noteEn: 'Controlled Persian/Islamic style' },
  ];

  // — Premium gating (سکه-locked stories) —
  const FREE_IDS = ['rostam-sohrab', 'leyli-majnun', 'zahhak-kaveh', 'yusuf'];
  STORIES.forEach(s => { s.premium = !FREE_IDS.includes(s.id); s.unlockCost = 20; });

  // ===========================================================
  //  مدل درآمدی — سکه‌محور (coin economy)
  // ===========================================================

  const PLANS = [
    { id: 'free', fa: 'رایگان', en: 'Free', coins: 0, period: '', periodEn: '', tag: 'با تبلیغ موضوعی', tagEn: 'With themed ads', tint: '#a8b2d4',
      features: ['دسترسی به داستان‌های منتخب', 'کیفیت ۷۲۰p', 'کسب ۵+ سکه با هر تماشا', 'نمایش آگهی موضوعی بین داستان‌ها'],
      featuresEn: ['Access to selected stories', '720p quality', 'Earn 5+ coins per watch', 'Themed ads between stories'] },
    { id: 'plus', fa: 'بدون تبلیغ', en: 'Ad-Free', coins: 100, period: 'ماه', periodEn: 'mo', tag: 'محبوب‌ترین', tagEn: 'Most popular', popular: true, tint: '#45d6c8',
      features: ['حذف کامل تبلیغات', 'کیفیت ۱۰۸۰p', 'دسترسی کامل به آرشیو', 'تماشای آفلاین'],
      featuresEn: ['No ads at all', '1080p quality', 'Full archive access', 'Offline viewing'] },
    { id: 'vip', fa: 'برجسته', en: 'Premium', coins: 250, period: 'ماه', periodEn: 'mo', tag: 'تجربهٔ کامل', tagEn: 'The full experience', tint: '#d4a94c',
      features: ['کیفیت ۴K', 'تصاویر AI اختصاصیِ هر داستان', 'نسخهٔ صوتی با صدای نقالان', 'پخش هم‌زمان روی ۲ دستگاه'],
      featuresEn: ['4K quality', 'Dedicated AI art per story', 'Audio narration by storytellers', 'Stream on 2 devices at once'] },
  ];

  const COIN_BUNDLES = [
    { coins: 100, toman: '۸۹٬۰۰۰', tomanEn: '89,000', bonus: 0 },
    { coins: 300, toman: '۲۴۹٬۰۰۰', tomanEn: '249,000', bonus: 30, popular: true },
    { coins: 700, toman: '۵۲۹٬۰۰۰', tomanEn: '529,000', bonus: 120 },
  ];
  const COIN_EARN = [
    { fa: 'تماشای کامل هر داستان', en: 'Watch a full story', val: '۵+', valEn: '5+', icon: 'play' },
    { fa: 'تکمیل یک مجموعه', en: 'Complete a collection', val: '۵۰+', valEn: '50+', icon: 'layers' },
    { fa: 'ورود روزانه (استمرار)', en: 'Daily login streak', val: '۲+', valEn: '2+', icon: 'flame' },
    { fa: 'معرفی دوستان', en: 'Refer friends', val: '۳۰+', valEn: '30+', icon: 'users' },
  ];
  const COIN_SPEND = [
    { fa: 'اشتراک بدون تبلیغ', en: 'Ad-free subscription', val: '۱۰۰− / ماه', valEn: '100− / mo', icon: 'bell' },
    { fa: 'باز کردن داستان ویژه', en: 'Unlock a premium story', val: '۲۰−', valEn: '20−', icon: 'book' },
    { fa: 'تولید تصویر AI اختصاصی', en: 'Generate dedicated AI art', val: '۵۰−', valEn: '50−', icon: 'sparkle' },
  ];
  const WALLET = {
    balance: 320,
    history: [
      { fa: 'تماشای «رستم و سهراب»', en: 'Watched "Rostam & Sohrab"', val: '۵+', valEn: '5+', when: 'امروز ۱۴:۲۰', whenEn: 'Today 14:20', kind: 'in', pay: 'done' },
      { fa: 'شارژ کیف پول — زرین‌پال', en: 'Wallet top-up — ZarinPal', val: '۳۳۰+', valEn: '330+', when: 'امروز ۱۲:۰۵', whenEn: 'Today 12:05', kind: 'in', pay: 'pending', gateway: 'zarinpal', ref: 'ZP-۸۲۳۹۱' },
      { fa: 'اشتراک بدون تبلیغ — خرداد', en: 'Ad-free subscription — June', val: '۱۰۰−', valEn: '100−', when: '۱ خرداد', whenEn: 'Jun 1', kind: 'out', pay: 'done' },
      { fa: 'خرید بستهٔ ۳۰۰ سکه — Stripe', en: '300-coin bundle — Stripe', val: '۳۳۰+', valEn: '330+', when: '۱ خرداد', whenEn: 'Jun 1', kind: 'in', pay: 'done', gateway: 'stripe', ref: 'ch_۳Kx۹' },
      { fa: 'باز کردن «خسرو و شیرین»', en: 'Unlocked "Khosrow & Shirin"', val: '۲۰−', valEn: '20−', when: '۲۹ اردیبهشت', whenEn: 'May 19', kind: 'out', pay: 'done' },
      { fa: 'شارژ کیف پول — زرین‌پال', en: 'Wallet top-up — ZarinPal', val: '۱۰۰+', valEn: '100+', when: '۲۷ اردیبهشت', whenEn: 'May 17', kind: 'in', pay: 'failed', gateway: 'zarinpal', ref: 'ZP-۸۱۰۲۲' },
      { fa: 'تکمیل مجموعهٔ شاهنامه', en: 'Completed the Shahnameh collection', val: '۵۰+', valEn: '50+', when: '۲۵ اردیبهشت', whenEn: 'May 15', kind: 'in', pay: 'done' },
    ],
  };

  const PAY_STATUS = {
    done:    { fa: 'موفق',      en: 'Successful', tint: '#1cb7ac', icon: 'check' },
    pending: { fa: 'در انتظار', en: 'Pending',    tint: '#d4a94c', icon: 'clock' },
    failed:  { fa: 'ناموفق',    en: 'Failed',     tint: '#c4703a', icon: 'flame' },
  };

  const SOCIALS = [
    { id: 'instagram', fa: 'اینستاگرام', en: 'Instagram', handle: '@ravyar.myth', glyph: 'instagram', tint: '#d98a52' },
    { id: 'telegram', fa: 'تلگرام', en: 'Telegram', handle: '@ravyar_stories', glyph: 'telegram', tint: '#45d6c8' },
    { id: 'youtube', fa: 'یوتیوب', en: 'YouTube', handle: 'RavyarStories', glyph: 'youtube', tint: '#c4703a' },
    { id: 'x', fa: 'ایکس', en: 'X', handle: '@ravyar_myth', glyph: 'x', tint: '#a8b2d4' },
    { id: 'aparat', fa: 'آپارات', en: 'Aparat', handle: 'ravyar', glyph: 'aparat', tint: '#4d82dd' },
  ];

  const SUPPORT_CHANNELS = [
    { id: 'chat', fa: 'گفتگوی زنده', en: 'Live chat', sub: 'پاسخ‌گویی آنی · ۲۴ ساعته', subEn: 'Instant replies · 24/7', icon: 'chat', tint: '#45d6c8', meta: 'آنلاین', metaEn: 'Online' },
    { id: 'ticket', fa: 'ثبت تیکت', en: 'Open a ticket', sub: 'پاسخ تا کمتر از ۲ ساعت', subEn: 'Reply within 2 hours', icon: 'pen', tint: '#d4a94c', meta: 'پیگیری‌دار', metaEn: 'Tracked' },
    { id: 'call', fa: 'تماس تلفنی', en: 'Phone call', sub: '۰۲۱–۹۱۰۰۲۰۳۰ · ۹ تا ۲۱', subEn: '021-91002030 · 9am–9pm', icon: 'phone', tint: '#c4703a', meta: 'فوری', metaEn: 'Urgent' },
    { id: 'faq', fa: 'سؤالات متداول', en: 'FAQ', sub: 'پاسخ پرسش‌های پرتکرار', subEn: 'Answers to common questions', icon: 'book', tint: '#4d82dd', meta: '۴۲ مقاله', metaEn: '42 articles' },
  ];
  const FAQ = [
    { q: 'چطور سکه به‌دست بیاورم؟', qEn: 'How do I earn coins?',
      a: 'با تماشای کامل هر داستان، ورود روزانه، تکمیل مجموعه‌ها و معرفی دوستان سکه می‌گیرید. موجودی در کیف پول ذخیره می‌شود.',
      aEn: 'You earn coins by watching full stories, daily logins, completing collections, and referring friends. Your balance is stored in your wallet.' },
    { q: 'اشتراک بدون تبلیغ چطور کار می‌کند؟', qEn: 'How does the ad-free plan work?',
      a: 'ماهانه ۱۰۰ سکه از کیف پول شما کسر می‌شود و تبلیغات بین داستان‌ها به‌طور کامل حذف می‌گردد.',
      aEn: '100 coins are deducted from your wallet each month and all ads between stories are removed entirely.' },
    { q: 'پرداختم ناموفق شد، سکه کسر شده — چه کنم؟', qEn: 'My payment failed but coins were deducted — what now?',
      a: 'در «وضعیت پرداخت‌ها» تراکنش را با کد پیگیری ببینید. مبالغ ناموفق تا ۷۲ ساعت به‌صورت خودکار بازگردانده می‌شود.',
      aEn: 'Check the transaction with its reference code under "Payment status". Failed amounts are refunded automatically within 72 hours.' },
    { q: 'از کدام درگاه‌ها می‌توانم پرداخت کنم؟', qEn: 'Which payment gateways can I use?',
      a: 'زرین‌پال برای پرداخت داخلی (ریالی) و Stripe برای پرداخت بین‌المللی (ارزی).',
      aEn: 'ZarinPal for domestic (Rial) payments and Stripe for international (foreign-currency) payments.' },
  ];

  const NOTIFICATIONS = [
    { id: 'n1', fa: 'داستان تازه: «گذر سیاوش از آتش» منتشر شد', en: 'New story: "Siavash Through Fire" is live', when: '۱۰ دقیقه پیش', whenEn: '10 min ago', icon: 'sparkle', tint: '#45d6c8', unread: true, kind: 'content' },
    { id: 'n2', fa: 'شارژ کیف پول از زرین‌پال در انتظار تأیید است', en: 'ZarinPal wallet top-up awaiting confirmation', when: '۱ ساعت پیش', whenEn: '1 hour ago', icon: 'clock', tint: '#d4a94c', unread: true, kind: 'pay' },
    { id: 'n3', fa: 'پشتیبانی به تیکت شما پاسخ داد', en: 'Support replied to your ticket', when: '۳ ساعت پیش', whenEn: '3 hours ago', icon: 'chat', tint: '#c4703a', unread: true, kind: 'support' },
    { id: 'n4', fa: '۵ سکه بابت تماشای «رستم و سهراب» افزوده شد', en: '5 coins added for watching "Rostam & Sohrab"', when: 'امروز', whenEn: 'Today', icon: 'coin', tint: '#d4a94c', unread: false, kind: 'coin' },
    { id: 'n5', fa: 'اشتراک بدون تبلیغ شما ۶ روز دیگر تمدید می‌شود', en: 'Your ad-free plan renews in 6 days', when: 'دیروز', whenEn: 'Yesterday', icon: 'bell', tint: '#4d82dd', unread: false, kind: 'sub' },
  ];

  const AD_SAMPLE = { brand: 'نگارستانِ ایران', brandEn: 'Negarestan-e Iran', headline: 'کارگاه نگارگری و مینیاتور ایرانی — ثبت‌نام دورهٔ تابستان', headlineEn: 'Persian miniature & illumination workshop — enroll for summer', cat: 'myth', cta: 'اطلاعات بیشتر', ctaEn: 'Learn more' };
  const AD_CAMPAIGNS = [
    { id: 'a1', brand: 'نشر شاهنامه', brandEn: 'Shahnameh Press', cat: 'epic',    impr: '۲۱۴٬۰۰۰', imprEn: '214,000', ctr: '۳٫۸', ctrEn: '3.8', revenue: '۴۲٫۵', revenueEn: '42.5', status: 'active', fill: 92 },
    { id: 'a2', brand: 'نگارستانِ ایران', brandEn: 'Negarestan-e Iran', cat: 'myth', impr: '۱۸۶٬۰۰۰', imprEn: '186,000', ctr: '۴٫۱', ctrEn: '4.1', revenue: '۳۸٫۲', revenueEn: '38.2', status: 'active', fill: 88 },
    { id: 'a3', brand: 'بازی رستم‌نامه', brandEn: 'Rostam-nameh Game', cat: 'epic',  impr: '۱۵۲٬۰۰۰', imprEn: '152,000', ctr: '۵٫۲', ctrEn: '5.2', revenue: '۵۱٫۰', revenueEn: '51.0', status: 'active', fill: 95 },
    { id: 'a4', brand: 'فیروزهٔ نیشابور', brandEn: 'Nishapur Turquoise', cat: 'history', impr: '۹۸٬۴۰۰', imprEn: '98,400', ctr: '۲٫۹', ctrEn: '2.9', revenue: '۱۹٫۶', revenueEn: '19.6', status: 'paused', fill: 64 },
    { id: 'a5', brand: 'آموزشگاه نگارگری', brandEn: 'Miniature Academy', cat: 'myth', impr: '۷۶٬۲۰۰', imprEn: '76,200', ctr: '۳٫۴', ctrEn: '3.4', revenue: '۱۵٫۳', revenueEn: '15.3', status: 'review', fill: 0 },
    { id: 'a6', brand: 'موسیقی سنتی چنگ', brandEn: 'Chang Classical Music', cat: 'sufi', impr: '۶۴٬۸۰۰', imprEn: '64,800', ctr: '۲٫۶', ctrEn: '2.6', revenue: '۱۲٫۱', revenueEn: '12.1', status: 'active', fill: 71 },
  ];

  const REVENUE = {
    mrr: '۳۱۲', mrrEn: '312', adRevenue: '۱۷۸', adRevenueEn: '178', coinSales: '۲۴۶', coinSalesEn: '246',
    conversion: '۶٫۲', conversionEn: '6.2', arpu: '۴۸', arpuEn: '48', activeSubs: '۹٬۶۷۳', activeSubsEn: '9,673',
    planMix: [{ id: 'free', fa: 'رایگان', en: 'Free', pct: 71, tint: '#a8b2d4' }, { id: 'plus', fa: 'بدون تبلیغ', en: 'Ad-Free', pct: 21, tint: '#45d6c8' }, { id: 'vip', fa: 'برجسته', en: 'Premium', pct: 8, tint: '#d4a94c' }],
    months: [42, 51, 47, 58, 63, 69, 74, 81, 78, 88, 96, 104],
  };

  const GATEWAYS = [
    { id: 'zarinpal', fa: 'زرین‌پال', en: 'ZarinPal', sub: 'پرداخت داخلی · ریالی', subEn: 'Domestic · Rial', badge: 'داخلی', badgeEn: 'Domestic', tint: '#ffc627', mark: 'Z' },
    { id: 'stripe', fa: 'Stripe', en: 'Stripe', sub: 'پرداخت بین‌المللی · ارزی', subEn: 'International · FX', badge: 'خارجی', badgeEn: 'Global', tint: '#635bff', mark: 'S' },
  ];
  const AI_CONNECTIONS = [
    { name: 'OpenAI', kind: 'متن + تصویر', kindEn: 'Text + Image', status: 'connected', tint: '#1cb7ac' },
    { name: 'Anthropic Claude', kind: 'متن', kindEn: 'Text', status: 'connected', tint: '#c4703a' },
    { name: 'Google Gemini', kind: 'متن', kindEn: 'Text', status: 'connected', tint: '#4d82dd' },
    { name: 'Replicate · MJ/SD', kind: 'تصویر', kindEn: 'Image', status: 'connected', tint: '#45d6c8' },
    { name: 'Adobe Firefly', kind: 'تصویر', kindEn: 'Image', status: 'pending', tint: '#d4a94c' },
  ];

  const PROVIDERS = [
    { id: 'openai', name: 'OpenAI', kind: 'متن + تصویر', kindEn: 'Text + Image', tint: '#1cb7ac', keyLabel: 'API Key', placeholder: 'sk-···', base: 'https://api.openai.com/v1', models: ['GPT-4o', 'GPT-4 Turbo', 'DALL·E 3'], status: 'connected', docs: 'platform.openai.com' },
    { id: 'anthropic', name: 'Anthropic Claude', kind: 'متن', kindEn: 'Text', tint: '#c4703a', keyLabel: 'API Key', placeholder: 'sk-ant-···', base: 'https://api.anthropic.com', models: ['Claude Opus 4', 'Claude Sonnet 4', 'Claude Haiku'], status: 'connected', docs: 'console.anthropic.com' },
    { id: 'gemini', name: 'Google Gemini', kind: 'متن', kindEn: 'Text', tint: '#4d82dd', keyLabel: 'API Key', placeholder: 'AIza···', base: 'https://generativelanguage.googleapis.com', models: ['Gemini 2.5 Pro', 'Gemini 2.5 Flash'], status: 'connected', docs: 'aistudio.google.com' },
    { id: 'replicate', name: 'Replicate · MJ/SD', kind: 'تصویر', kindEn: 'Image', tint: '#45d6c8', keyLabel: 'API Token', placeholder: 'r8_···', base: 'https://api.replicate.com/v1', models: ['Midjourney proxy', 'SDXL', 'Stable Diffusion 3'], status: 'connected', docs: 'replicate.com' },
    { id: 'firefly', name: 'Adobe Firefly', kind: 'تصویر', kindEn: 'Image', tint: '#d4a94c', keyLabel: 'Client ID', secret: 'Client Secret', placeholder: 'firefly-client-id', base: 'https://firefly-api.adobe.io', models: ['Firefly Image 3'], status: 'pending', docs: 'developer.adobe.com' },
  ];
  const AUTOMATION_DEFAULTS = {
    autoPublish: false, moderation: true, watermark: true, concurrency: 3,
    imageSize: '1024×1024', outputLang: 'فارسی', retries: 2,
  };

  window.OMID = { CATEGORIES, POETS, HEROES, ERAS, STYLES, STORIES, COLLECTIONS, TEXT_MODELS, IMAGE_MODELS,
    PLANS, COIN_BUNDLES, COIN_EARN, COIN_SPEND, WALLET, PAY_STATUS, SOCIALS, SUPPORT_CHANNELS, FAQ, NOTIFICATIONS, AD_SAMPLE, AD_CAMPAIGNS, REVENUE, GATEWAYS, AI_CONNECTIONS, PROVIDERS, AUTOMATION_DEFAULTS,
    numFa, num, toLatin, getLang, setLang, L, TX,
    byId: (id) => STORIES.find(s => s.id === id),
    catOf: (id) => CATEGORIES.find(c => c.id === id),
    poetOf: (id) => POETS.find(p => p.id === id),
  };
  // expose helpers globally for terse use in screens
  window.L = L; window.TX = TX;
})();
