:root {
  color-scheme: dark;
  --bg: #0a0a0d;
  --card: #15151b;
  --card-2: #1c1c24;
  --border: rgba(255, 255, 255, 0.06);
  --text: #f5f3fa;
  --hint: #8b8798;
  --subtitle: #a9a4b8;
  --accent: #a238ff;
  --accent-2: #c77dff;
  --accent-deep: #5b0fa8;
  --accent-text: #ffffff;
  --link: #c77dff;
  --header: #8b8798;
  --danger: #ff4d6d;
  --success: #3ddc97;
  --separator: rgba(255, 255, 255, 0.06);
  --soft: rgba(162, 56, 255, 0.14);
  --glow: 0 0 24px rgba(162, 56, 255, 0.45);
  --radius: 22px;
  --radius-sm: 14px;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 320px;
  background: radial-gradient(120% 90% at 50% -20%, rgba(162, 56, 255, 0.22), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

body.no-tabs #app { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }

h1, h2, h3 { margin: 0; }
button { font: inherit; color: inherit; }

svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.lg { width: 26px; height: 26px; }

.splash { display: flex; align-items: center; justify-content: center; min-height: 70vh; flex-direction: column; gap: 18px; }
.splash .logo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 28px rgba(162, 56, 255, 0.55);
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(162, 56, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Page headers ---------- */

.page-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 8px 4px 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--header);
  margin: 22px 6px 10px;
}

/* ---------- Home: top bar ---------- */

.topbar { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; }
.topbar .spacer { flex: 1; }

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--card); }
.icon-btn .dot {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg), var(--glow);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.pill .coin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: var(--glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}
.pill .plus {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--glow);
}

/* ---------- Home: profile ---------- */

.profile { text-align: center; margin-bottom: 18px; }
.ring {
  width: 92px;
  height: 92px;
  margin: 0 auto 10px;
  border-radius: 50%;
  padding: 5px;
  border: 2px dashed var(--accent);
  box-shadow: var(--glow);
  position: relative;
}
.ring .face {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-2), var(--accent-deep));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  overflow: hidden;
}
.ring .face img { width: 100%; height: 100%; object-fit: cover; }
.profile .name { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.profile .handle { color: var(--hint); font-size: 14px; margin-top: 2px; }
.profile .chip {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 16px; }
.stats .s { text-align: center; position: relative; padding: 2px 4px; cursor: default; }
.stats .s + .s::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18%;
  bottom: 18%;
  border-left: 1px solid var(--separator);
}
.stats .v { display: inline-flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats .v svg { color: var(--accent); filter: drop-shadow(0 0 6px rgba(162, 56, 255, 0.6)); }
.stats .k { color: var(--hint); font-size: 13px; margin-top: 2px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin-bottom: 14px; }
.day {
  background: var(--card);
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 10px 0 12px;
  text-align: center;
  min-width: 0;
}
.day .dots { height: 10px; display: flex; justify-content: center; gap: 3px; align-items: center; }
.day .dots i { width: 5px; height: 5px; border-radius: 50%; background: rgba(255, 255, 255, 0.28); display: block; }
.day .dots i.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.day .wd { color: var(--hint); font-size: 13px; margin-top: 6px; }
.day .dn { font-size: 16px; font-weight: 700; margin-top: 2px; }
.day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(162, 56, 255, 0.35), var(--glow); }
.day.today .wd { color: var(--text); }
.day.future { opacity: 0.45; }

/* ---------- Home: feature cards ---------- */

.feature-row { display: grid; grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr); gap: 10px; margin-bottom: 10px; }

.fcard {
  position: relative;
  border: 0;
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 118px;
  overflow: hidden;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.12s ease;
}
.fcard:active { transform: scale(0.98); }
.fcard .t { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; position: relative; z-index: 1; }
.fcard .d { font-size: 13px; color: var(--subtitle); margin-top: 6px; position: relative; z-index: 1; max-width: 70%; }
.fcard .accent { color: var(--accent-2); font-weight: 700; }

.fcard.small { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; text-align: center; }
.fcard.small .t { font-size: 16px; }
.fcard.small .d { max-width: none; margin-top: 2px; }
.fcard.small .bubble {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-2);
  color: var(--accent-2);
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 2px rgba(162, 56, 255, 0.35);
  font-size: 18px;
  font-weight: 800;
}

