body {
    font-family: Arial, sans-serif;
    background-color: #f6f7f9;
    color: #202735;
    line-height: 1.6;
}

.correlation-visualizer {
    max-width: 1220px;
    margin: auto;
    padding: 24px;
    background: #fff;
}

.main-header {
    margin-bottom: 20px;
}

.main-header h1 {
    color: #111827;
    font-size: 2rem;
    letter-spacing: 0;
    line-height: 1.15;
    margin: 0 0 8px;
}

.main-header p {
    color: #536174;
    font-size: 1.08rem;
    line-height: 1.55;
    max-width: 920px;
    margin: 0;
}

.lab-layout {
    display: grid;
    grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.controls-panel,
.visual-panel,
.teaching-panel,
.explanation-section {
    border: 1px solid #dce3ec;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.controls-panel {
    padding: 18px;
}

.control-group {
    display: grid;
    gap: 7px;
    margin-bottom: 14px;
}

.control-group label,
.checkbox-control {
    color: #344054;
    font-size: 0.9rem;
    font-weight: 700;
}

.control-group select,
.control-group textarea,
.generator-grid select,
.generator-grid input {
    width: 100%;
    border: 1px solid #c5ceda;
    border-radius: 6px;
    color: #202735;
    font: inherit;
    padding: 8px 10px;
    background: #fff;
}

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

.control-group select:focus,
.control-group textarea:focus,
.generator-grid select:focus,
.generator-grid input:focus {
    border-color: #2563eb;
    outline: 2px solid rgba(37, 99, 235, 0.18);
}

.control-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 4px 0 16px;
}

.checkbox-control {
    align-items: center;
    display: flex;
    gap: 8px;
    font-weight: 600;
}

.checkbox-control input {
    height: 16px;
    width: 16px;
}

.generator-panel {
    border: 1px solid #dce3ec;
    border-radius: 8px;
    margin: 0 0 16px;
    padding: 14px;
}

.generator-panel legend {
    color: #394150;
    font-size: 0.92rem;
    font-weight: 700;
    padding: 0 6px;
}

.generator-grid {
    align-items: center;
    display: grid;
    gap: 8px 10px;
    grid-template-columns: 82px minmax(0, 1fr);
}

.generator-grid label {
    color: #596579;
    font-size: 0.86rem;
    font-weight: 700;
}

.generator-grid input,
.generator-grid select {
    font-size: 0.92rem;
    padding: 7px 8px;
}

.secondary-button {
    background: #f1f6ff;
    border: 1px solid #b8cdf8;
    border-radius: 6px;
    color: #17418d;
    cursor: pointer;
    font-weight: 700;
    margin-top: 10px;
    padding: 8px 12px;
    width: 100%;
}

.secondary-button:hover {
    background: #dbe9ff;
}

.draw-button {
    background-color: #2563eb;
    border: 0;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-weight: 700;
    padding: 10px 16px;
    width: 100%;
}

.draw-button:hover {
    background-color: #1d4ed8;
}

.input-hint {
    color: #657083;
    font-size: 0.88rem;
    margin: 12px 0 0;
}

.input-hint.error {
    color: #b91c1c;
    font-weight: 700;
}

.visual-panel {
    overflow: hidden;
}

.plot-legend {
    align-items: center;
    background: #f8fafc;
    border-bottom: 1px solid #dce3ec;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 12px 16px;
}

.legend-item {
    align-items: center;
    color: #475467;
    display: inline-flex;
    font-size: 0.84rem;
    font-weight: 700;
    gap: 7px;
    white-space: nowrap;
}

.legend-swatch {
    border-radius: 2px;
    display: inline-block;
    height: 12px;
    width: 18px;
}

.point-swatch {
    background: #2563eb;
}

.positive-swatch {
    background: rgba(37, 99, 235, 0.22);
    border: 1px solid rgba(37, 99, 235, 0.4);
}

.negative-swatch {
    background: rgba(225, 29, 72, 0.20);
    border: 1px solid rgba(225, 29, 72, 0.36);
}

.legend-line {
    display: inline-block;
    height: 0;
    width: 24px;
}

.regression-line {
    border-top: 2px solid #e11d48;
}

.mean-line {
    border-top: 2px dashed #f59e0b;
}

.ellipse-line {
    border-top: 2px dashed #10b981;
}

.canvas-container {
    background: #fbfcfe;
    border-bottom: 1px solid #dce3ec;
    min-height: 520px;
    width: 100%;
}

#canvas {
    display: block;
    height: auto;
    max-width: 100%;
    touch-action: manipulation;
    width: 100%;
}

.stats-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 14px;
}

.stat-card {
    border: 1px solid #dce3ec;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    padding: 14px;
}

.wide-stat {
    grid-column: 1 / -1;
}

.stat-card h3 {
    color: #202735;
    font-size: 0.98rem;
    margin: 0 0 10px;
}

.stat-table,
.matrix-table {
    border-collapse: collapse;
    font-size: 0.88rem;
    table-layout: fixed;
    width: 100%;
}

.stat-table th,
.stat-table td,
.matrix-table th,
.matrix-table td {
    background: transparent !important;
    border-top: 1px solid #e5e9f0;
    color: #111827;
    padding: 6px 4px;
    text-align: right;
}

.stat-table th,
.matrix-table th {
    color: #596579;
    font-weight: 700;
}

.stat-table th:first-child,
.stat-table td:first-child {
    text-align: left;
}

.stat-table th:nth-child(3) {
    padding-left: 12px;
}

