/* VARIABILI GLOBALI (Stile Istituzionale Elegante) */
:root {
    --bg-color: #f8fafc;
    --text-color: #1e293b;
    --text-light: #64748b;
    
    --primary: #0f172a; /* Blu profondo / Grafite */
    --primary-light: #334155;
    --accent: #d97706; /* Ambra acceso per richiamare la luce dell'intelletto */
    --accent-hover: #b45309;
    
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    
    --font-title: 'Merriweather', serif;
    --font-main: 'Inter', sans-serif;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    
    --radius-md: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

h1, h2, h3, h4, h5 {
    font-family: var(--font-title);
    color: var(--primary);
    line-height: 1.3;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-hover); }

/* CONTENITORI E UTILITY */
.container { max-width: 1200px; margin: 0 auto; padding: 0 2rem; position: relative; z-index: 10; }
.bg-light { background-color: #f1f5f9; }
.section-title { font-size: 2rem; margin-bottom: 2rem; border-bottom: 2px solid var(--border-color); padding-bottom: 0.5rem; }

/* HEADER */
.site-header { background: var(--card-bg); border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm); }
.header-container { display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; }
.logo { font-family: var(--font-title); font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.logo span { color: var(--accent); font-style: italic; }

.main-nav { display: flex; gap: 1.5rem; }
.nav-link { color: var(--text-light); font-weight: 500; padding: 0.5rem 0; position: relative; }
.nav-link:hover, .nav-link.active { color: var(--primary); }
.nav-link.active::after { content: ''; position: absolute; bottom: 0; left: 0; width: 100%; height: 2px; background: var(--accent); }

/* BOTTONI */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.75rem 1.5rem; font-weight: 600; border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s; border: none; font-size: 1rem; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-light); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.secondary:hover { background: #f8fafc; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-hover); }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.btn.outline-accent { border: 1px solid var(--accent); color: var(--accent); background: transparent; }
.btn.outline-accent:hover { background: var(--accent); color: #fff; }

/* HERO SECTION */
.hero { position: relative; padding: 5rem 0; background-color: var(--primary); color: #fff; overflow: hidden; }
.hero-bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0.1; background-image: radial-gradient(circle at 20% 50%, rgba(255,255,255,0.8) 0%, transparent 50%); }
.hero-content { max-width: 800px; }
.hero .title { color: #fff; font-size: 3.5rem; margin-bottom: 1.5rem; }
.hero .subtitle { font-size: 1.4rem; color: #cbd5e1; margin-bottom: 1.5rem; font-family: var(--font-title); font-style: italic; }
.hero .intro { font-size: 1.1rem; color: #94a3b8; margin-bottom: 2.5rem; }
.hero-buttons { display: flex; gap: 1rem; }
.hero-buttons .btn.primary { background: var(--accent); color: #fff; }
.hero-buttons .btn.primary:hover { background: var(--accent-hover); }
.hero-buttons .btn.secondary { border-color: rgba(255,255,255,0.5); color: #fff; background: transparent; }
.hero-buttons .btn.secondary:hover { background: rgba(255,255,255,0.1); border-color: #fff; }

/* SEARCH AND FILTERS */
.search-section { padding: 3rem 0; background: #fff; border-bottom: 1px solid var(--border-color); }
.search-bar-wrapper { position: relative; max-width: 800px; margin: 0 auto 2rem auto; }
.search-icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); font-size: 1.2rem; opacity: 0.5; }
#search-input { width: 100%; padding: 1.2rem 1rem 1.2rem 3rem; font-size: 1.1rem; border: 2px solid var(--border-color); border-radius: var(--radius-lg); outline: none; transition: border-color 0.2s; font-family: var(--font-main); }
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.1); }

.filters-wrapper { max-width: 1000px; margin: 0 auto; text-align: center; }
.filters-label { font-weight: 600; color: var(--text-light); margin-bottom: 0.5rem; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; }
.category-filters { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.filter-chip { padding: 0.4rem 1rem; background: var(--bg-color); border: 1px solid var(--border-color); border-radius: 20px; font-size: 0.9rem; cursor: pointer; transition: all 0.2s; color: var(--text-light); }
.filter-chip:hover { background: #e2e8f0; color: var(--text-color); }
.filter-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* VIEWS */
.view-section { display: none; padding: 4rem 0; min-height: 50vh; }
.view-section.active { display: block; }

/* LIBRERIA (SCAFFALE) */
.results-info { margin-bottom: 1.5rem; color: var(--text-light); font-size: 0.95rem; }

.bookshelf {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 20px;
    /* Sfondo a righe: muro + mensola */
    background-image: 
        linear-gradient(to bottom, transparent 270px, #5c4033 270px, #3e2723 290px),
        linear-gradient(to right, #f8fafc, #e2e8f0); /* Muro chiaro */
    background-size: 100% 290px, 100% 100%;
    border: 15px solid #4a332a;
    border-bottom: 30px solid #3e2723;
    border-radius: 8px;
    box-shadow: inset 0 10px 20px rgba(0,0,0,0.2), 0 15px 30px rgba(0,0,0,0.3);
    min-height: 610px; /* Almeno 2 mensole intere + bordi */
}

.book-on-shelf {
    width: 140px;
    height: 220px;
    margin: 50px 15px 20px 15px; /* 50 + 220 + 20 = 290px esatti per mensola */
    position: relative;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: -5px 5px 15px rgba(0,0,0,0.4);
    transform-origin: bottom center;
}

.book-on-shelf:hover {
    transform: translateY(-15px) scale(1.05) rotateZ(2deg);
    z-index: 10;
}

.book-on-shelf img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 3px 6px 6px 3px;
    /* Effetto costina del libro */
    border-left: 5px solid rgba(255,255,255,0.4);
    box-shadow: inset 2px 0 5px rgba(0,0,0,0.3);
}

.book-title-tooltip {
    position: absolute;
    top: -45px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 20;
    box-shadow: var(--shadow-md);
    font-weight: 600;
}
.book-title-tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px 5px 0;
    border-style: solid;
    border-color: var(--primary) transparent transparent transparent;
}

.book-on-shelf:hover .book-title-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* VISTA AUTORI */
.authors-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2rem; }
.author-card { background: var(--card-bg); border-radius: var(--radius-lg); padding: 2rem; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; text-align: center; }
.author-avatar { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; margin-bottom: 1rem; border: 3px solid var(--bg-color); box-shadow: 0 0 0 1px var(--border-color); filter: grayscale(50%); }
.author-name { font-size: 1.3rem; margin-bottom: 0.5rem; }
.author-stats { font-size: 0.85rem; color: var(--accent); font-weight: 600; text-transform: uppercase; margin-bottom: 1rem; }
.author-books { font-size: 0.9rem; color: var(--text-light); text-align: left; width: 100%; border-top: 1px solid var(--border-color); padding-top: 1rem; }
.author-books ul { list-style: none; }
.author-books li { margin-bottom: 0.5rem; }
.author-books a { color: var(--primary); font-weight: 500; }
.author-books a:hover { color: var(--accent); text-decoration: underline; }

/* ISTRUZIONI */
.how-to-use { padding: 4rem 0; }
.instructions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 2rem; }
.instruction-card { background: #fff; padding: 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); }
.instruction-card h3 { font-size: 1.2rem; margin-bottom: 1rem; font-family: var(--font-main); }

/* FOOTER */
.site-footer { background: var(--card-bg); padding: 3rem 0; border-top: 1px solid var(--border-color); text-align: center; color: var(--text-light); font-size: 0.95rem; }
.site-footer a { color: var(--primary); font-weight: 600; }

/* MODALE DETTAGLIO LIBRO */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(15, 23, 42, 0.8); backdrop-filter: blur(5px); z-index: 1000; display: flex; justify-content: center; align-items: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-content { background: var(--card-bg); width: 100%; max-width: 800px; max-height: 90vh; overflow-y: auto; border-radius: var(--radius-lg); position: relative; box-shadow: var(--shadow-lg); transform: translateY(20px); transition: transform 0.3s; }
.modal-overlay.open .modal-content { transform: translateY(0); }
.modal-close { position: absolute; top: 1rem; right: 1rem; background: #f1f5f9; border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 1.5rem; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-light); transition: all 0.2s; z-index: 10; }
.modal-close:hover { background: #e2e8f0; color: var(--text-color); }

.modal-body { padding: 3rem; }
.modal-header { display: flex; gap: 2rem; margin-bottom: 2rem; border-bottom: 1px solid var(--border-color); padding-bottom: 2rem; }
.modal-cover { width: 180px; flex-shrink: 0; border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.modal-info h2 { font-size: 2.2rem; margin-bottom: 0.5rem; }
.modal-author { font-size: 1.2rem; color: var(--text-light); font-family: var(--font-title); font-style: italic; margin-bottom: 1rem; }
.modal-meta { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; font-size: 0.9rem; color: var(--text-light); }
.modal-meta span { background: #f1f5f9; padding: 0.3rem 0.8rem; border-radius: 4px; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.modal-tag { font-size: 0.8rem; background: rgba(217, 119, 6, 0.1); color: var(--accent); padding: 0.2rem 0.6rem; border-radius: 12px; }

.modal-desc { margin-bottom: 2rem; }
.modal-desc h3 { font-size: 1.2rem; margin-bottom: 1rem; font-family: var(--font-main); }
.modal-actions { display: flex; gap: 1rem; }

/* RESPONSIVE */
@media (max-width: 768px) {
    .hero .title { font-size: 2.5rem; }
    .hero-layout { grid-template-columns: 1fr; }
    .modal-header { flex-direction: column; }
    .modal-cover { width: 140px; margin: 0 auto; }
    .modal-info { text-align: center; }
    .modal-meta { justify-content: center; }
    .modal-tags { justify-content: center; }
    .modal-actions { flex-direction: column; }
    .modal-body { padding: 1.5rem; }
}
