:root {
  --bg: #f5f5fa;
  --card: #ffffff;
  --text: #1c1c28;
  --muted: #6b6b80;
  --border: #e6e6ef;
  --accent: #6457f0;
  --accent-2: #8b5cf6;
  --accent-soft: rgba(100, 87, 240, 0.12);
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(20, 20, 50, 0.05), 0 4px 16px rgba(20, 20, 50, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121218;
    --card: #1c1c25;
    --text: #ececf3;
    --muted: #9a9ab0;
    --border: #2b2b38;
    --accent: #8b80ff;
    --accent-2: #a78bfa;
    --accent-soft: rgba(139, 128, 255, 0.16);
    --danger: #ff6b6f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
h1 { margin: 0; font-size: 1.75rem; letter-spacing: -0.02em; }
h2 { margin: 0 0 4px; font-size: 1.2rem; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }
.error { color: var(--danger); margin: 0; font-size: 0.9rem; }
.error:empty { display: none; }

.btn {
  height: 46px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-weight: 600;
}
.btn.primary { border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn:active { transform: scale(0.98); }

input[type="password"], input[type="text"] {
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- Connexion ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 24px;
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-icon { align-self: center; border-radius: 18px; }

/* ---------- Appli ---------- */
.app {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.head .muted::first-letter { text-transform: uppercase; }
.head-right { position: relative; display: flex; align-items: center; gap: 8px; }
.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(229, 72, 77, 0.12);
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  fill: var(--muted);
}
.icon-btn:hover { background: var(--accent-soft); }
.menu {
  position: absolute;
  top: 48px;
  right: 0;
  z-index: 10;
  min-width: 240px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.menu button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
}
.menu button:hover { background: var(--accent-soft); }

.add { display: flex; gap: 10px; margin-bottom: 18px; }
.add input { flex: 1; box-shadow: var(--shadow); border-color: transparent; }
.add input:focus { border-color: var(--accent); }
.add-btn {
  flex: none;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: var(--shadow);
}
.add-btn:active { transform: scale(0.95); }

.progress { display: flex; align-items: center; gap: 12px; margin: 0 2px 14px; font-size: 0.85rem; }
.progress-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
#progress-fill { height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.3s; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 10px 14px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow);
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }

.check {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.check:hover { border-color: var(--accent); }
.check svg { opacity: 0; transform: scale(0.6); transition: opacity 0.15s, transform 0.15s; }
.item.done .check { border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.item.done .check svg { opacity: 1; transform: none; }

.text { flex: 1; min-width: 0; padding: 6px 0; overflow-wrap: anywhere; cursor: text; }
.item.done .text { color: var(--muted); text-decoration: line-through; }
.edit { height: 38px !important; padding: 0 10px !important; }

.del {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  opacity: 0.55;
}
.del:hover { opacity: 1; color: var(--danger); background: rgba(229, 72, 77, 0.1); }
@media (hover: hover) {
  .item .del { opacity: 0; }
  .item:hover .del, .del:focus-visible { opacity: 0.7; }
}

.empty { padding: 48px 16px; text-align: center; }
.empty p { margin: 4px 0; }
.empty-icon { font-size: 2.6rem; margin-bottom: 8px; }

.done-section { margin-top: 26px; }
.done-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.done-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}
.chev { transition: transform 0.2s; }
.done-section.open .chev { transform: rotate(90deg); }
.done-section:not(.open) #done-list { display: none; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 0.9rem; padding: 6px; }
.link-btn:hover { color: var(--danger); }

/* ---------- Dialogue & toast ---------- */
dialog {
  width: min(400px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(10, 10, 20, 0.45); }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  z-index: 20;
}
