/* Replicator Dynamics Visualizer - Styles */
/* Scoped with rd- prefix to prevent global style pollution */

:root {
    --rd-primary: #6366f1;
    --rd-primary-dark: #4f46e5;
    --rd-secondary: #8b5cf6;
    --rd-accent: #f59e0b;
    --rd-success: #10b981;
    --rd-danger: #ef4444;
    --rd-text: #1f2937;
    --rd-text-light: #6b7280;
    --rd-bg: #ffffff;
    --rd-bg-alt: #f9fafb;
    --rd-border: #e5e7eb;
    --rd-shadow: rgba(0, 0, 0, 0.1);
    --rd-strategy1: #ef4444;
    --rd-strategy2: #22c55e;
    --rd-strategy3: #3b82f6;
}

/* Base Styles */
.rd-hero {
    text-align: center;
    padding: 3rem 1rem;
    background: linear-gradient(135deg, var(--rd-primary) 0%, var(--rd-secondary) 100%);
    color: white;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px var(--rd-shadow);
}

.rd-hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.025em;
}

.rd-hero-subtitle {
    font-size: 1.125rem;
    opacity: 0.95;
    margin: 0 0 1.5rem 0;
    font-weight: 300;
}

.rd-formula {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    margin: 1.5rem auto;
    max-width: 600px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.rd-formula-text {
    font-family: 'Times New Roman', serif;
    font-size: 1.5rem;
    font-style: italic;
    letter-spacing: 0.05em;
}

.rd-hero-description {
    max-width: 800px;
    margin: 1.5rem auto 0;
    line-height: 1.6;
    opacity: 0.9;
}

/* Main Content */
.rd-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

.rd-section {
    background: var(--rd-bg);
    border-radius: 0.5rem;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px var(--rd-shadow);
    border: 1px solid var(--rd-border);
}

.rd-section-title {
    font-size: 1.875rem;
    font-weight: 600;
    color: var(--rd-text);
    margin: 0 0 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rd-section-title::before {
    content: '';
    width: 4px;
    height: 1.875rem;
    background: var(--rd-primary);
    border-radius: 2px;
}

.rd-section-desc {
    color: var(--rd-text-light);
    margin: 0.5rem 0 1.5rem 0;
    line-height: 1.6;
}

/* Tabs */
.rd-tabs {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.rd-tab {
    padding: 0.75rem 1.5rem;
    background: var(--rd-bg-alt);
    border: 2px solid var(--rd-border);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: var(--rd-text);
    transition: all 0.2s ease;
    flex: 1;
    min-width: 120px;
}

.rd-tab:hover {
    background: var(--rd-bg);
    border-color: var(--rd-primary);
    color: var(--rd-primary);
}

.rd-tab.active {
    background: var(--rd-primary);
    border-color: var(--rd-primary);
    color: white;
}

/* Simplex Visualization */
.rd-simplex-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.rd-simplex-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1rem;
}

.rd-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    color: var(--rd-text);
}

.rd-legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.rd-legend-marker {
    width: 12px;
    height: 12px;
    border: 3px solid;
    border-radius: 50%;
}

/* Control Panel */
.rd-controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.rd-control-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

.rd-control-group.rd-sliders {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.rd-button {
    padding: 0.75rem 1.5rem;
    background: var(--rd-bg-alt);
    color: var(--rd-text);
    border: 2px solid var(--rd-border);
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rd-button:hover {
    background: var(--rd-bg);
    border-color: var(--rd-primary);
    color: var(--rd-primary);
}

.rd-button-primary {
    background: var(--rd-primary);
    border-color: var(--rd-primary);
    color: white;
}

.rd-button-primary:hover {
    background: var(--rd-primary-dark);
    border-color: var(--rd-primary-dark);
    color: white;
}

.rd-slider-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rd-slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    color: var(--rd-text);
}

.rd-slider-value {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--rd-primary);
}

.rd-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--rd-border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.rd-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--rd-primary);
    cursor: pointer;
    box-shadow: 0 2px 4px var(--rd-shadow);
    transition: all 0.2s ease;
}

