:root {
    --bg-color: #050510;
    --glass-bg: rgba(15, 15, 30, 0.7);
    --glass-border: rgba(0, 240, 255, 0.3);
    --text-color: #ffffff;
    --accent-color: #00f0ff;
    --accent-glow: rgba(0, 240, 255, 0.8);
    --secondary-color: #d500f9;
    --secondary-glow: rgba(213, 0, 249, 0.8);
    --grid-line: rgba(255, 255, 255, 0.05);

    /* Tetromino Colors */
    --color-i: #00ffff;
    --color-j: #2de2e6;
    --color-l: #ffb86c;
    --color-o: #f9f871;
    --color-s: #00ff66;
    --color-t: #ff00ff;
    --color-z: #ff0055;
    --color-gray: #444444;
}

.hidden {
    display: none !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 50% 10%, rgba(0, 240, 255, 0.15) 0%, transparent 60%),
        radial-gradient(circle at 10% 90%, rgba(213, 0, 249, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 90% 90%, rgba(0, 240, 255, 0.1) 0%, transparent 50%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1400px;
    padding: 20px;
}

header {
    margin-bottom: 30px;
    text-align: center;
}

@media (min-width: 901px) {

    /* Align Title with Board Center in Single Player Mode using JS class */
    body.single-mode header h1 {
        transform: translateX(-110px);
        /* Slightly adjusted from 115px */
        display: inline-block;
    }
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 8px;
    text-transform: uppercase;
    margin: 0;
}

@media (max-width: 600px) {
    header h1 {
        font-size: 1.8rem;
        /* Smaller font on mobile */
        letter-spacing: 4px;
        margin-bottom: 10px;
        position: relative;
        z-index: 10;
    }

    /* Fix for potential double rendering or layout shifts */
    .logo-animation {
        display: none;
        /* Hide animated logo blocks on mobile to save space/reduce glitches */
    }
}

header h1 .highlight {
    color: transparent;
    -webkit-text-stroke: 2px var(--accent-color);
    text-shadow: 0 0 20px var(--accent-glow);
}

/* Server Status Dot */
#server-status-dot {
    color: red;
    /* Default disconnected */
    transition: color 0.5s ease;
    text-shadow: 0 0 10px red;
    font-weight: bold;
}

#server-status-dot.connected {
    color: #00ff66;
    /* Green connected */
    text-shadow: 0 0 10px #00ff66;
}

/* Screen Transitions */
.screen {
    width: 100%;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Main Menu (No Border) */
.main-menu {
    width: 100%;
    max-width: 650px;
    background: transparent;
    border: none;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.menu-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 30px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    max-width: 800px;
    margin: 0 auto;
    /* Ensure centering */
}

.input-stack {
    display: flex;
    flex-direction: column;
    gap: 25px;
    /* Increased gap */
    width: 100%;
}

.text-btn {
    margin-top: 15px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #aaa;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
}

.text-btn:hover {
    border-color: #fff;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Rank Cards */
.top-ranks-display {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    /* Equal width for all 3 cards */
    gap: 15px;
    width: 100%;
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .top-ranks-display {
        grid-template-columns: 1fr;
        /* Stack vertically on mobile */
        gap: 10px;
    }

    .rank-card {
        padding: 10px;
        display: flex;
        justify-content: space-between;
        /* Horizontal layout inside card for compactness */
        align-items: center;
    }

    .rank-title {
        margin-bottom: 0;
        font-size: 0.8rem;
    }

    .rank-name {
        font-size: 1.1rem;
        text-align: right;
    }
}

.rank-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px 10px;
    border-radius: 15px;
    text-align: center;
    transition: all 0.3s;
    cursor: pointer;
}

.rank-card:hover {
    background: rgba(0, 240, 255, 0.1);
    border-color: var(--accent-color);
    transform: translateY(-5px);
    box-shadow: 0 0 15px var(--accent-glow);
}

.rank-title {
    display: block;
    font-size: 0.7rem;
    color: #888;
    margin-bottom: 8px;
    letter-spacing: 1px;
    white-space: nowrap;
    /* Prevent wrapping */
}

.rank-name {
    display: flex;
    /* Changed from block to flex for column layout if needed, or just block */
    flex-direction: column;
    gap: 2px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-glow);
    white-space: normal;
    /* Allow wrapping or multi-line */
}

/* Modal Ranking List Name */
.r-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-glow);
}

