:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;

  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-sub: #475569;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e293b;
  --primary-border: #1e3a8a;
  
  --success: #22c55e;
  --success-bg: #052e16;
  --success-border: #14532d;
  
  --danger: #ef4444;
  --danger-bg: #450a0a;
  --danger-border: #7f1d1d;
  
  --warning: #f59e0b;
  --warning-bg: #451a03;
  --warning-border: #78350f;

  --bg-main: #090d16;
  --bg-card: #111827;
  --bg-subtle: #1f2937;
  --border-color: #374151;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-sub: #cbd5e1;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* App Header */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.logo-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.logo-title span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-subtle);
  border-color: var(--text-muted);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.nav-tab-btn {
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.nav-tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Main Container */
.main-wrapper {
  max-width: 840px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 16px 40px;
  flex: 1;
}

/* Card Style */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
  transition: var(--transition);
}

/* Home / Welcome Screen */
.welcome-hero {
  text-align: center;
  padding: 30px 16px 20px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  margin-bottom: 16px;
}

.welcome-hero h2 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--text-main);
}

.welcome-hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 540px;
  margin: 0 auto 24px;
}

.exam-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.meta-box {
  background: var(--bg-subtle);
  padding: 16px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  border: 1px solid var(--border-color);
}

.meta-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.meta-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Mode Selection Cards */
.mode-selection-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.mode-card {
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 16px;
  cursor: pointer;
  background: var(--bg-card);
  transition: var(--transition);
  position: relative;
  text-align: left;
}

.mode-card:hover {
  border-color: var(--primary-border);
  background: var(--primary-light);
  transform: translateY(-2px);
}

.mode-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.mode-card .mode-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.mode-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-main);
}

.mode-card p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badge-recommend {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #ea580c;
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #15803d;
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger-border);
}

.btn-danger-outline:hover {
  background: var(--danger-bg);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 1.05rem;
}

/* Exam Active Screen */
.exam-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.exam-counter {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.exam-counter .current-num {
  font-size: 1.3rem;
  color: var(--primary);
}

.exam-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px 12px;
  border-radius: 20px;
}

.progress-track {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #38bdf8);
  width: 0%;
  transition: width 0.3s ease;
}

/* Question Sheet Drawer / Quick Jump Grid */
.quick-jump-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.jump-bubble {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid var(--border-color);
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.jump-bubble:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.jump-bubble.answered {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.jump-bubble.current {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: scale(1.08);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4);
}

/* Question Content Card */
.question-card {
  padding: 28px;
}

.q-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.q-type-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
}

.q-type-badge.choice {
  background: #ede9fe;
  color: #6d28d9;
}

.q-type-badge.tf {
  background: #e0f2fe;
  color: #0369a1;
}

.q-points {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.q-stem {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.5;
  margin-bottom: 24px;
}

/* Options List */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  width: 100%;
}

.option-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

.option-key {
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: var(--transition);
}

.option-btn.selected .option-key {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.option-text {
  flex: 1;
  line-height: 1.5;
}

/* True/False Large Buttons Layout */
.tf-options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.tf-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  transition: var(--transition);
  gap: 8px;
}

.tf-btn .tf-icon {
  font-size: 2.4rem;
  font-weight: 900;
}

.tf-btn.btn-tf-o .tf-icon {
  color: var(--success);
}

.tf-btn.btn-tf-x .tf-icon {
  color: var(--danger);
}

.tf-btn .tf-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.tf-btn:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.tf-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

/* Question Nav Bottom Bar */
.exam-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

/* Result Screen */
.result-banner {
  text-align: center;
  padding: 36px 20px 28px;
  position: relative;
  overflow: hidden;
}

.result-badge-huge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px;
  border-radius: 30px;
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-badge-huge.passed {
  background: var(--success-bg);
  color: var(--success);
  border: 1.5px solid var(--success-border);
}

.result-badge-huge.failed {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
}

.score-display-wrapper {
  margin-bottom: 24px;
}

.score-number {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.score-number.passed {
  color: var(--success);
}

.score-number.failed {
  color: var(--danger);
}

.score-unit {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.result-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0 28px;
  padding: 16px;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.res-stat-item {
  text-align: center;
}

.res-stat-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-main);
}

.res-stat-lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.result-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

/* Review Filter Tabs */
.review-filter-bar {
  display: flex;
  gap: 8px;
  margin: 32px 0 16px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-sub);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.filter-chip:hover {
  background: var(--bg-subtle);
}

.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Review Card */
.review-item {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  padding: 20px;
  margin-bottom: 16px;
  transition: var(--transition);
}

.review-item.is-wrong {
  border-left: 5px solid var(--danger);
}

.review-item.is-correct {
  border-left: 5px solid var(--success);
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.review-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 16px;
  line-height: 1.5;
}

.answer-comparison-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-subtle);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.ans-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ans-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.ans-tag.tag-user {
  background: #f1f5f9;
  color: #475569;
}

.ans-tag.tag-user-wrong {
  background: #fee2e2;
  color: #dc2626;
}

.ans-tag.tag-user-correct {
  background: #dcfce7;
  color: #16a34a;
}

.ans-tag.tag-correct {
  background: #dcfce7;
  color: #15803d;
}

.options-preview {
  margin-top: 10px;
  font-size: 0.88rem;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-left: 6px;
  border-left: 2px solid var(--border-color);
}

.opt-preview-item.correct {
  color: var(--success);
  font-weight: 600;
}

.opt-preview-item.wrong {
  color: var(--danger);
  text-decoration: line-through;
}

/* Question Bank Search & Browser */
.search-bar-wrap {
  position: relative;
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
}

/* Modal styles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 1.2rem;
  color: var(--text-main);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* Confetti Animation */
@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.pop-in {
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Responsive tweaks */
@media (max-width: 640px) {
  .welcome-hero h2 {
    font-size: 1.4rem;
  }
  .q-stem {
    font-size: 1.1rem;
  }
  .score-number {
    font-size: 4rem;
  }
  .header-container {
    padding: 8px 12px;
  }
  .logo-title h1 {
    font-size: 1rem;
  }
  .main-wrapper {
    padding: 12px 10px 30px;
  }
  .card {
    padding: 18px 14px;
  }
  .exam-topbar {
    padding: 10px 14px;
  }
}
