:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-soft: #eef2ff;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow: 0 4px 16px rgba(15,23,42,.06);
  --shadow-lg: 0 16px 40px rgba(99,102,241,.18);
  --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --gradient-soft: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  --t: cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0%, transparent 60%),
    radial-gradient(800px 500px at 100% 0%, #f3e8ff 0%, transparent 60%);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 11px 22px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all .2s var(--t); white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--gradient); color: #fff; box-shadow: 0 4px 14px rgba(99,102,241,.35); }
.btn-primary:hover { box-shadow: 0 6px 20px rgba(99,102,241,.45); transform: translateY(-1px); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--primary-soft); color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: 13px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: transparent; cursor: pointer; font-size: 18px;
  color: var(--text-muted); display: flex; align-items: center;
  justify-content: center; transition: all .2s var(--t);
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary); transform: scale(1.08); }

.glass {
  background: rgba(255,255,255,.75);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(226,232,240,.6);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* 登录页 */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 40px 32px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg); border: 1px solid rgba(226,232,240,.8);
  animation: slideUp .5s var(--t);
}
.auth-logo {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 20px;
  background: var(--gradient); display: flex; align-items: center;
  justify-content: center; font-size: 32px;
  box-shadow: 0 12px 28px rgba(99,102,241,.35);
}
.auth-title { font-size: 26px; text-align: center; font-weight: 800; letter-spacing: -.02em; }
.auth-sub { text-align: center; color: var(--text-muted); margin: 8px 0 28px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-input {
  padding: 14px 16px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; background: var(--surface);
  transition: all .2s var(--t); color: var(--text);
}
.auth-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.12); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }
.auth-switch { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; margin-left: 4px; }
.auth-switch a:hover { text-decoration: underline; }

