/* ==========================================================================
   Cartographie Collatz — Style hybride
   - Typographie académique (inspiration Claude Design, Tao, AMS Notices)
   - Interactivité dark theme (Mermaid, Chart.js, modal)
   ========================================================================== */

/* --- Variables : thème sombre (canonique) --- */
:root, html[data-theme="dark"] {
  --bg-primary: #0e0f13;
  --bg-secondary: #16181f;
  --bg-tertiary: #1f2229;
  --bg-elevated: #252832;
  --text-primary: #e8e6e0;
  --text-secondary: #b8b5ad;
  --text-muted: #8b887f;
  --accent: #c8a86a;       /* gold sober (encre vieille) */
  --accent-soft: #8b7c5f;
  --accent-red: #c25450;
  --accent-amber: #d4a045;
  --accent-blue: #6a93b8;
  --accent-green: #6a9b7a;
  --accent-violet: #9080a8;
  --border: #2d3038;
  --shadow-elevated: 0 10px 40px rgba(0, 0, 0, 0.5);
  --serif: 'Crimson Pro', 'Source Serif Pro', 'Iowan Old Style', Georgia, serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

/* --- Thème clair (mode lecture académique, inspiration AMS Notices) --- */
html[data-theme="light"] {
  --bg-primary: #fbfaf6;          /* parchemin légèrement crème */
  --bg-secondary: #f5f2ea;
  --bg-tertiary: #ece8dc;
  --bg-elevated: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #3d3a35;
  --text-muted: #6b6760;
  --accent: #8b6f30;              /* doré plus profond, lisible sur clair */
  --accent-soft: #a08850;
  --accent-red: #a83d3a;
  --accent-amber: #b07e22;
  --accent-blue: #3d6890;
  --accent-green: #4d7958;
  --accent-violet: #6b5683;
  --border: #d8d3c4;
  --shadow-elevated: 0 6px 24px rgba(60, 50, 30, 0.12);
}

/* Auto-detect prefers-color-scheme: light si l'utilisateur n'a rien choisi */
@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    --bg-primary: #fbfaf6;
    --bg-secondary: #f5f2ea;
    --bg-tertiary: #ece8dc;
    --bg-elevated: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #3d3a35;
    --text-muted: #6b6760;
    --accent: #8b6f30;
    --accent-soft: #a08850;
    --accent-red: #a83d3a;
    --accent-amber: #b07e22;
    --accent-blue: #3d6890;
    --accent-green: #4d7958;
    --accent-violet: #6b5683;
    --border: #d8d3c4;
    --shadow-elevated: 0 6px 24px rgba(60, 50, 30, 0.12);
  }
}

/* Transitions douces lors du switch de thème */
html, body, .topbar, .card, .highlight, table, button, .modal {
  transition: background-color 0.25s ease, color 0.2s ease, border-color 0.2s ease;
}

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

/* ==========================================================================
   I18N — FOUC prevention pour le pattern dual-lang inline
   Ces règles s'appliquent UNIQUEMENT avant que main.js ait fini d'initialiser
   (avant que data-lang soit posé sur <html>). Empêche l'affichage simultané
   FR+EN au premier paint. Une fois main.js actif, [hidden] prend le relais.
   ========================================================================== */
html:not([data-lang]):not([lang="fr"]) [lang="fr"]:not(html) { display: none; }
html:not([data-lang])[lang="fr"] [lang="en"]:not(html) { display: none; }

html { scroll-behavior: smooth; }

/* ==========================================================================
   SCROLL PROGRESS BAR — fine ligne dorée en haut de page
   Utilise une CSS Animation moderne (scroll-driven animations) si disponible,
   sinon fallback JS dans main.js qui met à jour --scroll-progress.
   ========================================================================== */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-amber) 100%);
  transform-origin: left center;
  transform: scaleX(var(--scroll-progress, 0));
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(200, 168, 106, 0.4);
}
@supports (animation-timeline: scroll()) {
  .scroll-progress {
    animation: scroll-progress-anim auto linear;
    animation-timeline: scroll(root);
    transform: none;
  }
  @keyframes scroll-progress-anim {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
  }
}

/* ==========================================================================
   THEME TOGGLE BUTTON — icône sun/moon
   ========================================================================== */
#themeBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1rem;
}
#themeBtn .sun-icon { display: none; }
#themeBtn .moon-icon { display: inline; }
html[data-theme="light"] #themeBtn .sun-icon { display: inline; }
html[data-theme="light"] #themeBtn .moon-icon { display: none; }

/* ==========================================================================
   CITATION MODAL — onglets format + zone copy
   ========================================================================== */
.cite-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}
.cite-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.6rem 1rem;
  color: var(--text-secondary);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}
.cite-tab:hover {
  color: var(--text-primary);
}
.cite-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
#citeOutput {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 1rem 1.2rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
}
#copyCiteBtn:hover {
  background: rgba(200, 168, 106, 0.1);
}

/* ==========================================================================
   COMMAND PALETTE / SEARCH (⌘K)
   ========================================================================== */
