:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e6e9ef;
  --brand: #2f6fed;
  --brand-ink: #1b4fc0;
  --brand-soft: #eaf1ff;
  --gold: #e0a92b;
  --gold-soft: #fbf1d8;
  --danger: #d8453b;
  --ok: #2f9e6b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20,30,60,.05), 0 10px 30px rgba(20,30,60,.06);
  --shadow-lg: 0 12px 40px rgba(47,111,237,.18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 60% at 50% -10%, #dce8ff 0%, rgba(220,232,255,0) 60%),
    var(--bg);
}

.view { display: none; padding-top: 20px; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Auth ---------- */
#auth-view { position: relative; overflow: hidden; min-height: 100vh; }
.auth-bg {
  position: absolute; inset: 0; z-index: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: .3; pointer-events: none;
}
.auth-bg svg { width: 118%; height: auto; max-height: 100%; }
.auth-card { position: relative; z-index: 1; margin-top: 7vh; text-align: center; }
.brand { margin-bottom: 20px; }
.logo {
  width: 76px; height: 76px; border-radius: 22px;
  background: linear-gradient(160deg, #4f8bff, #2f6fed);
  color: #fff; font-size: 38px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px; box-shadow: var(--shadow-lg);
}
.brand h1 { margin: 0; font-size: 27px; font-weight: 700; letter-spacing: 3px; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.tabs { display: flex; gap: 8px; margin: 18px 0; }
.tab {
  flex: 1; padding: 13px; border: 1px solid var(--line);
  background: var(--surface); border-radius: 14px;
  font-size: 16px; color: var(--muted); cursor: pointer;
  transition: .15s;
}
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-lg); }

/* ---------- Forms ---------- */
#auth-form { display: flex; flex-direction: column; gap: 12px; }
input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%; padding: 16px 14px; font-size: 17px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--ink);
  appearance: none; -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'><path d='M3 5l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none'/></svg>");
  background-repeat: no-repeat; background-position: right 16px center;
  padding-right: 42px;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

.msg { min-height: 18px; margin: 2px 2px; font-size: 14px; color: var(--danger); text-align: left; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 14px;
  padding: 13px 18px; font-size: 16px; cursor: pointer; transition: .12s;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-lg); }
.btn.primary.big { width: 100%; padding: 17px; font-size: 18px; font-weight: 600; margin-top: 6px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 8px 10px; font-weight: 500; }
.btn:active { transform: scale(.97); }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.who { display: flex; align-items: center; gap: 10px; }
.uname { font-weight: 700; font-size: 18px; }
.link { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 4px 6px; }
.link:active { color: var(--danger); }

