:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #14181f;
  --muted: #5d6675;
  --line: #e2e6ec;
  --accent: #e8590c;        /* pallina */
  --accent-soft: #fff0e6;
  --blue: #1c5fd4;          /* tavolo */
  --up: #12805c;
  --down: #c92a2a;
  --warn-bg: #fff4d6;
  --warn: #8a5a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --text: #e8ebf0;
    --muted: #98a2b3;
    --line: #2a313b;
    --accent: #ff7a2e;
    --accent-soft: #2b1d14;
    --blue: #6aa1ff;
    --up: #3cc796;
    --down: #ff6b6b;
    --warn-bg: #2e2612;
    --warn: #f0c060;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 8px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.up { color: var(--up); font-weight: 600; }
.down { color: var(--down); font-weight: 600; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-sub { color: var(--muted); font-weight: 500; font-size: 13px; }
.ball { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: inset -3px -3px 0 rgba(0,0,0,.12); }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500; white-space: nowrap; }
@media (max-width: 1060px) { .nav a[href="/stato"] { display: none; } .topbar .search { width: 220px; } }
.nav a.on, .nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar .search { margin-left: auto; width: 280px; }

/* search */
.search, .hero-search { position: relative; }
input[type=search], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; outline: none;
}
input[type=search]:focus, select:focus { border-color: var(--blue); background: var(--surface); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; z-index: 20;
}
.search-results a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; color: var(--text); }
.search-results a:hover, .search-results a.sel { background: var(--surface-2); text-decoration: none; }
.search-results .sr-sub { color: var(--muted); font-size: 12px; }
.search-results .sr-pts { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* hero */
.hero { padding: 40px 0 24px; }
.hero h1 { font-size: 36px; max-width: 760px; }
.lead { color: var(--muted); font-size: 17px; max-width: 760px; margin: 0 0 20px; }
.hero-search { max-width: 560px; }
.hero-search input { padding: 14px 16px; font-size: 16px; background: var(--surface); box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-v { font-size: 24px; font-weight: 600; }
.stat-l { color: var(--muted); font-size: 13px; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 16px 0; box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .card { margin: 0; }
.btn { display: inline-block; background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 10px; font-weight: 600; margin: 20px 0; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); margin: 4px 0 0; font-size: 14px; }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.tag-mix { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--blue); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.footer { color: var(--muted); font-size: 13px; padding: 32px 16px 48px; }
.footer-nav { display: none; flex-wrap: wrap; gap: 8px 16px; margin-bottom: 10px; font-size: 15px; font-weight: 600; }

/* lists */
.plist { list-style: none; margin: 8px 0 0; padding: 0; }
.plist li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.plist li a { display: flex; flex-direction: column; min-width: 0; color: var(--text); }
.plist .pname { font-weight: 600; }
.plist .pclub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plist .ppos { color: var(--muted); font-size: 12px; }

/* page head & filters */
.pagehead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; padding: 28px 0 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select { width: auto; }
.filters input[type=search] { width: 220px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg input { display: none; }
.seg span { display: block; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* tables */
.tablewrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .num { text-align: right; }
.tbl.narrow { width: auto; min-width: 420px; }
.res { display: inline-block; width: 22px; text-align: center; border-radius: 6px; font-weight: 700; font-size: 12px; padding: 2px 0; }
.res-w { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.res-l { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.show-sm { display: none; }

/* profile */
.profile { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 20px; padding: 28px 0 8px; }
.kpis { display: flex; gap: 12px; flex-wrap: wrap; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 150px; }
.kpi-main { border-color: var(--accent); background: var(--accent-soft); }
.kpi-l { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-v { font-size: 26px; font-weight: 600; }
.pm { font-size: 13px; color: var(--muted); margin-left: 6px; font-weight: 500; }
.pm-s { font-size: 11px; color: var(--muted); font-weight: 400; }
.kpi-s { font-size: 12px; color: var(--muted); }
.legend { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-left: 8px; }
.sw-new { background: var(--accent); }
.sw-off { background: var(--muted); }
.sw-norm { background: repeating-linear-gradient(90deg, var(--blue) 0 2px, transparent 2px 5px); }
.chart { height: 240px; margin-top: 8px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid line { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; font-family: Inter, sans-serif; }
.tabs { display: flex; gap: 4px; margin-top: 20px; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs + .card { margin-top: 8px; }
.group-tabs { margin: 4px 0 8px; flex-wrap: wrap; }
.group-tabs a { font-weight: 600; padding: 8px 14px; border-radius: 8px; color: var(--muted); }
.group-tabs a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.group-tabs a:hover { text-decoration: none; color: var(--text); }

/* head to head */
.h2h { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; }
.h2h-side.right { text-align: right; }
.h2h-name { font-size: 18px; font-weight: 700; }
.h2h-pts { font-size: 20px; margin-top: 6px; }
.h2h-mid { text-align: center; }
.h2h-score { font-size: 40px; font-weight: 700; }

.pager { display: flex; justify-content: space-between; align-items: center; margin: 16px 0; }
.pager a { font-weight: 600; }
.home-filter { margin: 8px 0 12px; }
.home-filter select { width: auto; }
/* stato raccolta */
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--up); animation: pulse 1.6s infinite; }
.live.off .dot { background: var(--down); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.fase-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fase-num { font-size: 15px; }
.bar { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 10px 0 8px; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #ffd2b0)); border-radius: 999px; transition: width .8s ease; }
.fase.done .bar-fill { background: var(--up); }
.fase-sub { display: flex; justify-content: space-between; gap: 12px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { padding: 4px 0; color: var(--muted); }
.steps li::after { content: attr(data-time); margin-left: 8px; font-size: 12px; font-family: "JetBrains Mono", monospace; }
.steps li.ok { color: var(--up); }
.steps li.ok::before { content: "✓ "; }
.steps li.now { color: var(--text); font-weight: 600; }
.steps li.now::before { content: "▶ "; color: var(--accent); }
#log div { padding: 3px 0; word-break: break-word; }
.sim-pick { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: start; }
.sim-pick .search { margin-top: 8px; }
.sim-vs { align-self: center; color: var(--muted); font-weight: 600; }
.sim-type { margin: 8px 0; }
.sim-type select { width: auto; }
.btn-ghost + .btn-ghost { margin-left: 6px; }
@media (max-width: 760px) { .sim-pick { grid-template-columns: 1fr; } .sim-vs { justify-self: center; } }
.prose { max-width: 760px; padding: 28px 0; }
.prose li { margin-bottom: 8px; }
.prose h2 { margin-top: 28px; }

@media (max-width: 760px) {
  .topbar-inner { gap: 12px; }
  .topbar .search { width: auto; flex: 1; }
  .nav { display: none; }
  .footer-nav { display: flex; }
  .profile { gap: 12px; }
  .kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; }
  .kpi { min-width: 0; padding: 10px; }
  .tbl th, .tbl td { padding: 8px 6px; }
  .tbl.narrow { min-width: 0; width: 100%; }
  .kpi-v { font-size: 18px; }
  .kpi-l { font-size: 10px; }
  .kpi-s { font-size: 11px; }
  .brand-sub { display: none; }
  .hero h1 { font-size: 28px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  .h2h { grid-template-columns: 1fr; text-align: center; }
  .h2h-side.right { text-align: center; }
  .filters input[type=search] { width: 100%; }
}
