/* Тренажёр 1С:Профессионал — оформление Mini App
   Тема: системная / светлая / тёмная. Шрифт: системный / Google Sans. */
:root {
  --radius: 16px;
  --radius-sm: 12px;
  --gap: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* светлая тема */
  --bg: #f4f5f7;
  --bg-soft: #eceef1;
  --card: #ffffff;
  --card-2: #f7f8fa;
  --text: #14161a;
  --text-soft: #5f6673;
  --hint: #8b929e;
  --line: rgba(20, 22, 26, .09);
  --accent: #2f7bd8;
  --accent-soft: rgba(47, 123, 216, .12);
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --ok-soft: rgba(31, 157, 85, .13);
  --bad: #d6402f;
  --bad-soft: rgba(214, 64, 47, .12);
  --warn: #c98a00;
  --mark: #ffe9a8;
  --mark-text: #6b4a00;
  --nav-bg: rgba(255, 255, 255, .86);
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 6px 20px rgba(16, 20, 30, .05);
  --shadow-nav: 0 8px 28px rgba(16, 20, 30, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --bg-soft: #161a20;
  --card: #191d24;
  --card-2: #1f242c;
  --text: #eef1f6;
  --text-soft: #a9b1bd;
  --hint: #7e8794;
  --line: rgba(255, 255, 255, .09);
  --accent: #5b9bf0;
  --accent-soft: rgba(91, 155, 240, .16);
  --accent-text: #0b1018;
  --ok: #43c07a;
  --ok-soft: rgba(67, 192, 122, .16);
  --bad: #f0705f;
  --bad-soft: rgba(240, 112, 95, .16);
  --warn: #e0b34d;
  --mark: rgba(224, 179, 77, .26);
  --mark-text: #f2d38a;
  --nav-bg: rgba(25, 29, 36, .88);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-nav: 0 8px 28px rgba(0, 0, 0, .45);
}

/* системная тема: подхватываем тёмную схему устройства */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0f1115; --bg-soft: #161a20; --card: #191d24; --card-2: #1f242c;
    --text: #eef1f6; --text-soft: #a9b1bd; --hint: #7e8794; --line: rgba(255,255,255,.09);
    --accent: #5b9bf0; --accent-soft: rgba(91,155,240,.16); --accent-text: #0b1018;
    --ok: #43c07a; --ok-soft: rgba(67,192,122,.16); --bad: #f0705f; --bad-soft: rgba(240,112,95,.16);
    --warn: #e0b34d; --mark: rgba(224,179,77,.22); --nav-bg: rgba(25,29,36,.88);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
    --shadow-nav: 0 8px 28px rgba(0,0,0,.45);
  }
}

[data-font="google"] {
  --font: "Google Sans", "Google Sans Text", "Product Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  font-size: 16px; line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
body { overflow-x: hidden; }

#app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* ── шапка ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar__title { flex: 1; font-weight: 600; font-size: 17px; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: 0; background: transparent; color: var(--accent);
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--accent-soft); }
#btn-close { color: var(--hint); }

/* ── экран ─────────────────────────────────────────────────────────────── */
.screen { flex: 1; padding: 14px 14px calc(112px + var(--safe-bottom)); }
.screen--plain { padding-bottom: calc(24px + var(--safe-bottom)); }

