:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --accent-primary: #8b5cf6;
    /* Violet */
    --accent-glow: rgba(139, 92, 246, 0.5);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --grid-line: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);

    /* Responsive Vars */
    --app-max-width: 500px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

.hidden {
    display: none !important;
}

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

#app {
    width: 100%;
    max-width: var(--app-max-width);
    height: 100%;
    max-height: 1000px;
    /* Limit height on massive screens */
    display: flex;
    flex-direction: column;
    padding: clamp(10px, 3vh, 20px);
    padding-top: calc(var(--safe-top) + clamp(10px, 2vh, 20px));
    padding-bottom: calc(var(--safe-bottom) + clamp(10px, 2vh, 20px));
    gap: clamp(10px, 2vh, 20px);
    position: relative;
    background: var(--bg-primary);
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.5);
    /* Card effect on desktop */
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.brand h1 {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    font-weight: 800;
    background: linear-gradient(135deg, #c084fc, #6366f1);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.05em;
    white-space: nowrap;
}

.stats-group {
    display: flex;
    gap: 20px;
}

.score-container {
    text-align: right;
}

.score-container .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score-container .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: 0 2px 10px var(--accent-glow);
    transition: transform 0.1s;
}

.score-container .value.pop {
    animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

    50% {
        transform: scale(1.5);
        color: var(--accent-primary);
    }

    100% {
        transform: scale(1);
    }
}

/* Main Board Area */
main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: var(--bg-secondary);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
}

#canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#grid-canvas,
#bg-canvas {
    position: absolute;
    border-radius: 8px;
}

#bg-canvas {
    z-index: 1;
}

#grid-canvas {
    z-index: 2;
}

#message-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 30px;
    z-index: 50;
    opacity: 1;
    transition: opacity 0.3s;
    padding: 20px;
    box-sizing: border-box;
}

#message-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#message-overlay h2 {
    font-size: clamp(1.6rem, 5vw, 2.5rem);
    font-weight: 900;
    margin: 0 auto 20px auto;
    /* Centered with bottom spacing */
    text-transform: uppercase;
    color: #f87171;
    text-shadow: 0 4px 20px rgba(248, 113, 113, 0.4);
    text-align: center;
    width: 90%;
    max-width: 600px;
    line-height: 1.2;
}

.btn-primary {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border: none;
    padding: 12px 32px;
    border-radius: 50px;
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--accent-glow);
    transition: transform 0.1s, box-shadow 0.1s;
}

.btn-primary:active {
    transform: scale(0.95);
    box-shadow: 0 2px 5px var(--accent-glow);
}

button:disabled {
    cursor: not-allowed;
    filter: grayscale(1);
    opacity: 0.6;
    box-shadow: none !important;
    transform: none !important;
}

/* Tray Area */
footer {
    height: clamp(100px, 18vh, 160px);
    background: var(--glass-bg);
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--glass-border);
    margin-top: auto;
    flex-shrink: 0;
}

#tray {
    display: flex;
    gap: 20px;
    width: 100%;
    justify-content: center;
}

.tray-figure {
    width: clamp(60px, 10vh, 100px);
    height: clamp(60px, 10vh, 100px);
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: grab;
    transition: transform 0.2s, background 0.2s;
}

.tray-figure:active {
    cursor: grabbing;
    transform: scale(0.9);
}

.tray-figure canvas {
    pointer-events: none;
}

/* Menu & Overlays */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Move content to top */
    z-index: 1000;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: 80px;
    /* Space for centered floating toggles */
}

.menu-overlay h2 {
    margin-top: 20px;
    margin-bottom: 2.5rem;
    font-size: 2.2rem;
    color: white;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.menu-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(1.1);
}

#main-menu {
    justify-content: center;
    padding-top: 0;
    /* Logo is fine centered */
}

.logo {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 900;
    background: linear-gradient(135deg, #60a5fa 0%, #a855f7 50%, #ec4899 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 15px rgba(168, 85, 247, 0.4));
    letter-spacing: -2px;
    margin-bottom: clamp(1rem, 5vh, 4rem);
}

.menu-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 4rem;
}

/* Floating Toggles - Centered at top */
.lang-btn.floating-lang,
.settings-btn.floating-settings {
    position: absolute;
    top: 20px;
    z-index: 1001;
}

.floating-lang {
    left: calc(50% - 47px);
    transform: translateX(-50%);
}

.floating-settings {
    left: calc(50% + 47px);
    transform: translateX(-50%);
}

.settings-btn,
.lang-btn {
    background: rgba(255, 255, 255, 0.1);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    font-weight: 700;
}

.settings-btn svg {
    width: 24px;
    height: 24px;
    display: block;
    stroke: white;
    transition: transform 0.6s ease;
}

.settings-btn:hover,
.lang-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.floating-settings:hover,
.floating-lang:hover {
    transform: translateX(-50%) scale(1.05);
    /* Important: keep translateX */
}

.settings-btn:hover svg {
    transform: rotate(90deg);
}

