/* Stile comune all'area di gestione e alla pagina pubblica.
   Palette e tono del prototipo (lega-tappe-op.html), con due ritocchi di contrasto:
   --red-fill per lo sfondo dei pulsanti e --red-text per le scritte rosse.
   Nota: la Content-Security-Policy vieta gli attributi style="..." nell'HTML,
   quindi tutto lo stile passa da classi definite qui. */

:root {
  --ink: #0E1726; --panel: #16233A; --panel-soft: #1C2C47; --line: #2A3B58;
  --parchment: #EDE4CF; --muted: #8A98B0;
  --red: #D6362E;       /* accenti e bordi (es. scheda attiva) */
  --red-fill: #B92D26;  /* sfondo dei pulsanti principali: testo chiaro leggibile */
  --red-text: #E5544B;  /* scritte rosse su fondo scuro */
  --gold: #C9A24B; --gold-soft: #3A3220;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --nav-h: 0px;     /* altezza della barra di navigazione in basso (solo telefono) */
  --azioni-h: 0px;  /* altezza della barra delle azioni fissa (se presente) */
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--ink); color: var(--parchment); font-family: var(--sans);
  min-height: 100vh; line-height: 1.4; -webkit-tap-highlight-color: transparent;
}
.serif { font-family: var(--serif); }
.num { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
a { color: var(--gold); }
.nascosto { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- intestazione e contenuto ---------- */
.testata { background: var(--panel); border-bottom: 1px solid var(--line); padding: 16px; }
.wrap { max-width: 980px; margin: 0 auto; }
.testata .wrap { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.kicker { font-size: 12px; color: var(--gold); margin-bottom: 2px; }
.kicker a { color: inherit; text-decoration: none; }
h1 { font-family: var(--serif); font-size: 24px; font-weight: 400; }
h2 { font-family: var(--serif); font-size: 22px; font-weight: 400; }
h3 { font-family: var(--serif); font-size: 18px; font-weight: 400; }
.meta { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.5; }
.meta b { color: var(--parchment); font-weight: 600; }
main { max-width: 980px; margin: 0 auto; padding: 20px 16px calc(32px + var(--nav-h) + var(--azioni-h) + env(safe-area-inset-bottom)); }
.sub { font-size: 14px; color: var(--muted); margin: 6px 0 16px; max-width: 68ch; }
.sezione { margin-top: 28px; }
.sezione > h3 { margin-bottom: 10px; }
.hint { font-size: 13px; color: var(--muted); }
.vuoto { color: var(--muted); padding: 8px 0; }
.riga-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tra { justify-content: space-between; }
.spazio-sopra { margin-top: 16px; }
.spazio-sotto { margin-bottom: 16px; }

/* ---------- pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  background: var(--red-fill); color: var(--parchment); font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: transform 120ms var(--ease-out), opacity 120ms ease;
  touch-action: manipulation; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--line); font-weight: 500; }
.btn.oro { background: var(--gold); color: var(--ink); }
.btn.piccolo { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn.largo { width: 100%; min-height: 52px; font-size: 16px; }
.link {
  background: none; border: none; color: var(--gold); cursor: pointer; font-size: 14px;
  min-height: 44px; padding: 0; text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
}
.link.tenue { color: var(--muted); }
.link.pericolo { color: var(--red-text); }
.icona-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--gold); cursor: pointer; border-radius: 10px;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { opacity: 0.88; }
  .link:hover { text-decoration: underline; }
}

/* ---------- campi ---------- */
label.campo { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  background: var(--ink); border: 1px solid var(--line); border-radius: 10px; color: var(--parchment);
  min-height: 44px; padding: 0 12px; font-size: 16px; /* 16px: iOS non fa zoom sul campo */ width: 100%;
}
input:focus, select:focus { border-color: var(--gold); outline: none; }
input::placeholder { color: var(--muted); }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--red); }
input:disabled, select:disabled { opacity: 0.6; }
.griglia { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.campo-check { flex-direction: row !important; align-items: center; gap: 10px !important; font-size: 15px !important; color: var(--parchment) !important; min-height: 44px; }

/* ---------- contenitori ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.pad { padding: 16px; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.open { color: var(--gold); border-color: var(--gold); }
.badge.closed { color: var(--parchment); }
.avviso { border: 1px solid var(--gold); background: var(--gold-soft); border-radius: 12px; padding: 14px; font-size: 14px; }
.avviso.rosso { border-color: var(--red-text); background: transparent; color: var(--red-text); }
.conferma { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.conferma .testo { color: var(--red-text); font-size: 14px; width: 100%; }

/* ---------- tabelle ---------- */
.tabella-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead tr { background: var(--panel-soft); color: var(--muted); text-align: left; }
th { padding: 10px 12px; font-weight: 500; white-space: nowrap; }
td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.r { text-align: right; }
.c { text-align: center; }
.pos { color: var(--muted); width: 36px; }
.pname { font-weight: 500; }
.psub { font-size: 12px; color: var(--muted); }
.totale { font-size: 17px; font-weight: 600; }

/* ---------- chip dei risultati di tappa ---------- */
.chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 24px;
  padding: 0 5px; border-radius: 4px; font-size: 13px; border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.chip.contato { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); font-weight: 600; }
.chip.scartato { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--red-text); }
.chip.assente { border-style: dashed; color: var(--muted); }
.legenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legenda span { display: flex; gap: 6px; align-items: center; }

