:root {
    --bg-color: #050510;
    --grid-bg: #111122;
    --text-color: #e0e0ff;
    --accent-color: #00ffcc;
    --neon-blue: #00f3ff;
    --neon-pink: #ff00ff;
    --neon-green: #00ff00;
    --block-size: 40px;
    --grid-width: 6;
    --grid-height: 13;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Orbitron', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

.game-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.2);
    backdrop-filter: blur(10px);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 150px;
}

.panel {
    background: rgba(0, 0, 0, 0.5);
    padding: 15px;
    border: 1px solid var(--neon-blue);
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 0 5px var(--neon-blue);
}

h2 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--neon-blue);
    text-shadow: 0 0 5px var(--neon-blue);
}

#score,
#level {
    font-size: 1.5rem;
    font-weight: bold;
}

.game-board-container {
    position: relative;
    border: 2px solid var(--neon-pink);
    border-radius: 5px;
    box-shadow: 0 0 15px var(--neon-pink);
    background-color: var(--grid-bg);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(var(--grid-width), var(--block-size));
    grid-template-rows: repeat(var(--grid-height), var(--block-size));
    width: calc(var(--grid-width) * var(--block-size));
    height: calc(var(--grid-height) * var(--block-size));
}

.cell {
    width: var(--block-size);
    height: var(--block-size);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: 'Zen Dots', cursive;
    color: white;
}

.block {
    width: 90%;
    height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    /* Circles like Puyo or rounded squares? Let's go with rounded squares for numbers */
    border-radius: 8px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    font-weight: bold;
    transition: transform 0.1s;
}

/* Number Colors */
.num-0 {
    background-color: #cccccc;
    box-shadow: 0 0 10px #cccccc;
    color: black;
}

.num-1 {
    background-color: #ff3333;
    box-shadow: 0 0 10px #ff3333;
}

.num-2 {
    background-color: #ff9933;
    box-shadow: 0 0 10px #ff9933;
}

.num-3 {
    background-color: #ffff33;
    box-shadow: 0 0 10px #ffff33;
    color: black;
}

.num-4 {
    background-color: #33ff33;
    box-shadow: 0 0 10px #33ff33;
    color: black;
}

.num-5 {
    background-color: #33ffff;
    box-shadow: 0 0 10px #33ffff;
    color: black;
}

.num-6 {
    background-color: #3333ff;
    box-shadow: 0 0 10px #3333ff;
}

.num-7 {
    background-color: #9933ff;
    box-shadow: 0 0 10px #9933ff;
}

.limit-line {
    position: absolute;
    top: calc(var(--block-size) * 2 - 2px);
    /* Align exactly with bottom of row 1 */
    left: 0;
    width: 100%;
    height: 4px;
    /* Thicker line */
    background-color: red;
    box-shadow: 0 0 10px red;
    z-index: 5;
    pointer-events: none;
    opacity: 0.7;
}

.clearing {
    animation: clearAnim 0.3s forwards;
}

@keyframes clearAnim {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

.next-block-display {
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Health Bar removed */

/* Menu Styles */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    color: white;
}

.title {
    font-size: 3rem;
    color: var(--neon-pink);
    text-shadow: 0 0 20px var(--neon-pink);
    margin-bottom: 40px;
    font-family: 'Zen Dots', cursive;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.menu-btn {
    padding: 15px 40px;
    font-size: 1.5rem;
    background: transparent;
    border: 2px solid var(--neon-blue);
    color: var(--neon-blue);
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    transition: all 0.2s;
    text-shadow: 0 0 5px var(--neon-blue);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
}

.menu-btn:hover {
    background: var(--neon-blue);
    color: black;
    box-shadow: 0 0 20px var(--neon-blue);
}

.menu-btn.small {
    font-size: 1rem;
    padding: 10px 20px;
    margin-top: 20px;
}

#difficulty-select {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.hidden {
    display: none !important;
}

/* Game Instance & VS Mode */
.game-instance {
    display: flex;
    gap: 20px;
}

.vs-mode {
    gap: 50px;
}

.vs-mode .game-instance {
    transform: scale(0.9);
    /* Scale down slightly to fit two */
}

.cpu-instance .game-board-container {
    border-color: var(--neon-green);
    box-shadow: 0 0 15px var(--neon-green);
}

.cpu-instance h2 {
    color: var(--neon-green);
    text-shadow: 0 0 5px var(--neon-green);
}

/* Mobile Controls */
.mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 20;
    pointer-events: none;
    /* Let clicks pass through container */
}

