:root {
  --navy: #17365d;
  --blue: #2c6e9f;
  --sky: #eaf5fb;
  --gold: #d9a62e;
  --cream: #fffaf0;
  --ink: #263238;
  --green: #2e7d32;
  --green-bg: #e7f5e8;
  --red: #b3261e;
  --red-bg: #fdeceb;
  --line: #c7d9e5;
  --shadow: 0 8px 24px rgba(23, 54, 93, .13);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
  background:
    radial-gradient(circle at 15% 12%, rgba(217, 166, 46, .16), transparent 24rem),
    linear-gradient(180deg, #eef8fc 0%, #fffaf0 100%);
  min-height: 100vh;
}

button, a { font: inherit; }
button { touch-action: manipulation; }

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

.home-link {
  display: inline-block;
  padding: 8px 15px;
  color: white;
  background: var(--navy);
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-decoration: none;
}

.home-link:hover, .home-link:focus-visible { background: var(--blue); }

.page-heading {
  padding: 22px 12px 18px;
  text-align: center;
}

.eyebrow, .category-label {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: .82rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 8px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: clamp(2rem, 6vw, 3.25rem);
}

.page-heading > p:last-child { margin-bottom: 0; font-size: 1.05rem; }
.section-heading { margin-bottom: 16px; text-align: center; }
.section-heading h2 { margin-bottom: 5px; color: var(--navy); }
.section-heading p { margin-bottom: 0; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.category-card {
  display: flex;
  min-height: 230px;
  padding: 22px;
  flex-direction: column;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: center;
  transition: transform .16s ease, border-color .16s ease;
}

.category-card:hover, .category-card:focus-visible {
  border-color: var(--gold);
  transform: translateY(-3px);
}

.category-icon {
  display: grid;
  width: 68px;
  height: 68px;
  margin-bottom: 13px;
  place-items: center;
  border-radius: 50%;
  background: var(--sky);
  font-size: 2rem;
}

.category-card h3 { margin-bottom: 9px; color: var(--navy); font-size: 1.2rem; }
.category-card p { margin-bottom: 16px; line-height: 1.42; }
.category-card strong { margin-top: auto; color: var(--blue); }

.quiz-topbar, .progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.quiz-topbar { justify-content: space-between; margin-bottom: 12px; }
.text-button { border: 0; color: var(--navy); background: transparent; cursor: pointer; font-weight: 800; }
.score-box { display: flex; align-items: center; gap: 9px; color: var(--navy); }
.score-box strong {
  display: grid;
  min-width: 44px;
  min-height: 44px;
  padding: 4px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--navy);
  font-size: 1.15rem;
}

.progress-row { margin: 0 auto 14px; }
#progress-text { min-width: 92px; font-size: .9rem; font-weight: 700; }
.progress-track { height: 12px; flex: 1; overflow: hidden; border-radius: 999px; background: #dbe8ef; }
#progress-fill { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--gold), #f0c95d); transition: width .25s; }

.question-card, .results-card {
  padding: clamp(24px, 5vw, 42px);
  border: 2px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
}

.question-card h2 {
  margin-bottom: 10px;
  color: var(--navy);
  font-family: Georgia, serif;
  font-size: clamp(1.8rem, 5vw, 2.65rem);
}

.question { margin-bottom: 20px; font-size: 1.08rem; line-height: 1.45; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.answer-button {
  min-height: 64px;
  padding: 12px 15px;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: white;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.3;
}

.answer-button:hover:not(:disabled), .answer-button:focus-visible { border-color: var(--blue); background: var(--sky); }
.answer-button.correct { border-color: var(--green); color: #185c1d; background: var(--green-bg); }
.answer-button.wrong { border-color: var(--red); color: #7c1b16; background: var(--red-bg); }
.answer-button:disabled { cursor: default; }

.feedback {
  margin-top: 18px;
  padding: 16px 18px;
  border-left: 6px solid var(--green);
  border-radius: 9px;
  background: var(--green-bg);
}

.feedback h3 { margin-bottom: 6px; color: var(--green); }
.feedback p { margin-bottom: 7px; line-height: 1.45; }
.feedback p:last-child { margin-bottom: 0; }
.reference { color: var(--navy); font-weight: 800; }

.primary-button, .secondary-button {
  padding: 12px 18px;
  border: 2px solid var(--navy);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button { margin-top: 18px; color: white; background: var(--navy); }
.primary-button:hover, .primary-button:focus-visible { background: var(--blue); border-color: var(--blue); }
.secondary-button { color: var(--navy); background: white; }
.secondary-button:hover, .secondary-button:focus-visible { background: var(--sky); }
.attempt-note { min-height: 22px; margin: 10px 0 0; color: #52616b; text-align: center; }

.results-card { max-width: 700px; margin: 20px auto; text-align: center; }
.results-card h2 { color: var(--navy); font-family: Georgia, serif; font-size: 2rem; }
.final-score { display: flex; margin: 18px 0; flex-direction: column; color: var(--navy); }
.final-score strong { font-size: 3.5rem; line-height: 1; }
.mastery-message { padding: 12px; border-radius: 10px; background: var(--cream); font-weight: 700; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.result-actions .primary-button { margin-top: 0; }
.message.error { padding: 12px; color: var(--red); background: var(--red-bg); text-align: center; }
footer { padding: 18px; color: #51616c; text-align: center; font-size: .9rem; }

@media (max-width: 760px) {
  .category-grid { grid-template-columns: 1fr; }
  .category-card { min-height: 0; }
}

@media (max-width: 600px) {
  .answers { grid-template-columns: 1fr; }
  .question-card, .results-card { padding: 22px 17px; }
  .result-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
