/* --- CONFIGURACIÓ GLOBAL I VARIABLES --- */
:root {
    /* Colors Corporatius / Natura */
    --primary: #059669; /* Verd maragda */
    --primary-hover: #047857;
    --accent: #d97706; /* Carbassa */
    
    /* Colors Carta */
    --fauna-color: #d97706;
    --fauna-bg: #fff7ed;
    --flora-color: #15803d;
    --flora-bg: #f0fdf4;

    /* Tema Clar (Defecte) */
    --bg-body: #f3f4f6;
    --bg-panel: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --input-bg: #f9fafb;
    --input-border: #d1d5db;
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-panel: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --input-bg: #0f172a;
    --input-border: #475569;
    --primary: #34d399;
}

* { box-sizing: border-box; }

body {
    font-family: 'Nunito', sans-serif; /* Font moderna i amable */
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* --- CONTROLS (PANELL ESQUERRE) --- */
.controls {
    width: 420px;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    z-index: 10;
    box-shadow: 5px 0 15px rgba(0,0,0,0.05);
}

.app-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h2 { margin: 0; font-size: 1.4rem; font-weight: 800; color: var(--primary); }

.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Custom Scrollbar */
.scroll-content::-webkit-scrollbar { width: 6px; }
.scroll-content::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 4px; }

/* Formularis Moderns */
.form-group { display: flex; flex-direction: column; gap: 6px; }
label { font-weight: 700; font-size: 0.85em; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

input[type="text"], input[type="number"], select, textarea {
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-main);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95em;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
}

.row { display: flex; gap: 15px; }
.row > div { flex: 1; }

/* Botons i Selectors */
.type-selector {
    display: flex;
    gap: 10px;
    background: var(--input-bg);
    padding: 5px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.type-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    transition: 0.2s;
    font-family: inherit;
    background: transparent;
    color: var(--text-muted);
}
.type-btn:hover { background: rgba(0,0,0,0.05); }
.type-btn.active-fauna { background: var(--fauna-color); color: white; box-shadow: 0 2px 5px rgba(217, 119, 6, 0.4); }
.type-btn.active-flora { background: var(--flora-color); color: white; box-shadow: 0 2px 5px rgba(21, 128, 61, 0.4); }

.settings-row { display: flex; gap: 10px; }
.theme-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}
.theme-btn:hover { background: var(--border-color); }

/* Botó de paperera (Esborrar) - Vermell en hover */
.delete-btn:hover {
    background: #fee2e2;
    color: #ef4444;
    border-color: #ef4444;
}
[data-theme="dark"] .delete-btn:hover {
    background: #451a1a;
}

/* File Input Hack */
.file-input-wrapper { position: relative; overflow: hidden; display: inline-block; width: 100%; }
.file-input-wrapper input[type=file] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.file-custom-label {
    display: block;
    background: var(--input-bg);
    border: 1px dashed var(--input-border);
    padding: 10px;
    text-align: center;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.9em;
    transition: 0.2s;
}
.file-input-wrapper:hover .file-custom-label { border-color: var(--primary); color: var(--primary); }

/* Sliders */
.label-row { display: flex; justify-content: space-between; align-items: center; }
.range-value { background: var(--primary); color: white; padding: 2px 8px; border-radius: 10px; font-size: 0.8em; font-weight: bold; }
input[type=range] { width: 100%; cursor: pointer; accent-color: var(--primary); }

/* Grid d'icones */
.icons-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* Inputs Personalitzats (Ocults per defecte) */
#inp-collection-custom, #inp-sub-custom {
    border: 2px dashed var(--primary);
    background-color: var(--input-bg);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- PREVIEW AREA (DRETA) --- */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-image: radial-gradient(var(--border-color) 2px, transparent 2px);
    background-size: 30px 30px;
    padding: 40px;
    position: relative;
    overflow: hidden;
}

/* --- BARRA D'ACCIONS (BOTONS) --- */
.actions-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
}

.action-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 50px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.action-btn:active { transform: translateY(0); }

/* Botó Descarregar */
.download-btn { background-color: var(--primary); color: white; }
.download-btn:hover { background-color: var(--primary-hover); }

