:root {
    --primary-color: #2196F3;
    --primary-hover: #1976D2;
    --success-color: #4CAF50;
    --success-hover: #45a049;
    --danger-color: #ff4d4d;
    --danger-hover: #e60000;
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-main: #2c3e50;
    --text-secondary: #5f6368;
    --border-color: #dcdcdc;
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --radius: 8px;
}

body {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    padding: 1rem;
    margin: 0;
    min-height: 100vh;
    box-sizing: border-box;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 1rem 0;
    color: var(--text-main);
    text-align: center;
}

h2 {
    font-size: 1.1rem;
    margin-top: 0;
    margin-bottom: 0.8rem;
    color: var(--primary-color);
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 0.95rem;
    margin: 1rem 0 0.5rem 0;
    color: var(--text-main);
}

.container {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 1100px;
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Layout Grid */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (min-width: 900px) {
    .main-grid {
        grid-template-columns: 300px 1fr; /* Fixed width left, flexible right */
        gap: 2rem;
    }
}

/* Panels */
.panel {
    display: flex;
    flex-direction: column;
}

.caption {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: -0.5rem 0 0.5rem 0;
    text-align: center;
}

/* Left Panel: Canvas & Prediction */
.canvas-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 0.5rem;
}

canvas#canvas {
    border: 3px solid #333;
    background-color: black;
    cursor: crosshair;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    width: 220px;
    height: 220px;
}

.controls {
    margin-top: 0.5rem;
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    width: 100%;
}

button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
}
button:active { transform: scale(0.97); }

#clearBtn { background-color: var(--danger-color); color: white; }
#clearBtn:hover { background-color: var(--danger-hover); }

#predictBtn { background-color: var(--success-color); color: white; }
#predictBtn:hover { background-color: var(--success-hover); }

.result-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border-color);
    text-align: center;
}

#prediction {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 0.2rem 0;
    line-height: 1;
}

#confidence {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* Probability Bars */
.bar-container {
    display: flex;
    align-items: flex-end;
    height: 80px;
    gap: 4px;
    justify-content: center;
}

.bar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 20px;
    height: 100%;
    justify-content: flex-end;
}

.bar-value {
    font-size: 0.6rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
    opacity: 0;
}

.bar {
    width: 100%;
    background-color: #eee;
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}
.bar.active { background-color: var(--primary-color); }
.bar-label { font-size: 0.65rem; margin-top: 2px; color: #777; }


/* Right Panel: Training */
.train-section {
    background: #fafafa;
    padding: 1.2rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* Charts */
.charts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

@media (min-width: 600px) {
    .charts-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.chart-container {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    height: 200px;
    position: relative;
}

/* Status Bar */
.status-bar {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem 0.8rem;
    font-family: 'Consolas', monospace;
    font-size: 0.8rem;
    color: var(--text-main);
    margin-top: 0.5rem;
    white-space: pre-wrap;
    min-height: 1.2rem;
}

/* Layer Builder */
.layer-builder {
    margin-bottom: 1rem;
}

.layer-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0.5rem;
}

.layer-controls button {
    padding: 4px 10px;
    font-size: 0.8rem;
    background: white;
    border: 1px solid #ccc;
    color: var(--text-main);
}
.layer-controls button:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #f0f7ff;
}

.layer-list {
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 4px;
    max-height: 160px;
    overflow-y: auto;
    padding: 4px;
}

.layer-row {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    font-size: 0.85rem;
}
.layer-row:last-child { border-bottom: none; }
.layer-row:hover { background-color: #f9f9f9; }
.layer-row.selected { background-color: #e3f2fd; }

.layer-type { font-weight: 600; width: 90px; }
.layer-dims { display: flex; align-items: center; gap: 4px; color: #666; margin-left: auto; }
.layer-dims input {
    width: 45px;
    padding: 2px 4px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 0.8rem;
    text-align: right;
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    align-items: end;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-row label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-row input {
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
}

.form-row.full-width {
    grid-column: 1 / -1;
}

#startTrainBtn {
    background-color: var(--primary-color);
    color: white;
    width: 100%;
    margin-top: 0.5rem;
}
#startTrainBtn:hover { background-color: var(--primary-hover); }
#startTrainBtn:disabled { background-color: #ccc; cursor: not-allowed; }

/* Toggle Switch */
.switch-inline {
    font-size: 0.8rem;
    font-weight: normal;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}