/* CSS Variables - Dark Mode Theme (default) */
/* Color contrast ratios improved for WCAG AA compliance */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f172a;
    --bg-card: #1f2937;
    --bg-hover: #374151;
    --text-primary: #f5f5f5;
    --text-secondary: #b8bcc4;  /* Improved from #9ca3af - 5.2:1 contrast */
    --text-muted: #8b9099;      /* Improved from #6b7280 - 4.6:1 contrast */
    --accent-primary: #818cf8;   /* Improved from #6366f1 - 5.0:1 contrast */
    --accent-secondary: #a78bfa; /* Improved from #8b5cf6 - 5.3:1 contrast */
    --accent-success: #34d399;   /* Improved from #10b981 - 5.5:1 contrast */
    --accent-warning: #fbbf24;   /* Improved from #f59e0b - 6.0:1 contrast */
    --accent-danger: #f87171;    /* Improved from #ef4444 - 5.0:1 contrast */
    --success-color: #34d399;    /* Alias for accent-success */
    --danger-color: #f87171;     /* Alias for accent-danger */
    --border-color: #4b5563;     /* Improved from #374151 */
    --highlight-move: rgba(255, 255, 0, 0.4);
    --highlight-check: rgba(239, 68, 68, 0.5);
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* Light Mode Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #e2e8f0;
    --bg-tertiary: #cbd5e1;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --border-color: #cbd5e1;
    --highlight-move: rgba(255, 255, 0, 0.5);
    --highlight-check: rgba(239, 68, 68, 0.4);
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.15);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* App Container */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-img {
    height: 2.2rem;
    width: auto;
    vertical-align: middle;
}

.nav {
    display: flex;
    gap: 0.75rem;
}

/* Hide hamburger on desktop, shown via media query */
.hamburger-btn {
    display: none;
}

.nav-btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 8px;
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--accent-primary);
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 200px 1fr 280px;
    gap: 1.5rem;
    flex: 1;
}

/* Control Panel */
.control-panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    height: fit-content;
}

.control-group {
    margin-bottom: 1.25rem;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.control-group input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    padding: 0;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-group input[type="range"]:focus {
    outline: none;
}

.control-group input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.control-group label span {
    font-weight: 600;
    color: var(--accent-primary);
}

.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-success), #059669);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

/* Player Info */
.player-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-card);
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow);
}

.player-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.player-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-fallback {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.player-details {
    flex: 1;
}

.player-name {
    display: block;
    font-weight: 600;
    font-size: 1rem;
}

.player-rating {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-width: 120px;
    font-size: 1.1rem;
}

/* Chess Board */
.chess-board {
    width: 500px;
    height: 500px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

/* Chessboard.js overrides */
.board-b72b1 {
    border-radius: 8px;
    /* Prevent scroll while dragging pieces on touch devices */
    touch-action: none;
}

/* Allow touch manipulation on squares for piece selection */
.board-b72b1 .square-55d63 {
    touch-action: manipulation;
}

.square-55d63 {
    transition: background-color 0.15s ease;
}

.highlight-move {
    background-color: var(--highlight-move) !important;
}

.highlight-check {
    background-color: var(--highlight-check) !important;
}

.highlight-hint {
    background: radial-gradient(circle, rgba(0, 0, 0, 0.2) 25%, transparent 25%);
}

.highlight-selected {
    background-color: rgba(99, 102, 241, 0.5) !important;
}

/* Keyboard navigation focus indicator */
.keyboard-focus {
    outline: 3px solid var(--accent-primary) !important;
    outline-offset: -3px;
    box-shadow: inset 0 0 0 3px rgba(129, 140, 248, 0.5) !important;
}

/* Board focus state */
#board:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

#board:focus:not(:focus-visible) {
    outline: none;
}

/* Side Panel */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.status-card,
.move-history-card,
.info-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.status-card h3,
.move-history-card h3,
.info-card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.status-content p {
    margin-bottom: 0.5rem;
}

#gameStatus {
    font-size: 1.1rem;
    font-weight: 600;
}

.evaluation {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

#evalScore {
    font-weight: 600;
    color: var(--text-primary);
}

#evalScore.positive {
    color: var(--accent-success);
}

#evalScore.negative {
    color: var(--accent-danger);
}

/* Move History */
.move-list {
    max-height: 300px;
    overflow-y: auto;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
}

.move-row {
    display: flex;
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--border-color);
}

.move-number {
    width: 30px;
    color: var(--text-muted);
}

.move-white,
.move-black {
    flex: 1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.move-white:hover,
.move-black:hover {
    background: var(--bg-hover);
}

.move-current {
    background: var(--accent-primary);
    color: white;
}

/* Info List */
.info-list {
    list-style: none;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.info-list li {
    padding: 0.375rem 0;
    padding-left: 1rem;
    position: relative;
}

.info-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent-primary);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: auto;
}

/* Thinking Indicator */
.thinking {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-warning);
}

