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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #8b7355;
    --accent-color: #c9a961;
    --text-dark: #2c3e50;
    --text-light: #6c757d;
    --bg-cream: #faf8f3;
    --bg-white: #ffffff;
    --border-color: #e5e5e5;
    --shadow-light: rgba(0, 0, 0, 0.05);
    --shadow-medium: rgba(0, 0, 0, 0.1);
    --shadow-heavy: rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Lato', sans-serif;
    background: var(--bg-cream);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden;
}

body.popup-open {
    overflow: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: 0 10px 40px var(--shadow-medium);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #34495e 100%);
    color: white;
    padding: 60px 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.03)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.03)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.3;
}

.header-content {
    position: relative;
    z-index: 1;
}

.ornament-top, .ornament-bottom {
    width: 100px;
    height: 2px;
    background: var(--accent-color);
    margin: 20px auto;
    position: relative;
}

.ornament-top::before, .ornament-top::after,
.ornament-bottom::before, .ornament-bottom::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
    top: -3px;
}

.ornament-top::before {
    left: 20px;
}

.ornament-top::after {
    right: 20px;
}

.ornament-bottom::before {
    left: 20px;
}

.ornament-bottom::after {
    right: 20px;
}

.main-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 4em;
    font-weight: 400;
    margin: 20px 0 10px;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.subtitle {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.4em;
    font-style: italic;
    opacity: 0.95;
    letter-spacing: 2px;
    font-weight: 300;
}

/* Sezione Introduttiva */
.intro-section {
    background: var(--bg-cream);
    padding: 50px 40px;
    border-bottom: 1px solid var(--border-color);
}

.intro-content {
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

.intro-text {
    font-size: 1.1em;
    color: var(--text-light);
    line-height: 1.8;
    margin-bottom: 30px;
    font-weight: 300;
}

.intro-quote {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.6em;
    font-style: italic;
    color: var(--secondary-color);
    border-left: 3px solid var(--accent-color);
    padding-left: 30px;
    text-align: left;
    max-width: 600px;
    margin: 0 auto;
}

.main-content {
    padding: 40px;
}

/* Titoli delle Sezioni */
.section-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 2em;
    color: var(--primary-color);
    margin-bottom: 25px;
    display: flex;
    align-items: center;
    gap: 15px;
    font-weight: 500;
}

.title-icon {
    font-size: 0.8em;
    opacity: 0.7;
}

/* Sezione Ricerca */
.search-section {
    margin-bottom: 40px;
    padding: 35px;
    background: var(--bg-cream);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 25px;
}

#searchInput {
    flex: 1;
    padding: 16px 24px;
    font-size: 16px;
    font-family: 'Lato', sans-serif;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    outline: none;
    transition: all 0.3s ease;
    background: white;
}

#searchInput:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.1);
}

#searchBtn {
    padding: 16px 35px;
    font-size: 16px;
    font-family: 'Lato', sans-serif;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

#searchBtn:hover {
    background: #34495e;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-medium);
}

#searchBtn:active {
    transform: translateY(0);
}

.search-results {
    margin-top: 25px;
}

.result-item {
    background: white;
    padding: 25px;
    margin-bottom: 15px;
    border-radius: 6px;
    border-left: 4px solid var(--accent-color);
    box-shadow: 0 2px 8px var(--shadow-light);
    transition: transform 0.2s, box-shadow 0.2s;
}

.result-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.result-item h3 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.5em;
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 500;
}

.occurrence {
    padding: 12px 15px;
    margin: 8px 0;
    background: var(--bg-cream);
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.6;
    border-left: 2px solid var(--border-color);
    transition: all 0.2s ease;
}

.clickable-occurrence {
    border-left: 3px solid var(--accent-color);
}

.clickable-occurrence:hover {
    transform: translateX(3px);
    box-shadow: 0 2px 8px var(--shadow-light);
    background: #f0f0f0;
}

.occurrence .line-number {
    color: var(--secondary-color);
    font-weight: 600;
    margin-right: 12px;
    font-size: 0.9em;
}

