/* Evolution Simulator Styles */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 10px;
}

/* Welcome Screen */
#welcome-screen {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 30px;
    max-width: 900px;
    margin: 20px auto;
}

#welcome-screen h1 {
    color: #2c3e50;
    margin-bottom: 20px;
    text-align: center;
}

.welcome-content {
    max-height: 500px;
    overflow-y: auto;
    padding: 20px;
    background: #fafafa;
    border-radius: 4px;
    margin-bottom: 20px;
}

.welcome-content p {
    margin-bottom: 12px;
    color: #3d4a57;
}

.welcome-content h2 {
    color: #2c3e50;
    font-size: 1.2em;
    margin-top: 20px;
    margin-bottom: 10px;
}

.welcome-content h2:first-child {
    margin-top: 0;
}

.welcome-content h3 {
    color: #34495e;
    font-size: 1em;
    margin-top: 15px;
    margin-bottom: 5px;
}

.welcome-content ul {
    margin: 10px 0 16px 20px;
    padding-left: 18px;
}

.welcome-content li {
    margin-bottom: 6px;
}

.cell-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin: 15px 0;
}

.cell-type-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 4px;
}

.cell-color-box {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    border: 1px solid #ccc;
}

.welcome-footer {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.welcome-footer .btn {
    margin-left: auto;
}

.welcome-footer label {
    font-weight: 500;
}

.welcome-footer select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.btn {
    padding: 6px 16px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #ecf0f1;
    color: #333;
}

.btn-secondary:hover {
    background: #ddd;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* Simulation Screen */
#simulation-screen {
    display: none;
    height: 100vh;
    padding: 0;
    overflow: hidden;
}

#simulation-screen.active {
    display: flex;
    flex-direction: column;
}

/* Top Toolbar */
.top-toolbar {
    background: white;
    border-bottom: 1px solid #ddd;
    padding: 6px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.toolbar-title {
    color: #2c3e50;
    font-size: 1.1em;
    font-weight: 600;
    margin-right: 8px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: #ddd;
}

.main-layout {
    display: grid;
    grid-template-columns: 360px 1fr 320px;
    gap: 8px;
    flex: 1;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
}

@media (max-width: 1600px) {
    .main-layout {
        grid-template-columns: 1fr 320px;
    }
    .legend-panel {
        display: none;
    }
}

@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
}

/* Bottom Panel for Selected Organism */
.bottom-panel {
    background: white;
    border-top: 2px solid #3498db;
    padding: 12px 15px;
    display: none;
    flex-shrink: 0;
    height: 200px;
    overflow: hidden;
    position: relative;
}

.bottom-panel.active {
    display: flex;
    gap: 20px;
    align-items: stretch;
}

.bottom-panel-close {
    position: absolute;
    top: 8px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: #e74c3c;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.bottom-panel-close:hover {
    background: #c0392b;
}

.bottom-panel-content {
    display: flex;
    gap: 20px;
    width: 100%;
    height: 100%;
}

/* Organism shape preview */
.organism-preview {
    flex: 0 0 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.organism-preview h4 {
    margin: 0 0 6px 0;
    color: #2c3e50;
    font-size: 0.9em;
}

#organism-shape-canvas {
    background: #1a1a2e;
    border-radius: 4px;
    width: 120px;
    height: 120px;
}

.organism-preview-label {
    font-size: 0.75em;
    color: #666;
    margin-top: 4px;
}

/* Organism stats */
.organism-stats {
    flex: 0 0 160px;
}

.organism-stats h4 {
    margin: 0 0 6px 0;
    color: #2c3e50;
    font-size: 0.9em;
}

.organism-stats .stats-grid {
    font-size: 0.85em;
}

/* Organism composition */
.organism-comp {
    flex: 0 0 180px;
}

.organism-comp h4 {
    margin: 0 0 6px 0;
    color: #2c3e50;
    font-size: 0.9em;
}

/* Neural network container */
.neural-network-container {
    flex: 1;
    min-width: 250px;
    display: flex;
    flex-direction: column;
}

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