#searchPalette {
  align-items: flex-start;
  padding-top: 8vh;
}
.search-palette {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.search-icon {
  font-size: 1.4rem;
  color: var(--accent);
}
#searchInputPalette {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 500;
}
#searchInputPalette::placeholder { color: var(--text-muted); }
.search-esc {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.45rem;
  letter-spacing: 0.05em;
}
.search-results {
  max-height: 50vh;
  overflow-y: auto;
}
.search-result {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 0.8rem 1.2rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active {
  background: var(--bg-tertiary);
  border-left-color: var(--accent);
}
.search-result-type {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(200, 168, 106, 0.1);
  border: 1px solid rgba(200, 168, 106, 0.3);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  flex-shrink: 0;
  min-width: 65px;
  text-align: center;
  margin-top: 0.1rem;
}
.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-word;
}
.search-result-subtitle {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}
.search-result-desc {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.4;
}
.search-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}
.search-footer {
  display: flex;
  gap: 1.2rem;
  padding: 0.7rem 1.2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-tertiary);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--sans);
}
.search-footer kbd {
  font-family: var(--mono);
  font-size: 0.7rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  margin-right: 0.3rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   DEPENDENCY GRAPH (D3) — styling tooltip + nodes
   ========================================================================== */
#dependency-graph svg {
  display: block;
  cursor: grab;
}
#dependency-graph svg:active {
  cursor: grabbing;
}
#graph-tooltip {
  margin-top: 1rem;
  transition: all 0.2s;
}
.graph-tooltip-type {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}
.graph-tooltip-name {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 0.3rem;
}
.graph-tooltip-sub {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   CHANGELOG entries
   ========================================================================== */
.changelog-entry {
  border-left: 3px solid var(--border);
  padding: 0 0 1rem 1.5rem;
  margin: 1.8rem 0;
  position: relative;
}
.changelog-entry::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 8px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
}
.changelog-entry header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.changelog-entry h2 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin: 0;
  font-weight: 600;
}
.changelog-entry time {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.version-tag {
  display: inline-block;
  background: rgba(200, 168, 106, 0.15);
  color: var(--accent);
  border: 1px solid rgba(200, 168, 106, 0.4);
  padding: 0.15rem 0.6rem;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.changelog-entry ul {
  list-style: none;
  padding-left: 0;
}
.changelog-entry li {
  padding-left: 1.2rem;
  position: relative;
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
  line-height: 1.5;
}
.changelog-entry li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* ==========================================================================
   FOOTER status badge
   ========================================================================== */
.footer-status {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(106, 155, 122, 0.1);
  border: 1px solid rgba(106, 155, 122, 0.4);
  border-radius: 3px;
  padding: 0.2rem 0.55rem;
  color: var(--accent-green);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-decoration: none;
}
.status-badge:hover {
  background: rgba(106, 155, 122, 0.18);
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 4px rgba(106, 155, 122, 0.6);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.status-sep {
  color: var(--border);
}

/* ==========================================================================
   HERO BANNER — image-based hero on homepage
   Reprend la palette de l'OG image avec une stratégie multi-couche :
   - background-image + radial-gradient overlay
   - Λ watermark animé (drift léger)
   - contenu typographique premier plan
   ========================================================================== */
.hero-banner {
  position: relative;
  width: 100%;
  height: clamp(360px, 48vw, 540px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
  margin: 0;
  isolation: isolate;
  border-bottom: 1px solid var(--border);
}
.hero-banner-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 75% 50%, rgba(200, 168, 106, 0.18) 0%, transparent 60%),
    linear-gradient(135deg, #0e0f13 0%, #16181f 50%, #1f2229 100%);
  z-index: -2;
}
html[data-theme="light"] .hero-banner-bg {
  background:
    radial-gradient(ellipse at 75% 50%, rgba(139, 111, 48, 0.10) 0%, transparent 60%),
    linear-gradient(135deg, #fbfaf6 0%, #f5f2ea 50%, #ece8dc 100%);
}
.hero-banner-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--bg-primary) 0%, rgba(14,15,19,0.4) 50%, transparent 100%);
  z-index: -1;
}
html[data-theme="light"] .hero-banner-overlay {
  background: linear-gradient(90deg, rgba(251,250,246,0.92) 0%, rgba(251,250,246,0.5) 60%, transparent 100%);
}
.hero-banner-lambda {
  position: absolute;
  /* TOC est désormais collapsée par défaut (36px), donc Λ peut s'étendre librement.
     Buffer minimal de 50px pour ne pas mordre la barre TOC repliée. */
  right: max(50px, 4vw);
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--serif);
  font-size: clamp(260px, 44vw, 480px);
  font-weight: 600;
  color: var(--accent);
  opacity: 0.10;
  line-height: 1;
  pointer-events: none;
  z-index: -1;
  user-select: none;
  animation: lambda-drift 18s ease-in-out infinite alternate;
}
@keyframes lambda-drift {
  from { transform: translate(0, -50%) rotate(0deg); }
  to   { transform: translate(-2vw, -52%) rotate(-1.5deg); }
}
.hero-banner-content {
  position: relative;
  z-index: 1;
  padding: 0 max(70px, 6vw);
  max-width: min(60ch, 920px);
}
.hero-banner-eyebrow {
  font-family: var(--mono);
  font-size: clamp(0.7rem, 1vw, 0.85rem);
  letter-spacing: 0.12em;
  color: var(--accent-green);
  background: rgba(106, 155, 122, 0.08);
  border: 1px solid rgba(106, 155, 122, 0.4);
  border-radius: 4px;
  padding: 0.4rem 0.9rem;
  display: inline-block;
  margin-bottom: 1.5rem;
}
.hero-banner-title {
  font-family: var(--serif);
  font-size: clamp(1.6rem, 3.4vw, 2.8rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--accent);
  margin: 0;
  text-wrap: balance;
}
html[data-theme="light"] .hero-banner-title {
  color: #6e5520;
}
.hero-banner-title em {
  font-style: italic;
  color: var(--text-secondary);
  font-weight: 600;
}
.hero-banner-subtitle {
  margin-top: 1.2rem;
  font-family: var(--sans);
  font-size: clamp(0.95rem, 1.5vw, 1.15rem);
  color: var(--text-secondary);
}
.hero-banner-subtitle code {
  background: rgba(200, 168, 106, 0.12);
  color: var(--accent);
  font-family: var(--mono);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  font-size: 0.95em;
}
.hero-banner-pills {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.banner-pill {
  background: rgba(212, 160, 69, 0.12);
  border: 1px solid rgba(212, 160, 69, 0.4);
  color: var(--accent-amber);
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.35rem 0.8rem;
  border-radius: 4px;
  letter-spacing: 0.02em;
}
@media (max-width: 640px) {
  .hero-banner {
    height: auto;
    padding: 3rem 1rem;
  }
  .hero-banner-content {
    padding: 0 1rem;
  }
}

/* ==========================================================================
   STICKY TABLE OF CONTENTS — sidebar latérale qui suit le scroll
   Auto-générée à partir des h2/h3 visibles, highlight section courante
   ========================================================================== */
/* TOC : drawer collapsé sur le bord droit, expand au hover/focus
   - État collapsé : 36px de large, juste un handle "≡" + indicateur dot
     de la section courante
   - État expand : 220px avec liste complète des sections
   - Transition douce 0.25s */
.toc {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 36px;
  max-height: 70vh;
  overflow: hidden;
  z-index: 50;
  font-family: var(--sans);
  font-size: 0.78rem;
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  padding: 0.5rem;
  transition: width 0.25s ease, padding 0.25s ease;
  cursor: pointer;
  pointer-events: auto;
}
.toc:hover, .toc:focus-within {
  width: 240px;
  overflow-y: auto;
  padding: 0.9rem 0.6rem 0.9rem 1rem;
  cursor: default;
}
@supports not (backdrop-filter: blur(8px)) {
  .toc { background: var(--bg-secondary); }
}

/* Handle visible en mode collapsé (icône ≡ verticale) */
.toc::before {
  content: '☰';
  display: block;
  text-align: center;
  font-size: 1.1rem;
  color: var(--accent);
  padding: 0.4rem 0;
  pointer-events: none;
  line-height: 1;
  letter-spacing: 0;
  transition: opacity 0.2s;
}
.toc:hover::before, .toc:focus-within::before { opacity: 0; height: 0; padding: 0; }

/* En mode collapsé, ne montre que le handle ; cache le contenu interne */
.toc .toc-title, .toc .toc-list {
  opacity: 0;
  transition: opacity 0.2s 0s;
  pointer-events: none;
}
.toc:hover .toc-title, .toc:focus-within .toc-title,
.toc:hover .toc-list, .toc:focus-within .toc-list {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.2s 0.1s;
}

/* Indicateur dot vertical sur la barre repliée (montre la position dans la page) */
.toc::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 60%;
  background: linear-gradient(to bottom,
    var(--border) 0%, var(--border) calc(var(--toc-progress, 0) * 100%),
    var(--accent) calc(var(--toc-progress, 0) * 100%),
    var(--accent) calc(var(--toc-progress, 0) * 100% + 8px),
    var(--border) calc(var(--toc-progress, 0) * 100% + 8px), var(--border) 100%);
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.toc:hover::after, .toc:focus-within::after { opacity: 0; }
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-item { margin: 0; padding: 0; }
.toc-link {
  display: block;
  padding: 0.3rem 0.4rem;
  color: var(--text-muted);
  text-decoration: none;
  line-height: 1.4;
  border-left: 2px solid transparent;
  margin-left: -2.8rem;
  padding-left: 2.4rem;
  transition: color 0.15s, border-color 0.15s;
}
.toc-link:hover { color: var(--text-primary); }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.toc-link.toc-h3 {
  padding-left: 3rem;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.toc-title {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.5rem;
  padding-left: 0.4rem;
}
@media (max-width: 1280px) {
  .toc { display: none; }
}

/* ==========================================================================
   LAMBDA EXPLORER (page /lambda/)
   ========================================================================== */
.lambda-explorer {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.8rem;
  margin: 2rem 0;
}
.lambda-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
}
.lambda-control-row {
  flex: 1 1 240px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.lambda-control-row label {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--text-primary);
}
.lambda-control-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.lambda-formula {
  font-family: var(--mono);
  font-size: 1.1rem;
  color: var(--text-secondary);
  flex-basis: 100%;
  text-align: center;
  padding: 0.6rem 0;
  background: var(--bg-tertiary);
  border-radius: 4px;
}
.lambda-value {
  font-weight: 700;
  margin-left: 0.5rem;
}
.lambda-status {
  flex-basis: 100%;
  font-family: var(--sans);
  font-size: 0.92rem;
  padding: 0.7rem 1rem;
  border-radius: 4px;
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
  text-align: center;
}
.lambda-status.status-far { border-left-color: var(--text-muted); color: var(--text-muted); }
.lambda-status.status-barina { border-left-color: var(--accent-red); color: var(--accent-red); }
.lambda-status.status-hercher-baker { border-left-color: var(--accent-amber); color: var(--accent-amber); }
#lambdaCanvas {
  width: 100%;
  height: auto;
  background: var(--bg-tertiary);
  border-radius: 4px;
  cursor: crosshair;
  display: block;
}
.lambda-legend {
  margin-top: 1.2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem 1.2rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.legend-color {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
}
.legend-color.legend-line {
  height: 3px;
  width: 18px;
  border-radius: 0;
}

/* ==========================================================================
   TEAM CARD avec PORTRAIT — humanise la section Équipe
   ========================================================================== */
/* Layout vertical : photo centrée en haut, bio pleine largeur en dessous.
   Évite que la bio s'écrase en colonne étroite quand la card-grid est en
   3 colonnes (~329px par card). */
.team-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}
.team-card-pi {
  border-left: 3px solid var(--accent);
}
.team-portrait {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  border: 2px solid var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  margin: 0 0 0.4rem 0;
}
.team-portrait::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, transparent 60%, rgba(200, 168, 106, 0.15));
  pointer-events: none;
}
html[data-theme="light"] .team-portrait {
  border-color: var(--accent-soft);
  box-shadow: 0 4px 14px rgba(60, 50, 30, 0.18);
}
.team-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(0.05) contrast(1.05);
}
.team-card:hover .team-portrait {
  transform: scale(1.04);
  box-shadow: 0 8px 28px rgba(200, 168, 106, 0.3);
}
.team-body { min-width: 0; }
.team-role {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin: 0.2rem 0 0.8rem 0 !important;
}
.team-links {
  margin-top: 1rem !important;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.team-link {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}
.team-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.team-link-orcid {
  background: rgba(166, 206, 57, 0.08);
  border-color: rgba(166, 206, 57, 0.3);
  color: #a6ce39;
}
.team-link-orcid::before {
  content: '◯ ';
  font-weight: bold;
}
@media (max-width: 640px) {
  .team-card {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 1rem;
  }
  .team-portrait { width: 100px; height: 100px; margin: 0 auto; }
  .team-card-pi { text-align: left; }
  .team-card-pi .team-portrait { margin: 0; }
  .team-links { justify-content: flex-start; }
}

/* ==========================================================================
   FOOTER AVATAR signature (mini portrait)
   ========================================================================== */
.footer-author {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
}
.footer-author-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--accent);
  flex-shrink: 0;
}
.footer-author-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(0.1);
}
.footer-author-name {
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 600;
}

