/* ============================================================
 * Idle-Âge — Bibliothèque — UI Material Design 3
 * Thème clair/sombre via data-theme, tokens M3, composants :
 * top app bar, nav rail, cards, chips, boutons, progress, dialog,
 * snackbar, FAB.
 * ============================================================ */

/* ---------- Tokens M3 (dark par défaut) ---------- */
:root, html[data-theme="dark"] {
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;
  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;
  --md-sys-color-tertiary: #efb8c8;
  --md-sys-color-on-tertiary: #492532;
  --md-sys-color-tertiary-container: #633b48;
  --md-sys-color-on-tertiary-container: #ffd8e4;
  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8c1d18;
  --md-sys-color-on-error-container: #f9dedc;
  --md-sys-color-background: #141218;
  --md-sys-color-on-background: #e6e0e9;
  --md-sys-color-surface: #141218;
  --md-sys-color-on-surface: #e6e0e9;
  --md-sys-color-surface-variant: #49454f;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;
  --md-sys-color-surface-container-low: #1d1b20;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;
  --md-sys-color-inverse-surface: #e6e0e9;
  --md-sys-color-inverse-on-surface: #322f35;
  --md-sys-color-inverse-primary: #6750a4;
  --md-sys-color-success: #8fd694;
  --md-sys-color-on-success: #14391b;
  --md-sys-color-surface-tint: #d0bcff;
  --md-sys-shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  --md-sys-shadow-2: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px 2px rgba(0,0,0,.15);
  --md-sys-shadow-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
  --md-sys-state-hover: 0.08;
  --md-sys-state-focus: 0.12;
  --md-sys-state-pressed: 0.12;
  --md-sys-state-dragged: 0.16;
  --md-shape-corner-extra-small: 4px;
  --md-shape-corner-small: 8px;
  --md-shape-corner-medium: 12px;
  --md-shape-corner-large: 16px;
  --md-shape-corner-extra-large: 28px;
  --md-motion-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-motion-emphasized: cubic-bezier(0.2, 0, 0, 1);
}

/* ---------- Thème clair ---------- */
html[data-theme="light"] {
  --md-sys-color-primary: #6750a4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #eaddff;
  --md-sys-color-on-primary-container: #21005d;
  --md-sys-color-secondary: #625b71;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e8def8;
  --md-sys-color-on-secondary-container: #1d192b;
  --md-sys-color-tertiary: #7d5260;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #ffd8e4;
  --md-sys-color-on-tertiary-container: #31111d;
  --md-sys-color-error: #b3261e;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #f9dedc;
  --md-sys-color-on-error-container: #410e0b;
  --md-sys-color-background: #fffbfe;
  --md-sys-color-on-background: #1c1b1f;
  --md-sys-color-surface: #fffbfe;
  --md-sys-color-on-surface: #1c1b1f;
  --md-sys-color-surface-variant: #e7e0ec;
  --md-sys-color-on-surface-variant: #49454f;
  --md-sys-color-outline: #79747e;
  --md-sys-color-outline-variant: #cac4d0;
  --md-sys-color-surface-container-low: #f7f2fa;
  --md-sys-color-surface-container: #f3edf7;
  --md-sys-color-surface-container-high: #ece6f0;
  --md-sys-color-surface-container-highest: #e6e0e9;
  --md-sys-color-inverse-surface: #313033;
  --md-sys-color-inverse-on-surface: #f4eff4;
  --md-sys-color-inverse-primary: #d0bcff;
  --md-sys-color-success: #2e7d32;
  --md-sys-color-on-success: #ffffff;
  --md-sys-color-surface-tint: #6750a4;
  --md-sys-shadow-1: 0 1px 3px 1px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-sys-shadow-2: 0 2px 6px 2px rgba(0,0,0,.15), 0 1px 2px rgba(0,0,0,.3);
  --md-sys-shadow-3: 0 4px 8px 3px rgba(0,0,0,.15), 0 1px 3px rgba(0,0,0,.3);
}

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-family: "Roboto", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100vh;
}

/* Scrollbar discrète */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--md-sys-color-outline-variant); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Top App Bar ---------- */
.top-app-bar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  height: 64px; padding: 0 16px;
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-shadow-1);
}
.app-bar-leading { display: flex; align-items: center; gap: 12px; }
.app-bar-icon { font-size: 24px; }
.app-bar-title-block { display: flex; flex-direction: column; line-height: 1.2; }
.app-bar-title {
  font-size: 1.375rem; font-weight: 500;
  color: var(--md-sys-color-on-surface);
}
.app-bar-subtitle {
  font-size: 0.75rem; color: var(--md-sys-color-on-surface-variant);
}

