/* ================================================================
   Pixel LEGO Translator widget
   دکمه‌ی مترجم با لوگوی لگوی پیکسلی + پنل انتخاب زبان (انیمیشنی)
   ================================================================ */
.zht-tr {
    --zht-tr-clip: polygon(
        0 6px, 3px 6px, 3px 3px, 6px 3px, 6px 0,
        calc(100% - 6px) 0, calc(100% - 6px) 3px, calc(100% - 3px) 3px, calc(100% - 3px) 6px, 100% 6px,
        100% calc(100% - 6px), calc(100% - 3px) calc(100% - 6px), calc(100% - 3px) calc(100% - 3px), calc(100% - 6px) calc(100% - 3px), calc(100% - 6px) 100%,
        6px 100%, 6px calc(100% - 3px), 3px calc(100% - 3px), 3px calc(100% - 6px), 0 calc(100% - 6px)
    );
    --zht-tr-clip-sm: polygon(
        0 3px, 3px 3px, 3px 0,
        calc(100% - 3px) 0, calc(100% - 3px) 3px, 100% 3px,
        100% calc(100% - 3px), calc(100% - 3px) calc(100% - 3px), calc(100% - 3px) 100%,
        3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px)
    );
    --zht-tr-pixel-font: 'Press Start 2P', 'Courier New', monospace;

    --zht-tr-clip-tab: polygon(
        0 6px, 3px 6px, 3px 3px, 6px 3px, 6px 0,
        100% 0, 100% 100%,
        6px 100%, 6px calc(100% - 3px), 3px calc(100% - 3px), 3px calc(100% - 6px), 0 calc(100% - 6px)
    );
    --zht-tr-clip-tab-sm: polygon(
        0 3px, 3px 3px, 3px 0,
        100% 0, 100% 100%,
        3px 100%, 3px calc(100% - 3px), 0 calc(100% - 3px)
    );

    /* زبانه‌ای چسبیده به لبه‌ی راست صفحه، وسط ارتفاع (بدون transform تا پنل fixed درست کار کند) */
    position: fixed;
    right: calc(env(safe-area-inset-right, 0px) + 6px);
    top: calc(50% - 34px);
    z-index: 9998;
    direction: ltr;
    text-align: left;
    font-family: 'Poppins', Arial, sans-serif;
}
.zht-tr *, .zht-tr *::before, .zht-tr *::after { box-sizing: border-box; }

/* ---------------- دکمه ---------------- */
.zht-tr-btn-wrap {
    position: relative;
    width: 68px;
    height: 68px;
    filter: drop-shadow(0 0 0 #fff) drop-shadow(3px 4px 0 rgba(0, 0, 0, 0.35)) drop-shadow(0 0 12px rgba(47, 111, 237, 0.45));
    transition: transform 0.15s steps(3);
}
.zht-tr-btn {
    position: absolute;
    inset: 0;
    padding: 0;
    border: 0;
    cursor: pointer;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
}
.zht-tr-btn-in {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}
.zht-tr-btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.zht-tr-btn-wrap:active { transform: translateY(2px); }

.zht-tr-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
    -webkit-user-drag: none;
    user-select: none;
    animation: zhtTrBob 1.4s steps(2) infinite;
}
.zht-tr-btn:hover .zht-tr-logo { animation: zhtTrHop 0.5s steps(4) infinite; }
.zht-tr.is-busy .zht-tr-logo { animation: zhtTrShake 0.3s steps(2) infinite; }

@keyframes zhtTrBob   { 0%, 100% { transform: translateY(1px); } 50% { transform: translateY(-2px); } }
@keyframes zhtTrHop   { 0%, 100% { transform: translateY(2px); } 50% { transform: translateY(-5px); } }
@keyframes zhtTrShake { 0% { transform: translateX(-2px) rotate(-4deg); } 100% { transform: translateX(2px) rotate(4deg); } }