/* ==========================================================================
   READING META — temps de lecture, dernière vérification
   ========================================================================== */
.reading-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.2rem 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.reading-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.reading-meta-item::before {
  content: '·';
  color: var(--border);
}
.reading-meta-item:first-child::before { display: none; }

/* ==========================================================================
   THEOREM PERMALINKS — hover ¶ icon, click to copy URL
   ========================================================================== */
.has-permalink {
  position: relative;
}
.permalink-icon {
  display: inline-block;
  margin-left: 0.4rem;
  opacity: 0;
  font-size: 0.85em;
  color: var(--accent);
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
  user-select: none;
}
.has-permalink:hover .permalink-icon { opacity: 0.7; }
.permalink-icon:hover { opacity: 1 !important; transform: scale(1.15); }
.permalink-copied {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--bg-primary);
  padding: 0.6rem 1.2rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 10000;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  animation: permalink-toast 1.8s ease-out forwards;
}
@keyframes permalink-toast {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(20px); }
}

/* ==========================================================================
   READING FOCUS MODE — touche F dim tout sauf la section courante
   ========================================================================== */
html[data-focus-mode="on"] body > * {
  transition: opacity 0.4s ease;
  opacity: 0.18;
}
html[data-focus-mode="on"] .topbar,
html[data-focus-mode="on"] .scroll-progress,
html[data-focus-mode="on"] .toc {
  opacity: 0.5;
}
html[data-focus-mode="on"] .focus-active {
  opacity: 1 !important;
}

