*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: #f6f8fa;
  color: #1f2328;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  background: #fff;
  border-bottom: 1px solid #d0d7de;
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-content h1 { font-size: 18px; font-weight: 600; }
.today-label { color: #57606a; font-size: 13px; }

/* ── Layout ── */
.main {
  max-width: 820px;
  margin: 24px auto;
  padding: 0 24px;
}

/* ── Add form ── */
.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.add-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.add-form input:focus {
  border-color: #0969da;
  box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.12);
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: #2da44e; color: #fff; }
.btn-primary:hover { background: #2c974b; }

/* ── Habit cards ── */
.habits-list { display: flex; flex-direction: column; gap: 8px; }

.habit-card {
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.habit-card:hover { border-color: #b3c4d6; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.habit-card.selected { border-color: #0969da; }
.habit-card.done .habit-name { text-decoration: line-through; color: #8c959f; }

.habit-check {
  width: 18px;
  height: 18px;
  border: 2px solid #d0d7de;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.habit-check:hover { border-color: #2da44e; }
.habit-check:active { transform: scale(0.9); }
.habit-check.checked { background: #2da44e; border-color: #2da44e; }
.habit-check.checked::after {
  content: '';
  display: block;
  width: 5px;
  height: 8px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.habit-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit-name:hover { color: #0969da; }

.habit-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: #57606a;
  min-width: 52px;
}
.streak-badge.active { color: #bc4c00; font-weight: 600; }

.total-badge { font-size: 12px; color: #8c959f; min-width: 50px; }

.delete-btn {
  background: none;
  border: none;
  color: #cf222e;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.habit-card:hover .delete-btn { opacity: 1; }
.delete-btn:hover { background: #ffebe9; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: #57606a;
}
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: #1f2328; }
.empty-state p { font-size: 13px; }

/* ── Detail panel ── */
.detail-panel { margin-top: 16px; }
.detail-panel.hidden { display: none; }

.detail-card {
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  padding: 20px 24px;
}

.detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}
.detail-top h2 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }

.detail-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-chip {
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 13px;
}

.close-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #57606a;
  line-height: 1;
  padding: 0 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.close-btn:hover { background: #f6f8fa; color: #1f2328; }

/* ── Contribution grid ── */
.grid-wrapper {
  overflow-x: auto;
  padding-bottom: 4px;
}

.grid-months {
  position: relative;
  height: 18px;
  padding-left: 28px;
  margin-bottom: 2px;
}
.grid-month-label {
  position: absolute;
  font-size: 11px;
  color: #57606a;
  white-space: nowrap;
}

.grid-body { display: flex; gap: 4px; }

.grid-days {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 9px;
  color: #57606a;
  width: 24px;
  flex-shrink: 0;
  padding-top: 1px;
  text-align: right;
}
.grid-days span { height: 11px; display: flex; align-items: center; justify-content: flex-end; }

.contribution-grid { display: flex; gap: 2px; }

.grid-col { display: flex; flex-direction: column; gap: 2px; }

.grid-cell {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: #ebedf0;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.1s;
}
.grid-cell:hover { opacity: 0.75; }
.grid-cell.completed { background: #40c463; }
.grid-cell.today { outline: 1.5px solid #0969da; outline-offset: 1px; }
.grid-cell.empty { background: transparent; cursor: default; pointer-events: none; }

.grid-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  justify-content: flex-end;
}
.legend-label { font-size: 11px; color: #57606a; }
.legend-cell { width: 11px; height: 11px; border-radius: 2px; }
.legend-cell[data-level="0"] { background: #ebedf0; }
.legend-cell[data-level="1"] { background: #9be9a8; }
.legend-cell[data-level="2"] { background: #40c463; }
.legend-cell[data-level="3"] { background: #216e39; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .header-content { gap: 4px; }
  .today-label { display: none; }
  .total-badge { display: none; }
  .detail-card { padding: 16px; }
}