.nn-header h4 {
    margin: 0;
    color: #2c3e50;
    font-size: 0.9em;
}

.nn-header span {
    font-size: 0.75em;
    color: #888;
}

#nn-canvas {
    background: #1a1a2e;
    border-radius: 4px;
    flex: 1;
    width: 100%;
}

/* Legend Panel */
.legend-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 15px;
    min-height: 0;
    overflow-y: auto;
}

.legend-panel h2 {
    color: #2c3e50;
    font-size: 1.05em;
    margin-bottom: 10px;
    font-weight: 600;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px;
    background: #fafafa;
    border-radius: 4px;
}

.legend-color {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid #999;
    flex-shrink: 0;
}

.legend-info {
    flex: 1;
}

.legend-info strong {
    display: block;
    color: #2c3e50;
    margin-bottom: 2px;
}

.legend-info span {
    font-size: 0.85em;
    color: #666;
}

.legend-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.legend-section h3 {
    color: #34495e;
    font-size: 0.95em;
    margin-bottom: 8px;
    font-weight: 600;
}

/* Canvas Panel */
.canvas-panel {
    background: transparent;
    min-height: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.canvas-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.92);
    color: #2c3e50;
    font-size: 12px;
    border: 1px solid rgba(52, 152, 219, 0.28);
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    pointer-events: none;
    white-space: nowrap;
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    max-width: 100%;
    max-height: 100%;
}

.canvas-container.zoomed-in {
    justify-content: flex-start;
    align-items: flex-start;
}

#sim-canvas {
    display: block;
    cursor: pointer;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    flex-shrink: 0;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Right Panel */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    overflow-y: auto;
}

.info-panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 12px;
}

.info-panel h2 {
    color: #2c3e50;
    font-size: 1.05em;
    margin-bottom: 8px;
    font-weight: 600;
}

.info-panel h3 {
    color: #34495e;
    font-size: 0.95em;
    margin-top: 10px;
    margin-bottom: 5px;
    font-weight: 600;
}

.stats-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 12px;
    font-size: 0.85em;
}

.stats-grid dt {
    font-weight: 500;
    color: #555;
}

.stats-grid dd {
    font-family: 'Consolas', monospace;
}

.chart-container {
    width: 100%;
    height: 100px;
    margin: 8px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.organism-composition {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.comp-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85em;
}

.comp-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid #999;
}

.cell-dist-bars {
    margin-top: 8px;
}

.cell-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.cell-bar-label {
    width: 55px;
    font-size: 0.8em;
    font-weight: 500;
}

.cell-bar-bg {
    flex: 1;
    height: 18px;
    background: #f0f0f0;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.cell-bar-fill {
    height: 100%;
    transition: width 0.3s;
}

.cell-bar-count {
    width: 40px;
    text-align: right;
    font-size: 0.85em;
    font-family: 'Consolas', monospace;
}

/* Control Groups (used in toolbar) */
.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-group label {
    font-size: 0.8em;
    font-weight: 500;
    color: #555;
    white-space: nowrap;
}

.control-group select,
.control-group input[type="number"] {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

.control-group input[type="range"] {
    width: 80px;
}

.control-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

.button-group {
    display: flex;
    gap: 6px;
}

.param-value {
    font-size: 0.75em;
    color: #7f8c8d;
    min-width: 55px;
}

.tooltip {
    position: relative;
    cursor: help;
}

.tooltip:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 0.85em;
    z-index: 1000;
    margin-bottom: 5px;
}

/* Scrollbar styling */
.welcome-content::-webkit-scrollbar,
.right-panel::-webkit-scrollbar,
.legend-panel::-webkit-scrollbar {
    width: 8px;
}

.welcome-content::-webkit-scrollbar-track,
.right-panel::-webkit-scrollbar-track,
.legend-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.welcome-content::-webkit-scrollbar-thumb,
.right-panel::-webkit-scrollbar-thumb,
.legend-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.welcome-content::-webkit-scrollbar-thumb:hover,
.right-panel::-webkit-scrollbar-thumb:hover,
.legend-panel::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ===================== */
/* Modal Overlay Styles  */
/* ===================== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #2c3e50;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0 5px;
}

.modal-close:hover {
    color: #e74c3c;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Guide Modal */