/* Buttons */
.glow-btn {
    position: relative;
    padding: 15px 40px;
    font-size: 1.2rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #fff;
    background: transparent;
    border: 2px solid var(--accent-color);
    border-radius: 50px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s;
    box-shadow: 0 0 15px var(--accent-glow);
    width: 100%;
    margin-bottom: 15px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

#start-btn {
    width: 70%;
    /* Reduced width */
    margin-left: auto;
    margin-right: auto;
}

.glow-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 0 25px var(--accent-glow);
    background: rgba(0, 240, 255, 0.1);
}

.secondary-glow {
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px var(--secondary-glow);
}

.secondary-glow:hover {
    background: rgba(213, 0, 249, 0.1);
    box-shadow: 0 0 25px var(--secondary-glow);
}

/* GAME INTERFACE - 3 COLUMN LAYOUT */
.game-interface {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-flow: row wrap;
    /* Allow wrapping */
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
    padding-top: 10px;
}

/* Columns */
.player-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 480px;
    flex-shrink: 1;
    /* Allow shrinking */
}

.stats-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    /* Flexible width */
    max-width: 200px;
    margin-top: 60px;
    flex-shrink: 0;
}

/* Canvas Scaling */
#game-canvas,
#opponent-canvas {
    width: 100%;
    /* Take full available width of container */
    height: auto;
    max-width: 450px;
    /* Don't exceed native resolution width too much */
    max-height: 70vh;
    /* Strictly cap height */
    aspect-ratio: 1 / 2;
    margin: 0 auto;
    display: block;
    object-fit: contain;
}

.gesture-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 400;
    touch-action: none;
    display: none;
}

/* Mobile / Responsive Adjustments */
/* Mobile / Responsive Adjustments */
/* Mobile / Responsive Adjustments */
@media (max-width: 900px) {
    .app-container {
        padding: 5px;
        width: 100%;
        overflow-x: hidden;
    }

    .game-interface {
        flex-direction: row;
        /* Side-by-side layout */
        align-items: flex-start;
        justify-content: center;
        gap: 5px;
        /* Minimal gap */
        width: 100%;
    }

    /* Player Column (Game Board) - Left Side */
    .player-column {
        width: 70%;
        /* Majority width */
        max-width: none;
        padding: 0;
        margin: 0;
        flex: 0 0 70%;
    }

    /* Stats Column - Right Side */
    .stats-column {
        flex-direction: column;
        /* Vertical stack */
        flex-wrap: nowrap;
        width: 28%;
        /* Remaining width */
        max-width: none;
        margin-top: 40px;
        /* Align with board content below header */
        gap: 5px;
        order: 0;
        /* Default order (Right) */
        flex: 0 0 28%;
    }

    /* Adjust elements to fit narrow column */
    .stat-card {
        padding: 5px;
        min-width: 0;
        /* Allow shrinking */
        width: 100%;
    }

    .stat-card canvas {
        width: 100% !important;
        /* Force fit */
        height: auto !important;
        max-height: 60px;
    }

    .stat-grid {
        display: flex;
        flex-direction: column;
        /* Stack scores vertically */
        gap: 5px;
        width: 100%;
    }

    .stat-item {
        padding: 5px;
        min-width: 0;
        width: 100%;
        font-size: 0.8rem;
    }

    .stat-label {
        font-size: 0.6rem;
        margin-bottom: 2px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .center-controls {
        width: 100%;
        justify-content: center;
        margin-top: 5px;
        flex-wrap: wrap;
    }

    .icon-btn {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    /* Force canvas to fit */
    .game-board-wrapper {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 2px;
        border-width: 2px;
    }

    #game-canvas {
        width: 100%;
        height: auto;
        max-height: 80vh;
        /* Maximize height */
    }

    /* Column Header Adjustments */
    .column-header {
        justify-content: center;
        position: relative;
        height: 30px;
        margin-bottom: 5px;
    }

    .header-controls-left {
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
    }

    .column-header h3 {
        margin: 0;
        font-size: 0.9rem;
    }

    .glow-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }

    .room-list {
        grid-template-columns: 1fr;
    }
}

.column-header h3 {
    margin-left: auto;
    /* Push title to right or center? User said "Left placement" for buttons. Let's keep title naturally flow or push it? */
    /* If we want buttons left, title right? Or title next to it? */
    /* "Player 1" usually center or left. Let's just remove margin-left auto to keep them side by side left aligned, or spacer? */
    /* Actually, the previous layout was space-between. Now we interpret "buttons left". */
    /* Let's try: Buttons Left, Title Right (via margin-left: auto on title) */
    margin-left: auto;
    font-size: 1.2rem;
    color: var(--text-color);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

/* Board Wrapper */
.game-board-wrapper {
    position: relative;
    padding: 5px;
    background: #000;
    border: 3px solid var(--accent-color);
    border-radius: 10px;
    box-shadow: 0 0 20px var(--accent-glow);
}

.opponent-wrapper {
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px var(--secondary-glow);
}

canvas {
    display: block;
    background: #000;
}

/* Stat Cards */
.stat-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 15px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    position: relative;
}