/* جرقه‌های پیکسلی دور دکمه */
.zht-tr-spark {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #ffe27a;
    box-shadow: 4px 0 #ffe27a, -4px 0 #ffe27a, 0 4px #ffe27a, 0 -4px #ffe27a;
    opacity: 0;
    pointer-events: none;
    animation: zhtTrSpark 2.4s steps(1) infinite;
}
.zht-tr-spark.s1 { top: -6px;  left: -6px;  animation-delay: 0s; }
.zht-tr-spark.s2 { top: 26px;  left: -10px; animation-delay: 0.8s; background: #ff9be8; box-shadow: 4px 0 #ff9be8, -4px 0 #ff9be8, 0 4px #ff9be8, 0 -4px #ff9be8; }
.zht-tr-spark.s3 { bottom: -4px; left: 4px; animation-delay: 1.6s; background: #b18cff; box-shadow: 4px 0 #b18cff, -4px 0 #b18cff, 0 4px #b18cff, 0 -4px #b18cff; }
@keyframes zhtTrSpark { 0% { opacity: 1; transform: scale(0.5); } 20% { opacity: 1; transform: scale(1); } 45%, 100% { opacity: 0; } }

/* نشان زبان فعلی */
.zht-tr-badge {
    position: absolute;
    top: -4px;
    left: -6px;
    z-index: 2;
    display: none;
    padding: 4px 4px 3px;
    background: #2fbf5f;
    color: #06210f;
    border: 2px solid #06210f;
    font-family: var(--zht-tr-pixel-font);
    font-size: 8px;
    line-height: 1;
    text-transform: uppercase;
}
.zht-tr.is-translated .zht-tr-badge { display: block; }

/* ---------------- پنل ---------------- */
.zht-tr-panel {
    position: fixed;
    right: calc(env(safe-area-inset-right, 0px) + 82px);
    top: 50%;
    width: min(272px, calc(100vw - 106px));
    filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 26px rgba(138, 75, 255, 0.35));
    transform-origin: 100% 50%;
    transform: translateY(-50%) scale(0.3);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.36s steps(6), opacity 0.2s steps(3), visibility 0s linear 0.36s;
}
.zht-tr.is-open .zht-tr-panel {
    transform: translateY(-50%) scale(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: transform 0.36s steps(6), opacity 0.2s steps(3), visibility 0s;
}
.zht-tr-panel-border {
    padding: 3px;
    background: linear-gradient(135deg, #ffb020, #ff4fd8 55%, #8a4bff);
    clip-path: var(--zht-tr-clip);
}
.zht-tr-panel-in {
    position: relative;
    max-height: calc(100vh - 36px);
    overflow-x: hidden;
    overflow-y: auto;
    padding: 14px 14px 12px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 100% 6px,
        #0d0719;
    clip-path: var(--zht-tr-clip-sm);
}

.zht-tr-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.zht-tr-title {
    font-family: var(--zht-tr-pixel-font);
    font-size: 11px;
    line-height: 1.4;
    letter-spacing: 1px;
    color: #ffb020;
    text-shadow: 2px 2px 0 #7b2ff7;
}
.zht-tr-close {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 2px solid #3a2a5a;
    background: #1a1030;
    color: #ff8fd0;
    cursor: pointer;
    font-family: var(--zht-tr-pixel-font);
    font-size: 10px;
    line-height: 1;
}
.zht-tr-close:hover { background: #ff4fd8; color: #fff; border-color: #fff; }
.zht-tr-hint {
    margin: 0 0 4px;
    font-size: 11px;
    color: #a99bc4;
    letter-spacing: 0.4px;
}

.zht-tr-list {
    list-style: none;
    margin: 0;
    padding: 12px 2px 4px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* هر زبان یک قطعه‌ی لگو است */
.zht-tr-brick {
    --brick: #2f6fed;
    --brick-dark: #1a3f96;
    --brick-light: #6d9cff;
    --brick-text: #fff;
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 0;
    border-radius: 3px;
    background: var(--brick);
    color: var(--brick-text);
    cursor: pointer;
    text-align: left;
    box-shadow: inset 0 3px 0 var(--brick-light), inset -3px 0 0 rgba(0, 0, 0, 0.14), 0 5px 0 var(--brick-dark);
    transition: transform 0.12s steps(2), box-shadow 0.12s steps(2);
}
/* گل‌میخ‌های لگو روی قطعه (چهار تا) */
.zht-tr-brick::before {
    content: "";
    position: absolute;
    top: -6px;
    left: 18px;
    width: 16px;
    height: 6px;
    background: var(--brick-light);
    border-radius: 2px 2px 0 0;
    box-shadow: 46px 0 0 var(--brick-light), 92px 0 0 var(--brick-light), 138px 0 0 var(--brick-light);
}
.zht-tr-brick:hover { transform: translateY(-2px); box-shadow: inset 0 3px 0 var(--brick-light), inset -3px 0 0 rgba(0, 0, 0, 0.14), 0 7px 0 var(--brick-dark); }
.zht-tr-brick:active,
.zht-tr-brick.is-active { transform: translateY(4px); box-shadow: inset 0 3px 0 var(--brick-light), inset -3px 0 0 rgba(0, 0, 0, 0.14), 0 1px 0 var(--brick-dark); }
.zht-tr-brick:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

.zht-c-blue   { --brick: #2f6fed; --brick-dark: #1a3f96; --brick-light: #6d9cff; }
.zht-c-yellow { --brick: #ffcd1c; --brick-dark: #b58a00; --brick-light: #ffe680; --brick-text: #2a1d00; }
.zht-c-green  { --brick: #2fbf5f; --brick-dark: #187a38; --brick-light: #74e69a; }
.zht-c-red    { --brick: #e63b3b; --brick-dark: #9a1c1c; --brick-light: #ff8a8a; }

.zht-tr-flag {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, 0.55);
    background: rgba(255, 255, 255, 0.9) center / cover no-repeat;
    box-shadow: 2px 3px 0 rgba(0, 0, 0, 0.3);
}
.zht-tr-names { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1 1 auto; }
.zht-tr-name {
    font-family: var(--zht-tr-pixel-font);
    font-size: 10px;
    line-height: 1.3;
    letter-spacing: 0.5px;
}
.zht-tr-sub { font-size: 11px; line-height: 1.2; opacity: 0.85; }

/* تیک پیکسلی برای زبان فعال */
.zht-tr-check {
    flex: 0 0 auto;
    width: 24px;
    height: 18px;
    display: none;
}
.zht-tr-brick.is-active .zht-tr-check { display: block; }
.zht-tr-check rect { fill: currentColor; }

.zht-tr-status {
    min-height: 20px;
    margin-top: 12px;
    font-family: var(--zht-tr-pixel-font);
    font-size: 8px;
    line-height: 1.6;
    letter-spacing: 0.5px;
    color: #74e69a;
}
.zht-tr-status.is-error { color: #ff7a7a; }
.zht-tr.is-busy .zht-tr-status::after { content: ""; animation: zhtTrDots 0.9s steps(4) infinite; }
@keyframes zhtTrDots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.zht-tr-note { margin: 8px 0 0; font-size: 10px; line-height: 1.5; color: #6f6288; }

/* باز شدن پنل: قطعه‌ها مثل لگو یکی‌یکی می‌افتند */
.zht-tr.is-open .zht-tr-list li {
    animation: zhtTrDrop 0.55s steps(11) both;
    animation-delay: calc(var(--i, 0) * 110ms + 180ms);
}
@keyframes zhtTrDrop {
    0%   { transform: translateY(-44px); opacity: 0; }
    55%  { transform: translateY(5px);   opacity: 1; }
    75%  { transform: translateY(-4px); }
    100% { transform: translateY(0);     opacity: 1; }
}

@supports (height: 100dvh) {
    .zht-tr-panel-in { max-height: calc(100dvh - 36px); }
}

/* مخفی‌کردن نوار و رابط پیش‌فرض گوگل ترنسلیت */
#zht-gt-element { position: absolute !important; left: -9999px !important; top: 0 !important; width: 1px; height: 1px; overflow: hidden; }
body > .skiptranslate,
iframe.goog-te-banner-frame,
.goog-te-banner-frame,
.VIpgJd-ZVi9od-ORHb-OEVmcd,
#goog-gt-tt,
.goog-te-balloon-frame { display: none !important; }
body { top: 0 !important; }
.goog-text-highlight { background: none !important; box-shadow: none !important; }

/* اندروید و موبایل: زبانه کمی بالاتر از وسط می‌نشیند تا روی نقطه‌های اسلایدر محصولات
   و دکمه‌های موزیک/بالا (پایین سمت راست) نیفتد و با شست هم قابل‌دسترس بماند */
@media (max-width: 768px) {
    .zht-tr { top: calc(30% - 34px); }
    .zht-tr-panel { right: calc(env(safe-area-inset-right, 0px) + 78px); }
}
/* گوشی در حالت افقی */
@media (max-height: 520px) {
    .zht-tr { top: calc(26% - 34px); }
}

@media (prefers-reduced-motion: reduce) {
    .zht-tr-logo, .zht-tr-spark, .zht-tr.is-open .zht-tr-list li { animation: none !important; }
    .zht-tr-spark { display: none; }
    .zht-tr-panel { transition: opacity 0.15s linear, visibility 0s; transform: translateY(-50%); }
}
