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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: #fff;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.subtitle {
    color: #a0a0a0;
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.game-info {
    margin-bottom: 20px;
}

.status {
    font-size: 1.3rem;
    padding: 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 10px;
}

.status.winner {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.turn-indicator {
    font-size: 1.1rem;
    color: #a0a0a0;
}

.turn-indicator .player-x {
    color: #3b82f6;
    font-weight: bold;
}

.turn-indicator .player-o {
    color: #ef4444;
    font-weight: bold;
}

.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 30px;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.cell {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.cell:hover:not(.occupied) {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.cell.occupied {
    cursor: not-allowed;
}

.cell.x {
    color: #3b82f6;
    text-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.cell.o {
    color: #ef4444;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
}

.cell.fading {
    animation: fading 1.5s infinite;
}

.cell.fading::after {
    content: '⚠';
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 0.8rem;
}

@keyframes fading {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.cell.winning {
    background: rgba(74, 222, 128, 0.3);
    animation: winner-glow 1s infinite;
}

@keyframes winner-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(74, 222, 128, 0.5); }
    50% { box-shadow: 0 0 30px rgba(74, 222, 128, 0.8); }
}

.numpad-hint {
    margin-top: 15px;
    color: #666;
    font-size: 0.9rem;
}

.controls {
    margin-bottom: 30px;
}

.btn {
    padding: 15px 40px;
    font-size: 1.1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: bold;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(59, 130, 246, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.move-history {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
    text-align: left;
}

.move-history h3 {
    margin-bottom: 15px;
    color: #a0a0a0;
}

#history-list {
    max-height: 150px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.9rem;
}

.history-item {
    padding: 5px 10px;
    margin: 3px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
}

.history-item.x {
    border-left: 3px solid #3b82f6;
}

.history-item.o {
    border-left: 3px solid #ef4444;
}

.history-item.vanished {
    text-decoration: line-through;
    opacity: 0.5;
}

.rules {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 20px;
    text-align: left;
}

.rules h3 {
    margin-bottom: 15px;
}

.rules ul {
    list-style: none;
    padding-left: 0;
}

.rules li {
    padding: 8px 0;
    padding-left: 25px;
    position: relative;
}

.rules li::before {
    content: '•';
    position: absolute;
    left: 5px;
    color: #3b82f6;
}

.fading-text {
    animation: fading 1.5s infinite;
    color: #ef4444;
}

/* Error toast */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: white;
    padding: 15px 30px;
    border-radius: 10px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
}

/* Responsive */
@media (max-width: 500px) {
    .cell {
        width: 80px;
        height: 80px;
        font-size: 2.5rem;
    }
    
    h1 {
        font-size: 2rem;
    }
}

/* ============== New Multiplayer Styles ============== */

.section {
    margin-bottom: 30px;
}

/* Login/User Form */
.user-form {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 30px;
}

.user-form h3 {
    margin-bottom: 20px;
}

#login-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.divider {
    color: #666;
    font-size: 0.9rem;
}

#username-input, #new-username-input {
    padding: 12px 20px;
    font-size: 1rem;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    width: 100%;
    max-width: 250px;
    text-align: center;
}

#username-input::placeholder, #new-username-input::placeholder {
    color: #888;
}

#username-input:focus, #new-username-input:focus {
    outline: 2px solid #3b82f6;
}

/* Profile Card */
.profile-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 20px;
}

.profile-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.profile-header .username {
    font-size: 1.5rem;
    font-weight: bold;
}

.profile-header .rank {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 20px;
}

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

.stat-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #3b82f6;
}

.stat-label {
    font-size: 0.9rem;
    color: #888;
}

.btn-small {
    padding: 8px 20px;
    font-size: 0.9rem;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 30px;
    border-radius: 15px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.modal-content h3, .modal-content h2 {
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

/* Game Mode Selection */
.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
}

.btn-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid transparent;
    border-radius: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
}

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

.mode-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.mode-title {
    font-size: 1.2rem;
    font-weight: bold;
}

.mode-desc {
    font-size: 0.9rem;
    color: #888;
}

.online-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #888;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Matchmaking */
.matchmaking-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 40px;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.matchmaking-card h3 {
    margin-bottom: 10px;
}

