.quiz-page {
  max-width: 1120px;
}

.topic-tabs,
.view-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.topic-tabs a,
.view-tab {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.topic-tabs a.active,
.view-tab.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.view-tabs {
  margin-bottom: 12px;
}

.quiz-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 0 18px;
}

.quiz-header h1 {
  font-size: clamp(30px, 4vw, 44px);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 1fr));
  min-width: 300px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: var(--radius);
}

.scoreboard div {
  padding: 11px 14px;
  text-align: center;
}

.scoreboard div + div {
  border-left: 1px solid var(--line);
}

.scoreboard span,
.scoreboard small,
.result-stats strong,
.result-stats span {
  display: block;
}

.scoreboard span {
  font-size: 20px;
  font-weight: 700;
}

.scoreboard small,
.result-stats span {
  color: var(--muted);
  font-size: 12px;
}

.progress {
  height: 7px;
  overflow: hidden;
  margin-bottom: 14px;
  background: #dfe4e2;
  border-radius: 4px;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.quiz-panel,
.resume-panel,
.result-panel,
.setup-panel,
.stats-panel {
  min-height: 500px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.resume-panel {
  min-height: 280px;
}

.setup-panel h2,
.stats-panel h2 {
  font-size: 28px;
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row small,
.settings-hint,
.stats-heading > p,
.empty-state {
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(170px, .7fr) repeat(2, 1.25fr);
  gap: 12px;
}

.field,
.toggle-row {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.field > span {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.field select {
  width: 100%;
  min-height: 42px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.toggle-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
}

.settings-hint {
  margin: 14px 0 0;
  font-size: 14px;
}

.resume-panel h2 {
  font-size: 27px;
}

.question-topic,
.result-label {
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.quiz-panel h2 {
  min-height: 60px;
  margin-bottom: 22px;
  font-size: 25px;
}

.answers {
  display: grid;
  gap: 10px;
}

.answer-button {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.answer-button:hover:not(:disabled) {
  border-color: #77998f;
  background: #f5faf8;
}

.answer-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible {
  outline: 3px solid #f0c75e;
  outline-offset: 2px;
}

.answer-button.selected {
  border-color: var(--accent);
  background: var(--soft);
}

.answer-button.correct {
  border-color: #2f7d4c;
  background: #eaf6ee;
}

.answer-button.incorrect {
  border-color: #a63d3d;
  background: #fbeaea;
}

.answer-letter {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-weight: 700;
}

.feedback {
  margin-top: 18px;
  padding: 14px 16px;
  border-left: 4px solid var(--accent);
  background: var(--soft);
}

.feedback.wrong {
  border-left-color: #a63d3d;
  background: #fbeaea;
}

.feedback-title,
.reference-link,
.mistake-reference {
  font-weight: 700;
}

.reference-link,
.mistake-reference {
  display: inline-block;
  margin-top: 4px;
}

.quiz-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary-button:disabled {
  border-color: #aeb8b4;
  background: #aeb8b4;
  cursor: not-allowed;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  text-decoration: none;
}

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

.result-panel h2 {
  font-size: 32px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 26px auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-stats div {
  min-width: 0;
  padding: 16px 8px;
}

.result-stats div + div {
  border-left: 1px solid var(--line);
}

.result-stats strong {
  font-size: 25px;
  white-space: nowrap;
}

.mistakes {
  margin-top: 28px;
  text-align: left;
}

.mistakes h3 {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.mistake-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.mistake-item p {
  margin: 4px 0;
}

.mistake-answer {
  color: #8b3030;
}

.correct-answer {
  color: #24653e;
}

.result-actions {
  justify-content: center;
}

.stats-panel {
  min-height: 0;
}

.stats-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin: 22px 0 28px;
  border: 1px solid var(--line);
}

.stats-summary div {
  min-width: 0;
  padding: 15px 10px;
  text-align: center;
}

.stats-summary div + div {
  border-left: 1px solid var(--line);
}

.stats-summary strong,
.stats-summary span {
  display: block;
}

.stats-summary strong {
  font-size: 23px;
}

.stats-summary span {
  color: var(--muted);
  font-size: 12px;
}

.stats-columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 28px;
}

.stats-columns section,
.stats-section {
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.stats-section {
  margin-top: 30px;
}

.stats-reset-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px 28px;
  align-items: end;
}

.stats-reset-section h3,
.stats-reset-section p {
  margin-bottom: 0;
}

.stats-reset-section p {
  max-width: 720px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.stats-reset-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.stats-reset-field {
  min-width: 220px;
}

.danger-button {
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid #a84a45;
  border-radius: 6px;
  background: #fff;
  color: #8b302c;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.danger-button-strong {
  background: #8b302c;
  color: #fff;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #f8e9e7;
  outline: 2px solid #d39a96;
  outline-offset: 1px;
}

.danger-button-strong:hover,
.danger-button-strong:focus-visible {
  background: #722622;
}

.danger-button:disabled {
  border-color: #c8cecb;
  background: #eef1f0;
  color: #77817d;
  cursor: not-allowed;
  outline: 0;
}

.stats-reset-status {
  grid-column: 1 / -1;
  min-height: 20px;
  margin-top: -10px;
  color: var(--accent-dark) !important;
  font-weight: 700;
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.chart-row {
  display: grid;
  grid-template-columns: 88px 1fr 45px;
  gap: 9px;
  align-items: center;
  font-size: 13px;
}

.chart-track {
  height: 12px;
  overflow: hidden;
  background: #dfe4e2;
  border-radius: 3px;
}

.chart-bar {
  height: 100%;
  background: var(--accent);
}

.stats-link {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.stats-link:hover,
.stats-link:focus-visible {
  color: var(--accent);
}

.hard-question {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.hard-question:hover span {
  text-decoration: underline;
}

.table-wrap {
  overflow-x: auto;
}

.question-stats-wrap {
  overflow-x: visible;
}

.stats-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.stats-panel th,
.stats-panel td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.stats-panel th {
  background: #f2f5f4;
  font-size: 12px;
  white-space: nowrap;
}

.stats-panel table:not(.question-stats-table) td:not(:first-child),
.question-stats-table td:nth-child(n + 3) {
  white-space: nowrap;
}

.question-stats-table {
  table-layout: fixed;
}

.question-stats-table th:first-child,
.question-stats-table td:first-child {
  width: 48px;
  text-align: center;
}

.question-stats-table th:nth-child(n + 3):not(:last-child),
.question-stats-table td:nth-child(n + 3):not(:last-child) {
  width: 56px;
  text-align: center;
}

.question-stats-table th:last-child,
.question-stats-table td:last-child {
  width: 92px;
  text-align: center;
}

.question-stats-table .question-cell {
  white-space: normal;
  overflow-wrap: break-word;
}

.metric-heading {
  color: var(--accent-dark);
  font-size: 18px !important;
  text-align: center !important;
}

.metric-glyph,
.status-short {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.status-mastered { background: #e1f2e7; color: #24653e; }
.status-progress { background: #fff0cc; color: #765514; }
.status-new { background: #e8eceb; color: #52615d; }

[hidden] {
  display: none !important;
}

@media (max-width: 700px) {
  .topic-tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    overflow: visible;
  }

  .topic-tabs a {
    padding: 9px 3px;
    font-size: 13px;
    text-align: center;
  }

  .quiz-header {
    align-items: stretch;
    flex-direction: column;
  }

  .scoreboard {
    min-width: 0;
  }

  .quiz-panel,
  .resume-panel,
  .result-panel,
  .setup-panel,
  .stats-panel {
    min-height: 0;
    padding: 20px;
  }

  .quiz-panel h2 {
    min-height: 0;
    font-size: 22px;
  }

  .result-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings-grid,
  .stats-columns {
    grid-template-columns: 1fr;
  }

  .stats-reset-section,
  .stats-reset-controls {
    grid-template-columns: 1fr;
  }

  .stats-reset-field {
    min-width: 0;
  }

  .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-summary div + div {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .stats-summary div:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .stats-heading {
    align-items: start;
    flex-direction: column;
  }

  .result-stats div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .result-stats div:nth-child(4) {
    border-top: 1px solid var(--line);
  }

  .question-stats-table,
  .question-stats-table tbody {
    display: block;
  }

  .question-stats-table thead {
    display: none;
  }

  .question-stats-table tr {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .question-stats-table td {
    width: auto !important;
    padding: 6px 4px;
    border: 0;
  }

  .question-stats-table .topic-number {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
    text-align: left;
    font-size: 16px;
  }

  .question-stats-table .question-cell {
    grid-column: 2 / -1;
    grid-row: 1;
    min-width: 0;
    padding-left: 8px;
    text-align: left;
    line-height: 1.45;
  }

  .question-stats-table .metric-cell {
    display: flex;
    grid-row: 2;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  .question-stats-table td:nth-child(3) { grid-column: 1; }
  .question-stats-table td:nth-child(4) { grid-column: 2; }
  .question-stats-table td:nth-child(5) { grid-column: 3; }
  .question-stats-table td:nth-child(6) { grid-column: 4; }
  .question-stats-table td:nth-child(7) { grid-column: 5; }

  .metric-glyph,
  .status-short {
    display: inline;
  }

  .metric-glyph {
    color: var(--accent-dark);
    font-size: 15px;
  }

  .status-cell > .metric-glyph {
    display: none;
  }

  .status-long {
    display: none;
  }

  .question-stats-table .status {
    min-width: 24px;
    padding: 2px 5px;
    text-align: center;
  }
}

@media print {
  .progress,
  .quiz-actions,
  .result-actions {
    display: none;
  }
}
