/* --- common.css --- */
/* --- Общие Стили --- */
@font-face {
  font-family: "Twemoji Country Flags";
  unicode-range: U+1F1E6-1F1FF;
  src: url("https://unpkg.com/country-flag-emoji-polyfill@0.1.5/dist/TwemojiCountryFlags.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Twemoji Country Flags";
  unicode-range: U+1F1E6-1F1FF;
  src: url("https://unpkg.com/country-flag-emoji-polyfill@0.1.5/dist/TwemojiCountryFlags.woff2") format("woff2");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

:root {
    --global-font-size: 16px;
    --global-font-family: "Twemoji Country Flags", 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --app-height: 100dvh;
    
    /* --- Светлая тема (Дефолтная) --- */
    --bg-grad-start: #f1f5f9;
    --bg-grad-end: #cbd5e1;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --text-color: #0f172a;
    --bg-color: #ffffff;
    --paper-color: #f8fafc;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --gold-color: #f59e0b;
    --selected-category-bg: color-mix(in srgb, var(--success-color) 15%, transparent);
    --partial-category-bg: color-mix(in srgb, #3b82f6 40%, transparent);
    --selected-theme-bg: color-mix(in srgb, #10b981 30%, transparent);
    --partial-theme-bg: color-mix(in srgb, #3b82f6 30%, transparent);
    --app-bottom-safe: 40px;
    --shadow-color: rgba(15, 23, 42, 0.08);
}

/* --- Классическая уютная тема (Сепия) --- */
[data-theme="sepia"], .theme-sepia {
    --bg-grad-start: #d7c29e;
    --bg-grad-end: #b9a178;
    --accent-color: #5d4037;
    --accent-hover: #4e342e;
    --text-color: #3e2723;
    --bg-color: #fdf5e6;
    --paper-color: #faf3e0;
    --success-color: #4CAF50;
    --danger-color: #f44336;
    --gold-color: #FFD700;
    --selected-category-bg: color-mix(in srgb, var(--success-color) 15%, transparent);
    --partial-category-bg: color-mix(in srgb, #87CEEB 40%, transparent);
    --selected-theme-bg: color-mix(in srgb, #90EE90 50%, transparent);
    --partial-theme-bg: color-mix(in srgb, #ADD8E6 50%, transparent);
    --shadow-color: rgba(93, 64, 55, 0.15);
}

/* --- Современная Тёмная тема --- */
[data-theme="dark"], .theme-dark {
    --bg-grad-start: #0f172a;
    --bg-grad-end: #020617;
    --accent-color: #c4b5fd;
    --accent-hover: #8b5cf6;
    --text-color: #f8fafc;
    --text-muted: #cbd5e1;
    --bg-color: #1e293b;
    --paper-color: #111827;
    --border-color: rgba(196, 181, 253, 0.38);
    --success-color: #10b981;
    --danger-color: #f43f5e;
    --gold-color: #fbbf24;
    --selected-category-bg: color-mix(in srgb, var(--success-color) 25%, transparent);
    --partial-category-bg: color-mix(in srgb, #60a5fa 40%, transparent);
    --selected-theme-bg: color-mix(in srgb, #10b981 40%, transparent);
    --partial-theme-bg: color-mix(in srgb, #60a5fa 40%, transparent);
    --shadow-color: rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

button, input, select, textarea, a, .tactical-row, .start-batch-btn, .continue-batch-btn {
    touch-action: manipulation;
}

/* --- Twemoji Country Flags Polyfill --- */
@font-face {
    font-family: "Twemoji Country Flags";
    src: url("https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1.3/dist/TwemojiCountryFlags.woff2") format("woff2");
}

.emoji-flag {
    font-family: "Twemoji Country Flags", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif !important;
    font-style: normal;
    font-weight: normal;
}

body {
    font-family: var(--global-font-family);
    font-size: var(--global-font-size);
    background: linear-gradient(135deg, var(--bg-grad-start), var(--bg-grad-end));
    min-height: var(--app-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease, font-size 0.3s, font-family 0.3s;
    color: var(--text-color);
}



.main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 960px;
    position: relative;
    min-height: unset;
    margin-bottom: 40px;
    /* отрыв от низа */
    margin-bottom: var(--app-bottom-safe);
}




.container {
    background: color-mix(in srgb, var(--bg-color) 94%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--cab-border, rgba(148, 163, 184, 0.15));
    color: var(--text-color);
    border-radius: 24px;
    box-shadow: 0 10px 30px var(--shadow-color);
    padding: 30px 25px;
    max-width: 900px;
    width: 100%;
    position: relative;
    overflow: visible;
    margin-top: 10px;
    margin-bottom: 10px;
    transition: max-width 0.4s ease-in-out, background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* --- Стили для кнопки "Назад" (используется на стр. Выбора) --- */
.header-controls {
    display: flex;
    width: 100%;
    max-width: 900px;
    /* Совпадает с .container */
    margin-bottom: 10px;
    justify-content: flex-start;
}

.header-controls .button {
    padding: 8px 15px;
    font-size: 0.9em;
    width: auto;
    /* Переопределяем width: 100% */
}

h1 {
    color: var(--accent-color);
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.8em;
    position: relative;
}

h2,
h3 {
    color: var(--accent-hover);
    margin-bottom: 15px;
    margin-top: 10px;
}

.button {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 20px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    margin: 5px;
    width: auto;
    font-weight: 500;
}

.button:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.button.secondary {
    background: var(--paper-color);
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
}

.button.secondary:hover:not(:disabled) {
    color: white;
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #bbb;
    color: #777;
    border-color: #bbb;
    box-shadow: none;
    transform: none;
}

.button.small {
    padding: 6px 15px;
    font-size: 0.9em;
    text-decoration: none !important;
}

.tooltip {
    position: fixed;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    transition: opacity 0.2s, visibility 0s linear 0.2s;
    pointer-events: none;
    white-space: pre-wrap;
    max-width: 300px;
    line-height: 1.4;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.tooltip.visible {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}


/* --- Общая Адаптация --- */
@media (max-width: 768px) {
    body {
        padding: 5px;
    }

    .container {
        padding: 24px 16px;
        border-radius: 24px;
        min-height: calc(var(--app-height) - 20px);
    }

    /* --- Адаптация кнопки "Назад" --- */
    .header-controls {
        margin-bottom: 5px;
        padding: 0 10px;
    }

    h1 {
        font-size: 1.6em;
    }

    .button {
        padding: 12px 20px;
    }
}

/* --- GLOBAL PRELOADER (Обновленный) --- */
#global-preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Изменено: полупрозрачный светлый фон (R, G, B, Прозрачность от 0 до 1) */
    background: rgba(245, 245, 235, 0.85);
    z-index: 99999;
    /* Поверх всего */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    backdrop-filter: blur(2px);
    /* Дополнительный эффект размытия фона под прелоадером (работает в современных браузерах) */
}

#global-preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* Анимация пульсации для иконки */
.preloader-icon {
    /* Изменено: Размер увеличен в 5 раз (было 4rem) */
    font-size: 20rem;
    animation: markPulse 500ms infinite ease-in-out;
    /* Чуть медленнее пульсация (2s) */
    margin-bottom: 10px;
    /* Убрал отступ снизу, при таком размере он не нужен */
    line-height: 1;
}

.preloader-text {
    font-family: var(--global-font-family);
    color: var(--accent-color);
    font-size: 3.0rem;
    /* Чуть увеличил текст */
    font-weight: 600;
    opacity: 0.8;
    letter-spacing: 2px;
    margin-top: -10px;
    /* Подтянул текст поближе к огромному мозгу */
}

@keyframes markPulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    /* Изменено: пульсация стала мягче (1.05 вместо 1.1), так как объект огромный */
    40% {
        transform: scale(1.05);
        opacity: 0.9;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Стили для кнопок виджета */
#audio-widget button {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 5px;
    transition: transform 0.2s;
}

#audio-widget button:hover {
    transform: scale(1.2);
}

#audio-widget button.muted {
    opacity: 0.6;
    filter: grayscale(100%);
}


html {
    font-size: 16px;
}

@media (min-height: 900px) {
    body {
        justify-content: center;
    }
}

@media (min-width: 1920px) {
    html {
        font-size: 18px;
        /* ≈ 112–120% */
    }
}

@media (min-width: 2560px) {
    html {
        font-size: 19px;
    }
}


/* --- Cookie Consent Banner --- */
.cookie-consent-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    background: var(--bg-color);
    /* Используем твой бежевый фон */
    border: 2px solid var(--accent-color);
    /* Твой акцентный коричневый */
    color: var(--text-color);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    z-index: 99999;
    /* Поверх всего, даже прелоадера */
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    animation: slideUp 0.5s ease-out;
    font-family: var(--global-font-family);
}

.cookie-consent-banner p {
    margin-bottom: 15px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.cookie-consent-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.cookie-consent-banner .button {
    background: #7c3aed !important;
    color: #fff !important;
}

.cookie-consent-banner .button:hover:not(:disabled) {
    background: #6d28d9 !important;
}

[data-theme="dark"] .cookie-consent-banner .button,
.theme-dark .cookie-consent-banner .button {
    background: #6d28d9 !important;
    color: #fff !important;
}

[data-theme="dark"] .cookie-consent-banner .button:hover:not(:disabled),
.theme-dark .cookie-consent-banner .button:hover:not(:disabled) {
    background: #5b21b6 !important;
}

/* Анимация появления */
@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

@keyframes btnPulse {
    0% { opacity: 1; transform: scale(0.95); }
    50% { opacity: 0.6; transform: scale(1); box-shadow: 0 0 10px rgba(255, 255, 255, 0.3); }
    100% { opacity: 1; transform: scale(0.95); }
}

.btn-loading-pulse {
    animation: btnPulse 0.6s ease-in-out infinite !important;
    pointer-events: none;
}

/* Адаптивность для мобилок */
@media (max-width: 480px) {
    .cookie-consent-banner {
        width: 95%;
        bottom: 10px;
        padding: 15px;
    }

    .cookie-consent-actions {
        flex-direction: row;
    }
}

/* --- PREMIUM GLOBAL HEADER BAR SYSTEM --- */
body.themed-body {
  padding-top: 64px;
  box-sizing: border-box;
}

.login-header-bar {
  position: absolute;
  top: 0;
  left: 50%;
  width: auto;
  padding: 10px 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0 0 22px 22px;
  z-index: 100;
  transform: translateX(-50%);
  transition: background 0.4s ease, border-color 0.4s ease;
}
[data-theme="dark"] .login-header-bar {
  background: rgba(15, 23, 42, 0.4);
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
}
[data-theme="sepia"] .login-header-bar {
  background: rgba(244, 228, 205, 0.4);
  border-bottom: 1px solid rgba(93, 64, 55, 0.15);
}
.login-header-logo {
  font-size: 1.15em;
  font-weight: 800;
  color: var(--accent-color);
  letter-spacing: 0.5px;
  line-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.login-header-nav {
  display: inline-flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}
.app-mark-icon {
  width: 24px;
  height: 24px;
  display: inline-block;
  vertical-align: middle;
}
.login-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-settings-btn {
  background: rgba(181, 133, 77, 0.12);
  color: var(--accent-color);
  border: 1px solid var(--border-color);
  width: 42px;
  height: 42px;
  border-radius: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.header-settings-btn:hover {
  background: var(--accent-color);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--shadow-color);
}
.header-settings-btn:active {
  transform: translateY(0);
}
.header-settings-popover {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: min(260px, calc(100vw - 24px));
  padding: 12px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg-color) 94%, white 6%);
  border: 1px solid var(--cab-border, rgba(148, 163, 184, 0.18));
  box-shadow: 0 18px 40px var(--shadow-color);
  backdrop-filter: blur(12px);
  display: none;
  z-index: 260;
}
.header-settings-popover[hidden] {
  display: none !important;
}
.header-settings-popover.active {
  display: block;
}
.header-settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.header-settings-row + .header-settings-row {
  margin-top: 12px;
}
.header-settings-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-color);
  opacity: 0.72;
}
.header-settings-popover .lang-switcher-bar,
.header-settings-popover .theme-switcher-bar {
  height: 36px;
  margin: 0;
  box-sizing: border-box;
  align-items: center;
}
.header-settings-popover .lang-switcher-bar {
  width: 100%;
  justify-content: space-between;
}
.header-settings-popover .lang-switch-btn {
  flex: 1 1 0;
}
.theme-switcher-bar {
  display: flex;
  gap: 6px;
  background: rgba(181, 133, 77, 0.1);
  padding: 4px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
}
[data-theme="dark"] .theme-switcher-bar {
  background: rgba(139, 92, 246, 0.15);
}
.theme-switch-btn {
  background: none;
  border: none;
  font-size: 1.1em;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.25s ease;
}
.theme-switch-btn:hover {
  background: rgba(181, 133, 77, 0.2);
}
[data-theme="dark"] .theme-switch-btn:hover {
  background: rgba(139, 92, 246, 0.25);
}
.theme-switch-btn.active {
  background: var(--accent-color) !important;
  box-shadow: 0 2px 8px var(--shadow-color);
}

@media (max-width: 600px) {
  body.themed-body {
    padding-top: 58px;
  }
  .login-header-bar {
    top: 0;
    left: 50%;
    width: min(calc(100vw - 12px), 540px);
    padding: max(7px, env(safe-area-inset-top)) 10px 7px;
    gap: 6px;
    position: fixed;
    justify-content: space-between;
    border-radius: 0 0 18px 18px;
    transform: translateX(-50%);
    overflow: visible;
  }
  .login-header-bar--home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
  .login-header-bar--back {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
  }
  .login-header-controls {
    flex-grow: 0;
    width: auto;
    min-width: 0;
    justify-content: flex-end;
    gap: 6px;
    justify-self: end;
  }
  .login-header-nav {
    gap: 8px;
    min-width: 0;
  }
  .login-header-logo {
    display: none;
  }
  .login-header-logo.mobile-header-brand {
    display: inline-flex;
    min-width: 0;
    max-width: 100%;
    overflow: visible;
    text-overflow: ellipsis;
    font-size: clamp(0.82rem, 3.8vw, 1rem);
    line-height: 30px;
    gap: 6px;
  }
  .login-header-logo.mobile-header-brand .app-mark-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
  }
  .login-header-bar--home .login-header-logo.mobile-header-brand {
    justify-self: start;
  }
  .login-header-bar--back .login-header-logo.mobile-header-brand {
    justify-self: start;
  }
  .lang-switcher-bar {
    margin-bottom: 0;
    padding: 2px;
    border-radius: 18px;
  }
  .lang-switch-btn {
    padding: 5px 8px;
    min-width: 36px;
    font-size: 0.72rem;
    border-radius: 14px;
  }
  .theme-switcher-bar {
    padding: 2px;
    gap: 2px;
    border-radius: 18px;
    flex: 0 0 auto;
  }
  .theme-switch-btn {
    width: 26px;
    height: 26px;
    font-size: 0.88em;
  }
  .header-settings-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    font-size: 0.98rem;
  }
  .header-settings-popover {
    top: 56px;
    left: 50%;
    width: min(250px, calc(100vw - 20px));
    padding: 10px;
  }
  .back-to-main-btn-premium {
    width: 32px !important;
    height: 32px !important;
    flex: 0 0 auto;
  }
  .back-to-main-btn-premium svg {
    width: 14px;
    height: 14px;
  }
  .login-header-bar--back .login-header-nav {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }
  .container, .themed-container, .menu-container {
    margin-top: 10px;
  }
}

/* --- PREMIUM BACK BUTTON SYSTEM --- */
.back-to-main-btn-premium {
  background: rgba(181, 133, 77, 0.1);
  color: var(--accent-color);
  border: 1px solid var(--border-color);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}
[data-theme="dark"] .back-to-main-btn-premium {
  background: rgba(139, 92, 246, 0.15);
}
.back-to-main-btn-premium:hover {
  background: var(--accent-color);
  color: #fff;
  transform: scale(1.08);
  box-shadow: 0 4px 15px var(--shadow-color);
}
.back-to-main-btn-premium:active {
  transform: scale(0.95);
}


/* Оптимизация для Firefox (включая мобильный) */
@supports (-moz-appearance: none) {
    /* 1. Жестко отключаем размытие везде (повышаем специфичность, чтобы перебить !important из inline стилей) */
    *, 
    .home-header-bar, .login-header-bar, .menu-container, .container, .glass-panel, .header-settings-popover,
    [class*="glass"], [class*="modal"], [class*="overlay"], .theme-card, .category-item,
    .app-header, .app-bottom-nav, .cab-header, .chat-panel, .chat-contacts-panel, .chat-main-panel,
    .lc-modal-overlay, .story-card, .story-top-bar, .story-bottom-bar,
    .dt-header, .dt-bottom-nav, .item-row {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* 2. Убираем тяжелый фон с body, убивающий композитор при скролле */
    body {
        background-attachment: scroll !important;
        background: none !important;
    }
    
    /* 3. Выносим градиент в отдельный GPU-слой на псевдоэлементе */
    body::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg, var(--bg-grad-start), var(--bg-grad-end));
        z-index: -1;
        transform: translateZ(0); /* Аппаратное ускорение */
        pointer-events: none;
    }

    /* Адаптация под темную тему Firefox */
    [data-theme="dark"] body::before,
    body.theme-dark::before {
        background: 
            radial-gradient(circle at top, rgba(124, 58, 237, 0.16), transparent 38%),
            linear-gradient(135deg, #0f172a 0%, #020617 100%) !important;
    }

    /* Делаем фоны чуть менее прозрачными, так как нет размытия, и упрощаем тени */
    .home-header-bar, .login-header-bar, .menu-container, .container, .glass-panel, .header-settings-popover, .home-settings-popover, .theme-card, .category-item {
        background: rgba(255, 255, 255, 0.98) !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
    }
    [data-theme="dark"] .home-header-bar, [data-theme="dark"] .login-header-bar, [data-theme="dark"] .menu-container, [data-theme="dark"] .container, [data-theme="dark"] .glass-panel, [data-theme="dark"] .header-settings-popover, [data-theme="dark"] .home-settings-popover, [data-theme="dark"] .theme-card, [data-theme="dark"] .category-item {
        background: rgba(15, 23, 42, 0.98) !important;
    }

    /* 4. Убираем тяжелую маску-градиент, которая заставляет мобильный процессор Gecko тормозить */
    .login-dynamic-scroll, .dynamic-scroll {
        mask-image: none !important;
        -webkit-mask-image: none !important;
        border-bottom: 1px dashed var(--accent-color);
    }
}