.thinking::before {
    content: '';
    width: 8px;
    height: 8px;
    background: var(--accent-warning);
    border-radius: 50%;
    animation: pulse 1s ease-in-out infinite;
}

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

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .control-panel {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }

    .control-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .game-area {
        order: -1;
    }

    .side-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .side-panel > * {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 900px) {
    .header {
        flex-wrap: wrap;
        position: relative;
    }

    .header .logo {
        order: 1;
        flex: 1;
    }

    /* Hamburger Button - Mobile */
    .hamburger-btn {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        padding: 10px;
        background: var(--bg-hover);
        border: none;
        border-radius: 8px;
        cursor: pointer;
        z-index: 1001;
        order: 2;
    }

    .hamburger-line {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--text-primary);
        border-radius: 2px;
        transition: all 0.3s ease;
    }

    .hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(1) {
        transform: rotate(45deg) translate(5px, 6px);
    }

    .hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(2) {
        opacity: 0;
    }

    .hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -6px);
    }

    /* Mobile Navigation */
    .nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--bg-card);
        padding: 1rem;
        border-radius: 0 0 12px 12px;
        box-shadow: var(--shadow-lg);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: all 0.3s ease;
        z-index: 1000;
        order: 3;
    }

    .nav.active {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .nav-btn {
        width: 100%;
        text-align: center;
        padding: 0.875rem 1rem;
        min-height: 44px;
    }

    /* Touch target sizes for mobile */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Improve move history touch targets */
    .move-white,
    .move-black {
        padding: 0.625rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .chess-board {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 1;
    }

    .control-panel {
        grid-template-columns: 1fr;
    }

    .player-info {
        max-width: 100%;
    }
}

/* Game Over Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.modal p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal .btn {
    min-width: 120px;
}

/* ==================== AUTH MODAL ==================== */

.auth-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.auth-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.auth-modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    position: relative;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.auth-modal-overlay.active .auth-modal {
    transform: translateY(0);
}

.auth-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.auth-close:hover {
    color: var(--text-primary);
}

/* Auth Tabs */
.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    color: var(--accent-primary);
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
}

/* Auth Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-error {
    color: var(--accent-danger);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    min-height: 1.25rem;
}

.btn-full {
    width: 100%;
}

/* Auth Divider */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.auth-divider span {
    padding: 0 1rem;
}

/* OAuth Buttons */
.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.oauth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.oauth-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.oauth-btn svg {
    flex-shrink: 0;
}

.oauth-btn.google:hover {
    border-color: #ea4335;
}

.oauth-btn.github:hover {
    border-color: #f0f0f0;
}

.oauth-btn.discord:hover {
    border-color: #5865f2;
}

/* ==================== USER MENU ==================== */

.nav-btn.logged-in {
    background: var(--accent-primary);
}

.user-menu-dropdown {
    position: fixed;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem;
    min-width: 280px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideDown 0.2s ease;
}

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

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.25rem;
}

.user-info {
    flex: 1;
}

.user-name {
    display: block;
    font-weight: 600;
    font-size: 1.1rem;
}

.user-rating {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.user-menu-stats {
    display: flex;
    justify-content: space-around;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
}

.user-menu-stats .stat {
    text-align: center;
}

.user-menu-stats .stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-primary);
}

.user-menu-stats .stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.user-menu-items {
    padding-top: 0.75rem;
}

.user-menu-items hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0.5rem 0;
}

.menu-item {
    display: block;
    padding: 0.625rem 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.2s;
}

.menu-item:hover {
    background: var(--bg-hover);
}

.menu-item.logout {
    color: var(--accent-danger);
}

.menu-item.logout:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ==================== FRIENDS ==================== */

.friends-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.friends-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.friends-modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    position: relative;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.friends-modal-overlay.active .friends-modal {
    transform: translateY(0);
}

.friends-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.friends-close:hover {
    color: var(--text-primary);
}

.friends-modal h2 {
    margin-bottom: 1rem;
    text-align: center;
}

.friends-tabs {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.friends-tab {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    font-size: 0.9rem;
}

.friends-tab:hover {
    color: var(--text-primary);
}

.friends-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.friends-count {
    font-size: 0.8rem;
    opacity: 0.8;
}

.pending-count {
    color: var(--accent-warning);
}

.friends-tab-content {
    display: none;
    overflow-y: auto;
    max-height: calc(80vh - 200px);
}

.friends-tab-content.active {
    display: block;
}

.friends-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.friends-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.friend-item:hover {
    background: var(--bg-hover);
}

.friend-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
}

.friend-info {
    flex: 1;
    min-width: 0;
}

