:root {
  --bg: #f6f1e7; --bg2: #efe7d8; --card: #fffdf8; --fg: #2a241e; --muted: #85786a; --line: #d9ccb6;
  --accent: #8a4b24; --accent-soft: #f1e2d2;
  --m: #3f6c8f; --m-soft: #e6eef5; --f: #a2486b; --f-soft: #f6e6ec;
  --ok: #2f7d4a; --mid: #b07d16; --low: #b1a596; --bad: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 4px 14px rgba(60, 40, 20, .08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1814; --bg2: #221e19; --card: #2a251f; --fg: #eee6da; --muted: #a89a89; --line: #43392f;
    --accent: #e0a874; --accent-soft: #3a2c20;
    --m: #8fb6d6; --m-soft: #24303a; --f: #e09ab5; --f-soft: #3a2830;
    --low: #6f6458; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); line-height: 1.5;
       display: flex; flex-direction: column; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; }

/* ---------- En-tête ---------- */
.top { display: flex; align-items: center; gap: 12px 24px; flex-wrap: wrap; padding: 10px 16px;
       background: var(--card); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg);
         font-family: var(--serif); font-size: 1.3rem; font-weight: 600; }
.brand-mark { color: var(--accent); font-size: 1.4rem; }
.tabs { display: flex; gap: 4px; }
.tabs a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 500; }
.tabs a.actif { background: var(--accent-soft); color: var(--accent); }
.search { position: relative; margin-left: auto; flex: 0 1 280px; min-width: 160px; }
.search input { width: 100%; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
                background: var(--bg); color: var(--fg); font: inherit; }
.suggest { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--card);
           border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 320px; overflow: auto; }
.suggest a { display: block; padding: 7px 12px; text-decoration: none; color: var(--fg); }
.suggest a:hover, .suggest a.sel { background: var(--accent-soft); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.vue { flex: 1; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }

/* ---------- Barre d'outils de l'arbre ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
           padding: 10px 16px; }
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--fg); box-shadow: var(--shadow); }
.tools { display: flex; gap: 6px; }
.tools button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 12px; cursor: pointer; min-width: 34px; }
.tools button:hover { border-color: var(--accent); }

/* ---------- Scène de l'arbre ---------- */
.stage { flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none; min-height: 360px;
         background: radial-gradient(circle at 50% 100%, var(--bg2), var(--bg) 70%); outline: none; }
.stage.drag { cursor: grabbing; }
.canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas svg { position: absolute; left: 0; top: 0; overflow: visible; }
.canvas svg path { fill: none; stroke: var(--line); stroke-width: 2; }

.carte { position: absolute; width: 168px; height: 70px; background: var(--card); border-radius: 10px;
         box-shadow: var(--shadow); border: 1px solid var(--line); border-top: 4px solid var(--low);
         padding: 6px 10px 6px; cursor: pointer; user-select: none; display: flex; flex-direction: column;
         justify-content: center; transition: transform .12s ease, border-color .12s; }
.carte:hover { transform: translateY(-2px); border-color: var(--accent); }
.carte.m { border-top-color: var(--m); }
.carte.f { border-top-color: var(--f); }
.carte.racine { outline: 2px solid var(--accent); outline-offset: 2px; }
.carte.choisie { background: var(--accent-soft); }
.carte .pr { font-family: var(--serif); font-size: .95rem; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.carte .nm { font-weight: 700; letter-spacing: .02em; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.carte .an { font-size: .75rem; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.carte .so { position: absolute; top: 3px; right: 7px; font-size: .65rem; color: var(--muted); }
.carte.vide { border-style: dashed; border-top-width: 1px; background: transparent; box-shadow: none; color: var(--muted);
              align-items: center; cursor: default; font-size: .8rem; height: 46px; }
.carte.vide:hover { transform: none; border-color: var(--line); }
.carte.plus::after { content: "▲"; position: absolute; top: -16px; left: 50%; transform: translateX(-50%);
                     font-size: .6rem; color: var(--muted); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--low); flex: none; }
.dot.prouve { background: var(--ok); } .dot.deduit { background: var(--mid); } .dot.indice { background: var(--low); }
.legende { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; padding: 8px 16px; font-size: .8rem; color: var(--muted); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Panneau latéral (fiche) ---------- */
.panneau { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--card);
           border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0,0,0,.12); z-index: 10;
           overflow-y: auto; padding: 20px 22px 40px; }
.fermer { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; font-size: 1.6rem;
          line-height: 1; cursor: pointer; color: var(--muted); }
.fiche-tete { display: flex; gap: 14px; align-items: center; margin: 4px 0 14px; }
.avatar { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-family: var(--serif);
          font-size: 1.3rem; color: #fff; background: var(--low); flex: none; }
.avatar.m { background: var(--m); } .avatar.f { background: var(--f); }
.fiche h1 { font-family: var(--serif); font-size: 1.35rem; margin: 0; line-height: 1.2; }
.fiche h1 b { letter-spacing: .02em; }
.fiche h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bouton { display: inline-block; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
          text-decoration: none; color: var(--fg); font-size: .9rem; cursor: pointer; }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
.chrono { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.chrono li { position: relative; padding: 0 0 12px 16px; }
.chrono li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
                     background: var(--card); border: 2px solid var(--line); }
.chrono li.prouve::before { border-color: var(--ok); background: var(--ok); }
.chrono li.deduit::before { border-color: var(--mid); }
.chrono .quoi { font-weight: 600; }
.chrono .src { font-size: .78rem; color: var(--muted); }
.badge { display: inline-block; font-size: .68rem; padding: 0 7px; border-radius: 10px; margin-left: 6px; vertical-align: 1px;
         background: var(--bg2); color: var(--muted); border: 1px solid var(--line); }
.badge.prouve { background: var(--ok); color: #fff; border-color: var(--ok); }
.badge.deduit { background: var(--mid); color: #fff; border-color: var(--mid); }
.liens { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.liens a { display: flex; gap: 8px; align-items: center; text-decoration: none; color: var(--fg); padding: 6px 8px;
           border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.liens a:hover { border-color: var(--accent); }
.liens .role { font-size: .75rem; color: var(--muted); min-width: 58px; }
.note { background: var(--bg); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 0 8px 8px 0;
        font-family: var(--serif); white-space: pre-line; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.docs a { display: block; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.docs img { display: block; width: 100%; height: 90px; object-fit: cover; }

/* ---------- Index ---------- */
#vue-index { padding: 16px; max-width: 1100px; width: 100%; margin: 0 auto; overflow-y: auto; }
#vue-index h1 { font-family: var(--serif); font-weight: 600; }
.lettre { font-family: var(--serif); font-size: 1.2rem; color: var(--accent); border-bottom: 1px solid var(--line); margin: 22px 0 8px; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.grille a { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--card);
            border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--fg); }
.grille a:hover { border-color: var(--accent); }

.pied { text-align: center; padding: 8px 16px 12px; font-size: .78rem; color: var(--muted); }

@media (max-width: 640px) {
  .top { gap: 8px 12px; }
  .search { flex-basis: 100%; margin-left: 0; }
  .panneau { top: auto; height: 78vh; width: 100%; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; }
  .legende { font-size: .72rem; gap: 10px; }
}
