/* ==================== CSS VARIABLES ==================== */
:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-tertiary: #1a1a3a;
    --bg-card: rgba(30, 30, 60, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.4);
    
    --x-color: #4cc9f0;
    --x-glow: rgba(76, 201, 240, 0.4);
    --o-color: #f72585;
    --o-glow: rgba(247, 37, 133, 0.4);
    
    --success: #00d26a;
    --warning: #ffc048;
    --error: #ff4757;
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);
}

/* ==================== RESET & BASE ==================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-primary);
    background-image: 
        radial-gradient(ellipse at top, rgba(108, 92, 231, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom, rgba(247, 37, 133, 0.1) 0%, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==================== HOME BUTTON ==================== */
.home-button {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 48px;
    height: 48px;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    z-index: 1000;
}

.home-button:hover {
    background: var(--accent);
    color: white;
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}

.home-button svg {
    width: 24px;
    height: 24px;
}

/* ==================== CONTAINER ==================== */
.container {
    text-align: center;
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

/* ==================== HEADER ==================== */
header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--x-color), var(--o-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.highlight {
    color: var(--accent-light);
    -webkit-text-fill-color: var(--accent-light);
}

header p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

/* ==================== LOBBY SECTION ==================== */
.lobby-section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    padding: 2rem;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-lg);
}

.input-group input,
.join-group input,
.join-row input {
    width: 100%;
    padding: 14px 18px;
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    text-align: center;
    transition: var(--transition);
    outline: none;
}

.input-group input:focus,
.join-group input:focus,
.join-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-group input::placeholder,
.join-group input::placeholder,
.join-row input::placeholder {
    color: var(--text-muted);
}

/* ==================== ACTIONS ==================== */
.actions {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.solo-group, .multi-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.solo-group h3, .multi-group h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.divider {
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

/* ==================== DIFFICULTY BUTTONS ==================== */
.difficulty-buttons {
    display: flex;
    gap: 8px;
}

.diff-btn {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.diff-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.diff-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 0 15px var(--accent-glow);
}

/* ==================== BUTTONS ==================== */
.controls button,
.actions button:not(.diff-btn),
.join-group button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: white;
    border: none;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
    width: 100%;
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
}

.controls button:hover,
.actions button:not(.diff-btn):hover,
.join-group button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--accent-glow);
}

.controls button:active,
.actions button:not(.diff-btn):active,
.join-group button:active {
    transform: translateY(1px);
}

.secondary-btn {
    background: linear-gradient(135deg, var(--o-color), #ff5ca2) !important;
    box-shadow: var(--shadow-md), 0 0 20px var(--o-glow) !important;
}

.secondary-btn:hover {
    box-shadow: var(--shadow-lg), 0 0 30px var(--o-glow) !important;
}

.join-row {
    display: flex;
    gap: 10px;
}

.join-row input {
    flex: 1;
}

.join-row button {
    width: auto !important;
    padding: 14px 20px !important;
}

/* ==================== GAME SECTION ==================== */
.game-section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.room-info {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
    background: var(--bg-glass);
    padding: 10px 16px;
    border-radius: var(--border-radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.room-info .highlight {
    color: var(--accent-light);
    font-weight: 600;
}

#copy-code-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    transition: var(--transition);
    opacity: 0.7;
}

#copy-code-btn:hover {
    transform: scale(1.1);
    opacity: 1;
}

/* ==================== SCORES ==================== */
.scores-container {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 1.5rem;
    padding: 16px 24px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.player-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.player-score .name {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.player-score .score {
    font-size: 1.8rem;
    font-weight: 700;
}

#score-x .score {
    color: var(--x-color);
    text-shadow: 0 0 20px var(--x-glow);
}

#score-o .score {
    color: var(--o-color);
    text-shadow: 0 0 20px var(--o-glow);
}

/* ==================== GAME INFO / TURN ==================== */
.game-info {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
}

.player-status {
    padding: 12px 24px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius-sm);
    font-weight: 700;
    font-size: 1.2rem;
    opacity: 0.4;
    transition: var(--transition);
    min-width: 80px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.player-status.active {
    opacity: 1;
    transform: scale(1.1);
}

#status-x {
    color: var(--x-color);
}

#status-x.active {
    box-shadow: 0 0 20px var(--x-glow);
    border-color: var(--x-color);
}

#status-o {
    color: var(--o-color);
}

#status-o.active {
    box-shadow: 0 0 20px var(--o-glow);
    border-color: var(--o-color);
}

/* ==================== GAME BOARD ==================== */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    background: linear-gradient(145deg, var(--bg-secondary), var(--bg-tertiary));
    padding: 16px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    aspect-ratio: 1 / 1;
    box-shadow: 
        var(--shadow-lg),
        inset 0 2px 10px rgba(255, 255, 255, 0.05),
        inset 0 -2px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.cell {
    background: var(--bg-primary);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    position: relative;
    box-shadow: 
        inset 0 2px 8px rgba(0, 0, 0, 0.4),
        0 2px 4px rgba(255, 255, 255, 0.05);
}

.cell:hover:not(.taken) {
    background: var(--bg-tertiary);
    transform: scale(0.98);
}

.cell.x {
    color: var(--x-color);
    text-shadow: 0 0 30px var(--x-glow);
}

.cell.o {
    color: var(--o-color);
    text-shadow: 0 0 30px var(--o-glow);
}

/* Animation for appearing */
.cell span {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Style for the oldest move that is about to be removed */
.cell.fading {
    opacity: 0.4;
    border: 2px dashed var(--text-muted);
}

/* Winning cells animation */
.cell.winning {
    animation: winPulse 0.5s ease-in-out infinite alternate;
}

@keyframes winPulse {
    from { 
        transform: scale(1);
        filter: brightness(1);
    }
    to { 
        transform: scale(1.05);
        filter: brightness(1.3);
    }
}

/* ==================== WINNER MESSAGE ==================== */
#winner-message {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.1);
    animation: slideUp 0.5s ease;
}

#winner-message h2 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--x-color), var(--o-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ==================== UTILITY ==================== */
.hidden {
    display: none !important;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .cell {
        font-size: 2.5rem;
    }
    
    .home-button {
        width: 40px;
        height: 40px;
        top: 15px;
        left: 15px;
    }
    
    .home-button svg {
        width: 20px;
        height: 20px;
    }
}