.matchmaking-card p {
    color: #888;
    margin-bottom: 10px;
}

#queue-timer {
    font-family: monospace;
    color: #3b82f6;
}

/* Players Info (Online Game) */
.players-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.player-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 25px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    min-width: 120px;
}

.player-card.player-x {
    border: 2px solid #3b82f6;
}

.player-card.player-o {
    border: 2px solid #ef4444;
}

.player-card.active {
    animation: pulse 1s infinite;
}

.player-symbol {
    font-size: 1.5rem;
    font-weight: bold;
}

.player-card.player-x .player-symbol {
    color: #3b82f6;
}

.player-card.player-o .player-symbol {
    color: #ef4444;
}

.player-name {
    font-weight: bold;
    margin: 5px 0;
}

.player-elo {
    font-size: 0.9rem;
    color: #888;
}

.vs {
    font-size: 1.2rem;
    font-weight: bold;
    color: #666;
}

/* Turn Timer */
.turn-timer {
    font-size: 1.2rem;
    color: #f59e0b;
    margin-top: 10px;
}

.turn-timer.warning {
    color: #ef4444;
    animation: pulse 0.5s infinite;
}

/* Game Over Modal */
.game-over-content h2 {
    font-size: 1.8rem;
}

.elo-change {
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.elo-change.positive {
    color: #22c55e;
}

.elo-change.negative {
    color: #ef4444;
}

/* User Header */
.user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.header-username {
    font-weight: bold;
    font-size: 1.1rem;
}

.btn-logout {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid #ef4444;
    color: #ef4444;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Menu Tabs */
.menu-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 12px 30px;
    font-size: 1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: bold;
    background: rgba(255, 255, 255, 0.05);
    color: #888;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.tab-btn.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.tab-content {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Match History */
.match-history {
    margin-top: 25px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 15px;
    padding: 20px;
}

.match-history h3 {
    margin-bottom: 15px;
    text-align: left;
}

.match-history-list {
    max-height: 300px;
    overflow-y: auto;
}

.match-item {
    display: grid;
    grid-template-columns: 1fr 1fr 60px 80px;
    gap: 10px;
    align-items: center;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid #666;
}

.match-item.win {
    border-left-color: #22c55e;
}

.match-item.loss {
    border-left-color: #ef4444;
}

.match-item.draw {
    border-left-color: #f59e0b;
}

.match-result {
    font-weight: bold;
    text-align: left;
}

.match-item.win .match-result {
    color: #22c55e;
}

.match-item.loss .match-result {
    color: #ef4444;
}

.match-item.draw .match-result {
    color: #f59e0b;
}

.match-opponent {
    color: #aaa;
    text-align: left;
}

.match-elo {
    text-align: center;
}

.elo-gain {
    color: #22c55e;
    font-weight: bold;
}

.elo-loss {
    color: #ef4444;
    font-weight: bold;
}

.match-date {
    color: #666;
    font-size: 0.85rem;
    text-align: right;
}

.no-matches, .loading, .error {
    color: #666;
    text-align: center;
    padding: 20px;
}

.error {
    color: #ef4444;
}

/* Register Card */
.register-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
}

.register-card h3 {
    margin-bottom: 15px;
}

.register-desc {
    color: #888;
    margin-bottom: 25px;
}

.register-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

#register-username-input {
    padding: 12px 20px;
    font-size: 1rem;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    width: 100%;
    max-width: 250px;
    text-align: center;
}

#register-username-input::placeholder {
    color: #888;
}

#register-username-input:focus {
    outline: 2px solid #3b82f6;
}

.register-note {
    margin-top: 20px;
    color: #666;
    font-size: 0.85rem;
    font-style: italic;
}

/* Controls adjustment */
.controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Additional responsive */
@media (max-width: 500px) {
    .profile-stats {
        gap: 15px;
    }
    
    .stat-value {
        font-size: 1.4rem;
    }
    
    .players-info {
        flex-direction: column;
        gap: 10px;
    }
    
    .vs {
        display: none;
    }
    
    .player-card {
        flex-direction: row;
        gap: 15px;
        width: 100%;
        justify-content: center;
    }
}
