/* WBGM — собственные стили приложения.
   Вынесено из index.html: там они занимали 32 КБ и мешали читать разметку.

   Подключать ПОСЛЕ tailwind.wbgm.css и fa.wbgm.css — здесь есть правила,
   которые их намеренно перебивают.

   Заставка и один маленький набор ключевых кадров остались внутри index.html:
   они должны сработать в первый же кадр, до того как браузер скачает этот файл. */

/* Под системными кнопками виден фон страницы. По умолчанию он белый,
   отсюда светлая полоса внизу — красим в цвет приложения. */
html {
    background-color: #0e1621;
}

:root {
    --player-height: 0px;
    /* Отступы под вырез камеры, полосу состояния и полосу жестов */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Только в установленном приложении на телефоне: в браузере полосы
   рисует он сам, а на компьютере вырезов не бывает. */
/* Записываем плоско, без вложенных @media: так правило понимают все браузеры,
   включая старые сборки Safari */
@media (display-mode: standalone) and (max-width: 767px),
       (display-mode: minimal-ui) and (max-width: 767px) {
        /* Полоса состояния и полоса жестов получают цвет шапки, а
           содержимое опускается ниже выреза камеры. Граница между
           телефоном и приложением исчезает. */
        #main-body {
            /* Полосу состояния система красит сама по theme-color.
               Нам остаётся не дать содержимому уехать под вырез камеры
               и под полосу жестов. */
            background: #17212b;
            padding-top: var(--safe-top);
            padding-bottom: var(--safe-bottom);
            padding-left: var(--safe-left);
            padding-right: var(--safe-right);
        }
}
body.global-audio-active {
    --player-height: 60px;
}

/* Новый шрифт, сглаживание текста и современный интервал */
body { 
    background-color: #0e1621; 
    color: #f5f5f5; 
    /* Системный шрифт: на Android это Roboto, на iPhone — San Francisco.
       Оба уже есть на устройстве, качать нечего. */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; 
    overflow: hidden; 
    overscroll-behavior-y: none; 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
    letter-spacing: -0.015em;
}

.custom-scrollbar::-webkit-scrollbar { width: 4px; height: 4px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background-color: rgba(255, 255, 255, 0.1); border-radius: 10px; }

/* Скрытие скроллбара для горизонтальных панелей реакций */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* Фон переписки. Раньше картинка тянулась с чужого сайта — при плохой связи
   она не приходила, и переписка выглядела голой. Теперь своя, с сервера. */
.chat-bg { background-color: #0d1420; }

video { outline: none; }
input, textarea { color: white; }

@keyframes replyFlash {
    0%, 100% { background-color: transparent; }
    25% { background-color: rgba(82, 136, 193, 0.30); }
}
.reply-flash { animation: replyFlash 1.2s ease; border-radius: 16px; }

#global-startup-loader {
    position: fixed; inset: 0; z-index: 99999; background-color: #0e1621;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: opacity 0.5s ease;
}

.tg-audio-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    transition: background 0.1s;
}
.tg-audio-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--thumb-color, #fff);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    border: none;
    transition: transform 0.1s;
}
.tg-audio-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}
.tg-audio-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--thumb-color, #fff);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}
.tg-audio-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.gap-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 100%;
    background: transparent;
    outline: none;
}
.gap-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.2s;
}
.bubble-rounded { border-radius: 12px; overflow: hidden; }

