:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --secondary-color: #6B7280;
    --success-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --background: #F9FAFB;
    --surface: #FFFFFF;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 400px;
}

.toast {
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: slideIn 0.3s ease-out;
    border-left: 4px solid;
}

.toast.toast-error {
    border-left-color: var(--danger-color);
    background: #FEF2F2;
}

.toast.toast-success {
    border-left-color: var(--success-color);
    background: #F0FDF4;
}

.toast.toast-warning {
    border-left-color: var(--warning-color);
    background: #FFFBEB;
}

.toast.toast-info {
    border-left-color: var(--primary-color);
    background: #EEF2FF;
}

.toast-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 0.875rem;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

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

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.removing {
    animation: slideOut 0.3s ease-out forwards;
}

.screen {
    display: none !important;
    min-height: 100vh;
}

.screen.active {
    display: block !important;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Navbar */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-content h1 {
    font-size: 1.5rem;
}

.logo-link {
    transition: transform 0.2s ease, opacity 0.2s ease;
    user-select: none;
}

.logo-link:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

.logo-link:active {
    transform: scale(0.95);
}

.nav-right {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
    background: #4B5563;
    transform: translateY(-2px);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.25rem;
    width: 100%;
}

.btn-icon {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--background);
}

/* Loading Screen */
#loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

#loading h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
}

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

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

/* Auth Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

#login-screen h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
    text-align: center;
}

#login-screen h2 {
    text-align: center;
    margin-bottom: 0.5rem;
}

#login-screen p {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.info-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Home Screen */
.welcome {
    text-align: center;
    margin-bottom: 3rem;
}

.welcome h2 {
    font-size: 2rem;
}

.actions {
    margin-bottom: 2rem;
}

.game-link-section {
    background: var(--surface);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.game-link-section h3 {
    margin-bottom: 1rem;
}

.link-container {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.link-container input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

.waiting-text {
    color: var(--text-secondary);
    font-style: italic;
}

.hidden {
    display: none !important;
}

/* Waiting Section */
.waiting-section {
    text-align: center;
    padding: 3rem 2rem;
}

.waiting-section h2 {
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.waiting-section .spinner {
    margin-top: 2rem;
}

/* Disconnect Banner */
.disconnect-banner {
    background: var(--warning-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    animation: pulse 2s ease-in-out infinite;
}

.disconnect-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.disconnect-content span {
    font-weight: 600;
    flex: 1;
    min-width: 200px;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

/* Session Score */
.session-score {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.score-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.score-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
}

.score-separator {
    font-size: 2rem;
    font-weight: 300;
    color: var(--text-secondary);
}

/* Game Screen */
.game-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.player {
    text-align: center;
    flex: 1;
}

.player-name {
    font-weight: 600;
    font-size: 1.125rem;
    display: block;
    margin-bottom: 0.5rem;
}

.player-status {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.vs {
    font-weight: bold;
    font-size: 1.5rem;
    color: var(--text-secondary);
    margin: 0 1rem;
}

.move-selection {
    text-align: center;
}

.move-selection h3 {
    margin-bottom: 2rem;
}

.moves {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.move-btn {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 1rem;
    padding: 2rem 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.move-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.move-btn.selected {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.1);
}

.move-emoji {
    font-size: 3rem;
}

.move-label {
    font-weight: 600;
    font-size: 1.125rem;
}

/* Game Result */
.game-result {
    text-align: center;
}

.result-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

.move-result {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.move-result .move-emoji {
    font-size: 4rem;
    padding: 1rem;
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: var(--shadow);
}

.move-result .label {
    font-weight: 600;
    color: var(--text-secondary);
}

.result-text {
    font-size: 2rem;
    margin-bottom: 2rem;
}

.result-text.win {
    color: var(--success-color);
}

.result-text.lose {
    color: var(--danger-color);
}

.result-text.draw {
    color: var(--warning-color);
}

.result-actions {
    display: flex;
    gap: 1rem;
}

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

/* Profile Screen */
.profile-header {
    text-align: center;
    margin-bottom: 2rem;
}

.profile-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    margin: 0 auto 1rem;
    box-shadow: var(--shadow-lg);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

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

.chart-container {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.chart-container h3 {
    margin-bottom: 1rem;
}

.recent-games,
.head-to-head {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.recent-games h3,
.head-to-head h3 {
    margin-bottom: 1rem;
}

.game-item,
.h2h-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.h2h-info {
    flex: 1;
}

.h2h-chart {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
}

.h2h-stats {
    flex-shrink: 0;
    text-align: right;
}

.game-item:last-child,
.h2h-item:last-child {
    border-bottom: none;
}

.game-item.win {
    background: rgba(16, 185, 129, 0.1);
}

.game-item.lose {
    background: rgba(239, 68, 68, 0.1);
}

.game-item.draw {
    background: rgba(245, 158, 11, 0.1);
}

.info-box {
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid var(--primary-color);
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
    color: var(--primary-color);
}

/* User Avatar */
#user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

#user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    .moves {
        grid-template-columns: 1fr;
    }

    .game-info {
        flex-direction: column;
        gap: 1rem;
    }

    .vs {
        transform: rotate(90deg);
    }

    .result-display {
        flex-direction: column;
        gap: 1rem;
    }

    .link-container {
        flex-direction: column;
    }

    .toast-container {
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
        max-width: none;
    }

    .h2h-chart {
        width: 60px;
        height: 60px;
    }

    .h2h-item {
        gap: 0.5rem;
    }
}