.stat-table td,
.matrix-table td {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.matrix-table th:first-child {
    text-align: left;
}

.teaching-panel {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
    margin-top: 20px;
    padding: 18px;
}

.teaching-panel h2 {
    color: #111827;
    font-size: 1.35rem;
    margin: 0 0 8px;
}

.teaching-panel p {
    color: #536174;
    margin: 0;
}

.concept-list {
    align-content: start;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.concept-list span {
    background: #f1f6ff;
    border: 1px solid #c9dcff;
    border-radius: 6px;
    color: #173b7a;
    font-size: 0.9rem;
    font-weight: 700;
    padding: 8px 10px;
}

.explanation-section {
    margin-top: 40px;
    padding: 30px;
}

.section-header h2 {
    align-items: center;
    border-bottom: 2px solid #2563eb;
    color: #333;
    display: flex;
    font-size: 1.8rem;
    font-weight: 700;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 12px;
}

.explanation-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.explanation-card {
    background: #f8f9fa;
    border-left: 4px solid #2563eb;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    padding: 24px;
}

.explanation-card h3 {
    color: #333;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 16px;
}

.explanation-card p {
    color: #555;
    font-size: 1rem;
    line-height: 1.7;
    margin-bottom: 12px;
}

.formula-box {
    background: white;
    border: 2px solid #2563eb;
    border-radius: 6px;
    font-family: "Courier New", monospace;
    margin: 16px 0;
    padding: 16px 20px;
}

.formula-box p {
    color: #333;
    font-size: 1.02rem;
    font-weight: 600;
    margin: 8px 0;
    text-align: center;
}

.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

.dark-mode .correlation-visualizer,
.dark-mode .controls-panel,
.dark-mode .visual-panel,
.dark-mode .teaching-panel,
.dark-mode .explanation-section {
    background: #1f1f1f;
    border-color: #444;
}

.dark-mode .main-header h1,
.dark-mode .teaching-panel h2,
.dark-mode .section-header h2,
.dark-mode .stat-card h3,
.dark-mode .explanation-card h3 {
    color: #e0e0e0;
}

.dark-mode .main-header p,
.dark-mode .teaching-panel p,
.dark-mode .control-group label,
.dark-mode .checkbox-control,
.dark-mode .input-hint,
.dark-mode .explanation-card p {
    color: #d7d7d7;
}

.dark-mode .control-group select,
.dark-mode .control-group textarea,
.dark-mode .generator-grid select,
.dark-mode .generator-grid input {
    background: #2a2a2a;
    border-color: #555;
    color: #e0e0e0;
}

.dark-mode .generator-panel {
    border-color: #444;
}

.dark-mode .generator-panel legend,
.dark-mode .generator-grid label {
    color: #d7d7d7;
}

.dark-mode .secondary-button {
    background: #17253d;
    border-color: #294673;
    color: #d9e7ff;
}

.dark-mode .secondary-button:hover {
    background: #20375e;
}

.dark-mode .canvas-container {
    background: #171717;
    border-bottom-color: #444;
}

.dark-mode .plot-legend {
    background: #202020;
    border-bottom-color: #444;
}

.dark-mode .legend-item {
    color: #d7d7d7;
}

.dark-mode .stat-card {
    background: #202020;
    border-color: #444;
}

.dark-mode .stat-table th,
.dark-mode .stat-table td,
.dark-mode .matrix-table th,
.dark-mode .matrix-table td {
    background: transparent !important;
    border-top-color: #3b3b3b;
}

.dark-mode .stat-table th,
.dark-mode .matrix-table th {
    color: #bfc7d5;
}

.dark-mode .stat-table td,
.dark-mode .matrix-table td {
    color: #f4f6f8;
}

.dark-mode .concept-list span {
    background: #17253d;
    border-color: #294673;
    color: #d9e7ff;
}

.dark-mode .explanation-card {
    background: #2a2a2a;
    border-left-color: #3b82f6;
}

.dark-mode .formula-box {
    background: #1a1a1a;
    border-color: #3b82f6;
}

.dark-mode .formula-box p {
    color: #e0e0e0;
}

@media (max-width: 960px) {

    .lab-layout,
    .teaching-panel {
        grid-template-columns: 1fr;
    }

    .canvas-container {
        min-height: 500px;
    }
}

@media (max-width: 680px) {
    body {
        background: #fff;
    }

    .correlation-visualizer {
        padding: 10px;
    }

    .main-header {
        margin-bottom: 14px;
    }

    .main-header h1 {
        font-size: 1.45rem;
    }

    .main-header p {
        font-size: 0.96rem;
    }

    .lab-layout {
        gap: 12px;
    }

    .controls-panel,
    .visual-panel,
    .teaching-panel,
    .explanation-section {
        border-radius: 6px;
        box-shadow: none;
    }

    .controls-panel {
        padding: 12px;
    }

    .control-grid,
    .stats-grid,
    .concept-list {
        grid-template-columns: 1fr;
    }

    .control-group textarea {
        min-height: 170px;
    }

    .generator-grid {
        grid-template-columns: 72px minmax(0, 1fr);
    }

    .plot-legend {
        gap: 7px 10px;
        padding: 9px 10px;
    }

    .legend-item {
        font-size: 0.78rem;
        white-space: normal;
    }

    .legend-line {
        width: 18px;
    }

    .canvas-container {
        min-height: 420px;
    }

    .stats-grid {
        gap: 10px;
        padding: 10px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-table,
    .matrix-table {
        font-size: 0.8rem;
    }

    .stat-table th,
    .stat-table td,
    .matrix-table th,
    .matrix-table td {
        padding: 5px 3px;
    }

    .teaching-panel {
        margin-top: 12px;
        padding: 12px;
    }

    .explanation-section {
        margin-top: 24px;
        padding: 16px 12px;
    }

    .section-header h2 {
        font-size: 1.4rem;
    }

    .explanation-card {
        padding: 16px;
    }
}