:root {
  --bg: #0d0d0f;
  --surface: #18181b;
  --surface2: #27272a;
  --border: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --accent: #6366f1;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  background: linear-gradient(135deg, #1e1b4b 0%, #0d0d0f 60%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  font-size: 2rem;
  line-height: 1;
}

.logo h1 {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.logo p {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #4f46e5; transform: translateY(-1px); }

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid #7f1d1d;
}
.btn-danger:hover { background: #7f1d1d33; }

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

/* ── Main layout ── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 5rem 2rem;
}

.empty-state .empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.empty-state h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ── Habit grid ── */
.habits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.habit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.habit-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.habit-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--card-color, var(--accent));
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.card-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.card-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.card-start {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.card-actions {
  display: flex;
  gap: 0.4rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.habit-card:hover .card-actions {
  opacity: 1;
}

/* ── Timer display ── */
.timer-block {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  text-align: center;
}

.timer-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.timer-units {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0.25rem;
  flex-wrap: nowrap;
  overflow: hidden;
}

.timer-unit {
  text-align: center;
  min-width: 2.4rem;
  flex-shrink: 0;
}

.timer-value {
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1;
}

.timer-unit-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.15rem;
}

.timer-sep {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--border);
  line-height: 1;
  align-self: flex-start;
  padding-top: 0.1rem;
  flex-shrink: 0;
}

/* ── Savings ── */
.savings-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #052e16 0%, #14532d22 100%);
  border: 1px solid #166534;
  border-radius: 10px;
  padding: 0.85rem 1.25rem;
}

.savings-label {
  font-size: 0.75rem;
  color: #86efac;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.savings-amount {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--success);
  font-variant-numeric: tabular-nums;
}

.savings-hidden {
  display: none;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}

/* ── Form ── */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.icon-btn {
  font-size: 1.3rem;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transition: all 0.12s;
}

.icon-btn:hover { background: var(--border); }
.icon-btn.selected { border-color: var(--accent); background: #312e81; }

.color-grid {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.color-swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.12s;
  outline: 3px solid transparent;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { outline-color: #fff; outline-offset: 2px; }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(4rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.25s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.toast-success { border-color: #166534; color: #86efac; }
.toast.toast-error   { border-color: #991b1b; color: #fca5a5; }

/* ── Confirm dialog ── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
}
.confirm-overlay.active { display: flex; }

.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 380px;
  width: 90%;
  text-align: center;
}
.confirm-box h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.confirm-box p  { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.5rem; }
.confirm-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .header { padding: 1rem; }
  .main   { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .habits-grid { grid-template-columns: 1fr; }
  .timer-value { font-size: 1.3rem; }
  .icon-grid { grid-template-columns: repeat(6, 1fr); }
}