:root{
  color-scheme:light dark;
  --bg:#F2F4F8;--card:#fff;--ink:#0F1728;--muted:#5B6578;--line:#E2E6EE;--soft:#EEF1F7;
  --accent:#2F5BEA;--on-accent:#fff;
  --win:#0E8A5F;--win-bg:#E3F5EC;--on-win:#fff;
  --loss:#C8372F;--loss-bg:#FCE9E7;--on-loss:#fff;
  --warn:#9A5200;--warn-bg:#FFF1DC;
  --shadow:0 1px 2px rgba(15,23,40,.05),0 6px 20px rgba(15,23,40,.05);
  --r:20px;
  --sat:env(safe-area-inset-top,0px);--sab:env(safe-area-inset-bottom,0px);--sal:env(safe-area-inset-left,0px);--sar:env(safe-area-inset-right,0px);
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  font-synthesis:none;-webkit-text-size-adjust:100%;text-size-adjust:100%;
}
@media(prefers-color-scheme:dark){:root{
  --bg:#0C0F16;--card:#161B25;--ink:#EEF2FA;--muted:#97A1B5;--line:#262D3B;--soft:#1D2330;
  --accent:#7C9BFF;--on-accent:#0C1330;
  --win:#47C58C;--win-bg:#123226;--on-win:#04180F;
  --loss:#F27B74;--loss-bg:#3A1C1E;--on-loss:#2A0A08;
  --warn:#F2B35E;--warn-bg:#3A2A10;
  --shadow:none;
}}
*{box-sizing:border-box}
[hidden]{display:none!important}
html{-webkit-tap-highlight-color:transparent}
body{margin:0;background:var(--bg);color:var(--ink);font-size:16px;line-height:1.4;min-height:100vh;min-height:100dvh;overflow-x:hidden;font-variant-numeric:tabular-nums}
body:has(dialog[open]){overflow:hidden}
h1,h2,h3,p,dl,dd,ul{margin:0;padding:0}
ul{list-style:none}
button,input{font:inherit;color:inherit}
button{cursor:pointer;touch-action:manipulation;-webkit-appearance:none;appearance:none}
button:disabled{cursor:not-allowed;opacity:.4}
:focus-visible{outline:3px solid var(--accent);outline-offset:2px}
b,strong{font-weight:700}

/* Barra alta */
.topbar{position:sticky;top:0;z-index:10;display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:calc(10px + var(--sat)) calc(16px + var(--sar)) 10px calc(16px + var(--sal));
  background:color-mix(in srgb,var(--bg) 88%,transparent);-webkit-backdrop-filter:saturate(1.6) blur(14px);backdrop-filter:saturate(1.6) blur(14px);border-bottom:1px solid var(--line)}
.switcher{display:flex;align-items:center;gap:8px;min-height:48px;min-width:0;padding:4px 14px 4px 14px;border:1px solid var(--line);border-radius:14px;background:var(--card);text-align:left}
.switcher-text{display:flex;flex-direction:column;min-width:0}
.switcher small{font-size:12px;color:var(--muted);line-height:1.2}
.switcher strong{font-size:17px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:56vw}
.chevron{font-size:20px;line-height:1;color:var(--muted);margin-top:-6px}
.round-btn{flex:none;width:48px;height:48px;border-radius:50%;border:1px solid var(--line);background:var(--card);font-size:15px;font-weight:800;letter-spacing:1px;display:grid;place-items:center}
.round-btn.small{width:44px;height:44px;font-size:16px;letter-spacing:0;background:var(--soft);border-color:transparent}

/* Pagina */
.page{width:100%;max-width:640px;margin:0 auto;padding:16px calc(16px + var(--sar)) calc(32px + var(--sab)) calc(16px + var(--sal));display:flex;flex-direction:column;gap:14px}
.card{background:var(--card);border-radius:var(--r);padding:20px;box-shadow:var(--shadow);border:1px solid var(--line);min-width:0}
.card-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:16px}
.card-head h2{font-size:19px;font-weight:750;letter-spacing:-.3px;line-height:1.25}
.card-head h2 span{color:var(--muted);font-weight:600}
.muted-strong{font-size:15px;color:var(--muted);font-weight:650;white-space:nowrap}
.label{font-size:14px;color:var(--muted);font-weight:600;margin-bottom:6px}
.badge{font-size:13px;font-weight:700;border-radius:99px;padding:5px 11px;white-space:nowrap}
.badge-live{background:var(--soft);color:var(--ink)}
.badge-success{background:var(--win-bg);color:var(--win)}
.badge-failed{background:var(--loss-bg);color:var(--loss)}
.pill{font-size:13px;font-weight:650;background:var(--soft);color:var(--muted);border-radius:99px;padding:5px 11px}