/* Language Menu */
.lang-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
}

.lang-grid .lang-btn {
    padding: 1rem;
    font-size: 1rem;
    width: 100%;
    height: auto;
}

.lang-grid .lang-btn:hover {
    transform: scale(1.02);
}

.lang-btn.active {
    background: rgba(96, 165, 250, 0.2);
    border-color: #60a5fa;
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.3);
}

/* Main Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
    max-width: 320px;
}

.menu-btn {
    padding: clamp(0.8rem, 2vh, 1.2rem);
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    font-weight: 700;
    color: white;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(5px);
    text-transform: uppercase;
    font-family: 'Outfit', sans-serif;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-5px) scale(1.02);
    border-color: #60a5fa;
    box-shadow: 0 10px 30px -10px rgba(96, 165, 250, 0.4);
}

/* Size & Level Selectors */
#size-selector,
#level-select {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.size-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 280px;
    margin-bottom: 2rem;
}

.size-btn {
    text-align: center;
    border-left: 5px solid #8b5cf6 !important;
}

/* Modes Colors */
#btn-online {
    border-left: 5px solid #10b981 !important;
}

.menu-btn[data-mode="infinite"] {
    border-left: 5px solid #60a5fa;
}

.menu-btn[data-mode="timed_2"] {
    border-left: 5px solid #06b6d4;
}

.menu-btn[data-mode="timed_5"] {
    border-left: 5px solid #a855f7;
}

.menu-btn[data-mode="timed_10"] {
    border-left: 5px solid #ec4899;
}

.menu-btn[data-mode="adventure"] {
    border-left: 5px solid #f59e0b;
}

/* Settings List */
.settings-list {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.music-selector {
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.selector-header {
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.selector-header:hover {
    background: rgba(255, 255, 255, 0.1);
}

.selector-header .chevron {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
    color: var(--accent-primary);
}

.music-selector.open .chevron {
    transform: rotate(180deg);
}

.selector-dropdown {
    max-height: 250px;
    overflow-y: auto;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease;
    opacity: 1;
}

.selector-dropdown.hidden {
    display: block !important;
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.sel-item {
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sel-item:hover {
    background: rgba(139, 92, 246, 0.2);
    color: white;
}

.sel-item.active {
    background: rgba(139, 92, 246, 0.3);
    color: var(--accent-primary);
    border-left: 3px solid var(--accent-primary);
}

.setting-item.vertical {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.setting-label-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

/* Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #374151;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: #6366f1;
}

input:checked+.slider:before {
    transform: translateX(22px);
}

/* Range Slider */
.range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 5px;
    background: #374151;
    outline: none;
    transition: background .2s;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #8b5cf6;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    transition: transform .1s;
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.range-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: #8b5cf6;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

/* Buttons General */
.btn-back {
    display: block;
    margin: auto auto 50px auto !important;
    /* Even more space at top, and some at bottom */
    padding: 0.8rem 2.5rem;
    background: transparent;
    border: 2px solid #ef4444;
    color: #ef4444;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 700;
    text-transform: uppercase;
    transition: all 0.3s;
}

.btn-back:hover {
    background: #ef4444;
    color: white;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
}

.btn-secondary {
    padding: 1rem 2.5rem;
    color: #e5e7eb;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.3s;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

.btn-secondary:hover {
    border-color: #94a3b8;
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* In-Game Menu Button */
#menu-btn-ingame {
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
    padding: 0.7rem 1.4rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    font-family: 'Outfit', sans-serif;
}

#menu-btn-ingame:hover {
    border-color: #60a5fa;
    color: #60a5fa;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(96, 165, 250, 0.2);
}

/* Level List Overlay */
#level-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    padding: 10px;
    margin-bottom: 2rem;
}

.level-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1.5rem 1rem;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.level-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #a855f7;
    transform: translateY(-3px);
}

.level-btn.locked {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
    border-color: rgba(255, 255, 255, 0.05);
}

.level-btn.locked:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.05);
}

.level-status-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.level-info strong {
    font-size: 1.1rem;
    color: white;
}

.vps-toggle {
    margin-top: 2rem;
    background: rgba(16, 185, 129, 0.1) !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
}

/* Mobile */
@media (max-width: 480px) {
    .brand h1 {
        font-size: 1.2rem;
    }
}

/* Landscape Mode on Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #app {
        max-width: 400px;
        /* Keep it vertical card style */
        padding: 5px;
        gap: 5px;
    }

    .logo {
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }

    .menu-buttons {
        gap: 0.5rem;
    }

    .menu-btn {
        padding: 0.5rem;
    }

    footer {
        height: 80px;
    }
}

/* Large Screens (Monitor/TV) */
@media (min-width: 1200px) {
    :root {
        --app-max-width: 550px;
    }

    #app {
        border: 1px solid var(--glass-border);
        border-radius: 30px;
        margin: 20px;
    }
}

