body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Шапка */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left)) 10px max(16px, env(safe-area-inset-right));
  background: var(--topbar-bg);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  line-height: 1.15;
}
.brand img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}
.brand b {
  display: block;
  font-size: 15px;
}
.brand-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
}
.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.me {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  min-width: 0;
}
.me-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
  color: var(--ink-2);
}
.cls-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
}

.app {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.narrow {
  max-width: 600px;
  margin: 0 auto;
}
.loading {
  padding: 80px 0;
  text-align: center;
  color: var(--muted);
}
.foot {
  padding: 24px 16px 32px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ── Главная ── */
.hero {
  display: grid;
  gap: 28px;
  align-items: center;
  padding: 8px 0 36px;
}
@media (min-width: 860px) {
  .hero {
    grid-template-columns: 1.05fr 1fr;
    gap: 48px;
    padding: 32px 0 56px;
  }
}
.hero h1 {
  font-size: clamp(36px, 7vw, 60px);
  margin: 12px 0 18px;
}
.hero h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--red);
}
.hero .lead {
  font-size: 18px;
  color: var(--ink-2);
  max-width: 34em;
}
.hero .cta {
  margin-top: 24px;
}
#join {
  scroll-margin-top: 72px;
}
.hero-photo {
  position: relative;
  margin: 0;
}
.hero-photo img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--r-lg);
}
.hero-photo figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.date-stamp {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
}
.date-stamp b {
  font-family: var(--serif);
  font-size: 16px;
  color: var(--red);
}

