/* ========================================
   Doppelganger Chess - Premium Dark Theme
   ======================================== */

:root {
    /* Color Palette */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-glass: rgba(26, 26, 37, 0.8);

    --accent-primary: #7c3aed;
    --accent-secondary: #a78bfa;
    --accent-glow: rgba(124, 58, 237, 0.3);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;

    --border-color: rgba(148, 163, 184, 0.1);
    --border-glow: rgba(124, 58, 237, 0.5);

    /* Board Colors */
    --board-light: #e8dcc4;
    --board-dark: #7d945d;
    --board-highlight: rgba(56, 189, 248, 0.5);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);
}

/* ========================================
   Base Styles
   ======================================== */

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Animated background gradient */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(124, 58, 237, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(167, 139, 250, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(124, 58, 237, 0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: -1;
}

/* ========================================
   Typography
   ======================================== */

h1,
h2,
h3,
h4 {
    font-weight: 600;
    letter-spacing: -0.02em;
}

h1 {
    font-size: 1.75rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.125rem;
    color: var(--text-secondary);
}

h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ========================================
   Layout Components
   ======================================== */

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

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-icon {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 10px var(--accent-glow));
}

.logo h1 {
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    color: var(--text-secondary);
}

.main-content {
    flex: 1;
    padding: var(--spacing-xl);
}

.game-layout {
    display: grid;
    grid-template-columns: 320px 1fr 320px;
    gap: var(--spacing-xl);
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}

/* ========================================
   Glass Panel
   ======================================== */

.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), #6d28d9);
    color: white;
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--accent-glow);
}

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

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

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

.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.btn-link {
    background: transparent;
    color: var(--accent-secondary);
    padding: 0;
}

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

.btn-full {
    width: 100%;
}

/* ========================================
   Forms
   ======================================== */

.form-group {
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    margin-bottom: var(--spacing-md);
    min-height: 1.25rem;
}

/* ========================================
   Modal
   ======================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity var(--transition-normal);
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    width: 100%;
    max-width: 400px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal h2 {
    margin-bottom: var(--spacing-xs);
}

.modal-subtitle {
    color: var(--text-muted);
    margin-bottom: var(--spacing-xl);
}

.auth-switch {
    margin-top: var(--spacing-lg);
    text-align: center;
    color: var(--text-muted);
}

/* ========================================
   Chessboard Customization
   ======================================== */

.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    position: relative;
    /* Required for absolute-positioned promotion modal */
}

.chessboard {
    width: 100%;
    max-width: 560px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg), 0 0 50px rgba(0, 0, 0, 0.5);
}

/* Override chessboard.js styles */
.board-b72b1 {
    border-radius: var(--radius-lg);
}

.square-55d63 {
    transition: background-color var(--transition-fast);
}

.white-1e1d7 {
    background-color: var(--board-light) !important;
}

.black-3c85d {
    background-color: var(--board-dark) !important;
}

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

.game-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--success);
    animation: pulse 2s infinite;
}

.status-indicator.thinking {
    background: var(--warning);
}

.status-indicator.gameover {
    background: var(--error);
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

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

.game-controls {
    display: flex;
    gap: var(--spacing-sm);
}

/* ========================================
   Side Panels
   ======================================== */

.side-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    overflow: hidden;
}

.side-panel h3 {
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
}

.stat-item {
    display: flex;
    flex-direction: column;
    padding: var(--spacing-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-secondary);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Settings */
.settings-section {
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.slider-container {
    margin-top: var(--spacing-md);
}

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

.slider-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: var(--spacing-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.slider-labels span:nth-child(2) {
    font-weight: 600;
    color: var(--accent-secondary);
}

.setting-hint {
    margin-top: var(--spacing-sm);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Move History */
.move-history {
    max-height: 240px;
    overflow-y: auto;
    padding-right: var(--spacing-sm);
    min-height: 150px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm);
}

.move-history::-webkit-scrollbar {
    width: 4px;
}

.move-history::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

.move-history::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: var(--radius-full);
}

.empty-history {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: var(--spacing-xl);
}

.move-row {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) 0;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.875rem;
}

.move-number {
    color: var(--text-muted);
    min-width: 2rem;
}

.move-white,
.move-black {
    flex: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

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

.move-white {
    color: var(--text-primary);
}

.move-black {
    color: var(--text-secondary);
}

/* Doppelganger Status */
.doppelganger-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) var(--spacing-md);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(167, 139, 250, 0.05));
    border: 1px solid var(--accent-glow);
    border-radius: var(--radius-md);
}

.doppel-icon {
    font-size: 1.5rem;
}

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

.doppel-text.matched {
    color: var(--accent-secondary);
    font-weight: 500;
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast-container {
    position: fixed;
    bottom: var(--spacing-xl);
    right: var(--spacing-xl);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    z-index: 1100;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: toastSlideIn 0.3s ease;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--error);
}

.toast.info {
    border-color: var(--accent-primary);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 1200px) {
    .game-layout {
        grid-template-columns: 1fr;
        max-width: 600px;
    }

    .side-panel {
        order: 1;
    }

    .board-container {
        order: 0;
    }
}

