:root {
  --bg: #0d0d0f;
  --surface: #18181b;
  --surface2: #27272a;
  --border: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --accent: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
  --header-bg: rgba(13,13,15,0.85);
  --savings-bg: rgba(5,46,22,0.8);
  --savings-border: rgba(22,101,52,0.6);
  --savings-text: #86efac;
  --auth-glow: #0f2a50;
}

[data-theme="light"] {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface2: #eeeef2;
  --border: #d1d1d8;
  --text: #09090b;
  --text-muted: #6b6b7b;
  --header-bg: rgba(244,244,246,0.85);
  --savings-bg: rgba(220,252,231,0.7);
  --savings-border: rgba(34,197,94,0.4);
  --savings-text: #15803d;
  --auth-glow: #dbeafe;
}

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

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 15% 0%, rgba(37,99,235,0.07) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 100%, rgba(56,189,248,0.04) 0%, transparent 50%);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.4rem 2.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height:79px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
    font-family: var(--font-sans);
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
}

.logo h1 {
  font-size: 1.35rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(37,99,235,0.35);
}

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.1); border-color: var(--danger); }

/* ── Card action buttons ── */
.card-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
}
.card-action-btn svg { width: 15px; height: 15px; }
.card-action-btn:hover { background: var(--border); color: var(--text); }
.card-action-delete:hover { background: rgba(239,68,68,0.12); color: #f87171; border-color: rgba(239,68,68,0.3); }

/* ── Header right / user pill ── */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.85rem 0.3rem 0.3rem;
}

.user-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  letter-spacing: 0;
  text-transform: uppercase;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
  margin: 0 0.1rem;
}

/* ── Theme toggle ── */
.theme-toggle {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
  color: var(--text-muted);
}
.theme-toggle:hover { background: var(--border); }

.user-pill-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.15rem;
  margin: -0.15rem;
  transition: opacity 0.15s;
}
.user-pill-link:hover { opacity: 0.75; }

.user-logout {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.user-logout:hover { color: var(--danger); }

/* ── Settings page ── */
.settings-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 1.25rem;
  transition: color 0.15s;
}
.settings-back:hover { color: var(--text); }

.settings-title {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
}

.settings-alert {
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
}
.settings-alert-error {
  background: rgba(127,29,29,0.2);
  border: 1px solid #991b1b;
  color: #fca5a5;
}
.settings-alert-success {
  background: rgba(5,46,22,0.4);
  border: 1px solid #166534;
  color: #86efac;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.settings-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1.1rem;
}

.settings-section-label-danger { color: var(--danger); }

.settings-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.settings-avatar {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  letter-spacing: 0;
  text-transform: uppercase;
}

.settings-profile-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.settings-profile-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.settings-danger-card {
  border-color: rgba(239,68,68,0.25);
}

.settings-danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.settings-danger-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.settings-danger-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 380px;
  line-height: 1.5;
}

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

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

.empty-state .empty-icon {
  font-size: 4rem;
  margin-bottom: 1.25rem;
  opacity: 0.5;
  display: block;
}

.empty-state h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}

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

.habit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  display: flex;
  flex-direction: column;
}

.habit-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--card-color, var(--accent)) 40%, var(--border));
  box-shadow:
    0 12px 40px rgba(0,0,0,0.45),
    0 0 0 1px color-mix(in srgb, var(--card-color, var(--accent)) 20%, transparent);
}

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

/* ── Card header ── */
.card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}

.card-icon-wrap {
  width: 2.8rem;
  height: 2.8rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--card-color, var(--accent)) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--card-color, var(--accent)) 25%, transparent);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.card-meta {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-start {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.card-start::before {
  content: '📅';
  font-size: 0.65rem;
}

/* ── Timer display ── */
.timer-block {
  background: color-mix(in srgb, var(--card-color, var(--accent)) 7%, var(--surface2));
  border: 1px solid color-mix(in srgb, var(--card-color, var(--accent)) 18%, transparent);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.85rem;
  text-align: center;
}

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

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

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

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

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

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

/* ── Savings ── */
.savings-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--savings-bg);
  border: 1px solid var(--savings-border);
  border-radius: 10px;
  padding: 0.75rem 1.1rem;
  margin-bottom: 0.85rem;
}

