/* =========================================
   1. Variables & Reset
   ========================================= */
:root {
    --primary-color: #6366f1; /* Indigo */
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;
    
    --transition-speed: 0.3s;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================
   2. Layout & Header
   ========================================= */
.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.025em;
}

.main-nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-speed);
}

.nav-btn:hover {
    background-color: var(--bg-color);
    color: var(--primary-color);
}

.nav-btn.active {
    background-color: var(--primary-color);
    color: white;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-muted);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    border: 2px solid white;
    box-shadow: var(--shadow-sm);
}

/* =========================================
   3. Main Container & Sections
   ========================================= */
.container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    flex: 1;
    width: 100%;
}

.section {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-main);
    font-weight: 700;
}

.note {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 1rem;
    font-style: italic;
}

/* =========================================
   4. Game Mode & Difficulty Selector
   ========================================= */
.game-mode-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
    gap: 1rem;
}

.mode-toggle {
    display: flex;
    gap: 0.5rem;
}

.mode-btn {
    background: white;
    border: 2px solid var(--border-color);
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.mode-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.mode-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.difficulty-selector label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.difficulty-selector select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
}

.difficulty-selector select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* =========================================
   5. PVP Join Section
   ========================================= */
.pvp-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

#room-code-input {
    flex: 1;
    min-width: 150px;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    font-weight: 600;
}

#room-code-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.room-code-display {
    font-size: 0.9rem;
    color: var(--success-color);
    font-weight: 600;
    text-align: center;
    padding: 0.5rem;
    background: rgba(34, 197, 94, 0.1);
    border-radius: var(--radius-md);
    margin-top: 0.5rem;
}

/* =========================================
   6. Game Section Styles
   ========================================= */
.game-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.score-board {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: var(--radius-md);
}

.player-score, .computer-score {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
}

.vs {
    font-weight: 800;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.game-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 2rem 0;
    min-height: 150px;
}

.hand-display {
    font-size: 5rem;
    color: var(--secondary-color);
    transition: transform 0.3s ease;
}

.hand-display.shake {
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

.choices-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.choice-btn {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100px;
}

.choice-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.choice-btn i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.choice-btn span {
    font-weight: 600;
    color: var(--text-main);
}

.result-message {
    font-size: 1.25rem;
    font-weight: 600;
    min-height: 1.5em;
    margin-bottom: 1.5rem;
    color: var(--text-main);
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.btn-primary, .btn-secondary, .btn-danger {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 1rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--bg-color);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* =========================================
   7. Leaderboard Styles
   ========================================= */
.leaderboard-table-container {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.leaderboard-table th, .leaderboard-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table th {
    background-color: var(--bg-color);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.leaderboard-table tr:last-child td {
    border-bottom: none;
}

.leaderboard-table tr:hover {
    background-color: var(--bg-color);
}

.rank-cell {
    font-weight: 700;
    color: var(--primary-color);
}

/* =========================================
   8. Replays & Settings
   ========================================= */
.replays-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.replay-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.replay-header {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
}

.replay-details {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.settings-group {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.settings-group h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-main);
}

.avatar-customizer {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.avatar-preview {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    border: 3px solid white;
    box-shadow: var(--shadow-md);
}

.avatar-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.avatar-controls input[type="text"] {
    width: 60px;
    padding: 0.5rem;
    text-align: center;
    font-size: 1.2rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.avatar-controls input[type="color"] {
    width: 60px;
    height: 40px;
    border: none;
    cursor: pointer;
    background: none;
}

/* =========================================
   9. Overlays & Utilities
   ========================================= */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 2000;
}

.toast {
    background: var(--text-main);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* =========================================
   10. Responsive Adjustments
   ========================================= */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .main-nav {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .game-mode-selector {
        flex-direction: column;
        align-items: stretch;
    }
    
    .mode-toggle {
        justify-content: center;
    }
    
    .difficulty-selector {
        justify-content: center;
    }
    
    .pvp-controls {
        flex-direction: column;
    }
    
    #room-code-input {
        width: 100%;
    }
    
    .game-area {
        flex-direction: column;
        gap: 2rem;
    }
    
    .choices-container {
        flex-wrap: wrap;
    }
    
    .choice-btn {
        width: 80px;
        padding: 0.75rem;
    }
    
    .score {
        font-size: 2rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }
    
    .game-container {
        padding: 1.5rem;
    }
    
    .hand-display {
        font-size: 3.5rem;
    }
    
    .choice-btn {
        width: 70px;
        padding: 0.5rem;
    }
    
    .choice-btn i {
        font-size: 1.5rem;
    }
    
    .choice-btn span {
        font-size: 0.8rem;
    }
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.auth-form input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.auth-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}