/* Mobile-first: il layout base è per smartphone; i media query in fondo allargano per tablet/desktop. */
:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #17201b;
  --muted: #5f6b65;
  --line: #e2e7e4;
  --brand: #0f5132;
  --brand-2: #198754;
  --accent: #ffc83d;
  --won: #198754;
  --lost: #c0392b;
  --pending: #7d8a84;
  --notice-bg: #fff4d6; --notice-fg: #5c4400;
  --warn-bg: #fdecea; --warn-fg: #6b1c13;
  --radius: 16px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #18201c; --text: #e8eeea; --muted: #9aa8a1; --line: #2a3530;
    --brand: #0b3a24; --brand-2: #2fa56b;
    --notice-bg: #3a3014; --notice-fg: #ffe7a3;
    --warn-bg: #3d1a16; --warn-fg: #ffc9c1;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
}
button { font: inherit; touch-action: manipulation; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 14px; }
.muted { color: var(--muted); }

/* Header compatto */
.top { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; padding-top: var(--safe-t); }
.top-inner { display: flex; justify-content: space-between; align-items: center; min-height: 56px; }
.brand { font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.updated { font-size: .75rem; opacity: .8; }
.btn-icon {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12); color: #fff; font-size: 1.4rem; cursor: pointer;
}
.btn-icon.spin { animation: spin 1s linear infinite; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Navigazione in basso, a portata di pollice */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.tab {
  background: none; border: 0; color: var(--muted); font-size: .72rem; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer;
}
.tab .ico { font-size: 1.35rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--brand-2); }
.tab.active .ico { filter: none; opacity: 1; }

main { padding-top: 14px; padding-bottom: 8px; }
.panel { display: none; }
.panel.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.notice { background: var(--notice-bg); color: var(--notice-fg); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: .9rem; }

/* Schedina */
.hero { background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; border: 0; }
.hero h1 { margin: 0; font-size: 1.05rem; font-weight: 600; opacity: .95; }
.hero .sub { font-size: .85rem; opacity: .8; }
.hero-odds { font-size: 3rem; font-weight: 800; line-height: 1; margin: 14px 0 4px; }
.hero-odds small { font-size: .9rem; font-weight: 500; opacity: .8; margin-left: 6px; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.stat { background: rgba(255,255,255,.14); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.15; }
.stat small { opacity: .85; font-size: .78rem; }
.hero-note { margin: 12px 0 0; font-size: .85rem; opacity: .9; }

.leg { padding: 14px 0; border-top: 1px solid var(--line); }
.leg:first-child { border-top: 0; padding-top: 2px; }
.leg:last-child { padding-bottom: 2px; }
.leg-meta { font-size: .8rem; color: var(--muted); }
.leg-match { font-weight: 700; font-size: 1.02rem; margin: 2px 0 8px; }
.leg-pick { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.leg-pick .what { font-weight: 700; color: var(--brand-2); }
.leg-pick .what small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.leg-pick .odds { font-size: 1.35rem; font-weight: 800; white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; color: #fff; vertical-align: middle; }
.badge.won { background: var(--won); } .badge.lost { background: var(--lost); } .badge.pending { background: var(--pending); }
.hero .badge { background: rgba(255,255,255,.25); }

/* Partite */
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 0 -14px 12px; padding: 2px 14px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 0 14px; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.match-meta { font-size: .8rem; color: var(--muted); }
.match-teams { font-weight: 800; font-size: 1.05rem; margin: 2px 0; }
.xg { font-size: .82rem; color: var(--muted); }
.probs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.p { border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px 12px; position: relative; overflow: hidden; }
.p .fill { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--brand-2); border-radius: 0 4px 0 0; }
.p .lbl { font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p .row { display: flex; justify-content: space-between; align-items: baseline; }
.p .pct { font-weight: 800; font-size: 1.15rem; }
.p .q { font-size: .8rem; color: var(--muted); }
.p.in-combo { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
details summary { cursor: pointer; color: var(--muted); font-size: .88rem; padding: 12px 0 0; min-height: 36px; }
.fine { font-size: .78rem; color: var(--muted); }

/* Storico */
.hist-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hist-legs { margin: 10px 0 0; padding: 0; list-style: none; font-size: .88rem; }
.hist-legs li { padding: 6px 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.summary-grid small { font-size: .72rem; }
.summary-grid b { display: block; font-size: 1.35rem; }

.prose h2 { margin-top: 0; font-size: 1.2rem; }
.prose h3 { font-size: 1.02rem; }
.prose p, .prose li { font-size: .95rem; }
.prose ul { padding-left: 20px; }
.warn { background: var(--warn-bg); color: var(--warn-fg); border-radius: 12px; padding: 12px 14px; margin-top: 16px; font-size: .9rem; }
.foot { color: var(--muted); font-size: .75rem; text-align: center; padding-top: 4px; padding-bottom: 16px; }
.empty { text-align: center; padding: 32px 18px; }
.empty .big { font-size: 2.5rem; }
.empty h2 { font-size: 1.1rem; }

/* Tablet e desktop */
@media (min-width: 640px) {
  .probs { grid-template-columns: repeat(4, 1fr); }
  .hero-stats { grid-template-columns: repeat(3, 1fr); }
  .bottom-nav { max-width: 520px; margin: 0 auto 12px; border-radius: 20px; border: 1px solid var(--line); height: var(--nav-h); padding-bottom: 0; bottom: var(--safe-b); }
}

/* Calendario e storico */
.card-title { font-size: 1.05rem; margin: 0 0 6px; }
.day-head { font-size: .8rem; font-weight: 700; color: var(--brand-2); margin: 14px 0 4px; }
.up-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); font-size: .93rem; }
.up-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.up-teams { font-weight: 600; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; margin-left: 4px; vertical-align: middle; }
.nowrap { white-space: nowrap; }
.day-head::first-letter { text-transform: uppercase; }

/* Forma e AI */
.form-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.form-row > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.form { display: inline-flex; gap: 3px; flex: none; }
.form i { font-style: normal; font-size: .7rem; font-weight: 800; width: 20px; height: 20px; border-radius: 5px; display: inline-grid; place-items: center; color: #fff; }
.form .f-V { background: var(--won); } .form .f-N { background: var(--pending); } .form .f-P { background: var(--lost); }
.ai-card { border-color: var(--brand-2); }
.ai-card p { margin: 6px 0; }
.ai-note { font-size: .88rem; margin: 8px 2px 0; color: var(--text); }
.ai-foot { font-size: .72rem; color: var(--muted); margin: 8px 0 0; }
.ai-box { margin-top: 10px; }
.ai-btn { width: 100%; min-height: 44px; border-radius: 12px; border: 1px dashed var(--brand-2); background: transparent; color: var(--brand-2); font-weight: 700; cursor: pointer; }
.ai-btn:disabled { opacity: .7; cursor: wait; }
.ai-card-inline { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: .92rem; }
.ai-card-inline p { margin: 4px 0; }
