:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #172033;
  --muted: #667085;
  --border: #d8dee9;
  --primary: #1f6feb;
  --primary-dark: #1557bd;
  --success: #14804a;
  --danger: #c7362f;
  --warning-bg: #fff7dc;
  --warning-text: #856404;
  --radius: 18px;
  --shadow: 0 16px 45px rgba(23, 32, 51, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(34px, 6vw, 62px); line-height: .95; letter-spacing: -.045em; margin-bottom: 14px; }
h2 { font-size: 21px; letter-spacing: -.02em; margin-bottom: 14px; }
h3 { font-size: 16px; margin-bottom: 10px; }

.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 22px 0 50px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.brand {
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  text-align: left;
}
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--text);
  color: white;
  font-weight: 900;
  letter-spacing: -.04em;
}
.brand strong, .brand small { display: block; line-height: 1.15; }
.brand small { color: var(--muted); font-size: 13px; }

.view { display: none; animation: fadeIn .18s ease both; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card, .center-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.center-card {
  min-height: 68vh;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 12px;
  padding: 32px;
}
.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--surface-2);
  border-top-color: var(--primary);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.kicker {
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 10px;
}
.lead { color: var(--muted); line-height: 1.65; max-width: 760px; font-size: 17px; margin-bottom: 0; }
.small { font-size: 14px; padding: 9px 12px; }
.primary, .ghost, .success, .danger, .back {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 13px 18px;
  font-weight: 800;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.primary { color: white; background: var(--primary); }
.primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.ghost, .back { color: var(--text); background: white; border-color: var(--border); }
.ghost:hover, .back:hover { background: var(--surface-2); transform: translateY(-1px); }
.success { color: white; background: var(--success); }
.danger { color: white; background: var(--danger); }
.back { margin-bottom: 16px; }

.dashboard-hero {
  min-height: 360px;
  padding: clamp(26px, 5vw, 54px);
  background: linear-gradient(135deg, #ffffff 0%, #f2f6ff 100%);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 28px;
}
.hero-button { min-width: 190px; padding: 17px 26px; font-size: 17px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.stats-grid.compact { margin-top: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(23, 32, 51, .05);
}
.stat strong { display: block; font-size: 30px; letter-spacing: -.04em; margin-bottom: 4px; }
.stat span { color: var(--muted); font-size: 13px; }
.dashboard-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; }
.dashboard-grid .card, .results-card, .mistakes-card { padding: 22px; }
.card-title { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.empty-state { color: var(--muted); line-height: 1.6; }
.summary-list { display: grid; gap: 10px; }
.summary-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.summary-line:last-child { border-bottom: 0; }
.summary-line span { color: var(--muted); }
.summary-line strong { text-align: right; }

.setup-card { padding: clamp(20px, 4vw, 34px); }
.setup-head { display: grid; grid-template-columns: 1fr auto; gap: 22px; align-items: start; margin-bottom: 28px; }
.counter-box {
  min-width: 150px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 18px;
  padding: 16px;
  text-align: center;
}
.counter-box strong { display: block; font-size: 30px; letter-spacing: -.04em; }
.counter-box span { color: var(--muted); font-size: 13px; }
.form-section { margin-top: 24px; }
.mode-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.mode {
  min-height: 112px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 18px;
  padding: 16px;
  text-align: left;
  color: var(--text);
}
.mode strong { display: block; margin-bottom: 8px; font-size: 16px; }
.mode span { color: var(--muted); font-size: 13px; line-height: 1.4; }
.mode.selected { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(31, 111, 235, .10); }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: white;
  color: var(--text);
  padding: 13px 14px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(31, 111, 235, .10); }
.check-row {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 14px;
}
.check-row input, .check-list input { accent-color: var(--primary); }
.advanced {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  background: #fbfcfe;
}
.advanced summary { cursor: pointer; font-weight: 800; }
.filter-toolbar { display: flex; gap: 8px; margin: 16px 0; }
.filters-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.check-list { max-height: 250px; overflow: auto; display: grid; gap: 8px; padding-right: 5px; }
.check-list label {
  display: flex;
  align-items: start;
  gap: 8px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 12px;
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.warning { margin-top: 18px; border-radius: 14px; background: var(--warning-bg); color: var(--warning-text); padding: 14px; line-height: 1.45; }
.setup-actions { display: flex; justify-content: flex-end; margin-top: 24px; }
.setup-actions .primary { min-width: 180px; }

body.in-quiz .topbar { display: none; }
.quiz-view.active { display: grid; min-height: 100vh; grid-template-rows: auto auto 1fr auto; gap: 14px; width: min(1040px, 100%); margin: 0 auto; }
.quiz-top, .quiz-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 12px;
  box-shadow: 0 10px 30px rgba(23, 32, 51, .05);
}
.quiz-top { justify-content: space-between; }
.quiz-status { text-align: center; }
.quiz-status strong { display: block; font-size: 20px; }
.quiz-status span { color: var(--muted); font-size: 13px; }
.timer { min-width: 96px; text-align: center; border: 1px solid var(--border); border-radius: 16px; padding: 8px 10px; background: var(--surface-2); }
.timer span { display: block; color: var(--muted); font-size: 12px; }
.timer strong { font-size: 20px; }
.progress { height: 9px; border-radius: 999px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.progress div { height: 100%; width: 0; background: var(--primary); transition: width .2s ease; }
.question-card {
  padding: clamp(20px, 4vw, 42px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 440px;
}
.question-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; margin-bottom: 18px; }
#question-title { font-size: clamp(25px, 4vw, 44px); line-height: 1.08; margin-bottom: 24px; }
.options { display: grid; gap: 11px; }
.option {
  width: 100%;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  text-align: left;
  line-height: 1.42;
}
button.option:hover { background: #f7f9fd; }
.option-letter {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  font-weight: 900;
}
.option.selected { border-color: var(--primary); background: #f1f6ff; }
.option.correct { border-color: #81c995; background: #effaf3; }
.option.wrong { border-color: #f28b82; background: #fff2f1; }
.feedback { margin-top: 16px; border-radius: 16px; border: 1px solid var(--border); background: #fbfcfe; padding: 15px; line-height: 1.55; }
.feedback.good { border-color: #81c995; background: #effaf3; }
.feedback.bad { border-color: #f28b82; background: #fff2f1; }
.quiz-actions { justify-content: flex-end; position: sticky; bottom: 12px; }
.quiz-actions .ghost:first-child { margin-right: auto; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.mistakes-card { margin-top: 18px; }
.mistake-list { display: grid; gap: 12px; }
.mistake-item { border: 1px solid var(--border); background: #fbfcfe; border-radius: 16px; padding: 15px; }
.mistake-item h3 { line-height: 1.35; margin-bottom: 10px; }
.mistake-item p { margin: 6px 0; color: var(--muted); line-height: 1.45; }
.mistake-item strong { color: var(--text); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 999;
  background: var(--text);
  color: white;
  border-radius: 999px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  max-width: min(500px, calc(100vw - 28px));
}

@media (max-width: 900px) {
  .dashboard-hero, .setup-head, .dashboard-grid, .filters-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .hero-button { width: fit-content; }
}

@media (max-width: 620px) {
  .shell { width: min(100% - 20px, 1120px); padding-top: 14px; }
  .topbar { align-items: flex-start; }
  .brand-mark { width: 42px; height: 42px; }
  .dashboard-hero { min-height: 0; padding: 24px; }
  .stats-grid, .mode-list, .settings-grid { grid-template-columns: 1fr; }
  .quiz-top { flex-wrap: wrap; }
  .quiz-status { order: 3; width: 100%; }
  .question-meta { flex-direction: column; gap: 5px; }
  .quiz-actions { flex-wrap: wrap; }
  .quiz-actions button { flex: 1 1 auto; }
  .quiz-actions .ghost:first-child { margin-right: 0; }
}
