/* CSS Reset and Variables */
:root {
    --primary-color: #0066FF;
    --primary-hover: #0052CC;
    --secondary-color: #6B7280;
    --secondary-hover: #4B5563;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #F59E0B;
    --background: #FFFFFF;
    --surface: #F9FAFB;
    --border: #E5E7EB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-inverse: #FFFFFF;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0F172A;
        --surface: #1E293B;
        --border: #334155;
        --text-primary: #F1F5F9;
        --text-secondary: #94A3B8;
        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
        --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    }
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* Header */
.header {
    text-align: center;
    margin: 2rem 0 3rem;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color) 0%, #8B5CF6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background-color: var(--surface);
}

.btn .icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* Input */
.input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background-color: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.1);
}

/* Auth Section */
.auth-section {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.user-info span {
    font-weight: 500;
}

/* Game Menu */
.game-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 2rem;
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.divider {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.join-game {
    display: flex;
    gap: 0.75rem;
    width: 100%;
    max-width: 400px;
}

.join-game .input {
    flex: 1;
}

/* Game Section */
.game-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Game Info */
.game-info {
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.players {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: relative;
}

.player-symbol {
    font-size: 2rem;
    font-weight: 700;
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background-color: var(--background);
    box-shadow: var(--shadow-sm);
}

.player-x .player-symbol {
    color: var(--primary-color);
}

.player-o .player-symbol {
    color: #8B5CF6;
}

.player-name {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-indicator {
    position: absolute;
    bottom: -0.5rem;
    width: 100%;
    height: 3px;
    background-color: var(--success-color);
    border-radius: 2px;
    opacity: 0;
    transition: var(--transition);
}

.player.active .player-indicator {
    opacity: 1;
}

.vs {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.game-status {
    text-align: center;
    padding: 0.75rem;
    background-color: var(--background);
    border-radius: var(--radius-md);
}

.status-text {
    font-weight: 500;
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    padding: 1.5rem;
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    aspect-ratio: 1;
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.cell {
    background-color: var(--background);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.cell:hover:not(.occupied):not(.disabled) {
    background-color: var(--surface);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

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

.cell.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.cell.x {
    color: var(--primary-color);
}

.cell.o {
    color: #8B5CF6;
}

.cell.winner {
    background-color: rgba(16, 185, 129, 0.1);
    border-color: var(--success-color);
    animation: pulse 0.5s ease-out;
}

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

/* Cell content animation */
.cell::after {
    content: attr(data-content);
    position: absolute;
    opacity: 0;
    transform: scale(0) rotate(180deg);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.cell.occupied::after {
    opacity: 1;
    transform: scale(1) rotate(0);
}

/* Game Actions */
.game-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

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

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

.loading-text {
    color: var(--text-inverse);
    font-weight: 500;
}

/* Error Message */
.error-message {
    position: fixed;
    top: 1rem;
    right: 1rem;
    left: 1rem;
    max-width: 400px;
    margin: 0 auto;
    background-color: var(--error-color);
    color: var(--text-inverse);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    z-index: 1001;
    animation: slideDown 0.3s ease-out;
}

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

.error-close {
    background: none;
    border: none;
    color: var(--text-inverse);
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.error-close:hover {
    opacity: 1;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 1rem;
}

.modal-content {
    background-color: var(--background);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 400px;
    width: 100%;
    animation: modalIn 0.3s ease-out;
}

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

.modal-content h3 {
    margin-bottom: 1rem;
}

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

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

.share-link-container .input {
    flex: 1;
    font-size: 0.875rem;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

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

    .logo {
        font-size: 2rem;
    }

    .game-board {
        gap: 0.5rem;
        padding: 1rem;
    }

    .cell {
        font-size: 2.5rem;
    }

    .players {
        gap: 0.5rem;
    }

    .player-symbol {
        font-size: 1.5rem;
        width: 2.5rem;
        height: 2.5rem;
    }

    .player-name {
        font-size: 0.75rem;
        max-width: 80px;
    }

    .game-actions {
        flex-direction: column;
        width: 100%;
    }

    .game-actions .btn {
        width: 100%;
    }
}

/* Login Form Styles */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

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

.login-error {
    padding: 0.75rem;
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    border-radius: var(--radius-sm);
    color: var(--error-color);
    font-size: 0.875rem;
    text-align: center;
}

.login-footer {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.login-footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.login-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

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