:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #5c5c5c;
  --line: #d9d6cf;
  --accent: #2f4f4f;
  --rust: #8a3b2e;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 3.2rem;
}

body {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}

.wrap {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---------- entête ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 2.75rem 0 2rem;
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.site-header h1 {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.subtitle {
  margin: 0.75rem 0 0;
  color: var(--muted);
  max-width: 46rem;
}

.subtitle a {
  color: var(--accent);
}

.meta {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

/* ---------- sommaire ---------- */

.toc {
  position: sticky;
  top: 0;
  z-index: 900;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toc .wrap {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  overflow-x: auto;
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
}

.toc a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  padding: 0.25rem 0.6rem;
  white-space: nowrap;
  border: 1px solid transparent;
}

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

/* ---------- sections ---------- */

main {
  padding: 2rem 0 3rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1.75rem;
  margin-bottom: 1.75rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.3rem;
  font-weight: 600;
}

.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.panel-head h2 {
  margin: 0;
}

.explain {
  margin: 0 0 1.25rem;
  color: #3d3d3d;
  max-width: 52rem;
}

.explain strong {
  color: var(--text);
}

/* ---------- cartes de stats ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  border-top: 2px solid var(--accent);
  padding-top: 0.5rem;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
}

.stat-label {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- graphiques ---------- */

.chart-box {
  margin-bottom: 1rem;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.canvas-holder {
  position: relative;
  height: 280px;
}

[data-chart="chart-timeline"] {
  height: 260px;
}

[data-chart="chart-lengths"],
[data-chart="chart-ages"] {
  height: 240px;
}

[data-chart="chart-comparison"] {
  height: 320px;
}

[data-chart="chart-clusters"] {
  height: 220px;
}

canvas {
  max-width: 100%;
}

/* ---------- carte ---------- */

#map {
  height: 460px;
  border: 1px solid var(--line);
  z-index: 1;
}

/* ---------- onglets ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab {
  border: 1px solid var(--line);
  background: transparent;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

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

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  position: relative;
}

/* ---------- clusters / thèmes ---------- */

.clusters {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.cluster-card {
  border: 1px solid var(--line);
  padding: 0.75rem 1rem;
}

.cluster-card h4 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.keywords {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---------- concordancier ---------- */

.kwic {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 420px;
  overflow-y: auto;
}

.kwic-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 3fr;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid #eee;
  font-size: 0.9rem;
}

.kwic-name {
  color: var(--muted);
}

.kwic-ctx mark {
  background: #e7e0c9;
  padding: 0 0.15rem;
}

/* ---------- recherche & filtres ---------- */

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

.search input,
.filters select {
  border: 1px solid var(--line);
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.92rem;
  background: var(--bg);
}

.search input {
  width: min(260px, 100%);
}

.hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- tableau ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.45rem;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

th[data-sort] {
  cursor: pointer;
}

th[data-sort]:hover {
  color: var(--accent);
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f3f1ec;
}

.groups-cell {
  font-size: 0.84rem;
  color: var(--muted);
}

/* ---------- méthode ---------- */

.method-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.method-grid p {
  margin: 0;
  font-size: 0.94rem;
  color: #3d3d3d;
}

.method-grid code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.05rem 0.3rem;
}

.book-cite {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  background: var(--bg);
}

.book-cite p {
  margin: 0;
  font-size: 0.94rem;
}

.book-cite a {
  color: var(--accent);
}

/* ---------- dialogue lettre ---------- */

dialog {
  border: 1px solid var(--line);
  padding: 1.5rem;
  max-width: 760px;
  width: calc(100% - 2rem);
  max-height: 85vh;
  font: inherit;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

dialog h3 {
  margin: 0 0 0.25rem;
  padding-right: 2rem;
}

.dialog-meta {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-bio {
  margin: 0 0 1rem;
  font-size: 0.92rem;
  color: #3d3d3d;
  border-left: 3px solid var(--line);
  padding-left: 0.75rem;
}

#dialog-text {
  white-space: pre-wrap;
  font-family: inherit;
  margin: 0;
  max-height: 45vh;
  overflow: auto;
  line-height: 1.65;
}

.dialog-link {
  margin: 1rem 0 0;
  font-size: 0.9rem;
}

.dialog-link a {
  color: var(--accent);
}

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

/* ---------- pied de page ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0 2rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer a {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 640px) {
  .site-header h1 {
    font-size: 1.5rem;
  }

  .panel {
    padding: 1.1rem;
  }

  #map {
    height: 340px;
  }

  .kwic-row {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}
