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

body {
    font-family: 'Courier New', monospace;
    background: #0a0a0a;
    color: #e0e0e0;
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: #111;
    border-bottom: 1px solid #333;
    flex-wrap: wrap;
}

header h1 {
    font-size: 24px;
    color: #4fc3f7;
    letter-spacing: 4px;
}

.subtitle {
    color: #666;
    font-size: 12px;
}

.badge {
    background: #1b5e20;
    color: #81c784;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}

.badge.preprod {
    background: #e65100;
    color: #ffb74d;
}

.indicator {
    margin-left: auto;
    padding: 4px 12px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: bold;
}

.indicator.alive {
    background: #1b5e20;
    color: #4caf50;
    animation: pulse 2s infinite;
}

.indicator.dead {
    background: #b71c1c;
    color: #ef5350;
}

.indicator.survived {
    background: #1b5e20;
    color: #66bb6a;
    font-weight: bold;
    animation: glow 1.5s infinite;
}

.indicator.spawning {
    background: #1a237e;
    color: #7986cb;
    animation: pulse 1s infinite;
}

.indicator.batch {
    background: #0d2d44;
    color: #4fc3f7;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes glow {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px #4caf5066; }
    50% { opacity: 0.8; box-shadow: 0 0 16px #4caf5099; }
}

main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

.panel {
    background: #151515;
    border: 1px solid #2a2a2a;
    border-radius: 4px;
    padding: 16px;
}

.panel h2 {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

/* Metabolic meters */
.meter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.meter label {
    width: 24px;
    font-size: 12px;
    color: #888;
}

.bar {
    flex: 1;
    height: 16px;
    background: #1a1a1a;
    border-radius: 2px;
    overflow: hidden;
}

.fill {
    height: 100%;
    background: #4fc3f7;
    transition: width 0.3s ease;
    border-radius: 2px;
}

.fill.catalyst {
    background: #ff9800;
}

.value {
    width: 48px;
    text-align: right;
    font-size: 11px;
    color: #aaa;
}

/* Viability */
.viability {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.viability label {
    font-size: 11px;
    color: #666;
}

.viability-bar {
    flex: 1;
    height: 8px;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
}

.viability-fill {
    height: 100%;
    background: linear-gradient(90deg, #f44336, #ff9800, #4caf50);
    transition: width 0.3s ease;
    border-radius: 4px;
}

#viability-value {
    font-size: 11px;
    color: #aaa;
    width: 40px;
    text-align: right;
}

/* Motor */
.motor-values {
    display: flex;
    gap: 24px;
    font-size: 14px;
}

.motor-values strong {
    color: #4fc3f7;
}

/* Info grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 13px;
}

.info-grid strong {
    color: #4fc3f7;
}

/* Canvas */
canvas {
    width: 100%;
    background: #0d0d0d;
    border-radius: 2px;
}

/* Full-width panels */
.full-width,
#timeline-panel {
    grid-column: 1 / -1;
}

/* Layer progress bar */
.layer-progress {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 16px;
}

.layer-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 4px;
    font-size: 12px;
    color: #555;
    transition: all 0.3s ease;
}

.layer-step.active {
    background: #1b3a1b;
    border-color: #4caf50;
    color: #4caf50;
}

.layer-step.completed {
    background: #0d2d44;
    border-color: #4fc3f7;
    color: #4fc3f7;
}

.layer-num {
    font-weight: bold;
    font-size: 14px;
}

.layer-label {
    font-size: 11px;
}

.layer-connector {
    width: 20px;
    height: 1px;
    background: #2a2a2a;
}

/* Narrative text */
.narrative {
    font-size: 13px;
    line-height: 1.6;
    color: #bbb;
    padding: 12px 16px;
    background: #0d0d0d;
    border-left: 3px solid #4fc3f7;
    border-radius: 0 4px 4px 0;
    margin-bottom: 12px;
}

/* Layer stats */
.layer-stats {
    display: flex;
    gap: 24px;
    font-size: 12px;
    color: #666;
}

.layer-stats strong {
    color: #4fc3f7;
}

/* Tooltips */
[data-tooltip] {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted #444;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #ccc;
    padding: 8px 12px;
    border-radius: 4px;
    border: 1px solid #444;
    font-size: 11px;
    font-weight: normal;
    text-transform: none;
    letter-spacing: 0;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    line-height: 1.5;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 100;
}
[data-tooltip]:hover::after {
    opacity: 1;
}
.panel h2[data-tooltip] {
    border-bottom: none;
}

/* How it works link */
.how-link {
    text-decoration: none;
    color: #4fc3f7;
    font-size: 12px;
    border: 1px solid #333;
    padding: 2px 8px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}
.how-link:hover {
    background: #1a1a1a;
    border-color: #4fc3f7;
}

/* Run History */
.run-history-list {
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
}
.run-entry {
    padding: 4px 8px;
    border-left: 3px solid #333;
    margin-bottom: 2px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.run-survived { border-left-color: #4caf50; }
.run-died { border-left-color: #f44336; }
.run-num { color: #666; font-weight: bold; min-width: 30px; }
.run-result { color: #bbb; flex: 1; }
.run-seed { color: #555; font-size: 10px; }
.run-history-empty { color: #444; font-style: italic; padding: 8px; }

/* Event Log */
.event-log {
    max-height: 200px;
    overflow-y: auto;
    font-size: 11px;
    font-family: 'Courier New', monospace;
}
.event-entry {
    padding: 3px 8px;
    border-left: 2px solid #333;
    margin-bottom: 1px;
    display: flex;
    gap: 8px;
}
.event-icon {
    color: #666;
    font-weight: bold;
    min-width: 20px;
}
.event-spawn { border-left-color: #4fc3f7; }
.event-spawn .event-icon { color: #4fc3f7; }
.event-death { border-left-color: #f44336; }
.event-death .event-icon { color: #f44336; }
.event-survived { border-left-color: #4caf50; }
.event-survived .event-icon { color: #4caf50; }
.event-perturbation { border-left-color: #ff9800; }
.event-perturbation .event-icon { color: #ff9800; }
.event-layer_advance { border-left-color: #e040fb; }
.event-layer_advance .event-icon { color: #e040fb; }
.event-msg { color: #999; }
.event-empty { color: #444; font-style: italic; padding: 8px; }

/* Batch Controls */
.batch-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.batch-controls button {
    padding: 8px 16px;
    background: #1b5e20;
    color: #81c784;
    border: 1px solid #2e7d32;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s;
}

.batch-controls button:hover {
    background: #2e7d32;
    border-color: #4caf50;
    color: #a5d6a7;
}

.cancel-btn {
    background: #b71c1c !important;
    color: #ef5350 !important;
    border-color: #c62828 !important;
}
.cancel-btn:hover {
    background: #c62828 !important;
    border-color: #f44336 !important;
    color: #ff8a80 !important;
}

.batch-progress-container {
    flex: 1;
    min-width: 200px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-bar {
    flex: 1;
    height: 20px;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #2a2a2a;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4fc3f7, #4caf50);
    transition: width 0.5s ease;
    width: 0%;
    border-radius: 3px;
}

.batch-progress-label {
    font-size: 11px;
    color: #888;
    min-width: 200px;
}

/* Evolution progress fill (purple gradient) */
.evo-fill {
    background: linear-gradient(90deg, #ce93d8, #ab47bc);
}

/* Charts divider */
.charts-divider {
    background: #111;
    border-color: #333;
    text-align: center;
}

.charts-divider h2 {
    color: #4fc3f7;
    font-size: 14px;
    letter-spacing: 3px;
    margin-bottom: 4px;
}

.charts-hint {
    color: #555;
    font-size: 12px;
}

/* Chart panels */
.chart-panel {
    min-height: 250px;
}

.chart-panel canvas {
    background: transparent;
    max-height: 300px;
}

/* Changelog Modal */
.changelog-modal-content {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

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

.changelog-text {
    color: #bbb;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
}

/* Footer */
footer {
    text-align: center;
    padding: 12px;
    color: #444;
    font-size: 11px;
    border-top: 1px solid #1a1a1a;
    display: flex;
    justify-content: center;
    gap: 24px;
}

.footer-version {
    color: #4fc3f7;
    font-weight: bold;
}

/* Terminal toggle button */
.terminal-toggle-btn {
    margin-left: 16px;
    padding: 4px 12px;
    background: #1a1a1a;
    color: #4fc3f7;
    border: 1px solid #333;
    border-radius: 3px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 12px;
}
.terminal-toggle-btn:hover {
    background: #252525;
    border-color: #4fc3f7;
}

/* Terminal Sidebar */
.terminal-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 50%;
    height: 100vh;
    background: #0a0a0a;
    border-left: 1px solid #333;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease;
}
.terminal-sidebar.hidden {
    display: none;
}
.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #111;
    border-bottom: 1px solid #333;
    color: #4fc3f7;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
}
.terminal-close-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    font-family: 'Courier New', monospace;
}
.terminal-close-btn:hover {
    color: #f44336;
}
#terminal-container {
    flex: 1;
    padding: 4px;
    overflow: hidden;
}

/* Login Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal.hidden {
    display: none;
}
.modal-content {
    background: #151515;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 32px;
    min-width: 300px;
    text-align: center;
}
.modal-content h3 {
    color: #4fc3f7;
    margin-bottom: 20px;
    font-size: 16px;
    letter-spacing: 2px;
}
.modal-content input {
    width: 100%;
    padding: 10px 14px;
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #e0e0e0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    margin-bottom: 16px;
    outline: none;
}
.modal-content input:focus {
    border-color: #4fc3f7;
}
.modal-content button {
    width: 100%;
    padding: 10px;
    background: #4fc3f7;
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 13px;
}
.modal-content button:hover {
    background: #81d4fa;
}
.error {
    color: #f44336;
    font-size: 12px;
    margin-top: 12px;
}

@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }
    #timeline-panel,
    .full-width {
        grid-column: 1;
    }
    .terminal-sidebar {
        width: 100%;
    }
    .batch-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .batch-progress-container {
        min-width: unset;
    }
}