.control-row {
    display: flex;
    gap: 20px;
    pointer-events: auto;
    /* Re-enable clicks on buttons */
}

.control-btn {
    width: 60px;
    height: 60px;
    background: rgba(0, 243, 255, 0.2);
    border: 2px solid var(--neon-blue);
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    touch-action: manipulation;
    /* Prevent double-tap zoom */
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    /* Enable clicks */
}

.control-btn:active {
    background: var(--neon-blue);
    color: black;
}

.action-btn {
    border-color: var(--neon-pink);
    background: rgba(255, 0, 255, 0.2);
}

.action-btn:active {
    background: var(--neon-pink);
}

.mobile-pause-btn {
    display: none;
    /* Hidden by default (Desktop) */
}

/* Responsive Design */
@media (max-width: 768px) {

    /* 1P Mode (Portrait) */
    .single-player {
        --block-size: 28px;
        /* Smaller blocks for mobile */
        display: grid;
        grid-template-columns: auto 100px;
        grid-template-rows: auto;
        gap: 10px;
        padding: 10px;
        width: 100%;
        max-width: 400px;
        justify-content: center;
    }

    .single-player .game-instance {
        display: contents;
        /* Use parent grid */
    }

    .single-player .game-board-container {
        grid-column: 1;
        grid-row: 1 / span 3;
        margin-bottom: 80px;
        /* Space for controls */
    }

    .single-player .sidebar.right {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
    }

    .single-player .sidebar.left {
        grid-column: 2;
        grid-row: 2;
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .mobile-pause-btn {
        display: flex;
        width: 50px;
        height: 50px;
        margin-top: 10px;
    }

    .mobile-controls {
        display: flex;
        flex-direction: row;
        gap: 10px;
        bottom: 10px;
        width: 100%;
        justify-content: center;
    }

    .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* VS Mode (Landscape Force) */
    .vs-mode {
        flex-direction: row;
        width: 100vw;
        height: 100vh;
        padding: 10px;
        gap: 10px;
        justify-content: center;
        align-items: center;
    }

    .vs-mode .game-instance {
        transform: scale(0.6);
        /* Smaller for mobile landscape */
        flex-direction: row;
        gap: 10px;
    }

    .vs-mode .sidebar {
        width: 80px;
        /* Compact sidebar */
    }

    .vs-mode .panel {
        padding: 5px;
    }

    .vs-mode .mobile-controls {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        padding: 0 20px;
        bottom: 10px;
        width: 100%;
    }

    .vs-mode .control-row {
        gap: 10px;
    }

    .vs-mode .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* Mobile X Button Position */
    #x-share-btn {
        top: 20px;
        bottom: auto;
        right: 20px;
    }

    /* Mobile Controls Layout */
    .mobile-controls {
        justify-content: flex-start;
        /* Align arrows to left */
        padding: 0 20px;
        /* Add padding */
    }

    #btn-rotate {
        margin-left: auto;
        /* Push rotate button to right */
    }
}

/* Landscape specific adjustments */
@media (max-width: 900px) and (orientation: landscape) {
    .game-container {
        padding: 5px;
    }

    .vs-mode .game-instance {
        transform: scale(0.55);
    }

    .vs-mode .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* Mobile X Button Position */
    #x-share-btn {
        top: 20px;
        bottom: auto;
        right: 20px;
    }

    /* Mobile Controls Layout */
    .mobile-controls {
        justify-content: flex-start;
        /* Align arrows to left */
        padding: 0 20px;
        /* Add padding */
    }

    #btn-rotate {
        margin-left: auto;
        /* Push rotate button to right */
    }
}

/* X Share Button (Desktop Default) */
#x-share-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background-color: #000;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.5;
    transition: opacity 0.3s ease, transform 0.2s ease;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#x-share-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

#x-share-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}