.app-bar-stats {
  flex: 1; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap;
}
.stat-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-extra-large);
  padding: 6px 14px;
  transition: background var(--md-motion-standard) 0.2s;
}
.stat-chip:hover { background: var(--md-sys-color-surface-container-highest); }
.stat-icon { font-size: 1.1rem; }
.stat-text { display: flex; flex-direction: column; line-height: 1.15; }
.stat-value { font-weight: 600; font-size: 0.95rem; color: var(--md-sys-color-on-surface); }
.stat-label { font-size: 0.7rem; color: var(--md-sys-color-on-surface-variant); }
.stat-label.pos { color: var(--md-sys-color-success); }
.stat-label.neg { color: var(--md-sys-color-error); }

.app-bar-actions { display: flex; gap: 4px; }

/* ---------- Icon buttons ---------- */
.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: none; border-radius: 50%;
  font-size: 1.25rem; cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  transition: background var(--md-motion-standard) 0.2s;
}
.icon-btn:hover { background: rgba(128,128,128,0.12); color: var(--md-sys-color-on-surface); }
.icon-btn:disabled { opacity: 0.38; cursor: default; }

/* ---------- Bandeau de ressources ---------- */
.res-strip {
  position: sticky; top: 64px; z-index: 90;
  display: flex; gap: 8px;
  padding: 8px 16px;
  background: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.res-strip::-webkit-scrollbar { display: none; }
.res-strip .res-chip { flex: 0 0 auto; }
.res-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-corner-extra-large);
  padding: 4px 12px;
  font-size: 0.8125rem; font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}
.res-chip b { color: var(--md-sys-color-on-surface); font-weight: 600; }
.res-icon { font-size: 0.9rem; }

/* ---------- Navigation Rail (desktop) / Bottom bar (mobile-first) ---------- */
/* Par défaut (mobile) : barre de navigation EN BAS */
.nav-rail {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 80;
  height: 64px;
  display: flex; flex-direction: row; align-items: stretch; justify-content: space-around;
  gap: 0; padding: 0 4px;
  background: var(--md-sys-color-surface-container);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  border-right: none;
}
.nav-rail-item {
  flex: 1; width: auto; height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: transparent;
  border: none; border-radius: 0;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  transition: background var(--md-motion-standard) 0.2s, color var(--md-motion-standard) 0.2s;
  min-width: 0;
}
.nav-rail-item:hover { background: rgba(128,128,128,0.08); }
.nav-rail-icon {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  border-radius: var(--md-shape-corner-extra-large);
  padding: 4px 8px;
  transition: background var(--md-motion-standard) 0.2s;
}
.nav-rail-label {
  font-size: 0.625rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.nav-rail-item.active { color: var(--md-sys-color-on-secondary-container); }
.nav-rail-item.active .nav-rail-icon { background: var(--md-sys-color-secondary-container); }
.nav-rail-spacer { display: none; }

/* Desktop (≥900px) : rail vertical à gauche */
@media (min-width: 900px) {
  .nav-rail {
    left: 0; right: auto; bottom: 0; top: 64px;
    width: 80px; height: auto;
    flex-direction: column; align-items: center;
    gap: 12px; padding: 12px 0;
    border-top: none;
    border-right: 1px solid var(--md-sys-color-outline-variant);
  }
  .nav-rail-item {
    flex: none; width: 56px; height: 56px;
    border-radius: var(--md-shape-corner-large);
  }
  .nav-rail-label { font-size: 0.6875rem; }
  .nav-rail-spacer { display: block; flex: 1; }
  .content { margin-left: 80px; }
  .res-strip { padding-left: 96px; flex-wrap: wrap; overflow-x: visible; }
  .app-bar-stats { display: flex; }
  .snackbar { left: 96px; }
  body { padding-bottom: 0; }
}

/* ---------- Contenu (mobile-first) ---------- */
.content {
  margin-left: 0;
  padding: 16px 16px 96px 16px; /* espace pour la bottom bar */
  max-width: 1200px;
}

/* ============ Desktop amélioré (≥900px) : grille multi-colonnes ============ */
@media (min-width: 900px) {
  .content {
    margin-left: 80px;
    margin-right: auto;
    padding: 24px 32px 32px 32px;
    width: calc(100% - 80px);
    max-width: 1400px;
  }
  .res-strip {
    position: sticky; top: 64px;
    margin-left: 80px;
    width: calc(100% - 80px);
  }
  .top-app-bar {
    padding-left: 96px;
  }
  /* Grille 2 colonnes pour les blocs de catégorie (métiers, compétences, biens) */
  #jobs-container, #skills-container, #goods-container, #achievements-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
    align-items: start;
  }
  .cat-block {
    margin-bottom: 24px;
    break-inside: avoid;
  }
  /* Voies et journal en pleine largeur */
  #routes-container, .journal-card {
    grid-column: 1 / -1;
  }
  .glossary-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .fab {
    bottom: 32px; right: 32px;
  }
  /* Encyclopédie : grille 2 colonnes pour les cartes de fonctionnalités */
  #encyclo-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
    align-items: start;
  }
  #encyclo-features .card {
    break-inside: avoid;
  }
  /* Meta-summary en pleine largeur dans la grille achievements */
  #meta-summary {
    grid-column: 1 / -1;
  }
  /* Dialog plus large sur desktop */
  .dialog {
    width: min(680px, calc(100vw - 48px));
  }
}

