/**
 * توجه: بر خلاف بقیه‌ی بلوک‌های این مجموعه، اینجا عمداً direction ثابت (rtl)
 * تحمیل نمی‌شود. جهت از صفحه/عنصر والد به ارث می‌رسد.
 *
 * نکته‌ی فنی مهم درباره‌ی جهت حرکت ریل: برای اینکه حلقه‌ی بی‌درز مرور محتوا
 * درست کار کند، ریل داخلی همیشه به یک روش ثابت (translateX منفی) پیمایش
 * می‌شود. برای اینکه از دید کاربر، محتوا در سایت‌های راست‌چین از چپ وارد و
 * زیر جعبه‌ی عنوان (که سمت راست است) ناپدید شود - نه برعکس - کل ویوپورت با
 * transform: scaleX(-1) آینه می‌شود و هر آیتم داخل آن دوباره scaleX(-1)
 * می‌شود تا متن/تصویرش دوباره درست (غیرآینه‌ای) دیده شود. این روش، بر خلاف
 * صرفاً معکوس‌کردن جهت انیمیشن، مکانیزم چرخش بی‌درز را خراب نمی‌کند.
 */
.anlamtv-news-ticker {
    position: relative;
    display: flex;
    align-items: stretch;
    height: var(--anlamtv-ticker-height, 30px);
    max-height: var(--anlamtv-ticker-height, 30px);
    background: #fff;
    border: 1px solid #eee;
    color: #222;
    border-radius: 4px;
    overflow: hidden;
    margin: 16px 0;
    font-size: var(--anlamtv-ticker-font-size, 13px);
    line-height: var(--anlamtv-ticker-line-height, 1.4);
}

/* --- جعبه‌ی عنوان: تنها بخش قرمز، شامل آیکون پالسی و متن --- */
.anlamtv-news-ticker__label {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #d32f2f;
    color: #fff;
    padding: 0 14px;
    font-weight: bold;
    white-space: nowrap;
}

.anlamtv-news-ticker__label-icon {
    position: relative;
    flex: 0 0 auto;
    width: calc(var(--anlamtv-ticker-height, 30px) * 0.6);
    height: calc(var(--anlamtv-ticker-height, 30px) * 0.6);
}

.anlamtv-news-ticker__box {
    position: absolute;
    width: 24%;
    height: 24%;
    display: inline-block;
    animation: anlamtv-ticker-box-pulse 1.7s infinite ease-in-out both;
}

.anlamtv-news-ticker__box--1 {
    top: 22%;
    inset-inline-start: 22%;
    animation-delay: 0.2s;
    background-color: rgba(255, 255, 255, 0.5);
}

.anlamtv-news-ticker__box--2 {
    top: 22%;
    inset-inline-start: 56%;
    animation-delay: 0.3s;
    background-color: rgba(255, 255, 255, 0.5);
}

.anlamtv-news-ticker__box--3 {
    top: 56%;
    inset-inline-start: 22%;
    animation-delay: 0.4s;
    background-color: rgba(255, 255, 255, 0.8);
}

.anlamtv-news-ticker__box--4 {
    top: 56%;
    inset-inline-start: 56%;
    animation-delay: 0.5s;
    background-color: rgba(255, 255, 255, 0.8);
}

