:root {
    --bg-color: #0d0d12;
    --panel-color: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --accent-color: #00f2ff;
    --text-color: #ffffff;
    --font-family: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Background Animation Effect */
body::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, rgba(0, 242, 255, 0.05) 0%, transparent 50%);
    z-index: -1;
    animation: rotate 20s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 2rem;
    z-index: 1;
}

header h1 {
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: 0.5rem;
    background: linear-gradient(to right, #00f2ff, #7000ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
}

main {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.game-container {
    background: var(--panel-color);
    backdrop-filter: blur(10px);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(255, 255, 255, 0.02);
    position: relative;
    height: 624px;
    /* Canvas (600) + Padding (20) + Border (4) */
}

#tetris {
    display: block;
    background: #000;
    border-radius: 4px;
    height: 100%;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    z-index: 10;
}

.level-up-overlay {
    pointer-events: none;
    background: transparent;
    backdrop-filter: none;
    z-index: 20;
}

.level-up-overlay h2 {
    font-size: 3rem;
    color: #00f2ff;
    text-shadow: 0 0 20px rgba(0, 242, 255, 0.8), 0 0 40px rgba(0, 242, 255, 0.5);
    animation: levelUpPop 1.5s ease-out forwards;
}

@keyframes levelUpPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    20% {
        transform: scale(1.1);
        opacity: 1;
    }

    80% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

.overlay h2 {
    font-size: 2rem;
    color: #ff0055;
    text-shadow: 0 0 20px rgba(255, 0, 85, 0.5);
    margin-bottom: 1rem;
}

.overlay p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

#restart-btn {
    background: linear-gradient(135deg, #00f2ff, #7000ff);
    border: none;
    border-radius: 8px;
    color: white;
    padding: 0.8rem 2rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

#restart-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.4);
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 180px;
}

.panel-section {
    background: var(--panel-color);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.2rem;
    text-align: center;
}

.panel-section h2 {
    font-size: 0.8rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 0.5rem;
    letter-spacing: 0.1rem;
}

.panel-section div {
    font-size: 1.5rem;
    font-weight: 700;
}

#next {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-top: 0.5rem;
}

.controls-hint {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.6;
    padding: 0 0.5rem;
}

#start-btn {
    background: linear-gradient(135deg, #00f2ff, #7000ff);
    border: none;
    border-radius: 12px;
    color: white;
    padding: 1rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.2);
}

#start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(0, 242, 255, 0.4);
}

#start-btn:active {
    transform: translateY(0);
}

/* Tetromino Colors & Glows */
.t-piece {
    color: #A000F0;
}

.i-piece {
    color: #00F0F0;
}

.o-piece {
    color: #F0F000;
}

.j-piece {
    color: #0000F0;
}

.l-piece {
    color: #F0A000;
}

.s-piece {
    color: #00F000;
}

.z-piece {
    color: #F00000;
}

/* Mobile Control Layout */
.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-top: 0.2rem;
    /* Reduced from 1rem */
    z-index: 5;
}

.control-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.ctrl-btn {
    width: 55px;
    /* Slightly smaller */
    height: 55px;
    background: rgba(255, 255, 255, 0.05);
    /* More transparent */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.5);
    /* Less intrusive color */
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(2px);
    transition: all 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:active {
    background: rgba(0, 242, 255, 0.2);
    color: white;
    transform: scale(0.9);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.3);
}

.hard-drop-btn {
    width: 180px;
    height: 45px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* Mobile Responsiveness - Horizontal Side-by-Side */
@media (max-width: 600px) {
    body {
        overflow: auto;
        align-items: center;
        padding: 0;
        display: flex;
        justify-content: center;
    }

    .container {
        padding: 0.5rem;
        gap: 0.5rem;
        transform: scale(0.9);
        transform-origin: center top;
        width: 100%;
        max-width: 100vw;
    }

    header h1 {
        font-size: 2rem;
        letter-spacing: 0.3rem;
        margin-bottom: 0.5rem;
    }

    main {
        display: flex !important;
        flex-direction: row !important;
        /* Force side-by-side */
        flex-wrap: nowrap !important;
        /* Prevent wrapping */
        justify-content: center;
        align-items: flex-start;
        gap: 0.8rem;
        width: 100%;
    }

    .game-container {
        height: 500px;
        /* Adjusted height */
        width: 200px;
        /* Adjusted width */
        padding: 5px;
        flex-shrink: 0;
    }

    #tetris {
        width: 100%;
        height: 100%;
    }

    .side-panel {
        width: 100px;
        /* Compact side panel */
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .panel-section {
        padding: 0.5rem;
    }

    .panel-section h2 {
        font-size: 0.55rem;
    }

    .panel-section div {
        font-size: 0.9rem;
    }

    #next {
        width: 50px;
        height: 50px;
    }

    .mobile-controls {
        display: flex;
        margin-top: 0.2rem;
    }

    .hard-drop-btn {
        width: 160px;
    }

    .overlay h2 {
        font-size: 1.5rem;
    }
}

@media (max-width: 420px) {
    .container {
        transform: scale(0.75);
    }
}

@media (max-width: 350px) {
    .container {
        transform: scale(0.6);
    }
}