/* Tennis&Friends — modulo tabellone, stile Sofascore (vedi design/richieste-2026-11-07/PIANO.md, D8).
   Solo token della spec: nessun hex nuovo. Pillola attiva = --verde-900 (come la tab attiva «Tabellone» del mockup 02):
   quasi nero come Sofascore, ma dentro la famiglia verde dell'app. Fondo delle colonne = --nebbia-100. */

.tbs {
  --tbs-card: 208px; --tbs-gap: 44px; --tbs-cella: 108px; --tbs-riga: 32px; --tbs-pad: 16px;
  --tbs-linea: color-mix(in srgb, var(--linea-tabellone) 38%, transparent);
  margin-top: 12px;
}
@media (min-width: 1024px) { .tbs { --tbs-card: 236px; --tbs-gap: 56px; --tbs-cella: 112px; } }

/* ---- testata: selettore, schermo intero, pillole dei turni ---- */
.tbs-testa {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; margin-inline: calc(var(--margine) * -1); padding: 8px var(--margine) 0;
  background: var(--foglio); border-bottom: 1px solid var(--filo);
}
.tbs-riga-alta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tbs-sel { position: relative; }
.tbs-schede { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--filo-forte); border-radius: var(--r-box); background: var(--nebbia-100); }
.tbs-schede button {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 18px; border: 0; border-radius: var(--r-cella);
  background: transparent; color: var(--inchiostro); font: 600 16px/1 var(--font-testo); cursor: pointer;
  transition: background-color var(--t-breve) var(--ease), transform var(--t-press) var(--ease);
}
.tbs-schede button .ico-svg { width: 20px; height: 20px; }
.tbs-schede button.attiva { background: var(--carta); box-shadow: var(--ombra-1); color: var(--verde-900); }
.tbs-schede button:not(.attiva):active { transform: scale(.98); background: var(--menta-50); }
.tbs-schede button:focus-visible { outline: 2px solid var(--verde-azione); outline-offset: 2px; }
.tbs-sel-btn {
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 8px 0 14px; border: 1px solid var(--filo-forte); border-radius: var(--r-box);
  background: var(--carta); color: var(--inchiostro); font: 600 16px/1 var(--font-testo); cursor: pointer;
  transition: background-color var(--t-breve) var(--ease), transform var(--t-press) var(--ease);
}
.tbs-sel-btn.fisso { padding-right: 16px; cursor: default; }
.tbs-sel-btn .ico-svg { width: 20px; height: 20px; }
.tbs-sel-btn:not(.fisso):active { transform: scale(.98); background: var(--menta-50); }
.tbs-freccia { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--nebbia-100); }
.tbs-freccia .ico-svg { width: 16px; height: 16px; }
.tbs-sel-btn[aria-expanded="true"] .tbs-freccia .ico-svg { transform: rotate(180deg); }
.tbs-menu {
  position: absolute; z-index: 6; top: calc(100% + 6px); left: 0; min-width: 190px; padding: 6px;
  background: var(--carta); border: 1px solid var(--filo-forte); border-radius: var(--r-box); box-shadow: var(--ombra-2);
}
.tbs-menu[hidden] { display: none; }
.tbs-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--r-cella);
  background: transparent; color: var(--inchiostro); font: 600 15px/1 var(--font-testo); text-align: left; cursor: pointer;
}
.tbs-menu button .ico-svg { width: 20px; height: 20px; }
.tbs-menu button span { flex: 1; }
.tbs-menu button .ico-svg:last-child:not(:first-child) { color: var(--verde-azione); }
.tbs-menu button.attiva { background: var(--menta-100); }
.tbs-menu button:active { background: var(--menta-200); }
.tbs-pieno-btn {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; border: 1px solid var(--filo-verde); border-radius: var(--r-box);
  background: var(--menta-100); color: var(--verde-900); cursor: pointer;
  transition: background-color var(--t-breve) var(--ease), transform var(--t-press) var(--ease);
}
.tbs-pieno-btn:active { transform: scale(.94); background: var(--menta-200); }
.tbs-pieno-btn .ico-svg { width: 22px; height: 22px; }
.tbs-ico-comprimi, .tbs-pieno .tbs-ico-espandi { display: none; }
.tbs-pieno .tbs-ico-comprimi { display: grid; }

