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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #00223c 0%, #86A40C 100%);
    color: #333;
    overflow: hidden;
    height: 100vh;
}

.screen {
    display: none;
    width: 100vw;
    height: 100vh;
}

.screen.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

#leaderboardTable {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

#leaderboardTable th {
    background: linear-gradient(135deg, #00223c 0%, #86A40C 100%);
    color: white;
    padding: 15px;
    text-align: left;
}

/* Login Screen */
.login-container {
    background: #FFFFFF;
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 400px;
    max-width: 90vw;
}

.login-container h1 {
    color: #00223c;
    margin-bottom: 10px;
    font-size: 2.5em;
}

.login-container p {
    color: #666;
    margin-bottom: 30px;
}

#loginForm input {
    width: 100%;
    padding: 15px;
    margin: 10px 0;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s;
}

#loginForm input:focus {
    outline: none;
    border-color: #00223c;
}

.btn {
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
    margin: 10px 0;
    display: block;
}

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

.btn-primary {
    background: #00223c;
    color: #FFFFFF;
}

.btn-secondary {
    background: #BD3D1F;
    color: #FFFFFF;
}

.btn-info {
    background: #86A40C;
    color: #FFFFFF;
}

.btn-danger {
    background: #BD3D1F;
    color: #FFFFFF;
}

.btn-small {
    padding: 10px 20px;
    font-size: 14px;
    min-width: 100px;
    border: 2px solid transparent;
    position: relative;
    z-index: 10;
}

.btn-small:hover {
    border-color: #FFAF2C;
    background-color: #BD3D1F !important;
}

/* Matchmaking Screen */
.matchmaking-container {
    background: #FFFFFF;
    padding: 60px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #00223c;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 30px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Game Screen */
#gameScreen {
    display: none;
    flex-direction: column;
    background: #1a1a2e;
    height: 100vh;
    overflow: hidden;
}

#gameScreen.active {
    display: flex;
}

.game-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 15px 30px;
    background: rgba(0, 34, 60, 0.8);
    color: white;
    height: 60px;
    flex-shrink: 0;
}

.game-field-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: auto;
    max-width: 90vw;
}

.field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 15px 20px;
    background: rgba(0, 34, 60, 0.9);
    color: #FFFFFF;
    border-radius: 10px 10px 0 0;
    margin-bottom: 0;
    z-index: 5;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    box-sizing: border-box;
}

.player-info {
    font-size: 18px;
    font-weight: bold;
}

.timer {
    font-size: 32px;
    font-weight: bold;
    color: #FFAF2C;
}

.game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px;
    height: calc(100vh - 60px);
    overflow: hidden;
}

.game-board {
    width: min(75vh, 75vw);
    height: min(75vh, 75vw);
    display: grid;
    gap: 3px;
    padding: 20px;
    background: #0f0f1e;
    border-radius: 0 0 10px 10px;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    aspect-ratio: 1;
}

.game-board.single {
    border-radius: 0 0 10px 10px;
}

.game-field-container .field-header {
    width: min(75vh, 75vw);
}

.game-field-container .game-board {
    width: min(75vh, 75vw);
    height: min(75vh, 75vw);
}

.game-board::before {
    content: attr(data-player);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 18px;
    font-weight: bold;
}

.pipe-cell {
    background: linear-gradient(135deg, #1a1a2e 0%, #2a2a3e 100%);
    border: 1px solid #3a3a5e;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    aspect-ratio: 1;
    width: 100%;
    height: 100%;
}

.pipe-cell:hover {
    background: linear-gradient(135deg, #2a2a3e 0%, #3a3a5e 100%);
    transform: scale(1.02);
    box-shadow: inset 0 0 20px rgba(134, 164, 12, 0.3);
}

.pipe-cell.connected {
    background: linear-gradient(135deg, #1e3a5f 0%, #2a5a8e 100%);
    border-color: #86A40C;
    box-shadow: 0 0 20px rgba(134, 164, 12, 0.6), inset 0 0 30px rgba(134, 164, 12, 0.2);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(134, 164, 12, 0.6), inset 0 0 30px rgba(134, 164, 12, 0.2);
    }
    50% { 
        box-shadow: 0 0 35px rgba(134, 164, 12, 0.9), inset 0 0 40px rgba(134, 164, 12, 0.4);
    }
}

.pipe-cell.start {
    background: linear-gradient(135deg, #2d5a3d 0%, #86A40C 100%);
    border-color: #FFAF2C;
    box-shadow: 0 0 20px rgba(134, 164, 12, 0.6);
}

.pipe-cell.start::before {
    content: 'START';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.3);
    font-weight: bold;
    font-size: 10px;
    letter-spacing: 1px;
    z-index: 0;
}

.pipe-cell.end {
    background: linear-gradient(135deg, #5a2d3d 0%, #BD3D1F 100%);
    border-color: #FFAF2C;
    box-shadow: 0 0 20px rgba(189, 61, 31, 0.6);
}

.pipe-cell.end::before {
    content: 'ZIEL';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.3);
    font-weight: bold;
    font-size: 10px;
    letter-spacing: 1px;
    z-index: 0;
}

.pipe-cell.start.connected,
.pipe-cell.end.connected {
    animation: pulse 2s ease-in-out infinite;
}

.pipe-svg {
    width: 100%;
    height: 100%;
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: relative;
    z-index: 1;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.4));
}

