:root {
  --bg: #f7f6f2; --card: #fff; --text: #1d1d24; --muted: #75737d; --line: #e6e3da;
  --accent: #4a55a2; --accent-ink: #fff; --soft: #e9ebf7; --ok: #2e7d5b; --shadow: 0 2px 12px rgba(0,0,0,.08);
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14141a; --card: #1f1f27; --text: #eeeef4; --muted: #9c9aa6; --line: #33333d; --soft: #2a2d4a; --accent: #8c97e6; --accent-ink: #14141a; --ok: #6fcf9f; --shadow: none; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.page { max-width: 680px; margin: 0 auto; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 40px); }
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.topbar h1 { flex: 1; margin: 0; font-size: 1.5rem; line-height: 1.2; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 16px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: #c0392b; }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; box-shadow: var(--shadow); flex: none; }

.search { width: 100%; padding: 12px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); outline: none; }
.search:focus { border-color: var(--accent); }
.fgroup { margin-top: 12px; }
.fgroup > .label { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.fgroup .label button { border: 0; background: none; color: var(--accent); font-size: .8rem; font-weight: 600; cursor: pointer; text-transform: none; letter-spacing: 0; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .9rem; }
.chip small { color: var(--muted); margin-left: 2px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.on small { color: inherit; opacity: .8; }
.count { margin: 14px 0 0; color: var(--muted); font-size: .85rem; }

.cards { margin-top: 8px; display: grid; gap: 12px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; cursor: pointer; }
.card .top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.tag { background: var(--soft); border-radius: 999px; padding: 2px 10px; font-size: .8rem; }
.done-badge { margin-left: auto; color: var(--ok); font-weight: 700; font-size: .85rem; }
.card .name { font-weight: 700; margin-bottom: 2px; }
.card .consigne { margin: 0; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.card .actions { margin-top: 10px; display: flex; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 90dvh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(var(--safe-b) + 20px); max-width: 680px; margin: 0 auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; }
.sheet textarea { width: 100%; min-height: 220px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 10px; font: 13px/1.4 ui-monospace, Menlo, monospace; outline: none; resize: vertical; }
.sheet textarea:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row .btn { flex: 1; }
.msg { white-space: pre-wrap; font-size: .9rem; margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--soft); }
.msg.err { color: #c0392b; }
.menu { display: grid; gap: 8px; }
.menu .btn { text-align: left; border-radius: 14px; }

.detail .consigne { font-size: 1.2rem; line-height: 1.5; margin: 10px 0 16px; white-space: pre-wrap; }
.detail .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: var(--radius); padding: 8px 12px; box-shadow: var(--shadow); }
.stepper .val { font-weight: 700; font-size: 1.1rem; text-align: center; }
.stepper .val small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
.stepper .icon-btn { box-shadow: none; background: var(--soft); font-weight: 700; }
.dice-hint { margin: 0 0 8px; color: var(--muted); font-size: .9rem; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; z-index: 200; font-size: .9rem; display: flex; gap: 12px; align-items: center; white-space: nowrap; }
.toast button { border: 0; background: none; color: #aab4ff; font-weight: 700; cursor: pointer; padding: 0; }
.hint { color: var(--muted); font-size: .85rem; }
