:root {
  --bg: var(--tg-theme-bg-color, #f4f5f1);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d2721);
  --hint: var(--tg-theme-hint-color, #6c7770);
  --accent: #286b4c;
  --accent-strong: #1d553b;
  --accent-text: #ffffff;
  --accent-soft: rgba(40, 107, 76, .09);
  --line: rgba(29, 39, 33, .12);
  --ok: #28744f;
  --bad: #b9433e;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

#app {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 18px calc(100px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

h1 { font-size: 22px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.025em; }
h2 { font-size: 18px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -.015em; }
p { margin: 0 0 8px; }
.muted { color: var(--hint); font-size: 14px; }

/* ---------- главный экран ---------- */
.home-hero,
.hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  margin-bottom: 16px;
}
.home-hero { animation: enter .22s ease-out both; }
.brand-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .045em;
}
.brand-mark {
  position: relative;
  display: inline-block;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 7px;
  background: var(--accent);
}
.brand-mark::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 11px;
  width: 2px;
  border-left: 2px dashed rgba(255, 255, 255, .9);
}
.brand-location {
  color: var(--hint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
}
.home-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}
.home-copy { min-width: 0; }
.home-copy h1 { max-width: 460px; font-size: clamp(27px, 5.5vw, 38px); }
.home-copy > .muted { max-width: 420px; margin-bottom: 0; }
.home-copy > .muted + .muted { margin-top: 8px; }
.hero-stat {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-start;
  min-width: 94px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
}
.hero-stat strong {
  font-size: 32px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.04em;
}
.hero-stat span { margin-top: 6px; color: var(--hint); font-size: 11px; }