.stat-label {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
    letter-spacing: 2px;
}

.stat-grid {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 10px;
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent-color);
}

/* Center Controls (Toggles) */
.center-controls {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.icon-btn:hover {
    border-color: var(--accent-color);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: translateY(-2px);
}

.icon-btn.danger:hover {
    border-color: #ff0055;
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.5);
}

.small-toggle {
    width: 32px;
    height: 32px;
    font-size: 1rem;
    border-radius: 50%;
}

/* Lobby & Waiting Room (No Borders) */
.lobby-container,
.waiting-container {
    width: 100%;
    max-width: 900px;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Apply box style to inner content logic if needed, but for now just removing outer border as requested */
/* If content needs background, apply to children */

.room-list {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.room-item {
    background: var(--glass-bg);
    /* Content box has bg */
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 20px;
    transition: all 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 15px;
}

.room-item:hover {
    background: rgba(0, 240, 255, 0.05);
    border-color: var(--accent-color);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
    transform: scale(1.02);
}

/* Waiting Room Slots */
.players-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    width: 100%;
    margin: 40px 0;
}

.player-slot {
    width: 250px;
    background: var(--glass-bg);
    border: 2px dashed var(--glass-border);
    border-radius: 20px;
    padding: 40px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: all 0.3s;
}

.player-slot.host {
    border-style: solid;
    border-color: var(--accent-color);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
}

.player-slot.occupied {
    border-style: solid;
    border-color: var(--secondary-color);
    box-shadow: 0 0 20px rgba(213, 0, 249, 0.2);
}

.vs-divider {
    font-size: 3rem;
    font-weight: 900;
    font-style: italic;
    color: var(--secondary-color);
    text-shadow: 0 0 20px var(--secondary-glow);
    animation: vsPulse 1.5s infinite;
}

@keyframes vsPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Inputs */
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 15px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: #fff;
    font-size: 1.1rem;
    outline: none;
    transition: all 0.3s;
    text-align: center;
}

input[type="text"]:focus,
input[type="password"]:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-color);
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Modals */
.modal {
    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: 2000;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: #101020;
    border: 2px solid var(--glass-border);
    border-radius: 30px;
    width: 90%;
    max-width: 500px;
    padding: 30px;
    box-shadow: 0 0 50px rgba(0, 240, 255, 0.2);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-header {
    width: 100%;
    display: flex;
    justify-content: center;
    /* Center Title */
    align-items: center;
    position: relative;
    margin-bottom: 20px;
}

.lobby-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.lobby-actions-stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.close-btn {
    position: absolute;
    right: 0;
    top: -10px;
    background: rgba(0, 240, 255, 0.1);
    /* Cyan bg */
    border: 2px solid var(--accent-color);
    /* Cyan border */
    color: var(--accent-color);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Ranking Tabs */
.ranking-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    background: transparent;
    padding: 0;
    width: 100%;
}

.rank-tab {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #aaa;
    padding: 12px;
    font-weight: 700;
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.3s;
    font-size: 0.9rem;
}

.rank-tab:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.rank-tab.active {
    background: var(--accent-color);
    color: #000;
    border-color: var(--accent-color);
    box-shadow: 0 0 15px var(--accent-glow);
}

.close-btn:hover {
    background: var(--accent-color);
    color: #000;
    transform: rotate(90deg);
}

/* Game Creation Modal Specifics */
.mode-selector {
    display: flex;
    gap: 15px;
    width: 100%;
}

.radio-container {
    flex: 1;
    cursor: pointer;
    position: relative;
}

.radio-container input {
    display: none;
}

.mode-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    transition: all 0.3s;
}

.radio-container input:checked+.radio-mark+.mode-label {
    border-color: var(--accent-color);
    background: rgba(0, 240, 255, 0.1);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.3);
}

.mode-label strong {
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 5px;
}

.mode-label span {
    font-size: 0.8rem;
    color: #aaa;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 10px);
    height: calc(100% - 10px);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 10px;
    text-align: center;
}

/* Mobile & Virtual Controls */
.virtual-controls {
    display: none;
    /* Hidden by default on PC */
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
}