.highlight {
    background: linear-gradient(120deg, #fff3cd 0%, #ffe69c 100%);
    padding: 2px 6px;
    font-weight: 600;
    border-radius: 3px;
    color: var(--primary-color);
}

.load-more-occurrences {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Lato', sans-serif;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.load-more-occurrences:hover {
    background: #b89a5f;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.load-more-occurrences:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Selettore PDF */
.pdf-selector {
    margin-bottom: 40px;
    padding: 35px;
    background: var(--bg-cream);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.selector-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

#pdfSelect {
    flex: 1;
    padding: 16px 20px;
    font-size: 16px;
    font-family: 'Lato', sans-serif;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    outline: none;
    background: white;
    min-width: 250px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#pdfSelect:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.1);
}

#loadPdfBtn {
    padding: 16px 35px;
    font-size: 16px;
    font-family: 'Lato', sans-serif;
    font-weight: 600;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
}

#loadPdfBtn:hover {
    background: #34495e;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-medium);
}

/* Visualizzatore PDF */
.pdf-viewer-section {
    margin-top: 40px;
}

.pdf-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 20px 25px;
    background: var(--bg-cream);
    border-radius: 8px 8px 0 0;
    flex-wrap: wrap;
    border: 1px solid var(--border-color);
    border-bottom: none;
}

.pdf-controls button {
    padding: 10px 20px;
    font-size: 14px;
    font-family: 'Lato', sans-serif;
    font-weight: 500;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pdf-controls button:hover:not(:disabled) {
    background: #34495e;
    transform: translateY(-1px);
}

.pdf-controls button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.6;
}

.page-info-wrapper {
    margin: 0 15px;
    padding: 10px 20px;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

#pageInfo {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 14px;
}

.page-jump {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

#pageInput {
    width: 80px;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    text-align: center;
    font-family: 'Lato', sans-serif;
    font-size: 14px;
    transition: all 0.3s ease;
}

#pageInput:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.1);
}

.zoom-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: 15px;
    padding: 0 10px;
    border-left: 1px solid var(--border-color);
}

.zoom-controls button {
    padding: 8px 12px;
    font-size: 18px;
    font-weight: 600;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.zoom-controls button:hover:not(:disabled) {
    background: #34495e;
    transform: translateY(-1px);
}

.zoom-controls button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.6;
}

.zoom-controls button:active:not(:disabled) {
    transform: translateY(0);
}

.zoom-level {
    min-width: 55px;
    text-align: center;
    font-weight: 600;
    color: var(--primary-color);
    font-size: 14px;
    font-family: 'Lato', sans-serif;
}

.pdf-container {
    background: #e8e8e8;
    min-height: 700px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px;
    border-radius: 0 0 8px 8px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-top: none;
}

.pdf-container canvas {
    max-width: 100%;
    height: auto;
    box-shadow: 0 8px 30px var(--shadow-heavy);
    background: white;
    border-radius: 4px;
}

.placeholder-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-height: 500px;
}

.book-icon {
    font-size: 5em;
    opacity: 0.3;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
}

.placeholder {
    text-align: center;
    color: var(--text-light);
    font-size: 1.2em;
    font-style: italic;
    font-family: 'Cormorant Garamond', serif;
}

.loading {
    text-align: center;
    color: var(--secondary-color);
    font-size: 1.1em;
    font-style: italic;
}

/* Responsive */
@media (max-width: 768px) {
    .main-title {
        font-size: 2.5em;
        letter-spacing: 2px;
    }
    
    .subtitle {
        font-size: 1.1em;
    }
    
    header {
        padding: 40px 20px;
    }
    
    .intro-section {
        padding: 30px 20px;
    }
    
    .intro-quote {
        font-size: 1.3em;
        padding-left: 20px;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .search-section,
    .pdf-selector {
        padding: 20px;
    }
    
    .section-title {
        font-size: 1.6em;
    }
    
    .search-box {
        flex-direction: column;
    }
    
    .selector-wrapper {
        flex-direction: column;
        align-items: stretch;
    }
    
    #pdfSelect {
        width: 100%;
    }
    
    .pdf-controls {
        justify-content: center;
        padding: 15px;
    }
    
    .page-jump {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }
    
    .zoom-controls {
        margin-left: 0;
        margin-top: 10px;
        width: 100%;
        justify-content: center;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding-top: 10px;
        padding-left: 0;
    }
    
    .pdf-container {
        padding: 20px;
        min-height: 500px;
    }
    
    .pdf-container canvas {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Popup Fullscreen */
.intro-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.95);
    backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    overflow-y: auto;
    padding: 20px;
}

