:root {
  --day-blue: #dbe8fb; --day-blue-text: #2a64b8; --day-blue-strong: #3b82e0;
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f4f4f6;
  --text: #1c1c1e;
  --muted: #8a8a90;
  --line: #e4e4ea;
  --accent: #4fb18c;
  --accent-strong: #3e9c79;
  --accent-soft: #e2f3ec;
  --on-accent: #ffffff;
  --done-bg: #e3f5e8;
  --done-text: #3f7d55;
  --late: #e0474c;
  --late-bg: #fde9e9;
  --shadow: 0 6px 24px rgba(20, 20, 40, .07), 0 1px 3px rgba(20, 20, 40, .06);
  --shadow-strong: 0 10px 30px rgba(20, 20, 40, .18);
  --radius: 22px;
  --nav-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214; --card: #1c1d21; --card-2: #26272c; --text: #f1f1f3; --muted: #9a9aa2; --line: #2e2f35;
    --accent: #5cc49d; --accent-strong: #6fd3ad; --accent-soft: #1b3a2f; --done-bg: #1a3324; --done-text: #8fd6a6;
    --late: #ff6b6f; --late-bg: #3a1f22; --shadow: 0 6px 24px rgba(0,0,0,.35); --shadow-strong: 0 10px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214; --card: #1c1d21; --card-2: #26272c; --text: #f1f1f3; --muted: #9a9aa2; --line: #2e2f35;
  --accent: #5cc49d; --accent-strong: #6fd3ad; --accent-soft: #1b3a2f; --done-bg: #1a3324; --done-text: #8fd6a6;
  --late: #ff6b6f; --late-bg: #3a1f22; --shadow: 0 6px 24px rgba(0,0,0,.35); --shadow-strong: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Shell ---------- */
#app { height: 100dvh; }
.shell { height: 100%; position: relative; }
.view {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 8px) 16px calc(var(--nav-h) + var(--safe-b) + 40px);
}
.view-inner { max-width: 760px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); z-index: 20;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.tabs {
  flex: 1; display: flex; pointer-events: auto; height: var(--nav-h); padding: 6px;
  background: color-mix(in srgb, var(--card) 86%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 40px; box-shadow: var(--shadow);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 32px; font-size: 11.5px; font-weight: 500; color: var(--text); min-width: 0; text-decoration: none;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { color: var(--accent); background: var(--card-2); }
.fab {
  pointer-events: auto; width: 68px; height: 68px; flex: none; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-strong);
  display: grid; place-items: center; transition: transform .15s;
}
.fab:active { transform: scale(.93); }
.fab svg { width: 32px; height: 32px; }
.fab-label { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .view { position: relative; inset: auto; height: 100dvh; padding: 24px 32px 48px; }
  .view-inner { max-width: 1100px; }
  .tabbar {
    position: static; flex-direction: column-reverse; justify-content: flex-end; align-items: stretch;
    padding: 24px 16px; gap: 20px; border-right: 1px solid var(--line); background: var(--card); pointer-events: auto;
  }
  .tabs { flex: none; flex-direction: column; height: auto; border: 0; box-shadow: none; background: none; padding: 0; gap: 4px; border-radius: 0; }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 14px; font-size: 15px; border-radius: 12px; }
  .tab svg { width: 22px; height: 22px; }
  .tab:hover { background: var(--card-2); }
  .fab { width: auto; height: 46px; border-radius: 14px; gap: 8px; display: flex; justify-content: center; font-weight: 600; }
  .fab svg { width: 22px; height: 22px; }
  .fab-label { display: inline; }
  .brand { display: flex !important; }
}
.brand { display: none; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; padding: 0 6px; }
.big-check { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: var(--shadow-strong); }
.big-check svg { width: 34px; height: 34px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }

