:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header .subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 6px;
}

/* Welcome */
.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.welcome-card h2 {
  font-size: 1.25rem;
  margin-bottom: 16px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 20px 0 28px;
}

.info-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.info-item .val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.info-item .lbl {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.mode-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--muted);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
}

/* Quiz layout */
.quiz-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.progress-bar-wrap {
  flex: 1;
  min-width: 200px;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.progress-bar {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 4px;
  transition: width 0.3s;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 8px 16px;
  background: var(--surface2);
  border-radius: 8px;
}

.timer.warn {
  color: var(--warn);
}

.timer.danger {
  color: var(--error);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.q-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--muted);
}

.badge.topic {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
}

.badge.warn-badge {
  color: var(--warn);
  background: rgba(245, 158, 11, 0.15);
}

.q-stem {
  font-size: 1.05rem;
  margin-bottom: 12px;
  white-space: pre-wrap;
}

.q-stem-zh {
  font-size: 0.95rem;
  color: #a5b4c8;
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin-bottom: 20px;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
  color: var(--text);
  font-size: 0.95rem;
}

.option:hover:not(.disabled) {
  border-color: var(--border);
  background: #2a3a50;
}

.option.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.option.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.12);
}

.option.wrong {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.12);
}

.option.disabled {
  cursor: default;
  opacity: 0.85;
}

.option-key {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.option-text {
  flex: 1;
  word-break: break-word;
}

.feedback {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.feedback.ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.feedback.bad {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.feedback.note {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fcd34d;
  margin-top: 8px;
}

/* 答题详细解析 */
.feedback-head {
  font-size: 1rem;
  font-weight: 600;
}

.exp-block {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.65;
}

.exp-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.exp-knowledge {
  border-left: 3px solid var(--accent);
}

.exp-why {
  border-left: 3px solid var(--success);
}

.exp-distractors,
.exp-others {
  border-left: 3px solid var(--error);
}

.exp-body {
  color: var(--muted);
}

.exp-item {
  margin-top: 8px;
  color: var(--muted);
}

.exp-item:first-of-type {
  margin-top: 4px;
}

.exp-key {
  display: inline-block;
  min-width: 22px;
  margin-right: 8px;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  text-align: center;
}

.nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

/* Question grid */
.grid-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
}

.grid-panel h3 {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.q-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 8px;
}

.q-grid button {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.q-grid button:hover {
  border-color: var(--accent);
}

.q-grid button.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.q-grid button.answered {
  background: rgba(59, 130, 246, 0.25);
  border-color: var(--accent);
}

.q-grid button.correct {
  background: rgba(34, 197, 94, 0.25);
  border-color: var(--success);
}

.q-grid button.wrong {
  background: rgba(239, 68, 68, 0.25);
  border-color: var(--error);
}

/* Results */
.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  text-align: center;
  box-shadow: var(--shadow);
}

.score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  margin: 0 auto 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 6px solid var(--border);
}

.score-circle.pass {
  border-color: var(--success);
}

.score-circle.fail {
  border-color: var(--error);
}

.score-circle .pct {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
}

.score-circle .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.results-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 24px 0;
  flex-wrap: wrap;
}

.stat .n {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat .l {
  font-size: 0.85rem;
  color: var(--muted);
}

.stat.correct .n { color: var(--success); }
.stat.wrong .n { color: var(--error); }
.stat.skip .n { color: var(--muted); }

.wrong-list {
  text-align: left;
  margin-top: 28px;
  max-height: 400px;
  overflow-y: auto;
}

.wrong-list h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.wrong-item {
  padding: 12px;
  background: var(--surface2);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.wrong-item strong {
  color: var(--accent);
}

.hidden {
  display: none !important;
}

/* ===== Library 主页 ===== */
.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.library-toolbar h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.library-hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* 首次使用引导卡片 */
.guide-card {
  position: relative;
  background: linear-gradient(135deg, var(--surface2), var(--surface));
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

.guide-card.hidden {
  display: none;
}

.guide-card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.guide-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.guide-close:hover {
  background: var(--border);
  color: var(--text);
}

.guide-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
  padding: 0;
}

.guide-steps li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.guide-num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-steps strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 2px;
}

.guide-steps p {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.guide-steps code {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.78rem;
  color: var(--accent);
}

.guide-steps a {
  color: var(--accent);
  text-decoration: none;
}

.guide-steps a:hover {
  text-decoration: underline;
}

.bank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.bank-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
}

.bank-card:hover {
  border-color: var(--accent);
}

.bank-card-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bank-title {
  font-size: 1.05rem;
  font-weight: 700;
  word-break: break-word;
}

.bank-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
}

.bank-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--muted);
}

.bank-tag.builtin {
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
}

.bank-progress {
  color: var(--accent);
}

.bank-card-actions {
  display: flex;
  gap: 10px;
}

.bank-card-actions .bank-open {
  flex: 1;
}

.bank-empty {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ===== Modal 弹窗 ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface2);
}

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-hint {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.modal-hint code {
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: #93c5fd;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.modal-msg {
  font-size: 0.85rem;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
}

.modal-msg.success,
.modal-msg.ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.modal-msg.error,
.modal-msg.bad {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.modal-msg.info {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

/* ===== Field 表单 ===== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.field-label .req {
  color: var(--error);
}

.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.field input[type="text"]:focus,
.field input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.field input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.field input[type="file"]::file-selector-button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  margin-right: 12px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ===== 导入进度 ===== */
.import-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.import-progress-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: 5px;
  overflow: hidden;
}

.import-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  border-radius: 5px;
  transition: width 0.3s;
}

.import-progress-text {
  font-size: 0.82rem;
  color: var(--muted);
}

@media (max-width: 600px) {
  .app { padding: 16px 12px 32px; }
  .question-card { padding: 20px 16px; }
  .welcome-card { padding: 24px 18px; }
  .bank-grid { grid-template-columns: 1fr; }
  .library-toolbar { flex-direction: column; align-items: flex-start; }
}
