:root {
  --bg: #0f1720; --panel: #17212c; --panel2: #1f2b38; --line: #2c3a4a;
  --text: #e8eef4; --muted: #8fa1b3; --accent: #f28c28; --accent2: #ffb366;
  --good: #2fae66; --good-d: #1d6e41; --bad: #d9534f; --bad-d: #8a2d2a;
  --info: #3b8fd9; --court: #e9a560; --court-line: #fff8ee; --court-paint: #d98a45;
  --r: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
input, select, textarea { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; border: 0; background: var(--panel2); border-radius: 10px;
  padding: 10px 14px; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(.97); filter: brightness(1.2); }
button.primary { background: var(--accent); color: #1a0f00; font-weight: 700; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: var(--bad-d); }
button[disabled] { opacity: .4; pointer-events: none; }
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); min-height: 58px; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { flex: 1; overflow: auto; padding: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 17px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f input, label.f select { background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px; font-size: 16px; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; }
.list .item .grow { flex: 1; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--panel2); color: var(--muted); }
.pill.live { background: var(--accent); color: #1a0f00; font-weight: 700; }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 6px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--panel); }
table.tbl td.l, table.tbl th.l { text-align: left; }
table.tbl tr.grp th { border-bottom: 0; color: var(--accent2); }
table.tbl tr.team td { color: var(--muted); font-style: italic; }
table.tbl tr.tot td { font-weight: 700; background: var(--panel2); }
table.tbl tr.oppt td { font-weight: 700; color: var(--muted); }
table.tbl input { width: 70px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-size: 15px; }
table.tbl input.w-num { width: 54px; }
table.tbl input.w-name { width: 160px; }
.tblwrap { overflow: auto; max-width: 100%; }
.seg { display: inline-flex; background: var(--panel2); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { background: transparent; padding: 8px 12px; }
.seg button.on { background: var(--accent); color: #1a0f00; font-weight: 700; }

/* ---------- LIVE ---------- */
.view.liveview { padding: 0; overflow: hidden; display: flex; }
.live { flex: 1; height: 100%; display: grid; grid-template-columns: 250px minmax(300px, 1fr) minmax(360px, 1.15fr); gap: 10px; padding: 10px; overflow: hidden; }
.col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.roster { background: var(--panel); border-radius: var(--r); overflow: auto; flex: 1; }
.roster .sec { padding: 6px 12px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; background: var(--panel2); position: sticky; top: 0; z-index: 1; }
.pl { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.pl.sel { background: #3a2a14; box-shadow: inset 4px 0 0 var(--accent); }
.pl .num { width: 34px; height: 34px; border-radius: 50%; background: var(--panel2); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.pl.court .num { background: var(--accent); color: #1a0f00; }
.pl .nm { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .pts { font-size: 13px; color: var(--muted); width: 30px; text-align: right; }
.fouls { display: flex; gap: 2px; }
.fouls i { width: 7px; height: 14px; border-radius: 2px; background: var(--line); }
.fouls i.on { background: var(--accent2); }
.fouls.out i.on { background: var(--bad); }
.pcard { background: var(--panel); border-radius: var(--r); padding: 12px; }
.pcard .who { font-size: 19px; font-weight: 700; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.kpi { background: var(--panel2); border-radius: 8px; padding: 7px 8px; }
.kpi b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 11px; color: var(--muted); }
.ftbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.big { padding: 16px 10px; font-size: 17px; font-weight: 700; border-radius: 12px; }
.g { background: var(--good-d); } .b { background: var(--bad-d); }
.teambox { background: var(--panel); border-radius: var(--r); padding: 10px; display: grid; gap: 8px; }
.tline { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-size: 14px; }
.bonus { font-weight: 800; color: var(--bad); }
.tstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; font-size: 13px; }
.tstats div { background: var(--panel2); border-radius: 8px; padding: 6px; }
.tstats b { font-size: 16px; }
.undo { background: var(--bad-d); padding: 12px; border-radius: 12px; text-align: left; font-size: 14px; line-height: 1.3; }
.undo small { display: block; color: #f3c9c7; }
.court { background: var(--panel); border-radius: var(--r); padding: 8px; position: relative; }
.court svg { width: 100%; height: auto; display: block; touch-action: manipulation; margin: 0 auto; }
#courtbox svg { width: auto; max-width: 100%; max-height: calc(100vh - 560px); min-height: 220px; }
.oppts { display: grid; grid-template-columns: auto 1fr 1fr 1fr; gap: 8px; align-items: center; }
.oppts .who { font-size: 12px; color: var(--muted); max-width: 120px; }
.acts { display: grid; gap: 7px; overflow: auto; }
.act { display: grid; grid-template-columns: 74px 1fr 1fr; gap: 6px; align-items: center; }
.act.one button { grid-column: 2 / -1; }
.act button { padding: 12px 8px; font-weight: 700; font-size: 15px; position: relative; }
.act button .c { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; background: rgba(0,0,0,.35); border-radius: 99px; padding: 2px 7px; }
.act .lbl { font-size: 11px; line-height: 1.2; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pos { background: var(--good-d); } .neg { background: var(--bad-d); } .neu { background: #24496b; }
.score { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.score small { font-size: 14px; font-weight: 600; color: var(--muted); }
.per { background: var(--accent); color: #1a0f00; font-weight: 800; border-radius: 8px; padding: 4px 10px; }

/* popup tiro */
.shotpop { position: absolute; z-index: 5; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: grid; gap: 6px; width: 200px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.shotpop .vals { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* modali */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.sheet { background: var(--panel); border-radius: 16px; width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); }
.sheet .hd { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sheet .hd h3 { margin: 0; flex: 1; font-size: 18px; }
.sheet .bd { padding: 14px; overflow: auto; }
.subs { display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 14px; }
.subs .pl { border-radius: 8px; margin-bottom: 4px; background: var(--panel2); }
.clock { display: flex; gap: 8px; align-items: center; font-size: 15px; }
.clock select { font-size: 28px; font-weight: 800; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000c; padding: 10px 16px; border-radius: 10px; z-index: 99; font-size: 15px; pointer-events: none; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.charts .court svg { max-height: 380px; }

@media (max-width: 1050px) {
  .live { grid-template-columns: 210px 1fr 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (orientation: portrait) {
  .live { grid-template-columns: 1fr 1fr; grid-auto-rows: min-content; overflow: auto; }
  .live .col.c1 { grid-column: 1 / -1; max-height: 260px; }
}
@media print {
  :root { --bg: #fff; --panel: #fff; --panel2: #eee; --text: #000; --muted: #444; --line: #bbb; }
  .topbar button, .noprint { display: none !important; }
  .view { overflow: visible; }
  .app { height: auto; }
  table.tbl { font-size: 10px; }
  .card { break-inside: avoid; }
}

/* quadro statistiche in una schermata */
.board { display: flex; flex-direction: column; gap: 8px; height: calc(100vh - 90px); height: calc(100dvh - 90px); min-height: 640px; }
.boardtop { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.parz { margin-left: auto; }
.parz table.tbl td, .parz table.tbl th { padding: 2px 8px; font-size: 13px; }
.boardbox { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 6px; }
table.tbl.compact td, table.tbl.compact th { padding: 3px 4px; font-size: 13px; }
table.tbl.compact th { font-size: 11px; }
table.tbl tr[data-a] { cursor: pointer; }
table.tbl tr.hl td { background: #3a2a14; }
.boardmaps { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.boardmaps .court { display: flex; flex-direction: column; align-items: center; min-height: 0; padding: 6px; }
.boardmaps .court svg { flex: 1; min-height: 0; width: auto; height: 100%; max-width: 100%; }
.maplbl { text-align: center; font-size: 14px; margin-top: 2px; }
.maphint { align-self: center; text-align: center; max-width: 170px; font-size: 13px; }
.sheet.full { width: 100%; height: 100%; }
.sheet.full .bd { padding: 10px; }
.sheet.full .board { height: calc(100vh - 110px); height: calc(100dvh - 110px); }
@media print { .board { height: auto; } .boardmaps { height: 320px; } .maphint { display: none; } }

/* falli: tacche personali + caselle espulsione */
.foulbox { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.ejbox { display: flex; gap: 3px; }
.ejbox i { width: 13px; height: 10px; border-radius: 2px; border: 1.5px solid var(--bad); }
.ejbox i.on { background: var(--bad); }
/* finestre di scelta avversario e tipo fallo */
.oppgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.oppbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px; background: var(--panel2); border: 1px solid var(--line); }
.oppbtn b { font-size: 28px; line-height: 1; }
.oppbtn span { font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oppbtn small { font-size: 11px; color: var(--muted); }
.ftgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ftbtn { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 8px; background: var(--panel2); border: 1px solid var(--line); }
.ftbtn .code { font-size: 30px; font-weight: 800; min-width: 52px; height: 52px; display: grid; place-items: center; }
.ftbtn .code.circ { border: 3px solid var(--text); border-radius: 50%; width: 52px; }
.ftbtn small { font-size: 11px; color: var(--accent2); }
