/**
 * Neural Arena - Futuristic Spaceship Theme
 * CSS Variables and Base Styles
 */

/* =============================================================================
   CSS Variables
   ============================================================================= */

:root {
    /* Backgrounds */
    --bg-deep: #0a0a0f;
    --bg-surface: #12121a;
    --bg-elevated: #1a1a24;
    --bg-overlay: rgba(10, 10, 15, 0.95);

    /* Primary - Cyan Glow */
    --primary: #00f0ff;
    --primary-dim: #00a0aa;
    --primary-dark: #006070;
    --primary-glow: rgba(0, 240, 255, 0.3);
    --primary-glow-intense: rgba(0, 240, 255, 0.6);

    /* Secondary - Magenta Accent */
    --secondary: #ff00aa;
    --secondary-dim: #aa0077;
    --secondary-glow: rgba(255, 0, 170, 0.3);

    /* Status Colors */
    --success: #00ff88;
    --success-dim: #00aa55;
    --success-glow: rgba(0, 255, 136, 0.3);

    --warning: #ff8800;
    --warning-dim: #aa5500;
    --warning-glow: rgba(255, 136, 0, 0.3);

    --error: #ff3366;
    --error-dim: #aa2244;
    --error-glow: rgba(255, 51, 102, 0.3);

    /* Text */
    --text: #e0e0e8;
    --text-dim: #6a6a7a;
    --text-bright: #ffffff;
    --text-muted: #4a4a5a;

    /* Borders */
    --border: #2a2a3a;
    --border-light: #3a3a4a;
    --border-glow: var(--primary);

    /* Fonts */
    --font-ui: 'Orbitron', 'Exo 2', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Font Sizes */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);

    /* Glows */
    --glow-sm: 0 0 10px var(--primary-glow);
    --glow-md: 0 0 20px var(--primary-glow);
    --glow-lg: 0 0 30px var(--primary-glow), 0 0 60px var(--primary-glow);

    /* Z-index layers */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal: 300;
    --z-toast: 400;
}


/* =============================================================================
   Reset & Base Styles
   ============================================================================= */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text);
    background-color: var(--bg-deep);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dim);
}

/* Selection */
::selection {
    background: var(--primary-dim);
    color: var(--bg-deep);
}


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

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-ui);
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-bright);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p {
    margin-bottom: var(--space-4);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-bright);
}

code, pre {
    font-family: var(--font-mono);
}

code {
    background: var(--bg-elevated);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}


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

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: var(--z-sticky);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-shrink: 0;
}

.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 0 var(--space-4);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.user-profile-compact {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.user-profile-compact .input {
    width: 120px;
}

.x-handle-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding-left: var(--space-2);
    transition: border-color var(--transition-fast);
}

.x-handle-wrapper:hover {
    border-color: var(--border-light);
}

.x-handle-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.x-handle-wrapper .input {
    border: none;
    background: transparent;
    padding-left: var(--space-1);
    width: 80px;
}

.x-handle-wrapper .input:focus {
    box-shadow: none;
}

.x-icon {
    color: var(--text-dim);
    flex-shrink: 0;
}

.header-stats {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding-right: var(--space-4);
    border-right: 1px solid var(--border);
    margin-right: var(--space-2);
}

.header-stats .stat {
    flex-direction: row;
    gap: var(--space-1);
}

.header-stats .stat-label {
    font-size: var(--text-xs);
}

.header-stats .stat-value {
    font-size: var(--text-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--primary);
    text-shadow: var(--glow-sm);
}

.logo-icon {
    font-size: var(--text-2xl);
}

.app-main {
    display: grid;
    grid-template-columns: 1fr 560px;
    flex: 1;
    gap: var(--space-3);
    padding: var(--space-3);
    min-height: 0; /* Important for flex child to respect parent height */
    overflow: hidden;
}

/* Arena grid component sizing */
arena-grid {
    display: block;
    height: 100%;
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    min-height: 0;
}

.sidebar-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}

.section-title {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: var(--space-3);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-6);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.footer-stats {
    display: flex;
    gap: var(--space-6);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.stat-label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

.stat-value {
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--primary);
}


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

@media (max-width: 1199px) {
    .app-main {
        grid-template-columns: 1fr 560px;
    }
}

@media (max-width: 991px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .sidebar {
        order: 2;
    }
}

/* Mobile leaderboard - hidden on desktop, visible on mobile */
.mobile-leaderboard {
    display: none;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    border: 1px solid var(--border);
}

/* Mobile leaderboard compact - hidden, only modal shown */
.mobile-leaderboard-compact {
    display: none;
}