.friend-name {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-rating,
.friend-status {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.friend-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

.requests-section-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 1rem 0 0.5rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.requests-section-title:first-child {
    margin-top: 0;
}

/* Add Friend Form */
.add-friend-form {
    padding: 1rem 0;
}

.add-friend-form label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.search-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.search-input-wrapper input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-results {
    margin-top: 1rem;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-hint,
.search-loading,
.search-empty,
.search-error {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
}

.search-error {
    color: var(--accent-danger);
}

.status-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ==================== CHALLENGES ==================== */

.challenge-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    animation: fadeIn 0.2s ease;
}

.challenge-modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

.challenge-modal h3 {
    margin: 0 0 1rem 0;
    color: var(--accent-primary);
}

.challenge-modal p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.challenge-details {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin: 1rem 0 !important;
}

.challenge-details .time-control {
    background: var(--bg-tertiary);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-weight: 500;
    color: var(--text-primary);
}

.challenge-details .game-type {
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.85rem;
}

.challenge-details .game-type.casual {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-success);
}

.challenge-details .game-type.rated {
    background: rgba(251, 191, 36, 0.15);
    color: var(--accent-warning);
}

.challenge-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.challenge-actions .btn {
    flex: 1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* Challenge Setup Modal */
.challenge-setup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    animation: fadeIn 0.2s ease;
}

.challenge-setup-modal {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

.challenge-setup-modal h3 {
    margin: 0 0 1.5rem 0;
    text-align: center;
    color: var(--text-primary);
}

.challenge-option {
    margin-bottom: 1.25rem;
}

.challenge-option label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.challenge-option select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
}

.challenge-option select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.game-type-buttons {
    display: flex;
    gap: 0.5rem;
}

.game-type-btn {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.game-type-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.game-type-btn.active {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent-primary);
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 1rem 2rem;
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    z-index: 1200;
    animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s;
}

.toast-notification.success {
    background: var(--accent-success);
    color: white;
}

.toast-notification.error {
    background: var(--accent-danger);
    color: white;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ==================== GAME ANALYSIS ==================== */

.analysis-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    animation: fadeIn 0.2s ease;
}

.analysis-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 95%;
    max-width: 1000px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.analysis-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
}

.analysis-close:hover {
    color: var(--text-primary);
}

.analysis-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.analysis-header h2 {
    margin: 0 0 0.5rem 0;
}

.game-players {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    font-size: 1.1rem;
}

.game-players .player {
    font-weight: 500;
}

.game-players .player.white::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background: #f0d9b5;
    border: 1px solid #999;
    border-radius: 2px;
    margin-right: 0.5rem;
}

.game-players .player.black::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background: #333;
    border: 1px solid #999;
    border-radius: 2px;
    margin-right: 0.5rem;
}

.game-players .result {
    padding: 0.25rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
    font-weight: 600;
}

.analysis-content {
    display: flex;
    padding: 1.5rem;
    gap: 1.5rem;
    overflow: hidden;
    flex: 1;
}

.analysis-board-container {
    flex-shrink: 0;
}

.analysis-board {
    width: 400px;
    height: 400px;
    border-radius: 4px;
    overflow: hidden;
}

.analysis-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.control-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.control-btn.play-btn {
    width: 56px;
}

.speed-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.speed-control input[type="range"] {
    width: 120px;
}

.analysis-sidebar {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.move-navigator {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 1rem;
}

.move-table {
    width: 100%;
    border-collapse: collapse;
}

.move-table td {
    padding: 0.375rem 0.5rem;
}

.move-number {
    color: var(--text-muted);
    text-align: right;
    width: 30px;
}

.move {
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}

.move:hover {
    background: var(--bg-hover);
}

.move.current {
    background: var(--accent-primary);
    color: white;
}

.no-moves {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.game-info {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 1rem;
}

.game-info p {
    margin: 0.5rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.game-info strong {
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .analysis-content {
        flex-direction: column;
    }

    .analysis-board {
        width: 100%;
        height: auto;
        aspect-ratio: 1;
        max-width: 400px;
        margin: 0 auto;
    }

    .analysis-sidebar {
        min-width: 0;
    }
}

/* ==================== ONBOARDING ==================== */

.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    pointer-events: none;
}

.onboarding-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.onboarding-highlight {
    position: relative;
    z-index: 2001;
    box-shadow: 0 0 0 4px var(--accent-primary), 0 0 0 8px rgba(99, 102, 241, 0.3);
    border-radius: 8px;
}

.onboarding-tooltip {
    position: fixed;
    z-index: 2002;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: auto;
}

.onboarding-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.tooltip-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 320px;
    box-shadow: var(--shadow-lg);
}

.tooltip-content h3 {
    margin: 0 0 0.75rem 0;
    color: var(--accent-primary);
    font-size: 1.1rem;
}

.tooltip-content p {
    margin: 0 0 1rem 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.tooltip-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tooltip-btn {
    flex: 1;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tooltip-btn.primary {
    background: var(--accent-primary);
    color: white;
}

.tooltip-btn.primary:hover {
    background: var(--accent-primary-hover);
}

.tooltip-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tooltip-btn.secondary:hover {
    background: var(--bg-hover);
}

.tooltip-progress {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.progress-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-color);
    transition: all 0.2s;
}

.progress-dot.active {
    background: var(--accent-primary);
    transform: scale(1.2);
}

.progress-dot.completed {
    background: var(--accent-success);
}

.tooltip-skip {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.5rem;
}

.tooltip-skip:hover {
    color: var(--text-secondary);
    text-decoration: underline;
}

.tooltip-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--bg-card);
    transform: rotate(45deg);
}

.position-top .tooltip-arrow {
    bottom: -6px;
    left: 50%;
    margin-left: -6px;
}

.position-bottom .tooltip-arrow {
    top: -6px;
    left: 50%;
    margin-left: -6px;
}

.position-left .tooltip-arrow {
    right: -6px;
    top: 50%;
    margin-top: -6px;
}

.position-right .tooltip-arrow {
    left: -6px;
    top: 50%;
    margin-top: -6px;
}

.onboarding-welcome {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 2003;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
}

.onboarding-welcome.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.welcome-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
}

.welcome-content h2 {
    margin: 0 0 0.75rem 0;
    color: var(--accent-primary);
}

