/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

/* Main container */
.main-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(10px);
    position: relative;
}

/* Left panel - Controls */
.left-panel {
    flex: 0 0 380px;
    min-width: 300px;
    max-width: 600px;
    padding: 15px;
    background: #1e1e2e;
    border-right: 2px solid #2d2d3f;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Header */
.header {
    padding-bottom: 15px;
    border-bottom: 2px solid #2d2d3f;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.header h1 {
    color: #e0e0e0;
    font-size: 22px;
    margin-bottom: 0;
}

.header .btn {
    margin-left: 10px;
    flex-shrink: 0;
}

.mode-selector select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    font-size: 14px;
    background: #2a2a3a;
    color: #e0e0e0;
    cursor: pointer;
}

/* Sections */
.section {
    padding: 15px;
    background: #2a2a3a;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.section h3 {
    color: #e0e0e0;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
}

/* Parameter rows and groups */
.param-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.param-row:last-child {
    margin-bottom: 0;
}

.param-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.param-group label {
    font-size: 12px;
    font-weight: 500;
    color: #b0b0b0;
    margin-bottom: 4px;
}

.param-group select,
.param-group input[type="number"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    font-size: 13px;
    background: #1e1e2e;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

.param-group select:focus,
.param-group input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Buttons */
.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    flex: 1;
    min-width: 80px;
}

.btn.primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn.secondary {
    background: #4a4a5a;
    color: #e0e0e0;
}

.btn.secondary:hover {
    background: #5a5a6a;
    transform: translateY(-1px);
}

