:root{
  --bg: #FBFAF6;
  --bg-grad: #F3F6FF;
  --surface: #FFFFFF;
  --text: #1F2430;
  --text-dim: #8B909C;
  --text-faint: #B7BAC3;
  --border: rgba(31,36,48,0.06);
  --shadow: 0 1px 2px rgba(31,36,48,0.04), 0 8px 24px -12px rgba(31,36,48,0.12);
  --shadow-hover: 0 4px 8px rgba(31,36,48,0.05), 0 16px 32px -14px rgba(31,36,48,0.16);
  --accent: #2FB37F;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

*{ box-sizing: border-box; }
html,body{ height: 100%; }
body{
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(120% 100% at 50% -10%, var(--bg-grad) 0%, var(--bg) 45%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app{
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 28px 20px calc(100px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  animation: rise .5s ease both;
}
.top__eyebrow{
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-dim);
  text-transform: capitalize;
}
.top__greeting{
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ring{
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}
.ring__svg{ width: 100%; height: 100%; transform: rotate(-90deg); }
.ring__track,.ring__fill{
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
}
.ring__track{ stroke: rgba(47,179,127,0.14); }
.ring__fill{
  stroke: var(--accent);
  stroke-dasharray: 169.6;
  stroke-dashoffset: 169.6;
  transition: stroke-dashoffset .5s cubic-bezier(.4,0,.2,1);
}
.ring__count{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

/* ---------- list ---------- */
.list{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit{
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  animation: rise .5s cubic-bezier(.16,1,.3,1) both;
  animation-delay: calc(var(--i, 0) * 45ms);
  transition: box-shadow .2s ease, transform .2s ease, opacity .3s ease;
}
@media (hover: hover){
  .habit:hover{ box-shadow: var(--shadow-hover); transform: translateY(-1px); }
}

.habit[data-status="paused"]{
  opacity: .55;
}
.habit[data-status="paused"] .habit__icon{ filter: grayscale(45%); }
.habit[data-skipped="true"]{ opacity: .7; }

.kebab-wrap{
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
}
.habit__pause{
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-dim);
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s ease, background .15s ease, transform .15s ease;
}
.habit__pause svg{ width: 18px; height: 7px; }
.habit__pause:hover{ color: var(--text); background: rgba(31,36,48,0.07); }
.habit__pause:active{ transform: scale(.92); }
.habit__pause:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }

.habit-menu{
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-hover);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 148px;
  z-index: 30;
  animation: rise .15s ease both;
}
.habit-menu button{
  border: none;
  background: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.habit-menu button:hover{ background: rgba(31,36,48,0.06); }

.habit__identity{
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
}
.habit__identity:focus-visible{ outline: 2px solid var(--accent); outline-offset: 3px; }

.habit__icon{
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.habit__body{ min-width: 0; flex: 1; display: flex; flex-direction: column; }
.habit__name{
  display: block;
  margin: 0 0 3px;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit__schedule{
  display: inline-flex;
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  align-items: center;
  gap: 5px;
}
.habit__schedule::before{
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .5;
}

.habit__resume{
  border: none;
  background: rgba(31,36,48,0.06);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s ease, color .15s ease;
}
.habit__resume:hover{ background: rgba(31,36,48,0.1); color: var(--text); }

.habit__check{
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(31,36,48,0.12);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .2s ease, border-color .2s ease;
}
.habit__check svg{
  width: 18px;
  height: 18px;
  opacity: 0;
  transform: scale(.5);
  transition: opacity .15s ease, transform .15s ease;
}
.habit__check:active{ transform: scale(.9); }
.habit__check:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }

.habit__check[data-done="true"]{
  background: var(--habit-color, var(--accent));
  border-color: var(--habit-color, var(--accent));
}
.habit__check[data-done="true"] svg{ opacity: 1; transform: scale(1); stroke: #fff; }
.habit__check.pulse{ animation: pop .38s cubic-bezier(.34,1.56,.64,1); }

.habit__count{
  flex-shrink: 0;
  min-width: 46px;
  height: 40px;
  border-radius: 999px;
  border: 2px solid rgba(31,36,48,0.12);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .2s ease, border-color .2s ease, color .2s ease;
}
.habit__count:active{ transform: scale(.92); }
.habit__count:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
.habit__count[data-full="true"]{
  background: var(--habit-color, var(--accent));
  border-color: var(--habit-color, var(--accent));
  color: #fff;
}
.habit__count.pulse{ animation: pop .38s cubic-bezier(.34,1.56,.64,1); }

.habit__check--skip{
  border-color: rgba(31,36,48,0.12);
  color: var(--text-faint);
}
.habit__check--skip svg{ opacity: 1; transform: scale(1); }

/* ---------- empty state ---------- */
.empty{
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  margin: 60px 0;
}

/* ---------- priorities ---------- */
.priorities{
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.priorities__title{
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.005em;
}
.priorities__subtitle{
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-transform: capitalize;
}
.priorities__list{
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.priority-row{
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.priority-row__badge{
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(47,179,127,0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.priority-row__input{
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  padding: 4px 0;
}
.priority-row__input:focus{ outline: none; }
.priority-row__input::placeholder{ color: var(--text-faint); }
.priority-row__check{
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(31,36,48,0.12);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background .2s ease, border-color .2s ease;
}
.priority-row__check svg{ width: 13px; height: 13px; opacity: 0; transform: scale(.5); transition: opacity .15s ease, transform .15s ease; }
.priority-row__check[data-done="true"]{ background: var(--accent); border-color: var(--accent); }
.priority-row__check[data-done="true"] svg{ opacity: 1; transform: scale(1); stroke: #fff; }
.priority-row.is-done .priority-row__input{ color: var(--text-faint); text-decoration: line-through; }

/* ---------- FAB ---------- */
.fab{
  position: fixed;
  right: max(20px, calc((100vw - 480px) / 2 + 20px));
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px -6px rgba(47,179,127,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s cubic-bezier(.34,1.56,.64,1);
  z-index: 10;
}
.fab svg{ width: 24px; height: 24px; }
.fab:hover{ transform: scale(1.06); }
.fab:active{ transform: scale(.94); }
.fab:focus-visible{ outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- overlay / sheet ---------- */
.overlay{
  position: fixed;
  inset: 0;
  background: rgba(20,22,30,0);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  transition: background .2s ease;
}
.overlay.is-open{ background: rgba(20,22,30,0.4); }
.overlay[hidden]{ display: none; }

.sheet{
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.overlay.is-open .sheet{ transform: translateY(0); }
@media (min-width: 560px){
  .overlay{ align-items: center; }
  .sheet{ border-radius: 24px; max-height: 80vh; transform: translateY(12px) scale(.98); opacity: 0; }
  .overlay.is-open .sheet{ transform: translateY(0) scale(1); opacity: 1; }
}

.sheet__handle{
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(31,36,48,0.14);
  margin: 6px auto 14px;
}
.sheet__title{
  margin: 0 0 18px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.field{ display: block; margin-bottom: 18px; }
.field__label{
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.field__input{
  width: 100%;
  border: 1.5px solid rgba(31,36,48,0.12);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
}
.field__input:focus{ outline: none; border-color: var(--accent); }

.icon-picker-toggle{
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1.5px solid rgba(31,36,48,0.12);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.icon-picker-toggle__preview{
  font-size: 22px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: 10px;
}
.icon-picker{
  margin-top: 10px;
  border: 1.5px solid rgba(31,36,48,0.1);
  border-radius: var(--radius-md);
  padding: 10px;
}
.icon-picker__search{
  width: 100%;
  border: 1.5px solid rgba(31,36,48,0.1);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  margin-bottom: 10px;
}
.icon-picker__search:focus{ outline: none; border-color: var(--accent); }
.icon-picker__grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.icon-picker__item{
  border: none;
  background: none;
  font-size: 20px;
  padding: 6px 0;
  border-radius: 8px;
  cursor: pointer;
}
.icon-picker__item:hover{ background: rgba(31,36,48,0.06); }
.icon-picker__item.is-selected{ background: rgba(47,179,127,0.16); }

.swatches{ display: flex; flex-wrap: wrap; gap: 10px; }
.swatch{
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.6);
  transition: transform .15s cubic-bezier(.34,1.56,.64,1);
}
.swatch.is-selected{ transform: scale(1.15); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px currentColor; outline: 2px solid rgba(31,36,48,0.2); }

.seg{
  display: flex;
  background: var(--bg);
  border: 1.5px solid rgba(31,36,48,0.1);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}
.seg__btn{
  flex: 1;
  border: none;
  background: none;
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.seg__btn.is-selected{ background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.days-picker{ display: flex; gap: 6px; margin-top: 10px; }
.day-chip{
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(31,36,48,0.12);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.day-chip.is-selected{ background: var(--accent); border-color: var(--accent); color: #fff; }

.stepper{
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 10px;
}
.stepper__btn{
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid rgba(31,36,48,0.12);
  background: var(--bg);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}
.stepper__value{ font-size: 16px; font-weight: 700; min-width: 20px; text-align: center; }

.sheet__actions{
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn{
  flex: 1;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn--ghost{ background: rgba(31,36,48,0.06); color: var(--text); }
.btn--ghost:hover{ background: rgba(31,36,48,0.1); }
.btn--primary{ background: var(--accent); color: #fff; }
.btn--primary:hover{ filter: brightness(1.05); }
.btn--danger{ flex: none; background: none; color: #E1493A; padding: 13px 4px; }
.btn--danger:hover{ text-decoration: underline; }

/* ---------- footer ---------- */
.foot{
  margin-top: auto;
  padding-top: 32px;
  text-align: center;
}
.foot p{
  margin: 0;
  font-size: 12px;
  color: var(--text-faint);
}

/* ---------- motion ---------- */
@keyframes rise{
  from{ opacity: 0; transform: translateY(10px); }
  to{ opacity: 1; transform: translateY(0); }
}
@keyframes pop{
  0%{ transform: scale(1); }
  40%{ transform: scale(1.18); }
  100%{ transform: scale(1); }
}
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
