/* =========================================================
   The Ape Society rarity guide. Builds on ../style.css (tokens, header, buttons, footer)
   and ../gallery/gallery.css (tier colours, tabs, search, popup buttons).
   The other layouts it was chosen from live in lab/rarity-versions/.
   ========================================================= */

.rg-app { min-height: 50vh; }
.rg-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.rg-bar .gx-search { flex: 1 1 260px; max-width: 520px; }
.rg-empty { padding: 40px 0; text-align: center; color: var(--ink-2); }
.rg-icon { display: block; width: 100%; height: 100%; object-fit: contain; }
.rg-crown { display: inline-block; width: 18px; height: auto; margin-right: 6px; vertical-align: -1px; }

/* tier legend: doubles as a filter */
.rg-tiers { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: clamp(28px, 3.4vw, 44px); }
.rg-tier {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  background: transparent; color: var(--ink); border: 1px solid var(--rule); border-radius: 18px;
  font: 500 13px/1 var(--sans); cursor: pointer; transition: border-color .25s var(--ease), background-color .25s var(--ease);
}
.rg-tier:hover { border-color: color-mix(in srgb, var(--tc) 70%, transparent); }
.rg-tier[aria-pressed="true"] { border-color: var(--tc); background: color-mix(in srgb, var(--tc) 16%, transparent); }
.rg-tier-r { color: var(--ink-3); font-weight: 400; }
.rg-tier:focus-visible, .rg-tile:focus-visible { outline: 1px solid var(--gold-l); outline-offset: 2px; }

/* ---------- the board ---------- */
.rg-board { columns: 3 300px; column-gap: clamp(32px, 4vw, 64px); }
.rg-group { break-inside: avoid; margin-bottom: clamp(32px, 3.6vw, 48px); }
.rg-group h2 { margin: 0 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--rule); font: 400 clamp(22px, 2vw, 26px)/1.2 var(--serif); }
.rg-tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
.rg-tile {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 6px; margin: 0 -6px;
  background: none; border: 0; color: var(--ink); text-align: left; cursor: pointer; border-radius: 2px;
  transition: background-color .2s var(--ease);
}
.rg-tile:hover { background: rgba(239, 233, 223, .045); }
.rg-tile-icon {
  flex: none; width: 52px; height: 52px; padding: 4px; background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--tc) 55%, transparent);
  transition: border-color .2s var(--ease);
}
.rg-tile:hover .rg-tile-icon { border-color: var(--tc); }
.rg-tile-txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rg-tile-name { font: 400 14px/1.25 var(--sans); }
.rg-tile-p { font: 500 13px/1 var(--sans); color: var(--tc); font-variant-numeric: tabular-nums; }

/* ---------- the trait popup ---------- */
.rg-d-head { display: flex; align-items: center; gap: 18px; }
.rg-d-icon { flex: none; width: 96px; height: 96px; padding: 6px; background: var(--bg); border: 1px solid color-mix(in srgb, var(--tc) 60%, transparent); }
.rg-d-name { margin: 0; font: 400 clamp(26px, 2.6vw, 32px)/1.1 var(--serif); }
.rg-d-meta { margin: 8px 0 0; font-size: 14px; color: var(--ink-2); }
.rg-d-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 22px 0 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.rg-d-stats div { padding: 14px 0; }
.rg-d-stats div + div { padding-left: 16px; border-left: 1px solid var(--rule); }
.rg-d-stats dt { font: 500 10.5px/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }
.rg-d-stats dd { margin: 8px 0 0; font: 400 clamp(20px, 2vw, 24px)/1 var(--serif); font-variant-numeric: tabular-nums; }
.rg-d-tier { color: var(--tc); }
.rg-d-sub { margin: 22px 0 10px; font-size: 14px; color: var(--ink-2); }
.rg-d-apes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.rg-d-apes a { display: block; color: var(--ink-2); font-size: 12px; line-height: 1.3; }
.rg-d-apes a img:not(.rg-crown) { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; background: var(--bg); border: 1px solid var(--rule); transition: border-color .2s var(--ease); }
.rg-d-apes a.is-king img:not(.rg-crown) { border-color: var(--gold); }
.rg-d-apes a span { display: block; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rg-d-apes .rg-crown { width: 14px; margin-right: 4px; vertical-align: 0; }
.rg-d-apes a:hover { color: var(--ink); }
.rg-d-apes a:hover img:not(.rg-crown) { border-color: var(--gold); }
.rg-d-more { margin: 22px 0 0; text-align: center; }

.rg-dlg {
  width: min(640px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0;
  border: 1px solid var(--rule-2); background: var(--bg-2); color: var(--ink); overflow-y: auto; overscroll-behavior: contain;
}
.rg-dlg::backdrop { background: rgba(4, 4, 3, .8); }
.rg-dlg .ap-top { justify-content: space-between; padding: 12px 12px 0; }
.rg-dlg .rg-d { padding: 4px clamp(20px, 4vw, 36px) clamp(24px, 4vw, 34px); }
@media (prefers-reduced-motion: no-preference) {
  .rg-dlg[open] { animation: rg-fade .28s var(--ease); }
  .rg-dlg[open]::backdrop { animation: rg-fade .28s var(--ease); }
}
@keyframes rg-fade { from { opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 600px) {
  .rg-tiles { gap: 4px 10px; }
  .rg-tile { gap: 10px; }
  .rg-tile-icon { width: 46px; height: 46px; }
  .rg-tile-name { font-size: 13.5px; }
  .rg-tier { height: 34px; padding: 0 12px; font-size: 12.5px; }
  .rg-tier-r { display: none; }
  .rg-d-head { gap: 14px; }
  .rg-d-icon { width: 76px; height: 76px; }
  .rg-d-stats dd { font-size: 20px; }
  .rg-d-apes { gap: 6px; }
  .rg-d-apes a span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
