:root {
  --bg: #0f1220;
  --bg-soft: #171a2b;
  --card: #1c2036;
  --card-hover: #232843;
  --border: #2b3050;
  --text: #e8eaf2;
  --muted: #9aa0bf;
  --primary: #6c8cff;
  --primary-strong: #5575ff;
  --success: #34d399;
  --danger: #f87171;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1c2142 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 10%, #1a2740 0%, transparent 55%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  font-size: 34px;
  filter: drop-shadow(0 4px 10px rgba(108, 140, 255, 0.4));
}

.brand h1 {
  font-size: 24px;
  letter-spacing: -0.3px;
}

.subtitle {
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.today-pill {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #fff;
  box-shadow: 0 6px 16px rgba(85, 117, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(85, 117, 255, 0.5); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .stat-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.stat-card .stat-label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* Section title */
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title h2 { font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }

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

.habit-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: background 0.15s ease, border-color 0.15s ease;
  border-left: 4px solid var(--habit-color, var(--primary));
}
.habit-card:hover { background: var(--card-hover); }

.habit-emoji {
  font-size: 26px;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  border-radius: 12px;
  flex-shrink: 0;
}

.habit-info { flex: 1; min-width: 0; cursor: pointer; }
.habit-info .habit-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.habit-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
}
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: #ffb454;
}

/* Mini week dots */
.week-dots { display: flex; gap: 5px; }
.week-dot {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  position: relative;
}
.week-dot.done {
  background: var(--habit-color, var(--success));
  border-color: transparent;
}
.week-dot.today { outline: 2px solid var(--primary); outline-offset: 1px; }

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

.done-btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.done-btn:hover { border-color: var(--success); color: var(--success); }
.done-btn.checked {
  background: var(--success);
  border-color: var(--success);
  color: #06291c;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-emoji { font-size: 50px; margin-bottom: 10px; }
.empty-state h3 { margin-bottom: 6px; }
.empty-state p { color: var(--muted); margin-bottom: 18px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.6);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.15s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow);
  animation: pop 0.16s ease;
}
.modal-lg { max-width: 560px; }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.field { display: block; margin-bottom: 18px; }
.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}
.field input[type="text"] {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
}
.field input[type="text"]:focus { border-color: var(--primary); }

.emoji-picker, .color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-opt, .color-opt {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 20px;
  transition: transform 0.1s ease;
}
.emoji-opt:hover, .color-opt:hover { transform: scale(1.08); }
.emoji-opt.selected { border-color: var(--primary); background: var(--card-hover); }
.color-opt.selected { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px currentColor; }

/* Detail modal */
.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.detail-stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.detail-stat .v { font-size: 22px; font-weight: 800; }
.detail-stat .l { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.calendar-head h4 { font-size: 15px; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-label {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 4px;
}
.cal-cell {
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.cal-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-cell.done {
  background: var(--habit-color, var(--success));
  color: #06291c;
  font-weight: 700;
  border-color: transparent;
}
.cal-cell.today { outline: 2px solid var(--primary); outline-offset: 1px; }
.cal-cell.future { opacity: 0.4; cursor: default; }
.cal-cell:not(.empty):not(.future):hover { transform: scale(1.08); }

.detail-danger {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

/* AI suggest modal */
.ai-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -4px;
}
.ai-chip {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ai-chip:hover { color: var(--text); border-color: var(--muted); }
.ai-run-btn { width: 100%; }
.ai-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
}
.ai-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 14px;
  padding: 12px;
}
.ai-card-emoji {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.ai-card-info { flex: 1; min-width: 0; }
.ai-card-name { font-weight: 700; font-size: 14px; }
.ai-card-reason { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.ai-card .btn { flex-shrink: 0; padding: 8px 12px; font-size: 12.5px; }
.ai-add-done {
  background: var(--success);
  color: #06281c;
  cursor: default;
}

/* Responsive */
@media (max-width: 620px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .week-dots { display: none; }
  .habit-meta { gap: 8px; }
  .brand h1 { font-size: 20px; }
}
/* AI responsive mobile */
@media (max-width: 620px) {
  .ai-card {
    align-items: flex-start;
    gap: 10px;
  }

  .ai-card-info {
    min-width: 0;
  }

  .ai-card-name {
    line-height: 1.35;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .ai-card-reason {
    line-height: 1.45;
    overflow-wrap: anywhere;
  }

  .ai-card .btn {
    align-self: flex-start;
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  .modal {
    max-width: 100%;
    border-radius: 18px;
  }

  .modal-body {
    padding: 16px;
  }

  .ai-card {
    display: grid;
    grid-template-columns: 42px 1fr;
    grid-template-areas:
      "emoji info"
      "button button";
  }

  .ai-card-emoji {
    grid-area: emoji;
  }

  .ai-card-info {
    grid-area: info;
  }

  .ai-card .btn {
    grid-area: button;
    width: 100%;
    margin-top: 4px;
  }

  .ai-examples {
    gap: 6px;
  }

  .ai-chip {
    font-size: 12px;
    padding: 6px 10px;
  }
}