:root {
    --bg-color: #000000;
    --grid-bg: #101012;
    --text-color: #fff;
    --accent-color: #14F195; /* Solana Green */
    --secondary-color: #9945FF; /* Solana Purple */
    --border-color: #9945FF;
    --highlight: #14F195;
}

body {
    background: linear-gradient(135deg, #000000 0%, #1a1a2e 100%);
    color: var(--text-color);
    font-family: 'Press Start 2P', cursive;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    touch-action: manipulation; /* Allow scroll but improve touch */
    overflow-y: auto; /* Enable vertical scroll */
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    max-width: 600px;
    width: 100%;
    margin-bottom: 50px; /* Space for scrolling past controls */
}

.title {
    font-size: 3rem;
    margin: 40px 0 20px; /* Increased top margin */
    background: linear-gradient(to right, #14F195, #9945FF);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0px 0px 10px rgba(153, 69, 255, 0.5);
    letter-spacing: 5px;
}

.main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
}

.game-area {
    position: relative;
    border: 4px solid var(--border-color);
    background: var(--grid-bg);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

canvas#tetris {
    display: block;
}

.left-panel, .right-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100px;
}

.stat-box {
    background: #111;
    padding: 10px;
    border: 2px solid #333;
    text-align: center;
    box-shadow: 0 0 10px rgba(20, 241, 149, 0.1);
}

.stat-box label {
    display: block;
    font-size: 0.7rem;
    color: #aaa;
    margin-bottom: 5px;
}

.stat-box div {
    font-size: 1rem;
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-color);
}

.preview-box {
    background: #050505;
    border: 2px solid #333;
    padding: 5px;
    text-align: center;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

.preview-box label {
    font-size: 0.7rem;
    color: #aaa;
    margin-bottom: 5px;
}

.retro-btn {
    background: linear-gradient(90deg, #9945FF 0%, #14F195 100%);
    border: none;
    padding: 10px 5px;
    font-family: inherit;
    font-size: 0.7rem;
    color: #000;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(20, 241, 149, 0.3);
    transition: transform 0.1s;
    font-weight: bold;
}

.retro-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #000;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
    z-index: 10;
}

.hidden {
    display: none !important;
}

.overlay h2 {
    color: #ff3333;
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.overlay input {
    font-family: inherit;
    padding: 8px;
    text-align: center;
    text-transform: uppercase;
    width: 70%;
    border: 2px solid #fff;
    background: #000;
    color: #fff;
}

.overlay button {
    font-family: inherit;
    padding: 10px 20px;
    background: var(--accent-color);
    border: none;
    color: #000;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #222;
    border: 4px solid var(--highlight);
    padding: 20px;
    width: 80%;
    max-width: 400px;
    position: relative;
    color: #fff;
}

.close-modal {
    position: absolute;
    top: 5px;
    right: 10px;
    font-size: 1.5rem;
    cursor: pointer;
}

#high-score-list {
    list-style: none;
    padding: 0;
    margin-top: 15px;
    max-height: 300px;
    overflow-y: auto;
}

#high-score-list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #444;
    font-size: 0.8rem;
}

.mobile-controls-hint {
    display: none;
    font-size: 0.6rem;
    text-align: center;
    color: #888;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .left-panel {
        flex-direction: row;
        width: 100%;
        justify-content: space-between;
        order: 1; /* Stats on top */
    }
    
    .stat-box {
        flex: 1;
        padding: 5px;
    }
    
    .game-area {
        order: 2;
    }
    
    .right-panel {
        flex-direction: row;
        width: 100%;
        justify-content: center;
        order: 3;
        gap: 10px;
    }
    
    .preview-box {
        display: none; /* Hide preview on very small screens if needed, or re-layout */
    }
    
    .mobile-controls-hint {
        display: block;
        width: 100%;
    }
}

/* On-screen Controls */
.controls-container {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 300px;
}

.control-row {
    display: flex;
    gap: 15px;
    justify-content: center;
    width: 100%;
}

.control-btn {
    background: #1a1a1a;
    border: 2px solid #333;
    color: var(--accent-color);
    font-size: 1.5rem;
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 4px 0 #000;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.1s;
}

.control-btn:active {
    background: #2a2a2a;
    box-shadow: 0 0 0 #000;
    transform: translateY(4px);
    border-color: var(--accent-color);
}

.control-btn.round {
    border-radius: 50%;
    background: #1a1a1a;
    color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.control-btn.wide {
    width: 100%;
    height: 50px;
    font-size: 1rem;
    background: linear-gradient(90deg, #14F195 0%, #14F195 100%);
    color: #000;
    font-family: 'Press Start 2P', cursive;
    border: none;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(20, 241, 149, 0.4);
}