.pipe-cell:active .pipe-svg {
    transform: rotate(90deg) scale(0.95);
}

/* Glow effect for connected pipes */
.pipe-cell.connected .pipe-svg {
    filter: drop-shadow(0 0 8px rgba(134, 164, 12, 0.8)) 
            drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.4));
}

/* Solution path highlighting */
.pipe-cell.solution-path {
    background: linear-gradient(135deg, #86A40C 0%, #FFAF2C 100%);
    border-color: #FFFFFF;
    box-shadow: 0 0 25px rgba(134, 164, 12, 0.9), inset 0 0 40px rgba(134, 164, 12, 0.3);
    animation: solution-pulse 1.5s ease-in-out infinite;
}

@keyframes solution-pulse {
    0%, 100% { 
        box-shadow: 0 0 25px rgba(134, 164, 12, 0.9), inset 0 0 40px rgba(134, 164, 12, 0.3);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 40px rgba(134, 164, 12, 1), inset 0 0 50px rgba(134, 164, 12, 0.5);
        transform: scale(1.02);
    }
}

.pipe-cell.solution-path .pipe-svg {
    filter: drop-shadow(0 0 12px rgba(134, 164, 12, 1)) 
            drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.4));
}

.pipe-cell.solution-path::after {
    content: '✓';
    position: absolute;
    top: 5px;
    right: 5px;
    color: #86A40C;
    font-size: 12px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    animation: check-appear 0.5s ease-out;
}

@keyframes check-appear {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Game Overlay */
.game-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.game-overlay.active {
    display: flex;
}

.overlay-content {
    background: #FFFFFF;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 500px;
}

.overlay-content h2 {
    color: #00223c;
    margin-bottom: 20px;
    font-size: 2em;
}

.overlay-content p {
    color: #00223c;
    margin-bottom: 30px;
    font-size: 1.2em;
    white-space: pre-line;
    line-height: 1.6;
}

.overlay-content .btn {
    margin: 5px;
}

/* Leaderboard Screen */
.leaderboard-container {
    background: #FFFFFF;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.leaderboard-container h1 {
    color: #00223c;
    margin-bottom: 30px;
    text-align: center;
}

#leaderboardTable {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

#leaderboardTable th {
    background: linear-gradient(135deg, #00223c 0%, #86A40C 100%);
    color: white;
    padding: 15px;
    text-align: left;
}

#leaderboardTable td {
    padding: 12px 15px;
    border-bottom: 1px solid #ddd;
}

#leaderboardTable tr:hover {
    background: #f5f5f5;
}

#leaderboardTable tr:nth-child(1) td {
    background: #FFAF2C;
    font-weight: bold;
}

#leaderboardTable tr:nth-child(2) td {
    background: #86A40C;
    color: #FFFFFF;
}

#leaderboardTable tr:nth-child(3) td {
    background: #BD3D1F;
    color: #FFFFFF;
}

/* Responsive */
@media (max-width: 768px) {
    .login-container {
        min-width: 90%;
        padding: 30px 20px;
    }

    .button-group {
        flex-direction: column;
    }

    .game-header {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        height: auto;
    }

    .game-container {
        flex-direction: column;
        height: auto;
    }

    .game-board {
        width: 100% !important;
        height: 50vh;
    }

    .game-board.single {
        width: 100% !important;
        height: 100%;
    }
}

@media (max-width: 480px) {
    .timer {
        font-size: 24px;
    }

    .player-info {
        font-size: 14px;
    }

    #leaderboardTable {
        font-size: 12px;
    }

    #leaderboardTable th,
    #leaderboardTable td {
        padding: 8px 5px;
    }
}