.section {
  padding: 36px 0;
  border-top: 1px solid var(--line);
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.section h2 {
  font-size: clamp(24px, 4vw, 32px);
}

.steps {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  counter-reset: step;
  padding: 0;
  margin: 0;
  list-style: none;
}
@media (min-width: 760px) {
  .steps {
    grid-template-columns: repeat(3, 1fr);
  }
}
.steps li {
  background: var(--surface);
  padding: 22px 22px 24px;
}
.steps li::before {
  counter-increment: step;
  content: '0' counter(step);
  display: block;
  font-family: var(--serif);
  font-size: 34px;
  line-height: 1;
  color: var(--red);
  margin-bottom: 14px;
}
.steps h3 {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0;
}
.steps p {
  color: var(--ink-2);
  font-size: 15px;
}

/* Регистрация */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.reg {
  padding: 24px;
  display: grid;
  gap: 18px;
}
.reg h2 {
  font-size: 26px;
}
.reg .sub {
  color: var(--ink-2);
  margin-top: 6px;
}
.reg-class {
  display: grid;
  gap: 10px;
}
.seg.who {
  grid-auto-flow: row;
  grid-template-columns: repeat(4, 1fr) 1.9fr;
}
.seg.who label[for='g0'] {
  font-size: 15px;
}
.seg.letters {
  grid-auto-flow: row;
  grid-template-columns: repeat(6, 1fr);
}
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* Прогресс */
.greet {
  display: grid;
  gap: 20px;
  padding: 8px 0 28px;
}
.greet h1 {
  font-size: clamp(30px, 6vw, 44px);
}
.greet .lead {
  color: var(--ink-2);
  font-size: 17px;
  margin-top: 8px;
}
.tiles {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--r);
  border: 1.5px dashed var(--line-strong);
  color: var(--muted);
  font-family: var(--serif);
  font-size: clamp(20px, 5vw, 30px);
  background: transparent;
}
.tile small {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.tile.ok {
  border: 0;
  background: var(--navy);
  color: #fff;
}
.tile.bad {
  border: 1.5px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
}
.tile.bad small {
  color: var(--bad);
}
.tiles-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.tiles-legend span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}
.tiles-legend .l-ok::before {
  background: var(--navy);
}
.tiles-legend .l-bad::before {
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
}
.tiles-legend .l-none::before {
  border: 1.5px dashed var(--line-strong);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.stat {
  background: var(--surface);
  padding: 16px;
}
.stat .v {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1.1;
}
.stat .k {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.closed-note {
  padding: 14px 16px;
  border-radius: var(--r);
  background: var(--paper-2);
  color: var(--ink-2);
  font-size: 15px;
}

/* ── Вопрос ── */
.q-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.q-no {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink-2);
}
.q-no b {
  font-size: 28px;
  color: var(--red);
  margin-right: 2px;
}
.chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface);
  white-space: nowrap;
}
.q-figure {
  margin: 0 0 18px;
}
.q-figure .frame {
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #0d0f14;
}
.q-figure img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}
.q-figure img.contain {
  object-fit: contain;
}
.q-figure figcaption {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.q-body {
  font-size: 19px;
  line-height: 1.5;
  margin-bottom: 22px;
}
.q-body.compact {
  font-size: 16px;
  color: var(--ink-2);
  margin-bottom: 18px;
}
.q-body p + p {
  margin-top: 10px;
}

.options {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}
.options legend {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 0;
}
.opt {
  position: relative;
}
.opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.opt label {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  cursor: pointer;
  font-size: 16px;
  line-height: 1.4;
  transition: border-color 0.12s, background 0.12s;
}
.opt label:hover {
  border-color: var(--line-strong);
}
.opt .mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-2);
  margin-top: -4px;
}
.opt.multi .mark {
  border-radius: 7px;
}
.opt input:checked + label {
  border-color: var(--navy);
  background: var(--sel-bg);
}
.opt input:checked + label .mark {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.opt input:focus-visible + label {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* после ответа */
.opt.is-correct input + label {
  border-color: var(--ok);
  background: var(--ok-bg);
}
.opt.is-correct input + label .mark {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.opt.is-wrong input + label {
  border-color: var(--bad);
  background: var(--bad-bg);
}
.opt.is-wrong input + label .mark {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}
.opt.locked label {
  cursor: default;
}
.opt .tag {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
}
.opt.is-correct .tag {
  color: var(--ok);
}
.opt.is-wrong .tag {
  color: var(--bad);
}

.num-input {
  font-family: var(--serif);
  font-size: 32px;
  min-height: 72px;
  text-align: center;
  letter-spacing: 0.04em;
}

.submit-bar {
  position: sticky;
  bottom: 0;
  margin: 22px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--paper) 30%);
}
.submit-bar .note {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

/* Результат */
.verdict {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 18px;
  border-radius: var(--r-lg);
  margin-bottom: 18px;
}
.verdict.ok {
  background: var(--ok-bg);
  color: var(--ok-ink);
}
.verdict.bad {
  background: var(--bad-bg);
  color: var(--bad-ink);
}
.verdict .icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.verdict.ok .icon {
  background: var(--ok);
}
.verdict.bad .icon {
  background: var(--bad);
}
.verdict h2 {
  font-size: 24px;
}
.verdict p {
  font-size: 15px;
  margin-top: 2px;
}
.your-answer {
  font-size: 15px;
  color: var(--ink-2);
  margin-bottom: 18px;
}
.your-answer b {
  color: var(--ink);
}
.explain {
  margin-top: 22px;
  padding: 22px;
}
.explain h3 {
  font-size: 22px;
  margin-bottom: 12px;
}
.explain .text p {
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1.6;
}
.explain .text p + p {
  margin-top: 12px;
}
.explain .answer-line {
  padding: 12px 14px;
  border-left: 3px solid var(--ok);
  background: var(--ok-bg);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin-bottom: 16px;
  font-weight: 600;
}
.sources {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.sources ul {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}
.sources a {
  word-break: break-all;
  color: var(--ink-2);
}
.next {
  margin-top: 22px;
  display: grid;
  gap: 12px;
  text-align: center;
}
.next p {
  color: var(--ink-2);
}

.empty {
  text-align: center;
  padding: 64px 0;
}
.empty h1 {
  font-size: 32px;
  margin-bottom: 12px;
}
.empty p {
  color: var(--ink-2);
  margin-bottom: 24px;
}

.inline-reg {
  margin-bottom: 26px;
}

@media (max-width: 420px) {
  .stat .v {
    font-size: 24px;
  }
  .me-name {
    display: none;
  }
}
