:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --board-bg: rgba(30, 41, 59, 0.7);
    --cell-bg: rgba(51, 65, 85, 0.5);
    --board-padding: 15px;
    --transition-speed: 100ms;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: #0f172a;
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    user-select: none;
    padding: 20px 0;
}

/* --- GAME UI STYLES --- */
.main-header {
    text-align: center;
    margin-bottom: 20px;
    width: 100%;
}

.title {
    font-size: 3.5rem;
    font-weight: 900;
    line-height: 1;
    background: linear-gradient(to right, #38bdf8, #e879f9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 15px rgba(232, 121, 249, 0.2);
}

.subtitle {
    font-size: 2rem;
    color: #facc15;
    -webkit-text-fill-color: #facc15;
    text-shadow: 0 0 10px rgba(250, 204, 21, 0.5);
}

.instructions {
    color: #94a3b8;
    font-size: 1rem;
}

.boards-wrapper {
    display: flex;
    gap: 50px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    width: 100%;
    max-width: 1100px;
    padding: 0 20px;
}

.player-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 440px;
}

.player-section h2 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.controls {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-top: 5px;
}

.player1-section h2 { color: #38bdf8; }
.player2-section h2 { color: #e879f9; }

.score-box {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 20px;
    text-align: center;
    min-width: 120px;
    margin-bottom: 20px;
}

.player1-section .score-box { border-color: rgba(56, 189, 248, 0.3); box-shadow: 0 0 15px rgba(56, 189, 248, 0.2); }
.player2-section .score-box { border-color: rgba(232, 121, 249, 0.3); box-shadow: 0 0 15px rgba(232, 121, 249, 0.2); }

.score-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #cbd5e1;
    margin-bottom: 4px;
}

.score-value {
    font-size: 1.7rem;
    font-weight: 900;
}

.game-container {
    position: relative;
    background: var(--board-bg);
    padding: var(--board-padding);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    aspect-ratio: 1;
    touch-action: none;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 15px;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.tile-container {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2;
    pointer-events: none;
}

.tile-2 { --bg: #38bdf8; --text: #1e293b; }
.tile-4 { --bg: #818cf8; --text: #1e293b; }
.tile-8 { --bg: #c084fc; --text: #fff; }
.tile-16 { --bg: #e879f9; --text: #fff; }
.tile-32 { --bg: #f472b6; --text: #fff; }
.tile-64 { --bg: #fb7185; --text: #fff; }
.tile-128 { --bg: #facc15; --text: #1e293b; }
.tile-256 { --bg: #fde047; --text: #1e293b; }
.tile-512 { --bg: #a3e635; --text: #1e293b; }
.tile-1024 { --bg: #4ade80; --text: #1e293b; }
.tile-2048 { --bg: #2dd4bf; --text: #fff; }
.tile-super { --bg: #22d3ee; --text: #fff; }

.tile {
    position: absolute;
    top: calc(var(--board-padding) + var(--y) * (100% - var(--board-padding)) / 4);
    left: calc(var(--board-padding) + var(--x) * (100% - var(--board-padding)) / 4);
    width: calc((100% - 5 * var(--board-padding)) / 4);
    height: calc((100% - 5 * var(--board-padding)) / 4);
    
    background: var(--bg, #fff);
    color: var(--text, #1e293b);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.2rem;
    font-weight: 900;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1), inset 0 2px 0 rgba(255,255,255,0.2);
    
    transition: var(--transition-speed) ease-in-out;
    transition-property: top, left;
}

.tile.tile-128, .tile.tile-256, .tile.tile-512 { font-size: 1.8rem; }
.tile.tile-1024, .tile.tile-2048, .tile.tile-super { font-size: 1.4rem; }

.tile-inner {
    width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
}

@keyframes appear { 0% { opacity: 0; transform: scale(0); } 100% { opacity: 1; transform: scale(1); } }
.tile-new .tile-inner { animation: appear 150ms ease 100ms backwards; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
.tile-merged .tile-inner { animation: pop 150ms ease 100ms backwards; }

.game-message {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    z-index: 100;
    backdrop-filter: blur(5px);
    border-radius: 16px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.game-message.active { display: flex; animation: fade-in 0.5s ease; }
.game-message p {
    font-size: 3rem;
    font-weight: 900;
    color: #ef4444;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
    text-transform: uppercase;
}

@keyframes fade-in { 0% { opacity: 0; } 100% { opacity: 1; } }

/* --- LANDING UI STYLES --- */
.landing-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #1e1b4b 0%, #0f172a 50%, #312e81 100%);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    overflow: hidden;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.cube {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    font-weight: 900;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: floatCube linear infinite;
    opacity: 0.15;
}
.cube-2 { width: 80px; height: 80px; background: #38bdf8; font-size: 2rem; color: #fff; left: 10%; top: 20%; animation-duration: 12s; }
.cube-4 { width: 120px; height: 120px; background: #c084fc; font-size: 3.5rem; color: #fff; right: 15%; top: 15%; animation-duration: 18s; animation-direction: reverse; }
.cube-8 { width: 100px; height: 100px; background: #facc15; font-size: 3rem; color: #1e293b; left: 20%; top: 70%; animation-duration: 15s; }
.cube-2048 { width: 150px; height: 150px; background: #f472b6; font-size: 4rem; color: #fff; right: 10%; bottom: 10%; animation-duration: 20s; animation-direction: reverse; }

@keyframes floatCube {
    0% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-30px) rotate(180deg); }
    100% { transform: translateY(0) rotate(360deg); }
}

.glass-panel {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 24px;
    padding: 50px;
    text-align: center;
    width: 90%;
    max-width: 500px;
    z-index: 10;
}

.hero-title {
    font-size: 6rem;
    font-weight: 900;
    line-height: 0.9;
    color: #fff;
    text-shadow: 0 10px 20px rgba(0,0,0,0.5);
    margin-bottom: 5px;
}
.hero-subtitle {
    display: block;
    font-size: 1.8rem;
    background: linear-gradient(to right, #38bdf8, #e879f9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 12px;
}

.hero-desc {
    color: #cbd5e1;
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.lang-switcher {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
}
.lang-switcher button {
    background: rgba(15, 23, 42, 0.6);
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}
.lang-switcher button.active {
    background: #38bdf8;
    color: #0f172a;
    border-color: #38bdf8;
}
.lang-switcher button:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

.nickname-input {
    width: 100%;
    padding: 18px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.8);
    border: 2px solid #38bdf8;
    color: white;
    font-size: 1.3rem;
    text-align: center;
    outline: none;
    font-family: inherit;
    font-weight: 800;
    margin-bottom: 25px;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
    transition: all 0.3s ease;
}

.nickname-input:focus {
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.6);
    border-color: #e879f9;
}

.menu-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.btn-mega {
    width: 100%;
    background: linear-gradient(135deg, #10b981 0%, #3b82f6 100%);
    color: white;
    border: none;
    padding: 20px;
    border-radius: 16px;
    font-size: 1.4rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
    transition: all 0.3s ease;
    margin-bottom: 10px;
    font-family: inherit;
}
.btn-mega small {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.9;
    margin-top: 5px;
}
.btn-mega:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 15px 30px rgba(16, 185, 129, 0.6);
}

.divider {
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 700;
    margin: 20px 0;
    letter-spacing: 2px;
}

.room-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.btn-standard {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 15px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}
.btn-standard:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}
.alt-btn {
    background: #e879f9;
    border-color: #e879f9;
    color: #fff;
}
.alt-btn:hover {
    background: #d946ef;
}

.join-box {
    display: flex;
    gap: 10px;
}

.join-box input {
    flex: 2;
    padding: 15px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2rem;
    text-align: center;
    outline: none;
    font-family: inherit;
    font-weight: 700;
    transition: border-color 0.2s;
    text-transform: uppercase;
}
.join-box input:focus { border-color: #e879f9; }
.join-box button { flex: 1; margin: 0; }

body[data-current-lang="de"] .room-actions .btn-standard,
body[data-current-lang="fr"] .room-actions .btn-standard {
    font-size: 0.75rem;
    padding: 12px 5px;
    letter-spacing: -0.5px;
}

.room-code-display {
    font-size: 4rem;
    color: #facc15;
    margin: 20px 0;
    letter-spacing: 15px;
    font-weight: 900;
    text-shadow: 0 0 20px rgba(250,204,21,0.3);
}

.loader {
    width: 60px; height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.1);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

#matchmaking-status {
    color: #ef4444;
    margin-top: 15px;
    font-weight: 700;
    min-height: 20px;
}

.server-status {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: #10b981;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-top: 10px;
    margin-bottom: 5px;
    gap: 8px;
    z-index: 3000;
    transition: all 0.3s ease;
}
.server-status.offline {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}
.pulse-dot {
    width: 8px; height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
    animation: pulse 2s infinite;
}
.server-status.offline .pulse-dot {
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
    animation: none;
}
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); } 70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }

@media screen and (max-width: 950px) {
    .boards-wrapper { flex-direction: column; align-items: center; gap: 30px; }
}

@media screen and (max-width: 540px) {
    body { padding: 0; margin: 0; }
    .boards-wrapper { padding: 10px; display: flex; flex-direction: column; width: 100%; max-width: 500px; margin: 0 auto; gap: 15px; }
    
    .title { font-size: 2.2rem; }
    .subtitle { font-size: 1.2rem; }
    
    .player1-section { 
        max-width: 100%; 
        width: 100%;
        order: 2; 
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: "title score" "board board";
        align-items: center;
        gap: 10px;
        background: rgba(30, 41, 59, 0.4);
        border-radius: 16px;
        border: 1px solid rgba(255, 255, 255, 0.05);
        padding: 15px;
        box-sizing: border-box;
    }
    .player1-section h2 { grid-area: title; text-align: left; font-size: 1.1rem; margin: 0; line-height: 1.2; }
    .player1-section .score-box { grid-area: score; min-width: 80px; padding: 6px 12px; margin: 0; }
    .player1-section .score-label { font-size: 0.6rem; margin-bottom: 2px; }
    .player1-section .score-value { font-size: 1.4rem; }
    .player1-section .game-container { grid-area: board; padding: 8px; --board-padding: 8px; border-radius: 12px; width: 100%; margin: 0; }
    .player1-section .grid-container { gap: 8px; }
    .player1-section .tile { font-size: 1.6rem; }
    .player1-section .tile.tile-128, .player1-section .tile.tile-256, .player1-section .tile.tile-512 { font-size: 1.3rem; }
    .player1-section .tile.tile-1024, .player1-section .tile.tile-2048, .player1-section .tile.tile-super { font-size: 1rem; }
    .player1-section .game-message p { font-size: 2.2rem; }
    
    .player2-section { order: 1; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; width: 100%; gap: 12px; padding: 5px 10px; background: rgba(30, 41, 59, 0.4); border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.05); }
    .player2-section h2 { font-size: 1.1rem; margin: 0; text-align: right; flex: 1; }
    .player2-section .controls { display: none; }
    .player2-section .score-box { min-width: unset; padding: 4px 10px; margin: 0; border-radius: 6px; }
    .player2-section .score-label { font-size: 0.5rem; }
    .player2-section .score-value { font-size: 1.1rem; }
    .player2-section .game-container { padding: 3px; --board-padding: 3px; border-radius: 6px; width: 70px; border: 2px solid rgba(232, 121, 249, 0.4); box-shadow: 0 4px 10px rgba(0,0,0,0.5); aspect-ratio: 1; flex-shrink: 0; }
    .player2-section .grid-container { gap: 3px; }
    .player2-section .grid-cell { border-radius: 2px; }
    .player2-section .tile { font-size: 0.5rem !important; border-radius: 2px; }
    .player2-section .game-message { border-radius: 6px; }
    .player2-section .game-message p { font-size: 0.65rem; text-shadow: none; font-weight: 800; line-height: 1.1; }

    .glass-panel { padding: 20px 15px; width: 95%; border-radius: 16px; margin: auto; }
    .hero-title { font-size: 3.2rem; display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-bottom: 5px; }
    .hero-subtitle { display: inline-block; font-size: 1.2rem; letter-spacing: 1px; }
    .hero-desc { font-size: 0.95rem; margin-bottom: 15px; }
    
    .nickname-input { padding: 12px; font-size: 1.1rem; margin-bottom: 15px; }
    .btn-mega { font-size: 1.1rem; padding: 14px 10px; white-space: normal; line-height: 1.2; }
    .btn-mega small { margin-top: 3px; font-size: 0.8rem; }
    .divider { margin: 15px 0; }
    .btn-standard { font-size: 1rem; padding: 12px; }
    
    .join-box { flex-direction: row; gap: 5px; width: 100%; }
    .join-box input { padding: 10px; font-size: 1rem; flex: 0 0 175px; width: 175px; text-align: center; }
    .join-box button { flex: 1; min-width: 0; padding: 10px 4px; font-size: 0.8rem; word-break: break-all; white-space: normal; line-height: 1.1; }
    
    .lang-switcher { margin-top: 15px; flex-wrap: wrap; width: 100%; justify-content: center; }
    .lang-switcher button { padding: 6px 4px; font-size: 0.8rem; flex: 1; text-align: center; }
    
    .room-code-display { font-size: 2.5rem; letter-spacing: 3px; margin: 10px 0; }
    .cube { display: none; } 
}

@media screen and (max-height: 500px) and (orientation: landscape) {
    body { padding: 0; margin: 0; overflow: hidden; }
    
    /* Landing UI */
    .glass-panel { padding: 8px 15px; width: 90%; max-width: 600px; display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 5px; }
    .hero-title { font-size: 1.8rem; margin: 0; display: inline-block; }
    .hero-subtitle { font-size: 0.9rem; letter-spacing: 2px; display: inline-block; }
    .hero-desc { display: none; }
    .nickname-input { margin: 0; padding: 6px; font-size: 0.9rem; width: 140px; }
    #menu-actions { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; margin-top: 0; }
    .btn-mega { font-size: 0.9rem; padding: 6px 12px; margin: 0; }
    .btn-mega small { display: none; }
    .divider { margin: 0 5px; width: auto; padding: 0; }
    .room-actions { margin: 0; flex-direction: row; gap: 8px; }
    .btn-standard { font-size: 0.8rem; padding: 6px 8px; margin: 0; }
    .join-box { margin: 0; width: auto; }
    .join-box input { width: 60px; flex: 0 0 60px; padding: 6px; font-size: 0.8rem; }
    .room-code-display { font-size: 1.5rem; margin: 0; }
    .server-status { margin: 0; padding: 4px 8px; font-size: 0.7rem; width: auto; }
    .lang-switcher { margin-top: 0; width: auto; }
    .lang-switcher button { padding: 4px 8px; font-size: 0.7rem; }
    
    /* Game UI */
    .main-header { display: flex; flex-direction: row; justify-content: space-between; align-items: center; padding: 0 10px; margin: 0; min-height: 30px; }
    .main-header .title { font-size: 1.2rem; margin: 0; }
    .main-header .subtitle { font-size: 0.7rem; }
    #main-instructions { margin: 0; font-size: 0.8rem; min-height: unset; position: absolute; left: 50%; transform: translateX(-50%); top: 5px; z-index: 100; }
    #room-info { margin: 0; font-size: 0.75rem; }

    .boards-wrapper { padding: 0; gap: 15px; margin-top: 5px; display: flex; flex-direction: row; justify-content: center; align-items: flex-start; }
    
    .player-section { width: 40vw; max-width: 200px; display: flex; flex-direction: column; align-items: center; background: transparent; border: none; padding: 0; box-shadow: none; order: unset; }
    .player1-section { display: flex; }
    .player-section h2 { font-size: 0.8rem; margin-bottom: 2px; text-align: center; width: 100%; justify-content: center; }
    .score-box { min-width: 60px; padding: 3px 8px; margin-bottom: 4px; margin-top: 0; align-self: center; justify-self: center; }
    .score-label { font-size: 0.5rem; margin-bottom: 0px; }
    .score-value { font-size: 1rem; }
    
    .game-container { padding: 4px; --board-padding: 4px; border-radius: 8px; width: 100%; aspect-ratio: 1; margin: 0; }
    .grid-container { gap: 4px; }
    .tile { font-size: 1rem; border-radius: 4px; }
    .grid-cell { border-radius: 4px; }
    .tile.tile-128, .tile.tile-256, .tile.tile-512 { font-size: 0.8rem; }
    .tile.tile-1024, .tile.tile-2048, .tile.tile-super { font-size: 0.6rem; }
    .game-message p { font-size: 1rem; }
    .cube { display: none; }
}