/* ==========================================================================
   THEME SEPIA (3e theme — papier ancien académique)
   ========================================================================== */
html[data-theme="sepia"] {
  --bg-primary: #f4ecd8;
  --bg-secondary: #ede4ce;
  --bg-tertiary: #e3d9c0;
  --bg-elevated: #fbf6e9;
  --text-primary: #2d2418;
  --text-secondary: #4a3f2c;
  --text-muted: #6e6147;
  --accent: #8b5a1f;
  --accent-soft: #a87740;
  --accent-red: #9c3d3a;
  --accent-amber: #b07e22;
  --accent-blue: #3d6890;
  --accent-green: #4d6e3a;
  --accent-violet: #6e5683;
  --border: #c8bfa3;
  --shadow-elevated: 0 6px 24px rgba(80, 60, 30, 0.18);
}

/* ==========================================================================
   FOOTER BADGES (Open Science + ORCID + Verify)
   ========================================================================== */
.footer-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.2rem;
  align-items: center;
  font-size: 0.75rem;
}
.footer-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.3rem 0.65rem;
  text-decoration: none;
  color: var(--text-secondary);
  font-family: var(--mono);
  transition: all 0.15s;
}
.footer-badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.footer-badge.badge-orcid {
  background: rgba(166, 206, 57, 0.08);
  border-color: rgba(166, 206, 57, 0.4);
  color: #a6ce39;
}
.footer-badge.badge-orcid::before {
  content: '◯';
  color: #a6ce39;
  font-weight: bold;
}
.footer-badge.badge-doi {
  background: rgba(106, 147, 184, 0.08);
  border-color: rgba(106, 147, 184, 0.4);
  color: var(--accent-blue);
}
.footer-badge.badge-doi::before { content: '🔗'; font-size: 0.85em; filter: grayscale(0.5); }
.footer-badge.badge-license::before { content: '⚖'; }
.footer-badge.badge-verify {
  background: rgba(106, 155, 122, 0.08);
  border-color: rgba(106, 155, 122, 0.4);
  color: var(--accent-green);
}
.footer-badge.badge-verify::before { content: '⏱'; }
.footer-badge.badge-open {
  background: rgba(212, 160, 69, 0.08);
  border-color: rgba(212, 160, 69, 0.4);
  color: var(--accent-amber);
}
.footer-badge.badge-open::before { content: '◇'; }

