/* Religio Mundi — feuille de style
   Concept : un atlas sobre ; la carte et la frise sont les pièces maîtresses, les fiches s'ouvrent en panneau latéral.
   Couleurs d'aire = données ; l'accent de l'interface reste neutre (bleu encre du logo). */
:root {
  --bg: #f1f4f7;
  --surface: #ffffff;
  --surface-2: #e8edf2;
  --fg: #1b2430;
  --muted: #5b6775;
  --line: #d3dae2;
  --accent: #2f5f8a;
  --accent-fg: #ffffff;
  --land: #dfe5ea;
  --land-line: #c2ccd6;
  --sea: #f1f4f7;
  --shadow: 0 10px 30px rgba(20, 30, 45, .12);
  --font-display: "Fraunces", "Georgia", serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  /* couleurs d'aire (données) */
  --a-christianisme: #4a7fb5; --a-islam: #3f9a8f; --a-judaisme: #7d6fc2; --a-abrahamique: #a07cc0;
  --a-hindouisme: #d49a3a; --a-bouddhisme: #c8684f; --a-dharmique: #e0955a; --a-iranienne: #a4568e;
  --a-asie: #6fa15c; --a-monde: #4f9a7c; --a-afrique: #3f8f6e; --a-ameriques: #2f8a94; --a-oceanie: #2b9aa8;
  --a-antiquite: #b48a6a; --a-europe: #8c8565; --a-prehistoire: #7a7f86; --a-autre: #9aa3ad;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121820; --surface: #1a222c; --surface-2: #232d39; --fg: #e6e9ed; --muted: #9aa6b3; --line: #2d3947;
    --accent: #8fb6dc; --accent-fg: #0f1721; --land: #222c38; --land-line: #334151; --sea: #121820;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121820; --surface: #1a222c; --surface-2: #232d39; --fg: #e6e9ed; --muted: #9aa6b3; --line: #2d3947;
  --accent: #8fb6dc; --accent-fg: #0f1721; --land: #222c38; --land-line: #334151; --sea: #121820;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 15px; line-height: 1.5; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: 1.15; text-wrap: balance; margin: 0; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* --- en-tête ------------------------------------------------------------------- */
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 8px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand h1 { font-size: 1.25rem; }
.brand small { display: block; font-family: var(--font-body); font-size: .72rem; color: var(--muted); letter-spacing: .04em; }
.search { flex: 1 1 220px; min-width: 0; position: relative; }
.search input { width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); font: inherit; }
.sugg { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; z-index: 20; }
.sugg button { display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; cursor: pointer; }
.sugg button:hover, .sugg button:focus { background: var(--surface-2); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--fg); font-weight: 600; }

/* --- vues ------------------------------------------------------------------------- */
main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px 48px; max-width: 1400px; margin: 0 auto; }
.view { display: grid; gap: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.toolbar select, .toolbar input[type="text"] { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); font: inherit; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); color: var(--fg); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c, var(--muted)); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend button { border: 1px solid transparent; background: var(--surface); cursor: pointer; }
.legend button[aria-pressed="false"] { opacity: .45; }
.legend button:hover { border-color: var(--line); }

