/**
 * Neural Arena - UI Components
 * Buttons, Inputs, Cards, etc.
 */

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Primary Button - Cyan Glow */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-dim), var(--primary));
    border-color: var(--primary);
    color: var(--bg-deep);
    filter: drop-shadow(var(--glow-sm));
}

.btn-primary:hover:not(:disabled) {
    filter: drop-shadow(var(--glow-md));
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

/* Secondary Button */
.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border-light);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

/* Ghost Button */
.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
    color: var(--primary);
    background: var(--bg-elevated);
}

/* Danger Button */
.btn-danger {
    background: var(--error-dim);
    border-color: var(--error);
    color: var(--text-bright);
}

.btn-danger:hover:not(:disabled) {
    background: var(--error);
    filter: drop-shadow(0 0 10px var(--error-glow));
}

/* Success Button */
.btn-success {
    background: var(--success-dim);
    border-color: var(--success);
    color: var(--bg-deep);
}

.btn-success:hover:not(:disabled) {
    background: var(--success);
    filter: drop-shadow(0 0 10px var(--success-glow));
}

/* Button Sizes */
.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-base);
}

.btn-block {
    width: 100%;
}

/* Icon Button */
.btn-icon-only {
    padding: var(--space-2);
    aspect-ratio: 1;
}

.btn-icon {
    font-size: var(--text-base);
}


/* =============================================================================
   Inputs
   ============================================================================= */

.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

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

.input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.input:hover {
    border-color: var(--border-light);
}

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

.input::placeholder {
    color: var(--text-muted);
}

/* Input sizes */
.input-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
}

/* Select */
.select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    color: var(--text);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236a6a7a'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

.select:hover {
    border-color: var(--border-light);
}

.select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.select option {
    background: var(--bg-surface);
    color: var(--text);
}

.select optgroup {
    font-weight: 600;
    color: var(--text-dim);
}

.select-sm {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    padding-right: var(--space-6);
    background-size: 10px;
    background-position: right var(--space-2) center;
}


/* =============================================================================
   Sliders
   ============================================================================= */

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--glow-sm);
    transition: all var(--transition-fast);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--glow-md);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--glow-sm);
}

/* Parameter list */
.param-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.param-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.param-label {
    display: flex;
    justify-content: space-between;
    font-size: var(--text-sm);
    color: var(--text);
}

.param-value {
    font-family: var(--font-mono);
    color: var(--primary);
}


/* =============================================================================
   Cards & Panels
   ============================================================================= */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    transition: all var(--transition-fast);
}

.card:hover {
    border-color: var(--border-light);
}

.card.active {
    border-color: var(--primary);
    box-shadow: var(--glow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}

.card-title {
    font-size: var(--text-base);
    font-weight: 600;
}


/* =============================================================================
   Charts
   ============================================================================= */

.chart-wrapper {
    margin-bottom: var(--space-3);
}

.chart-wrapper:last-child {
    margin-bottom: 0;
}

.chart-title {
    font-size: var(--text-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
    margin-bottom: var(--space-2);
}

.chart-container {
    position: relative;
    height: 80px;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}


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

.modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: var(--text-xl);
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: var(--text-2xl);
    cursor: pointer;
    padding: var(--space-1);
    line-height: 1;
    transition: color var(--transition-fast);
}

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

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
}

/* Help Modal */
.modal-help-content {
    max-width: 700px;
}

.help-body {
    font-size: var(--text-sm);
    line-height: 1.6;
}

.help-section {
    margin-bottom: var(--space-6);
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: var(--text-base);
    color: var(--primary);
    margin-bottom: var(--space-3);
}

.help-section p {
    color: var(--text);
    margin-bottom: var(--space-2);
}

.help-section ol,
.help-section ul {
    margin: var(--space-3) 0;
    padding-left: var(--space-6);
    color: var(--text);
}

.help-section li {
    margin-bottom: var(--space-2);
}

.help-section li strong {
    color: var(--primary);
}

.tier-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.tier-item {
    background: var(--bg-deep);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    border-left: 3px solid var(--primary);
}

.tier-item h4 {
    font-size: var(--text-sm);
    color: var(--secondary);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tier-item p {
    margin-bottom: var(--space-1);
    font-size: var(--text-xs);
}

.tier-item p:last-child {
    margin-bottom: 0;
}


/* =============================================================================
   Leaderboard Tabs
   ============================================================================= */

.leaderboard-tabs {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.tab-row {
    display: flex;
    gap: var(--space-2);
}

.tab-btn {
    flex: 1;
    padding: var(--space-2) var(--space-2);
    font-family: var(--font-ui);
    font-size: var(--text-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--bg-surface);
    border-color: var(--border-light);
    color: var(--text);
}

.tab-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--bg-deep);
    font-weight: 600;
}

.modal-leaderboard-content {
    max-width: 650px;
}

/* Mobile tabs - smaller */
.mobile-tabs .tab-btn {
padding: var(--space-1) var(--space-1);
    font-size: 10px;
}

/* Mobile leaderboard adjustments */
@media (max-width: 767px) {
    .leaderboard-entry {
        grid-template-columns: 35px 1fr minmax(0, max-content) minmax(60px, auto);
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
    }

    .leaderboard-entry.no-algo {
        grid-template-columns: 35px 1fr minmax(60px, auto);
    }

    .leaderboard-algo {
        max-width: 100px;
        font-size: var(--text-xs);
    }

    .leaderboard-score {
        font-size: var(--text-base);
        min-width: 60px;
    }
}


/* =============================================================================
   Leaderboard
   ============================================================================= */

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.leaderboard-entry {
    display: grid;
    grid-template-columns: 40px 1fr minmax(0, max-content) minmax(70px, auto);
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    min-width: 0;
}

/* When filtered by algorithm, hide algo column */
.leaderboard-entry.no-algo {
    grid-template-columns: 40px 1fr minmax(70px, auto);
}

.leaderboard-entry:hover {
    background: var(--bg-surface);
}

.leaderboard-rank {
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-dim);
    text-align: center;
}

.leaderboard-entry:nth-child(1) .leaderboard-rank {
    color: #ffd700;
}

.leaderboard-entry:nth-child(2) .leaderboard-rank {
    color: #c0c0c0;
}

.leaderboard-entry:nth-child(3) .leaderboard-rank {
    color: #cd7f32;
}

.leaderboard-user {
    display: flex;
    flex-direction: column;
}

.leaderboard-name {
    font-weight: 600;
    color: var(--text);
}

.leaderboard-handle {
    font-size: var(--text-sm);
    color: var(--primary);
}

.leaderboard-algo {
    font-size: var(--text-sm);
    color: var(--text-dim);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    min-width: 0;
}

.leaderboard-score {
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--success);
    white-space: nowrap;
    text-align: right;
    min-width: 70px;
}


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

.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: slideIn 0.3s ease;
}

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

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

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

.toast-message {
    font-size: var(--text-sm);
}

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


/* =============================================================================
   Live Indicator
   ============================================================================= */

.live-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

.live-indicator.paused {
    background: var(--warning);
    animation: none;
}

.live-indicator.stopped {
    background: var(--text-dim);
    animation: none;
}


/* =============================================================================
   About Section
   ============================================================================= */

.about-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.about-text {
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--text);
    margin: 0;
}

.about-text strong {
    color: var(--primary);
    font-weight: 600;
}

.about-text:first-child {
    margin-top: 0;
}

.about-text:last-child {
    margin-bottom: 0;
}
