@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 24px;
    /* box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15); */
    padding: 40px 30px;
    text-align: center;
    max-width: 480px;
    width: 100%;
}

h1 {
    color: #2d3748;
    margin-bottom: 4px;
    font-size: clamp(1.2em, 4vw, 1.5em);
    font-weight: 700;
}

.subtitle {
    color: #718096;
    font-size: 0.75em;
    margin-bottom: 12px;
}

.game-info {
    margin: 12px 0;
    font-size: 0.9em;
    font-weight: 600;
    color: #4a5568;
    min-height: 24px;
}

.game-info .current-player { color: #667eea; }
.game-info .winner { color: #48bb78; font-weight: 700; }
.game-info .loser { color: #f56565; font-weight: 700; }
.game-info .draw { color: #ed8936; font-weight: 700; }
.game-info .waiting { color: #718096; }

.player-info {
    background: #f7fafc;
    border-radius: 12px;
    padding: 8px 16px;
    margin-bottom: 12px;
    border: 1px solid #e2e8f0;
}

/* Floating player names bar at bottom */
.player-names {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 480px;
    width: calc(100% - 40px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    padding: 8px;
    display: flex;
    gap: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    z-index: 100;
    animation: slideUp 0.3s ease-out;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% { 
        box-shadow: 0 2px 8px rgba(72, 187, 120, 0.2);
    }
    50% { 
        box-shadow: 0 4px 16px rgba(72, 187, 120, 0.4);
    }
}

.player-card {
    flex: 1;
    background: transparent;
    padding: 12px 16px;
    border-radius: 12px;
    border: none;
    transition: all 0.3s ease;
    position: relative;
    cursor: default;
    border-bottom: 3px solid transparent;
}

.player-card.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 3px solid #48bb78;
    box-shadow: 0 2px 8px rgba(72, 187, 120, 0.2);
    animation: pulse 2s infinite;
}

.player-card.active::after {
    content: '●';
    position: absolute;
    top: 8px;
    right: 12px;
    color: #48bb78;
    font-size: 1.2em;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.player-label {
    font-size: 0.65em;
    color: #718096;
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.player-card.active .player-label {
    color: rgba(255, 255, 255, 0.9);
}

.player-name {
    color: #2d3748;
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-card.active .player-name {
    color: white;
    font-weight: 700;
}

.status-line {
    font-size: 0.75em;
    color: #718096;
    text-align: center;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    background: #48bb78;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 16px 0;
    padding: 16px;
    background: #f7fafc;
    border-radius: 16px;
}

.cell {
    aspect-ratio: 1;
    background: white;
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    font-size: clamp(2em, 8vw, 2.5em);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #2d3748;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell:hover:not(.taken):not(.disabled) {
    background: #edf2f7;
    border-color: #cbd5e0;
    transform: scale(1.05);
}

.cell.disabled {
    cursor: not-allowed;
}

.cell.x {
    color: #667eea;
}

.cell.o {
    color: #ed64a6;
}

.cell.winner-cell {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    border-color: #48bb78;
    animation: winnerPulse 0.6s ease-in-out infinite;
}

@keyframes winnerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

button.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 14px 28px;
    font-size: 0.95em;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
}

button.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

button.btn:active {
    transform: translateY(0);
}

button.btn-secondary {
    background: #edf2f7;
    color: #4a5568;
}

button.btn-secondary:hover {
    background: #e2e8f0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.score-board {
    display: inline-flex;
    gap: 8px;
    padding: 4px 12px;
    background: #f7fafc;
    border-radius: 20px;
    border: 1px solid #e2e8f0;
    margin-left: 12px;
    vertical-align: middle;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.score-label {
    font-size: 0.65em;
    color: #718096;
    font-weight: 600;
    text-transform: uppercase;
}

.score-value {
    font-size: 0.9em;
    font-weight: 700;
}

.score-value.wins { color: #48bb78; }
.score-value.losses { color: #f56565; }
.score-value.draws { color: #ed8936; }

.lobby-container {
    padding: 20px;
    background: #f7fafc;
    border-radius: 16px;
    margin-bottom: 20px;
}

.lobby-title {
    font-size: 1.1em;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 16px;
}

.waiting-games {
    max-height: 300px;
    overflow-y: auto;
}

.waiting-game-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid #e2e8f0;
    transition: all 0.3s ease;
    cursor: pointer;
}

.waiting-game-card:hover {
    border-color: #667eea;
    background: #f7fafc;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.waiting-player-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.waiting-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1em;
}

.waiting-player-name {
    font-weight: 600;
    color: #2d3748;
}

.waiting-time {
    font-size: 0.85em;
    color: #718096;
}

.join-btn {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9em;
}

.join-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.3);
}

.empty-lobby {
    text-align: center;
    padding: 40px 20px;
    color: #718096;
}

.name-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.name-modal.hidden {
    display: none;
}

.name-modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.name-modal h2 {
    color: #2d3748;
    margin-bottom: 12px;
    font-size: 1.8em;
}

.name-modal p {
    color: #718096;
    margin-bottom: 24px;
}

.name-input {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1em;
    margin-bottom: 20px;
    font-family: 'Poppins', sans-serif;
}

.name-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.rematch-notification {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px;
    margin: 16px 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.rematch-timer {
    font-size: 1.4em;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 8px;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 16px;
        padding-bottom: 90px;
    }
    
    h1 {
        font-size: 1.2em;
        margin-bottom: 2px;
    }
    
    .subtitle {
        font-size: 0.7em;
        margin-bottom: 8px;
    }
    
    .player-info {
        padding: 6px 12px;
        margin-bottom: 8px;
    }
    
    .status-line {
        font-size: 0.7em;
    }
    
    .game-info {
        margin: 8px 0;
        font-size: 0.85em;
    }
    
    .board {
        gap: 8px;
        margin: 12px 0;
        padding: 12px;
    }
    
    .cell {
        font-size: 2em;
    }
    
    .player-names {
        bottom: 10px;
        padding: 8px 12px;
        gap: 6px;
        max-width: calc(100% - 20px);
    }
    
    .player-card {
        padding: 8px 10px;
    }
    
    .player-label {
        font-size: 0.6em;
        margin-bottom: 2px;
    }
    
    .player-name {
        font-size: 0.8em;
    }
    
    .controls {
        flex-direction: column;
        margin-top: 12px;
    }
    
    button.btn {
        width: 100%;
        padding: 12px 20px;
        font-size: 0.9em;
    }
    
    .score-board {
        margin-top: 16px;
        padding: 12px;
    }
}

/* Add padding to body for floating bar */
body.game-active {
    padding-bottom: 80px;
}
