* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html, body {
    overflow: hidden;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: contain;
}

body {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 20px;
    /* overscroll-behavior-y: none;
    overscroll-behavior-x: none; */
}

#game-screen {
    overscroll-behavior: none;
}

.container {
    width: 900px;
    height: calc(100vh - 5vh);
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    position: relative;
}

.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    transition: transform 0.5s ease, opacity 0.5s ease;
    overflow: hidden;
}

.hidden {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
}

h1 {
    font-size: 3.5rem;
    margin-bottom: 20px;
    text-align: center;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    line-height: 1.2;
}

h2 {
    font-size: 2rem;
    margin-bottom: 15px;
    color: #4ecdc4;
    text-align: center;
}

h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #4ecdc4;
}

.btn {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    border: none;
    color: white;
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    margin: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 250px;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(1px);
}

/* Главное меню */
#main-menu {
    text-align: center;
    gap: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    font-size: 5rem;
    margin-bottom: 10px;
    position: relative;
    width: 120px;
    height: 120px;
    display: flex;
    justify-content: center;
    margin-bottom: 120px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 280px;
    gap: 10px;
    align-items: center;
}

#main-menu p {
    font-size: 1.1rem;
    color: #aaa;
    margin-bottom: 10px;
    text-align: center;
}

/* Кнопка таблицы лидеров - делаем такой же как кнопки режимов */
#leaderboard-btn {
    background: transparent;
    border: 2px solid #4ecdc4;
    color: white;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    margin: 5px;
    transition: all 0.3s ease;
    text-align: center;
    width: 100%;
    max-width: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    font-weight: 600;
}

#leaderboard-btn:hover {
    background: rgba(78, 205, 196, 0.1);
    transform: translateY(-2px);
}

/* Кнопки выбора режима */
.mode-selection {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 280px;
    margin-bottom: 20px;
    align-items: center;
}

.mode-btn {
    background: transparent;
    border: 2px solid #4ecdc4;
    color: white;
    padding: 15px 30px;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    margin: 5px;
    transition: all 0.3s ease;
    text-align: center;
    width: 100%;
    max-width: 250px;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.mode-btn:hover {
    background: rgba(78, 205, 196, 0.1);
    transform: translateY(-2px);
}

.mode-description {
    font-size: 0.9rem;
    color: #aaa;
    text-align: center;
    margin-top: 5px;
}

.mode-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

/* Делаем кнопки визуально одинаковыми */
#leaderboard-btn, .mode-btn {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 2px solid #4ecdc4;
    background: transparent;
    color: #fff;
    position: relative;
    overflow: hidden;
}

#leaderboard-btn::before, .mode-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.5s;
}

#leaderboard-btn:hover::before, .mode-btn:hover::before {
    left: 100%;
}

#leaderboard-btn:active, .mode-btn:active {
    transform: translateY(0) scale(0.98);
}

/* Игровой экран - улучшенная компоновка */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin-bottom: 20px;
    padding: 0 10px;
}

.game-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.stat-label {
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #4ecdc4;
}