/* ---------- Hero ---------- */
.hero {
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(135deg, #ffffff, #f4f8ff);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.level-badge {
  flex: none; width: 92px; height: 92px; border-radius: 26px;
  background: linear-gradient(160deg, #5a5f6b, #33373f); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; text-align: center; line-height: 1.25;
  padding: 8px; box-shadow: 0 8px 22px rgba(20,30,60,.18);
}
.hero-info { flex: 1; min-width: 0; }
.hero-score { display: flex; align-items: baseline; gap: 8px; }
.hero-score b { font-size: 40px; font-weight: 800; letter-spacing: .5px; }
.hero-score span { color: var(--muted); font-size: 14px; }
.hero-per { margin-top: 6px; font-size: 14px; color: var(--muted); }
.hero-per b { color: var(--brand-ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.pc-head, .quota-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.pc-next { color: var(--brand-ink); font-weight: 600; }
.pc-foot { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ---------- Progress ---------- */
.progress { height: 12px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.bar { height: 100%; width: 0%; background: var(--brand); border-radius: 999px; transition: width .45s ease; }
.bar.gold { background: linear-gradient(90deg, #f3c969, #e0a92b); }

.quota-hint { margin: 10px 0 0; font-size: 13px; }
.quota-hint.ok { color: var(--ok); }
.quota-hint.danger { color: var(--danger); }

/* ---------- Field & stepper ---------- */
.field-label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 8px; font-weight: 500; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper input {
  flex: 1; text-align: center; font-size: 22px; font-weight: 700;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step-btn {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 26px; font-weight: 600; color: var(--brand); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.step-btn:active { background: var(--brand-soft); }

/* ---------- Result banner ---------- */
.result-banner {
  margin-top: 14px; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, #3b82f6, #2f6fed); color: #fff;
  text-align: center; box-shadow: var(--shadow-lg);
}
.result-banner.hidden { display: none; }
.result-banner .big-num { font-size: 34px; font-weight: 800; }
.result-banner .sub { font-size: 14px; opacity: .92; margin-top: 6px; }
.result-banner .sub.strong { font-weight: 700; opacity: 1; margin-top: 8px; }
.result-banner.levelup { background: linear-gradient(135deg, #f0b53a, #e0a92b); color: #3a2c05; }
.result-banner.pop { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.9); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }

/* ---------- Leaderboard ---------- */
.board-title { margin: 0; font-size: 19px; font-weight: 700; }
.board-date { color: var(--muted); font-size: 13px; }
.board-list { display: flex; flex-direction: column; gap: 10px; }
.board-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 13px 15px; box-shadow: var(--shadow);
}
.rank {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: #eef0f4; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.rank.top1 { background: linear-gradient(160deg,#f7d774,#e7b53b); color: #5a4410; }
.rank.top2 { background: linear-gradient(160deg,#dde3ec,#b9c2cf); color: #3a4250; }
.rank.top3 { background: linear-gradient(160deg,#ecc79c,#d3a06a); color: #5a3a17; }
.b-row-main { flex: 1; min-width: 0; }
.b-name { font-weight: 700; font-size: 16px; }
.b-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.b-score { text-align: right; }
.b-score .s { font-size: 19px; font-weight: 800; }
.b-score .lv { font-size: 12px; color: var(--brand-ink); margin-top: 2px; }
.me-tag { font-size: 11px; color: var(--gold); font-weight: 700; margin-left: 6px; background: var(--gold-soft); padding: 1px 6px; border-radius: 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- 线路图 ---------- */
.map-note { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 14px 10px; }
.map-wrap { background: #f7f8fa; border-radius: 16px; padding: 8px 6px; margin: 0 14px; overflow-x: auto; }
.map-wrap svg { width: 100%; height: auto; display: block; }
.map-legend { display: flex; gap: 14px 18px; justify-content: center; flex-wrap: wrap; margin: 14px 14px 6px; }
.map-legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: #2b2f36; }
.map-legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* ---------- Line chips (official colors) ---------- */
.line-chip {
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px;
  border-radius: 999px; letter-spacing: .5px; white-space: nowrap;
}
.line-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* ---------- Line picker ---------- */
.line-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.line-opt {
  display: flex; align-items: center; gap: 9px;
  padding: 14px 14px; border: 2px solid var(--line); border-radius: 14px;
  background: var(--surface); cursor: pointer; font-size: 16px; font-weight: 600;
  color: var(--ink); transition: .12s;
}
.line-opt::before {
  content: ''; width: 14px; height: 14px; border-radius: 50%;
  background: var(--c); flex: none;
}
.line-opt.selected { border-color: var(--c); background: #fff; box-shadow: 0 0 0 3px rgba(20,30,60,.06); }
.line-opt:active { transform: scale(.98); }

/* ---------- Favorite tag (record view) ---------- */
.fav-tag {
  font-size: 12px; color: var(--muted); background: #f1f3f7;
  padding: 2px 9px; border-radius: 999px; font-weight: 600;
}

/* ---------- Board favorite line ---------- */
.b-fav { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.b-fav-empty { color: var(--muted); font-size: 12px; font-weight: 500; }
.fav-title { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- History ---------- */
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 13px 15px; box-shadow: var(--shadow);
}
.h-main { flex: 1; min-width: 0; }
.h-line { font-weight: 700; font-size: 15px; }
.h-date { font-size: 12px; color: var(--muted); margin-top: 2px; }
.h-right { text-align: right; }
.h-st { font-size: 15px; font-weight: 700; }
.h-score { font-size: 13px; color: var(--ok); margin-top: 2px; font-weight: 600; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: sticky; bottom: 0;
  display: flex; gap: 8px;
  background: rgba(255,255,255,.94); backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 8px; margin-top: 16px; box-shadow: var(--shadow);
}
.tabbar.hidden { display: none; }
.tab-item {
  flex: 1; border: none; background: transparent; padding: 12px;
  border-radius: 12px; font-size: 15px; font-weight: 600;
  color: var(--muted); cursor: pointer; transition: .12s;
}
.tab-item.active { background: var(--brand); color: #fff; }
.tab-item:active { transform: scale(.97); }

/* ---------- 登录卡片毛玻璃 ---------- */
.auth-card {
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 26px;
  box-shadow: 0 10px 34px rgba(31, 38, 60, .18);
  padding: 26px 22px;
  margin-top: 8vh;
  margin-bottom: 0;
}
