/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-dark: #0a1628;
    --bg-panel: #121e36;
    --bg-card: #1a2a4a;
    --bg-canvas: #0d1a2f;
    --text-primary: #e0e8f0;
    --text-secondary: #8899aa;
    --text-muted: #556677;
    --accent: #00c8ff;
    --accent-glow: rgba(0, 200, 255, 0.3);
    --health-low: #ff4444;
    --health-mid: #ffaa00;
    --health-high: #44dd44;
    --tier-locked: #333;
    --border: #1e3050;
    --radius: 8px;
    --radius-lg: 12px;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
}

.hidden { display: none !important; }

/* === Ecosystem Picker === */
.picker-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    z-index: 100;
}

.picker-content {
    text-align: center;
    max-width: 700px;
    padding: 40px;
}

.picker-content h1 {
    font-size: 3rem;
    font-weight: 300;
    letter-spacing: 4px;
    color: var(--accent);
    margin-bottom: 8px;
}

.picker-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 40px;
}

.ecosystem-cards {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
}

.ecosystem-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 30px 24px;
    width: 280px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.ecosystem-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 30px rgba(0, 200, 255, 0.15);
}

.ecosystem-card h3 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.ecosystem-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.4;
}

.ecosystem-card .difficulty {
    display: inline-block;
    margin-top: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.difficulty-beginner { background: rgba(68, 221, 68, 0.15); color: #44dd44; }
.difficulty-intermediate { background: rgba(255, 170, 0, 0.15); color: #ffaa00; }
.difficulty-advanced { background: rgba(255, 68, 68, 0.15); color: #ff4444; }

/* === Game Layout === */
.game-ui {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    height: 60px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.game-title {
    font-size: 1.2rem;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--accent);
}

.ecosystem-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: var(--bg-card);
    padding: 4px 12px;
    border-radius: 20px;
}

.header-center {
    flex: 1;
    max-width: 400px;
    margin: 0 30px;
}

.health-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.health-bar-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.health-bar-track {
    flex: 1;
    height: 10px;
    background: var(--bg-dark);
    border-radius: 5px;
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    border-radius: 5px;
    background: var(--health-high);
    transition: width 0.5s ease, background-color 0.5s ease;
}

.health-bar-value {
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}

.header-right {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.btn:hover {
    background: var(--bg-panel);
    color: var(--text-primary);
}

/* Body (palette + canvas) */
.game-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Palette sidebar */
.palette {
    width: 240px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px;
}

.palette-title {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 16px;
}

.palette-tier {
    margin-bottom: 20px;
}

.tier-header {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tier-locked-badge {
    font-size: 0.65rem;
    color: var(--tier-locked);
    background: rgba(255,255,255,0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

.palette-element {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 4px;
    border-radius: var(--radius);
    cursor: grab;
    transition: background 0.15s;
    user-select: none;
}

.palette-element:hover {
    background: var(--bg-card);
}

.palette-element:active {
    cursor: grabbing;
}

.palette-element.locked {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.palette-element.maxed {
    opacity: 0.4;
    cursor: not-allowed;
}

.palette-element.selected {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
}

.palette-element .el-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.palette-element .el-info {
    flex: 1;
    min-width: 0;
}

.palette-element .el-name {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.palette-element .el-count {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Canvas */
.canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.canvas-drop-zone {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.canvas-drop-zone.drag-over {
    background: rgba(0, 200, 255, 0.03);
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
}

.canvas-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 1rem;
    text-align: center;
    pointer-events: none;
}

/* Placed elements on canvas */
.canvas-element {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: grab;
    user-select: none;
    transition: opacity 0.5s, filter 0.5s, transform 0.3s;
}

.canvas-element:active { cursor: grabbing; }

.canvas-element .el-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    position: relative;
}

.canvas-element .el-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: center;
    white-space: nowrap;
}

.canvas-element .el-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ff4444;
    color: white;
    font-size: 12px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.canvas-element:hover .el-remove { opacity: 1; }

/* Health states */
.canvas-element.thriving {
    opacity: 1;
    filter: none;
    animation: pulse 3s infinite ease-in-out;
}

.canvas-element.thriving .el-icon {
    box-shadow: 0 0 12px rgba(68, 221, 68, 0.3);
}

.canvas-element.struggling {
    opacity: 0.7;
    filter: saturate(0.5) brightness(0.9);
}

.canvas-element.struggling .el-icon {
    box-shadow: 0 0 12px rgba(255, 170, 0, 0.3);
}

.canvas-element.dying {
    opacity: 0.4;
    filter: grayscale(0.8) brightness(0.7);
    animation: wither 2s infinite ease-in-out;
}

.canvas-element.dying .el-icon {
    box-shadow: 0 0 12px rgba(255, 68, 68, 0.3);
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

@keyframes wither {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(-2deg) scale(0.96); }
}

/* Info panel */
.info-panel {
    padding: 10px 20px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    min-height: 44px;
    flex-shrink: 0;
}

.info-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.info-text strong {
    color: var(--text-primary);
}

.info-text .fact {
    color: var(--accent);
    font-style: italic;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--text-primary);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    animation: toastIn 0.3s ease-out;
    max-width: 340px;
}

.toast.toast-success { border-left: 3px solid var(--health-high); }
.toast.toast-warning { border-left: 3px solid var(--health-mid); }
.toast.toast-danger  { border-left: 3px solid var(--health-low); }
.toast.toast-info    { border-left: 3px solid var(--accent); }

.toast.fade-out { animation: toastOut 0.3s ease-in forwards; }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(100%); opacity: 0; }
}

/* === Scrollbar styling === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