.fcard.hero {
  background:
    radial-gradient(90% 120% at 100% 0%, rgba(199, 125, 255, 0.35), transparent 60%),
    linear-gradient(135deg, #2a0f45 0%, #150a22 70%);
}
.fcard.hero .mark {
  position: absolute;
  right: -6px;
  bottom: -14px;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  object-fit: cover;
  filter: blur(2px) brightness(0.4);
}

.fcard.wide {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 96px;
  width: 100%;
  margin-bottom: 10px;
  padding: 0 16px 0 0;
  background: linear-gradient(90deg, rgba(162, 56, 255, 0.28), var(--card) 46%);
}
.fcard.wide .art {
  width: 120px;
  align-self: stretch;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  border-radius: var(--radius) 60px 60px var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  box-shadow: var(--glow);
}
.fcard.wide .art svg { width: 44px; height: 44px; }
.fcard.wide .d { max-width: none; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qbtn {
  border: 0;
  background: var(--card);
  border-radius: 18px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  min-height: 58px;
}
.qbtn:active { transform: scale(0.98); }
.qbtn .ic {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--soft);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: rgba(14, 14, 18, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .inner { max-width: 560px; margin: 0 auto; display: flex; height: var(--tabbar-h); }
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.tab.active { color: var(--accent-2); }
.tab.active::before {
  content: "";
  position: absolute;
  top: -1px;
  width: 34px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--accent);
  box-shadow: var(--glow);
}
.tab.active svg { filter: drop-shadow(0 0 6px rgba(162, 56, 255, 0.7)); }

/* ---------- Cards & lists ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.card.pad { padding: 16px 18px; }

.list { margin: 0; padding: 0; list-style: none; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  min-height: 52px;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  border-top: 1px solid var(--separator);
}
.row.clickable { cursor: pointer; }
.row.clickable:active { background: rgba(255, 255, 255, 0.03); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .subtitle { font-size: 13px; color: var(--hint); margin-top: 2px; }
.row .value { font-weight: 700; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.row .value.neg { color: var(--danger); }
.row .value.pos { color: var(--success); }
.row .chev { color: var(--hint); display: flex; }
.row .ic {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--soft);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.row .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  font-size: 16px;
  background: linear-gradient(145deg, var(--accent-2), var(--accent-deep));
}
.row .rank { width: 30px; text-align: center; font-size: 18px; font-weight: 800; color: var(--hint); }

.kv { padding: 2px 0; }
.kv .row { min-height: 44px; padding-top: 10px; padding-bottom: 10px; }
.kv .row .title { font-weight: 500; color: var(--subtitle); white-space: normal; }
.kv .row .subtitle { font-size: 12px; color: var(--hint); }
.kv .row .value { white-space: normal; max-width: 62%; overflow-wrap: anywhere; }
.kv .row.total .title { color: var(--text); font-weight: 700; }
.kv .row.total .value { font-size: 18px; color: var(--accent-2); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 16px 4px; }
.card-head .title { font-weight: 800; font-size: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--soft);
  color: var(--accent-2);
  white-space: nowrap;
}
.badge.green { background: rgba(61, 220, 151, 0.14); color: var(--success); }
.badge.red { background: rgba(255, 77, 109, 0.14); color: var(--danger); }
.badge.gray { background: rgba(255, 255, 255, 0.07); color: var(--hint); }

.note { font-size: 13px; color: var(--hint); padding: 0 16px 14px; }

.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 14px;
  background: rgba(255, 184, 0, 0.1);
  border: 1px solid rgba(255, 184, 0, 0.18);
}
.banner.error { background: rgba(255, 77, 109, 0.1); border-color: rgba(255, 77, 109, 0.2); }
.banner.info { background: var(--soft); border-color: rgba(162, 56, 255, 0.25); }

.empty { text-align: center; color: var(--hint); padding: 40px 20px; }
.empty .big { font-size: 44px; margin-bottom: 10px; }

/* ---------- Forms ---------- */

form { margin: 0; }
.field { padding: 13px 16px; }
.field + .field { border-top: 1px solid var(--separator); }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 2px 0;
}
.field input::placeholder, .field textarea::placeholder { color: #5d5968; }
.field textarea { resize: vertical; min-height: 96px; }
.field select { appearance: none; -webkit-appearance: none; }
.field select option { background: var(--card); color: var(--text); }
.field .help { font-size: 12px; color: var(--hint); margin-top: 6px; }
.card:focus-within { border-color: rgba(162, 56, 255, 0.45); }

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  border-radius: 16px;
  padding: 15px 16px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #7b1fe0);
  color: #fff;
  box-shadow: 0 8px 24px rgba(162, 56, 255, 0.35);
  transition: opacity 0.15s ease, transform 0.12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; pointer-events: none; }
.btn.secondary { background: var(--card-2); color: var(--accent-2); box-shadow: none; border: 1px solid rgba(162, 56, 255, 0.25); }
.btn.danger { background: rgba(255, 77, 109, 0.12); color: var(--danger); box-shadow: none; }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; border-radius: 11px; }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; border-color: rgba(255, 255, 255, 0.3); border-top-color: currentColor; }

.actions { display: grid; gap: 10px; margin: 16px 0 12px; }
.actions.two { grid-template-columns: 1fr 1fr; }

.segmented {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--subtitle);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: var(--glow); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: 18px; padding: 12px 14px; border: 1px solid var(--border); }
.stat .k { font-size: 12px; color: var(--hint); }
.stat .v { font-size: 18px; font-weight: 800; margin-top: 2px; }

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--card) 0%, #22202b 50%, var(--card) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  margin-bottom: 12px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px);
  background: #24202e;
  border: 1px solid rgba(162, 56, 255, 0.35);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 77, 109, 0.5); }

.help-text p { margin: 0 0 10px; }
.help-text ul { margin: 0 0 12px; padding-left: 20px; color: var(--subtitle); }
.help-text li { margin-bottom: 6px; }

.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--hint); }
