:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

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

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

.page {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}

h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin: 4px;
}

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

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

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

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

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 18px;
}

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

.quiz-select {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  margin-bottom: 12px;
  cursor: pointer;
}

.quiz-select:focus {
  outline: none;
  border-color: var(--primary);
}

.custom-quiz-list {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.custom-quiz-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.custom-quiz-item span {
  font-size: 14px;
  color: var(--text);
}

.btn-text {
  background: none;
  border: none;
  color: var(--error);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 0;
  margin-top: 8px;
}

.btn-text:hover {
  text-decoration: underline;
}

.btn-small {
  padding: 6px 12px;
  font-size: 14px;
}

/* Button Groups */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.btn-group .btn {
  flex: 1;
  min-width: 70px;
}

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

/* Quiz List */
.quiz-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 24px 0;
}

/* Settings */
.setting-group {
  margin-bottom: 24px;
}

.setting-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
}

/* Quiz Header */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

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

.score {
  font-weight: 600;
  color: var(--primary);
}

/* Question */
.question {
  margin-bottom: 24px;
}

.question-content {
  font-size: 18px;
  font-weight: 500;
  line-height: 1.5;
  white-space: pre-wrap;
}

.question-type {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 8px;
}

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

.option {
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
}

.option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.option span {
  flex: 1;
}

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

.option.selected {
  border-color: var(--primary);
  background: #e0f2fe;
}

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

.option.wrong {
  border-color: var(--error);
  background: #fee2e2;
}

/* Feedback */
.feedback {
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  margin-bottom: 16px;
}

.feedback.correct {
  background: #dcfce7;
  color: var(--success);
}

.feedback.wrong {
  background: #fee2e2;
  color: var(--error);
}

/* Navigation */
.nav-buttons {
  display: flex;
  gap: 12px;
}

.nav-buttons .btn {
  flex: 1;
}

.nav-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 24px;
}

.nav-links a {
  color: var(--primary);
  text-decoration: none;
}

.nav-links a:hover {
  text-decoration: underline;
}

/* Back Link */
.back-link {
  display: block;
  text-align: center;
  margin-top: 16px;
  color: var(--text-secondary);
  text-decoration: none;
}

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

/* Result */
.score-card {
  text-align: center;
  padding: 32px;
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  border-radius: 12px;
  color: white;
  margin-bottom: 24px;
}

.score-value {
  font-size: 48px;
  font-weight: 700;
}

.score-detail {
  font-size: 18px;
  opacity: 0.9;
}

.score-points {
  font-size: 16px;
  margin-top: 8px;
  opacity: 0.9;
}

/* Analysis */
.analysis {
  margin-bottom: 24px;
}

.analysis h3 {
  font-size: 16px;
  margin-bottom: 16px;
}

.analysis-item {
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  border-left: 4px solid;
}

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

.analysis-item.wrong {
  background: #fef2f2;
  border-color: var(--error);
}

.analysis-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.q-number {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
}

.q-status {
  font-weight: 600;
}

.analysis-item.correct .q-status {
  color: var(--success);
}

.analysis-item.wrong .q-status {
  color: var(--error);
}

.q-content {
  font-weight: 500;
  margin-bottom: 8px;
}

.q-answer {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.q-explanation {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 8px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 4px;
}

.result-actions {
  display: flex;
  gap: 12px;
}

.result-actions .btn {
  flex: 1;
}

/* History */
.history-list, .error-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.history-title {
  font-weight: 500;
  margin-bottom: 8px;
}

.history-meta {
  display: flex;
  gap: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

.history-meta .mode {
  color: var(--primary);
}

.history-meta .score {
  color: var(--error);
}

.history-time {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* Errors */
.error-item {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
}

.error-number {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--error);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
}

.error-content {
  font-weight: 500;
  margin-bottom: 8px;
}

.error-answer {
  font-size: 14px;
  color: var(--success);
  margin-bottom: 8px;
}

.error-explanation {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.error-item .btn-small {
  margin-top: 8px;
}

.empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
}

.modal-content h3 {
  margin-bottom: 16px;
}

.modal-content textarea {
  width: 100%;
  height: 200px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  resize: vertical;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.modal-buttons .btn {
  flex: 1;
}

/* Loading Overlay */
#loadingOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-box {
  background: var(--surface);
  padding: 32px 48px;
  border-radius: 12px;
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  font-size: 16px;
  color: var(--text);
}

/* Responsive */
@media (max-width: 480px) {
  .container {
    padding: 12px;
  }

  .page {
    padding: 16px;
  }

  h1 {
    font-size: 20px;
  }

  .question-content {
    font-size: 16px;
  }

  .option {
    padding: 12px;
    font-size: 14px;
  }

  .score-card {
    padding: 24px;
  }

  .score-value {
    font-size: 36px;
  }
}