:root {
  --bg: #f3f4fb;
  --surface: #ffffff;
  --surface-2: #f7f7fd;
  --text: #15172c;
  --muted: #5e6283;
  --faint: #9296b3;
  --line: #e2e4f0;
  --accent: #5a55f0;
  --accent-2: #7c4dff;
  --accent-soft: #ecebff;
  --on-accent: #ffffff;
  --good: #15944a;
  --good-soft: #e5f6ec;
  --bad: #d4343a;
  --bad-soft: #fdeaea;
  --warn: #c26b00;
  --warn-soft: #fff2dc;
  --road: #e9eaf2;
  --shelf: #f6efe4;
  --shelf-edge: #c9a878;
  --shadow: 0 1px 2px rgba(20, 22, 50, 0.06), 0 6px 20px rgba(20, 22, 50, 0.06);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f1d;
    --surface: #17192c;
    --surface-2: #1d2036;
    --text: #eceefd;
    --muted: #a0a5c8;
    --faint: #6d7196;
    --line: #2a2d49;
    --accent: #8580ff;
    --accent-2: #a37dff;
    --accent-soft: #25254d;
    --on-accent: #0e0f1d;
    --good: #4ade80;
    --good-soft: #143322;
    --bad: #f87171;
    --bad-soft: #3b1a1f;
    --warn: #fbbf24;
    --warn-soft: #3a2b0e;
    --road: #22253b;
    --shelf: #2a2419;
    --shelf-edge: #7a6240;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 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.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 120px; }

/* ── общее ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.grow { flex: 1; }
.stack > .chip, .hero > .chip { align-self: flex-start; }
.error:empty { display: none; }
.task-row { margin-bottom: 0; }
h1 { font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 20px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 13px; margin: 10px 4px 0; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: 14px; border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent);
  font-weight: 650; font-size: 16.5px; width: 100%;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.small { min-height: 40px; font-size: 14.5px; width: auto; padding: 0 14px; border-radius: 12px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px 0; }

.field {
  width: 100%; min-height: 52px; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); font-size: 16px;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
textarea.field { min-height: 96px; resize: vertical; }
.code-input { font-size: 34px; letter-spacing: 0.4em; text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; padding-left: 0.4em; }
.error { color: var(--bad); font-weight: 600; }
.note { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14.5px; }
.note.warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.note.good { background: var(--good-soft); border-color: transparent; }
.note.bad { background: var(--bad-soft); border-color: transparent; }

/* ── вход ── */
.hero { padding: 36px 4px 20px; }
.hero .logo { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; margin-bottom: 18px; box-shadow: var(--shadow); }
.names { display: flex; flex-direction: column; gap: 8px; }
.name-btn { display: flex; justify-content: space-between; align-items: center; min-height: 54px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-align: left; font-weight: 550; }
.name-btn:active { background: var(--accent-soft); }
.name-btn[disabled] { opacity: 0.45; }

/* ── главная ── */
.top { display: flex; align-items: center; gap: 16px; }
.ring { flex: none; width: 84px; height: 84px; position: relative; }
.ring svg { width: 84px; height: 84px; transform: rotate(-90deg); }
.ring .track { stroke: var(--line); }
.ring .fill { stroke: var(--accent); transition: stroke-dasharray 0.6s ease; }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1; }
.ring .val b { font-size: 22px; font-weight: 750; }
.ring .val span { font-size: 11px; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s ease; }
.task-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); text-align: left; margin-bottom: 8px; box-shadow: var(--shadow); }
.task-row .num { flex: none; width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; font-weight: 750; background: var(--accent-soft); color: var(--accent); }
.task-row .body { flex: 1; min-width: 0; }
.task-row .title { font-weight: 650; }
.task-row .meta { font-size: 12.5px; color: var(--muted); }
.task-row .status { flex: none; font-weight: 700; font-size: 14px; }
.task-row.done .num { background: var(--good-soft); color: var(--good); }
.task-row.next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.task-row.locked { opacity: 0.55; box-shadow: none; }

/* ── экран задания ── */
.bar-top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); margin: -16px -16px 12px; padding: 10px 12px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.back { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 20px; flex: none; }
.bar-top .t { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.dock .inner { max-width: 560px; margin: 0 auto; }
.dock .hint { font-size: 12.5px; color: var(--muted); text-align: center; margin-bottom: 8px; }

/* сортировка */
.seq { display: flex; flex-direction: column; gap: 8px; }
.slot { display: flex; align-items: flex-start; gap: 10px; min-height: 52px; padding: 12px 14px; border-radius: 14px; border: 1.5px dashed var(--line); background: var(--surface-2); color: var(--faint); text-align: left; width: 100%; }
.slot.filled { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--text); animation: pop 0.18s ease; }
.slot .n { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-weight: 750; font-size: 13px; background: var(--surface); color: var(--accent); }
.pool { display: flex; flex-direction: column; gap: 8px; }
.pool-item { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-align: left; box-shadow: var(--shadow); width: 100%; }
.pool-item:active { transform: scale(0.99); }
@keyframes pop { from { transform: scale(0.97); opacity: 0.6; } to { transform: none; opacity: 1; } }

