/* ============================================================
   simulators.css
   Shared stylesheet for Understanding ML interactive simulators
   ============================================================ */

/* ----------------------------------------------------------
   Theme Variables
   ---------------------------------------------------------- */

[data-theme="bias-variance"] {
    --sim-primary: #3b82f6;
    --sim-primary-light: #dbeafe;
    --sim-primary-dark: #2563eb;
    --sim-gradient: linear-gradient(135deg, #1e3a8a, #3b82f6);
}

[data-theme="gradient-descent"] {
    --sim-primary: #f59e0b;
    --sim-primary-light: #fef3c7;
    --sim-primary-dark: #d97706;
    --sim-gradient: linear-gradient(135deg, #78350f, #f59e0b);
}

[data-theme="svm-classifier"] {
    --sim-primary: #8b5cf6;
    --sim-primary-light: #ede9fe;
    --sim-primary-dark: #7c3aed;
    --sim-gradient: linear-gradient(135deg, #4c1d95, #8b5cf6);
}

[data-theme="decision-tree"] {
    --sim-primary: #10b981;
    --sim-primary-light: #d1fae5;
    --sim-primary-dark: #059669;
    --sim-gradient: linear-gradient(135deg, #064e3b, #10b981);
}

[data-theme="neural-network"] {
    --sim-primary: #f43f5e;
    --sim-primary-light: #ffe4e6;
    --sim-primary-dark: #e11d48;
    --sim-gradient: linear-gradient(135deg, #881337, #f43f5e);
}

[data-theme="kmeans-clustering"] {
    --sim-primary: #6366f1;
    --sim-primary-light: #e0e7ff;
    --sim-primary-dark: #4f46e5;
    --sim-gradient: linear-gradient(135deg, #312e81, #6366f1);
}

/* ----------------------------------------------------------
   Page Layout
   ---------------------------------------------------------- */

.simulator-page {
    min-height: 100vh;
    background-color: #f9fafb;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    color: #1f2937;
    line-height: 1.6;
}

/* ----------------------------------------------------------
   Header
   ---------------------------------------------------------- */

.simulator-header {
    background: var(--sim-gradient);
    color: #fff;
    padding: 24px;
}

.simulator-header .back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 8px;
    transition: color 0.2s ease;
}

.simulator-header .back-link:hover {
    color: #fff;
}

.simulator-header .sim-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
}

.simulator-header .sim-subtitle {
    font-size: 0.95rem;
    opacity: 0.85;
    margin: 4px 0 0;
}

/* ----------------------------------------------------------
   Container
   ---------------------------------------------------------- */

.simulator-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
}

/* ----------------------------------------------------------
   Description Card
   ---------------------------------------------------------- */

.simulator-description {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    padding: 24px;
    margin-bottom: 24px;
}

.simulator-description h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
    color: #111827;
}

.simulator-description p {
    margin: 0;
    color: #4b5563;
    font-size: 0.95rem;
}

/* ----------------------------------------------------------
   Controls Panel
   ---------------------------------------------------------- */

.controls-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    padding: 20px;
}

.control-group {
    margin-bottom: 16px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.875rem;
    color: #374151;
}

.control-input,
.control-select,
.control-textarea {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #fff;
    font-size: 0.9rem;
    font-family: inherit;
    color: #1f2937;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.control-input:focus,
.control-select:focus,
.control-textarea:focus {
    outline: none;
    border-color: var(--sim-primary);
    box-shadow: 0 0 0 3px var(--sim-primary-light);
}

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

.control-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* --- Range slider --- */
.control-range {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
    margin: 8px 0;
}

.control-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--sim-primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.control-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.control-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--sim-primary);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.control-range-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--sim-primary-dark);
    margin-left: 8px;
}

/* ----------------------------------------------------------
   Buttons
   ---------------------------------------------------------- */

.sim-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.sim-btn:hover {
    transform: translateY(-1px);
}

.sim-btn:active {
    transform: translateY(0);
}

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

.sim-btn-primary {
    background-color: var(--sim-primary);
}

.sim-btn-primary:hover:not(:disabled) {
    background-color: var(--sim-primary-dark);
}

.sim-btn-secondary {
    background-color: #4b5563;
}

.sim-btn-secondary:hover:not(:disabled) {
    background-color: #374151;
}

.sim-btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ----------------------------------------------------------
   Visualization Panel
   ---------------------------------------------------------- */

.viz-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    min-height: 400px;
    padding: 20px;
    position: relative;
}

.viz-canvas {
    width: 100%;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    box-sizing: border-box;
}

