/* ════════════════════════════════════════════════════════════════
   RULES EXPLORER — Core Rules V11
   Reprend la direction « Cogitator » de l'app Missions Primaires
   (or terni, rouge sang, hairlines, micro-labels mono). Thème scopé
   à .re-wrap pour ne pas affecter le header/footer partagés.
   ════════════════════════════════════════════════════════════════ */

.re-wrap {
  --bg:      #14120f;
  --bg2:     #191613;
  --panel:   #1e1b17;
  --panel2:  #26221c;
  --line:    #322d25;
  --line2:   #423a2e;
  --text:    #e9e4d8;
  --muted:   #a59c8a;
  --muted2:  #7a7263;

  --gold:        #c5a059;
  --gold-bright: #e2c685;
  --gold-dim:    #8a7244;
  --red:         #a4322b;
  --red-bright:  #c8453c;

  --radius:  10px;
  --radius2: 6px;
  --shadow:    0 12px 32px rgba(0,0,0,.45);
  --shadow-lg: 0 24px 70px rgba(0,0,0,.6);

  --font:  'Space Grotesk', 'Segoe UI', sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --u: 1rem;

  font-family: var(--font);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  max-width: 1280px;
  margin: 0 auto;
  padding: calc(var(--u) * 1.2) clamp(16px, 3vw, 36px) calc(var(--u) * 3);
}
html:not(.dark) .re-wrap {
  --bg:      #e9e5dc;
  --bg2:     #e2ddd2;
  --panel:   #faf8f3;
  --panel2:  #f0ece3;
  --line:    #d6cfc0;
  --line2:   #c2b9a5;
  --text:    #1d1a15;
  --muted:   #6e6657;
  --muted2:  #948a76;
  --red:     #99281f;
  --gold-dim:#a98c52;
  --shadow:    0 8px 24px rgba(40,32,16,.14);
  --shadow-lg: 0 24px 60px rgba(40,32,16,.22);
}

.re-wrap button, .re-wrap select, .re-wrap input { font-family: inherit; }

/* texture discrète : fines lignes horizontales quasi invisibles */
body.ornaments::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, color-mix(in srgb, var(--text) 1.4%, transparent) 3px 4px);
}
.page { position: relative; z-index: 1; }

/* ───────── labels & entêtes partagés ───────── */
.sec-kicker {
  font-family: var(--mono); font-size: .66rem; letter-spacing: .26em;
  text-transform: uppercase; color: var(--gold);
  display: flex; align-items: center; gap: 10px; margin-bottom: 7px;
}
.sec-hd { margin: 0 0 calc(var(--u) * .9); }
.sec-hd--row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sec-hd h2 { font-size: 1.25rem; font-weight: 700; letter-spacing: .01em; }
.hint { color: var(--muted); font-size: .84rem; margin-top: 3px; }

.empty, .loading {
  color: var(--muted); font-size: .86rem; text-align: center;
  padding: calc(var(--u) * 1.4);
  border: 1px dashed var(--line2); border-radius: var(--radius);
}
.loading { border: none; text-align: left; padding: calc(var(--u) * .5) 0; }

/* ───────── barre d'outils : recherche + langue ───────── */
.re-toolbar {
  display: flex; align-items: center; gap: calc(var(--u) * .8);
  margin-bottom: calc(var(--u) * 1.4); flex-wrap: wrap;
}
.re-search {
  flex: 1; min-width: 240px; position: relative;
  display: flex; align-items: center;
}
.re-search-ico {
  position: absolute; left: 13px; color: var(--muted2); font-size: 1.1rem; pointer-events: none;
}
.re-search input {
  width: 100%; padding: 12px 38px 12px 38px;
  border: 1px solid var(--line2); border-radius: var(--radius2);
  background: var(--panel); color: var(--text); font-size: .95rem;
  transition: border-color .15s;
}
.re-search input:focus { outline: none; border-color: var(--gold); }
.re-clear {
  position: absolute; right: 8px; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1.4rem; line-height: 1; padding: 0 6px; transition: color .15s;
}
.re-clear:hover { color: var(--gold-bright); }