.savings-label {
  font-size: 0.7rem;
  color: var(--savings-text);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

/* ── Category picker ── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}

.category-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 0.5rem;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
  font-family: inherit;
}

.category-card:hover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
  transform: translateY(-2px);
}

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

.category-card-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.category-card-custom {
  border-style: dashed;
}

.category-card-custom .category-card-name { color: var(--text-muted); }

/* ── Modal step 2 header (with back button) ── */
.modal-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* Higher specificity than .modal h2 so the overrides actually win */
.modal .modal-header h2 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
  text-align: center;
}

.modal-header .btn-back {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-back:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 100;
  backdrop-filter: blur(6px);
  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: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

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

.modal h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

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

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

.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, box-shadow 0.15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.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.25rem;
  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: rgba(37,99,235,0.15); }

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

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

.color-swatch:hover { transform: scale(1.2); }
.color-swatch.selected { outline-color: rgba(255,255,255,0.8); }

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(4rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 200;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

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

.toast.toast-success { border-color: #166534; color: #86efac; background: rgba(5,46,22,0.9); }
.toast.toast-error   { border-color: #991b1b; color: #fca5a5; background: rgba(69,10,10,0.9); }

/* ── Confirm dialog ── */
.confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 150;
  backdrop-filter: blur(4px);
  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: 2rem;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  animation: slideUp 0.18s ease;
}
.confirm-box h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.6rem; }
.confirm-box p  { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1.75rem; line-height: 1.6; }
.confirm-actions { display: flex; gap: 0.75rem; justify-content: center; }
.review-stars { font-size: 1.5rem; letter-spacing: 0.05rem; margin-bottom: 0.75rem; }

/* ── Card actions ── */
.card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

/* ── Streak records ── */
.streak-records {
  margin-bottom: 0.85rem;
}

.streak-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.streak-count {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.streak-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  font-size: 0.8rem;
  transition: background 0.12s;
}

.streak-row:hover { background: var(--surface2); }

.streak-rank {
  font-size: 0.95rem;
  flex-shrink: 0;
  width: 1.4rem;
  text-align: center;
}

.streak-dur {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface2);
  border-radius: 5px;
  padding: 0.1rem 0.4rem;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.streak-meta {
  color: var(--text-muted);
  font-size: 0.73rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* ── Auth / Login page ── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: radial-gradient(ellipse at 50% 0%, var(--auth-glow) 0%, var(--bg) 65%);
}

.auth-wrap {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}


.auth-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.auth-logo p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.auth-tabs {
  display: flex;
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.25rem;
  margin-bottom: 1.5rem;
  gap: 0.25rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-tab:not(.active):hover { color: var(--text); }

.auth-error {
  background: rgba(127,29,29,0.2);
  border: 1px solid #991b1b;
  color: #fca5a5;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.forgot-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.forgot-link:hover { color: var(--text); }

.auth-submit {
  width: 100%;
  justify-content: center;
  padding: 0.7rem;
  margin-top: 0.5rem;
}

.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 3rem; }
.pw-toggle {
  position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; font-size: 0.72rem; font-weight: 600;
  color: var(--text-muted); cursor: pointer; font-family: inherit;
  padding: 0.15rem 0.3rem; border-radius: 4px; transition: color 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.pw-toggle:hover { color: var(--text); }
.pw-match-ok  { color: var(--success); }
.pw-match-err { color: var(--danger); }

/* ── Mobile bottom nav ── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  z-index: 50;
  align-items: center;
  justify-content: space-around;
  padding: 0 0.25rem;
  padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.22rem;
  text-decoration: none;
  color: var(--text-muted);
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  padding: 0.65rem 0.6rem;
  min-height: 56px;
  flex: 1;
  transition: color 0.15s;
}

.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item:not(.mobile-nav-add):hover { color: var(--text); }
.mobile-nav-item.mobile-nav-signout:hover { color: var(--danger); }

.mobile-nav-svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.mobile-nav-label {
  font-size: 0.56rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mobile-nav-add {
  color: #fff;
  background: var(--accent);
  border-radius: 14px;
  flex: none;
  padding: 0.5rem 1rem;
  margin: 0.4rem 0.1rem;
  min-height: auto;
  box-shadow: 0 2px 12px rgba(37,99,235,0.4);
}
.mobile-nav-add:hover { background: #1d4ed8; color: #fff; }

/* ── Sort bar ── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.sort-bar::-webkit-scrollbar { display: none; }

.sort-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.sort-btn {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}
.sort-btn:hover { color: var(--text); border-color: var(--text-muted); }
.sort-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Donate presets ── */
.donate-preset {
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.55rem 1.25rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  letter-spacing: 0.01em;
}
.donate-preset:hover {
  color: var(--text);
  border-color: var(--text-muted);
  background: var(--surface2);
}
.donate-preset.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px rgba(37,99,235,0.35);
}

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 2rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.footer a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer a:hover { color: var(--text); }

/* ── Onboarding tour ── */
.tour-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.tour-backdrop.active { display: block; }

.tour-tip {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 202;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  max-width: 340px;
  width: calc(100% - 2rem);
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  text-align: center;
  animation: slideUp 0.2s ease;
}
.tour-tip.active { display: block; }

.tour-step-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}
.tour-tip-icon { font-size: 2.25rem; line-height: 1; margin-bottom: 0.6rem; }
.tour-tip h3  { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.4rem; }
.tour-tip p   { font-size: 0.85rem; color: var(--text-muted); line-height: 1.65; margin-bottom: 1.5rem; }
.tour-actions { display: flex; gap: 0.75rem; justify-content: center; }
.tour-dots    { display: flex; gap: 5px; justify-content: center; margin-bottom: 1.25rem; }
.tour-dot     { width: 6px; height: 6px; border-radius: 50%; background: var(--border); transition: background 0.2s; }
.tour-dot.active { background: var(--accent); }

/* Tooltips — desktop hover only */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 500;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
}
@media (hover: hover) {
  [data-tooltip]:hover::after { opacity: 1; }
}
.card-action-delete[data-tooltip]::after {
  left: auto;
  right: 0;
  transform: none;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .header-inner { padding: 1.4rem 1rem; }
  .main   { padding: 1.5rem 1rem 6rem; }
  .form-row { grid-template-columns: 1fr; }
  .habits-grid { grid-template-columns: 1fr; }
  .timer-value { font-size: 1.2rem; }
  .icon-grid { grid-template-columns: repeat(6, 1fr); }
  .user-pill { display: none; }
  .header-add-btn { display: none; }
  .theme-toggle { display: none; }
  .mobile-nav { display: flex; }
}

/* ── Drag & drop reordering ── */
.drag-handle {
  display: block;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: grab;
  user-select: none;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  touch-action: none;
}
.drag-handle:hover { color: var(--text); background: var(--surface2); }
.drag-handle:active { cursor: grabbing; }

.habit-card.dragging {
  opacity: 0.45;
  transform: scale(0.97);
}
.habit-card.drag-over {
  box-shadow: 0 0 0 2.5px var(--accent);
  transform: translateY(-3px);
}

/* ── Share modal ── */
.share-box {
  max-width: 600px !important;
  width: 94vw !important;
}
.share-canvas-wrap {
  margin: 0.75rem 0;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
  border: 1px solid var(--border);
}
.share-canvas-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
}
.share-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin-top: 0.75rem;
}
.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.share-btn:hover { background: var(--border); color: var(--text); }
.share-btn-done { background: var(--accent); color: #fff; border-color: var(--accent); }
.share-btn-done:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }