/* Clash Royale Stats 3.1.0 - Cards screen (T-012 / R-010 Arena redesign;
   T4-005 / R-009 + R-012: "Which cards carry me, and which ones beat me?").

   Composes web/css/tokens.css + components.css primitives (.card/.card-head/
   .card-title/.card-sub/.info-tip/.chip/.tag/.pill/.meter/.art/.eyebrow);
   nothing here redefines a token or a shared component class. The screen is a
   `.screen-stack` (20px between sections), so no card carries its own bottom
   margin. Mobile-first; the >=1024px block turns the "Your cards" list into a
   real multi-column table: `.cards-row-extra` collapses with `display:contents`
   so its four figures become direct items of `.cards-row`'s own grid, next to
   the three items of `.cards-row-main` - see the class comments below for the
   exact column mapping shared with the head row.

   T4-015: the sort chips are the sort control below 1024px and are hidden from
   1024px, where the column headers (a role=columnheader cell around a real
   <button>) sort instead; the expand buttons are the shared `.list-more`
   class from components.css (no local style here). */

/* ---------- nemesis banner (decision 8 / D-025) ---------- */

.cards-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border-color: rgba(229, 72, 77, .35);
}
.cards-alert-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.cards-alert-eyebrow { display: inline-flex; align-items: center; gap: 5px; width: fit-content; }
.cards-alert-name { font-weight: 800; font-size: 15px; }
/* The rule the banner ranks by ("NEMESIS · last 10 games"): the word stays an
   eyebrow, the qualifier reads as plain lowercase text. */
.cards-alert-window { text-transform: none; letter-spacing: 0; font-weight: 700; color: var(--ink-2); }
/* Two clauses. On a phone each takes its own line (never cut mid-number, no
   ellipsis); from 560px they run on one line joined by the " · ". */
.cards-alert-line { display: block; line-height: 1.4; }
.cards-alert-a, .cards-alert-b { display: block; }
.cards-alert-sep { display: none; }
.cards-alert-go { flex: none; }

@media (min-width: 560px) {
  .cards-alert-a, .cards-alert-b { display: inline; }
  .cards-alert-sep { display: inline; }
}

@keyframes cr-cards-flash {
  0%, 100% { background: transparent; }
  30% { background: var(--gold-soft); }
}
.cards-flash { animation: cr-cards-flash 1.5s ease; border-radius: 10px; }

/* ---------- shared section card ---------- */

.cards-card { display: flex; flex-direction: column; gap: 12px; }
.cards-card .card-head { margin-bottom: 0; }
.cards-empty { color: var(--ink-3); font-size: 13px; padding: 4px 0; }

