:root {
  --bg: #0d1117;
  --bg-soft: #010409;
  --panel: #161b22;
  --panel-2: #1c2129;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #6e7681;
  --blue: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --amber: #d29922;
  --purple: #bc8cff;
  --teal: #39c5cf;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(1, 4, 9, 0.55);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 14px calc(28px + env(safe-area-inset-bottom));
}

.loading, .error-box {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.error-box code {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--amber);
  font-size: 13px;
}

/* ---------- header ---------- */
.hd {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -14px;
  padding: 12px 14px 8px;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.hd-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.hd h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.3px;
}
.hd h1 small {
  font-size: 12px;
  font-weight: 400;
  color: var(--dim);
  margin-left: 6px;
}
.hd .meta {
  font-size: 11.5px;
  color: var(--dim);
  white-space: nowrap;
}

/* exam chips */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 10px 0 4px;
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
  scroll-snap-type: x proximity;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12.5px;
  line-height: 1.25;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}
.chip b { display: block; color: var(--text); font-size: 13px; font-weight: 600; }
.chip.on {
  border-color: var(--blue);
  background: rgba(88, 166, 255, 0.13);
  color: var(--blue);
}
.chip.on b { color: #cfe4ff; }

/* tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin: 12px 0 0;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  padding: 3px;
}
.tabs button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-family: inherit;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
}
.tabs button.on {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
  font-weight: 600;
}

/* ---------- cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-hd h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.4px;
}
.card-hd .hint { font-size: 11.5px; color: var(--dim); }

/* hero */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}
.hero-total .num {
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.hero-total .lbl {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.hero-ranks {
  display: flex;
  gap: 16px;
  text-align: right;
}
.rank-block .num {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rank-block .lbl { font-size: 11px; color: var(--dim); }
.delta { font-size: 11.5px; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--dim); }

.warn {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(210, 153, 34, 0.1);
  border: 1px solid rgba(210, 153, 34, 0.35);
  color: #e3b341;
  font-size: 12px;
  line-height: 1.45;
}

.insight {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.pill {
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  white-space: nowrap;
}
.pill.good { border-color: rgba(63, 185, 80, 0.4); color: #56d364; }
.pill.bad { border-color: rgba(248, 81, 73, 0.4); color: #ff7b72; }
.pill.blue { border-color: rgba(88, 166, 255, 0.4); color: #79c0ff; }

/* subject grid */
.grid-subj {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}
@media (min-width: 560px) {
  .grid-subj { grid-template-columns: 1fr 1fr; }
}

.subj {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 13px 14px;
  position: relative;
  overflow: hidden;
}
.subj::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--c, var(--blue));
  opacity: 0.85;
}
.subj.missing { opacity: 0.55; }
.subj-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.subj-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.subj-score {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.subj-score small { font-size: 11px; font-weight: 400; color: var(--dim); margin-left: 2px; }
.subj-ranks {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.tag {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 2px 7px;
  font-variant-numeric: tabular-nums;
}
.tag b { color: var(--text); font-weight: 650; }

/* compare bar */
.bar {
  position: relative;
  height: 7px;
  border-radius: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  margin-top: 10px;
  overflow: visible;
}
.bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(88,166,255,.35), var(--c, var(--blue)));
}
.bar-avg {
  position: absolute;
  top: -3px; bottom: -3px;
  width: 2px;
  background: var(--amber);
  border-radius: 2px;
}
.bar-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.spark { margin-top: 8px; }

/* charts */
.chart-wrap { margin-top: 4px; }
svg { display: block; width: 100%; height: auto; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
}
.legend i {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* data table */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th, .tbl td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--border-soft);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { color: var(--dim); font-weight: 500; font-size: 11.5px; }
.scroll-x { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }

/* form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
input, select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
input:focus, select:focus { outline: none; border-color: var(--blue); }
input, select { min-height: 44px; }
.subj-form {
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  padding: 10px;
  margin-top: 8px;
  background: var(--panel-2);
}
.subj-form .title { font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 7px; }
.f4 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
pre.json {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 11.5px;
  line-height: 1.55;
  overflow-x: auto;
  color: #a5d6ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-height: 340px;
}
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  min-height: 42px;
}
.btn.primary {
  background: #1f6feb;
  border-color: #1f6feb;
  color: #fff;
  font-weight: 600;
}
.btn:active { transform: scale(0.985); }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

.note {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.6;
  margin-top: 10px;
}
.note code {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--amber);
  font-size: 11.5px;
}
.foot {
  text-align: center;
  font-size: 11px;
  color: #484f58;
  margin-top: 22px;
  line-height: 1.7;
}
.hidden { display: none !important; }