@media (max-width: 767px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    #app {
        min-height: auto;
        overflow: visible;
    }

    .app-header {
        padding: var(--space-2) var(--space-3);
        flex-wrap: wrap;
        gap: var(--space-2);
        flex-shrink: 0;
    }

    .header-left {
        order: 1;
    }

    .header-center {
        order: 3;
        flex-basis: 100%;
        padding: var(--space-2) 0 0;
        display: none; /* Hide profile on mobile - too cramped */
    }

    .header-right {
        order: 2;
        gap: var(--space-2);
        flex-wrap: wrap;
        align-items: center;
    }

    .logo-text {
        display: none;
    }

    .btn-label {
        display: none;
    }

    /* Make train button more prominent on mobile */
    #btn-train-all {
        padding: var(--space-2) var(--space-3);
        flex-shrink: 0;
    }

    #btn-train-all .btn-label {
        display: inline; /* Show label for train button */
    }

    /* Hide compact mobile leaderboard - only show modal */
    .mobile-leaderboard-compact {
        display: none !important;
    }

    /* Hide stats on mobile */
    .header-stats {
        display: none;
    }

    /* Hide add arena on mobile (single arena only) */
    #btn-add-arena {
        display: none;
    }

    .app-main {
        padding: var(--space-3);
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        overflow: visible;
        min-height: auto;
        flex: none;
    }

    .sidebar {
        order: 2;
        max-height: none;
        overflow-y: visible;
        overflow-x: hidden;
    }

    .sidebar-section {
        overflow: visible;
    }

    .about-content {
        overflow: visible;
    }

    .about-text {
        overflow: visible;
        word-wrap: break-word;
    }

    /* Ensure bottom padding so text isn't cut off */
    #app {
        padding-bottom: var(--space-6);
    }

    .app-main {
        padding-bottom: var(--space-6);
    }

    /* Larger touch targets */
    .btn {
        min-height: 44px;
    }

    .app-footer {
        flex-direction: column;
        gap: var(--space-4);
    }

    .user-profile {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Modal adjustments for mobile */
    .modal {
        padding: var(--space-2);
    }

    .modal-content {
        max-height: 90vh;
    }

    .modal-body {
        padding: var(--space-4);
    }

    /* Help modal on mobile */
    .tier-item {
        padding: var(--space-3);
    }

    /* Hide full mobile leaderboard section (using compact version in header instead) */
    .mobile-leaderboard {
        display: none;
    }

    /* Show leaderboard button on mobile - opens modal */
    #btn-leaderboard {
        display: inline-flex;
    }
}


/* =============================================================================
   Accessibility
   ============================================================================= */

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

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

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    padding: var(--space-2) var(--space-4);
    background: var(--primary);
    color: var(--bg-deep);
    z-index: 9999;
}

.skip-link:focus {
    top: var(--space-4);
}


/* =============================================================================
   Secondary Navigation (Top Nav)
   ============================================================================= */

.top-nav {
    background: linear-gradient(180deg, rgba(0, 240, 255, 0.1) 0%, var(--bg-surface) 100%);
    border-bottom: 1px solid var(--primary-dim);
    padding: var(--space-2) var(--space-4);
    flex-shrink: 0;
}

.top-nav-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.top-nav-brand {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    transition: color var(--transition-fast);
}

.top-nav-brand:hover {
    color: var(--primary);
}

.top-nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.top-nav-link {
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 500;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all var(--transition-fast);
}

.top-nav-link-primary {
    background: var(--secondary);
    color: var(--text-bright);
    box-shadow: 0 0 15px var(--secondary-glow);
}

.top-nav-link-primary:hover {
    background: var(--secondary-dim);
    color: var(--text-bright);
    transform: translateY(-1px);
    box-shadow: 0 0 25px var(--secondary-glow);
}

.top-nav-link-secondary {
    background: var(--bg-elevated);
    color: var(--success);
    border: 1px solid var(--success-dim);
}

.top-nav-link-secondary:hover {
    background: var(--success-dim);
    color: var(--text-bright);
    border-color: var(--success);
    box-shadow: 0 0 15px var(--success-glow);
}

.top-nav-link-accent {
    color: var(--primary);
    border: 1px solid var(--border);
    background: transparent;
}

.top-nav-link-accent:hover {
    background: var(--primary-dark);
    color: var(--text-bright);
    border-color: var(--primary-dim);
}

@media (max-width: 767px) {
    .top-nav {
        padding: var(--space-2);
    }

    .top-nav-content {
        flex-direction: column;
        gap: var(--space-2);
    }

    .top-nav-brand {
        font-size: var(--text-xs);
    }

    .top-nav-links {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--space-2);
    }

    .top-nav-link {
        font-size: var(--text-xs);
        padding: var(--space-1) var(--space-3);
    }
}
