:root {
  --bg: #f4f1fa;
  --card: #ffffff;
  --ink: #2b2638;
  --muted: #7a7290;
  --primary: #7c4dff;
  --primary-2: #9c6bff;
  --accent: #00c853;
  --warn: #ff6d00;
  --bad: #ff5252;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(60, 40, 120, .10);
}

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

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--ink);
  min-height: 100vh;
}

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

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 24px;
  background: linear-gradient(160deg, #7c4dff33, #00c85322);
}

.auth-card {
  background: var(--card); border-radius: 26px; box-shadow: var(--shadow);
  padding: 34px 28px; width: 100%; max-width: 420px; text-align: center;
}

.auth-logo { font-size: 54px; margin-bottom: 4px; }
.auth-card h1 { margin: 0 0 4px; font-size: 26px; }
.auth-sub { color: var(--muted); margin: 0 0 18px; }

.auth-error {
  background: #ff52521a; color: var(--bad); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}

.auth-input {
  display: block; width: 100%; margin: 10px 0; padding: 14px 16px;
  border: 2px solid #e5ddf7; border-radius: 14px; font-size: 16px;
  background: #faf8ff; color: var(--ink);
}
.auth-input:focus { outline: none; border-color: var(--primary); }

.auth-alt { color: var(--muted); font-size: 14px; margin-top: 18px; }
.auth-alt a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* ---------- buttons ---------- */

.btn {
  border: none; border-radius: 14px; cursor: pointer;
  font-size: 16px; font-weight: 600; padding: 12px 18px;
  transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.btn-big { width: 100%; padding: 15px; font-size: 18px; margin-top: 8px; }
.btn-ghost { background: transparent; color: var(--primary); padding: 8px 10px; font-size: 14px; text-decoration: none; }
.btn-soft { background: #f0eaff; color: var(--primary); }
.btn-danger-soft { background: #ffe5e5; color: var(--bad); font-size: 13px; padding: 8px 12px; }
.btn-acc { background: linear-gradient(135deg, #00c853, #00e676); color: #fff; }

/* ---------- app shell ---------- */

.app-root { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--card);
  position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 10px rgba(0,0,0,.05);
}
.topbar-left { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.logo { font-size: 22px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.chip {
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 700;
  white-space: nowrap;
}
.chip-streak { background: #fff1e6; color: var(--warn); }
.chip-points { background: #fff8d6; color: #b28900; }

.view { flex: 1; padding: 16px 14px 90px; max-width: 640px; margin: 0 auto; width: 100%; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--card);
  box-shadow: 0 -4px 18px rgba(0,0,0,.08);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbtn {
  flex: 1; background: none; border: none; font-size: 22px; padding: 6px 0;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbtn span { font-size: 11px; font-weight: 600; }
.tabbtn.active { color: var(--primary); }

/* ---------- cards ---------- */

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.card h2 .icon { font-size: 26px; }
.card-sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

.hello { font-size: 22px; font-weight: 800; margin: 4px 0 12px; }

/* challenge cards */
.ch-title { font-weight: 800; font-size: 17px; margin-bottom: 2px; }
.ch-desc { color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.ch-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 6px; }

.progressbar { background: #ede8f7; border-radius: 999px; height: 14px; overflow: hidden; }
.progressbar > div {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: width .4s ease; min-width: 0;
}
.progressbar > div.done { background: linear-gradient(90deg, #00c853, #00e676); }

.ch-done-badge {
  background: linear-gradient(135deg, #00c853, #00e676); color: #fff;
  font-weight: 800; font-size: 13px; padding: 5px 12px; border-radius: 999px;
  display: inline-block;
}

.everyone { margin-top: 10px; font-size: 13px; color: var(--muted); }
.everyone b.me-name { color: var(--primary); }

/* leaderboard */
.lb-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px;
  border-bottom: 1px solid #f0ecfa; font-size: 16px;
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { width: 26px; text-align: center; font-weight: 800; }
.lb-name { flex: 1; font-weight: 600; }
.lb-pts { font-weight: 800; color: #b28900; }
.lb-streak { font-size: 13px; color: var(--warn); }

/* log page */
.logtype-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.logtype-btn {
  border: 2px solid #e5ddf7; background: var(--card); border-radius: 16px;
  padding: 12px 6px; font-size: 15px; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink);
}
.logtype-btn .big-emoji { font-size: 30px; }
.logtype-btn.selected { border-color: var(--primary); background: #f4edff; }

.logentry-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 2px;
  border-bottom: 1px solid #f0ecfa; font-size: 15px;
}
.logentry-row:last-child { border-bottom: none; }
.logentry-row .le-emoji { font-size: 24px; }
.logentry-row .le-main { flex: 1; }
.logentry-row .le-note { color: var(--muted); font-size: 13px; }

.stepper { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 12px 0; }
.stepper button {
  width: 58px; height: 58px; border-radius: 50%; border: none;
  font-size: 30px; font-weight: 800; color: #fff; cursor: pointer;
}
.stepper button:active { transform: scale(.93); }
.step-minus { background: #ff8a80; }
.step-plus { background: var(--primary); }
.stepper .step-val { font-size: 34px; font-weight: 800; min-width: 90px; text-align: center; }

/* goals */
.goal-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.goal-row .progress-wrap { flex: 1; }

.goal-form-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.goal-form-row select, .goal-form-row input {
  padding: 12px; border-radius: 12px; border: 2px solid #e5ddf7;
  font-size: 15px; background: #faf8ff; color: var(--ink);
}
.goal-form-row input { width: 110px; }
.goal-form-row select.cat { flex: 1; }

/* badges */
.badge-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.badge { text-align: center; padding: 10px 4px; border-radius: 14px; font-size: 11px; }
.badge .b-emoji { font-size: 30px; display: block; margin-bottom: 4px; }
.badge.earned { background: #fff6d6; }
.badge.locked { opacity: .38; filter: grayscale(.9); }

/* history */
.hist-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.hist-cell {
  aspect-ratio: 1; border-radius: 10px; background: #ece7f8;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted);
}
.hist-cell.l1 { background: #d9c9f5; color: var(--ink); }
.hist-cell.l2 { background: #b39bff; color: #fff; }
.hist-cell.l3 { background: var(--primary); color: #fff; }
.hist-cell.today { outline: 2px solid var(--accent); }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 90px; background: #2b2638; color: #fff; padding: 12px 22px;
  border-radius: 999px; font-weight: 700; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 100;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: .96; }

.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 15px; }

.section-label { font-size: 13px; font-weight: 800; letter-spacing: .06em; color: var(--muted);
  text-transform: uppercase; margin: 18px 2px 8px; }

.profile-row { display: flex; gap: 8px; margin-bottom: 10px; }
.profile-row input { flex: 1; }