.rd-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--rd-primary-dark);
}

.rd-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--rd-primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px var(--rd-shadow);
    transition: all 0.2s ease;
}

.rd-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: var(--rd-primary-dark);
}

/* Payoff Matrix Editor */
.rd-matrix-editor {
    display: flex;
    justify-content: center;
}

.rd-matrix-grid {
    display: grid;
    grid-template-columns: auto repeat(3, 80px);
    gap: 0.5rem;
    align-items: center;
}

.rd-matrix-header {
    font-weight: 600;
    color: var(--rd-text);
    text-align: center;
    padding: 0.5rem;
}

.rd-matrix-row-label {
    font-weight: 600;
    color: var(--rd-text);
    padding: 0.5rem 1rem;
    text-align: right;
}

.rd-matrix-cell {
    width: 80px;
    height: 40px;
    border: 2px solid var(--rd-border);
    border-radius: 0.375rem;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    background: var(--rd-bg);
    transition: all 0.2s ease;
}

.rd-matrix-cell:focus {
    outline: none;
    border-color: var(--rd-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* State Display */
.rd-state-display,
.rd-payoff-display {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.rd-state-item,
.rd-payoff-item {
    background: var(--rd-bg-alt);
    padding: 1rem;
    border-radius: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rd-state-total,
.rd-payoff-avg {
    background: var(--rd-primary);
    color: white;
}

.rd-state-total .rd-state-label,
.rd-payoff-avg .rd-payoff-label {
    color: rgba(255, 255, 255, 0.9);
}

.rd-state-value,
.rd-payoff-value {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    font-size: 1.125rem;
}

.rd-state-label,
.rd-payoff-label {
    font-weight: 500;
    color: var(--rd-text-light);
}

/* Canvas Containers */
.rd-canvas-container {
    display: flex;
    justify-content: center;
    margin: 1.5rem 0;
}

canvas {
    background: var(--rd-bg);
    border: 1px solid var(--rd-border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px var(--rd-shadow);
    max-width: 100%;
    height: auto;
}

/* Phase Controls */
.rd-phase-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1rem;
}

.rd-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--rd-text);
}

.rd-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--rd-primary);
}

/* Analysis Results */
.rd-analysis-container {
    text-align: center;
}

.rd-results {
    margin-top: 1.5rem;
    text-align: left;
}

.rd-result-section {
    background: var(--rd-bg-alt);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--rd-primary);
}

.rd-result-section h4 {
    margin: 0 0 1rem 0;
    color: var(--rd-text);
    font-size: 1.125rem;
}

.rd-result-section ul {
    margin: 0;
    padding-left: 1.5rem;
}

.rd-result-section li {
    margin-bottom: 0.5rem;
    color: var(--rd-text);
}

.rd-equilibrium-point {
    display: inline-block;
    background: var(--rd-bg);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    margin: 0.25rem;
    border: 2px solid var(--rd-border);
    font-family: 'Courier New', monospace;
}

.rd-equilibrium-point.stable {
    border-color: var(--rd-success);
    background: rgba(16, 185, 129, 0.1);
}