/* ============ Très grand écran (≥1400px) : grille 3 colonnes ============ */
@media (min-width: 1400px) {
  #jobs-container, #skills-container, #goods-container, #achievements-container {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .glossary-grid {
    grid-template-columns: 1fr 1fr 1fr 1fr;
  }
  #encyclo-features {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
.section-title {
  font-size: 1.5rem; font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 16px;
}
.tab { display: none; animation: fadeIn 0.2s var(--md-motion-standard); }
.tab.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.cat-block { margin-bottom: 28px; }
.cat-title {
  font-size: 1.125rem; font-weight: 500;
  color: var(--md-sys-color-primary);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

/* ---------- Cards (M3 elevated) ---------- */
.card {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-shape-corner-medium);
  box-shadow: var(--md-sys-shadow-1);
  padding: 16px;
  margin-bottom: 12px;
  transition: box-shadow var(--md-motion-standard) 0.2s;
}
.card:hover { box-shadow: var(--md-sys-shadow-2); }
.card.locked {
  background: var(--md-sys-color-surface-container-low);
  border: 1px dashed var(--md-sys-color-outline-variant);
  box-shadow: none;
  opacity: 0.75;
}
.card.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.card.owned { border-left: 4px solid var(--md-sys-color-success); }
.card.housing-active { border-left: 4px solid var(--md-sys-color-tertiary); }
.card h4 {
  font-size: 1rem; font-weight: 500;
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  margin-bottom: 4px;
}
.card .sub { font-size: 0.8125rem; color: var(--md-sys-color-on-surface-variant); margin-bottom: 8px; }
.card.active .sub { color: var(--md-sys-color-on-primary-container); opacity: 0.85; }
.card .row {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.card .row > span {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.8125rem;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-shape-corner-extra-large);
  padding: 3px 10px;
  color: var(--md-sys-color-on-surface-variant);
}
.card.active .row > span {
  background: rgba(0,0,0,0.12);
  color: var(--md-sys-color-on-primary-container);
}
.card .row b { color: var(--md-sys-color-on-surface); font-weight: 600; }
.card.active .row b { color: var(--md-sys-color-on-primary-container); }

