/* PalermasFantasy — "Noite de jogo".
   Campo de padel à noite: fundo petróleo → verde-escuro com brilho de projetor no topo,
   superfícies planas e sólidas (sem vidro, sem bordas), menta só para ação e estado ativo,
   amarelo-bola só em pormenor. Um só layout em coluna em qualquer largura.
   Hierarquia por espaço, tamanho e peso; poucas linhas.
   Todos os valores visuais vêm dos tokens em :root. Exceção documentada: o limite da
   media query (40rem) não aceita variáveis. */

:root {
  color-scheme: dark light;

  /* Cor — tema escuro (principal). Superfícies sólidas.
     Contrastes calculados (WCAG): sobre --surface #163235: ink 12.0:1, muted 6.3:1,
     accent-text 8.1:1, ok 7.0:1, bad 6.0:1. Sobre --surface-raised #2a5256: ink 7.6:1.
     on-pick/pick-bg 10.2:1. Opção vs superfície 1.6:1; escolhida vs não escolhida 5.1:1. */
  --bg: #07131a;
  --bg-bottom: #0a2022;
  --bg-glow: rgb(63 224 181 / 0.16);
  --surface: #163235;
  --surface-raised: #2a5256;
  --surface-hover: #336167;
  --pick-bg: #3fe0b5;
  --on-pick: #04201a;
  --glass-solid: #14302f;
  --glass-blur: 18px;
  --nav-bg: rgb(9 30 33 / 0.72);
  --field-bg: rgb(0 0 0 / 0.22);
  --line-strong: rgb(255 255 255 / 0.24);
  /* Linha fina decorativa entre filas (sem significado, isenta de contraste). */
  --line: rgb(255 255 255 / 0.1);
  --control-line: #6f8d89;
  --ink: #e9f2f0;
  --muted: #9fb5b1;
  --accent: #3fe0b5;
  --accent-hover: #74ecca;
  --accent-edge: #3fe0b5;
  --accent-text: #3fe0b5;
  --on-accent: #04201a;
  --accent-wash: rgb(63 224 181 / 0.14);
  --ball: #d9e24a;
  --on-ball: #07131a;
  --ok: #6ccf7e;
  --ok-wash: rgb(108 207 126 / 0.14);
  --bad: #ff8b80;
  --bad-wash: rgb(255 139 128 / 0.12);
  --focus: #3fe0b5;
  --skeleton: rgb(255 255 255 / 0.06);
  --skeleton-hi: rgb(255 255 255 / 0.13);
  /* Ligações do quadro em árvore: a mesma linha dos controlos (resolve-se também no tema claro). */
  --bt-line: var(--control-line);
  --mesh: url("assets/pattern-mesh.svg");

  /* Tipo: só pilhas do sistema; títulos pesados e compactos; números tabulares. */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs-2xs: 0.6875rem;
  --fs-xs: 0.75rem;
  --fs-s: 0.875rem;
  --fs-m: 1rem;
  --fs-l: 1.25rem;
  --fs-xl: 2rem;
  --fs-2xl: 3rem;
  --fw-regular: 400;
  --fw-semi: 600;
  --fw-bold: 700;
  --fw-heavy: 850;
  --lh-tight: 1.05;
  --lh-snug: 1.25;
  --lh-body: 1.5;
  --lh-prose: 1.65;
  --ls-tight: -0.03em;
  --ls-label: 0.1em;
  --ls-code: 0.16em;
  --measure: 65ch;

  /* Espaço (escala única, base 4 px). */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Forma: cartões 24 px, controlos 14 px, pílula para chips, separadores e barra. */
  --r-card: 24px;
  --r-control: 14px;
  --r-s: 8px;
  --r-pill: 999px;
  --bw: 1px;
  --bw-strong: 2px;
  --bw-focus: 2px;
  --focus-offset: 3px;

  /* Medidas. */
  --tap: 2.75rem;
  --field-h: 3rem;
  --maxw: 40rem;
  --top-h: 3.75rem;
  --nav-h: 3.5rem;
  --nav-maxw: 28rem;
  --icon: 1.25rem;
  --icon-s: 1rem;
  --dot: 0.625rem;
  --logo-h: 2rem;
  --logo-w-l: 17rem;
  --ill-w: 20rem;
  --ill-w-s: 10rem;
  --mesh-size: 24px;
  --glow-h: 26rem;
  --chevron: 0.375rem;
  --sk-h: 0.875rem;
  --sk-block: 5rem;
  --rank-pos: 2.5rem;
  --rank-num: 5rem;
  --pos-w: 1.75rem;
  /* Barra de percentagem das estatísticas. */
  --bar-h: 0.375rem;
  /* Quadro em árvore: largura de cada ronda e corredor entre rondas (onde passam as ligações). */
  --bcol-w: 17rem;
  --bt-gap: 2rem;

  /* Elevação: duas apenas. Cartões planos; só a barra flutuante se descola, com sombra leve. */
  --elev-0: none;
  --elev-1: 0 6px 18px rgb(0 0 0 / 0.3);

  /* Movimento. */
  --dur-fast: 150ms;
  --dur: 220ms;
  --dur-slow: 1400ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --press: 0.97;

  /* Camadas. */
  --z-nav: 10;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Tema claro: mesmos nomes. Contrastes calculados sobre --surface #f9fbfa: ink 16.4:1,
       muted 6.5:1, accent-text 5.1:1, ok 5.2:1, bad 6.3:1. Sobre --surface-raised #d3e0dc:
       ink 12.6:1. on-pick/pick-bg 5.1:1. Opção vs superfície 1.3:1; escolhida vs não 3.9:1. */
    --bg: #eef4f2;
    --bg-bottom: #d6e8e3;
    --bg-glow: rgb(63 224 181 / 0.22);
    --surface: #f9fbfa;
    --surface-raised: #d3e0dc;
    --surface-hover: #c5d6d1;
    --pick-bg: #0a7a5e;
    --on-pick: #f9fbfa;
    --glass-solid: #f7faf9;
    --nav-bg: rgb(255 255 255 / 0.8);
    --field-bg: rgb(255 255 255 / 0.9);
    --line-strong: rgb(11 31 34 / 0.26);
    --line: rgb(11 31 34 / 0.1);
    --control-line: #6d807d;
    --ink: #0b1f22;
    --muted: #4b5f5d;
    --accent: #3fe0b5;
    --accent-hover: #2fcfa4;
    --accent-edge: #0a7a5e;
    --accent-text: #0a7a5e;
    --on-accent: #04201a;
    --accent-wash: rgb(63 224 181 / 0.12);
    --on-ball: #0b1f22;
    --ok: #1d7a3c;
    --ok-wash: rgb(29 122 60 / 0.1);
    --bad: #b3261e;
    --bad-wash: rgb(179 38 30 / 0.08);
    --focus: #0a7a5e;
    --skeleton: rgb(11 31 34 / 0.06);
    --skeleton-hi: rgb(11 31 34 / 0.12);
    --elev-1: 0 6px 18px rgb(11 31 34 / 0.12);
  }
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-m);
  font-weight: var(--fw-regular);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(120% var(--glow-h) at 50% 0%, var(--bg-glow), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  font-weight: var(--fw-heavy);
  text-wrap: balance;
}

