/* ==========================================================================
   Design tokens: l'unico posto in cui si definiscono colori, raggi, spazi
   Contrasti misurati (WCAG) sulla card --surface-2: testo 15:1, testo-2 7.6:1,
   testo-3 5.4:1, accento 12.9:1, colori sport > 7:1.
   ========================================================================== */
@font-face { font-family: "Inter"; src: url("fonts/inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("fonts/space-grotesk.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }

:root {
  --bg: #0E1116;
  --surface-1: #151A21;
  --surface-2: #1A1F27;
  --surface-3: #232A34;
  --border: #262D37;
  --border-strong: #36404D;
  --text: #F2F5F7;
  --text-2: #A7B1BE;
  --text-3: #8A95A3;
  --accent: #C6F432;
  --on-accent: #0E1116;
  --accent-soft: rgba(198, 244, 50, .12);
  --success: #4ADE80;
  --warning: #FFB547;
  --error: #FF7A7A;
  --calcio: #2DD4BF;
  --basket: #FF9F43;
  --tennis: #6CB6FF;

  --r-lg: 20px; --r-md: 14px; --r-sm: 10px; --r-pill: 999px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-num: "Space Grotesk", "Inter", system-ui, sans-serif;
  --tab-h: 64px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 15px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
/* fascia dietro la barra di stato dell'iPhone (modalità app) */
body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: var(--safe-t); background: var(--bg); z-index: 25; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 20px; height: 20px; flex: none; }

/* ---------- Layout ---------- */
#app { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + var(--s4)) var(--s4) calc(var(--tab-h) + var(--safe-b) + var(--s6)); }
.view { animation: entra .28s var(--ease) both; }
@keyframes entra { from { opacity: 0; transform: translateY(8px); } }
.view.dettaglio { animation-name: entra-lato; }
@keyframes entra-lato { from { opacity: 0; transform: translateX(16px); } }

.top { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin: var(--s2) 0 var(--s4); }
.top h1 { font: 700 30px/1.05 var(--font-num); letter-spacing: -.02em; }
.top p { color: var(--text-3); font-size: 13px; margin-top: var(--s1); }
.stato-dati { display: inline-flex; align-items: center; gap: 6px; }
.stato-dati::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.stato-dati.off::before { background: var(--warning); }

/* ---------- Filtri a pillola ---------- */
.filtri {
  position: sticky; top: var(--safe-t); z-index: 5; display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--s4)); padding: var(--s2) var(--s4) var(--s3);
  background: linear-gradient(var(--bg) 75%, transparent);
}
.filtri::-webkit-scrollbar { display: none; }
.pill {
  min-height: 44px; padding: 0 var(--s4); border-radius: var(--r-pill); border: 1px solid var(--border-strong);
  background: var(--surface-1); color: var(--text-2); font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: var(--s2); white-space: nowrap;
  transition: background .2s, color .2s, border-color .2s, transform .12s;
}
.pill:active { transform: scale(.96); }
.pill svg { width: 16px; height: 16px; }
.pill[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.pill[aria-pressed="true"] svg { color: var(--on-accent) !important; }

/* ---------- Gruppi per giorno ---------- */
.giorno { margin-top: var(--s5); }
.giorno h2 {
  display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s3);
  font: 600 13px var(--font-ui); text-transform: uppercase; letter-spacing: .08em; color: var(--text-3);
}
.giorno h2 b { color: var(--text); font-weight: 600; }
.giorno h2 .conta { margin-left: auto; letter-spacing: 0; text-transform: none; font-weight: 500; }
.lista { display: grid; gap: var(--s3); }