/* ---------- Chips (assist / filtres) ---------- */
.badge {
  display: inline-flex; align-items: center;
  font-size: 0.6875rem; font-weight: 500;
  height: 24px; padding: 0 10px;
  border-radius: var(--md-shape-corner-small);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.badge.nourriture { background: #e8d5a3; color: #4a3a12; }
.badge.logement { background: #d5c4e8; color: #33235a; }
.badge.travail { background: #bcd9e8; color: #123a4a; }
.badge.confort { background: #ecc9dc; color: #5a2340; }
.badge.outils { background: #c4e8bd; color: #1d4a1a; }
html[data-theme="dark"] .badge.nourriture { background: #5a4a1e; color: #f0dfa8; }
html[data-theme="dark"] .badge.logement { background: #4a3a6e; color: #dccdf0; }
html[data-theme="dark"] .badge.travail { background: #1e4a5e; color: #b8dcec; }
html[data-theme="dark"] .badge.confort { background: #5e2a48; color: #f0c9dc; }
html[data-theme="dark"] .badge.outils { background: #2a5e28; color: #cdf0c4; }

.owned-tag {
  font-size: 0.75rem; font-weight: 500;
  color: var(--md-sys-color-success);
}
.hint { font-size: 0.75rem; color: var(--md-sys-color-on-surface-variant); font-weight: 400; }
.secret { font-style: italic; }

/* ---------- Linear progress (M3) ---------- */
.prog {
  height: 4px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
  margin: 8px 0 4px 0;
}
.prog > .fill {
  height: 100%;
  background: var(--md-sys-color-primary);
  border-radius: 2px;
  transition: width 0.15s linear;
}
.card.active .prog > .fill { background: var(--md-sys-color-on-primary-container); }
.prog > .label {
  font-size: 0.6875rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

/* ---------- Boutons M3 ---------- */
.btn-filled, .btn-outlined, .btn-text, .btn-tonal {
  font-family: inherit;
  font-size: 0.875rem; font-weight: 500;
  letter-spacing: 0.1px;
  height: 40px; padding: 0 24px;
  border-radius: var(--md-shape-corner-extra-large);
  border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: box-shadow var(--md-motion-standard) 0.2s, background var(--md-motion-standard) 0.2s;
  position: relative;
}
.btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-shadow-1);
}
.btn-filled:hover { box-shadow: var(--md-sys-shadow-2); }
.btn-tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.btn-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}
.btn-outlined:hover { background: rgba(103,80,164,0.08); }
.btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  height: 40px; padding: 0 12px;
}
.btn-text:hover { background: rgba(103,80,164,0.08); }
.btn-filled:disabled, .btn-tonal:disabled, .btn-outlined:disabled, .btn-text:disabled {
  background: rgba(128,128,128,0.12);
  color: rgba(128,128,128,0.6);
  box-shadow: none; cursor: default;
  border-color: transparent;
}
.btn-outlined:disabled { border-color: rgba(128,128,128,0.12); }

/* Bouton compact dans les cards */
.card button, .card .btn-filled, .card .btn-outlined {
  height: 36px; padding: 0 16px; font-size: 0.8125rem;
}

/* ---------- Switch (M3) pour l'entraînement ---------- */
.switch {
  position: relative; display: inline-flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none;
  font-size: 0.875rem; color: var(--md-sys-color-on-surface);
}
.switch input { display: none; }
.switch .track {
  width: 52px; height: 32px;
  background: var(--md-sys-color-surface-container-highest);
  border: 2px solid var(--md-sys-color-outline);
  border-radius: 16px;
  position: relative;
  transition: background var(--md-motion-standard) 0.2s, border-color var(--md-motion-standard) 0.2s;
}
.switch .thumb {
  position: absolute; top: 2px; left: 2px;
  width: 24px; height: 24px;
  background: var(--md-sys-color-outline);
  border-radius: 50%;
  transition: transform var(--md-motion-standard) 0.2s, background var(--md-motion-standard) 0.2s;
}
.switch input:checked + .track { background: var(--md-sys-color-primary); border-color: var(--md-sys-color-primary); }
.switch input:checked + .track .thumb {
  transform: translateX(20px);
  background: var(--md-sys-color-on-primary);
  width: 28px; height: 28px; top: 0; left: 0;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 70;
  width: 56px; height: 56px;
  border-radius: var(--md-shape-corner-large);
  border: none; cursor: pointer;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 1.5rem;
  box-shadow: var(--md-sys-shadow-3);
  display: flex; align-items: center; justify-content: center;
  transition: box-shadow var(--md-motion-standard) 0.2s, transform var(--md-motion-standard) 0.2s;
}
.fab:hover { box-shadow: 0 6px 10px 4px rgba(0,0,0,.15), 0 2px 3px rgba(0,0,0,.3); transform: scale(1.04); }

/* ---------- Snackbar (M3) ---------- */
.snackbar {
  position: fixed; left: 96px; right: 24px; bottom: 24px; z-index: 200;
  min-width: 288px; max-width: 480px;
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border-radius: var(--md-shape-corner-extra-small);
  box-shadow: var(--md-sys-shadow-3);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 16px;
  font-size: 0.875rem;
  transform: translateY(150%);
  opacity: 0;
  transition: transform var(--md-motion-emphasized) 0.25s, opacity var(--md-motion-standard) 0.25s;
  pointer-events: none;
}
.snackbar.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
.snackbar-text { flex: 1; }
.snackbar-action {
  background: transparent; border: none; cursor: pointer;
  color: var(--md-sys-color-inverse-primary);
  font-weight: 500; font-size: 0.875rem;
  text-transform: uppercase; letter-spacing: 0.5px;
  font-family: inherit;
}

/* ---------- Dialog (M3) ---------- */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.32);
  display: flex; align-items: center; justify-content: center;
  animation: scrimIn 0.2s var(--md-motion-standard);
}
.dialog-scrim.hidden { display: none; }
@keyframes scrimIn { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-shape-corner-extra-large);
  box-shadow: var(--md-sys-shadow-3);
  width: min(560px, calc(100vw - 48px));
  padding: 24px;
  text-align: center;
  animation: dialogIn 0.25s var(--md-motion-emphasized);
}
@keyframes dialogIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.dialog-icon { font-size: 2.5rem; margin-bottom: 12px; }
.dialog-title { font-size: 1.5rem; font-weight: 400; margin-bottom: 12px; }
.dialog-content {
  font-size: 0.875rem; color: var(--md-sys-color-on-surface-variant);
  white-space: pre-line; text-align: left;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-corner-medium);
  padding: 16px; margin-bottom: 20px;
  max-height: 300px; overflow-y: auto;
}
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
}

/* ---------- Journal ---------- */
.journal-card { max-height: 70vh; overflow-y: auto; }
#journal-list { font-size: 0.8125rem; color: var(--md-sys-color-on-surface-variant); line-height: 1.6; }
#journal-list .new { color: var(--md-sys-color-on-surface); font-weight: 500; }

/* ---------- Voies ---------- */
.route-card.done {
  border-left: 4px solid var(--md-sys-color-tertiary);
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}
.route-card.done .sub { color: var(--md-sys-color-on-tertiary-container); opacity: 0.85; }

/* ---------- Utilitaires ---------- */
.missing { color: var(--md-sys-color-error) !important; }
.mt-8 { margin-top: 8px; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Responsive mobile ---------- */
@media (max-width: 899px) {
  /* Les stats restent VISIBLES (voir refonte mobile plus bas) */
  .nav-rail-label { font-size: 0.5625rem; }
}

/* ============ Badge de vitesse (mode test) ============ */
.speed-badge {
  display: inline-block;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  font-size: 0.6875rem; font-weight: 600;
  border-radius: var(--md-shape-corner-small);
  padding: 1px 6px; margin-left: 6px;
  vertical-align: middle;
}
.speed-badge.hidden { display: none; }
.icon-btn.speed-active { color: var(--md-sys-color-tertiary); }

/* ============ Boutons de vitesse / langue ============ */
.speed-buttons {
  display: flex; gap: 8px; flex-wrap: wrap;
  justify-content: center; margin-top: 12px;
}
.speed-btn.active, .lang-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary);
}

/* ============ Onglet Succès ============ */
.meta-summary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  margin-bottom: 16px;
}
.meta-summary h4 { margin-bottom: 6px; font-size: 0.95rem; }
.meta-summary .row { margin-bottom: 0; }
.meta-summary .row > span {
  background: rgba(0,0,0,0.12);
  color: var(--md-sys-color-on-primary-container);
}
.ach-card.ach-done {
  border-left: 4px solid var(--md-sys-color-tertiary);
}
.ach-reward {
  font-size: 0.75rem;
  color: var(--md-sys-color-tertiary);
  font-weight: 600;
  margin-top: 4px;
}

/* ============ Encyclopédie ============ */
.encyclo-tabs {
  display: flex; gap: 8px; margin-bottom: 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.encyclo-tab-btn {
  background: transparent; border: none; cursor: pointer;
  padding: 10px 16px;
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.encyclo-tab-btn.active {
  color: var(--md-sys-color-primary);
  border-bottom-color: var(--md-sys-color-primary);
}
.encyclo-pane { display: none; }
.encyclo-pane.active { display: block; }
.encyclo-intro {
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 16px; font-size: 0.9rem;
}
.glossary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 700px) {
  .glossary-grid { grid-template-columns: 1fr 1fr; }
}
.glossary-term {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-corner-medium);
  padding: 12px 14px;
}
.glossary-term b {
  display: block;
  color: var(--md-sys-color-primary);
  font-size: 0.9rem; margin-bottom: 2px;
}
.glossary-term span {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---------- Carte « Prochain âge » ---------- */
.advance-card {
  border: 1px solid var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.advance-card.advance-ready {
  border-width: 2px;
  box-shadow: 0 0 12px rgba(208, 188, 255, 0.4);
}
.advance-card h4 { color: var(--md-sys-color-on-primary-container); }
.advance-card .sub { color: var(--md-sys-color-on-primary-container); opacity: 0.85; }
.advance-ok { color: var(--md-sys-color-on-primary-container); font-weight: 600; }
.advance-missing { opacity: 0.75; }

/* ---------- Arbre des âges ---------- */
.ages-tree {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-shape-corner-large);
  padding: 16px;
  margin-bottom: 16px;
}
.ages-level {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  padding: 8px 0;
}
.ages-level + .ages-level { border-top: 1px dashed var(--md-sys-color-outline-variant); }
.age-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--md-sys-shape-corner-medium, 12px);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  min-width: 140px;
}
.age-node .age-emoji { font-size: 1.1rem; }
.age-node .age-name { font-size: 0.85rem; font-weight: 500; }
.age-current {
  border: 2px solid var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.age-visited { opacity: 0.75; }
.age-reachable {
  border: 1px solid var(--md-sys-color-tertiary);
  color: var(--md-sys-color-tertiary);
}
.age-far { opacity: 0.55; }

/* ---------- Panneau tutoriel ---------- */
.tutorial-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: var(--md-shape-corner-large);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.tutorial-panel.hidden { display: none; }
.tutorial-step {
  background: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.tutorial-text { font-size: 0.9rem; line-height: 1.4; }

/* Badges starter sur les cartes d'avancement */
.advance-card .starter-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 8px;
}
.starter-easy { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.starter-hard { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }

/* Badge « âge prêt » dans la topbar */
.age-ready-btn.hidden { display: none; }
.age-ready-btn {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  animation: ageReadyPulse 1.5s infinite;
}
@keyframes ageReadyPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ============================================================
 * REFONTE MOBILE (smartphones) — priorité petits écrans
 * Touch targets ≥ 44px, stats TOUJOURS visibles, cartes denses.
 * ============================================================ */

/* Menu secondaire ⋮ */
.more-menu {
  position: fixed; top: 60px; right: 8px; z-index: 190;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-medium);
  box-shadow: var(--md-sys-shadow-2);
  min-width: 200px; padding: 6px;
  display: flex; flex-direction: column;
}
.more-menu.hidden { display: none; }
.more-menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 14px; min-height: 48px;
  background: transparent; border: none; border-radius: var(--md-shape-corner-small);
  font-family: inherit; font-size: 0.9rem; text-align: left; cursor: pointer;
  color: var(--md-sys-color-on-surface);
}
.more-menu-item:hover { background: rgba(128,128,128,0.08); }
.more-menu-item.danger { color: var(--md-sys-color-error); }