/* ==========================================================================
   PRINT STYLESHEET — académique propre, monochrome, pas de chrome UI
   ========================================================================== */
@media print {
  * { background: white !important; color: black !important; box-shadow: none !important; }
  body { font-family: 'Crimson Pro', Georgia, serif; font-size: 11pt; line-height: 1.45; }
  .topbar, .scroll-progress, .toc, .footer-status, .footer-badges,
  .modal-overlay, .search-palette, #themeBtn, #langBtn, #citeBtn, #printBtn,
  .filter-bar, .toolbar-actions { display: none !important; }
  .hero-banner { height: auto; padding: 1rem 0; border: 1px solid #ccc; }
  .hero-banner-bg, .hero-banner-overlay, .hero-banner-lambda { display: none !important; }
  a { color: black !important; text-decoration: underline; }
  a[href^="http"]::after { content: " ↗ " attr(href); font-size: 9pt; color: #555 !important; }
  pre { background: #f5f5f5 !important; color: #333 !important; border: 1px solid #ccc; }
  pre code { color: #333 !important; }
  h1, h2, h3 { page-break-after: avoid; }
  section { page-break-inside: avoid; }
  table { border-collapse: collapse; }
  table, th, td { border: 1px solid #888 !important; }
  .badge { border: 1px solid #666 !important; color: black !important; background: #eee !important; }
  /* Inclure URL canonique en footer print */
  body::after {
    content: "Source: collatz-lab.org · DOI 10.5281/zenodo.19790406 · Eric Merle 2026";
    display: block;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #888;
    font-size: 9pt;
    color: #555 !important;
    text-align: center;
  }
}

/* ==========================================================================
   SIDE-BY-SIDE LEAN ↔ MATH (sur /preuve/)
   ========================================================================== */
.lean-math-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  margin: 2rem 0;
  align-items: stretch;
}
.lean-math-pair > div {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.2rem;
}
.lean-math-pair .lmp-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
  display: block;
}
.lean-math-pair pre {
  margin: 0 !important;
  font-size: 0.78rem !important;
}
.lean-math-pair .lmp-math {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
}
@media (max-width: 800px) {
  .lean-math-pair { grid-template-columns: 1fr; }
}

/* ==========================================================================
   COMMENTS / GISCUS section
   ========================================================================== */
.comments-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.comments-section h3 {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

body {
  font-family: var(--sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.65;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Top bar / nav --- */
.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.9rem 2rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}

.brand {
  font-family: var(--serif);
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.brand span:not(.brand-mark) {
  white-space: nowrap;
}

.brand-mark {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 1px solid var(--accent);
  color: var(--accent);
  text-align: center;
  line-height: 26px;
  margin-right: 0.5rem;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  vertical-align: middle;
  border-radius: 2px;
}

.nav {
  display: flex;
  gap: 1.5rem;
  margin-left: auto;
  font-size: 0.875rem;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  padding: 0.2rem 0.1rem;
}

.nav a:hover, .nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: 1rem;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-family: var(--sans);
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 0.04em;
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Hero --- */
.hero {
  max-width: 1100px;
  margin: 0 auto;
  padding: 5rem 2rem 4rem;
  border-bottom: 1px solid var(--border);
}

.hero-eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.5rem;
  font-family: var(--sans);
  font-weight: 500;
}

.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.15;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

.hero h1 em {
  color: var(--accent);
  font-style: italic;
}

.hero-lede {
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 720px;
  margin-bottom: 2.5rem;
}

/* --- Stats clés --- */
.key-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2rem 3rem;
  margin-top: 3rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

.key-stat .value {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
  margin-bottom: 0.4rem;
}

.key-stat .value sup, .key-stat .value sub {
  font-size: 0.55em;
}

.key-stat .label {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}

.key-stat .desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.4;
}

/* --- Sections --- */
section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 4rem 2rem;
  border-bottom: 1px solid var(--border);
}

section:last-of-type { border-bottom: none; }

.section-eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
  font-weight: 600;
}

section h2 {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 3.5vw, 2.4rem);
  line-height: 1.2;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

section h3 {
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 600;
  margin: 2rem 0 1rem;
  color: var(--text-primary);
}

section p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
  max-width: 740px;
}

section p strong { color: var(--text-primary); font-weight: 600; }

/* --- Cards --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem;
  transition: all 0.2s;
}

.card:hover {
  border-color: var(--accent-soft);
  background: var(--bg-tertiary);
}

.card-eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
  font-weight: 600;
}

.card h3 {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  color: var(--text-primary);
}

.card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 0;
}

.card ul {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.8rem;
  padding-left: 1.2rem;
  list-style: none;
}

.card ul li {
  padding-left: 0.5rem;
  position: relative;
  margin-bottom: 0.3rem;
}

.card ul li:before {
  content: "—";
  position: absolute;
  left: -1rem;
  color: var(--text-muted);
}

.card a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
  font-size: 0.85rem;
}

.card a:hover { border-color: var(--accent); }

/* --- Mermaid container --- */
.mermaid-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2rem 1.5rem;
  margin: 2rem 0;
  overflow-x: auto;
}

.mermaid {
  text-align: center;
}

/* --- Pull quote (verrou central) --- */
.lockbox {
  margin: 3rem 0;
  padding: 2rem 2.5rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-secondary);
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.lockbox .formula {
  display: block;
  text-align: center;
  font-size: 1.6rem;
  margin: 1rem 0;
  color: var(--accent);
  font-style: italic;
}

.lockbox .footer {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--sans);
  letter-spacing: 0.02em;
}

