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

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    max-width: 1200px;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5em;
    text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff;
    }
    to {
        text-shadow: 0 0 20px #00ffff, 0 0 30px #00ffff, 0 0 40px #00ffff;
    }
}

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

.game-board {
    background: #0f0f0f;
    border: 4px solid #00ffff;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
}

#gameCanvas {
    display: block;
    background: #000;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 25px;
    min-width: 250px;
}

.stats-section,
.next-piece-section,
.controls-section {
    background: rgba(15, 15, 15, 0.8);
    border: 2px solid #00ffff;
    border-radius: 10px;
    padding: 20px;
}

.stats-section h2 {
    text-align: center;
    font-size: 2em;
    margin-bottom: 20px;
    color: #00ffff;
}

.stat {
    margin-bottom: 15px;
}

.stat label {
    display: block;
    font-size: 0.9em;
    color: #aaa;
    margin-bottom: 5px;
}

.stat .value {
    font-size: 2em;
    font-weight: bold;
}

.score-value {
    color: #00ffff;
}

.level-value {
    color: #ffff00;
}

.lines-value {
    color: #00ff00;
}

.combo-value {
    color: #ff00ff;
    animation: pulse 0.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.next-piece-section h3,
.controls-section h3 {
    margin-bottom: 15px;
    color: #00ffff;
    text-align: center;
}

#nextPieceCanvas {
    display: block;
    margin: 0 auto;
    background: #1a1a1a;
    border-radius: 5px;
}

.controls-section ul {
    list-style: none;
}

.controls-section li {
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #ccc;
}

kbd {
    background: #333;
    border: 1px solid #555;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: 'Courier New', monospace;
    color: #fff;
    box-shadow: 0 2px 0 #111;
}

.button-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px 24px;
    font-family: 'Courier New', monospace;
    font-size: 1em;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #00ffff 0%, #0088ff 100%);
    color: #000;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 255, 255, 0.5);
}

