@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700;800&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Montserrat', sans-serif; }

body {
    background: linear-gradient(135deg, #09102b, #11347a);
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Glassmorphism Effect */
.glass {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
}

.btn {
    background: linear-gradient(90deg, #42b2ff, #6b4cff);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(66, 178, 255, 0.5);
}

/* Screens Management */
.screen { display: none; min-height: 100vh; padding: 20px; }
.screen.active { display: flex; flex-direction: column; }

/* Login */
#login-screen { justify-content: center; align-items: center; }
.login-box { padding: 40px; width: 100%; max-width: 400px; text-align: center; }
.main-logo { width: 80px; margin-bottom: 10px; }
.login-box h2 { font-weight: 800; font-size: 24px; margin-bottom: 5px; }
.login-box p { font-size: 12px; color: #a0a5b5; margin-bottom: 30px; text-transform: uppercase; letter-spacing: 1px; }
.login-box input {
    width: 100%; padding: 15px; margin-bottom: 15px;
    border-radius: 8px; border: none;
    background: #f0f4f8; color: #333; font-weight: 600;
}
.login-footer { margin-top: 20px; font-size: 10px !important; }

/* Header Styles */
header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 30px; margin-bottom: 30px; width: 100%;
}
.header-left { display: flex; align-items: center; gap: 15px; }
.header-logo { height: 40px; }
.user-greeting { font-weight: 700; font-size: 18px; }
.user-sub { font-size: 12px; color: #a0a5b5; }
.header-right { display: flex; align-items: center; gap: 20px; font-weight: 700; }
.header-right a { color: #42b2ff; text-decoration: none; cursor: pointer; }
.stat { display: flex; align-items: center; gap: 8px; }

/* Game Layout */
.game-container {
    display: grid;
    grid-template-columns: 250px auto 250px;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
    flex-grow: 1;
}

.panel-group { display: flex; flex-direction: column; gap: 20px; }
.stat-box { padding: 20px; text-align: center; }
.stat-box span { display: block; font-size: 11px; color: #a0a5b5; font-weight: 700; margin-bottom: 5px; }
.stat-box strong { font-size: 32px; font-weight: 800; }

.tetris-wrapper {
    background: #f4f7fb;
    border-radius: 15px;
    position: relative;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
    min-height: 600px;
}
canvas { display: block; border-radius: 5px; }
#tetris-canvas { background: #e0e6ed; }

.play-overlay {
    position: absolute; width: 100%; height: 100%;
    background: rgba(244, 247, 251, 0.85);
    display: flex; justify-content: center; align-items: center;
    z-index: 10; border-radius: 15px;
}

/* Leaderboard */
/* Leaderboard */
.leaderboard { 
    padding: 30px 25px 20px 25px; /* 30px зверху, 25px по боках, 20px знизу */
}
.leaderboard h3 { 
    font-size: 12px; 
    color: #a0a5b5; 
    text-align: center; 
    margin-bottom: 15px; 
}
.player-row { 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 10px; 
    font-weight: 600; 
    font-size: 14px; 
    align-items: center; 
}
.player-row { display: flex; justify-content: space-between; margin-bottom: 10px; font-weight: 600; font-size: 14px; align-items: center; }
.rank { 
    width: 22px; height: 22px; border-radius: 50%; 
    display: inline-flex; justify-content: center; align-items: center;
    font-size: 11px; margin-right: 8px; background: rgba(255,255,255,0.1);
}
.rank-1 { background: #ffd700; color: #000; }
.rank-2 { background: #c0c0c0; color: #000; }
.rank-3 { background: #cd7f32; color: #000; }

/* Boosts */
.boosts-grid { display: flex; gap: 10px; margin-top: 10px; }
.boost-item {
    width: 50px; height: 50px; border-radius: 10px;
    display: flex; justify-content: center; align-items: center;
    font-weight: 800; font-size: 20px; cursor: pointer; transition: 0.2s;
}
.boost-item:hover { background: rgba(66, 178, 255, 0.3); transform: translateY(-3px); }

/* Shop */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; max-width: 1000px; margin: 0 auto; }
.shop-card { padding: 30px 20px; text-align: center; }
.shop-icon { width: 60px; height: 60px; background: rgba(0,0,0,0.2); border-radius: 12px; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; font-size: 24px; font-weight: 800; }
.shop-card h4 { font-size: 24px; color: #ffca28; margin-bottom: 15px; }
/* НОВЕ: Стилі для управління та лічильників бустів */
.controls-box {
    text-align: left !important;
}
.controls-list {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.controls-list p {
    font-size: 13px;
    font-weight: 600;
    color: #e0e6ed;
}

.boost-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}
.boost-count {
    font-size: 14px;
    font-weight: 800;
    color: #ffca28; /* Золотий колір для відображення кількості */
}
/* НОВЕ: Масштабування картинок всередині кнопок бустів та магазину */
.boost-item img {
    width: 65%; /* Розмір іконки відносно квадрата */
    height: auto;
    object-fit: contain;
    pointer-events: none; /* Щоб клік мишкою точно спрацьовував на кнопку, а не губився на картинці */
}

.shop-icon img {
    width: 60%; 
    height: auto;
    object-fit: contain;
}
/* НОВЕ: Кастомне модальне вікно */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(9, 16, 43, 0.8); /* Темне перекриття фону */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none; /* Щоб не заважало клікати, коли сховане */
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
    /* Прибиваємо скрол коли модаль активна */
    position: fixed;
}

/* Прибиваємо скрол body коли модаль відкрита */
body.modal-open {
    overflow: hidden;
}

.modal-box {
    padding: 30px;
    width: 90%;
    max-width: 350px;
    text-align: center;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-overlay.active .modal-box {
    transform: translateY(0);
}

.modal-box h3 {
    margin-bottom: 15px;
    color: #42b2ff;
    font-size: 20px;
}

.modal-box p {
    margin-bottom: 25px;
    font-size: 14px;
    line-height: 1.5;
    color: #e0e6ed;
}

.modal-box .btn {
    width: 100%;
}

/* === Мобільний режим === */
body.mobile-mode .game-container {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
    margin: 0 auto;
    padding: 0 8px;
}
body.mobile-mode .panel-group:first-child,
body.mobile-mode .panel-group:last-child {
    display: none;
}
body.mobile-mode .tetris-wrapper {
    min-height: auto;
    width: 300px;
    flex-shrink: 0;
}
body.mobile-mode header .stat.coin .stat-text { display: none; }
body.mobile-mode header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 15px;
}
body.mobile-mode .user-sub { display: none; }

/* НОВЕ: Сховати текст в мобільній версії */
body.mobile-mode #pause-btn {
    font-size: 0; /* Сховати текст */
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

body.mobile-mode #pause-btn::before {
    content: attr(data-icon);
    font-size: 18px;
}

/* Змінюємо іконку для стану паузи */
body.mobile-mode #pause-btn[data-icon="▶"]::before {
    content: "▶";
}

body.mobile-mode #pause-btn[data-icon="⏸"]::before {
    content: "⏸";
}

/* Сховати текст "Liberty coins" - показати тільки іконку */
body.mobile-mode .header-right .stat.coin {
    font-size: 0;
}

body.mobile-mode .header-right .stat.coin::before {
    content: '🟡 ';
    font-size: 16px;
    margin-right: 4px;
}

body.mobile-mode .header-right .stat.coin span {
    font-size: 14px;
}

/* Дозволяємо скрол у мобільному режимі */
body.mobile-mode {
    overflow-y: auto;
}
body.mobile-mode #main-screen {
    min-height: auto;
    padding-bottom: 30px;
}

/* Колонка: топ-бар + canvas */
.mobile-canvas-col {
    display: contents; /* в десктопному режимі не впливає на layout */
}
body.mobile-mode .mobile-canvas-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Верхня інфо-панель */
.mobile-top-bar {
    width: 300px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 8px 12px;
    gap: 8px;
    flex-shrink: 0;
}
.mobile-bar-label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    color: #a0a5b5;
    letter-spacing: 1px;
    text-align: center;
    margin-bottom: 3px;
}
.mobile-next-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.mobile-next-block canvas {
    background: #1e293b;
    border-radius: 6px;
}
.mobile-score-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.mobile-score-block strong {
    font-size: 22px;
    font-weight: 800;
    color: #fff;
}
.mobile-bar-divider {
    width: 1px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
}

/* Мобільний рейтинг під canvas */
.mobile-leaderboard {
    width: 300px;
    padding: 16px 20px;
    flex-shrink: 0;
}
.mobile-leaderboard h3 {
    font-size: 12px;
    color: #a0a5b5;
    text-align: center;
    margin-bottom: 14px;
    letter-spacing: 1px;
}
#mobile-leaderboard-list .player-row {
    font-size: 13px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
#mobile-leaderboard-list .player-row:last-child {
    border-bottom: none;
}

/* Мобільна панель бустів зліва */
.mobile-boosts-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    padding: 10px 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    backdrop-filter: blur(10px);
    align-self: flex-start;
    /* Вирівнюємо по верху canvas — відступ = висота top-bar + gap */
    margin-top: 76px;
}
.mobile-boost-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.mobile-boost-wrapper .boost-item {
    width: 44px;
    height: 44px;
    border-radius: 10px;
}
.mobile-boost-wrapper .boost-count {
    font-size: 12px;
    font-weight: 800;
    color: #ffca28;
}

/* Свайп-підказка */
.swipe-hint {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: rgba(9, 16, 43, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(66, 178, 255, 0.2);
    border-radius: 30px;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 600;
    color: #a0b4cc;
    white-space: nowrap;
    z-index: 50;
    pointer-events: none;
    animation: hint-fade 4s ease forwards;
    animation-delay: 1s;
}
@keyframes hint-fade {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* === Адаптив магазину === */
@media (max-width: 700px) {
    #shop-screen header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px;
    }
    #shop-screen .header-right {
        gap: 12px;
        font-size: 13px;
    }

    .shop-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 0 12px;
    }

    .shop-card {
        padding: 18px 12px;
    }

    .shop-icon {
        width: 48px;
        height: 48px;
        margin-bottom: 12px;
    }

    .shop-card p {
        font-size: 12px;
        margin-bottom: 8px;
    }

    .shop-card h4 {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .shop-card .btn {
        padding: 9px 14px;
        font-size: 13px;
        width: 100%;
    }
}

@media (max-width: 400px) {
    .shop-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 0 8px;
    }

    .shop-card {
        padding: 14px 10px;
    }

    .shop-icon {
        width: 40px;
        height: 40px;
        margin-bottom: 10px;
    }

    .shop-card p {
        font-size: 11px;
        line-height: 1.4;
    }

    .shop-card h4 {
        font-size: 16px;
    }

    .shop-card .btn {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* Модальне вікно вибору музики */
.music-selector-box {
    max-width: 500px;
    max-height: 70vh;
    overflow-y: auto;
}

.music-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.music-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.music-item.selected {
    border-color: #42b2ff;
    background: rgba(66, 178, 255, 0.15);
}

.music-item-name {
    font-weight: 600;
    color: #fff;
    flex: 1;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 100px;
}

/* Нові стилі для кубків */
.stat.trophy {
    cursor: pointer;
    transition: transform 0.2s, text-shadow 0.2s;
}

.stat.trophy:hover {
    transform: scale(1.1);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* Модальне вікно рейтингу кубків */
.trophy-modal-box {
    max-width: 500px;
    max-height: 70vh;
    overflow-y: auto;
}

.trophy-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
    max-height: 60vh;
    overflow-y: auto;
}

.trophy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border-left: 4px solid rgba(255, 215, 0, 0.3);
    transition: all 0.3s ease;
}

.trophy-row:hover {
    background: rgba(255, 215, 255, 0.1);
    border-left-color: #ffd700;
    transform: translateX(4px);
}

.trophy-row.my-row {
    border-left-color: #42b2ff;
    background: rgba(66, 178, 255, 0.1);
}

.trophy-rank {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 14px;
    margin-right: 12px;
    flex-shrink: 0;
}

.trophy-rank-1 {
    background: #ffd700;
    color: #000;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.trophy-rank-2 {
    background: #c0c0c0;
    color: #000;
}

.trophy-rank-3 {
    background: #cd7f32;
    color: #fff;
}

.trophy-rank-other {
    background: rgba(255, 255, 255, 0.1);
    color: #a0a5b5;
}

.trophy-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.trophy-name {
    font-weight: 700;
    font-size: 14px;
    color: #fff;
}

.trophy-count {
    font-size: 12px;
    color: #a0a5b5;
}

.trophy-value {
    font-weight: 800;
    font-size: 18px;
    color: #ffd700;
    min-width: 40px;
    text-align: right;
}