/* --- Filters / search --- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.filter-bar input {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  font-family: var(--sans);
  min-width: 240px;
  flex-grow: 1;
}

.filter-bar input:focus {
  outline: none;
  border-color: var(--accent-soft);
}

.filter-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  font-family: var(--sans);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.15s;
}

.filter-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 600;
}

/* --- Table --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 1rem 0 2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  background: var(--bg-secondary);
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--bg-tertiary);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border-bottom: 1px solid var(--accent-soft);
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
}

tbody tr:hover {
  background: var(--bg-tertiary);
}

td code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent);
  background: var(--bg-primary);
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
}

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  font-family: var(--sans);
}

.badge.jar { background: linear-gradient(135deg, rgba(200, 168, 106, 0.35), rgba(200, 168, 106, 0.15)); color: #f3d99c; border: 1px solid rgba(200, 168, 106, 0.7); font-weight: 700; box-shadow: 0 0 0.4rem rgba(200, 168, 106, 0.3); }
.badge.cds { background: rgba(194, 84, 80, 0.15); color: #d57975; border: 1px solid rgba(194, 84, 80, 0.4); }
.badge.partiel { background: rgba(212, 160, 69, 0.15); color: #e0b87c; border: 1px solid rgba(212, 160, 69, 0.4); }
.badge.inconnu { background: rgba(106, 147, 184, 0.15); color: #9bb6cf; border: 1px solid rgba(106, 147, 184, 0.4); }
.badge.prouve { background: rgba(106, 155, 122, 0.15); color: #94c3a4; border: 1px solid rgba(106, 155, 122, 0.4); }
.badge.prometteur { background: rgba(200, 168, 106, 0.15); color: var(--accent); border: 1px solid rgba(200, 168, 106, 0.4); }
.badge.axiome { background: rgba(144, 128, 168, 0.15); color: #b3a4cc; border: 1px solid rgba(144, 128, 168, 0.4); }
.badge.invente { background: rgba(94, 30, 30, 0.4); color: #c89895; border: 1px solid rgba(127, 29, 29, 0.5); text-decoration: line-through; }

/* Mise en valeur ligne JAR dans le tableau */
#pistesTable tbody tr[data-piste-id="★ JAR"] {
  background: linear-gradient(90deg, rgba(200, 168, 106, 0.08), rgba(200, 168, 106, 0.02));
  border-left: 3px solid var(--accent);
}
#pistesTable tbody tr[data-piste-id="★ JAR"] td:first-child {
  color: var(--accent);
  font-weight: 700;
}
#pistesTable tbody tr[data-piste-id="★ JAR"]:hover {
  background: linear-gradient(90deg, rgba(200, 168, 106, 0.15), rgba(200, 168, 106, 0.05));
}