/* ── нижнее меню (как в Telegram) ──────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 0 auto calc(10px + var(--safe-bottom));
  width: min(420px, calc(100% - 24px));
  padding: 6px 8px;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(18px);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-nav);
}
.tab {
  border: 0; background: transparent; color: var(--hint);
  display: grid; place-items: center;
  height: 44px; border-radius: 16px; cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .12s ease;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab:active { transform: scale(.94); }
.tab.active { color: var(--accent); background: var(--accent-soft); }

/* ── карточки ──────────────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--accent), #7b5cf0);
  color: #fff; border-radius: 22px; padding: 18px;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.02em; }
.hero p { margin: 0; opacity: .92; font-size: 13.5px; }
.hero__row { display: flex; gap: 18px; margin-top: 14px; }
.hero__stat b { display: block; font-size: 20px; font-weight: 700; }
.hero__stat span { font-size: 11.5px; opacity: .88; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.card--tap { cursor: pointer; transition: transform .12s ease, border-color .15s ease; }
.card--tap:active { transform: scale(.985); border-color: var(--accent-soft); }
.card__title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px;
  letter-spacing: -.01em; }
.card__sub { color: var(--text-soft); font-size: 13px; margin-top: 3px; }
.card__row { display: flex; align-items: center; gap: 12px; }
.card__icon {
  font-size: 20px; width: 42px; height: 42px; flex: 0 0 42px;
  display: grid; place-items: center; border-radius: 14px;
  background: var(--accent-soft); color: var(--accent);
}
.card__chev { color: var(--hint); display: grid; place-items: center; }
.card__chev svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.statbox { background: var(--card); border-radius: var(--radius-sm); padding: 13px 12px; text-align: center;
  box-shadow: var(--shadow); }
.statbox b { display: block; font-size: 21px; letter-spacing: -.02em; }
.statbox span { font-size: 11.5px; color: var(--hint); }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--hint); margin: 20px 4px 8px; font-weight: 600; }

/* ── кнопки ────────────────────────────────────────────────────────────── */
.btn {
  display: block; width: 100%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 600; font-family: inherit;
  padding: 14px 16px; border-radius: 14px; margin-top: 10px;
  transition: transform .12s ease, opacity .15s ease;
}
.btn:active { transform: scale(.985); opacity: .9; }
.btn--ghost { background: transparent; color: var(--accent); border: 1.5px solid var(--accent); }
.btn--soft { background: var(--bg-soft); color: var(--text); }
.btn--danger { background: var(--bad); color: #fff; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; }

/* ── тест ──────────────────────────────────────────────────────────────── */
.quiz-head {
  position: sticky; top: 54px; z-index: 15;
  background: var(--bg);
  margin: -14px -14px 12px; padding: 10px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.quiz-head__top { display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; color: var(--hint); }
.quiz-timer { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text);
  background: var(--bg-soft); padding: 3px 10px; border-radius: 999px; }
.quiz-timer.low { color: #fff; background: var(--bad); }
.progress { height: 5px; background: var(--bg-soft); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--accent); width: 0; transition: width .25s ease;
  border-radius: 3px; }

.q-text { font-size: 17px; font-weight: 600; margin: 4px 0 12px; letter-spacing: -.01em; }
.q-img { width: 100%; border-radius: 12px; margin: 6px 0 12px; background: #fff;
  cursor: zoom-in; display: block; }
.q-chapter { font-size: 11.5px; color: var(--hint); margin-bottom: 6px; }
.hint-word { font-weight: 700; border-radius: 5px; padding: 0 3px; }
.hint-word--question { background: var(--mark); color: var(--mark-text, inherit); }
.hint-word--answer { background: var(--ok-soft); color: var(--ok);
  box-shadow: inset 0 -2px 0 var(--ok); }
.hint-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--hint);
  margin-top: 6px; }
.hint-legend i { font-style: normal; font-weight: 700; padding: 1px 6px; border-radius: 5px; }

