/**
 * RL GRIDWORLD SIMULATION STYLES
 * ==============================
 * Q-Learning visualization with "glass-box" approach
 */

/* Container */
.rl-container {
    font-family: 'Courier New', monospace;
    background: #0d1117;
    color: #c9d1d9;
    padding: 15px;
    border-radius: 8px;
    max-width: 800px;
    margin: 0 auto;
}

/* Main Layout */
.rl-main-layout {
    display: flex;
    gap: 15px;
}

/* Control Panel */
.rl-control-panel {
    width: 220px;
    flex-shrink: 0;
}

.rl-control-section {
    background: rgba(30, 40, 55, 0.8);
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.rl-control-section h4 {
    margin: 0 0 8px 0;
    font-size: 11px;
    color: #58a6ff;
    border-bottom: 1px solid #30363d;
    padding-bottom: 5px;
}

/* Parameter Groups */
.rl-param-group {
    margin-bottom: 8px;
}

.rl-param-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 10px;
    margin-bottom: 3px;
}

.rl-param-label .name {
    color: #8b949e;
}

.rl-param-label .value {
    color: #58a6ff;
    font-weight: bold;
}

.rl-param-label .unit {
    color: #6e7681;
    margin-left: 2px;
    font-size: 9px;
}

/* Sliders - single track: only the runnable track is drawn, not the input box */
.rl-slider {
    width: 100%;
    height: 6px;
    min-height: 18px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
    display: block;
    box-sizing: border-box;
}

.rl-slider::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: #30363d;
}

.rl-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #58a6ff;
    cursor: pointer;
    margin-top: -4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.rl-slider::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: #30363d;
}

