/* ========================================= */
/* --- 1. ORIGINAL DESKTOP STYLES (BASE) --- */
/* ========================================= */

:root {
    --color-canvas-subtle: #f0f2f5; 
    --header-bg: #0f172a; 
    --color-success-fg: #1a7f37;
    --color-success-bg: #dafbe1;
    --color-danger-fg: #cf222e;
    --color-danger-bg: #ffebe9;
    
    /* Exam Theme (Dark) */
    --exam-bg: #15202b;
    --exam-card-bg: #1c262f;
    --exam-text: #c9d1d9;
    --modal-dark-bg: #212936;
}

* { box-sizing: border-box; }

body {
    font-family: Arial, sans-serif;
    /* Базовые настройки фона для ПК (фиксированный) */
    background: url('colors.png') no-repeat center center fixed;
    background-size: cover;
    background-color: var(--color-canvas-subtle);
    color: #24292e;
    margin: 0; padding: 0; 
    min-height: 100vh; /* Используем min-height вместо height для прокрутки фона */
    display: flex; flex-direction: column;
    overflow-x: hidden; /* Скрываем горизонтальный скролл */
}

/* --- BUTTONS --- */
button {
  appearance: none; background-color: #fafbfc; border: 1px solid rgba(27, 31, 35, 0.15);
  border-radius: 6px; box-sizing: border-box; color: #24292e; cursor: pointer;
  display: inline-block; font-family: Arial, sans-serif; font-size: 14px;
  font-weight: 500; line-height: 20px; padding: 6px 16px; transition: 0.2s;
}
button:hover { background-color: #f3f4f6; }
button:disabled { background-color: #fafbfc; color: #959da5; cursor: default; }

button.primary-btn { color: #fff; background-color: #2da44e; border-color: rgba(27, 31, 35, 0.15); }
button.primary-btn:hover { background-color: #2c974b; }
button.large-btn { padding: 12px 24px; font-size: 16px; }

button.secondary-btn-dark { background: #30363d; color: #c9d1d9; border: 1px solid #6e7681; }
button.secondary-btn-dark:hover { background: #3b434b; }

button.text-btn { background: none; border: none; color: #0969da; padding: 0; margin-left: 5px; text-decoration: underline; }
button.text-btn:hover { background: none; color: #0a58ca; }

.vk-btn {
    width: 100%; background: #0077FF; color: white; border: none; border-radius: 6px;
    padding: 12px; margin-bottom: 15px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 15px; transition: background 0.2s;
}
.vk-btn:hover { background: #0066DD; }
#profile-sync-status { font-weight: 500; font-size: 13px; color: #7adbfb !important; }
.social-auth { margin-bottom: 20px; }
.divider { display: flex; align-items: center; text-align: center; color: #888; margin: 15px 0; font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid #ddd; }
.divider::before { margin-right: 10px; }
.divider::after { margin-left: 10px; }


/* --- HEADER --- */
header {
    background-color: var(--header-bg);
    height: 70px;
    display: flex; justify-content: center; 
    align-items: center; 
    box-shadow: 0 4px 6px rgba(0,0,0,0.3); flex-shrink: 0; z-index: 100;
    padding: 0 15px;
    position: relative;
}
.header-inner { display: flex; align-items: center; justify-content: center; width: 100%; }
.nav-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 5px; margin: 0 auto; }
.nav-btn { font-size: 15px; white-space: nowrap; }
.nav-btn.active { background-color: #edeff2; border-color: rgba(27, 31, 35, 0.15); color: #24292e; }

.profile-nav-btn {
    position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
    display: flex; align-items: center; gap: 10px; cursor: pointer; color: #fff;
}
.profile-avatar-small {
    width: 32px; height: 32px; background: #2da44e; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 18px; overflow: hidden;
}
.profile-avatar-small img { width: 100%; height: 100%; object-fit: cover; }
#header-username { font-weight: bold; font-size: 14px; }


/* --- LAYOUT --- */
main { flex: 1; overflow-y: auto; padding: 20px 10px; display: flex; justify-content: center; position: relative; }
.container { width: 100%; max-width: 800px; padding-bottom: 40px; }
.view-section { display: none; }
.view-section.active { display: block; }
.content-box { background: #fff; border: 1px solid #d0d7de; border-radius: 6px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
h2 { text-align: center; margin-bottom: 20px; font-weight: normal; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
.content-box h2, .intro-card h2, .auth-card h2 { color: #24292e; text-shadow: none; }

.auth-card { background: #fff; border: 1px solid #d0d7de; border-radius: 8px; padding: 30px; max-width: 400px; margin: 40px auto; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.auth-form input { width: 100%; margin-bottom: 10px; padding: 10px; border: 1px solid #d0d7de; border-radius: 6px; }
.auth-footer { margin-top: 20px; font-size: 13px; color: #57606a; }

.profile-header-card { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: #fff; padding: 30px; border-radius: 8px; margin-bottom: 20px; display: flex; align-items: center; gap: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.2); }
.profile-avatar-large { width: 70px; height: 70px; background: #2da44e; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 36px; border: 3px solid #fff; overflow: hidden; }
.profile-avatar-large img { width: 100%; height: 100%; object-fit: cover; }
.profile-info { flex: 1; text-align: left; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.stat-card { background: #fff; padding: 15px; border-radius: 8px; border: 1px solid #d0d7de; text-align: center; }
.stat-value { font-size: 24px; font-weight: bold; color: #0969da; }
.stat-desc { font-size: 12px; color: #57606a; }

/* --- ICONS --- */
.soft-icon { width: 100px; height: 100px; margin: 0 auto 25px auto; position: relative; }
.soft-icon.profile .shape-1 { position: absolute; width: 50px; height: 50px; background: #0969da; border-radius: 50%; top: 10px; left: 25px; }
.soft-icon.profile .shape-2 { position: absolute; width: 80px; height: 40px; background: #0969da; border-radius: 40px 40px 0 0; bottom: 10px; left: 10px; opacity: 0.8; }
.soft-icon.marathon .shape-1 { position: absolute; width: 50px; height: 50px; background: #4285F4; border-radius: 50%; top: 0; left: 10px; opacity: 0.9; }
.soft-icon.marathon .shape-2 { position: absolute; width: 45px; height: 45px; background: #34A853; border-radius: 8px; bottom: 5px; right: 10px; opacity: 0.9; transform: rotate(15deg); }
.soft-icon.marathon .shape-3 { position: absolute; width: 0; height: 0; border-left: 20px solid transparent; border-right: 20px solid transparent; border-bottom: 40px solid #FBBC05; bottom: 10px; left: 15px; opacity: 0.9; }
.soft-icon.exam .shape-1 { position: absolute; width: 50px; height: 50px; background: #EA4335; border-radius: 12px; top: 5px; right: 15px; opacity: 0.9; transform: rotate(-10deg); }
.soft-icon.exam .shape-2 { position: absolute; width: 50px; height: 50px; background: #4285F4; border-radius: 50%; bottom: 10px; left: 15px; opacity: 0.9; }
.soft-icon.exam .shape-3 { position: absolute; width: 30px; height: 6px; background: #fff; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(45deg); border-radius: 4px; z-index: 2; }
.soft-icon.exam .shape-3::after { content:''; position: absolute; width: 30px; height: 6px; background: #fff; transform: rotate(90deg); border-radius: 4px; }
.soft-icon.tickets .shape-1 { position: absolute; width: 40px; height: 50px; background: #4285F4; border-radius: 4px; left: 20px; top: 15px; transform: rotate(-10deg); opacity: 0.8; }
.soft-icon.tickets .shape-2 { position: absolute; width: 40px; height: 50px; background: #fff; border: 2px solid #4285F4; border-radius: 4px; left: 35px; top: 20px; transform: rotate(5deg); display: flex; flex-direction: column; justify-content: space-evenly; align-items: center; }
.soft-icon.tickets .shape-2::before, .soft-icon.tickets .shape-2::after { content:''; width: 20px; height: 2px; background: #4285F4; display: block; }
.soft-icon.range .shape-1 { position: absolute; width: 60px; height: 6px; background: #eee; border-radius: 3px; top: 30px; left: 20px; }
.soft-icon.range .shape-1::after { content:''; position: absolute; width: 14px; height: 14px; background: #34A853; border-radius: 50%; top: -4px; left: 10px; }
.soft-icon.range .shape-2 { position: absolute; width: 60px; height: 6px; background: #eee; border-radius: 3px; top: 60px; left: 20px; }
.soft-icon.range .shape-2::after { content:''; position: absolute; width: 14px; height: 14px; background: #EA4335; border-radius: 50%; top: -4px; right: 15px; }
.soft-icon.mistakes .shape-1 { position: absolute; width: 50px; height: 50px; background: #ffebe9; border: 2px solid #cf222e; border-radius: 50%; top: 20px; left: 25px; }
.soft-icon.mistakes .shape-2 { position: absolute; width: 4px; height: 20px; background: #cf222e; top: 35px; left: 48px; transform: rotate(45deg); border-radius: 2px; }
.soft-icon.mistakes .shape-3 { position: absolute; width: 4px; height: 20px; background: #cf222e; top: 35px; left: 48px; transform: rotate(-45deg); border-radius: 2px; }


.btn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 10px; }
.range-controls { max-width: 400px; margin: 0 auto; }
.range-inputs { display: flex; gap: 15px; justify-content: center; align-items: flex-end; }
.input-group { flex: 1; display: flex; flex-direction: column; text-align: left; }
.input-group label { font-size: 12px; color: #57606a; margin-bottom: 6px; }
input[type="number"] { background-color: #fafbfc; border: 1px solid rgba(27, 31, 35, 0.15); border-radius: 6px; padding: 6px 12px; width: 100%; height: 34px; text-align: center; font-size: 16px; }

.menu-card-rect { display: flex; align-items: center; padding: 15px; gap: 15px; background: #fff; border: 1px solid #d0d7de; border-radius: 8px; margin-bottom: 15px; text-align: left; cursor: default; }
.menu-card-rect .soft-icon { width: 60px; height: 60px; margin: 0; flex-shrink: 0; transform: scale(0.8); }
.menu-card-info h3 { margin: 0 0 5px 0; font-size: 16px; color: #24292e; }
.menu-card-info p { margin: 0; font-size: 12px; color: #57606a; }
.intro-card { background: #fff; border: 1px solid #d0d7de; border-radius: 8px; padding: 40px 20px; text-align: center; max-width: 500px; margin: 0 auto; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* --- EXAM DASHBOARD --- */
#view-exam-dashboard.full-width {
    width: 100vw; max-width: none; position: absolute; top: 0; left: 0; bottom: 0; background: var(--exam-bg); 
    padding: 10px; z-index: 150; display: none; flex-direction: column;
}
#view-exam-dashboard.active { display: flex; }
.dashboard-header { display: flex; justify-content: space-between; align-items: center; color: var(--exam-text); margin-bottom: 5px; padding: 5px 10px; height: 50px; position: relative; flex-shrink: 0; }
.dash-timer { font-size: 24px; font-weight: bold; font-family: monospace; background-color: #2da44e; color: #fff; padding: 5px 15px; border-radius: 6px; position: absolute; left: 50%; transform: translateX(-50%); }
.exam-grid-container { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr); grid-auto-flow: column; gap: 8px; padding: 5px; min-height: 0; }

.exam-card { background: var(--exam-card-bg); border-radius: 8px; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; position: relative; border: 2px solid transparent; height: 100%; }
.exam-card:hover { border-color: #4285F4; }
.exam-card.answered { opacity: 0.6; }
.exam-card-img { width: 100%; height: 60%; object-fit: cover; background: #111; }
.exam-card-body { flex-grow: 1; padding: 4px; color: #c9d1d9; font-size: 10px; line-height: 1.1; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; background: var(--exam-card-bg); }
.exam-card-img[style*="display:none"] + .exam-card-body { height: 100%; font-size: 12px; padding: 10px; }
.exam-card-num { position: absolute; top: 0; left: 0; background: #0969da; color: #fff; padding: 2px 6px; border-bottom-right-radius: 6px; font-size: 11px; font-weight: bold; z-index: 5; }
.grid-simple { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.grid-simple .exam-card { height: 160px; background: #fff; border: 1px solid #ddd; }
.grid-simple .exam-card .exam-card-body { color: #333; background: #fff; }

.question-card { background: #fff; padding: 20px; border-radius: 6px; border: 1px solid #d0d7de; text-align: center; }
.q-text { font-size:18px; font-weight:600; margin-bottom:15px; }
.q-image { max-width: 100%; border-radius: 6px; margin: 15px auto; display: block; }
.answers-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.answer-btn { width: 100%; height: auto; display: flex; align-items: flex-start; margin-bottom: 8px; text-align: left; justify-content: flex-start; }
.answer-btn.correct { background-color: var(--color-success-bg); border-color: var(--color-success-fg); color: var(--color-success-fg); }
.answer-btn.wrong { background-color: var(--color-danger-bg); border-color: var(--color-danger-fg); color: var(--color-danger-fg); }
.marathon-stats-bar { display: flex; justify-content: center; gap: 20px; margin-bottom: 15px; padding: 10px; background: #fff; border-radius: 8px; border: 1px solid #d0d7de; font-family: monospace; font-size: 16px; }
.stat-item { display: flex; flex-direction: column; align-items: center; }
.stat-val { font-size: 24px; font-weight: bold; }
.stat-label { font-size: 10px; color: #57606a; text-transform: uppercase; }
.marathon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)); gap: 5px; max-height: 150px; overflow-y: auto; padding: 5px; background: #f6f8fa; border-radius: 6px; border: 1px solid #d0d7de; margin-bottom: 20px; }
.marathon-btn { height: 30px; font-size: 10px; padding: 0; border: 1px solid #d0d7de; background: #fff; color: #57606a; }
.marathon-btn.active { border: 2px solid #0969da; }
.marathon-btn.correct { background-color: var(--color-success-bg); color: var(--color-success-fg); }
.marathon-btn.wrong { background-color: var(--color-danger-bg); color: var(--color-danger-fg); }

.pagination-container { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 20px; max-height: 120px; overflow-y: auto; padding: 5px; background: #fff; border-radius: 6px; border: 1px solid #d0d7de; }
.page-btn { width: 32px; height: 32px; padding: 0; font-size: 12px; display: flex; justify-content: center; align-items: center; }
.page-btn.current { background-color: #edeff2; font-weight: bold; border-color: #24292e; }

.hint-block { display: none; margin-top: 20px; background: #fff8c5; border: 1px solid #d4a72c; padding: 15px; border-radius: 6px; text-align: left; }
.hint-block.visible { display: block; }
.nav-controls { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; position: sticky; bottom: 0; background: rgba(255,255,255,0.95); border-top: 1px solid #eee; padding: 15px; z-index: 10; margin-left: -20px; margin-right: -20px; margin-bottom: -20px; border-radius: 0 0 6px 6px; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-content.dark-modal { background: var(--modal-dark-bg); color: #c9d1d9; border: 1px solid #30363d; box-shadow: 0 0 20px rgba(0,0,0,0.5); width: 95%; max-width: 800px; border-radius: 8px; overflow: hidden; max-height: 90vh; display: flex; flex-direction: column; }
.result-modal-content.dark-modal h2 { color: #fff; }
#exam-modal-question { padding: 20px; overflow-y: auto; font-size: 16px; flex: 1; text-align: center; }
.dark-footer { padding: 15px; background: #161b22; border-top: 1px solid #30363d; display: flex; justify-content: space-between; align-items: center; color: #8b949e; }


/* ========================================= */
/* --- 2. MOBILE ADAPTATIONS (MAX 800PX) --- */
/* ========================================= */

@media (max-width: 800px) {
    /* 2.0. PROFESSIONAL BACKGROUND FIX */
    body {
        /* Принудительно включаем картинку, перезаписывая любые 'none' */
        background-image: url('colors.png'); 
        
        /* 'scroll' - картинка скроллится вместе с контентом (нет дерганий на iOS) */
        background-attachment: scroll; 
        
        /* 'cover' - заполняет весь экран, обрезая лишнее, но сохраняя пропорции */
        background-size: cover; 
        
        background-position: center center;
        background-repeat: no-repeat;
    }

    /* 2.1 Header & Nav */
    header { height: 60px; padding: 0 10px; justify-content: space-between; }
    .header-inner { justify-content: space-between; }
    .nav-bar { width: calc(100% - 70px); justify-content: flex-start; margin: 0; padding-right: 10px; overflow-x: auto; scrollbar-width: none; }
    .nav-bar::-webkit-scrollbar { display: none; }
    #header-username { display: none; }
    
    /* 2.2 Layout & Containers */
    .container { padding-bottom: 70px; }
    
    /* 2.3 Exam Grid (Fix for Mobile Performance) */
    .exam-grid-container { 
        display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); 
        grid-template-rows: auto; grid-auto-flow: row; /* Обычный поток, не колонки */
        overflow-y: auto; 
    }
    .exam-card { height: 100px; } /* Фикс высота для мобилок */

    /* 2.4 Modals (Bottom Sheet style) */
    .modal-overlay { align-items: flex-end; }
    .modal-content.dark-modal { 
        width: 100%; border-radius: 16px 16px 0 0; 
        max-height: 90vh; 
        max-width: none; 
    }
    .modal-footer { padding-bottom: 25px; } /* Учет Safe Area iPhone */

    /* 2.5 Touch Improvements */
    button { padding: 12px 16px; touch-action: manipulation; }
    .answer-btn { padding: 15px; font-size: 15px; }
    .nav-controls { padding-bottom: 20px; }
    
    /* 2.6 Pagination scroll */
    .pagination-container { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; }
}
