/* === Top Decks Page === */

.metagame-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.metagame-summary {
  min-width: 220px;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding-top: 0.25rem;
}

.metagame-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--sheen), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--inner-highlight), var(--shadow-sm);
}

.metagame-control,
.sort-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.metagame-control span,
.sort-control span {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Sort: segmented track like the period/map filters. */
.sort-control {
  gap: 0.625rem;
}

.sort-control .sort-btn:first-of-type { margin-left: 0; }

.sort-btn {
  min-height: 32px;
  padding: 0.3125rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.sort-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.sort-btn.active {
  color: var(--gold-hi);
  border-color: var(--accent-border);
  background: linear-gradient(180deg, rgba(247, 220, 154, 0.16) 0%, rgba(232, 162, 69, 0.1) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 0 16px -6px rgba(232, 162, 69, 0.7);
}

.metagame-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.archetype-card {
  --arch-faction: var(--border-strong);
  position: relative;
  background: var(--sheen), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--inner-highlight), var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.archetype-card:has(.faction-badge.skaal) { --arch-faction: var(--skaal); }
.archetype-card:has(.faction-badge.grenalia) { --arch-faction: var(--grenalia); }
.archetype-card:has(.faction-badge.lucia) { --arch-faction: var(--lucia); }
.archetype-card:has(.faction-badge.neutral) { --arch-faction: var(--neutral); }
.archetype-card:has(.faction-badge.shadis) { --arch-faction: var(--shadis); }
.archetype-card:has(.faction-badge.archaeon) { --arch-faction: var(--archaeon); }

/* Faction glow behind the commander token. */
.archetype-card::before {
  content: '';
  position: absolute;
  left: -40px;
  top: 0;
  width: 200px;
  height: 92px;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--arch-faction) 22%, transparent), transparent);
  pointer-events: none;
}

.archetype-card:hover,
.archetype-card.expanded {
  border-color: var(--accent-line);
  box-shadow: var(--inner-highlight), var(--glow-warm);
}

.archetype-card.expanded {
  border-color: var(--accent-border);
}

.archetype-tab {
  width: 100%;
  min-height: 92px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.archetype-tab-bg {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 100%;
  display: flex;
  align-items: center;
  overflow: hidden;
  pointer-events: none;
  opacity: 0.32;
  z-index: 0;
}

.archetype-tab-bg-left {
  left: 0;
  -webkit-mask-image: linear-gradient(to right, black 0%, transparent 100%);
  mask-image: linear-gradient(to right, black 0%, transparent 100%);
}

.archetype-tab-bg-right {
  right: 0;
  opacity: 0.2;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 70%);
  mask-image: linear-gradient(to right, transparent 0%, black 70%);
}

.archetype-bg-img {
  display: block;
  height: 100%;
  width: 68px;
  object-fit: cover;
  object-position: center;
  flex-shrink: 0;
}

.archetype-bg-card {
  object-position: center top;
}

.archetype-bg-commander {
  width: 80px;
}

.archetype-main,
.archetype-metrics,
.archetype-token {
  position: relative;
  z-index: 1;
}

/* Token column when the suite UI renders one. */
.archetype-tab:has(.archetype-token) {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.archetype-tab:hover .archetype-token {
  transform: scale(1.05);
}

.archetype-tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  border-radius: var(--radius-lg);
}

.archetype-main {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

.archetype-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex-wrap: wrap;
}

.archetype-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.archetype-commander {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.archetype-card-preview {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
  min-height: 23px;
}

.metagame-chip {
  display: inline-flex;
  align-items: center;
  max-width: 190px;
  min-height: 22px;
  padding: 0.1875rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-inset);
  color: var(--text-secondary);
  font-size: 0.6875rem;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archetype-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr)) 28px;
  gap: 0.5rem;
  align-items: center;
}

.archetype-metric {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  align-items: flex-end;
}

.metric-label {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-value {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.archetype-toggle {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  color: var(--gold);
  background: rgba(232, 162, 69, 0.06);
  font-size: 1rem;
  font-weight: 600;
  transition: background var(--dur) ease, border-color var(--dur) ease, color var(--dur) ease;
}

.archetype-tab:hover .archetype-toggle,
.archetype-card.expanded .archetype-toggle {
  color: var(--gold-hi);
  border-color: var(--accent-border);
  background: rgba(232, 162, 69, 0.14);
}

.archetype-panel {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-inset);
}

.archetype-panel-inner {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
}

.archetype-panel-copy h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.archetype-panel-copy h3::before {
  content: '';
  width: 5px;
  height: 5px;
  background: var(--gold);
  transform: rotate(45deg);
}

.archetype-panel-copy p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.metagame-card-table-wrap {
  border-radius: var(--radius);
}

.metagame-card-table th,
.metagame-card-table td {
  padding: 0.5rem 0.75rem;
}

.metagame-card-name {
  font-weight: 600;
}

.metagame-deck-name {
  font-weight: 600;
}

.metagame-deck-name a {
  color: var(--gold-text);
  text-decoration: none;
}

.metagame-deck-name a:visited {
  color: #d9a35a;
}

.metagame-deck-name a:hover,
.metagame-deck-name a:focus {
  text-decoration: underline;
}

.archetype-panel-divider {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border-subtle);
  margin: 0.25rem 0;
}

.metagame-card-row {
  cursor: default;
}

.metagame-card-row .metagame-card-name {
  cursor: help;
}

.metagame-empty {
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.875rem;
}

.metagame-empty-inline {
  padding: 1rem;
  background: var(--bg-card);
}

@media (max-width: 860px) {
  .metagame-header {
    flex-direction: column;
    gap: 0.5rem;
  }

  .metagame-summary {
    min-width: 0;
    text-align: left;
  }

  .archetype-tab,
  .archetype-tab:has(.archetype-token) {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .archetype-tab:not(:has(.archetype-token)) {
    grid-template-columns: 1fr;
  }

  .archetype-metrics {
    grid-column: 1 / -1;
  }

  .archetype-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr)) 28px;
  }

  .archetype-metric {
    align-items: flex-start;
  }

  .archetype-panel-inner {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .metagame-toolbar {
    align-items: stretch;
  }

  .metagame-control {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
  }

  .sort-control {
    width: 100%;
  }

  /* Card art behind the metrics competes with the text at this width. */
  .archetype-tab-bg-right {
    display: none;
  }

  .metagame-control select {
    width: 100%;
  }

  .archetype-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) 28px;
  }

  .archetype-toggle {
    grid-row: 1 / 3;
    grid-column: 3;
    align-self: center;
    justify-self: end;
  }
}

@media (max-width: 560px) {
  .archetype-tab { padding: 0.875rem; gap: 0.75rem; }
  .archetype-token { --tk: 40px; align-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .archetype-tab:hover .archetype-token { transform: none; }
}
