:root {
    --desert-green: #4b6043;
    --sage: #8da083;
    --sand: #f4e4bc;
    --terracotta: #cc7d5c;
    --dark: #2d3436;
    --gold: #f1c40f;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--sand);
    color: var(--dark);
    margin: 0;
    padding: 20px;
}

header {
    text-align: center;
    padding: 40px 0;
    border-bottom: 3px solid var(--desert-green);
    margin-bottom: 20px;
    position: relative; /* Importante per il logo desktop */
}

h1 {
    color: var(--desert-green);
    font-size: 5.5rem;
    margin: 0;
}

.paragrafi {
    font-size: 1.2rem;
}

#cactus-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); 
    gap: 25px;
    padding: 20px 0;
    max-width: 1200px;
    margin: 0 auto;
}

.card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.card img {
    width: 100%;
    height: 250px;
    object-fit: cover;
    cursor: pointer;
}

.card-content {
    padding: 20px;
}

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

.badge {
    background: var(--sage);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
}

.tag-tipo {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: bold;
    color: var(--desert-green);
    border: 1px solid var(--desert-green);
    padding: 2px 8px;
    border-radius: 5px;
}

h3 {
    margin: 10px 0;
    color: var(--terracotta);
}

.difficulty {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #eee;
    font-size: 0.85rem;
    font-weight: bold;
}

.stars {
    color: var(--gold);
    margin-left: 5px;
}

/* Stili del Popup (Modal) */
.modal {
    border: none;
    padding: 0;
    border-radius: 15px;
    background: transparent;
    max-width: 90vw;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 15px;
    border-radius: 15px;
    position: relative;
}

.modal-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 10px;
    display: block;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2.5rem;
    color: var(--terracotta);
    cursor: pointer;
    line-height: 1;
}

/* Sezione Download */
.download-section {
    text-align: center;
    padding: 60px 20px;
    background-color: var(--sage);
    color: white;
    margin-top: 50px;
    border-radius: 15px;
}

.btn-download {
    background-color: var(--terracotta);
    color: white;
    text-decoration: none;
    padding: 15px 25px;
    border-radius: 8px;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    margin: 10px;
    transition: transform 0.2s;
}

.btn-download:hover { transform: scale(1.05); }

/* Filtri / Controls */
.controls {
    max-width: 1200px;
    margin: 20px auto;
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    position: sticky;
    top: 10px; /* Distanza dal bordo superiore */
    z-index: 1000; /* Assicura che stia sopra le card */
}

.filter-group label {
    font-weight: bold;
    margin-right: 10px;
    color: var(--desert-green);
}

.filter-group select {
    padding: 8px;
    border-radius: 5px;
    border: 1px solid var(--sage);
}

/* Nuove Info Famiglia e Origine */
.extra-info {
    font-size: 0.85rem;
    background: #f9f9f9;
    padding: 10px;
    border-radius: 8px;
    margin: 10px 0;
    border-left: 4px solid var(--sage);
}

.extra-info p { margin: 3px 0; }

/* Logo GitHub Desktop */
.github-profile {
    position: absolute;
    top: 20px;
    right: 20px;
    transition: transform 0.3s ease;
}

.github-profile img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid var(--desert-green);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.github-profile:hover {
    transform: scale(1.1);
}

/* Pulsante Torna in Cima */
#backToTop {
    display: none;
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 99;
    background-color: var(--terracotta);
    color: white;
    border: none;
    outline: none;
    width: 50px;
    height: 50px;
    cursor: pointer;
    border-radius: 50%;
    font-size: 24px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    transition: opacity 0.3s, transform 0.3s;
}

/* ============================================================
   AGGIUNTE: BARRA DI RICERCA (PC & Mobile)
   ============================================================ */
.search-box {
    flex: 1; 
    min-width: 250px;
}

#search-input {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid var(--sage);
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

#search-input:focus {
    border-color: var(--terracotta);
}

@media (min-width: 601px) {
    .search-box {
        flex: 0 1 600px; /* Lunghezza controllata su PC */
        margin-right: auto; /* Allinea a sinistra spingendo i filtri a destra */
    }
}

/* ============================================================
   RESPONSIVE: MOBILE (Sotto 600px)
   ============================================================ */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    /* Barra Titolo + Logo Mobile */
    header {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        padding: 15px;
        background-color: white;
        border-radius: 12px;
        box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    }

    /* Elemento invisibile per bilanciare il logo e centrare il titolo */
    header::before {
        content: "";
        width: 50px;
        order: 1;
    }

    h1 {
        font-size: 1.3rem !important;
        margin: 0;
        text-align: center;
        order: 2;
        flex: 1;
    }

    .github-profile {
        position: static !important;
        margin: 0;
        order: 3;
        width: 50px;
        display: flex;
        justify-content: flex-end;
    }

    .github-profile img {
        width: 50px !important;
        height: 50px !important;
        border-width: 2px;
    }

    /* Descrizione e contatore sotto la barra */
    header p {
        width: 100%;
        font-size: 0.85rem;
        margin: 10px 0 0 0;
        text-align: center;
        order: 4;
    }

    /* Controlli Filtri Mobile */
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .search-box {
        width: 100%;
        order: -1; /* Ricerca sempre in alto nei filtri */
    }

    .filter-group {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .filter-group select {
        width: 60%;
    }

    /* Ripristino Grid Card Mobile (come l'originale) */
    #cactus-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .card img {
        height: 200px;
    }
    
    .card-content h3 {
        font-size: 1.2rem;
    }
}