:root {
  --bg: #EEF2F1;
  --surface: #FFFFFF;
  --ink: #13233A;
  --muted: #5E6B7A;
  --line: #D6DEE0;
  --accent: #2D5BD3;
  --gain: #13805A;
  --loss: #C23B32;
  --s-news0: #2D5BD3;
  --s-controllo: #B97A0B;
  --s-spy: #8794A3;
  --radius-lg: 18px;
  --radius-sm: 10px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1726; --surface: #16233A; --ink: #E7EDF5; --muted: #93A1B3; --line: #26364F;
    --accent: #7EA2FF; --gain: #3CCB8C; --loss: #FF7A6E;
    --s-news0: #7EA2FF; --s-controllo: #F0B44C; --s-spy: #6F7E92;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1726; --surface: #16233A; --ink: #E7EDF5; --muted: #93A1B3; --line: #26364F;
  --accent: #7EA2FF; --gain: #3CCB8C; --loss: #FF7A6E;
  --s-news0: #7EA2FF; --s-controllo: #F0B44C; --s-spy: #6F7E92;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ------------------------------------------------------------- struttura */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabs-h) + env(safe-area-inset-bottom) + 24px);
  outline: none;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs svg, .icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { border: 0; background: none; padding: 8px; border-radius: 50%; color: var(--muted); cursor: pointer; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- tipografia */
h2 { font-size: 17px; margin: 28px 0 8px; letter-spacing: -0.005em; }
h2:first-child { margin-top: 8px; }
.lead { font-size: 22px; line-height: 1.3; font-weight: 650; letter-spacing: -0.015em; margin: 6px 0 4px; }
.lead .n { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.gain { color: var(--gain); }
.loss { color: var(--loss); }

/* ------------------------------------------------------------- la gara (grafico) */
.race { margin: 10px -16px 0; padding: 0 16px; }
.race svg { display: block; width: 100%; height: auto; overflow: visible; }
.race .grid { stroke: var(--line); stroke-width: 1; }
.race .zero { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 4; }
.race .axis { fill: var(--muted); font-size: 11px; }
.race .lbl { font-size: 13px; font-weight: 700; }
.race path { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.race path.spy { stroke-width: 2; stroke-dasharray: 5 5; }
.empty-chart {
  border: 1.5px dashed var(--line); border-radius: var(--radius-lg); padding: 28px 18px;
  color: var(--muted); text-align: center; margin-top: 10px;
}

/* ------------------------------------------------------------- blocchi strategia */
.strat {
  background: var(--surface); border-radius: var(--radius-lg); padding: 14px 16px; margin-top: 12px;
  border-left: 5px solid var(--sc, var(--accent));
}
.strat h3 { font-size: 16px; margin: 0; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.strat h3 .ret { font-size: 20px; }
.strat .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0 2px; }
.facts div { font-size: 13px; color: var(--muted); }
.facts b { display: block; font-size: 17px; color: var(--ink); }
.note-box { font-size: 13px; color: var(--muted); margin: 18px 2px 0; }

/* ------------------------------------------------------------- liste */
.list { background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; margin-top: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 700; }
.row .d { font-size: 13px; color: var(--muted); }
.row .v { text-align: right; font-weight: 650; white-space: nowrap; }
.side { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 13px; flex: none; }
.side.buy { background: color-mix(in srgb, var(--gain) 16%, transparent); color: var(--gain); }
.side.sell { background: color-mix(in srgb, var(--loss) 16%, transparent); color: var(--loss); }
.status { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--muted); }
.status.todo { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.empty { padding: 16px; color: var(--muted); }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 2px; }

/* ------------------------------------------------------------- azioni e moduli */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: var(--radius-sm); padding: 11px 16px; font-weight: 700; cursor: pointer;
  background: var(--accent); color: #fff; min-height: 44px;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--line); }
.btn.quiet { background: transparent; color: var(--muted); padding: 11px 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.confirm { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 16px 14px; }
.confirm label { font-size: 13px; color: var(--muted); }
.confirm input, .field input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: var(--bg); min-height: 44px;
}
.confirm .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.field { display: flex; gap: 8px; margin-top: 8px; }
.field input { flex: 1; text-transform: uppercase; }
.field input::placeholder { text-transform: none; }
.chip[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 999px;
  padding: 4px 4px 4px 12px; font-weight: 650; font-size: 14px; border: 1px solid var(--line); }
.chip.warn { border-color: var(--loss); }
.chip.held { border-color: var(--accent); }
.chip button { border: 0; background: none; width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ------------------------------------------------------------- notizie */
.news-t { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.news-t button { border: 0; background: none; padding: 0; font-weight: 800; font-size: 17px; cursor: pointer; color: var(--ink); }
.tag { font-size: 12px; font-weight: 700; color: var(--accent); margin-left: 6px; }
.art { display: block; padding: 6px 0 0; color: var(--ink); text-decoration: none; }
.art:hover { text-decoration: underline; }
.art .when { color: var(--muted); font-size: 12px; display: block; }

/* ------------------------------------------------------------- login */
.login { max-width: 360px; margin: 14vh auto 0; text-align: left; }
.login h2 { font-size: 26px; margin-bottom: 6px; }
.login input { width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--line);
  background: var(--surface); margin: 14px 0 10px; min-height: 48px; }
.err { color: var(--loss); font-size: 14px; min-height: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); transition: opacity .2s, transform .2s; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.locked .tabs, body.locked #refresh { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
