:root {
  --bg: #14161f;
  --surface: #1d2030;
  --surface-2: #262a3d;
  --line: #33384f;
  --text: #eceef5;
  --muted: #9aa0b8;
  --gold: #e8b04a;
  --gold-soft: rgba(232, 176, 74, 0.16);
  --t-S: #ff6b6b;
  --t-A: #ff9f43;
  --t-B: #f7d154;
  --t-C: #7bd389;
  --t-D: #5fa8ff;
  --t-E: #8f95ab;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--gold); }
img { display: block; }
.art { display: block; position: relative; border-radius: 50%; overflow: hidden; background: var(--surface-2); flex: 0 0 auto; }
.art img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.42); }

.wrap { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ── En-tête ── */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(20, 22, 31, 0.92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; }
h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; white-space: nowrap; }
h1 span { color: var(--gold); }
.help-btn {
  flex: 0 0 auto; align-self: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--gold); background: var(--gold-soft); color: var(--gold); font-weight: 800; font-size: 16px;
}
.meta { flex: 1; margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.3; text-align: right; }

main { padding-top: 14px; padding-bottom: 8px; }

/* ── Sélection des types ── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.panel-hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
.count { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 4px; }
.count.full { color: var(--gold); font-weight: 600; }
.link { white-space: nowrap; background: none; border: 0; padding: 6px 4px; color: var(--gold); font-weight: 600; font-size: 14px; }

.tribes { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.tribe {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 7px 2px 5px; min-height: 72px;
  background: var(--surface-2); border: 2px solid transparent; border-radius: 12px;
  font-size: 11.5px; color: var(--muted);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.tribe .art { width: 40px; height: 40px; }
.tribe img { filter: grayscale(0.85) brightness(0.75); transition: filter 0.15s; }
.tribe:active { transform: scale(0.96); }
.tribe.on { border-color: var(--gold); background: var(--gold-soft); color: var(--text); font-weight: 600; }
.tribe.on img { filter: none; }
.tribe.on .art { box-shadow: 0 0 0 2px var(--gold); }

/* ── Filtres ── */
.controls { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 12px 0 4px; }
.controls-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.link.small { font-size: 13px; padding: 2px 0; text-decoration: underline; text-underline-offset: 3px; }
.ctl { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.ctl-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ctl-row { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 12px; }
.ctl-row .ctl { flex: 1 1 260px; }
.mode-intro { margin: 8px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px;
}
.seg button {
  border: 0; background: none; border-radius: 9px;
  padding: 8px 4px; font-size: 13px; line-height: 1.2; color: var(--muted); text-align: center;
}
.seg button.on { background: var(--gold); color: #1a1406; font-weight: 700; }

.summary { color: var(--muted); font-size: 13px; margin: 10px 2px; }

/* ── Tiers ── */
.tier-group { margin-bottom: 18px; }
.tier-group h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 15px; color: var(--text); font-weight: 700; }
.tier-group h3 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.list { display: grid; gap: 10px; }
.tier-group > .comp + .comp { margin-top: 10px; }

.badge {
  flex: 0 0 auto; display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  font-weight: 800; font-size: 17px; color: #14161f; background: var(--t-E);
}
.tier-group h3 .badge { width: 26px; height: 26px; font-size: 14px; border-radius: 8px; }
[data-tier="S"].badge { background: var(--t-S); }
[data-tier="A"].badge { background: var(--t-A); }
[data-tier="B"].badge { background: var(--t-B); }
[data-tier="C"].badge { background: var(--t-C); }
[data-tier="D"].badge { background: var(--t-D); }

/* ── Carte de compo ── */
.comp { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.comp.open { border-color: #4a5070; }
.comp.dimmed { opacity: 0.5; }
.comp-head {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 12px 12px 8px; text-align: left;
}
.grade { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 0 0 auto; }
.grade-lbl { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.comp-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.comp-title strong { font-size: 16px; line-height: 1.2; }
.sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.mini-tribes { display: inline-flex; gap: 2px; }
.mini-tribes .art { width: 22px; height: 22px; box-shadow: 0 0 0 1px var(--line); }
.neutral { font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; color: var(--t-E); }
.pill[data-tier="S"] { color: var(--t-S); }
.pill[data-tier="A"] { color: var(--t-A); }
.pill[data-tier="B"] { color: var(--t-B); }
.pill[data-tier="C"] { color: var(--t-C); }
.pill[data-tier="D"] { color: var(--t-D); }
.pill.plain { color: var(--muted); border-color: var(--line); font-weight: 500; }
.pill[data-diff="Easy"] { color: var(--t-C); border-color: currentColor; }
.pill[data-diff="Hard"] { color: var(--t-A); border-color: currentColor; }
.nums { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.avg { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.chev { color: var(--muted); font-size: 22px; transition: transform 0.2s; }
.comp.open .chev { transform: rotate(90deg); }

.strip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 12px; flex-wrap: wrap; }
.verdict { flex: 1 0 100%; margin: 0; padding: 6px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.verdict::before { margin-right: 6px; }
.verdict.good { background: rgba(123, 211, 137, 0.12); color: var(--t-C); }
.verdict.good::before { content: "✓"; }
.verdict.warn { background: rgba(255, 159, 67, 0.12); color: var(--t-A); }
.verdict.warn::before { content: "!"; }
.verdict.bad { background: rgba(255, 107, 107, 0.12); color: var(--t-S); }
.verdict.bad::before { content: "✗"; }
.cores { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cores-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); writing-mode: horizontal-tb; width: 44px; line-height: 1.2; }
.rates { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.rates b { color: var(--text); font-variant-numeric: tabular-nums; }
.rates .low { color: var(--t-A); }

/* ── Vignettes de cartes ── */
.thumb { position: relative; padding: 0; border: 0; background: none; }
.thumb .art { box-shadow: 0 0 0 2px var(--line); }
.thumb.sm .art { width: 44px; height: 44px; }
.thumb.lg { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.thumb.lg .art { width: 64px; height: 64px; }
.tav {
  position: absolute; z-index: 1; top: -3px; left: -3px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--gold); color: #1a1406; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}
.thumb.lg .tav { left: calc(50% - 38px); }
.cname { font-size: 11px; line-height: 1.2; color: var(--muted); text-align: center; }

.details { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 14px; background: #191c2a; }
.details h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gold); }
.details h4 span { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px 6px; }
.tip { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.tip + .tip { margin-top: 8px; }
.tip p { margin: 0 0 6px; }
.tip .when b { color: var(--gold); }
.tip .by { margin: 0; font-size: 11px; color: var(--muted); }
.orig { margin-top: 6px; font-size: 12px; color: var(--muted); }
.orig summary { cursor: pointer; color: var(--gold); width: max-content; }
.orig p { margin: 6px 0 0; font-style: italic; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.more { display: block; margin: 4px auto 14px; white-space: normal; text-align: center; }

.foot { color: var(--muted); font-size: 12px; padding-bottom: calc(24px + var(--safe-b)); }

/* ── Carte en grand ── */
.card-dialog {
  border: 0; padding: 0; background: none; color: var(--text);
  max-width: min(92vw, 380px); width: 100%; overflow: visible;
}
.card-dialog::backdrop { background: rgba(8, 9, 14, 0.82); }
.card-dialog img { width: 100%; height: auto; aspect-ratio: 512 / 772; object-fit: contain; }
.card-dialog p { text-align: center; margin: 4px 0 0; font-weight: 600; }
.card-dialog form { position: absolute; top: -6px; right: -6px; z-index: 1; }
.close {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 24px; line-height: 1;
}

/* ── Aide ── */
.help-dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text);
  width: min(94vw, 620px); max-height: 86vh; padding: 18px 18px 22px; overflow-y: auto;
}
.help-dialog::backdrop { background: rgba(8, 9, 14, 0.82); }
.help-dialog form { position: sticky; top: 0; float: right; margin: -6px -6px 0 8px; z-index: 1; }
.help-dialog h2 { font-size: 19px; margin: 0 0 4px; }
.help-dialog h3 { font-size: 14px; color: var(--gold); margin: 18px 0 6px; }
.help-dialog p, .help-dialog li, .help-dialog dd { font-size: 14px; line-height: 1.5; }
.help-dialog p { margin: 0 0 8px; }
.help-dialog ul { margin: 0; padding-left: 18px; }
.help-dialog dt { font-weight: 700; margin-top: 8px; }
.help-dialog dd { margin: 2px 0 0; color: #c9cde0; }
.tiers-legend { list-style: none; padding: 0 !important; display: grid; gap: 6px; }
.tiers-legend li { display: flex; align-items: center; gap: 10px; }
.tiers-legend .badge { width: 26px; height: 26px; font-size: 14px; border-radius: 8px; }

/* ── Tablette / iPad : deux colonnes de compos ── */
@media (min-width: 760px) {
  body { font-size: 16px; }
  .top-row { padding-block: 14px; }
  h1 { font-size: 24px; }
  .meta { font-size: 13px; }
  .tribes { grid-template-columns: repeat(11, 1fr); }
  .tribe { min-height: 92px; font-size: 12px; }
  .tribe .art { width: 52px; height: 52px; }
  .tier-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
  .tier-group h3 { grid-column: 1 / -1; margin-bottom: 0; }
  .tier-group > .comp + .comp { margin-top: 0; }
  .comp.open { grid-column: 1 / -1; }
  .cores-lbl { width: auto; }
  #hidden-block .list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 760px) and (max-width: 1023px) {
  .tribes { grid-template-columns: repeat(6, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
