/* ==========================================================================
   Atlas Conquest — Beta Analytics suite
   --------------------------------------------------------------------------
   Shared by analytics.html (Overview), commanders, cards, meta, metagame and
   goals. Loads after brand.css (and before any single-page stylesheet), so it
   refines the shared components for the suite:

     1. Analytics tab bar (.sub-nav)          5. Commander roster (Commanders)
     2. Page hero additions (.an-hero)        6. Overview blocks (.an-*)
     3. Sticky filter bar (.time-filter-bar)  7. Meta + Goals refinements
     4. Commander tokens (.cmd-token)         8. Motion

   Brand with restraint: OptimusPrinceps only for page/section titles; every
   number, label and control stays in Inter.
   ========================================================================== */

:root {
  --an-subnav-h: 48px;
}

@media (max-width: 768px) {
  :root { --an-subnav-h: 46px; }
}

/* Page sections inside <main> keep the old rhythm. */
#main { display: block; }
#main:focus { outline: none; }

/* ─── 1. Analytics tab bar ───────────────────────────────────────────── */

.sub-nav {
  height: var(--an-subnav-h);
  background:
    linear-gradient(180deg, rgba(9, 12, 19, 0.94) 0%, rgba(11, 15, 23, 0.88) 100%);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid rgba(232, 162, 69, 0.13);
  box-shadow: 0 10px 26px -22px rgba(0, 0, 0, 0.95);
  /* Holds still across page loads like the main nav; the active ink slides. */
  view-transition-name: an-subnav;
}

.sub-nav-inner {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.sub-nav-label {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: none;
  margin-right: 0.5rem;
  padding-right: 1.125rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-text);
  white-space: nowrap;
  position: relative;
}

.sub-nav-label::after {
  content: '';
  position: absolute;
  right: 0;
  top: 25%;
  bottom: 25%;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(232, 162, 69, 0.35), transparent);
}

.sub-nav-label img {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 8px rgba(255, 150, 40, 0.35));
}

.sub-nav-scroller {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.sub-nav-scroller::-webkit-scrollbar { display: none; }

.sub-nav.is-fade-end .sub-nav-scroller {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 48px), transparent);
}

.sub-nav.is-fade-start .sub-nav-scroller {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 48px);
  mask-image: linear-gradient(90deg, transparent, #000 48px);
}

.sub-nav.is-fade-start.is-fade-end .sub-nav-scroller {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 48px, #000 calc(100% - 48px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 48px, #000 calc(100% - 48px), transparent);
}

.sub-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 100%;
  padding: 0 1rem;
  border-radius: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: none;
  box-shadow: none;
  transition: color var(--dur) ease, text-shadow var(--dur) ease;
}

/* Hover underline grows from the centre. */
.sub-nav-link::after {
  content: '';
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: rgba(232, 162, 69, 0.4);
  transform: scaleX(0);
  transition: transform 0.22s var(--ease-out);
}

.sub-nav-link:hover {
  color: var(--text);
  background: none;
}

.sub-nav-link:hover::after { transform: scaleX(1); }

.sub-nav-link:focus-visible {
  outline-offset: -4px;
  border-radius: 6px;
}

.sub-nav-link.active,
.sub-nav-link[aria-current="page"] {
  color: var(--gold-hi);
  background: none;
  box-shadow: none;
  text-shadow: 0 0 18px rgba(232, 162, 69, 0.45);
}

.sub-nav-link[aria-current="page"]::after { display: none; }

/* The active "ink": molten underline with a centre diamond. It carries its
   own view-transition-name, so moving between tabs slides it across. */
.sub-nav-ink {
  position: absolute;
  left: 0.625rem;
  right: 0.625rem;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(232, 162, 69, 0) 0%, #e8a245 18%, #ffd27a 50%, #e8a245 82%, rgba(232, 162, 69, 0) 100%);
  box-shadow: 0 0 10px rgba(255, 170, 60, 0.55), 0 -3px 14px rgba(232, 140, 50, 0.25);
  pointer-events: none;
  view-transition-name: an-tab-ink;
}

.sub-nav-ink::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -2px;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  background: #ffe2a3;
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(255, 190, 90, 0.9);
}

