/* ==========================================
   ГЛОБАЛЬНЫЙ СБРОС И НАТИВНЫЕ ОПТИМИЗАЦИИ
   ========================================== */
* {
    -webkit-tap-highlight-color: transparent !important; /* Убираем синее мигание при клике */
    -webkit-touch-callout: none !important; /* Отключаем системное меню "Копировать/Сохранить" при долгом тапе */
    user-select: none; /* Запрещаем выделять элементы интерфейса как текст */
    overscroll-behavior-y: none; /* Отключаем "резиновую" прокрутку (Pull-to-refresh) */
    box-sizing: border-box;
}

/* Разрешаем выделять текст ТОЛЬКО внутри сообщений и полей ввода */
.msg, textarea, input {
    user-select: text;
}

/* ==========================================
   БАЗОВЫЙ КАРКАС ПРИЛОЖЕНИЯ (ФИКС СЕРОЙ ПОЛОСЫ)
   ========================================== */
html, body {
    background-color: var(--bg-color, #f5f7fb); /* Светлый фон всего приложения */
    color: var(--text-main, #333333);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    margin: 0; 
    padding: 0; 
    
    width: 100%;
    height: 100%; 
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0;
    
    display: flex; 
    flex-direction: column; 
    overflow: hidden;
}

/* ==========================================
   ШАПКА И СТАТУС-БАР
   ========================================== */
.header {
    background: var(--bg-panel, #ffffff); 
    padding: max(12px, env(safe-area-inset-top, 12px)) 10px 12px 10px; 
    text-align: center; 
    font-weight: bold; 
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    z-index: 100;
    position: relative;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

.header-left {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
}

.header .btn-small {
    padding: 4px 7px;
    font-size: var(--header-btn-size, 11px);
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-center-btn,
#el_gen_1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    padding: 4px 6px;
    margin: 0;
    border: none;
    background: transparent;
    font: inherit;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.header-center-btn:active,
#el_gen_1:active {
    opacity: 0.7;
}

#header-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

#header-avatar {
    vertical-align: middle;
}

.btn-small { 
    background: var(--btn-small-bg, var(--msg-out-bg, #e3f2fd)); 
    color: var(--btn-small-text, var(--text-main, #333333)); 
    border: 1px solid rgba(0, 0, 0, 0.08); 
    padding: 5px 10px; 
    border-radius: 10px; 
    font-size: 12px; 
    cursor: pointer; 
    font-weight: 600;
}

#status-bar { 
    background: var(--msg-out-bg, #e3f2fd); 
    text-align: center; 
    font-size: 11px; 
    padding: 5px; 
    color: var(--text-main, #333333); 
    font-weight: bold; 
    flex-shrink: 0; 
    transition: background 0.3s ease; 
}
#status-bar.restoring { background: #ff9800; color: white; }

/* ==========================================
   СПИСКИ И ЧАТ (ПЛАВНЫЙ СКРОЛЛ)
   ========================================== */
#contact-list { 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto; 
    background: var(--bg-color, #f5f7fb); 
    flex: 1; 
    min-height: 0;
    padding-bottom: 50px; 
    -webkit-overflow-scrolling: touch; /* Нативный скролл */
}

.folders-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    flex: 0 0 auto;
    min-height: 42px;
    box-sizing: border-box;
    padding: 6px 15px 10px 15px;
    border-bottom: 1px solid rgba(128,128,128,0.2);
    margin-bottom: 10px;
    background: var(--bg-color, #f5f7fb);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.folders-tabs::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.folder-tab-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
    max-width: min(24ch, 64vw);
    min-width: 0;
    transition: all 0.2s;
    background: var(--bg-panel, #ffffff);
    color: var(--text-main, #333);
    border: 1px solid rgba(128,128,128,0.2);
}

.folder-tab-item.active {
    background: var(--primary-color, #40a7e3);
    color: white;
    border: none;
}

.folder-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.folder-badge {
    flex-shrink: 0;
    background: #ff4d4d;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    display: none;
}

.folder-badge-tag {
    background: rgba(64,167,227,0.1);
    color: var(--primary-color, #40a7e3);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    border: 1px solid rgba(64,167,227,0.3);
    display: inline-block;
    font-weight: normal;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-badge-tag-more {
    cursor: pointer;
}

.folder-create-btn {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    flex-shrink: 0;
    background: var(--bg-panel, #ffffff);
    color: var(--text-main, #333);
    border: 1px dashed var(--primary-color, #40a7e3);
}

.contacts-view-toggle {
    width: 34px;
    height: 34px;
    border-radius: 14px;
    border: 1px solid rgba(128,128,128,0.24);
    background: var(--bg-panel, #ffffff);
    color: var(--text-main, #333);
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.contacts-grid-view {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-content: start;
    padding: 0 10px 50px;
}

.contacts-list-view {
    display: flex !important;
    flex-direction: column;
}

#contact-list.contacts-hidden {
    display: none !important;
}

.contacts-grid-view .folders-tabs {
    grid-column: 1 / -1;
    margin: 0 -10px 2px;
    order: 2;
    position: static;
    top: auto;
    z-index: auto;
}

.contacts-section-title {
    padding: 10px 16px 4px;
    color: var(--text-sub, #888888);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.contacts-grid-view .contacts-section-title {
    grid-column: 1 / -1;
    padding: 8px 6px 0;
    order: 3;
}

.contacts-grid-view .contact-card {
    position: relative;
    min-height: 132px;
    padding: 12px 10px;
    border: 1px solid rgba(128,128,128,0.18);
    border-radius: 18px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    overflow: visible;
    order: 3;
}

.contacts-grid-view .contact-card.contact-actions-open {
    z-index: 30050;
}

.contacts-grid-view .contact-card:active {
    transform: scale(0.98);
}

.contacts-grid-view .contact-avatar {
    width: 54px;
    height: 54px;
    font-size: 21px;
}

.contacts-grid-view .contact-info {
    width: 100%;
    align-items: center;
    gap: 3px;
}

.contacts-grid-view .contact-header,
.contacts-grid-view .contact-sub-header {
    justify-content: center;
}

.contacts-grid-view .contact-sub-header {
    flex-direction: column;
    gap: 5px;
}

.contacts-grid-view .contact-name {
    flex: 0 1 auto;
    max-width: 100%;
    font-size: 14px;
}

.contacts-grid-view .contact-sub {
    max-width: 100%;
    font-size: 11px;
}

.contacts-grid-view .unread-badge {
    position: absolute;
    top: 9px;
    right: 9px;
}

.contacts-grid-view .contact-actions-wrapper {
    position: absolute;
    top: 8px;
    right: 4px;
    z-index: 5;
}

.contacts-grid-view .action-toggle {
    padding: 4px 8px;
    font-size: 18px;
}

.contacts-grid-view .contact-actions {
    position: fixed;
    right: auto;
    top: auto;
    transform: none;
    width: min(300px, calc(100vw - 28px));
    max-width: calc(100vw - 28px);
    flex-wrap: nowrap;
    justify-content: space-around;
    gap: 6px;
    padding: 7px 9px;
    border-radius: 14px;
    overflow-x: auto;
    scrollbar-width: none;
    z-index: 30060;
}

.contacts-grid-view .contact-actions::-webkit-scrollbar {
    display: none;
}

.contact-actions-floating {
    position: fixed !important;
    right: auto !important;
    top: auto;
    transform: none !important;
    width: min(300px, calc(100vw - 28px));
    max-width: calc(100vw - 28px);
    flex-wrap: nowrap;
    justify-content: space-around;
    gap: 6px;
    padding: 7px 9px;
    border-radius: 14px;
    overflow-x: auto;
    scrollbar-width: none;
    z-index: 40000;
    pointer-events: auto;
}

.contact-actions-floating::-webkit-scrollbar {
    display: none;
}

.contact-actions-floating span {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.contacts-grid-view .contact-actions span {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.contacts-grid-view .contact-folders-badges {
    display: none;
}

.contacts-grid-view .contacts-system-card {
    grid-column: 1 / -1;
    order: 1;
    min-height: 72px;
    height: auto;
    margin: 6px 0 8px;
    padding: 12px 15px;
    box-sizing: border-box;
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;
    text-align: left;
    border-radius: 14px;
    overflow: visible;
}

.contacts-grid-view .contacts-system-card .contact-avatar {
    width: 50px;
    height: 50px;
    font-size: 20px;
}

.contacts-grid-view .contacts-system-card .contact-info {
    align-items: stretch;
    gap: 0;
}

.contacts-grid-view .contacts-system-card .contact-header {
    justify-content: space-between;
}

.contacts-grid-view .contacts-system-card .contact-sub-header {
    justify-content: flex-start;
    flex-direction: row;
    gap: 0;
}

.contacts-grid-view .contacts-system-card .contact-name {
    font-size: 16px;
}

.contacts-grid-view .contacts-system-card .contact-sub {
    font-size: 13px;
}

.contacts-grid-view .contacts-system-card .unread-badge {
    position: static;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.folder-select-content {
    background: var(--bg-panel, #ffffff);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    max-height: 80vh;
    overflow-x: hidden;
}

.folder-select-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    color: var(--accent-color, #4a90e2);
}

.folder-select-header h3 {
    margin: 0;
    font-size: 18px;
}

.folder-select-close {
    font-size: 24px;
    cursor: pointer;
    color: var(--text-main, #333);
}

.folder-select-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.folder-select-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: var(--bg-color, #f5f7fb);
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(128,128,128,0.2);
    min-width: 0;
}

.folder-select-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: bold;
    color: var(--text-main, #333);
}

.folder-select-item-check {
    flex-shrink: 0;
}

.folder-select-new-btn {
    background: var(--bg-color, #f5f7fb);
    color: var(--primary-color, #40a7e3);
    border: 1px dashed var(--primary-color, #40a7e3);
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 10px;
    text-align: center;
}

.folder-select-done-btn {
    background: var(--primary-color, #40a7e3);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
}

#chat { 
    flex: 1; 
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    padding: 15px; 
    overflow-y: auto; 
    overflow-x: hidden;
    display: flex; 
    flex-direction: column; 
    background: var(--bg-chat, #efece5); 
    -webkit-overflow-scrolling: touch; /* Нативный скролл */
}

/* ==========================================
   КОНТАКТЫ
   ========================================== */
.contact-card { background: var(--bg-panel, #ffffff); padding: 12px 15px; display: flex; align-items: center; gap: 15px; border-bottom: 1px solid #f0f0f0; cursor: pointer; transition: background 0.2s; }
.contact-card:active { background: var(--bg-hover, #f0f4f8); }
.contact-avatar { width: 50px; height: 50px; border-radius: 50%; background: linear-gradient(135deg, #85c4f2, var(--accent-color, #4a90e2)); color: white; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; flex-shrink: 0; background-size: cover; background-position: center; }
.contact-info { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.contact-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.contact-name { font-weight: bold; color: var(--text-main, #333333); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { color: var(--text-sub, #888888); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: #ff4d4d; color: white; font-size: 11px; padding: 2px 7px; border-radius: 10px; font-weight: bold; flex-shrink: 0; display: none; }
.contact-actions-wrapper {
    display: flex;
    align-items: center;
    position: relative;
}

.contact-actions {
    display: none;
    position: absolute;
    right: 35px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-panel, #ffffff);
    border: 1px solid rgba(128,128,128,0.2);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    z-index: 100;
    gap: 8px;
}

.contact-actions span {
    cursor: pointer;
    padding: 5px;
    background: transparent;
    border-radius: 8px;
    color: var(--accent-color, #4a90e2);
}

.action-toggle {
    cursor: pointer;
    padding: 5px 15px;
    font-size: 22px;
    color: var(--text-main, #333);
    opacity: 0.6;
    user-select: none;
}

.contact-info {
    min-width: 0;
}

.contact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-width: 0;
}

.contact-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-sub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-width: 0;
}

.contact-sub {
    flex-shrink: 0;
}

.contact-folders-badges {
    display: flex;
    align-items: center;
    gap: 3px;
    overflow: hidden;
    flex-shrink: 1;
    white-space: nowrap;
    margin-left: 8px;
}

/* ==========================================
   СООБЩЕНИЯ
   ========================================== */
.msg { max-width: 80%; padding: 5px 10px; border-radius: var(--msg-radius, 15px); margin-bottom: 2px; font-size: 15px; line-height: 1.4; word-wrap: break-word; box-shadow: none; color: var(--text-main, #333333); font-weight: 500; letter-spacing: 0.2px; text-shadow: none; display: block; touch-action: pan-y; position: relative; }
.msg.in { background: transparent; border: none; align-self: flex-start; border-bottom-left-radius: 5px; backdrop-filter: none; -webkit-backdrop-filter: none; text-align: left; }
.msg.out { background: transparent; border: none; align-self: flex-end; border-bottom-right-radius: 5px; color: var(--primary-color, #4a90e2); font-weight: 600; backdrop-filter: none; -webkit-backdrop-filter: none; text-align: right; }
.msg.in.msg-sticker, .msg.out.msg-sticker { background: transparent !important; border: none !important; box-shadow: none !important; padding: 0 !important; backdrop-filter: none; -webkit-backdrop-filter: none; text-shadow: none !important; align-items: flex-start; }
.msg.out.msg-sticker { align-items: flex-end; }
.msg small { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 10px; color: inherit; margin-top: 5px; }

@keyframes msgHighlightPulse {
    0%, 100% {
        outline-color: transparent;
        filter: brightness(1);
    }
    12%, 88% {
        outline-color: var(--primary-color, #40a7e3);
        filter: brightness(1.2);
    }
}
@-webkit-keyframes msgHighlightPulse {
    0%, 100% {
        outline-color: transparent;
        -webkit-filter: brightness(1);
    }
    12%, 88% {
        outline-color: var(--primary-color, #40a7e3);
        -webkit-filter: brightness(1.2);
    }
}
#chat .msg.msg-highlighted {
    position: relative !important;
    z-index: 120 !important;
    /* .msg-animated держит статический opacity:0 и проявляется своей анимацией;
       наша подсветка её перебивает, поэтому фиксируем видимость явно */
    opacity: 1 !important;
    transform: none !important;
    outline: 3px solid var(--primary-color, #40a7e3) !important;
    outline-offset: 4px !important;
    box-shadow:
        0 0 0 6px rgba(64, 167, 227, 0.28),
        0 0 28px rgba(64, 167, 227, 0.5) !important;
    /* Статичная подсветка без анимации: при перерисовке чата класс навешивается
       заново, и пульсирующая анимация каждый раз стартовала с прозрачной рамки —
       из-за этого подсветка "моргала". Теперь повторное навешивание незаметно. */
}
body.theme-bubbles #chat .msg.msg-highlighted:not(.msg-sticker) {
    box-shadow:
        0 0 0 6px color-mix(in srgb, var(--primary-color, #40a7e3) 35%, transparent),
        0 0 32px color-mix(in srgb, var(--primary-color, #40a7e3) 55%, transparent) !important;
}

/* Облака сообщений (Bubbles) */
body.theme-bubbles .msg.in:not(.msg-sticker) {
    background: var(--bg-panel, #ffffff);
    color: var(--msg-in-bubble-text, var(--text-main, #333333));
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 8px 12px;
}
body.theme-bubbles .msg.out:not(.msg-sticker) {
    background: var(--primary-color, #4a90e2);
    color: var(--msg-out-bubble-text, #ffffff);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 8px 12px;
}
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-reply-wrapper {
    border-left-color: currentColor;
    background: rgba(255,255,255,0.2);
}
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-reply-sender {
    color: inherit;
}
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-reply-text {
    color: inherit;
    opacity: 0.92;
}
body.theme-bubbles .msg.in:not(.msg-sticker) .msg-meta,
body.theme-bubbles .msg.in:not(.msg-sticker) small,
body.theme-bubbles .msg.in:not(.msg-sticker) .msg-ticks.first-tick,
body.theme-bubbles .msg.in:not(.msg-sticker) .msg-ticks.read-ticks,
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-meta,
body.theme-bubbles .msg.out:not(.msg-sticker) small,
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-ticks.first-tick,
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-ticks.read-ticks,
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-meta-media,
body.theme-bubbles .msg.in:not(.msg-sticker) .msg-meta-media,
body.theme-bubbles #chat .msg.in:not(.msg-sticker) .msg-meta,
body.theme-bubbles #chat .msg.in:not(.msg-sticker) small,
body.theme-bubbles #chat .msg.in:not(.msg-sticker) .msg-ticks,
body.theme-bubbles #chat .msg.out:not(.msg-sticker) .msg-meta,
body.theme-bubbles #chat .msg.out:not(.msg-sticker) small,
body.theme-bubbles #chat .msg.out:not(.msg-sticker) .msg-ticks {
    color: currentColor !important;
    -webkit-text-fill-color: currentColor !important;
    opacity: 0.85 !important;
}
body.theme-bubbles .msg .msg-ticks.read-ticks,
body.theme-bubbles .msg .msg-ticks.visible {
    opacity: 1 !important;
}
body.theme-bubbles .msg.out:not(.msg-sticker) a {
    color: inherit;
    text-decoration: underline;
}
/* В режиме «облака» голосовые и видео-кружочки идут без облака:
   у плеера/кружка свои элементы, и внешний пузырь создаёт «облако в облаке».
   #chat в селекторе нужен, чтобы перебить тематические правила из chat-styles.css. */
body.theme-bubbles #chat .msg.msg-media-voice,
body.theme-bubbles #chat .msg.msg-media-video,
body.theme-bubbles #chat .msg.msg-media-image {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-radius: 0 !important;
    padding: 5px 0 !important;
}
body.theme-bubbles-off #chat .msg.in:not(.msg-sticker),
body.theme-bubbles-off #chat .msg.out:not(.msg-sticker) {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.circle-video { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; border: 3px solid var(--accent-color, #4a90e2); }
#video-preview-container { display: none; position: absolute; bottom: 130px; right: 20px; width: 150px; height: 150px; border-radius: 50%; overflow: hidden; border: 3px solid #ff4d4d; box-shadow: 0 5px 15px rgba(0,0,0,0.2); z-index: 100; }
#video-preview { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

/* ==========================================
   ПАНЕЛЬ ВВОДА (ИДЕАЛЬНАЯ ПРИВЯЗКА К НИЗУ)
   ========================================== */
.reply-bar {
    flex: 0 0 100%;
    width: 100%;
    order: -1;
    background: var(--bg-panel, #ffffff);
    border: 1px solid var(--bg-hover, #f0f4f8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin: 0 0 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    z-index: 12;
}
.reply-banner-icon {
    color: var(--primary-color, #40a7e3);
    font-size: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reply-banner-content {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.reply-banner-sender {
    color: var(--primary-color, #40a7e3);
    font-weight: bold;
    font-size: 13px;
}
.reply-banner-text {
    color: var(--text-sub, #7f91a4);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.reply-banner-close {
    background: none;
    border: none;
    color: var(--text-sub, #7f91a4);
    font-size: 18px;
    cursor: pointer;
    padding: 5px;
    margin-left: 10px;
}

.controls { 
    display: flex; 
    align-items: flex-end; 
    padding: 8px 10px;
    padding-bottom: max(45px, calc(30px + env(safe-area-inset-bottom, 0px)));
    background: var(--bg-panel, #ffffff); 
    border-top: 1px solid #e0e0e0; 
    gap: 8px; 
    flex-shrink: 0; 
    z-index: 10;
    flex-wrap: wrap;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: visible;
    position: relative;
}


.input-area {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    background: var(--bg-hover, #f0f4f8);
    border-radius: 20px;
    align-items: flex-end;
    padding: 0 4px;
    min-height: 40px;
    overflow: hidden;
}
textarea#content {
    flex: 1 1 0;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--text-main, #333333);
    font-size: max(14px, 0.875rem);
    padding: 8px 6px;
    outline: none;
    resize: none;
    height: 40px;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.25;
    font-family: inherit;
    overflow-y: auto;
}
.input-area button {
    background: none;
    border: none;
    color: var(--text-sub, #888888);
    font-size: clamp(16px, 4.5vw, 20px);
    padding: 6px 4px;
    cursor: pointer;
    min-height: 40px;
    min-width: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.controls > button {
    background: var(--accent-color, #4a90e2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: clamp(16px, 5vw, 20px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* ==========================================
   ОБЛАКО ДЛЯ ДЛИННОГО ТЕКСТА
   ========================================== */
#text-cloud-preview {
    position: fixed;
    bottom: calc(94px + env(safe-area-inset-bottom, 0px));
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    width: auto;
    max-height: min(56dvh, 520px);
    background: var(--bg-color, #f5f7fb);
    border: 1px solid var(--accent-color, #4a90e2);
    border-radius: 20px 20px 20px 0;
    padding: 15px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    z-index: 20050;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text-main, #333333);
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-y: auto;
    animation: popCloud 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-sizing: border-box;
    cursor: text;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
}

#text-cloud-preview .sm-long-text-editor {
    width: 100%;
    min-height: 140px;
    max-height: min(52dvh, 480px);
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-main, #333333);
    font: inherit;
    line-height: 1.4;
    white-space: pre-wrap;
    overflow-y: auto;
    padding: 0;
    box-sizing: border-box;
}

@media (min-width: 720px) {
    #text-cloud-preview {
        left: 50%;
        right: auto;
        width: min(680px, calc(100vw - 24px));
        transform: translateX(-50%);
    }
}

#text-cloud-preview .sm-long-text-editor::placeholder {
    color: var(--text-sub, #7f91a4);
}

.pending-media-preview {
    position: fixed;
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: calc(94px + env(safe-area-inset-bottom, 0px));
    min-height: 64px;
    padding: 8px 42px 8px 10px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(64, 167, 227, 0.18);
    box-shadow: 0 8px 24px rgba(0,0,0,0.22);
    z-index: 20001;
    display: none;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

@media (min-width: 520px) {
    .pending-media-preview {
        left: 50%;
        right: auto;
        width: min(420px, calc(100vw - 24px));
        transform: translateX(-50%);
    }
}

.pending-media-preview img {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-color, #f5f7fb);
    box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

.pending-media-info {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
}

.pending-media-info span {
    color: var(--accent-color, #4a90e2);
    font-size: 15px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pending-media-info small {
    color: var(--text-sub, #7f91a4);
    font-size: 14px;
}

#pending-media-remove {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    min-width: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(127, 145, 164, 0.18);
    color: var(--text-sub, #7f91a4);
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#reaction-panel {
    position: fixed !important;
    left: max(10px, env(safe-area-inset-left, 0px)) !important;
    right: max(10px, env(safe-area-inset-right, 0px)) !important;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    width: auto !important;
    max-width: none !important;
    max-height: min(360px, 48dvh) !important;
    box-sizing: border-box;
    z-index: 20000 !important;
    overflow: hidden;
}

#reaction-panel > div {
    max-height: calc(min(360px, 48dvh) - 24px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start !important;
    align-content: flex-start;
}

@media (min-width: 520px) {
    #reaction-panel {
        left: 50% !important;
        right: auto !important;
        width: min(420px, calc(100vw - 24px)) !important;
        transform: translateX(-50%);
    }
}

@keyframes popCloud {
    0% { transform: translateY(20px) scale(0.9); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.cloud-cursor {
    display: inline-block;
    width: 2px;
    background-color: var(--primary-color, #40a7e3);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    height: 1.2em;
    margin-left: -1px;
    margin-right: -1px;
}
.cloud-selection {
    background-color: rgba(64, 167, 227, 0.3);
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.controls.typing #content {
    order: 1;
}
.controls.typing #bomb-btn {
    order: 3;
}

.controls.recording #content {
    display: none;
}

.controls.recording #send-btn {
    display: none;
}

.controls.recording #reaction-btn,
.controls.recording #bomb-btn,
.controls.recording-audio #video-btn,
.controls.recording-video #voice-btn {
    display: none;
}

.recording-visual {
    display: none;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    padding: 6px 8px 6px 2px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    color: var(--text-main, #333333);
}

.controls.recording .recording-visual {
    display: flex;
    order: 2;
}

.cancel-record-btn {
    display: none !important;
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    margin: 3px 2px 3px 0;
    border-radius: 50%;
    background: rgba(255, 77, 77, 0.12) !important;
    color: #ff4d4d !important;
    border: 1px solid rgba(255, 77, 77, 0.35) !important;
    font-size: 18px !important;
    font-weight: 800;
    line-height: 1;
    order: 1;
    flex-shrink: 0;
}

.controls.recording .cancel-record-btn {
    display: flex !important;
}

.controls.recording-audio #voice-btn,
.controls.recording-video #video-btn {
    order: 3;
    margin-left: 8px;
    background: rgba(255, 152, 0, 0.18);
    border-radius: 50%;
}

.recording-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.recording-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ff4d4d;
    box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.55);
    flex-shrink: 0;
    animation: recordDotPulse 1.2s ease-out infinite;
}

#recording-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main, #333333);
}

#recording-time {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--text-sub, #7f91a4);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.recording-wave {
    height: 14px;
    display: flex;
    align-items: center;
    gap: 3px;
    opacity: 0.95;
}

.recording-wave span {
    width: 3px;
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(180deg, var(--primary-color, #40a7e3), #ff4d4d);
    animation: recordWave 0.95s ease-in-out infinite;
}

.recording-wave span:nth-child(2) { animation-delay: -0.82s; }
.recording-wave span:nth-child(3) { animation-delay: -0.68s; }
.recording-wave span:nth-child(4) { animation-delay: -0.54s; }
.recording-wave span:nth-child(5) { animation-delay: -0.40s; }
.recording-wave span:nth-child(6) { animation-delay: -0.26s; }
.recording-wave span:nth-child(7) { animation-delay: -0.12s; }
.recording-wave span:nth-child(8) { animation-delay: 0s; }

.recording-progress {
    height: 3px;
    border-radius: 999px;
    background: rgba(127, 145, 164, 0.24);
    overflow: hidden;
}

.recording-progress span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary-color, #40a7e3), #ff4d4d);
    transition: width 0.25s ease;
}

.recording-active {
    color: #ff4d4d !important;
    animation: pulse 1s infinite;
}

@keyframes recordDotPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.55); }
    70% { box-shadow: 0 0 0 8px rgba(255, 77, 77, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

@keyframes recordWave {
    0%, 100% { height: 5px; opacity: 0.55; }
    50% { height: 14px; opacity: 1; }
}

@keyframes pulse { 0% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.1); } 100% { opacity: 1; transform: scale(1); } }

/* ==========================================
   МОДАЛЬНЫЕ ОКНА И ИНПУТЫ
   ========================================== */
.modal {
    display: none;
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: var(--bg-panel, #ffffff) !important;
    padding: 25px !important;
    border-radius: 20px !important;
    z-index: 10000 !important;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15) !important;
    width: 85% !important;
    max-width: 340px !important;
    border: 1px solid #e0e0e0 !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto !important;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.modal::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}
#qr-code,
#invite-qr-code {
    max-width: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
}
.qr-white-box {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    box-sizing: border-box;
    background: #fff;
    padding: 12px;
    border-radius: 10px;
}
.qr-white-box canvas,
.qr-white-box img,
#qr-code canvas,
#qr-code img,
#invite-qr-code canvas,
#invite-qr-code img {
    display: block;
    max-width: 100%;
    height: auto !important;
}
.modal h3 { margin-top: 0; color: var(--accent-color, #4a90e2); text-align: center; font-size: 18px; }
.modal input { width: 100%; padding: 12px; margin-bottom: 15px; background: var(--bg-color, #f5f7fb); border: 1px solid #e0e0e0; color: var(--text-main, #333333); border-radius: 12px; box-sizing: border-box; }
.modal button[style*="background:none"],
.modal button[style*="background: none"] {
    color: var(--text-main, #333333) !important;
    font-weight: 600;
}
/* Клавиатура + трёхкнопочная навигация: прокрутка вместо «белой полосы», единый фон */
#web3-auth-modal {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    background: var(--bg-panel, #ffffff);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    text-align: center;
    padding: max(20px, env(safe-area-inset-top, 0px)) 20px calc(24px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.auth-input { width: 100%; padding: 15px; margin-bottom: 15px; background: var(--bg-color, #f5f7fb); border: 1px solid var(--accent-color, #4a90e2); color: var(--text-main, #333333); border-radius: 15px; text-align: center; font-size: 16px; }
.btn-primary { background: var(--accent-color, #4a90e2); color: white; padding: 15px; width: 100%; border-radius: 15px; border: none; font-weight: bold; font-size: 16px; cursor: pointer; }

/* ==========================================
   ГАЛЕРЕЯ, МЕДИА И ИНВАЙТЫ
   ========================================== */
#chat-media-list { max-height: 350px !important; padding: 8px !important; background: var(--bg-hover, #f0f4f8); border-radius: 12px; border: 1px solid #e0e0e0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior-y: auto; }
.media-gallery-item { display: flex; align-items: center; padding: 12px 10px !important; margin-bottom: 6px !important; background: var(--bg-panel, #ffffff); border: 1px solid #e0e0e0; border-radius: 8px; cursor: pointer; transition: background 0.2s ease; }
.media-gallery-item:active { background: var(--bg-color, #f5f7fb); }
.media-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-right: 12px; flex-shrink: 0; background: var(--msg-out-bg, #e3f2fd); color: var(--accent-color, #4a90e2);}
.media-info { flex: 1; display: flex; flex-direction: column; }
.media-title { color: var(--text-main, #333333); font-size: 14px; font-weight: bold; }
.media-sender { color: var(--accent-color, #4a90e2); font-size: 12px; font-weight: bold; margin: 3px 0; display: block; }
.media-date { color: var(--text-sub, #888888); font-size: 11px; display: block; }

.highlight-msg { animation: flashMessage 2s ease-out; }
@keyframes flashMessage { 0% { transform: scale(1); box-shadow: 0 0 0px rgba(74, 144, 226, 0); } 15% { transform: scale(1.02); box-shadow: 0 0 20px rgba(74, 144, 226, 0.4); background: var(--msg-out-bg, #e3f2fd); } 100% { transform: scale(1); box-shadow: 0 0 0px rgba(74, 144, 226, 0); } }

.invite-card { background: var(--bg-panel, #ffffff); border: 1px solid var(--accent-color, #4a90e2); border-radius: 12px; padding: 12px; margin-top: 5px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }
.invite-header { color: #ff9800; font-weight: bold; font-size: 13px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.invite-body { color: var(--text-main, #333333); font-size: 14px; margin-bottom: 12px; line-height: 1.4; }
.invite-room-name { color: var(--accent-color, #4a90e2); font-size: 16px; font-weight: bold; display: inline-block; margin-top: 5px; }
.invite-btn { flex: 1; padding: 10px; border: none; border-radius: 8px; font-size: 13px; font-weight: bold; cursor: pointer; color: white; transition: opacity 0.2s; }
.invite-btn:active { opacity: 0.7; }
.invite-btn.accept { background: #4CAF50; }
.invite-btn.decline { background: #ff4d4d; }

.media-tabs-container { display: flex; justify-content: space-around; background: var(--bg-panel, #ffffff); padding: 10px 5px; border-radius: 12px 12px 0 0; margin-bottom: 5px; }
.media-tab { color: var(--text-sub, #888888); font-size: 14px; font-weight: bold; padding: 6px 16px; border-radius: 20px; cursor: pointer; transition: all 0.2s ease; }
.media-tab.active { background: var(--msg-out-bg, #e3f2fd); color: var(--accent-color, #4a90e2); }

.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding-bottom: 10px; }
.media-grid-item { aspect-ratio: 1 / 1; background: var(--bg-hover, #f0f4f8); position: relative; cursor: pointer; overflow: hidden; touch-action: pan-y; border-radius: 10px; content-visibility: auto; contain-intrinsic-size: 110px; contain: layout paint style; }
.media-grid-item img, .media-grid-item video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.media-grid-item img.media-thumb-img, .media-grid-item video.media-thumb-video { opacity: 0; transition: opacity 0.25s ease; }
.media-grid-item.media-grid-loaded img.media-thumb-img, .media-grid-item.media-grid-loaded video.media-thumb-video { opacity: 1; }
/* Empty <img src=""> / <video> must never show the native broken-image glyph. */
.hidden-media { display: none !important; }
.video-grid-overlay { position: absolute; bottom: 5px; left: 5px; background: rgba(0, 0, 0, 0.6); color: white; font-size: 10px; padding: 3px 6px; border-radius: 5px; display: flex; align-items: center; gap: 4px; font-weight: bold; pointer-events: none; z-index: 2; }

/* Loading shimmer + spinner for gallery thumbnails */
.media-grid-loading { background: linear-gradient(100deg, var(--bg-hover, #e9eef5) 30%, rgba(255,255,255,0.55) 50%, var(--bg-hover, #e9eef5) 70%); background-size: 200% 100%; animation: mediaGridShimmer 1.2s ease-in-out infinite; }
@keyframes mediaGridShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.media-grid-spinner { position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border: 2px solid rgba(74,144,226,0.25); border-top-color: var(--accent-color, #4a90e2); border-radius: 50%; animation: mediaGridSpin 0.8s linear infinite; z-index: 1; }
@keyframes mediaGridSpin { to { transform: rotate(360deg); } }
.media-grid-failed { background: var(--bg-hover, #f0f4f8); animation: none; }
.media-grid-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 26px; opacity: 0.45; }

.media-empty-text { color: var(--text-sub, #888888); font-size: 14px; text-align: center; padding: 28px 12px; }

/* Smoother, theme-aware scrollbar for the media gallery */
#chat-media-list { scrollbar-width: thin; scrollbar-color: var(--accent-color, #4a90e2) transparent; scroll-behavior: smooth; }
#chat-media-list::-webkit-scrollbar { width: 6px; }
#chat-media-list::-webkit-scrollbar-track { background: transparent; margin: 4px 0; }
#chat-media-list::-webkit-scrollbar-thumb { background: rgba(74, 144, 226, 0.55); background: color-mix(in srgb, var(--accent-color, #4a90e2) 55%, transparent); border-radius: 6px; min-height: 40px; }
#chat-media-list::-webkit-scrollbar-thumb:active { background: var(--accent-color, #4a90e2); }

/* ==========================================
   БОМБОЧКИ
   ========================================== */
.bomb-timer-badge { background: #ff4d4d; color: white; font-size: 10px; font-weight: bold; padding: 2px 6px; border-radius: 6px; margin-left: 8px; display: inline-flex; align-items: center; gap: 3px; box-shadow: 0 0 5px rgba(255, 77, 77, 0.3); animation: pulse-bomb 1.5s infinite; }
@keyframes pulse-bomb { 0% { opacity: 1; } 50% { opacity: 0.6; } 100% { opacity: 1; } }

.msg-exploding { animation: explode-fade 1s forwards; }
@keyframes explode-fade { 0% { transform: scale(1); opacity: 1; filter: blur(0); } 50% { transform: scale(1.05); opacity: 0.5; filter: blur(2px); background: #ff4d4d; } 100% { transform: scale(0.8); opacity: 0; filter: blur(5px); display: none; } }

/* ==========================================
   АНИМАЦИИ И ЭФФЕКТЫ (ВЕСЕЛЬЕ)
   ========================================== */
@keyframes fallFx {
    0% { transform: translateY(0px) rotate(0deg); }
    100% { transform: translateY(110vh) rotate(360deg); }
}
@keyframes riseFx {
    0% { transform: translateY(50px) rotate(0deg); }
    100% { transform: translateY(-110vh) rotate(360deg); }
}

#fx-container.fx-ambient {
    z-index: 120 !important;
    overflow: hidden;
}

.fx-ambient-particle {
    position: absolute;
    width: var(--fx-size);
    height: var(--fx-size);
    font-size: var(--fx-size);
    opacity: var(--fx-opacity);
    pointer-events: none;
    will-change: transform, opacity;
    animation-duration: var(--fx-duration);
    animation-delay: var(--fx-delay);
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

.fx-fall {
    animation-name: ambientFall;
}

.fx-rise {
    animation-name: ambientRise;
}

.fx-wander {
    animation-name: ambientWander;
}

.fx-fire-rise {
    animation-name: emberRise;
}

.fx-snow {
    mix-blend-mode: screen;
}

.fx-snowflake {
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.96), rgba(210,235,255,0.38) 62%, transparent 72%);
    box-shadow: 0 0 10px rgba(230, 245, 255, 0.45);
    filter: blur(0.15px);
}

.fx-hearts {
    mix-blend-mode: screen;
}

.fx-heart {
    transform: rotate(45deg);
    background: linear-gradient(135deg, rgba(255, 140, 190, 0.94), rgba(255, 64, 128, 0.62));
    border-radius: 4px;
    box-shadow: 0 0 14px rgba(255, 90, 160, 0.35);
}

.fx-heart::before,
.fx-heart::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
}

.fx-heart::before {
    left: -50%;
}

.fx-heart::after {
    top: -50%;
}

.fx-autumn .fx-leaf {
    background: linear-gradient(135deg, #f7b44a 0%, #c85a2a 45%, #6f351c 100%);
    border-radius: 0 70% 0 70%;
    box-shadow: inset 1px 1px 0 rgba(255,255,255,0.18), 0 6px 14px rgba(92, 50, 18, 0.18);
}

.fx-autumn .fx-leaf:nth-child(3n) {
    background: linear-gradient(135deg, #d56b2c, #8f3b20 55%, #5b2a18);
}

.fx-autumn .fx-leaf:nth-child(4n) {
    background: linear-gradient(135deg, #e8c15a, #9a6f28 55%, #4d3a1f);
}

.fx-spring {
    mix-blend-mode: screen;
}

.fx-sakura-petal {
    background: radial-gradient(circle at 30% 28%, rgba(255,255,255,0.85), rgba(255, 185, 215, 0.86) 42%, rgba(235, 96, 150, 0.38) 100%);
    border-radius: 70% 30% 70% 30%;
    box-shadow: 0 0 10px rgba(255, 170, 210, 0.24);
}

.fx-bubbles {
    mix-blend-mode: screen;
}

.fx-bubble {
    border-radius: 50%;
    border: 1px solid rgba(210, 245, 255, 0.52);
    background:
        radial-gradient(circle at 30% 28%, rgba(255,255,255,0.8) 0 8%, transparent 10%),
        radial-gradient(circle at 65% 70%, rgba(120,220,255,0.2), transparent 55%);
    box-shadow: inset 0 0 12px rgba(190, 245, 255, 0.25), 0 0 12px rgba(120, 220, 255, 0.18);
}

.fx-fire {
    mix-blend-mode: screen;
    background: radial-gradient(ellipse at 50% 100%, rgba(255, 92, 12, 0.18), transparent 50%);
}

.fx-fire-glow {
    position: absolute;
    left: -10%;
    right: -10%;
    bottom: -18%;
    height: 42%;
    background: radial-gradient(ellipse at 50% 100%, rgba(255, 112, 28, 0.32), rgba(255, 48, 18, 0.08) 42%, transparent 72%);
    filter: blur(18px);
    animation: fireGlowPulse 4s ease-in-out infinite;
}

.fx-ember {
    border-radius: 50% 50% 46% 46%;
    background: radial-gradient(circle at 45% 35%, #fff0a8 0%, #ff9d2e 34%, #ef3b18 68%, transparent 72%);
    box-shadow: 0 0 12px rgba(255, 106, 31, 0.62), 0 0 26px rgba(255, 72, 20, 0.22);
}

.fx-cats {
    mix-blend-mode: screen;
}

.fx-cat-paw {
    width: calc(var(--fx-size) * 0.95);
    height: calc(var(--fx-size) * 0.8);
}

.fx-cat-paw::before {
    content: '';
    position: absolute;
    left: 34%;
    top: 38%;
    width: 42%;
    height: 40%;
    border-radius: 50% 50% 45% 45%;
    background: rgba(210, 230, 255, 0.56);
    box-shadow:
        -0.36em -0.34em 0 -0.08em rgba(210, 230, 255, 0.54),
        0 -0.44em 0 -0.08em rgba(210, 230, 255, 0.62),
        0.36em -0.34em 0 -0.08em rgba(210, 230, 255, 0.54);
    filter: drop-shadow(0 0 7px rgba(170, 210, 255, 0.24));
}

.fx-cat-eyes {
    width: calc(var(--fx-size) * 1.4);
    height: calc(var(--fx-size) * 0.55);
}

.fx-cat-eyes::before,
.fx-cat-eyes::after {
    content: '';
    position: absolute;
    top: 0;
    width: 38%;
    height: 100%;
    border-radius: 50% 50% 42% 42%;
    background: radial-gradient(circle, rgba(200,255,150,0.95), rgba(100,190,80,0.3) 62%, transparent 70%);
    box-shadow: 0 0 14px rgba(160,255,120,0.35);
}

.fx-cat-eyes::before {
    left: 0;
}

.fx-cat-eyes::after {
    right: 0;
}

#fx-container.fx-on-light.fx-ambient,
#fx-container.fx-on-light.fx-rain {
    mix-blend-mode: normal;
}

#fx-container.fx-on-light.fx-hearts .fx-heart {
    background: linear-gradient(135deg, rgba(255, 92, 160, 0.98), rgba(200, 28, 96, 0.78));
    box-shadow: 0 0 0 1px rgba(150, 20, 80, 0.18), 0 8px 18px rgba(190, 34, 102, 0.28);
}

#fx-container.fx-on-light.fx-snow .fx-snowflake {
    background: radial-gradient(circle, rgba(120, 170, 210, 0.72), rgba(70, 120, 170, 0.28) 62%, transparent 72%);
    box-shadow: 0 0 8px rgba(70, 120, 170, 0.24);
}

#fx-container.fx-on-light.fx-spring .fx-sakura-petal {
    background: radial-gradient(circle at 30% 28%, rgba(255,255,255,0.72), rgba(238, 118, 166, 0.9) 44%, rgba(180, 52, 112, 0.46) 100%);
    box-shadow: 0 0 0 1px rgba(170, 60, 120, 0.12), 0 8px 16px rgba(170, 60, 120, 0.18);
}

#fx-container.fx-on-light.fx-bubbles .fx-bubble {
    border-color: rgba(42, 126, 170, 0.55);
    background:
        radial-gradient(circle at 30% 28%, rgba(255,255,255,0.95) 0 8%, transparent 10%),
        radial-gradient(circle at 65% 70%, rgba(45, 150, 205, 0.24), transparent 55%);
    box-shadow: inset 0 0 12px rgba(52, 150, 205, 0.2), 0 0 10px rgba(42, 126, 170, 0.18);
}

#fx-container.fx-on-light.fx-cats .fx-cat-paw::before {
    background: rgba(78, 88, 120, 0.42);
    box-shadow:
        -0.36em -0.34em 0 -0.08em rgba(78, 88, 120, 0.38),
        0 -0.44em 0 -0.08em rgba(78, 88, 120, 0.48),
        0.36em -0.34em 0 -0.08em rgba(78, 88, 120, 0.38);
    filter: drop-shadow(0 0 5px rgba(48, 58, 90, 0.16));
}

#fx-container.fx-on-light.fx-cats .fx-cat-eyes::before,
#fx-container.fx-on-light.fx-cats .fx-cat-eyes::after {
    background: radial-gradient(circle, rgba(54, 130, 62, 0.82), rgba(24, 92, 44, 0.28) 62%, transparent 70%);
    box-shadow: 0 0 10px rgba(24, 92, 44, 0.18);
}

#fx-container.fx-on-light.fx-fire {
    background: radial-gradient(ellipse at 50% 100%, rgba(216, 68, 10, 0.18), transparent 50%);
}

#fx-container.fx-on-light.fx-fire .fx-fire-glow {
    background: radial-gradient(ellipse at 50% 100%, rgba(230, 74, 20, 0.28), rgba(200, 34, 10, 0.08) 42%, transparent 72%);
}

#fx-container.fx-on-light.fx-fire .fx-ember {
    background: radial-gradient(circle at 45% 35%, #fff2a0 0%, #ff8a22 34%, #c92812 68%, transparent 72%);
    box-shadow: 0 0 10px rgba(210, 68, 18, 0.42), 0 0 20px rgba(210, 68, 18, 0.16);
}

#fx-container.fx-on-light.fx-autumn .fx-leaf {
    box-shadow: inset 1px 1px 0 rgba(255,255,255,0.2), 0 6px 14px rgba(92, 50, 18, 0.24);
}

#fx-container.fx-on-light.fx-rain {
    background:
        radial-gradient(ellipse at 50% 0%, rgba(72, 118, 170, 0.1), transparent 45%),
        linear-gradient(180deg, rgba(40, 70, 100, 0.08), rgba(20, 40, 60, 0.04));
}

#fx-container.fx-on-light.fx-rain .fx-raindrop {
    background: linear-gradient(180deg, transparent 0%, rgba(70, 125, 180, 0.58) 52%, rgba(50, 100, 150, 0.1) 100%);
}

#fx-container.fx-on-light.fx-rain .fx-rain-splash {
    border-color: rgba(70, 125, 180, 0.32);
}

@keyframes ambientFall {
    0% {
        transform: translate3d(0, -18vh, 0) rotate(var(--fx-rotate));
        opacity: 0;
    }
    12% { opacity: var(--fx-opacity); }
    50% { transform: translate3d(var(--fx-sway), 54vh, 0) rotate(calc(var(--fx-rotate) + var(--fx-spin))); }
    100% {
        transform: translate3d(var(--fx-drift), 124vh, 0) rotate(calc(var(--fx-rotate) + var(--fx-spin-2)));
        opacity: 0;
    }
}

@keyframes ambientRise {
    0% {
        transform: translate3d(0, 14vh, 0) scale(0.72) rotate(var(--fx-rotate));
        opacity: 0;
    }
    16% { opacity: var(--fx-opacity); }
    72% { opacity: var(--fx-opacity); }
    100% {
        transform: translate3d(var(--fx-drift), -118vh, 0) scale(1.08) rotate(calc(var(--fx-rotate) + var(--fx-spin)));
        opacity: 0;
    }
}

@keyframes ambientWander {
    0% {
        transform: translate3d(0, 112vh, 0) scale(0.85) rotate(var(--fx-rotate));
        opacity: 0;
    }
    15% { opacity: var(--fx-opacity); }
    50% { transform: translate3d(var(--fx-sway), 42vh, 0) scale(1) rotate(calc(var(--fx-rotate) + 18deg)); }
    100% {
        transform: translate3d(var(--fx-drift), -24vh, 0) scale(0.8) rotate(calc(var(--fx-rotate) - 16deg));
        opacity: 0;
    }
}

@keyframes emberRise {
    0% {
        transform: translate3d(0, 8vh, 0) scale(0.45);
        opacity: 0;
    }
    14% { opacity: var(--fx-opacity); }
    60% { opacity: var(--fx-opacity); }
    100% {
        transform: translate3d(var(--fx-drift), -96vh, 0) scale(0.08);
        opacity: 0;
    }
}

@keyframes fireGlowPulse {
    0%, 100% { opacity: 0.78; transform: scaleX(1); }
    50% { opacity: 1; transform: scaleX(1.08); }
}

#fx-container.fx-rain {
    z-index: 120 !important;
    mix-blend-mode: screen;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(180, 210, 255, 0.12), transparent 45%),
        linear-gradient(180deg, rgba(8, 16, 28, 0.16), rgba(4, 8, 14, 0.08));
}

#fx-container.fx-rain::before {
    content: '';
    position: absolute;
    inset: -10%;
    opacity: 0;
    background: rgba(210, 230, 255, 0.75);
    transition: opacity 0.08s ease-out;
}

#fx-container.fx-rain.fx-rain-lightning::before {
    opacity: 0.2;
    animation: rainLightning 0.16s ease-out;
}

#fx-container.fx-rain.fx-rain-heavy {
    background:
        radial-gradient(ellipse at 50% 0%, rgba(180, 210, 255, 0.18), transparent 48%),
        linear-gradient(180deg, rgba(8, 16, 28, 0.22), rgba(4, 8, 14, 0.12));
}

#fx-container.fx-rain.fx-rain-heavy .fx-raindrop {
    filter: brightness(1.35) drop-shadow(0 0 4px rgba(160, 210, 255, 0.35));
}

#fx-container.fx-rain.fx-rain-heavy .fx-rain-mist {
    opacity: 1;
}

.fx-rain-mist {
    position: absolute;
    inset: auto -10% 0 -10%;
    height: 34%;
    background: linear-gradient(180deg, transparent, rgba(180, 205, 230, 0.12));
    filter: blur(10px);
    opacity: 0.8;
}

.fx-raindrop {
    position: absolute;
    top: -24vh;
    width: 1px;
    border-radius: 999px;
    pointer-events: none;
    transform: rotate(12deg);
    transform-origin: center bottom;
    background: linear-gradient(180deg, transparent 0%, rgba(230, 245, 255, 0.92) 52%, rgba(120, 180, 230, 0.08) 100%);
    animation-name: realRainFall;
    animation-duration: var(--rain-duration, 2.6s);
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    will-change: transform;
}

.fx-rain-back {
    width: 1px;
    filter: blur(0.4px);
}

.fx-rain-mid {
    width: 1.5px;
    filter: blur(0.15px);
}

.fx-rain-front {
    width: 2px;
    filter: drop-shadow(0 0 3px rgba(160, 210, 255, 0.45));
}

.fx-rain-splashes {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.fx-rain-splash {
    position: absolute;
    width: 16px;
    height: 4px;
    border: 1px solid rgba(190, 225, 255, 0.38);
    border-top: none;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.2);
    animation: realRainSplash 0.8s ease-out infinite;
}

@keyframes realRainFall {
    0% { transform: translate3d(0, -30vh, 0) rotate(8deg); }
    100% { transform: translate3d(-9vw, 132vh, 0) rotate(8deg); }
}

@keyframes realRainSplash {
    0% { opacity: 0; transform: scale(0.2); }
    42% { opacity: 0.46; }
    100% { opacity: 0; transform: scale(1.25); }
}

@keyframes rainLightning {
    0%, 100% { opacity: 0; }
    18% { opacity: 0.22; }
    38% { opacity: 0.06; }
    62% { opacity: 0.18; }
}

@keyframes popInMsg {
    0% { opacity: 0; transform: scale(0.8) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes pawTapIn {
    0% { transform: translate(-30px, 30px) scale(0); opacity: 0; }
    50% { transform: translate(0, 0) scale(1.5); opacity: 1; }
    100% { transform: translate(-20px, 20px) scale(0); opacity: 0; }
}
@keyframes pawTapOut {
    0% { transform: translate(30px, 30px) scale(0); opacity: 0; }
    50% { transform: translate(0, 0) scale(1.5); opacity: 1; }
    100% { transform: translate(20px, 20px) scale(0); opacity: 0; }
}

.msg-animated {
    animation: popInMsg 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    animation-delay: 0.2s;
    opacity: 0;
    position: relative;
}
.msg-animated::after {
    content: '🐾';
    position: absolute;
    bottom: -15px;
    left: -20px;
    font-size: 24px;
    opacity: 0;
    animation: pawTapIn 0.6s ease-out forwards;
    z-index: 10;
    pointer-events: none;
}
.msg.out.msg-animated::after {
    left: auto;
    right: -20px;
    animation: pawTapOut 0.6s ease-out forwards;
}

/* Скроллбары для модалок */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 3px; }

/* ==========================================
   📢 РЕКЛАМНЫЙ БАННЕР (Ad Banner)
   ========================================== */
#ad-banner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: adBannerFadeIn 0.3s ease-out;
}
#ad-banner-overlay.ad-banner-hiding {
    animation: adBannerFadeOut 0.4s ease-in forwards;
}
@keyframes adBannerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes adBannerFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
#ad-banner-box {
    background: var(--bg-panel, #ffffff);
    border: 2px solid #ff9800;
    border-radius: 20px;
    padding: 30px 25px;
    max-width: 380px;
    width: 85%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(255, 152, 0, 0.15), 0 0 0 1px rgba(255, 152, 0, 0.05);
    animation: adBannerPop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes adBannerPop {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
#ad-banner-box .ad-badge {
    display: inline-block;
    background: #ff9800;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 15px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
#ad-banner-box .ad-text {
    color: var(--text-main, #333333);
    font-size: 18px;
    font-weight: bold;
    line-height: 1.4;
    margin-bottom: 12px;
}
#ad-banner-box .ad-subtext {
    color: var(--text-sub, #888888);
    font-size: 13px;
    margin-bottom: 18px;
}
#ad-banner-box .ad-image {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
}
#ad-banner-box .ad-link-btn {
    display: inline-block;
    background: #ff9800;
    color: #fff;
    padding: 12px 30px;
    border-radius: 25px;
    font-weight: bold;
    font-size: 15px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}
#ad-banner-box .ad-link-btn:active {
    background: #e68900;
}
#ad-banner-timer {
    color: var(--text-sub, #888888);
    font-size: 12px;
    margin-top: 15px;
}
#ad-banner-close {
    background: #17212b !important;
    border: 2px solid #ffffff !important;
    color: #ffffff !important;
    font-size: 20px;
    font-weight: 900;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35), 0 0 0 3px rgba(255,152,0,0.35);
    transition: transform 0.15s ease, background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
#ad-banner-close:hover,
#ad-banner-close:focus {
    background: #ff9800 !important;
    color: #ffffff !important;
    outline: none;
}
#ad-banner-close:active {
    transform: scale(0.94);
}

/* ==========================================
   AUTH UI CLASSES
   ========================================== */
.auth-title { color:var(--primary-color, #40a7e3); margin-bottom:10px; }
.auth-title-setup { color:var(--primary-color, #40a7e3); margin-top: 0; margin-bottom: 10px; }
.auth-title-social { color:#4CAF50; margin-top: 0; }
.auth-title-success { color:#4CAF50; }
.auth-title-import { color:var(--orange-color, #ff9800); }
.auth-loading { color:var(--primary-color, #40a7e3); text-align:center; margin-top:20px; }

.auth-subtitle { color:var(--text-sub, #7f91a4); }
.auth-desc { color:var(--text-sub, #7f91a4); font-size:12px; margin-bottom:15px; line-height: 1.4; }
.auth-desc-social { color:var(--text-sub, #7f91a4); font-size:13px; }
.auth-desc-social-mb { color:var(--text-sub, #7f91a4); font-size:13px; margin-bottom:15px; }
.auth-note { color:var(--text-sub, #7f91a4); font-size:11px; margin-top:15px; }

.auth-warning { color:#ff4d4d; font-size:12px; margin-top:10px; }
.auth-alert { color:#ff4d4d; font-weight:bold; font-size:13px; margin-bottom:10px; }

.auth-seed-container { position: relative; background:#1c2938; border:1px solid var(--orange-color, #ff9800); border-radius:8px; padding:15px; margin-bottom:15px; cursor:pointer; }
.auth-seed-overlay { position: absolute; top:0; left:0; width:100%; height:100%; display:flex; justify-content:center; align-items:center; background: rgba(28, 41, 56, 0.85); z-index:2; border-radius:8px; font-weight:bold; color:var(--orange-color, #ff9800); font-size:14px; }
.auth-seed-text { color:var(--primary-color, #40a7e3); font-size:16px; line-height:1.5; filter: blur(5px); display:block; text-align:center; }

.auth-input-mb { margin-bottom:15px; }
.auth-input-mb10 { margin-bottom:10px; }
.auth-input-panic { margin-bottom:15px; border-color:#ff4d4d; }
.auth-textarea { height:80px; }

.auth-switch-container { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; background: var(--bg-color, #f5f7fb); padding: 10px; border-radius: 8px; }
.auth-switch-label { color: var(--accent-color, #4a90e2); font-size: 13px; font-weight: bold; }
.auth-switch-wrap { position: relative; display: inline-block; width: 40px; height: 24px; flex-shrink: 0; }
.auth-switch-input { opacity: 0; width: 0; height: 0; }
.auth-switch-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--btn-dark, #2b5278); transition: .4s; border-radius: 24px; }

.btn-success { background:#4CAF50; }
.btn-success-mt { background:#4CAF50; margin-top:15px; font-size:14px; }
.btn-warning-mt { background:var(--orange-color, #ff9800); margin-top: 15px; }
.btn-dark-mb { background:var(--btn-dark, #2b5278); margin-bottom:15px; }

.btn-link { background:none; color:var(--primary-color, #40a7e3); text-decoration:underline; border:none; cursor:pointer; font-size:14px; margin-top:15px; }
.btn-cancel { background:none; color:#ff4d4d; border:none; margin-top:10px; cursor:pointer; }
.btn-skip { background:none; color:var(--text-main, #333333); border:none; margin-top:10px; cursor:pointer; font-weight:600; }
.btn-link-success { background:none; color:#4CAF50; text-decoration:underline; border:none; cursor:pointer; margin-top:10px; }
.btn-link-gray { background:none; border:none; color:var(--text-main, #333333); text-decoration:underline; cursor:pointer; margin-top:10px; font-weight:600; }

/* ==========================================
   THEME PALETTES & COLOR PICKER
   ========================================== */
.palette-item {
    position: relative;
    background: var(--bg-panel, #ffffff);
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}
.palette-item.active {
    border: 2px solid var(--primary-color, #40a7e3);
    box-shadow: 0 0 8px var(--primary-color, #40a7e3);
}
.palette-checkmark {
    display: none;
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--primary-color, #40a7e3);
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
.palette-item.active .palette-checkmark {
    display: flex;
}
.palette-colors {
    display: flex;
    gap: 4px;
}
.palette-color-1, .palette-color-2, .palette-color-3 {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}
.palette-name {
    font-size: 11px;
    color: var(--text-main, #333333);
    font-weight: bold;
    max-width: 100%;
    overflow-wrap: anywhere;
    line-height: 1.2;
    text-align: center;
}

#appearance-modal {
    overflow-x: hidden !important;
    top: calc(env(safe-area-inset-top, 0px) + 10px) !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: min(92vw, 380px) !important;
    max-width: min(380px, calc(100vw - 20px)) !important;
    max-height: none !important;
    height: auto !important;
    border-color: rgba(255, 255, 255, 0.08) !important;
    background-clip: padding-box;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
}

#appearance-modal * {
    min-width: 0;
    max-width: 100%;
}

#appearance-modal div,
#appearance-modal .palette-item,
#appearance-modal .style-item {
    touch-action: pan-y;
}

#appearance-modal button,
#appearance-modal select,
#appearance-modal label {
    touch-action: manipulation;
}

#appearance-modal input[type="color"] {
    pointer-events: none;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: 1px solid rgba(255, 255, 255, 0.18) !important;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
}

#appearance-modal .appearance-picker-section > summary::-webkit-details-marker {
    display: none;
}

#appearance-modal .appearance-picker-section > summary::after {
    content: 'Открыть';
    flex: 0 0 auto;
    color: var(--primary-color, #40a7e3);
    font-size: 11px;
    font-weight: 800;
}

#appearance-modal .appearance-picker-section[open] > summary::after {
    content: 'Скрыть';
}

#appearance-modal div[style*="justify-content: space-between"] {
    gap: 10px;
    flex-wrap: wrap;
}

#appearance-modal div[style*="justify-content: space-between"] > span {
    flex: 1 1 120px;
    overflow-wrap: anywhere;
    line-height: 1.25;
}

#appearance-modal div[style*="justify-content: space-between"] > div {
    flex: 0 1 auto;
    justify-content: flex-end;
}

#fun-pet-type,
#fun-fx-select {
    width: min(150px, 46vw) !important;
    max-width: 100% !important;
}

#appearance-modal .switch {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    flex: 0 0 40px !important;
}

#palettes-grid,
#styles-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(92px, 100%), 1fr)) !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    box-sizing: border-box;
}

#palettes-grid .palette-item,
#styles-grid .palette-item,
#styles-grid .style-item {
    min-width: 0;
    max-width: 100%;
}

.style-name {
    max-width: 100%;
    overflow-wrap: anywhere;
    line-height: 1.15;
    text-align: center;
}

.color-picker-item {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}
.color-picker-item.active {
    transform: scale(1.15);
    box-shadow: 0 0 0 3px var(--bg-panel, #fff), 0 0 0 6px var(--text-main, #333), 0 5px 15px rgba(0,0,0,0.5);
    z-index: 10;
}
.color-picker-name {
    font-size: 9px;
    text-align: center;
    word-break: break-word;
    line-height: 1.1;
    pointer-events: none;
}

/* sm-chat-load.js classes */
.load-older-btn { width:100%; background:none; border:none; color:var(--primary-color, #40a7e3); padding:15px; cursor:pointer; font-weight:bold; font-size:14px; }
/* Разделитель сообщений по дням (Сегодня / Вчера / дата) */
.chat-date-divider { display:flex; align-items:center; justify-content:center; width:100%; margin:14px 0 10px; pointer-events:none; }
.chat-date-divider span { display:inline-block; padding:4px 12px; border-radius:14px; background:rgba(0,0,0,0.32); color:#fff; font-size:12px; font-weight:600; line-height:1.3; text-shadow:0 1px 2px rgba(0,0,0,0.35); backdrop-filter:blur(2px); -webkit-backdrop-filter:blur(2px); }

/* ===== Непрослушанные входящие голосовые / видеокружки ===== */

/* Голосовое: пока не прослушано — кнопка play красная.
   После прослушивания класс снимается, кнопка возвращается к обычному виду. */
.msg.in.voice-unlistened .voice-play-btn {
    background: #ff4d4d;
    color: #fff;
    box-shadow: 0 2px 8px rgba(255,77,77,0.5), 0 0 0 1px rgba(255,255,255,0.12) inset;
}

/* Видеокружок: пока не просмотрено — ободок красный со свечением. */
.msg.in.voice-unlistened .circle-video {
    border-color: #ff4d4d;
    box-shadow: 0 0 0 1px rgba(255,77,77,0.55), 0 0 12px rgba(255,77,77,0.6);
    animation: smUnlistenedRing 1.8s ease-in-out infinite;
}

@keyframes smUnlistenedRing {
    0%, 100% { box-shadow: 0 0 0 1px rgba(255,77,77,0.5), 0 0 10px rgba(255,77,77,0.45); }
    50% { box-shadow: 0 0 0 2px rgba(255,77,77,0.85), 0 0 16px rgba(255,77,77,0.8); }
}
.msg-reply-wrapper { border-left:3px solid var(--primary-color, #40a7e3); padding-left:8px; margin-bottom:5px; background:rgba(64,167,227,0.1); border-radius:4px; padding:4px; cursor:pointer; }
.msg-reply-sender { color:var(--primary-color, #40a7e3); font-size:11px; }
.msg-reply-text { font-size:11px; color:#a6c4e0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:200px; }
#chat .msg { -webkit-user-select:none; user-select:none; touch-action:pan-y; will-change:transform; }
#chat.msg-action-focus > *:not(.msg-action-target) { filter:blur(5px); opacity:0.12; transition:filter 0.16s ease, opacity 0.16s ease; pointer-events:none; }
#chat.msg-action-focus .msg-action-target { position:relative; z-index:10040; filter:none !important; opacity:1 !important; transform:scale(1.015); box-shadow:0 8px 26px rgba(0,0,0,0.28); transition:transform 0.16s ease, box-shadow 0.16s ease; }
#chat.msg-action-focus .voice-menu-btn[data-sm-media-menu="1"] { display:none; }
.msg-pinned-mark { display:inline-flex; align-items:center; justify-content:center; width:18px; height:18px; margin-right:5px; border-radius:50%; background:rgba(20,32,24,0.82); color:#fff; font-size:11px; line-height:1; vertical-align:middle; box-shadow:0 1px 4px rgba(0,0,0,0.28); }
.msg-media-footer .msg-pinned-mark { margin-right:0; }
.msg-action-menu { position:fixed; z-index:30050; display:flex; gap:6px; padding:6px; border-radius:14px; background:rgba(20, 32, 24, 0.96); box-shadow:0 6px 20px rgba(0,0,0,0.28); border:1px solid rgba(255,255,255,0.12); touch-action:manipulation; }
.msg-action-menu button { touch-action:manipulation; border:none; border-radius:10px; padding:9px 12px; background:var(--primary-color, #40a7e3); color:white; font-size:13px; font-weight:bold; cursor:pointer; white-space:nowrap; }
.msg-action-menu .msg-action-icon-btn { width:42px; height:42px; padding:0; border-radius:50%; font-size:19px; line-height:42px; text-align:center; }
.msg-action-menu button + button { background:var(--bg-panel, #ffffff); color:var(--text-main, #333333); }
.msg-reply-button { display:none; position:absolute; top:50%; width:22px; height:22px; margin-top:-11px; border:1px solid rgba(64,167,227,0.35); border-radius:50%; background:rgba(255,255,255,0.88); color:var(--primary-color, #40a7e3); box-shadow:0 1px 5px rgba(0,0,0,0.16); font-size:13px; line-height:20px; padding:0; cursor:pointer; opacity:0; transform:scale(0.92); transition:opacity 0.16s ease, transform 0.16s ease; z-index:3; }
.msg.in .msg-reply-button { right:-27px; }
.msg.out .msg-reply-button { left:-27px; }
.msg:hover .msg-reply-button,
.msg:focus-within .msg-reply-button,
.msg.is-reply-swiping .msg-reply-button,
.msg-reply-button:focus { display:block; opacity:0.9; transform:scale(1); }
.msg-reply-button:active { transform:scale(0.94); }
body.theme-bubbles .msg.out:not(.msg-sticker) .msg-reply-button { background:rgba(255,255,255,0.95); color:var(--primary-color, #4a90e2); }
@media (hover: none), (pointer: coarse) {
    .msg.is-reply-swiping .msg-reply-button { display:block; opacity:0.82; transform:scale(1); }
}
.media-dl-btn { display:none; text-decoration:none; background:#182533; color:var(--primary-color, #40a7e3); padding:5px 12px; border-radius:8px; font-size:12px; font-weight:bold; margin-top:5px; border: 1px solid var(--btn-dark, #2b5278); cursor:pointer; }
.reaction-img { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; }
.reaction-emoji { font-size:16px; }
.reaction-wrapper { font-size:12px; color:var(--text-sub, #7f91a4); font-style:italic; }
.sticker-img { width: 100px; height: 100px; object-fit: contain; filter: drop-shadow(0 0 5px rgba(0,0,0,0.2)); }
.msg-image { display:block; max-width:100%; border-radius:10px; cursor:pointer; }
.msg-image-wrapper { display:flex; flex-direction:column; align-items:center; max-width:100%; }
.msg-image-row { display:flex; align-items:center; gap:8px; max-width:100%; }
.msg.out .msg-image-row { flex-direction:row-reverse; }
.msg-image-shell { position:relative; display:inline-block; max-width:100%; }
.media-caption { align-self:stretch; margin-top:8px; color:currentColor; font-size:14px; line-height:1.35; white-space:pre-wrap; word-break:break-word; }
.msg.in .media-caption { text-align:left; }
.msg.out .media-caption { text-align:right; }
.msg-media-footer { display:flex; align-items:center; justify-content:center; gap:10px; margin-top:6px; flex-wrap:nowrap; width:100%; }
.msg-media-actions { position:absolute; left:8px; bottom:8px; display:flex; align-items:center; gap:6px; flex-shrink:0; z-index:2; }
.msg-meta.msg-meta-media { margin-top:0; flex-shrink:0; white-space:nowrap; opacity:0.85; }
.msg.out .msg-media-footer { justify-content:flex-end; }
.msg.in .msg-media-footer { justify-content:flex-start; }
.media-btn { background:var(--bg-panel, #ffffff); color:var(--text-main, #333333); border:none; padding:0 15px; height:36px; border-radius:18px; font-size:13px; font-weight:bold; cursor:pointer; line-height:36px; text-align:center; box-shadow:0 1px 3px rgba(0,0,0,0.1); text-decoration:none; display:inline-block; }
.media-icon-btn { width:34px; height:34px; border-radius:50%; border:none; background:rgba(255,255,255,0.92); color:var(--text-main, #333333); display:inline-flex; align-items:center; justify-content:center; font-size:16px; font-weight:bold; line-height:1; cursor:pointer; box-shadow:0 2px 8px rgba(0,0,0,0.24); padding:0; backdrop-filter:blur(6px); }
.media-icon-btn:active { transform:scale(0.94); }
.msg-image-row .voice-menu-btn,
.media-video-wrapper .voice-menu-btn { flex:0 0 32px; align-self:center; }
.forward-media-item { width:100%; text-align:left; font:inherit; }
body.image-viewer-open { overflow:hidden !important; }
#image-viewer-modal.active { position:fixed !important; inset:0 !important; left:0 !important; right:0 !important; top:0 !important; bottom:0 !important; width:100% !important; height:100% !important; max-width:none !important; max-height:none !important; z-index:2147483647 !important; background:#000 !important; display:flex !important; align-items:center !important; justify-content:center !important; padding:0 !important; margin:0 !important; border-radius:0 !important; }
#image-viewer-modal.active > div:not(#image-viewer-counter) { width:100% !important; height:100% !important; overflow:hidden !important; display:flex !important; align-items:center !important; justify-content:center !important; }
/* Date/counter bar must stay pinned to the top, not stretched to full height
   (otherwise the centered flex content pushes the date to the middle of the photo). */
#image-viewer-counter { height:auto !important; width:max-content !important; align-items:initial !important; justify-content:initial !important; }
/* No backdrop-filter / brightness filters on the viewer: on some Android WebViews
   they force a blurred or darkened compositing pass over the full-screen photo. */
#image-viewer-img { width:auto !important; height:auto !important; max-width:100% !important; max-height:100% !important; object-fit:contain !important; border-radius:0 !important; margin:auto !important; filter:none !important; -webkit-filter:none !important; opacity:1 !important; mix-blend-mode:normal !important; image-rendering:auto !important; }
.voice-btn { flex-shrink:0; }
.media-video-wrapper { display:flex; flex-direction:row; align-items:center; justify-content:center; gap:10px; }
.msg.out .media-video-wrapper { flex-direction:row-reverse; }
.media-video-controls { display:flex; flex-direction:column; gap:10px; justify-content:center; width:auto; flex-shrink:0; }
.media-audio-wrapper { display:flex; align-items:center; width:min(330px, 74vw); max-width:100%; }
.media-audio { width:1px; height:1px; opacity:0; pointer-events:none; flex:0 0 1px; }
.voice-player-row { display:flex; align-items:center; gap:7px; width:100%; padding:2px 0; }
.voice-play-btn,
.voice-menu-btn,
.voice-reply-btn { width:32px; height:32px; min-width:32px; border:none; border-radius:50%; background:var(--bg-panel, #ffffff); color:var(--text-main, #333333); box-shadow:0 1px 3px rgba(0,0,0,0.1); cursor:pointer; font-size:13px; line-height:32px; padding:0; text-align:center; }
.voice-menu-btn { font-size:20px; font-weight:bold; line-height:28px; }
.voice-reply-btn { font-size:17px; font-weight:bold; }
.voice-play-visual { position:relative; flex:1; min-width:0; min-height:40px; padding:4px 6px; display:flex; flex-direction:column; justify-content:center; gap:4px; color:currentColor; }
.voice-play-visual .recording-meta { display:flex; align-items:center; gap:6px; min-width:0; font-size:13px; font-weight:700; line-height:1; }
.voice-play-visual .recording-dot { width:9px; height:9px; border-radius:50%; background:#ff4d4d; flex-shrink:0; opacity:0.45; animation:none; box-shadow:none; }
.voice-play-visual.is-playing .recording-dot { opacity:1; animation:recordDotPulse 1.2s ease-out infinite; }
.voice-play-time { flex-shrink:0; color:var(--text-sub, #7f91a4); font-variant-numeric:tabular-nums; font-weight:600; font-size:13px; }
.voice-play-visual .recording-wave { height:14px; display:flex; align-items:center; gap:3px; opacity:0.95; }
.voice-play-visual .recording-wave span { width:3px; height:5px; border-radius:999px; background:linear-gradient(180deg, var(--primary-color, #40a7e3), #ff4d4d); animation:none; opacity:0.55; }
.voice-play-visual.is-playing .recording-wave span { animation:recordWave 0.95s ease-in-out infinite; }
.voice-play-visual .recording-wave span:nth-child(2) { animation-delay:-0.82s; }
.voice-play-visual .recording-wave span:nth-child(3) { animation-delay:-0.68s; }
.voice-play-visual .recording-wave span:nth-child(4) { animation-delay:-0.54s; }
.voice-play-visual .recording-wave span:nth-child(5) { animation-delay:-0.40s; }
.voice-play-visual .recording-wave span:nth-child(6) { animation-delay:-0.26s; }
.voice-play-visual .recording-wave span:nth-child(7) { animation-delay:-0.12s; }
.voice-play-visual .recording-wave span:nth-child(8) { animation-delay:0s; }
.voice-play-visual .recording-progress { height:3px; border-radius:999px; background:rgba(127, 145, 164, 0.24); overflow:hidden; }
.voice-play-visual .voice-progress-fill { display:block; width:0; height:100%; border-radius:inherit; background:linear-gradient(90deg, var(--primary-color, #40a7e3), #ff4d4d); transition:width 0.25s ease; }
.voice-play-visual .voice-seek { position:absolute; inset:0; z-index:2; width:100%; height:100%; opacity:0.001; cursor:pointer; touch-action:none; }
.msg.out .media-audio-wrapper,
.msg.out .voice-player-row {
    flex-direction: row-reverse;
}
.file-msg-wrapper { display:flex; align-items:center; background:#1c2938; padding:10px; border-radius:10px; border:1px solid var(--btn-dark, #2b5278); gap:10px; }
.file-msg-icon { background:var(--primary-color, #40a7e3); color:white; width:40px; height:40px; border-radius:8px; display:flex; align-items:center; justify-content:center; font-size:20px; flex-shrink:0; }
.file-msg-info { flex:1; overflow:hidden; }
.file-msg-name { color:white; font-size:14px; font-weight:bold; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.file-msg-dl { color:#4CAF50; font-size:12px; font-weight:bold; text-decoration:none; cursor:pointer; }
.sys-invite-wrapper { background:#1c2938; padding:15px; border-radius:12px; border:1px dashed var(--orange-color, #ff9800); text-align:center; min-width: 200px; }
.sys-invite-icon { font-size:24px; margin-bottom:5px; }
.sys-invite-title { color:var(--orange-color, #ff9800); }
.sys-invite-name { color:white; font-size:16px; display:block; margin: 5px 0 15px 0; }
.sys-invite-btn { border:none; padding:10px 15px; border-radius:8px; font-weight:bold; cursor:pointer; width:100%; margin-bottom:8px; }
.sys-invite-btn.accept { background:#4CAF50; color:white; }
.sys-invite-btn.decline { background:var(--btn-dark, #2b5278); color:#ff4d4d; padding:8px 15px; margin-bottom:0; }
.single-emoji-msg { font-size: 80px; line-height: 1.1; display: inline-block; filter: drop-shadow(0 0 10px rgba(0,0,0,0.15)); }
.msg-sender-wrapper { display:flex; align-items:center; gap:8px; margin-bottom:4px; }
.msg-sender-sticker { background: rgba(0,0,0,0.3); padding: 2px 8px; border-radius: 10px; display: inline-block; margin-bottom: 4px; max-width: max-content; }
.msg-ticks { font-size:12px; margin-left:4px; opacity:0; transform: translateY(5px); display:inline-block; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.msg-ticks.visible { opacity:1; transform: translateY(0); }
.msg-ticks.first-tick { color: inherit; }
.msg-ticks.read-ticks { color: inherit; }
.msg-meta { display:flex; justify-content:flex-end; align-items:center; gap:4px; margin-top:5px; font-size:10px; color:currentColor; opacity: 1; }
.msg-meta.msg-meta-sticker { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 10px; color: white; width: max-content; margin-left: auto; margin-right: 0; opacity: 1; }
.d-none { display: none; }