:root {
    --tg-theme-bg-color: #f5f5f5;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #707579;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #ffffff;
}

/* Настройки для запуска в реальном Телеграме (подтягиваем системные цвета) */
@media (prefers-color-scheme: dark) {
    :root {
        --tg-theme-bg-color: #18222d;
        --tg-theme-text-color: #ffffff;
        --tg-theme-hint-color: #b1c3d5;
        --tg-theme-link-color: #62bcf9;
        --tg-theme-button-color: #2f8cc9;
        --tg-theme-button-text-color: #ffffff;
        --tg-theme-secondary-bg-color: #212d3b;
    }
    
    .screen {
        background: rgba(24, 34, 45, 0.8) !important; /* Благородный темный полупрозрачный фон */
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: url('bg.jpg') no-repeat center center fixed;
    background-size: cover;
    color: var(--tg-theme-text-color, #222222);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 70px 20px 20px 20px;
}


/* Эффект матового стекла для всех игровых экранов */
.screen {
    width: 100%;
    max-width: 450px;
    background: rgba(255, 255, 255, 0.75); /* Белый полупрозрачный фон для светлой темы */
    backdrop-filter: blur(15px);          /* Красивое размытие заднего фона */
    -webkit-backdrop-filter: blur(15px);  /* Размытие для iOS устройств */
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    text-align: center;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.hidden {
    display: none !important;
}

/* Верхняя шапка меню — плавающая поверх всех экранов */
.top-header-menu {
    position: fixed;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}
.top-header-menu > * {
    pointer-events: auto;
}

/* В режиме теста прячем язык и профиль — остаётся только кнопка звука */
body.in-quiz #lang-select,
body.in-quiz #profile-toggle-btn {
    display: none;
}

/* Элегантный стиль для кнопок звука и личного кабинета */
.header-menu-btn {
    background: rgba(36, 129, 204, 0.1); 
    color: var(--tg-theme-link-color, #2481cc);
    border: none;
    padding: 8px 14px;
    border-radius: 20px; 
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
}

.header-menu-btn:active {
    transform: scale(0.95);
}

/* Круглый заменяемый список ручного выбора языков */
.header-lang-dropdown {
    background: rgba(36, 129, 204, 0.1);
    color: var(--tg-theme-link-color, #2481cc);
    border: none;
    padding: 6px 10px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    width: auto;
    margin-top: 0;
}

/* Контейнер приветствия */
.welcome-container {
    margin: 20px 0;
    text-align: left;
}

.welcome-text {
    font-size: 15px;
    line-height: 1.5;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color);
    opacity: 0.9;
}

.test-features {
    background: rgba(0, 0, 0, 0.03);
    padding: 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.8;
}

/* Кнопочная система */
.main-btn, .share-button, .premium-button {
    width: 100%;
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 12px;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.main-btn:active, .answer-btn:active {
    transform: scale(0.98);
}

.answer-btn {
    width: 100%;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    margin-top: 10px;
    cursor: pointer;
    background-color: rgba(36, 129, 204, 0.08);
    color: var(--tg-theme-link-color);
    text-align: left;
    padding-left: 18px;
    transition: background 0.2s ease;
}

.answer-btn:hover {
    background-color: rgba(36, 129, 204, 0.15);
}

/* === V2: снимаем залипание фокуса после тапа === */
.answer-btn:focus,
.answer-btn:focus-visible {
    outline: none;
}

/* === V2: подсветка при нажатии (мобильная) === */
.answer-btn:active {
    background-color: rgba(36, 129, 204, 0.20);
    transform: scale(0.99);
}

.premium-button {
    background: linear-gradient(135deg, #f1c40f, #f39c12);
    color: #fff;
}

/* Кнопка «Пройти тест заново» — призрачная, чтобы не спорить с основными действиями */
.restart-btn {
    width: 100%;
    background: transparent;
    color: var(--tg-theme-link-color, #2481cc);
    border: 2px solid var(--tg-theme-link-color, #2481cc);
    padding: 12px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.restart-btn:active {
    transform: scale(0.98);
    background: rgba(36, 129, 204, 0.08);
}

/* Тёмная тема — лёгкая подсветка при наведении */
@media (prefers-color-scheme: dark) {
    .restart-btn:active {
        background: rgba(98, 188, 249, 0.15);
    }
}
/* Верхняя плашка прогресса и таймера */
.progress-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.03);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    color: var(--tg-theme-text-color);
}

.progress-bar strong {
    color: var(--tg-theme-text-color);
    font-weight: 700;
}

.timer-box {
    font-size: 15px;
    font-weight: bold;
    color: var(--tg-theme-link-color);
    background: rgba(36, 129, 204, 0.1);
    padding: 4px 10px;
    border-radius: 6px;
    font-variant-numeric: tabular-nums;
}

.timer-box.urgent {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Крупный вывод чисел/слов для кратковременной памяти */
.memory-display-value {
    font-size: clamp(18px, 6vw, 32px);
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--tg-theme-link-color);
    margin: 30px 0;
    background: rgba(36, 129, 204, 0.05);
    padding: 20px;
    border-radius: 12px;
    border: 2px dashed rgba(36, 129, 204, 0.2);
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-align: center;
}

.memory-timer-notice {
    font-size: 14px;
    font-weight: bold;
    color: #e67e22;
    padding: 15px;
    font-style: italic;
}

.quiz-img {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 16px;
}

/* Калибровочный блок возраста */
.calibration-box {
    padding: 10px 0;
}
.calibration-box p {
    font-size: 14px;
    margin: 10px 0 16px 0;
    opacity: 0.8;
}

/* Результаты и шкалы */
.iq-score-box {
    margin: 20px 0;
}
.iq-value {
    font-size: 48px;
    font-weight: 800;
    color: #2ecc71;
    margin-top: 8px;
}

.categories-stats {
    background: rgba(0, 0, 0, 0.02);
    padding: 16px;
    border-radius: 12px;
    margin: 16px 0;
    text-align: left;
}

.stat-row {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
}
.stat-row span { width: 110px; font-weight: 500; }
.stat-row strong { width: 40px; text-align: right; }

.progress-bar-mini {
    flex-grow: 1;
    background: rgba(0, 0, 0, 0.05);
    height: 8px;
    border-radius: 4px;
    margin: 0 10px;
    overflow: hidden;
}

.bar {
    height: 100%;
    width: 0%;
    background-color: var(--tg-theme-button-color);
    border-radius: 4px;
    transition: width 0.6s ease;
}

/* Модальные окна (Оверлей) */
.screen.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 16px;
}

.modal-content {
    background: var(--tg-theme-secondary-bg-color);
    padding: 24px;
    border-radius: 16px;
    width: 100%;
    max-width: 380px;
    text-align: left;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--tg-theme-hint-color);
    cursor: pointer;
}

.app-footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid rgba(0,0,0,0.05);
}
.footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
}
.footer-link-btn {
    background: none;
    border: none;
    color: var(--tg-theme-hint-color, #707579);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
}
.copyright-text {
    font-size: 11px;
    color: var(--tg-theme-hint-color);
    margin-top: 10px;
    opacity: 0.6;
}
/* Мелкий шрифт для юридического соглашения под кнопкой старта */
.privacy-agreement-notice {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 10px;
    color: var(--tg-theme-text-color);
    line-height: 1.3;
}
/* V2: Панель бонусов во время теста */
.bonus-panel {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
}

.bonus-btn {
    flex: 1;
    background: rgba(36, 129, 204, 0.08);
    color: var(--tg-theme-link-color, #2481cc);
    border: 1px solid transparent; /* ВМЕСТО border: none; (резервируем место под рамку) */
    padding: 8px 6px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.3s ease; /* ВМЕСТО transition: all; */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    outline: none; /* Убираем стандартную обводку браузера */
    -webkit-tap-highlight-color: transparent; /* Убираем синюю вспышку при тапе на Android */
}

.bonus-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.bonus-btn:disabled,
.bonus-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    background: rgba(0, 0, 0, 0.05);
}

.bonus-counter {
    background: rgba(36, 129, 204, 0.18);
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: bold;
}

/* Заблокированный вариант ответа (после подсказки) */
.answer-btn.disabled-answer {
    opacity: 0.25;
    pointer-events: none;
    text-decoration: line-through;
}
/* V2: блок статистики в профиле */
.profile-stats-block {
    margin-top: 20px;
    padding: 16px;
    background: rgba(36, 129, 204, 0.05);
    border-radius: 12px;
}

.stat-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    padding: 6px 0;
    color: var(--tg-theme-text-color);
}

.stat-line strong {
    color: var(--tg-theme-link-color, #2481cc);
    font-weight: 700;
}

/* V2: Шапка профиля с аватаром */
.profile-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
}

.profile-avatar-wrap {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    position: relative;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 2px solid rgba(36, 129, 204, 0.2);
}

.profile-avatar-placeholder {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2481cc, #62bcf9);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    text-transform: uppercase;
    border: 2px solid rgba(36, 129, 204, 0.2);
}

.profile-header-info {
    flex-grow: 1;
    min-width: 0;
}

/* === V2: Блок настроек (модалка звука и вибрации) === */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.settings-row:last-of-type {
    border-bottom: none;
}

.settings-toggle {
    width: 42px;
    height: 24px;
    appearance: none;
    -webkit-appearance: none;
    background: #cccccc;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
    border: none;
    outline: none;
}

.settings-toggle:checked {
    background: #2ecc71;
}

.settings-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    transition: left 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.settings-toggle:checked::after {
    left: 20px;
}

@media (prefers-color-scheme: dark) {
    .settings-row {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }
    .settings-toggle {
        background: #444c55;
    }
    .settings-toggle:checked {
        background: #2ecc71;
    }
}

/* Мягкая синяя пульсация для кнопки времени */
.bonus-btn.attention-mode {
    background: rgba(36, 129, 204, 0.15) !important;
    border-color: rgba(36, 129, 204, 0.5) !important; /* Меняем только цвет рамки */
    animation: pulse-blue 2s ease-in-out infinite alternate;
}

@keyframes pulse-blue {
    0% { box-shadow: 0 0 0 rgba(36, 129, 204, 0); }
    100% { box-shadow: 0 0 10px rgba(36, 129, 204, 0.5); }
}

/* Мягкая зеленая пульсация для подсказки */
.bonus-btn.attention-mode-green {
    background: rgba(46, 204, 113, 0.15) !important;
    border-color: rgba(46, 204, 113, 0.5) !important; /* Меняем только цвет рамки */
    animation: pulse-green 2s ease-in-out infinite alternate;
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 10px rgba(46, 204, 113, 0.5); }
}