::view-transition-group(an-subnav) { animation-duration: 0.22s; }
::view-transition-old(an-subnav) { display: none; }
::view-transition-new(an-subnav) { animation: none; }
::view-transition-group(an-tab-ink) {
  animation-duration: 0.34s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (max-width: 960px) {
  .sub-nav-label span { display: none; }
  .sub-nav-label { padding-right: 0.875rem; margin-right: 0.25rem; }
}

@media (max-width: 768px) {
  /* The scroller is its own element (.sub-nav-scroller); the row itself
     just keeps the phone gutter. */
  .sub-nav-inner { padding-right: 1rem; }
  .sub-nav-label { display: none; }
  .sub-nav-scroller { margin: 0 -0.5rem; }
  .sub-nav-link { padding: 0 0.875rem; font-size: 0.8125rem; }
  .sub-nav-link::after { left: 0.875rem; right: 0.875rem; }
}

/* ─── 2. Page hero additions ─────────────────────────────────────────── */

.an-hero .ac-page-hero__lede { max-width: 60ch; }

.an-hero .ac-page-hero__meta {
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.an-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 28px;
  padding: 0.25rem 0.75rem;
  border: 1px solid rgba(232, 162, 69, 0.2);
  border-radius: var(--radius-pill);
  background: rgba(9, 12, 19, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ac-text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.an-chip .hero-stat {
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

.an-chip strong { color: var(--ac-text); font-weight: 700; }

.an-chip__ico {
  width: 13px;
  height: 13px;
  flex: none;
  color: var(--gold);
}

.an-chip--beta {
  color: var(--gold-text);
  border-color: rgba(232, 162, 69, 0.38);
  background: linear-gradient(180deg, rgba(232, 162, 69, 0.14), rgba(232, 162, 69, 0.06)), rgba(9, 12, 19, 0.62);
}

.an-chip--beta::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--gold);
  transform: rotate(45deg);
  box-shadow: 0 0 8px rgba(255, 170, 60, 0.7);
}

/* Data heroes: keep the art present but quiet behind the copy. */
.an-hero .ac-page-hero__art { filter: saturate(0.9); }

/* On phones the copy runs over the top of the art too, so darken the
   whole plate a little more than the default vertical fade. */
@media (max-width: 768px) {
  .an-hero::after {
    background:
      linear-gradient(0deg, var(--ac-navy-1) 0%, rgba(11, 15, 23, 0.9) 42%, rgba(11, 15, 23, 0.72) 78%, rgba(11, 15, 23, 0.6) 100%),
      radial-gradient(ellipse 80% 60% at 20% 110%, rgba(240, 120, 30, 0.18), transparent 70%),
      var(--ac-hex) 0 0 / 56px 97px;
  }
}

@media (max-width: 560px) {
  .an-chip { font-size: 0.6875rem; min-height: 26px; padding: 0.2rem 0.625rem; }
}

/* ─── 3. Sticky filter bar ───────────────────────────────────────────── */

.has-sub-nav .time-filter-bar {
  top: calc(var(--nav-height) + var(--an-subnav-h));
}

.time-filter-bar {
  background: rgba(11, 15, 23, 0.86);
  border-bottom: 1px solid var(--border-subtle);
}

.time-filter-inner {
  min-height: 54px;
  gap: 0.75rem 1.25rem;
  flex-wrap: wrap;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.an-filter {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.time-filter-bar .an-filter .filter-label { margin-right: 0; }

/* Segmented track: recessed well, gold active segment. */
.an-seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-inset);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
}

.an-seg .time-btn,
.an-seg .map-btn {
  border-color: transparent;
  background: transparent;
  padding: 0.3125rem 0.8125rem;
  min-height: 30px;
}

.an-seg .time-btn:hover,
.an-seg .map-btn:hover {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.04);
}

.an-seg .time-btn.active,
.an-seg .map-btn.active {
  color: var(--gold-hi);
  border-color: rgba(232, 162, 69, 0.55);
  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);
}

.an-filter-summary {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin: 0 0 0 auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.an-filter-summary__count {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text);
}

.an-filter-summary__count::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--gold);
  transform: rotate(45deg);
  opacity: 0.8;
}

@media (max-width: 1100px) {
  .an-filter-summary__scope { display: none; }
}

@media (max-width: 768px) {
  .time-filter-inner {
    min-height: 50px;
    gap: 0.5rem 0.75rem;
    flex-wrap: nowrap;
  }
  .an-filter { gap: 0.375rem; min-width: 0; }
  /* The shared script swaps the pills for a <select> here; drop the track. */
  .an-seg:has(.filter-select) {
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
  }
  .an-filter-summary { font-size: 0.6875rem; }
}

