/* Базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    text-align: center;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-bottom: 60px; /* Учитываем нижнюю панель Telegram */
}

/* Светлая тема (по умолчанию) */
body.light-theme {
    background-color: #ffffff;
    color: #000000;
}

/* Тёмная тема */
body.dark-theme {
    background-color: #1a1a1a;
    color: #ffffff;
}

/* Анимации */
@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

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

@keyframes buttonHover {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
    100% { transform: translateX(0); }
}

/* Применение анимаций к экранам */
#main-menu,
#difficulty-screen,
#waiting-screen,
#game-screen,
#stats-screen {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Заголовки */
h1, h2, h3 {
    margin: 10px 0;
}

h1 {
    font-size: 1.8rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.2rem;
}

/* Кнопки */
button {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s ease;
    width: 80%;
    max-width: 300px;
    margin: 10px auto;
    display: block;
}

button:hover {
    animation: buttonHover 0.2s ease forwards;
}

/* Стили для кнопок в светлой теме */
body.light-theme button {
    background-color: #0088cc;
    color: #ffffff;
}

body.light-theme button:hover {
    background-color: #006699;
}

/* Стили для кнопок в тёмной теме */
body.dark-theme button {
    background-color: #40c4ff;
    color: #000000;
}

body.dark-theme button:hover {
    background-color: #0288d1;
}

/* Кнопка "Назад" или "Отменить" */
#exit-to-menu,
#cancel-match,
#back-to-menu-from-difficulty,
#back-to-menu-from-stats {
    background-color: #ff4d4d;
    color: #ffffff;
}

#exit-to-menu:hover,
#cancel-match:hover,
#back-to-menu-from-difficulty:hover,
#back-to-menu-from-stats:hover {
    background-color: #e60000;
}

/* Поле ввода ника */
#nickname {
    width: 80%;
    max-width: 300px;
    padding: 10px;
    margin: 10px auto;
    border-radius: 10px;
    border: 1px solid #ccc;
    font-size: 1rem;
    display: block;
}

body.dark-theme #nickname {
    background-color: #333;
    color: #fff;
    border-color: #555;
}

/* Главное меню */
#main-menu {
    padding: 20px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Кнопка переключения темы */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    width: auto;
    margin: 0;
}

body.light-theme .theme-toggle {
    color: #000000;
}

body.dark-theme .theme-toggle {
    color: #ffffff;
}

/* Экран выбора сложности */
#difficulty-screen {
    padding: 20px;
}

#easy-mode {
    background-color: #4CAF50;
}

#easy-mode:hover {
    background-color: #45a049;
}

#medium-mode {
    background-color: #FFC107;
}

#medium-mode:hover {
    background-color: #e6b800;
}

#hard-mode {
    background-color: #F44336;
}

#hard-mode:hover {
    background-color: #d32f2f;
}

/* Экран ожидания */
#waiting-screen {
    padding: 20px;
    position: relative;
}

.waiting-animation {
    width: 40px;
    height: 40px;
    border: 4px solid transparent;
    border-top-color: #0088cc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

body.dark-theme .waiting-animation {
    border-top-color: #40c4ff;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Игровое поле */
#game-screen {
    padding: 20px;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    width: 90%;
    max-width: 300px;
    margin: 20px auto;
}

#game-board.winner {
    animation: shake 0.5s ease;
}

.cell {
    aspect-ratio: 1 / 1; /* Делаем клетки квадратными */
    background-color: #f0f0f0;
    border-radius: 10px;
    cursor: pointer;
    font-size: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.cell span {
    animation: scaleIn 0.3s ease forwards;
}

body.dark-theme .cell {
    background-color: #333;
}

.cell:hover {
    background-color: #e0e0e0;
}

body.dark-theme .cell:hover {
    background-color: #444;
}

/* Экран рейтинга и достижений */
#stats-screen {
    padding: 20px;
}

#leaderboard, #achievements {
    margin: 20px 0;
}

#leaderboard-table {
    width: 90%;
    max-width: 350px;
    margin: 0 auto;
    border-collapse: collapse;
}

#leaderboard-table th, #leaderboard-table td {
    padding: 8px;
    border: 1px solid #ccc;
    font-size: 0.9rem;
}

body.dark-theme #leaderboard-table th,
body.dark-theme #leaderboard-table td {
    border-color: #555;
}

#achievements-list {
    list-style: none;
    padding: 0;
}

#achievements-list li {
    padding: 10px;
    background-color: #f0f0f0;
    margin: 5px 0;
    border-radius: 10px;
    font-size: 0.9rem;
}

body.dark-theme #achievements-list li {
    background-color: #333;
}