/* --- Canvas-specific styles for interactive visualizations --- */
.viz-canvas-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 6px;
    background: #fafbfc;
}

.viz-canvas-container canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
}

.viz-canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.viz-canvas-tooltip {
    position: absolute;
    background: rgba(31, 41, 55, 0.92);
    color: #f9fafb;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, monospace;
    pointer-events: none;
    white-space: nowrap;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.viz-axis-label {
    font-size: 0.75rem;
    fill: #6b7280;
    font-family: system-ui, sans-serif;
}

.viz-grid-line {
    stroke: #e5e7eb;
    stroke-width: 0.5;
    stroke-dasharray: 2 4;
}

.viz-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 0;
    font-size: 0.82rem;
    color: #4b5563;
}

.viz-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.viz-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ----------------------------------------------------------
   Step Tracker
   ---------------------------------------------------------- */

.step-tracker {
    display: flex;
    gap: 0;
    overflow-x: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    margin-bottom: 24px;
}

.step-item {
    flex-shrink: 0;
    padding: 12px 20px;
    border-bottom: 3px solid transparent;
    text-align: center;
    cursor: pointer;
    font-size: 0.875rem;
    color: #6b7280;
    font-weight: 500;
    transition: color 0.2s ease, border-color 0.2s ease;
    white-space: nowrap;
    user-select: none;
}

.step-item:hover {
    color: #1f2937;
    background: #f9fafb;
}

.step-item.active {
    border-bottom-color: var(--sim-primary);
    color: var(--sim-primary-dark);
    font-weight: 700;
}

.step-item.completed {
    border-bottom-color: #10b981;
    color: #059669;
    opacity: 0.8;
}

/* ----------------------------------------------------------
   Log Panel
   ---------------------------------------------------------- */

.log-panel {
    background: #1f2937;
    color: #f9fafb;
    border-radius: 8px;
    padding: 16px;
    font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono",
        Menlo, Consolas, monospace;
    font-size: 0.8rem;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.5;
}

.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid #374151;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry .timestamp {
    color: #9ca3af;
    margin-right: 8px;
}

/* ----------------------------------------------------------
   Stats Bar
   ---------------------------------------------------------- */

.stats-bar {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.stat-item {
    background: #fff;
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    text-align: center;
    flex: 1;
    min-width: 120px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sim-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* ----------------------------------------------------------
   Animations
   ---------------------------------------------------------- */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 var(--sim-primary-light);
    }
    50% {
        box-shadow: 0 0 0 8px transparent;
    }
    100% {
        box-shadow: 0 0 0 0 transparent;
    }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-up {
    animation: slideIn 0.3s ease;
}

.pulse-highlight {
    animation: pulse 0.6s ease;
}

/* ----------------------------------------------------------
   Pipeline Visualization
   ---------------------------------------------------------- */

.pipeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    overflow-x: auto;
    padding: 8px 0;
}

.pipeline-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.pipeline-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2.5px solid #d1d5db;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #9ca3af;
    transition: background-color 0.4s ease, border-color 0.4s ease, color 0.4s ease, box-shadow 0.4s ease;
}

.pipeline-node.is-active .pipeline-circle {
    border-color: var(--sim-primary);
    color: var(--sim-primary);
    box-shadow: 0 0 0 4px var(--sim-primary-light);
}

.pipeline-node.is-completed .pipeline-circle,
.pipeline-circle.filled {
    background-color: var(--sim-primary);
    border-color: var(--sim-primary);
    color: #fff;
}

.pipeline-label {
    font-size: 0.65rem;
    color: #9ca3af;
    text-align: center;
    max-width: 64px;
    line-height: 1.2;
    transition: color 0.3s ease;
}

.pipeline-node.is-active .pipeline-label {
    color: var(--sim-primary-dark);
    font-weight: 600;
}

.pipeline-node.is-completed .pipeline-label {
    color: #059669;
}

.pipeline-connector {
    width: 24px;
    height: 2.5px;
    background: #d1d5db;
    flex-shrink: 0;
    margin: 0 2px;
    margin-bottom: 20px;
    border-radius: 2px;
    transition: background-color 0.4s ease;
}

.pipeline-connector.is-filled {
    background: var(--sim-primary);
}

/* ----------------------------------------------------------
   Parameter Card (ML Simulators)
   ---------------------------------------------------------- */

.param-card {
    padding: 4px 0;
}

.param-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.param-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--sim-primary-light);
    color: var(--sim-primary-dark);
}

.param-done-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #d1fae5;
    color: #065f46;
}

.param-card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px;
}

