:root {
  --bg: #F4F2FB;
  --surface: #FFFFFF;
  --surface-2: #F0EDFA;
  --text: #1E1B2E;
  --muted: #6B6880;
  --line: #E3DFF2;
  --primary: #6C4CF1;
  --primary-dark: #4F33C9;
  --flame: #FF8A00;
  --flame-dark: #D86F00;
  --mint: #1FC48D;
  --mint-dark: #139A6D;
  --red: #E5484D;
  --gold: #F5B301;
  --radius: 18px;
  --shadow: 0 2px 0 var(--line);
  --tabbar-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12101C; --surface: #1D1A2B; --surface-2: #262238; --text: #F2F0FA;
    --muted: #A5A1BC; --line: #332E4A; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12101C; --surface: #1D1A2B; --surface-2: #262238; --text: #F2F0FA;
  --muted: #A5A1BC; --line: #332E4A; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
img { max-width: 100%; }
a { color: var(--primary); font-weight: 800; }
a.btn { color: #fff; text-decoration: none; }
a.btn.ghost { color: var(--text); }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; min-height: 100%; position: relative; background: var(--bg); }
@media (min-width: 560px) {
  body { background: #E6E1F7; }
  .app { box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(40,20,120,.15); min-height: 100vh; }
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 2px solid var(--line);
}
.topbar .brand { font-weight: 900; font-size: 20px; color: var(--primary); margin-right: auto; letter-spacing: -.3px; }
.stat-pill { display: inline-flex; align-items: center; gap: 4px; font-weight: 900; font-size: 15px; padding: 4px 8px; border-radius: 999px; }
.stat-pill.flame { color: var(--flame); }
.stat-pill.flame.off { color: var(--muted); filter: grayscale(1); }
.stat-pill.xp { color: var(--primary); }
.stat-pill.freeze { color: #2F9BEA; }

.view { padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); outline: none; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px;
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface);
  border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20;
}
.tab { background: none; border: 0; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 800; color: var(--muted); cursor: pointer; }
.tab-ico { font-size: 22px; filter: grayscale(1); opacity: .6; transition: transform .15s; }
.tab.active { color: var(--primary); }
.tab.active .tab-ico { filter: none; opacity: 1; transform: translateY(-2px) scale(1.1); }

/* type */
h1 { font-size: 24px; font-weight: 900; margin: 4px 0 12px; letter-spacing: -.4px; }
h2 { font-size: 18px; font-weight: 900; margin: 22px 0 10px; }
h3 { font-size: 15px; font-weight: 800; margin: 0 0 6px; }
p { line-height: 1.5; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* cards */
.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.tight { padding: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* chunky buttons */
.btn {
  --c: var(--primary); --cd: var(--primary-dark);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 900; font-size: 15px; letter-spacing: .3px;
  background: var(--c); color: #fff; box-shadow: 0 4px 0 var(--cd); cursor: pointer;
  text-transform: uppercase; transition: transform .05s, box-shadow .05s; user-select: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--cd); }
.btn.block { width: 100%; }
.btn.mint { --c: var(--mint); --cd: var(--mint-dark); }
.btn.flame { --c: var(--flame); --cd: var(--flame-dark); }
.btn.ghost { --c: var(--surface); --cd: var(--line); color: var(--text); border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); }
.btn.danger { --c: var(--red); --cd: #B3363A; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--primary); font-weight: 800; cursor: pointer; padding: 4px; }

/* inputs */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 800; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, select.input {
  width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface-2); font-size: 16px; outline: none;
}
.input:focus { border-color: var(--primary); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; line-height: 1.4; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; margin-top: 1px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line); background: var(--surface); border-radius: 14px; padding: 10px 12px;
  font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 3px 0 var(--line);
}
.chip.on { border-color: var(--primary); color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); box-shadow: 0 3px 0 var(--primary); }

