/* Import czcionek */
@import url('https://fonts.googleapis.com/css2?family=Joti+One&display=swap');

/* Reset i podstawowe style */
* { box-sizing: border-box; }

body {
    font-family: "Joti One", serif;
    font-weight: 400;
    text-align: center;
    background: linear-gradient(135deg, #000000, #1a1a1a, #0a0a0a);
    color: #ffffff;
    margin: 0;
    padding: 0;
    height: 90vh;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Wspólne klasy dla przycisków */
.btn-base {
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 12px;
    font-family: "Joti One", serif;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-base:hover {
    transform: translateY(-2px);
}

.btn-base:disabled {
    background: linear-gradient(135deg, #37474f, #455a64);
    color: #90a4ae;
    cursor: not-allowed;
    transform: none;
}

/* Wspólne klasy dla gradientów */
.gradient-primary {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.gradient-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #3a3a3a, #4a4a4a);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}

.gradient-success {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.gradient-success:hover:not(:disabled) {
    background: linear-gradient(135deg, #3a3a3a, #4a4a4a);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}

.gradient-danger {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.gradient-danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #3a3a3a, #4a4a4a);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}

.gradient-warning {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.gradient-warning:hover:not(:disabled) {
    background: linear-gradient(135deg, #3a3a3a, #4a4a4a);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}

.gradient-resume {
    background: linear-gradient(135deg, #4caf50, #66bb6a);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.gradient-resume:hover:not(:disabled) {
    background: linear-gradient(135deg, #66bb6a, #81c784);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

/* Wspólne klasy dla paneli */
.panel-base {
    background: linear-gradient(135deg, #1a1a1a, #2a2a2a);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.8);
    border-radius: 12px;
}

/* Container główny */
.container {
    max-width: 100%;
    height: 100vh;
    margin: 0 auto;
    background: linear-gradient(135deg, #0f0f0f, #1f1f1f);
    padding: 15px;
    box-shadow: 0 0 50px rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
}

/* Layout responsywny */
.game-layout {
    display: flex;
    flex-direction: column;
    height: 90%;
    gap: min(2vh, 40px);
}

.game-main {
    order: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.game-controls {
    order: 2;
    flex-shrink: 0;
}

/* Informacje o graczu */
.player-info {
    display: flex;
    justify-content: space-between;
    /*align-items: center;*/
    padding: 10px;
    margin-bottom: 5px;
}

.player-details {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.player-nick {
    font-size: clamp(1.1em, 3vw, 1.5em);
    font-weight: bold;
}

.player-points {
    font-size: clamp(0.9em, 2.5vw, 1.1em);
    color: #64b5f6;
    display: flex;
    align-items: center;
    gap: 5px;
}

.guest-info {
    font-size: clamp(1em, 2vw, 1.2em);
    color: #b0bec5;
    max-width: 300px;
}

.auth-btn, .logout-btn {
    font-size: clamp(1em, 3vw, 1.1em);
    padding: 10px 14px;
    min-width: 45px;
    min-height: 45px;
}

.auth-btn {
    background: linear-gradient(135deg, #4caf50, #66bb6a);
}

.logout-btn {
    background: linear-gradient(135deg, #f44336, #ef5350);
}

/* Pole gry */
.game-board {
    background: linear-gradient(135deg, #0a0a0a, #1a1a1a);
    border-radius: 20px;
    padding: clamp(10px, 2vh, 15px);
    margin: 15px 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: clamp(8px, 1.5vh, 12px);
    position: relative;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 4px 20px rgba(0,0,0,0.8), 0 8px 25px rgba(0,0,0,0.5);
    width: 100%;
    flex: 1;
    aspect-ratio: 1;
    max-height: min(70vh, 100vw);
    max-width: 100vw;
    margin-left: auto;
    margin-right: auto;
}

.tile {
    background: linear-gradient(135deg, #1a1a1a, #2a2a2a);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2em, 8vw, 4em);
    font-weight: bold;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
    touch-action: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    aspect-ratio: 1;
}

/* Kolory kafelków */
.tile-2 { background: linear-gradient(135deg, #4a5c2a, #6a7c3a); color: #fff; }
.tile-4 { background: linear-gradient(135deg, #5a4c2a, #7a6c3a); color: #fff; }
.tile-8 { background: linear-gradient(135deg, #6a3c2a, #8a5c3a); color: #fff; }
.tile-16 { background: linear-gradient(135deg, #7a2c2a, #9a4c3a); color: #fff; }
.tile-32 { background: linear-gradient(135deg, #3a4a5a, #4a5a6a); color: #fff; }
.tile-64 { background: linear-gradient(135deg, #4a3a5a, #5a4a6a); color: #fff; }
.tile-128 { background: linear-gradient(135deg, #5a3a4a, #6a4a5a); color: #fff; }
.tile-256 { background: linear-gradient(135deg, #6a2a3a, #7a3a4a); color: #fff; }
.tile-512 { background: linear-gradient(135deg, #8a4a2a, #aa6a3a); color: #fff; }
.tile-1024 { background: linear-gradient(135deg, #2a4a8a, #3a5aaa); color: #fff; }
.tile-2048 {
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #000;
    animation: pulse 1s infinite;
    border-color: #ffd700;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(255, 215, 0, 0.5); }
    50% { transform: scale(1.05); box-shadow: 0 0 30px rgba(255, 215, 0, 0.8); }
}

/* Logo gry */
.game-logo {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a0a0a, #1a1a1a);
    border-radius: 20px;
    z-index: 50;
}

.logo-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Overlay pauzy */
.pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 20px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: clamp(1.2em, 3vw, 1.5em);
    color: #64b5f6;
    z-index: 100;
}

/* Pasek statystyk */
.stats-bar {
    display: flex;
    justify-content: space-between;
    padding: clamp(12px, 2vh, 15px);
    margin-bottom: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.9em, 2.5vw, 1.1em);
}

.stat-emoji {
    font-size: 1.2em;
}

.stat-value {
    font-weight: bold;
    color: #64b5f6;
}

/* Siatka przycisków */
.buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, 1fr);
    gap: clamp(12px, 2vh, 15px);
    margin-bottom: 0;
    flex: 1;
}

.btn {
    padding: clamp(15px, 3vh, 20px) 12px;
    font-size: clamp(0.8em, 2.2vw, 0.95em);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: clamp(50px, 8vh, 60px);
}

.btn-pause {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
}

.btn-home {
    background: linear-gradient(135deg, #2c2c2c, #3a3a3a);
}

/* Layout poziomy */
@media (orientation: landscape) and (min-width: 768px) {
    body { height: 100vh; }

    .container {
        width: 100vw;
        height: 100vh;
        padding: 20px;
        border-radius: 0;
    }

    .game-layout {
        flex-direction: row;
        gap: 25px;
        height: 100%;
    }

    .game-main {
        flex: 1;
        justify-content: center;
        align-items: center;
        display: flex;
        flex-direction: column;
        order: 1;
    }

    .game-controls {
        flex: 0 0 320px;
        order: 2;
        gap: 15px;
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    /* Ukryj elementy pionowe, pokaż poziome */
    .player-info-portrait,
    .stats-bar-portrait {
        display: none !important;
    }

    .player-info-landscape,
    .stats-bar-landscape {
        display: flex !important;
        margin-bottom: 0;
    }

    .game-board {
        width: min(80vh, 80vw);
        height: min(80vh, 80vw);
        max-height: none;
        max-width: none;
        margin: 0;
        flex: none;
    }

    .buttons-grid {
        margin-bottom: 0;
        flex: 1;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: repeat(6, 1fr);
        gap: 10px;
    }

    .btn {
        min-height: auto;
        padding: 12px 15px;
        font-size: 0.85em;
    }

    /* Jeśli nie mieszczą się wszystkie przyciski, przełącz na 2x3 */
    @media (max-height: 600px) {
        .buttons-grid {
            grid-template-columns: 1fr 1fr;
            grid-template-rows: repeat(3, 1fr);
            gap: 8px;
        }
    }
}

/* Domyślnie ukryj elementy poziome */
.player-info-landscape,
.stats-bar-landscape {
    display: none;
}

/* Modalne okna */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: linear-gradient(135deg, #0f0f0f, #1f1f1f);
    padding: 30px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0,0,0,0.9);
    text-align: center;
    max-width: min(500px, 90vw);
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-large {
    max-width: min(700px, 95vw);
    max-height: 90vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-content h2 {
    color: #64b5f6;
    margin: 0;
    font-size: clamp(1.5em, 4vw, 2em);
}

.close-btn-large {
    font-size: clamp(1.5em, 4vw, 2em);
    padding: 10px 15px;
    min-width: 50px;
    min-height: 50px;
}

/* Przyciski potwierdzenia */
.confirm-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.confirm-btn {
    width: 100%;
    padding: 15px;
    font-size: clamp(1em, 3vw, 1.1em);
}

.confirm-btn.confirm-yes {
    background: linear-gradient(135deg, #4caf50, #66bb6a);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.confirm-btn.confirm-no {
    background: linear-gradient(135deg, #f44336, #ef5350);
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.3);
}

/* Nawigacja rankingu */
.ranking-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    padding: 10px;
    border-radius: 12px;
    gap: 10px;
}

.nav-btn {
    padding: 10px 15px;
    border-radius: 10px;
    font-family: inherit;
    flex: 1;
}

.page-info {
    display: none;
}

/* Tabela rankingu */
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.ranking-table th,
.ranking-table td {
    padding: clamp(8px, 2vw, 12px) clamp(6px, 1.5vw, 8px);
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-family: "Joti One", serif;
}

.ranking-table th {
    background: linear-gradient(135deg, #1a1a1a, #2a2a2a);
    color: #64b5f6;
    font-weight: bold;
}

.ranking-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.05);
}

/* Ukryj datę na małych ekranach */
@media (max-width: 768px) and (orientation: portrait) {
    .date-column { display: none; }
}

/* Kolorowanie pozycji w rankingu */
.ranking-table tbody tr:nth-child(1) td:first-child { color: #ffd700; }
.ranking-table tbody tr:nth-child(2) td:first-child { color: #c0c0c0; }
.ranking-table tbody tr:nth-child(3) td:first-child { color: #cd7f32; }
.ranking-table tbody tr:nth-child(4) td:first-child { color: #ff6b6b; }
.ranking-table tbody tr:nth-child(5) td:first-child { color: #4ecdc4; }
.ranking-table tbody tr:nth-child(6) td:first-child { color: #45b7d1; }
.ranking-table tbody tr:nth-child(7) td:first-child { color: #96ceb4; }
.ranking-table tbody tr:nth-child(8) td:first-child { color: #feca57; }
.ranking-table tbody tr:nth-child(9) td:first-child { color: #ff9ff3; }
.ranking-table tbody tr:nth-child(10) td:first-child { color: #a29bfe; }

/* Zasady gry */
.rules-description {
    color: #b0bec5;
    line-height: 1.6;
    margin-bottom: 25px;
    text-align: left;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 12px;
}

.legend-tile {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    flex-shrink: 0;
}

.legend-text {
    font-size: clamp(0.8em, 2vw, 0.9em);
    color: #b0bec5;
}

/* Ekran końca gry */
.game-over {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #fff;
    padding: 20px;
    z-index: 1000;
    overflow-y: auto;
}

.game-over-content {
    text-align: center;
    max-width: min(600px, 90vw);
    width: 100%;
    position: relative;
}

.close-game-over-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    border-radius: 50%;
    width: clamp(45px, 8vw, 50px);
    height: clamp(45px, 8vw, 50px);
    font-size: clamp(1.5em, 4vw, 2em);
    z-index: 1001;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.dead-mouse-img-large {
    width: 100%;
    max-width: clamp(200px, 50vw, 300px);
    height: auto;
    object-fit: contain;
    margin: 20px 0;
}

.game-over h2 {
    margin: 20px 0;
    color: #ff6b6b;
    font-size: clamp(1.8em, 5vw, 2.5em);
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}

.final-stats-simple {
    padding: clamp(15px, 4vw, 25px);
    border-radius: 15px;
    margin: 20px 0;
}

.final-stat-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 0;
    gap: 15px;
    font-size: clamp(1em, 3vw, 1.2em);
}

.stat-icon {
    font-size: 1.5em;
    width: 30px;
    text-align: center;
}

.stat-label {
    color: #b0bec5;
    min-width: 100px;
    text-align: left;
}

.stat-value {
    color: #64b5f6;
    font-weight: bold;
    flex: 1;
    text-align: left;
}

.moves-header {
    color: #b0bec5;
    font-size: clamp(1em, 2.5vw, 1.1em);
    margin: 20px 0 10px 0;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.moves-stats {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-top: 15px;
}

.move-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.move-icon {
    font-size: clamp(1.2em, 3vw, 1.5em);
}

.move-count {
    color: #64b5f6;
    font-weight: bold;
    font-size: clamp(1em, 2.5vw, 1.1em);
}