:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1a1f2b;
  --muted: #6b7280;
  --border: #e3e7ef;
  --primary: #4f7cff;
  --primary-ink: #ffffff;
  --ok: #22a06b;
  --warn: #e0a800;
  --danger: #e0574b;
  --shadow: 0 1px 3px rgba(20,30,60,.08), 0 6px 20px rgba(20,30,60,.05);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171f;
    --card: #1e232e;
    --text: #eef1f6;
    --muted: #9aa3b2;
    --border: #2c3440;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* layout */
.wrap { max-width: 640px; margin: 0 auto; padding: 16px; padding-block: 16px; }
header.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
}
header.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; }
header.topbar .who { font-size: .85rem; color: var(--muted); }

/* tab bar */
nav.tabs {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; border: 0; background: none; color: var(--muted);
  padding: 10px 4px 12px; font-size: .72rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
nav.tabs button .ic { font-size: 1.35rem; line-height: 1; }
nav.tabs button.active { color: var(--primary); font-weight: 600; }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.chore {
  display: flex; align-items: center; gap: 12px;
}
.chore .body { flex: 1; min-width: 0; }
.chore .name { font-weight: 600; }
.chore.done .name { text-decoration: line-through; color: var(--muted); }
.chore.free { border-style: dashed; }
.chore.late { border-left: 4px solid var(--danger); }
.meta { font-size: .8rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 3px; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 9px; font-size: .75rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* buttons */
button.btn {
  border: 0; border-radius: 10px; padding: 10px 14px; font-size: 15px;
  font-weight: 600; cursor: pointer; background: var(--primary); color: var(--primary-ink);
}
button.btn.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
button.btn.ok { background: var(--ok); }
button.btn.sm { padding: 7px 11px; font-size: 14px; }
button.btn.icon { padding: 8px 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* forms — font-size >=16px per evitare lo zoom di iOS */
label { display: block; font-size: .82rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font-size: 16px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text);
}
input[type=checkbox] { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* login */
.userpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px,1fr)); gap: 12px; }
.avatar {
  aspect-ratio: 1; border-radius: 16px; border: 2px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; background: var(--card); gap: 6px; padding: 8px;
}
.avatar .circle {
  width: 46px; height: 46px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; font-weight: 700;
}
.avatar .nm { font-size: .85rem; font-weight: 600; }

/* balance bars */
.bal-row { margin: 10px 0; }
.bal-head { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.bar { height: 12px; border-radius: 999px; background: var(--bg); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; }

/* timer */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: .95; }
h2.sec { font-size: 1rem; margin: 18px 4px 8px; }
