:root {
  --bg: #f4f7fb;
  --bg-soft: #eaf0f8;
  --card: #ffffff;
  --text: #14213d;
  --muted: #5d6b82;
  --line: #dde5f0;
  --brand: #0f766e;
  --brand-strong: #0b5d56;
  --brand-soft: #d7f0ed;
  --accent: #2563eb;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --err: #b91c1c;
  --err-soft: #fee2e2;
  --warn: #b45309;
  --shadow: 0 10px 30px rgba(20, 33, 61, 0.08);
  --shadow-sm: 0 2px 8px rgba(20, 33, 61, 0.06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1421;
    --bg-soft: #111c2d;
    --card: #152238;
    --text: #e8eefb;
    --muted: #9db0cc;
    --line: #24344d;
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #103b39;
    --accent: #60a5fa;
    --ok: #4ade80;
    --ok-soft: #0f3320;
    --err: #f87171;
    --err-soft: #3a1414;
    --warn: #fbbf24;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(45, 212, 191, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(37, 99, 235, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

.boot {
  margin: auto;
  color: var(--muted);
  font-size: 18px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--card) 82%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  background: none;
  border: 0;
  color: inherit;
  padding: 0;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.brand-title { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }

.header-actions { display: flex; align-items: center; gap: 10px; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--text);
  max-width: 220px;
}
.user-chip .avatar {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-strong);
  font-weight: 700; font-size: 12px; flex: 0 0 auto;
}
.user-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */
.main {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 36px) clamp(16px, 4vw, 40px) 64px;
  flex: 1;
}

.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: clamp(24px, 4vw, 32px); }
h2 { font-size: clamp(20px, 3vw, 24px); }
h3 { font-size: 17px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: clamp(18px, 3vw, 26px);
}
.card.flush { padding: 0; overflow: hidden; }
.card-title { font-weight: 750; font-size: 17px; margin-bottom: 4px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease, opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  background: var(--bg-soft);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #04201d; } }

.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-soft); }
.btn-danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn-danger:hover:not(:disabled) { background: var(--err-soft); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: 14px; }

/* ---------- Auth ---------- */
.auth-wrap { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.auth-card { width: 100%; max-width: 430px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .logo-big {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px;
  display: grid; place-items: center; font-size: 32px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 650; color: var(--muted); }
.field input {
  font-family: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.auth-toggle { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.link {
  color: var(--brand-strong);
  font-weight: 650;
  cursor: pointer;
  background: none; border: 0; padding: 0; font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
@media (prefers-color-scheme: dark) { .link { color: var(--brand); } }

.form-error {
  background: var(--err-soft);
  color: var(--err);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 12px;
}
.form-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.stat .label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- Topic list ---------- */
.topic {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
}
.topic:first-child { border-top: 0; }
.topic-main { flex: 1; min-width: 0; }
.topic-name { font-weight: 700; }
.topic-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.topic-progress { height: 6px; border-radius: 999px; background: var(--bg-soft); margin-top: 10px; overflow: hidden; }
.topic-progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand), var(--accent)); }

/* ---------- Quiz ---------- */
.quiz-top { display: flex; flex-direction: column; gap: 12px; }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 650;
  padding: 5px 11px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-strong);
}
@media (prefers-color-scheme: dark) { .badge { color: var(--brand); } }
.badge.neutral { background: var(--bg-soft); color: var(--muted); }

.progress-track { height: 9px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.progress-track > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .25s ease; }

.question-text { font-size: clamp(18px, 2.4vw, 21px); font-weight: 700; line-height: 1.45; letter-spacing: -0.01em; }

.options { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.option {
  display: flex; align-items: flex-start; gap: 12px;
  width: 100%; text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 15.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.option:hover:not(.disabled) { border-color: var(--brand); background: var(--bg-soft); }
.option .marker {
  flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800;
  background: var(--bg-soft); color: var(--muted);
  border: 1px solid var(--line);
  margin-top: 1px;
}
.option.selected { border-color: var(--brand); background: var(--brand-soft); }
.option.selected .marker { background: var(--brand); color: #fff; border-color: var(--brand); }
.option.disabled { cursor: default; }
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .marker { background: var(--ok); color: #fff; border-color: var(--ok); }
.option.wrong { border-color: var(--err); background: var(--err-soft); }
.option.wrong .marker { background: var(--err); color: #fff; border-color: var(--err); }
.option .opt-text { flex: 1; }

.feedback {
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  border: 1px solid var(--line);
}
.feedback.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.feedback.err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.feedback .fb-title { font-weight: 800; margin-bottom: 4px; }
.feedback .fb-list { margin: 6px 0 0; padding-left: 18px; }
.feedback .fb-list li { margin: 2px 0; }

.quiz-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; flex-wrap: wrap; }
.quiz-actions .right { margin-left: auto; display: flex; gap: 10px; }

/* ---------- Results ---------- */
.result-hero { text-align: center; padding: 8px 0 4px; }
.score-ring {
  --p: 0;
  width: 150px; height: 150px; border-radius: 50%;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  background:
    radial-gradient(closest-side, var(--card) 78%, transparent 79%),
    conic-gradient(var(--brand) calc(var(--p) * 1%), var(--bg-soft) 0);
  box-shadow: var(--shadow-sm);
}
.score-ring .score-num { font-size: 34px; font-weight: 850; letter-spacing: -0.03em; }
.score-ring .score-den { font-size: 13px; color: var(--muted); margin-top: -4px; }

.review-list { display: flex; flex-direction: column; gap: 12px; }
.review-item { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; background: var(--card); }
.review-q { font-weight: 650; margin-bottom: 8px; }
.review-line { font-size: 14px; margin-top: 4px; }
.review-line .tag { font-weight: 700; }
.review-line.bad .tag { color: var(--err); }
.review-line.good .tag { color: var(--ok); }
.review-line ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- History ---------- */
.history-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}
.history-item:first-child { border-top: 0; }
.history-main { flex: 1; min-width: 0; }
.history-mode { font-weight: 650; }
.history-date { font-size: 12.5px; color: var(--muted); }
.score-pill {
  font-weight: 800; font-size: 14px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text);
  white-space: nowrap;
}
.score-pill.good { background: var(--ok-soft); color: var(--ok); }
.score-pill.mid { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.score-pill.bad { background: var(--err-soft); color: var(--err); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hidden { display: none !important; }

@media (max-width: 560px) {
  .header { padding: 12px 16px; }
  .brand-sub { display: none; }
  .user-chip .name { max-width: 90px; }
  .topic { flex-wrap: wrap; }
  .topic .btn { width: 100%; }
  .quiz-actions { flex-direction: column-reverse; }
  .quiz-actions .right { margin-left: 0; width: 100%; }
  .quiz-actions .right .btn, .quiz-actions > .btn { width: 100%; }
}
