:root {
  --accent: #1F3864;
  --accent-2: #2E75B6;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1b1f27;
  --muted: #5b6475;
  --line: #d7dce5;
  --sel: #e6eefb;
  --err: #b3261e;
  --err-bg: #fdecea;
  --radius: 14px;
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent-2: #7fa7ff;
    --bg: #0f141c;
    --card: #171e29;
    --text: #e7ebf2;
    --muted: #9aa4b5;
    --line: #2d384a;
    --sel: #1f3350;
    --err: #ff8a80;
    --err-bg: #3a1d1d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* Шапка и прогресс */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--accent); color: #fff; padding-top: env(safe-area-inset-top); }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; min-height: 48px; gap: 12px; }
.brand { font-weight: 600; font-size: 15px; }
.progress-label { font-size: 14px; opacity: .9; white-space: nowrap; }
.progress { height: 4px; background: rgba(255, 255, 255, .25); }
#progress-bar { height: 100%; width: 0; background: #fff; transition: width .25s ease; }

/* Текст */
h1 { font-size: 24px; line-height: 1.25; margin: 20px 0 12px; }
h2.module-title { font-size: 19px; margin: 26px 0 6px; color: var(--accent-2); }
.lead { font-size: 18px; }
.muted, .hint { color: var(--muted); font-size: 15px; }
.hint { margin: 2px 0 10px; }

/* Карточки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
fieldset.card { min-width: 0; }
legend { float: left; width: 100%; padding: 0; margin: 0 0 10px; font-weight: 600; font-size: 17px; line-height: 1.35; }
legend + * { clear: both; }
.item.done > legend::after { content: "  ✓"; color: var(--accent-2); }
.invalid { border-color: var(--err) !important; box-shadow: 0 0 0 2px var(--err-bg); }
.error-box { background: var(--err-bg); color: var(--err); border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-weight: 600; }
.error-box ul { margin: 6px 0 0; padding-left: 20px; font-weight: 400; }

/* Варианты ответа — крупные кнопки */
.choices { display: grid; gap: 8px; clear: both; }
.choices.grid2 { grid-template-columns: 1fr 1fr; }
.choice { position: relative; display: block; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.choice > input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choice > span {
  display: flex; align-items: center; min-height: var(--tap); padding: 10px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card);
  font-size: 16px; line-height: 1.25; user-select: none; transition: background .12s, border-color .12s;
}
.choices.grid2 .choice > span { justify-content: center; text-align: center; }
.choice > input:checked + span { border-color: var(--accent-2); background: var(--sel); font-weight: 600; }
.choice > input[type="checkbox"]:checked + span::before { content: "✓"; margin-right: 8px; color: var(--accent-2); }
.choice > input:focus-visible + span { outline: 3px solid var(--accent-2); outline-offset: 2px; }

/* Поля ввода (16px — чтобы iOS не зумил) */
.field-label { display: block; font-weight: 600; margin-bottom: 8px; }
input[type="text"], select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 12px; min-height: var(--tap);
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card); color: var(--text);
}
textarea { resize: vertical; min-height: 96px; }
.at-input { position: relative; }
.at-input > span { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 16px; pointer-events: none; }
.at-input > input[type="text"] { padding-left: 30px; }
input[type="text"]:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-2); outline-offset: 1px; }

/* Топ-3 и согласие */
.top-card.selected { border-color: var(--accent-2); }
.top-label, .consent { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; font-size: 16px; }
.top-label input, .consent input { width: 24px; height: 24px; flex: 0 0 24px; margin: 1px 0 0; accent-color: var(--accent-2); }
.hours { margin-top: 12px; }

/* Нижняя панель навигации */
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
}
.nav-inner { display: flex; gap: 10px; }
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 18px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-size: 17px; font-weight: 600;
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.btn-primary { flex: 1; background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.linklike { border: none; background: none; color: var(--accent-2); padding: 0; min-height: 0; font-weight: 400; text-decoration: underline; }

/* Служебное */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: #1b1f27; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 15px; z-index: 10; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: .95; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.done-card { text-align: center; padding: 28px 18px; }
.field-error { color: var(--err); font-size: 15px; margin: 8px 0 0; }
.admin { padding-top: 12px; max-width: 1100px; }
.admin .btn { margin: 4px 0; }
.admin h2 { font-size: 19px; margin: 26px 0 10px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin-table th, .admin-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.admin-table th { font-weight: 600; white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: none; }
.reset-confirm { margin: 12px 0; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .92em; }

@media (min-width: 640px) {
  h1 { font-size: 28px; }
  .choices.grid4-md { grid-template-columns: repeat(4, 1fr); }
  .choices.cols2-md { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