h1 {
  font-size: var(--fs-xl);
}

h2 {
  font-size: var(--fs-l);
}

h3 {
  font-size: var(--fs-m);
  line-height: var(--lh-snug);
}

p,
ul,
ol,
dl,
dd {
  margin: 0;
}

a {
  color: var(--accent-text);
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: var(--bw-focus) solid var(--focus);
  outline-offset: var(--focus-offset);
}

.icon {
  width: var(--icon);
  height: var(--icon);
  flex: none;
  vertical-align: middle;
}

.icon-s {
  width: var(--icon-s);
  height: var(--icon-s);
  flex: none;
  vertical-align: middle;
}

.muted {
  color: var(--muted);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Etiqueta: maiúsculas pequenas com tracking. */
.label,
label,
th {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--muted);
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- barra flutuante: o único vidro ---------- */

.tabbar {
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
}

/* Sem desfoque disponível: cor sólida, para o texto nunca ficar sobre conteúdo a passar. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tabbar {
    background-color: var(--glass-solid);
  }
}

/* ---------- estrutura ---------- */

/* Uma só coluna centrada em qualquer largura, incluindo o quadro. */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--space-4) var(--space-6);
  display: grid;
  gap: var(--space-5);
}

.topbar {
  display: flex;
  align-items: center;
  min-height: var(--top-h);
  padding-top: env(safe-area-inset-top);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--r-s);
}

.brand img {
  display: block;
  height: var(--logo-h);
  width: auto;
}

/* Aviso: faixa tingida, sem borda, com ícone; nunca só cor. */
.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-control);
  background: var(--accent-wash);
  color: var(--ink);
  font-size: var(--fs-s);
  font-weight: var(--fw-semi);
}

.notice .icon {
  color: var(--accent-text);
}

.notice.error {
  background: var(--bad-wash);
}

.notice.error .icon {
  color: var(--bad);
}

/* Cartão de formulário/informação: superfície plana e sólida, sem borda nem sombra. */
.panel {
  background-color: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--elev-0);
  padding: var(--space-5) var(--space-4);
  display: grid;
  gap: var(--space-4);
  align-content: start;
  min-width: 0;
}

.page-head {
  display: grid;
  gap: var(--space-2);
  padding-top: var(--space-2);
}

.page-head h1 {
  overflow-wrap: anywhere;
}

.page-head p {
  max-width: var(--measure);
}

.section {
  display: grid;
  gap: var(--space-3);
}

.section-title {
  font-size: var(--fs-m);
}

/* ---------- a carregar ---------- */

.skeleton {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) 0;
}

