*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  color: #222;
  min-height: 100vh;
}

header {
  background: #1a56db;
  color: white;
  padding: 16px 24px 0;
}

header h1 { font-size: 1.3em; margin-bottom: 12px; }

.subject-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.subject-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.85);
  padding: 4px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.subject-btn:hover { background: rgba(255,255,255,0.25); color: white; }
.subject-btn.active { background: white; color: #1a56db; border-color: white; }

.grade-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.grade-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: rgba(255,255,255,0.85);
  padding: 4px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.8em;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.grade-btn:hover { background: rgba(255,255,255,0.25); color: white; }
.grade-btn.active { background: white; color: #1a56db; border-color: white; }

.tabs { display: flex; gap: 4px; }

.tab-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-size: 0.9em;
  font-weight: 500;
  transition: color 0.15s;
}

.tab-btn:hover { color: white; }
.tab-btn.active { color: white; border-bottom-color: white; }

main { padding: 24px; max-width: 900px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card h2 { font-size: 1em; color: #444; margin-bottom: 16px; }

/* AI Performance Review */
.ai-review-date { font-size: 0.8em; color: #888; margin-bottom: 8px; font-weight: 600; }
.ai-review-body { font-size: 0.9em; line-height: 1.6; color: #333; }
.ai-review-older {
  border-top: 1px solid #eee;
  margin-top: 14px;
  padding-top: 10px;
}
.ai-review-older summary {
  cursor: pointer;
  font-size: 0.8em;
  color: #888;
  font-weight: 600;
}
.ai-review-older .ai-review-body { margin-top: 8px; }

.stat-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

.stat-card {
  background: white;
  border-radius: 8px;
  padding: 16px 20px;
  flex: 1;
  min-width: 140px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card .label { font-size: 0.75em; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { font-size: 1.8em; font-weight: 700; color: #1a56db; margin-top: 4px; }
.stat-card .sub { font-size: 0.8em; color: #666; margin-top: 2px; }

/* Topic bars */
.topic-bar-row { display: flex; align-items: center; margin-bottom: 12px; gap: 12px; }
.topic-label { width: 130px; font-size: 0.85em; text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; background: #eee; border-radius: 4px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s; }
.bar-fill.green { background: #22c55e; }
.bar-fill.yellow { background: #f59e0b; }
.bar-fill.red { background: #ef4444; }
.topic-pct { width: 44px; font-size: 0.85em; color: #555; }

/* History list */
.history-item {
  border-bottom: 1px solid #eee;
  padding: 12px 0;
  cursor: pointer;
}
.history-item:last-child { border-bottom: none; }
.history-item .row { display: flex; justify-content: space-between; align-items: center; }
.history-item .date { font-size: 0.85em; color: #888; }
.history-item .badge {
  font-size: 0.75em; padding: 2px 8px; border-radius: 12px; font-weight: 600;
}
.badge.ela { background: #dbeafe; color: #1e40af; }
.badge.math { background: #ede9fe; color: #6d28d9; }
.badge.gt_math { background: #fae8ff; color: #86198f; }
.badge.science { background: #d1fae5; color: #065f46; }
.badge.social_studies { background: #ffedd5; color: #9a3412; }
.badge.vocabulary { background: #e0f2fe; color: #075985; }
.badge.nnat { background: #fee2e2; color: #991b1b; }
.badge.practice { background: #fef3c7; color: #92400e; }
.history-item .score { font-weight: 700; font-size: 1.05em; }
.history-detail {
  display: none; margin-top: 10px; font-size: 0.82em;
  background: #f9fafb; border-radius: 6px; padding: 10px;
}
.history-detail.open { display: block; }
.detail-grid { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.detail-item { min-width: 80px; }
.detail-item.wrong { color: #dc2626; }
.detail-item.right { color: #16a34a; }

/* Score chart (SVG) */
#score-chart svg { width: 100%; height: 200px; }

/* This week */
.week-meta { font-size: 0.9em; color: #555; line-height: 1.8; }
.topic-tag {
  display: inline-block; background: #dbeafe; color: #1e40af;
  border-radius: 12px; padding: 2px 10px; font-size: 0.8em; margin: 2px;
}

.concept-list { margin: 4px 0 0 20px; padding: 0; font-size: 0.85em; color: #444; }
.concept-list li { margin-bottom: 2px; }

.empty-state { text-align: center; color: #aaa; padding: 40px 0; font-size: 0.9em; }

/* Pending tests list */
.test-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}
.test-item:last-child { border-bottom: none; }

.print-btn {
  display: inline-block;
  padding: 6px 14px;
  background: #1a56db;
  color: white;
  border-radius: 6px;
  font-size: 0.85em;
  font-weight: 500;
  text-decoration: none;
}
.print-btn:hover { background: #1e40af; }

/* History detail — question review */
.q-number { font-size: 0.75em; font-weight: 700; color: #888; text-transform: uppercase; letter-spacing: 0.05em; margin: 14px 0 6px; }
.q-number:first-child { margin-top: 4px; }
.q-detail { border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; margin-bottom: 4px; background: white; }
.q-header { margin-bottom: 8px; }
.q-status { font-size: 0.78em; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.q-status.correct { background: #dcfce7; color: #15803d; }
.q-status.wrong { background: #fee2e2; color: #b91c1c; }
.q-status.skipped { background: #f3f4f6; color: #6b7280; }
.q-text { font-size: 0.88em; line-height: 1.5; margin-bottom: 10px; }
.q-choices { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.choice-item { font-size: 0.85em; padding: 4px 8px; border-radius: 4px; background: #f9fafb; }
.choice-correct { background: #dcfce7; color: #15803d; font-weight: 600; }
.choice-wrong { background: #fee2e2; color: #b91c1c; font-weight: 600; }
.solution-btn {
  font-size: 0.8em; padding: 4px 12px; border: 1px solid #d1d5db;
  border-radius: 4px; background: white; cursor: pointer; color: #374151;
}
.solution-btn:hover { background: #f3f4f6; }
.q-solution { display: none; margin-top: 8px; font-size: 0.85em; line-height: 1.6; color: #374151; padding: 8px; background: #fefce8; border-radius: 4px; border-left: 3px solid #f59e0b; }
.q-solution.open { display: block; }
.q-meta { font-size: 0.78em; color: #6b7280; margin-bottom: 8px; }
.q-meta div { margin-bottom: 2px; }

/* Take-test view */
.take-test-view { background: white; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.tt-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; font-size: 0.85em; color: #666; }
.tt-timer { font-variant-numeric: tabular-nums; }
.tt-progress { font-weight: 600; }
.tt-question { font-size: 0.95em; line-height: 1.6; margin-bottom: 18px; }
.tt-choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.tt-choice {
  text-align: left; padding: 10px 14px; border: 1px solid #d1d5db; border-radius: 6px;
  background: white; cursor: pointer; font-size: 0.9em; font-family: inherit;
}
.tt-choice:hover { background: #f9fafb; }
.tt-choice.selected { background: #dbeafe; border-color: #1a56db; font-weight: 600; }
.tt-nav { display: flex; justify-content: space-between; gap: 10px; }
.tt-nav button {
  padding: 8px 20px; border-radius: 6px; border: none; cursor: pointer; font-size: 0.9em; font-weight: 500;
}
.tt-nav .tt-back { background: #f3f4f6; color: #374151; }
.tt-nav .tt-next { background: #1a56db; color: white; }
.tt-nav .tt-skip { background: transparent; color: #888; text-decoration: underline; }

.tt-review-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 20px; }
.tt-review-cell {
  width: 40px; height: 40px; border-radius: 6px; border: 1px solid #d1d5db;
  background: #f3f4f6; color: #6b7280; font-size: 0.85em; cursor: pointer;
}
.tt-review-cell.answered { background: #dbeafe; border-color: #1a56db; color: #1e40af; font-weight: 600; }
.tt-review-cell.skipped { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

.tt-reason-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #e5e7eb; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tt-reason-select { padding: 4px 8px; border-radius: 4px; border: 1px solid #d1d5db; font-size: 0.85em; }
.tt-reason-detail { flex: 1; min-width: 160px; padding: 4px 8px; border-radius: 4px; border: 1px solid #d1d5db; font-size: 0.85em; }

/* Error Log filters */
.error-log-filters { display: flex; gap: 10px; margin-bottom: 16px; }
.error-log-filters select {
  padding: 6px 10px; border-radius: 6px; border: 1px solid #d1d5db;
  font-size: 0.85em; font-family: inherit; background: white; color: #374151;
}
/* Error Log practice mode */
.hidden { display: none; }

#error-log-topics { display: flex; flex-wrap: wrap; gap: 10px; }
.elp-topic-btn {
  padding: 10px 16px; border-radius: 8px; border: 1px solid #d1d5db;
  background: white; cursor: pointer; font-size: 0.9em; font-family: inherit; color: #374151;
}
.elp-topic-btn:hover { background: #f9fafb; }
.elp-back {
  background: transparent; border: none; color: #1a56db; cursor: pointer;
  font-size: 0.85em; padding: 0 0 12px; text-decoration: underline;
}
.elp-question { font-size: 0.95em; line-height: 1.6; margin-bottom: 18px; }
.elp-choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.elp-choice {
  text-align: left; padding: 10px 14px; border: 1px solid #d1d5db; border-radius: 6px;
  background: white; cursor: pointer; font-size: 0.9em; font-family: inherit;
}
.elp-choice:hover:not(:disabled) { background: #f9fafb; }
.elp-choice.selected { background: #dbeafe; border-color: #1a56db; font-weight: 600; }
.elp-choice:disabled { cursor: default; opacity: 0.7; }
.elp-feedback { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; font-size: 0.9em; }
.elp-feedback.correct { background: #dcfce7; color: #166534; }
.elp-feedback.incorrect { background: #fee2e2; color: #991b1b; }
.elp-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.elp-actions button {
  padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer;
  font-size: 0.9em; font-weight: 500; font-family: inherit;
}
.elp-actions .elp-primary { background: #1a56db; color: white; }
.elp-actions .elp-secondary { background: #f3f4f6; color: #374151; }
.elp-hint { margin-top: 12px; padding: 10px 14px; background: #f3f4f6; border-radius: 6px; font-size: 0.85em; color: #374151; }
