/* --- Reset & Basic Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Baloo 2', cursive, sans-serif;
    background-color: #f0f9ff;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

/* --- ВАЖЛИВО: Стилізація екрану завантаження (для динамічного створення JS) --- */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #87CEEB; /* Світло-блакитний фон */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: #fff;
    text-align: center;
    padding: 20px;
    /* Додамо плавний перехід для зникнення, якщо потрібно */
    /* transition: opacity 0.5s ease-out; */
}

/* Стилізація елементів, які JS додасть до #loading-screen */
#loading-screen h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    color: #FFD700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

#loading-screen img {
    /* Стиль для зображення, якщо ви вкажете src в JS */
    /* Приклад: */
    /* content: url('path/to/your/loading-image.gif'); */
    max-width: 60%;
    max-height: 40%;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    /* Якщо JS не встановлює src, цей стиль не відобразить img */
     /* Заглушка, якщо JS не вставить img */
    background-color: #eee;
    min-height: 150px;
    display: block; /* Щоб розміри працювали */

}

#loading-screen p {
    font-size: 0.9em;
    margin-top: 5px;
}


/* --- Головний контейнер --- */
.container {
    background-color: #ffffff;
    padding: 25px 40px;
    border-radius: 25px;
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.15);
    max-width: 900px;
    width: 100%;
    text-align: center;
    /* ВАЖЛИВО: Спочатку прихований */
    visibility: hidden;
    position: relative;
}

/* --- Заголовки --- */
h1 {
    color: #007bff;
    margin-bottom: 30px;
    font-size: 2.8em;
}

h2 {
    color: #fd7e14;
    margin-top: 40px;
    margin-bottom: 20px;
    font-size: 1.8em;
}

h3 {
    color: #198754;
    margin-bottom: 15px;
    font-size: 1.5em;
}

/* --- Секція інструкцій --- */
#toggleGuide {
    position: absolute;
    top: 25px;
    right: 30px;
    background-color: #ffc107;
    color: #333;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.8em;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s, transform 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

#toggleGuide:hover {
    background-color: #e0a800;
    transform: scale(1.1);
}

#guide {
    background-color: #fffbea;
    padding: 20px;
    border-radius: 15px;
    border: 2px dashed #ffc107;
    margin-top: 15px;
    margin-bottom: 30px;
    text-align: left;
    font-size: 0.95em;
}
#guide h4 { color: #0d6efd; margin-top: 15px; margin-bottom: 5px; font-size: 1.2em; }
#guide h5 { color: #6f42c1; margin-top: 10px; margin-bottom: 5px; font-size: 1.1em; }
#guide ul { list-style: none; padding-left: 20px; }
#guide li { margin-bottom: 8px; }
#guide b { color: #dc3545; }

.hidden {
    display: none;
}

/* --- Секція налаштувань --- */
.settings {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center; /* Змінено для кращого вирівнювання */
    gap: 25px;
    margin-bottom: 40px;
    background-color: #e7f5ff;
    padding: 20px;
    border-radius: 15px;
}

.setting-item {
    display: flex;
     /* Змінено на row для вирівнювання мітки та select */
    flex-direction: row;
    align-items: center;
    gap: 10px; /* Проміжок між міткою та select */
}

.settings label {
    font-weight: bold;
    color: #0056b3;
    font-size: 1.1em;
    margin-bottom: 0; /* Забрати нижній відступ, якщо елементи в ряд */
}

.settings select {
    padding: 10px 15px;
    border: 2px solid #007bff;
    border-radius: 10px;
    font-family: inherit;
    font-size: 1em;
    min-width: 150px;
    background-color: #fff;
    cursor: pointer;
}

/* --- Ігрова зона --- */
.game-area { /* Нова обгортка */
    border: 5px solid #20c997;
    background: linear-gradient(135deg, #e0fff0, #d1f7ff);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 40px;
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1);
}

.start-stop-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
}

