:root {
    --bg-main: #f4f1ea;
    --bg-page: #fdfbf7;
    --text-color: #2c2c2c;
    --accent: #1e3a5f;
    --accent-light: #2b5c8f;
    --brand-gold: #f59e0b;
    --highlight-word: #ffe082;
    --highlight-sentence: #fff8e1;
    --border-color: #dcd6cc;
    --reader-font-size: 18px;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Masquage accessible de l'input file sans bloquer le clic sur mobile */
.sr-only-file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Barre d'outils supérieure */
.toolbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.6rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 0.82rem;
}

/* Logo LexiPage */
.brand-logo {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    margin-right: 0.5rem;
    user-select: none;
}

.brand-logo svg {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.brand-name span {
    color: var(--brand-gold);
}

.btn-upload, .btn-nav, .btn-font {
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 0.45rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
    transition: background 0.2s;
    user-select: none;
}

.btn-font {
    background-color: #eef4fa;
    color: var(--accent);
    border: 1px solid #d0e0f0;
    padding: 0.35rem 0.6rem;
}

.btn-upload:hover, .btn-nav:hover:not(:disabled) {
    background-color: var(--accent-light);
}

.btn-font:hover {
    background-color: var(--accent);
    color: #fff;
}

.btn-nav:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.font-size-indicator {
    font-size: 0.8rem;
    color: #666;
    min-width: 36px;
    text-align: center;
    font-weight: 600;
}

#book-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #555;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-indicator {
    font-size: 0.85rem;
}

#page-input {
    width: 52px;
    padding: 0.25rem;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

select {
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 0.85rem;
    background: #fff;
    cursor: pointer;
}

.badge {
    background: #eef4fa;
    color: var(--accent);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Zone de lecture */
.reader-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.reader-page {
    background: var(--bg-page);
    width: 100%;
    max-width: 800px;
    padding: 2.5rem 3rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    border: 1px solid var(--border-color);
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: var(--reader-font-size);
    line-height: 1.75;
    color: var(--text-color);
    transition: font-size 0.15s ease;
}

.empty-state {
    font-family: 'Segoe UI', sans-serif;
    text-align: center;
    color: #666;
    padding: 2.5rem 1rem;
    font-size: 1rem;
}

.empty-state h2 {
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.empty-state ul {
    text-align: left;
    max-width: 520px;
    margin: 1.25rem auto 0;
    line-height: 1.6;
}

.empty-state li {
    margin-bottom: 0.5rem;
}

.sentence {
    transition: background-color 0.15s;
    border-radius: 3px;
}

.sentence.active-sentence {
    background-color: var(--highlight-sentence);
}

.word {
    cursor: pointer;
    border-radius: 3px;
    padding: 0 1px;
    transition: background-color 0.15s;
}

.word:hover {
    background-color: rgba(43, 92, 143, 0.15);
}

.word.active-word {
    background-color: var(--highlight-word);
    font-weight: bold;
}

p.pdf-paragraph {
    margin-bottom: 1.15em;
    text-align: justify;
}

/* Pop-up Modal */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.popup-card {
    background: #fff;
    width: 100%;
    max-width: 520px;
    border-radius: 10px;
    padding: 1.35rem;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-height: 85vh;
    overflow-y: auto;
}

.popup-close {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #888;
    cursor: pointer;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1rem;
    padding-right: 2rem;
}

.word-title-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.popup-header h3 {
    font-size: 1.3rem;
    color: var(--accent);
}

.section-header-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.result-section {
    margin-bottom: 1rem;
}

.result-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #777;
    margin-bottom: 0.35rem;
}

.section-header-inline h4 {
    margin-bottom: 0;
}

.result-box {
    background: #f8f9fa;
    border-left: 4px solid var(--accent);
    padding: 0.75rem 0.9rem;
    border-radius: 4px;
    font-size: 1rem;
    white-space: pre-line;
    line-height: 1.5;
}

.sentence-original {
    font-style: italic;
    color: #444;
    background: #fdfbf7;
    padding: 0.6rem 0.8rem;
    border: 1px solid #eee;
    border-radius: 4px;
    margin-bottom: 0.75rem;
    line-height: 1.45;
    font-size: 0.95rem;
}

.sentence-translated {
    background: #eef6ff;
    color: #1e3a5f;
    padding: 0.6rem 0.8rem;
    border-radius: 4px;
    font-weight: 500;
    line-height: 1.45;
    font-size: 0.95rem;
}

.btn-audio {
    background: #eef4fa;
    border: 1px solid #d0e0f0;
    color: var(--accent);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.95rem;
}

.btn-audio:hover {
    background: var(--accent);
    color: #fff;
}

.btn-audio-small {
    border-radius: 6px;
    width: auto;
    height: auto;
    padding: 0.22rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.loader {
    padding: 1.5rem 0;
    text-align: center;
    color: #666;
    font-style: italic;
}

.error-box {
    color: #b71c1c;
    background: #ffebee;
    padding: 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

/* Adaptation Mobile */
@media (max-width: 640px) {
    .toolbar {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    .reader-wrapper {
        padding: 0.5rem 0.35rem;
    }
    .reader-page {
        padding: 1.15rem 1rem;
        line-height: 1.6;
    }
    p.pdf-paragraph {
        text-align: left;
    }
    #book-title {
        max-width: 110px;
    }
}