.rd-equilibrium-point.unstable {
    border-color: var(--rd-danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Educational Content - Accordion */
.rd-accordion {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rd-accordion-item {
    background: var(--rd-bg-alt);
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--rd-border);
}

.rd-accordion-header {
    width: 100%;
    padding: 1.25rem 1.5rem;
    background: var(--rd-bg-alt);
    border: none;
    text-align: left;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--rd-text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.rd-accordion-header:hover {
    background: var(--rd-bg);
}

.rd-accordion-header.active {
    background: var(--rd-primary);
    color: white;
}

.rd-accordion-icon {
    font-size: 1.5rem;
    font-weight: 300;
    transition: transform 0.2s ease;
}

.rd-accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.rd-accordion-content.active {
    max-height: 2000px;
}

.rd-accordion-content > * {
    padding: 0 1.5rem 1.5rem;
}

.rd-accordion-content p {
    margin-bottom: 1rem;
    line-height: 1.7;
    color: var(--rd-text);
}

.rd-math-block {
    background: var(--rd-bg);
    padding: 1.5rem;
    border-radius: 0.375rem;
    border-left: 4px solid var(--rd-secondary);
    margin: 1rem 0;
}

.rd-math {
    font-family: 'Times New Roman', serif;
    font-style: italic;
    font-size: 1.125rem;
    background: var(--rd-bg-alt);
    padding: 0.75rem 1rem;
    border-radius: 0.25rem;
    margin: 0.75rem 0;
    text-align: center;
}

.rd-math-block ul {
    margin: 0.75rem 0 0 0;
    padding-left: 1.5rem;
}

.rd-math-block li {
    margin-bottom: 0.5rem;
    color: var(--rd-text);
}

/* Game Cards */
.rd-game-grid,
.rd-application-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.rd-game-card,
.rd-application-card {
    background: var(--rd-bg);
    padding: 1.25rem;
    border-radius: 0.375rem;
    border: 1px solid var(--rd-border);
    transition: all 0.2s ease;
}

.rd-game-card:hover,
.rd-application-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--rd-shadow);
    border-color: var(--rd-primary);
}

.rd-game-card h4,
.rd-application-card h4 {
    margin: 0 0 0.75rem 0;
    color: var(--rd-primary);
    font-size: 1.125rem;
}

.rd-game-card p,
.rd-application-card p {
    margin: 0;
    line-height: 1.6;
    color: var(--rd-text-light);
    font-size: 0.9375rem;
}

/* Footer */
.rd-footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--rd-text-light);
    font-size: 0.9375rem;
    border-top: 1px solid var(--rd-border);
    margin-top: 2rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .rd-hero h1 {
        font-size: 1.875rem;
    }

    .rd-hero-subtitle {
        font-size: 1rem;
    }

    .rd-formula-text {
        font-size: 1.125rem;
    }

    .rd-section {
        padding: 1.5rem;
    }

    .rd-section-title {
        font-size: 1.5rem;
    }

    .rd-tabs {
        flex-direction: column;
    }

    .rd-tab {
        min-width: 100%;
    }

    .rd-simplex-legend {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .rd-control-group.rd-sliders {
        grid-template-columns: 1fr;
    }

    .rd-state-display,
    .rd-payoff-display {
        grid-template-columns: 1fr;
    }

    .rd-phase-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .rd-game-grid,
    .rd-application-grid {
        grid-template-columns: 1fr;
    }

    .rd-matrix-grid {
        grid-template-columns: auto repeat(3, 60px);
    }

    .rd-matrix-cell {
        width: 60px;
        height: 36px;
        font-size: 0.875rem;
    }
}

@media (max-width: 480px) {
    .rd-hero {
        padding: 2rem 0.75rem;
    }

    .rd-section {
        padding: 1rem;
    }

    canvas {
        max-width: 100%;
        height: auto;
    }

    #rd-simplex-canvas,
    #rd-phase-canvas,
    #rd-time-canvas {
        width: 100% !important;
        height: auto !important;
    }
}

/* Print Styles */
@media print {
    .rd-hero {
        background: white;
        color: black;
        box-shadow: none;
    }

    .rd-section {
        page-break-inside: avoid;
        box-shadow: none;
    }

    .rd-button {
        display: none;
    }

    .rd-accordion-content {
        max-height: none !important;
    }

    .rd-accordion-icon {
        display: none;
    }
}

/* Animation */
@keyframes rd-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(99, 102, 241, 0);
    }
}

/* Accessibility */
.rd-button:focus,
.rd-tab:focus,
.rd-slider:focus,
.rd-matrix-cell:focus,
.rd-accordion-header:focus {
    outline: 2px solid var(--rd-primary);
    outline-offset: 2px;
}

.rd-checkbox:focus-within {
    outline: 2px solid var(--rd-primary);
    outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .rd-button,
    .rd-tab,
    .rd-game-card,
    .rd-application-card,
    .rd-slider::-webkit-slider-thumb,
    .rd-slider::-moz-range-thumb {
        transition: none;
        animation: none;
    }
}
