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

:root {
  --surface: #ffffff;
  --border: #e6e0f8;
  --text: #1e1b2e;
  --muted: #9189a8;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
  --radius: 12px;
  --dot-color: rgba(124, 58, 237, 0.14);
  --dot-size: 22px;
}

body {
  background-color: #faf8ff;
  background-image:
    radial-gradient(circle, var(--dot-color) 1.2px, transparent 1.2px),
    linear-gradient(155deg, #faf8ff 0%, #fff4fd 45%, #f0f8ff 100%);
  background-size: var(--dot-size) var(--dot-size), 100% 100%;
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 52px 20px 80px;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

header {
  margin-bottom: 32px;
}

h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #7c3aed 0%, #db2777 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.15;
  margin-bottom: 6px;
}

.header-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.date {
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  margin-left: auto;
}

.progress-bar {
  height: 3px;
  background: #ede9fe;
  border-radius: 99px;
  margin-top: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(to right, #7c3aed, #22c55e);
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

/* ── Add habit ───────────────────────────────────────────────────────────── */

.add-habit {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.06);
}

.add-row {
  display: flex;
  gap: 8px;
}

.add-habit input {
  flex: 1;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #faf8ff;
  outline: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.add-habit input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.add-habit input::placeholder {
  color: #c4bbdb;
}

.add-habit button {
  padding: 9px 18px;
  background: linear-gradient(135deg, #7c3aed, #9333ea);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
  white-space: nowrap;
}

.add-habit button:hover { opacity: 0.9; transform: translateY(-1px); }
.add-habit button:active { transform: translateY(0); }

/* Category picker */
.cat-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.cat-pill {
  padding: 3px 10px;
  border-radius: 99px;
  border: 1.5px solid transparent;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  background: #f4f2fb;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.cat-pill .cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cat-pill.active {
  color: white;
  border-color: transparent;
}

/* ── Habit list ──────────────────────────────────────────────────────────── */

#habit-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--hc-main, #d1d5db);
  border-radius: var(--radius);
  padding: 13px 14px;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
}

.habit-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.habit-item.done {
  background: var(--hc-light, #f0fdf4);
  border-color: var(--hc-mid, #86efac);
  border-left-color: var(--hc-main, #22c55e);
}

/* Checkbox */
.habit-check {
  width: 21px;
  height: 21px;
  border: 2px solid var(--hc-main, #d1d5db);
  border-radius: 6px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.habit-item.done .habit-check {
  background: var(--hc-main);
  border-color: var(--hc-main);
}

.habit-check svg { display: none; }
.habit-item.done .habit-check svg { display: block; }

/* Habit info */
.habit-info {
  flex: 1;
  min-width: 0;
}

.habit-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.habit-name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-item.done .habit-name {
  color: var(--hc-main);
  text-decoration: line-through;
  text-decoration-color: var(--hc-main);
  opacity: 0.75;
}

.cat-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}

.habit-streak {
  font-size: 0.77rem;
  color: var(--muted);
  margin-top: 2px;
}

.habit-item.done .habit-streak {
  color: var(--hc-main);
  opacity: 0.8;
}

/* Delete button */
.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.habit-item:hover .delete-btn { opacity: 1; }
.delete-btn:hover { color: var(--danger); }

/* Empty state */
.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 48px;
  display: none;
}

.empty-state.visible { display: block; }

/* ── Monthly Grid ─────────────────────────────────────────────────────────── */

#grid-section {
  margin-top: 36px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 20px 20px 18px;
  box-shadow: 0 2px 16px rgba(124, 58, 237, 0.06);
}

.grid-title-row {
  margin-bottom: 14px;
}

.grid-month-label {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Scrollable wrapper — enables sticky first column */
.grid-scroll-wrap {
  overflow-x: auto;
  overflow-y: visible;
  /* hide scrollbar but keep scrollability */
  scrollbar-width: thin;
  scrollbar-color: #ddd9f0 transparent;
  padding-bottom: 4px;
}

.grid-scroll-wrap::-webkit-scrollbar {
  height: 4px;
}

.grid-scroll-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.grid-scroll-wrap::-webkit-scrollbar-thumb {
  background: #ddd9f0;
  border-radius: 99px;
}

/* The grid itself */
.habit-grid {
  display: grid;
  /* grid-template-columns set via JS */
  gap: 2px;
  min-width: max-content;
}

/* Day-number header cells */
.grid-day-num {
  width: 20px;
  height: 20px;
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  letter-spacing: -0.02em;
}

.grid-day-num.is-today {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
}

/* Habit name column — sticky */
.grid-name-cell {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 10px;
  height: 20px;
}

.grid-name-cell.header-spacer {
  /* top-left corner */
}

.grid-cat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.grid-habit-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 108px;
}

/* Individual day cells */
.grid-cell {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  transition: transform 0.1s;
  cursor: default;
}

.grid-cell:hover {
  transform: scale(1.2);
  z-index: 1;
  position: relative;
}

.grid-cell.is-future {
  background: transparent !important;
  border: 1.5px dashed #e0dcf0;
}

/* Row gap between habits */
.grid-row-gap {
  height: 3px;
  grid-column: 1 / -1;
}
