:root {
  --bg: #14141f;
  --card: #1f1f2e;
  --line: #2c2c40;
  --text: #f2f2f7;
  --muted: #9a9ab0;
  --accent: #7c6cff;
  --danger: #ff5c7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { margin: 0; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 20px 0 12px; }

.icon-btn {
  background: var(--card); color: var(--text); border: 0; border-radius: 12px;
  width: 44px; height: 44px; font-size: 22px; cursor: pointer;
}

/* Week strip */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 16px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 0; border: 0; border-radius: 14px; background: transparent;
  color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.day[aria-current="date"] { background: var(--card); color: var(--text); }
.day:disabled { opacity: .35; cursor: default; }
.ring {
  --p: 0;
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1turn), var(--line) 0);
  font-size: 13px; font-weight: 600; color: var(--text);
}
.ring span { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; }
.day[aria-current="date"] .ring span { background: var(--card); }

/* Habit cards */
.habits { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.habit {
  --c: var(--accent);
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 18px; background: var(--card);
  position: relative; overflow: hidden;
}
.habit .fill {
  position: absolute; inset: 0; background: var(--c); opacity: .22;
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform .25s;
}
.habit.done .fill { opacity: .4; }
.habit > * { position: relative; }
.check {
  flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0;
  background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; padding: 0;
}
.check:disabled { cursor: default; }
.emoji {
  width: 44px; height: 44px; flex: none; border-radius: 14px; display: grid; place-items: center;
  font-size: 24px; background: color-mix(in srgb, var(--c) 30%, transparent);
}
.name, .meta { display: block; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { font-size: 13px; color: var(--muted); }
.habit.done .name { text-decoration: line-through; text-decoration-color: var(--c); }
.more { background: none; border: 0; color: var(--muted); font-size: 22px; width: 36px; height: 44px; cursor: pointer; }

.empty { text-align: center; color: var(--muted); margin-top: 48px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 32px; cursor: pointer;
  box-shadow: 0 8px 24px rgb(0 0 0 / .4);
}

/* Dialogs */
dialog {
  width: min(520px, calc(100% - 24px)); max-height: 90dvh; overflow: auto;
  border: 0; border-radius: 22px; padding: 20px;
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .6); }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.emoji-input { font-size: 24px; width: 80px; text-align: center; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; }

.colors, .days { display: flex; flex-wrap: wrap; gap: 8px; }
.colors input, .days input { position: absolute; opacity: 0; pointer-events: none; }
.swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.colors input:checked + .swatch { border-color: var(--text); }
.colors input:focus-visible + .swatch, .days input:focus-visible + span { outline: 2px solid var(--accent); }
.days span {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--bg); color: var(--muted); cursor: pointer; font-size: 13px;
}
.days input:checked + span { background: var(--accent); color: #fff; }

.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.actions.col { flex-direction: column; }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: var(--accent); color: #fff; text-align: center;
}
.btn.ghost { background: var(--line); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); margin-right: auto; }

/* Detail */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 16px; }
.stat { background: var(--bg); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat small { color: var(--muted); }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cal-head button { background: var(--bg); color: var(--text); border: 0; border-radius: 10px; width: 36px; height: 36px; cursor: pointer; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: 12px; }
.cal .wd { color: var(--muted); }
.cal .c { aspect-ratio: 1; display: grid; place-items: center; border-radius: 10px; background: var(--bg); color: var(--muted); }
.cal .c.off { opacity: .3; }
.cal .c.done { background: var(--c); color: #fff; font-weight: 600; }
.cal .c.today { outline: 2px solid var(--c); }
