:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --card-2: #f0f3f9;
  --text: #131a26;
  --muted: #5b6675;
  --line: #e2e7f0;
  --accent: #16a34a;
  --accent-2: #0ea5e9;
  --warn: #d97706;
  --danger: #dc2626;
  --ring-bg: #e6ebf3;
  --shadow: 0 6px 22px rgba(20, 30, 55, 0.08);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #131c2e;
    --card-2: #1b263b;
    --text: #eaf0fb;
    --muted: #93a1b8;
    --line: #24314a;
    --ring-bg: #24314a;
    --shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px 26px; width: 100%; max-width: 380px; text-align: center;
}
.logo-badge {
  width: 74px; height: 74px; border-radius: 20px; margin: 0 auto 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 34px;
}
.auth-card h1 { font-size: 22px; margin: 4px 0 2px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card-2); color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }
.btn {
  width: 100%; padding: 13px; border: none; border-radius: 12px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; transition: filter .15s;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- App shell ---------- */
.app { max-width: 620px; margin: 0 auto; padding: 0 16px 96px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 4px 8px;
}
.topbar .hello { font-size: 20px; font-weight: 700; }
.topbar .date { color: var(--muted); font-size: 13px; }
.xp-pill {
  display: inline-flex; align-items: center; gap: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
}
.xp-pill .fire { color: var(--warn); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 14px;
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.card h2 .muted { color: var(--muted); font-weight: 500; font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Rings */
.rings { display: flex; gap: 10px; justify-content: space-around; text-align: center; }
.ring { width: 92px; }
.ring svg { display: block; margin: 0 auto; }
.ring .lab { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ring .val { font-size: 13px; font-weight: 700; }

/* Task list */
.task {
  display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.task:last-child { border-bottom: none; }
.check {
  width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--line);
  background: var(--card-2); display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 18px; flex: 0 0 auto; transition: all .15s;
}
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.task .t-label { flex: 1; }
.task .t-sub { font-size: 12px; color: var(--muted); }

/* water */
.water-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* progress bar */
.bar { height: 10px; background: var(--ring-bg); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; }

/* food list */
.food-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.food-item:last-child { border-bottom: none; }
.food-item .x { color: var(--muted); background: none; border: none; font-size: 18px; padding: 4px 8px; }
.food-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.food-btn {
  text-align: left; border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  border-radius: 12px; padding: 10px 12px;
}
.food-btn b { display: block; font-size: 14px; }
.food-btn span { font-size: 12px; color: var(--muted); }

/* sport */
.sport-week { display: flex; gap: 8px; margin: 10px 0 4px; }
.sport-dot {
  flex: 1; height: 46px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--muted);
}
.sport-dot.done { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.sport-log { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.type-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* badges */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.badge {
  text-align: center; padding: 12px 6px; border-radius: 14px; background: var(--card-2); border: 1px solid var(--line);
  opacity: .4; filter: grayscale(1);
}
.badge.on { opacity: 1; filter: none; border-color: var(--accent); }
.badge .ic { font-size: 22px; }
.badge .nm { font-size: 11px; margin-top: 4px; }

/* chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; max-height: 52vh; overflow-y: auto; }
.msg { padding: 10px 14px; border-radius: 14px; max-width: 85%; font-size: 15px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--card-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; }
.chat-input input { flex: 1; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card-2); color: var(--text); }
.typing { color: var(--muted); font-size: 13px; font-style: italic; }

/* weight chart */
.chart { width: 100%; height: 170px; }

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--card);
  border-top: 1px solid var(--line); display: flex; justify-content: space-around;
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); z-index: 50;
}
.tabbar button {
  background: none; border: none; color: var(--muted); font-size: 11px; display: flex;
  flex-direction: column; align-items: center; gap: 3px; padding: 4px 10px; flex: 1;
}
.tabbar button .ic { font-size: 20px; }
.tabbar button.active { color: var(--accent); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
  max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; flex: 1; }
.pill-stat { display: flex; gap: 14px; }
.pill-stat .s { flex: 1; text-align: center; background: var(--card-2); border-radius: 12px; padding: 12px 6px; }
.pill-stat .s b { display: block; font-size: 20px; }
.pill-stat .s span { font-size: 12px; color: var(--muted); }
.reward { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.reward:last-child { border-bottom: none; }
.reward.reached b { color: var(--accent); }

/* Sticky terug-knop bovenaan subschermen (altijd bereikbaar, ook los van de onderbalk) */
.backbar {
  position: sticky; top: 0; z-index: 40;
  margin: 0 -16px 12px; padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.backbar .btn { width: auto; }
