/* Базовые стили для улучшенной версии */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Montserrat', sans-serif;
    background: url('/static/fon.png') center center / cover no-repeat fixed;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Лоадер на весь экран */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.global-loader.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #4A90E2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

.loader-text {
    color: white;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
}

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

/* Контейнер игры */
.game-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90vw;
    height: 90vw;
    max-width: 600px;
    max-height: 600px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.game-wrapper.loaded {
    opacity: 1;
}

.outer-container {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.outer-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.game-container {
    background: white;
    padding: 8px;
    border-radius: 8px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    width: 75%;
}

/* Сетка ячеек */
.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.1px;
}

.cell {
    width: calc((77vw - 40px) / 5);
    height: calc((77vw - 40px) / 5);
    max-width: 112px;
    max-height: 112px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    perspective: 1000px;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.cell:hover {
    transform: scale(1.02);
}

.cell:active {
    transform: scale(0.98);
}

.cell.opening {
    pointer-events: none;
}

.cell.opened {
    pointer-events: none;
}

.cell .flipper {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.cell.opened .flipper {
    transform: rotateY(180deg);
}

.cell img.cover,
.cell img.revealed {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    backface-visibility: hidden;
}

.cell img.revealed {
    transform: rotateY(180deg);
}

/* UI элементы */
.text-window {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -260px);
    width: 250px;
    height: auto;
    z-index: 100;
}

.text-window img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.open-button {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 210px);
    width: 230px;
    height: 55px;
    border-radius: 10px;
    overflow: hidden;
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 100;
    transition: transform 0.1s ease;
}

.open-button:hover {
    transform: translate(-50%, 210px) scale(1.02);
}

.open-button:active {
    transform: translate(-50%, 210px) scale(0.98);
}

.open-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.open-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: translate(-50%, 210px);
}

.clicks-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 300px);
    font-weight: 600;
    font-size: 18px;
    color: #000000;
    text-align: center;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
    z-index: 100;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    z-index: 1001;
    width: 80%;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-text {
    margin-bottom: 15px;
    font-size: 16px;
    line-height: 1.4;
    color: #333;
    font-weight: 500;
}

.modal-button {
    position: relative;
    background: #4A90E2;
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
    font-family: 'Montserrat', sans-serif;
}

.modal-button:hover {
    background: #357ABD;
}

.modal-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.timer {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ff4444;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

/* Призовые модалки */
.prize-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.prize-modal.show {
    opacity: 1;
}

.prize-modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    width: 80%;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 24px;
    color: #666;
    padding: 0;
    line-height: 1;
}

.prize-text {
    font-size: 18px;
    line-height: 1.4;
    color: #333;
    font-weight: 500;
    margin-bottom: 15px;
    white-space: pre-line;
}

.write-button {
    background: #4A90E2;
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
    font-family: 'Montserrat', sans-serif;
    margin-top: 20px;
    text-decoration: none;
    display: inline-block;
}

.write-button:hover {
    background: #357ABD;
}

/* Адаптивность */
@media screen and (max-height: 650px) {
    .text-window {
        transform: translate(-50%, -230px);
        width: 200px;
    }

    .open-button {
        transform: translate(-50%, 190px);
        width: 180px;
        height: 45px;
    }

    .open-button:hover {
        transform: translate(-50%, 190px) scale(1.02);
    }

    .open-button:active {
        transform: translate(-50%, 190px) scale(0.98);
    }

    .open-button:disabled {
        transform: translate(-50%, 190px);
    }

    .clicks-text {
        transform: translate(-50%, 260px);
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .modal-content,
    .prize-modal-content {
        width: 90%;
        padding: 20px;
    }
    
    .modal-text,
    .prize-text {
        font-size: 15px;
    }
}