.cards-error { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.cards-error .error-text { margin-top: 0; }

/* The initials CRUI.art would only draw AFTER a failed load: shown under a
   not-yet-loaded (lazy) image so the square is never blank. */
.cards-art-ph { position: absolute; inset: 0; }

/* ---------- opponent cards + tower troops: two compact columns ---------- */

.cards-2col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.cards-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.cards-mini-list { display: flex; flex-direction: column; gap: 10px; }
.cards-mini-row { display: flex; align-items: center; gap: 8px; scroll-margin: 90px; }
.cards-mini-col { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.cards-mini-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cards-mini-empty { padding: 4px 0; }

/* Tower troops: a column with no data is hidden, and the one left takes the
   whole row instead of leaving a blank half. */
.cards-tower-cols { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }

/* Phones narrower than 360px stack the columns; from 360 up they stay side by side. */
@media (max-width: 359px) {
  .cards-2col { grid-template-columns: minmax(0, 1fr); }
  .cards-tower-cols { grid-auto-flow: row; grid-auto-columns: auto; }
}

/* ---------- sort chips + the one Filter chip ---------- */

.cards-sort-row { display: flex; flex-wrap: wrap; gap: 6px; }
.cards-sort-row .chip { padding: 0 12px; }
.cards-sort-row .cards-filter-chip { margin-left: auto; }
@media (min-width: 1024px) {
  /* One sort control per width: from 1024px the column headers sort; only the
     Filter chip stays. (display:none - not focusable, not announced.) The lone
     chip would otherwise sit orphaned in a row of its own, so it moves up into
     the card head's line, beside the info tip (right: card padding + tip +
     gap). The row stays in the DOM after the head, so reading order is intact. */
  .cards-sort-row .chip:not(.cards-filter-chip) { display: none; }
  #cards-main-card { position: relative; }
  #cards-main-card .cards-sort-row { position: absolute; top: 10px; right: 56px; }
}

/* ---------- your cards ----------
   Desktop column order/count MUST match between `.cards-table-head` and
   `.cards-row` once `.cards-row-extra` collapses to `display: contents`: card,
   games, win% (meter+pct together), Wilson low, decks, share, last played - 7
   tracks. Below 1024px the head and the row's button share one flex track set:
   card (flex), games 36, win% 100, then a 14px chevron / spacer. */

.cards-table-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0 6px;
  border-bottom: 1px solid var(--line);
}
.cards-table-head::after { content: ""; width: 14px; flex: none; }
/* Header cells: plain labels below 1024px (nothing to tap); from 1024px a
   sortable cell wraps one real <button> that inherits the eyebrow look. */
.cards-grid { display: flex; flex-direction: column; gap: 12px; }
.cards-th { display: inline-flex; align-items: center; justify-content: flex-end; color: var(--ink-3); text-align: right; white-space: nowrap; }
.cards-th.on { color: var(--gold); }
.cards-th-card { flex: 1; justify-content: flex-start; text-align: left; }
.cards-thead-extra { display: none; }
.cards-th-btn {
  color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit;
  padding: 4px 0; white-space: nowrap; border-radius: 6px;
}
/* The direction glyph is its own flex item in a plain-label cell, so the gap
   is a margin, not a leading space. */
.cards-th-dir:not(:empty) { margin-left: 4px; }
.cards-th-btn:hover { color: var(--ink); }
.cards-th.on .cards-th-btn:hover { color: var(--gold); }
.cards-table-head [data-col="games"] { width: 36px; flex: none; }
.cards-table-head [data-col="winPct"] { width: 100px; flex: none; }

.cards-table { display: flex; flex-direction: column; }
.cards-row { border-top: 1px solid var(--line); }
.cards-row:first-child { border-top: 0; }

/* The row IS the disclosure: this is a <button aria-expanded> below 1024px. */
.cards-row-main {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 52px; padding: 8px 0;
  text-align: left; color: inherit; border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.cards-row-main:active { background: var(--s2); }
.cards-row-card { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.cards-row-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; }
.cards-row-name .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cards-evo-tag { background: var(--gold-soft); color: var(--gold); flex: none; }
.cards-row-games { width: 36px; flex: none; text-align: right; font-size: 12px; color: var(--ink-2); }
.cards-row-winpct { width: 100px; flex: none; display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cards-row-winpct .meter { width: 48px; flex: 0 1 48px; min-width: 20px; }
.cards-row-chev { width: 14px; flex: none; display: inline-flex; color: var(--ink-3); }
.cards-row-main[aria-expanded="true"] .cards-row-chev .i { transform: rotate(180deg); }

.cards-row-extra { display: none; }
.cards-row-extra.open {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px;
  padding: 0 0 12px 36px;
}
@media (min-width: 520px) {
  .cards-row-extra.open { grid-template-columns: repeat(4, max-content); justify-content: start; gap: 10px 28px; }
}
.cards-stat { display: flex; flex-direction: column; gap: 2px; min-width: 62px; }
.cards-stat-label { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.cards-stat-value { font-size: 12px; font-weight: 700; color: var(--ink-2); }

.cards-row-skeleton-bar { height: 40px; margin: 6px 0; border-radius: 10px; }

/* Under 360px the win-rate meter goes, so a card name still has room. */
@media (max-width: 359px) {
  .cards-row-winpct { width: 48px; }
  .cards-row-winpct .meter { display: none; }
  .cards-table-head [data-col="winPct"] { width: 48px; }
}

@media (min-width: 1024px) {
  .cards-table-head { display: grid; grid-template-columns: minmax(0, 1fr) 70px 130px 104px 60px 70px 100px; gap: 10px; }
  .cards-table-head::after { display: none; }
  .cards-thead-extra { display: contents; }

  .cards-row { display: grid; grid-template-columns: minmax(0, 1fr) 70px 130px 104px 60px 70px 100px; gap: 10px; align-items: center; padding: 8px 0; }
  .cards-row-main { display: contents; }
  .cards-row-extra,
  .cards-row-extra.open { display: contents; }
  .cards-row-extra .cards-stat { flex-direction: row; justify-content: flex-end; gap: 6px; align-items: baseline; }
  .cards-row-extra .cards-stat-label { display: none; }
  .cards-row-extra .cards-stat-value { text-align: right; width: 100%; color: var(--ink); }
  .cards-row-games { width: auto; }
  .cards-row-winpct { width: auto; }
  .cards-row-winpct .meter { width: 66px; flex-basis: 66px; }
  .cards-table-head [data-col="games"],
  .cards-table-head [data-col="winPct"] { width: auto; }
}

/* ---------- evolutions ---------- */

.cards-evo-list { display: flex; flex-direction: column; }
.cards-evo-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.cards-evo-row:first-child { padding-top: 0; border-top: 0; }
.cards-evo-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cards-evo-side.end { justify-content: flex-end; text-align: right; }
.cards-evo-col { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cards-evo-side.end .cards-evo-col { align-items: flex-end; }
.cards-evo-pct { font-weight: 700; }

.cards-evo-paired { grid-column: 1 / -1; margin-top: 4px; }
.cards-evo-paired summary { cursor: pointer; font-size: 12px; color: var(--ink-2); list-style: none; }
.cards-evo-paired summary::-webkit-details-marker { display: none; }
.cards-evo-paired-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* ---------- filter sheet (rarity + sample size) ---------- */

.cards-filter-group { display: flex; flex-direction: column; gap: 4px; }
.cards-rarity-row { width: 100%; min-height: 44px; text-align: left; justify-content: space-between; }
.cards-rarity-row.on { color: var(--gold); }
.cards-rarity-row-label { flex: 1; }
