:root {
  --primary: #4f46e5;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --danger: #dc2626;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
}

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

body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 5%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-size: 21px;
  font-weight: 800;
  color: var(--primary);
}

.header-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.container {
  max-width: 1100px;
  margin: 30px auto;
  padding: 0 18px;
}

.exam-info {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(130px, 0.7fr) minmax(160px,
      0.85fr);
  gap: 14px;
  margin-bottom: 22px;
}

.info-card {
  background: white;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

/* Tên đề thi dài vẫn nằm gọn trong thẻ */
.exam-name {
  font-size: clamp(15px, 1.5vw, 18px);
  line-height: 1.4;
  font-weight: 700;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.exam-info .info-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.info-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 5px;
}

.info-value {
  font-size: 21px;
  font-weight: 700;
}

.timer {
  color: var(--danger);
}

.progress-wrapper {
  background: #e2e8f0;
  height: 8px;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}

.exam-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 22px;
  align-items: start;
}

.question-card,
.sidebar,
.result-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.03);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.question-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 16px;
  font-weight: 700;
}

.question-title {
  font-size: 20px;
  line-height: 1.6;
  margin-bottom: 24px;
  white-space: pre-line;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option {
  width: 100%;
  text-align: left;
  padding: 15px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  display: flex;
  gap: 13px;
  align-items: flex-start;
  background: white;
  transition: 0.2s;
  color: #1e293b;
}

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

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

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

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

.option-letter {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f1f5f9;
  font-weight: 700;
}

.option.selected .option-letter {
  color: white;
  background: var(--primary);
}

.option.correct .option-letter {
  color: white;
  background: var(--success);
}

.option.wrong .option-letter {
  color: white;
  background: var(--danger);
}

.explanation {
  display: none;
  margin-top: 20px;
  padding: 15px;
  background: #f8fafc;
  border-radius: 10px;
  border-left: 4px solid var(--primary);
}

.explanation.show {
  display: block;
}

.navigation {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.btn {
  padding: 11px 18px;
  border-radius: 9px;
  font-weight: 700;
  transition: 0.2s;
}

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

.btn-primary:hover {
  background: #4338ca;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--text);
}

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

.sidebar h3 {
  font-size: 17px;
  margin-bottom: 5px;
}

.sidebar-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.question-number {
  aspect-ratio: 1;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--text);
  font-weight: 700;
  border: 1px solid transparent;
}

.question-number.answered {
  background: #dcfce7;
  color: #166534;
}

.question-number.current {
  border: 2px solid var(--primary);
  color: var(--primary);
}

.question-number.correct {
  background: #dcfce7;
  color: #166534;
}

.question-number.wrong {
  background: #fee2e2;
  color: #991b1b;
}

.legend {
  margin-top: 18px;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 7px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: #dcfce7;
}

.dot-gray {
  background: #f1f5f9;
}

.submit-sidebar {
  width: 100%;
  margin-top: 22px;
}

.result-card {
  display: none;
  margin-top: 24px;
  text-align: center;
}

.result-card.show {
  display: block;
}

.result-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--primary);
  margin: 10px 0;
}

.result-details {
  color: var(--muted);
  margin-bottom: 20px;
}

.result-summary {
  display: flex;
  justify-content: center;
  gap: 25px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.result-summary strong {
  display: block;
  font-size: 23px;
}

.result-summary .green {
  color: var(--success);
}

.result-summary .red {
  color: var(--danger);
}

.footer {
  text-align: center;
  padding: 25px;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

@media (max-width: 800px) {
  .exam-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: -1;
  }

  .question-grid {
    grid-template-columns: repeat(10, 1fr);
  }

  .exam-info {
    gap: 8px;
    grid-template-columns: minmax(0, 1.2fr) minmax(120px, 0.8fr);
  }

  .exam-info .info-card:first-child {
    grid-column: 1 / -1;
  }

  .info-card {
    padding: 14px;
  }

  .info-value {
    font-size: 17px;
  }

  .exam-name {
    font-size: 16px;
    -webkit-line-clamp: 3;
    line-clamp: 3;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 12px 16px;
  }

  .brand {
    font-size: 17px;
  }

  .header-subtitle {
    display: none;
  }

  .container {
    margin-top: 18px;
    padding: 0 12px;
  }

  .question-card,
  .sidebar,
  .result-card {
    padding: 17px;
  }

  .question-title {
    font-size: 17px;
  }

  .question-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .navigation .btn {
    padding: 10px 12px;
    font-size: 13px;
  }
}

.question-number.unanswered {
  background: #fef3c7;
  color: #92400e;
}

.result-time {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: -10px 0 20px;
  color: var(--muted);
  font-size: 15px;
}

.result-time strong {
  color: var(--primary);
  font-size: 17px;
  font-weight: 700;
}

#resultCard {
  scroll-margin-top: 20px;
}