.sk-line,
.sk-block {
  display: block;
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-hi) 50%, var(--skeleton) 75%);
  background-size: 200% 100%;
  animation: shimmer var(--dur-slow) linear infinite;
}

.sk-line {
  height: var(--sk-h);
  width: 55%;
  border-radius: var(--r-pill);
}

.sk-line.short {
  width: 30%;
}

.sk-block {
  height: var(--sk-block);
  border-radius: var(--r-card);
}

.loading-page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* ---------- vazio e erro ---------- */

.empty,
.failed {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-radius: var(--r-card);
}

/* Vazio: superfície plana, sem contorno. */
.empty {
  background: var(--surface);
}

.empty img {
  width: var(--ill-w-s);
  height: auto;
}

.empty p,
.failed p {
  max-width: var(--measure);
}

.failed {
  background: var(--bad-wash);
}

.failed-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--fw-bold);
  line-height: var(--lh-snug);
}

.failed-title .icon {
  color: var(--bad);
}

/* ---------- botões ---------- */

.btn,
.btn-ghost,
.btn-danger,
.btn-google,
.opt,
.tab {
  font: inherit;
  min-height: var(--tap);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.btn,
.btn-ghost,
.btn-danger,
.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border-radius: var(--r-control);
  font-weight: var(--fw-bold);
  text-decoration: none;
}

/* Ação principal: menta cheia. */
.btn {
  border: var(--bw) solid var(--accent-edge);
  background: var(--accent);
  color: var(--on-accent);
}

.btn:hover {
  background: var(--accent-hover);
}

/* Secundária: superfície elevada, sem contorno visível (traço transparente mantém a altura). */
.btn-ghost {
  border: var(--bw) solid transparent;
  background: var(--surface-raised);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--surface-hover);
}

/* Destrutiva: texto vermelho, tinta vermelha suave no hover; nunca menta. */
.btn-danger {
  border: var(--bw) solid transparent;
  background: var(--bad-wash);
  color: var(--bad);
}

.btn-danger:hover {
  border-color: var(--bad);
}

/* Google: neutra e forte (tinta cheia), distinta da ação menta. */
.btn-google {
  width: 100%;
  border: var(--bw) solid var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.btn-google:hover {
  background: var(--muted);
  border-color: var(--muted);
}

.btn-google svg {
  width: var(--icon);
  height: var(--icon);
}

.btn:active,
.btn-ghost:active,
.btn-danger:active,
.btn-google:active,
.opt:active,
.tab:active {
  transform: scale(var(--press));
}

/* Desativado: tracejado e texto apagado, não só transparência. */
.btn:disabled,
.btn-ghost:disabled,
.btn-danger:disabled,
.btn-google:disabled {
  cursor: not-allowed;
  transform: none;
  border-style: dashed;
  border-color: var(--control-line);
  background: transparent;
  color: var(--muted);
}

.btn-block {
  width: 100%;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---------- campos ---------- */

form {
  display: grid;
  gap: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-2);
}

input[type="email"],
input[type="text"],
select {
  width: 100%;
  min-height: var(--field-h);
  padding: 0 var(--space-4);
  font: inherit;
  color: var(--ink);
  background-color: var(--field-bg);
  border: var(--bw) solid var(--control-line);
  border-radius: var(--r-control);
  transition: border-color var(--dur-fast) var(--ease);
}

input[type="email"]:hover,
input[type="text"]:hover,
select:hover {
  border-color: var(--ink);
}

input[type="email"]:focus-visible,
input[type="text"]:focus-visible,
select:focus-visible {
  border-color: var(--accent-edge);
  outline-offset: 0;
}

input:user-invalid {
  border-color: var(--bad);
}

select {
  appearance: none;
  padding-right: var(--space-7);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - var(--space-5)) 50%, calc(100% - var(--space-5) + var(--chevron)) 50%;
  background-size: var(--chevron) var(--chevron);
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

select option {
  background: var(--glass-solid);
  color: var(--ink);
}

.code-input {
  font-family: var(--font-mono);
  letter-spacing: var(--ls-code);
}

/* Separador "ou": só a palavra, sem linhas. */
.or {
  text-align: center;
  font-size: var(--fs-s);
}

/* ---------- entrada ---------- */

.wrap:has(.entry) .topbar {
  display: none;
}

.entry {
  display: grid;
  gap: var(--space-5);
  padding-top: calc(env(safe-area-inset-top) + var(--space-6));
}

/* Cabeça de entrada: logótipo e o campo iluminado sobre a malha da rede, que se desvanece. */
.entry-brand {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: var(--space-5);
  justify-items: start;
  padding: var(--space-4) 0;
}

.entry-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--mesh);
  background-size: var(--mesh-size) var(--mesh-size);
  -webkit-mask-image: linear-gradient(180deg, transparent, var(--ink) 40%, transparent);
  mask-image: linear-gradient(180deg, transparent, var(--ink) 40%, transparent);
}

