:root {
  color-scheme: light dark;
  --bg: #eef1f9;
  --bg-glow: #dfe6ff;
  --card: #ffffff;
  --text: #14161f;
  --muted: #6d7386;
  --faint: #a2a8ba;
  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #e11d48;
  --line: rgba(20, 22, 40, 0.08);
  --border: rgba(20, 22, 40, 0.07);
  --soft: rgba(79, 70, 229, 0.06);
  --soft-2: rgba(20, 22, 40, 0.045);
  --chip: rgba(79, 70, 229, 0.1);
  --switch: #c7cce0;
  --scroll: rgba(79, 70, 229, 0.32);
  --shadow: 0 1px 2px rgba(16, 18, 38, 0.05), 0 12px 32px -14px rgba(16, 18, 38, 0.22);
  --shadow-lg: 0 2px 8px rgba(16, 18, 38, 0.08), 0 34px 70px -24px rgba(16, 18, 38, 0.32);
  --ring: rgba(79, 70, 229, 0.16);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0d18;
    --bg-glow: #1b2350;
    --card: #141827;
    --text: #edf0f8;
    --muted: #98a0bd;
    --faint: #6a7290;
    --primary: #7c8bff;
    --primary-2: #a78bfa;
    --good: #34d399;
    --warn: #fbbf24;
    --bad: #fb7185;
    --line: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.07);
    --soft: rgba(124, 139, 255, 0.1);
    --soft-2: rgba(255, 255, 255, 0.045);
    --chip: rgba(124, 139, 255, 0.16);
    --switch: #3a4160;
    --scroll: rgba(124, 139, 255, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
    --shadow-lg: 0 3px 10px rgba(0, 0, 0, 0.55), 0 40px 80px -28px rgba(0, 0, 0, 0.8);
    --ring: rgba(124, 139, 255, 0.24);
  }
}

* {
  box-sizing: border-box;
}

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "Segoe UI",
    "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei",
    sans-serif;
  background:
    radial-gradient(1100px 560px at 12% -12%, var(--bg-glow) 0%, transparent 58%),
    radial-gradient(980px 520px at 104% -4%, rgba(124, 58, 237, 0.16) 0%, transparent 54%),
    radial-gradient(900px 620px at 50% 118%, rgba(20, 184, 166, 0.12) 0%, transparent 58%),
    linear-gradient(180deg, #f6f7fd 0%, var(--bg) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(1100px 560px at 12% -12%, #1b2350 0%, transparent 58%),
      radial-gradient(980px 520px at 104% -4%, rgba(124, 58, 237, 0.24) 0%, transparent 54%),
      radial-gradient(900px 620px at 50% 118%, rgba(20, 184, 166, 0.14) 0%, transparent 58%),
      linear-gradient(180deg, #0c1020 0%, var(--bg) 100%);
  }
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

.page {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 48px;
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
}

.topbar {
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  box-shadow: 0 10px 24px -8px rgba(79, 70, 229, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-text h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.3px;
  background: linear-gradient(120deg, var(--text) 35%, var(--primary) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.1px;
}

.search-wrap {
  position: relative;
}

.search {
  display: flex;
  gap: 8px;
  background: var(--card);
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.24s var(--ease), border-color 0.24s var(--ease),
    transform 0.24s var(--ease);
}

.search:focus-within {
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--ring);
  transform: translateY(-1px);
}

.suggest {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
  max-height: 264px;
  overflow-y: auto;
  animation: rise 0.16s ease;
}

.suggest.hidden {
  display: none;
}

.suggest-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s;
}

.suggest-item:hover,
.suggest-item.active {
  background: var(--soft, #f2f4ff);
}

.suggest-item .py {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

.suggest-empty {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}

.search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 13px;
  font-size: 14.5px;
  color: var(--text);
}

.search input::placeholder {
  color: var(--faint);
}

.search button {
  border: none;
  border-radius: 11px;
  padding: 10px 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px rgba(79, 70, 229, 0.7);
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
}

.search button:hover {
  opacity: 0.94;
  box-shadow: 0 10px 26px -8px rgba(79, 70, 229, 0.8);
}

.search button:active {
  transform: scale(0.97);
}

.hint {
  min-height: 18px;
  margin: 11px 4px 0;
  color: var(--bad);
  font-size: 12.5px;
}

.hint.info {
  color: var(--muted);
}

.result.hidden {
  display: none;
}

.result {
  animation: rise 0.28s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 14px;
}

.student-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.student-info {
  flex: 1;
  min-width: 0;
}

.student-name {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.2px;
}

.student-meta {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.rank-pill {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(79, 70, 229, 0.18);
}

.rank-pill b {
  font-size: 15px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, var(--soft), transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 8px;
  text-align: center;
  transition: background 0.24s var(--ease), box-shadow 0.24s var(--ease),
    transform 0.24s var(--ease);
}

.stat.grade-tint {
  box-shadow: inset 3px 0 0 0 var(--grade-color, var(--primary));
}

.stat .value {
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}

.stat .value small {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.stat .value.accent {
  color: var(--primary);
}

.stat .label {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.section-title {
  font-size: 13.5px;
  font-weight: 700;
  margin: 0 0 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.1px;
}

.section-title::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  box-shadow: 0 0 10px -2px var(--primary);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 10px 6px;
  text-align: center;
}

thead th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}

tbody td {
  border-bottom: 1px solid var(--line);
}

tbody tr:last-child td {
  border-bottom: none;
}

td.subject {
  font-weight: 700;
}

.diff-good {
  color: var(--good);
}

.diff-bad {
  color: var(--bad);
}

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart {
  width: 100%;
  height: 220px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 26px 0;
  font-size: 14px;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--faint);
  font-size: 11.5px;
  margin-top: 22px;
  padding: 0 4px env(safe-area-inset-bottom);
}

.motion-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px;
}

.motion-toggle.hidden {
  display: none;
}

.motion-switch {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 999px;
  background: var(--switch);
  transition: background 0.22s var(--ease);
}

.motion-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s var(--ease);
}