/* --- Multiplayer Lobby --- */
.lobby-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.tab-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    padding: 0.5rem 1.5rem;
    border-radius: 2rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #000;
    box-shadow: 0 0 15px var(--primary-glow);
}

.id-display-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.code-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 1rem;
    border-radius: 1rem;
    font-family: monospace;
    font-size: 1.2rem;
    text-align: center;
    width: 100%;
    outline: none;
}

.code-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 0.8rem;
    width: 3.5rem;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lobby-status {
    min-height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 1rem;
}

.overlay-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: -12px;
    text-align: center;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#connect-btn {
    display: block;
    margin: 20px auto 0 auto;
    width: 100%;
    max-width: 200px;
    text-align: center;
}

.lobby-filters {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.rooms-list {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 45vh;
    overflow-y: auto;
    padding: 6px;
}

.room-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 12px;
    gap: 10px;
}

.room-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.room-name {
    font-weight: 700;
}

.room-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.room-actions-inline {
    display: flex;
    gap: 8px;
}

.room-btn {
    padding: 6px 10px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    cursor: pointer;
}

.room-btn.waiting {
    background: #22c55e;
    color: #0b1f10;
}

.room-btn.active {
    background: #1d4ed8;
    color: #e5edff;
}

.room-panel {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.room-title {
    font-size: 1.2rem;
    font-weight: 800;
}

.room-status {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.room-pending {
    color: #fbbf24;
    font-size: 0.9rem;
}

.room-actions {
    display: flex;
    gap: 10px;
}

#profile-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 10px;
    white-space: nowrap;
}

.auth-section {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
}

.profile-inline {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.profile-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-error {
    color: #f87171;
    font-size: 0.85rem;
    text-align: center;
}

/* --- Split Screen (Multiplayer) --- */
#app.multiplayer-mode {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    max-width: none;
    padding: clamp(10px, 2vh, 20px);
    box-sizing: border-box;
    gap: 10px;
}

/* Desktop Split Screen */
@media (min-width: 992px) {
    #app.multiplayer-mode {
        display: grid;
        grid-template-areas:
            "header header"
            "local remote"
            "footer .";
        /* Tray stays under local board */
        grid-template-columns: repeat(2, minmax(400px, 500px));
        grid-template-rows: auto auto auto;
        justify-content: center;
        /* Center the columns in the viewport */
        align-items: start;
        /* Top-align sections */
        gap: 30px 60px;
        /* Vertical gap 30, Horizontal gap 60 */
        padding: 40px;
        max-width: 1400px;
        margin: 0 auto;
        box-shadow: 0 0 100px rgba(0, 0, 0, 0.5);
        border-radius: 30px;
        height: auto;
        min-height: 95vh;
        margin-top: 2.5vh;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(20px);
    }
}

#app.multiplayer-mode .game-header {
    grid-area: header;
}

#app.multiplayer-mode .game-board-container {
    grid-area: local;
    width: 100%;
    height: 60vh;
    /* Fixed relative height for board area */
    display: flex;
    justify-content: center;
    align-items: center;
}

#app.multiplayer-mode #remote-board-container {
    grid-area: remote;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: start;
    /* Top-align opponent board with local */
    padding: 20px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-sizing: border-box;
    position: relative;
}

#app.multiplayer-mode #remote-canvas {
    max-width: 100%;
    max-height: 70vh;
    height: auto;
    object-fit: contain;
}

#app.multiplayer-mode .tray-container {
    grid-area: footer;
    width: 100%;
    margin-top: 20px;
}

#remote-board-container.hidden {
    display: none !important;
}

.remote-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.remote-score {
    color: var(--primary-color);
    text-shadow: 0 0 10px var(--primary-glow);
}

#remote-canvas {
    width: 100%;
    aspect-ratio: 1;
    /* Keep square */
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.8rem;
}

/* Mobile Multiplayer Refinements */
@media (max-width: 991px) {
    #app.multiplayer-mode .game-board-container {
        flex: 1;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 0;
    }

    /* Fixed PIP style relative to app container */
    #app.multiplayer-mode #remote-board-container {
        position: fixed;
        top: 80px;
        /* Below header */
        right: 15px;
        width: clamp(100px, 30vw, 160px);
        background: rgba(15, 23, 42, 0.85);
        backdrop-filter: blur(12px);
        border: 2px solid var(--accent-primary);
        border-radius: 12px;
        padding: 8px;
        z-index: 1000;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
        display: flex;
        flex-direction: column;
    }

    #app.multiplayer-mode #remote-canvas {
        width: 100% !important;
        height: auto !important;
    }

    .remote-header {
        font-size: 0.75rem;
        margin-bottom: 4px;
        justify-content: space-between;
    }
}

/* Remote Tray */
.remote-tray {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    min-height: 40px;
}

.remote-tray-figure {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

.remote-tray-figure canvas {
    width: 100%;
    height: 100%;
}

@media (min-width: 992px) {
    .remote-tray {
        gap: 10px;
        padding: 10px;
    }

    .remote-tray-figure {
        width: 50px;
        height: 50px;
    }
}