.tbs-turni {
  position: relative; display: flex; gap: 8px; margin-inline: calc(var(--margine) * -1); padding: 10px var(--margine) 12px;
  overflow-x: auto; scrollbar-width: none; scroll-padding-inline: var(--margine); overscroll-behavior-x: contain;
}
.tbs-turni::-webkit-scrollbar { display: none; }
.tbs-turni [role="tab"] {
  flex: none; min-width: 44px; height: 44px; padding: 0 18px; border: 0; border-radius: var(--r-pill);
  background: var(--nebbia-100); color: var(--inchiostro); font: 600 15px/1 var(--font-testo); white-space: nowrap; cursor: pointer;
  transition: background-color var(--t-breve) var(--ease), color var(--t-breve) var(--ease), transform var(--t-press) var(--ease);
}
.tbs-turni [role="tab"]:active { transform: scale(.96); }
.tbs-turni [role="tab"][aria-selected="true"] { background: var(--verde-900); color: #fff; }

/* ---- area scorrevole ---- */
.tbs-area {
  container-type: inline-size; margin-inline: calc(var(--margine) * -1); background: var(--nebbia-100);
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding-inline: var(--tbs-pad);
  scrollbar-width: none; outline-offset: -3px;
}
.tbs-area::-webkit-scrollbar { display: none; }
.tbs-tela { display: flex; width: max-content; min-width: 100%; height: calc(var(--tbs-righe) * var(--tbs-cella) * var(--tbs-s, 1) + var(--tbs-pad) + 34px); padding: var(--tbs-pad) var(--tbs-pad) 0; }
.tbs-col { flex: 0 0 calc(var(--tbs-card) + var(--tbs-gap)); width: calc(var(--tbs-card) + var(--tbs-gap)); height: calc(var(--tbs-righe) * var(--tbs-cella) * var(--tbs-s, 1)); scroll-snap-align: start; }
.tbs-col.finale { flex-basis: calc(var(--tbs-card) + 120px); width: calc(var(--tbs-card) + 120px); }
.tbs-coda { flex: 0 0 max(0px, calc(100cqw - var(--tbs-card) - var(--tbs-gap) - 2 * var(--tbs-pad))); }
.tbs-celle { height: 100%; display: flex; flex-direction: column; }
.tbs-coppia { position: relative; flex: 2; display: flex; flex-direction: column; min-height: 0; }
.tbs-cella { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; padding-right: var(--tbs-gap); }
.tbs-col.finale .tbs-cella { padding-right: 0; gap: 14px; }

/* linee di collegamento: due partite → la successiva (coppia), oppure 1:1 (diretta, es. S1 → Silver) */
.tbs-coppia > .tbs-cella::after, .tbs-cella.diretta::after, .tbs-coppia::after { content: ''; position: absolute; top: 50%; height: 0; margin-top: -1px; border-top: 2px solid var(--tbs-linea); pointer-events: none; }
.tbs-coppia > .tbs-cella::after { right: calc(var(--tbs-gap) / 2); width: calc(var(--tbs-gap) / 2); }
.tbs-coppia::before { content: ''; position: absolute; top: 25%; bottom: 25%; right: calc(var(--tbs-gap) / 2 - 1px); width: 0; border-left: 2px solid var(--tbs-linea); pointer-events: none; }
.tbs-coppia::after { right: 0; width: calc(var(--tbs-gap) / 2); }
.tbs-cella.diretta::after { right: 0; width: var(--tbs-gap); }

/* ---- card partita ---- */
.tbs-card {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; width: 100%; margin: 0;
  padding: 4px 12px 4px 10px; background: var(--carta); border: 1px solid var(--filo); border-radius: var(--r-box); box-shadow: var(--ombra-1);
  color: var(--inchiostro); font: inherit; text-align: left; -webkit-tap-highlight-color: transparent;
}
button.tbs-card { cursor: pointer; transition: transform var(--t-press) var(--ease), box-shadow var(--t-breve) var(--ease); }
button.tbs-card:active { transform: scale(.985); }
.tbs-card.mia { border-color: var(--verde-azione); box-shadow: 0 0 0 1px var(--verde-azione), var(--ombra-1); }
.tbs-card.attenuata { background: transparent; box-shadow: none; border-style: dashed; border-color: var(--filo-forte); }
.tbs-card.attenuata .tbs-riga { color: var(--grigio); }
.tbs-card .avatar { box-shadow: none; }
.tbs-lati { display: grid; grid-auto-rows: var(--tbs-riga); min-width: 0; }
.tbs-riga { display: flex; align-items: center; gap: 8px; min-width: 0; font: 500 14px/1.1 var(--font-testo); color: var(--grigio-chiaro); }
.tbs-riga.vince { color: var(--inchiostro); font-weight: 700; }
.tbs-riga:not(.vince):not(.perde):not(.segnaposto):not(.bye) { color: var(--inchiostro); font-weight: 600; }
.tbs-riga.segnaposto, .tbs-riga.bye { font-weight: 500; }
.tbs-riga.bye .tbs-nome { font-style: italic; }
.tbs-nome { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tbs-seed {
  flex: none; display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--cielo-testo); color: #fff; font: 800 11px/1 var(--font-titoli); font-variant-numeric: tabular-nums;
}
.tbs-disco {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--nebbia-100); color: var(--grigio);
  font: 700 10px/1 var(--font-titoli);
}
.tbs-esito { display: grid; grid-auto-rows: var(--tbs-riga); justify-items: end; align-items: center; min-width: 14px; font: 600 15px/1 var(--font-titoli); font-variant-numeric: tabular-nums; }
.tbs-n { color: var(--grigio-chiaro); }
.tbs-n.vince { color: var(--inchiostro); font-weight: 800; }
.tbs-esito.testo { grid-auto-rows: auto; align-content: center; align-self: stretch; color: var(--grigio-chiaro); font: 600 13px/1.2 var(--font-testo); }
.tbs-quando { display: grid; gap: 2px; justify-items: end; color: var(--grigio-chiaro); font: 500 13px/1.1 var(--font-testo); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbs-quando b { font-weight: 600; color: var(--grigio); }
.tbs-badge-finale {
  position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); padding: 3px 10px; border: 1px solid var(--oro); border-radius: var(--r-pill);
  background: var(--oro-50); color: var(--oro-testo); font: 800 12px/1.1 var(--font-titoli); letter-spacing: .01em; pointer-events: none;
}
.tbs-trofeo { flex: none; display: grid; justify-items: center; gap: 4px; width: 92px; }
.tbs-coppa { width: 52px; height: 61px; }
.tbs-vincitore { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--inchiostro); font: 700 12px/1.2 var(--font-testo); }

