:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --ink: #1b1a17;
  --muted: #6d675d;
  --line: #e3ddd2;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --mark: #9a6f1c;
  --up: #1d7a4f;
  --down: #b3392f;
  --serif: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --title: clamp(26px, 7vw, 38px);
  --body: 17px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141311; --surface: #1d1c19; --ink: #ece7de; --muted: #9b9488; --line: #34312c;
    --accent: #7cc4a8; --accent-ink: #0f1a16; --mark: #d7a94b; --up: #6fcf9b; --down: #f08a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141311; --surface: #1d1c19; --ink: #ece7de; --muted: #9b9488; --line: #34312c;
  --accent: #7cc4a8; --accent-ink: #0f1a16; --mark: #d7a94b; --up: #6fcf9b; --down: #f08a80;
  color-scheme: dark;
}
:root[data-size="large"] { --title: clamp(30px, 8.4vw, 44px); --body: 20px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
html { background: var(--bg); }
body {
  margin: 0; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* ---------- barra in alto ---------- */
.top {
  flex: none; z-index: 10;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}
.brand { display: flex; align-items: center; gap: 10px; padding-top: 8px; min-height: 48px; }
.logo { white-space: nowrap; font-family: var(--serif); font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.meta { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; color: var(--muted); text-align: right; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); margin-right: -8px;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { display: flex; gap: 4px; padding: 4px 0 10px; }
.progress[hidden], .progress:empty { display: none; }
.progress button {
  flex: 1; height: 4px; padding: 0; border: 0; border-radius: 2px; cursor: pointer;
  background: var(--line); position: relative; transition: background .2s;
}
.progress button::after { content: ""; position: absolute; inset: -10px 0; } /* area di tocco più grande */
.progress button.read { background: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.progress button.current { background: var(--accent); }

/* ---------- contenuto ---------- */
.view { flex: 1; min-height: 0; width: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.feed-mode .view { overflow: hidden; }

/* ---------- feed verticale, una schermata alla volta ---------- */
.feed {
  height: 100%; overflow-y: auto; overscroll-behavior: contain;
  scroll-snap-type: y mandatory; scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }
.slide {
  height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; position: relative;
  border-top: 1px solid var(--line);
}
.slide-inner {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; justify-content: center;
  padding-top: 20px; padding-bottom: 12px;
}
.slide-inner > * { flex: none; }

.next-hint {
  flex: none; align-self: center; display: flex; flex-direction: column-reverse; align-items: center; gap: 0;
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 12px; font-variant-numeric: tabular-nums; padding: 6px 24px 12px;
}
.next-hint .chev { font-size: 18px; line-height: 1; animation: nudge 1.8s ease-in-out infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

.kicker { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--mark); }
.story-head { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.source { font-weight: 700; color: var(--ink); text-transform: uppercase; letter-spacing: .06em; font-size: 12px; }
.lang { margin-left: auto; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.coverage { margin: 14px 0 0; font-size: 13px; color: var(--mark); font-weight: 600; }
.title {
  overflow-wrap: anywhere;
  font-family: var(--serif); font-weight: 700;
  font-size: var(--title); line-height: 1.15; letter-spacing: -0.015em;
  margin: 10px 0 16px; text-wrap: balance;
}
.summary { font-size: var(--body); line-height: 1.6; margin: 0 0 24px; color: var(--ink); opacity: .88; }
.actions { display: flex; gap: 10px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 600; font-size: 15px; border-radius: 999px; padding: 12px 18px; min-height: 48px;
  text-decoration: none; cursor: pointer; border: 1px solid var(--accent);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.actions .btn.primary { flex: 1; min-width: 0; }
.btn.ghost { background: none; color: var(--accent); }
.btn.round { width: 48px; padding: 0; flex: none; }
.btn.round[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.btn.wide { width: 100%; }
.btn svg { width: 20px; height: 20px; }

.also-btn {
  margin-top: 18px; align-self: flex-start; border: 0; background: none; padding: 8px 0; cursor: pointer;
  color: var(--muted); font-size: 14px; font-weight: 600; text-align: left;
}
.also { list-style: none; padding: 0; margin: 0 0 16px; }
.also li { border-top: 1px solid var(--line); }
.also a { display: block; padding: 14px 0; color: var(--ink); text-decoration: none; font-size: 16px; line-height: 1.4; }
.also b { display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }

/* ---------- mercati ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile-name { font-size: 12px; color: var(--muted); font-weight: 600; }
.tile-val { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-ch { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-ch.up { color: var(--up); }
.tile-ch.down { color: var(--down); }
.fine { font-size: 12px; color: var(--muted); margin: 14px 0 0; line-height: 1.45; }

/* ---------- fine ---------- */
.done .slide-inner { text-align: center; align-items: center; }
.done .check {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 18px;
  display: grid; place-items: center; font-size: 34px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
}
.done h2 { font-family: var(--serif); font-size: clamp(34px, 9vw, 52px); margin: 0 0 16px; letter-spacing: -0.02em; }
.done p { color: var(--muted); font-size: var(--body); line-height: 1.5; margin: 0 auto 8px; max-width: 30ch; }
.done-stats { display: flex; gap: 8px; justify-content: center; margin: 0 0 18px; width: 100%; max-width: 380px; }
.stat {
  flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.3; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 20px; }
.row.left { justify-content: flex-start; margin-top: 8px; }

/* ---------- pagine: salvati e tu ---------- */
.page { padding-top: 4px; padding-bottom: 32px; }
.page-title { font-family: var(--serif); font-size: 30px; margin: 8px 0 12px; letter-spacing: -0.015em; }
.item { padding: 16px 0; border-bottom: 1px solid var(--line); }
.item .t { display: block; margin-top: 6px; font-family: var(--serif); font-weight: 700; font-size: 20px; line-height: 1.25; color: var(--ink); text-decoration: none; }
.item-actions { display: flex; gap: 18px; margin-top: 6px; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 8px 0; cursor: pointer; font-weight: 600; }
.link-btn.danger { color: var(--down); }
.empty { text-align: center; color: var(--muted); padding-top: 64px; padding-bottom: 64px; line-height: 1.55; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 18px 16px; margin-bottom: 12px;
}
.card h2 { font-size: 17px; margin: 0 0 8px; }
.card p { color: var(--muted); font-size: 15px; line-height: 1.5; margin: 0 0 12px; }
.card .fine { margin: 14px 0 0; }
.streak { text-align: center; }
.flame { font-size: 40px; line-height: 1; }
.streak-n { display: block; font-size: 48px; line-height: 1.1; font-variant-numeric: tabular-nums; margin-top: 4px; }
.streak-l { color: var(--muted); font-size: 14px; }
.week-dots { display: flex; justify-content: space-between; margin-top: 16px; max-width: 320px; margin-inline: auto; }
.wd { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); font-weight: 600; }
.wd i { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: block; }
.wd.on i { background: var(--accent); border-color: var(--accent); }
.wd.today span { color: var(--ink); }
.stats { display: flex; gap: 8px; padding: 8px; }
.stats .stat { border: 0; background: none; }
.steps { margin: 0 0 14px; padding-left: 20px; line-height: 1.5; font-size: 15px; }
.steps li { margin-bottom: 8px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.setting > span { font-size: 15px; font-weight: 600; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 8px 12px; min-height: 36px; font-size: 14px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.colophon { font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center; margin: 20px 8px 0; }

/* ---------- barra delle sezioni in basso ---------- */
.tabbar {
  flex: none; display: flex; z-index: 10;
  background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; cursor: pointer; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; min-height: 54px; font-size: 11px; font-weight: 600; position: relative;
}
.tabbar button[aria-selected="true"] { color: var(--ink); }
.tabbar button[aria-selected="true"] svg { stroke-width: 2.3; }
.tabbar .dot { position: absolute; top: 8px; left: calc(50% + 9px); width: 7px; height: 7px; border-radius: 50%; background: var(--mark); }
.tabbar .dot[hidden] { display: none; }

/* ---------- foglio dal basso, avvisi, guida ---------- */
.sheet, .intro {
  position: fixed; inset: 0; z-index: 50;
  background: rgb(0 0 0 / .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden], .intro[hidden], .toast[hidden] { display: none; }
.sheet-box {
  width: 100%; max-width: 640px; max-height: 80dvh; overflow-y: auto;
  background: var(--surface); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 4px; text-transform: uppercase; letter-spacing: .06em; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: var(--bg); border-radius: 999px;
  padding: 10px 16px; font-size: 14px; font-weight: 600; max-width: calc(100% - 32px);
  box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}

.intro { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.intro-box {
  width: 100%; max-width: 480px; background: var(--surface); color: var(--ink);
  border-radius: 20px; padding: 24px 20px 20px; animation: up .2s ease-out;
}
.intro h2 { font-family: var(--serif); font-size: 26px; margin: 0 0 12px; }
.intro ol { margin: 0 0 12px; padding-left: 20px; line-height: 1.5; font-size: 16px; }
.intro li { margin-bottom: 8px; }
.intro p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 18px; }
.intro button {
  width: 100%; min-height: 50px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
}

@media (prefers-reduced-motion: reduce) {
  .next-hint .chev, .sheet-box, .intro-box, .icon-btn.spin svg { animation: none; }
}