/* ---------- Common header ---------- */
.topbar {
  position: sticky; top: calc(-1 * var(--safe-t) - 8px); z-index: 5; margin: 0 -16px 8px; padding: calc(var(--safe-t) + 8px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: flex; align-items: center; gap: 10px;
}
@media (min-width: 900px) { .topbar { top: -24px; margin: -24px -32px 12px; padding: 24px 32px 12px; } }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; text-align: center; font-weight: 700; text-transform: capitalize; }
.topbar .spacer { flex: 1; }
.round-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--card); border: 1px solid var(--line); color: var(--accent);
}
.round-btn svg { width: 20px; height: 20px; }
.round-btn.filled { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.round-btn:disabled { opacity: .35; cursor: default; }
.round-btn.sm { width: 36px; height: 36px; }

.segmented { display: flex; background: var(--card-2); border-radius: 12px; padding: 3px; gap: 2px; flex: 1; max-width: 360px; margin: 0 auto; }
.segmented button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; font-size: 20px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2, .card-head h3 { flex: 1; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 24px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px;
}
.btn.block { width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--accent); }
.btn.danger { background: var(--late-bg); color: var(--late); }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.link { color: var(--accent); font-weight: 500; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.input, .textarea, .select {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card-2);
  outline: none; font-size: 16px;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 20px; background: var(--card-2); font-size: 14px; font-weight: 500; border: 1px solid transparent; }
.chip.active { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--line); }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }
.swatch.none { background: repeating-linear-gradient(45deg, var(--card-2), var(--card-2) 4px, var(--line) 4px, var(--line) 8px); }

/* ---------- Tasks : week ---------- */
.day-block { margin-bottom: 14px; scroll-margin-top: 70px; }
.day-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px 6px 6px; font-weight: 600; font-size: 15px;
}
.day-head .label { flex: 1; }
.day-head .add { width: 34px; height: 34px; border-radius: 50%; color: var(--accent); display: grid; place-items: center; }
.day-head .add svg { width: 20px; height: 20px; }
.day-block .day-head .label { color: var(--day-blue-text); }
.day-block.future .day-head .label { color: var(--muted); }
.day-block.today .day-head .label { color: var(--day-blue-strong); }
.day-block.today .day-head .label::after {
  content: "Aujourd'hui"; margin-left: 8px; font-size: 11px; font-weight: 700; text-transform: uppercase;
  background: var(--day-blue-strong); color: #fff; padding: 2px 7px; border-radius: 8px; vertical-align: 2px;
}

.task-list { background: var(--card); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.task {
  display: flex; align-items: center; min-height: 50px; border-bottom: 1px solid var(--line); position: relative;
  transition: background .2s;
}
.task:last-child { border-bottom: 0; }
.task .bar { width: 5px; align-self: stretch; flex: none; }
.task .title { flex: 1; min-width: 0; padding: 12px 12px; cursor: pointer; overflow-wrap: anywhere; }
.task .title small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.task .check {
  width: 54px; align-self: stretch; display: grid; place-items: center; flex: none;
}
.task .check i {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; transition: all .15s;
}
.task .check svg { width: 16px; height: 16px; opacity: 0; color: #fff; }
.task.done { background: var(--done-bg); }
.task.done .title { color: var(--done-text); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--done-text) 50%, transparent); }
.task.done .check i { background: #4caf6e; border-color: #4caf6e; }
.task.done .check svg { opacity: 1; }
.task.late { background: var(--late-bg); }
.task.late .check i { border-color: var(--late); background: color-mix(in srgb, var(--late) 15%, transparent); }
.task.late .title small.late-tag { color: var(--late); }
.task.new .title { padding: 6px 8px; }
.task.new input { width: 100%; border: 0; background: none; outline: none; padding: 8px 4px; font-size: 16px; }
.task.placeholder .title { color: var(--muted); font-size: 14.5px; }
.list-loader { height: 1px; }
.jump-today {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 24px); z-index: 15;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 20px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-strong);
}
@media (min-width: 900px) { .jump-today { bottom: 28px; left: calc(50% + 116px); } }

@media (min-width: 900px) {
  .week-grid .day-block { display: grid; grid-template-columns: 210px 1fr; gap: 18px; align-items: start; }
  .week-grid .day-head { padding-top: 14px; }
}