/* ---- schermo intero (API Fullscreen oppure, dove manca, a tutta finestra) ---- */
body.tbs-blocca { overflow: hidden; }
.tbs.tbs-pieno {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; margin: 0; background: var(--foglio);
  padding-top: env(safe-area-inset-top);
}
.tbs-pieno .tbs-testa { position: static; margin-inline: 0; padding-inline: var(--margine); }
.tbs-pieno .tbs-turni { margin-inline: calc(var(--margine) * -1); }
.tbs-pieno .tbs-area { flex: 1; min-height: 0; margin-inline: 0; overflow-y: auto; }
/* schermo intero col telefono in orizzontale: selettore, pillole e bottone su una sola riga per lasciare spazio al tabellone */
@media (max-height: 520px) {
  .tbs-pieno .tbs-testa { display: flex; align-items: center; gap: 12px; padding-block: 6px; }
  .tbs-pieno .tbs-riga-alta { display: contents; }
  .tbs-pieno .tbs-sel { order: 1; }
  .tbs-pieno .tbs-turni { order: 2; flex: 1; min-width: 0; margin-inline: 0; padding: 0; }
  .tbs-pieno .tbs-pieno-btn { order: 3; }
}

@media (min-width: 1024px) {
  .tbs { border: 1px solid var(--filo); border-radius: var(--r-card); }
  .tbs-testa { margin-inline: 0; border-radius: var(--r-card) var(--r-card) 0 0; padding-inline: 20px; }
  .tbs-turni { margin-inline: -20px; padding-inline: 20px; scroll-padding-inline: 20px; }
  .tbs-area { margin-inline: 0; border-radius: 0 0 var(--r-card) var(--r-card); }
  .tbs.tbs-pieno { border: 0; border-radius: 0; }
  .tbs-pieno .tbs-testa, .tbs-pieno .tbs-area { border-radius: 0; }
}

@media (hover: hover) {
  .tbs-sel-btn:not(.fisso):hover, .tbs-pieno-btn:hover { background: var(--menta-50); }
  .tbs-turni [role="tab"][aria-selected="false"]:hover { background: var(--menta-100); }
  .tbs-menu button:hover { background: var(--menta-50); }
  button.tbs-card:hover { box-shadow: var(--ombra-2); }
}
@media (prefers-reduced-motion: reduce) {
  .tbs *, .tbs *::before, .tbs *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .tbs-area, .tbs-turni { scroll-behavior: auto; }
}