.welcome-content p {
    margin: 0 0 1.5rem 0;
    color: var(--text-secondary);
}

/* ==================== MULTIPLAYER ==================== */

/* Time Control Selection */
.time-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.time-control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.time-control-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
}

.time-control-btn.selected {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.15);
}

.time-control-btn .time-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.time-control-btn .time-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.time-control-btn .time-value {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.time-control-btn .queue-count {
    font-size: 0.7rem;
    color: var(--accent-primary);
    margin-top: 0.25rem;
    font-weight: 500;
}

/* Searching Spinner */
.searching-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 1s linear infinite;
}

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

/* Game Notification */
.game-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

.game-notification.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* Game Clock */
.game-clock {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 1.25rem;
    font-weight: 600;
}

.game-clock.active {
    background: var(--accent-primary);
    color: white;
}

.game-clock.low-time {
    background: var(--accent-danger);
    color: white;
    animation: pulse 0.5s ease-in-out infinite;
}

/* Multiplayer Controls */
.multiplayer-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.multiplayer-controls .btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.85rem;
}

/* Opponent Info */
.opponent-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.opponent-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-success);
}

.opponent-status .status-dot.disconnected {
    background: var(--accent-danger);
    animation: pulse 1s ease-in-out infinite;
}

/* ==================== LEADERBOARD ==================== */

.leaderboard-container {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.leaderboard-tabs {
    display: flex;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
}

.lb-tab {
    flex: 1;
    padding: 0.875rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
}

.lb-tab:hover {
    color: var(--text-primary);
}

.lb-tab.active {
    color: var(--accent-primary);
}

.lb-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-primary);
}

.leaderboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    margin: 2rem auto;
    animation: spin 1s linear infinite;
}

.empty-state {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Leaderboard List */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lb-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: background 0.2s;
}

.lb-player:hover {
    background: var(--bg-hover);
}

.lb-player.top-rank {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.1));
}

.lb-rank {
    width: 32px;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.lb-player.top-rank .lb-rank {
    font-size: 1.25rem;
}

.lb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.lb-info {
    flex: 1;
    min-width: 0;
}

.lb-username {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-category {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.lb-rating {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-primary);
    min-width: 50px;
    text-align: right;
}

.lb-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 80px;
}

.lb-record {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.lb-winrate {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Recent Games List */
.recent-games-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.recent-game {
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 3px solid var(--border-color);
}

.recent-game.white-win {
    border-left-color: #fff;
}

.recent-game.black-win {
    border-left-color: #333;
}

.recent-game.draw {
    border-left-color: var(--text-muted);
}

.rg-players {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.rg-white {
    font-weight: 500;
}

.rg-vs {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.rg-black {
    font-weight: 500;
}

.rg-result {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent-primary);
}

.rg-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Stats Modal */
.stats-modal {
    text-align: center;
}

.stats-rating {
    margin: 1.5rem 0;
}

.stats-rating .rating-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.stats-rating .rating-category {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.rating-progress {
    margin-top: 0.75rem;
}

.progress-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.rating-progress span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.rating-max {
    color: var(--accent-success);
    font-weight: 500;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.stat-box {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
}

.stat-box .stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-box .stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.stat-box.win .stat-value {
    color: var(--accent-success);
}

.stat-box.loss .stat-value {
    color: var(--accent-danger);
}

.stat-box.draw .stat-value {
    color: var(--text-secondary);
}

.stats-winrate {
    font-size: 1rem;
    color: var(--text-secondary);
}

.stats-winrate strong {
    color: var(--accent-primary);
    font-size: 1.25rem;
}

/* ==================== PUZZLE MODAL ==================== */

#puzzle-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#puzzle-modal[style*="display: block"] {
    display: flex !important;
}

.puzzle-modal-content {
    max-width: 600px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.puzzle-container {
    padding: 1rem 0;
}

.puzzle-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.puzzle-info .label {
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.puzzle-board {
    width: 100%;
    max-width: 400px;
    margin: 0 auto 1rem;
}

#puzzle-board {
    width: 400px !important;
    height: 400px !important;
}

.puzzle-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.puzzle-message {
    font-weight: 500;
}

.puzzle-message.success {
    color: var(--accent-success);
}

.puzzle-message.error {
    color: var(--accent-danger);
}

.puzzle-message.info {
    color: var(--accent-primary);
}

.puzzle-timer {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 1.25rem;
    color: var(--text-secondary);
}

.puzzle-controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.puzzle-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.puzzle-stats .stat {
    text-align: center;
}

.puzzle-stats .label {
    color: var(--text-muted);
    display: block;
    font-size: 0.85rem;
}

.highlight-hint {
    box-shadow: inset 0 0 0 4px var(--accent-warning) !important;
}

/* ==================== FEED MODAL ==================== */

#feed-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#feed-modal[style*="display: block"] {
    display: flex !important;
}

.feed-modal-content {
    max-width: 600px;
    max-height: 80vh;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
}

.feed-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.feed-tab {
    padding: 0.5rem 1.5rem;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feed-tab:hover {
    color: var(--text-primary);
}

.feed-tab.active {
    background: var(--accent-primary);
    color: white;
}

.feed-container {
    max-height: 60vh;
    overflow-y: auto;
}

.feed-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.feed-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 10px;
    transition: transform 0.2s ease;
}

.feed-item:hover {
    transform: translateX(4px);
}

.feed-item-avatar {
    flex-shrink: 0;
}

.feed-item-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.feed-item-content {
    flex: 1;
    min-width: 0;
}

.feed-item-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}

.feed-item-username {
    font-weight: 600;
    color: var(--text-primary);
}

.feed-item-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.feed-item-body {
    color: var(--text-secondary);
}

.feed-item-icon {
    margin-right: 0.5rem;
}

.feed-item-actions {
    margin-top: 0.5rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    padding: 0;
    font-size: 0.9rem;
}

.btn-link:hover {
    text-decoration: underline;
}

.feed-empty,
.feed-error {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.feed-loading {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
}

#feed-load-more {
    display: block;
    width: 100%;
    margin-top: 1rem;
}

/* ==================== NEWS ITEMS ==================== */

.news-item {
    border-left: 3px solid var(--accent-primary);
}

.news-icon {
    width: 48px;
    height: 48px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.feed-item-source {
    font-weight: 600;
    color: var(--accent-primary);
    font-size: 0.85rem;
}

.news-title {
    display: block;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    line-height: 1.4;
    margin: 0.25rem 0;
    transition: color 0.2s ease;
}

.news-title:hover {
    color: var(--accent-primary);
}

.news-description {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0.5rem 0 0 0;
    line-height: 1.4;
}

/* ==================== SKELETON LOADING STATES ==================== */

/* Skeleton base animation */
@keyframes skeleton-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-hover) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* Skeleton shapes */
.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-heading {
    height: 1.5em;
    width: 40%;
    margin-bottom: 1rem;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-button {
    height: 40px;
    width: 100px;
    border-radius: 8px;
}

.skeleton-card {
    padding: 1rem;
    background: var(--bg-card);
    border-radius: 12px;
}

/* Skeleton for move list */
.skeleton-move-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.skeleton-move-number {
    width: 30px;
    height: 1em;
}

.skeleton-move {
    width: 50px;
    height: 1em;
}

/* Skeleton for player info */
.skeleton-player {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-card);
    border-radius: 10px;
}

.skeleton-player-details {
    flex: 1;
}

.skeleton-player-name {
    height: 1em;
    width: 80px;
    margin-bottom: 0.5rem;
}

.skeleton-player-rating {
    height: 0.8em;
    width: 60px;
}

/* Skeleton for feed items */
.skeleton-feed-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 10px;
    margin-bottom: 0.75rem;
}

.skeleton-feed-content {
    flex: 1;
}

/* Skeleton for leaderboard */
.skeleton-lb-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.skeleton-lb-rank {
    width: 32px;
    height: 1em;
}

.skeleton-lb-info {
    flex: 1;
}

.skeleton-lb-rating {
    width: 50px;
    height: 1.2em;
}

/* Loading spinner with message */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-muted);
}

.loading-state .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading-state .loading-message {
    font-size: 0.9rem;
}

/* Error state */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}