.intro-popup.active {
    opacity: 1;
    visibility: visible;
}

.popup-content {
    background: var(--bg-white);
    border-radius: 12px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: popupFadeIn 0.6s ease-out;
    display: flex;
    flex-direction: column;
}

.popup-content > .popup-image-container {
    order: -1;
    flex-shrink: 0;
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.popup-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 28px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.popup-close:hover {
    background: #34495e;
    transform: rotate(90deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.popup-image-container {
    width: 100%;
    height: 800px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    background: linear-gradient(135deg, var(--bg-cream) 0%, #f5f3ef 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    position: relative;
    margin: 0;
    flex-shrink: 0;
}

.popup-image-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="0.5" fill="rgba(0,0,0,0.02)"/><circle cx="75" cy="75" r="0.5" fill="rgba(0,0,0,0.02)"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
    opacity: 0.15;
    pointer-events: none;
    z-index: 1;
}

.popup-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

#popupImage {
    height: 800px;
}

.popup-text-container {
    padding: 40px;
    flex: 1;
}

.popup-text {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.3em;
    line-height: 1.8;
    color: var(--text-dark);
    text-align: center;
}

.popup-text h2 {
    font-family: 'Cormorant Garamond', serif;
    font-size: 2em;
    color: var(--primary-color);
    margin-bottom: 20px;
    font-weight: 500;
}

.popup-text p {
    margin-bottom: 15px;
}

.popup-text p:last-child {
    margin-bottom: 0;
}

/* Responsive per popup */
@media (max-width: 768px) {
    .popup-content {
        max-width: 95%;
        max-height: 95vh;
    }
    
    .popup-image-container {
        height: 400px;
    }
    
    .popup-image {
        width: 100%;
        max-height: 400px;
    }
    
    .popup-text-container {
        padding: 25px;
    }
    
    .popup-text {
        font-size: 1.1em;
    }
    
    .popup-text h2 {
        font-size: 1.6em;
    }
    
    .popup-close {
        width: 35px;
        height: 35px;
        font-size: 24px;
        top: 10px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .main-title {
        font-size: 2em;
    }
    
    .pdf-controls button {
        font-size: 12px;
        padding: 8px 12px;
    }
    
    .pdf-controls button span:not(:first-child):not(:last-child) {
        display: none;
    }
    
    .zoom-controls {
        margin-top: 8px;
        padding-top: 8px;
    }
    
    .zoom-controls button {
        min-width: 32px;
        height: 32px;
        font-size: 16px;
        padding: 6px 10px;
    }
    
    .zoom-level {
        min-width: 45px;
        font-size: 12px;
    }
    
    .pdf-container {
        padding: 10px;
        min-height: 400px;
    }
    
    .pdf-container canvas {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .popup-text-container {
        padding: 20px;
    }
    
    .popup-text {
        font-size: 1em;
    }
    
    .popup-text h2 {
        font-size: 1.4em;
    }
}

.close-btn-bottom {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 1.1em;
    border-radius: 6px;
    cursor: pointer;
    font-family: 'Lato', sans-serif;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.close-btn-bottom:hover {
    background: #34495e;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

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

/* Footer */
.site-footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 40px;
}

.footer-text {
    font-family: 'Cormorant Garamond', serif;
    font-size: 0.8em;
    color: rgba(44, 62, 80, 0.6);
    font-style: italic;
    letter-spacing: 1px;
    margin: 0;
    opacity: 0.8;
}
