:root {
  --bg: #FAF8F5;
  --surface: #FFFFFF;
  --ink: #2D2D3A;
  --muted: #6B6B7B;
  --primary: #6C5CE7;
  --primary-d: #5A4BD4;
  --primary-soft: #F0EEFC;
  --coral: #FF6B6B;
  --mint: #1DD1A1;
  --sun: #FECA57;
  --sky: #54A0FF;
  --radius: 16px;
  --radius-sm: 10px;
  --pill: 999px;
  --shadow: 0 6px 20px rgba(45,45,58,.08);
  --shadow-sm: 0 2px 8px rgba(45,45,58,.06);
  --space: 16px;
}

@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/nunito-regular.54ef89211626.woff2") format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("../fonts/nunito-extrabold.a28521c77f4a.woff2") format('woff2');
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  padding-bottom: 84px;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 760px; margin: 0 auto; padding: var(--space); }
h1 { font-weight: 800; font-size: 1.7rem; margin: .1em 0 .6em; }
h2, h3 { font-weight: 800; margin: .4em 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted, .label { color: var(--muted); }
.label { font-size: .8rem; }
hr { border: none; border-top: 1px solid #eee; margin: 18px 0; }

/* ---- cards ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---- buttons ----
   Base uses :where() (zero specificity) so submit buttons get the look
   automatically, while modifier classes (.btn-sm/.btn-danger/...) always win.
   Links styled as buttons need the explicit .btn class for the base. */
:where(.btn, button[type=submit], input[type=submit]) {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: #fff; border: none;
  border-radius: var(--pill); padding: 12px 20px;
  font-family: inherit; font-weight: 800; font-size: 1rem;
  cursor: pointer; min-height: 48px; box-shadow: var(--shadow-sm);
  transition: transform .05s ease, background .15s ease; text-decoration: none;
}
:where(.btn, button[type=submit], input[type=submit]):hover { background: var(--primary-d); text-decoration: none; }
:where(.btn, button[type=submit], input[type=submit]):active { transform: translateY(1px); }
.btn-sm { padding: 8px 14px; min-height: 38px; font-size: .85rem; }
.btn-ghost { background: var(--primary-soft); color: var(--primary); box-shadow: none; }
.btn-danger { background: var(--coral); }
.btn-success { background: var(--mint); }
.btn-block { width: 100%; }

/* ---- forms ---- */
form p { margin: 0 0 14px; }
label { font-weight: 700; display: block; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=email],
input[type=time], input[type=datetime-local], input[type=search], textarea, select {
  width: 100%; padding: 12px 14px; border: 2px solid #ECECEC;
  border-radius: var(--radius-sm); font-family: inherit; font-size: 1rem;
  background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,92,231,.15);
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
input[type=color] { width: 48px; height: 38px; padding: 2px; border-radius: var(--radius-sm); border: 2px solid #ECECEC; }
input[type=file] { font-size: .9rem; }
textarea { min-height: 72px; }

/* ---- pills / badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: var(--pill); font-size: .72rem; font-weight: 800; color: #fff; }
.badge-photo { background: var(--sky); }
.badge-trust { background: var(--mint); }
.badge-time  { background: var(--sun); color: #5A4A10; }
.badge-value { background: var(--coral); }
.points-pill { background: var(--primary-soft); color: var(--primary); font-weight: 800; border-radius: var(--pill); padding: 3px 12px; font-size: .85rem; white-space: nowrap; }

/* ---- top tab bar ---- */
nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: 68px;
  display: flex; justify-content: space-around; align-items: center;
  background: #fff; border-top: 1px solid #eee;
  box-shadow: 0 -4px 16px rgba(45,45,58,.05); z-index: 50;
}
nav.tabbar a, nav.tabbar form { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 0; }
nav.tabbar a { color: var(--muted); font-size: .68rem; font-weight: 700; text-decoration: none; }
nav.tabbar a.active { color: var(--primary); }
nav.tabbar .ico { font-size: 1.35rem; line-height: 1; }
nav.tabbar button {
  background: none; border: none; font-family: inherit; font-size: .68rem; font-weight: 700;
  color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px;
}

/* ---- home: greeting + points banner ---- */
.points-banner { background: linear-gradient(135deg, var(--primary), #8E7BFF); color: #fff; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.points-banner .big { font-size: 2.1rem; font-weight: 800; line-height: 1; }
.points-banner .label { color: rgba(255,255,255,.85); }
.greet { font-weight: 800; font-size: 1.4rem; margin: 0 0 10px; }

/* ---- challenge cards ---- */
.challenge.done { background: #EAFFF6; box-shadow: var(--shadow-sm); }
.challenge-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.challenge-title { font-weight: 800; font-size: 1.05rem; }
.challenge-meta { margin: 6px 0; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.challenge-done { color: var(--mint); font-weight: 800; font-size: 1.05rem; }
.challenge-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0 0; }
.challenge-form input[type=number] { width: 110px; }
.err { color: var(--coral); font-weight: 700; margin-top: 8px; }

/* ---- leaderboard ---- */
table.board { width: 100%; border-collapse: collapse; }
table.board td { padding: 11px 8px; border-top: 1px solid #F0EEF0; vertical-align: middle; }
table.board tr:first-child td { border-top: none; }
.rank-badge { display: inline-flex; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 800; align-items: center; justify-content: center; font-size: .82rem; }
.rank-1 .rank-badge { background: var(--sun); color: #5A4A10; }
.rank-2 .rank-badge { background: #E3E3EA; color: #4a4a55; }
.rank-3 .rank-badge { background: #F6C89A; color: #6a3d12; }
.lb-name { font-weight: 800; }
.lb-score { text-align: right; font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.view-toggle { display: inline-block; margin-bottom: 10px; }

/* ---- profile ---- */
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar-ring { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary); background: #eee; }
.avatar-lg { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 4px solid var(--primary); background: #eee; }
.total-big { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.breakdown { width: 100%; }
.breakdown td { padding: 6px 0; border-top: 1px solid #f3f1f3; }
.chip { display: inline-block; background: var(--primary-soft); color: var(--primary); border-radius: var(--pill); padding: 4px 12px; font-weight: 800; font-size: .85rem; margin: 3px 4px 3px 0; }

/* ---- history ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.history { width: 100%; border-collapse: collapse; }
table.history th { text-align: left; font-size: .78rem; color: var(--muted); padding: 6px 8px; }
table.history td { padding: 10px 8px; border-top: 1px solid #F0EEF0; vertical-align: middle; }
.hist-thumb { height: 46px; border-radius: 10px; display: block; }

/* ---- auth card ---- */
.auth { max-width: 380px; margin: 7vh auto; }
.auth .brand { text-align: center; font-size: 2.6rem; margin-bottom: 4px; }
.auth h1 { text-align: center; }

/* ---- messages / toasts ---- */
.messages { position: fixed; top: 12px; left: 0; right: 0; display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 100; pointer-events: none; padding: 0 12px; }
.toast { background: #fff; border-radius: var(--pill); padding: 10px 18px; box-shadow: var(--shadow); font-weight: 700; border-left: 5px solid var(--primary); max-width: 90%; }
.toast.error { border-color: var(--coral); }
.toast.success { border-color: var(--mint); }

/* ---- misc ---- */
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .emoji { font-size: 2.2rem; display: block; margin-bottom: 6px; }
.row-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.stack > * + * { margin-top: 10px; }
