:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #626b73;
  --line: #d8ded7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warn: #b45309;
  --bad: #b42318;
  --good: #047857;
  --shadow: 0 16px 40px rgba(18, 38, 35, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.masthead,
.results-head {
  padding: 28px 4px 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  max-width: 10ch;
  font-size: clamp(2.4rem, 13vw, 4.8rem);
}

h2 {
  font-size: 1.45rem;
}

.lede {
  max-width: 44rem;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.setup-panel,
.question-panel,
.mistake-panel,
.domain-card,
.review-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.setup-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.mistake-panel {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 16px;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2ee;
}

.mode-button,
.count-button,
.primary-button,
.secondary-button,
.quiet-button,
.choice-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.mode-button {
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.mode-button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px;
  color: var(--ink);
}

.toggle-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.toggle-row input {
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.question-count {
  display: grid;
  gap: 10px;
  padding: 12px 2px 2px;
}

.question-count small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.count-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.count-button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 900;
}

.count-button.active {
  border-color: var(--accent);
  background: #e8f4f1;
  color: var(--accent-strong);
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.quiet-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--bad);
  font-weight: 800;
}

.mistake-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mistake-bank-list {
  display: grid;
  gap: 8px;
}

.mistake-bank-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.mistake-bank-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.mistake-bank-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

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

.timer {
  min-width: 78px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: center;
  font-weight: 900;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe2dc;
}

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

.question-panel {
  margin-top: 16px;
  padding: 18px;
}

.question-text {
  margin: 0 0 18px;
  font-size: 1.16rem;
  font-weight: 800;
  line-height: 1.42;
}

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

.choice-button {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: start;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--ink);
  text-align: left;
  line-height: 1.35;
}

.choice-letter {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  background: #e4ebe5;
  font-weight: 900;
}

.choice-button.selected {
  border-color: var(--accent);
  background: #e8f4f1;
}

.choice-button.correct {
  border-color: var(--good);
  background: #ecfdf3;
}

.choice-button.incorrect {
  border-color: var(--bad);
  background: #fff1f0;
}

.feedback {
  min-height: 26px;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

.quiz-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
  margin-top: 14px;
}

.results-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.domain-results {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.domain-card {
  padding: 14px;
}

.domain-card strong {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.domain-meter {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1e7e2;
}

.domain-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.review-list {
  display: grid;
  gap: 12px;
  margin: 18px 0 32px;
}

.review-item {
  padding: 14px;
  box-shadow: none;
}

.review-item p {
  margin: 8px 0;
  line-height: 1.45;
}

.review-item .answer {
  color: var(--good);
  font-weight: 800;
}

@media (max-width: 520px) {
  .app {
    padding: 14px;
  }

  .quiz-header {
    align-items: flex-start;
  }

  .question-panel {
    padding: 14px;
  }

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

  .results-actions,
  .mistake-actions {
    grid-template-columns: 1fr;
  }
}
