:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #17181c;
  --muted: #6b6f7a;
  --line: #e7e5df;
  --accent: #17181c;
  --good: #16a34a;
  --bad: #dc2626;
  --radius: 16px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --ink: #f2f3f5;
    --muted: #9aa0ad;
    --line: #272b33;
    --accent: #f2f3f5;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 14px; }

/* layout */
#app { min-height: 100dvh; }
main { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
nav#nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 10; }
nav#nav button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
nav#nav button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
nav#nav button.active { color: var(--ink); font-weight: 600; }
nav#nav button.active span { filter: none; opacity: 1; }
h2 { font-size: 22px; margin: 4px 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }

/* boutons / champs */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.login-card p { margin: 0; }

/* période */
.period { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; flex: 1; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.nav-arrows { display: flex; gap: 4px; }
.nav-arrows button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 18px; cursor: pointer; }
.nav-arrows button:disabled { opacity: .35; }
.range { color: var(--muted); font-size: 14px; margin: 0 0 12px; text-transform: capitalize; }

/* score */
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.score { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: relative; overflow: hidden; }
.score::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.score .who { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.score .num { font-size: 44px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.score .sub { color: var(--muted); font-size: 13px; }
.score.lead .who::after { content: "👑"; font-size: 14px; }
.balance { margin: 14px 0 6px; height: 14px; border-radius: 99px; overflow: hidden; display: flex; background: var(--line); }
.balance div { height: 100%; transition: width .5s ease; }
.verdict { text-align: center; font-weight: 600; margin: 6px 0 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.card canvas { width: 100% !important; }
.chart-wrap { position: relative; height: 230px; }

/* tâches */
.search { margin-bottom: 8px; }
.cat { margin-top: 18px; }
.cat h3 { margin-top: 0; }
.task { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.task:active { transform: scale(.99); }
.task .name { flex: 1; }
.pts { font-weight: 800; min-width: 44px; text-align: center; background: var(--bg); border-radius: 10px; padding: 6px 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pts.neg { color: var(--bad); }
.pts.pos { color: var(--good); }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 7px; margin-left: 6px; white-space: nowrap; }

/* fil */
.item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.dot { width: 34px; height: 34px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: 13px; }
.item .note { margin-top: 4px; font-size: 14px; }
.item img.thumb { margin-top: 8px; width: 96px; height: 96px; object-fit: cover; border-radius: 12px; cursor: zoom-in; display: block; }
.item .side { text-align: right; }
.item .undo { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 4px 0; cursor: pointer; text-decoration: underline; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

/* réglages */
.set-row { display: grid; grid-template-columns: 1fr 74px; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 8px; }
.set-row.off { opacity: .5; }
.set-row .opts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); align-items: center; }
.set-row .opts label { display: flex; align-items: center; gap: 6px; }
.set-row .opts input[type=checkbox] { width: auto; }
.set-row input { padding: 9px 10px; }
.stack { display: grid; gap: 10px; }
.change { font-size: 13px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--line); }

/* feuille modale */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px); max-width: 720px; margin: 0 auto; max-height: 90dvh; overflow: auto; animation: up .2s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet .big { font-size: 34px; font-weight: 800; margin: 6px 0 12px; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 22px; cursor: pointer; }
.stepper span { min-width: 32px; text-align: center; font-weight: 700; font-size: 20px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); border-radius: 99px; padding: 8px 14px; background: none; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.chip.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 15%, transparent); }
.photo-btn { display: flex; align-items: center; gap: 10px; }
.photo-btn img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.sheet .actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 8px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 40; display: grid; place-items: center; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; z-index: 50; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast button { background: none; border: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* tuiles de catégories */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 4px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 124px; padding: 14px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; color: var(--ink); font: inherit; cursor: pointer; text-align: center; }
.tile:active { transform: scale(.97); }
.tile .ico { font-size: 40px; line-height: 1.1; }
.tile .lbl { font-weight: 700; }
.tile .cnt { font-size: 12px; color: var(--muted); }
.tile.malus { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); background: color-mix(in srgb, var(--bad) 7%, var(--card)); }
.back { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 0; cursor: pointer; }
.cat-title { font-size: 20px; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 4px 0 10px; }
.token { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* profil */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.sw { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; background: var(--c); cursor: pointer; padding: 0; box-shadow: inset 0 0 0 2px var(--card); }
.sw.on { border-color: var(--ink); }
.sw.custom { display: grid; place-items: center; background: var(--bg); color: var(--muted); font-weight: 700; border: 2px dashed var(--line); position: relative; overflow: hidden; box-shadow: none; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer; }

/* tâche ponctuelle */
.tile.oneoff { grid-column: 1 / -1; min-height: 92px; border-style: dashed; background: color-mix(in srgb, var(--accent) 5%, var(--card)); }
.tile.oneoff .ico { font-size: 30px; }
.task.oneoff-link { border-style: dashed; color: var(--muted); }
