:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1c2033;
  --ink-soft: #5a6079;
  --line: #e2e5f0;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --good: #128a5a;
  --good-bg: #e6f6ef;
  --good-line: #7fd0ad;
  --bad: #c62b45;
  --bad-bg: #fdeced;
  --bad-line: #f0a3ae;
  --code-bg: #f2f3f9;
  --shadow: 0 1px 2px rgba(20, 24, 50, .06), 0 6px 20px rgba(20, 24, 50, .06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161f;
    --card: #1d202c;
    --ink: #e9ebf5;
    --ink-soft: #a0a6bd;
    --line: #2e3242;
    --accent: #8b87ff;
    --accent-soft: #262a41;
    --good: #5fd6a4;
    --good-bg: #17342a;
    --good-line: #2f7d5e;
    --bad: #ff8b9c;
    --bad-bg: #3a1f26;
    --bad-line: #8c4453;
    --code-bg: #14161f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.hidden { display: none !important; }

/* ------------------------------------------------------------- header */

.site-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 20px;
}
.logo {
  font-size: 30px;
  line-height: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}
h1 { font-size: 21px; margin: 0; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--ink-soft); font-size: 13.5px; }

/* -------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 19px; letter-spacing: -.01em; }
.card h3 { margin: 0 0 12px; font-size: 15px; letter-spacing: -.01em; }
.card p { margin: 0 0 12px; color: var(--ink-soft); font-size: 15px; }
.card p:last-of-type { margin-bottom: 16px; }
.tip {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px !important;
  color: var(--ink) !important;
}

/* ------------------------------------------------------------ buttons */

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 11px;
  border: 1px solid transparent;
  padding: 11px 18px;
  cursor: pointer;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--accent-soft); color: var(--ink); }
.btn.small { padding: 8px 14px; font-size: 13.5px; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.secondary:hover { filter: brightness(.97); }

.foot-actions { text-align: center; margin-top: 20px; }
.result-actions { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.result-actions .btn { flex: 1 1 200px; }

/* -------------------------------------------------------- progress bar */

.quiz-bar { margin-bottom: 16px; }
.bar-track {
  height: 7px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width .3s ease;
}
.bar-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
}
.score-pill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px;
  font-weight: 600;
}

/* ----------------------------------------------------------- question */

.chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 99px;
  padding: 4px 10px;
  margin-bottom: 12px;
}
.q-text { font-size: 17px; font-weight: 600; margin: 0 0 14px; line-height: 1.45; }

.code, pre.code {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  margin: 0 0 16px;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
}

.options { display: grid; gap: 9px; }
.opt {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--ink);
  transition: border-color .12s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.opt:disabled { cursor: default; }
