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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.lang-selector {
  display: flex;
  gap: 4px;
}

.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  border: 2px solid transparent;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, border-color 0.2s;
}

.lang-btn:hover {
  opacity: 0.8;
}

.lang-btn.active {
  opacity: 1;
  border-color: var(--primary);
}

/* Main container */
main {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

/* Home screen */
.home {
  text-align: center;
  padding-top: 32px;
}

.home h1 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.home p {
  color: var(--text-light);
  margin-bottom: 32px;
}

.category-select {
  margin-bottom: 32px;
}

.category-select label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

.category-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.category-btn {
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.category-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.category-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.mode-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto;
}

.mode-btn {
  display: block;
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.mode-btn.primary {
  background: var(--primary);
  color: #fff;
}

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

.mode-btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

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

/* Browse screen */
.browse-header {
  margin-bottom: 16px;
}

.browse-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.browse-filters select,
.browse-filters input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--surface);
  flex: 1;
  min-width: 140px;
}

.browse-filters input {
  min-width: 200px;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.question-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e0e7ff;
  color: #3730a3;
}

.badge.scope-basic {
  background: #dbeafe;
  color: #1e40af;
}

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

.question-text {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 16px;
  line-height: 1.6;
}

.question-media {
  margin-bottom: 16px;
  text-align: center;
}

.question-media img,
.question-media video {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius);
}

.answers-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.answer-item {
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s;
}

.answer-item:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.answer-item.selected {
  border-color: var(--primary);
  background: #dbeafe;
}

.answer-item.correct {
  border-color: var(--success);
  background: var(--success-bg);
}

.answer-item.incorrect {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.answer-item .answer-label {
  font-weight: 700;
  margin-right: 6px;
}

.show-answer-btn,
.nav-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.show-answer-btn {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

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

.question-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

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

.nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.question-counter {
  color: var(--text-light);
  font-size: 0.9rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

/* Exam screen */
.exam-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.exam-timer {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.exam-timer.warning {
  color: var(--danger);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.exam-progress {
  color: var(--text-light);
  font-weight: 600;
}

.exam-question .answers-list .answer-item {
  padding: 14px 18px;
  font-size: 1rem;
}

.exam-nav {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.exam-next-btn {
  padding: 12px 32px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

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

.exam-next-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Results screen */
.results {
  text-align: center;
  padding-top: 32px;
}

.results h2 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.results-score {
  font-size: 3rem;
  font-weight: 800;
  margin: 16px 0;
}

.results-score.pass {
  color: var(--success);
}

.results-score.fail {
  color: var(--danger);
}

.results-info {
  color: var(--text-light);
  margin-bottom: 24px;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  margin: 0 auto 32px;
}

.results-review {
  margin-top: 16px;
}

.results-review h3 {
  text-align: left;
  margin-bottom: 12px;
}

.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  text-align: left;
}

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

.review-item.review-incorrect {
  border-left: 4px solid var(--danger);
}

.review-question {
  font-weight: 500;
  margin-bottom: 8px;
}

.review-answers {
  font-size: 0.9rem;
  color: var(--text-light);
}

.review-answers .your-answer {
  font-weight: 600;
}

.review-answers .correct-answer {
  color: var(--success);
  font-weight: 600;
}

/* Yes/No buttons for browse and exam */
.yn-answers {
  display: flex;
  gap: 12px;
}

.yn-answers .answer-item {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}

/* Loading state */
.loading {
  text-align: center;
  padding: 48px;
  color: var(--text-light);
}

.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive */
@media (min-width: 640px) {
  main {
    padding: 24px;
  }

  .home h1 {
    font-size: 2.2rem;
  }

  .mode-buttons {
    flex-direction: row;
    max-width: none;
    justify-content: center;
  }

  .mode-btn {
    flex: 0 0 auto;
    min-width: 200px;
  }
}

/* Back button */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-light);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

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

/* Utility */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-16 {
  margin-top: 16px;
}