/* carte */
.map-wrap { position: relative; background: var(--sea); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.map-wrap svg { display: block; width: 100%; height: auto; max-width: 100%; aspect-ratio: 1.9; touch-action: none; }
.map-wrap .land { fill: var(--land); stroke: var(--land-line); stroke-width: .5; }
.map-wrap .pt { stroke: var(--surface); stroke-width: 1; cursor: pointer; }
.map-wrap .pt:hover { stroke: var(--fg); }
.map-wrap .lieu { fill: none; stroke: var(--fg); stroke-width: 1; cursor: pointer; }
.map-wrap .lbl { font-size: 10px; fill: var(--fg); paint-order: stroke; stroke: var(--sea); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.map-ctl { position: absolute; right: 8px; top: 8px; display: grid; gap: 4px; }
.map-ctl button { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .85rem; box-shadow: var(--shadow); max-width: 260px; }
.era { display: grid; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.era-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.era-head strong { font-family: var(--font-display); font-size: 1.4rem; font-weight: 500; }
.era input[type="range"] { width: 100%; accent-color: var(--accent); }
.era-ticks { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); }
.era-ticks span { flex: 1; text-align: center; }
.era-ticks span:first-child { text-align: left; } .era-ticks span:last-child { text-align: right; }
.era-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.era-presets button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: .78rem; cursor: pointer; }
.era-presets button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* frise */
.frise-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.frise-wrap svg { display: block; min-width: 900px; }
.frise-wrap .bar { cursor: pointer; }
.frise-wrap .bar:hover rect { stroke: var(--fg); }
.frise-wrap .bar text { font-size: 11px; fill: var(--fg); pointer-events: none; }
.frise-wrap .grp { font-family: var(--font-display); font-size: 14px; fill: var(--fg); }
.frise-wrap .axis text { font-family: var(--font-mono); font-size: 10px; fill: var(--muted); }
.frise-wrap .axis line { stroke: var(--line); }
.frise-wrap .open-end { stroke: var(--surface); stroke-width: 2; }

/* liste */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; text-align: left; cursor: pointer; display: grid; gap: 6px; min-width: 0; }
.card:hover { border-color: var(--accent); }
.card h3 { font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .85rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: .78rem; color: var(--muted); }
.count { color: var(--muted); font-size: .85rem; }

/* fiche (panneau) */
.panel { position: fixed; inset: calc(env(safe-area-inset-top, 0px) + var(--top-h, 56px)) 0 0 auto; width: min(560px, 100%); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 30; overflow-y: auto; transform: translateX(100%); transition: transform .25s ease; padding-right: env(safe-area-inset-right, 0px); }
.panel.open { transform: none; }
.panel-in { padding-left: 20px; padding-right: 20px; padding-block: 16px 40px; display: grid; gap: 18px; }
.panel-head { display: grid; gap: 8px; position: sticky; top: 0; background: var(--surface); padding-block: 4px 10px; border-bottom: 1px solid var(--line); z-index: 1; }
.panel-head .row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.panel-head h2 { font-size: 1.7rem; }
.close { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; flex: none; }
.sec { display: grid; gap: 6px; }
.sec h3 { font-size: 1.05rem; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.sec p { margin: 0; }
.kv { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 4px 12px; font-size: .92rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; }
.src { font-size: .75rem; color: var(--muted); }
.badge { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 4px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.warn { background: color-mix(in srgb, var(--a-hindouisme) 22%, var(--surface-2)); color: var(--fg); }
.notice { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: .85rem; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.links button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px 3px 6px; font-size: .82rem; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.links button:hover { border-color: var(--accent); }
.links .rel { color: var(--muted); font-size: .72rem; }
.list { margin: 0; padding-left: 18px; display: grid; gap: 3px; font-size: .92rem; }
.list li span { color: var(--muted); font-size: .8rem; }
.intro { font-size: .95rem; max-width: 65ch; }
.intro-more { white-space: pre-line; }

/* pied de page */
.foot { border-top: 1px solid var(--line); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 14px calc(14px + env(safe-area-inset-bottom, 0px)); display: flex; flex-wrap: wrap; gap: 6px 20px; justify-content: center; font-size: .8rem; color: var(--muted); text-align: center; }
.foot strong { color: var(--fg); font-weight: 600; }

/* à propos */
.prose { max-width: 70ch; display: grid; gap: 12px; }
.prose h2 { font-size: 1.5rem; }
.prose h3 { font-size: 1.1rem; margin-top: 8px; }
.prose table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.table-wrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--font-display); font-size: 1.6rem; font-weight: 500; }
.stat span { font-size: .78rem; color: var(--muted); }

@media (max-width: 640px) {
  .brand small { display: none; }
  .tabs { width: 100%; justify-content: space-between; }
  .tabs button { padding: 6px 8px; font-size: .9rem; }
  .map-wrap svg { aspect-ratio: 1.3; }
  .kv { grid-template-columns: 1fr; }
}