.rl-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #58a6ff;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.rl-slider.alpha::-webkit-slider-thumb { background: #f97583; }
.rl-slider.gamma::-webkit-slider-thumb { background: #56d364; }
.rl-slider.epsilon::-webkit-slider-thumb { background: #d2a8ff; }
.rl-slider.alpha::-moz-range-thumb { background: #f97583; }
.rl-slider.gamma::-moz-range-thumb { background: #56d364; }
.rl-slider.epsilon::-moz-range-thumb { background: #d2a8ff; }

/* Buttons */
.rl-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.rl-btn {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #30363d;
    border-radius: 4px;
    background: #21262d;
    color: #c9d1d9;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 60px;
}

.rl-btn:hover {
    background: #30363d;
    border-color: #58a6ff;
}

.rl-btn.primary {
    background: #238636;
    border-color: #238636;
    color: white;
}

.rl-btn.primary:hover {
    background: #2ea043;
}

.rl-btn.danger {
    background: #da3633;
    border-color: #da3633;
    color: white;
}

.rl-btn.danger:hover {
    background: #f85149;
}

.rl-btn.active {
    background: #1f6feb;
    border-color: #1f6feb;
}

.rl-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Stats Display */
.rl-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.rl-stat-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 6px;
    border-radius: 4px;
    text-align: center;
}

.rl-stat-item .label {
    font-size: 8px;
    color: #8b949e;
    display: block;
}

.rl-stat-item .value {
    font-size: 14px;
    font-weight: bold;
    color: #58a6ff;
}

.rl-stat-item .value.reward-positive { color: #56d364; }
.rl-stat-item .value.reward-negative { color: #f97583; }

/* Visual Panel */
.rl-visual-panel {
    flex: 1;
    min-width: 0;
}

/* Grid Board */
.rl-grid-container {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.rl-grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 10px;
}

.rl-grid-header .title {
    color: #58a6ff;
    font-weight: bold;
}

.rl-mode-indicator {
    background: #21262d;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 9px;
    color: #d2a8ff;
}

.rl-grid-board {
    display: inline-grid;  /* Use inline-grid so container shrinks to fit content */
    gap: 2px;
    position: relative;  /* Required for absolute positioning of agent */
}

.rl-grid-wrapper {
    text-align: center;  /* Center the inline-grid */
}

/* Grid Cells */
.rl-cell {
    position: relative;
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
}

.rl-cell:hover {
    border-color: #58a6ff;
}

.rl-cell.start {
    background: #1f6feb;
    border-color: #58a6ff;
}

.rl-cell.wall {
    background: #484f58;
    border-color: #6e7681;
}

.rl-cell.pit {
    background: linear-gradient(135deg, #da3633 0%, #8b1914 100%);
    border-color: #f97583;
}

.rl-cell.goal {
    background: linear-gradient(135deg, #238636 0%, #0d5d25 100%);
    border-color: #56d364;
}

/* Q-Value Triangles */
.rl-q-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.rl-q-triangle {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Up triangle */
.rl-q-triangle.up {
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 10px solid #00d2ff;  /* Cyan for positive */
}

/* Down triangle */
.rl-q-triangle.down {
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid #00d2ff;  /* Cyan for positive */
}

/* Left triangle */
.rl-q-triangle.left {
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 10px solid #00d2ff;  /* Cyan for positive */
}

/* Right triangle */
.rl-q-triangle.right {
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 10px solid #00d2ff;  /* Cyan for positive */
}

/* Best action highlight */
.rl-q-triangle.best {
    filter: brightness(1.3);
}

/* Agent Avatar */
.rl-agent {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #f0883e;
    border: 2px solid #ffb86c;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    box-shadow: 0 0 10px rgba(240, 136, 62, 0.5);
    transition: all 0.15s ease-out;
}

.rl-agent::after {
    content: '🤖';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
}

/* Cell Icons */
.rl-cell-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    z-index: 5;
}

/* Q-Value Text (hover) */
.rl-q-text {
    position: absolute;
    font-size: 9px;
    color: rgba(255, 255, 255, 0.8);
    z-index: 8;
    text-shadow: 0 0 2px black;
    opacity: 0;
    transition: opacity 0.2s;
}

.rl-cell:hover .rl-q-text {
    opacity: 1;
}

.rl-q-text.up { top: 2px; left: 50%; transform: translateX(-50%); }
.rl-q-text.down { bottom: 2px; left: 50%; transform: translateX(-50%); }
.rl-q-text.left { left: 2px; top: 50%; transform: translateY(-50%); }
.rl-q-text.right { right: 2px; top: 50%; transform: translateY(-50%); }

/* Cell Type Selector */
.rl-cell-types {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.rl-type-btn {
    padding: 4px 8px;
    border: 1px solid #30363d;
    border-radius: 4px;
    background: #21262d;
    color: #c9d1d9;
    font-family: 'Courier New', monospace;
    font-size: 9px;
    cursor: pointer;
    transition: all 0.15s;
}

.rl-type-btn:hover {
    background: #30363d;
}

.rl-type-btn.active {
    border-color: #58a6ff;
    background: #1f6feb;
}

.rl-type-btn.empty { border-color: #30363d; }
.rl-type-btn.wall { border-color: #6e7681; }
.rl-type-btn.pit { border-color: #f97583; }
.rl-type-btn.goal { border-color: #56d364; }

/* Info Panel */
.rl-info-panel {
    background: rgba(30, 40, 55, 0.8);
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 10px;
    margin-top: 10px;
}

.rl-info-panel h4 {
    margin: 0 0 8px 0;
    font-size: 11px;
    color: #58a6ff;
    border-bottom: 1px solid #30363d;
    padding-bottom: 5px;
}

/* Q-Table Display */
.rl-qtable-display {
    font-size: 9px;
    max-height: 120px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px;
    border-radius: 4px;
}

.rl-qtable-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.rl-qtable-row .state {
    color: #8b949e;
}

.rl-qtable-row .values {
    color: #56d364;
}

/* Legend */
.rl-legend {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 9px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    margin-top: 10px;
}

.rl-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rl-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.rl-legend-color.start { background: #1f6feb; }
.rl-legend-color.empty { background: #21262d; border: 1px solid #30363d; }
.rl-legend-color.wall { background: #484f58; }
.rl-legend-color.pit { background: #da3633; }
.rl-legend-color.goal { background: #238636; }
.rl-legend-color.agent { background: #f0883e; border-radius: 50%; }

/* Algorithm Log */
.rl-log {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    padding: 6px;
    font-size: 11px;
    max-height: 80px;
    overflow-y: auto;
}

.rl-log-entry {
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #8b949e;
}

.rl-log-entry .action {
    color: #d2a8ff;
}

.rl-log-entry .reward {
    color: #56d364;
}

.rl-log-entry .reward.negative {
    color: #f97583;
}

/* Q-Update Calculation Panel */
.rl-calc-panel {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    padding: 10px;
    font-size: 12px;
}

.rl-calc-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    gap: 10px;
}

.rl-calc-label {
    color: #fff;
    flex-shrink: 0;
}

.rl-calc-value {
    color: #58a6ff;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    text-align: right;
    min-width: 60px;
}

.rl-calc-divider {
    border-top: 1px solid #30363d;
    margin: 6px 0;
}

.rl-calc-result {
    background: rgba(88, 166, 255, 0.1);
    padding: 5px;
    border-radius: 4px;
    margin: 4px -5px;
}

.rl-calc-result .rl-calc-value {
    color: #56d364;
    font-size: 14px;
}

.rl-calc-formula {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #fff;
    text-align: center;
    line-height: 1.6;
}

.rl-calc-value.positive {
    color: #56d364;
}

.rl-calc-value.negative {
    color: #f97583;
}

/* Action Determination Panel */
.rl-determination-panel {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    padding: 10px;
    font-size: 12px;
}

.rl-determination-content {
    color: #c9d1d9;
    line-height: 1.5;
}

.rl-determine-method {
    font-weight: bold;
    margin-bottom: 6px;
    font-size: 13px;
}

.rl-determine-detail {
    margin-bottom: 4px;
    font-size: 11px;
}

.rl-determine-qblock {
    margin: 8px 0;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

.rl-determine-qrow {
    padding: 2px 0;
}

.rl-determine-qrow.rl-determine-best {
    color: #56d364;
    font-weight: bold;
}

/* Equation Display */
.rl-equation {
    background: rgba(0, 0, 0, 0.4);
    padding: 10px;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 11px;
    text-align: center;
    border-left: 3px solid #58a6ff;
}

.rl-equation .formula {
    font-family: 'Times New Roman', serif;
    font-size: 13px;
    color: #c9d1d9;
}

.rl-equation .description {
    font-size: 9px;
    color: #8b949e;
    margin-top: 5px;
}

/* Preset Dropdown */
.rl-preset-select {
    width: 100%;
    padding: 6px;
    border: 1px solid #30363d;
    border-radius: 4px;
    background: #21262d;
    color: #c9d1d9;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    cursor: pointer;
}

.rl-preset-select:focus {
    outline: none;
    border-color: #58a6ff;
}

/* Episode Progress */
.rl-progress-bar {
    width: 100%;
    height: 6px;
    background: #21262d;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 5px;
}

.rl-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #238636, #56d364);
    transition: width 0.3s;
}

/* Epsilon Decay Indicator - hidden to avoid double scrollbar with the epsilon slider */
.rl-epsilon-bar {
    display: none;
}

.rl-epsilon-fill {
    height: 100%;
    background: #d2a8ff;
    transition: width 0.3s;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .rl-main-layout {
        flex-direction: column;
    }
    
    .rl-control-panel {
        width: 100%;
    }
}
