:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --surface-card: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --accent-track: #b7d3f6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11,11,11,0.04), 0 8px 24px rgba(11,11,11,0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-card: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-strong: #6da7ec;
    --accent-track: #104281;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --warning: #fab219;
    --critical: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-card: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-strong: #6da7ec;
  --accent-track: #104281;
  --good: #0ca30c;
  --good-text: #0ca30c;
  --warning: #fab219;
  --critical: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  background: var(--surface-2);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
}

a { color: var(--accent); }

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px calc(80px + env(safe-area-inset-bottom));
}

/* --- top bar --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--gridline);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
}

.brand .mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 15px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.whoami {
  font-size: 13px;
  color: var(--text-secondary);
  margin-right: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

/* --- buttons --- */

button, .btn {
  font-family: inherit;
  font-size: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
}

button:hover, .btn:hover { border-color: var(--accent); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-danger {
  color: var(--critical);
  border-color: var(--critical);
  background: transparent;
}
.btn-danger:hover { background: var(--critical); color: white; }

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-primary); border-color: var(--border); }

/* --- cards --- */

.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card + .card { margin-top: 14px; }

/* --- auth pages --- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.auth-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
  margin: 0 auto 16px;
}

.auth-card h1 {
  font-size: 19px;
  text-align: center;
  margin: 0 0 4px;
}

.auth-sub {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 24px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 14px 0 6px;
}

input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gridline);
  background: var(--surface-1);
  color: var(--text-primary);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.field-error {
  color: var(--critical);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

.auth-card form { margin-top: 4px; }
.auth-card .btn-primary { width: 100%; margin-top: 20px; padding: 11px; }

/* --- progress panel --- */

.progress-panel {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.progress-hero {
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  min-width: 96px;
}

.progress-hero small {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-secondary);
}

.progress-body { flex: 1; min-width: 220px; }

.progress-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.meter-track {
  height: 12px;
  border-radius: 999px;
  background: var(--accent-track);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-stats {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-stats b { color: var(--text-primary); font-weight: 700; }

/* --- add task form --- */

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.add-form input[type="text"] { flex: 1; min-width: 160px; }
.add-form select { width: auto; }
.add-form button[type="submit"] { flex-shrink: 0; }

.add-more-toggle {
  font-size: 13px;
  color: var(--accent);
  background: none;
  border: none;
  padding: 6px 0 0;
  cursor: pointer;
}

/* --- top-level view tabs (Tasks / Activity) --- */

.view-tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
}

.view-tab {
  flex: 1;
  border-radius: var(--radius-md);
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  background: var(--surface-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  box-shadow: var(--shadow);
}
.view-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* --- category tabs (horizontally scrollable, mobile-first) --- */

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  margin: -2px -2px 12px;
  padding: 2px 2px 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
}
.category-tabs::-webkit-scrollbar { display: none; }

.category-tab {
  flex-shrink: 0;
  scroll-snap-align: start;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.category-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* --- filters --- */

.filters {
  display: flex;
  gap: 6px;
  margin: 0 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.filter-btn.active {
  background: var(--surface-1);
  border-color: var(--text-secondary);
  color: var(--text-primary);
  font-weight: 700;
}

/* --- task groups & rows --- */

.category-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 22px 0 8px;
}
.category-heading:first-child { margin-top: 0; }

.task-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--gridline);
}
.task-row:last-child { border-bottom: none; }

.task-check {
  margin-top: 2px;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--good);
  cursor: pointer;
}

.task-main { flex: 1; min-width: 0; }

.task-title {
  font-size: 14.5px;
  font-weight: 500;
  word-break: break-word;
}
.task-title.done {
  color: var(--text-muted);
  text-decoration: line-through;
}

.task-notes {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  word-break: break-word;
}

.task-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.recurrence-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-strong);
  margin-top: 4px;
}

/* --- subtasks (checklist steps within a task) --- */

.subtask-toggle {
  border: none;
  background: none;
  padding: 6px 0 0;
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
}
.subtask-toggle:hover { color: var(--accent); }

.subtask-box {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}

.subtask-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
}

.subtask-check {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--good);
  cursor: pointer;
}

.subtask-title {
  flex: 1;
  font-size: 13px;
  word-break: break-word;
}
.subtask-title.done {
  color: var(--text-muted);
  text-decoration: line-through;
}

.subtask-del {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  flex-shrink: 0;
}
.subtask-del:hover { color: var(--critical); }

.subtask-add-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.subtask-add-row input {
  flex: 1;
  font-size: 13px;
  padding: 7px 10px;
}
.subtask-add-row button {
  flex-shrink: 0;
  padding: 7px 12px;
  font-size: 13px;
}

/* --- activity feed --- */

.activity-item {
  display: flex;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--gridline);
}
.activity-item:last-child { border-bottom: none; }

.activity-icon {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.activity-text { font-size: 13.5px; }
.activity-text b { font-weight: 700; }

.activity-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.task-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* --- household / users --- */

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--gridline);
}
.user-row:last-child { border-bottom: none; }

.user-name { font-weight: 600; font-size: 14px; }
.user-sub { font-size: 12px; color: var(--text-muted); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.setup-link-box {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--gridline);
  border-radius: var(--radius-md);
  font-size: 13px;
}
.setup-link-box code {
  display: block;
  word-break: break-all;
  margin: 8px 0;
  font-size: 12.5px;
  color: var(--accent-strong);
}

/* --- modal --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,11,11,0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 100;
  overflow-y: auto;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h2 { font-size: 17px; margin: 0; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
}

.theme-toggle {
  width: 32px;
  height: 32px;
}

@media (max-width: 480px) {
  .progress-panel { gap: 16px; }
  .progress-hero { font-size: 38px; }
}

@media (max-width: 640px) {
  .add-form { flex-direction: column; align-items: stretch; }
  .add-form select { width: 100%; }
  .add-form button[type="submit"] { width: 100%; }
  .modal-backdrop { padding: 16px; align-items: center; }
  .whoami { max-width: 64px; }
}

@media (max-width: 380px) {
  .brand-text { display: none; }
}
