:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --text: #16201d;
  --muted: #687772;
  --border: #d6e0dc;
  --primary: #0f6f61;
  --primary-dark: #084d43;
  --accent: #b75d28;
  --danger: #b72b35;
  --success: #177245;
  --shadow: 0 16px 40px rgba(22, 32, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  min-height: 42px;
  padding: 0 16px;
}

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

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

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

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 8px 0 24px;
}

.topbar h1,
.section-heading h2,
.panel h2 {
  margin: 0;
}

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

.summary-strip {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 18px;
  padding: 14px 18px;
}

.summary-strip span {
  color: var(--muted);
  white-space: nowrap;
}

.summary-strip strong {
  color: var(--text);
  display: block;
  font-size: 1.2rem;
}

.layout {
  align-items: start;
  display: grid;
  gap: 22px;
  grid-template-columns: 300px 1fr;
}

.panel,
.workspace,
.history-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  position: sticky;
  top: 18px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select {
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  min-height: 42px;
  padding: 0 12px;
}

.workspace {
  min-height: 520px;
  padding: 24px;
}

.empty-state {
  align-content: center;
  display: grid;
  min-height: 460px;
  text-align: center;
}

.empty-state h2 {
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1;
  margin: 0 0 12px;
}

.empty-state p {
  color: var(--muted);
  margin: 0 auto;
  max-width: 620px;
}

.hidden {
  display: none !important;
}

.quiz {
  display: grid;
  gap: 22px;
}

.quiz-header {
  align-items: start;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding-bottom: 18px;
}

.quiz-header h2 {
  font-size: 1.45rem;
  margin: 0;
}

.timer {
  background: #16201d;
  border-radius: 6px;
  color: white;
  font-weight: 800;
  min-width: 92px;
  padding: 10px 12px;
  text-align: center;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.55;
}

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

.answer-option {
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 22px 1fr;
  line-height: 1.45;
  padding: 14px;
}

.answer-option:hover {
  background: var(--surface-2);
}

.answer-option input {
  margin-top: 3px;
  min-height: auto;
}

.quiz-actions {
  align-items: center;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr auto auto;
  padding-top: 18px;
}

#progressText {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.score-card {
  background: var(--surface-2);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
  padding: 20px;
}

.score-card strong {
  font-size: clamp(2.2rem, 7vw, 4.4rem);
  line-height: 1;
}

.topic-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin: 16px 0 24px;
}

.topic-pill {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.review-list,
.history-list {
  display: grid;
  gap: 12px;
}

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

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

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

.review-item h3,
.history-item h3 {
  font-size: 1rem;
  margin: 0 0 8px;
}

.review-item p,
.history-item p,
.section-heading p {
  color: var(--muted);
  margin: 4px 0;
}

.history-section {
  margin-top: 22px;
  padding: 22px;
}

.section-heading {
  align-items: end;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-item {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
}

.badge {
  border-radius: 999px;
  color: white;
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 9px;
}

.badge.good {
  background: var(--success);
}

.badge.bad {
  background: var(--danger);
}

code {
  background: #edf1ef;
  border-radius: 4px;
  padding: 2px 5px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar,
  .section-heading,
  .quiz-header {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-strip,
  .layout {
    display: grid;
    grid-template-columns: 1fr;
  }

  .controls-panel {
    position: static;
  }

  .workspace {
    padding: 16px;
  }

  .quiz-actions {
    grid-template-columns: 1fr 1fr;
  }

  #progressText {
    grid-column: 1 / -1;
    order: -1;
  }

  .history-item {
    grid-template-columns: 1fr;
  }
}
