:root {
  --bg: #0e151d;
  --surface: #161f2a;
  --surface-2: #1d2836;
  --line: #263241;
  --line-soft: #1f2a37;
  --text: #e8eef5;
  --muted: #8496a9;

  --elite: #e8b13a;
  --strong: #6f8fd4;
  --solid: #7d8fa1;
  --m05: #2bb8a6;
  --m15: #a97ee0;
  --win: #3fb264;
  --loss: #e0625a;
  --late: #d98b3f;
  /* Reservado ao cromado interactivo. Não pode coincidir com nenhuma cor
     semântica, senão uma etiqueta parece um botão. */
  --accent: #4d9fff;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  /* Sombra tingida com o azul do fundo, em vez de preto genérico. */
  --shadow: 0 1px 2px rgba(6, 12, 20, .4), 0 4px 12px rgba(6, 12, 20, .22);

  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: 200ms;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background-color: var(--bg);
  /* Halo frio no topo: dá profundidade sem virar o gradiente roxo-azul
     que denuncia interfaces geradas. */
  background-image:
    radial-gradient(1000px 420px at 50% -160px, rgba(77, 159, 255, .075), transparent 68%),
    radial-gradient(700px 300px at 88% 0, rgba(232, 177, 58, .035), transparent 62%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text",
               "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* Grão fixo por cima de tudo — quebra a chapa digital sem custar layout. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: .022;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wrap { max-width: 760px; margin: 0 auto; }

/* Números tabulares: num interface de dados os valores não podem saltar
   de largura quando mudam. */
.score, .stat-value, .detail-value, .count, .card-meta {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ── Topo ─────────────────────────────────────────────────────────── */
.topbar {
  position: relative;
  background: linear-gradient(180deg, #1b2634 0%, var(--surface) 100%);
  padding-top: env(safe-area-inset-top);
}
/* Fio que esmorece nas pontas em vez de uma linha reta de ponta a ponta. */
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 22%, var(--line) 78%, transparent);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.3px;
}
.logo-soft { color: var(--muted); font-weight: 500; }
.logo-mark {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(77, 159, 255, .1), inset 0 0 0 2px var(--elite);
}

.top-right { display: flex; align-items: center; gap: 8px; }

.updated {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(14, 21, 29, .45);
  font-size: 11px;
  color: var(--muted);
}
.updated:empty { display: none; }
.updated::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--win);
  box-shadow: 0 0 6px rgba(63, 178, 100, .7);
}

.refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(14, 21, 29, .45);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.refresh:hover:not(:disabled) { border-color: var(--accent); background: rgba(77, 159, 255, .1); }
.refresh:active:not(:disabled) { transform: scale(.92); }
.refresh:disabled { opacity: .45; cursor: default; }
.refresh:disabled .refresh-icon { animation: spin 1s linear infinite; }

.refresh-icon {
  width: 14px;
  height: 14px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}
.refresh:hover:not(:disabled) .refresh-icon { border-color: var(--accent); border-top-color: transparent; }

@keyframes spin {
  to { transform: rotate(315deg); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Tabs ─────────────────────────────────────────────────────────── */
.tabs {
  background: rgba(22, 31, 42, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tabs-inner { display: flex; }
.tab {
  position: relative;
  flex: 1;
  padding: 13px 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--dur) var(--ease);
}
.tab::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 260ms var(--ease);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); font-weight: 500; }
.tab.is-active::after { transform: scaleX(1); }

.count {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  font-size: 11px;
  color: var(--muted);
}
.tab.is-active .count { background: rgba(75, 150, 230, .16); color: var(--accent); }

/* ── Painéis ──────────────────────────────────────────────────────── */
.panel { display: none; padding: 14px 12px 8px; }
.panel.is-active { display: block; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select,
.filters input[type="date"] {
  flex: 1 1 130px;
  min-width: 0;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--dur) var(--ease);
}
.filters select:hover,
.filters input[type="date"]:hover { border-color: #33445a; }
.filters .dates { display: flex; gap: 8px; flex: 1 1 100%; }
.date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}
.date-field input[type="date"] { flex: 1; min-width: 0; }
.filters input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(.65);
  cursor: pointer;
}

