/* =========================================================
   components.css — panels, buttons, sliders, toggles, stats,
                    canvas, legend.
   ========================================================= */

/* ---------- Panels (cards inside rails) ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.panel h2 {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    margin-bottom: 10px;
}

/* ---------- Form rows ---------- */
.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0 0;
}
.row label { color: var(--text-muted); font-size: 0.86rem; }

select {
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    min-width: 150px;
}

/* ---------- Sliders ---------- */
.slider-row { margin: 10px 0 0; }
.slider-row:first-of-type { margin-top: 0; }
.slider-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: var(--text);
    font-size: 0.86rem;
    margin-bottom: 2px;
}
.slider-label output,
.slider-label .slider-value {
    font-family: var(--mono);
    color: var(--accent-strong);
    font-size: 0.84rem;
}
.slider-value {
    width: 70px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--accent-strong);
    text-align: right;
    -moz-appearance: textfield;
}
.slider-value::-webkit-outer-spin-button,
.slider-value::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.slider-value:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}
input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    margin: 2px 0 0;
}
.slider-row.disabled { opacity: 0.38; pointer-events: none; }

/* ---------- Buttons ---------- */
.btn {
    cursor: pointer;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    font-weight: 500;
    transition: transform 0.05s ease, box-shadow 0.15s ease,
                background 0.15s ease, border-color 0.15s ease;
}
.btn:hover  { background: var(--bg-soft); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

/* The Train button is the page's primary CTA — give it weight. */
.btn-train {
    padding: 9px 20px;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    box-shadow: 0 2px 10px rgba(58, 109, 240, 0.28);
    margin-left: 4px;
}
.btn-train:hover {
    box-shadow: 0 4px 14px rgba(58, 109, 240, 0.38);
}

/* Step is a secondary action that mirrors Train's height for visual balance. */
.btn-step {
    padding: 9px 14px;
    font-weight: 500;
    border-color: var(--accent-soft);
    color: var(--accent-strong);
    background: var(--accent-soft);
}
.btn-step:hover {
    background: #d8e3ff;
    border-color: #b9caff;
}
:root[data-theme="dark"] .btn-step:hover {
    background: rgba(91, 140, 255, 0.28);
    border-color: rgba(91, 140, 255, 0.5);
}

/* ---------- Class toggle (10 classes, 5 cols × 2 rows) ---------- */
.class-toggle {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    background: var(--bg-soft);
    padding: 4px;
    border-radius: var(--radius);
}
.class-btn {
    border: none;
    background: transparent;
    padding: 6px 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-weight: 500;
    font-size: 0.82rem;
    transition: all 0.15s ease;
}
.class-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}
.dot {
    width: 9px; height: 9px; border-radius: 50%;
    display: inline-block;
}
.dot-c1  { background: var(--c1); }
.dot-c2  { background: var(--c2); }
.dot-c3  { background: var(--c3); }
.dot-c4  { background: var(--c4); }
.dot-c5  { background: var(--c5); }
.dot-c6  { background: var(--c6); }
.dot-c7  { background: var(--c7); }
.dot-c8  { background: var(--c8); }
.dot-c9  { background: var(--c9); }
.dot-c10 { background: var(--c10); }

.hint {
    font-size: 0.78rem;
    color: var(--text-faint);
    margin: 8px 0 4px;
    line-height: 1.4;
}

/* ---------- Checkboxes ---------- */
.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}
.checkbox input { accent-color: var(--accent); }
.checkbox-inline { padding: 4px 6px; }

/* ---------- Stats (right rail) ---------- */
.stats {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}
.stat {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
}
.stat-label {
    font-size: 0.7rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.stat-val {
    font-family: var(--mono);
    color: var(--text);
    font-size: 0.95rem;
    margin-top: 2px;
    word-break: break-word;
}

/* Make the Status row pop — it changes during training. */
.panel-stats .stat:first-child .stat-val { color: var(--accent-strong); }

/* ---------- Canvas + legend ---------- */
.canvas-frame {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    container-type: size;
    background: var(--surface-2);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}
canvas {
    /* Pick the largest square that fits inside the container. */
    width:  min(100cqw, 100cqh);
    height: min(100cqw, 100cqh);
    aspect-ratio: 1 / 1;
    background: #fff;
    border-radius: var(--radius);
    cursor: crosshair;
    display: block;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0 4px;
    align-items: center;
    justify-content: center;
}
.legend i {
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle;
}
.sw { width: 12px; height: 12px; border-radius: 50%; }
.sw-c1  { background: var(--c1); }
.sw-c2  { background: var(--c2); }
.sw-c3  { background: var(--c3); }
.sw-c4  { background: var(--c4); }
.sw-c5  { background: var(--c5); }
.sw-c6  { background: var(--c6); }
.sw-c7  { background: var(--c7); }
.sw-c8  { background: var(--c8); }
.sw-c9  { background: var(--c9); }
.sw-c10 { background: var(--c10); }
.sw-sv  { background: transparent; border: 2px solid var(--sv); }
.sw-bnd { width: 22px; height: 0; border-top: 2px solid var(--boundary); border-radius: 0; }
.sw-mar { width: 22px; height: 0; border-top: 2px dashed var(--margin); border-radius: 0; }

/* On stacked layouts (genuinely small screens), give the canvas a usable height. */
@media (max-width: 900px), (max-height: 480px) {
    .canvas-frame { min-height: min(72vw, 560px); }
    canvas { width: 100%; height: auto; }
}
