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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f7fa;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    border: 1px solid #e1e4e8;
}

header {
    background: #24292e;
    color: white;
    padding: 25px 30px;
    text-align: center;
    border-bottom: 2px solid #1a1e22;
}

header h1 {
    font-size: 2em;
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1em;
    opacity: 0.85;
    font-weight: 400;
}

.main-content {
    display: flex;
    gap: 20px;
    padding: 20px;
}

.canvas-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

#gridCanvas {
    border: 1px solid #d1d5da;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    cursor: crosshair;
}

.control-panel {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.section {
    background: #fafbfc;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #e1e4e8;
}

.section h3 {
    color: #24292e;
    margin-bottom: 12px;
    font-size: 0.95em;
    font-weight: 600;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 8px;
}

.mode-buttons {
    display: flex;
    gap: 10px;
}

.mode-btn {
    flex: 1;
    padding: 10px 8px;
    border: 2px solid #0366d6;
    background: white;
    color: #0366d6;
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-btn:hover {
    background: #f0f0f0;
}

.mode-btn.active {
    background: #0366d6;
    color: white;
}

.agent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    max-height: 180px;
    overflow-y: auto;
}

.agent-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: white;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.3s;
}

.agent-item:hover {
    border-color: #0366d6;
}

.agent-item.selected {
    border-color: #0366d6;
    background: #f0f4ff;
}

.agent-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #333;
}

.agent-info {
    flex: 1;
    font-size: 0.9em;
}

.agent-algorithm {
    padding: 2px 8px;
    background: #0366d6;
    color: white;
    border-radius: 4px;
    font-size: 0.8em;
    margin-top: 4px;
    display: inline-block;
}

.agent-status {
    font-size: 0.75em;
    color: #666;
    margin-top: 2px;
}

.agent-metrics {
    margin-top: 6px;
    padding: 6px;
    background: #f0f4ff;
    border-radius: 4px;
    font-size: 0.7em;
    line-height: 1.5;
    color: #333;
}

.agent-metrics div {
    display: flex;
    justify-content: space-between;
}

.delete-agent {
    background: #dc3545;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
}

.delete-agent:hover {
    background: #c82333;
}

.algorithm-select {
    margin-top: 5px;
    padding: 4px;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 0.85em;
}

.scenario-select {
    width: 100%;
    padding: 10px;
    border: 2px solid #0366d6;
    border-radius: 6px;
    font-size: 0.95em;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

.scenario-select:hover {
    border-color: #0366d6;
}

.scenario-select:focus {
    outline: none;
    border-color: #0366d6;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.scenario-desc {
    margin-top: 8px;
    font-size: 0.75em;
    color: #666;
    line-height: 1.3;
    font-style: italic;
    min-height: 30px;
}

.action-btn {
    width: 100%;
    padding: 12px;
    background: #2ea44f;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn:hover {
    background: #2c974b;
}

.control-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.control-btn {
    padding: 10px 8px;
    border: 2px solid #0366d6;
    background: white;
    color: #0366d6;
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s;
}

.control-btn:hover:not(:disabled) {
    background: #0366d6;
    color: white;
}

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

.control-btn.primary {
    background: #2ea44f;
    color: white;
    border-color: #2ea44f;
}

.control-btn.primary:hover:not(:disabled) {
    background: #2c974b;
    border-color: #2c974b;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 15px;
}

#speedSlider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #d3d3d3;
    outline: none;
    -webkit-appearance: none;
}

#speedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0366d6;
    cursor: pointer;
}

#speedSlider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #0366d6;
    cursor: pointer;
    border: none;
}

#speedValue {
    min-width: 40px;
    font-weight: bold;
    color: #0366d6;
}

.stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9em;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
}

.stat-label {
    color: #666;
}

.stat-value {
    font-weight: bold;
    color: #0366d6;
}

.instructions {
    font-size: 0.85em;
    line-height: 1.6;
    color: #555;
}

.instructions p {
    margin-bottom: 10px;
}

.instructions strong {
    color: #333;
}

/* Metrics Panel */
.metrics-panel {
    width: 100%;
    max-width: 800px;
    background: #fafbfc;
    border-radius: 6px;
    padding: 18px;
    border: 1px solid #e1e4e8;
}

.metrics-panel h3 {
    color: #24292e;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 1px solid #e1e4e8;
    padding-bottom: 10px;
}

.metrics-comparison {
    min-height: 100px;
}

.metrics-hint {
    text-align: center;
    color: #999;
    font-style: italic;
    padding: 30px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.metric-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ddd;
}

.metric-agent {
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
}

.metric-algo {
    font-size: 0.85em;
    background: #0366d6;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
}

.metric-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-label {
    font-size: 0.85em;
    color: #666;
    font-weight: 500;
}

.metric-value {
    font-size: 1.1em;
    font-weight: bold;
    color: #333;
}

.metric-value.highlight {
    color: #0366d6;
    font-size: 1.3em;
}

@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }
}