.motion-toggle[aria-pressed="true"] .motion-switch {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}

.motion-toggle[aria-pressed="true"] .motion-switch::after {
  transform: translateX(13px);
}

.motion-toggle[aria-pressed="true"] .motion-label {
  color: var(--text);
}

.hidden {
  display: none !important;
}

.card.hidden,
.charts.hidden {
  display: none;
}

.rank-row {
  content-visibility: auto;
  contain-intrinsic-size: 44px;
}

.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  background: var(--soft-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 14px;
}

.tab-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 0;
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 2px 10px rgba(16, 18, 38, 0.1);
  transition: transform 0.34s var(--ease), width 0.34s var(--ease);
  z-index: 0;
}

.tab {
  position: relative;
  z-index: 1;
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease);
}

.tab.active {
  color: var(--text);
  font-weight: 700;
}

.panel.hidden {
  display: none;
}

.history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.history.hidden {
  display: none;
}

.history-label {
  font-size: 12px;
  color: var(--muted);
}

.history-chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 18, 38, 0.06);
}

.history-chip:hover {
  color: var(--primary);
}

.history-clear {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

.grade-badge {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

.overview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap table {
  min-width: 460px;
}

.rank-row {
  cursor: pointer;
}

.rank-row:hover {
  background: var(--soft);
}

.rank-row td.row-name {
  font-weight: 700;
}

.medal {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 10px -4px rgba(0, 0, 0, 0.4);
}

@media (max-width: 640px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts {
    grid-template-columns: 1fr;
  }
  .stat .value {
    font-size: 19px;
  }
}

@media (hover: hover) {
  .card {
    transition: box-shadow 0.3s var(--ease), transform 0.3s var(--ease),
      border-color 0.3s var(--ease);
  }
  .card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
  }
  .stat:hover {
    transform: translateY(-2px);
  }
}

/* ---------------- 滚动与动效 ---------------- */

.card {
  animation: rise 0.36s var(--ease) both;
}

.result > .card:nth-child(2) {
  animation-delay: 0.05s;
}

.result > .card:nth-child(3) {
  animation-delay: 0.1s;
}

.charts .card {
  animation-delay: 0.12s;
}

.suggest-item,
.history-chip,
.tab,
.search button {
  transition: background 0.18s var(--ease), color 0.18s var(--ease),
    box-shadow 0.18s var(--ease), transform 0.18s var(--ease);
}

.suggest-item:active,
.history-chip:active {
  transform: scale(0.98);
}

.table-wrap,
.suggest {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scroll);
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
  background-clip: content-box;
}

/* ---------------- 动画效果 ---------------- */

@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loadbar {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(420%);
  }
}

tbody tr {
  animation: rowIn 0.36s var(--ease) both;
}

.grade-badge {
  animation: pop 0.32s var(--ease) both;
}

.rank-pill.pop,
.student-name.pop {
  animation: pop 0.36s var(--ease) both;
}

.history-chip,
.suggest-item {
  animation: rowIn 0.26s var(--ease) both;
}

.topbar {
  animation: rowIn 0.4s var(--ease) both;
}

.loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  pointer-events: none;
}

.loading-bar.active {
  opacity: 1;
}

.loading-bar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28%;
  background: linear-gradient(
    90deg,
    transparent,
    var(--primary),
    var(--primary-2),
    transparent
  );
}

.loading-bar.active::before {
  animation: loadbar 1.05s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------- 考试选择器 ---------------- */

.exam-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.exam-bar label {
  font-size: 12.5px;
  color: var(--muted);
  flex: none;
}

.exam-bar select {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13.5px;
  color: var(--text);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.exam-bar select:focus {
  outline: none;
  border-color: rgba(79, 70, 229, 0.45);
  box-shadow: 0 0 0 4px var(--ring);
}

/* ---------------- 骨架屏 ---------------- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--soft-2);
  border-radius: 8px;
  min-height: 12px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.55),
    transparent
  );
  animation: shimmer 1.3s infinite;
}

@media (prefers-color-scheme: dark) {
  .skeleton::after {
    background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 255, 255, 0.08),
      transparent
    );
  }
}

.skeleton-line {
  height: 12px;
  margin: 8px 0;
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
}

.skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  flex: none;
}

.skeleton-stat {
  height: 58px;
  border-radius: 12px;
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}