/* ---------- Card partita ---------- */
.card {
  --sport: var(--accent);
  position: relative; display: block; width: 100%; text-align: left; overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent 40%), var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4);
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 8px 24px rgba(0,0,0,.30);
  transition: transform .15s var(--ease), border-color .15s; color: inherit; text-decoration: none;
}
.card:active { transform: scale(.98); border-color: var(--border-strong); }
.card::before { content: ""; position: absolute; left: 0; top: var(--s4); bottom: var(--s4); width: 3px; border-radius: 0 3px 3px 0; background: var(--sport); }
.s-calcio { --sport: var(--calcio); } .s-basket { --sport: var(--basket); } .s-tennis { --sport: var(--tennis); }

.meta { display: flex; align-items: center; gap: var(--s2); min-height: 20px; font-size: 12px; font-weight: 500; color: var(--text-3); }
.tag { display: inline-flex; align-items: center; gap: 6px; color: var(--sport); font-weight: 600; min-width: 0; }
.tag svg { width: 14px; height: 14px; }
.tag span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .turno { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ora { margin-left: auto; font: 600 13px var(--font-num); color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.live { color: var(--error); display: inline-flex; align-items: center; gap: 5px; }
.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulsa 1.4s infinite; }
@keyframes pulsa { 50% { opacity: .3; } }

.squadre { margin: var(--s3) 0 var(--s3); display: grid; gap: var(--s2); }
.sq { display: flex; align-items: center; gap: var(--s3); min-height: 32px; font-weight: 600; font-size: 16px; }
.sq .nome { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sq .rk { color: var(--text-3); font: 500 12px var(--font-num); }
.stemma {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  font: 700 11px var(--font-num); letter-spacing: -.02em; color: var(--sport);
  background: color-mix(in srgb, var(--sport) 14%, var(--surface-3));
  border: 1px solid color-mix(in srgb, var(--sport) 35%, transparent);
}
.stemma.img { background: rgba(255,255,255,.04); border-color: var(--border); }
.stemma img { width: 24px; height: 24px; object-fit: contain; }
.stemma.xl { width: 64px; height: 64px; font-size: 18px; }
.stemma.xl img { width: 46px; height: 46px; }
.forma { margin-left: auto; display: flex; gap: 3px; flex: none; }
.forma i { width: 18px; height: 18px; border-radius: 5px; font: 700 10px/18px var(--font-num); text-align: center; font-style: normal; color: var(--on-accent); }
.forma .V { background: var(--success); } .forma .N { background: var(--text-3); } .forma .P { background: var(--error); }

.recap { font-size: 13px; color: var(--text-2); border-top: 1px solid var(--border); padding-top: var(--s3); }
.pick { margin-top: var(--s3); display: flex; align-items: center; gap: var(--s3); background: var(--surface-3); border-radius: var(--r-md); padding: 10px var(--s3); min-height: 56px; }
.pick > div { min-width: 0; }
.pick small { display: block; font-size: 11px; font-weight: 500; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.pick b { display: block; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .pct { margin-left: auto; font: 700 24px var(--font-num); color: var(--accent); font-variant-numeric: tabular-nums; }
.pick.vuoto { color: var(--text-3); font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-alta { color: var(--success); background: rgba(74,222,128,.12); }
.b-media { color: var(--warning); background: rgba(255,181,71,.12); }
.b-bassa { color: var(--error); background: rgba(255,122,122,.12); }

.stella { width: 44px; height: 44px; margin: -12px -12px -12px 0; display: grid; place-items: center; color: var(--text-3); flex: none; border-radius: 50%; transition: transform .2s var(--ease), color .2s; }
.stella:active { transform: scale(.85); }
.stella[aria-pressed="true"] { color: var(--accent); }
.stella[aria-pressed="true"] svg { fill: currentColor; }

/* ---------- Avvisi e stati vuoti ---------- */
.avviso { display: flex; gap: var(--s3); align-items: flex-start; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3) var(--s4); font-size: 13px; color: var(--text-2); margin-top: var(--s3); }
.avviso svg { color: var(--warning); width: 18px; height: 18px; margin-top: 1px; }
.vuoto-grande { text-align: center; padding: var(--s6) var(--s4); color: var(--text-2); }
.vuoto-grande svg { width: 40px; height: 40px; color: var(--text-3); margin: 0 auto var(--s3); }
.vuoto-grande b { display: block; color: var(--text); font-size: 16px; margin-bottom: var(--s1); }
.disclaimer { margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); text-align: center; }

/* ---------- Skeleton ---------- */
.sk-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); display: grid; gap: var(--s3); }
.sk { height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--surface-3) 0, #2C3440 50%, var(--surface-3) 100%); background-size: 200% 100%; animation: luccica 1.4s infinite linear; }
.sk.alto { height: 44px; border-radius: var(--r-md); }
@keyframes luccica { to { background-position: -200% 0; } }

/* ---------- Ricerca ---------- */
.cerca { position: relative; margin-bottom: var(--s4); }
.cerca svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.cerca input {
  width: 100%; height: 52px; border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text); font: 500 16px var(--font-ui); padding: 0 48px 0 44px; outline: none; -webkit-appearance: none;
  transition: border-color .2s, box-shadow .2s;
}
.cerca input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cerca input::placeholder { color: var(--text-3); }
.cerca input::-webkit-search-cancel-button, .cerca input::-webkit-search-decoration { -webkit-appearance: none; display: none; }
.cerca .pulisci { position: absolute; right: 4px; top: 4px; width: 44px; height: 44px; display: grid; place-items: center; color: var(--text-3); }
.recenti { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip { min-height: 44px; display: inline-flex; align-items: center; gap: var(--s2); padding: 0 var(--s4); border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); font-size: 14px; font-weight: 500; }
.chip svg { width: 16px; height: 16px; color: var(--text-3); }
.titoletto { display: flex; align-items: center; justify-content: space-between; margin: var(--s5) 0 var(--s3); font: 600 13px var(--font-ui); text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.titoletto button { min-height: 44px; padding: 0 var(--s2); color: var(--text-2); text-transform: none; letter-spacing: 0; font-weight: 500; }
mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; }

