/* Backpropagation Tutorial - Dark Theme CSS */

.backprop-container {
    display: grid;
    grid-template-columns: 250px 1fr;
    grid-template-rows: 1fr;
    gap: 10px;
    padding: 10px;
    background: #1a1a1a;
    color: #eee;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 75vh; /* Reduced by 25% from 100vh */
}

/* Sidebar Controls */
.backprop-sidebar {
    grid-column: 1;
    grid-row: 1 / -1;
    background: #2a2a2a;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
}

.backprop-control-group {
    margin-bottom: 20px;
}

.backprop-control-group h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #4ecdc4;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.backprop-control-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.backprop-control-row label {
    font-size: 12px;
    min-width: 80px;
    color: #ccc;
}

.backprop-control-row input[type="range"] {
    flex: 1;
    height: 4px;
    background: #444;
    border-radius: 2px;
    outline: none;
}

.backprop-control-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: #4ecdc4;
    border-radius: 50%;
    cursor: pointer;
}

.backprop-control-row input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #4ecdc4;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.backprop-value {
    flex-shrink: 0;
    min-width: 50px;
    font-size: 12px;
    color: #fff;
    font-weight: bold;
    text-align: right;
}

.backprop-control-row select {
    flex: 1;
    padding: 5px;
    background: #333;
    color: #eee;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 12px;
}

#select-scenario {
    flex: 0 0 auto;
    width: calc(100% - 90px); /* Account for label (80px) + gap (10px) + extra (20px) = 110px, then subtract 30px more = 140px */
}

.backprop-btn {
    width: 100%;
    padding: 10px;
    margin: 5px 0;
    background: #4ecdc4;
    color: #1a1a1a;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.backprop-btn:hover {
    background: #5eddd4;
}

.backprop-btn:active {
    background: #3ebcb4;
}

.backprop-btn-secondary {
    background: #555;
    color: #eee;
}

.backprop-btn-secondary:hover {
    background: #666;
}

.backprop-btn.active {
    background: #ff6b6b;
}

/* Main Content Area */
.backprop-main {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto auto;
    gap: 10px;
    max-width: 800px;
}

/* Chain Rule Panel - Full Width */
.backprop-panel:has(#mathPanel),
.backprop-panel.loss-panel {
    grid-column: 1 / -1;
}

.backprop-panel {
    background: #2a2a2a;
    border-radius: 8px;
    padding: 10px;
    position: relative;
    overflow: hidden;
}

.backprop-panel h4 {
    margin: 0 0 10px 0;
    font-size: 12px;
    color: #4ecdc4;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Network Canvas */
#netCanvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #1e1e1e;
    border-radius: 4px;
}

/* Loss Chart Canvas */
#lossCanvas {
    width: 100%;
    min-height: 135px; /* Reduced by 25% from 180px */
    display: block;
    background: #1e1e1e;
    border-radius: 4px;
}


/* Math Panel */
#mathPanel {
    width: 100%;
    min-height: 160px; /* Increased to accommodate two equation rows */
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    border-radius: 4px;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
}

#mathPanel .instruction-text {
    color: #888;
    font-size: 12px;
    text-align: center;
    margin-top: 20px;
}

/* Loss Calculation Panel */
#lossPanel {
    width: 100%;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    background: #1e1e1e;
    border-radius: 4px;
    padding: 15px;
    overflow-y: auto;
    overflow-x: hidden;
}

#lossPanel .instruction-text {
    color: #888;
    font-size: 12px;
    text-align: center;
    margin-top: 20px;
}

#lossPanel #loss-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    visibility: visible;
    margin-left: -20px;
}

#mathPanel #math-content {
    display: flex;
    flex-direction: column; /* Stack rows vertically */
    gap: 20px; /* Space between the two equations */
    visibility: hidden; /* Hidden by default, shown on hover */
    margin-left: -20px; /* Shift text boxes to the left by 20px */
}

.math-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    max-width: 100%;
}

/* Delta breakdown row styling */
.math-row.delta-breakdown {
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
    margin-bottom: 15px;
}

/* Optional: Make the update row slightly different to distinguish it */
.math-row.update-row {
    border-top: 1px solid #333;
    padding-top: 15px;
}

/* Ensure the gradient copy in the second row matches the original color */
.math-row.update-row .gradient-term .value {
    color: #ff6b6b; /* Default red, JS will update this */
}

.math-term {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: #2a2a2a;
    border-radius: 4px;
    min-width: 80px;
    max-width: 100px;
    flex-shrink: 1;
}

.math-term .label {
    font-size: 10px;
    color: #888;
    margin-bottom: 5px;
}

.math-term .symbol {
    font-size: 14px;
    color: #4ecdc4;
    font-style: italic;
}

.math-term .value {
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    font-family: 'Courier New', monospace;
    word-break: break-all;
    text-align: center;
}

.math-term.delta-term .value {
    color: #f1c40f;
}

.math-term.input-term .value {
    color: #fff;
}

.math-operator {
    font-size: 20px;
    color: #666;
    margin: 0 5px;
}

/* Stats Display */
.backprop-stats {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 11px;
    color: #ccc;
}

.backprop-stats .stat-row {
    display: flex;
    justify-content: space-between;
}

.backprop-stats .stat-label {
    color: #888;
}

.backprop-stats .stat-value {
    color: #4ecdc4;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    .backprop-container {
        grid-template-columns: 200px 1fr;
    }
    
    .backprop-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
    }
}