@media (max-width: 768px) {
    .virtual-controls {
        display: block;
        width: 100%;
        max-width: 400px;
        bottom: 50px;
        /* Higher up */
    }

    /* Bigger buttons for mobile */
    .vc-btn {
        width: 65px;
        height: 65px;
        font-size: 1.5rem;
        background: rgba(255, 255, 255, 0.1);
        border: 2px solid rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        color: white;
        display: flex;
        justify-content: center;
        align-items: center;
        touch-action: manipulation;
        -webkit-user-select: none;
        user-select: none;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    }

    .vc-btn:active,
    .vc-btn.active {
        background: var(--accent-color);
        color: #000;
        transform: scale(0.95);
    }

    .vc-row {
        display: flex;
        justify-content: center;
        gap: 20px;
        margin-bottom: 15px;
    }

    /* Layout Adjustments for VS Mode on Mobile */
    .game-interface.vs-active {
        display: grid;
        grid-template-columns: 68% 32%;
        /* Increase local player width (approx 2/3 vs 1/3) */
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "local stats"
            "local opponent";
        gap: 2px;
        padding-top: 5px;
        width: 100%;
        height: 85vh;
        /* Constrain height to viewport */
        overflow: hidden;
        align-items: start;
    }

    .game-interface.vs-active .local-player-column {
        grid-area: local;
        width: 100%;
        flex: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
        padding-right: 2px;
    }

    .game-interface.vs-active .stats-column {
        grid-area: stats;
        display: flex !important;
        /* Force show */
        flex-direction: row;
        /* Horizontal stats */
        flex-wrap: wrap;
        width: 100%;
        margin-top: 0;
        gap: 2px;
        justify-content: center;
        align-content: center;
        max-height: 20%;
        /* Limit height */
    }

    .game-interface.vs-active .opponent-player-column {
        grid-area: opponent;
        width: 100%;
        flex: none;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        /* Align to top of cell */
        height: 100%;
    }

    /* Adjust canvases in VS Mobile Grid */
    .game-interface.vs-active #game-canvas {
        width: 100%;
        height: auto;
        max-height: 85vh;
        /* Maximize height */
        object-fit: contain;
    }

    .game-interface.vs-active #opponent-canvas {
        width: 90%;
        /* Fill the narrower column */
        height: auto;
        max-height: 35vh;
        object-fit: contain;
        align-self: center;
        /* Center in its cell */
    }

    /* Compact Stats Elements */
    .game-interface.vs-active .stat-card {
        padding: 2px;
        width: 45%;
        border: none;
        background: transparent;
    }

    .game-interface.vs-active .stat-label {
        font-size: 0.5rem;
    }

    .game-interface.vs-active .stat-card canvas {
        max-height: 40px;
    }

    .game-interface.vs-active .stat-grid {
        display: none;
        /* Hide numerical score details on mobile VS to save space, or make tiny */
    }

    .game-interface.vs-active .center-controls {
        display: none;
        /* Hide toggle buttons in VS Mobile */
    }

    .game-interface.vs-active .column-header h3 {
        font-size: 0.7rem;
        margin-bottom: 2px;
    }

    /* =========================================
       MOBILE SINGLE PLAY OPTIMIZATION (v2.4 Refined)
       ========================================= */

    /* Root container full height handling */
    .app-container {
        height: 100dvh;
        padding: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    header {
        flex: 0 0 auto;
        margin-bottom: 5px;
        padding-top: 10px;
    }

    /* Main Interface Wrapper */
    .game-interface:not(.vs-active) {
        flex: 1;
        /* Fill remaining height after header */
        display: flex;
        flex-flow: row nowrap !important;
        justify-content: center;
        align-items: stretch;
        width: 100%;
        height: 100%;
        /* Fill container */
        padding: 0 5px 50px 5px;
        /* Bottom padding for safety */
        overflow: hidden;
        gap: 0;
        margin: 0;
    }

    /* 1. Left Section: Game Board + Controls */
    .game-interface:not(.vs-active) .player-column {
        flex: 0 0 68%;
        max-width: 68%;
        height: 100%;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        /* Stack Board & Controls */
        justify-content: flex-end;
        /* Align to bottom */
    }

    .game-interface:not(.vs-active) .column-header {
        display: none;
    }

    /* Board Wrapper: Flexible height */
    .game-interface:not(.vs-active) .game-board-wrapper {
        flex: 1 1 auto;
        /* Grow and Shrink */
        width: 100%;
        min-height: 0;
        /* Important for scroll containers */
        padding: 0;
        border: none;
        background: #000;
        display: flex;
        align-items: flex-end;
        /* Align canvas to bottom so it touches controls */
        justify-content: center;
        overflow: hidden;
    }

    /* Canvas: Prioritize Vertical Fill to avoid bottom gaps */
    .game-interface:not(.vs-active) #game-canvas {
        height: 100%;
        /* Force full height use */
        width: 100%;
        object-fit: contain;
        /* Maintain aspect ratio, adds side bars if needed */
        max-width: 100%;
    }

    /* 2. Right Section: Stats */
    .game-interface:not(.vs-active) .stats-column {
        flex: 0 0 32%;
        max-width: 32%;
        height: 100%;
        margin: 0;
        display: flex;
        flex-direction: column;
        gap: 5px;
        padding: 0 0 0 5px;
        /* Left padding as gap */
        background: transparent;
        border-left: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* Stats Styling - FIX ASPECT RATIO */
    .game-interface:not(.vs-active) .stat-card {
        width: 100%;
        padding: 5px;
        background: rgba(255, 255, 255, 0.05);
        border: none;
        border-radius: 6px;
        margin-bottom: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .game-interface:not(.vs-active) .stat-card canvas {
        width: auto !important;
        /* Allow natural width */
        height: 45px !important;
        /* Fixed height to prevent stretching */
        aspect-ratio: auto;
        /* Preserve ratio */
        display: block;
    }

    .game-interface:not(.vs-active) .stat-label {
        font-size: 0.6rem;
        text-align: center;
        width: 100%;
        display: block;
    }

    .game-interface:not(.vs-active) .stat-value {
        font-size: 1rem;
    }

    /* Controls: Natural Flow */
    .game-interface:not(.vs-active) .virtual-controls {
        /* display: block is default, .hidden will override it naturally */
        width: 100%;
        flex: 0 0 auto;
        /* Don't shrink */
        padding: 5px 0 0 0;
        background: transparent;
        z-index: 50;
    }

    /* Ensure hidden class works */
    .game-interface:not(.vs-active) .virtual-controls.hidden {
        display: none !important;
    }

    .game-interface:not(.vs-active) .vc-row {
        gap: 3px;
        margin-bottom: 3px;
    }

    .game-interface:not(.vs-active) .vc-btn {
        height: 50px;
        font-size: 0.8rem;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.15);
    }

    .game-interface:not(.vs-active) .center-controls {
        display: none;
    }

    .special-txt-btn {
        font-size: 0.9rem;
        letter-spacing: 1px;
    }
}

