:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #121826;
  --muted: #5b6577;
  --border: #dde2ea;
  --accent: #2457d6;
  --accent-soft: #e6edfc;
  --on-accent: #ffffff;
  --ok: #17864a;
  --ok-soft: #e3f4ea;
  --bad: #cf3434;
  --bad-soft: #fbe8e8;
  --tip: #8a5a00;
  --tip-soft: #fff4d6;
  --warn: #b4540a;
  --warn-soft: #ffeedd;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1218;
    --surface: #161b24;
    --surface-2: #1f2633;
    --text: #e8ecf3;
    --muted: #98a2b4;
    --border: #2a3242;
    --accent: #6b95ff;
    --accent-soft: #1d2a4a;
    --on-accent: #0b1020;
    --ok: #44c27b;
    --ok-soft: #123020;
    --bad: #ff6d6d;
    --bad-soft: #3a1b1d;
    --tip: #f2c25b;
    --tip-soft: #2f2612;
    --warn: #ff9f4a;
    --warn-soft: #3a2413;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1218;
  --surface: #161b24;
  --surface-2: #1f2633;
  --text: #e8ecf3;
  --muted: #98a2b4;
  --border: #2a3242;
  --accent: #6b95ff;
  --accent-soft: #1d2a4a;
  --on-accent: #0b1020;
  --ok: #44c27b;
  --ok-soft: #123020;
  --bad: #ff6d6d;
  --bad-soft: #3a1b1d;
  --tip: #f2c25b;
  --tip-soft: #2f2612;
  --warn: #ff9f4a;
  --warn-soft: #3a2413;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
button { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }

.container {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px;
}