#guide-modal .modal-content {
    max-width: 700px;
    width: 90%;
}

#guide-modal .modal-body {
    max-height: 60vh;
    overflow-y: auto;
}

#guide-modal h3 {
    color: #3498db;
    margin-top: 20px;
    margin-bottom: 10px;
}

#guide-modal ul {
    margin-left: 20px;
}

#guide-modal li {
    margin-bottom: 5px;
}

/* Organism Designer Modal */
#designer-modal .modal-content {
    max-width: 800px;
    width: 95%;
}

.designer-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.designer-palette {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 100px;
}

.palette-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    background: #f8f9fa;
    transition: all 0.2s;
}

.palette-btn:hover {
    background: #e9ecef;
}

.palette-btn.active,
.palette-btn.selected {
    border-color: #3498db;
    background: #e3f2fd;
}

.palette-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
    border: 1px solid #333;
}

.designer-grid-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.designer-grid {
    display: grid;
    grid-template-columns: repeat(12, 28px);
    grid-template-rows: repeat(12, 28px);
    gap: 1px;
    background: #ddd;
    padding: 1px;
    border-radius: 4px;
}

.designer-cell {
    width: 28px;
    height: 28px;
    background: #1a1a2e;
    cursor: pointer;
    transition: background 0.1s;
}

.designer-cell:hover {
    opacity: 0.8;
}

.designer-preview {
    text-align: center;
    min-width: 150px;
}

.designer-preview canvas {
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #1a1a2e;
}

.designer-stats {
    margin-top: 10px;
    font-size: 0.9em;
}

.designer-stats .valid {
    color: #27ae60;
}

.designer-stats .invalid {
    color: #e74c3c;
}

/* History Modal */
#history-modal .modal-content {
    max-width: 1100px;
    width: 95%;
}

.history-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.history-charts {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-chart-container {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
}

.history-chart-container h4 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 0.95em;
}

.history-chart-container canvas {
    width: 100%;
    height: 120px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
}

.history-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.history-stat-section {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 6px;
}

.history-stat-section h4 {
    margin: 0 0 12px 0;
    color: #2c3e50;
    font-size: 0.95em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

.species-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.species-list li {
    padding: 8px 10px;
    margin-bottom: 5px;
    background: #fff;
    border-radius: 4px;
    border-left: 3px solid #3498db;
    font-size: 0.9em;
}

.species-list li:nth-child(1) { border-left-color: #f1c40f; }
.species-list li:nth-child(2) { border-left-color: #95a5a6; }
.species-list li:nth-child(3) { border-left-color: #cd6155; }

.species-name {
    font-weight: 600;
    color: #2c3e50;
}

.species-detail {
    color: #7f8c8d;
    font-size: 0.85em;
    margin-top: 3px;
}

.stat-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.stat-item {
    background: #fff;
    padding: 10px;
    border-radius: 4px;
    text-align: center;
}

.stat-value {
    font-size: 1.4em;
    font-weight: bold;
    color: #3498db;
}

.stat-label {
    font-size: 0.8em;
    color: #7f8c8d;
    margin-top: 3px;
}

/* Species Card (styled species display with body preview) */
.species-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: #fff;
    border-radius: 6px;
    border-left: 4px solid #3498db;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.species-card:nth-child(1) { border-left-color: #f1c40f; }
.species-card:nth-child(2) { border-left-color: #95a5a6; }
.species-card:nth-child(3) { border-left-color: #cd6155; }
.species-card:nth-child(4) { border-left-color: #3498db; }
.species-card:nth-child(5) { border-left-color: #9b59b6; }

.species-card-body {
    flex-shrink: 0;
}

.species-body-preview {
    border-radius: 4px;
    background: #1a1a2e;
}

.species-card-info {
    flex: 1;
    min-width: 0;
}

.species-composition {
    font-size: 0.85em;
    line-height: 1.5;
    margin-bottom: 4px;
}

.species-card .species-detail {
    margin-top: 0;
}
