/* =========================================================================
   ابزار «متن ثابت در ویدیو»
   ظاهر این ابزار عمداً با بقیه برنامه هم‌خانواده است (همان رنگ‌ها، همان
   گردی گوشه‌ها، همان فونت) تا مثل یک بخش الحاقی به نظر نرسد.
   ========================================================================= */

/* ---------------- جداکننده و دکمه ورودی در تب «متن» ---------------- */

.so-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 20px 0 20px;
    margin-top: 6px;
}
.so-divider .so-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, #3a3a3a 20%, #3a3a3a 80%, transparent);
}
.so-divider .so-dot {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #fff;
    background: linear-gradient(135deg, #7C4DFF, #00D7FF);
    box-shadow: 0 0 0 4px rgba(124, 77, 255, 0.12), 0 4px 12px rgba(0, 0, 0, 0.4);
}

.so-open-wrap { padding: 14px 20px 18px 20px; }

.so-open-btn {
    width: 100%;
    border: 1px solid #3a3a3a;
    border-radius: 18px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    font-family: inherit;
    color: #fff;
    text-align: right;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #23203a 0%, #1b1b24 55%, #1e2430 100%);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.so-open-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 25%, rgba(255, 255, 255, 0.07) 45%, transparent 65%);
    transform: translateX(-120%);
    animation: soSheen 4.5s ease-in-out infinite;
    pointer-events: none;
}
@keyframes soSheen {
    0%, 60% { transform: translateX(-120%); }
    100%    { transform: translateX(120%); }
}
.so-open-btn:active { transform: scale(0.985); }
.so-open-btn.has-items { border-color: rgba(124, 77, 255, 0.55); box-shadow: 0 6px 22px rgba(124, 77, 255, 0.18); }

.so-open-ico {
    width: 44px; height: 44px; flex-shrink: 0;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem; color: #fff;
    background: linear-gradient(135deg, #7C4DFF, #FF4081);
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.45);
}
.so-open-txt { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.so-open-txt b { font-size: 1rem; font-weight: 900; }
.so-open-txt small { font-size: 0.72rem; color: #9a9a9a; }
.so-open-count {
    min-width: 26px; height: 26px; padding: 0 8px;
    border-radius: 13px; background: #2c2c2c; color: #888;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.78rem; font-weight: bold;
}
.so-open-btn.has-items .so-open-count { background: var(--primary); color: #fff; }
.so-open-arrow { color: #666; font-size: 0.9rem; }

/* ---------------- سربرگ استودیو ---------------- */

#section-static { padding: 0 0 20px 0; }

.so-head {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #2a2a2a;
    position: sticky; top: 0; z-index: 6;
    background: var(--panel-bg);
}
.so-back {
    width: 38px; height: 38px; border-radius: 12px;
    background: #262626; border: 1px solid #383838; color: #ddd;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1rem;
}
.so-back:active { transform: scale(0.92); }
.so-head-title { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.so-head-title b { font-size: 1.02rem; font-weight: 900; }
.so-head-title small { font-size: 0.72rem; color: #888; }

/* ---------------- ردیف عناصر ---------------- */

.so-layers {
    display: flex; gap: 10px; padding: 14px 18px 4px 18px;
    overflow-x: auto; scrollbar-width: none;
}
.so-layers::-webkit-scrollbar { display: none; }

.so-chip {
    flex-shrink: 0;
    min-width: 96px; max-width: 140px;
    background: #232323; border: 2px solid #333; border-radius: 14px;
    padding: 10px 12px; cursor: pointer; position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    transition: 0.18s;
}
.so-chip.active { border-color: var(--primary); background: #2a2438; }
.so-chip:active { transform: scale(0.96); }
.so-chip-ico { font-size: 1rem; color: #bbb; }
.so-chip.active .so-chip-ico { color: var(--primary); }
.so-chip-name {
    font-size: 0.75rem; color: #ddd; max-width: 100%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.so-chip-thumb {
    width: 34px; height: 34px; border-radius: 8px; object-fit: cover;
    background: #111; border: 1px solid #3a3a3a;
}
/* دو دکمه گوشه هر عنصر: چشم (مخفی/نمایش) و سطل (حذف کامل با تأیید) */
.so-chip-eye, .so-chip-del {
    position: absolute; top: -7px;
    width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 0.62rem;
    border: 1px solid #4a4a4a;
}
.so-chip-eye { left: -7px; background: #333; color: #999; }
.so-chip-del { right: -7px; background: #3a1f1f; border-color: #5a2a2a; color: #ff6b6b; }
.so-chip-eye:active, .so-chip-del:active { transform: scale(0.88); }
.so-chip.hidden-item { opacity: 0.45; }

.so-add {
    flex-shrink: 0; min-width: 88px;
    border: 2px dashed #3d3d3d; border-radius: 14px;
    background: transparent; color: #999; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 12px; font-family: inherit; font-size: 0.75rem;
}
.so-add i { font-size: 1rem; }
.so-add:active { transform: scale(0.96); border-color: var(--primary); color: var(--primary); }

/* ---------------- حالت خالی ---------------- */

.so-empty {
    text-align: center; padding: 34px 24px; color: #777;
    display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.so-empty-ico {
    width: 74px; height: 74px; border-radius: 50%;
    border: 2px dashed #3a3a3a; color: #555;
    display: flex; align-items: center; justify-content: center; font-size: 1.8rem;
}
.so-empty b { color: #ccc; font-size: 0.95rem; }
.so-empty span { font-size: 0.78rem; line-height: 1.8; max-width: 300px; }

/* ---------------- تب‌های تنظیمات ---------------- */

.so-tabs {
    display: flex; gap: 6px; margin: 14px 18px 0 18px;
    background: #1b1b1b; padding: 5px; border-radius: 14px; border: 1px solid #2c2c2c;
}
.so-tab {
    flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px;
    font-size: 0.78rem; color: #999; cursor: pointer; transition: 0.18s;
    white-space: nowrap;
}
.so-tab.active { background: var(--primary); color: #fff; font-weight: bold; box-shadow: 0 3px 10px rgba(124, 77, 255, 0.35); }

.so-body { padding: 16px 18px 0 18px; }

/* ---------------- اجزای فرم ---------------- */

.so-card {
    background: #1c1c1c; border: 1px solid #2c2c2c;
    border-radius: 16px; padding: 14px; margin-bottom: 12px;
}
.so-card-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.82rem; color: #bbb; margin-bottom: 12px; font-weight: bold;
}
.so-card-title i { color: var(--primary); font-size: 0.85rem; }

.so-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.so-row:last-child { margin-bottom: 0; }
.so-row-label { font-size: 0.78rem; color: #999; flex-shrink: 0; min-width: 68px; }

.so-slider-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.so-slider-head span { font-size: 0.78rem; color: #999; }
.so-badge {
    background: #2e2e2e; color: #ddd; border-radius: 8px;
    padding: 2px 9px; font-size: 0.72rem; font-family: monospace; direction: ltr;
}
.so-slider { width: 100%; margin: 0; }
.so-slider-block { margin-bottom: 14px; }
.so-slider-block:last-child { margin-bottom: 0; }

.so-textarea {
    width: 100%; background: #141414; color: #fff; border: 1px solid #383838;
    border-radius: 12px; padding: 12px; font-family: inherit; font-size: 1rem;
    min-height: 84px; resize: vertical; line-height: 1.7; margin: 0;
    user-select: text;
}
.so-textarea:focus { border-color: var(--primary); }

.so-grid { display: grid; gap: 8px; }
.so-grid-2 { grid-template-columns: 1fr 1fr; }
.so-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.so-grid-4 { grid-template-columns: repeat(4, 1fr); }

.so-opt {
    background: #262626; border: 2px solid transparent; border-radius: 11px;
    color: #bbb; padding: 10px 6px; font-family: inherit; font-size: 0.76rem;
    cursor: pointer; text-align: center; transition: 0.15s;
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.so-opt i { font-size: 0.85rem; }
.so-opt.active { border-color: var(--primary); background: #2b2340; color: #fff; }
.so-opt:active { transform: scale(0.96); }
.so-opt.font-opt { font-size: 0.95rem; padding: 12px 6px; }

.so-swatch {
    width: 40px; height: 32px; border-radius: 10px; cursor: pointer;
    border: 2px solid #444; flex-shrink: 0;
    background-image:
        linear-gradient(45deg, #555 25%, transparent 25%),
        linear-gradient(-45deg, #555 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #555 75%),
        linear-gradient(-45deg, transparent 75%, #555 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0;
    position: relative; overflow: hidden;
}
.so-swatch span { position: absolute; inset: 0; display: block; }
.so-swatch:active { transform: scale(0.94); }

.so-toggle {
    display: flex; align-items: center; justify-content: space-between;
    background: #232323; border: 1px solid #333; border-radius: 12px;
    padding: 11px 13px; cursor: pointer; margin-bottom: 12px;
}
.so-toggle:last-child { margin-bottom: 0; }
.so-toggle-label { font-size: 0.82rem; color: #ccc; display: flex; align-items: center; gap: 9px; }
.so-toggle-label i { color: #777; width: 16px; text-align: center; }
.so-switch {
    width: 44px; height: 25px; border-radius: 13px; background: #3a3a3a;
    position: relative; transition: 0.22s; flex-shrink: 0;
}
.so-switch::after {
    content: ''; position: absolute; top: 3px; right: 3px;
    width: 19px; height: 19px; border-radius: 50%; background: #888; transition: 0.22s;
}
.so-toggle.on .so-switch { background: rgba(124, 77, 255, 0.35); }
.so-toggle.on .so-switch::after { background: var(--primary); transform: translateX(-19px); }
.so-toggle.on .so-toggle-label i { color: var(--primary); }

.so-anchor-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    background: #141414; border: 1px solid #303030; border-radius: 12px; padding: 6px;
}
.so-anchor {
    aspect-ratio: 1.7 / 1; border-radius: 8px; background: #242424;
    border: 1px solid #333; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.so-anchor::after { content: ''; width: 12px; height: 4px; border-radius: 2px; background: #666; }
.so-anchor:active { transform: scale(0.93); }
.so-anchor.active { background: rgba(124, 77, 255, 0.18); border-color: var(--primary); }
.so-anchor.active::after { background: var(--primary); }

.so-time-btn {
    flex: 1; background: #262626; border: 1px solid #383838; border-radius: 11px;
    color: #ddd; padding: 10px; font-family: monospace; font-size: 0.85rem;
    cursor: pointer; direction: ltr; text-align: center;
}
.so-time-btn:active { transform: scale(0.97); border-color: var(--primary); }
.so-time-btn.auto { color: #777; font-family: inherit; }

.so-danger {
    width: 100%; background: rgba(255, 82, 82, 0.1); border: 1px solid rgba(255, 82, 82, 0.35);
    color: #ff6b6b; border-radius: 13px; padding: 12px; font-family: inherit;
    font-size: 0.85rem; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 8px; margin-top: 4px;
}
.so-danger:active { transform: scale(0.98); }

.so-hint {
    font-size: 0.72rem; color: #777; line-height: 1.8;
    background: #1a1a1a; border-right: 3px solid var(--primary);
    border-radius: 8px; padding: 9px 11px; margin-top: 10px;
}

/* ---------------- لایه پیش‌نمایش روی ویدیو ---------------- */

#overlayLayer {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none; overflow: hidden; z-index: 30;
}

/* عناصر همیشه با دست جابه‌جا و با دو انگشت کوچک و بزرگ می‌شوند — حتی وقتی
   استودیو باز نیست. یک ضربه ساده (بدون حرکت) مثل قبل ویدیو را پخش/متوقف
   می‌کند تا رفتار همیشگی برنامه به هم نخورد. */
.so-el {
    position: absolute;
    will-change: transform, opacity;
    transform-origin: center center;
    pointer-events: auto;
    cursor: move;
    touch-action: none;
}
.so-mini-layer .so-el { pointer-events: none; cursor: default; }

.so-el-inner { position: relative; display: inline-block; }

.so-text {
    white-space: pre;
    font-weight: normal;
    font-synthesis-weight: none;
    paint-order: stroke fill;
    -webkit-font-smoothing: antialiased;
    /* جهت هر خط از محتوای خودش تعیین می‌شود، نه از جهت کلی عنصر.
       بدون این، در «@app_alpha» علامت @ که کاراکتر خنثی است به سمت راست
       می‌رفت و «app_alpha@» دیده می‌شد. موتور رندر سرور هم همین کار را
       می‌کند (تابع line_direction در features/static_overlay.py). */
    unicode-bidi: plaintext;
}

.so-img { display: block; }

/* قاب انتخاب: فقط داخل استودیو دیده می‌شود */
#overlayLayer.editing .so-el.selected::after {
    content: '';
    position: absolute;
    inset: -14px;
    border: 3px dashed rgba(124, 77, 255, 0.95);
    border-radius: 12px;
    pointer-events: none;
}
#overlayLayer.editing .so-el.out-of-range { opacity: 0.4 !important; }
#overlayLayer.editing .so-el.out-of-range::after { border-color: rgba(255, 152, 0, 0.9); }

.so-outrange-note {
    margin-top: 10px; font-size: 0.72rem; color: #FFB74D;
    background: rgba(255, 152, 0, 0.1); border: 1px solid rgba(255, 152, 0, 0.3);
    border-radius: 10px; padding: 9px 11px; line-height: 1.7;
    display: flex; align-items: center; gap: 8px;
}

/* =========================================================================
   کلید دوحالته: قالب آماده / تنظیمات پیشرفته
   ========================================================================= */

.so-modes {
    display: flex; gap: 8px; margin: 14px 18px 0 18px;
    background: #171717; padding: 6px; border-radius: 16px; border: 1px solid #2c2c2c;
}
.so-mode {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
    padding: 12px 6px; border-radius: 12px; font-size: 0.82rem; color: #999;
    cursor: pointer; transition: 0.2s; white-space: nowrap;
}
.so-mode i { font-size: 0.85rem; }
.so-mode.active {
    color: #fff; font-weight: bold;
    background: linear-gradient(135deg, #7C4DFF, #5E35B1);
    box-shadow: 0 4px 14px rgba(124, 77, 255, 0.4);
}

/* ---------------- دسته‌بندی قالب‌ها ---------------- */

.so-tplcats {
    display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none;
    padding-bottom: 12px; margin-bottom: 4px;
}
.so-tplcats::-webkit-scrollbar { display: none; }
.so-tplcat {
    flex-shrink: 0; padding: 8px 15px; border-radius: 999px;
    background: #232323; border: 1px solid #333; color: #aaa;
    font-size: 0.76rem; cursor: pointer; transition: 0.16s; white-space: nowrap;
}
.so-tplcat.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: bold; }
.so-tplcat:active { transform: scale(0.95); }

/* ---------------- کارت‌های قالب ---------------- */

.so-tplgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.so-tplgrid.img { grid-template-columns: 1fr 1fr 1fr; }

.so-tplcard {
    background: #1a1a1a; border: 2px solid #2b2b2b; border-radius: 15px;
    overflow: hidden; cursor: pointer; transition: 0.18s;
}
.so-tplcard:active { transform: scale(0.96); }
.so-tplcard.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.18); }

.so-tplstage {
    height: 86px; display: flex; align-items: center; justify-content: center;
    padding: 8px; overflow: hidden;
    background:
        linear-gradient(135deg, rgba(124, 77, 255, 0.10), rgba(0, 215, 255, 0.06)),
        repeating-linear-gradient(45deg, #101010 0 9px, #151515 9px 18px);
}
/* اندازه فونت اینجا تعیین نمی‌شود — tplCardStyle آن را می‌گذارد تا با ضریب
   کوچک‌سازی کارت هماهنگ بماند. */
.so-tplsample {
    text-align: center; line-height: 1.25;
    max-width: 100%; white-space: nowrap;
}
.so-tplname {
    padding: 8px 6px; text-align: center; font-size: 0.72rem; color: #aaa;
    border-top: 1px solid #262626; background: #1d1d1d;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.so-tplcard.active .so-tplname { color: #fff; background: #241d38; }

/* =========================================================================
   کادر پیش‌نمایش شناور
   ========================================================================= */

.so-mini {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%) translateY(-140%);
    width: min(94%, 420px);
    background: rgba(20, 20, 24, 0.92);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 20px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.55);
    z-index: 9000;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.25, 1), opacity 0.24s ease, visibility 0.24s;
}
.so-mini.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.so-mini-stage {
    position: relative; width: 100%; height: 132px;
    overflow: hidden; background: #0d0d10;
}
.so-mini-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.so-mini-layer {
    position: absolute; top: 0; left: 0;
    transform-origin: top left;
    pointer-events: none;
}
.so-mini-badge {
    position: absolute; top: 8px; right: 8px;
    font-size: 0.62rem; color: #fff;
    background: rgba(124, 77, 255, 0.85);
    padding: 3px 9px; border-radius: 999px;
    letter-spacing: 0.3px;
}

.so-mini-bar {
    display: flex; align-items: center; gap: 7px; padding: 8px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.so-mini-btn {
    height: 32px; min-width: 32px; padding: 0 9px;
    border-radius: 10px; border: 1px solid #3a3a3a; background: #262626;
    color: #ddd; font-family: inherit; font-size: 0.72rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    flex-shrink: 0;
}
.so-mini-btn:active { transform: scale(0.94); }
.so-mini-btn.wide { flex: 1; }
.so-mini-time { font-family: monospace; font-size: 0.75rem; color: #999; direction: ltr; padding: 0 2px; }

/* =========================================================================
   ویدیوی ثابت
   ========================================================================= */

.so-vid { display: block; }

.so-vidbox {
    width: 100%; height: 150px; border-radius: 14px; overflow: hidden;
    background: #0e0e0e; border: 1px solid #333;
    display: flex; align-items: center; justify-content: center;
}
.so-vidbox video { max-width: 100%; max-height: 100%; }

/* ---------------- دکمه‌های بزرگ حالت خالی ---------------- */

.so-empty-actions {
    display: flex; flex-direction: column; gap: 10px;
    width: 100%; max-width: 340px; margin-top: 6px;
}
.so-big {
    display: flex; align-items: center; gap: 14px;
    width: 100%; padding: 15px 16px;
    background: #1e1e1e; border: 1px solid #333; border-radius: 16px;
    color: #fff; font-family: inherit; cursor: pointer; text-align: right;
    transition: 0.18s;
}
.so-big:active { transform: scale(0.98); border-color: var(--primary); }
.so-big i {
    width: 42px; height: 42px; flex-shrink: 0; border-radius: 13px;
    display: flex; align-items: center; justify-content: center; font-size: 1.05rem;
    background: linear-gradient(135deg, #7C4DFF, #5E35B1);
    box-shadow: 0 4px 12px rgba(124, 77, 255, 0.35);
}
.so-big-txt { flex: 1; min-width: 0; }
.so-big-txt b { font-size: 0.92rem; font-weight: 900; display: block; }
.so-big-txt small { display: block; font-size: 0.7rem; color: #888; margin-top: 3px; }