/* Botó Copiar */
.copy-btn { 
    background-color: #ffffff; 
    color: #1f2937; 
    border: 2px solid var(--border-color); 
}
.copy-btn:hover { 
    border-color: var(--primary); 
    background-color: var(--primary);
    color: white; 
}

/* --- CARTA (ESTIL) --- */
.card {
    --card-w: 320px;
    --card-h: 480px;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
    border: 10px solid;
    display: flex;
    flex-direction: column;
    background: white;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.card:hover { transform: translateY(-5px); }

/* Colors dinàmics */
.card[data-type="fauna"] { border-color: var(--fauna-color); background: var(--fauna-bg); }
.card[data-type="flora"] { border-color: var(--flora-color); background: var(--flora-bg); }
.card[data-type="fauna"] .header, .card[data-type="fauna"] .trophic-circle { background-color: var(--fauna-color); }
.card[data-type="flora"] .header, .card[data-type="flora"] .trophic-circle { background-color: var(--flora-color); }

.header {
    color: white;
    padding: 15px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.header .name { font-size: 1.3em; font-weight: 800; text-transform: uppercase; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.header .icon-text { font-size: 0.95em; font-weight: 700; background: rgba(0,0,0,0.1); padding: 2px 8px; border-radius: 12px; }

.image-container {
    height: 190px;
    background-color: #e2e8f0;
    margin: 12px;
    border: 3px solid rgba(255,255,255,0.5);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; position: relative;
    background-size: cover; background-position: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1);
}
.image-placeholder { font-size: 3em; color: #94a3b8; }

.rarity-badge {
    position: absolute; bottom: 8px; right: 8px;
    background: rgba(0,0,0,0.8); color: #fbbf24;
    padding: 4px 10px; border-radius: 6px;
    font-size: 0.9em; font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
}

.stats-container {
    display: flex; justify-content: space-around;
    padding: 5px 0 15px 0;
    align-items: center;
}
.stat-box { text-align: center; width: 30%; }
.stat-label { font-size: 0.7em; text-transform: uppercase; color: #64748b; font-weight: 800; letter-spacing: 0.5px; margin-bottom: 2px; }
.stat-value { font-size: 1.5em; font-weight: 900; color: #334155; }

.trophic-circle {
    width: 40px; height: 40px; border-radius: 50%; color: white;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto; font-weight: 800; font-size: 1.3em;
    border: 3px solid white; box-shadow: 0 4px 6px rgba(0,0,0,0.15);
}

.icons-row { display: flex; justify-content: center; gap: 12px; padding: 5px; }
.icon-badge {
    background: white; width: 36px; height: 36px;
    border-radius: 50%; border: 2px solid #e2e8f0;
    display: flex; align-items: center; justify-content: center;
    color: #475569; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    font-size: 1.1em;
}

.description-box {
    padding: 10px 20px; font-size: 0.9em; font-style: italic;
    color: #4b5563; text-align: center; line-height: 1.4;
    flex-grow: 1; display: flex; align-items: center; justify-content: center;
    font-family: 'Georgia', serif;
}

.card-footer {
    font-size: 0.7em; text-align: right; padding: 6px 15px;
    color: rgba(0,0,0,0.4); font-weight: 800; background: rgba(0,0,0,0.03);
    text-transform: uppercase; letter-spacing: 1px;
}

/* Nivells Tròfics */
.bg-t-1 { background-color: #22c55e !important; } /* Verd */
.bg-t-2 { background-color: #eab308 !important; } /* Groc */
.bg-t-3 { background-color: #f97316 !important; } /* Taronja */
.bg-t-4 { background-color: #ef4444 !important; } /* Vermell */

/* --- PEU DE PÀGINA DE L'APP --- */
.app-footer {
    position: absolute; bottom: 0; width: 100%;
    text-align: center; font-size: 0.75rem;
    padding: 8px; background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
}
.app-footer a { color: var(--text-main); text-decoration: none; font-weight: bold; }

/* Responsive Mobile */
@media (max-width: 850px) {
    body { flex-direction: column; height: auto; overflow: auto; }
    .controls { width: 100%; height: auto; border-right: none; box-shadow: none; }
    .scroll-content { overflow: visible; }
    .preview-area { padding: 40px 10px 80px 10px; }
}
