:root {
  color-scheme: light;
  --bg: #f3f3f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --habit: #2f9e44;
  --cross: #c5c5cb;
  --line: rgba(0, 0, 0, 0.06);
  --track: #e4e4ea;
  --nav: rgba(255, 255, 255, 0.94);
  --today-soft: rgba(47, 158, 68, 0.12);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111113;
  --card: #1c1c1e;
  --text: #f2f2f7;
  --muted: #8d8d93;
  --habit: #62c574;
  --cross: #636366;
  --line: rgba(255, 255, 255, 0.08);
  --track: #3a3a3c;
  --nav: rgba(22, 22, 24, 0.94);
  --today-soft: rgba(98, 197, 116, 0.16);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
}

.top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
}

.top h1 {
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 650;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  padding: 0;
}

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

.main { flex: 1; overflow: auto; }

.tab { padding: 4px 12px 16px; }

.composer, .pool-add {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.composer input, .pool-add input, .pool-row input, .edit-title {
  font-size: 16px;
  border: 0;
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}

.composer input, .pool-add input { flex: 1; }

.composer button, .pool-add button {
  border: 0;
  background: var(--habit);
  color: #fff;
  border-radius: 12px;
  padding: 0 14px;
  font-weight: 650;
}

.grid-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(5, 34px);
  align-items: center;
}

.head-nums { min-height: 48px; }
.head-wds { margin-bottom: 4px; }

.today-pct {
  justify-self: end;
  font-weight: 750;
  font-size: 16px;
  padding-right: 4px;
}

.weekday, .chart-day, .chart-wd { text-align: center; }
.weekday, .chart-wd { font-size: 11px; color: var(--muted); }
.weekday.is-today { color: var(--text); font-weight: 700; }

.day-cell {
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.card {
  background: var(--card);
  border-radius: 14px;
  min-height: 52px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.habit-card.is-dragging {
  position: relative;
  z-index: 5;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

body.is-reordering,
body.is-reordering .main {
  overflow: hidden;
  touch-action: none;
}

.habit-title {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0 8px 0 14px;
  color: var(--habit);
  font-weight: 400;
  font-size: 15px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.2;
}

.daily-title.is-empty { color: var(--muted); font-weight: 500; }

.mark {
  width: 34px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--cross);
  display: grid;
  place-items: center;
  justify-self: center;
  padding: 0;
}

.mark.is-done { color: var(--habit); }
.mark:disabled { visibility: hidden; }

.name { min-width: 0; padding: 8px 0; touch-action: none; }

.edit-title { width: calc(100% - 16px); margin-left: 8px; padding: 8px 10px; }

.empty, .hint, .caption, .month-caption { color: var(--muted); }
.empty { text-align: center; margin: 28px 12px; }
.hint { font-size: 14px; margin: 8px 0 14px; }
.caption { text-align: center; min-height: 22px; margin: 14px 0 0; }

.ring { position: relative; flex: none; }
.ring svg { display: block; width: 100%; height: 100%; }
.ring-track, .ring-value { fill: none; stroke-width: 3; }
.ring-track { stroke: var(--track); }
.ring-value { stroke-linecap: round; }
.ring-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 650;
  line-height: 1;
}

.chart-scroll {
  overflow: hidden;
  padding: 8px 0 4px;
}

.chart-row {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  align-items: end;
  row-gap: 12px;
  width: 100%;
}

.chart-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.chart-col.is-empty .chart-day { color: var(--muted); }
.bar-track {
  height: 72px;
  width: 8px;
  display: flex;
  align-items: flex-end;
}
.bar { width: 100%; border-radius: 3px 3px 1px 1px; }
.chart-day {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  width: 100%;
}
.chart-day.is-today { color: var(--habit); }

.month-switch {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  margin: 12px 0;
}

.month-switch button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 24px;
  line-height: 1;
}

.month-switch button:disabled { opacity: 0.35; }
.month-label { text-align: center; font-weight: 650; }

.month-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.cal-weekdays, .cal-week { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-weekdays {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin-bottom: 4px;
}

.cal-cell {
  background: none;
  border: 0;
  padding: 3px 0;
  display: flex;
  justify-content: center;
  border-radius: 12px;
}

.cal-cell.is-out { opacity: 0.42; }
.cal-cell.is-selected { background: var(--today-soft); }

.plain-day {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: var(--nav);
  backdrop-filter: blur(16px);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}

.nav-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0 2px;
}

.nav-btn.is-active { color: var(--habit); font-weight: 650; }

.pool-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.pool-top {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
}

.pool-top h2 { margin: 0; text-align: center; font-size: 17px; }

#pool-close {
  border: 0;
  background: none;
  color: var(--habit);
  font-weight: 650;
  padding: 8px 0;
  text-align: left;
}

.pool-list { flex: 1; overflow: auto; }

.pool-row { display: flex; gap: 8px; margin-bottom: 8px; }
.pool-row input { flex: 1; }

.pool-row button {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 0 4px;
}

.pool-add { margin-top: 8px; margin-bottom: 0; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  max-width: 488px;
  margin: 0 auto;
  background: #1c1c1e;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
  z-index: 30;
}

html[data-theme="dark"] .toast { background: #2c2c2e; }
