:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #efefef;
  --ink: #141414;
  --muted: #626262;
  --line: #e2e2e2;
  --red: #d71920;
  --red-2: #a3121a;
  --black: #141414;
  --black-2: #2b2b2b;
  --on-red: #ffffff;
  --accent: var(--red);
  --win: #11865a;
  --win-bg: #dff5ea;
  --loss: #3a3a3a;
  --loss-bg: #e6e6e6;
  --warn: #9a6400;
  --warn-bg: #fff1cc;
  --mine: #fdeaea;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0d;
    --surface: #181818;
    --surface-2: #232323;
    --ink: #f2f2f2;
    --muted: #a3a3a3;
    --line: #2e2e2e;
    --accent: #ff4b50;
    --win: #45cf8f;
    --win-bg: #133326;
    --loss: #d0d0d0;
    --loss-bg: #333333;
    --warn: #ffc94d;
    --warn-bg: #3a2e10;
    --mine: #3a1214;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* Header */
.top {
  background: var(--red);
  color: var(--on-red);
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; max-width: 720px; margin: 0 auto; }
.brand > div { flex: 1; min-width: 0; }
.bolt { width: 34px; height: 34px; fill: #fff; flex: none; }
.top h1 { margin: 0; font-size: 22px; letter-spacing: .02em; text-transform: uppercase; font-weight: 800; }
.stamp { margin: 0; font-size: 12px; color: rgb(255 255 255 / .82); }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view > * + * { margin-top: 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 24px 4px 8px; }
.view > h2:first-child { margin-top: 4px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

/* Next match hero */
.hero {
  background: linear-gradient(135deg, var(--black) 0%, var(--black-2) 100%);
  color: #fff;
  border: 0;
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 140px; height: 140px;
  background: var(--red); opacity: .35; border-radius: 50%;
}
.hero .label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: #ff5a5f; font-weight: 700; }
.hero .when { font-size: 15px; margin-top: 4px; color: #e6e6e6; }
.hero .countdown { font-size: 13px; color: #ff8a8d; margin-top: 2px; }
.hero .vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin: 16px 0; }
.hero .vs .t { font-size: 18px; font-weight: 800; line-height: 1.2; }
.hero .vs .t:last-child { text-align: right; }
.hero .vs .x { font-size: 13px; color: #9a9a9a; }
.hero .mine { color: #fff; text-decoration: underline; text-decoration-color: var(--red); text-decoration-thickness: 3px; text-underline-offset: 5px; }
.hero .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hero .venue { font-size: 14px; color: #e6e6e6; margin-bottom: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer;
  min-height: 40px;
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--on-red); }
.hero .btn:not(.primary) { background: rgb(255 255 255 / .1); border-color: rgb(255 255 255 / .2); color: #fff; }

/* Stats strip */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); padding: 12px 4px; }
.stats div { text-align: center; }
.stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* Match rows */
.list { overflow: hidden; }
.match {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.match:first-child { border-top: 0; }
.date { text-align: center; line-height: 1.1; }
.date .d { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.date .m { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.date .h { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.teams { min-width: 0; }
.teams .row { display: flex; justify-content: space-between; gap: 8px; }
.teams .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.teams .name.mine { font-weight: 800; }
.teams .name.won { font-weight: 700; }
.teams .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.meta a { color: var(--muted); }
.sets { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pill {
  font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em;
}
.pill.v { background: var(--win-bg); color: var(--win); }
.pill.p { background: var(--loss-bg); color: var(--loss); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.home { background: var(--surface-2); color: var(--muted); }
.maplink {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); flex: none;
}
.maplink svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.match.mine-row { background: linear-gradient(90deg, var(--mine), transparent 70%); }

/* Standings */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 6px; text-align: center; font-size: 14px; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
td.team, th.team { text-align: left; }
td.team { font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.pts { font-weight: 800; font-size: 16px; }
tr.mine td { background: var(--mine); }
tr.mine td:first-child { box-shadow: inset 4px 0 0 var(--red); }
tr.mine td.team { font-weight: 800; }
.form { display: inline-flex; gap: 3px; }
.form i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.form i.V { background: var(--win); }
.form i.P { background: var(--loss); }
.note { font-size: 13px; color: var(--muted); padding: 0 4px; }

/* Selector / toggles */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; min-height: 40px;
}
.seg button[aria-pressed="true"] { background: var(--red); color: var(--on-red); border-color: var(--red); }
select {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); min-height: 44px;
}

/* Update view */
.steps { padding: 6px 16px; margin: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; padding: 12px 0 12px 40px; position: relative; border-top: 1px solid var(--line); }
.steps li:first-child { border-top: 0; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 12px;
  width: 26px; height: 26px; border-radius: 50%; background: var(--red); color: var(--on-red);
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.steps p { margin: 4px 0 8px; color: var(--muted); font-size: 14px; }
.drop {
  display: block; text-align: center; padding: 24px 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  cursor: pointer; background: var(--surface);
}
.drop.over { border-color: var(--red); background: var(--mine); }
.drop b { display: block; font-size: 16px; }
.drop span { font-size: 13px; color: var(--muted); }
.drop input { display: none; }
.champ { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.champ:first-child { border-top: 0; }
.champ div { flex: 1; min-width: 0; }
.champ b { display: block; }
.champ span { font-size: 13px; color: var(--muted); }
.icon-btn { border: 0; background: var(--surface-2); width: 40px; height: 40px; border-radius: 12px; cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pad { padding: 16px; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  border: 0; background: none; padding: 8px 4px 10px; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600;
  min-height: 60px;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button[aria-current="page"] { color: var(--accent); }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 480px; margin: 0 auto; background: var(--black); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25); font-size: 14px;
}
.toast.error { background: var(--red); }

@media (min-width: 560px) {
  .match { grid-template-columns: 60px 1fr auto; }
}

/* Header quick link */
.csi-link {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  padding: 8px 12px; min-height: 40px; border-radius: 999px;
  background: rgb(0 0 0 / .18); border: 1px solid rgb(255 255 255 / .35);
  color: #fff; text-decoration: none; font-size: 14px; font-weight: 700;
}
.csi-link svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Reminder banner */
.banner { padding: 14px 16px; border-color: var(--red); background: var(--mine); }
.banner-text b { display: block; }
.banner-text span { font-size: 14px; color: var(--muted); }
.banner .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.banner .btn:not(.primary) { background: var(--surface); }

/* Quick link card */
.quick { display: flex; align-items: center; gap: 14px; padding: 16px; text-decoration: none; background: var(--red); color: var(--on-red); border: 0; }
.quick b { display: block; }
.quick small { color: rgb(255 255 255 / .85); font-size: 13px; }
.quick-icon { width: 44px; height: 44px; border-radius: 12px; background: #fff; color: var(--red); display: grid; place-items: center; flex: none; }
.quick-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Selettore squadra */
.field { display: block; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 6px; font-weight: 600; }
.team-link {
  border: 0; background: none; padding: 0; font: inherit; font-weight: inherit; color: inherit; cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left;
  text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px;
}
.team-link:hover { text-decoration-color: var(--accent); }