.entry-brand picture img {
  display: block;
  width: min(100%, var(--logo-w-l));
  height: auto;
}

.entry-court {
  width: 100%;
  max-width: var(--ill-w);
  height: auto;
}

.entry-legal {
  font-size: var(--fs-s);
}

/* ---------- quadros (lista) ---------- */

/* Lista: cada quadro é uma superfície plana; separam-se por espaço, não por linhas. */
.draw-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.draw-link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  min-height: var(--tap);
  padding: var(--space-4);
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease);
}

.draw-link:hover {
  background: var(--surface-raised);
}

/* Ponto de estado: cheio e aceso se aberto, anel vazio se fechado. */
.draw-link::before {
  content: "";
  grid-row: 1 / span 2;
  width: var(--dot);
  height: var(--dot);
  border-radius: var(--r-pill);
  border: var(--bw-strong) solid var(--control-line);
}

.draw-link.is-open::before {
  border-color: var(--accent);
  background: var(--accent);
}

.draw-link h2 {
  font-size: var(--fs-l);
  overflow-wrap: anywhere;
}

.draw-link .meta {
  grid-column: 2;
  font-size: var(--fs-s);
  font-variant-numeric: tabular-nums;
}

.draw-link .badge {
  grid-column: 3;
  grid-row: 1 / span 2;
}

.draw-link.is-closed h2 {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  justify-self: start;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  white-space: nowrap;
}

/* Aberto: tinta menta. Fechado: cadeado e texto apagado, sem contorno. */
.badge.open {
  background: var(--accent-wash);
  color: var(--accent-text);
}

.badge.closed {
  background: transparent;
  color: var(--muted);
}

/* ---------- quadro ---------- */

.back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  justify-self: start;
  min-height: var(--tap);
  padding: 0 var(--space-3) 0 var(--space-1);
  border-radius: var(--r-pill);
  color: var(--ink);
  font-weight: var(--fw-bold);
  text-decoration: none;
}

.back:hover {
  background: var(--surface);
}

/* A ver as escolhas de outro jogador: faixa plana, texto à esquerda, "Voltar" à direita.
   O nome longo quebra linha (nunca fica escondido) e o botão não encolhe nem se sobrepõe. */
.viewing {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--r-card);
  background: var(--surface);
}

.viewing p {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-s);
  line-height: var(--lh-snug);
  color: var(--muted);
  overflow-wrap: anywhere;
}

.viewing strong {
  color: var(--ink);
  font-weight: var(--fw-bold);
}

.viewing .btn-ghost {
  flex: none;
}

.draw-head {
  display: grid;
  gap: var(--space-3);
}

.draw-head h1 {
  overflow-wrap: anywhere;
}

.draw-head .meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-size: var(--fs-s);
  font-variant-numeric: tabular-nums;
}

.draw-head p {
  max-width: var(--measure);
}

/* Partilhar / Estatísticas: lado a lado; a 360 px partem para a linha seguinte. */
.head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.head-actions .btn-ghost {
  font-size: var(--fs-s);
  line-height: var(--lh-snug);
}

.tally {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: var(--fw-heavy);
}

/* Marcador: número grande e tabular, como num placard. */
.score {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-2xl);
  font-weight: var(--fw-heavy);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  color: var(--ink);
}

.scoreline {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
}

/* Pontuação: fechada por defeito; abre-se tocando no título. */
.scoring {
  border-radius: var(--r-card);
  background: var(--surface);
}

.scoring summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border-radius: var(--r-card);
  cursor: pointer;
  list-style: none;
}

.scoring summary::-webkit-details-marker {
  display: none;
}

/* Seta: aponta para baixo fechada, para cima aberta. */
.scoring summary::after {
  content: "";
  width: var(--chevron);
  height: var(--chevron);
  border-right: var(--bw-strong) solid currentColor;
  border-bottom: var(--bw-strong) solid currentColor;
  transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}

.scoring[open] summary::after {
  transform: rotate(-135deg);
}

.points {
  list-style: none;
  padding: 0 var(--space-4) var(--space-4);
  display: grid;
  gap: var(--space-2);
}

.points li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--fs-s);
}

.points strong {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Quadro: uma ronda por baixo da outra, em qualquer largura. */
.bracket {
  display: grid;
  gap: var(--space-5);
}

/* Ronda: superfície plana; os jogos lá dentro separam-se por espaço. */
.round {
  display: grid;
  gap: var(--space-4);
  align-content: start;
  min-width: 0;
  padding: var(--space-5) var(--space-4);
  border-radius: var(--r-card);
  background: var(--surface);
}

/* No admin as rondas já estão dentro de um painel: sem segunda superfície. */
.panel .round {
  padding: 0;
  background: none;
}

.round-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}

.round-head h2 {
  font-size: var(--fs-m);
}

.round-head .muted {
  font-size: var(--fs-xs);
  white-space: nowrap;
}

/* Jogos da ronda: separados por espaço, sem linhas. */
.matches {
  list-style: none;
  padding: 0;
  display: grid;
  gap: var(--space-6);
}

