/* ======================= BESTIAIRE ======================= */

/*
 * Page à part, comme la Boutique : le cabinet des trophées d'un chasseur. Le
 * décor passe sous les dégradés, qui l'assombrissent : ce sont les monstres
 * qui doivent ressortir, pas les murs.
 */
#bestiary-screen {
    background:
        radial-gradient(ellipse 70% 50% at 50% -8%, rgba(79, 212, 138, 0.08), transparent 70%),
        linear-gradient(180deg, rgba(15, 15, 12, 0.8), rgba(9, 9, 6, 0.92)),
        url('../assets/backdrops/bg_bestiary.webp') center / cover no-repeat,
        var(--ink);
}

/* Titre et corps sur la même largeur, centrés. */
#bestiary-screen .page-head, .bestiary-body { width: 100%; max-width: 1240px; margin-left: auto; margin-right: auto; }

.bestiary-tally {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--line);
    border-radius: 999px;
}

.bestiary-tally small { font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-dim); }
.bestiary-tally .res-icon { width: 22px; height: 22px; display: inline-flex; }
.bestiary-tally .res-icon .ui-art { width: 100%; height: 100%; object-fit: contain; }
.bestiary-tally .res-value { font-variant-numeric: tabular-nums; color: var(--gold-lit); }
.bestiary-bar {
    width: 72px; height: 5px; border-radius: 3px; overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
}
.bestiary-bar i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: inherit; }

.bestiary-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 4px 24px;
}

.bestiary-worlds { display: flex; flex-direction: column; gap: 26px; }

/* ---- Un monde ---- */
.beast-world-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(217, 164, 65, 0.28);
}
.beast-world-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.05rem;
    letter-spacing: 0.08em;
    color: var(--gold-lit);
}
.beast-world-sub { font-size: 0.7rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/*
 * Les rangs se lisent en deux colonnes : piétaille et élites côte à côte, puis
 * les gardiens et le Gardien du Monde. Plus le rang monte, plus la carte
 * s'élargit — le Gardien du Monde a la plus grande.
 */
.beast-tiers { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 18px; }
.beast-group.tier-trash, .beast-group.tier-elite { grid-column: span 2; }
.beast-group.tier-boss { grid-column: span 3; }
.beast-group.tier-worldboss { grid-column: span 1; }
.beast-group-title {
    margin: 0 0 8px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.beast-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tier-worldboss .beast-grid { grid-template-columns: minmax(0, 1fr); }

/* ---- Une carte ---- */
.beast-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    /* Une fiche à la manière de Dofus 3 : panneau graphite, filet fin, et une
       lumière douce venue du haut pour détacher le monstre. */
    padding: 12px 10px 12px;
    background:
        radial-gradient(ellipse 80% 55% at 50% 34%, rgba(194, 232, 0, 0.07), transparent 70%),
        linear-gradient(180deg, #2d2e28, #1f1f1b);
    border: 1px solid var(--stone-500);
    border-radius: 8px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 6px 14px rgba(0, 0, 0, 0.45);
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.beast-card:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.beast-card:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
/* La carte ouverte se reconnaît à son liseré doré, posé sous le cadre. */
.beast-card.open { border-color: var(--lime); box-shadow: 0 0 0 1px var(--lime), 0 0 18px rgba(194, 232, 0, 0.25); }

/* Écusson de rang, épinglé dans l'angle de la fiche. */
.beast-tier { position: absolute; top: 8px; left: 8px; width: 30px; height: 30px; display: inline-flex; z-index: 1; }
.beast-tier .bs-ico-art { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6)); }

/*
 * Chaque monstre se tient sur son socle, comme une pièce de collection.
 *
 * Le socle (256 × 96) a sa face supérieure centrée aux deux tiers de sa hauteur
 * en partant du bas : c'est là que se posent les pieds, soit 0,24 × sa largeur.
 * L'image, carrée, est placée par son point d'appui (`--ax`, `--ay`, mesurés
 * sur chaque illustration) et non par sa boîte.
 */
.beast-art {
    --mob-h: 118px;
    --plinth-w: 150px;
    position: relative;
    width: 100%;
    height: calc(var(--mob-h) + var(--plinth-w) * 0.24 + 4px);
    background: url('../assets/ui/beast_plinth.webp') center bottom / var(--plinth-w) auto no-repeat;
}
/* Gardiens et Gardien du Monde partagent une rangée : même hauteur de carte. */
.tier-boss .beast-art,
.tier-worldboss .beast-art { --mob-h: 176px; --plinth-w: 190px; }
.beast-img {
    position: absolute;
    left: 50%;
    bottom: calc(var(--plinth-w) * 0.24);
    width: var(--mob-h);
    height: var(--mob-h);
    max-width: none;
    transform: translate(calc(var(--ax, 0.5) * -100%), calc((1 - var(--ay, 0.97)) * 100%));
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.6));
}
.beast-emoji { position: absolute; left: 50%; bottom: calc(var(--plinth-w) * 0.24); transform: translateX(-50%); font-size: 3.4rem; line-height: 1; }