/* --- Stats / progress --- */
.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  margin: 0.6rem 0;
  padding: 0.6rem 0;
}

.progress-row .label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.progress-row .label strong { color: var(--text-primary); }

.progress-bar {
  background: var(--bg-tertiary);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 0.4rem;
  width: 100%;
}

.progress-fill {
  height: 100%;
  transition: width 0.6s ease-out;
}

.progress-fill.red { background: var(--accent-red); }
.progress-fill.amber { background: var(--accent-amber); }
.progress-fill.blue { background: var(--accent-blue); }
.progress-fill.green { background: var(--accent-green); }
.progress-fill.violet { background: var(--accent-violet); }
.progress-fill.gold { background: var(--accent); }

.progress-row .value {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 600;
}

/* --- Code Lean : sombre par défaut, clair en theme="light" --- */
pre {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.2rem !important;
  margin: 1.5rem 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  overflow-x: auto;
  position: relative;
}

pre[class*="language-"] { background: #0a0c10; }

/* En thème clair : conserver code dark (lisibilité Lean syntax highlighting)
   mais avec une bordure plus marquée pour le contraste visuel */
html[data-theme="light"] pre,
html[data-theme="light"] pre[class*="language-"] {
  background: #1f2229;
  border: 1px solid #d0c8b4;
  box-shadow: var(--shadow-elevated);
}
html[data-theme="light"] pre code {
  color: #e8e6e0;
}

pre .lean-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  font-family: var(--sans);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--accent-green);
  text-transform: uppercase;
  border: 1px solid var(--accent-green);
  padding: 0.1rem 0.5rem;
  border-radius: 2px;
}

code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--accent);
  background: rgba(200, 168, 106, 0.08);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
}

/* --- Chart container --- */
.chart-container {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.5rem;
  margin: 2rem 0;
  height: 380px;
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem 1rem;
  overflow-y: auto;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-width: 720px;
  width: 100%;
  padding: 2rem;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal h3 {
  font-family: var(--serif);
  font-size: 1.5rem;
  margin-bottom: 1.2rem;
  padding-right: 2.5rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.3rem;
}

.modal-close:hover { color: var(--accent-red); }

.modal-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1.5rem;
  font-size: 0.9rem;
  margin: 1rem 0;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.modal-meta dt {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  font-weight: 600;
  padding-top: 0.15rem;
}

.modal-meta dd { color: var(--text-primary); }

/* --- Test cards --- */
.test-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-green);
  border-radius: 4px;
  padding: 1.2rem;
}

.test-card.warning { border-left-color: var(--accent-amber); }

.test-card .test-id {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-green);
  font-weight: 600;
  margin-bottom: 0.4rem;
  letter-spacing: 0.04em;
}

.test-card.warning .test-id { color: var(--accent-amber); }

.test-card .test-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.test-card .test-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.test-card .test-file {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
  word-break: break-all;
}

/* --- Mea culpa list --- */
.mea-culpa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.mc-item {
  border-left: 2px solid var(--accent-soft);
  padding: 0.8rem 1.2rem;
  background: var(--bg-secondary);
}

.mc-item .id {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
}

