:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a65;
  --border: #e2e0d8;
  --accent: #2f5fd0;
  --accent-soft: #e6edfb;
  --good: #1f8a4c;
  --good-soft: #e3f4ea;
  --bad: #c23b32;
  --bad-soft: #fbe7e5;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1f1f1d;
    --text: #ecebe6;
    --muted: #9b9a94;
    --border: #34342f;
    --accent: #7aa2ff;
    --accent-soft: #23304d;
    --good: #4cc27f;
    --good-soft: #1b3326;
    --bad: #f07a70;
    --bad-soft: #3b211f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.streak { color: var(--muted); font-size: 0.9rem; }

main { max-width: 860px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 1.7rem; margin: 8px 0 4px; }
.lead { color: var(--muted); margin: 0 0 24px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.topic {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: border-color .15s, transform .15s;
}
.topic:hover, .topic:focus-visible { border-color: var(--accent); transform: translateY(-2px); outline: none; }
.topic .icon { font-size: 1.6rem; }
.topic h3 { margin: 6px 0 2px; font-size: 1.05rem; }
.topic p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.topic .best { margin-top: 10px; font-size: 0.8rem; color: var(--accent); }

.quiz-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 10px; color: var(--muted); font-size: 0.95rem;
}
#quiz-title { font-weight: 600; color: var(--text); }

.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 18px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card.center { text-align: center; }

.prompt { color: var(--muted); margin: 0 0 6px; font-size: 0.95rem; }
.sentence { font-size: 1.35rem; margin: 0 0 20px; }
.sentence .blank {
  display: inline-block; min-width: 3.5em; border-bottom: 2px solid var(--accent);
  text-align: center; color: var(--accent); font-weight: 600;
}

.options { display: grid; gap: 10px; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }

.option {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 14px; font: inherit; font-size: 1.05rem;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; text-align: left;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .key { font-size: 0.75rem; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.option.correct { background: var(--good-soft); border-color: var(--good); }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); }
.option:disabled { cursor: default; }

.type-row { display: flex; gap: 10px; flex-wrap: wrap; }
.type-row input {
  flex: 1 1 180px; font: inherit; font-size: 1.1rem; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
.type-row input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.type-row input.correct { border-color: var(--good); background: var(--good-soft); }
.type-row input.wrong { border-color: var(--bad); background: var(--bad-soft); }

.feedback { margin-top: 18px; padding: 12px 14px; border-radius: 10px; }
.feedback.good { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback strong { display: block; margin-bottom: 2px; }

button.primary, button.secondary {
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
#next-btn { margin-top: 16px; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

.hint { color: var(--muted); font-size: 0.8rem; text-align: center; margin-top: 14px; }
kbd { border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 0.75rem; }

.big { font-size: 2.6rem; font-weight: 700; margin: 6px 0; }
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

#mistakes { text-align: left; margin-top: 18px; }
#mistakes h3 { font-size: 1rem; margin-bottom: 6px; }
#mistakes li { margin-bottom: 8px; }
#mistakes .yours { color: var(--bad); text-decoration: line-through; }
#mistakes .right { color: var(--good); font-weight: 600; }
@media (hover: none) { .hint { display: none; } }