.beast-name {
    font-family: var(--font-display);
    font-size: 0.82rem;
    color: #f0e6d2;
    text-align: center;
    text-wrap: balance;
}
.beast-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.64rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}
.beast-elem { display: inline-flex; width: 14px; height: 14px; }

/* Jamais croisé : une silhouette. C'est le vide qui donne envie de descendre. */
.beast-card.unknown .beast-img,
.bs-portrait.unknown .bs-portrait-img { filter: brightness(0) drop-shadow(0 0 1px rgba(160, 175, 210, 0.45)); opacity: 0.7; }
.beast-card.unknown .beast-emoji { filter: brightness(0); opacity: 0.6; }
.beast-card.unknown .beast-name { color: var(--text-dim); letter-spacing: 0.2em; }

/* ---- La fiche ---- */
/* La fiche est une page du carnet : parchemin sombre, coins de cuir épinglés. */
.bestiary-sheet {
    position: fixed;
    z-index: 9000;
    width: min(410px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    background: linear-gradient(180deg, #2d2e28, #1c1c19);
    border: 1px solid var(--stone-500);
    border-radius: 10px;
    padding: 18px 16px 16px;
    box-shadow: var(--lift), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    font-size: 0.78rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bs-close {
    position: absolute;
    top: 2px;
    right: 4px;
    width: 26px;
    height: 26px;
    border: 0;
    background: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
}
.bs-close:hover { color: #fff; }

.bs-head { display: flex; gap: 12px; align-items: center; }
.bs-portrait {
    --mob-h: 84px;
    --plinth-w: 96px;
    position: relative;
    flex: 0 0 104px;
    height: calc(var(--mob-h) + var(--plinth-w) * 0.24 + 4px);
    background: url('../assets/ui/beast_plinth.webp') center bottom / var(--plinth-w) auto no-repeat;
}
.bs-portrait-img {
    position: absolute;
    left: 50%;
    bottom: calc(var(--plinth-w) * 0.24);
    width: var(--mob-h);
    height: var(--mob-h);
    transform: translate(calc(var(--ax, 0.5) * -100%), calc((1 - var(--ay, 0.97)) * 100%));
}
.bs-ident { min-width: 0; display: flex; flex-direction: column; gap: 5px; padding-right: 18px; }
.bs-ident h3 { margin: 0; font-family: var(--font-display); font-size: 1rem; color: #f0e6d2; letter-spacing: 0.04em; }
.bs-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.bs-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    border: 1px solid var(--stone-500);
    color: var(--text-soft);
}
.bs-chip.tier-elite { border-color: rgba(166, 139, 255, 0.6); color: #c9b8ff; }
.bs-chip.tier-boss { border-color: rgba(255, 157, 92, 0.6); color: #ffb185; }
.bs-chip.tier-worldboss { border-color: var(--gold); color: var(--gold-lit); }
.bs-chip.elem { border-color: color-mix(in srgb, var(--elem) 60%, transparent); color: var(--elem); }
.bs-chip-ico { display: inline-flex; width: 15px; height: 15px; }
.bs-count { margin: 0; font-size: 0.66rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.bs-section { display: flex; flex-direction: column; gap: 6px; }
.bs-section h4 {
    margin: 0;
    font-size: 0.58rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--gold);
    font-weight: 700;
}
.bs-section h4 small { text-transform: none; letter-spacing: 0; color: var(--text-dim); font-weight: 400; font-size: 0.62rem; margin-left: 4px; }

.bs-where { margin: 0; display: flex; flex-direction: column; gap: 1px; }
.bs-where b { color: #f0e6d2; font-weight: 600; }
.bs-where span { color: var(--text-soft); font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.bs-hint { margin: 0; font-size: 0.68rem; color: var(--text-dim); font-style: italic; }

.bs-ico, .bs-tile-ico, .bs-intent-ico, .bs-loot-ico { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; }
.bs-ico-art { width: 100%; height: 100%; object-fit: contain; }

/* Valeurs : six cases égales, l'illustration puis le chiffre. */
.bs-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.bs-tile {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    column-gap: 6px;
    align-items: center;
    padding: 5px 7px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
}
.bs-tile-ico { grid-row: span 2; width: 20px; height: 20px; }
.bs-tile-label { font-size: 0.58rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.bs-tile b { font-family: var(--font-display); color: #fff; font-size: 0.86rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bs-tile small { grid-column: 1 / -1; font-size: 0.56rem; color: var(--text-dim); }

.bestiary-sheet .res-row { gap: 5px; }
.bestiary-sheet .res-cell { padding: 4px 3px; font-size: 0.7rem; }
.bestiary-sheet .res-ico { width: 17px; height: 17px; }

/* Cycle d'intentions : il se lit, donc il s'apprend. */
.bs-cycle { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.bs-intent {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px 2px 4px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.68rem;
}
.bs-intent.danger-0 { color: #a9c6f0; }
.bs-intent.danger-1 { color: #ffb185; }
.bs-intent.danger-2 { color: var(--blood-lit); }
.bs-intent-ico { width: 18px; height: 18px; }
.bs-arrow { color: var(--text-dim); }
.bs-loop { color: var(--text-dim); margin-left: 2px; }

/* Butin : la panoplie signature d'abord, puis le reste. */
.bs-loots { display: flex; flex-direction: column; gap: 4px; }
.bs-loot { padding: 5px 8px; border-radius: 7px; background: rgba(255, 255, 255, 0.03); }
.bs-loot.signature { background: rgba(217, 164, 65, 0.08); border: 1px solid rgba(217, 164, 65, 0.3); }
.bs-loot.signature.locked { opacity: 0.7; }
.bs-loot-line { display: flex; align-items: center; gap: 8px; }
.bs-loot-ico { width: 20px; height: 20px; }
.bs-loot-label { flex: 1; min-width: 0; display: flex; flex-direction: column; color: var(--text-soft); }
.bs-loot-label b { color: var(--gold-lit); font-weight: 600; }
.bs-loot-label small { font-size: 0.6rem; color: var(--text-dim); }
.bs-loot-pct {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: var(--font-display);
    color: #fff;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.bs-loot-pct small { font-family: inherit; font-size: 0.56rem; color: var(--text-dim); }
.bs-pieces { display: flex; gap: 5px; margin-top: 5px; }
.bs-piece {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(217, 164, 65, 0.25);
}
.bs-piece-art { max-width: 88%; max-height: 88%; object-fit: contain; }

@media (max-width: 1000px) {
    .beast-group.tier-trash, .beast-group.tier-elite,
    .beast-group.tier-boss, .beast-group.tier-worldboss { grid-column: 1 / -1; }
    .tier-worldboss .beast-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .beast-grid,
    .tier-worldboss .beast-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .beast-art { --mob-h: 96px; --plinth-w: 124px; }
    .tier-boss .beast-art, .tier-worldboss .beast-art { --mob-h: 110px; --plinth-w: 136px; }
    .beast-tier { width: 24px; height: 24px; }
    .bestiary-bar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .beast-card { transition: none; }
    .beast-card:hover { transform: none; }
}

/* L'écho de la créature (la Forge) : ses caractéristiques sous la ligne. */
.bs-echo-lignes { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 4px 0 0 2px; font-size: 0.78rem; color: var(--text-soft); }
.bs-echo-ligne { display: inline-flex; align-items: center; gap: 5px; }
