:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --text: #22252a;
  --muted: #6b7078;
  --line: #e4e0d8;
  --track: #ece8e0;
  --a: #2a9d8f;
  --b: #e76f51;
  --radius: 14px;
  color-scheme: light;
}

/* Sombre : thème choisi, ou thème système si aucun choix */
:root[data-theme="dark"] {
  --bg: #15171a;
  --card: #1f2226;
  --text: #eceae6;
  --muted: #9a9fa6;
  --line: #2f3338;
  --track: #2b2f34;
  --a: #3bb8a8;
  --b: #f08466;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --card: #1f2226;
    --text: #eceae6;
    --muted: #9a9fa6;
    --line: #2f3338;
    --track: #2b2f34;
    --a: #3bb8a8;
    --b: #f08466;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }

h1 { font-size: 1.6rem; margin: 8px 0 4px; }
h2 { font-size: 1.05rem; margin: 24px 0 10px; }
.card h2 { margin-top: 0; }

.center { text-align: center; padding-top: 12vh; }
.center .card { max-width: 340px; margin: 16px auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.stack { display: grid; gap: 10px; }
.stack > * { min-width: 0; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

input, button { font: inherit; color: inherit; }

input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

button {
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  cursor: pointer;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }

button.link {
  background: none;
  color: var(--muted);
  padding: 4px 6px;
  font-weight: 500;
  text-decoration: underline;
}

.emoji-input { flex: 0 0 56px !important; text-align: center; }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.error { color: var(--b); min-height: 1.2em; margin: 0; }

header { position: relative; }
header .me { margin: 0; color: var(--muted); }
.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 6px 10px;
  font-weight: 500;
}

/* Choix de la personne */
.pick { display: grid; gap: 12px; max-width: 320px; margin: 20px auto; }
.pick button { padding: 18px; font-size: 1.15rem; color: #fff; }

/* Onglets de période */
.tabs { display: flex; gap: 6px; margin: 16px 0; }
.tabs button {
  flex: 1;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--line);
  font-weight: 500;
  padding: 8px 6px;
}
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.section-head h2 { margin-bottom: 10px; }

/* Barre de progression à deux */
.versus .names {
  display: flex;
  justify-content: space-between;
  font-size: .9rem;
  margin-bottom: 4px;
}
.versus .names span:first-child { color: var(--a); font-weight: 600; }
.versus .names span:last-child { color: var(--b); font-weight: 600; }

.bar {
  display: flex;
  height: 14px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--track);
}
.bar div { transition: flex-grow .35s ease; }
.bar .seg-a { background: var(--a); }
.bar .seg-b { background: var(--b); }
.score .bar { height: 20px; }

/* Tâches */
.tasks { display: grid; gap: 10px; }
.task-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.task-top .emoji { font-size: 1.4rem; }
.task-top .name { flex: 1; font-weight: 600; }
.task-top .delete { background: none; color: var(--b); padding: 2px 8px; font-size: 1.1rem; }
.task-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.task-actions .done { flex: 1; color: #fff; }
.task-actions .amount {
  padding: 10px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* Historique */
.recent { list-style: none; margin: 0; padding: 6px 14px; }
.recent li { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.recent li:last-child { border-bottom: 0; }
.recent .when { color: var(--muted); float: right; }
.recent .remove { float: right; background: none; color: var(--muted); padding: 0 0 0 10px; font-weight: 400; }
.recent .empty { color: var(--muted); }

/* Courses */
.shopping { list-style: none; margin: 12px 0 4px; padding: 0; }
.shopping li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.shopping li:last-child { border-bottom: 0; }
.shopping label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.shopping input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--a); }
.shopping .done span { text-decoration: line-through; color: var(--muted); }
.shopping .who { font-size: .8rem; color: var(--muted); }
.shopping .remove { background: none; color: var(--muted); padding: 2px 8px; }
.shopping .empty { color: var(--muted); border: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100% - 32px);
}

/* Onglets de vue (Tâches / Historique) */
.views { display: flex; gap: 4px; margin: 16px 0 0; border-bottom: 1px solid var(--line); }
.views button {
  background: none;
  color: var(--muted);
  border-radius: 0;
  border-bottom: 3px solid transparent;
  padding: 10px 14px;
}
.views button.active { color: var(--text); border-bottom-color: var(--text); }
h3 { font-size: .95rem; margin: 16px 0 6px; }

/* Récompenses et gages */
.balance { margin: 0 0 10px; }
.rewards-list, .gages { list-style: none; margin: 0; padding: 0; }
.rewards-list li, .gages li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.rewards-list li:last-child, .gages li:last-child { border-bottom: 0; }
.reward-name { flex: 1; }
.rewards-list .cost { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.rewards-list .claim { padding: 6px 12px; }
.rewards-list .empty, .gages .empty { color: var(--muted); }
.rewards #add-reward { margin-top: 10px; }
.cost-input { flex: 0 0 72px !important; }
.gages label { flex: 1; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.gages input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--a); flex: none; }
.gages .paid label > span { color: var(--muted); text-decoration: line-through; }
.gages .who { font-size: .8rem; color: var(--muted); }
.remove { background: none; color: var(--muted); padding: 2px 8px; font-weight: 400; }

/* Histogramme mensuel */
.legend { display: flex; gap: 16px; margin-bottom: 12px; font-size: .9rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.legend-item .swatch { margin-right: 0; }
.plot { position: relative; height: 200px; margin: 0 0 26px 28px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.gridline span {
  position: absolute;
  left: -28px;
  top: -.6em;
  width: 22px;
  text-align: right;
  font-size: .72rem;
  color: var(--muted);
}
.cols { position: absolute; inset: 0; display: flex; }
.col { flex: 1; position: relative; display: flex; flex-direction: column; justify-content: flex-end; cursor: default; outline: none; }
.col:hover, .col:focus { background: color-mix(in srgb, var(--text) 5%, transparent); border-radius: 6px 6px 0 0; }
.bars { height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.vbar { width: min(14px, 30%); border-radius: 4px 4px 0 0; min-height: 0; transition: height .3s ease; }
.xlabel {
  position: absolute;
  bottom: -22px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
}
.tooltip {
  position: absolute;
  z-index: 10;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: .85rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / .15);
  pointer-events: none;
  white-space: nowrap;
}

/* Détail par mois */
.months { display: grid; gap: 10px; }
.month summary { cursor: pointer; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.month-name { font-weight: 600; }
.month-totals { font-size: .9rem; }
.month table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .9rem; }
.month th, .month td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.month th { color: var(--muted); font-weight: 500; }
.month .num { text-align: right; font-variant-numeric: tabular-nums; }
.month .gages { margin-top: 8px; font-size: .9rem; }
.month .gages li { display: block; }
