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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1), 0 4px 10px rgba(0,0,0,0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* Header */
header {
  background: linear-gradient(135deg, #1e3a5f 0%, #3b82f6 100%);
  color: white;
  padding: 2rem 1.5rem 1.5rem;
  text-align: center;
}

.header-content h1 {
  font-size: 2rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-block;
  letter-spacing: -0.02em;
}

.header-content h1:hover {
  opacity: 0.9;
}

.subtitle {
  opacity: 0.85;
  font-size: 1.05rem;
  margin-top: 0.25rem;
}

.score-bar {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
  font-size: 0.95rem;
  font-weight: 600;
}

/* Breadcrumb */
.breadcrumb {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.breadcrumb-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  font-weight: 500;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}

.breadcrumb-current {
  color: var(--text-muted);
  font-weight: 500;
}

.separator {
  color: var(--text-muted);
}

/* Main */
main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.hidden {
  display: none !important;
}

/* Subject Grid */
#subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.subject-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}

.subject-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.subject-icon {
  font-size: 2.2rem;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.subject-info h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.subject-info p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Topic List */
.topic-header {
  margin-bottom: 1.5rem;
}

.topic-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.topic-header p {
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.topics-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.topic-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.topic-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.topic-card h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.topic-card .question-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Quiz */
.quiz-container {
  max-width: 680px;
  margin: 0 auto;
}

.quiz-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.quiz-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.question-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.option-btn:hover:not(.disabled) {
  border-color: var(--primary);
  background: #eff6ff;
}

.option-label {
  font-weight: 700;
  color: var(--text-muted);
  min-width: 1.5rem;
  flex-shrink: 0;
}

.option-btn.correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.option-btn.correct .option-label {
  color: var(--success);
}

.option-btn.incorrect {
  border-color: var(--danger);
  background: #fef2f2;
}

.option-btn.incorrect .option-label {
  color: var(--danger);
}

.option-btn.disabled {
  cursor: default;
}

/* Feedback */
.feedback-box {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.feedback-box.correct {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.feedback-box.incorrect {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.explanation {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  opacity: 0.9;
}

.btn-next {
  margin-top: 1.25rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.85rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}

.btn-next:hover {
  background: var(--primary-hover);
}

/* Results */
.results-container {
  text-align: center;
  max-width: 500px;
  margin: 2rem auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
}

.results-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.results-container h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.results-score {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0.5rem 0;
}

.results-bar-container {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin: 1rem 0;
}

.results-bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
}

.results-message {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.btn {
  padding: 0.85rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

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

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

/* Footer */
footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* Question type badges */
.question-type-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  margin-right: 0.75rem;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

.badge-mc {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-short {
  background: #fef3c7;
  color: #92400e;
}

.badge-long {
  background: #ede9fe;
  color: #6d28d9;
}

/* Short answer */
.short-answer-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.short-answer-input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
}

.short-answer-input:focus {
  outline: none;
  border-color: var(--primary);
}

.short-answer-input.input-correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.short-answer-input.input-incorrect {
  border-color: var(--danger);
  background: #fef2f2;
}

.short-answer-input:disabled {
  opacity: 0.7;
  cursor: default;
}

.btn-submit {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 0.85rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}

.btn-submit:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Long answer */
.long-answer-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}

.marks-badge {
  display: inline-block;
  background: #ede9fe;
  color: #6d28d9;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.8rem;
  border-radius: 8px;
  align-self: flex-start;
}

.long-answer-input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  min-height: 160px;
  line-height: 1.6;
  transition: border-color 0.15s;
}

.long-answer-input:focus {
  outline: none;
  border-color: var(--primary);
}

.long-answer-input:disabled {
  opacity: 0.7;
  cursor: default;
}

/* Mark scheme panel */
.mark-scheme-panel {
  background: var(--surface);
  border: 2px solid #c4b5fd;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1rem;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.mark-scheme-panel h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: #6d28d9;
}

.mark-scheme-list {
  list-style: none;
  padding: 0;
  margin-bottom: 1.25rem;
}

.mark-scheme-list li {
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
  background: #f5f3ff;
  border-radius: 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  border-left: 3px solid #8b5cf6;
}

.model-answer-section {
  margin-bottom: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.model-answer-text {
  background: #fafaf9;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.self-assess-section {
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.self-assess-section h4 {
  color: var(--text);
}

.self-assess-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.self-assess-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  min-width: 3.5rem;
  text-align: center;
}

.self-assess-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #eff6ff;
  transform: translateY(-1px);
}

.self-assess-btn.selected {
  border-color: #8b5cf6;
  background: #ede9fe;
  color: #6d28d9;
}

.self-assess-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Topic card actions row */
.topic-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.topic-action-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  text-align: center;
}

.topic-action-btn:active {
  transform: scale(0.97);
}

.topic-action-btn.action-learn {
  background: #dbeafe;
  color: #1d4ed8;
}

.topic-action-btn.action-learn:hover {
  background: #bfdbfe;
}

.topic-action-btn.action-quiz {
  background: #f0fdf4;
  color: #166534;
}

.topic-action-btn.action-quiz:hover {
  background: #dcfce7;
}

/* Learn View */
.learn-container {
  max-width: 760px;
  margin: 0 auto;
}

.learn-header {
  margin-bottom: 2rem;
}

.learn-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
}

.learn-subtitle {
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-size: 1rem;
}

.learn-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.learn-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.learn-section-header {
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.learn-section-header .section-icon {
  font-size: 1.1rem;
}

.learn-section-body {
  padding: 1.25rem;
}

/* Key points */
.key-point {
  margin-bottom: 1.25rem;
}

.key-point:last-child {
  margin-bottom: 0;
}

.key-point h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.key-point p {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text);
}

/* Key terms */
.key-term {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.key-term:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.key-term:first-child {
  padding-top: 0;
}

.key-term dt {
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 120px;
  flex-shrink: 0;
  color: var(--text);
}

.key-term dd {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
}

/* Formulas */
.formula-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.formula-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* Exam tips */
.exam-tips-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.exam-tip {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
  padding: 0.5rem 0.75rem;
  background: #fffbeb;
  border-radius: 8px;
  border: 1px solid #fef3c7;
}

.exam-tip::before {
  content: "💡";
  flex-shrink: 0;
}

/* Learn actions */
.learn-actions {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* No content available message */
.learn-no-content {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}

.learn-no-content p {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.learn-no-content .learn-no-content-sub {
  font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 640px) {
  header {
    padding: 1.5rem 1rem 1rem;
  }

  .header-content h1 {
    font-size: 1.5rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  main {
    padding: 1rem;
  }

  #subject-grid {
    grid-template-columns: 1fr;
  }

  .topics-container {
    grid-template-columns: 1fr;
  }

  .question-text {
    font-size: 1.1rem;
  }

  .results-container {
    padding: 2rem 1.25rem;
  }
}