.param-card-desc {
    color: #4b5563;
    font-size: 0.925rem;
    margin: 0 0 20px;
    line-height: 1.6;
}

.param-prompts {
    background: #f9fafb;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 20px;
    border-left: 3px solid var(--sim-primary);
}

.param-prompts-heading {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sim-primary-dark);
    margin: 0 0 10px;
}

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

.param-prompts-list li {
    padding: 6px 0;
    padding-left: 18px;
    position: relative;
    color: #374151;
    font-size: 0.9rem;
    line-height: 1.5;
}

.param-prompts-list li::before {
    content: "\203A";
    position: absolute;
    left: 0;
    color: var(--sim-primary);
    font-weight: 700;
    font-size: 1.1em;
}

.param-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ----------------------------------------------------------
   Data Panel (Dataset display for ML simulators)
   ---------------------------------------------------------- */

.data-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    padding: 24px;
    margin-bottom: 24px;
    border-left: 4px solid var(--sim-primary);
}

.data-panel-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px;
}

.data-panel-text {
    color: #4b5563;
    font-size: 0.925rem;
    margin: 0;
    line-height: 1.65;
}

/* ----------------------------------------------------------
   Results Grid (ML Simulators)
   ---------------------------------------------------------- */

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 8px;
}

.result-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    padding: 20px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.25s ease, transform 0.2s ease, box-shadow 0.25s ease;
    animation-fill-mode: both;
}

.result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}

.result-card.is-active {
    border-color: var(--sim-primary);
    box-shadow: 0 0 0 3px var(--sim-primary-light), 0 8px 16px rgba(0, 0, 0, 0.08);
}

.result-card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.result-card-name {
    font-size: 1rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.result-card-metric {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
    background: var(--sim-primary-light);
    color: var(--sim-primary-dark);
    white-space: nowrap;
    flex-shrink: 0;
}

.result-card-desc {
    color: #4b5563;
    font-size: 0.85rem;
    margin: 0 0 14px;
    line-height: 1.55;
}

/* ----------------------------------------------------------
   Comparison Table (ML Simulators)
   ---------------------------------------------------------- */

.compare-matrix {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    padding: 24px;
    margin-top: 24px;
    margin-bottom: 24px;
}

.compare-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 16px;
}

.compare-table-wrap {
    overflow-x: auto;
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.compare-table th {
    background: var(--sim-primary);
    color: #fff;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
}

.compare-table th:first-child {
    border-radius: 6px 0 0 0;
}

.compare-table th:last-child {
    border-radius: 0 6px 0 0;
}

.compare-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
    color: #374151;
    line-height: 1.5;
}

.compare-table tr:last-child td {
    border-bottom: none;
}

.compare-dim {
    font-weight: 700;
    color: #111827;
    white-space: nowrap;
    background: #f9fafb;
    width: 100px;
}

.compare-table ul {
    list-style: disc;
    padding-left: 16px;
    margin: 0;
}

.compare-table li {
    margin-bottom: 2px;
}

/* ----------------------------------------------------------
   Responsive (768px breakpoint)
   ---------------------------------------------------------- */

@media (max-width: 768px) {
    .simulator-header {
        padding: 16px;
    }

    .simulator-header .sim-title {
        font-size: 1.25rem;
    }

    .simulator-container {
        padding: 16px;
    }

    .simulator-description {
        padding: 16px;
        margin-bottom: 16px;
    }

    .controls-panel {
        padding: 16px;
    }

    .viz-panel {
        min-height: 300px;
        padding: 16px;
    }

    .step-tracker {
        margin-bottom: 16px;
    }

    .step-item {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .stats-bar {
        gap: 8px;
    }

    .stat-item {
        min-width: 80px;
        padding: 10px 12px;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .sim-btn-group {
        flex-direction: column;
    }

    .sim-btn {
        width: 100%;
    }

    .log-panel {
        max-height: 200px;
        padding: 12px;
    }

    .pipeline {
        justify-content: flex-start;
        padding: 8px 4px;
    }

    .pipeline-circle {
        width: 28px;
        height: 28px;
        font-size: 0.65rem;
    }

    .pipeline-label {
        font-size: 0.55rem;
        max-width: 48px;
    }

    .pipeline-connector {
        width: 12px;
    }

    .results-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .result-card {
        padding: 16px;
    }

    .compare-table {
        font-size: 0.78rem;
    }

    .compare-table th,
    .compare-table td {
        padding: 8px 10px;
    }

    .param-actions {
        flex-direction: column;
    }

    .param-actions .sim-btn {
        width: 100%;
    }

    .viz-canvas-container canvas {
        min-height: 250px;
    }
}
