/* ============================================
   EvolutionAI — Stylesheet
   ============================================ */

:root {
    --bg:        #0a0e17;
    --surface:   #111827;
    --surface2:  #1e293b;
    --border:    #1e3a5f;
    --text:      #e2e8f0;
    --text-dim:  #94a3b8;
    --accent:    #4ade80;
    --accent2:   #22d3ee;
    --danger:    #f87171;
    --warning:   #fbbf24;
    --purple:    #a78bfa;
    --radius:    8px;
    --font:      'Inter', system-ui, sans-serif;
    --mono:      'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    min-height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
header {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-weight: 300;
}

/* Main Layout */
.main-layout {
    display: grid;
    grid-template-columns: 260px 1fr 300px;
    flex: 1;
    gap: 0;
    overflow: hidden;
}

/* Panels */
.panel {
    padding: 16px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.data-panel {
    border-right: none;
    border-left: 1px solid var(--border);
}

.panel h2 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--accent);
    margin: 16px 0 10px;
    font-weight: 600;
}

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

/* Controls */
.control-group {
    margin-bottom: 14px;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.val {
    color: var(--accent);
    font-family: var(--mono);
    font-weight: 500;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-dim);
    opacity: 0.6;
    margin-top: 2px;
}

select {
    width: 100%;
    padding: 6px 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    outline: none;
}

select:focus { border-color: var(--accent); }

/* Buttons */
.btn-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface2);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary {
    background: var(--accent);
    color: #0a0e17;
    border-color: var(--accent);
    font-weight: 600;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.events-row { margin-top: 6px; }

.btn-event {
    font-size: 0.7rem;
    padding: 5px 10px;
    border-color: var(--warning);
    color: var(--warning);
}

.btn-event:hover {
    background: var(--warning);
    color: #000;
}

.btn-event.active-event {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    animation: pulse-event 1s infinite;
}

@keyframes pulse-event {
    0%, 100% { box-shadow: 0 0 4px rgba(248, 113, 113, 0.4); }
    50% { box-shadow: 0 0 12px rgba(248, 113, 113, 0.8); }
}

/* Simulation Area */
.simulation-area {
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    overflow: hidden;
}

.canvas-wrapper {
    position: relative;
    flex: 1;
    min-height: 400px;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

#world-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.gen-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-dim);
    background: rgba(10, 14, 23, 0.8);
    padding: 6px 12px;
    border-radius: var(--radius);
    backdrop-filter: blur(8px);
}

.gen-overlay strong {
    color: var(--accent);
    font-family: var(--mono);
}

/* Theory Cards */
.theory-cards {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.card {
    flex: 1;
    min-width: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: default;
    transition: all 0.3s;
    position: relative;
}

.card h3 {
    font-size: 0.78rem;
    margin-bottom: 4px;
    color: var(--text);
}

.card p {
    font-size: 0.65rem;
    color: var(--text-dim);
    line-height: 1.4;
}

.card.active {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.15);
}

.card.highlight-selection { border-color: var(--accent); box-shadow: 0 0 16px rgba(74, 222, 128, 0.3); }
.card.highlight-mutation  { border-color: var(--purple); box-shadow: 0 0 16px rgba(167, 139, 250, 0.3); }
.card.highlight-drift     { border-color: var(--warning); box-shadow: 0 0 16px rgba(251, 191, 36, 0.3); }
.card.highlight-speciation { border-color: var(--accent2); box-shadow: 0 0 16px rgba(34, 211, 238, 0.3); }
.card.highlight-adaptation { border-color: #f472b6; box-shadow: 0 0 16px rgba(244, 114, 182, 0.3); }

.card-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--surface2);
    transition: background 0.3s;
}

.card-indicator.active {
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 2px currentColor; }
    50% { box-shadow: 0 0 8px currentColor; }
}

/* Charts */
.data-panel canvas {
    width: 100%;
    background: var(--surface2);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

/* Phylo tree */
.phylo-container {
    background: var(--surface2);
    border-radius: var(--radius);
    padding: 10px;
    min-height: 120px;
    font-family: var(--mono);
    font-size: 0.65rem;
    color: var(--text-dim);
    overflow: hidden;
    margin-bottom: 12px;
}

.phylo-node {
    padding-left: 14px;
    border-left: 1px solid var(--border);
    margin: 2px 0;
    line-height: 1.6;
}

.phylo-node .species-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.phylo-node.extinct { opacity: 0.4; text-decoration: line-through; }

/* Event log */
.event-log {
    background: var(--surface2);
    border-radius: var(--radius);
    padding: 10px;
    max-height: 180px;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: 0.65rem;
    line-height: 1.8;
}

.event-log .log-entry {
    color: var(--text-dim);
    border-bottom: 1px solid rgba(255,255,255,0.03);
    padding: 2px 0;
}

.log-entry .gen-tag {
    color: var(--accent);
    margin-right: 6px;
}

.log-entry.event-extinction { color: var(--danger); }
.log-entry.event-speciation { color: var(--accent2); }
.log-entry.event-adaptation { color: #f472b6; }
.log-entry.event-catastrophe { color: var(--warning); }
.log-entry.event-mutation { color: var(--purple); }

/* Canvas overlays for events */
.canvas-wrapper .event-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.event-flash.meteor   { background: radial-gradient(circle at 60% 30%, rgba(248,113,113,0.5), transparent 70%); }
.event-flash.ice-age  { background: linear-gradient(180deg, rgba(147,197,253,0.4), transparent); }
.event-flash.plague    { background: radial-gradient(circle, rgba(74,222,128,0.3), transparent 70%); }
.event-flash.radiation { background: radial-gradient(circle, rgba(167,139,250,0.4), transparent 60%); }

.event-flash.show { opacity: 1; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Responsive */
@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    .panel { border: none; border-bottom: 1px solid var(--border); }
    .data-panel { border-top: 1px solid var(--border); border-bottom: none; }
    .controls-panel {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0 16px;
    }
    .controls-panel h2 { grid-column: 1 / -1; }
}