.btn-secondary {
    background: linear-gradient(135deg, #666 0%, #444 100%);
    color: #fff;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #777 0%, #555 100%);
}

.btn-secondary.active {
    background: linear-gradient(135deg, #00cc00 0%, #008800 100%);
    box-shadow: 0 0 15px rgba(0, 255, 0, 0.5);
}

.btn-secondary.active:hover {
    background: linear-gradient(135deg, #00dd00 0%, #009900 100%);
}

.btn-large {
    padding: 15px 30px;
    font-size: 1.2em;
}

.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.game-over-content {
    text-align: center;
    padding: 40px;
    background: rgba(15, 15, 15, 0.95);
    border: 4px solid #ff0000;
    border-radius: 15px;
    box-shadow: 0 0 50px rgba(255, 0, 0, 0.5);
}

.game-over-content h2 {
    font-size: 3em;
    color: #ff0000;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #ff0000;
}

.final-score {
    font-size: 1.5em;
    margin-bottom: 30px;
    color: #00ffff;
}

.final-score span {
    font-size: 1.5em;
    font-weight: bold;
}

/* Mobile Touch Controls */
.mobile-controls {
    display: none; /* Hidden on desktop */
    margin-top: 20px;
    padding: 20px;
    background: rgba(15, 15, 15, 0.9);
    border: 2px solid #00ffff;
    border-radius: 15px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.controls-row {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 15px;
}

.controls-row:last-child {
    margin-bottom: 0;
}

.control-btn {
    background: linear-gradient(135deg, #00ffff 0%, #0088ff 100%);
    border: 3px solid #00ffff;
    border-radius: 12px;
    color: #000;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s ease;
    box-shadow: 0 4px 0 #006666, 0 6px 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 70px;
    padding: 10px;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #006666, 0 2px 5px rgba(0, 0, 0, 0.5);
    background: linear-gradient(135deg, #00dddd 0%, #0066ff 100%);
}

.btn-icon {
    font-size: 2em;
    line-height: 1;
    margin-bottom: 5px;
}

.btn-label {
    font-size: 0.7em;
    letter-spacing: 1px;
}

/* Top row buttons (Rotate & Drop) */
.top-row .control-btn {
    flex: 1;
    max-width: 180px;
}

.rotate-btn {
    background: linear-gradient(135deg, #ff00ff 0%, #cc00cc 100%);
    border-color: #ff00ff;
    box-shadow: 0 4px 0 #660066, 0 6px 10px rgba(0, 0, 0, 0.5);
}

.rotate-btn:active {
    background: linear-gradient(135deg, #dd00dd 0%, #aa00aa 100%);
    box-shadow: 0 0 0 #660066, 0 2px 5px rgba(0, 0, 0, 0.5);
}

.drop-btn {
    background: linear-gradient(135deg, #ffff00 0%, #cccc00 100%);
    border-color: #ffff00;
    box-shadow: 0 4px 0 #666600, 0 6px 10px rgba(0, 0, 0, 0.5);
}

.drop-btn:active {
    background: linear-gradient(135deg, #dddd00 0%, #aaaa00 100%);
    box-shadow: 0 0 0 #666600, 0 2px 5px rgba(0, 0, 0, 0.5);
}

/* Bottom row buttons (Movement) */
.bottom-row .move-btn {
    width: 80px;
    height: 80px;
    min-height: auto;
}

.bottom-row .move-btn .btn-icon {
    font-size: 2.5em;
    margin: 0;
}

/* Responsive design */
@media (max-width: 900px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 600px;
    }

    /* Show mobile controls on tablets */
    .mobile-controls {
        display: block;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5em;
        margin-bottom: 15px;
    }

    .game-board {
        width: 100%;
    }

    #gameCanvas {
        width: 100% !important;
        height: auto !important;
        max-width: 400px;
        display: block;
        margin: 0 auto;
    }

    /* Always show mobile controls on phones */
    .mobile-controls {
        display: block;
        max-width: 400px;
        margin: 15px auto 0;
        padding: 15px;
    }

    /* Optimize control buttons for small screens */
    .controls-row {
        gap: 10px;
        margin-bottom: 10px;
    }

    .top-row .control-btn {
        min-height: 60px;
        font-size: 0.9em;
    }

    .bottom-row .move-btn {
        width: 65px;
        height: 65px;
    }

    .btn-icon {
        font-size: 1.8em;
    }

    .btn-label {
        font-size: 0.65em;
    }

    /* Compact side panel on mobile */
    .side-panel {
        padding: 15px;
    }

    .stats-section,
    .next-piece-section,
    .controls-section {
        padding: 15px;
        margin-bottom: 15px;
    }

    .stats-section h2 {
        font-size: 1.5em;
    }

    .stat .value {
        font-size: 1.5em;
    }

    /* Hide keyboard controls on mobile */
    .controls-section {
        display: none;
    }

    .button-section {
        gap: 8px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9em;
    }

    /* Game over overlay adjustments */
    .game-over-content {
        padding: 30px 20px;
        margin: 0 10px;
    }

    .game-over-content h2 {
        font-size: 2em;
    }

    .final-score {
        font-size: 1.2em;
    }
}

/* Landscape mobile optimization */
@media (max-width: 900px) and (orientation: landscape) {
    .game-container {
        flex-direction: row;
        gap: 15px;
    }

    .game-board {
        flex: 0 0 auto;
    }

    #gameCanvas {
        max-height: 70vh;
        width: auto !important;
    }

    .side-panel {
        flex: 1;
        max-width: 300px;
    }

    .mobile-controls {
        margin-top: 10px;
        padding: 10px;
    }

    .controls-row {
        gap: 8px;
        margin-bottom: 8px;
    }

    .control-btn {
        min-height: 50px;
        font-size: 0.8em;
    }

    .bottom-row .move-btn {
        width: 60px;
        height: 60px;
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 380px) {
    header h1 {
        font-size: 1.2em;
    }

    .controls-row {
        gap: 8px;
    }

    .top-row .control-btn {
        min-height: 55px;
        font-size: 0.85em;
    }

    .bottom-row .move-btn {
        width: 58px;
        height: 58px;
    }

    .btn-icon {
        font-size: 1.6em;
    }
}