.opt-key {
  flex: 0 0 auto;
  width: 23px;
  height: 23px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.opt-text {
  font-family: var(--mono);
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  padding-top: 2px;
}
.opt.is-correct { border-color: var(--good-line); background: var(--good-bg); }
.opt.is-correct .opt-key { background: var(--good); color: #fff; }
.opt.is-wrong { border-color: var(--bad-line); background: var(--bad-bg); }
.opt.is-wrong .opt-key { background: var(--bad); color: #fff; }
.opt.is-dim { opacity: .55; }

/* -------------------------------------------------------- explanation */

.explain {
  margin-top: 16px;
  border-radius: 12px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  animation: rise .22s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.explain.good { background: var(--good-bg); border-color: var(--good-line); }
.explain.bad { background: var(--bad-bg); border-color: var(--bad-line); }
.explain h4 { margin: 0 0 8px; font-size: 15px; }
.explain.good h4 { color: var(--good); }
.explain.bad h4 { color: var(--bad); }
.explain p { margin: 0 0 9px; font-size: 14.5px; color: var(--ink); }
.explain p:last-child { margin-bottom: 0; }
.explain .label { font-weight: 700; }
.explain code, .review code {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(125, 130, 160, .16);
  padding: 1px 5px;
  border-radius: 5px;
}
.sheet-ref {
  display: inline-block;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-style: italic;
}
.next-row { margin-top: 16px; display: flex; justify-content: flex-end; }
.kbd-hint { font-size: 12px; color: var(--ink-soft); text-align: center; margin-top: 14px; }

/* ------------------------------------------------------------ results */

.score-card { text-align: center; }
.score-big { font-size: 46px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; }
.score-big span { font-size: 24px; color: var(--ink-soft); font-weight: 600; }
.verdict { font-size: 16px; margin: 8px 0 0; color: var(--ink); font-weight: 600; }
.verdict-sub { font-size: 14px; color: var(--ink-soft); margin-top: 4px; }

.review { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.review:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.review h4 { margin: 0 0 10px; font-size: 14px; }
.review .line { font-size: 14.5px; margin: 0 0 8px; }
.review .line:last-child { margin-bottom: 0; }
.chose { color: var(--bad); font-weight: 700; }
.answer-is { color: var(--good); font-weight: 700; }
/* Answers can be several lines of output — keep them aligned as one block
   rather than letting line 2 wrap back under the label. */
.review .opt-text {
  display: inline-block;
  vertical-align: top;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  max-width: 100%;
  overflow-x: auto;
}

/* --------------------------------------------------------- topic bars */

.tbar { margin-bottom: 11px; }
.tbar:last-child { margin-bottom: 0; }
.tbar-top {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  margin-bottom: 5px;
  gap: 10px;
}
.tbar-name { font-weight: 600; }
.tbar-val { color: var(--ink-soft); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.tbar-track { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; }
.tbar-fill { height: 100%; border-radius: 99px; transition: width .4s ease; }
.tbar-fill.hi { background: var(--good); }
.tbar-fill.mid { background: #e0a32e; }
.tbar-fill.lo { background: var(--bad); }
.tbar-fill.none { background: var(--line); }

.stat-row { display: flex; gap: 10px; }
.stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat-lbl { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat-row { margin-bottom: 16px; }

.topic-list { margin: 0; padding-left: 20px; columns: 2; font-size: 14px; color: var(--ink-soft); }
.topic-list li { margin-bottom: 3px; break-inside: avoid; }

.focus-note {
  font-size: 13.5px;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 14px;
}

/* ------------------------------------------------------- home mode cards */

.mode-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.mode-card { display: flex; flex-direction: column; margin-bottom: 16px; }
.mode-card p { flex: 1; }
.mode-icon { font-size: 26px; line-height: 1; margin-bottom: 8px; }
.mode-stat { margin-bottom: 12px; min-height: 0; }
.pill {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px;
}
.pill-done { color: var(--good); border-color: var(--good-line); background: var(--good-bg); }

/* ------------------------------------------------------------- task list */

.task-row {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 13px 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.task-row:last-child { border-bottom: 0; }
.task-row:hover { background: var(--accent-soft); }
.task-num {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.task-row.is-solved .task-num { background: var(--good); color: #fff; }
.task-body { flex: 1; min-width: 0; }
.task-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-title { font-weight: 600; font-size: 15px; display: block; }
.task-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 99px; padding: 2px 7px;
}
.task-meta { display: block; font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.task-go { color: var(--ink-soft); font-size: 20px; flex: 0 0 auto; }

.spec { margin: 0 0 4px; padding-left: 20px; font-size: 14.5px; color: var(--ink-soft); }
.spec li { margin-bottom: 5px; }
.solved-note {
  margin-top: 14px; font-size: 13.5px; color: var(--good);
  background: var(--good-bg); border: 1px solid var(--good-line);
  border-radius: 10px; padding: 8px 11px;
}

/* ---------------------------------------------------------------- editor */

.editor-card { padding-bottom: 16px; }
.editor-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 9px; gap: 10px;
}
.editor-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.py-status { font-size: 12px; color: var(--ink-soft); }
.py-status.ready { color: var(--good); }

.editor-wrap {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--code-bg);
  overflow: hidden;
}
.gutter {
  flex: 0 0 auto;
  padding: 12px 8px 12px 12px;
  text-align: right;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  opacity: .6;
  background: transparent;
  overflow: hidden;
  user-select: none;
  min-width: 38px;
}
.gline-bad { color: var(--bad); opacity: 1; font-weight: 700; }
.editor {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  resize: vertical;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  padding: 12px 12px 12px 4px;
  min-height: 230px;
  white-space: pre;
  overflow-x: auto;
  tab-size: 4;
}
.editor-actions { display: flex; gap: 9px; margin-top: 13px; align-items: center; flex-wrap: wrap; }
.editor-actions .btn.ghost { margin-left: auto; }

/* --------------------------------------------------------------- results */

.result-card.good { border-color: var(--good-line); }
.result-card.bad { border-color: var(--bad-line); }
.result-card h3 { font-size: 17px; margin-bottom: 10px; }
.result-card.good h3 { color: var(--good); }
.result-card.bad h3 { color: var(--bad); }
.running-note { margin: 0 !important; color: var(--ink-soft); }

.case {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 13px;
  margin-top: 11px;
  background: var(--code-bg);
}
.case.ok { border-color: var(--good-line); background: var(--good-bg); }
.case.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.case-head { font-weight: 700; font-size: 14px; margin-bottom: 7px; }
.check-row { display: flex; gap: 8px; font-size: 13.5px; margin-bottom: 3px; align-items: baseline; }
.check-mark { flex: 0 0 auto; font-weight: 700; }
.check-row.ok .check-mark { color: var(--good); }
.check-row.bad .check-mark { color: var(--bad); }
.case-got-label { font-size: 12.5px; color: var(--ink-soft); margin-top: 9px; margin-bottom: 4px; }
.case-got { margin: 0 !important; background: var(--card); font-size: 13px; max-height: 220px; overflow: auto; }
.error-line { margin-bottom: 12px !important; border-left: 3px solid var(--bad); background: var(--card); }
.faint { font-size: 13px; color: var(--ink-soft); }

.diagnosis {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 13px;
}
.diagnosis h4 { margin: 0 0 6px; font-size: 15px; }
.diagnosis p { margin: 0 0 6px; font-size: 14.5px; color: var(--ink); }

.hint-card h3 { margin-bottom: 11px; }
.hint-row { display: flex; gap: 10px; font-size: 14.5px; color: var(--ink) !important; margin-bottom: 10px !important; }
.hint-n {
  flex: 0 0 auto;
  width: 21px; height: 21px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.hint-solution-note { font-size: 13.5px; font-style: italic; }

@media (max-width: 560px) {
  .mode-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 420px) {
  .topic-list { columns: 1; }
  .score-big { font-size: 40px; }
  .card { padding: 17px; }
  .editor { font-size: 12.5px; }
  .gutter { font-size: 12.5px; min-width: 32px; padding-left: 8px; }
  .editor-actions .btn { flex: 1 1 auto; }
  .editor-actions .btn.ghost { margin-left: 0; }
}