/* ---------- Tasks : month ---------- */
.month-block { margin-bottom: 26px; scroll-margin-top: 64px; }
.month-title { font-size: 20px; font-weight: 700; margin: 6px 4px 10px; text-transform: capitalize; }
.month-block.current .month-title { color: var(--accent-strong); }
.dow { display: grid; grid-template-columns: repeat(7, 1fr); font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 4px; }
.mgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.mcell { min-height: 84px; border-bottom: 1px solid var(--line); padding: 4px 2px; cursor: pointer; min-width: 0; }
.mcell.empty { cursor: default; }
.mcell .num { font-size: 13px; font-weight: 600; text-align: center; width: 24px; height: 24px; line-height: 24px; margin: 0 auto 3px; border-radius: 50%; }
.mcell.today .num { background: var(--late); color: #fff; }
.mcell.past .num { color: var(--muted); }
.mchip {
  display: block; font-size: 10px; line-height: 1.25; padding: 1px 3px; margin-bottom: 2px; border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--card-2); border-left: 3px solid var(--muted);
}
.mchip.done { opacity: .5; text-decoration: line-through; }
.mmore { font-size: 10px; color: var(--muted); padding-left: 3px; }
@media (min-width: 900px) {
  .mcell { min-height: 120px; padding: 6px 4px; }
  .mchip { font-size: 12px; padding: 2px 5px; }
  .mcell:hover { background: var(--card-2); }
}