/* ---------- Scheda partita ---------- */
.barra-sup { display: flex; align-items: center; justify-content: space-between; margin: 0 -10px var(--s3); }
.indietro, .azione { min-width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 2px; border-radius: var(--r-pill); color: var(--text-2); font-weight: 500; padding: 0 10px; }
.indietro:active, .azione:active { background: var(--surface-2); }
.azione[aria-pressed="true"] { color: var(--accent); }
.azione[aria-pressed="true"] svg { fill: currentColor; }
.hero { position: relative; text-align: center; padding: var(--s5) var(--s4); border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--border);
  background: radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--sport) 16%, transparent), transparent 70%), var(--surface-2); }
.hero .tag { justify-content: center; font-size: 13px; }
.hero .quando { color: var(--text-2); font: 600 14px var(--font-num); margin-top: var(--s1); }
.contro { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: var(--s2); margin-top: var(--s5); }
.lato { display: grid; justify-items: center; gap: var(--s2); min-width: 0; }
.lato .nome { font-weight: 600; font-size: 15px; line-height: 1.25; }
.lato .sub { font-size: 12px; color: var(--text-3); }
.lato .segui { min-height: 44px; padding: 0 var(--s3); border-radius: var(--r-pill); display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: 12px; font-weight: 600; border: 1px solid var(--border); }
.lato .segui svg { width: 14px; height: 14px; }
.lato .segui[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.lato .segui[aria-pressed="true"] svg { fill: currentColor; }
.vs { font: 700 14px var(--font-num); color: var(--text-3); margin-top: 22px; }
.luogo { margin-top: var(--s4); font-size: 12px; color: var(--text-3); }

.sez { margin-top: var(--s3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); }
.sez h3 { display: flex; align-items: center; gap: var(--s2); font-size: 15px; font-weight: 600; margin-bottom: var(--s4); }
.sez h3 svg { color: var(--accent); width: 18px; height: 18px; }
.sez h3 .badge { margin-left: auto; }
.esito { display: flex; align-items: center; gap: var(--s3); background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-radius: var(--r-md); padding: var(--s3); margin-bottom: var(--s4); }
.esito small { display: block; font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.esito b { font-size: 16px; }
.esito .pct { margin-left: auto; font: 700 30px var(--font-num); color: var(--accent); }
.gruppo-barre + .gruppo-barre { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border); }
.gruppo-barre h4 { font-size: 12px; font-weight: 500; color: var(--text-3); margin-bottom: var(--s2); text-transform: uppercase; letter-spacing: .06em; }
.barra { display: grid; grid-template-columns: minmax(64px, 30%) 1fr 44px; align-items: center; gap: var(--s3); min-height: 28px; font-size: 13px; color: var(--text-2); }
.barra > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.traccia { height: 10px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.riemp { height: 100%; width: 0; border-radius: inherit; background: var(--text-3); transition: width .9s var(--ease); }
.riemp.top { background: var(--accent); }
.barra .v { text-align: right; font: 600 14px var(--font-num); color: var(--text); font-variant-numeric: tabular-nums; }
.motivi { list-style: none; display: grid; gap: var(--s2); margin-top: var(--s4); }
.motivi li { display: flex; gap: 10px; font-size: 14px; color: var(--text-2); }
.motivi li::before { content: ""; flex: none; width: 6px; height: 6px; margin-top: 8px; border-radius: 50%; background: var(--accent); }
.nota { margin-top: var(--s4); font-size: 12px; color: var(--text-3); }
.nota.forte { color: var(--warning); display: flex; gap: var(--s2); }
.disc-sez { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }

.due-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.col h4 { font-size: 13px; font-weight: 600; margin-bottom: var(--s2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.righe { list-style: none; display: grid; gap: 6px; }
.righe li { display: flex; align-items: center; gap: var(--s2); font-size: 12px; color: var(--text-2); min-width: 0; }
.righe li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.righe .num { color: var(--text); margin-left: auto; flex: none; }
.pallino { width: 18px; height: 18px; flex: none; border-radius: 5px; font: 700 10px/18px var(--font-num); text-align: center; color: var(--on-accent); }
.pallino.V { background: var(--success); } .pallino.N { background: var(--text-3); } .pallino.P { background: var(--error); }
.tab-class { width: 100%; border-collapse: collapse; font-size: 13px; }
.tab-class th { font-weight: 500; color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; text-align: right; padding: 0 0 var(--s2); }
.tab-class th:first-child, .tab-class td:first-child { text-align: left; }
.tab-class td { padding: var(--s2) 0; border-top: 1px solid var(--border); text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.tab-class td:first-child { font-family: var(--font-ui); font-weight: 600; }
.tab-class td .pos { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: var(--surface-3); font: 600 12px var(--font-num); margin-right: var(--s2); }
.vuoto { font-size: 13px; color: var(--text-3); }
.aggiornato { margin-top: var(--s4); text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- Barra di navigazione ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  padding: 6px var(--s4) calc(6px + var(--safe-b)); background: rgba(21, 26, 33, .86);
  backdrop-filter: saturate(140%) blur(18px); -webkit-backdrop-filter: saturate(140%) blur(18px);
  border-top: 1px solid var(--border);
}
.tabbar .dentro { display: flex; justify-content: space-around; width: 100%; max-width: 560px; }
.tabbar a { min-width: 76px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 500; color: var(--text-3); text-decoration: none; transition: color .2s; }
.tabbar a svg { width: 24px; height: 24px; transition: transform .2s var(--ease); }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar a[aria-current="page"] svg { transform: translateY(-1px); }
.tabbar a:active svg { transform: scale(.88); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + var(--s4)); transform: translate(-50%, 20px); opacity: 0; background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text); font-size: 14px; font-weight: 500; padding: 10px var(--s4); border-radius: var(--r-pill); transition: opacity .2s, transform .25s var(--ease); pointer-events: none; z-index: 30; white-space: nowrap; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
