:root {
  --bg: #f2f5f4;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #16211f;
  --muted: #5b6b67;
  --line: #e1e8e5;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --down: #15803d;
  --stable: #8b9c97;
  --up: #d9480f;
  --wait-bg: #e3f4e8;    --wait-fg: #14532d;
  --buy-bg: #ffedd5;     --buy-fg: #7c2d12;
  --neutral-bg: #e5eaf0; --neutral-fg: #334155;
  --stale-bg: #ececec;   --stale-fg: #4b5563;
  --warn-bg: #fff7e0;    --warn-line: #f2d675;
  --bad-bg: #fee2e2;     --bad-fg: #991b1b;
  --shadow: 0 1px 2px rgba(16, 24, 22, .04), 0 8px 24px -12px rgba(16, 24, 22, .18);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1211;
    --surface: #141d1b;
    --surface-2: #1b2624;
    --text: #e9f1ef;
    --muted: #98aba6;
    --line: #253330;
    --brand: #2dd4bf;
    --brand-2: #5eead4;
    --down: #4ade80;
    --stable: #7c8f8a;
    --up: #fb923c;
    --wait-bg: #123524;    --wait-fg: #bbf7d0;
    --buy-bg: #402410;     --buy-fg: #fed7aa;
    --neutral-bg: #1f2a36; --neutral-fg: #cbd5e1;
    --stale-bg: #23282a;   --stale-fg: #b4bcbc;
    --warn-bg: #2b260f;    --warn-line: #6b5c18;
    --bad-bg: #3f1616;     --bad-fg: #fca5a5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 28px -14px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1211;
  --surface: #141d1b;
  --surface-2: #1b2624;
  --text: #e9f1ef;
  --muted: #98aba6;
  --line: #253330;
  --brand: #2dd4bf;
  --brand-2: #5eead4;
  --down: #4ade80;
  --stable: #7c8f8a;
  --up: #fb923c;
  --wait-bg: #123524;    --wait-fg: #bbf7d0;
  --buy-bg: #402410;     --buy-fg: #fed7aa;
  --neutral-bg: #1f2a36; --neutral-fg: #cbd5e1;
  --stale-bg: #23282a;   --stale-fg: #b4bcbc;
  --warn-bg: #2b260f;    --warn-line: #6b5c18;
  --bad-bg: #3f1616;     --bad-fg: #fca5a5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 28px -14px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, "Segoe UI", system-ui, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  transition: background-color .25s ease, color .25s ease;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.app { max-width: 560px; margin: 0 auto; padding: 0 16px 28px; }

/* ---------- Header ---------- */
.hero {
  margin: 0 -16px 18px;
  padding: 18px 16px 20px;
  background: linear-gradient(155deg, var(--brand) 0%, var(--brand-2) 130%);
  color: #ffffff;
  border-radius: 0 0 26px 26px;
}
.hero-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
.brand-icon { width: 26px; height: 26px; flex: none; }
.hero-updated { margin: 10px 0 0; font-size: 0.86rem; color: rgba(255,255,255,.88); }

.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: rgba(255,255,255,.22); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px;
  background: var(--surface-2);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- Loading skeleton ---------- */
.skeleton { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 18px; }
.sk-line, .sk-bar { background: var(--surface-2); border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
.sk-line { height: 14px; margin-bottom: 10px; }
.sk-bar { height: 14px; border-radius: 7px; margin: 14px 0; }
.sk-w40 { width: 40%; } .sk-w60 { width: 60%; height: 26px; } .sk-w70 { width: 70%; } .sk-w80 { width: 85%; }
@keyframes pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px 18px;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card, .sk-line, .sk-bar { animation: none; } }

.status-row { display: flex; align-items: center; gap: 12px; }
.status-icon {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: 14px;
}
.status-icon svg { width: 24px; height: 24px; }
.status-icon.wait { background: var(--wait-bg); color: var(--wait-fg); }
.status-icon.buy_now { background: var(--buy-bg); color: var(--buy-fg); }
.status-icon.neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.status-icon.stale { background: var(--stale-bg); color: var(--stale-fg); }

.headline { margin: 0; font-size: 1.4rem; line-height: 1.22; font-weight: 800; letter-spacing: -0.01em; }
.summary { margin: 2px 0 0; color: var(--muted); font-size: 0.94rem; }

.price-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px; padding: 12px 14px;
  background: var(--surface-2); border-radius: 14px;
}
.price-box { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.price-row .price-box:last-child { text-align: right; }
.price-label { font-size: 0.76rem; color: var(--muted); }
.price-value { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.price-arrow { width: 16px; height: 16px; flex: none; color: var(--muted); transform: rotate(-90deg); }

.change-pill {
  display: inline-flex; align-items: baseline; gap: 5px;
  margin-top: 14px; padding: 7px 12px;
  background: var(--surface-2); border-radius: 999px;
  font-size: 0.88rem;
}
.change-pill b { font-size: 1rem; font-variant-numeric: tabular-nums; }

.probs { margin-top: 18px; }
.probs-title { margin: 0 0 8px; font-size: 0.84rem; color: var(--muted); }
.bar { display: flex; height: 12px; border-radius: 7px; overflow: hidden; background: var(--line); }
.bar > span { display: block; height: 100%; width: 0; transition: width .6s cubic-bezier(.22,.9,.32,1); }
.bar .down { background: var(--down); }
.bar .stable { background: var(--stable); }
.bar .up { background: var(--up); }
.legend { display: flex; justify-content: space-between; gap: 6px; margin-top: 9px; }
.legend .item { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.legend .item:nth-child(2) { align-items: center; }
.legend .item:nth-child(3) { align-items: flex-end; }
.legend b { font-size: 1.08rem; font-variant-numeric: tabular-nums; }
.legend .k { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 0.82rem; }
.legend .k::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.legend .down .k::before { background: var(--down); }
.legend .stable .k::before { background: var(--stable); }
.legend .up .k::before { background: var(--up); }

.block { margin-top: 18px; }
.block h3 { margin: 0 0 8px; font-size: 0.86rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.block ul { margin: 0; padding: 0; list-style: none; }
.block li { position: relative; padding-left: 18px; margin: 7px 0; font-size: 0.94rem; }
.block li::before { content: ""; position: absolute; left: 0; top: 0.55em; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.block.caution { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 14px; padding: 14px 14px 12px; }
.block.caution li::before { background: #b45309; }

.block.check { border-radius: 14px; padding: 14px 14px; }
.block.check h3 { color: inherit; opacity: .75; }
.block.check p { margin: 0; font-size: 0.94rem; }
.block.check-confermata { background: var(--wait-bg); color: var(--wait-fg); }
.block.check-smentita { background: var(--bad-bg); color: var(--bad-fg); }
.block.check-stabile { background: var(--neutral-bg); color: var(--neutral-fg); }

.conf { margin: 16px 0 0; font-size: 0.8rem; color: var(--muted); }

.error { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ---------- Ad slot ---------- */
.ad-slot {
  display: flex; align-items: center; justify-content: center;
  min-height: 90px;
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 18px 0 4px;
}

/* ---------- Fonti delle notizie (dentro un <details class="how">) ---------- */
.sources-list { list-style: none; margin: 8px 0 0; padding: 0; }
.sources-list li { padding: 10px 0; border-top: 1px solid var(--line); }
.sources-list li:first-child { border-top: 0; }
.source-title { display: block; color: var(--text); font-size: 0.92rem; font-weight: 600; text-decoration: none; }
.source-title:hover { color: var(--brand); text-decoration: underline; }
.source-meta { margin-top: 2px; color: var(--muted); font-size: 0.78rem; }

/* ---------- How it works (disclosure) ---------- */
.how { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 6px; }
.how summary {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 2px;
  font-weight: 700; font-size: 0.95rem;
  cursor: pointer; list-style: none;
}
.how summary::-webkit-details-marker { display: none; }
.chev { width: 18px; height: 18px; color: var(--muted); transition: transform .2s ease; }
.how[open] .chev { transform: rotate(180deg); }
.how-body p { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }

/* ---------- Footer ---------- */
.foot { padding-top: 16px; margin-top: 10px; color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--line); }
.foot p { margin: 8px 0; }
.foot a { color: var(--brand); }

/* ---------- Cookie consent ---------- */
.consent {
  position: fixed; left: 12px; right: 12px; bottom: 12px;
  max-width: 536px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 40;
}
.consent p { margin: 0 0 12px; font-size: 0.87rem; color: var(--text); }
.consent a { color: var(--brand); }
.consent-actions { display: flex; gap: 10px; justify-content: flex-end; }

.btn { border: 0; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 700; cursor: pointer; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }

@media (min-width: 620px) {
  .app { padding-left: 24px; padding-right: 24px; }
  .hero { margin-left: -24px; margin-right: -24px; padding-left: 24px; padding-right: 24px; }
  .brand { font-size: 1.4rem; }
  .headline { font-size: 1.6rem; }
}
