/* Block Drop - Game Styles */

.game-area {
    max-width: 600px;
}

/* Info Bar */
.game-info-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: stretch;
}

.info-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 8px 16px;
    text-align: center;
    min-width: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.info-label {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    font-weight: 700;
}

.info-value {
    display: block;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-heading);
    font-family: 'Oswald', sans-serif;
}

/* Controls */
.game-controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
}

/* Board Layout */
.board-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

.board-container {
    position: relative;
    background: #0a0c14;
    border: 2px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 4px;
    line-height: 0;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size, 28px));
    grid-template-rows: repeat(20, var(--cell-size, 28px));
    gap: 1px;
    background: rgba(255, 255, 255, 0.03);
}

.cell {
    width: var(--cell-size, 28px);
    height: var(--cell-size, 28px);
    background: rgba(255, 255, 255, 0.02);
    border-radius: 2px;
}

/* Piece colors */
.cell.I { background: linear-gradient(135deg, #00e5ff, #00b8d4); box-shadow: inset 0 0 6px rgba(0, 229, 255, 0.4); }
.cell.O { background: linear-gradient(135deg, #ffeb3b, #fdd835); box-shadow: inset 0 0 6px rgba(255, 235, 59, 0.4); }
.cell.T { background: linear-gradient(135deg, #ce93d8, #ab47bc); box-shadow: inset 0 0 6px rgba(206, 147, 216, 0.4); }
.cell.S { background: linear-gradient(135deg, #69f0ae, #00e676); box-shadow: inset 0 0 6px rgba(105, 240, 174, 0.4); }
.cell.Z { background: linear-gradient(135deg, #ef5350, #e53935); box-shadow: inset 0 0 6px rgba(239, 83, 80, 0.4); }
.cell.J { background: linear-gradient(135deg, #42a5f5, #1e88e5); box-shadow: inset 0 0 6px rgba(66, 165, 245, 0.4); }
.cell.L { background: linear-gradient(135deg, #ffa726, #fb8c00); box-shadow: inset 0 0 6px rgba(255, 167, 38, 0.4); }

/* Ghost piece */
.cell.ghost {
    background: none;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

/* Line clear animation */
.cell.clearing {
    animation: lineClear 0.3s ease-out forwards;
}

@keyframes lineClear {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); background: #fff; opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

/* Next Piece Box */
.info-item.next-piece-box {
    padding: 4px 10px;
    min-width: 70px;
}

.info-item.next-piece-box .info-label {
    margin-bottom: 4px;
}

#next-piece {
    display: grid;
    grid-template-columns: repeat(4, 12px);
    grid-template-rows: repeat(4, 12px);
    gap: 1px;
    justify-content: center;
}

#next-piece .cell {
    width: 12px;
    height: 12px;
}

/* Game Over Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: var(--radius-md);
}

.overlay.hidden {
    display: none !important;
}

.result-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-subtle);
    padding: 28px;
    border-radius: var(--radius-lg);
    text-align: center;
    width: 90%;
    max-width: 280px;
    box-shadow: var(--shadow-card);
    line-height: 1.4;
}

.result-content h2 {
    color: var(--text-heading);
    margin-bottom: 12px;
    font-family: 'Oswald', sans-serif;
}

.result-content p {
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 16px;
}

.result-content .btn-primary {
    margin-top: 16px;
}

/* Touch Controls — desktop hidden, mobile/tablet shows D-pad */
.touch-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    touch-action: manipulation;
}

.touch-row {
    display: flex;
    gap: 14px;
    justify-content: center;
    align-items: center;
}

.touch-btn {
    background: var(--bg-surface);
    border: 2px solid var(--border-subtle);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.05s ease, background 0.08s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    font-weight: 700;
}

.touch-btn.pressed {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    transform: scale(0.92);
}

.touch-btn-dir,
.touch-btn-down,
.touch-btn-rotate {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    font-size: 28px;
}

.touch-btn-drop {
    width: 220px;
    height: 50px;
    border-radius: var(--radius-md);
    font-size: 16px;
    letter-spacing: 2px;
}

/* ────────── FULLSCREEN PLAY MODE for mobile/tablet ────────── */
@media (max-width: 1024px) {
    /* Show touch controls at this width */
    .touch-controls {
        display: flex;
    }

    /* When the body has .playing, hide page chrome and lock to viewport */
    body.playing {
        overflow: hidden;
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
    }

    body.playing header,
    body.playing .hamburger-menu,
    body.playing footer,
    body.playing .how-to-play,
    body.playing .game-stats-section,
    body.playing .game-header,
    body.playing .game-controls {
        display: none !important;
    }

    body.playing main {
        padding: 0 !important;
        margin: 0 !important;
    }

    body.playing .game-area {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        padding: 0 !important;
        margin: 0 !important;
        border-radius: 0;
        border: none;
        background: var(--bg-page, #0a0c12);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Compact top info strip during play */
    body.playing .game-info-bar {
        margin: 0;
        padding: 6px 8px;
        gap: 6px;
        flex-wrap: nowrap;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border-subtle);
        flex-shrink: 0;
    }

    body.playing .info-item {
        padding: 4px 6px;
        min-width: 0;
        flex: 1;
        background: transparent;
        border: none;
    }

    body.playing .info-label {
        font-size: 9px;
        margin-bottom: 1px;
    }

    body.playing .info-value {
        font-size: 16px;
        line-height: 1;
    }

    body.playing .info-item.next-piece-box {
        padding: 2px 6px;
    }

    body.playing #next-piece {
        grid-template-columns: repeat(4, 7px);
        grid-template-rows: repeat(4, 7px);
    }

    body.playing #next-piece .cell {
        width: 7px;
        height: 7px;
    }

    /* Board fills the available space */
    body.playing .board-wrapper {
        flex: 1;
        margin: 0;
        padding: 8px 0;
        align-items: center;
        justify-content: center;
        min-height: 0;
    }

    body.playing .board-container {
        padding: 3px;
        border-radius: 6px;
    }

    /* Cell sized to fit BOTH viewport width AND height — whichever is smaller */
    /* Available height ≈ 100vh - top info (~38px) - controls area (~210px) - padding (~20px) */
    /* Board is 20 cells tall + 19 gaps + 6px padding/border ≈ 20 cells + 25px */
    body.playing #game-board {
        --cell-size: min(
            calc((100vw - 14px) / 10),
            calc((100dvh - 270px) / 20)
        );
    }

    /* Controls area at bottom */
    body.playing .touch-controls {
        flex-shrink: 0;
        padding: 10px 8px 16px;
        margin-top: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border-subtle);
        gap: 8px;
    }

    body.playing .touch-row {
        gap: 14px;
    }

    /* Pause button shown during play, top-right corner */
    body.playing .play-pause-btn {
        display: flex;
    }

    /* When NOT playing on mobile, the page is normal-flow with regular layout */
}

/* Smaller phones: tighten control sizes */
@media (max-width: 480px) {
    body.playing .touch-btn-dir,
    body.playing .touch-btn-down,
    body.playing .touch-btn-rotate {
        width: 62px;
        height: 62px;
        font-size: 24px;
    }

    body.playing .touch-btn-drop {
        width: 180px;
        height: 44px;
        font-size: 14px;
    }

    body.playing .touch-row {
        gap: 12px;
    }

    body.playing .touch-controls {
        padding: 8px 6px 12px;
        gap: 6px;
    }

    /* Slightly smaller cell budget for short phones */
    body.playing #game-board {
        --cell-size: min(
            calc((100vw - 14px) / 10),
            calc((100dvh - 240px) / 20)
        );
    }
}

@media (max-width: 360px) {
    body.playing .touch-btn-dir,
    body.playing .touch-btn-down,
    body.playing .touch-btn-rotate {
        width: 54px;
        height: 54px;
        font-size: 22px;
    }

    body.playing .touch-row {
        gap: 10px;
    }

    body.playing .touch-btn-drop {
        width: 160px;
    }
}

/* Pause button shown only during play */
.play-pause-btn {
    display: none;
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 50;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.play-pause-btn:active {
    background: var(--accent);
    color: #fff;
}

/* Mobile: when NOT playing, use compact normal layout */
@media (max-width: 768px) and (orientation: portrait) {
    body:not(.playing) .game-area {
        padding: 16px 10px;
    }

    body:not(.playing) #game-board {
        --cell-size: 24px;
    }

    body:not(.playing) .game-info-bar {
        gap: 6px;
    }
}
