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

:root {
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --secondary-color: #64748b;
    --accent-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 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);
}

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

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 60px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.elo-display {
    background: var(--surface-alt);
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-size: 0.9rem;
    white-space: nowrap;
    min-width: fit-content;
}

/* Header button specific styling */
.header-controls .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Game Setup Styles */
.game-setup {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.setup-card {
    background: var(--surface);
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.setup-card h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.setting {
    margin-bottom: 1.5rem;
}

.setting label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.setting select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

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

.setting input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.setting input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
}

.elo-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Button Styles */
.btn {
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
}

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

.btn-start {
    background: var(--accent-color);
    color: white;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    width: 100%;
    justify-content: center;
}

.btn-start:hover {
    background: #059669;
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    width: 100%;
    justify-content: center;
}

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

.btn-chat {
    background: var(--primary-color);
    color: white;
    padding: 0.75rem;
    border-radius: 0 0.5rem 0.5rem 0;
}

.btn-chat:hover {
    background: var(--primary-dark);
}

/* Game Layout */
.game-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr 380px;
    grid-template-areas: "left center right";
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
    min-height: calc(100vh - 6rem);
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: calc(100vh - 10rem);
}

.sidebar.left {
    grid-area: left;
    justify-content: flex-start;
}

.sidebar.right {
    grid-area: right;
    justify-content: flex-start;
}

.main-board {
    grid-area: center;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    min-height: calc(100vh - 8rem);
}

/* Move History */
.move-history {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.move-history h3 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

#moveList {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.8;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.move-pair {
    margin-bottom: 0.25rem;
}

.move-number {
    font-weight: 700;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.move {
    margin-right: 1rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s;
}

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

/* Game Controls */
.game-controls {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.status {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: center;
    padding: 0.75rem;
    border-radius: 0.5rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
}

/* Chess Board */
.board-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

#chessboard {
    border: 3px solid var(--text-primary);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    width: min(80vh, 600px);
    height: min(80vh, 600px);
}

/* Chat Styles */
.chat-container {
    background: var(--surface);
    border-radius: 0.75rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    height: calc(100vh - 10rem);
    display: flex;
    flex-direction: column;
    min-height: 500px;
}

.chat-container h3 {
    font-size: 1.125rem;
    padding: 1.5rem 1.5rem 0.75rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    max-width: 90%;
    animation: fadeIn 0.3s ease-in;
}

.message-content {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.ai-message {
    align-self: flex-start;
}

.ai-message .message-content {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
}

.user-message {
    align-self: flex-end;
}

.user-message .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

/* Chess move and opening name styling */
.chess-move {
    background-color: #2d3748;
    color: #e2e8f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.85em;
    font-weight: 500;
    display: inline-block;
    margin: 0 2px;
    white-space: nowrap;
}

.chess-opening {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9em;
    display: inline-block;
    margin: 0 2px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.message-content ul {
    margin: 0.5rem 0;
    padding-left: 1rem;
}

.message-content li {
    margin: 0.25rem 0;
    list-style-type: none;
    position: relative;
}

.message-content li::before {
    content: '•';
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    left: -1rem;
}

/* Feedback Section Styles */
.feedback-section {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.feedback-container {
    background: var(--surface);
    border-radius: 1rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.feedback-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-alt);
    border-radius: 1rem 1rem 0 0;
}

.feedback-header h2 {
    color: var(--text-primary);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.btn-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

.feedback-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.community-section, .feedback-form-section {
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface-alt);
}

.community-section h3, .feedback-form-section h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.community-section p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.btn-discord {
    background: #5865f2;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.btn-discord:hover {
    background: #4752c4;
    transform: translateY(-1px);
}

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

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

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

.form-group input, .form-group select, .form-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
    background: var(--surface);
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

@media (max-width: 768px) {
    .header {
        padding: 0.5rem 1rem;
        min-height: 50px;
    }
    
    .header h1 {
        font-size: 1.25rem;
    }
    
    .header-controls {
        gap: 0.5rem;
    }
    
    .header-controls .btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .elo-display {
        padding: 0.35rem 0.6rem;
        font-size: 0.8rem;
    }

    .feedback-container {
        width: 95%;
        margin: 1rem;
    }
    
    .feedback-content {
        padding: 1rem;
        gap: 1.5rem;
    }
    
    .community-section, .feedback-form-section {
        padding: 1rem;
    }
}

.chat-input-container {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0;
}

#chatInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem 0 0 0.5rem;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

#chatInput:focus {
    border-color: var(--primary-color);
}

/* Highlight styles for chess squares */
.highlight-source {
    background-color: rgba(59, 130, 246, 0.3) !important;
}

.highlight-destination {
    position: relative;
}

.highlight-destination::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    background-color: rgba(59, 130, 246, 0.6);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Status variations */
.thinking {
    background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
    color: white;
}

.game-over {
    background: linear-gradient(135deg, #ef4444, #dc2626) !important;
    color: white;
}

.win {
    background: linear-gradient(135deg, #10b981, #059669) !important;
    color: white;
}

.draw {
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
    color: white;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 280px 1fr 320px;
        gap: 1rem;
        padding: 1rem;
    }
}

@media (max-width: 968px) {
    .game-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas: 
            "center"
            "left" 
            "right";
        gap: 1rem;
    }
    
    .sidebar.left {
        flex-direction: row;
        gap: 1rem;
    }
    
    .move-history,
    .game-controls {
        flex: 1;
    }
    
    .chat-container {
        height: 400px;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 640px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .header-controls {
        width: 100%;
        justify-content: center;
    }
    
    .sidebar.left {
        flex-direction: column;
    }
    
    .game-layout {
        padding: 0.75rem;
    }
}
