:root {
  --bg: #faf9f7;
  --bg-card: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #6b6b70;
  --accent: #8a1f2d;
  --border: #e4e1db;
  --radius: 10px;
  --max-width: 1100px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

img { max-width: 100%; display: block; }

button { font: inherit; }

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

/* --- Barre d'onglets en haut --- */

.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 249, 247, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.tabbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.tabbar-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-secondary);
  margin-right: auto;
}

.tab-link {
  padding: 6px 4px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- En-tête d'accueil --- */

.home-header {
  text-align: center;
  padding: 28px 16px 8px;
}

.home-header img.logo {
  max-height: 90px;
  max-width: 100%;
  margin: 0 auto 14px;
}

.home-header p.presentation {
  max-width: 560px;
  margin: 0 auto;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
}

/* --- Dernier numéro --- */

.latest-section {
  text-align: center;
  padding: 24px 16px 8px;
}

.latest-section .kicker {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.latest-cover {
  display: inline-block;
  width: min(260px, 70vw);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0,0,0,0.16);
  background: var(--bg-card);
  transition: transform 0.15s ease;
}

.latest-cover:hover { transform: translateY(-2px); }

.latest-cover img { width: 100%; display: block; }

.latest-title {
  margin-top: 10px;
  font-weight: 600;
  font-size: 15px;
}

.latest-cover-wrap {
  position: relative;
  display: inline-block;
}

/* --- Étoile favoris (réutilisée sur les couvertures : accueil, année, favoris, anniversaire) --- */

.fav-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
}

.fav-btn.active {
  color: #ffd452;
}

.issue-card-wrap .fav-btn {
  width: 24px;
  height: 24px;
  font-size: 13px;
  top: 4px;
  right: 4px;
}

/* --- Il y a X ans --- */

.anniversary-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.anniversary-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.anniversary-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.anniversary-card-wrap { position: relative; }

.anniversary-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.anniversary-card .cover {
  flex: 0 0 auto;
  width: 70px;
  height: 92px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.14);
}

.anniversary-card .cover img { width: 100%; height: 100%; object-fit: cover; }

.anniversary-info { flex: 1; min-width: 0; }

.anniversary-title {
  font-weight: 600;
  font-size: 15px;
}

.anniversary-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.anniversary-chevron {
  color: var(--text-secondary);
  font-size: 18px;
}

/* --- Favoris (bandeau horizontal sur l'accueil) --- */

.favorites-scroll {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.favorites-scroll .issue-card-wrap {
  flex: 0 0 104px;
}

.favorites-scroll .issue-card .cover { aspect-ratio: 104 / 136; }

/* --- Sections génériques --- */

.section {
  padding: 24px 16px 8px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
}

/* --- Grille des piles par année --- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px;
}

.pile {
  text-align: center;
  cursor: pointer;
}

.pile-stack {
  position: relative;
  height: 148px;
  margin-bottom: 8px;
}

.pile-stack .card-back {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 104px;
  height: 136px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 2px 5px rgba(0,0,0,0.10);
}

.pile-stack .card-back.b1 { transform: translate(-50%, -50%) rotate(-4deg) translate(-4px, 2px); }
.pile-stack .card-back.b2 { transform: translate(-50%, -50%) rotate(4deg) translate(4px, 2px); }

.pile-stack .cover {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 104px;
  height: 136px;
  transform: translate(-50%, -50%);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 3px 8px rgba(0,0,0,0.16);
}

.pile-stack .cover img { width: 100%; height: 100%; object-fit: cover; }

.pile-year { font-weight: 700; font-size: 15px; }
.pile-count { font-size: 12px; color: var(--text-secondary); }

/* --- Grille de numéros (page année) --- */

.issue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 22px;
}

.issue-card-wrap { position: relative; }

.issue-card { text-align: center; }

.issue-card .cover {
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-card);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  aspect-ratio: 130 / 170;
}

.issue-card .cover img { width: 100%; height: 100%; object-fit: cover; }

.issue-card .numero { margin-top: 6px; font-weight: 600; font-size: 13px; }
.issue-card .mois { font-size: 12px; color: var(--text-secondary); }

/* --- Fil d'ariane / retour --- */

.back-link {
  display: inline-block;
  margin: 18px 16px 0;
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 6px 16px 0;
}

/* --- Recherche --- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  margin: 16px;
}

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
}

.search-bar .icon { color: var(--text-secondary); font-size: 15px; }
.search-bar .clear-btn {
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  padding: 0 2px;
}

.titles-only {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.titles-only .box {
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--text-secondary);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
}

.titles-only.checked .box {
  background: var(--accent);
  border-color: var(--accent);
}

hr.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0 0 4px;
}

.result-list { padding: 0 16px 32px; }

.result-item {
  display: block;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.result-item .r-title { font-weight: 600; font-size: 15px; }
.result-item .r-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

/* --- Recherches récentes --- */

.recent-searches {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 24px;
}

.recent-searches-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.clear-history-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.recent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

/* --- Détail d'article --- */

.article-page { padding: 16px 16px 48px; max-width: 720px; margin: 0 auto; }

.article-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.article-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.pdf-link-btn {
  flex: 1;
  display: block;
  text-align: center;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: 10px;
}

.share-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
}

.article-title {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 14px;
}

.article-body {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.article-body mark, .article-title mark {
  background: #fdeb8f;
  color: inherit;
  border-radius: 2px;
}

/* --- Écran de chargement (index de recherche) --- */

.loading-block {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Écrans larges (ordinateur) --- */

@media (min-width: 720px) {
  .home-header { padding-top: 40px; }
  .home-header img.logo { max-height: 110px; }
  .home-header p.presentation { font-size: 16px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 26px; }
  .issue-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 26px; }

  .tabbar-inner { padding: 14px 24px; }
}

@media (min-width: 1000px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}