/* ───────── switch langue FR/EN ───────── */
.lang-switch { display: inline-flex; border: 1px solid var(--line2); border-radius: var(--radius2); overflow: hidden; }
.lang-switch button {
  background: transparent; color: var(--muted); cursor: pointer; border: none;
  font-family: var(--mono); font-size: .72rem; font-weight: 600; letter-spacing: .08em;
  padding: 9px 14px; transition: background .15s, color .15s;
}
.lang-switch button + button { border-left: 1px solid var(--line2); }
.lang-switch button:hover { color: var(--gold-bright); }
.lang-switch button.is-active { background: var(--gold); color: #1a1a1a; }

/* ───────── disposition générale ───────── */
.re-layout { display: grid; grid-template-columns: minmax(0, 270px) minmax(0, 1fr); gap: calc(var(--u) * 1.6); align-items: start; }
@media (max-width: 860px) { .re-layout { grid-template-columns: 1fr; } }

/* ───────── sidebar sections ───────── */
.re-sidebar { position: sticky; top: calc(var(--u) * 1); }
@media (max-width: 860px) { .re-sidebar { position: static; } }
.re-sections { display: flex; flex-direction: column; gap: 3px; max-height: 76vh; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
@media (max-width: 860px) { .re-sections { max-height: 320px; } }
.re-sec {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: var(--radius2);
  padding: 9px 11px; transition: background .14s, border-color .14s, color .14s;
}
.re-sec:hover { background: var(--panel); border-color: var(--line); }
.re-sec.is-active { background: color-mix(in srgb, var(--gold) 12%, var(--panel)); border-color: var(--gold-dim); }
.re-sec-idx { font-family: var(--mono); font-size: .72rem; color: var(--gold-dim); flex: none; width: 1.6em; }
.re-sec.is-active .re-sec-idx { color: var(--gold-bright); }
.re-sec-name { flex: 1; min-width: 0; font-size: .88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.re-sec-n { font-family: var(--mono); font-size: .7rem; color: var(--muted2); flex: none; }

/* ───────── liste des règles ───────── */
.re-count { font-family: var(--mono); font-size: .74rem; letter-spacing: .06em; color: var(--muted); white-space: nowrap; }
.re-list { display: flex; flex-direction: column; gap: 4px; }
.re-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-left: 3px solid var(--gold-dim); border-radius: var(--radius2);
  padding: 11px 13px; transition: border-color .14s, transform .12s, background .14s;
}
.re-row:hover { transform: translateX(2px); border-left-color: var(--gold); border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); }
.re-row-num { font-family: var(--mono); font-size: .82rem; font-weight: 600; color: var(--gold-bright); flex: none; width: 3.3em; letter-spacing: .03em; }
.re-row-title { flex: 1; min-width: 0; font-size: .92rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.re-row-sec { font-family: var(--mono); font-size: .64rem; color: var(--muted2); border: 1px solid var(--line2); padding: 2px 6px; border-radius: 3px; flex: none; }
.re-row-ver { font-family: var(--mono); font-size: .68rem; color: var(--muted2); flex: none; }

/* ───────── modale détail ───────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8,6,4,.72); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; z-index: 1; width: min(680px, 94vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--gold-dim); border-radius: var(--radius);
  padding: calc(var(--u) * 1.6) calc(var(--u) * 1.7) calc(var(--u) * 1.7);
  box-shadow: var(--shadow-lg); animation: reModalIn .2s ease;
}
@keyframes reModalIn { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .modal-card { animation: none; } }
body.ornaments .modal-card::before, body.ornaments .modal-card::after { content: ''; position: absolute; width: 18px; height: 18px; pointer-events: none; }
body.ornaments .modal-card::before { top: 7px; left: 7px; border-top: 2px solid var(--gold); border-left: 2px solid var(--gold); }
body.ornaments .modal-card::after { bottom: 7px; right: 7px; border-bottom: 2px solid var(--gold); border-right: 2px solid var(--gold); }
.modal-close { position: absolute; top: 12px; right: 14px; z-index: 2; background: none; border: none; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; transition: color .15s; }
.modal-close:hover { color: var(--gold-bright); }

.re-detail-head { border-left: 4px solid var(--gold); padding-left: 14px; margin-bottom: calc(var(--u) * 1.1); }
.re-detail-toprow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-right: 30px; }
.re-detail-lang { flex: none; }
.re-detail-meta { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.re-detail-num { font-family: var(--mono); font-size: 1rem; font-weight: 600; color: var(--gold-bright); letter-spacing: .04em; }
.re-detail-sec { font-family: var(--mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.re-detail-title { font-size: 1.6rem; font-weight: 700; line-height: 1.1; margin: 6px 0 10px; text-wrap: pretty; }
.re-badges { display: flex; flex-wrap: wrap; gap: 7px; }
.re-badge {
  font-family: var(--mono); font-size: .66rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--gold-bright); border: 1px solid var(--gold-dim); padding: 3px 8px; border-radius: 3px;
}
.re-badge--muted { color: var(--muted); border-color: var(--line2); text-transform: none; letter-spacing: .02em; }
.re-badge--doc { color: var(--muted); border-color: var(--line2); text-transform: none; letter-spacing: .02em; }

.re-body { white-space: pre-wrap; line-height: 1.6; font-size: .95rem; color: var(--text); }

/* références XX.XX cliquables dans le corps */
.re-ref {
  color: var(--gold-bright); text-decoration: none; cursor: pointer; font-weight: 600;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  border-bottom: 1px dashed var(--gold-dim); border-radius: 2px;
  padding: 0 2px; transition: background .12s, color .12s, border-color .12s;
}
.re-ref:hover, .re-ref:focus-visible {
  color: #fff; border-bottom-color: var(--gold-bright);
  background: color-mix(in srgb, var(--gold) 18%, transparent); outline: none;
}

/* bouton « Retour » (navigation entre règles référencées) */
.re-back {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line2); border-radius: var(--radius2);
  font-family: var(--mono); font-size: .72rem; letter-spacing: .06em;
  padding: 6px 11px; margin-bottom: calc(var(--u) * .8);
  transition: border-color .15s, color .15s;
}
.re-back:hover { border-color: var(--gold); color: var(--gold-bright); }

.re-history { margin-top: calc(var(--u) * 1.3); border-top: 1px solid var(--line); padding-top: calc(var(--u) * .8); }
.re-history summary {
  cursor: pointer; font-family: var(--mono); font-size: .72rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--gold); list-style: none;
}
.re-history summary::-webkit-details-marker { display: none; }
.re-history summary::before { content: '▸ '; color: var(--gold-dim); }
.re-history[open] summary::before { content: '▾ '; }
.re-rev-list { margin-top: calc(var(--u) * .7); display: flex; flex-direction: column; gap: 8px; }
.re-rev { display: flex; gap: 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px dashed var(--line2); }
.re-rev:last-child { border-bottom: none; }
.re-rev-ver { font-family: var(--mono); font-size: .8rem; font-weight: 600; color: var(--gold-bright); flex: none; width: 3em; }
.re-rev-main { flex: 1; min-width: 0; }
.re-rev-line { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.re-rev-date { font-family: var(--mono); font-size: .76rem; color: var(--text); }
.re-rev-doc { font-size: .82rem; color: var(--muted); }
.re-rev-note { font-size: .82rem; color: var(--muted); margin-top: 2px; font-style: italic; }
.re-rev-empty { color: var(--muted); font-size: .84rem; }
