﻿body {
    font-family: Arial,Helvetica,sans-serif;
    background: #111;
    color: #eee;
    margin: 0;
    padding: 10px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game {
    display: flex;
    gap: 18px;
    justify-content: center;
    align-items: flex-start;
    margin: 0 auto;
    width: 100%;
    max-width: 540px;
}

.board-wrap {
    position: relative;
    width: min(75vw, 260px);
    max-width: 75vw;
    margin-bottom: 0;
}

.board {
    width: 100%;
    aspect-ratio: 1 / 2;
    border: 2px solid #444;
    background: #222;
    position: relative;
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
    max-width: 75vw;
    max-height: 90vh;
}

.cell {
    width: 10%;
    height: 5%;
    float: left;
    border: 1px solid #333;
    box-sizing: border-box;
    background: #222;
    transition: background 0.1s;
}

.sidepanel {
    width: 180px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    min-width: 70px;
    max-width: 35vw;
}

.status {
    margin-bottom: 13px;
    text-align: left;
    width: 100%;
}

button {
    padding: 6px 10px;
    background: #444;
    color: #eee;
    border: none;
    cursor: pointer;
    width: 100%;
    max-width: 140px;
    min-width: 68px;
    box-sizing: border-box;
    transition: background 0.2s;
    margin-bottom: 7px;
}

    button:hover {
        background: #555;
    }

.preview-label {
    font-size: 0.95em;
    opacity: 0.75;
    margin-bottom: 3px;
}

.preview-box {
    width: 90px;
    height: 60px;
    background: #1a1a1a;
    border: 2px solid #444;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
}

#next {
    display: grid;
    grid-template-rows: repeat(4,15px);
    grid-template-columns: repeat(4,15px);
}

.next-cell {
    width: 15px;
    height: 15px;
    border: 1px solid #333;
    box-sizing: border-box;
    background: #1a1a1a;
}
/* --- Touch Controls --- */
.touch-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    margin: 14px auto 0 auto;
}

.touch-row {
    display: flex;
    gap: 7px;
    width: 100%;
    justify-content: center;
}

.touch-btn {
    width: 39px;
    height: 39px;
    background: #222;
    border: 2px solid #444;
    border-radius: 10px;
    color: #eee;
    font-size: 1.8em;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 170, 0);
    touch-action: manipulation;
    transition: background 0.15s,border-color 0.15s;
}

    .touch-btn:active {
        background: #555;
        border-color: #aaa;
        color: #fff;
    }
/* --- Overlay по центру поля --- */
.gameover, .paused {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2;
    pointer-events: auto;
}

    .gameover h2 {
        color: #f44;
        margin-bottom: 14px;
        font-size: 2.0em;
    }

.paused {
    background: rgba(0,0,0,0.7);
}

.paused-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
}

.paused h2 {
    color: #ffb700;
    margin-bottom: 12px;
}
/* --- Мобильные стили --- */
@media (max-width:700px) {
    #game {
        flex-direction: row;
        align-items: flex-start;
        max-width: 99vw;
        gap: 2vw;
    }

    .board-wrap {
        width: 65vw;
        max-width: 65vw;
        min-width: 0;
    }

    .board {
        min-width: 0;
        min-height: 0;
        width: 65vw;
        max-width: 65vw;
        aspect-ratio: 1/2;
    }

    .cell {
        width: 10%;
        height: 5%;
    }

    .sidepanel {
        width: 28vw;
        min-width: 42px;
        max-width: 31vw;
        font-size: 0.97em;
        padding-top: 2px;
    }

    .preview-box {
        width: 22vw; /* Ширина относительно боковой панели, достаточно для 4 ячеек */
        max-width: 60px;
        height: 22vw;
        max-height: 60px;
        min-width: 36px;
        min-height: 36px;
        padding: 0;
        box-sizing: border-box;
        overflow: hidden;
        margin-bottom: 13px;
    }

    #next {
        width: 100%;
        height: 100%;
        display: grid;
        grid-template-rows: repeat(4, 1fr);
        grid-template-columns: repeat(4, 1fr);
        gap: 0;
    }

    .next-cell {
        width: 100%;
        height: 100%;
        max-width: 15px;
        max-height: 15px;
        min-width: 6px;
        min-height: 6px;
    }

    .touch-controls {
        display: flex;
        position: static;
        width: 98vw;
        max-width: 430px;
        margin: 3vw 0 4vw 0;
        z-index: 20;
        gap: 10px;
    }

    .touch-row {
        display: flex;
        gap: 10px;
        width: 100%;
        justify-content: center;
    }

    .touch-btn {
        width: 56px !important;
        height: 56px !important;
        min-width: 44px;
        min-height: 44px;
        max-width: 62px;
        max-height: 62px;
        font-size: 2.1em;
        border-radius: 10px;
        padding: 0;
        box-sizing: border-box;
    }

    .controls {
        display: none !important;
    }
}

@media (max-width:400px) {
    .sidepanel {
        width: 20vw;
        min-width: 34px;
        max-width: 23vw;
    }

    .preview-box {
        width: 12vw;
    }
}
