:root {
  color-scheme: dark;
  --fond: #0d0b12;
  --fond-carte: #181420;
  --fond-champ: #110e18;
  --bord: #3a3148;
  --or: #c9a45c;
  --or-clair: #e8cf94;
  --texte: #ece6f2;
  --texte-doux: #a79fb4;
  --bon: #6fcf97;
  --mauvais: #ef7b7b;
  --focus: #8fb8ff;
  --d-aptitude: #3e9d56;
  --d-maitrise: #d9b438;
  --d-amelioration: #4a8fd6;
  --d-difficulte: #7a4fb5;
  --d-defi: #b5342f;
  --d-contrainte: #2b2b2f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background-image: radial-gradient(120% 60% at 50% -10%, #241a33 0%, transparent 60%);
  min-height: 100vh;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: .02em; margin: 0 0 .4em; }
h1 { color: var(--or-clair); font-size: 1.6rem; }
h2 { font-size: 1.25rem; color: var(--or-clair); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .6em; }
a { color: var(--or-clair); }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-seul { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.evitement { position: absolute; left: 8px; top: -60px; background: var(--or); color: #000; padding: 8px 12px; z-index: 100; }
.evitement:focus { top: 8px; }

.entete { padding: 16px 16px 8px; max-width: 760px; margin: 0 auto; }
.resume { color: var(--texte-doux); margin: 0; font-size: .95rem; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; outline: none; }

.carte, .panneau > article {
  background: var(--fond-carte); border: 1px solid var(--bord); border-radius: 10px;
  padding: 16px; margin-bottom: 12px;
}
.aide { color: var(--texte-doux); font-size: .9rem; }
.erreur { color: var(--mauvais); min-height: 1.5em; margin-top: 8px; }

label { display: block; margin: 12px 0 4px; }
input, select {
  width: 100%; padding: 12px; font: inherit; color: var(--texte);
  background: var(--fond-champ); border: 1px solid var(--bord); border-radius: 8px; min-height: 44px;
}
.rangee { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
button, .bouton {
  font: inherit; min-height: 44px; padding: 10px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--or); color: var(--texte); background: transparent; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button.primaire { background: linear-gradient(#d8b66e, #a98440); color: #1a1208; font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }
.bouton { margin-top: 12px; }

.onglets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 14px; }
.onglets button { padding: 10px 4px; font-size: .95rem; border-color: var(--bord); }
.onglets button[aria-current="page"] { border-color: var(--or); color: var(--or-clair); background: #241d30; }

.grille { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.pastille { border: 1px solid var(--bord); border-radius: 8px; padding: 8px 10px; background: var(--fond-champ); }
.pastille small { display: block; color: var(--texte-doux); }
.valeur { font-size: 1.4rem; color: var(--or-clair); font-family: Georgia, serif; }
.dette { color: var(--mauvais); }
.tableau { width: 100%; border-collapse: collapse; }
.tableau th, .tableau td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--bord); }
.tableau td.num, .tableau th.num { text-align: right; }
.ligne-action { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-top: 10px; }
.ligne-action > div { flex: 1 1 110px; }
.badge { display: inline-block; padding: 0 8px; border-radius: 99px; border: 1px solid var(--bord); font-size: .85rem; }
.bon { color: var(--bon); } .mauvais { color: var(--mauvais); }
.compte { font-variant-numeric: tabular-nums; font-size: 1.3rem; color: var(--or-clair); }

.message {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: #2a2236; border: 1px solid var(--or); border-radius: 8px; padding: 10px 16px; z-index: 50;
}
.message:empty { display: none; }
.message.erreur-msg { border-color: var(--mauvais); }

/* ---- Écran de résolution (référence : jet de dés de Baldur's Gate 3) ---- */
.resolution {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow-y: auto; background: rgba(5, 4, 9, .88);
}
.cadre {
  position: relative; width: min(100%, 440px); text-align: center; padding: 28px 20px 22px;
  background: linear-gradient(#1b1526, #120e1a); border: 2px solid var(--or); border-radius: 18px;
  box-shadow: 0 0 0 4px #120e1a, 0 0 0 5px #7b6030, 0 20px 60px rgba(0, 0, 0, .7);
}
.cadre::before, .cadre::after {   /* filets dorés */
  content: ""; position: absolute; left: 24px; right: 24px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--or), transparent);
}
.cadre::before { top: 8px; } .cadre::after { bottom: 8px; }
.res-titre { font-size: 1.5rem; margin: 0; }
.res-sous-titre { color: var(--texte-doux); margin-bottom: 16px; }
.res-difficulte { margin: 8px 0 12px; }
.res-etiquette { display: block; font-size: .75rem; letter-spacing: .15em; text-transform: uppercase; color: var(--texte-doux); }
.res-chiffre { font-family: Georgia, serif; font-size: 2.2rem; color: #fff; }

.res-des { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; min-height: 80px; margin: 12px 0 16px; }
.de {
  width: 56px; height: 56px; display: grid; place-items: center; font-size: 1.1rem; font-weight: 700; color: #fff;
  background: var(--couleur, #555); position: relative; opacity: 0; transform: scale(.4) rotate(-90deg);
  transition: opacity .35s, transform .45s cubic-bezier(.2, .9, .3, 1.2);
}
.de.visible { opacity: 1; transform: none; }
.de.d6 { border-radius: 10px; }
.de.d8 { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); width: 64px; height: 64px; }
.de.d12 { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%); width: 64px; height: 64px; }
.de-aptitude { --couleur: var(--d-aptitude); } .de-maitrise { --couleur: var(--d-maitrise); color: #1a1208; }
.de-amelioration { --couleur: var(--d-amelioration); } .de-difficulte { --couleur: var(--d-difficulte); }
.de-defi { --couleur: var(--d-defi); } .de-contrainte { --couleur: var(--d-contrainte); border: 1px solid #666; }

.res-bonus { list-style: none; margin: 0 0 12px; padding: 0; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.res-bonus li {
  min-width: 82px; padding: 8px 6px; border: 1px solid var(--or); border-radius: 12px; background: #20182c;
  opacity: 0; transform: translateY(10px); transition: opacity .3s, transform .3s;
}
.res-bonus li.visible { opacity: 1; transform: none; }
.res-bonus .chiffre { display: block; font-weight: 700; font-size: 1.1rem; color: var(--or-clair); }
.res-bonus small { color: var(--texte-doux); }
.res-bonus li.contre .chiffre { color: var(--mauvais); }
.res-verdict { font-family: Georgia, serif; font-size: 1.4rem; margin: 8px 0 12px; }
.res-verdict.gagne { color: var(--bon); } .res-verdict.perdu { color: var(--mauvais); }

/* Cadre en arche, losanges d'ornement, lueurs de verdict (inspiré du prototype d20) */
.cadre {
  width: min(100%, 400px); padding: 48px 22px 24px; margin: auto;   /* centré, et défilable s'il est plus haut que l'écran */
  border-radius: 160px 160px 26px 26px / 95px 95px 26px 26px;
  box-shadow: 0 0 0 5px #0e0b14, 0 0 0 6.5px rgba(201, 164, 92, .5), 0 24px 70px rgba(0, 0, 0, .75),
              inset 0 0 50px rgba(120, 100, 210, .12);
  transition: box-shadow .7s;
}
.cadre.succes { box-shadow: 0 0 0 5px #0e0b14, 0 0 0 6.5px rgba(243, 220, 158, .8), 0 0 70px rgba(240, 195, 100, .35), inset 0 0 60px rgba(240, 195, 100, .12); }
.cadre.echec  { box-shadow: 0 0 0 5px #0e0b14, 0 0 0 6.5px rgba(190, 70, 60, .7), 0 0 70px rgba(200, 50, 40, .3), inset 0 0 60px rgba(200, 50, 40, .12); }
.cadre::before, .cadre::after {
  left: calc(50% - 7px); right: auto; width: 14px; height: 14px; transform: rotate(45deg);
  background: #15121f; border: 1.5px solid var(--or);
}
.cadre::before { top: -9px; bottom: auto; }
.cadre::after { bottom: -9px; top: auto; }
.cadre .res-difficulte { margin: 2px 0 6px; }
.cadre .res-chiffre { font-size: 1.8rem; line-height: 1.1; }
.cadre .res-sous-titre { margin-bottom: 8px; }
.res-epreuve { margin: 0; font-size: .7rem; letter-spacing: .25em; text-transform: uppercase; color: var(--texte-doux); }
.res-son { position: absolute; top: 14px; right: 18px; min-height: 36px; min-width: 36px; padding: 4px; border-color: var(--bord); font-size: 1rem; }
.res-barre {
  position: relative; height: 9px; margin: 10px -22px 0;
  border-top: 1px solid #7a5d2c; border-bottom: 1px solid #7a5d2c;
  background: repeating-linear-gradient(115deg, rgba(201, 164, 92, .55) 0 3px, transparent 3px 7px);
}
.res-scene { position: relative; margin: 6px 0 0; min-height: 90px; }
.res-zone { position: relative; width: 100%; }
.res-zone canvas { display: block; }
.res-etiquettes { position: absolute; inset: 0; pointer-events: none; }
.res-sym {
  position: absolute; transform: translate(-50%, -50%) scale(.3); opacity: 0; font-size: 1.35rem; font-weight: 700;
  color: #fff; text-shadow: 0 1px 4px #000, 0 0 10px rgba(0, 0, 0, .8); transition: opacity .25s, transform .3s cubic-bezier(.2, 1.6, .4, 1);
}
.res-sym.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.res-etincelles { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.res-etincelles i { position: absolute; width: 6px; height: 6px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
.res-total { min-height: 1.6em; margin: 4px 0 8px; font-family: Georgia, serif; font-size: 1.15rem; color: var(--or-clair); }
.pop { animation: pop .35s ease-out; }
@keyframes pop { 40% { transform: scale(1.18); } }
.res-bonus li.actif { border-color: var(--or-clair); box-shadow: 0 0 18px rgba(240, 200, 110, .5); transform: translateY(-4px); }
.res-verdict { animation: verdict .7s cubic-bezier(.2, 1.5, .4, 1) both; letter-spacing: .08em; text-transform: uppercase; font-size: 1.2rem; }
.res-verdict.gagne { background: linear-gradient(#fff5cf, #d6a447); -webkit-background-clip: text; background-clip: text; color: transparent; }
@keyframes verdict { from { opacity: 0; transform: scale(.5); } to { opacity: 1; transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .de, .res-bonus li, .res-sym { transition: none; transform: none; }
  .res-sym { transform: translate(-50%, -50%); }
  .res-verdict, .pop { animation: none; }
}
@media (max-width: 380px) {
  .onglets button { font-size: .85rem; }
}
