/* ================================
   Thèmes jour / nuit
================================ */
:root {
  --bg-color: #f8f5ef;
  --text-color: #222;
  --link-color: #0044aa;
  --link-hover: #001e60;
  --menu-bg: #eae6df;
  --menu-text: #222;
  --menu-active-bg: #d9d4cc;
  --blockquote-bg: #f1ede6;
  --blockquote-border: #cfc6b8;
  --accent-color: #b5895a;
  --text-muted: #666;
}

[data-theme="dark"] {
  --bg-color: #181818;
  --text-color: #e4e4e4;
  --link-color: #a8c8ff;
  --link-hover: #cfe3ff;
  --menu-bg: #1f1f1f;
  --menu-text: #f1f1f1;
  --menu-active-bg: #2c2c2c;
  --blockquote-bg: #222;
  --blockquote-border: #444;
  --accent-color: #ffcf66;
}

/* ================================
   Structure générale
================================ */
html { scroll-behavior: smooth; }

@font-face {
  font-family: 'Lora';
  src: url('../fonts/Lora-Regular.woff2') format('woff2'),
       url('../fonts/Lora-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Lora';
  src: url('../fonts/Lora-Bold.woff2') format('woff2'),
       url('../fonts/Lora-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: 'Lora', serif;
  font-size: 17.5px;
  line-height: 1.8;
  max-width: 750px;
  margin: 0 auto;
  padding: 1em;
  background: var(--bg-color);
  color: var(--text-color);
  transition: background 0.4s ease, color 0.4s ease;
  -webkit-font-smoothing: antialiased;
}

@media (min-width: 900px) {
  body {
    font-size: 18px;
    line-height: 1.9;
  }
}

/* ================================
   En-tête et navigation
================================ */

header {
  background: none;
  box-shadow: none;
  transition: opacity 0.3s ease;
}
header:hover {
  opacity: 1;
}
header a {
  color: var(--text-color);
  opacity: 0.8;
  transition: opacity 0.3s ease;
}
header a:hover {
  opacity: 1;
}

/* Bloc général nav (valeur par défaut compatible) */
nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  font-size: 1rem;
  background:  none;
  border-radius: 6px;
  padding: 0.6em 0.8em;
}

nav a {
  color: var(--menu-text);
  text-decoration: none;
  font-weight: 500;
  padding: 0.3em 0.6em;
  border-radius: 4px;
  transition: background 0.2s ease, color 0.2s ease;
}

nav a.active {
  background: var(--menu-active-bg);
  font-weight: 600;
}

nav a:hover {
  background: rgba(0,0,0,0.08);
  text-decoration: none;
}

/* Séparation visuelle si plusieurs nav successifs */
header nav + nav {
  border-top: 1px solid rgba(0,0,0,0.05);
  margin-top: 0.4em;
  padding-top: 0.4em;
}

/* ================================
   Menus harmonisés
================================ */
.main-menu, .sub-menu, .section-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1em;
  background:  none;
  padding: 0.7em 1em;
  border-radius: 6px;
  margin-bottom: 1em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.main-menu a, .sub-menu a, .section-menu a {
  color: var(--menu-text);
  text-decoration: none;
  font-weight: 500;
  padding: 0.35em 0.6em;
  border-radius: 4px;
  transition: background 0.2s ease, color 0.2s ease;
}

.main-menu a.active,
.sub-menu a.active,
.section-menu a.active {
  background: var(--menu-active-bg);
  font-weight: 600;
}

.main-menu a:hover,
.sub-menu a:hover,
.section-menu a:hover {
  background: rgba(0,0,0,0.08);
}

/* Sous-menu plus léger visuellement */
.sub-menu {
  font-size: 0.95em;
  padding: 0.5em 0.8em;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

[data-theme='dark'] .sub-menu {
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* Section-menu (pages générées) */
.section-menu {
  font-size: 0.95em;
  margin-bottom: 1em;
  text-align: center;
}

[data-theme="dark"] .main-menu,
[data-theme="dark"] .sub-menu,
[data-theme="dark"] .section-menu {
  box-shadow: 0 1px 2px rgba(255,255,255,0.05);
}

/* Menu du footer harmonisé */
footer nav {
  margin-bottom: 0.8em;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8em;
  background: transparent;
  box-shadow: none;
}

footer nav a {
  color: var(--menu-text);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

footer nav a:hover {
  color: var(--accent-color);
  text-decoration: underline;
}

/* ================================
   Contenu principal
================================ */
main {
  max-width: 760px;
  margin: 1.5em auto;
  padding: 0 1em;
  text-align: justify;
}

h1, h2, h3 {
  font-family: "Lora", serif;
  font-weight: 700;
  color: var(--text-color);
  line-height: 1.3;
  transition: color 0.3s ease;
}

h1 {
  font-size: 1.2em;
  margin: 1em 0 0.4em;
  text-align: center;
}

h2 {
  font-size: 1.1em;
  margin-top: 1em;
  margin-bottom: 0.4em;
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

p { margin-bottom: 1em; }

blockquote {
  background: var(--blockquote-bg);
  border-left: 4px solid var(--blockquote-border);
  padding: 0.8em 1em;
  margin: 1.2em 0;
  font-style: italic;
}

/* ================================
   Grilles de sections et pagination
================================ */
.sections-grid a,
main.container p a {
  display: inline-block;
  margin: 0.3rem 0.3rem;
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  text-decoration: none;
  border-radius: 4px;
}

.sections-grid a:hover,
main.container p a:hover {
  background: rgba(0,0,0,0.05);
}

/* ================================
   Page de recherche
================================ */
.search-container { text-align: center; margin: 2em 0 3em; }

.search-input {
  width: 80%;
  max-width: 600px;
  font-size: 1.15em;
  padding: 0.7em 1em;
  border: 1px solid #bbb;
  border-radius: 8px;
  background: var(--bg-color);
  color: var(--text-color);
  transition: all 0.3s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.search-input:focus {
  outline: none;
  border-color: var(--link-color);
  box-shadow: 0 0 5px rgba(0,68,170,0.25);
}

.search-options {
  margin-top: 0.8em;
  font-size: 0.95em;
  color: var(--text-color);
}

.search-options label { margin-right: 1em; cursor: pointer; }

[data-theme="dark"] .search-input {
  background: #1b1b1b;
  border-color: #444;
  color: #eee;
}

/* ============================
   Résultats de recherche
============================ */
#results, .results { width: 100%; box-sizing: border-box; }

.hit, .search-result {
  display: block;
  padding: 0.75rem 0;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.hit:first-child, .search-result:first-child { border-top: none; }

.hit .snippet, .search-result .snippet {
  display: block;
  margin: 0.35rem 0 0;
  color: rgba(0,0,0,0.85);
  line-height: 1.5;
  font-size: 0.98rem;
}

.hit a, .search-result a {
  font-weight: 600;
  margin-right: 0.5rem;
  color: var(--link-color);
}

mark {
  background: #fff59d;
  color: #000;
  padding: 0 .12em;
  border-radius: 2px;
}

[data-theme="dark"] mark {
  background: #ffcf66;
  color: #000;
}

/* Correction mode sombre pour les résultats de recherche */
[data-theme="dark"] .hit .snippet,
[data-theme="dark"] .search-result .snippet {
  color: var(--text-color);
}

[data-theme="dark"] .hit,
[data-theme="dark"] .search-result {
  border-top: 1px solid rgba(255,255,255,0.1);
}

[data-theme="dark"] .page-info {
  color: rgba(255,255,255,0.6);
}

/* Pagination */
.pagination {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px dashed rgba(0,0,0,0.06);
}

.page-btn {
  background: var(--menu-bg);
  color: var(--menu-text);
  border: 1px solid rgba(0,0,0,0.08);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.page-info {
  color: rgba(0,0,0,0.6);
  font-size: 0.95rem;
}

/* ============================
   Boutons flottants
============================ */
#side-controls {
  position: fixed;
  right: 1rem;
  bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 1000;
}

#side-controls button {
  background: rgba(0,0,0,0.06);
  color: #222;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: background 0.3s ease, transform 0.2s ease;
}

#side-controls button:hover {
  transform: scale(1.1);
  background: var(--accent-color);
  color: #fff;
}

[data-theme='dark'] #side-controls button {
  background: rgba(255,255,255,0.12);
  color: #eee;
}

[data-theme='dark'] #side-controls button:hover {
  background: rgba(255,255,255,0.25);
}

/* ============================
   Footer
============================ */
footer {
  text-align: center;
  font-size: 0.9em;
  padding: 2em 0;
  color: var(--menu-text);
  background: var(--menu-bg);
  border-top: 1px solid rgba(0,0,0,0.05);
  transition: background 0.4s ease, color 0.4s ease;
}

.theme-footer-btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: var(--menu-bg);
  color: var(--menu-text);
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.3s ease, color 0.3s ease;
}

.theme-footer-btn:hover {
  background: rgba(0,0,0,0.08);
}

[data-theme='dark'] .theme-footer-btn:hover {
  background: rgba(255,255,255,0.15);
}

/* ============================
   Info box
============================ */
.info {
  background-color: var(--menu-bg);
  border-left: 4px solid var(--accent-color);
  padding: 0.75em 1em;
  border-radius: 6px;
  margin: 1.5em 0;
  font-size: 0.95em;
}

/* ============================
   Liens longs et lisibilité
============================ */

/* Empêche les liens longs de casser la mise en page */
a {
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}

/* Évite les cassures étranges dans les liens inclus dans des paragraphes justifiés */
main p a {
  white-space: normal;
  text-align: left;
}

/* ============================
   Texte non justifié
============================ */

/* Classe optionnelle à appliquer pour les sommaires, index, listes de liens, etc. */
.unjustified {
  text-align: left !important;
  text-justify: auto;
  hyphens: manual;
}

/* Variante centrée possible si besoin d’un rendu plus aéré */
.unjustified.center {
  text-align: center !important;
}

/* Variante "non-justifié compact" pour des listes de liens denses */
.unjustified.compact a {
  display: inline-block;
  margin: 0.2em 0.4em;
  padding: 0.25em 0.45em;
}

/* ============================
   Responsive
============================ */
@media (max-width: 768px) {
  header { padding: 0.8em 0.5em 1em; }
  nav, .main-menu, .sub-menu, .section-menu { gap: 0.6em; padding: 0.5em; }
  nav a, .main-menu a, .sub-menu a, .section-menu a {
    font-size: 0.95rem;
    padding: 0.25em 0.45em;
  }
  h1 { font-size: 1.3em; margin-top: 1em; }
  body { font-size: 1.05rem; line-height: 1.65; }
  .search-input { width: 90%; font-size: 1.05em; padding: 0.6em 0.8em; }
}
.badge {
  display: inline-block;
  padding: 0 6px;
  margin-right: 6px;
  border-radius: 4px;
  color: #222;
  font-size: 0.75em;
  text-transform: capitalize;
}
/* ============================
   Images
============================ */
.fullwidth-image {
  margin: 1.5em 0;
  text-align: center;
}

.fullwidth-image img {
  width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.2s ease;
}

.fullwidth-image img:hover {
  transform: scale(1.02);
}

.fullwidth-image figcaption {
  font-size: 0.9rem;
  color: var(--text-muted, #666);
  margin-top: 0.4em;
}

[data-theme="dark"] .fullwidth-image img {
  box-shadow: 0 2px 6px rgba(255,255,255,0.05);
}

/* ============================
   Sections — mode clair (version corrigée pour data-theme sur <html>)
============================ */
html[data-theme="light"] body.section-accueil {
  --accent-color: #b05a5a;
  --bg-color: #f8f5ef;
  --menu-bg: #f3e9e7;
  --menu-text: #3a1e1e;
  --menu-active-bg: #e5d3d0;
  --blockquote-bg: #f7ecea;
  --blockquote-border: #d9b2ad;
  --link-color: #b05a5a;
  --link-hover: #802f2f;
}

html[data-theme="light"] body.section-roman {
  --accent-color: #b05a5a;
  --bg-color: #fff9f7;
  --menu-bg: #f3e9e7;
  --menu-text: #3a1e1e;
  --menu-active-bg: #e5d3d0;
  --blockquote-bg: #f7ecea;
  --blockquote-border: #d9b2ad;
  --link-color: #b05a5a;
  --link-hover: #802f2f;
}

html[data-theme="light"] body.section-anthologie {
  --accent-color: #4b7fa0;
  --bg-color: #f8fbfd;
  --menu-bg: #e8f1f6;
  --menu-text: #203444;
  --menu-active-bg: #d7e5ef;
  --blockquote-bg: #eef6fa;
  --blockquote-border: #b9d3e3;
  --link-color: #4b7fa0;
  --link-hover: #2c5a7a;
}

html[data-theme="light"] body.section-albertine {
  --accent-color: #b67eb0;
  --bg-color: #fdf9fd;
  --menu-bg: #f3e8f2;
  --menu-text: #3c2b3d;
  --menu-active-bg: #e3cde2;
  --blockquote-bg: #f8eef7;
  --blockquote-border: #d4b0d2;
  --link-color: #b67eb0;
  --link-hover: #8f4e90;
}

html[data-theme="light"] body.section-ressources {
  --accent-color: #5a8b6a;
  --bg-color: #f8fdf9;
  --menu-bg: #e6f1e9;
  --menu-text: #24382c;
  --menu-active-bg: #d4e6d9;
  --blockquote-bg: #edf7ef;
  --blockquote-border: #b7d2bc;
  --link-color: #5a8b6a;
  --link-hover: #2f5238;
}

/* ============================
   Mode nuit : rien à changer
============================ */
html[data-theme="dark"] body.section-accueil,
html[data-theme="dark"] body.section-roman,
html[data-theme="dark"] body.section-anthologie,
html[data-theme="dark"] body.section-albertine,
html[data-theme="dark"] body.section-ressources {
  /* hérite du mode nuit global */
}

/* ============================
   Améliorations ergonomiques recherche
============================ */
.result-link {
  display: inline-block;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease, transform 0.1s ease;
}

.result-link:hover {
  color: var(--link-hover);
  transform: translateX(2px);
  text-decoration: underline;
}

.nolink {
  color: var(--text-muted);
  font-style: italic;
}

.summary {
  margin-bottom: 1rem;
  font-size: 0.95em;
  color: var(--text-muted);
}

.error {
  color: crimson;
  font-weight: 500;
}

/* Badges de section (plus homogènes) */
.badge {
  display: inline-block;
  padding: 0.15em 0.45em;
  margin-right: 0.4em;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 600;
  color: #222;
  vertical-align: middle;
  text-transform: capitalize;
}

/* Meilleure intégration sombre */
[data-theme="dark"] .badge {
  color: #111;
  opacity: 0.95;
}

/* Focus sur champ de recherche */
.search-input:focus-visible {
  outline: 2px solid var(--link-color);
  outline-offset: 2px;
}

/* Lisibilité pagination */
.pagination {
  margin-top: 1.2rem;
}

.pagination button.page-btn {
  font-weight: 500;
  transition: background 0.3s ease, transform 0.1s ease;
}

.pagination button.page-btn:hover {
  transform: scale(1.05);
}

.page-info {
  font-size: 0.95em;
  color: var(--text-muted);
}

/* --- Filtres de section (recherche globale) --- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 1rem 0 1.5rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border-color, #ccc);
  border-bottom: 1px solid var(--border-color, #ccc);
}

.filters label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.95rem;
  background: var(--filter-bg, #f7f7f7);
  border: 1px solid #ddd;
  border-radius: 2rem;
  padding: 0.3rem 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filters input[type="checkbox"] {
  accent-color: #555; /* couleur de coche */
  transform: scale(1.1);
}

.filters label:hover {
  background: #e8e8e8;
}

body[data-theme="dark"] .filters label {
  background: #333;
  border-color: #555;
}

body[data-theme="dark"] .filters label:hover {
  background: #444;
}
