/* ---------- база ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 750; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: grid; gap: 12px; }
.stack-lg { display: grid; gap: 20px; }
.grow { flex: 1; min-width: 0; }

.app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.screen {
  flex: 1;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
  animation: screen-in .22s ease-out;
}
.screen.no-tabs { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.splash { min-height: 70dvh; display: grid; place-content: center; text-align: center; gap: 8px; color: var(--muted); }
.seo-intro { max-width: 640px; margin: 0 auto; padding: 0 16px 24px; text-align: center; color: var(--muted); font-size: 15px; }
.seo-intro h1 { font-size: 20px; }
.splash-icon { font-size: 64px; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* ---------- нижнее меню ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--surface);
  box-shadow: var(--shadow-up);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; max-width: 112px;
  display: grid; justify-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none;
  padding: 6px 0; border-radius: 12px;
}
.tabbar a b { font-weight: 600; }
.tabbar a .ic { transition: transform .15s; }
.tabbar a.active { color: var(--primary); }
.tabbar a.active .ic { transform: scale(1.1); stroke-width: 2.2; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 20px;
  border: 0; border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  font-weight: 700; font-size: 17px; text-decoration: none;
  cursor: pointer; user-select: none;
  transition: transform .08s, filter .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible, .answer:focus-visible, .card-btn:focus-visible { outline: 3px solid var(--primary-2); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 6px 18px rgba(91, 75, 245, .35); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-danger { background: var(--bad-bg); color: var(--bad); }
.btn-block { width: 100%; }
.btn-big { min-height: 64px; font-size: 20px; border-radius: 22px; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0;
  background: var(--surface-2); display: grid; place-items: center; font-size: 20px; cursor: pointer;
}

/* ---------- карточки ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-btn { display: block; width: 100%; text-align: left; border: 0; cursor: pointer; color: inherit; font: inherit; transition: transform .08s; }
.card-btn:active { transform: scale(.98); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 700; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--bad); color: #fff; font-size: 12px; font-weight: 800; display: inline-grid; place-items: center; }

/* ---------- шапка ---------- */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 44px; }
.topbar h1, .topbar h2 { flex: 1; min-width: 0; }

/* ---------- главная ---------- */
.hello { display: flex; gap: 12px; align-items: flex-start; }
.avatar {
  flex: none; width: 52px; height: 52px; border-radius: 18px;
  display: grid; place-items: center; font-size: 30px;
  background: var(--av, var(--primary-soft));
}
.avatar.lg { width: 76px; height: 76px; border-radius: 24px; font-size: 44px; }
.bubble {
  position: relative; background: var(--surface); border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); font-size: 15px;
}
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat b { font-size: 22px; display: block; line-height: 1.1; }
.stat .label { font-size: 13px; color: var(--muted); }
.flame { color: var(--flame); }
.xpbar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.xpbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: 6px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }

