:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  width: 100%;
  overflow-x: clip;
}

header {
  margin-bottom: 32px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
  flex: 1;
  min-width: 0;
}

header p,
#header-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.guest-hint {
  color: var(--warning);
  font-size: 0.85rem;
}

.user-bar .hidden {
  display: none;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.auth-card {
  max-width: 400px;
  margin: 0 auto;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}

.auth-tab.active {
  background: var(--accent);
  color: white;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-form input {
  padding: 10px 12px;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.auth-hint {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--danger);
  min-height: 1.2em;
}

.bank-class-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

.bank-class-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.bank-class-options {
  display: flex;
  gap: 10px;
}

.bank-class-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 0.15s, background 0.15s;
}

.bank-class-btn:has(input:checked) {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
}

.bank-class-btn input {
  accent-color: var(--accent);
}

.class-totals {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.class-totals span strong {
  color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 560px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.practice-progress {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
  min-height: 1.5em;
}

.practice-progress .prior-wrong {
  color: #e74c3c;
}

.practice-progress .prior-correct {
  color: #2ecc71;
}

.mode-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.mode-card h2 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.mode-card p {
  color: var(--muted);
  font-size: 0.88rem;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  max-width: 100%;
  overflow-x: clip;
}

.question-stem {
  margin-bottom: 20px;
}

.question-meta {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.question-body {
  font-size: 1.05rem;
  line-height: 1.75;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-break: auto;
}

.option-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-break: auto;
}

.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;
  max-width: 100%;
  overflow: hidden;
}

.option:hover {
  border-color: var(--accent);
}

.option.selected {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
}

.option.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.12);
}

.option.wrong {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

.option input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.option-label {
  font-weight: 600;
  min-width: 24px;
  flex-shrink: 0;
}

.feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: 10px;
  display: none;
}

.feedback.show {
  display: block;
}

.feedback.correct {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.feedback.wrong {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
  align-items: center;
}

.practice-toolbar {
  justify-content: flex-end;
}

.practice-toolbar .btn {
  flex: 0 0 auto;
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-secondary:hover {
  background: #2f3f56;
}

.exam-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.exam-timer.urgent {
  color: #c0392b;
}

.exam-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.exam-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  max-height: 120px;
  overflow-y: auto;
}

.nav-dot {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
}

.nav-dot.answered {
  background: rgba(59, 130, 246, 0.35);
  color: var(--text);
}

.nav-dot.current {
  outline: 2px solid var(--accent);
  color: var(--text);
}

.result-banner {
  text-align: center;
  padding: 28px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.result-banner.pass {
  background: rgba(34, 197, 94, 0.15);
}

.result-banner.fail {
  background: rgba(239, 68, 68, 0.15);
}

.result-banner h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.result-banner.pass h2 {
  color: var(--success);
}

.result-banner.fail h2 {
  color: var(--danger);
}

.wrong-list {
  max-height: 400px;
  overflow-y: auto;
}

.wrong-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--surface2);
  font-size: 0.9rem;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-break: auto;
}

.wrong-item:last-child {
  border-bottom: none;
}

.hidden {
  display: none !important;
}

.back-link {
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  margin-bottom: 16px;
  display: inline-block;
}

.back-link:hover {
  color: var(--accent);
}

/* —— 手机端适配 —— */
@media (max-width: 640px) {
  .container {
    padding: max(16px, env(safe-area-inset-top)) 12px
      max(28px, env(safe-area-inset-bottom));
  }

  header {
    margin-bottom: 20px;
  }

  header h1 {
    font-size: clamp(1.05rem, 4.5vw, 1.35rem);
    line-height: 1.45;
  }

  .header-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .user-bar {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
  }

  .guest-hint {
    flex: 1 1 100%;
    font-size: 0.78rem;
    line-height: 1.4;
  }

  #header-subtitle {
    font-size: 0.82rem;
  }

  .bank-class-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .bank-class-options {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .bank-class-btn {
    justify-content: center;
    padding: 10px 6px;
    font-size: 0.9rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 20px;
  }

  .stat-card {
    padding: 12px 8px;
  }

  .stat-card .value {
    font-size: 1.2rem;
  }

  .stat-card .label {
    font-size: 0.75rem;
  }

  .mode-card {
    padding: 18px;
  }

  .mode-card:active {
    border-color: var(--accent);
  }

  .card {
    padding: 16px;
  }

  .question-body {
    font-size: 1rem;
    line-height: 1.7;
  }

  .option {
    padding: 14px;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
  }

  .option input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex-shrink: 0;
  }

  .practice-progress,
  .exam-progress {
    font-size: 0.82rem;
    line-height: 1.5;
  }

  .exam-progress {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .exam-nav {
    max-height: 96px;
    gap: 5px;
  }

  .nav-dot {
    width: 34px;
    height: 34px;
    font-size: 0.72rem;
  }

  .practice-toolbar,
  .exam-toolbar {
    flex-wrap: nowrap;
    justify-content: stretch;
    gap: 6px;
  }

  .practice-toolbar .btn,
  .exam-toolbar .btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 40px;
    padding: 8px 4px;
    font-size: 0.78rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  .result-banner {
    padding: 20px 16px;
  }

  .result-banner h2 {
    font-size: 1.25rem;
  }

  .back-link {
    font-size: 0.85rem;
    margin-bottom: 12px;
  }

  .auth-form input {
    font-size: 16px; /* 避免 iOS 自动放大 */
  }
}

@media (hover: none) {
  .mode-card:hover {
    transform: none;
  }
}