@media (max-width: 420px) {
  .time-filter-bar .an-filter .filter-label { display: none; }
}

@media (max-width: 340px) {
  .an-filter-summary { display: none; }
}

/* ─── 4. Commander tokens ────────────────────────────────────────────── */
/* In game, every unit is a round portrait in a coloured ring. Here the ring
   is the commander's faction colour (data meaning, never decoration). */

.cmd-token {
  --tk: 48px;
  --ring: var(--gold);
  --ring-w: max(2px, calc(var(--tk) * 0.065));
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--tk);
  height: var(--tk);
  padding: var(--ring-w);
  border-radius: 50%;
  vertical-align: middle;
  background:
    linear-gradient(155deg,
      color-mix(in srgb, var(--ring) 58%, #fff) 0%,
      var(--ring) 38%,
      color-mix(in srgb, var(--ring) 62%, #000) 100%);
  box-shadow:
    0 0 0 1px rgba(3, 5, 9, 0.75),
    0 0 calc(var(--tk) * 0.32) calc(var(--tk) * -0.06) color-mix(in srgb, var(--ring) 60%, transparent),
    0 calc(var(--tk) * 0.08) calc(var(--tk) * 0.2) calc(var(--tk) * -0.08) rgba(0, 0, 0, 0.85);
  transition: box-shadow 0.25s ease, transform 0.3s var(--ease-out), filter 0.25s ease;
}

/* No art (or it failed): the initial on a navy disc. */
.cmd-token::before {
  content: attr(data-initial);
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(60% 60% at 50% 35%, #273147, #0f141e);
  font-family: var(--font-display);
  font-size: calc(var(--tk) * 0.42);
  line-height: 1;
  color: var(--gold-text);
}

.cmd-token img {
  grid-area: 1 / 1;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1.5px rgba(4, 6, 10, 0.9);
}

/* Inner bevel: a lit top edge and a shadowed floor, like the in-game ring. */
.cmd-token::after {
  content: '';
  position: absolute;
  inset: var(--ring-w);
  border-radius: 50%;
  pointer-events: none;
  box-shadow:
    inset 0 calc(var(--tk) * -0.1) calc(var(--tk) * 0.18) rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.cmd-token[data-faction="skaal"] { --ring: var(--skaal); }
.cmd-token[data-faction="grenalia"] { --ring: var(--grenalia); }
.cmd-token[data-faction="lucia"] { --ring: var(--lucia); }
.cmd-token[data-faction="neutral"] { --ring: var(--neutral); }
.cmd-token[data-faction="shadis"] { --ring: var(--shadis); }
.cmd-token[data-faction="archaeon"] { --ring: var(--archaeon); }
.cmd-token[data-faction="adora"] { --ring: var(--adora); }
.cmd-token[data-faction="mechanus"] { --ring: var(--mechanus); }
.cmd-token[data-faction="treasure"] { --ring: var(--treasure); }

.cmd-token--xs { --tk: 22px; --ring-w: 2px; }
.cmd-token--sm { --tk: 32px; --ring-w: 2px; }
.cmd-token--md { --tk: 48px; }
.cmd-token--lg { --tk: 72px; }
.cmd-token--xl { --tk: 104px; }

.cmd-token--xs::after,
.cmd-token--sm::after { box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.4); }

/* Corner stat bubble (rank), like the counters on in-game units. */
.cmd-token__badge {
  position: absolute;
  top: -2px;
  left: -2px;
  z-index: 1;
  display: grid;
  place-items: center;
  min-width: max(20px, calc(var(--tk) * 0.34));
  height: max(20px, calc(var(--tk) * 0.34));
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: radial-gradient(70% 70% at 50% 30%, #2a3348, #0d121b);
  border: 1.5px solid rgba(247, 220, 154, 0.85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 10px -2px rgba(232, 162, 69, 0.6);
  font-family: var(--font-body);
  font-size: max(0.625rem, calc(var(--tk) * 0.15));
  font-weight: 700;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Card hover popup (#card-preview on Cards/Top Decks, #commander-card-preview
   for commander portraits on every analytics page — see analytics-ui.js). */
.card-preview {
  position: fixed;
  z-index: 1100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.6));
  /* Row, because a card that creates a token previews next to it. */
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.card-preview.visible {
  opacity: 1;
}

.card-preview img {
  display: block;
  width: 250px;
  /* No background — the transparent render lets the drop-shadow follow the card. */
}

/* Mentioned cards are supporting context — smaller than the hovered card. */
.card-preview .card-preview-mention {
  width: 190px;
}

/* Touch: a tapped commander portrait shows its card centred over a dim
   backdrop (initCommanderCardTap in analytics-ui.js). Mentioned tokens wrap
   underneath on narrow screens. */
.card-preview.card-preview--tap {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1101;
  flex-wrap: wrap;
  justify-content: center;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.card-preview--tap img { width: min(250px, 62vw); }
.card-preview--tap .card-preview-mention { width: min(150px, 38vw); }

.card-preview-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(6, 9, 14, 0.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.card-preview-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ─── 5. Commander roster (Commanders page) ──────────────────────────── */

.commander-grid.an-roster {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.875rem;
  margin-bottom: 2.5rem;
}

.an-roster .commander-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: 1rem 1rem 1rem 1.125rem;
  overflow: hidden;
  background:
    radial-gradient(120px 120px at 52px 50%, color-mix(in srgb, var(--card-faction) 16%, transparent), transparent 70%),
    var(--sheen),
    var(--bg-card);
}

/* Faction seam along the left edge. */
.an-roster .commander-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 2px;
  border-radius: 2px;
  background: var(--card-faction);
  box-shadow: 0 0 12px 1px color-mix(in srgb, var(--card-faction) 60%, transparent);
  opacity: 0.85;
}

.an-roster .commander-card:hover .cmd-token {
  transform: scale(1.05);
  box-shadow:
    0 0 0 1px rgba(3, 5, 9, 0.75),
    0 0 calc(var(--tk) * 0.5) calc(var(--tk) * -0.02) color-mix(in srgb, var(--ring) 75%, transparent),
    0 6px 14px -6px rgba(0, 0, 0, 0.85);
}

.an-roster .commander-card-body {
  padding: 0;
  background: none;
  min-width: 0;
}

.an-roster .commander-card-body::before { display: none; }

.an-roster .commander-card-name {
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
}

.an-roster .faction-badge { font-size: 0.5625rem; }

.an-roster .commander-card-stats {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  margin-top: 0.625rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.an-roster .commander-card-stats > span:first-child {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.an-roster .commander-card-games {
  display: inline;
  margin: 0 0 0 auto;
  font-size: 0.6875rem;
}

/* Winrate bar: fill to the value, tick at 50%. */
.an-wrbar {
  position: relative;
  height: 4px;
  margin-top: 0.5rem;
  border-radius: 4px;
  background: var(--bg-inset);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  overflow: visible;
}

.an-wrbar__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--wr, 0%);
  border-radius: inherit;
  background: var(--text-muted);
  transition: width 0.7s var(--ease-out);
}

.an-wrbar__fill.winrate-positive { background: linear-gradient(90deg, rgba(63, 185, 80, 0.45), var(--positive)); }
.an-wrbar__fill.winrate-negative { background: linear-gradient(90deg, rgba(248, 81, 73, 0.4), var(--negative)); }
.an-wrbar__fill.winrate-neutral { background: linear-gradient(90deg, rgba(179, 173, 161, 0.3), var(--text-secondary)); }

.an-wrbar::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: rgba(237, 231, 218, 0.45);
}

/* Name cells in tables: small token + name + badge. */
.an-cmd-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  white-space: nowrap;
}

.an-cmd-cell strong { font-weight: 600; }

@media (max-width: 1100px) {
  .commander-grid.an-roster { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .commander-grid.an-roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phones: two columns of upright token cards. */
@media (max-width: 560px) {
  .commander-grid.an-roster { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.625rem; }
  .an-roster .commander-card {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.75rem;
    padding: 1.125rem 0.75rem 0.875rem;
    text-align: center;
    background:
      radial-gradient(110px 90px at 50% 50px, color-mix(in srgb, var(--card-faction) 18%, transparent), transparent 72%),
      var(--sheen),
      var(--bg-card);
  }
  .an-roster .commander-card::before {
    left: 18%;
    right: 18%;
    top: 0;
    bottom: auto;
    width: auto;
    height: 2px;
  }
  .an-roster .cmd-token--lg { --tk: 64px; }
  .an-roster .commander-card-body { width: 100%; }
  .an-roster .commander-card-name { font-size: 0.8125rem; min-height: 2.5em; display: grid; place-items: center; }
  .an-roster .commander-card-stats { justify-content: center; flex-wrap: wrap; gap: 0 0.375rem; }
  .an-roster .commander-card-stats > span:first-child { font-size: 1rem; }
  .an-roster .commander-card-games { flex-basis: 100%; margin: 0.125rem 0 0; }
}

/* ─── 6. Overview ────────────────────────────────────────────────────── */

.an-overview-hero .ac-page-hero__inner > * { max-width: 640px; }
/* Overview is a data landing page: compact hero, and the headline numbers
   start close under the filter bar so they're in the first screen. (The
   Discord CTA lives in the nav and the footer band.) */
.an-overview-hero + .time-filter-bar + #overview.section { padding-top: clamp(1.75rem, 1rem + 2vw, 2.75rem); }

.an-section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  flex-wrap: wrap;
  margin-bottom: 1.75rem;
}

.an-section-head .section-title { margin-bottom: 0; }
.an-section-head .section-desc { margin: 0.75rem 0 0; }

.an-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gold-text);
  text-decoration: none;
  white-space: nowrap;
}

.an-link .ac-icon { width: 1em; height: 1em; transition: transform 0.2s var(--ease-out); }
.an-link:hover { color: var(--gold-hi); }
.an-link:hover .ac-icon { transform: translateX(3px); }

/* KPI tiles */
.an-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.an-kpi {
  position: relative;
  overflow: hidden;
  padding: 1.375rem 1.5rem 1.25rem;
  gap: 0.25rem;
}

.an-kpi .stat-label { color: var(--text-secondary); }

.an-kpi .stat-value {
  font-size: clamp(1.875rem, 1.4rem + 1.1vw, 2.5rem);
  line-height: 1.15;
}

.an-kpi__cap {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Faint hex in the corner, echoing the board. */
.an-kpi::after {
  content: '';
  position: absolute;
  right: -14px;
  top: -10px;
  width: 84px;
  height: 96px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 56 64'%3E%3Cpath d='M28 1.5 54 16.5v31L28 62.5 2 47.5v-31Z' fill='none' stroke='%23e8a245' stroke-width='1.5'/%3E%3Cpath d='M28 12 45 22v20L28 52 11 42V22Z' fill='none' stroke='%23e8a245' stroke-opacity='.6'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0.1;
  pointer-events: none;
}

/* Spotlight row: most played · highest winrate · first-turn */
.an-spot-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.an-spot {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding: 1.375rem 1.5rem 1.5rem;
  overflow: hidden;
}

.an-spot--cmd {
  --spot-faction: var(--gold);
  background:
    radial-gradient(160px 140px at 64px 92px, color-mix(in srgb, var(--spot-faction) 18%, transparent), transparent 72%),
    var(--sheen),
    var(--bg-card);
}

.an-spot__body {
  display: flex;
  align-items: center;
  gap: 1.125rem;
  min-width: 0;
}

.an-spot__text { min-width: 0; }

.an-spot .stat-value-sm {
  display: block;
  font-size: 1.125rem;
  line-height: 1.3;
  margin-bottom: 0.375rem;
}

.an-spot__metric {
  display: flex;
  align-items: baseline;
  gap: 0.375rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.an-spot__metric strong {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.an-spot__metric strong.winrate-positive { color: var(--positive); }
.an-spot__metric strong.winrate-negative { color: var(--negative); }

/* First-turn split bar */
.an-ft__numbers {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  font-variant-numeric: tabular-nums;
}

.an-ft__side { display: flex; flex-direction: column; gap: 0.125rem; }
.an-ft__side--second { align-items: flex-end; text-align: right; }

.an-ft__side .stat-value { font-size: 1.75rem; }

.an-ft__side span:first-child {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.an-ft__second {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: #b9cbe8;
}

.an-ft__bar {
  position: relative;
  display: flex;
  height: 10px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-inset);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.an-ft__bar-first {
  width: var(--ft, 50%);
  background: linear-gradient(90deg, #c96f22, #e8a245 70%, #f7dc9a);
  box-shadow: 0 0 12px rgba(232, 140, 50, 0.5);
  transition: width 0.8s var(--ease-out);
}

.an-ft__bar-second {
  flex: 1;
  background: linear-gradient(90deg, rgba(126, 154, 201, 0.45), rgba(157, 180, 220, 0.7));
}

.an-ft__bar::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: rgba(11, 15, 23, 0.9);
}

.an-ft .first-turn-note,
.an-ft__note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* Standings leaderboard: one ordered list flowing into two columns. */
.an-standings {
  padding: 0.75rem 1.25rem;
  margin-bottom: 0;
}

.an-standings__list {
  columns: 2;
  column-gap: 2.5rem;
  column-rule: 1px solid var(--border-subtle);
  list-style: none;
  margin: 0;
  padding: 0;
}

.an-standings__list > li {
  break-inside: avoid;
}

.an-standings__list > li.placeholder-text { padding: 1.5rem 0; column-span: all; }

.an-row {
  display: grid;
  grid-template-columns: 1.75rem auto minmax(0, 1fr) minmax(80px, min(34%, 240px)) 4.25rem;
  align-items: center;
  gap: 0.875rem;
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background var(--dur) ease;
}

.an-row:hover { background: rgba(232, 162, 69, 0.05); }
.an-row:hover .cmd-token { transform: scale(1.08); }

.an-row__rank {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.an-standings__list > li:nth-child(-n+3) .an-row__rank { color: var(--gold-text); }

.an-row__name {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.an-row__name strong {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.an-row__name .faction-badge { align-self: flex-start; font-size: 0.5625rem; }

.an-row__wr {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0.875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.an-row__wr .an-wrbar { margin-top: 0.375rem; }

.an-row__games {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.an-row.is-thin { opacity: 0.62; }
.an-row.is-thin .an-row__wr span { color: var(--text-muted); }

.an-standings-note {
  margin-top: 0.875rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Distribution panels on the overview */
.an-dist .chart-row { margin-top: 0; }

/* Explore tiles */
.an-explore {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1rem;
}

.an-tile {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.375rem;
  grid-column: span 2;
  min-height: 210px;
  padding: 1.375rem 1.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--inner-highlight), var(--shadow-sm);
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.3s var(--ease-out);
}

.an-tile--wide { grid-column: span 3; min-height: 250px; }

.an-tile__art {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--tile-pos, 70% 30%);
  opacity: 0.75;
  transition: transform 0.7s var(--ease-out), opacity 0.3s ease;
}

.an-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(0deg, rgba(9, 12, 19, 0.97) 0%, rgba(9, 12, 19, 0.82) 38%, rgba(9, 12, 19, 0.25) 100%),
    linear-gradient(90deg, rgba(9, 12, 19, 0.6) 0%, transparent 70%);
}

.an-tile::after {
  content: '';
  position: absolute;
  left: 1.5rem;
  right: 1.5rem;
  bottom: 0;
  height: 2px;
  background: var(--ac-grad-fire);
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity 0.25s ease, transform 0.35s var(--ease-out);
}

.an-tile:hover {
  border-color: var(--accent-line);
  transform: translateY(-3px);
  box-shadow: var(--inner-highlight), var(--glow-warm), var(--shadow-md);
}

.an-tile:hover .an-tile__art { transform: scale(1.05); opacity: 0.9; }
.an-tile:hover::after { opacity: 1; transform: none; }

.an-tile__kicker {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-text);
}

.an-tile__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--gold-hi);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
}

.an-tile__title .ac-icon {
  width: 18px;
  height: 18px;
  color: var(--gold);
  transition: transform 0.25s var(--ease-out);
}

.an-tile:hover .an-tile__title .ac-icon { transform: translateX(4px); }

.an-tile__desc {
  max-width: 44ch;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* About-the-data note with the beta CTA */
.an-about {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.5rem 2.5rem;
  margin-top: 2.5rem;
  padding: 1.75rem 2rem;
  overflow: hidden;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(60% 140% at 100% 50%, rgba(240, 120, 30, 0.12), transparent 70%),
    var(--ac-hex) 0 0 / 56px 97px,
    var(--bg-card);
  box-shadow: var(--inner-highlight), var(--shadow-sm);
}

.an-about h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text);
}

.an-about p {
  margin: 0;
  max-width: 70ch;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

.an-about__actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.an-about__hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

@media (max-width: 1100px) {
  .an-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-spot-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-spot-row .an-ft { grid-column: 1 / -1; }
  .an-standings__list { columns: 1; }
}

@media (max-width: 860px) {
  .an-explore { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .an-tile,
  .an-tile--wide { grid-column: span 1; min-height: 190px; }
  .an-tile--wide:first-child { grid-column: 1 / -1; }
  .an-about { grid-template-columns: 1fr; }
  .an-about__actions { align-items: flex-start; }
}

@media (max-width: 640px) {
  .an-kpis { gap: 0.75rem; }
  .an-kpi { padding: 1.125rem 1.125rem 1rem; }
  .an-kpi .stat-value { font-size: 1.75rem; }
  .an-spot-row { grid-template-columns: 1fr; gap: 0.75rem; }
  .an-standings { padding: 0.25rem 0.75rem; }
  .an-row {
    grid-template-columns: 1.25rem auto minmax(0, 1fr) 4.5rem;
    gap: 0.625rem;
    padding: 0.625rem 0.25rem;
  }
  .an-row__games { display: none; }
  .an-explore { grid-template-columns: 1fr; }
  .an-tile,
  .an-tile--wide,
  .an-tile--wide:first-child { grid-column: 1 / -1; min-height: 170px; }
  .an-about { padding: 1.375rem 1.25rem; }
}

/* ─── 7. Page refinements ────────────────────────────────────────────── */

/* Commander dropdown (Cards filter bar, Top Decks toolbar). */
.commander-select {
  min-height: 34px;
  padding: 0.375rem 2rem 0.375rem 0.875rem;
  background: var(--bg-inset) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23e8a245' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") right 0.75rem center / 12px no-repeat;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
}

.commander-select:hover { border-color: var(--border-strong); }

.commander-select:focus-visible {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(232, 162, 69, 0.14);
}

.commander-select option {
  background: var(--bg-elevated);
  color: var(--text);
}

/* Distribution + deck charts: section title spacing inside the suite */
.an-panel-title { margin-bottom: 1rem; }

/* Meta: collapsible sections read as accordion rows when closed. */
.section-title.collapsible {
  position: relative;
  padding-right: 3.25rem;
  cursor: pointer;
}

.section-title.collapsible .chevron {
  position: absolute;
  right: 0;
  top: -0.125rem;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23f2c271' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") center / 16px no-repeat,
    rgba(232, 162, 69, 0.06);
  /* The ▾ glyph stays in the markup as a no-CSS fallback; hide it here. */
  font-size: 0;
  color: transparent;
  -webkit-text-fill-color: transparent;
  cursor: pointer;
  transition: transform 0.3s var(--ease-out), background-color var(--dur) ease, border-color var(--dur) ease, box-shadow var(--dur) ease;
}

.section-title.collapsible .chevron:hover {
  background-color: rgba(232, 162, 69, 0.16);
  border-color: var(--accent-border);
  box-shadow: 0 0 16px -4px rgba(232, 162, 69, 0.55);
}

.section-title.collapsible.collapsed .chevron { transform: rotate(-90deg); }

section.is-collapsed { padding: 1.75rem 0; }
section.is-collapsed .section-title { margin-bottom: 0; }

.section.is-collapsed + .section.is-collapsed { border-top: 1px solid var(--border-subtle); }

/* Meta heatmap: commander tokens on both axes. */
.matchup-row-header .an-mh {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.matchup-col-header {
  position: relative;
  /* The header is rotated 180deg (bottom-to-top text), so its top padding
     ends up at the visual bottom: room for the token beside the cells. */
  padding-top: 2.25rem;
}

.matchup-col-header .cmd-token {
  position: absolute;
  top: 0.5rem;
  left: 50%;
  writing-mode: horizontal-tb;
  /* ...and the portrait is turned back upright. */
  transform: translateX(-50%) rotate(180deg);
}

/* Meta trend toggles: token pills, dimmed when off. */
.filter-btn.an-cmd-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  padding: 0.1875rem 0.75rem 0.1875rem 0.1875rem;
}

.an-cmd-pill .cmd-token { --tk: 22px; transition: filter 0.2s ease, opacity 0.2s ease; }
.an-cmd-pill:not(.active) .cmd-token { filter: grayscale(0.85) brightness(0.8); opacity: 0.75; }

/* Goals: three single targets per row; the starter-deck target (with its
   per-deck breakdown) takes a full row, its decks laid out side by side. */
@media (min-width: 900px) {
  .goals-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .goal-card:has(.goal-decks) {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    grid-template-rows: auto auto 1fr;
    column-gap: 2rem;
    align-items: start;
  }
  .goal-card:has(.goal-decks) > :not(.goal-decks) { grid-column: 1; }
  .goal-card:has(.goal-decks) .goal-decks {
    grid-column: 2;
    grid-row: 1 / span 3;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.5rem;
    margin: 0;
    padding: 0 0 0 2rem;
    border-top: 0;
    border-left: 1px solid var(--border-subtle);
    align-self: stretch;
    align-content: center;
  }
  .goal-card:has(.goal-decks) .goal-deck-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name name" "rate mark";
    gap: 0.25rem 0.5rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    background: var(--bg-inset);
  }
  .goal-card:has(.goal-decks) .goal-deck-name {
    grid-area: name;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .goal-card:has(.goal-decks) .goal-deck-rate { grid-area: rate; font-size: 0.9375rem; font-weight: 700; }
  .goal-card:has(.goal-decks) .goal-deck-mark { grid-area: mark; }
}

/* Goals: the bars fill on arrival. */
.goal-card .progress-fill { transition: width 0.9s var(--ease-out); }

/* A row reached from an article link (/cards.html#<slug>) glows gold briefly. */
.data-table tbody tr.is-linked td {
  background: rgba(232, 162, 69, 0.14);
  transition: background 0.6s ease;
}
.data-table tbody tr.is-linked td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.card-row td { scroll-margin-top: calc(var(--sticky-stack) + 48px); }

/* ─── 7b. Narrow tables (≤600px) ─────────────────────────────────────── */

/* Wide tables scroll sideways inside .table-wrapper. shared.js marks a wrapper
   .is-scrollable while columns are hidden off its right edge, and the fade
   below says "there's more this way" until you reach the end. */
@media (max-width: 600px) {
  .table-wrapper.is-scrollable:not(.is-at-end) {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), rgba(0, 0, 0, 0.25));
            mask-image: linear-gradient(90deg, #000 calc(100% - 44px), rgba(0, 0, 0, 0.25));
  }

  /* Commanders → Winrate by turns / actions / duration. The commander column
     stays pinned on the left at a fixed width so winrates are always in view;
     the faction pill goes (the token's ring already carries the faction). */
  .wr-bucket-table th.wr-cmd-col,
  .wr-bucket-table td.wr-cmd-col {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 9.5rem;
    min-width: 9.5rem;
    max-width: 9.5rem;
    background: var(--bg-card);
    box-shadow: inset -1px 0 0 var(--border);
  }
  .wr-bucket-table thead th.wr-cmd-col { background: #161d2a; z-index: 2; }
  .wr-bucket-table tbody tr:nth-child(even) .wr-cmd-col {
    background: linear-gradient(rgba(255, 255, 255, 0.014), rgba(255, 255, 255, 0.014)), var(--bg-card);
  }
  .wr-bucket-table tbody tr:hover .wr-cmd-col {
    background: linear-gradient(rgba(232, 162, 69, 0.055), rgba(232, 162, 69, 0.055)), var(--bg-card);
    box-shadow: inset 2px 0 0 var(--gold), inset -1px 0 0 var(--border);
  }
  .wr-bucket-table .an-cmd-cell { display: flex; gap: 0.5rem; min-width: 0; }
  .wr-bucket-table .an-cmd-cell .faction-badge { display: none; }
  .wr-bucket-table .an-cmd-cell strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8125rem;
  }
  .wr-bucket-table th:not(:first-child) { padding-left: 0.75rem; }

  /* Cards table: Faction and Type give way to the numbers; the faction moves
     to a 3px bar on the card name (type is still searchable above). */
  .data-table [data-col="faction"],
  .data-table [data-col="type"] { display: none; }
  .data-table .card-row td[data-col="name"] {
    box-shadow: inset 3px 0 0 var(--row-faction, transparent);
    min-width: 8.5rem;
  }
  .data-table .card-row:hover td[data-col="name"] {
    box-shadow: inset 3px 0 0 var(--gold);
  }
}

/* ─── 8. Motion ──────────────────────────────────────────────────────── */

.is-counting { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .sub-nav-link::after,
  .cmd-token,
  .an-tile,
  .an-tile__art,
  .an-tile::after,
  .an-wrbar__fill,
  .an-ft__bar-first,
  .goal-card .progress-fill,
  .section-title.collapsible .chevron { transition: none; }
  .an-tile:hover,
  .an-tile:hover .an-tile__art,
  .an-row:hover .cmd-token,
  .an-roster .commander-card:hover .cmd-token { transform: none; }
  .section-title.collapsible.collapsed .chevron { transform: rotate(-90deg); }
}