.error-state .error-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--accent-danger);
}

.error-state .error-message {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.error-state .retry-btn {
    padding: 0.5rem 1.5rem;
    background: var(--accent-primary);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.error-state .retry-btn:hover {
    background: var(--accent-secondary);
}

/* Screen reader only class */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip navigation link for accessibility */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    font-weight: 600;
    z-index: 10000;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
    outline: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Enhanced focus styles for interactive elements */
.nav-btn:focus-visible,
.btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.3);
}

/* Focus style for form inputs */
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 0;
    border-color: var(--accent-primary);
}

/* Focus style for details/summary (FAQ) */
.faq-item summary:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== FAQ SECTION (AEO) ==================== */

.faq-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    margin: 2rem 0;
}

.faq-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    text-align: center;
}

.faq-grid {
    display: grid;
    gap: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.faq-item {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.faq-item summary {
    padding: 1rem 1.25rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-primary);
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary::after {
    content: '+';
    font-size: 1.25rem;
    color: var(--accent-primary);
    transition: transform 0.2s;
}

.faq-item[open] summary::after {
    transform: rotate(45deg);
}

.faq-item summary:hover {
    background: var(--bg-hover);
}

.faq-answer {
    padding: 0 1.25rem 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.faq-answer p {
    margin: 0;
}

/* ==================== ENHANCED FOOTER ==================== */

.footer {
    background: var(--bg-card);
    border-radius: 12px;
    margin-top: 2rem;
    padding: 0;
}

.footer-content {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 2rem;
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.footer-brand h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.footer-brand p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.footer-links h4 {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-links ul {
    list-style: none;
}

.footer-links li {
    margin-bottom: 0.5rem;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent-primary);
}

.footer-bottom {
    padding: 1.5rem 2rem;
    text-align: center;
}

.footer-bottom p {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.footer-bottom a {
    color: var(--accent-primary);
    text-decoration: none;
}

.footer-bottom a:hover {
    text-decoration: underline;
}

.footer-bottom .copyright {
    margin-top: 0.5rem;
    font-size: 0.8rem;
}

@media (max-width: 768px) {
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .footer-links {
        padding-top: 1rem;
        border-top: 1px solid var(--border-color);
    }

    .faq-section {
        padding: 1.5rem 1rem;
    }
}

/* ==================== Promotion Dialog ==================== */
.promotion-dialog {
    position: absolute;
    z-index: 1000;
    background: var(--bg-card);
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    padding: 0;
    animation: promotionDialogFadeIn 0.2s ease-out;
    /* Ensure dialog stays within viewport */
    max-width: calc(100vw - 20px);
}

@keyframes promotionDialogFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.promotion-dialog-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    gap: 10px;
}

.promotion-title {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.promotion-pieces {
    display: flex;
    gap: 6px;
}

.promotion-piece {
    width: 50px;
    height: 50px;
    padding: 4px;
    background: var(--bg-hover);
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.promotion-piece:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: scale(1.1);
}

.promotion-piece:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.3);
}

.promotion-piece img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.promotion-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s ease;
}

.promotion-cancel:hover {
    background: var(--accent-danger);
    border-color: var(--accent-danger);
    color: white;
}

.promotion-cancel:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

/* ==================== Multiplayer Controls ==================== */
.multiplayer-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.multiplayer-controls .btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.multiplayer-controls .btn-icon {
    font-size: 1rem;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
    border: none;
}

.btn-danger:hover {
    background: #dc2626;
}

/* ==================== Password Requirements ==================== */
.password-requirements {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
}

.password-requirements .requirement {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: color 0.2s ease;
}

.password-requirements .requirement.met {
    color: var(--success-color);
}

.password-requirements .req-icon {
    font-size: 0.7rem;
    width: 1em;
    text-align: center;
}

/* ==================== Player Clock ==================== */
.player-clock {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    margin-left: auto;
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
    min-width: 70px;
    text-align: center;
}

.player-clock .clock-time {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text-primary);
}

.player-clock.active {
    background: var(--accent-primary);
    animation: clockPulse 1s ease-in-out infinite;
}

.player-clock.low-time {
    background: var(--accent-danger);
    animation: clockUrgent 0.5s ease-in-out infinite;
}

.player-clock.low-time .clock-time {
    color: white;
}

@keyframes clockPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

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

/* ==================== Move Review ==================== */
.move-white[data-ply],
.move-black[data-ply] {
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    padding: 2px 4px;
    border-radius: 3px;
}

.move-white[data-ply]:hover,
.move-black[data-ply]:hover {
    background: var(--accent-primary);
    color: white;
}

.move-white.active,
.move-black.active {
    background: var(--accent-primary);
    color: white;
    font-weight: bold;
}

.review-mode-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--accent-primary);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.btn-back-to-current {
    background: white;
    color: var(--accent-primary);
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s ease;
}