/* Safe-area pour iPhone (encoche/barre gestuelle) */
@supports (padding: max(0px)) {
  .nav-rail { padding-bottom: max(0px, env(safe-area-inset-bottom)); height: calc(64px + env(safe-area-inset-bottom)); }
  .nav-rail-item { height: 64px; }
  .top-app-bar { padding-top: max(4px, env(safe-area-inset-top)); }
}

/* Compactage universel des cartes sur petit écran */
@media (max-width: 700px) {
  /* --- Topbar : 2 lignes compactes, stats visibles --- */
  .top-app-bar {
    flex-wrap: wrap; gap: 4px 8px;
    padding: 6px 10px;
    height: auto; min-height: 56px;
  }
  .app-bar-leading { flex: 1 1 auto; min-width: 0; }
  .app-bar-icon { font-size: 1.4rem; }
  .app-bar-title { font-size: 0.95rem; }
  .app-bar-subtitle { font-size: 0.7rem; }
  .app-bar-stats {
    order: 3; flex-basis: 100%;
    display: flex; justify-content: flex-start;
    gap: 6px; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .app-bar-stats::-webkit-scrollbar { display: none; }
  .stat-chip { padding: 4px 10px; gap: 6px; border-radius: 999px; flex: 0 0 auto; }
  .stat-icon { font-size: 0.85rem; }
  .stat-value { font-size: 0.8rem; }
  .stat-label { font-size: 0.62rem; }
  .app-bar-actions { gap: 2px; }
  .icon-btn { width: 44px; height: 44px; font-size: 1.15rem; }

  /* --- Strip ressources : chips denses, scroll horizontal --- */
  .res-strip {
    padding: 5px 10px; gap: 6px;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .res-strip::-webkit-scrollbar { display: none; }
  .res-chip {
    flex: 0 0 auto; gap: 4px;
    padding: 4px 10px; font-size: 0.78rem;
    border-radius: 999px;
  }
  .res-chip b { font-size: 0.8rem; }
  .res-chip .res-icon { font-size: 0.85rem; }

  /* --- Contenu : marges réduites --- */
  .content { padding: 10px 10px calc(84px + env(safe-area-inset-bottom, 0px)); }
  .section-title { font-size: 1.05rem; margin: 8px 0 12px; }

  /* --- Cartes : denses mais lisibles --- */
  .card { padding: 10px 12px; margin-bottom: 8px; }
  .card h4 { font-size: 0.92rem; }
  .card .sub { font-size: 0.76rem; }
  .card .row { font-size: 0.74rem; gap: 4px 10px; }
  .card .label { font-size: 0.68rem; }
  .prog { height: 6px; }
  .mt-8 { margin-top: 6px; }

  /* --- Boutons : touch targets confortables --- */
  .card button {
    min-height: 44px; padding: 10px 18px;
    font-size: 0.85rem;
  }
  .switch { min-height: 44px; }
  .switch input { width: 22px; height: 22px; }

  /* --- Barre de navigation : labels --- */
  .nav-rail-item { height: 60px; }
  .nav-rail-icon { font-size: 1.2rem; padding: 3px 10px; }
  .nav-rail-label { font-size: 0.56rem; }

  /* --- FAB : au-dessus de la bottom bar --- */
  .fab {
    right: 14px; bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    width: 52px; height: 52px; font-size: 1.5rem;
  }

  /* --- Snackbar au-dessus de la bottom bar --- */
  .snackbar {
    left: 10px; right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    max-width: none; font-size: 0.82rem; padding: 12px 14px;
  }

  /* --- Arbre des âges : nodes compacts --- */
  .ages-tree { padding: 10px; }
  .age-node { padding: 8px 10px; min-width: 100px; }
  .age-node .age-name { font-size: 0.7rem; }
  .age-node .age-emoji { font-size: 0.95rem; }

  /* --- Dialogs : plein largeur --- */
  .dialog { width: calc(100vw - 24px); padding: 18px; }
  .dialog-actions { flex-wrap: wrap; gap: 8px; }
  .dialog-actions button { flex: 1 1 100%; min-height: 48px; }

  /* --- Tutoriel : compact --- */
  .tutorial-panel { padding: 10px 12px; gap: 10px; }
  .tutorial-text { font-size: 0.8rem; }
  .tutorial-step { font-size: 0.65rem; padding: 4px 10px; white-space: normal; }

  /* --- Journal + succès --- */
  .meta-summary .row > span { font-size: 0.7rem; }
  .ach-reward { font-size: 0.68rem; }

  /* --- Glossaire 2 colonnes si ça tient, sinon 1 --- */
  .glossary-grid { gap: 6px; }
  .glossary-term { padding: 8px 10px; }
  .glossary-term b { font-size: 0.8rem; }
  .glossary-term span { font-size: 0.7rem; }
}

/* Très petits écrans (≤ 380px, iPhone SE) */
@media (max-width: 380px) {
  .app-bar-title { font-size: 0.85rem; }
  .app-bar-icon { display: none; }
  .nav-rail-label { font-size: 0.5rem; }
  .card .row { font-size: 0.7rem; }
}

/* ---------- Panneau boosts (monétisation) ---------- */
.boosts-panel {
  margin-top: 16px; padding-top: 14px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  text-align: left;
}
.boost-title {
  font-weight: 600; font-size: 0.85rem; margin-bottom: 10px;
  color: var(--md-sys-color-on-surface);
}
.boost-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.boost-btn { flex: 1 1 45%; min-height: 44px; }
.boost-timer {
  font-weight: 700; color: var(--md-sys-color-tertiary);
  font-variant-numeric: tabular-nums;
}
.boost-premium-btn { width: 100%; margin-top: 10px; min-height: 48px; }
.boost-premium-note { text-align: center; margin-top: 10px; color: var(--md-sys-color-tertiary); }
.boost-premium-btn.hidden { display: none; }