main.container { flex: 1; padding-top: 20px; padding-bottom: 32px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, calc((100vw - 780px) / 2 + 16px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark svg { width: 30px; height: 30px; display: block; }
.brand-mark circle { fill: var(--accent); }
.brand-mark path { fill: none; stroke: var(--on-accent); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { font-size: 17px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.on svg { fill: #f5b301; stroke: #f5b301; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.timer.low { background: var(--bad-soft); color: var(--bad); }

/* ---------- generic ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); }
.small { font-size: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: default; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  margin-bottom: 12px;
}
.back:hover { color: var(--accent); }

.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.bar.ok > span { background: var(--ok); }

/* ---------- home ---------- */
.hero { padding: 22px; margin-bottom: 18px; }
.hero h1 { font-size: 28px; letter-spacing: -.01em; }
.hero p { margin: 8px 0 18px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.hero .bar { margin-top: 14px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px;
  text-decoration: none;
  color: var(--text);
  transition: transform .12s ease, border-color .12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .ico {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  margin-bottom: 8px;
}
.tile .ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile h2 { font-size: 18px; }
.tile p { margin: 0; font-size: 14px; color: var(--muted); }
.tile.main { grid-column: 1 / -1; background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tile.main p { color: color-mix(in srgb, var(--on-accent) 80%, transparent); }
.tile.main .ico { background: color-mix(in srgb, var(--on-accent) 18%, transparent); color: var(--on-accent); }

.section-title { font-size: 15px; font-weight: 600; color: var(--muted); margin: 26px 0 10px; }
.history { padding: 6px 16px; }
.history-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.history-row:last-child { border-bottom: 0; }
.pill { font-weight: 600; font-size: 13px; padding: 2px 10px; border-radius: 99px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- tickets ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--surface-2); border: 1px solid var(--border); }
.legend i.ok { background: var(--ok); border-color: var(--ok); }
.legend i.bad { background: var(--bad); border-color: var(--bad); }
.legend i.prog { background: var(--accent); border-color: var(--accent); }

.ticket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.ticket {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 12px 12px;
  text-decoration: none;
  color: var(--text);
  overflow: hidden;
}
.ticket:hover { border-color: var(--accent); }
.ticket small { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ticket b { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ticket .res { font-size: 13px; color: var(--muted); min-height: 19px; }
.ticket::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: transparent; }
.ticket.ok::after { background: var(--ok); }
.ticket.bad::after { background: var(--bad); }
.ticket.prog::after { background: var(--accent); }
.ticket.ok .res { color: var(--ok); font-weight: 600; }
.ticket.bad .res { color: var(--bad); font-weight: 600; }

/* ---------- topics ---------- */
.topic-list { display: grid; gap: 10px; }
.topic {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
}
.topic:hover { border-color: var(--accent); }
.topic .num {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700;
}
.topic h2 { font-size: 16px; font-weight: 600; }
.topic .bar { margin-top: 8px; }
.topic .count { font-size: 13px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- quiz ---------- */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.quiz-head h1 { font-size: 20px; }
.quiz-head .actions { display: flex; gap: 8px; }

.dots { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.dot {
  width: 31px; height: 31px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  color: var(--muted);
}
.dot.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.dot.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.dot.done { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.dot.cur { outline: 2px solid var(--accent); outline-offset: 2px; }
.dot.cur:not(.ok, .bad, .done) { color: var(--text); }

.progress-line { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-line .bar { flex: 1; }

.q-card { padding: 18px; }
.q-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.q-meta .grp { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 14px;
  cursor: zoom-in;
}
.q-text { font-size: 18px; font-weight: 600; margin: 0 0 14px; }

.options { display: grid; gap: 8px; }
.opt {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .1s ease, background .1s ease;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt:disabled { cursor: default; }
.opt .n {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--surface-2);
  font-weight: 700; font-size: 14px;
}
.opt .t { padding-top: 3px; }
.opt .mark { padding-top: 3px; font-weight: 700; }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt.picked .n { background: var(--accent); color: var(--on-accent); }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .n { background: var(--ok); color: #fff; }
.opt.correct .mark { color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .n { background: var(--bad); color: #fff; }
.opt.wrong .mark { color: var(--bad); }
.opt.dim { opacity: .6; }

.verdict { margin: 16px 0 0; font-weight: 700; font-size: 17px; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }

.why {
  margin-top: 12px;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-2);
  animation: rise .18s ease;
}
.why h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.why p { margin: 0; }
.tip {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--tip-soft);
  color: var(--text);
  font-size: 15px;
}
.tip b { color: var(--tip); }

@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.quiz-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.quiz-nav .btn { flex: 1; }
.kbd-hint { text-align: center; font-size: 13px; color: var(--muted); margin-top: 12px; }
kbd { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); }

/* ---------- results ---------- */
.result { padding: 24px; text-align: center; margin-bottom: 18px; }
.result .score { font-size: 54px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.result .score span { font-size: 26px; color: var(--muted); font-weight: 600; }
.result .status { display: inline-block; margin-top: 12px; font-weight: 700; padding: 6px 16px; border-radius: 99px; }
.result .status.ok { background: var(--ok-soft); color: var(--ok); }
.result .status.bad { background: var(--bad-soft); color: var(--bad); }
.result p { margin: 12px 0 0; color: var(--muted); }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

.review { display: grid; gap: 12px; }
.review-item { padding: 16px; }
.review-item .q-text { font-size: 16px; margin-bottom: 10px; }
.review-item .q-img { margin-bottom: 10px; }
.answer-line { font-size: 15px; margin: 4px 0; display: flex; gap: 8px; }
.answer-line b { flex: none; }
.answer-line.ok b { color: var(--ok); }
.answer-line.bad b { color: var(--bad); }

/* ---------- search ---------- */
.search-box {
  width: 100%;
  font: inherit;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin-bottom: 14px;
}
.search-box:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
details.why-toggle { margin-top: 10px; }
details.why-toggle summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 15px; }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 20px; margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 82%);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.footer { padding-top: 8px; padding-bottom: 28px; font-size: 13px; color: var(--muted); text-align: center; }

.review-item .q-img { max-height: 280px; }

/* ---------- disputed questions ---------- */
.dispute-line { margin: -4px 0 10px; }
.dispute-badge {
  display: inline-block;
  flex: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--warn-soft);
  color: var(--warn);
  white-space: nowrap;
}
.dispute {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  background: var(--warn-soft);
  font-size: 15px;
}
.dispute b { color: var(--warn); }
.tile .ico.warn { background: var(--warn-soft); color: var(--warn); }

@media (max-width: 520px) {
  /* Phones: larger type and tap targets (Pixel 8a is ~412 CSS px wide). */
  body { font-size: 17px; }
  .brand-text { font-size: 17px; }
  .back { font-size: 16px; }
  .btn { min-height: 50px; font-size: 17px; }
  .page-head h1 { font-size: 26px; }
  .page-head p { font-size: 16px; }

  .hero { padding: 18px; }
  .hero h1 { font-size: 26px; }
  .hero p { font-size: 16px; }
  .stat b { font-size: 22px; }
  .stat span { font-size: 14px; }
  .tile { padding: 16px; }
  .tile h2 { font-size: 19px; }
  .tile p { font-size: 15px; }
  .history-row { font-size: 16px; }

  .legend { font-size: 14px; }
  .ticket-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .ticket small { font-size: 13px; }
  .ticket b { font-size: 28px; }
  .ticket .res { font-size: 14px; }
  .topic h2 { font-size: 17px; }
  .topic .count { font-size: 14px; }

  .quiz-head h1 { font-size: 22px; }
  .dots { gap: 4px; }
  .dot { width: 34px; height: 34px; font-size: 14px; }
  .progress-line { font-size: 15px; }
  .q-card { padding: 14px; }
  .q-meta { font-size: 14px; }
  .q-text { font-size: 20px; line-height: 1.35; }
  .opt { padding: 14px; gap: 12px; grid-template-columns: 32px 1fr auto; }
  .opt .n { width: 32px; height: 32px; font-size: 15px; }
  .opt .t, .opt .mark { padding-top: 4px; }
  .verdict { font-size: 18px; }
  .why h3 { font-size: 13px; }
  .why p { font-size: 17px; line-height: 1.55; }
  .tip { font-size: 16px; }
  .dispute { font-size: 16px; }
  .dispute-badge { font-size: 13px; }
  .kbd-hint { display: none; }

  .result .score { font-size: 46px; }
  .result p { font-size: 16px; }
  .review-item .q-text { font-size: 17px; }
  .answer-line { font-size: 16px; }
  .search-box { font-size: 17px; }
  details.why-toggle summary { font-size: 16px; }
  .footer { font-size: 14px; }
}