.game {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.problem {
    font-size: 4em;
    font-weight: bold;
    color: #6f42c1;
    margin-bottom: 10px;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 10px 25px;
    border-radius: 15px;
    min-height: 80px;
    display: inline-block;
}

.timer {
    font-size: 1.4em;
    color: #dc3545;
    font-weight: bold;
}

.answer {
    padding: 15px;
    border: 3px solid #6f42c1;
    border-radius: 15px;
    font-size: 2em;
    width: 200px;
    max-width: 80%;
    text-align: center;
    font-family: inherit;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.answer::placeholder { color: #aaa; font-size: 0.8em; }
.answer:focus { outline: none; border-color: #fd7e14; box-shadow: 0 0 10px rgba(253, 126, 20, 0.5); }
.answer:disabled { background-color: #f8f9fa; cursor: not-allowed; } /* Стиль для стану disabled */

.result {
    font-size: 1.5em;
    font-weight: bold;
    min-height: 30px;
    margin-top: 10px;
}

/* --- Кнопки --- */
button {
    font-family: inherit;
    padding: 15px 30px;
    border: none;
    border-radius: 15px;
    font-size: 1.3em;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}
button:hover { transform: translateY(-3px); box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2); }
button:active { transform: translateY(1px); box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15); }

#start { background-color: #28a745; }
#start:hover { background-color: #218838; }

#stop { background-color: #dc3545; }
#stop:hover { background-color: #c82333; }

#check { background-color: #007bff; }
#check:hover { background-color: #0056b3; }

#clearHistory { background-color: #fd7e14; margin-top: 20px; }
#clearHistory:hover { background-color: #e66b0a; }

button:disabled {
    background-color: #adb5bd;
    color: #6c757d;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    text-shadow: none;
}

/* --- Секція статистики --- */
.stats {
    background-color: #fff3cd;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 40px;
    border: 2px solid #ffc107;
}
.stats h3 { color: #856404; margin-bottom: 15px; }
.stats p { font-size: 1.2em; color: #555; }
.stats span { font-weight: bold; color: #0d6efd; }
#percentage { color: #198754; }
#averageTime { margin-top: 10px; color: #6c757d; }

/* --- Секція діаграм та історії --- */
.charts-history {
    background-color: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
    margin-top: 30px;
}
.digit-filter {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    font-size: 0.9em;
}
.digit-filter label { cursor: pointer; margin-left: 5px; }
.digit-filter input[type="checkbox"] { cursor: pointer; width: 15px; height: 15px; vertical-align: middle; }

canvas {
    max-width: 100%;
    margin-bottom: 30px;
    background-color: #fff;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}
.history-table-container { overflow-x: auto; }
#history {
    width: 100%;
    border-collapse: collapse;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    font-size: 0.9em;
}
#history th, #history td { padding: 12px 15px; text-align: center; border: 1px solid #dee2e6; }
#history th { background-color: #0dcaf0; color: white; font-weight: bold; text-transform: uppercase; }
#history tr:nth-child(even) { background-color: #e9ecef; }
#history tr:hover { background-color: #d1ecf1; }

/* --- Footer --- */
footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    font-size: 0.85em;
    color: #6c757d;
}

/* --- Адаптивний дизайн --- */
@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 20px; }
    h1 { font-size: 2.2em; }
    h2 { font-size: 1.5em; }
    .problem { font-size: 3em; }
    .answer { font-size: 1.8em; width: 150px; }
    button { padding: 12px 20px; font-size: 1.1em; }
    .settings { gap: 15px; padding: 15px; }
    .settings label { font-size: 1em; }
    .settings select { padding: 8px 10px; font-size: 0.9em; min-width: 120px; }
    #toggleGuide { width: 40px; height: 40px; font-size: 1.5em; top: 15px; right: 15px; }
    #history th, #history td { padding: 8px 10px; }
    .setting-item { flex-direction: column; align-items: center; /* Повертаємо до стовпчика на менших екранах */ gap: 5px; }
    .settings label { margin-bottom: 5px; } /* Додаємо відступ знизу для міток */
}

@media (max-width: 480px) {
    h1 { font-size: 1.8em; }
    .problem { font-size: 2.5em; }
    .answer { font-size: 1.5em; }
    button { padding: 10px 15px; font-size: 1em; }
     .start-stop-buttons { flex-direction: column; gap: 10px; align-items: center; }
    .stats p { font-size: 1em; }
     #history { font-size: 0.8em; }
}