@media (max-width: 600px) {
    .header {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .main-content {
        padding: var(--spacing-md);
    }

    .game-controls {
        flex-wrap: wrap;
    }

    .game-controls .btn {
        flex: 1;
        min-width: 80px;
    }
}

/* ========================================
   Promotion Modal
   ======================================== */

.promotion-overlay {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: auto;
    height: auto;
    margin-left: 8px;
    /* Closer to board */
    z-index: 100;
    pointer-events: none;
}

/* Re-enable pointer events for the modal content */
.promotion-modal {
    pointer-events: auto;
    text-align: center;
    width: 80px;
    background: linear-gradient(135deg, #2d1f4e 0%, #1a1a2e 100%);
    /* Purple-ish gradient */
    border: 2px solid var(--accent-primary);
    box-shadow: 0 8px 32px rgba(124, 58, 237, 0.3);
    padding: var(--spacing-xs);
    border-radius: var(--radius-lg);
}

.promotion-modal h3 {
    display: none;
    /* Hide title for compact look */
}

.promotion-options {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    margin-top: 0;
}

.promotion-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
}

.promotion-option:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
    border-color: var(--accent-secondary);
}

.piece-img {
    width: 48px;
    height: 48px;
    pointer-events: none;
}

/* ========================================
   Elo Rating Display
   ======================================== */

.elo-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm) var(--spacing-md);
    margin-top: var(--spacing-sm);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.15) 0%, rgba(99, 102, 241, 0.1) 100%);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(124, 58, 237, 0.3);
}

.elo-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.elo-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-shadow: 0 2px 10px rgba(124, 58, 237, 0.3);
}

.doppelganger-elo {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(249, 115, 22, 0.1) 100%);
    border-color: rgba(239, 68, 68, 0.3);
}

.doppelganger-elo .elo-value {
    color: var(--accent-secondary);
    text-shadow: 0 2px 10px rgba(239, 68, 68, 0.3);
}

/* ========================================
   Welcome Modal
   ======================================== */

.welcome-modal {
    max-width: 500px;
    text-align: left;
}

.welcome-modal h2 {
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.welcome-content {
    margin-bottom: var(--spacing-lg);
}

.welcome-content h3 {
    font-size: 1rem;
    color: var(--accent-primary);
    margin: var(--spacing-md) 0 var(--spacing-sm) 0;
}

.welcome-content p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: var(--spacing-sm);
}

.info-box {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: rgba(124, 58, 237, 0.1);
    border-left: 3px solid var(--accent-primary);
    border-radius: var(--radius-md);
    margin: var(--spacing-md) 0;
}

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

.info-box p {
    margin: 0;
    font-size: 0.9rem;
}

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

.tips-list li {
    padding: var(--spacing-sm) 0;
    padding-left: var(--spacing-md);
    position: relative;
    color: var(--text-secondary);
    line-height: 1.5;
}

.tips-list li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent-primary);
}

/* Custom Checkbox */
.checkbox-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: var(--spacing-md);
    user-select: none;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.checkbox-container:hover .checkmark {
    border-color: var(--accent-primary);
}

.checkbox-container input:checked+.checkmark {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.checkbox-container input:checked+.checkmark::after {
    content: "✓";
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* ========================================
   Donation Section
   ======================================== */

.footer {
    text-align: center;
    padding: 0.5rem 2rem 2rem 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.donation-section {
    max-width: 600px;
    margin: 0 auto var(--spacing-lg) auto;
    padding: var(--spacing-lg);
    background: rgba(124, 58, 237, 0.08);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(124, 58, 237, 0.2);
}

.donation-text {
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
    font-size: 1rem;
}

.donation-options {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: var(--spacing-xl);
    flex-wrap: wrap;
}

.donation-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.wise-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: #9fe870;
    border-radius: var(--radius-md);
    text-decoration: none;
    color: #163300;
    font-weight: 600;
    transition: all 0.2s ease;
}

.wise-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(159, 232, 112, 0.4);
}

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

.qr-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

.paypal-qr {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-md);
    background: white;
    padding: 4px;
}

.copyright {
    color: var(--text-muted);
    margin: 0;
}

/* ========================================
   History Viewing Mode
   ======================================== */

#board.viewing-history {
    opacity: 0.85;
    filter: sepia(0.2);
}

.status-indicator.history {
    background: var(--warning);
    animation: none;
}

/* ========================================
   Mobile / Touch Compatibility
   ======================================== */

#board,
.board-container,
.square-55d63 {
    touch-action: none;
    /* Critical for dragging on touch devices */
    -webkit-user-select: none;
    user-select: none;
}

.opening-name {
    color: var(--text-accent);
    font-size: 0.9rem;
    margin-bottom: var(--spacing-sm);
    text-align: center;
    font-weight: 500;
    min-height: 1.2em;
    /* Prevent layout shift */
}

/* ========================================
   Arrows Layer
   ======================================== */

.board-container {
    position: relative;
    /* Context for absolute canvases */
}

.arrow-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to board (library handles mousedown on board) */
    z-index: 10;
    /* Above board pieces */
}