.mc-item .severity {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.mc-item .title {
  font-family: var(--serif);
  font-weight: 600;
  margin: 0.3rem 0;
}

.mc-item .rule {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* --- Footer --- */
footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 3rem 2rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4rem;
}

footer .footer-meta {
  margin-bottom: 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

footer p { margin-bottom: 0.5rem; max-width: 800px; margin-left: auto; margin-right: auto; }

footer a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

footer a:hover { border-bottom-color: var(--accent); }

/* --- Highlight box --- */
.highlight {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  padding: 1.5rem 2rem;
  margin: 2rem 0;
}

.highlight.warning { border-left-color: var(--accent-amber); }
.highlight.success { border-left-color: var(--accent-green); }
.highlight.danger { border-left-color: var(--accent-red); }

.highlight h3 { margin-top: 0; }
.highlight p:last-child { margin-bottom: 0; }

/* --- Responsive --- */
/* ==========================================================================
   RESPONSIVE — tablette (≤ 1024px) et mobile (≤ 768px / ≤ 480px)
   ========================================================================== */

/* Tablette / petit laptop ≤ 1024px */
@media (max-width: 1024px) {
  .nav { gap: 1rem; font-size: 0.85rem; }
  .nav a { padding: 0.4rem 0.5rem; }
  .hero-banner-title { font-size: clamp(1.4rem, 5vw, 2.4rem); }
  .hero-banner-lambda { font-size: clamp(220px, 38vw, 380px); right: 30px; }
  .card-grid { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
  .footer-badges { gap: 0.4rem; font-size: 0.7rem; }
}

/* Mobile ≤ 768px */
@media (max-width: 768px) {
  .topbar-inner {
    padding: 0.7rem 1rem;
    flex-wrap: wrap;
    gap: 0.8rem;
  }
  .brand { font-size: 0.95rem; }
  .brand-mark { width: 32px; height: 32px; font-size: 1.2rem; }
  .nav {
    order: 3;
    flex-basis: 100%;
    gap: 0.6rem;
    font-size: 0.78rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.3rem;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: 0.3rem 0.4rem; }
  .toolbar-actions {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    gap: 0.4rem;
    flex-wrap: wrap;
  }
  .toolbar-actions .btn-icon { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
  /* Hero banner mobile : compact, lambda discrète */
  .hero-banner {
    height: auto;
    min-height: 280px;
    padding: 2rem 0;
  }
  .hero-banner-content { padding: 0 1.5rem; }
  .hero-banner-title { font-size: 1.4rem; line-height: 1.2; }
  .hero-banner-subtitle { font-size: 0.92rem; }
  .hero-banner-subtitle code { font-size: 0.85rem; }
  .hero-banner-pills { flex-wrap: wrap; gap: 0.4rem; }
  .banner-pill { font-size: 0.7rem; padding: 0.3rem 0.7rem; }
  .hero-banner-lambda {
    font-size: clamp(180px, 60vw, 300px);
    right: -20px;
    opacity: 0.06;
  }
  /* Hero text */
  .hero { padding: 3rem 1.5rem 2.5rem; }
  .hero h1 { font-size: clamp(1.4rem, 5vw, 2rem); }
  section { padding: 3rem 1.5rem; }
  .key-stats { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
  .key-stat .value { font-size: 1.8rem; }
  .modal { padding: 1.5rem; }
  /* Tables : scroll horizontal forcé */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 0.78rem; min-width: 100%; }
  th, td { padding: 0.5rem 0.6rem; }
  /* Search palette mobile : full screen */
  .search-palette { max-width: 95vw; }
  /* Modal cite : full screen */
  .cite-tabs { font-size: 0.75rem; }
  .cite-tab { padding: 0.5rem 0.7rem; }
  /* Lambda explorer (page /lambda/) */
  #lambdaCanvas { aspect-ratio: 8/5; }
  /* Mermaid diagrams scroll horizontal */
  .mermaid-container { overflow-x: auto; }
  /* Footer badges wrap proprement */
  .footer-badges { gap: 0.3rem; }
  .footer-badge { padding: 0.25rem 0.5rem; font-size: 0.7rem; }
  /* Lean ↔ Math : 1 col en mobile */
  .lean-math-pair { grid-template-columns: 1fr; }
  /* TOC : déjà cachée < 1280px */
}

/* Mobile petit ≤ 480px */
@media (max-width: 480px) {
  .topbar-inner { padding: 0.5rem 0.7rem; }
  .brand span:not(.brand-mark) { display: none; } /* juste le Λ visible */
  .brand-mark { width: 36px; height: 36px; }
  .toolbar-actions .btn-icon { padding: 0.3rem 0.5rem; font-size: 0.72rem; }
  .hero-banner-eyebrow { font-size: 0.65rem; padding: 0.3rem 0.6rem; }
  .hero-banner-title { font-size: 1.2rem; }
  section { padding: 2rem 1rem; }
  .hero { padding: 2.5rem 1rem 2rem; }
  .key-stats { grid-template-columns: 1fr; }
  /* Card 1 col */
  .card-grid { grid-template-columns: 1fr; gap: 1rem; }
  .card { padding: 1.2rem; }
  .card h3 { font-size: 1rem; }
  /* Table : encore plus compact */
  table { font-size: 0.72rem; }
  th, td { padding: 0.4rem 0.45rem; }
  /* Mermaid diagrams */
  .mermaid { font-size: 0.7rem; }
}

/* Touch screens : agrandir les zones cliquables */
@media (hover: none) and (pointer: coarse) {
  .toc { display: none !important; } /* Pas de hover sur tactile */
  .btn-icon { min-height: 36px; min-width: 36px; }
  .nav a { min-height: 36px; display: inline-flex; align-items: center; }
}

/* --- Print --- */
@media print {
  .topbar, footer, .toolbar-actions, .filter-bar { display: none !important; }
  body { background: white; color: black; }
  .card, .test-card, .highlight, table, .mermaid-container, .chart-container, .lockbox {
    background: white !important;
    color: black !important;
    border: 1px solid #ccc !important;
    page-break-inside: avoid;
  }
  h1, h2, h3, p, td, th { color: black !important; }
  a { color: black !important; text-decoration: underline; }
  .badge { border: 1px solid #666 !important; color: black !important; background: #eee !important; }
  pre { background: #f5f5f5 !important; color: #333 !important; }
  pre code { color: #333 !important; }
}

/* --- Utility --- */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); }
.right { text-align: right; }

/* Inter + Crimson fonts via Google Fonts CDN (optimal load) */
