:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1b1d2a;
  --muted: #6b7088;
  --line: #e4e6f0;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --good: #16a34a;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 50, .06), 0 4px 14px rgba(20, 20, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --card: #181b25;
    --text: #eceef7;
    --muted: #9096ad;
    --line: #272b3a;
    --accent: #818cf8;
    --accent-soft: #23264a;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -.02em; }
.muted { color: var(--muted); margin: 2px 0 0; }
.small { font-size: .85rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 20px 8px;
  max-width: 640px; margin: 0 auto;
}
main { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
.view { display: none; }
.view.active { display: block; }

.icon-btn {
  border: 0; background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.3rem;
  box-shadow: var(--shadow); cursor: pointer;
}

.summary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff; border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px;
}
.summary b { font-size: 1.6rem; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.28); margin-top: 10px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: 99px; transition: width .3s; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
}
.card.done { opacity: .75; }
.card .emoji { font-size: 1.5rem; width: 36px; text-align: center; }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 600; overflow-wrap: anywhere; }
.card.done .title { text-decoration: line-through; text-decoration-color: var(--muted); }
.card .meta { color: var(--muted); font-size: .85rem; }
.streak { color: #ea580c; font-weight: 600; }

.check {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line);
  background: transparent; color: #fff; font-size: 1.2rem; cursor: pointer; flex: none;
}
.check.on { background: var(--good); border-color: var(--good); }
.check:disabled { opacity: .35; cursor: default; }
.edit {
  border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 6px;
}

.week { display: flex; gap: 4px; margin-top: 6px; }
.week span {
  width: 18px; height: 18px; border-radius: 5px; background: var(--line); font-size: .6rem;
  display: grid; place-items: center; color: var(--muted);
}
.week span.hit { background: var(--good); color: #fff; }
.week span.off { background: transparent; border: 1px dashed var(--line); }

.goal { flex-direction: column; align-items: stretch; gap: 8px; }
.goal .head { display: flex; align-items: center; gap: 8px; }
.goal .head .title { flex: 1; }
.progress { height: 10px; border-radius: 99px; background: var(--accent-soft); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.goal.complete .progress > i { background: var(--good); }
.goal .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pill {
  border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 600;
  padding: 8px 14px; border-radius: 99px; cursor: pointer;
}
.late { color: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat b { font-size: 1.6rem; display: block; }
.stat span { color: var(--muted); font-size: .85rem; }
.section-title { margin: 18px 4px 8px; font-size: .95rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.heat { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; background: var(--card); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--line); }
.heat i.l1 { background: color-mix(in srgb, var(--good) 35%, var(--line)); }
.heat i.l2 { background: color-mix(in srgb, var(--good) 65%, var(--line)); }
.heat i.l3 { background: var(--good); }

.fab {
  position: fixed; right: 20px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; font-size: 2rem; line-height: 1;
  background: var(--accent); color: #fff; box-shadow: 0 6px 18px rgba(79,70,229,.4); cursor: pointer;
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: none; color: var(--muted); padding: 16px 0; font: inherit; font-weight: 600; cursor: pointer;
}
.tab.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(92vw, 420px);
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 10, 25, .5); }
form, .menu { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
input {
  font: inherit; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); width: 100%;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.days { display: flex; gap: 6px; }
.days label { flex: 1; font-weight: 500; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span {
  display: grid; place-items: center; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  cursor: pointer; background: var(--bg);
}
.days input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.days input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
button.primary, button.ghost, button.danger {
  font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 12px; border: 0; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: var(--accent-soft); color: var(--accent); }
button.danger { background: none; color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #1b1d2a; color: #fff; padding: 10px 16px; border-radius: 99px; opacity: 0;
  transition: .25s; pointer-events: none; font-size: .9rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