.goal { display: flex; align-items: center; gap: 16px; }
.ring { flex: none; }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: url(#ringGrad); stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2, .8, .2, 1); }
.ring text { font-weight: 800; fill: var(--text); }

.quest { display: flex; gap: 12px; align-items: center; padding: 10px 0; }
.quest + .quest { border-top: 1px solid var(--line); }
.quest .q-icon { width: 36px; height: 36px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.quest.done .q-icon { background: var(--ok-bg); }
.quest.done .q-title { color: var(--muted); text-decoration: line-through; }
.minibar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.minibar > i { display: block; height: 100%; background: var(--ok); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-height: 92px; display: grid; align-content: space-between; gap: 6px; }
.tile .t-icon { font-size: 26px; }
.tile b { font-size: 16px; }

/* ---------- онбординг ---------- */
.onb { min-height: calc(100dvh - 40px); display: grid; grid-template-rows: auto 1fr auto; gap: 18px; }
.onb > .btn { position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots i { width: 8px; height: 8px; border-radius: 4px; background: var(--gray); transition: width .2s; }
.dots i.on { width: 24px; background: var(--primary); }
.choice-list { display: grid; gap: 12px; align-content: start; }
.choice { background: var(--surface); border: 3px solid transparent; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); text-align: left; cursor: pointer; width: 100%; color: inherit; }
.choice.on { border-color: var(--primary); background: var(--primary-soft); }
.choice .big { font-size: 22px; font-weight: 800; }
.mentor { display: flex; gap: 12px; align-items: flex-start; }
.mentor .quote { font-size: 14px; color: var(--muted); margin-top: 4px; font-style: italic; }
.goals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.goals .choice { text-align: center; padding: 18px 6px; }

/* ---------- вопрос ---------- */
.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.q-progress { flex: 1; height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.q-progress > i { display: block; height: 100%; background: var(--ok); border-radius: 6px; transition: width .3s; }
.combo { font-weight: 800; color: var(--flame); min-width: 48px; text-align: right; font-size: 15px; }
.combo.pop { animation: pop .35s; }
.q-img { border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); margin-bottom: 12px; }
.q-img img { width: 100%; height: auto; }
.q-text { font-size: 18px; font-weight: 650; margin-bottom: 14px; }
.answers { display: grid; gap: 10px; }
.answer {
  display: flex; gap: 12px; align-items: flex-start;
  width: 100%; min-height: var(--tap); padding: 14px 14px;
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  text-align: left; font-size: 16px; cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
}
.answer:active { transform: scale(.985); }
.answer .num { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.answer.correct { border-color: var(--ok); background: var(--ok-bg); }
.answer.correct .num { background: var(--ok); color: #fff; }
.answer.wrong { border-color: var(--bad); background: var(--bad-bg); animation: shake .35s; }
.answer.wrong .num { background: var(--bad); color: #fff; }
.answers.locked .answer { pointer-events: none; }
.answers.locked .answer:not(.correct):not(.wrong) { opacity: .55; }

/* Нижняя плашка после ответа */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-width: 560px; margin: 0 auto;
  background: var(--surface); border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-up);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 72dvh;
  display: flex; flex-direction: column; gap: 12px;
  animation: sheet-in .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet-body { overflow-y: auto; min-height: 0; flex: 1; overscroll-behavior: contain; }
.sheet-next { flex: none; }
.sheet.ok { border-top: 5px solid var(--ok); }
.sheet.bad { border-top: 5px solid var(--bad); }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
.verdict { font-weight: 800; font-size: 19px; }
.sheet.ok .verdict { color: var(--ok); }
.sheet.bad .verdict { color: var(--bad); }
.explain { font-size: 16px; }
.serious { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; font-size: 14px; line-height: 1.5; }
.serious .rule { font-weight: 700; margin-bottom: 4px; }
.spacer-sheet { height: 220px; }

/* ---------- итог ---------- */
.result-hero { text-align: center; display: grid; gap: 6px; justify-items: center; padding: 10px 0; }
.result-hero .emoji { font-size: 72px; animation: pop .5s; }
.big-num { font-size: 44px; font-weight: 900; line-height: 1; }
.ach { display: flex; gap: 12px; align-items: center; }
.ach .a-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 26px; background: var(--primary-soft); flex: none; }
.ach.locked .a-icon { background: var(--surface-2); filter: grayscale(1); opacity: .6; }

/* ---------- карта тем ---------- */
.topic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.topic {
  position: relative; overflow: hidden;
  background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
  min-height: 108px; display: grid; align-content: space-between; gap: 6px;
  border: 3px solid var(--tier, var(--gray));
}
.topic .t-icon { font-size: 26px; }
.topic .t-name { font-weight: 750; font-size: 15px; line-height: 1.2; }
.topic .t-meta { font-size: 12px; color: var(--muted); }
.topic .t-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.topic .t-bar > i { display: block; height: 100%; background: var(--tier, var(--gray)); }
.topic[data-tier="gray"] { --tier: var(--gray); }
.topic[data-tier="gray"] .t-icon { filter: grayscale(1); opacity: .5; }
.topic[data-tier="started"] { --tier: var(--started); }
.topic[data-tier="bronze"] { --tier: var(--bronze); }
.topic[data-tier="silver"] { --tier: var(--silver); }
.topic[data-tier="gold"] { --tier: var(--gold); background: linear-gradient(160deg, var(--surface) 60%, rgba(242, 180, 0, .18)); }
.topic[data-tier="gold"]::after { content: "★"; position: absolute; top: 8px; right: 10px; color: var(--gold); font-size: 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend .chip::before { content: ""; width: 10px; height: 10px; border-radius: 5px; background: var(--c); }

/* ---------- знаки ---------- */
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; border: 0; border-radius: 999px; padding: 8px 14px; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; font-size: 14px; cursor: pointer; color: var(--text); }
.seg button.on { background: var(--primary); color: #fff; }
.sign-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sign-cell { background: var(--surface); border-radius: var(--radius-sm); padding: 10px 6px; box-shadow: var(--shadow); display: grid; justify-items: center; gap: 6px; text-align: center; }
.sign-cell img { width: 64px; height: 64px; object-fit: contain; }
.sign-cell .num { font-weight: 800; font-size: 13px; }
.sign-cell .name { font-size: 12px; color: var(--muted); line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sign-cell.seen { outline: 2px solid var(--ok-bg); }
.no-img { width: 64px; height: 64px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-weight: 900; font-size: 16px; }
.tabs-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.tabs-wrap button { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; min-height: 40px; background: var(--surface); font-weight: 650; font-size: 14px; cursor: pointer; color: var(--text); }
.tabs-wrap button .cnt { color: var(--muted); font-weight: 500; font-size: 12px; }
.tabs-wrap button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink-strong, #fff); }
.tabs-wrap button.on .cnt { color: inherit; opacity: .75; }

.sign-card { display: grid; gap: 14px; }
.sign-head { display: flex; gap: 14px; align-items: center; }
.sign-head img, .sign-head .no-img { width: 112px; height: 112px; object-fit: contain; flex: none; }
.sign-head .no-img { font-size: 26px; }
.sign-head h2 { font-size: 19px; margin: 6px 0 2px; }
.sign-text { display: grid; gap: 10px; font-size: var(--fs-body, 16px); line-height: 1.55; }
.sign-text p { margin: 0; }
.sign-text .lead { font-size: 17px; font-weight: 600; }
.mentor-say { display: flex; gap: 10px; align-items: flex-start; }
.avatar.sm { width: 40px; height: 40px; font-size: 22px; border-radius: 13px; }
.sec { background: var(--surface); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 12px 14px; font-weight: 700; min-height: 48px; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.sec[open] > summary::after { transform: rotate(-135deg); }
.sec > summary .ic { color: var(--primary); flex: none; }
.sec-body { padding: 0 14px 14px; display: grid; gap: 8px; font-size: 15px; }
.bullets { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.fine { border-left: 3px solid var(--bad); padding: 6px 0 6px 10px; display: grid; gap: 2px; }
.fine-sum { font-weight: 800; }
.fine-art { font-size: 12px; color: var(--muted); }
.fine-text { font-size: 14px; color: var(--muted); }
.sign-nav { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); display: flex; gap: 8px; background: var(--bg); padding: 10px 0 calc(4px + env(safe-area-inset-bottom)); margin-bottom: calc(-18px - env(safe-area-inset-bottom)); }
.sign-nav .btn { min-width: 56px; }
.ic { flex: none; vertical-align: middle; }

/* модальное окно */
.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(10, 8, 30, .5); display: grid; align-items: end; animation: fade .2s; }
.modal { background: var(--bg); border-radius: 24px 24px 0 0; max-width: 560px; width: 100%; margin: 0 auto; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow-y: auto; animation: sheet-in .25s cubic-bezier(.2, .8, .2, 1); }
.modal-center { align-items: center; padding: 16px; }
.modal-center .modal { border-radius: 24px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- экзамен-босс ---------- */
.boss { background: linear-gradient(160deg, #2a0f2e, #4a1030); color: #fff; border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.boss-row { display: flex; align-items: center; gap: 12px; }
.boss-face { font-size: 44px; line-height: 1; transition: transform .2s; }
.boss-face.hit { animation: hit .4s; }
.boss-face.laugh { animation: laugh .5s; }
.boss-hp { height: 14px; border-radius: 7px; background: rgba(255, 255, 255, .15); overflow: hidden; margin-top: 6px; }
.boss-hp > i { display: block; height: 100%; background: linear-gradient(90deg, #ff4d5e, #ff9a3c); transition: width .4s; }
.boss .timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 18px; }
.boss .timer.low { color: #ffb4b4; animation: blink 1s infinite; }
.strikes { display: flex; gap: 4px; }
.strikes i { font-style: normal; opacity: .3; }
.strikes i.on { opacity: 1; }
.tickets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tickets a { aspect-ratio: 1; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); font-weight: 800; color: var(--text); font-size: 15px; text-decoration: none; }
.tickets a.passed { background: var(--ok-bg); color: var(--ok); }
.tickets a.failed { background: var(--bad-bg); color: var(--bad); }
@keyframes hit { 30% { transform: translateX(-8px) rotate(-8deg) scale(.9); } 60% { transform: translateX(6px) rotate(6deg); } }
@keyframes laugh { 25%, 75% { transform: translateY(-6px); } 50% { transform: translateY(0) scale(1.1); } }
@keyframes blink { 50% { opacity: .5; } }

/* ---------- график ---------- */
.chart text { fill: var(--muted); font-size: 10px; }
.chart .bar { fill: var(--primary); }
.chart .bar.ok { fill: var(--ok); }
.chart .goal-line { stroke: var(--flame); stroke-dasharray: 4 4; }

/* ---------- настройки ---------- */
.setting { display: grid; gap: 10px; }
.opts { display: flex; gap: 8px; flex-wrap: wrap; }
.opts button { flex: 1; min-width: 72px; min-height: 48px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; color: var(--text); }
.opts button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.input { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); }

/* ---------- эффекты ---------- */
.toasts { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 0; right: 0; z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 16px; font-weight: 700; box-shadow: var(--shadow); max-width: 100%; display: flex; gap: 10px; align-items: center; animation: toast-in .3s cubic-bezier(.2, .8, .2, 1); }
.toast.big { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; padding: 12px 16px; }
.toast .t-ico { font-size: 26px; }
.toast small { display: block; font-weight: 500; opacity: .85; }
.toast.out { animation: toast-out .3s forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-20px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-20px); } }
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.xp-float { position: fixed; font-weight: 900; color: var(--primary); font-size: 22px; animation: float-up 1s ease-out forwards; text-shadow: 0 2px 0 var(--surface); }
@keyframes float-up { to { transform: translateY(-70px); opacity: 0; } }
.confetti { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.levelup { text-align: center; display: grid; gap: 10px; justify-items: center; padding: 10px 0; }
.levelup .emoji { font-size: 72px; animation: pop .6s; }

.empty { text-align: center; padding: 40px 10px; display: grid; gap: 10px; justify-items: center; color: var(--muted); }
.empty .emoji { font-size: 56px; }

@media (min-width: 420px) {
  .sign-grid { grid-template-columns: repeat(4, 1fr); }
  .topic-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 340px) {
  .screen { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 22px; }
  .goals .choice { padding: 14px 4px; }
  .tickets { grid-template-columns: repeat(4, 1fr); }
  .sign-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