/* Jogo: sem cartão nem borda — meta, duplas, a tua escolha. */
.match {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

/* Meta numa só linha cinzenta; parte só entre as partes, nunca a meio de uma. */
.match-head {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums;
  line-height: var(--lh-snug);
  color: var(--muted);
}

.match-head span {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Um jogador por linha: só se parte entre jogadores, nunca a meio de um nome. */
.pl {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Jogo fechado: duas linhas; a vencedora a negrito com certo e resultado à direita. */
.versus {
  display: grid;
  gap: var(--space-2);
}

.versus .side {
  display: grid;
  grid-template-columns: var(--icon-s) minmax(0, 1fr) auto;
  align-items: start;
  column-gap: var(--space-2);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
}

.versus .tick {
  display: flex;
  align-items: center;
  height: calc(var(--lh-snug) * 1em);
  color: var(--ok);
}

/* Sem vencedor ainda: sem a coluna do certo, os nomes alinham com a meta. */
.versus:not(:has(.won)) .side {
  grid-template-columns: minmax(0, 1fr) auto;
}

.versus:not(:has(.won)) .tick {
  display: none;
}

.versus .side.won {
  font-weight: var(--fw-heavy);
}

.versus:has(.won) .side:not(.won) {
  color: var(--muted);
}

.versus .res {
  font-weight: var(--fw-heavy);
  font-size: var(--fs-s);
  white-space: nowrap;
}

.teams {
  font-weight: var(--fw-bold);
}

/* Escolha do vencedor: duas opções empilhadas em largura total. */
.opts {
  display: grid;
  gap: var(--space-2);
}

/* Opção: superfície elevada sem contorno; escolhida = fundo menta. */
.opt {
  display: grid;
  align-content: center;
  justify-items: start;
  width: 100%;
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  line-height: var(--lh-snug);
  color: var(--ink);
  background: var(--surface-raised);
  border: 0;
  border-radius: var(--r-control);
  font-weight: var(--fw-semi);
}

.opt:hover {
  background: var(--surface-hover);
}

.opt[aria-pressed="true"] {
  background: var(--pick-bg);
  color: var(--on-pick);
  font-weight: var(--fw-bold);
}

/* A gravar: texto apagado, sem mexer no fundo, para a escolha continuar visível. */
.opt:disabled {
  cursor: not-allowed;
  transform: none;
  color: var(--muted);
}

.opt[aria-pressed="true"]:disabled {
  color: var(--on-pick);
}

.match .btn-ghost {
  justify-self: start;
  font-size: var(--fs-s);
}

.hint {
  color: var(--muted);
  font-size: var(--fs-s);
}

.pick-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  font-size: var(--fs-s);
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-2);
  border-radius: var(--r-pill);
  font-weight: var(--fw-bold);
  font-size: var(--fs-s);
}

.mark.ok {
  color: var(--ok);
  background: var(--ok-wash);
}

.mark.bad {
  color: var(--bad);
  background: var(--bad-wash);
}

/* ---------- quadro em árvore (vista "Quadro") ---------- */

/* Alternador Lista/Quadro: encostado à esquerda; o espaço vertical vem do gap da .wrap. */
.view-switch {
  justify-self: start;
  max-width: 100%;
}

/* Rondas em colunas lado a lado; desliza na horizontal e sangra até à margem da .wrap
   (no telemóvel, até ao limite do ecrã). Contrastes (WCAG), escuro / claro:
   ink sobre --surface-raised 7.6 / 12.6:1; on-pick sobre --pick-bg 10.2 / 5.1:1;
   muted sobre --surface (vazia, isento) 6.3 / 6.5:1; ícone on-pick sobre --ok 8.9 / 5.2:1,
   sobre --bad 7.6 / 6.3:1; anel --ok sobre --bg 9.7 / 4.8:1, --bad 8.3 / 5.9:1. */
.btree {
  display: flex;
  align-items: stretch;
  gap: var(--bt-gap);
  min-width: 0;
  margin-inline: calc(-1 * var(--space-4));
  padding-inline: var(--space-4);
  scroll-padding-inline: var(--space-4);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  border-radius: var(--r-s);
}

/* Foco por dentro: a árvore toca nas margens do ecrã e um anel por fora ficaria cortado. */
.btree:focus-visible {
  outline-offset: calc(-1 * var(--bw-focus));
}

/* Ronda: largura fixa; todas as colunas têm a mesma altura (a da 1.ª ronda). */
.bcol {
  flex: none;
  width: var(--bcol-w);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-snap-align: start;
}

/* Cabeça: nome numa linha e pontos noutra; nunca parte, corta com reticências
   (o title tem o texto inteiro). Altura igual em todas as colunas, para os jogos alinharem. */
.bcol-head {
  font-size: var(--fs-s);
  font-weight: var(--fw-bold);
  line-height: var(--lh-snug);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bcol-head .muted {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  font-variant-numeric: tabular-nums;
}

/* Cada jogo ocupa uma fatia igual da altura; o par fica centrado na fatia.
   Assim o jogo p da ronda r+1 cai a meio dos jogos 2p-1 e 2p da ronda r. */
.bmatches {
  flex: 1;
  display: flex;
  flex-direction: column;
  list-style: none;
  padding: 0;
}

.bmatch {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding-block: var(--space-2);
}

/* Ligações em ângulo reto: cada jogo leva uma linha para a direita até meio do corredor;
   o de cima desce até ao limite da fatia, o de baixo sobe até lá; o jogo seguinte recebe
   uma linha horizontal do meio do corredor. */
.bmatch::before,
.bmatch::after {
  content: "";
  position: absolute;
  width: calc(var(--bt-gap) / 2);
  pointer-events: none;
}

.bmatch::before {
  top: 50%;
  left: calc(var(--bt-gap) / -2);
  border-top: var(--bw) solid var(--bt-line);
}

.bmatch::after {
  right: calc(var(--bt-gap) / -2);
  border-right: var(--bw) solid var(--bt-line);
}

.bmatch:nth-child(odd)::after {
  top: 50%;
  bottom: 0;
  border-top: var(--bw) solid var(--bt-line);
}

.bmatch:nth-child(even)::after {
  top: 0;
  bottom: 50%;
  border-bottom: var(--bw) solid var(--bt-line);
}

.bcol:first-child .bmatch::before,
.bcol:last-child .bmatch::after {
  content: none;
}

/* As duas duplas do jogo, juntas. */
.bpair {
  display: grid;
  gap: var(--space-1);
}

/* Dupla: como .opt — superfície elevada sem contorno, texto à esquerda, alvo de toque. */
.bopt {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  column-gap: var(--space-2);
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--fs-s);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
  text-align: left;
  color: var(--ink);
  background: var(--surface-raised);
  border: 0;
  border-radius: var(--r-control);
}

button.bopt {
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

button.bopt:not([aria-pressed="true"]):not(:disabled):hover {
  background: var(--surface-hover);
}

button.bopt:active {
  transform: scale(var(--press));
}

/* Escolhida (aberta) e escolhida sem resultado (fechada): fundo menta. */
button.bopt[aria-pressed="true"],
.bopt.is-picked,
.bopt.is-ok,
.bopt.is-bad {
  background: var(--pick-bg);
  color: var(--on-pick);
  font-weight: var(--fw-bold);
}

/* A gravar: texto apagado, o fundo da escolha não muda. */
button.bopt:disabled {
  cursor: not-allowed;
  transform: none;
  color: var(--muted);
}

button.bopt[aria-pressed="true"]:disabled {
  color: var(--on-pick);
}

.bname {
  min-width: 0;
}

/* Certa / errada: anel interior na cor do estado e ícone numa pastilha à direita
   (forma + cor, nunca só cor). */
.bopt.is-ok,
.bopt.is-bad {
  grid-template-columns: minmax(0, 1fr) auto;
}

.bopt.is-ok {
  box-shadow: inset 0 0 0 var(--bw-strong) var(--ok);
}

.bopt.is-bad {
  box-shadow: inset 0 0 0 var(--bw-strong) var(--bad);
}

.bmark {
  display: flex;
  padding: var(--space-1);
  border-radius: var(--r-pill);
  color: var(--on-pick);
}

.is-ok .bmark {
  background: var(--ok);
}

.is-bad .bmark {
  background: var(--bad);
}

/* Por definir e o BYE: planos e apagados. */
.bopt.is-empty,
.bopt.is-bye {
  color: var(--muted);
  background: var(--surface);
}

/* Dupla que avança sem jogar: aspeto normal, sem comportamento de botão. */
.bopt.is-bye.is-adv {
  color: var(--ink);
  background: var(--surface-raised);
}

/* ---------- classificação ---------- */

/* Separadores em pílula com ícone; deslizam na horizontal se não couberem. */
.seg {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding: var(--space-1);
  margin: calc(-1 * var(--space-1));
  scrollbar-width: none;
}

.tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  color: var(--ink);
  background-color: var(--surface);
  border: 0;
  border-radius: var(--r-pill);
  font-size: var(--fs-s);
  font-weight: var(--fw-bold);
  white-space: nowrap;
}

.tab:hover {
  background-color: var(--surface-raised);
}

.tab[aria-pressed="true"] {
  background: var(--pick-bg);
  color: var(--on-pick);
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.stepper .btn-ghost {
  min-width: var(--tap);
  padding: 0;
  border-radius: var(--r-pill);
}

.stepper strong {
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: clip;
}

.rank {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

/* Sem linhas entre filas: o espaço e o alinhamento fazem a tabela. */
.rank th,
.rank td {
  padding: var(--space-2) var(--space-1);
  text-align: right;
}

.rank th {
  font-size: var(--fs-2xs);
}

.rank .c-pos {
  width: var(--rank-pos);
  text-align: left;
}

.rank .c-num {
  width: var(--rank-num);
}

.rank .c-name {
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank td.c-num:nth-child(3) {
  font-weight: var(--fw-heavy);
}

.pos {
  display: inline-grid;
  place-items: center;
  min-width: var(--pos-w);
  height: var(--pos-w);
  border: var(--bw) solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--fs-s);
}

/* Pódio por forma e peso: 1.º cheio, 2.º traço forte, 3.º traço fino. */
.rank tr.top-1 .pos {
  background: var(--ink);
  color: var(--bg);
  font-weight: var(--fw-heavy);
}

.rank tr.top-2 .pos {
  border: var(--bw-strong) solid var(--ink);
  font-weight: var(--fw-heavy);
}

.rank tr.top-3 .pos {
  border-color: var(--control-line);
  font-weight: var(--fw-heavy);
}

.rank tr.top-1 td,
.rank tr.top-2 td,
.rank tr.top-3 td {
  font-weight: var(--fw-bold);
}

/* A tua linha: faixa menta suave, bola amarela e "(tu)". */
.rank tr.me td {
  background: var(--accent-wash);
  font-weight: var(--fw-heavy);
}

.rank tr.me td:first-child {
  border-radius: var(--r-s) 0 0 var(--r-s);
}

.rank tr.me td:last-child {
  border-radius: 0 var(--r-s) var(--r-s) 0;
}

.me-ball {
  display: inline-block;
  width: var(--dot);
  height: var(--dot);
  margin-right: var(--space-1);
  border-radius: var(--r-pill);
  background: var(--ball);
  box-shadow: 0 0 0 var(--bw) var(--on-ball);
  vertical-align: middle;
}

.me-tag {
  margin-left: var(--space-1);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--muted);
}

/* Nome como ligação: cor do texto e sublinhado fino; menta no hover/foco.
   Fica em linha para a reticência da célula continuar a cortar; o padding vertical
   alarga o alvo de toque dentro do padding da célula sem aumentar a linha. */
.rank-link {
  padding-block: var(--space-1);
  border-radius: var(--r-s);
  color: inherit;
  font-weight: inherit;
  text-decoration: underline;
  text-decoration-thickness: var(--bw);
  text-decoration-color: var(--line-strong);
  transition: color var(--dur-fast) var(--ease), text-decoration-color var(--dur-fast) var(--ease);
}

.rank-link:hover,
.rank-link:focus-visible {
  color: var(--accent-text);
  text-decoration-color: currentColor;
}

/* A célula corta o que sai dela: o anel de foco fica colado ao texto para não ser cortado. */
.rank-link:focus-visible {
  outline-offset: 0;
}

/* "Estatísticas do quadro" logo a seguir ao seletor: largura do texto, encostado à esquerda;
   o espaço acima e abaixo é o gap do .panel. */
.panel > .field + .btn-ghost {
  justify-self: start;
  font-size: var(--fs-s);
}

/* ---------- estatísticas do quadro ---------- */

/* Cinco superfícies planas, separadas por espaço (como as rondas). */
.stats {
  display: grid;
  gap: var(--space-3);
}

.stat-card {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  min-width: 0;
  padding: var(--space-5) var(--space-4);
  border-radius: var(--r-card);
  background: var(--surface);
}

.stat-card > h2 {
  font-size: var(--fs-m);
}

.stat-card > .muted {
  max-width: var(--measure);
  font-size: var(--fs-s);
  line-height: var(--lh-snug);
}

/* Corpo do cartão: um pouco mais afastado da explicação. */
.stat-card > .stat-list,
.stat-card > .stat-who,
.stat-card > .hint {
  margin-top: var(--space-2);
}

/* Filas separadas por linha fina. */
.stat-list {
  list-style: none;
  padding: 0;
  display: grid;
}

.stat-row {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding-block: var(--space-4);
  border-top: var(--bw) solid var(--line);
}

.stat-row:first-child {
  padding-top: 0;
  border-top: 0;
}

.stat-row:last-child {
  padding-bottom: 0;
}

/* Ronda · Jogo: meta pequena, como a cabeça do jogo. */
.stat-row > .muted:first-child {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
}

/* Detalhe por baixo da barra: nomes longos partem em vez de sair do cartão. */
.stat-row > .muted:last-child {
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  overflow-wrap: anywhere;
}

/* Dupla à esquerda (um jogador por linha, cortado com reticências; o title tem o nome
   inteiro) e percentagem à direita, alinhada com a última linha. */
.stat-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  column-gap: var(--space-3);
  font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
}

.stat-name {
  min-width: 0;
}

.stat-pct {
  font-weight: var(--fw-heavy);
  white-space: nowrap;
}

/* Barra: trilho neutro e fino, enchimento na cor de acento (legível em claro e escuro).
   Em "Jogos mais divididos" cada barra fica logo por baixo da sua dupla. */
.stat-bar {
  display: block;
  height: var(--bar-h);
  border-radius: var(--r-pill);
  background: var(--surface-raised);
  overflow: hidden;
}

.stat-fill {
  display: block;
  width: var(--pct);
  max-width: 100%;
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--accent-edge);
}