/* 顶栏 */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px; position: sticky; top: 12px; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.brand-icon {
  width: 34px; height: 34px; border-radius: 10px; background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.header-right { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
  background: var(--surface); border-radius: 999px; border: 1px solid var(--border);
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--gradient);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-name { font-size: 14px; font-weight: 600; }
.badge-admin {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #fff; font-weight: 700;
}
.sync-badge { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; transition: all .3s var(--t); }
.sync-badge.syncing { background: var(--warning); animation: pulse 1s infinite; }
.sync-badge.synced  { background: var(--success); }
.sync-badge.error   { background: var(--danger); }

/* 统计 */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 24px 0; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 12px;
  text-align: center; box-shadow: var(--shadow-sm);
  border: 1px solid rgba(226,232,240,.6);
  transition: all .2s var(--t); animation: slideUp .4s var(--t) backwards;
}
.stat-card:nth-child(1) { animation-delay: .05s; }
.stat-card:nth-child(2) { animation-delay: .10s; }
.stat-card:nth-child(3) { animation-delay: .15s; }
.stat-card:nth-child(4) { animation-delay: .20s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { font-size: 20px; margin-bottom: 4px; }
.stat-value {
  font-size: 26px; font-weight: 800; letter-spacing: -.02em;
  background: var(--gradient); -webkit-background-clip: text;
  background-clip: text; -webkit-text-fill-color: transparent;
}
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Section */
.section { margin: 32px 0; }
.section-title {
  font-size: 15px; font-weight: 700; margin-bottom: 14px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em;
}

/* 模式卡片 */
.mode-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.mode-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 20px; text-align: left;
  cursor: pointer; transition: all .2s var(--t); font-family: inherit;
  position: relative; overflow: hidden;
}
.mode-card::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background: var(--gradient-soft); opacity: 0; transition: opacity .3s var(--t);
}
.mode-card > * { position: relative; z-index: 1; }
.mode-card:hover:not(.disabled) {
  border-color: var(--primary-light); transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.mode-card:hover:not(.disabled)::before { opacity: 1; }
.mode-card.disabled { opacity: .5; cursor: not-allowed; }
.mode-icon { font-size: 26px; margin-bottom: 8px; }
.mode-title { font-size: 15px; font-weight: 700; }
.mode-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* 刷题 */
.quiz-wrap { max-width: 720px; margin: 0 auto; }
.quiz-header { display: flex; align-items: center; gap: 14px; padding: 12px 4px; }
.quiz-progress-wrap { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.quiz-progress-text { font-size: 13px; font-weight: 700; color: var(--text-muted); text-align: center; }
.quiz-progress-bar { height: 6px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.quiz-progress-bar > div { height: 100%; background: var(--gradient); border-radius: 999px; transition: width .4s var(--t); }
.fav-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: transparent; font-size: 22px; cursor: pointer;
  color: #cbd5e1; transition: all .2s var(--t);
}
.fav-btn:hover { background: var(--primary-soft); transform: scale(1.1); }
.fav-btn.active { color: #f59e0b; }
.auto-next-toggle.active { color: var(--primary); }

.quiz-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 28px; margin-top: 12px; box-shadow: var(--shadow);
  border: 1px solid rgba(226,232,240,.6); animation: slideUp .3s var(--t);
}
.quiz-type-badge {
  display: inline-block; font-size: 12px; font-weight: 700;
  color: var(--primary); background: var(--primary-soft);
  padding: 4px 12px; border-radius: 999px; margin-bottom: 14px;
}
.quiz-content { font-size: 17px; line-height: 1.75; margin-bottom: 24px; font-weight: 500; letter-spacing: -.005em; }
.quiz-content p { margin: 4px 0; }

.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.option {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: all .18s var(--t); background: var(--surface);
}
.option:hover { border-color: var(--primary-light); background: var(--primary-soft); }
.option.checked { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(99,102,241,.08); }
.option.submitted { cursor: default; pointer-events: none; }
.option.submitted:hover { background: var(--surface); border-color: var(--border); }
.option.correct { border-color: var(--success); background: var(--success-soft); }
.option.correct:hover { background: var(--success-soft); border-color: var(--success); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option.wrong:hover { background: var(--danger-soft); border-color: var(--danger); }
.option input { display: none; }
.option-name {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; background: #f1f5f9;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
  color: var(--text-muted); transition: all .18s var(--t);
}
.option.checked .option-name { background: var(--primary); color: #fff; }
.option.correct .option-name { background: var(--success); color: #fff; }
.option.wrong .option-name { background: var(--danger); color: #fff; }
.option-value { flex: 1; word-break: break-word; font-size: 15px; padding-top: 2px; }

/* 反馈 */
.feedback { padding: 16px 18px; border-radius: var(--radius-sm); margin-bottom: 18px; animation: slideUp .3s var(--t); }
.feedback-right { background: var(--success-soft); border-left: 4px solid var(--success); }
.feedback-wrong { background: var(--danger-soft); border-left: 4px solid var(--danger); }
.feedback-title { font-weight: 700; font-size: 15px; margin-bottom: 6px; }
.feedback-right .feedback-title { color: #047857; }
.feedback-wrong .feedback-title { color: #b91c1c; }
.feedback-correct { font-size: 14px; color: var(--text); }

/* 结果页 */
.result-wrap {
  max-width: 480px; margin: 60px auto; text-align: center;
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 48px 32px; box-shadow: var(--shadow-lg);
  border: 1px solid rgba(226,232,240,.8); animation: slideUp .5s var(--t);
}
.result-ring {
  width: 160px; height: 160px; margin: 0 auto 20px;
  border-radius: 50%; display: flex; align-items: center;
  justify-content: center; position: relative;
  background: conic-gradient(var(--primary) 0%, var(--primary-light) 100%);
}
.result-ring::before { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface); }
.result-rate {
  position: relative; font-size: 44px; font-weight: 800;
  background: var(--gradient); -webkit-background-clip: text;
  background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: -.03em;
}
.result-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.result-detail { color: var(--text-muted); margin: 8px 0 28px; font-size: 14px; }
.result-actions { display: flex; gap: 12px; justify-content: center; }

/* 自动跳转提示 */
.auto-next-hint {
  position: relative; display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 10px 16px; margin-bottom: 12px;
  background: var(--primary-soft); border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: var(--primary);
  overflow: hidden; animation: slideUp .2s var(--t);
}
.auto-next-hint .auto-next-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(99,102,241,.18); pointer-events: none; width: 0;
}
.auto-next-hint .auto-next-text { position: relative; z-index: 1; }
.auto-next-hint .auto-next-cancel {
  position: relative; z-index: 1; padding: 4px 12px; font-size: 12px;
  background: rgba(255,255,255,.7); color: var(--primary-dark);
}
.auto-next-hint .auto-next-cancel:hover { background: #fff; }
.auto-next-hint.paused { background: #f1f5f9; color: var(--text-muted); }
.auto-next-hint.paused .auto-next-fill { background: transparent; }

/* Toast */
.toast {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(24px);
  background: #1e293b; color: #fff; padding: 12px 22px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .3s var(--t);
  z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Loading */
.loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh; font-size: 15px; color: var(--text-muted); gap: 12px;
}
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  #app { padding: 14px 12px 40px; }
  .app-header { padding: 10px 12px; }
  .user-name { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }
  .mode-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .mode-card { padding: 16px; }
  .mode-icon { font-size: 22px; }
  .quiz-card { padding: 20px; }
  .quiz-content { font-size: 16px; }
  .auth-card { padding: 32px 24px; }
  .result-wrap { padding: 36px 24px; margin: 32px auto; }
  .result-ring { width: 140px; height: 140px; }
  .result-rate { font-size: 38px; }
}