.btn.small {
    padding: 4px 8px;
    font-size: 11px;
    flex: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Progress bar */
.progress-container {
    margin-bottom: 10px;
}

.progress-bar {
    width: 100%;
    height: 16px;
    background-color: #3d3d4f;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    font-weight: 500;
    color: #e0e0e0;
    font-size: 12px;
}

/* Score display */
.score-display {
    display: flex;
    justify-content: space-between;
    font-weight: 500;
    font-size: 12px;
}

.score-display div {
    color: #e0e0e0;
}

/* Function selector */
.function-selector {
    margin-bottom: 15px;
}

.function-selector label {
    font-size: 12px;
    font-weight: 500;
    color: #b0b0b0;
    margin-bottom: 4px;
    display: block;
}

.function-selector select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    font-size: 13px;
    background: #1e1e2e;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

.function-selector select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Function display */
.function-display {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.main-function, .last-generated-function {
    padding: 10px;
    border-radius: 6px;
    background: #1e1e2e;
    border-left: 4px solid #667eea;
    font-size: 12px;
}

.main-function {
    border-left-color: #28a745;
}

.last-generated-function {
    border-left-color: #ffc107;
}

.main-function strong, .last-generated-function strong {
    color: #e0e0e0;
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
}

#mainFunction, #lastGeneratedFunction {
    font-family: 'Courier New', monospace;
    background: #1a1a2a;
    padding: 6px;
    border-radius: 4px;
    margin: 4px 0;
    border: 1px solid #3d3d4f;
    font-size: 11px;
    word-break: break-all;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

#mainFunction[contenteditable="true"] {
    border-color: #667eea;
    background: #2a2a3a;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Function pair styles for PrimeFold mode */
.function-pair {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.function-item {
    padding: 10px;
    border-radius: 6px;
    background: #1e1e2e;
    border-left: 4px solid #667eea;
    font-size: 12px;
}

.function-item strong {
    color: #e0e0e0;
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
}

#functionX, #functionY {
    font-family: 'Courier New', monospace;
    background: #1a1a2a;
    padding: 6px;
    border-radius: 4px;
    margin: 4px 0;
    border: 1px solid #3d3d4f;
    font-size: 11px;
    word-break: break-all;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

#functionX[contenteditable="true"], #functionY[contenteditable="true"] {
    border-color: #667eea;
    background: #2a2a3a;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Stats display */
.stats-display, .cache-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-row {
    display: flex;
    gap: 10px;
}

.stat-item {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: #1e1e2e;
    border-radius: 4px;
    border: 1px solid #3d3d4f;
}

.stat-label {
    font-size: 11px;
    color: #b0b0b0;
    font-weight: 500;
}

.stat-value {
    font-size: 11px;
    color: #e0e0e0;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

/* Right panel - Visualization */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #1a1a2a;
    position: relative;
    min-width: 400px;
}

.visualization-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #2a2a3a;
    border-bottom: 2px solid #3d3d4f;
}

.visualization-title-section {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: nowrap;
    min-width: 0; /* Allow flex items to shrink below their content size */
    flex: 1; /* Take available space */
    overflow: hidden; /* Prevent overflow */
}

.visualization-title-section h2 {
    flex-shrink: 0;
    min-width: 0;
    overflow: visible;
    text-overflow: unset;
    white-space: normal;
}

.visualization-controls-row {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: nowrap;
    width: 100%;
    flex: 1 1 0%;
    min-width: 0; /* Allow shrinking */
    overflow: hidden; /* Prevent overflow */
    flex: 1; /* Take remaining space after title */
}

.visualization-header h2 {
    color: #e0e0e0;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.visualization-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.display-points-control {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.display-points-control label {
    font-size: 12px;
    font-weight: 500;
    color: #b0b0b0;
    white-space: nowrap;
}

.display-points-control input[type="number"] {
    width: 80px;
    padding: 4px 6px;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    font-size: 12px;
    background: #1e1e2e;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

.display-points-control input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

/* Visualization options */
.visualization-options {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
    width: 100%;
    flex: 1 1 0%;
    overflow-x: auto;
    min-width: 0; /* Allow shrinking */
}

.visualization-options > * {
    display: inline-flex;
    align-items: center;
    margin: 0;
    flex: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #b0b0b0;
    cursor: pointer;
    user-select: none;
    white-space: nowrap; /* Prevent text wrapping */
    flex-shrink: 0; /* Prevent shrinking */
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 16px;
    height: 16px;
    border: 2px solid #3d3d4f;
    border-radius: 3px;
    background: #1e1e2e;
    position: relative;
    transition: all 0.2s;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: #667eea;
    border-color: #667eea;
}

/* Ensure all checkboxes use the same blue color */
.checkbox-label input[type="checkbox"]:checked + .checkmark,
input[type="checkbox"]:checked {
    background: #667eea !important;
    border-color: #667eea !important;
}

/* Style for regular checkboxes (not using custom checkmark) */
input[type="checkbox"] {
    accent-color: #667eea;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label:hover .checkmark {
    border-color: #667eea;
}

/* Point size control */
.point-size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.point-size-control label {
    font-size: 12px;
    font-weight: 500;
    color: #b0b0b0;
    white-space: nowrap;
}

.point-size-control input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    font-size: 12px;
    background: #1e1e2e;
    color: #e0e0e0;
    transition: border-color 0.2s;
}

.point-size-control input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.visualization-container {
    flex: 1;
    min-height: 300px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #1a1a2a;
}

#visualizationCanvas {
    border: 2px solid #3d3d4f;
    border-radius: 8px;
    background: #0f0f1a;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #2a2a3a;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #e0e0e0;
}

.help-content h3 {
    color: #e0e0e0;
    margin: 15px 0 8px 0;
}

.help-content p {
    color: #b0b0b0;
    margin-bottom: 10px;
    line-height: 1.5;
}

.help-content ul {
    color: #b0b0b0;
    margin-left: 20px;
}

.help-content li {
    margin-bottom: 5px;
    line-height: 1.4;
}

/* Mobile responsiveness */
@media (max-width: 1200px) {
    .left-panel {
        flex: 0 0 350px;
        padding: 12px;
    }
    
    .param-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .stat-row {
        flex-direction: column;
        gap: 4px;
    }
    
    .visualization-title-section {
        gap: 15px; /* Reduce gap on smaller screens */
    }
    
    .visualization-controls-row {
        gap: 12px; /* Reduce gap on smaller screens */
    }
    
    .visualization-options {
        gap: 6px; /* Reduce gap between options */
    }
    
    .checkbox-label {
        font-size: 11px; /* Slightly smaller font */
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        height: 100vh;
    }
    
    .left-panel {
        flex: 0 0 auto;
        max-height: 50vh;
        overflow-y: auto;
        padding: 10px;
    }
    
    .right-panel {
        flex: 1;
        min-height: 50vh;
    }
    
    .visualization-header {
        padding: 10px 15px;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .visualization-title-section {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .visualization-controls-row {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .visualization-options {
        justify-content: center;
        flex-wrap: wrap; /* Allow wrapping on mobile */
        gap: 8px;
    }
    
    .visualization-controls {
        justify-content: center;
    }
    
    #visualizationCanvas {
        width: 100%;
        height: auto;
        max-height: calc(50vh - 80px);
    }
    
    .section {
        padding: 12px;
        margin-bottom: 8px;
    }
    
    .param-row {
        flex-direction: column;
        gap: 6px;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .stat-row {
        flex-direction: column;
        gap: 4px;
    }
    
    .modal-content {
        margin: 10% auto;
        width: 95%;
        padding: 20px;
    }
    
    .header {
        flex-direction: row;
        gap: 6px;
        padding-bottom: 10px;
    }
    
    .header h1 {
        font-size: 18px;
    }
    
    .header .btn {
        font-size: 12px;
        padding: 6px 10px;
    }
}

@media (max-width: 480px) {
    .left-panel {
        max-height: 45vh;
        padding: 8px;
    }
    
    .right-panel {
        min-height: 55vh;
    }
    
    .header h1 {
        font-size: 18px;
    }
    
    .section h3 {
        font-size: 14px;
    }
    
    .param-group label {
        font-size: 11px;
    }
    
    .param-group select,
    .param-group input[type="number"] {
        font-size: 12px;
        padding: 5px 6px;
    }
    
    .btn {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    #visualizationCanvas {
        max-height: calc(55vh - 60px);
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section {
    animation: fadeIn 0.3s ease-out;
}

/* Scrollbar styling */
.left-panel::-webkit-scrollbar {
    width: 6px;
}

.left-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.left-panel::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.left-panel::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Log Section */
.log-section {
    margin-top: 15px;
    padding: 15px;
    background: #2a2a3a;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    min-height: 200px;
    max-height: 50vh;
}

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

.log-header h3 {
    color: #e0e0e0;
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.log-controls {
    display: flex;
    gap: 8px;
}

.log-controls .btn {
    padding: 4px 8px;
    font-size: 11px;
    background: #4a4a5a;
    color: #e0e0e0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.log-controls .btn:hover {
    background: #5a5a6a;
    transform: translateY(-1px);
}

.log-controls .btn:active {
    transform: translateY(0);
}

.log-section h3 {
    color: #e0e0e0;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
}

.log-container {
    max-height: 200px;
    overflow-y: auto;
    background: #1e1e2e;
    border: 1px solid #3d3d4f;
    border-radius: 4px;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
}

.log-entry {
    color: #b0b0b0;
    margin-bottom: 4px;
    padding: 2px 0;
    border-bottom: 1px solid #2d2d3f;
}

.log-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.log-entry.error {
    color: #ff6b6b;
}

.log-entry.success {
    color: #51cf66;
}

.log-entry.info {
    color: #74c0fc;
}

.log-entry.warning {
    color: #ffd43b;
}

/* Scrollbar for log container */
.log-container::-webkit-scrollbar {
    width: 6px;
}

.log-container::-webkit-scrollbar-track {
    background: #1e1e2e;
}

.log-container::-webkit-scrollbar-thumb {
    background: #3d3d4f;
    border-radius: 3px;
}

.log-container::-webkit-scrollbar-thumb:hover {
    background: #4d4d5f;
}

/* Fitness Function Section */
#fitness-section {
  margin-top: 20px;
  padding: 12px 10px 10px 10px;
  background: #232336;
  border: 1px solid #3d3d4f;
  border-radius: 6px;
  color: #e0e0e0;
}
.fitness-metric-row {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  gap: 6px;
}
.fitness-metric-row label {
  min-width: 110px;
  margin-right: 4px;
  color: #e0e0e0;
}
.fitness-weight {
  width: 50px;
  margin-left: 4px;
  margin-right: 4px;
  background: #232336;
  color: #e0e0e0;
  border: 1px solid #444466;
}
.fitness-weight:focus {
  outline: 1.5px solid #6c63ff;
  background: #232336;
  color: #fff;
}

.fitness-threshold {
  width: 60px;
  margin-left: 4px;
  margin-right: 4px;
  background: #232336;
  color: #e0e0e0;
  border: 1px solid #444466;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
  transition: border-color 0.2s;
}

.fitness-threshold:focus {
  outline: 1.5px solid #6c63ff;
  background: #232336;
  color: #fff;
}

.fitness-threshold::placeholder {
  color: #888;
  font-size: 11px;
}

/* Resizable Sliders */
.resizer {
    background: #3d3d4f;
    cursor: col-resize;
    width: 4px;
    position: relative;
    transition: background-color 0.2s;
    z-index: 10;
}

.resizer:hover {
    background: #667eea;
}

.resizer.active {
    background: #667eea;
}

.resizer.horizontal {
    cursor: row-resize;
    width: auto;
    height: 4px;
    margin: 0 15px;
}

.resizer.horizontal:hover {
    background: #667eea;
}

.resizer.horizontal.active {
    background: #667eea;
}

/* Ensure panels maintain their structure during resize */
.left-panel.resizing {
    user-select: none;
}

.right-panel.resizing {
    user-select: none;
}

.visualization-container.resizing {
    user-select: none;
}

.log-section.resizing {
    user-select: none;
}

.function-input-invalid {
    border: 2px solid #e74c3c !important;
    background: #2a1a1a !important;
    color: #ffb3b3 !important;
}

.fitness-option-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

.fitness-option-row .checkbox-label {
    margin: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Remove custom tooltip for Help button only */
#helpBtn[title]:hover::after,
#helpBtn[title]:hover::before {
  display: none !important;
  content: none !important;
}

/* Remove custom tooltip for Zoom In, Out, and Reset View buttons */
#zoomInBtn[title]:hover::after,
#zoomInBtn[title]:hover::before,
#zoomOutBtn[title]:hover::after,
#zoomOutBtn[title]:hover::before,
#resetViewBtn[title]:hover::after,
#resetViewBtn[title]:hover::before {
  display: none !important;
  content: none !important;
}

/* Fix white background on number input spin arrows for all browsers */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  background: #232336 !important;
  color: #e0e0e0 !important;
  border-radius: 2px;
  border: none;
  /* Fallback for browsers that ignore background: invert arrow color */
  filter: invert(1) grayscale(1) brightness(0.7);
}
input[type="number"]::-moz-inner-spin-button,
input[type="number"]::-moz-outer-spin-button {
  background: #232336 !important;
  color: #e0e0e0 !important;
  border-radius: 2px;
  border: none;
  filter: invert(1) grayscale(1) brightness(0.7);
}
input[type="number"]::-ms-inner-spin-button {
  background: #232336 !important;
  color: #e0e0e0 !important;
  border-radius: 2px;
  border: none;
  filter: invert(1) grayscale(1) brightness(0.7);
}

/* Ensure all .btn and button backgrounds are dark and text is light */
.btn, button {
  background: #4a4a5a;
  color: #e0e0e0;
  border: none;
}
.btn.primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}
.btn.secondary {
  background: #4a4a5a;
  color: #e0e0e0;
}
.btn.secondary:hover, button:hover {
  background: #5a5a6a;
  color: #fff;
}

