:root {
  --bg: #f4f3fb;
  --card: #ffffff;
  --card-2: #f0eefc;
  --text: #17142b;
  --muted: #6b6785;
  --line: #e4e1f3;
  --brand: #6d5efc;
  --brand-2: #ff5fa2;
  --brand-ink: #ffffff;
  --good: #14a86b;
  --warn: #f08a24;
  --bad: #e5484d;
  --gold: #f5b301;
  --silver: #a3a9b8;
  --bronze: #cd7f4a;
  --shadow: 0 1px 2px rgba(23, 20, 43, .05), 0 8px 24px rgba(23, 20, 43, .06);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0d1c;
    --card: #1a1730;
    --card-2: #241f40;
    --text: #f3f1ff;
    --muted: #a19cc2;
    --line: #2d2850;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0d1c; --card: #1a1730; --card-2: #241f40; --text: #f3f1ff; --muted: #a19cc2; --line: #2d2850;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Outfit", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px;
}
.top h1 { font-size: 24px; line-height: 1.15; margin: 0; font-weight: 800; letter-spacing: -.02em; }
.top .sub { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 17px; margin: 0 0 10px; font-weight: 700; letter-spacing: -.01em; }
.card h3 { font-size: 15px; margin: 14px 0 6px; }
.card p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--brand) 0%, #8f6bff 45%, var(--brand-2) 100%);
  color: #fff; border-radius: 24px; padding: 18px; margin-bottom: 14px;
  display: flex; gap: 16px; align-items: center; box-shadow: 0 12px 30px rgba(109, 94, 252, .35);
}
.hero .ring { flex: none; width: 108px; height: 108px; position: relative; }
.hero .ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.hero .ring .center {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.05;
}
.hero .ring .pct { font-size: 22px; font-weight: 800; }
.hero .ring .lbl { font-size: 11px; opacity: .85; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.hero .meta { font-size: 13px; opacity: .92; margin-top: 6px; }
.hero .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.hero .chip { background: rgba(255, 255, 255, .2); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }

/* ---------- Segmented ---------- */
.seg {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px;
  background: var(--card-2); border-radius: 14px; margin-bottom: 12px;
}
.seg button {
  border: 0; background: transparent; border-radius: 10px; padding: 8px 0; font-weight: 600; font-size: 14px;
  cursor: pointer; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Leaderboard ---------- */
.lb { list-style: none; margin: 0; padding: 0; }
.lb li {
  display: grid; grid-template-columns: 28px 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.lb li:last-child { border-bottom: 0; }
.lb li.me { background: var(--card-2); border-radius: 14px; border-bottom-color: transparent; padding-left: 8px; padding-right: 8px; margin: 2px -4px; }
.rank { font-weight: 800; text-align: center; color: var(--muted); }
.rank.r1 { color: var(--gold); } .rank.r2 { color: var(--silver); } .rank.r3 { color: var(--bronze); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 21px; flex: none;
  background: color-mix(in srgb, var(--c, var(--brand)) 22%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c, var(--brand)) 60%, transparent);
}
.avatar.lg { width: 64px; height: 64px; font-size: 34px; }
.who { min-width: 0; }
.who .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .tags { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.bar { height: 6px; background: var(--card-2); border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--c, var(--brand)); }
.score { text-align: right; font-weight: 800; font-size: 17px; }
.score small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }

/* ---------- Feature cards ---------- */
.forfeit { border: 2px dashed color-mix(in srgb, var(--bad) 45%, transparent); }
.forfeit .loser { font-size: 20px; font-weight: 800; }
.journey .track { position: relative; height: 14px; background: var(--card-2); border-radius: 99px; margin: 14px 0 6px; }
.journey .track > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.journey .walker { position: absolute; top: 50%; transform: translate(-50%, -58%); font-size: 22px; }
.teams-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.teams-table td, .teams-table th { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.teams-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.teams-table td:last-child, .teams-table th:last-child { text-align: right; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card-2); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 18px; font-weight: 800; }
.stat span { font-size: 11px; color: var(--muted); }

.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.badge { background: var(--card-2); border-radius: 14px; padding: 10px 6px; text-align: center; font-size: 12px; line-height: 1.2; }
.badge .e { font-size: 28px; display: block; margin-bottom: 4px; }
.badge.locked { opacity: .38; filter: grayscale(1); }
.badge small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }

.chart { width: 100%; height: 150px; display: block; }
.chart .goal { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=url], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px;
  font-size: 16px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.big-input { font-size: 32px !important; font-weight: 800; text-align: center; letter-spacing: .02em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 700; cursor: pointer; text-decoration: none;
  background: var(--brand); color: var(--brand-ink); font-size: 16px; min-height: 48px;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--text); }
.btn.danger { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.btn.sm { padding: 8px 12px; min-height: 36px; font-size: 14px; border-radius: 11px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.picker button {
  aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; background: var(--card-2);
  font-size: 22px; cursor: pointer; padding: 0;
}
.picker button[aria-pressed="true"] { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 15%, transparent); }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches button { width: 100%; aspect-ratio: 1; max-width: 38px; justify-self: center; border-radius: 50%; border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--text); }
.toggle { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.toggle button { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 0; font-weight: 600; cursor: pointer; }
.toggle button[aria-pressed="true"] { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }

/* ---------- Setup guide ---------- */
.steps-list { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps-list > li { counter-increment: s; position: relative; padding: 0 0 14px 40px; }
.steps-list > li::before {
  content: counter(s); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.steps-list b { font-weight: 700; }
.copybox {
  display: flex; gap: 6px; align-items: center; background: var(--card-2); border-radius: 12px; padding: 6px; margin: 8px 0;
}
.copybox code { flex: 1; min-width: 0; font-size: 12px; padding: 6px 8px; overflow-wrap: anywhere; font-family: ui-monospace, Menlo, Consolas, monospace; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--card-2); }
.pill.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.callout { background: color-mix(in srgb, var(--brand) 10%, transparent); border-radius: 14px; padding: 12px; font-size: 14px; margin: 10px 0; }
.tabs-mini { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }

/* ---------- Welcome ---------- */
.welcome { text-align: center; padding-top: 6vh; }
.welcome .logo { width: 96px; height: 96px; border-radius: 26px; margin: 0 auto 14px; display: block; box-shadow: 0 12px 30px rgba(109, 94, 252, .35); }
.welcome h1 { font-size: 34px; margin: 0; font-weight: 800; letter-spacing: -.03em; }
.welcome p.lead { color: var(--muted); margin: 6px 0 24px; }
.feature-list { text-align: left; display: grid; gap: 10px; margin: 0 0 20px; }
.feature-list div { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.feature-list .e { font-size: 24px; }

/* ---------- Bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
}
.nav .inner { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.nav button {
  border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 0; cursor: pointer;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--brand); }

/* ---------- Sheet & toast ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 8, 25, .5); display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet .panel {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto;
  border-radius: 24px 24px 0 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .2s ease-out;
}
.sheet.still, .sheet.still .panel { animation: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px); transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
.install-banner { display: flex; gap: 10px; align-items: center; }
.install-banner .e { font-size: 26px; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 16px; width: max-content; margin: 8px auto; }
.empty { text-align: center; padding: 20px 8px; color: var(--muted); }
.empty .e { font-size: 40px; display: block; }
@media (max-width: 360px) {
  .hero { flex-direction: column; text-align: center; }
  .hero .chips { justify-content: center; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