/* Puntata */
.stake{font-size:clamp(46px,15vw,68px);font-weight:800;letter-spacing:-.04em;line-height:1.05;margin-bottom:12px;overflow-wrap:anywhere}
.meter{height:8px;border-radius:99px;background:var(--soft);overflow:hidden}
.meter-fill{height:100%;width:0;background:var(--accent);border-radius:99px;transition:width .3s,background .3s}
.meter-fill.high{background:var(--loss)}
.stake-sub{font-size:14px;color:var(--muted);margin:8px 0 20px}
.odds-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding-top:18px;border-top:1px solid var(--line)}
.odds-row label{font-size:16px;font-weight:600;line-height:1.25}
.odds-control{display:flex;align-items:center;flex:none;border:1.5px solid var(--line);border-radius:14px;background:var(--soft);overflow:hidden}
.odds-step{width:48px;height:52px;border:0;background:transparent;font-size:26px;font-weight:500;color:var(--accent);line-height:1}
.odds-step:active{background:var(--line)}
.odds-control input{width:72px;height:52px;border:0;background:var(--card);text-align:center;font-size:20px;font-weight:800;border-radius:0;outline:none;min-width:0;-webkit-appearance:none;appearance:none}
.odds-control:focus-within{border-color:var(--accent)}
.hint{font-size:13px;color:var(--muted);line-height:1.45;margin:8px 0 20px}
.hint.error{color:var(--loss)}