.answer {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--card); border: 1.5px solid transparent;
  border-radius: var(--radius-sm); padding: 12px; margin-bottom: 8px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .15s ease;
}
.answer:active { transform: scale(.99); }
.answer__num {
  flex: 0 0 24px; height: 24px; border-radius: 50%;
  background: var(--bg-soft); color: var(--text-soft);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 600;
}
.answer__text { flex: 1; font-size: 15px; }
.answer.chosen { border-color: var(--accent); background: var(--accent-soft); }
.answer.chosen .answer__num { background: var(--accent); color: var(--accent-text); }
.answer.correct { border-color: var(--ok); background: var(--ok-soft); }
.answer.correct .answer__num { background: var(--ok); color: #fff; }
.answer.wrong { border-color: var(--bad); background: var(--bad-soft); }
.answer.wrong .answer__num { background: var(--bad); color: #fff; }
.answer.locked { cursor: default; }
.answer.locked:active { transform: none; }

.result-badge { border-radius: 18px; padding: 18px 14px; text-align: center; margin-bottom: var(--gap);
  font-weight: 600; }
.result-badge--ok { background: var(--ok-soft); color: var(--ok); }
.result-badge--bad { background: var(--bad-soft); color: var(--bad); }
.result-badge b { display: block; font-size: 32px; letter-spacing: -.02em; }
.result-badge .hint { color: inherit; opacity: .8; }

.btn-mark {
  border: 1.5px dashed var(--line); background: transparent; color: var(--hint);
  border-radius: var(--radius-sm); padding: 9px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.btn-mark.on { border-style: solid; border-color: var(--warn); color: var(--warn); }

.nav-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.nav-grid button {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit;
}
.nav-grid button.done { background: var(--ok); color: #fff; border-color: var(--ok); }
.nav-grid button.wrong { background: var(--bad); color: #fff; border-color: var(--bad); }
.nav-grid button.marked { border-color: var(--warn); border-width: 2px; color: var(--warn); font-weight: 700; }
.nav-grid button.marked.done, .nav-grid button.marked.wrong { color: #fff; }
.nav-grid button.current { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--hint);
  margin-bottom: 8px; }
.nav-legend span { display: inline-flex; align-items: center; gap: 5px; }
.nav-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.nav-dot--done { background: var(--ok); }
.nav-dot--wrong { background: var(--bad); }
.nav-dot--mark { background: transparent; border: 2px solid var(--warn); }

/* ── настройки ─────────────────────────────────────────────────────────── */
.setting { display: flex; flex-direction: column; gap: 10px; padding: 13px 2px; }
.setting + .setting { border-top: 1px solid var(--line); }
.setting__text { min-width: 0; }
.setting__title { font-size: 15px; font-weight: 500; }
.setting__sub { font-size: 12.5px; color: var(--hint); margin-top: 2px; line-height: 1.35; }
/* если контрол узкий (тумблер) — ставим его в строку с текстом */
.setting:has(> .switch) { flex-direction: row; align-items: center; }
.setting:has(> .switch) .setting__text { flex: 1; }
.setting .segment { width: 100%; }
.setting .segment button { flex: 1; text-align: center; padding: 8px 6px; }

.segment { display: inline-flex; background: var(--bg-soft); border-radius: 12px; padding: 3px; gap: 2px; }
.segment button {
  border: 0; background: transparent; color: var(--text-soft);
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.segment button.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }

.setting__control { width: 100%; display: flex; align-items: center; gap: 10px; }
.range {
  -webkit-appearance: none; appearance: none;
  flex: 1; width: 100%; height: 30px; background: transparent; cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; margin-top: -10px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--card);
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.range::-moz-range-track {
  height: 8px; border-radius: 4px; background: var(--bg-soft); border: 1px solid var(--line);
}
.range::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--card);
}
[data-theme="dark"] .range::-webkit-slider-runnable-track { background: #2c333d; }
[data-theme="dark"] .range::-moz-range-track { background: #2c333d; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .range::-webkit-slider-runnable-track { background: #2c333d; }
  :root:not([data-theme="light"]) .range::-moz-range-track { background: #2c333d; }
}

.switch { position: relative; width: 50px; height: 30px; flex: 0 0 50px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--bg-soft);
  transition: background .18s ease; pointer-events: none;
}
.switch span::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform .18s ease;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

.card--active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow); }
.card--locked { opacity: .62; }
.card--locked .card__icon { background: var(--bg-soft); color: var(--hint); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-left: 6px;
}
.badge--lock { background: var(--bg-soft); color: var(--hint); }
.badge--ok { background: var(--ok-soft); color: var(--ok); }

/* ── прочее ────────────────────────────────────────────────────────────── */
.hint { color: var(--hint); font-size: 13px; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 46px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 7px; background: var(--bg-soft); border-radius: 4px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--accent); border-radius: 4px; }
.bar__fill.ok { background: var(--ok); }
.bar__fill.bad { background: var(--bad); }

.list-item { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--line); font-size: 14px; }
.list-item:last-child { border-bottom: 0; }

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal__box {
  position: relative; background: var(--card); border-radius: 20px;
  padding: 16px; margin: 16px; max-height: 85vh; overflow: auto; width: min(560px, 100%);
  box-shadow: var(--shadow);
}
.modal__box img { width: 100%; border-radius: 12px; background: #fff; }

.toast[hidden] { display: none; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(120px + var(--safe-bottom)); z-index: 80;
  background: rgba(20,20,22,.94); color: #fff; padding: 11px 16px;
  border-radius: 999px; font-size: 14px; max-width: 88vw; text-align: center;
  animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } }

.empty { text-align: center; color: var(--hint); padding: 44px 10px; }
.empty span { font-size: 40px; display: block; margin-bottom: 10px; }

input[type="text"], input:not([type]), input[type="password"] {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  font-size: 15px; font-family: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