@keyframes anlamtv-ticker-box-pulse {
    0%, 100% {
        transform: scale(0.7);
        opacity: 1;
    }
    40%, 80% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- بخش قابل اسکرول --- */
.anlamtv-news-ticker__viewport-wrapper {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
}

.anlamtv-news-ticker__viewport {
    height: 100%;
    overflow: hidden;
    direction: ltr; /* چیدمان داخلی همیشه چپ‌به‌راست محاسبه می‌شود؛ جهت دیداری
                        فقط با آینه‌کردن (scaleX) پایین کنترل می‌شود، نه با
                        وراثت جهت صفحه، تا هیچ‌وقت با هم تداخل نکنند */
}

[data-anlamtv-dir="rtl"] .anlamtv-news-ticker__viewport {
    transform: scaleX(-1);
}

[data-anlamtv-dir="rtl"] .anlamtv-news-ticker__item {
    transform: scaleX(-1);
}

/* --- آیتم مشترک بین هر سه حالت --- */
.anlamtv-news-ticker__item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 100%;
    padding: 0 14px;
    color: #222;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}

.anlamtv-news-ticker__item:hover .anlamtv-news-ticker__item-title {
    text-decoration: underline;
}

.anlamtv-news-ticker__item-img {
    flex: 0 0 auto;
    height: calc(var(--anlamtv-ticker-height, 30px) - 8px);
    width: auto;
    max-width: 60px;
    object-fit: cover;
    border-radius: 2px;
    display: block;
}

.anlamtv-news-ticker__item-dot {
    flex: 0 0 auto;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #d32f2f;
    opacity: 0.8;
    display: inline-block;
}

.anlamtv-news-ticker__item-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- دکمه‌های قبلی/بعدی: همیشه در انتهای دور از جعبه‌ی عنوان (با inset-inline-end
   که خودش بر اساس جهت واقعی صفحه به چپ یا راست ترجمه می‌شود)، خارج از لایه‌ی
   آینه‌شده تا خودشان معکوس نشوند --- */
.anlamtv-news-ticker__nav {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    padding-inline-end: 4px;
    padding-inline-start: 20px;
    background: linear-gradient(to left, #fff 60%, transparent);
    z-index: 5;
}

[dir="rtl"] .anlamtv-news-ticker__nav,
.anlamtv-news-ticker[data-anlamtv-dir="rtl"] .anlamtv-news-ticker__nav {
    background: linear-gradient(to right, #fff 60%, transparent);
}

.anlamtv-news-ticker__nav-btn {
    appearance: none;
    border: none;
    background: #f0f0f0;
    color: #555;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 9px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.anlamtv-news-ticker__nav-btn:hover {
    background: #d32f2f;
    color: #fff;
}

/* --- حالت ۱: ریل افقی (Marquee) ---
   توجه: حرکت پیوسته‌ی ریل دیگر با CSS @keyframes انجام نمی‌شود، بلکه کاملاً
   با جاوااسکریپت (requestAnimationFrame) کنترل می‌شود. تجربه نشان داد
   انیمیشن CSS بی‌نهایت، وقتی با توقف موقت دستی (هاور/درگ/دکمه‌ی قبلی-بعدی)
   از طریق override کردن inline style ترکیب می‌شد، گاهی به‌طور کامل متوقف
   می‌ماند یا موقعیت واقعی را از دست می‌داد (چون دو منبع کنترل - انیمیشن CSS
   و استایل inline - هم‌زمان روی transform رقابت می‌کردند). حالا فقط یک منبع
   کنترل (جاوااسکریپت) وجود دارد، هم پخش پیوسته و هم توقف/دکمه‌ها/درگ. */
.anlamtv-news-ticker__track--marquee {
    display: inline-flex;
    align-items: center;
    height: 100%;
    cursor: grab;
    touch-action: pan-y;
    will-change: transform;
}

.anlamtv-news-ticker.is-dragging .anlamtv-news-ticker__track--marquee {
    cursor: grabbing;
}

/* --- حالت ۲: فید محو (Fade) --- */
.anlamtv-news-ticker__track--fade {
    position: relative;
    height: 100%;
    cursor: grab;
    touch-action: pan-y;
}

.anlamtv-news-ticker__panel {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease;
}

.anlamtv-news-ticker__panel.is-active {
    opacity: 1;
    visibility: visible;
}

/* --- حالت ۳: سوایپ عمودی (Vertical) --- */
.anlamtv-news-ticker__track--vertical {
    position: relative;
    height: 100%;
    transition: transform 0.5s ease;
    cursor: grab;
    touch-action: pan-x;
}

.anlamtv-news-ticker.is-dragging .anlamtv-news-ticker__track--vertical {
    transition: none !important;
    cursor: grabbing;
}

.anlamtv-news-ticker__row {
    height: 100%;
    display: flex;
    align-items: center;
}

@media (max-width: 600px) {
    /* در عرض‌های موبایل: عنوان تمام‌عرض و در ردیف خودش، ریل خبری یک خط
       پایین‌تر و در ردیف مستقل خودش (با همان ارتفاع تنظیم‌شده) قرار می‌گیرد. */
    .anlamtv-news-ticker {
        flex-direction: column;
        height: auto;
        max-height: none;
    }

    .anlamtv-news-ticker__label {
        flex: 0 0 auto;
        width: 100%;
        box-sizing: border-box;
        justify-content: center;
        height: var(--anlamtv-ticker-height, 30px);
    }

    .anlamtv-news-ticker__viewport-wrapper {
        width: 100%;
        height: var(--anlamtv-ticker-height, 30px);
    }
}

@media (max-width: 480px) {
    .anlamtv-news-ticker__item-img {
        max-width: 40px;
    }
}