/* карточки */
.deck-card { min-height: 128px; display: flex; flex-direction: column; justify-content: center; font-size: 19px; font-weight: 600; line-height: 1.35; padding: 22px 18px; animation: slide 0.22s ease; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.deck-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dots { display: flex; gap: 5px; flex-wrap: wrap; }
.dots i { width: 8px; height: 8px; border-radius: 99px; background: var(--line); }
.dots i.on { background: var(--accent); }
.dots i.cur { outline: 2px solid var(--accent); outline-offset: 2px; }
.options { display: grid; gap: 8px; margin-top: 12px; }
.options.two { grid-template-columns: 1fr 1fr; }
.options.many { grid-template-columns: 1fr 1fr; }
.opt { min-height: 56px; padding: 10px 12px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; font-size: 15px; line-height: 1.25; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.opt:active { transform: scale(0.98); }
.summary-item { display: flex; gap: 10px; align-items: flex-start; width: 100%; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-align: left; }
.summary-item .ans { color: var(--accent); font-weight: 650; font-size: 14px; }

/* пилюли выбора */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 42px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-size: 14.5px; font-weight: 550; }
.pill.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.label { font-weight: 650; font-size: 14.5px; margin: 4px 0 8px; }
.counter { font-size: 12px; color: var(--faint); text-align: right; margin-top: 4px; }
.counter.ok { color: var(--good); }

/* антифрод */
.profile { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14.5px; }
.profile dt { color: var(--muted); }
.profile dd { margin: 0; font-weight: 600; }
.tx { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); text-align: left; width: 100%; box-shadow: var(--shadow); transition: border-color 0.15s ease, background 0.15s ease; }
.tx .time { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.tx .amount { font-size: 18px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.tx .line { grid-column: 1 / -1; font-size: 14px; color: var(--muted); }
.tx .line b { color: var(--text); font-weight: 600; }
.tx .flag { grid-column: 1 / -1; margin-top: 6px; font-weight: 650; font-size: 14px; color: var(--faint); }
.tx.on { border-color: var(--bad); background: var(--bad-soft); }
.tx.on .flag { color: var(--bad); }

/* разметка кадра */
.grid { display: grid; gap: 4px; padding: 8px; border-radius: 16px; user-select: none; -webkit-user-select: none; }
.grid.road { background: var(--road); }
.grid.shelf { background: var(--shelf); }
.cell { aspect-ratio: 1; border-radius: 10px; border: 2px solid transparent; background: color-mix(in srgb, var(--surface) 55%, transparent); display: grid; place-items: center; font-size: clamp(20px, 6.2vw, 30px); line-height: 1; padding: 0; position: relative; }
.grid.shelf .cell { border-bottom: 3px solid var(--shelf-edge); border-radius: 8px 8px 3px 3px; }
.cell.empty-slot { background: transparent; border: 2px dashed var(--shelf-edge); }
.cell.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.cell.on::after { content: "✓"; position: absolute; top: 1px; right: 3px; font-size: 11px; font-weight: 800; color: var(--accent); }
.cell.tp { border-color: var(--good); background: var(--good-soft); box-shadow: none; }
.cell.fp { border-color: var(--bad); background: var(--bad-soft); box-shadow: none; }
.cell.fn { border: 2px dashed var(--warn); background: var(--warn-soft); box-shadow: none; }
.cell.tp::after, .cell.fp::after, .cell.fn::after { content: none; }
.rowlabel { font-size: 11px; font-weight: 650; color: var(--muted); display: grid; align-items: center; line-height: 1.1; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12.5px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -2px; }
.legend .l-tp::before { background: var(--good-soft); border: 2px solid var(--good); }
.legend .l-fp::before { background: var(--bad-soft); border: 2px solid var(--bad); }
.legend .l-fn::before { background: var(--warn-soft); border: 2px dashed var(--warn); }

/* метрики */
.matrix { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 6px; font-size: 13px; }
.matrix .h { color: var(--muted); font-weight: 600; display: grid; place-items: center; text-align: center; padding: 4px; line-height: 1.2; }
.matrix .h.side { place-items: center start; text-align: left; }
.matrix .v { border-radius: 12px; padding: 10px 6px; text-align: center; }
.matrix .v b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.matrix .v small { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
.matrix .ok { background: var(--good-soft); color: var(--good); }
.matrix .no { background: var(--bad-soft); color: var(--bad); }
.num-field { display: flex; align-items: center; gap: 8px; }
.num-field .field { flex: 1; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.num-field .pct { font-size: 20px; font-weight: 700; color: var(--muted); }
details.cheat { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: var(--surface-2); }
details.cheat summary { font-weight: 650; cursor: pointer; }
.formula { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px; margin: 8px 0 0; }

/* промпт */
.preview { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px dashed var(--accent); border-radius: 14px; padding: 12px; min-height: 60px; }
.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; min-height: 50px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 550; font-size: 15px; }
.radio::before { content: ""; flex: none; width: 18px; height: 18px; border-radius: 99px; border: 2px solid var(--faint); }
.radio.on { border-color: var(--accent); background: var(--accent-soft); }
.radio.on::before { border: 6px solid var(--accent); }

/* разбор */
.verdict { text-align: center; padding: 24px 16px; }
.verdict .emoji { font-size: 44px; line-height: 1; }
.verdict .pts { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; margin-top: 8px; }
.verdict .pts span { font-size: 18px; color: var(--muted); font-weight: 600; }
.fb { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.fb .mark { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.fb.ok .mark { background: var(--good-soft); color: var(--good); }
.fb.no .mark { background: var(--bad-soft); color: var(--bad); }
.fb .what { font-size: 13.5px; margin-top: 4px; }
.fb .was { color: var(--bad); text-decoration: line-through; }
.fb .right { color: var(--good); font-weight: 650; }
.tag-bad { color: var(--bad); font-weight: 700; }
.tag-good { color: var(--good); font-weight: 700; }
.fb .why { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* окно подтверждения */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(10, 10, 25, 0.45); display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s ease; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); animation: up 0.2s ease; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: 90vw; animation: fade 0.2s ease; }
.spinner { width: 28px; height: 28px; border-radius: 99px; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