/* ---------- Tasks : list ---------- */
.list-section h4 { margin: 18px 6px 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.list-section h4::first-letter { text-transform: uppercase; }
.list-section.overdue h4 { color: var(--late); }
.empty-state { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty-state .big { font-size: 44px; margin-bottom: 8px; }

/* ---------- Mood ---------- */
.hello {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left; background: var(--accent); color: var(--on-accent);
  border-radius: 32px; padding: 14px 20px; font-weight: 700; font-size: 18px; box-shadow: var(--shadow); margin-bottom: 10px;
}
.hello .plus { width: 54px; height: 54px; border: 2px solid currentColor; border-radius: 50%; display: grid; place-items: center; flex: none; }
.hello .plus svg { width: 28px; height: 28px; }
.missing { text-align: center; color: var(--muted); margin: 6px 0 16px; font-size: 15px; }
.missing button { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.entry { display: flex; gap: 14px; align-items: flex-start; cursor: pointer; }
.entry .face { flex: none; }
.entry .body { flex: 1; min-width: 0; }
.entry .date { text-transform: uppercase; color: var(--muted); font-size: 14px; letter-spacing: .02em; }
.entry .mood { font-size: 26px; font-weight: 700; line-height: 1.15; }
.entry .mood small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.entry .acts { margin-top: 6px; font-size: 15px; color: var(--text); line-height: 1.7; }
.entry .acts span { white-space: nowrap; }
.entry .acts .sep { color: var(--line); margin: 0 4px; }
.entry .note { margin-top: 8px; color: var(--muted); font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry .more { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--line); color: var(--muted); display: grid; place-items: center; flex: none; }
.entry .more svg { width: 18px; height: 18px; }
.search-bar { margin-bottom: 14px; }
.mood-layout { display: block; }
@media (min-width: 1100px) {
  .mood-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
  .mood-side { position: sticky; top: 80px; }
}
@media (max-width: 1099px) { .mood-side { display: none; } }

/* ---------- Sheet / modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 20, .38); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease-out;
}
.sheet {
  background: var(--card); width: 100%; max-height: calc(100dvh - var(--safe-t) - 24px); border-radius: 26px 26px 0 0; overflow: hidden;
  display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2, .9, .3, 1); box-shadow: var(--shadow-strong);
}
.sheet.full { height: calc(100dvh - var(--safe-t) - 12px); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; text-align: center; }
.sheet-body { padding: 8px 18px calc(24px + var(--safe-b)); overflow-y: auto; flex: 1; }
.sheet-foot { padding: 10px 18px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); }
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { width: 580px; border-radius: 24px; max-height: 88vh; }
  .sheet.full { height: 88vh; }
  .sheet.narrow { width: 440px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.menu { padding: 6px 8px calc(10px + var(--safe-b)); }
.menu button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 14px; border-radius: 14px; font-size: 17px; text-align: left; }
.menu button:hover { background: var(--card-2); }
.menu button.danger { color: var(--late); }
.menu svg { width: 22px; height: 22px; }

#toast-root { position: fixed; left: 0; right: 0; top: calc(var(--safe-t) + 12px); z-index: 100; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 16px; font-size: 15px; box-shadow: var(--shadow-strong); animation: fade .2s; max-width: 90vw; }
.toast.error { background: var(--late); color: #fff; }

/* ---------- Entry editor ---------- */
.ask { text-align: center; font-size: 28px; font-weight: 800; margin: 8px 0 10px; }
.when-link { display: flex; justify-content: center; gap: 6px; align-items: center; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; margin: 0 auto 30px; font-size: 17px; }
.when-link svg { width: 20px; height: 20px; }
.faces { display: flex; justify-content: space-between; gap: 4px; max-width: 460px; margin: 0 auto; }
.faces button { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 16px; flex: 1; transition: transform .12s; }
.faces button:active { transform: scale(.92); }
.faces button.sel svg { filter: drop-shadow(0 0 0 currentColor); outline: 3px solid currentColor; outline-offset: 3px; border-radius: 50%; }
.day-choice { display: grid; gap: 12px; max-width: 420px; margin: 20px auto; }
.day-choice .btn { min-height: 58px; font-size: 18px; }
.step-center { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding-bottom: 60px; }
.group-card { border: 1px solid var(--line); border-radius: 20px; padding: 14px 12px 6px; margin-bottom: 12px; }
.group-card .gh { display: flex; align-items: center; gap: 8px; padding: 0 4px 10px; }
.group-card .gh h3 { flex: 1; margin: 0; font-size: 17px; font-weight: 500; }
.group-card.collapsed .acts-grid { display: none; }
.group-card.collapsed .gh .chev { transform: rotate(180deg); }
.acts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px 2px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0 8px; font-size: 13.5px; text-align: center; line-height: 1.15; min-width: 0; }
.act .ic {
  width: 54px; height: 54px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: 26px;
  transition: all .12s;
}
.act.sel .ic { background: var(--sel, var(--accent)); border-color: var(--sel, var(--accent)); transform: scale(1.04); }
.act span { overflow-wrap: anywhere; max-width: 100%; padding: 0 2px; }
.act.add .ic { color: var(--accent); border-style: dashed; font-size: 22px; }
.editor-top { display: flex; align-items: center; gap: 10px; padding: 14px 14px 6px; }
.back-face { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 30px; padding: 5px 14px 5px 8px; color: var(--accent); }
.back-face svg.chev { width: 20px; height: 20px; }
.section-label { display: flex; align-items: center; gap: 10px; font-size: 17px; margin: 18px 0 8px; }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.emoji-grid button { font-size: 26px; height: 46px; border-radius: 12px; }
.emoji-grid button.active { background: var(--accent-soft); outline: 2px solid var(--accent); }
.emoji-cat { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.icon-preview { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; font-size: 34px; flex: none; }

/* ---------- Stats ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow); }
.tile .v { font-size: 26px; font-weight: 800; }
.tile .k { font-size: 13px; color: var(--muted); }
@media (min-width: 700px) { .stat-tiles { grid-template-columns: repeat(4, 1fr); } }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px 4px; text-align: center; }
.cal .h { font-size: 13px; color: var(--muted); padding-bottom: 4px; }
.cal .d { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 14px; cursor: pointer; min-width: 0; }
.cal .d .c { width: 100%; max-width: 46px; aspect-ratio: 1; border-radius: 50%; background: var(--card-2); display: grid; place-items: center; color: var(--muted); }
.cal .d .c svg { width: 100%; height: 100%; }
.cal .d .c.plus svg { width: 45%; height: 45%; }
.cal .d.today .c { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent); }
.cal .d.today { color: var(--accent); font-weight: 700; }
.cal .d.other { opacity: .35; }
.cal .d.future { cursor: default; }
.counter-wrap { display: flex; flex-direction: column; align-items: center; }
.counter-faces { display: flex; justify-content: space-around; width: 100%; margin-top: 10px; }
.counter-faces button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; padding: 4px; border-radius: 14px; }
.counter-faces button.sel { background: var(--card-2); }
.counter-faces .badge {
  position: absolute; top: -6px; right: -4px; min-width: 24px; height: 24px; border-radius: 12px; color: #fff;
  font-size: 13px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--card); padding: 0 4px;
}
.bars .bar-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14.5px; }
.bars .bar-row .lbl { width: 140px; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars .bar-row .track { flex: 1; height: 12px; border-radius: 6px; background: var(--card-2); overflow: hidden; }
.bars .bar-row .fill { height: 100%; border-radius: 6px; }
.bars .bar-row .n { width: 30px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.goal { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.goal:first-of-type { border-top: 0; }
.goal .ring { flex: none; }
.goal .gbody { flex: 1; min-width: 0; }
.goal .gtitle { font-weight: 600; }
.goal .gsub { font-size: 13px; color: var(--muted); }
.goal .hist { display: flex; gap: 4px; margin-top: 6px; }
.goal .hist i { width: 14px; height: 14px; border-radius: 4px; background: var(--card-2); }
.goal .hist i.ok { background: var(--accent); }
.pixels { display: grid; grid-template-columns: 30px repeat(31, minmax(0, 1fr)); gap: 2px; font-size: 9px; color: var(--muted); }
.pixels span { overflow: hidden; white-space: nowrap; }
.pixels i { aspect-ratio: 1; border-radius: 3px; background: var(--card-2); }
.pixels i.na { background: transparent; }
.stats-grid { display: block; }
@media (min-width: 1100px) {
  .stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }
  .stats-grid .span2 { grid-column: span 2; }
}
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Settings ---------- */
.set-list { background: var(--card); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); margin-bottom: 8px; }
.set-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); min-height: 54px; }
.set-item:last-child { border-bottom: 0; }
.set-item .grow { flex: 1; min-width: 0; }
.set-item small { display: block; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-item .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; background: var(--card-2); flex: none; }
.set-title { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 22px 12px 8px; letter-spacing: .04em; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--card-2); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.danger { color: var(--late); }
.color-input { width: 44px; height: 36px; border: 0; padding: 0; background: none; border-radius: 8px; cursor: pointer; }
.settings-grid { display: block; }
@media (min-width: 1100px) { .settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; align-items: start; } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 380px; }
.login .logo { width: 84px; height: 84px; margin: 0 auto 14px; border-radius: 22px; display: block; box-shadow: var(--shadow); }
.login h1 { text-align: center; margin: 0 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 28px; }
.login .err { color: var(--late); text-align: center; min-height: 22px; margin: 4px 0 8px; font-size: 14.5px; }

