:root {
  --bg: #faf5ff;
  --bg-soft: #f5eefb;
  --card: #ffffff;
  --line: #ede4f7;
  --line-strong: #e0d4f0;
  --ink: #4c3d66;
  --ink-soft: #6b5b85;
  --muted: #8b7ca8;
  --muted-2: #a89bc0;
  --brand: #6d28d9;
  --brand-soft: #a78bfa;
  --brand-wash: #f3e8ff;
  --good: #34d399;
  --good-deep: #059669;
  --warn: #fb7185;
  --shadow: 0 1px 2px rgba(76, 61, 102, 0.06), 0 8px 24px rgba(76, 61, 102, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --nav-h: 64px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; }
.app-wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
  padding-top: calc(env(safe-area-inset-top) + 18px);
}

.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.topbar .eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted-2); }
.topbar h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.topbar p.sub { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.topbar h1.brand-title { margin: 0; font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: 0.01em; text-transform: uppercase; color: var(--ink); }
.brand-tag { margin: 8px 0 0; font-size: 15px; font-weight: 500; letter-spacing: 0.04em; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.section-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted-2); margin: 22px 4px 10px; }
.section-label:first-child { margin-top: 4px; }

/* ---------- Routine row ---------- */
.bucket-group { margin-bottom: 18px; }
.bucket-head { display: flex; align-items: center; gap: 8px; margin: 0 4px 8px; }
.bucket-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bucket-name { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; color: var(--ink-soft); }
.bucket-count { font-size: 12px; color: var(--muted-2); margin-left: auto; }

.routine {
  display: flex; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
}
.routine + .routine { margin-top: 10px; }
.routine.done { background: var(--bg-soft); border-color: var(--line); box-shadow: none; }

.check {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  border: 2px solid var(--line-strong); background: #fff;
  display: grid; place-items: center; transition: all 0.15s ease;
}
.check svg { width: 16px; height: 16px; opacity: 0; transform: scale(0.6); transition: all 0.15s ease; }
.check.on { background: var(--good); border-color: var(--good); }
.check.on svg { opacity: 1; transform: scale(1); stroke: #fff; }

.routine-body { flex: 1; min-width: 0; }
.routine-name { font-size: 15px; font-weight: 600; color: var(--ink); }
.routine.done .routine-name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--muted-2); }
.routine-meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; flex-wrap: wrap; }
.routine-note { font-size: 13px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.pill { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--brand-wash); color: var(--brand); white-space: nowrap; }
.pill.muted { background: var(--bg-soft); color: var(--muted); }
.pill.due { background: #fef3c7; color: #b45309; }
.pill.soft { background: var(--bg-soft); color: var(--ink-soft); }

.row-btn { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: var(--muted-2); }
.row-btn:hover { background: var(--bg-soft); color: var(--ink-soft); }
.row-btn svg { width: 18px; height: 18px; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 34px; }
.empty-art { margin: 0 auto 2px; line-height: 0; }
.empty-art svg.sisyphus { width: 128px; height: 128px; display: block; margin: 0 auto; }
.empty h3 { margin: 12px 0 4px; font-size: 17px; color: var(--ink-soft); font-weight: 700; }
.empty p { margin: 0; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 14px; font-size: 15px; font-weight: 600;
  background: var(--brand-wash); color: var(--brand); transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line-strong); }
.btn.danger { background: #fef2f2; color: var(--warn); }
.btn svg { width: 18px; height: 18px; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 11px; }

.add-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
  border-radius: 999px; background: var(--brand); color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 18px rgba(109, 40, 217, 0.28);
}
.add-pill svg { width: 16px; height: 16px; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat .num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; color: var(--brand); line-height: 1; }
.stat .lbl { margin-top: 6px; font-size: 13px; color: var(--muted); }
.stat .num.good { color: var(--good-deep); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.bar-row:first-child { margin-top: 4px; }
.bar-label { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); width: 128px; flex: none; }
.bar-track { flex: 1; height: 10px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 3px; border-radius: 999px; transition: width 0.3s ease; }
.bar-val { font-size: 12px; color: var(--muted); width: 30px; text-align: right; flex: none; }

/* ---------- AI review ---------- */
.review { white-space: pre-wrap; font-size: 14.5px; line-height: 1.6; color: var(--ink-soft); }
.review p { margin: 0 0 12px; }
.muted-note { font-size: 13px; color: var(--muted); line-height: 1.55; }
.muted-note a { color: var(--brand); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--brand-wash); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.banner.err { background: #fef2f2; color: var(--warn); }
.banner.ok { background: #ecfdf5; color: var(--good-deep); }

/* ---------- Settings ---------- */
.field { margin-top: 14px; }
.field:first-child { margin-top: 0; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.input, .select, .textarea {
  width: 100%; padding: 12px 13px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--ink); font-size: 15px; outline: none; transition: border-color 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand-soft); }
.textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238b7ca8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }

.bucket-edit { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.bucket-edit:last-child { border-bottom: none; }
.swatch-btn { width: 26px; height: 26px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); }
.bucket-edit .input { padding: 8px 11px; font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong); }
.swatch.sel { box-shadow: 0 0 0 2px var(--brand); }

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: stretch;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted-2); font-size: 11px; font-weight: 600; }
.nav-btn svg { width: 23px; height: 23px; }
.nav-btn.active { color: var(--brand); }

/* ---------- Modal / sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(40, 28, 66, 0.42); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  animation: rise 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line-strong); margin: 8px auto 14px; }
.sheet h2 { margin: 0 0 16px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }

.confirm { align-items: center; }
.confirm .sheet { max-width: 380px; border-radius: 20px; margin: 0 16px 16px; text-align: center; }
.confirm h2 { margin-top: 8px; }
.confirm p { color: var(--muted); font-size: 14px; margin: 0 0 4px; }

.hidden { display: none !important; }
