/* Design system del referto.
   Vincoli reali: si usa in piedi, con una mano, in una palestra illuminata al
   neon, spesso con le mani fredde. Da qui: bersagli ≥56px, contrasti alti,
   nessuna azione distruttiva raggiungibile per errore. */

:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --surface-3: #2a3039;
  --line: #333b46;
  --text: #eef2f6;
  --muted: #9aa5b1;
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --a-color: #3b82f6;
  --b-color: #f97316;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --tap: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --surface: #fff; --surface-2: #eef1f5; --surface-3: #e2e7ee;
    --line: #d3dae2; --text: #131820; --muted: #5b6674;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.4;
  overscroll-behavior: none;
}

/* Il segnapunti tocca decine di volte al minuto: nessuna selezione accidentale. */
body.no-select { user-select: none; -webkit-user-select: none; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 700; }
.center { text-align: center; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.tight { gap: .35rem; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
.stack { display: flex; flex-direction: column; gap: .6rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: max(.6rem, var(--pwa-safe-top,env(safe-area-inset-top,0px)));
}
.topbar .brand { font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: .5rem; }
.topbar .brand span.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

/* ---------- controlli ---------- */
.btn {
  min-height: 44px; padding: .6rem 1rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: .45rem; transition: filter .12s, transform .06s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04220f; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: .3rem .6rem; font-size: .85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: .4rem; }

label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin: 0 0 .8rem; }
legend { font-size: .8rem; color: var(--muted); font-weight: 700; padding: 0 .4rem; text-transform: uppercase; letter-spacing: .05em; }
.field { margin-bottom: .7rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; }
.check { display: flex; align-items: center; gap: .5rem; padding: .4rem 0; }
.check label { margin: 0; font-size: .92rem; color: var(--text); font-weight: 500; }

/* ---------- card e liste ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .8rem; }
.card.tight { padding: .7rem; }
.list { display: flex; flex-direction: column; gap: .5rem; }
.list-item {
  display: flex; align-items: center; gap: .7rem; padding: .7rem;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { border-color: var(--accent); }
.badge { font-size: .7rem; font-weight: 700; padding: .18rem .45rem; border-radius: 999px; background: var(--surface-3); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.badge.live { background: var(--danger); color: #fff; animation: pulse 1.6s infinite; }
.badge.done { background: var(--accent-dark); color: #fff; }
.badge.a { background: var(--a-color); color: #fff; }
.badge.b { background: var(--b-color); color: #fff; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
table.data td.num, table.data th.num { text-align: center; font-variant-numeric: tabular-nums; }
table.data tr.me { background: rgba(34,197,94,.08); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- stato connessione ---------- */
.sync-pill {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 700;
  padding: .25rem .6rem; border-radius: 999px; background: var(--surface-3); color: var(--muted);
}
.sync-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-pill.ok .dot { background: var(--accent); }
.sync-pill.pending { color: var(--warn); } .sync-pill.pending .dot { background: var(--warn); }
.sync-pill.offline { color: var(--danger); } .sync-pill.offline .dot { background: var(--danger); }

/* ---------- toast e modali ---------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(1rem, env(safe-area-inset-bottom)); z-index: 100; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; width: min(92vw, 520px); }
.toast { background: var(--surface-3); color: var(--text); border: 1px solid var(--line); padding: .6rem 1rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35); font-size: .9rem; text-align: center; }
.toast-error { border-color: var(--danger); color: #fff; background: var(--danger); }
.toast-success { border-color: var(--accent); }
.toast-warn { border-color: var(--warn); }
.toast.out { opacity: 0; transition: opacity .3s; }

dialog.modal { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); padding: 0; width: min(94vw, 520px); max-height: 88vh; }
dialog.modal.modal-wide { width: min(96vw, 860px); }
dialog.modal::backdrop { background: rgba(0,0,0,.6); }
.modal form { display: flex; flex-direction: column; max-height: 88vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--line); }

/* ================= SEGNAPUNTI ================= */

.scorer { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.scorer-head { display: flex; align-items: center; gap: .6rem; padding: .5rem .8rem; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: calc(12px + var(--pwa-safe-top,env(safe-area-inset-top,0px))); flex: none; }
.scorer-body { flex: 1; overflow-y: auto; padding: .6rem; }
.scorer-foot { flex: none; display: flex; gap: .5rem; padding: .5rem .6rem; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }

/* Il tabellone: due colonne enormi, una per squadra. */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: stretch; margin-bottom: .6rem; }
.team-panel { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: .7rem; display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.team-panel.serving { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.team-panel.side-a { border-top: 5px solid var(--a-color); }
.team-panel.side-b { border-top: 5px solid var(--b-color); }
.team-name { font-weight: 800; font-size: 1rem; display: flex; align-items: center; gap: .4rem; min-height: 2.6em; }
.serve-icon { color: var(--accent); font-size: 1.1rem; }
.point-btn {
  width: 100%; border: 0; border-radius: var(--radius); background: var(--surface-3); color: var(--text);
  font-size: clamp(3.2rem, 17vw, 6rem); font-weight: 800; font-variant-numeric: tabular-nums;
  line-height: 1; padding: .35em 0; cursor: pointer; transition: transform .06s, background .12s;
}
.point-btn:active { transform: scale(.96); background: var(--accent); color: #04220f; }
.point-btn:disabled { opacity: .45; cursor: not-allowed; }
.side-a .point-btn { box-shadow: inset 0 -4px 0 rgba(59,130,246,.5); }
.side-b .point-btn { box-shadow: inset 0 -4px 0 rgba(249,115,22,.5); }
.sets-won { text-align: center; font-size: .8rem; color: var(--muted); }
.sets-won b { font-size: 1.6rem; color: var(--text); display: block; font-variant-numeric: tabular-nums; }
.center-col { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; min-width: 72px; }
.set-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.set-history { display: flex; flex-direction: column; gap: .15rem; font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.set-history b { color: var(--text); }

/* Campo con le rotazioni */
.courts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .6rem; }
.court { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; }
.court h4 { margin: 0 0 .4rem; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; }
.court-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .3rem; }
.court-cell {
  aspect-ratio: 1.35; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; position: relative;
}
.court-cell:active { background: var(--surface-3); }
.court-cell .n { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.court-cell .p { position: absolute; top: 2px; left: 4px; font-size: .6rem; color: var(--muted); }
.court-cell.server { border-color: var(--accent); background: rgba(34,197,94,.14); }
.court-cell.libero { border-color: var(--warn); background: rgba(245,158,11,.14); }
.court-cell .lb { position: absolute; bottom: 2px; right: 4px; font-size: .58rem; color: var(--warn); font-weight: 700; }
.front-row { grid-column: 1 / -1; font-size: .6rem; color: var(--muted); text-align: center; letter-spacing: .1em; }

/* Azioni rapide */
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: .4rem; }
.action-btn { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; font-size: .8rem; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; cursor: pointer; }
.action-btn .ico { font-size: 1.25rem; }
.action-btn:active { background: var(--surface-3); }
.action-btn:disabled { opacity: .4; }
.action-btn.warn { border-color: var(--warn); color: var(--warn); }
.action-btn.danger { border-color: var(--danger); color: var(--danger); }

.log { max-height: 190px; overflow-y: auto; font-size: .82rem; }
.log-item { display: flex; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); align-items: center; }
.log-item .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .74rem; flex: none; width: 42px; }

.violation { border-left: 3px solid var(--warn); background: rgba(245,158,11,.1); padding: .5rem .7rem; border-radius: 6px; font-size: .85rem; margin-bottom: .4rem; }

/* Selettore giocatore: griglia di numeri grandi */
.numgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: .4rem; }
.numcell { min-height: 64px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.numcell b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.numcell span { font-size: .62rem; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 3px; }
.numcell.sel { border-color: var(--accent); background: rgba(34,197,94,.18); }
.numcell.on-court { border-color: var(--a-color); }
.numcell:disabled { opacity: .35; cursor: not-allowed; }

.sigpad { width: 100%; height: 160px; background: #fff; border-radius: 10px; border: 1px solid var(--line); touch-action: none; display: block; }

/* ================= LIVE ================= */
.live-head { text-align: center; padding: 1.2rem 1rem .6rem; }
.live-head h1 { font-size: clamp(1.4rem, 5vw, 2rem); }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tab { padding: .6rem .9rem; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.match-card { display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin-bottom: .5rem; }
.match-card.is-live { border-color: var(--danger); }
.match-card .tname { font-weight: 700; min-width: 0; }
.match-card .tname.right { text-align: right; }
.match-card .tname.winner::after { content: " ✓"; color: var(--accent); }
.match-card .sc { text-align: center; font-variant-numeric: tabular-nums; }
.match-card .sc .sets { font-size: 1.7rem; font-weight: 800; }
.match-card .sc .parts { font-size: .72rem; color: var(--muted); }
.match-meta { grid-column: 1 / -1; display: flex; gap: .5rem; flex-wrap: wrap; font-size: .74rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: .4rem; margin-top: .2rem; }

.group-block { margin-bottom: 1.4rem; }
.bracket { display: flex; gap: 1.2rem; overflow-x: auto; padding-bottom: .6rem; }
.bracket-round { min-width: 210px; display: flex; flex-direction: column; justify-content: space-around; gap: .6rem; }
.bracket-round h3 { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.bracket-match { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem; font-size: .85rem; }
.bracket-match .r { display: flex; justify-content: space-between; gap: .5rem; padding: .12rem 0; }
.bracket-match .r.w { font-weight: 700; color: var(--accent); }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty .ico { font-size: 2.5rem; display: block; margin-bottom: .5rem; opacity: .5; }

@media (max-width: 560px) {
  .courts { grid-template-columns: 1fr; }
  .scoreboard { grid-template-columns: 1fr auto 1fr; }
  .center-col { min-width: 56px; }
}
@media print { .no-print { display: none !important; } }
/* Telefono: nomi leggibili e comandi raggiungibili anche a 320 px. */
.scorer-head .grow { min-width: 0; }
.scorer-head .sync-pill { flex:none; max-width:45%; white-space:normal; }
.point-btn { min-height:140px; touch-action:manipulation; }
.team-name { overflow-wrap:anywhere; }
.final-status { padding:.8rem; background:var(--surface-2); border-left:4px solid var(--accent); }
@media(max-width:560px){
 .scorer-body { padding:.4rem; }
 .team-panel { padding:.35rem; }
 .team-name { font-size:.85rem; }
 .center-col { min-width:42px; }
 .point-btn { font-size:3.5rem; }
 .scorer-foot .btn { padding:.5rem; font-size:.85rem; }
 .list-item { flex-wrap:wrap; }
 .list-item .grow { flex-basis:65%; }
 .topbar { flex-wrap:wrap; }
 .wrap { padding:.65rem; }
 .fields { grid-template-columns:1fr; }
 .match-card { gap:.3rem; padding:.6rem; }
 .match-card .tname { font-size:.85rem; overflow-wrap:anywhere; }
}

.assignment-option{display:flex;align-items:center;gap:12px;padding:10px 0;min-height:44px;cursor:pointer}.assignment-option input{width:20px;height:20px;flex-shrink:0}.assignment-option span{overflow-wrap:anywhere}

/* Sestetti leggibili e selezione diretta delle sei posizioni. */
.court-name {font-size:.65rem;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.libero-list {display:flex;flex-wrap:wrap;gap:.4rem .8rem;padding:.6rem 0;font-size:.8rem;border-top:1px solid var(--line)}
.libero-list small {flex-basis:100%;color:var(--muted)}
.lineup-position {min-width:0;display:flex;flex-direction:column;gap:.5rem;padding:.6rem .3rem;border:1px solid var(--line);border-radius:6px;background:var(--surface-2)}
.lineup-position strong {font-size:.8rem}
.lineup-position select {width:100%;min-width:0;font-size:.85rem;padding:.6rem .2rem}
.lineup-courts {grid-template-columns:1fr}
@media(min-width:760px){.lineup-courts{grid-template-columns:1fr 1fr}}

/* Distinta: pagina dedicata, elenco compatto e modulo di un solo atleta. */
.sheet-page {max-width:900px;margin:auto;min-height:100dvh;padding-bottom:110px;user-select:text}
.sheet-header {position:sticky;top:0;z-index:5;display:flex;align-items:center;gap:12px;padding:calc(12px + var(--pwa-safe-top,env(safe-area-inset-top,0px))) 20px 12px;background:var(--bg);border-bottom:1px solid var(--line)}
.sheet-header h1 {font-size:clamp(20px,4vw,28px);margin:2px 0;line-height:1.2}
.sheet-eyebrow {margin:0;font-size:11px;letter-spacing:1.3px;color:var(--muted);font-weight:700}
.sheet-main {padding:24px}
.sheet-summary {display:grid;grid-template-columns:1fr 1.25fr 1fr;gap:12px;padding-bottom:20px;border-bottom:1px solid var(--line)}
.sheet-summary>div {display:flex;flex-direction:column;gap:4px}
.sheet-summary strong {font-size:20px;line-height:1.2}
.sheet-summary span {font-size:12px;color:var(--muted)}
.sheet-helper {font-size:14px;color:var(--muted);line-height:1.5;margin:16px 0 24px}
.sheet-section-title {display:flex;justify-content:space-between;align-items:center;gap:12px;margin:24px 0 12px}
.sheet-section-title h2,.athlete-editor h2 {font-size:18px;margin:0}
.athlete-list {padding:0;margin:0;list-style:none;border-top:1px solid var(--line)}
.athlete-row {display:flex;align-items:center;gap:14px;width:100%;text-align:left;padding:14px 0;background:transparent;color:var(--text);border:0;border-bottom:1px solid var(--line);font:inherit;min-height:76px;cursor:pointer}
.shirt-number {display:grid;place-items:center;flex:0 0 44px;height:44px;border:1px solid var(--line);border-radius:10px;font-size:21px;font-weight:750;font-variant-numeric:tabular-nums;background:var(--surface)}
.athlete-identity {flex:1;min-width:0;display:flex;flex-direction:column;gap:5px;overflow-wrap:anywhere}
.athlete-identity>strong {font-size:16px;font-weight:650}
.athlete-tags {display:flex;gap:6px;flex-wrap:wrap;font-size:11px;color:var(--muted)}
.athlete-tags span {border:1px solid var(--line);border-radius:4px;padding:2px 6px}
.edit-label {font-size:12px;color:var(--muted);flex-shrink:0}
.athlete-editor {padding:20px;border:1px solid var(--line);background:var(--surface);border-radius:16px;scroll-margin-top:100px}
.athlete-inputs {display:grid;grid-template-columns:76px 1fr 1fr;gap:12px;margin:20px 0 16px}
.sheet-field {display:flex;flex-direction:column;gap:6px;min-width:0;font-size:12px;color:var(--muted)}
.sheet-field input,.sheet-field select {width:100%;min-width:0;min-height:52px;font-size:16px;color:var(--text);border-radius:8px;padding:12px;background:var(--bg)}
.role-toggles {display:flex;gap:12px;flex-wrap:wrap}
.role-toggle {display:flex;align-items:center;gap:10px;min-height:48px;padding:8px 14px;border:1px solid var(--line);border-radius:8px;font-size:14px;cursor:pointer}
.role-toggle input {width:20px;height:20px;margin:0;accent-color:var(--accent)}
.sheet-edit-actions {display:flex;justify-content:flex-end;gap:8px;margin-top:20px}
.sheet-remove {margin-top:16px;min-height:44px;background:none;border:0;color:var(--danger);font:inherit;font-size:13px;padding:0 8px}
.sheet-error,.sheet-validation {color:var(--danger);font-size:14px;padding:12px 0;margin:0}
.sheet-empty {padding:24px 0 32px;border-bottom:1px solid var(--line)}
.sheet-empty h3 {font-size:18px;margin:0 0 8px}
.sheet-empty p {font-size:14px;color:var(--muted);max-width:360px;margin-bottom:20px}
.sheet-staff {margin-top:32px}
.staff-row {display:grid;grid-template-columns:170px 1fr 44px;align-items:end;gap:10px;margin:14px 0}
.sheet-footer {position:fixed;bottom:0;left:50%;transform:translateX(-50%);width:min(100%,900px);display:flex;justify-content:space-between;align-items:center;gap:16px;padding:14px 24px calc(14px + env(safe-area-inset-bottom));background:var(--bg);border-top:1px solid var(--line);z-index:6}
.sheet-draft {font-size:12px;color:var(--muted);max-width:180px}
.sheet-footer .btn {min-width:200px}
@media(max-width:560px){
 .sheet-header {padding-left:8px;padding-right:16px}
 .sheet-main {padding:18px 16px}
 .sheet-summary strong {font-size:18px}
 .athlete-editor {padding:16px}
 .athlete-inputs {grid-template-columns:64px 1fr;gap:12px}
 .athlete-inputs .sheet-field:first-child {grid-row:1/3;align-self:start}
 .athlete-inputs .sheet-field:first-child input {text-align:center;font-size:24px;height:62px;padding:8px}
 .athlete-inputs .sheet-field:last-child {grid-column:2}
 .sheet-edit-actions .btn {padding:12px;font-size:14px}
 .staff-row {grid-template-columns:1fr 44px}
 .staff-row .sheet-field:first-child {grid-column:1/-1}
 .sheet-footer {gap:10px;padding:12px 16px calc(12px + env(safe-area-inset-bottom))}
 .sheet-footer .btn {min-width:0;flex:1;font-size:14px}
 .sheet-draft {max-width:110px;font-size:11px}
 .sheet-page {padding-bottom:110px}
 .edit-label {font-size:11px}
}

.sheet-page {display:flex;flex-direction:column;padding-bottom:0}
.sheet-main {flex:1}
.sheet-footer {position:sticky;left:auto;transform:none;margin-top:auto;width:100%}
.sheet-page button,.sheet-page input,.sheet-page select {scroll-margin-block:120px}

/* Schermate segnapunti: ritmo uniforme fra sezioni e comandi. */
.scorer-body {display:flex;flex-direction:column;gap:16px;padding:16px;min-height:0}
.scorer-body > * {flex-shrink:0;margin-top:0;margin-bottom:0}
.scorer-body > .btn {align-self:stretch}
.scorer-body .card {padding:16px}
.scorer-body .card.tight {padding:14px}
.scorer-body .row {gap:10px}
.score-value {font-size:clamp(48px,10vw,88px);font-weight:800;line-height:1.15;padding:12px 0;font-variant-numeric:tabular-nums;text-align:center}
.add-point-btn {display:flex;justify-content:center;align-items:center;gap:8px;width:100%;min-height:56px;border:1px solid var(--line);border-radius:10px;background:var(--surface-3);color:var(--text);font:700 15px var(--font);padding:10px;touch-action:manipulation;cursor:pointer}
.add-point-btn>span:first-child {font-size:26px;line-height:1}
.add-point-btn:active {transform:scale(.97);background:var(--accent-dark);color:#fff}
.add-point-btn:disabled {opacity:.4;cursor:default}
.team-panel .sets-won {margin-top:12px}
.lineup-number {text-align:center;font-size:26px!important;font-weight:700;min-height:58px;padding:8px!important}
.lineup-number[aria-invalid=true] {border-color:var(--danger);outline-color:var(--danger)}
.lineup-feedback {font-size:12px;line-height:1.35;min-height:32px;overflow-wrap:anywhere;color:var(--muted)}
.lineup-feedback.invalid {color:var(--danger)}
.scorer > .sheet-page {width:100%;height:100%;min-height:0;flex:1;overflow:hidden;margin:0 auto}
.sheet-page > .sheet-main {min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;overscroll-behavior-y:contain;padding-bottom:28px}
.sheet-page > .sheet-header,.sheet-page > .sheet-footer {position:relative;flex-shrink:0}
.modal-body {min-height:0;overscroll-behavior-y:contain}
@media(max-width:560px){
 .scorer-body {gap:14px;padding:12px}
 .scorer-body .card {padding:14px}
 .team-panel {padding:10px 8px}
 .add-point-btn {font-size:13px;gap:5px;padding:8px 5px}
 .scoreboard {gap:8px}
 .lineup-position {padding:8px 6px}
 .lineup-feedback {font-size:11px}
}

/* v14 — Priorità al punteggio, comandi tattili e layout adattivi. */
.scorer-head,.scorer-foot {padding-left:max(12px,env(safe-area-inset-left));padding-right:max(12px,env(safe-area-inset-right))}
.scorer-head .icon-btn,.sheet-header .icon-btn,.sheet-page .icon-btn {min-width:44px;min-height:44px;flex-shrink:0}
.scorer-head .guide-link {min-height:44px;flex:none;text-decoration:none}
.scorer-body {padding-left:max(12px,env(safe-area-inset-left));padding-right:max(12px,env(safe-area-inset-right))}
.scorer-body > *,.match-support > * {min-width:0}
.match-support .card {margin:0}
.match-support {gap:14px}
.match-live .scoreboard {order:0}
.match-live .match-actions {order:1}
.match-live > .courts {order:2}
.match-live .match-support {order:3}
.match-live .team-name {font-size:clamp(14px,2.4vw,20px);line-height:1.25}
.match-live .sets-won {margin-top:0;display:flex;align-items:baseline;justify-content:center;gap:6px}
.match-live .sets-won b {font-size:20px}
.match-live .score-value {padding:4px 0;font-size:clamp(48px,9vw,84px)}
.match-live .add-point-btn {min-height:64px}
.side-a .add-point-btn {border-color:var(--a-color);box-shadow:inset 0 -3px var(--a-color)}
.side-b .add-point-btn {border-color:var(--b-color);box-shadow:inset 0 -3px var(--b-color)}
.match-live .court-cell {min-height:58px;aspect-ratio:auto;padding:16px 2px 5px;min-width:0;color:var(--text);font-family:inherit}
.court h4 {flex-wrap:wrap;gap:6px;overflow-wrap:anywhere}
.court-name {width:100%;text-align:center}
.match-live .actions {grid-template-columns:repeat(4,minmax(0,1fr));gap:8px}
.match-live .action-btn {min-height:56px;padding:6px 3px;overflow-wrap:anywhere}
.scorer-body .btn.small,.sheet-page .btn.small {min-height:44px}
.scorer :focus-visible,dialog :focus-visible {outline:3px solid var(--accent);outline-offset:3px}
.scorer > .wrap {overflow-y:auto;width:100%}
.access-page {width:100%;max-width:640px;margin:0 auto;flex:1;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:calc(20px + var(--pwa-safe-top,env(safe-area-inset-top,0px))) calc(16px + env(safe-area-inset-right,0px)) calc(24px + env(safe-area-inset-bottom,0px)) calc(16px + env(safe-area-inset-left,0px))}
.access-card {display:flex;flex-direction:column;gap:16px;padding:24px;margin:0;min-width:0}
.access-card > * {margin:0;min-width:0;flex-shrink:0}
.access-card h1 {font-size:clamp(1.5rem,5.7vw,1.85rem);line-height:1.15}
.access-kicker {font-size:.72rem;font-weight:700;letter-spacing:.07em;color:var(--muted)}
.access-steps {padding-left:1.25rem;display:grid;gap:8px}
.access-card .field {display:grid;gap:8px}
.access-card label {margin:0}
.access-card textarea {width:100%;min-height:96px;font-size:16px;line-height:1.5;user-select:text;-webkit-user-select:text;overflow-wrap:anywhere}
.access-card .btn {min-height:52px;white-space:normal;text-align:center;text-decoration:none}
.access-error {color:var(--danger);font-size:.9rem}
.access-error[hidden] {display:none}
@media(max-width:360px),(orientation:landscape) and (max-height:500px) {.access-card{padding:16px;gap:14px}}
.scorer .sheet-header {padding-left:max(8px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}
.sheet-main {padding-left:max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}
.sheet-footer {padding-left:max(16px,env(safe-area-inset-left));padding-right:max(16px,env(safe-area-inset-right))}
body.no-select dialog.modal {inset:var(--pwa-safe-top,env(safe-area-inset-top,0px)) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px);max-height:calc(100dvh - var(--pwa-safe-top,env(safe-area-inset-top,0px)) - env(safe-area-inset-bottom,0px) - 24px);max-width:calc(100vw - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px) - 16px)}
body.no-select .modal form {max-height:calc(100dvh - var(--pwa-safe-top,env(safe-area-inset-top,0px)) - env(safe-area-inset-bottom,0px) - 26px)}
body.no-select .modal-head,body.no-select .modal-foot {flex-shrink:0;gap:8px}
body.no-select .modal-head .icon-btn {min-width:44px;min-height:44px}
body.no-select .modal-foot .btn {min-height:48px;min-width:0}
body.no-select .modal-head h2 {overflow-wrap:anywhere}
@media(max-width:360px){
 .scorer-head {flex-wrap:wrap;gap:4px 8px;padding-top:calc(12px + var(--pwa-safe-top,env(safe-area-inset-top,0px)));padding-bottom:4px}
 .scorer-head .sync-pill {margin-left:auto;max-width:100%}
 .scorer-head .guide-link {padding:4px 8px}
 .match-live .center-col {min-width:30px}
 .match-live .scoreboard {gap:5px}
 .match-live .team-panel {padding:8px 5px}
 .match-live .team-name {font-size:13px}
 .match-live .add-point-btn {font-size:12px;gap:4px}
 .match-live .actions {grid-template-columns:repeat(3,minmax(0,1fr))}
 .modal-foot {padding:8px}
 .modal-foot .btn {padding:8px;font-size:14px}
 .sheet-summary {gap:8px}
 .sheet-summary strong {font-size:16px}
}
@media(min-width:700px){
 .scorer-body {max-width:1440px;width:100%;margin:auto;padding:20px max(20px,env(safe-area-inset-right,0px)) 20px max(20px,env(safe-area-inset-left,0px));gap:20px}
 .match-live {display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:auto auto 1fr;align-content:start;align-items:start}
 .match-live .scoreboard {grid-column:1;grid-row:1}
 .match-live .match-actions {grid-column:1;grid-row:2}
 .match-live > .courts {grid-column:2;grid-row:1/4;grid-template-columns:1fr;gap:16px}
 .match-live .match-support {grid-column:1;grid-row:3}
 .match-live .team-panel {padding:12px 8px}
 .match-live .center-col {min-width:32px}
 .match-live .team-name {font-size:16px}
 .match-live .add-point-btn {font-size:14px}
 .match-live .court-cell {min-height:70px}
}
@media(min-width:1100px){
 .match-live {grid-template-columns:minmax(0,1fr) minmax(0,1.15fr)}
 .match-live > .courts {grid-template-columns:1fr 1fr}
 .match-live .court-cell {min-height:78px}
 .match-live .add-point-btn {min-height:80px;font-size:17px}
}
/* Un telefono ruotato ha molto spazio in larghezza, poco in altezza. */
@media(orientation:landscape) and (max-height:500px){
 .scorer-head {padding-top:calc(6px + var(--pwa-safe-top,env(safe-area-inset-top,0px)));padding-bottom:2px;gap:8px}
 .scorer-head .icon-btn,.scorer-head .guide-link {min-height:44px}
 .scorer-foot {padding-top:4px;padding-bottom:max(4px,env(safe-area-inset-bottom))}
 .scorer-body {padding-top:10px;padding-bottom:10px;gap:12px}
 .match-live {display:flex}
 .match-live .scoreboard {width:100%}
 .match-live .team-panel {display:grid;grid-template-columns:76px minmax(0,1fr);gap:4px 12px;padding:8px 12px}
 .match-live .team-name {grid-column:1/-1;min-height:0;font-size:15px}
 .match-live .score-value {grid-column:1;grid-row:2/4;font-size:48px;align-self:center;padding:0}
 .match-live .add-point-btn {grid-column:2;grid-row:2;min-height:56px;font-size:14px}
 .match-live .sets-won {grid-column:2;grid-row:3;font-size:12px;line-height:1}
 .match-live .sets-won b {font-size:16px}
 .match-live .center-col {min-width:32px}
 .match-live .actions {grid-template-columns:repeat(7,minmax(0,1fr))}
 .match-live .courts,.lineup-courts {grid-template-columns:1fr 1fr}
 .match-live .court-cell {min-height:58px}
 .sheet-header {padding-top:calc(6px + var(--pwa-safe-top,env(safe-area-inset-top,0px)));padding-bottom:4px}
 .sheet-header h1 {font-size:20px}
 .sheet-footer {padding-top:6px;padding-bottom:max(6px,env(safe-area-inset-bottom))}
 .modal-head,.modal-foot {padding:4px 12px}
 .modal-head h2 {font-size:17px}
 .modal-body {padding:12px}
}
@media(prefers-reduced-motion:reduce){.badge.live{animation:none}.btn,.toast.out{transition:none}}

.match-live .match-warnings {order:-1;grid-column:1/-1;grid-row:1}
.match-live:has(.match-warnings) .scoreboard {grid-row:2}
.match-live:has(.match-warnings) .match-actions {grid-row:3}
.match-live:has(.match-warnings) > .courts {grid-row:2/5}
.match-live:has(.match-warnings) .match-support {grid-row:4}

/* Pulsante e spiegazione restano uniti; le due azioni sono separate. */
.preparation-actions {display:flex;flex-direction:column;gap:24px;margin-top:20px}
.preparation-action {display:flex;flex-direction:column;align-items:flex-start;gap:8px;min-width:0}
.preparation-action .btn {max-width:100%;min-height:48px;white-space:normal;text-align:left}
.preparation-action p {margin:0;line-height:1.5;max-width:65ch}

/* Guida interna: gara e scorrimento restano in memoria dietro al dialogo. */
dialog.scorer-guide {position:fixed;inset:0;margin:0;width:100%;height:100dvh;max-width:none;max-height:none;border:0;border-radius:0;padding:var(--pwa-safe-top,env(safe-area-inset-top,0px)) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px);background:var(--surface);color:var(--text);overflow:hidden}
dialog.scorer-guide[open] {display:flex;flex-direction:column}
.scorer-guide .guide-toolbar {flex:none;padding:12px 16px;border-bottom:1px solid var(--line)}
.scorer-guide .guide-toolbar h2 {margin:0;font-size:18px}
.scorer-guide .guide-frame {display:block;flex:1;min-height:0;width:100%;border:0;background:#f8f5ec}
.scorer-guide .guide-return-bar {flex:none;padding:12px 16px;border-top:1px solid var(--line);background:var(--surface)}
.scorer-guide .guide-return-bar .btn {min-height:52px;width:100%;white-space:normal}
@media(orientation:landscape) and (max-height:500px) {
 .scorer-guide .guide-toolbar {padding:8px 12px}
 .scorer-guide .guide-return-bar {padding:6px 12px}
 .scorer-guide .guide-return-bar .btn {min-height:44px}
}