/* Esito: azione principale */
.result-actions{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.result-btn{border:0;border-radius:18px;padding:16px 12px;min-height:84px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;transition:transform .12s}
.result-btn:not(:disabled):active{transform:scale(.97)}
.result-title{font-size:22px;font-weight:800;letter-spacing:-.3px}
.result-after{font-size:13px;opacity:.92}
.result-btn.win{background:var(--win);color:var(--on-win)}
.result-btn.loss{background:var(--loss);color:var(--on-loss)}
.risk-note{margin-top:14px;font-size:13px;color:var(--muted);line-height:1.5;text-align:center}
.risk-note.warning{color:var(--warn);background:var(--warn-bg);padding:10px 12px;border-radius:12px;text-align:left;font-weight:600}

.finished{text-align:center;padding:10px 0 4px}
.finish-icon{width:64px;height:64px;margin:0 auto 14px;border-radius:50%;display:grid;place-items:center;font-size:30px;font-weight:800;background:var(--win-bg);color:var(--win)}
.finish-icon.bad{background:var(--loss-bg);color:var(--loss)}
.finished h3{font-size:22px;letter-spacing:-.3px;margin-bottom:8px}
.finished p{color:var(--muted);line-height:1.55;margin-bottom:20px}

/* Avanzamento */
.segments{display:flex;gap:3px;height:12px}
.segments.dense{gap:1px}.segments.dense .seg{border-radius:2px}
.seg{flex:1;min-width:0;border-radius:4px;background:var(--soft)}
.seg.win{background:var(--win)}
.seg.loss{background:var(--loss)}
.seg.now{background:var(--card);box-shadow:inset 0 0 0 2px var(--accent)}
.seg-legend{display:flex;flex-wrap:wrap;gap:6px 18px;font-size:14px;color:var(--muted);margin:12px 0 18px}
.seg-legend span{display:flex;align-items:center;gap:6px}
.seg-legend b{color:var(--ink)}
.dot{width:10px;height:10px;border-radius:50%;display:inline-block;background:var(--soft);border:1px solid var(--line)}
.dot.win{background:var(--win);border-color:var(--win)}.dot.loss{background:var(--loss);border-color:var(--loss)}
.stats{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.stat{background:var(--soft);border-radius:16px;padding:14px;display:flex;flex-direction:column;gap:2px;min-width:0}
.stat:first-child{grid-column:1/-1}
.stat-label{font-size:13px;color:var(--muted);font-weight:600}
.stat-value{font-size:26px;font-weight:800;letter-spacing:-.03em;line-height:1.2;overflow-wrap:anywhere}
.stat-sub{font-size:13px;color:var(--muted)}
.positive{color:var(--win)!important}.negative{color:var(--loss)!important}

/* Grafico */
.chart{height:190px;position:relative}
.chart svg{display:block;width:100%;height:100%;overflow:visible}
.c-grid{stroke:var(--line);stroke-width:1}
.c-start{stroke:var(--muted);stroke-width:1.4;stroke-dasharray:6 5}
.c-line{fill:none;stroke:var(--accent);stroke-width:3;stroke-linejoin:round;stroke-linecap:round}
.c-area-stop{stop-color:var(--accent)}
.c-txt{fill:var(--muted);font-size:12px;font-family:inherit}
.c-pt-win{fill:var(--win);stroke:var(--card);stroke-width:2}
.c-pt-loss{fill:var(--loss);stroke:var(--card);stroke-width:2}
.c-pt-start{fill:var(--accent);stroke:var(--card);stroke-width:2}
.chart-legend{display:flex;gap:18px;font-size:13px;color:var(--muted);margin-top:10px}
.chart-legend span{display:flex;align-items:center;gap:7px}
.line-key{display:inline-block;width:18px;height:3px;border-radius:3px;background:var(--accent)}
.line-key.dashed{background:repeating-linear-gradient(90deg,var(--muted) 0 6px,transparent 6px 10px)}

/* Storico */
.history{display:flex;flex-direction:column}
.hrow{display:flex;align-items:center;gap:12px;padding:12px 0;border-top:1px solid var(--line)}
.hrow:first-child{border-top:0;padding-top:0}
.hchip{flex:none;min-width:76px;text-align:center;font-size:14px;font-weight:700;border-radius:10px;padding:7px 10px}
.hchip.win{background:var(--win-bg);color:var(--win)}.hchip.loss{background:var(--loss-bg);color:var(--loss)}
.hmain{flex:1;min-width:0;display:flex;flex-direction:column}
.hmain strong{font-size:16px}
.hmain small{font-size:13px;color:var(--muted)}
.hafter{text-align:right;font-weight:700;font-size:16px;white-space:nowrap}
.hafter small{display:block;font-size:12px;color:var(--muted);font-weight:500}
.empty{padding:14px 0 18px;text-align:center;color:var(--muted);line-height:1.5}
.history+.btn{margin-top:14px}

/* Dettagli */
.details{padding:0}
.details summary{list-style:none;padding:18px 20px;font-size:17px;font-weight:700;cursor:pointer;display:flex;justify-content:space-between;align-items:center;min-height:56px}
.details summary::-webkit-details-marker{display:none}
.details summary::after{content:"⌄";font-size:22px;color:var(--muted);transition:transform .2s}
.details[open] summary::after{transform:rotate(180deg)}
.params{padding:0 20px}
.params>div{display:flex;justify-content:space-between;gap:12px;padding:13px 0;border-top:1px solid var(--line);font-size:15px}
.params dt{color:var(--muted)}.params dd{font-weight:700;text-align:right}
.explain{padding:14px 20px 20px;font-size:13px;color:var(--muted);line-height:1.55}
.footer{padding:6px 8px 0;text-align:center;font-size:12px;color:var(--muted);line-height:1.6}

/* Bottoni */
.btn{border:0;border-radius:14px;min-height:52px;padding:0 20px;font-size:17px;font-weight:700;display:inline-flex;align-items:center;justify-content:center;gap:8px;transition:transform .12s}
.btn:not(:disabled):active{transform:scale(.98)}
.btn.block{width:100%}
.btn.primary{background:var(--accent);color:var(--on-accent)}
.btn.ghost{background:var(--soft);color:var(--ink)}

/* Finestre (a scorrimento dal basso su telefono) */
.modal{color:var(--ink);background:var(--card);border:0;padding:12px 20px calc(20px + var(--sab));width:100%;max-width:none;max-height:88vh;max-height:88dvh;overflow:auto;margin:auto 0 0;border-radius:24px 24px 0 0;box-shadow:0 -10px 50px rgba(0,0,0,.25);overscroll-behavior:contain}
.modal::backdrop{background:rgba(8,12,22,.55);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px)}
.modal[open]{animation:sheet-up .22s ease-out}
@keyframes sheet-up{from{transform:translateY(24px);opacity:0}to{transform:none;opacity:1}}
.sheet-grip{width:40px;height:5px;border-radius:9px;background:var(--line);margin:0 auto 14px}
.modal-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;margin-bottom:16px}
.modal-head h2{font-size:22px;font-weight:800;letter-spacing:-.4px;line-height:1.25;padding-top:7px}
.modal-text{color:var(--muted);line-height:1.55;margin-top:8px;font-size:16px}
.session-list{display:flex;flex-direction:column;gap:8px;margin-bottom:16px;max-height:50vh;overflow-y:auto}
.session-item{display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:100%;min-height:60px;padding:12px 16px;border-radius:16px;border:1.5px solid var(--line);background:var(--card);text-align:left}
.session-item.is-active{border-color:var(--accent);background:var(--soft)}
.session-item-name{font-size:17px;font-weight:700;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.session-item-detail{font-size:14px;color:var(--muted)}
.menu-list{display:flex;flex-direction:column;gap:8px}
.menu-item{display:flex;flex-direction:column;align-items:flex-start;gap:2px;width:100%;min-height:60px;padding:12px 16px;border:0;border-radius:16px;background:var(--soft);text-align:left}
.menu-item strong{font-size:17px}.menu-item span{font-size:14px;color:var(--muted)}
.menu-item.danger strong{color:var(--loss)}
.form-fields{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.field{display:flex;flex-direction:column;gap:6px;font-size:14px;font-weight:650;color:var(--muted)}
.field.wide{grid-column:1/-1}
.field input{width:100%;min-height:52px;padding:0 14px;border-radius:14px;border:1.5px solid var(--line);background:var(--soft);color:var(--ink);font-size:17px;font-weight:600;outline:0;-webkit-appearance:none;appearance:none}
.field input:focus{border-color:var(--accent);background:var(--card)}
.form-error{margin-top:14px;padding:12px 14px;border-radius:12px;background:var(--loss-bg);color:var(--loss);font-weight:600;font-size:15px;line-height:1.4}
.modal-warning{margin-top:14px;padding:12px 14px;border-radius:12px;background:var(--warn-bg);color:var(--warn);font-size:14px;line-height:1.5}
.modal-actions{display:flex;gap:10px;margin-top:20px}
.modal-actions .btn{flex:1}
.modal-actions .btn.primary{flex:1.4}

.divider-text{text-align:center;color:var(--muted);font-size:14px;margin:18px 0 12px}
.sync-status{font-size:15px;font-weight:650;margin-bottom:16px}
.sync-status.error{color:var(--loss)}
.code-box{background:var(--soft);border-radius:14px;padding:14px;overflow-wrap:anywhere}
.code-box code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:15px;line-height:1.6;letter-spacing:.04em;user-select:all;-webkit-user-select:all}
.code-actions{display:flex;gap:10px;margin-top:10px}.code-actions .btn{flex:1}
.modal-actions.stack{flex-direction:column}
.btn.danger-btn{color:var(--loss)}
.toast{position:fixed;left:50%;bottom:calc(20px + var(--sab));transform:translate(-50%,16px);width:max-content;max-width:min(92vw,420px);background:var(--ink);color:var(--bg);padding:14px 18px;border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.3);opacity:0;pointer-events:none;transition:.2s;z-index:1000;font-size:15px;line-height:1.4;font-weight:600}
.toast.shown{opacity:1;transform:translate(-50%,0);pointer-events:auto}
.toast{display:flex;align-items:center;gap:14px}
.toast-action{flex:none;min-height:44px;margin:-8px -8px -8px 0;padding:0 14px;border:0;border-radius:10px;background:rgba(255,255,255,.16);font-weight:800;font-size:15px;color:inherit}
.toast-action:active{background:rgba(255,255,255,.3)}
.scenario{font-size:14px;line-height:1.55;color:var(--muted);background:var(--soft);border-radius:14px;padding:12px 14px;margin-bottom:20px}
.stake.pulse{animation:stake-pulse .35s ease-out}
@keyframes stake-pulse{0%{transform:scale(.94);opacity:.4}100%{transform:none;opacity:1}}
.toast.error{background:var(--loss);color:var(--on-loss)}

/* Schermi larghi: finestre centrate */
@media(min-width:640px){
  .page{padding-top:24px;gap:16px}
  .modal{margin:auto;max-width:480px;border-radius:24px;padding-bottom:24px;max-height:90vh}
  .sheet-grip{display:none}
  .stats{grid-template-columns:repeat(3,1fr)}
  .stat:first-child{grid-column:auto}
  .stat-value{font-size:22px}
}
@media(max-width:360px){
  .odds-row{flex-direction:column;align-items:stretch}
  .odds-control{align-self:flex-end}
  .result-title{font-size:19px}
}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important}}
