:root {
    --primary-bg: #f8f9fa;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --border: #e5e7eb;

    /* Visualization Colors */
    --color-neg: #f59e0b;
    /* Amber/Orange for Negative */
    --color-pos: #8b5cf6;
    /* Violet for Positive */
    --color-bg-neg: #fef3c7;
    --color-bg-pos: #ddd6fe;

    --color-tp: #8b5cf6;
    --color-fp: #f59e0b;
    --color-fn: #a78bfa;
    /* Lighter violet */
    --color-tn: #fcd34d;
    /* Lighter amber */
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-main);
    line-height: 1.5;
    padding: 20px;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    text-align: center;
    margin-bottom: 10px;
}

h1 {
    font-size: 2.6rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: #1f2937;
}

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

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
}

/* Controls */
.controls {
    display: flex;
    justify-content: left;
    align-items: center;
    background: #f3f4f6;
    /* Light gray from image */
    padding: 20px 32px;
    border-radius: 16px;
    margin-bottom: 24px;
    border: 1px solid #e5e7eb;
    flex-wrap: wrap;
    gap: 3rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    max-width: 300px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.control-header label {
    /* text-gray-500 */
    font-size: 0.95rem;
}

.control-value {
    color: var(--accent);
    font-weight: 700;
}

.control-actions {
    margin-left: auto;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

input[type=range]:focus {
    outline: none;
}

/* Webkit Slider Track */
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    background: #e0e7ff;
    /* indigo-100 */
    border-radius: 4px;
    border: none;
}

/* Webkit Slider Thumb */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -6px;
    /* (trackHeight/2 - thumbHeight/2) */
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
    transition: box-shadow 0.2s;
}

input[type=range]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.3);
}

/* Firefox Styles */
input[type=range]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: #e0e7ff;
    border-radius: 4px;
    border: none;
}

input[type=range]::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

button.btn-primary {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 9999px;
    /* Pill shape */
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
    transition: all 0.2s;
    white-space: nowrap;
}

button.btn-primary:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(99, 102, 241, 0.5);
}

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

/* Main Viz Section */
.viz-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    position: relative;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.legend {
    display: flex;
    gap: 16px;
}

.legend-item {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.bg-neg {
    background: var(--color-bg-neg);
    color: #92400e;
}

.bg-pos {
    background: var(--color-bg-pos);
    color: #5b21b6;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 300px;
    background: #fdfdfd;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: crosshair;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.threshold-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: #333;
    left: 50%;
    /* Default */
    cursor: ew-resize;
    transform: translateX(-50%);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
}

.threshold-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: #333;
    border-radius: 50%;
    border: 2px solid white;
}

.threshold-display {
    text-align: center;
    margin-top: 12px;
    font-weight: 600;
    color: var(--text-main);
}

/* Bottom Grid */
.bottom-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .bottom-grid {
        grid-template-columns: 1fr;
    }
}

h3 {
    margin-bottom: 16px;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

/* Confusion Matrix */
.matrix-grid {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 8px;
    text-align: center;
}

.matrix-header,
.matrix-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.matrix-cell {
    padding: 16px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-weight: 700;
}

.matrix-cell .count {
    font-size: 1.5rem;
}

.matrix-cell .label {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.8;
}

.tp {
    background: var(--color-pos);
    color: white;
}

.tn {
    background: var(--color-neg);
    color: white;
}

.fp {
    background: var(--color-bg-neg);
    color: #92400e;
    border: 2px solid var(--color-neg);
}

.fn {
    background: var(--color-bg-pos);
    color: #5b21b6;
    border: 2px solid var(--color-pos);
}

/* Metrics */
.metric-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #f3f4f6;
}

.metrics-panel .metric-row:last-child {
    border-bottom: none;
}

.metric-name {
    color: var(--text-muted);
}

.metric-val {
    font-family: 'Courier New', monospace;
    font-weight: 700;
}

/* ROC Curve */
.canvas-wrapper-roc {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

/* Education Mode Styles */
.matrix-cell {
    transition: all 0.2s ease;
}

.matrix-cell.masked {
    cursor: pointer;
    /* Hide text */
    position: relative;
    user-select: none;
}

.matrix-cell.masked .count {
    opacity: 0;
}

.matrix-cell.masked::after {
    content: '?';
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: bold;
}

.matrix-cell.masked:hover {
    background: #d1d5db;
    border-color: #d1d5db;
}

/* Metrics masking */
.metrics-panel.masked .metric-val {
    filter: blur(5px);
    opacity: 0.5;
    user-select: none;
}

/* ROC Curve */
.canvas-wrapper-roc {
    width: 100%;
    aspect-ratio: 1;
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}