.btn-back-to-current:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ==================== Forgot Password ==================== */
.forgot-password-link {
    display: block;
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-decoration: none;
    transition: color 0.15s ease;
}

.forgot-password-link:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* ==================== Rating Notification ==================== */
.rating-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    z-index: 10000;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 2px solid var(--border-color);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.rating-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.rating-notification.fade-out {
    transform: translateX(-50%) translateY(-20px);
    opacity: 0;
}

.rating-notification.rating-up {
    border-color: var(--accent-success);
}

.rating-notification.rating-down {
    border-color: var(--accent-danger);
}

.rating-change-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.rating-label {
    color: var(--text-secondary);
    font-weight: 500;
    margin-right: 0.5rem;
}

.rating-old {
    color: var(--text-muted);
    text-decoration: line-through;
}

.rating-arrow {
    color: var(--text-secondary);
}

.rating-new {
    color: var(--text-primary);
    font-weight: bold;
    font-size: 1.1rem;
}

.rating-up .rating-change {
    color: var(--accent-success);
    font-weight: bold;
}

.rating-down .rating-change {
    color: var(--accent-danger);
    font-weight: bold;
}

/* ==================== Small Phone Responsive ==================== */
@media (max-width: 480px) {
    /* ==================== MOBILE LAYOUT ==================== */
    .app-container {
        padding: 0.5rem;
        padding-bottom: 1rem;
    }

    .header {
        padding: 0.5rem 0.75rem;
        margin-bottom: 0.75rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .logo-img {
        height: 28px;
        width: auto;
    }

    /* ==================== MOBILE NAVIGATION ==================== */
    .hamburger-btn {
        width: 48px;
        height: 48px;
    }

    .nav {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .nav-btn {
        padding: 1rem;
        font-size: 1rem;
        min-height: 52px;
        border-radius: 10px;
    }

    /* ==================== MOBILE CHESS BOARD ==================== */
    .game-area {
        width: 100%;
        max-width: 100%;
    }

    .board-wrapper {
        width: 100% !important;
        max-width: 100vw;
        touch-action: none;
    }

    #board {
        width: 100% !important;
    }

    .board-b72b1 {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 / 1;
    }

    /* Larger pieces for touch */
    .piece-417db {
        cursor: pointer !important;
    }

    /* ==================== MOBILE PLAYER INFO & CLOCKS ==================== */
    .player-info {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem;
        margin: 0.5rem 0;
    }

    .player-name {
        font-size: 0.95rem;
        font-weight: 600;
    }

    .player-clock {
        padding: 0.5rem 0.75rem;
        min-width: 70px;
        border-radius: 8px;
    }

    .player-clock .clock-time {
        font-size: 1.1rem;
        font-weight: 700;
    }

    /* ==================== MOBILE CONTROL PANEL ==================== */
    .control-panel {
        padding: 1rem;
        margin-top: 0.75rem;
    }

    .control-group {
        margin-bottom: 1rem;
    }

    .control-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    /* Larger touch targets for range sliders on mobile */
    .control-group input[type="range"] {
        height: 12px;
        margin: 0.5rem 0;
    }

    .control-group input[type="range"]::-webkit-slider-thumb {
        width: 32px;
        height: 32px;
    }

    .control-group input[type="range"]::-moz-range-thumb {
        width: 32px;
        height: 32px;
    }

    .control-buttons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    /* Touch-friendly buttons */
    .btn {
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
        min-height: 48px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .btn-full {
        grid-column: 1 / -1;
    }

    /* Sliders */
    input[type="range"] {
        height: 8px;
        -webkit-appearance: none;
        appearance: none;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
        -webkit-appearance: none;
        appearance: none;
    }

    /* ==================== MOBILE MOVE LIST ==================== */
    .move-list {
        max-height: 120px;
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    .move-list .move {
        padding: 0.25rem 0.5rem;
        min-height: 32px;
    }

    /* ==================== MOBILE SIDE PANEL ==================== */
    .side-panel {
        margin-top: 0.75rem;
    }

    .side-panel > * {
        min-width: 100%;
        padding: 1rem;
        border-radius: 12px;
    }

    /* ==================== MOBILE STATUS BAR ==================== */
    .status-bar {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
        border-radius: 10px;
        margin: 0.5rem 0;
    }

    /* ==================== MOBILE GAME NOTIFICATIONS ==================== */
    .game-notification {
        font-size: 0.9rem;
        padding: 0.75rem 1.25rem;
        max-width: 90%;
        border-radius: 10px;
    }

    /* ==================== MOBILE PROMOTION DIALOG ==================== */
    .promotion-dialog {
        left: 50% !important;
        transform: translateX(-50%);
        padding: 0.75rem;
        border-radius: 12px;
    }

    .promotion-piece {
        width: 52px;
        height: 52px;
        border-radius: 10px;
    }

    .promotion-piece img {
        width: 40px;
        height: 40px;
    }

    /* ==================== MOBILE MODALS ==================== */
    .auth-modal-overlay {
        padding: 0.5rem;
        align-items: flex-start;
        padding-top: 2rem;
    }

    .auth-modal {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 1.25rem;
        padding-top: 3rem;
        border-radius: 16px;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
    }

    .auth-close {
        top: 0.75rem;
        right: 0.75rem;
        font-size: 1.25rem;
        padding: 0.75rem;
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-tertiary);
        border-radius: 10px;
        color: var(--text-primary);
    }

    .auth-tabs {
        margin-bottom: 1.25rem;
    }

    .auth-tab {
        padding: 0.875rem 0.5rem;
        font-size: 0.95rem;
        min-height: 48px;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .form-group input {
        padding: 0.875rem 1rem;
        font-size: 1rem;
        min-height: 48px;
        border-radius: 10px;
    }

    .form-group small {
        font-size: 0.8rem;
        line-height: 1.4;
    }

    /* ==================== MOBILE TIME CONTROL BUTTONS ==================== */
    .time-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .time-control-btn {
        padding: 1rem 0.75rem;
        min-height: 80px;
        border-radius: 12px;
    }

    .time-control-btn .time-icon {
        font-size: 1.25rem;
    }

    .time-control-btn .time-label {
        font-size: 0.7rem;
    }

    .time-control-btn .time-value {
        font-size: 1rem;
    }

    /* ==================== MOBILE RATING NOTIFICATION ==================== */
    .rating-notification {
        width: 90%;
        max-width: 320px;
        padding: 1rem 1.25rem;
        border-radius: 12px;
    }

    .rating-change-content {
        font-size: 0.95rem;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
    }

    /* ==================== MOBILE FOOTER ==================== */
    .footer {
        padding: 1rem;
        font-size: 0.8rem;
        margin-top: 1rem;
    }

    .footer p {
        margin: 0.25rem 0;
    }
}

/* ==================== Puzzle Streak ==================== */
.streak-stat {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.streak-value {
    font-weight: bold;
    color: var(--accent-warning);
}

.streak-fire {
    font-size: 1.1em;
    margin-left: 0.25rem;
}

.streak-fire-animated {
    animation: streakFlame 0.5s ease-in-out infinite alternate;
}

@keyframes streakFlame {
    0% { transform: scale(1) rotate(-5deg); }
    100% { transform: scale(1.2) rotate(5deg); }
}

/* ==================== Theme Toggle ==================== */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    min-width: auto;
    border-radius: 50%;
    width: 40px;
    height: 40px;
}

.theme-toggle .theme-icon-dark,
.theme-toggle .theme-icon-light {
    font-size: 1.2rem;
    line-height: 1;
}

/* Dark mode (default): show moon, hide sun */
.theme-icon-dark {
    display: inline;
}

.theme-icon-light {
    display: none;
}

/* Light mode: show sun, hide moon */
[data-theme="light"] .theme-icon-dark {
    display: none;
}

[data-theme="light"] .theme-icon-light {
    display: inline;
}

/* Smooth transition for theme changes */
body {
    transition: background 0.3s ease, color 0.3s ease;
}

.header,
.control-panel,
.game-area,
.side-panel > *,
.btn,
.auth-modal,
.modal-content {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* ==================== Profile Modal ==================== */
.profile-modal {
    max-width: 450px;
}

.profile-stat {
    text-align: center;
    padding: 1rem;
    background: var(--bg-hover);
    border-radius: 8px;
}

.profile-stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
}

.profile-stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.profile-games-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.profile-games-list {
    max-height: 250px;
    overflow-y: auto;
}

.profile-games-loading,
.profile-games-empty,
.profile-games-error {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.profile-games-error {
    color: var(--accent-danger);
}

.profile-game-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: var(--bg-hover);
}

.profile-game-item:last-child {
    margin-bottom: 0;
}

.profile-game-result {
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    min-width: 45px;
    text-align: center;
}

.profile-game-result.win {
    background: rgba(52, 211, 153, 0.2);
    color: var(--accent-success);
}

.profile-game-result.loss {
    background: rgba(248, 113, 113, 0.2);
    color: var(--accent-danger);
}

.profile-game-result.draw {
    background: rgba(139, 144, 153, 0.2);
    color: var(--text-muted);
}

.profile-game-info {
    flex: 1;
    min-width: 0;
}

.profile-game-opponent {
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-game-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.profile-game-rating {
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 40px;
    text-align: right;
}

.profile-game-rating.positive {
    color: var(--accent-success);
}

.profile-game-rating.negative {
    color: var(--accent-danger);
}

/* ==================== Live Games ==================== */
.live-games-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.live-game-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-hover);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.live-game-players {
    flex: 1;
    min-width: 0;
}

.live-game-white,
.live-game-black {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.live-game-white .piece-icon {
    color: #f0d9b5;
}

.live-game-black .piece-icon {
    color: #555;
}

.live-game-vs {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0.25rem 0 0.25rem 1.5rem;
}

.live-game-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.live-game-moves {
    color: var(--accent-primary);
    font-weight: 500;
}

.btn-watch {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.player-rating {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==================== Puzzle & Feed Pages ==================== */

.page-content {
    flex: 1;
    padding: 1rem 0;
}

/* Puzzle Page */
.puzzle-page {
    max-width: 1200px;
    margin: 0 auto;
}

.puzzle-header {
    margin-bottom: 1.5rem;
}

.puzzle-header h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.puzzle-info-bar {
    display: flex;
    gap: 2rem;
    color: var(--text-secondary);
}

.puzzle-info-bar .label {
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.puzzle-main {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

.puzzle-board-wrapper {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.puzzle-board-large {
    width: 400px;
    height: 400px;
    margin: 0 auto 1rem;
}

.puzzle-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-hover);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.puzzle-message {
    font-weight: 500;
}

.puzzle-message.success { color: var(--accent-success); }
.puzzle-message.error { color: var(--accent-danger); }
.puzzle-message.info { color: var(--text-primary); }

.puzzle-timer {
    font-family: monospace;
    font-size: 1.25rem;
    color: var(--text-secondary);
}

.puzzle-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.puzzle-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.puzzle-stats-card,
.puzzle-history-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.puzzle-stats-card h3,
.puzzle-history-card h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-item {
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-hover);
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 1rem;
}

/* Feed Page */
.feed-page {
    max-width: 800px;
    margin: 0 auto;
}

.feed-tabs-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--bg-card);
    padding: 0.5rem;
    border-radius: 12px;
}

.feed-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.feed-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.feed-tab.active {
    background: var(--accent-primary);
    color: white;
}

.feed-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

.feed-list-page {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.feed-list-page .feed-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-hover);
    border-radius: 8px;
    transition: background 0.2s;
}

.feed-list-page .feed-item:hover {
    background: var(--bg-input);
}

.feed-item-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.feed-item-icon.news-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border-radius: 50%;
    font-size: 1.5rem;
}

.feed-item-content {
    flex: 1;
    min-width: 0;
}

.feed-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.feed-item-username,
.feed-item-source {
    font-weight: 600;
    color: var(--text-primary);
}

.feed-item-time {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.feed-item-message {
    color: var(--text-secondary);
}

.news-title {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    display: block;
    margin-bottom: 0.25rem;
}

.news-title:hover {
    text-decoration: underline;
}

.news-description {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.load-more-btn {
    width: 100%;
    margin-top: 1rem;
}

.feed-empty {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Responsive for puzzle page */
@media (max-width: 900px) {
    .puzzle-main {
        grid-template-columns: 1fr;
    }

    .puzzle-board-large {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 1;
    }

    .puzzle-sidebar {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .puzzle-stats-card,
    .puzzle-history-card {
        flex: 1;
        min-width: 250px;
    }
}

@media (max-width: 480px) {
    .puzzle-info-bar {
        flex-direction: column;
        gap: 0.5rem;
    }

    .puzzle-controls {
        flex-direction: column;
    }

    .puzzle-controls .btn {
        width: 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .feed-tabs-bar {
        flex-wrap: wrap;
    }

    .feed-tab {
        flex: none;
        width: calc(50% - 0.25rem);
    }

    .feed-tab:last-child {
        width: 100%;
    }
}
