:root {
  --bg: #0b0e18;
  --bg-2: #101426;
  --card: #161b2e;
  --card-2: #1c2238;
  --line: #262d47;
  --text: #eef1ff;
  --muted: #8f98bd;
  --accent: #5cf0c0;
  --accent-2: #7b8cff;
  --flame: #ff9f4a;
  --danger: #ff6b81;
  --radius: 20px;
  --shadow: 0 12px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(123, 140, 255, .22), transparent 60%),
    radial-gradient(700px 380px at 100% 0%, rgba(92, 240, 192, .16), transparent 55%),
    var(--bg);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(120px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 0;
}

h1, h2, h3, p { margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.topbar h1 {
  font-size: 26px;
  letter-spacing: -.02em;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: .18s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] {
  color: #0b0e18;
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- cards ---------- */
.card {
  background: linear-gradient(160deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.ring-wrap { position: relative; width: 108px; height: 108px; flex: 0 0 auto; }
.ring { width: 108px; height: 108px; transform: rotate(-90deg); }
.ring-bg, .ring-fg {
  fill: none;
  stroke-width: 11;
  stroke-linecap: round;
}
.ring-bg { stroke: rgba(255, 255, 255, .07); }
.ring-fg {
  stroke: var(--accent);
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset .6s cubic-bezier(.3, 1, .4, 1), stroke .3s;
}
.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  line-height: 1.1;
}
.ring-label strong { font-size: 24px; display: block; }
.ring-label span { font-size: 11px; color: var(--muted); }

.hero-copy h2 { font-size: 18px; margin-bottom: 4px; }
.hero-copy p { font-size: 13.5px; color: var(--muted); line-height: 1.4; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip b { color: var(--text); }

/* ---------- weekly chart ---------- */
.chart-card { margin-bottom: 22px; }
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 16px; }
.muted { color: var(--muted); font-size: 12.5px; }

.chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 140px;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}
.bar-value { font-size: 10.5px; color: var(--muted); height: 14px; }
.bar-track {
  width: 100%;
  height: 84px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .05);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.bar-fill {
  width: 100%;
  height: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  transition: height .6s cubic-bezier(.3, 1, .4, 1);
}
.bar-col.today .bar-day { color: var(--accent); font-weight: 700; }
.bar-col.today .bar-day::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  margin: 3px auto 0;
}
.bar-col.future .bar-track { opacity: .45; }
.bar-day { font-size: 11px; color: var(--muted); }
.bar-col.full .bar-fill { box-shadow: 0 0 16px rgba(92, 240, 192, .5); }
.chart-note { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* ---------- list ---------- */
.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 10px;
}
.list-head h2 { font-size: 16px; }

.habits { display: flex; flex-direction: column; gap: 10px; }

.habit {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: .2s;
  -webkit-tap-highlight-color: transparent;
}
.habit:active { transform: scale(.985); }
.habit.done { background: linear-gradient(120deg, rgba(92, 240, 192, .1), var(--card)); border-color: rgba(92, 240, 192, .3); }
.habit.off { opacity: .66; }
.habit.editing { border-style: dashed; }
.habits.editing .check { visibility: hidden; }

.habit-emoji {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-size: 21px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .06);
}

.habit-main { flex: 1 1 auto; min-width: 0; }
.habit-name {
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit.done .habit-name { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.habit-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}
.streak-pill { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.streak-pill.hot { color: var(--flame); }
.remind-pill { font-size: 11.5px; }

.dots { display: flex; gap: 4px; margin-top: 8px; }
.dot {
  width: 15px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
}
.dot.on { background: var(--accent); }
.dot.missed { background: rgba(255, 107, 129, .45); }
.dot.off { background: rgba(255, 255, 255, .05); }
.dot.future { background: rgba(255, 255, 255, .07); }
.dot.today { background: rgba(92, 240, 192, .35); }

.check {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  display: grid;
  place-items: center;
  color: transparent;
  cursor: pointer;
  transition: .2s;
}
.check svg { width: 22px; height: 22px; }
.habit.done .check {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e18;
  animation: pop .32s ease;
}
@keyframes pop {
  0% { transform: scale(.7); }
  60% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty-emoji { font-size: 40px; margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty p { font-size: 13.5px; }

/* ---------- fab ---------- */
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #0b0e18;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 28px rgba(92, 240, 192, .3);
  cursor: pointer;
  transition: .18s;
  z-index: 30;
}
.fab:active { transform: translateX(-50%) scale(.93); }

/* ---------- toasts ---------- */
.toast-stack {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(10px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: slidein .3s ease;
}
.toast .t-emoji { font-size: 20px; }
.toast .t-title { font-size: 14px; font-weight: 600; }
.toast .t-body { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
@keyframes slidein {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: none; }
}
.toast.out { animation: slideout .3s ease forwards; }
@keyframes slideout {
  to { opacity: 0; transform: translateY(-14px); }
}

/* ---------- sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 14, .66);
  backdrop-filter: blur(3px);
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-backdrop[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  padding: 12px 18px calc(22px + env(safe-area-inset-bottom));
  animation: rise .28s cubic-bezier(.3, 1, .4, 1);
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-grip {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 4px auto 14px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet-head h2 { font-size: 19px; }
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 8px;
  min-height: 40px;
}

.field { display: block; margin-bottom: 18px; }
.field-label {
  display: block;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 8px;
}
.text-input {
  width: 100%;
  font-size: 16px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  min-height: 50px;
  font-family: inherit;
}
.text-input:focus { outline: none; border-color: var(--accent); }

.emoji-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.emoji-btn {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 20px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.emoji-btn[aria-pressed="true"] { border-color: var(--accent); background: rgba(92, 240, 192, .14); }

.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  position: relative;
}
.color-btn .swatch { position: absolute; inset: 3px; border-radius: 50%; }
.color-btn[aria-pressed="true"] { border-color: var(--text); }

.day-row { display: flex; gap: 6px; }
.day-btn {
  flex: 1 1 0;
  min-height: 46px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.day-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #0b0e18; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row .field-label { margin-bottom: 0; }
.switch {
  width: 56px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 3px;
  cursor: pointer;
  display: flex;
  transition: .2s;
}
.switch span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--muted);
  transition: .2s;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] span { background: #0b0e18; transform: translateX(24px); }

.time-row { margin-top: 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.4; }
.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 14px;
}

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  flex: 1 1 auto;
  min-height: 52px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn.primary { background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: #0b0e18; border: none; }
.btn.danger { flex: 0 0 auto; padding: 0 18px; color: var(--danger); border-color: rgba(255, 107, 129, .35); background: rgba(255, 106, 129, .08); font-size: 14px; }
.btn.danger.arming { background: var(--danger); color: #0b0e18; border-color: var(--danger); }
.btn:active { transform: scale(.98); }

@media (min-width: 480px) {
  .topbar h1 { font-size: 30px; }
}