.stories-bar { display: flex; gap: 12px; overflow-x: auto; padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.stories-bar::-webkit-scrollbar { display: none; }
.story-ring { width: 56px; height: 56px; border-radius: 50%; padding: 2px; background: linear-gradient(45deg, #38bdf8, #8b5cf6, #d946ef); cursor: pointer; flex-shrink: 0; position: relative; }
.story-ring.viewed { background: #202b36; }
.story-ring img { width: 100%; height: 100%; border-radius: 50%; border: 2px solid #17212b; object-fit: cover; }

#smartProfileModal { transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); transform: translateY(100%); }
#smartProfileModal.active { transform: translateY(0); }
.profile-cover-container { height: 350px; position: relative; overflow: hidden; }
#mpCover { width: 100%; height: 100%; object-fit: cover; transform-origin: top center; will-change: transform; }
.profile-fade { background: linear-gradient(to top, #17212b 0%, transparent 100%); position: absolute; inset: 0; }

.video-preview-container { width: 320px; max-width: 100%; aspect-ratio: 16 / 9; background: rgba(0,0,0,0.5); position: relative; }

.video-circle-container {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    margin: 0 auto;
    background: #000;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}
.video-circle-container:hover { transform: scale(1.02); border-color: #5288c1; }
.video-circle-container video { width: 100%; height: 100%; object-fit: cover; }

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
#recording-overlay { backdrop-filter: blur(5px); }
.recording-circle { animation: pulse-ring 1.5s infinite; border: 3px solid #ef4444; }

#sidebar, #chat-area {
    margin-top: var(--player-height);
    height: calc(100% - var(--player-height));
    transition: margin-top 0.3s cubic-bezier(0.4, 0, 0.2, 1), height 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 767px) {
    #sidebar { width: 100%; display: flex !important; }
    #chat-area {
        position: fixed;
        /* Элемент с fixed отсчитывается от окна, а не от родителя, поэтому
           отступы под вырез приходится задавать ему отдельно. Без этого
           шапка чата на iPhone уезжала под часы и значки. */
        top: calc(var(--player-height) + var(--safe-top));
        left: var(--safe-left);
        width: calc(100% - var(--safe-left) - var(--safe-right));
        height: calc(100% - var(--player-height) - var(--safe-top) - var(--safe-bottom));
        margin-top: 0;
        transform: translateX(100%);
        display: flex !important;
        z-index: 100;
        pointer-events: none;
        /* Переход был мгновенным: сдвиг задан, а плавности не было.
           Кривая с торможением в конце — так двигаются системные экраны. */
        transition: transform .26s cubic-bezier(.32, .72, 0, 1);
    }
    body.chat-active #chat-area {
        transform: translateX(0);
        pointer-events: auto;
    }
    /* Список слегка отъезжает под переписку — появляется глубина */
    #sidebar {
        transition: transform .26s cubic-bezier(.32, .72, 0, 1), opacity .26s ease;
    }
    body.chat-active #sidebar {
        transform: translateX(-22%);
        opacity: .55;
    }
    @media (prefers-reduced-motion: reduce) {
        #chat-area, #sidebar { transition: none; }
    }
    .video-circle-container { width: 160px; height: 160px; }
}

/* Превью ссылок (Open Graph) */
.lp-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.link-preview-card { text-decoration: none; }
.link-preview-card img { background: rgba(255,255,255,0.04); }

/* Пульсация аватара во время звонка */
@keyframes ringPulse {
    0%   { box-shadow: 0 0 0 0 rgba(82,136,193,0.55); }
    70%  { box-shadow: 0 0 0 26px rgba(82,136,193,0); }
    100% { box-shadow: 0 0 0 0 rgba(82,136,193,0); }
}
.ring-pulse { position: absolute; inset: 0; border-radius: 9999px; animation: ringPulse 1.6s infinite; }

/* ==================================================================
   СОВРЕМЕННАЯ ДОВОДКА ТЁМНОЙ ТЕМЫ (палитра сохранена, вёрстка не тронута)
   ================================================================== */

/* Фон вокруг приложения (виден на ПК) — мягкое свечение и глубина */
#main-body {
    background:
        radial-gradient(1100px 700px at 18% -12%, rgba(82,136,193,.09), transparent 60%),
        radial-gradient(900px 600px at 115% 8%, rgba(43,82,120,.10), transparent 55%),
        #0a1017 !important;
}

/* Окно приложения на ПК — глубже тень, мягче край */
@media (min-width: 768px) {
    #app-screen {
        border-radius: 20px !important;
        box-shadow: 0 40px 90px -30px rgba(0,0,0,.70), 0 0 0 1px rgba(255,255,255,.05);
    }
}

/* Область чата — глубина радиальными свечениями поверх лёгкой текстуры */
.chat-bg {
    background-color: #0d1420;
    background-image:
        /* Ровное притенение поверх узора: без него рисунок спорил с текстом.
           Отдельным слоем фона, а не наложением поверх области чата —
           наложение навязывало потомкам своё положение и ломало разметку. */
        linear-gradient(rgba(13,20,32,.30), rgba(13,20,32,.30)),
        /* Мягкая подсветка сверху — она же была и раньше, узор под ней */
        radial-gradient(820px 560px at 12% -6%, rgba(82,136,193,.10), transparent 62%),
        radial-gradient(720px 520px at 110% 4%, rgba(43,82,120,.13), transparent 55%),
        image-set(url('chat-bg.webp?v=4') type('image/webp'), url('chat-bg.jpg?v=4') type('image/jpeg'));
    /* В натуральную величину. Растягивание на всё окно давало мыло:
       книжная картинка на широком экране увеличивалась вдвое с лишним.
       Здесь рисунок ровно такой, каким нарисован, и остаётся резким. */
    background-repeat: no-repeat, no-repeat, no-repeat, repeat;
    background-size: auto, auto, auto, auto;
    background-position: center, center, center, top center;
    background-blend-mode: normal, normal, normal, normal;
    /* Закреплена за окном: при прокрутке переписки фон стоит на месте,
       как в привычных мессенджерах, а не едет вместе с сообщениями */
    background-attachment: fixed, fixed, fixed, fixed;
}

/* Старым сборкам Safari image-set неизвестен — им отдаём обычный jpeg */
@supports not (background-image: image-set(url('a.webp') type('image/webp'))) {
    .chat-bg {
        background-image:
            linear-gradient(rgba(13,20,32,.30), rgba(13,20,32,.30)),
            radial-gradient(820px 560px at 12% -6%, rgba(82,136,193,.10), transparent 62%),
            radial-gradient(720px 520px at 110% 4%, rgba(43,82,120,.13), transparent 55%),
            url('chat-bg.jpg?v=4');
        background-repeat: no-repeat, no-repeat, no-repeat, repeat;
        background-size: auto, auto, auto, auto;
    }
}

/* Сайдбар — тонкий вертикальный градиент и аккуратная правая грань */
#sidebar {
    background: linear-gradient(180deg, #18232f, #151e28) !important;
    border-right: 1px solid rgba(255,255,255,.06) !important;
}

/* Верхние панели (шапки чата и треда) — насыщенный градиент без blur ради плавной прокрутки */
.tg-topbar {
    background: linear-gradient(180deg, rgba(29,41,54,.99), rgba(22,32,43,.99)) !important;
    box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 6px 18px -10px rgba(0,0,0,.6);
}

/* Нижние панели (ввод / только-чтение / подписаться) — в тон, с мягкой верхней гранью */
#input-area, #readonly-area, #join-area {
    background: linear-gradient(180deg, rgba(23,33,44,.99), rgba(19,28,37,1)) !important;
    border-top: 1px solid rgba(255,255,255,.06) !important;
}

/* Пузыри сообщений — мягче углы, объём и тонкая внутренняя грань */
.bubble-rounded { border-radius: 18px; }
.bubble-rounded.bg-tg-bubble {
    background: linear-gradient(180deg, #1d2d3d, #172433) !important;
    box-shadow: 0 1px 2px rgba(0,0,0,.28), inset 0 0 0 1px rgba(255,255,255,.035);
}
.bubble-rounded.bg-tg-bubbleMe {
    background: linear-gradient(180deg, #326199, #294f74) !important;
    box-shadow: 0 1px 2px rgba(0,0,0,.30), inset 0 0 0 1px rgba(255,255,255,.07);
}

/* Акцентные кнопки — лёгкий градиент; свечение и отклик только для <button> (не трогаем выделенный чат) */
.bg-tg-primary { background: linear-gradient(180deg, #5c95ce, #4c7fb6) !important; }
button.bg-tg-primary { box-shadow: 0 6px 16px -6px rgba(82,136,193,.5); }
button.bg-tg-primary:hover { filter: brightness(1.07); box-shadow: 0 9px 24px -6px rgba(82,136,193,.72); transform: translateY(-1px); }
button.bg-tg-primary:active { transform: scale(.95); }

/* Поле ввода — мягкий фон и подсветка при фокусе */
.input-shell {
    background: rgba(10,16,23,.85) !important;
    border-color: rgba(255,255,255,.07) !important;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.28);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.input-shell:focus-within {
    border-color: rgba(92,149,206,.55) !important;
    box-shadow: inset 0 1px 3px rgba(0,0,0,.28), 0 0 0 3px rgba(82,136,193,.13);
}

/* Аватар в шапке — мягкая тень */
#chat-avatar { box-shadow: 0 2px 10px rgba(0,0,0,.35); }

/* Скроллбар — опрятнее */
.custom-scrollbar::-webkit-scrollbar { width: 7px; height: 7px; }
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(255,255,255,.16), rgba(255,255,255,.08));
    border-radius: 20px; border: 2px solid transparent; background-clip: padding-box;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); background-clip: padding-box; }

/* Подсветка сообщения при переходе из поиска */
.msg-jump-highlight { animation: msgJump 2s ease; border-radius: 18px; }
@keyframes msgJump {
    0%, 55% { box-shadow: 0 0 0 3px rgba(82,136,193,.55); background: rgba(82,136,193,.10); }
    100% { box-shadow: 0 0 0 0 rgba(82,136,193,0); background: transparent; }
}

/* Профиль: карточки и заголовок современнее */
#smartProfileModal .bg-tg-bg { border: 1px solid rgba(255,255,255,.06); border-radius: 16px; }
#mpName { text-shadow: 0 2px 14px rgba(0,0,0,.65); letter-spacing: -0.02em; }
#mpStatus { text-shadow: 0 1px 8px rgba(0,0,0,.55); }

/* Кольцо историй вокруг аватарки в списке чатов (фирменная палитра) */
.chat-story-ring { padding: 2.5px; border-radius: 9999px; background: linear-gradient(45deg, #38bdf8, #5c95ce, #8b5cf6); cursor: pointer; }
.chat-story-ring.viewed { background: rgba(255,255,255,.22); }
.chat-story-ring img { border: 2px solid #17212b; }

/* Табы общих материалов в профиле */
.sp-tab { color: #8b98a5; background: rgba(255,255,255,.05); }
.sp-tab.active { background: rgba(82,136,193,.18); color: #6ab3f3; }

/* Код-блоки в сообщениях */
.rich-code-wrap { border-radius: 12px; overflow: hidden; background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.08); }
.rich-code-copy { display: flex; align-items: center; gap: 6px; width: 100%; padding: 7px 12px; font-size: 12px; font-weight: 600; color: #9ec5ef; background: rgba(255,255,255,.05); border: none; border-bottom: 1px solid rgba(255,255,255,.07); cursor: pointer; transition: background .15s; }
.rich-code-copy:hover { background: rgba(255,255,255,.1); }
.rich-code { margin: 0; padding: 11px 13px; overflow-x: auto; font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace; font-size: 12.5px; line-height: 1.5; color: #e6edf3; white-space: pre; }
.rich-inline-code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: rgba(255,255,255,.12); padding: 1px 5px; border-radius: 5px; }

/* Читалка документов */
#doc-viewer-modal { z-index: 7100; }
/* Читалка: темы, страницы, панели */
#dv-body.rd-theme-light { background: #f6f2e8; }
#dv-body.rd-theme-sepia { background: #efe3cb; }
#dv-body.rd-theme-light #rd-doc, #dv-body.rd-theme-light .dv-pre, #dv-body.rd-theme-light .dv-md { color: #23282e; }
#dv-body.rd-theme-sepia #rd-doc, #dv-body.rd-theme-sepia .dv-pre, #dv-body.rd-theme-sepia .dv-md { color: #3b2f21; }
#dv-body.rd-theme-light .fb2-author, #dv-body.rd-theme-sepia .fb2-author { color: #6b6255; }
#dv-body.rd-paged { overflow: hidden !important; position: relative; }
#dv-body.rd-paged #rd-doc { column-gap: 40px; column-fill: auto; transition: transform .22s ease; }
#rd-doc { max-width: 100%; }
#rd-doc img { max-width: 100%; height: auto; border-radius: 6px; margin: 10px auto; display: block; }
#rd-doc p { margin: 0 0 .7em; text-indent: 1.3em; text-align: justify; }
#rd-doc .rd-book-title { font-size: 1.5em; text-align: center; margin: .2em 0 .1em; text-indent: 0; font-weight: 700; }
#rd-doc .rd-book-author { text-align: center; opacity: .65; margin-bottom: 1em; text-indent: 0; }
#rd-doc .rd-sep { height: 1px; background: currentColor; opacity: .18; max-width: 180px; margin: 1.2em auto; }
#rd-doc .rd-ch-title { font-size: 1.2em; font-weight: 700; text-align: center; margin: 1.4em 0 .7em; text-indent: 0; }
#rd-doc h1, #rd-doc h2, #rd-doc h3 { text-indent: 0; }
#rd-pageind { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; font-size: 11.5px; color: #8b98a5; pointer-events: none; }
.rd-btn { padding: 5px 12px; border-radius: 999px; font-size: 12.5px; background: rgba(255,255,255,.07); color: #b7c2cd; transition: background .15s; }
.rd-btn:hover { background: rgba(255,255,255,.13); }
.rd-btn.rd-on { background: #5288c1; color: #fff; }
.dv-pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 1.55; color: #e6edf3; }
.dv-code { white-space: pre; overflow-x: auto; background: rgba(0,0,0,.3); padding: 14px; border-radius: 10px; font-size: 12.5px; line-height: 1.5; color: #e6edf3; }
.dv-md { color: #e9edf1; font-size: 15px; line-height: 1.65; }
.dv-md .dv-h { font-weight: 700; color: #fff; margin: 14px 0 6px; line-height: 1.3; }
.dv-md h1.dv-h { font-size: 22px; } .dv-md h2.dv-h { font-size: 19px; } .dv-md h3.dv-h { font-size: 17px; }
.dv-md h4.dv-h, .dv-md h5.dv-h, .dv-md h6.dv-h { font-size: 15px; }
.dv-md .dv-p { margin: 8px 0; }
.dv-md .dv-ul { margin: 8px 0 8px 20px; list-style: disc; }
.dv-md .dv-ul li { margin: 3px 0; }
.dv-md .dv-quote { border-left: 3px solid #5288c1; padding: 4px 12px; margin: 8px 0; color: #b8c2cc; background: rgba(255,255,255,.03); border-radius: 0 8px 8px 0; }
.dv-md .dv-code { margin: 10px 0; }

/* FB2-книга в читалке */
.fb2-book { max-width: 640px; margin: 0 auto; }
.fb2-title { font-size: 24px; text-align: center; margin: 8px 0 4px; }
.fb2-author { text-align: center; color: #8b98a5; font-size: 14px; margin-bottom: 12px; }
.fb2-sep { height: 1px; background: rgba(255,255,255,.1); margin: 16px auto; max-width: 200px; }
.fb2-sec-title { text-align: center; margin: 22px 0 12px; font-size: 18px; }
.fb2-subtitle { text-align: center; margin: 14px 0 8px; }
.fb2-p { text-indent: 1.4em; margin: 0 0 5px; text-align: justify; }
.fb2-poem { margin: 12px 0 12px 8px; font-style: italic; }
.fb2-stanza { margin: 8px 0; }
.fb2-v { margin-left: 1.6em; }
.fb2-author-line { text-align: right; color: #8b98a5; font-style: italic; margin: 4px 0 10px; }
.fb2-ann .fb2-p, .fb2-ann .dv-p { text-indent: 0; }
.fb2-img { display: block; max-width: 100%; max-height: 70vh; margin: 12px auto; border-radius: 12px; }
.fb2-cover .fb2-img { max-height: 58vh; margin: 4px auto 10px; box-shadow: 0 10px 30px -12px rgba(0,0,0,.6); }

/* Карточки скачивания */
.dl-card { transition: opacity .3s, transform .3s; }
.dl-indet { width: 40% !important; animation: dlSlide 1.1s linear infinite; }
@keyframes dlSlide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* Спойлер 18+: медиа размыто до нажатия (как в Telegram) */
[data-spoiler-wrap].sp-on img,
[data-spoiler-wrap].sp-on video { filter: blur(26px) saturate(1.15); transform: scale(1.1); }
.spoiler-cover {
    position: absolute; inset: 0; z-index: 20;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px;
    background: rgba(0,0,0,.28); cursor: pointer; border-radius: inherit;
}
.spoiler-cover .sp18 {
    width: 46px; height: 46px; border-radius: 9999px;
    background: rgba(0,0,0,.55); border: 1.5px solid rgba(255,255,255,.4);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: 13.5px; letter-spacing: .4px;
    backdrop-filter: blur(4px);
}
/* ==================================================================
   ВИЗУАЛЬНЫЙ СЛОЙ: список чатов, тактильность, микро-анимации
   ================================================================== */

/* Строка чата: плавный hover, объёмный активный элемент с меткой слева */
.chat-row { position: relative; transition: background-color .16s ease, transform .16s ease; }
.chat-row:not(.chat-row-active):hover { background: rgba(255,255,255,.055); }
.chat-row:active { transform: scale(.985); }
.chat-row-active {
    background: linear-gradient(135deg, #5288c1, #3f6d9f) !important;
    box-shadow: 0 8px 22px -12px rgba(82,136,193,.85);
}
.chat-row-active::before {
    content: ''; position: absolute; left: -1px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 26px; border-radius: 0 3px 3px 0; background: #cfe4ff;
}
.chat-row img { transition: transform .18s ease; }
.chat-row:hover img { transform: scale(1.04); }

/* Аватарки: тонкий контур, чтобы не сливались с фоном */
.chat-row img, #chat-avatar, .story-ring img { box-shadow: 0 0 0 1px rgba(255,255,255,.07); }

/* Тактильность кнопок по всему интерфейсу */
button:not(:disabled):active { transform: scale(.94); }
button { transition: transform .12s ease, background-color .16s ease, color .16s ease; }

/* Появление новых сообщений — мягкий подъём */
@keyframes msgIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
#messages > div { animation: msgIn .2s ease-out; }

/* Пустое состояние: светящийся шар с иконкой */
.empty-orb {
    width: 84px; height: 84px; border-radius: 9999px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; color: #6ea6dd;
    background: radial-gradient(circle at 32% 28%, rgba(82,136,193,.30), rgba(82,136,193,.07) 65%, transparent);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 16px 40px -20px rgba(82,136,193,.7);
    animation: orbFloat 4.5s ease-in-out infinite;
}
@keyframes orbFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* Бейдж непрочитанных — лёгкое свечение */
.bg-tg-primary.rounded-full.text-\[11px\] { box-shadow: 0 4px 12px -4px rgba(82,136,193,.9); }

/* Шапка чата и панель ввода — тоньше разделители */
.tg-topbar { border-bottom: 1px solid rgba(255,255,255,.055); }

/* Модалки: единый мягкий стиль карточек */
.modal-card, #poll-create-modal > div, #doc-viewer-modal > div {
    box-shadow: 0 30px 70px -25px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.06);
}

/* Поле поиска: живой фокус */
.search-input { transition: box-shadow .18s ease, background-color .18s ease; border: 1px solid transparent; }
.search-input:focus { background: rgba(13,20,32,.9); border-color: rgba(82,136,193,.45); box-shadow: 0 0 0 3px rgba(82,136,193,.14); }

/* Кнопки отправки и записи — объёмный градиент вместо плоской заливки */
#send-btn, #media-record-btn {
    background: linear-gradient(135deg, #5d95cf, #3f6d9f) !important;
    box-shadow: 0 8px 20px -8px rgba(82,136,193,.95), inset 0 1px 0 rgba(255,255,255,.16);
}
#send-btn:hover, #media-record-btn:hover { filter: brightness(1.07); }

/* Значки верификации */
.vbadge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 17px; height: 17px; border-radius: 9999px;
    font-size: 9px; color: #fff; vertical-align: middle;
    margin-left: 5px; flex-shrink: 0; position: relative; top: -1px;
}
.vbadge-lg { width: 24px; height: 24px; font-size: 12px; margin-left: 8px; top: -2px; }
.vb-music   { background: linear-gradient(135deg, #a855f7, #ec4899); box-shadow: 0 3px 10px -3px rgba(168,85,247,.85); }
.vb-writer  { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 3px 10px -3px rgba(245,158,11,.85); }
.vb-blogger { background: linear-gradient(135deg, #fb923c, #ef4444); box-shadow: 0 3px 10px -3px rgba(251,146,60,.85); }
.vb-general { background: linear-gradient(135deg, #3b9de8, #2b6cb0); box-shadow: 0 3px 10px -3px rgba(59,157,232,.85); }

/* Альбом из нескольких фото: на телефоне занимает почти всю ширину пузыря,
   иначе три картинки в ряд превращались в нечитаемые полоски */
.album-grid { width: min(74vw, 330px); }
@media (min-width: 640px) { .album-grid { width: 420px; } }

/* Мини-игры: экранное управление */
#arcade-modal.flex { display: flex; }
.arc-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 230px; margin: 0 auto; }
.arc-row { display: flex; gap: 8px; max-width: 400px; margin: 0 auto; }
.arc-row .arc-btn { flex: 1; }
.arc-btn {
    height: 58px; border-radius: 16px; font-size: 19px; color: #e9eef5;
    background: linear-gradient(180deg, rgba(255,255,255,.13), rgba(255,255,255,.05));
    border: 1px solid rgba(255,255,255,.1);
    display: flex; align-items: center; justify-content: center;
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
    box-shadow: 0 4px 14px -8px #000, inset 0 1px 0 rgba(255,255,255,.14);
}
.arc-btn:active { transform: scale(.93); background: rgba(82,136,193,.35); }

/* Анимированный стикер: рисунок внутри бывает крупнее отведённого места,
   поэтому границы задаём и здесь — на случай, если разметку перепишут */
[data-lottie] { overflow: hidden; }
[data-lottie] > svg { width: 100% !important; height: 100% !important; display: block; }

/* ───── Отделка ───── */

/* Пузыри сообщений: тонкая грань сверху даёт объём, тень отделяет от фона.
   Раньше это были плоские заливки, и на узорчатом фоне они терялись. */
.bubble-rounded {
    box-shadow: 0 1px 2px rgba(0,0,0,.28), 0 4px 12px -6px rgba(0,0,0,.35);
    border: 1px solid rgba(255,255,255,.05);
}

/* Строка чата: мягкий отклик на нажатие вместо мгновенной смены цвета */
.chat-row { transition: background .16s ease, transform .1s ease; }
.chat-row:active { transform: scale(.985); }

/* Поле ввода подсвечивается, когда в нём пишут — видно, что оно готово */
#input-area:focus-within {
    box-shadow: inset 0 1px 0 rgba(82,136,193,.35);
}

/* Полоса прокрутки тоньше и незаметнее: широкая системная в тёмной теме
   выглядит грубо */
.custom-scrollbar::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.13);
    border-radius: 999px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.22); }
.custom-scrollbar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }

/* Появление нового сообщения: короткий подъём вместо мгновенного возникновения */
@media (prefers-reduced-motion: no-preference) {
    .msg-enter { animation: msgIn .22s cubic-bezier(.22,.9,.32,1) both; }
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* ───── Поведение на телефонах ───── */

/* Инерционная прокрутка на iPhone: без неё лента едет рывками
   и останавливается сразу, как отпустишь палец */
#messages, #chat-list, .custom-scrollbar, .pres-scroll,
#sticker-content, #mpMembersList, #thread-messages {
    -webkit-overflow-scrolling: touch;
}

/* Долгое нажатие на картинку или кнопку вызывало системное меню
   «Сохранить изображение» поверх нашего — оно тут лишнее */
img, button, .arc-btn, .gp-k, .gp-btn, .pres-cell, .mp-act {
    -webkit-touch-callout: none;
}

/* Палец не попадает в цель меньше 44 точек. Кнопкам оставляем прежний вид,
   но расширяем область нажатия невидимой рамкой вокруг. */
@media (pointer: coarse) {
    .tap-safe { position: relative; }
    .tap-safe::after {
        content: ''; position: absolute;
        top: 50%; left: 50%; transform: translate(-50%, -50%);
        width: 44px; height: 44px;
    }
}

/* Рамка при переходе клавишами — видно, где находишься.
   Только при работе с клавиатуры: по нажатию мыши она не нужна. */
:focus-visible {
    outline: 2px solid rgba(82,136,193,.85);
    outline-offset: 2px;
    border-radius: 6px;
}
button:focus:not(:focus-visible), a:focus:not(:focus-visible) { outline: none; }

/* ───── Всплывающие уведомления поверх экрана ─────
   Появляются, когда приложение открыто: системное уведомление в этом
   случае показывается тихо, и сообщение легко пропустить. */
.nb-host {
    position: fixed; left: 0; right: 0;
    top: calc(var(--safe-top, 0px) + 8px);
    z-index: 10050;                       /* выше всех наших окон */
    display: flex; flex-direction: column; gap: 8px;
    padding: 0 10px;
    pointer-events: none;
}
.nb-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; max-width: 460px; margin: 0 auto;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(23, 33, 43, .96);
    border: 1px solid rgba(255,255,255,.09);
    box-shadow: 0 8px 28px rgba(0,0,0,.55);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    cursor: pointer; pointer-events: auto;
    /* Появление сверху вниз, как у системных уведомлений */
    opacity: 0; transform: translateY(-16px) scale(.97);
    transition: opacity .24s ease, transform .24s cubic-bezier(.22,.9,.32,1);
    -webkit-tap-highlight-color: transparent;
}
.nb-item.nb-in { opacity: 1; transform: none; }
.nb-item:active { transform: scale(.985); }
.nb-ava {
    width: 38px; height: 38px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
    border: 1px solid rgba(255,255,255,.10);
}
.nb-text { flex: 1; min-width: 0; display: block; }
.nb-title {
    display: block; font-size: 13.5px; font-weight: 600; color: #f5f5f5;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nb-body {
    display: block; font-size: 12.5px; color: #a7b4c2; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nb-x {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #7f93a8; font-size: 13px;
    transition: background .15s, color .15s;
}
.nb-x:hover { background: rgba(255,255,255,.08); color: #fff; }

@media (prefers-reduced-motion: reduce) {
    .nb-item { transition: opacity .1s ease; transform: none; }
}

/* ───── Кнопки внутри текста ─────
   Цвет берётся из переменной: её меняет выбор темы, и правила
   трогать не нужно. По умолчанию — цвет приложения. */
:root { --chip: #5288c1; }

.msg-chip {
    display: inline-flex; align-items: center; gap: 5px;
    margin: 1px 2px;
    padding: 2px 9px 3px;
    border-radius: 999px;
    font-size: 13px; font-weight: 500; line-height: 1.5;
    text-decoration: none; vertical-align: baseline;
    background: color-mix(in srgb, var(--chip) 22%, transparent);
    border: 1px solid color-mix(in srgb, var(--chip) 45%, transparent);
    color: color-mix(in srgb, var(--chip) 55%, #ffffff);
    transition: background .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.msg-chip i { font-size: 10.5px; opacity: .85; }
.msg-chip:hover { background: color-mix(in srgb, var(--chip) 34%, transparent); }
.msg-chip:active { transform: scale(.96); }
.msg-chip.chip-done {
    background: rgba(63,194,107,.24);
    border-color: rgba(63,194,107,.5);
    color: #b9f0cc;
}
/* В своём пузыре фон светлее — кнопке нужен другой оттенок */
.msg-chip.chip-me {
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.24);
    color: #eef4fb;
}
.msg-chip.chip-me:hover { background: rgba(255,255,255,.24); }

/* Старым браузерам color-mix неизвестен — им простые цвета */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .msg-chip {
        background: rgba(82,136,193,.22);
        border-color: rgba(82,136,193,.45);
        color: #9dc0e6;
    }
}

/* Выбор цвета кнопок */
.cc-row {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 10px 12px; border-radius: 12px; text-align: left;
    background: transparent; transition: background .15s;
}
.cc-row:hover { background: rgba(255,255,255,.06); }
.cc-row.cc-on { background: rgba(82,136,193,.18); }
.cc-dot {
    width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.28), 0 1px 3px rgba(0,0,0,.4);
}

/* Панель над выделенным текстом */
.chip-bar {
    position: absolute; left: 50%; transform: translateX(-50%);
    /* Над полем ввода. На телефоне системное меню браузера («Перевести»,
       «Вырезать») всплывает прямо над выделением, поэтому отходим повыше —
       иначе панели налезают друг на друга. */
    bottom: calc(100% + 8px);
    display: flex; gap: 4px; padding: 4px;
    background: #1c2733;
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,.45);
    z-index: 60;
    animation: chipBarIn .14s ease both;
}
@keyframes chipBarIn {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.chip-bar button {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 10px; border-radius: 9px;
    font-size: 12px; color: #b7c2cd; white-space: nowrap;
    transition: background .14s, color .14s;
}
.chip-bar button i { font-size: 11px; }
.chip-bar button:hover { background: rgba(255,255,255,.08); color: #fff; }
.chip-bar button:active { transform: scale(.95); }

/* На телефоне панель встаёт ВНУТРЬ ряда ввода, на место обычных значков.
   Отодвигать её вверх бесполезно: системное меню Android всегда встаёт
   над выделением, то есть ровно туда же. А в одном ряду с текстом
   перекрывать её нечем. */
.chip-bar-inline {
    position: static; transform: none;
    display: flex; align-items: center; gap: 2px;
    margin-left: auto; margin-bottom: 5px;
    padding: 0; background: none; border: none; box-shadow: none;
    animation: none;
    flex-shrink: 0;
}
.chip-bar-inline button {
    flex-direction: column; gap: 2px;
    padding: 4px 7px; font-size: 9.5px; line-height: 1.1;
    border-radius: 9px;
    background: rgba(82,136,193,.16);
    color: #9dc0e6;
}
.chip-bar-inline button i { font-size: 13px; }
.chip-bar-inline button:hover,
.chip-bar-inline button:active { background: rgba(82,136,193,.3); color: #fff; }

/* Пока панель показана, обычные значки уходят: места на всех не хватит */
.input-shell.chips-on > button,
.input-shell.chips-on > label { display: none; }

@media (pointer: coarse) {
    .chip-bar { z-index: 70; }
}

/* ───── Приветствие для новых участников ─────
   Карточка заметно отличается от обычных сообщений: это не переписка,
   а личная подсказка, которую видит только вошедший. */
.wc-card {
    margin: 4px 8px 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: linear-gradient(160deg, rgba(82,136,193,.16), rgba(43,82,120,.10));
    border: 1px solid rgba(82,136,193,.28);
    box-shadow: 0 2px 10px rgba(0,0,0,.28);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    transition: opacity .2s ease, transform .2s ease;
}
.wc-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; font-weight: 600; color: #9dc0e6;
    margin-bottom: 7px;
}
.wc-head > i { font-size: 14px; }
.wc-only {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 10.5px; font-weight: 500; color: #7f93a8;
    background: rgba(0,0,0,.22);
    padding: 2px 7px; border-radius: 999px;
}
.wc-body {
    font-size: 14px; line-height: 1.45; color: #eef3f8;
    word-break: break-word;
}
.wc-close {
    margin-top: 10px; width: 100%;
    padding: 7px 10px; border-radius: 10px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.08);
    color: #b7c2cd; font-size: 12.5px; font-weight: 500;
    transition: background .15s, color .15s;
}
.wc-close:hover { background: rgba(255,255,255,.11); color: #fff; }
.wc-close:active { transform: scale(.98); }

/* ───── Переключатели в настройках уведомлений ───── */
.np-sw {
    position: relative; flex-shrink: 0;
    width: 40px; height: 23px; border-radius: 999px;
    background: rgba(255,255,255,.10);
    border: 1px solid rgba(255,255,255,.10);
    transition: background .18s, border-color .18s;
}
.np-sw .np-dot {
    position: absolute; top: 2px; left: 2px;
    width: 17px; height: 17px; border-radius: 50%;
    background: #8b98a5;
    transition: transform .18s, background .18s;
}
.np-sw.np-on { background: rgba(82,136,193,.55); border-color: rgba(82,136,193,.7); }
.np-sw.np-on .np-dot { transform: translateX(17px); background: #fff; }

/* ───── Карточки профиля ─────
   Раньше это была плоская заливка без границ: блоки сливались друг с другом
   и с фоном. Тонкая рамка и мягкая тень разделяют их по смыслу. */
.mp-card {
    background: #0e1621;
    border: 1px solid rgba(255,255,255,.07);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.03);
}
.mp-card + .mp-card { margin-top: 12px; }

/* Участник в списке — своя строка с подсветкой при наведении */
#mpMembersList > * {
    border-radius: 10px;
    padding: 6px;
    transition: background .15s;
}
#mpMembersList > *:hover { background: rgba(255,255,255,.04); }

/* ───── Кнопки в карточке профиля ─────
   Раньше это были текстовые ссылки в одной строке с подписью «Участники»:
   на телефоне им не хватало места и они наезжали друг на друга. */
.mp-act {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 5px; padding: 10px 4px;
    border-radius: 12px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    color: #b7c2cd;
    transition: background .15s, border-color .15s, transform .1s;
    -webkit-tap-highlight-color: transparent;
}
.mp-act i { font-size: 15px; color: #5288c1; }
.mp-act span { font-size: 11.5px; line-height: 1; font-weight: 500; }
.mp-act:hover {
    background: rgba(82,136,193,.14);
    border-color: rgba(82,136,193,.35);
    color: #f5f5f5;
}
.mp-act:active { transform: scale(.95); }
.mp-act.hidden { display: none; }

/* ───── Статусы присутствия ─────
   Значки свои: плоские кружки со знаком. Цвет задаётся из кода,
   чтобы набор статусов можно было менять, не трогая стили. */
.pres-dot { display: inline-block; border-radius: 50%; flex-shrink: 0; position: relative; }
.pres-ring { border: 2.5px solid #17212b; }

/* «Не беспокоить» — с белой перекладиной, читается даже мелким */
.pres-bar::after {
    content: ''; position: absolute;
    top: 44%; left: 22%; width: 56%; height: 13%;
    background: #fff; border-radius: 1px;
}

/* Значок со знаком внутри. На аватаре нужна тёмная обводка: без неё
   значок сливается со светлой фотографией и знак теряется. */
.pres-badge {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; color: #fff; flex-shrink: 0; line-height: 1;
    box-shadow: 0 2px 5px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.22);
}
.pres-badge i {
    /* Лёгкая тень под знаком: он белый, а фон значка бывает светлым */
    text-shadow: 0 1px 1px rgba(0,0,0,.35);
    display: block;
}
.pres-badge.pres-ring {
    border: 2px solid #17212b;
    box-shadow: 0 1px 4px rgba(0,0,0,.55);
}
/* В выделенной строке обводка берёт её цвет, иначе виден тёмный ободок.
   Класс строки — chat-row: под прежним именем правило не работало вовсе. */
.chat-row.bg-tg-bubbleMe .pres-badge.pres-ring,
.chat-row[class*="bg-tg-bubbleMe"] .pres-badge.pres-ring { border-color: #2b5278; }

/* Крупный значок для окна выбора: тёмный круг, светящийся знак и пунктирное
   кольцо. Цвет приходит из кода переменной --pc, поэтому набор статусов можно
   менять, не трогая стили. */
.pres-neon {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%; flex-shrink: 0; line-height: 1;
    color: var(--pc, #8fa3b8);
    background: radial-gradient(circle at 50% 32%, #1f2836 0%, #141b26 70%, #10161f 100%);
    box-shadow: 0 0 14px -3px var(--pc, #8fa3b8),
                inset 0 0 10px -5px var(--pc, #8fa3b8),
                0 2px 6px rgba(0,0,0,.5);
}
.pres-neon i {
    display: block;
    /* Свечение знака: два слоя, ближний плотнее — так он читается и не мылится */
    text-shadow: 0 0 4px var(--pc, #8fa3b8), 0 0 10px var(--pc, #8fa3b8);
}
/* Пунктирное кольцо вокруг */
.pres-neon::before {
    content: ''; position: absolute; inset: -5px;
    border-radius: 50%;
    border: 1.5px dashed var(--pc, #8fa3b8);
    opacity: .55;
}
.pres-cell.pres-active .pres-neon::before { opacity: 1; }
.pres-cell.pres-active .pres-neon {
    box-shadow: 0 0 20px -2px var(--pc, #8fa3b8),
                inset 0 0 12px -4px var(--pc, #8fa3b8),
                0 2px 6px rgba(0,0,0,.5);
}
/* Кому мешает движение — уважаем настройку телефона */
@media (prefers-reduced-motion: no-preference) {
    .pres-cell.pres-active .pres-neon::before { animation: presSpin 9s linear infinite; }
}
@keyframes presSpin { to { transform: rotate(360deg); } }

/* Сетка выбора. Ширина колонки подбирается сама: на узком экране четыре
   в ряд, на широком пять — вместо жёсткого числа, из-за которого на телефоне
   получалось три штуки и список уезжал на два экрана. */
.pres-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
    gap: 2px;
}
.pres-cell {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 9px 2px 6px; border-radius: 10px;
    background: transparent; transition: background .15s, transform .1s;
    border: 1.5px solid transparent;
}
.pres-cell:hover { background: rgba(255,255,255,.06); }
.pres-cell:active { transform: scale(.94); }
.pres-cell.pres-active {
    background: rgba(82,136,193,.18);
    border-color: rgba(82,136,193,.55);
}
.pres-cap {
    font-size: 10px; line-height: 1.1; color: #b7c2cd; text-align: center;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; min-height: 22px; word-break: break-word;
}
.pres-cell.pres-active .pres-cap { color: #f5f5f5; }

/* Заголовок и кнопки не уезжают: прокручивается только сама сетка,
   иначе до «Сохранить» приходилось листать через весь список */
.pres-sheet { display: flex; flex-direction: column; max-height: 86vh; }
.pres-head, .pres-foot { flex-shrink: 0; }
.pres-scroll { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }

/* ───── Раскладка под джойстик приставки: крестовина слева, три кнопки справа ───── */
.gp-wrap { display: flex; align-items: center; justify-content: space-between; gap: 14px; max-width: 420px; margin: 0 auto; }
.gp-dpad { position: relative; width: 108px; height: 108px; flex-shrink: 0; }
.gp-dpad .gp-k {
    position: absolute; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(180deg, #3a4350, #232a34);
    border: 1px solid rgba(255,255,255,.10); color: #cfd8e3; font-size: 17px;
    box-shadow: 0 2px 4px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.08);
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
.gp-dpad .gp-up    { left: 36px; top: 0;    width: 36px; height: 40px; border-radius: 9px 9px 0 0; }
.gp-dpad .gp-down  { left: 36px; bottom: 0; width: 36px; height: 40px; border-radius: 0 0 9px 9px; }
.gp-dpad .gp-left  { top: 36px; left: 0;    width: 40px; height: 36px; border-radius: 9px 0 0 9px; }
.gp-dpad .gp-right { top: 36px; right: 0;   width: 40px; height: 36px; border-radius: 0 9px 9px 0; }
.gp-dpad .gp-hub {
    position: absolute; left: 36px; top: 36px; width: 36px; height: 36px;
    background: #2b323d; border-left: 1px solid rgba(255,255,255,.06); border-right: 1px solid rgba(255,255,255,.06);
}
.gp-k:active { background: linear-gradient(180deg, #5d95cf, #3f6d9f); color: #fff; }

.gp-face { display: flex; align-items: flex-end; gap: 9px; flex-shrink: 0; }
.gp-btn {
    width: 46px; height: 46px; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: #fff; line-height: 1;
    box-shadow: 0 3px 6px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.22);
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
    transition: transform .08s;
}
.gp-btn small { font-size: 8px; font-weight: 600; opacity: .75; margin-top: 2px; letter-spacing: .03em; }
.gp-btn:active { transform: scale(.92); filter: brightness(1.25); }
.gp-a { background: linear-gradient(180deg, #4f9440, #35692c); margin-bottom: 14px; }
.gp-b { background: linear-gradient(180deg, #cf3a30, #92241c); margin-bottom: 7px; }
.gp-c { background: linear-gradient(180deg, #d9a021, #a27312); }
.gp-c.gp-on { background: linear-gradient(180deg, #f5c93c, #c99a1a); box-shadow: 0 0 10px rgba(245,201,60,.6); }

@media (max-width: 380px) {
    .gp-dpad { width: 96px; height: 96px; }
    .gp-dpad .gp-up, .gp-dpad .gp-down { left: 32px; width: 32px; height: 36px; }
    .gp-dpad .gp-left, .gp-dpad .gp-right { top: 32px; width: 36px; height: 32px; }
    .gp-dpad .gp-hub { left: 32px; top: 32px; width: 32px; height: 32px; }
    .gp-btn { width: 42px; height: 42px; }
}
.arc-btn.arc-accent { background: linear-gradient(180deg, #5d95cf, #3f6d9f); color: #fff; border-color: rgba(255,255,255,.18); }
.arc-btn.arc-wide { flex: 1.4; }
.arc-mid { display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.18); font-size: 17px; }
/* Корпус карманной игрушки — включается только для «Ловца яиц».
   По бокам оставляем минимум, иначе экран не влезает и масштаб падает вдвое. */
.arc-stage-tight { padding: 4px !important; }
.arc-shell {
    position: relative; padding: 24px 4px 26px; border-radius: 16px;
    background: linear-gradient(180deg, #f5edda 0%, #e9dcc2 62%, #ded0b3 100%);
    border: 4px solid #d5382d;
    box-shadow: 0 16px 44px rgba(0,0,0,.6), inset 0 2px 0 rgba(255,255,255,.75), inset 0 -3px 6px rgba(0,0,0,.12);
}
.arc-shell::before {
    content: 'ТОЛСТЫЙ ЛОВИ'; position: absolute; top: 6px; left: 0; right: 0;
    text-align: center; font-size: 12px; font-weight: 800; letter-spacing: .1em; color: #d31f77;
}
.arc-shell::after {
    content: 'ИльинК'; position: absolute; bottom: 5px; left: 0; right: 0;
    text-align: center; font-size: 13px; font-weight: 800; letter-spacing: .14em; color: #23231f;
}
.arc-shell #arcade-canvas {
    border-radius: 5px !important; border: 3px solid #d5382d; display: block;
    box-shadow: 0 0 0 2px #f5edda, 0 3px 8px rgba(0,0,0,.4) !important;
}
/* id перебивает класс hidden, поэтому скрытое состояние прописываем отдельно */
#arcade-shell-pad { display: flex; justify-content: center; gap: 10px; margin-top: 7px; }
#arcade-shell-pad.hidden { display: none; }
#arcade-shell-pad button {
    font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: #3a3a34;
    background: linear-gradient(180deg, #cfcfc7, #a9a9a1); border: 2px solid #d5382d;
    border-radius: 999px; padding: 3px 11px; cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 1px 2px rgba(0,0,0,.3);
}
#arcade-shell-pad button.egg-on { background: linear-gradient(180deg, #f0a3a0, #d5382d); color: #fff; border-color: #8f1f18; }
#arcade-canvas { touch-action: none; background: #0c141d; }

/* Волна голосовых */
.voice-wave { display: block; height: 32px; cursor: pointer; }

/* Аудио-плеер в пузырях: стекло у своих, градиент у чужих */
.audio-btn-me {
    background: rgba(255,255,255,.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,.34);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}
.audio-btn-me:hover { background: rgba(255,255,255,.28); }
.audio-btn-other {
    background: linear-gradient(135deg, #5f98d1, #41699b);
    color: #fff;
    box-shadow: 0 5px 16px -7px rgba(82,136,193,.6);
}
.audio-title { font-size: 13.5px; font-weight: 600; color: rgba(255,255,255,.92); letter-spacing: .1px; }

/* Верхний мини-плеер: глубже фон, мягче типографика, градиентный прогресс */
#global-audio-player { background: linear-gradient(180deg, rgba(24,35,47,.97), rgba(15,23,32,.96)) !important; border-bottom-color: rgba(255,255,255,.07) !important; }
#gap-cover { border-radius: 10px; }
#gap-title { color: #e9eef4; font-size: 13.5px; }
#gap-artist { color: #8fb8e4; font-size: 11.5px; }
#gap-play-pause { color: #e9eef4; }
#gap-progress-fill { background: linear-gradient(90deg, #5c95ce, #83b6ea) !important; }

/* Тексты сообщений: мягкий белый вместо чистого */
.bubble-rounded .whitespace-pre-wrap { color: #e9eef5; }
.bubble-rounded.bg-tg-bubbleMe .whitespace-pre-wrap { color: rgba(255,255,255,.94); }

/* Ссылки в сообщениях: мягкий голубой, аккуратные переносы, тонкое подчёркивание */
.msg-link { overflow-wrap: anywhere; word-break: normal; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.msg-link-me { color: #c7defc; text-decoration-color: rgba(199,222,252,.45); }
.msg-link-me:hover { color: #ffffff; }
.msg-link-other { color: #6ab3f3; text-decoration-color: rgba(106,179,243,.4); }
.msg-link-other:hover { color: #8fc4f7; }

.spoiler-cover .sp-txt {
    font-size: 12px; color: #fff; font-weight: 500;
    background: rgba(0,0,0,.5); padding: 4px 12px; border-radius: 9999px;
    backdrop-filter: blur(4px);
}
