:root {
  --ink: #101411;
  --muted: #5d675f;
  --line: #b8c8b8;
  --line-strong: #8eaa92;
  --panel: #edf4eb;
  --panel-deep: #dfeadd;
  --page: #ffffff;
  --button: #f8faf7;
  --good: #1f6f3b;
  --good-bg: #edf7ef;
  --bad: #8c2d2d;
  --bad-bg: #fbefef;
  --focus: #265f38;
  --shadow: 0 1px 0 rgba(16, 20, 17, .08);
}

* { box-sizing: border-box; }
html { background: #fff; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.35;
}
button, select, input { font: inherit; }
button { color: inherit; }

.page-shell {
  width: min(760px, calc(100% - 28px));
  margin: 18px auto 28px;
}

.topbar {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 12px;
  box-shadow: var(--shadow);
}
.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: -.02em;
  font-size: 18px;
}
.history-button,
.button,
.settings-toggle {
  border: 1px solid #8f9690;
  background: var(--button);
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 #fff;
  transition: background-color .12s ease, border-color .12s ease, transform .12s ease;
}
.history-button:hover,
.button:hover,
.settings-toggle:hover { background: #fff; border-color: #707b72; }
.history-button:active,
.button:active,
.settings-toggle:active { transform: translateY(1px); }
.button.primary { background: #f4f8f3; border-color: #6d8e73; }

.masthead {
  margin: 10px auto 12px;
  min-height: 104px;
  border: 2px solid #49785a;
  box-shadow: inset 0 0 0 5px #e2ede2, 2px 3px 0 #a4b8a5;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  background: #fff;
}
.masthead h1 {
  margin: 0;
  font-size: clamp(42px, 9vw, 72px);
  line-height: .95;
  letter-spacing: -4px;
  font-weight: 900;
}
.question-count {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
}

.quiz { margin-top: 14px; }
.question-meta {
  min-height: 23px;
  background: var(--panel-deep);
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  padding: 3px 8px;
  border-block: 1px solid #d2dfd0;
}
.question-wrap { padding-top: 5px; }
.question-wrap.animate { animation: question-in .16s ease both; }
.question {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 500;
}
.answers {
  display: grid;
  gap: 2px;
  margin: 4px 0 8px 22px;
}
.answer {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  width: fit-content;
  max-width: calc(100% - 10px);
  padding: 3px 5px;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.answer:hover { background: #f5f7f4; border-color: #d8ded7; }
.answer input {
  margin: 2px 0 0;
  width: 17px;
  height: 17px;
  accent-color: #2e6e42;
  flex: 0 0 auto;
}
.answer.correct { background: var(--good-bg); border-color: #8eb79a; }
.answer.incorrect { background: var(--bad-bg); border-color: #cf9999; }
.answer.disabled { cursor: default; }


.custom-answer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 7px 0 2px 5px;
  max-width: 410px;
}
.custom-answer input {
  min-width: 0;
  flex: 1;
  height: 30px;
  border: 1px solid #8f9690;
  border-radius: 2px;
  background: #fff;
  padding: 4px 7px;
  color: var(--ink);
}
.custom-answer input:focus {
  outline: 2px solid rgba(38,95,56,.18);
  outline-offset: 1px;
  border-color: var(--focus);
}
.custom-answer .button { min-width: 68px; }

.feedback {
  border: 1px solid var(--line);
  padding: 6px 8px;
  margin: 8px 0;
  font-size: 13px;
  animation: fade-in .12s ease both;
}
.feedback.good { color: var(--good); background: var(--good-bg); border-color: #9cc3a6; }
.feedback.bad { color: var(--bad); background: var(--bad-bg); border-color: #d6aaaa; }

.quiz-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 35px;
  margin: 12px 0 8px;
}

.control-panel {
  background: var(--panel);
  padding: 5px 10px 10px;
  margin-top: 4px;
  border: 1px solid #dbe6d9;
}
.scoreline { text-align: center; font-size: 12px; margin-bottom: 4px; }
.settings-toggle { display: block; margin: 0 auto 8px; }
.settings { width: min(480px, 100%); margin: 0 auto; }
.settings[hidden] { display: none; }
.settings-head,
.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  align-items: center;
  gap: 14px;
}
.settings-head {
  font-size: 11px;
  color: #3f4a42;
  padding: 0 2px 3px;
}
.settings-head span:last-child { text-align: left; }
.setting-row { min-height: 28px; padding: 1px 2px; }
.setting-row:hover { background: rgba(255,255,255,.45); }
.setting-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.setting-left input { width: 15px; height: 15px; accent-color: #1775d1; margin: 0; }
.setting-left label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setting-row select {
  width: 100%;
  min-height: 25px;
  border: 1px solid #7c877e;
  background: #fff;
  border-radius: 2px;
  padding: 1px 4px;
}
.settings-divider { height: 1px; background: #cad7c8; margin: 5px 0; }
.mode-row { font-weight: 700; }
.mode-row .setting-left small { font-weight: 400; color: var(--muted); }
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 9px;
  align-items: center;
}
.text-button {
  border: 0;
  background: transparent;
  padding: 3px 1px;
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
}
.text-button:hover { text-decoration-thickness: 2px; }
.text-button.danger { color: #7c2424; }
.footer { text-align: center; margin-top: 8px; font-size: 11px; }

.history-dialog {
  width: min(700px, calc(100% - 24px));
  max-height: min(760px, calc(100vh - 30px));
  border: 1px solid #839184;
  border-radius: 3px;
  padding: 0;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 14px 50px rgba(22,30,23,.18);
}
.history-dialog::backdrop { background: rgba(15, 20, 16, .26); }
.history-dialog[open] { animation: dialog-in .15s ease both; }
.history-shell { padding: 14px; overflow: auto; max-height: inherit; }
.history-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #d9e0d8; padding-bottom: 8px; }
.history-head h2 { margin: 0; font-size: 22px; }
.close-button {
  width: 32px; height: 32px; border: 1px solid #aab2aa; background: #fff; border-radius: 2px; cursor: pointer;
  font-size: 24px; line-height: 1;
}
.history-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0,1fr));
  gap: 6px;
  margin: 12px 0 14px;
}
.stat-card { border: 1px solid #d7dfd6; background: var(--panel); padding: 8px; text-align: center; min-width: 0; }
.stat-value { display: block; font-weight: 800; font-size: 20px; }
.stat-label { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }
.history-section { margin-top: 15px; }
.history-section h3 { font-size: 13px; margin: 0 0 5px; }
.stats-row {
  display: grid;
  grid-template-columns: minmax(110px,1fr) 70px 70px 70px;
  gap: 8px;
  padding: 5px 3px;
  border-top: 1px solid #edf0ec;
  font-size: 12px;
}
.stats-row.header { font-weight: 700; border-top: 0; color: #445047; }
.stats-row span:not(:first-child) { text-align: right; }
.recent-list { border-top: 1px solid #e4e8e3; }
.recent-item { padding: 7px 2px; border-bottom: 1px solid #e8ece7; }
.recent-top { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--muted); }
.recent-q { margin-top: 2px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item.correct .recent-result { color: var(--good); }
.recent-item.incorrect .recent-result { color: var(--bad); }
.recent-item.skipped .recent-result { color: #6b6251; }
.empty { padding: 12px 0; color: var(--muted); font-size: 12px; }
.history-footer { display: flex; justify-content: flex-end; margin-top: 12px; padding-top: 8px; border-top: 1px solid #e3e8e2; }

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@keyframes question-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 620px) {
  .page-shell { width: min(100% - 16px, 760px); margin-top: 8px; }
  .masthead { min-height: 88px; }
  .masthead h1 { letter-spacing: -2.5px; }
  .answers { margin-left: 4px; }
  .answer { width: 100%; max-width: 100%; }
  .settings-head,
  .setting-row { grid-template-columns: minmax(0,1fr) 135px; gap: 8px; }
  .history-summary { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stats-row { grid-template-columns: minmax(95px,1fr) 55px 55px 55px; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