/* Mais / menos ousado: o nome é o destaque; vários nomes partem em segurança. */
.stat-who {
  font-size: var(--fs-l);
  font-weight: var(--fw-heavy);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-snug);
  overflow-wrap: anywhere;
}

.stat-card > .stat-who + .muted {
  font-size: var(--fs-xs);
}

/* ---------- ligas ---------- */

.leagues {
  list-style: none;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.league h3 {
  font-size: var(--fs-l);
  overflow-wrap: anywhere;
}

/* Código como um bilhete: mono, grande, sobre fundo de campo, sem contorno. */
.code {
  justify-self: start;
  max-width: 100%;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--r-control);
  background: var(--field-bg);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xl);
  font-weight: var(--fw-heavy);
  letter-spacing: var(--ls-code);
  line-height: var(--lh-snug);
  overflow-wrap: anywhere;
}

.league .actions .btn-danger {
  margin-left: auto;
}

/* ---------- perfil ---------- */

.facts {
  display: grid;
  gap: var(--space-4);
}

.facts div {
  display: grid;
  gap: var(--space-1);
}

.facts dd {
  font-weight: var(--fw-bold);
  overflow-wrap: anywhere;
}

/* ---------- admin ---------- */

.readonly {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  justify-self: start;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

/* ---------- barra inferior: cápsula flutuante ---------- */

body:has(.tabbar) {
  padding-bottom: calc(var(--nav-h) + 2 * var(--space-3) + env(safe-area-inset-bottom));
}

.tabbar {
  position: fixed;
  z-index: var(--z-nav);
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + var(--space-3));
  width: min(calc(100% - 2 * var(--space-3)), var(--nav-maxw));
  height: var(--nav-h);
  margin: 0 auto;
  padding: calc((var(--nav-h) - var(--tap)) / 2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background-color: var(--nav-bg);
  border: var(--bw) solid var(--line-strong);
  border-radius: var(--r-pill);
  box-shadow: var(--elev-1);
}

.tabbar a {
  flex: 1 1 var(--tap);
  min-width: var(--tap);
  height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--r-pill);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

/* Inativas: só o ícone; o rótulo fica para leitores de ecrã. */
.tabbar a:not([aria-current="page"]) span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.tabbar a:hover {
  color: var(--ink);
  background: var(--surface-raised);
}

/* Ativa: pílula menta com rótulo. */
.tabbar a[aria-current="page"] {
  flex: 0 1 auto;
  min-width: 0;
  padding: 0 var(--space-3);
  background: var(--accent);
  color: var(--on-accent);
}

.tabbar a[aria-current="page"] span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cinco entradas a 360 px: menos folga na pílula ativa. */
.tabbar:has(> a:nth-child(5)) {
  gap: 0;
}

.tabbar:has(> a:nth-child(5)) a[aria-current="page"] {
  padding: 0 var(--space-2);
  gap: var(--space-1);
}

/* ---------- páginas legais ---------- */

/* privacidade.html e termos.html: <main class="wrap"><article class="panel">. */
main.wrap > article {
  gap: var(--space-4);
  line-height: var(--lh-prose);
}

main.wrap > article > * {
  max-width: var(--measure);
}

main.wrap > article h2 {
  margin-top: var(--space-4);
}

main.wrap > article ul {
  padding-left: var(--space-5);
  display: grid;
  gap: var(--space-2);
}

/* Texto inicial do index.html e <noscript>. */
.loading {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--muted);
}

/* ---------- ecrãs maiores: só mais folga, o mesmo layout (o limite não aceita variáveis) ---------- */

@media (min-width: 40rem) {
  .wrap {
    padding: 0 var(--space-5) var(--space-6);
  }

  .panel,
  .bracket .round,
  .stat-card {
    padding: var(--space-5);
  }

  /* 100vw conta a barra de scroll vertical: corta essa sobra em vez de criar scroll na página. */
  body {
    overflow-x: clip;
  }

  /* A árvore sai da coluna e usa a largura do ecrã; as 4 rondas (16 duplas) ficam centradas
     e cabem inteiras a partir de ~1280px. Abaixo disso, desliza na horizontal como antes. */
  .btree {
    width: 100vw;
    margin-inline: calc(50% - 50vw);
    padding-inline: max(var(--space-5), calc((100vw - 4 * var(--bcol-w) - 3 * var(--bt-gap)) / 2));
    scroll-padding-inline: var(--space-5);
  }

  .btn-google {
    width: auto;
    justify-self: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none;
    transition: none;
  }

  .btn:active,
  .btn-ghost:active,
  .btn-danger:active,
  .btn-google:active,
  .opt:active,
  .tab:active,
  button.bopt:active {
    transform: none;
  }
}