/* hero */
.hero { display: flex; align-items: center; gap: 14px; }
.hero .avatar { flex: none; }
.level-badge { font-size: 12px; font-weight: 900; color: #fff; background: var(--primary); border-radius: 999px; padding: 3px 9px; display: inline-block; }
.bar { height: 14px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 2px solid var(--line); }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #8B6CFF, var(--primary)); border-radius: 999px; transition: width .6s cubic-bezier(.2,.9,.3,1.2); }
.bar.mint > i { background: linear-gradient(90deg, #4FE0AE, var(--mint)); }
.bar.flame > i { background: linear-gradient(90deg, #FFC15A, var(--flame)); }

/* streak card */
.streak-card { background: linear-gradient(135deg, #FFB347, var(--flame)); color: #fff; border: 0; box-shadow: 0 4px 0 var(--flame-dark); }
.streak-card.cold { background: linear-gradient(135deg, #A9A5BD, #7F7B96); box-shadow: 0 4px 0 #5E5A75; }
.streak-num { font-size: 44px; font-weight: 900; line-height: 1; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.wday { text-align: center; font-size: 11px; font-weight: 800; opacity: .9; }
.wdot { width: 30px; height: 30px; margin: 4px auto 0; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.25); font-size: 14px; }
.wdot.done { background: #fff; color: var(--flame); }
.wdot.rest { background: #fff; color: #7C6BD6; }
.wdot.frozen { background: #CFEAFF; color: #2F9BEA; }
.wdot.today { outline: 3px solid #fff; outline-offset: 2px; }

/* quests */
.quest { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 2px solid var(--line); }
.quest:first-of-type { border-top: 0; }
.quest .q-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-size: 20px; flex: none; }
.quest.done .q-ico { background: var(--mint); }
.quest.done .q-title { text-decoration: line-through; color: var(--muted); }
.q-title { font-weight: 800; }
.q-xp { font-weight: 900; color: var(--primary); font-size: 13px; }

/* lists */
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 2px solid var(--line); }
.list-item:first-child { border-top: 0; }
.thumb { width: 48px; height: 48px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; font-size: 22px; }
.empty { text-align: center; padding: 22px 10px; color: var(--muted); }

/* activity picker */
.act { border: 2px solid var(--line); background: var(--surface); border-radius: 16px; padding: 12px 6px; text-align: center; cursor: pointer; font-weight: 800; font-size: 13px; box-shadow: 0 3px 0 var(--line); }
.act .e { font-size: 28px; display: block; margin-bottom: 4px; }
.act.on { border-color: var(--primary); box-shadow: 0 3px 0 var(--primary); color: var(--primary); }

/* nutrition */
.nutri { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 8px; color: #fff; font-weight: 900; text-transform: uppercase; font-size: 14px; }
.nutri.a { background: #038141; } .nutri.b { background: #85BB2F; } .nutri.c { background: #FECB02; color: #222; }
.nutri.d { background: #EE8100; } .nutri.e { background: #E63E11; } .nutri.unknown { background: #999; }
.nut-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.nut-table td { padding: 7px 0; border-top: 1px solid var(--line); }
.nut-table td:last-child { text-align: right; font-weight: 800; }
.macro { background: var(--surface-2); border-radius: 14px; padding: 10px; text-align: center; }
.macro b { display: block; font-size: 18px; font-weight: 900; }
.macro span { font-size: 12px; color: var(--muted); font-weight: 700; }

/* league */
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 14px; }
.lb-row.me { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); }
.lb-rank { width: 26px; text-align: center; font-weight: 900; color: var(--muted); }
.lb-rank.top { color: var(--gold); }
.lb-xp { font-weight: 900; }
.tag { font-size: 11px; font-weight: 900; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

/* skins + achievements */
.skin { border: 2px solid var(--line); border-radius: 16px; padding: 8px 4px; text-align: center; background: var(--surface); cursor: pointer; position: relative; box-shadow: 0 3px 0 var(--line); }
.skin.on { border-color: var(--primary); box-shadow: 0 3px 0 var(--primary); }
.skin.locked { cursor: default; }
.skin.locked svg { filter: grayscale(1) brightness(.6); opacity: .45; }
.skin .lock { position: absolute; top: 6px; right: 6px; font-size: 13px; }
.skin small { display: block; font-size: 11px; font-weight: 800; color: var(--muted); line-height: 1.2; margin-top: 2px; }
.skin b { font-size: 12px; }
.badge { text-align: center; padding: 10px 4px; border-radius: 16px; background: var(--surface-2); }
.badge .e { font-size: 30px; display: block; }
.badge b { font-size: 12px; display: block; line-height: 1.2; margin-top: 4px; }
.badge.locked { opacity: .4; filter: grayscale(1); }

/* sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,10,40,.5); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto; background: var(--surface); z-index: 50;
  border-radius: 24px 24px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  animation: up .25s cubic-bezier(.2,.9,.3,1);
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet-close { position: absolute; top: 12px; right: 14px; background: var(--surface-2); border: 0; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; cursor: pointer; }
@keyframes up { from { transform: translate(-50%, 100%); } }
@keyframes fade { from { opacity: 0; } }

/* scanner */
.scanbox { position: relative; border-radius: 18px; overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 52vh; width: 100%; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanbox .reticle { position: absolute; left: 10%; right: 10%; top: 38%; height: 24%; border: 3px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scanbox .laser { position: absolute; left: 12%; right: 12%; top: 50%; height: 2px; background: #FF4D6D; box-shadow: 0 0 10px #FF4D6D; animation: laser 1.6s ease-in-out infinite; }
@keyframes laser { 0%,100% { transform: translateY(-30px); } 50% { transform: translateY(30px); } }
.scan-status { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; color: #fff; font-weight: 800; font-size: 13px; text-shadow: 0 1px 3px #000; }

/* toasts */
.toasts { position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 800; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toastin .3s cubic-bezier(.2,.9,.3,1.3); display: flex; gap: 10px; align-items: center; }
.toast.xp { background: var(--primary); color: #fff; }
.toast.good { background: var(--mint); color: #fff; }
.toast.warn { background: var(--flame); color: #fff; }
@keyframes toastin { from { transform: translateY(-20px) scale(.9); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; width: 100%; height: 100%; }

/* onboarding */
.onboard { min-height: 100vh; padding: 28px 20px 40px; display: flex; flex-direction: column; }
.onboard .big-avatar { display: grid; place-items: center; margin: 10px 0 20px; }
.onboard h1 { font-size: 28px; text-align: center; }
.steps { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.steps i { width: 26px; height: 6px; border-radius: 3px; background: var(--line); }
.steps i.on { background: var(--primary); }
.info { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.info ul { margin: 6px 0 0; padding-left: 18px; }
.notice { border-left: 4px solid var(--primary); }
.notice.warm { border-left-color: var(--flame); }

.bob { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.pop { animation: pop .5s cubic-bezier(.2,.9,.3,1.6); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

.demo-bar { border: 2px dashed var(--line); border-radius: 16px; padding: 12px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