/* =========================================
   NEW RANKING LIST STYLES (CARD LAYOUT)
   ========================================= */

.ranking-list-container {
    width: 100%;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
    margin-top: 10px;
}

/* Scrollbar styling */
.ranking-list-container::-webkit-scrollbar {
    width: 6px;
}

.ranking-list-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.ranking-list-container::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

/* Ranking Item Card */
.ranking-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 10px;
    transition: all 0.2s;
}

.ranking-item:hover {
    background: rgba(255, 255, 255, 0.08);
    /* Hover effect */
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateX(2px);
}

/* Columns & Labels */
.rank-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.rank-label {
    font-size: 0.7rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 2px;
}

/* Specific Column Widths */
.col-rank {
    width: 50px;
}

.col-user {
    flex: 2;
    align-items: flex-start;
    padding-left: 20px;
}

.col-score {
    flex: 1;
    align-items: flex-end;
}

.col-level {
    width: 60px;
}

.col-date {
    width: 100px;
    font-size: 0.8rem;
    color: #aaa;
    align-items: flex-end;
    text-align: right;
}

/* Data Text Styles */
.rank-num {
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

.rank-user {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1;
    text-align: left;
}

.rank-score-val {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
    white-space: nowrap;
}

.rank-level-val {
    font-size: 0.9rem;
    color: var(--secondary-color);
    font-weight: 600;
    line-height: 1;
}

.rank-date-val {
    font-size: 0.75rem;
    color: #aaa;
    text-align: right;
}

/* Top 3 Styling */
.rank-1 {
    border-color: rgba(255, 215, 0, 0.5);
    background: rgba(255, 215, 0, 0.05);
}

.rank-2 {
    border-color: rgba(192, 192, 192, 0.5);
    background: rgba(192, 192, 192, 0.05);
}

.rank-3 {
    border-color: rgba(205, 127, 50, 0.5);
    background: rgba(205, 127, 50, 0.05);
}

.rank-1 .rank-num {
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.rank-2 .rank-num {
    color: #C0C0C0;
    text-shadow: 0 0 10px rgba(192, 192, 192, 0.5);
}

.rank-3 .rank-num {
    color: #CD7F32;
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.5);
}

/* No Ranking Message */
.no-ranking {
    text-align: center;
    padding: 30px;
    color: #666;
    font-style: italic;
}