:root {
  --bg: #f4f6fb;
  --card: #fff;
  --ink: #1d2433;
  --muted: #6b7489;
  --line: #d5dbe8;
  --soft: #e6eaf3;
  --accent: #4f7cff;
  --accent-ink: #fff;
  --ok: #1faa59;
  --ok-bg: #e3f7ec;
  --bad: #e5484d;
  --bad-bg: #fdeaea;
  --check-bg: #fff6db;
  --star: #f5b700;
  --radius: 20px;
  --gap: 16px;
  font-family: -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { color: inherit; opacity: 1; cursor: default; }

#app {
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.bar { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.bar h1 { margin: 0; font-size: 32px; flex: 1; }
.back {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--card); font-size: 28px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.06);
}
.count { font-size: 22px; color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { height: 10px; border-radius: 5px; background: var(--soft); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }
.tile {
  background: var(--card); border-radius: var(--radius);
  padding: 24px; min-height: 140px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; gap: 12px;
  font-size: 26px; font-weight: 600; text-align: left;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.06);
}
.tile:active { transform: scale(0.98); }
.tile-icon { font-size: 44px; }
.tile-note { font-size: 16px; font-weight: 400; color: var(--muted); }
.meter { width: 100%; height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); }

.question {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; border-radius: var(--radius); padding: 16px;
}
.q-text {
  margin: 0; text-align: center; line-height: 1.5;
  font-size: clamp(28px, 4.6vw, 46px); font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.q-note { margin: 0; color: var(--muted); font-size: 18px; }
.slot {
  display: inline-block; min-width: 1.4em; padding: 0 0.2em;
  border-radius: 12px; background: var(--soft); color: var(--accent);
}

/* «Окошки» как в тетради: по клетке на цифру */
.field {
  display: inline-flex; gap: 4px; vertical-align: middle;
  padding: 4px; border-radius: 14px; cursor: pointer;
}
.field.active { background: var(--soft); box-shadow: inset 0 0 0 3px var(--accent); }
.box {
  width: 1.05em; height: 1.3em;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card);
  font-weight: 700;
}
.field.right .box { border-color: var(--ok); background: var(--ok-bg); }
.field.wrong .box { border-color: var(--bad); background: var(--bad-bg); }

.answer-area { width: 100%; display: flex; justify-content: center; }
.keypad { display: grid; grid-template-columns: repeat(3, 88px); gap: 12px; }
.keypad button {
  height: 72px; border-radius: 18px; background: var(--card);
  font-size: 34px; font-weight: 600;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.08);
}
.keypad button:active { background: var(--soft); }
.keypad .ok { background: var(--accent); color: var(--accent-ink); font-size: 26px; }
.keypad .ok:disabled { opacity: 0.35; }

.choices { display: grid; grid-template-columns: repeat(2, minmax(200px, 360px)); gap: 16px; }
.choices.compare { grid-template-columns: repeat(3, 120px); }
.choices button {
  min-height: 88px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--card); border: 3px solid transparent;
  font-size: 30px; font-weight: 600;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
}
.choices.compare button { font-size: 44px; }
.choices button.right { border-color: var(--ok); background: var(--ok-bg); }
.choices button.wrong { border-color: var(--bad); background: var(--bad-bg); opacity: 0.6; }

.flash-ok .question { animation: okflash 0.7s; }
@keyframes okflash { from { background: var(--ok-bg); } to { background: transparent; } }

.feedback {
  border-radius: var(--radius); padding: 20px 24px;
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px;
}
.feedback[hidden] { display: none; }
.feedback.check { background: var(--check-bg); }
.feedback.good { background: var(--ok-bg); }
.feedback.solution { background: var(--card); box-shadow: 0 2px 10px rgb(0 0 0 / 0.06); }
.fb-text { flex: 1; min-width: 280px; display: flex; flex-direction: column; gap: 10px; }
.fb-title { margin: 0; font-size: 24px; }
.fb-rule { margin: 0; font-size: 20px; }
.fb-cause { margin: 0; font-size: 18px; color: var(--bad); }
.fb-steps { margin: 0; padding: 0; list-style: none; font-size: 20px; line-height: 1.5; font-variant-numeric: tabular-nums; }

/* Таблица мер — эталон для самопроверки */
.mt { background: var(--card); border-radius: 16px; padding: 12px 16px; }
.mt + .mt { margin-top: 12px; }
.mt-title { font-size: 16px; color: var(--muted); margin-bottom: 6px; }
.mt-chain { display: flex; align-items: flex-start; flex-wrap: wrap; row-gap: 10px; }
.mt-chain + .mt-chain { margin-top: 10px; }
.mt-unit { font-size: 22px; font-weight: 600; white-space: nowrap; }
.mt-unit.on { color: var(--accent); }
.mt-link { display: flex; flex-direction: column; align-items: center; min-width: 72px; padding-top: 24px; margin: 0 -4px; }
.mt-arc {
  width: 100%; height: 14px;
  border: 2px solid var(--muted); border-top: 0;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.mt-k { font-size: 18px; font-weight: 600; margin-top: 2px; }
.mt-link.on .mt-arc { border-color: var(--accent); border-width: 3px; }
.mt-link.on .mt-k { color: var(--accent); }
.mt-formula { font-size: 28px; font-weight: 600; }
.reference { display: flex; flex-direction: column; }

.primary, .secondary { border-radius: 16px; padding: 16px 28px; font-size: 22px; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--card); box-shadow: 0 2px 8px rgb(0 0 0 / 0.08); }
.bar .secondary { font-size: 18px; padding: 12px 18px; }

.summary { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stars { margin: 0; font-size: 72px; color: var(--star); letter-spacing: 8px; }
.score { margin: 0; font-size: 30px; font-weight: 700; }
.praise { font-size: 22px; }
.summary h2 { font-size: 22px; margin: 16px 0 0; }
.causes { margin: 0; font-size: 18px; color: var(--muted); text-align: center; line-height: 1.6; }
.mistakes { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
.mistakes li { background: var(--card); border-radius: 16px; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; font-size: 20px; }
.m-given { color: var(--bad); }
.m-right { color: var(--ok); }
.m-fixed { color: var(--muted); font-size: 16px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-top: 16px; }

.modes { display: inline-flex; align-self: flex-start; gap: 4px; padding: 4px; border-radius: 14px; background: var(--soft); }
.mode { padding: 10px 18px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 18px; font-weight: 600; }
.mode.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgb(0 0 0 / 0.1); }
.mode-note { margin: 0; color: var(--muted); font-size: 16px; }
.tile-level { font-size: 16px; font-weight: 500; color: var(--accent); }
.level-up { margin: 0; font-size: 22px; font-weight: 600; color: var(--accent); }

@media (max-width: 700px) {
  .choices { grid-template-columns: 1fr 1fr; width: 100%; }
  .choices.compare { grid-template-columns: repeat(3, 1fr); }
  .keypad { grid-template-columns: repeat(3, 1fr); width: 100%; }
}
