:root {
  --bg: #0d0f12;
  --surface: #161a1f;
  --surface2: #1e232a;
  --line: #2a3038;
  --text: #eef1f4;
  --muted: #8b95a1;
  --accent: #c6f432;
  --accent-ink: #0d0f12;
  --ghost: #a08cff;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --r: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100dvh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h2 { font-size: 20px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(13, 15, 18, .86);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.brand svg { width: 28px; height: 28px; }

main { max-width: 560px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px; margin-bottom: 14px;
}
.card.flush { padding: 0; overflow: hidden; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 999px; font-weight: 700;
  background: var(--surface2); border: 1px solid var(--line);
  transition: transform .12s, background .2s;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--bad); color: #fff; border-color: transparent; }
.btn.sm { padding: 8px 14px; font-size: 14px; }
.btn.lg { flex: 1; padding: 16px; font-size: 17px; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface2); border: 1px solid var(--line);
}
.link { display: block; margin: 8px auto 24px; color: var(--muted); text-decoration: underline; font-size: 13px; }
.icon-btn { margin-left: auto; font-size: 18px; opacity: .45; padding: 4px 6px; border-radius: 8px; }
.icon-btn.on { opacity: 1; }
.select {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  background: var(--surface2); border: 1px solid var(--line);
}

/* Promo */
.promo {
  display: flex; gap: 14px; align-items: flex-start;
  background: linear-gradient(135deg, #1d1838, #161a1f 70%);
  border-color: #3a3166;
}
.promo-ghost { font-size: 40px; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px) rotate(-4deg); } }
.promo p { color: #c9c3e8; margin: 6px 0 12px; font-size: 14px; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ghost); background: rgba(160, 140, 255, .14); padding: 2px 8px; border-radius: 6px; margin-bottom: 4px;
}

/* Feed activity */
.act-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.act-head small { display: block; color: var(--muted); font-size: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 800; color: #0d0f12;
}
.avatar.big { width: 64px; height: 64px; font-size: 26px; }
.act h3 { font-size: 18px; margin-bottom: 8px; }
.act-stats { display: flex; gap: 22px; margin-bottom: 12px; }
.act-stats small { display: block; color: var(--muted); font-size: 12px; }
.act-stats b { font-size: 17px; }
canvas.mini { display: block; width: 100%; height: 150px; border-radius: 12px; background: #11151a; }
.act-foot { display: flex; gap: 8px; margin-top: 12px; }
.kudos, .race {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); font-weight: 600; font-size: 14px;
  position: relative;
}
.kudos.on { background: rgba(198, 244, 50, .14); border-color: var(--accent); color: var(--accent); }
.kudos:disabled { opacity: .6; cursor: default; }
.kudos.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.18); } }
.race { margin-left: auto; color: var(--ghost); border-color: #3a3166; }
.float-emoji { position: absolute; left: 12px; top: 0; pointer-events: none; animation: rise .8s ease-out forwards; }
@keyframes rise { to { transform: translateY(-40px) scale(1.4); opacity: 0; } }
.badge { display: inline-block; font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 8px; margin-bottom: 10px; }
.badge.win { background: rgba(61, 220, 151, .14); color: var(--good); }
.badge.lose { background: rgba(160, 140, 255, .14); color: var(--ghost); }

/* Record */
.map-wrap { position: relative; }
#recMap { display: block; width: 100%; height: 260px; background: #11151a; }
.map-overlay { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; justify-content: space-between; }
.seg { display: inline-flex; background: rgba(13, 15, 18, .8); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface2); color: var(--text); }
.seg button:disabled { opacity: .5; }
.rec-state {
  position: absolute; bottom: 10px; left: 10px; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; background: rgba(13, 15, 18, .8); border: 1px solid var(--line);
}
.rec-state.live::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 6px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat span { display: block; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat label { font-size: 12px; color: var(--muted); }
.stat.big { grid-column: 1 / -1; text-align: center; }
.stat.big span { font-size: 48px; }

.ghost-panel { border-color: #3a3166; }
.ghost-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-weight: 700; }
.ghost-ico { font-size: 20px; }
#ghostInfo { margin-top: 8px; }
.ghost-live { margin-top: 12px; }
.track { position: relative; padding: 6px 28px 6px 0; }
.lane { position: relative; height: 22px; margin: 4px 0; border-radius: 999px; background: var(--surface2); }
.dot {
  position: absolute; top: 50%; left: 0; width: 22px; height: 22px; margin-left: -11px; transform: translateY(-50%);
  border-radius: 50%; transition: left .6s linear; display: grid; place-items: center; font-size: 12px;
}
.dot.me { background: var(--accent); box-shadow: 0 0 12px rgba(198, 244, 50, .6); }
.dot.ghost { background: var(--ghost); opacity: .85; box-shadow: 0 0 12px rgba(160, 140, 255, .6); }
.dot.ghost::after { content: "👻"; }
.flag { position: absolute; right: 0; top: 50%; transform: translateY(-50%); font-size: 18px; }
.gap { text-align: center; font-weight: 800; font-size: 20px; margin-top: 8px; font-variant-numeric: tabular-nums; transition: color .3s; }
.gap.ahead { color: var(--good); }
.gap.behind { color: var(--ghost); }

.controls { display: flex; gap: 10px; margin-bottom: 20px; }

/* You */
.profile { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.goal { display: flex; align-items: center; gap: 16px; position: relative; }
.ring { width: 110px; height: 110px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring-bg { stroke: var(--surface2); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .8s ease; }
.ring-label { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 110px; text-align: center; }
.ring-label b { display: block; font-size: 22px; }
.ring-label small { color: var(--muted); font-size: 11px; }
.goal-text h3 { margin-bottom: 4px; }
.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.inline input { width: 70px; padding: 6px 8px; border-radius: 8px; background: var(--surface2); border: 1px solid var(--line); }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 130px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar i { display: block; width: 100%; border-radius: 6px 6px 3px 3px; background: var(--accent); min-height: 3px; transition: height .6s ease; }
.bar.zero i { background: var(--surface2); }
.bar small { font-size: 11px; color: var(--muted); }
.bar em { font-style: normal; font-size: 10px; color: var(--muted); }

.quests { list-style: none; display: grid; gap: 12px; }
.quests li { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; }
.q-ico { font-size: 22px; text-align: center; }
.q-title { font-weight: 700; font-size: 14px; }
.q-bar { height: 6px; border-radius: 999px; background: var(--surface2); margin-top: 6px; overflow: hidden; }
.q-bar i { display: block; height: 100%; background: var(--ghost); border-radius: 999px; transition: width .6s; }
.quests li.done .q-bar i { background: var(--good); }
.q-num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.quests li.done .q-num { color: var(--good); font-weight: 700; }

.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.totals b { display: block; font-size: 22px; }
.totals span { font-size: 12px; color: var(--muted); }

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(13, 15, 18, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tabbar svg .fill { fill: currentColor; }
.tabbar button.active { color: var(--accent); }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Dialog */
dialog {
  margin: auto; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--text);
  width: min(420px, calc(100% - 32px)); padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { padding: 20px; display: grid; gap: 14px; }
.dlg label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.dlg input { padding: 11px 12px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--line); color: var(--text); }
.dlg .row { display: flex; gap: 10px; justify-content: flex-end; }
.dlg-summary { display: flex; gap: 18px; flex-wrap: wrap; }
.dlg-summary div small { display: block; font-size: 12px; color: var(--muted); }
.dlg-summary b { font-size: 17px; }

/* Confetti */
.confetti { position: fixed; top: -10px; width: 8px; height: 14px; z-index: 40; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