.home-controls { margin: 0 0 22px; }
.langbar { display: flex; gap: 6px; margin: 0; }
.chip {
  flex: 1;
  padding: 8px 0;
  border: 1px solid transparent;
  background: rgba(120, 130, 122, .09);
  color: var(--text);
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.section-heading { margin: 0 2px 12px; }
.section-heading .muted { margin: 0; font-size: 13px; }
.modes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.mode {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 13px;
  width: 100%;
  text-align: left;
  min-height: 106px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
  animation: enter .22s ease-out both;
}
.mode:nth-child(2) { animation-delay: 25ms; }
.mode:nth-child(3) { animation-delay: 50ms; }
.mode:nth-child(4) { animation-delay: 75ms; }
.mode:nth-child(5) { animation-delay: 100ms; }
.mode-photo-wrap {
  display: block;
  width: 82px;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 12px;
  background: var(--accent-soft);
}
.mode-photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 200ms ease;
}
.mode.mode-no-photo { grid-template-columns: minmax(0, 1fr) 28px; padding-left: 17px; }
.mode-copy { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.mode-kicker {
  color: var(--accent);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .12em;
}
.mode .ttl { display: block; font-size: 15px; font-weight: 680; line-height: 1.25; }
.mode .sub { display: block; color: var(--hint); font-size: 12px; line-height: 1.35; }
.mode-arrow {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--hint);
  font-size: 14px;
  transition: color 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.mode:disabled { opacity: .5; cursor: default; }
.mode:disabled .mode-arrow { visibility: hidden; }

/* ---------- шапка теста ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.back {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 18px;
  cursor: pointer;
  flex: none;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.bar .mid { flex: 1; min-width: 0; }
.bar .counter { font-size: 13px; color: var(--hint); }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface);
  flex: none;
}
.timer.low { color: var(--bad); }

.progress {
  height: 4px;
  border-radius: 99px;
  background: rgba(128, 128, 128, .22);
  overflow: hidden;
  margin-top: 6px;
}
.progress i { display: block; height: 100%; background: var(--accent); transition: width 150ms ease; }

/* ---------- вопрос ---------- */
.qimg {
  width: 100%;
  max-height: min(56vh, 520px);
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  display: block;
  margin-bottom: 12px;
}
.qtext { font-size: 17px; font-weight: 650; line-height: 1.42; margin: 16px 2px; }

.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.opt .num {
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(128, 128, 128, .18);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}
.opt.ok { border-color: var(--ok); background: rgba(40, 116, 79, .07); }
.opt.ok .num { background: var(--ok); color: #fff; }
.opt.bad { border-color: var(--bad); background: rgba(185, 67, 62, .07); }
.opt.bad .num { background: var(--bad); color: #fff; }
.opt.locked { cursor: default; }

.verdict {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-weight: 600;
}
.verdict.ok { background: rgba(40, 116, 79, .1); color: var(--ok); }
.verdict.bad { background: rgba(185, 67, 62, .1); color: var(--bad); }
.answer-review {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.answer-review-title { color: var(--hint); font-size: 13px; font-weight: 600; }
.answer-correct { margin: 4px 0 0; font-weight: 600; }
.answer-explanation { margin-top: 12px; padding-top: 10px; border-top: 1px solid rgba(128, 128, 128, .18); }
.answer-explanation > strong { display: block; margin-bottom: 4px; }
.explanation-source { margin-top: 6px; color: var(--hint); font-size: 12px; }

/* ---------- нижняя кнопка ---------- */
.foot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.foot-inner { max-width: 744px; margin: 0 auto; }
.primary {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 150ms ease, background-color 150ms ease, opacity 150ms ease;
}
.primary:disabled { opacity: .5; }

/* ---------- результат ---------- */
.result-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  text-align: left;
  margin-bottom: 14px;
}
.result-head .big { font-size: 34px; font-weight: 700; margin: 6px 0; }
.result-head.pass .big { color: var(--ok); }
.result-head.fail .big { color: var(--bad); }
.wronglist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.wrongitem {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
}
.wrongitem .n { color: var(--hint); font-size: 13px; }
.wrongitem .answer-correct { margin: 8px 0; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions button { width: 100%; }
.ghost {
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.center { text-align: center; padding: 60px 0; color: var(--hint); }
.update-section { margin-bottom: 14px; }
.update-item {
  padding: 12px 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  line-height: 1.5;
}
.update-status {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.update-source {
  display: inline-block;
  margin: 4px 0 8px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}

/* ---------- экран доступа ---------- */
.idbox {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  letter-spacing: .5px;
  padding: 12px;
  border-radius: 12px;
background: var(--accent-soft);
}
  user-select: all;
  -webkit-user-select: all;
}

/* ---------- раздел «Правила» ---------- */
.rsearch {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.rsec { margin-bottom: 18px; }
.ritem {
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.5;
}
.ritem.sub { margin-left: 14px; font-size: 14.5px; }
.rnum {
  flex: none;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- защита от скриншотов ---------- */
.qimg { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

.wm {
  position: fixed;
  inset: 0;
  z-index: 9000;
  pointer-events: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(3, 1fr);
  overflow: hidden;
}
.wm span {
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: rgba(128, 128, 128, .16);
  transform: rotate(-24deg);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}
body.privacy #app,
body.privacy .wm { visibility: hidden; }
body.privacy::after {
  content: attr(data-privacy);
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  color: var(--hint);
  font-size: 18px;
  font-weight: 600;
}

.access-card { max-width: 520px; margin: min(12vh, 90px) auto 0; }
.access-card .brand-label { margin-bottom: 22px; }
.access-card h1 { margin-bottom: 12px; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(40, 107, 76, .32);
  outline-offset: 2px;
}

@media (hover: hover) {
  .mode:not(:disabled):hover {
    transform: translateY(-2px);
    border-color: rgba(40, 107, 76, .35);
  }
  .mode:not(:disabled):hover .mode-photo { transform: scale(1.04); }
  .mode:not(:disabled):hover .mode-arrow {
    color: var(--accent);
    border-color: rgba(40, 107, 76, .4);
    transform: translate(1px, -1px);
  }
  .opt:not(.locked):hover {
    transform: translateY(-1px);
    border-color: rgba(40, 107, 76, .4);
  }
  .primary:not(:disabled):hover { background: var(--accent-strong); }
  .ghost:hover, .back:hover { background: var(--accent-soft); border-color: rgba(40, 107, 76, .3); }
}

.mode:not(:disabled):active,
.opt:not(.locked):active,
.primary:not(:disabled):active,
.ghost:active,
.back:active { transform: scale(.99); }

@media (min-width: 680px) {
  #app { padding-right: 24px; padding-left: 24px; }
  .modes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .mode { grid-template-columns: 88px minmax(0, 1fr) 28px; min-height: 112px; }
  .mode-photo-wrap { width: 88px; }
  .home-controls { max-width: 330px; }
  .actions { flex-direction: row; }
}

@media (max-width: 420px) {
  #app { padding: 14px 14px calc(92px + env(safe-area-inset-bottom)); }
  .home-hero, .hero { padding: 18px; border-radius: 19px; }
  .home-hero .brand-label { margin-bottom: 20px; }
  .home-intro { align-items: flex-start; flex-direction: column; gap: 14px; }
  .hero-stat {
    flex-direction: row;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    padding: 10px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
  .hero-stat strong { font-size: 24px; }
  .hero-stat span { margin: 0; }
  .home-controls { margin-bottom: 19px; }
  .mode { grid-template-columns: 76px minmax(0, 1fr) 24px; gap: 11px; min-height: 94px; }
  .mode-photo-wrap { width: 76px; border-radius: 11px; }
  .mode-arrow { width: 23px; height: 23px; }
  .mode .ttl { font-size: 14px; }
  .mode .sub { font-size: 11px; }
  .brand-location { font-size: 9px; }
  .foot { padding-right: 14px; padding-left: 14px; }
}

@keyframes enter {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