/* ---------- Tasks : desktop spreadsheet layout (month & week) ---------- */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --day-blue: #1d3150; --day-blue-text: #93bdf5; --day-blue-strong: #3f86e6; } }
:root[data-theme="dark"] { --day-blue: #1d3150; --day-blue-text: #93bdf5; --day-blue-strong: #3f86e6; }
.sheet-month {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; margin-bottom: 28px;
  border: 1px solid var(--line);
}
.sheet-title { text-align: center; font-size: 20px; font-weight: 600; padding: 14px 0 12px; }
.sheet-month.current .sheet-title { color: var(--accent-strong); }
.sg-dow, .sg-nums, .sg-body { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.sg-dow div { text-align: center; font-weight: 700; padding: 8px 0; border-top: 1px solid var(--line); border-bottom: 2px solid var(--text); border-right: 1px solid var(--line); }
.sg-dow div:last-child { border-right: 0; }
.snum {
  text-align: center; font-weight: 700; font-size: 14.5px; padding: 7px 4px; background: var(--accent-soft); color: var(--accent-strong);
  border-right: 1px solid var(--line); cursor: pointer; border-bottom: 1px solid var(--line);
}
.snum:last-child, .scol:last-child { border-right: 0; }
.snum:hover { filter: brightness(.97); }
/* Day bands : blue for today and past days, grey for future days */
.snum.past { background: var(--day-blue); color: var(--day-blue-text); }
.snum.today { background: var(--day-blue-strong); color: #fff; }
.snum.future { background: var(--card-2); color: var(--muted); }
.snum.out, .scol.out .scell { background: var(--card-2); color: transparent; cursor: default; }
.scol { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.scol.today { background: color-mix(in srgb, var(--day-blue-strong) 5%, var(--card)); }
.sheet-week + .sheet-week .sg-nums { border-top: 1px solid var(--line); }
.scell {
  min-height: 32px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 4px 22px; font-size: 14px; line-height: 1.25; position: relative; overflow-wrap: anywhere;
}
.scol .scell:last-child { border-bottom: 0; }
.scell.empty-cell { cursor: text; }
.scell.empty-cell:hover { background: var(--card-2); }
.scell.empty-cell:hover::after { content: "+"; color: var(--muted); font-size: 16px; }
.scell.editing { background: var(--card); box-shadow: inset 0 0 0 2px var(--accent); }
.scell.editing::after { content: none !important; }
.scell input { width: 100%; border: 0; background: none; outline: none; text-align: center; font-size: 14px; padding: 0; }
.scell.task-cell { cursor: pointer; transition: background .15s; }
.scell.task-cell:hover { filter: brightness(.97); }
.scell.task-cell.tinted { background: color-mix(in srgb, var(--tc) 24%, var(--card)); }
.scell.task-cell.done { background: var(--done-bg); color: var(--done-text); }
.scell.task-cell.late { background: var(--late-bg); color: var(--late); }
.scell .edit {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center; color: var(--muted); opacity: 0; background: var(--card);
}
.scell .edit svg { width: 13px; height: 13px; }
.scell:hover .edit { opacity: 1; }
.sheet-nav { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.sheet-nav-label { font-size: 20px; font-weight: 700; flex: 1; text-align: center; }
/* Desktop week view : roomier grid */
.sheet-single .snum { padding: 14px 6px; font-size: 16px; }
.sheet-single .scell { min-height: 46px; font-size: 15px; padding: 6px 24px; }
.sheet-single .scell input { font-size: 15px; }
@media (min-width: 900px) { .view-inner.sheet-mode { max-width: 1600px; } }

/* ---------- Metrics (numeric habits) ---------- */
.metrics { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 10px; }
.metric-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 16px; border: 1.5px solid var(--line);
  transition: border-color .15s, background .15s;
}
.metric-row.set { border-color: var(--sel, var(--accent)); background: color-mix(in srgb, var(--sel, var(--accent)) 12%, var(--card)); }
.metric-row .ic { font-size: 22px; width: 32px; text-align: center; flex: none; }
.metric-row .mname { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-row .input { width: 78px; padding: 9px 8px; text-align: center; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-row .unit { width: 26px; color: var(--muted); font-size: 14px; flex: none; }
.metric-row .round-btn { font-size: 20px; font-weight: 600; }

/* ---------- Modal scroll lock (iOS scroll chaining) ---------- */
.modal-open, .modal-open body { overflow: hidden; }
.modal-open .view { overflow: hidden; touch-action: none; }
.backdrop { overscroll-behavior: contain; touch-action: none; }
.sheet { touch-action: pan-y; }
.sheet-body, .modal-scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ---------- Pixels : month grid ---------- */
.pix-sub { font-size: 14px; font-weight: 700; margin: 6px 0 8px; text-transform: capitalize; }
.mpix { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; max-width: 420px; margin-bottom: 18px; }
.mpix .h { font-size: 11px; color: var(--muted); text-align: center; }
.mpix i {
  aspect-ratio: 1; border-radius: 7px; background: var(--card-2); font-style: normal; font-size: 11px;
  display: grid; place-items: center; color: var(--muted);
}
.mpix i.on { color: rgba(255, 255, 255, .92); font-weight: 600; }
.mpix i.na { background: transparent; }
.legend i:not([style]) { background: var(--card-2); }

/* ---------- Metrics card figures ---------- */
.mtiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; text-align: center; }
.mtile { background: var(--card-2); border-radius: 12px; padding: 8px 4px; min-width: 0; }
.mtile .v { font-weight: 800; font-size: 14.5px; line-height: 1.2; overflow-wrap: anywhere; }
.mtile .k { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Sheet keyboard cursor ---------- */
.scell[tabindex]:focus { outline: 2px solid var(--day-blue-strong); outline-offset: -2px; position: relative; z-index: 1; }
.scell[tabindex]:focus .edit { opacity: 1; }
.scell.empty-cell:focus::after { content: "+"; color: var(--muted); font-size: 16px; }