/* ── Cartões ──────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 8px; }

.card {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  animation: rise 320ms var(--ease) both;
  overflow: hidden;
}
.card:hover { border-color: var(--line); background: #18222e; }

/* Faixa lateral com o tier — permite varrer a lista sem ler etiquetas. */
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--tier-color, transparent);
}
.card-ELITE  { --tier-color: var(--elite); }
.card-STRONG { --tier-color: var(--strong); }
.card-SOLID  { --tier-color: var(--solid); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
/* Entrada escalonada nos primeiros cartões — depois já não se nota. */
.card:nth-child(1) { animation-delay: 0ms; }
.card:nth-child(2) { animation-delay: 28ms; }
.card:nth-child(3) { animation-delay: 56ms; }
.card:nth-child(4) { animation-delay: 84ms; }
.card:nth-child(5) { animation-delay: 112ms; }
.card:nth-child(6) { animation-delay: 140ms; }
.card:nth-child(n + 7) { animation-delay: 165ms; }

.card-main { flex: 1; min-width: 0; }
.card-teams {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -.15px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vs { color: var(--muted); font-weight: 400; padding: 0 3px; }
.card-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}
.card-when { flex: none; color: #9aabbd; }
.card-league {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-tags { display: flex; align-items: center; gap: 5px; margin-top: 8px; flex-wrap: wrap; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  border-radius: var(--r-xs);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .3px;
  background: var(--surface-2);
  color: var(--muted);
}

/* Tier — ponto colorido sobre fundo neutro. A cor identifica, sem gritar. */
.tag-tier::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.tag-ELITE  { color: var(--elite); }
.tag-STRONG { color: var(--strong); }
.tag-SOLID  { color: var(--solid); }

/* Mercado — informação secundária (há um filtro para isto). Sem fundo. */
.tag-market {
  background: none;
  padding-left: 0;
  padding-right: 2px;
  font-weight: 500;
  letter-spacing: 0;
}
.tag-m05 { color: var(--m05); }
.tag-m15 { color: var(--m15); }

/* Resultado — o que interessa nos resolvidos. Preenchido. */
.tag-WIN  { background: rgba(63,178,100,.16); color: var(--win); }
.tag-LOSS { background: rgba(224,98,90,.15);  color: var(--loss); }

/* Tardio — contorno, para não competir com o resultado nem com ELITE. */
.tag-LATE {
  background: none;
  border: 1px solid rgba(217,139,63,.4);
  color: var(--late);
  padding: 1px 6px;
}

.card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}
.score {
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.7px;
  color: var(--tier-color, var(--text));
}

.mark {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  color: transparent;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform 90ms var(--ease);
}
.mark:hover { border-color: var(--accent); color: rgba(75,150,230,.5); }
.mark:active { transform: scale(.92); }
.mark[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.mark[aria-pressed="true"]:hover { background: #3d86d4; color: #fff; }

/* ── Detalhe colapsável ───────────────────────────────────────────── */
.detail { margin-top: 8px; }
.detail-toggle {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color var(--dur) var(--ease);
}
.detail-toggle:hover { color: var(--text); }
.detail-toggle::-webkit-details-marker { display: none; }
.detail-toggle::before { content: "▸ "; }
.detail[open] .detail-toggle::before { content: "▾ "; }

.detail-body {
  margin-top: 7px;
  padding: 11px 12px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  animation: rise 220ms var(--ease) both;
}
.detail-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 12.5px;
  padding: 3.5px 0;
}
.detail-label {
  color: var(--muted);
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
}
/* Guia ponteada entre rótulo e valor — em listas longas evita perder a
   associação entre os dois lados da linha. */
.detail-label::after {
  content: "";
  flex: 1;
  margin: 0 4px 0 8px;
  border-bottom: 1px dotted var(--line);
  transform: translateY(-3px);
}
.detail-value {
  flex: none;
  font-weight: 600;
  color: var(--text);
  min-width: 44px;
  text-align: right;
}

.detail-sep {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 14px 0 8px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}
.detail-sep:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.sep-title {
  font-size: 10px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  font-weight: 600;
  color: #9fb2c6;
}
.sep-note {
  font-size: 10.5px;
  font-style: italic;
  color: var(--muted);
}

/* ── Estatísticas ─────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  padding: 11px 8px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  text-align: center;
  animation: rise 300ms var(--ease) both;
}
.stat-value { font-size: 19px; font-weight: 700; letter-spacing: -.5px; }
.stat-label { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

/* ── Estados ──────────────────────────────────────────────────────── */
.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  text-wrap: balance;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
}

/* Esqueleto com a forma do cartão, em vez de um spinner genérico. */
.skeleton {
  height: 78px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -80% 0; }
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translate(-50%, 80px);
  padding: 10px 12px 10px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transition: transform 260ms var(--ease), opacity 260ms var(--ease);
  pointer-events: none;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }
.toast.has-action { pointer-events: auto; }

.toast-action {
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--accent);
  border-radius: var(--r-xs);
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.toast-action:hover { background: var(--accent); color: #0e151d; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