/* Основной layout игры */
.game-layout {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    gap: 30px;
    width: 100%;
    max-width: 900px;
    align-items: start;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.center-panel {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.game-board-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
}

.game-board {
    width: 300px;
    height: 520px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    display: grid;
    grid-template-rows: repeat(20, 1fr);
    grid-template-columns: repeat(10, 1fr);
    gap: 1px;
    padding: 10px;
}

.cell {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    will-change: transform, background-color;
}

.filled {
    background: #4ecdc4;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.2);
    transform: translateZ(0); /* Аппаратное ускорение */
}

.filled.I { background: #00cec9; }
.filled.J { background: #0984e3; }
.filled.L { background: #fdcb6e; }
.filled.O { background: #e17055; }
.filled.S { background: #00b894; }
.filled.T { background: #6c5ce7; }
.filled.Z { background: #e84393; }
.filled.l { background: #c0392b; }
.filled.C { background: #bdc3c7; }

/* Стили для панелей */
.panel-section {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.panel-section h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #4ecdc4;
    font-size: 1.1rem;
}

/* Контейнер следующей фигуры - всегда отображается */
.next-section {
    display: flex !important;
    flex-direction: column;
}

.next-piece-container {
    display: flex !important;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    width: 100%;
}

.next-piece {
    display: grid !important;
    grid-template-rows: repeat(4, 1fr);
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    width: 80px;
    height: 80px;
    min-width: 50px;
    min-height: 50px;
    max-width: 100px;
    max-height: 100px;
}

/* Управление */
.controls-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.control-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.key {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9rem;
    min-width: 60px;
    text-align: center;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.action {
    color: #fff;
    font-size: 0.9rem;
    flex: 1;
}

/* Подсказки */
.hints {
    color: #aaa;
    font-size: 0.85rem;
    line-height: 1.5;
}

.hints p {
    margin: 8px 0;
    position: relative;
    padding-left: 15px;
}

.hints p::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 4px;
    height: 4px;
    background: #4ecdc4;
    border-radius: 50%;
}

/* Таблица лидеров */
#leaderboard {
    text-align: center;
    justify-content: flex-start;
    padding-top: 40px;
}

.leaderboard-list {
    width: 100%;
    max-width: 500px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
    height: 450px;
    min-height: 450px;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: relative;
}

.leaderboard-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: contain;
}

/* Контейнер для записей с скроллом */
.leaderboard-entries {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 5px;
    padding-left: 5px;
    padding-top: 5px;
    margin-right: -5px;
}

/* Элемент таблицы лидеров - исправленная анимация */
.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    margin: 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    transition: all 0.3s ease;
    font-size: 1rem;
    min-height: 60px;
    position: relative;
    transform: translateX(0);
    border: 1px solid transparent;
    box-sizing: border-box;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Вариант с увеличением */
.leaderboard-item.scale-hover:hover {
    transform: scale(1.02);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    z-index: 1;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    z-index: 1;
}

/* Улучшение скроллбара для контейнера записей */
.leaderboard-entries::-webkit-scrollbar {
    width: 6px;
}

.leaderboard-entries::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.leaderboard-entries::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    border-radius: 3px;
}

.leaderboard-entries::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #ff5252, #00b894);
}

/* Для Firefox */
.leaderboard-entries {
    scrollbar-width: thin;
    scrollbar-color: #4ecdc4 rgba(255, 255, 255, 0.05);
}

.leaderboard-rank {
    font-weight: bold;
    color: #ff6b6b;
    font-size: 1.1rem;
    min-width: 40px;
}

.leaderboard-score {
    font-weight: bold;
    color: #4ecdc4;
    font-size: 1.2rem;
}

/* Сообщение когда нет результатов */
.leaderboard-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    flex-direction: column;
    color: #aaa;
    padding: 40px 20px;
    flex: 1;
}

.leaderboard-empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.leaderboard-empty-text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.leaderboard-empty-subtext {
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fadeIn 0.5s ease;
}

/* Вкладки таблицы лидеров */
.leaderboard-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 500px;
    justify-content: center;
    flex-shrink: 0;
}

.tab-btn {
    background: transparent;
    border: 2px solid #4ecdc4;
    color: white;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    max-width: 200px;
}

.tab-btn:hover {
    background: rgba(78, 205, 196, 0.1);
}

.tab-btn.active {
    background: #4ecdc4;
    color: #1a1a2e;
    font-weight: bold;
}

.tab-content {
    display: none;
    width: 100%;
    height: 100%;
    overflow-y: auto;    
    overscroll-behavior-y: contain;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Помехи в усложненном режиме */
.obstacle {
    background: #ff4757 !important;
    position: relative;
    overflow: hidden;
}

.obstacle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
    animation: shine 2s infinite;
}

@keyframes shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Кнопка меню с иконкой */
.btn-menu-icon {
    background: transparent;
    border: 2px solid #ff6b6b;
    color: #ff6b6b;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.btn-menu-icon:hover {
    background: rgba(255, 107, 107, 0.1);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 18px rgba(255, 107, 107, 0.4);
}

.btn-menu-icon:active {
    transform: translateY(0) scale(0.95);
}

/* Модальное окно меню */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.1);
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: modalAppear 0.3s ease;
}

.icon27 {
    display: inline-block;
    width: 27px;
    height: 27px;
    text-align: center;
    line-height: 27px;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    margin-bottom: 30px;
    color: #4ecdc4;
    font-size: 2rem;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-btn {
    background: transparent;
    border: 2px solid #4ecdc4;
    color: white;
    padding: 15px 25px;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.modal-btn:hover {
    background: rgba(78, 205, 196, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.modal-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.3rem;
}

.btn-main-menu {
    border-color: #ff6b6b;
    color: #ff6b6b;
}

.btn-main-menu:hover {
    background: rgba(255, 107, 107, 0.1);
}

.btn-restart {
    border-color: #fdcb6e;
    color: #fdcb6e;
}

.btn-restart:hover {
    background: rgba(253, 203, 110, 0.1);
}

.btn-resume {
    border-color: #00b894;
    color: #00b894;
}

.btn-resume:hover {
    background: rgba(0, 184, 148, 0.1);
}

@keyframes lineClear {
    0% { background-color: white; }
    50% { background-color: #4ecdc4; }
    100% { background-color: inherit; }
}

.line-clearing {
    animation: lineClear 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@media (max-width: 870px) {
    .panel-section h3 {
        font-size: 0.8rem;
        margin-bottom: 8px;
    }

    .hints p {
        font-size: 0.7rem;
        line-height: 1.3;
        margin: 4px 0;
        padding-left: 10px;
    }

    .game-layout {
        grid-template-columns: 1fr auto 1fr !important;
        grid-template-rows: 1fr;
        gap: 10px;
        width: 100%;
        height: calc(100vh - 100px);
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
        overflow: hidden;
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        height: 100vh;
        width: 100%;
    }
    
    .container {
        width: 100%;
        height: 100vh;
        border-radius: 15px;
        overflow: hidden;
    }
    
    .screen {
        position: absolute;
        width: 100%;
        height: 100%;
        padding: 15px;
        overflow: hidden;
    }
    
    h1 {
        font-size: 2.2rem;
        margin-bottom: 15px;
    }
    
    /* Главное меню для мобильных */
    #main-menu {
        gap: 15px;
        justify-content: center;
        padding-top: 20px;
    }
    
    .logo {
        margin-bottom: 50px;
        transform: scale(0.8);
    }
    
    .menu-buttons {
        max-width: 260px;
    }
    
    .mode-selection {
        max-width: 260px;
        margin-bottom: 15px;
    }
    
    #leaderboard-btn,
    .mode-btn {
        max-width: 240px;
        padding: 12px 25px;
        font-size: 1rem;
        min-height: 55px;
    }
    
    /* Игровой экран для мобильных */
    .game-header {
        position: relative;
        padding: 0 10px;
    }

    .mobile-next-piece {
        position: absolute;
        right: 60px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .game-stats {
        width: 100%;
        justify-content: space-between;
        gap: 5px;
    }
    
    .stat-item {
        flex: 1;
        min-width: 0;
    }
    
    .stat-label {
        font-size: 0.65rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .mode-display {
        display: none;
    }
    
    .btn-menu-icon {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
        flex-shrink: 0;
    }
    
    .game-layout {
        grid-template-columns: 1fr auto 1fr !important;
        grid-template-rows: 1fr;
        gap: 10px;
        width: 100%;
        height: calc(100vh - 100px);
    }
    
    .side-panel {
        display: flex;
        flex-direction: column;
        gap: 10px;
        max-width: 120px;
    }
    
    .center-panel {
        order: 2;
        position: relative;
        display: flex;
        justify-content: center;
        height: 100%;
    }
    
    .game-board-container {
        padding: 8px;
        margin: 0 auto;
        position: relative;
    }
    
    .game-board {
        width: 260px;
        height: 440px;
        touch-action: none;
    }
    
    /* Таблица лидеров для мобильных */
    #leaderboard {
        padding-top: 20px;
        overflow: hidden;
    }
    
    .leaderboard-list {
        max-width: 100%;
        margin: 15px 0;
        height: 400px;
        min-height: 400px;
        padding: 10px;
    }
    
    .leaderboard-entries {
        padding-right: 3px;
        padding-left: 3px;
        padding-top: 3px;
        margin-right: -3px;
    }
    
    .leaderboard-content {
        overflow: visible;
        height: auto;
        min-height: 300px;
        overscroll-behavior-y: contain;
        overscroll-behavior-x: contain;
    }
    
    .leaderboard-item {
        padding: 10px 12px;
        min-height: 45px;
        margin: 5px 0;
        font-size: 0.9rem;
    }
    
    .leaderboard-tabs {
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .tab-btn {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
    
    /* Модальное окно для мобильных */
    .modal-content {
        padding: 25px 20px;
        margin: 20px;
        width: calc(100% - 40px);
        max-width: none;
        overflow: hidden;
    }
    
    .modal-content h2 {
        font-size: 1.4rem;
        margin-bottom: 20px;
    }
    
    .modal-btn {
        padding: 12px 20px;
        font-size: 1rem;
        white-space: nowrap;
    }
    
    /* Game Over для мобильных */
    #game-over-overlay {
        border-radius: 15px;
    }
    
    .game-over-content {
        padding: 0 15px;
    }
    
    .game-over-stats {
        padding: 1rem;
        margin: 1rem 0;
    }
    
    .stat-row {
        font-size: 1rem !important;
        margin: 0.4rem 0 !important;
    }
    
    .game-over-buttons {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .hints p::before {
        width: 3px;
        height: 3px;
        top: 6px;
    }

    .right-panel{
        order: 3;
    }
    
    .control-item {
        background: rgba(255, 255, 255, 0.08);
    }
    
    .action {
        font-size: 0.7rem;
    }

    .left-panel {
        order: 1;
    }

    .center-panel {
        order: 2;
    }

    /* Адаптируем размеры боковых панелей */
    .panel-section {
        padding: 10px;
        min-height: auto;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(5px);
    }

    /* Блок следующей фигуры */
    .next-section {
        position: static !important;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 8px;
        padding: 8px;
    }

    .next-piece {
        width: 50px;
        height: 50px;
    }

    .controls-grid {
        gap: 6px;
    }

    .control-item {
        padding: 5px 8px;
        gap: 8px;
    }

    .key {
        padding: 0px 2px;
        font-size: 0.7rem;
        min-width: 20px;
    }

    .action {
        font-size: 0.7rem;
    }
}

@media (max-width: 540px) {
    
    .game-layout {
        grid-template-columns: 1fr auto !important;
        grid-template-rows: 1fr;
        gap: 5px;
        width: 100%;
        height: calc(100vh - 100px);
    }
    
    .right-panel{
        display: none !important;
    }
}

/* Для очень маленьких экранов */
@media (max-width: 480px) {
    .hints-section{
        display: none;
    }

    .side-panel {
        max-width: 100px;
    }

    .panel-section {
        padding: 6px;
    }

    .next-piece {
        width: 40px;
        height: 40px;
    }

    .mobile-next-piece {
        right: 50px;
    }

    .panel-section h3 {
        font-size: 0.7rem;
        margin-bottom: 8px;
    }


    .screen {
        position: absolute;
        width: 100%;
        height: 100%;
        padding: 5px;
        overflow: hidden;
    }
}

/* Для ландшафтной ориентации на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .game-layout {
        height: calc(100vh - 80px);
    }

    .side-panel {
        max-width: 100px;
    }

    .panel-section {
        padding: 5px;
    }

    .next-piece {
        width: 35px;
        height: 35px;
    }
}

/* Убираем компактный режим который скрывает боковые панели */
.compact-mode .side-panel {
    display: flex !important;
}

.compact-mode .game-layout {
    grid-template-columns: 1fr auto 1fr !important;
}

/* Адаптация для больших экранов */
@media (min-width: 1200px) {
    .container {
        width: 1000px;
    }
    
    .game-layout {
        grid-template-columns: 220px 1fr 220px;
        max-width: 1000px;
    }
    
    .game-board {
        width: 320px;
        height: 560px;
    }
    
    .game-header {
        max-width: 1000px;
    }
    
    .leaderboard-list {
        /* height: 500px;
        min-height: 500px; */
        max-width: 550px;
    }
}

@media (min-width: 1400px) {
    .container {
        width: 1100px;
    }
    
    .game-layout {
        grid-template-columns: 240px 1fr 240px;
        max-width: 1100px;
    }
    
    .game-board {
        width: 350px;
        height: 600px;
    }
    
    .game-header {
        max-width: 1100px;
    }
    
    .leaderboard-list {
        /* height: 550px;
        min-height: 500px; */
        max-width: 600px;
    }
}

@media (min-width: 1600px) {
    .container {
        width: 1200px;
    }
    
    .game-layout {
        grid-template-columns: 260px 1fr 260px;
        max-width: 1200px;
    }
    
    .game-board {
        width: 380px;
        height: 640px;
    }
    
    .game-header {
        max-width: 1200px;
    }
}

@media (min-width: 1920px) {
    .container {
        width: 1400px;
    }
    
    .game-layout {
        grid-template-columns: 280px 1fr 280px;
        max-width: 1400px;
    }
    
    .game-board {
        width: 420px;
        height: 700px;
    }
    
    .game-header {
        max-width: 1400px;
    }
    
    h1 {
        font-size: 4rem;
    }
    
    .btn {
        padding: 18px 45px;
        font-size: 1.3rem;
        max-width: 280px;
    }
    
    #leaderboard-btn, .mode-btn {
        font-size: 1.2rem;
        padding: 18px 35px;
        max-width: 280px;
    }
    
    .mode-title, #leaderboard-btn {
        font-size: 1.2rem;
    }
    
    .mode-description {
        font-size: 1rem;
    }
    
    .leaderboard-list {
        /* height: 600px;
        min-height: 600px; */
        max-width: 650px;
    }
}

@media (min-width: 2560px) {
    .container {
        width: 1600px;
    }
    
    .game-layout {
        grid-template-columns: 300px 1fr 300px;
        max-width: 1600px;
        gap: 40px;
    }
    
    .game-board {
        width: 450px;
        height: 750px;
    }
    
    .game-header {
        max-width: 1600px;
    }
    
    h1 {
        font-size: 4.5rem;
    }
    
    h2 {
        font-size: 2.5rem;
    }
    
    h3 {
        font-size: 1.4rem;
    }
    
    .btn {
        padding: 20px 50px;
        font-size: 1.4rem;
        max-width: 300px;
    }
    
    .stat-value {
        font-size: 1.8rem;
    }
    
    .stat-label {
        font-size: 1rem;
    }
    
    .leaderboard-list {
        /* height: 650px;
        min-height: 650px; */
        max-width: 700px;
    }
    
    .leaderboard-item {
        padding: 18px 25px;
        min-height: 70px;
        font-size: 1.1rem;
    }
    
    .leaderboard-rank {
        font-size: 1.2rem;
        min-width: 50px;
    }
    
    .leaderboard-score {
        font-size: 1.3rem;
    }
}

@media (min-width: 3840px) {
    .container {
        width: 2000px;
    }
    
    .game-layout {
        grid-template-columns: 350px 1fr 350px;
        max-width: 2000px;
        gap: 50px;
    }
    
    .game-board {
        width: 550px;
        height: 900px;
    }
    
    .game-header {
        max-width: 2000px;
    }
    
    h1 {
        font-size: 5rem;
    }
    
    h2 {
        font-size: 3rem;
    }
    
    h3 {
        font-size: 1.6rem;
    }
    
    .btn {
        padding: 25px 60px;
        font-size: 1.6rem;
        max-width: 350px;
    }
    
    .stat-value {
        font-size: 2rem;
    }
    
    .stat-label {
        font-size: 1.1rem;
    }
}

/* Адаптация для ультра-широких мониторов (2560×1080) */
@media (min-width: 2560px) and (max-height: 1080px) {
    .container {
        width: 1400px;
        height: 800px;
    }
    
    .game-layout {
        grid-template-columns: 250px 1fr 250px;
        max-width: 1400px;
    }
    
    .game-board {
        width: 400px;
        height: 650px;
    }
}

/* Адаптация для соотношения 16:10 (1920×1200, 1680×1050) */
@media (min-width: 1680px) and (max-height: 1050px),
       (min-width: 1920px) and (max-height: 1200px) {
    .container {
        height: 800px;
    }
    
    .game-board {
        height: 600px;
    }
}

/* Адаптация для очень маленьких высот (менее 550px) */
@media (max-height: 760px) { 
    body {
        padding: 5px;
        align-items: flex-start;
    }
    
    .container {
        height: 100vh;
        border-radius: 10px;
        max-height: 100vh;
    }
    
    .screen {
        padding: 3px;
        justify-content: flex-start;
        overflow-y: auto;
    }
    
    /* Главное меню для маленьких высот */
    #main-menu {
        padding-top: 10px;
        gap: 10px;
    }
    
    #main-menu h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }
    
    #main-menu p {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }
    
    .logo {
        margin-bottom: 20px;
        transform: scale(0.6);
    }
    
    .menu-buttons {
        max-width: 220px;
    }
    
    .mode-selection {
        max-width: 220px;
        margin-bottom: 10px;
    }
    
    #leaderboard-btn,
    .mode-btn {
        max-width: 200px;
        padding: 10px 20px;
        font-size: 0.9rem;
        min-height: 45px;
    }
    
    .mode-description {
        font-size: 0.8rem;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 1rem;
        margin: 4px;
    }
    
    /* Игровой экран для маленьких высот */
    .game-header {
        margin-bottom: 10px;
        height: 50px;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .btn-menu-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .game-layout {
        height: calc(100vh - 70px);
        gap: 2px;
    }
    
    .game-board-container {
        padding: 5px;
    }
    
    .game-board {
        width: 200px;
        height: 300px;
    }
    
    /* Таблица лидеров для маленьких высот */
    #leaderboard {
        padding-top: 10px;
    }
    
    #leaderboard h1 {
        font-size: 2rem;
        margin-bottom: 10px;
    }
    
    .leaderboard-list {
        max-height: calc(100vh - 140px);
        margin: 10px 0;
        padding: 10px;
        min-height: 300px;
    }
    
    .leaderboard-item {
        padding: 8px 10px;
        min-height: 40px;
        margin: 5px 0;
        font-size: 0.8rem;
    }
    
    .leaderboard-rank {
        font-size: 0.9rem;
        min-width: 30px;
    }
    
    .leaderboard-score {
        font-size: 1rem;
    }
    
    /* На мобильных убираем трансформацию чтобы не было скролла */
    .leaderboard-item:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.15);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
    
    .leaderboard-item.scale-hover:hover {
        transform: none;
    }
    
    /* Модальное окно для маленьких высот */
    .modal-content {
        padding: 15px;
        margin: 10px;
    }
    
    .modal-content h2 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }
    
    .modal-btn {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
    
    /* Game Over для маленьких высот */
    .game-over-content {
        padding: 0 10px;
        transform: scale(0.9);
    }
    
    .game-over-title {
        font-size: 1.8rem !important;
    }
    
    .game-over-stats {
        padding: 0.8rem;
        margin: 0.8rem 0;
    }
    
    .stat-row {
        font-size: 0.9rem !important;
        margin: 0.3rem 0 !important;
    }
    
    .game-over-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .game-over-buttons button {
        padding: 8px 15px;
        font-size: 0.9rem;
    }
}

@media (max-height: 480px) {
    .game-over-icon{
        display: none;
    }

    #leaderboard
    {
        padding-top: 0px;
    } 
    .leaderboard-tabs {
        margin-bottom: 2px;
    }

    .tab-btn {
        padding: 2px 20px;
    }

    #leaderboard h1 {
        font-size: 1.5rem;
        margin-bottom: 3px;
    }
}

/* Для экстремально маленьких высот (менее 450px) */
@media (max-height: 450px) {
    .container {
        border-radius: 5px;
    }
    
    .screen {
        padding: 5px;
    }
    
    #main-menu h1 {
        font-size: 1.5rem;
    }
    
    .logo {
        display: none;
    }
    
    #leaderboard-btn,
    .mode-btn {
        max-width: 180px;
        padding: 8px 15px;
        font-size: 0.85rem;
        min-height: 40px;
    }
    
    .mode-description {
        font-size: 0.75rem;
    }
    
    .game-board {
        width: 180px;
        height: 250px;
    }
    
    .game-header {
        height: 40px;
        margin-bottom: 5px;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
    
    .leaderboard-list {
        min-height: 250px;
        max-height:calc(100vh - 140px);
    }
    
    .leaderboard-item {
        padding: 6px 8px;
        min-height: 35px;
        font-size: 0.75rem;
    }
}

/* Компактный режим для игры */
.compact-mode .side-panel {
    display: flex !important;
}

.compact-mode .game-layout {
    grid-template-columns: 1fr auto 1fr !important;
    justify-items: center;
}

.compact-mode .game-board {
    width: 180px;
    height: 280px;
}

/* Улучшения для touch элементов на маленьких экранах */
@media (max-height: 550px) {
    .btn, .modal-btn, .mode-btn {
        min-height: 20px;
        touch-action: manipulation;
        padding: 1px 20px;
        margin: 2px;
    }
    
    .cell {
        min-width: 3px;
        min-height: 3px;
    }
    
    /* Улучшаем читаемость текста */
    .stat-value, .leaderboard-score {
        font-weight: bold;
        text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    }
}

/* Предотвращение слишком мелкого текста */
@media (max-height: 550px) {
    body {
        font-size: 14px;
    }
    
    .stat-label, .leaderboard-rank {
        font-size: 0.7rem;
    }
}

/* Оптимизация для портретной ориентации с маленькой высотой */
@media (max-height: 550px) and (orientation: portrait) {
    .game-board {
        width: 220px;
        height: 320px;
    }
    
    .game-stats {
        width: 100%;
        justify-content: space-around;
    }
}

/* Улучшение читаемости на очень больших экранах */
@media (min-width: 1920px) {
    body {
        font-size: 18px;
    }
    
    .game-board-container {
        padding: 20px;
    }
    
    .panel-section {
        padding: 25px;
    }
    
    .controls-grid {
        gap: 15px;
    }
    
    .control-item {
        padding: 12px 15px;
    }
    
    .key {
        padding: 8px 15px;
        font-size: 1rem;
        min-width: 70px;
    }
    
    .action {
        font-size: 1rem;
    }
}

/* Предотвращение слишком маленьких элементов на огромных экранах */
@media (min-width: 3000px) {
    .cell {
        min-width: 4px;
        min-height: 4px;
    }
    
    .btn {
        min-width: 200px;
    }
}

.logo-text {
    font-size: 4rem;
    font-weight: bold;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #6c5ce7);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Гарантируем что контейнеры не создают скролл */
.container, .screen, #main-menu, #game-screen {
    overflow: hidden !important;
}

/* Только таблица лидеров может иметь скролл */
.leaderboard-list {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
}

/* Улучшаем скроллбар для таблицы лидеров */
.leaderboard-list::-webkit-scrollbar {
    width: 4px;
    display: block !important;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    border-radius: 2px;
}

.leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #ff5252, #00b894);
}

/* Для Firefox */
.leaderboard-list {
    scrollbar-width: thin;
    scrollbar-color: #4ecdc4 rgba(255, 255, 255, 0.1);
}

/* Адаптация вкладок для мобильных */
@media (max-width: 480px) {
    .leaderboard-tabs {
        flex-direction: column;
        align-items: center;
    }
    
    .tab-btn {
        width: 100%;
        max-width: 250px;
    }
    
    .leaderboard-list {
        /* max-height: 400px; */
        padding: 15px;
    }
    
    .leaderboard-item {
        padding: 12px 15px;
        min-height: 50px;
    }
}

@media (max-height: 510px) and (min-width: 870px) {
    .hints-section{
        display: none;
    }
}

@media (max-height: 544px) {
    .logo {
        display: none !important;
    }
}

/* Гарантируем что контейнер всегда имеет правильную высоту */
.leaderboard-list:has(.leaderboard-empty) {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Улучшение скролла для контейнера с записями */
.leaderboard-content > div:first-child:not(.leaderboard-empty) {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior-y: contain;
    overscroll-behavior-x: contain;
}

/* Предотвращение слишком маленькой высоты */
.leaderboard-list {
    min-height: 50px !important;
}

/* Предотвращение любых горизонтальных скроллов */
.leaderboard-list * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Улучшение для очень длинных имен */
.leaderboard-item > div:first-child {
    min-width: 0;
    flex: 1;
}

.leaderboard-item .leaderboard-rank {
    flex-shrink: 0;
}

.leaderboard-item .leaderboard-score {
    flex-shrink: 0;
    margin-left: 10px;
}

.leaderboard-item[data-source="yandex"] {
    border-left: 3px solid #ffcc00;
}

.leaderboard-item[data-source="local"] {
    border-left: 3px solid #4ecdc4;
}

/* Индикаторы источников */
.source-badge {
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
}

.source-yandex {
    background: rgba(255, 204, 0, 0.2);
    color: #ffcc00;
}

.source-local {
    background: rgba(78, 205, 196, 0.2);
    color: #4ecdc4;
}

.modal-btn-div {
    background: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 160px
}