/* ---------- classifica generale: una riga per giocatore ---------- */
.generale { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); overflow: hidden; }
.gen-riga { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.gen-riga:first-child { border-top: none; }
.gen-testa { background: var(--panel-soft); color: var(--muted); font-size: 12px; padding-top: 8px; padding-bottom: 8px; }
.gen-pos { width: 26px; flex: none; color: var(--muted); font-size: 14px; }
.gen-riga.dentro .gen-pos { color: var(--gold); }
.gen-nome { flex: 1 1 0; min-width: 0; }
.gen-nome > span { display: block; }
.gen-nome .pname { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gen-chips { display: flex; gap: 4px; flex-wrap: wrap; order: 5; width: 100%; padding-left: 36px; }
.gen-pres { font-size: 12px; color: var(--muted); }
.gen-tot { font-size: 20px; font-weight: 600; min-width: 40px; text-align: right; }
.gen-gap { font-size: 12px; color: var(--muted); }
.gen-linea { padding: 6px 14px; border-top: 2px solid var(--red-text); font-size: 12px; color: var(--red-text); background: var(--ink); }
.gen-testa .gen-chips, .gen-testa .gen-pres { display: none; }
@media (min-width: 760px) {
  /* sul computer torna una tabella: chip in colonna, allineati */
  .gen-riga { flex-wrap: nowrap; }
  .gen-chips { order: 0; width: auto; padding-left: 0; flex-wrap: nowrap; }
  .gen-chips .chip { width: 34px; }
  .gen-pres { width: 64px; text-align: right; }
  .gen-testa .gen-chips, .gen-testa .gen-pres { display: flex; }
  .gen-testa .gen-chips span { width: 34px; text-align: center; }
  .gen-testa .gen-pres { display: block; }
}

/* ---------- navigazione della lega ---------- */
.schede { background: var(--panel); border-bottom: 1px solid var(--line); padding: 0 16px; }
.schede .wrap { display: flex; gap: 4px; overflow-x: auto; }
.scheda {
  display: flex; align-items: center; gap: 8px; color: var(--muted); padding: 12px 14px; font-size: 14px; font-weight: 500;
  text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap;
}
.scheda svg { display: none; }
.scheda.attiva { color: var(--parchment); border-bottom-color: var(--red); }
@media (max-width: 759px) {
  /* telefono: barra in basso, raggiungibile col pollice */
  :root { --nav-h: 60px; }
  .schede {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 0 0 env(safe-area-inset-bottom);
    border-bottom: none; border-top: 1px solid var(--line);
  }
  .schede .wrap { gap: 0; overflow: visible; }
  .scheda {
    flex: 1 1 0; flex-direction: column; gap: 3px; height: var(--nav-h); justify-content: center;
    padding: 0; font-size: 11px; border-bottom: none;
  }
  .scheda svg { display: block; }
}

/* sotto-schede (es. Turni · Iscritti · Classifica dentro una tappa) */
.sottoschede { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 -16px 16px; padding: 0 16px; }
.sottoscheda {
  flex: 1 1 0; min-height: 44px; display: flex; align-items: center; justify-content: center; text-decoration: none; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.sottoscheda.attiva { color: var(--parchment); border-bottom-color: var(--red); }
@media (min-width: 760px) { .sottoscheda { flex: 0 0 auto; padding: 0 18px; } }

/* barra delle azioni fissa in basso (sopra la navigazione) */
.barra-azioni {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 15;
  background: var(--panel); border-top: 1px solid var(--line); padding: 10px 16px;
}
.barra-azioni .wrap { display: flex; flex-direction: column; gap: 6px; }
.barra-azioni .nota { font-size: 12px; color: var(--muted); text-align: center; }
.barra-azioni .info {
  min-height: 52px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 15px; text-align: center; padding: 0 12px;
}
body.con-azioni { --azioni-h: 100px; } /* pulsante + nota sotto */
@media (min-width: 760px) { .barra-azioni .wrap { flex-direction: row; justify-content: flex-end; align-items: center; } .barra-azioni .btn.largo { width: auto; } }

/* ---------- timer del turno ---------- */
.timer {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.timer-tempo { font-size: 40px; line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; }
.timer-etichetta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.timer.extra .timer-tempo { color: var(--red-text); }
.timer.done { border-color: var(--red-text); }
.timer.done .timer-tempo { color: var(--red-text); animation: lampeggio 1s step-start infinite; }
@keyframes lampeggio { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .timer.done .timer-tempo { animation: none; } }

/* ---------- finale: tabellone (gestione e pagina pubblica) ---------- */
.campione { border: 1px solid var(--gold); background: var(--gold-soft); border-radius: 12px; padding: 16px 18px; margin-bottom: 20px; }
.campione .serif { font-size: 26px; color: var(--gold); }
.turni-finale { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 12px; }
.pillola {
  min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.pillola.attiva { border-color: var(--gold); background: var(--gold-soft); color: var(--gold); }
.tabellone { display: flex; gap: 16px; align-items: stretch; }
.colonna { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; flex: 1 1 0; min-width: 0; }
.colonna h3 { font-size: 15px; color: var(--muted); }
.bmatch { padding: 10px 14px 12px; }
.bmatch.live { border-color: var(--gold); }
.bgioc { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; align-items: baseline; }
.bgioc .seed { color: var(--muted); font-size: 12px; width: 22px; display: inline-block; }
.bgioc.vince-f { color: var(--gold); font-weight: 600; }
.bgioc.perde-f { color: var(--muted); }
.bgioc.tbd { color: var(--muted); font-style: italic; }
.bpunti { font-size: 17px; }
.opzioni { display: flex; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.opz {
  flex: 1 1 0; min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--ink);
  color: var(--muted); font-size: 15px; font-weight: 500; cursor: pointer; font-variant-numeric: tabular-nums;
  touch-action: manipulation; transition: transform 120ms var(--ease-out);
}
.opz:active { transform: scale(0.97); }
.opz.sel { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); font-weight: 600; }
@media (max-width: 759px) {
  /* telefono: un turno del tabellone alla volta, scelto con le pillole */
  .tabellone { display: block; }
  .colonna { display: none; gap: 10px; }
  .colonna.visibile { display: flex; }
  .colonna h3 { display: none; }
}
@media (min-width: 760px) { .turni-finale { display: none; } .tabellone { overflow-x: auto; } .colonna { min-width: 230px; } }

/* ---------- messaggi ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + var(--nav-h) + var(--azioni-h) + env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%); max-width: calc(100% - 32px); width: max-content;
  background: var(--panel-soft); border: 1px solid var(--gold); color: var(--parchment);
  padding: 12px 16px; border-radius: 10px; font-size: 14px;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.toast.errore { border-color: var(--red-text); }
.toast.entra { opacity: 0; transform: translate(-50%, 8px); }
@media (prefers-reduced-motion: reduce) { .toast { transition: opacity 200ms ease; } .toast.entra { transform: translateX(-50%); } }
