:root {
  --ink: #1f1640;
  --ink-2: #5b5478;
  --bg: #f6f3ff;
  --card: #ffffff;
  --line: #e6e0f5;
  --brand: #6c3ce1;
  --brand-2: #8b5cf6;
  --deep: #2a1659;
  --gold: #f5b82e;
  --ok: #1fae6a;
  --bad: #e5484d;
  --t1: #2f6fde; /* плитки ответов */
  --t2: #14a3a0;
  --t3: #e9a21b;
  --t4: #e0457b;
  --radius: 20px;
  --shadow: 0 6px 0 rgba(31, 22, 64, .08), 0 12px 28px rgba(31, 22, 64, .08);
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Montserrat', 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 17px; line-height: 1.45; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.hidden { display: none !important; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ===== Hero ===== */
.hero {
  position: relative; color: #fff; overflow: hidden;
  background: radial-gradient(120% 140% at 0% 0%, #8b5cf6 0%, #6c3ce1 40%, #3b1d8f 100%);
  padding: 28px 0 56px;
}
.hero::after { /* мягкая волна снизу */
  content: ''; position: absolute; left: -5%; right: -5%; bottom: -36px; height: 72px;
  background: var(--bg); border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}
.ornament { display: block; width: 100%; height: 26px; color: rgba(255, 255, 255, .35); }
.ornament.top { position: absolute; top: 0; left: 0; }
.hero .wrap { position: relative; z-index: 1; padding-top: 22px; }
.hero h1 {
  font-family: var(--display); font-weight: 800; letter-spacing: -.01em;
  font-size: clamp(2rem, 8vw, 3.4rem); margin: 0; line-height: 1.05;
}
.hero p.sub { margin: 10px 0 0; font-size: clamp(1rem, 3.6vw, 1.25rem); opacity: .92; font-weight: 700; }
.hero .who {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; padding: 8px 14px;
  background: rgba(255, 255, 255, .16); border-radius: 999px; font-weight: 700; font-size: .95rem;
}
.hero .who button { background: none; border: 0; color: #fff; text-decoration: underline; padding: 0; font-weight: 700; }
.topbtns { position: absolute; top: 34px; right: 16px; display: flex; gap: 8px; z-index: 2; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; display: grid; place-items: center;
  background: rgba(255, 255, 255, .18); color: #fff; font-size: 1.2rem;
}

/* ===== Главная: главы и карточки ===== */
main.home { padding: 8px 0 48px; }
.chapter { margin: 26px 0 8px; }
.chapter h2 {
  font-family: var(--display); font-size: clamp(1rem, 3.6vw, 1.25rem); font-weight: 700;
  margin: 0 0 14px; display: flex; align-items: flex-start; gap: 10px; color: var(--deep); line-height: 1.3;
}
.chapter h2::before { content: ''; width: 10px; height: 24px; border-radius: 6px; background: var(--c, var(--brand)); flex: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  position: relative; text-align: left; border: 0; border-radius: var(--radius); padding: 16px 16px 14px;
  min-height: 150px; display: flex; flex-direction: column; gap: 6px; color: #fff; text-decoration: none;
  background: var(--c); box-shadow: 0 6px 0 var(--cs, rgba(0, 0, 0, .18));
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-3px); }
.card:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--cs, rgba(0, 0, 0, .18)); }
.card .para { font-family: var(--display); font-weight: 800; font-size: 1.6rem; line-height: 1; }
.card .title { font-weight: 800; font-size: 1.05rem; line-height: 1.25; flex: 1; }
.card .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; font-weight: 800; }
.pill { background: rgba(255, 255, 255, .22); padding: 3px 10px; border-radius: 999px; }
.card .deco { position: absolute; right: -8px; top: -8px; width: 84px; height: 84px; opacity: .18; color: #fff; pointer-events: none; }
.card.closed {
  background: #ebe8f2; color: #8a849c; box-shadow: 0 6px 0 #d9d4e6; cursor: not-allowed;
}
.card.closed:hover { transform: none; }
.card.closed .pill { background: #fff; }
.lock { display: inline-flex; align-items: center; gap: 6px; }
.empty { text-align: center; color: var(--ink-2); padding: 40px 0; font-weight: 700; }

/* ===== Экраны с панелью ===== */
.screen { min-height: 100vh; min-height: 100dvh; }
.panel {
  background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 24px 20px;
  max-width: 560px; margin: -24px auto 32px; position: relative; z-index: 2;
}
.panel h2 { font-family: var(--display); font-size: clamp(1.2rem, 5vw, 1.6rem); margin: 4px 0 6px; line-height: 1.2; }
.panel .kicker { color: var(--brand); font-weight: 900; letter-spacing: .02em; }
.facts { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 18px; }
.fact { background: var(--bg); border-radius: 14px; padding: 10px 14px; font-weight: 800; }
.fact small { display: block; color: var(--ink-2); font-weight: 700; font-size: .78rem; }
label.f { display: block; font-weight: 800; margin: 14px 0 6px; }
.inp {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line); background: #fff;
  font-size: 1.05rem; color: var(--ink);
}
.inp:focus { border-color: var(--brand); outline: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 800;
  min-height: 40px;
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 16px;
  padding: 14px 22px; font-weight: 900; font-size: 1.05rem; min-height: 52px; text-decoration: none;
  background: var(--brand); color: #fff; box-shadow: 0 5px 0 #4a23b0; transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #4a23b0; }
.btn.big { width: 100%; font-size: 1.3rem; min-height: 64px; font-family: var(--display); letter-spacing: .02em; }
.btn.ghost { background: var(--bg); color: var(--deep); box-shadow: 0 5px 0 var(--line); }
.btn.gold { background: var(--gold); color: #3a2600; box-shadow: 0 5px 0 #c98f12; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.err { color: var(--bad); font-weight: 800; margin: 10px 0 0; min-height: 1.2em; }
.back { display: inline-flex; align-items: center; gap: 6px; color: #fff; text-decoration: none; font-weight: 800; }
.closed-box { text-align: center; padding: 10px 0; }
.closed-box .big-lock { font-size: 3rem; }

/* ===== Экран вопроса ===== */
.quiz {
  background: radial-gradient(120% 80% at 50% 0%, #3d2187 0%, #24124f 60%, #1a0d3a 100%);
  color: #fff; display: flex; flex-direction: column;
}
.qbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px 6px; max-width: 1040px; width: 100%; margin: 0 auto; }
.qbar .icon-btn { background: rgba(255, 255, 255, .12); flex: none; }
.qbar .count { font-weight: 900; font-size: 1rem; white-space: nowrap; }
.qbar .spacer { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .12); font-weight: 900; white-space: nowrap;
}
.badge.streak.hot { background: linear-gradient(90deg, #ff7a18, #f5b82e); color: #3a1800; animation: pop .35s; }
.progress { height: 8px; background: rgba(255, 255, 255, .14); border-radius: 99px; overflow: hidden; margin: 0 16px; max-width: 1008px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #f5b82e, #ff7a59); border-radius: 99px; transition: width .4s ease; }
.progress-wrap { max-width: 1040px; width: 100%; margin: 0 auto; }
.timer { height: 6px; margin: 8px 16px 0; background: rgba(255, 255, 255, .1); border-radius: 99px; overflow: hidden; }
.timer > i { display: block; height: 100%; width: 100%; background: #5eead4; border-radius: 99px; transform-origin: left; }
.timer.warn > i { background: #ff6b6b; }
.qbody { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 14px 16px 20px; max-width: 1040px; width: 100%; margin: 0 auto; }
.qcard {
  background: #fff; color: var(--ink); border-radius: 22px; padding: 20px 18px; text-align: center;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .25); display: flex; flex-direction: column; gap: 14px; align-items: center;
  animation: rise .35s ease;
}
.qtext { font-size: clamp(1.15rem, 4.6vw, 1.75rem); font-weight: 800; line-height: 1.3; margin: 0; }
.qimg {
  width: 100%; max-width: 560px; border-radius: 14px; cursor: zoom-in; display: block;
  border: 0; padding: 0; background: none; position: relative;
}
.qimg img { width: 100%; height: auto; max-height: 34vh; object-fit: contain; border-radius: 14px; display: block; }
.qimg .zoom { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .55); color: #fff; border-radius: 10px; padding: 2px 8px; font-size: .85rem; font-weight: 800; }
.tiles { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .tiles { grid-template-columns: 1fr 1fr; gap: 14px; } }
.tile {
  position: relative; border: 0; border-radius: 18px; padding: 14px 16px 14px 62px; min-height: 66px;
  text-align: left; color: #fff; font-weight: 800; font-size: clamp(1rem, 3.8vw, 1.25rem); line-height: 1.25;
  background: var(--tc); box-shadow: 0 6px 0 rgba(0, 0, 0, .28); transition: transform .12s, opacity .25s, box-shadow .12s;
  animation: rise .35s ease both;
}
@media (min-width: 640px) { .tile { min-height: 110px; } }
.tile:nth-child(1) { --tc: var(--t1); }
.tile:nth-child(2) { --tc: var(--t2); animation-delay: .04s; }
.tile:nth-child(3) { --tc: var(--t3); animation-delay: .08s; }
.tile:nth-child(4) { --tc: var(--t4); animation-delay: .12s; }
.tile:nth-child(5) { --tc: #7c5cff; }
.tile:nth-child(6) { --tc: #ff8a3d; }
.tile .sh {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px;
  border-radius: 12px; background: rgba(255, 255, 255, .22); display: grid; place-items: center;
}
.tile .sh svg { width: 22px; height: 22px; fill: #fff; }
.tile:not([disabled]):hover { transform: translateY(-2px); }
.tile:not([disabled]):active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .28); }
.tile[disabled] { cursor: default; }
.tiles.locked .tile { opacity: .35; animation: none; }
.tiles.locked .tile.right { opacity: 1; background: var(--ok); box-shadow: 0 0 0 4px #fff, 0 6px 0 rgba(0, 0, 0, .28); animation: pop .4s; }
.tiles.locked .tile.wrong { opacity: 1; background: var(--bad); animation: shake .4s; }
.tile .mark { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 1.4rem; }

/* Нижняя панель обратной связи */
.feedback {
  position: sticky; bottom: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: #fff; color: var(--ink); border-radius: 24px 24px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .25);
  animation: slideup .3s ease;
}
.feedback .in { max-width: 1008px; margin: 0 auto; display: grid; gap: 10px; }
.feedback .head { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 1.25rem; }
.feedback.ok .head { color: var(--ok); }
.feedback.no .head { color: var(--bad); }
.feedback .pts { margin-left: auto; font-family: var(--font); font-weight: 900; color: var(--brand); font-size: 1.1rem; }
.feedback .expl { margin: 0; color: var(--ink-2); font-weight: 700; }
.feedback .page { display: inline-flex; gap: 6px; align-items: center; background: var(--bg); color: var(--deep); padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .9rem; justify-self: start; }

/* Увеличение картинки */
.zoomer { position: fixed; inset: 0; background: rgba(10, 5, 25, .92); display: grid; place-items: center; z-index: 50; padding: 16px; cursor: zoom-out; }
.zoomer img { width: min(100%, 1100px); height: auto; max-height: 90vh; object-fit: contain; border-radius: 12px; }
.zoomer .credit { position: absolute; bottom: 12px; left: 16px; right: 16px; color: #cfc8e8; font-size: .8rem; text-align: center; word-break: break-all; }

/* ===== Результат ===== */
.result-hero { text-align: center; }
.ring { width: 170px; height: 170px; margin: 0 auto 8px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 2.4rem; color: var(--deep); }
.ring .val small { display: block; font-family: var(--font); font-size: .85rem; color: var(--ink-2); font-weight: 800; margin-top: -4px; }
.praise { font-family: var(--display); font-weight: 800; font-size: 1.3rem; margin: 4px 0 2px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 18px 0; }
@media (min-width: 480px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--bg); border-radius: 16px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 1.35rem; font-family: var(--display); }
.stat span { font-size: .8rem; color: var(--ink-2); font-weight: 800; }
.stat.ok b { color: var(--ok); }
.stat.no b { color: var(--bad); }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
h3.sec { font-family: var(--display); font-size: 1.05rem; margin: 26px 0 10px; }
.mistake { border: 2px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.mistake .mq { font-weight: 800; margin: 0 0 8px; }
.mistake .ans { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; margin: 4px 0; }
.mistake .ans.y { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 2px; }
.mistake .ans.c { color: var(--ok); }
.mistake .ex { color: var(--ink-2); margin: 8px 0 0; font-size: .95rem; }
.lb { list-style: none; margin: 0; padding: 0; }
.lb li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; font-weight: 800; }
.lb li:nth-child(odd) { background: var(--bg); }
.lb li.me { background: #fff4d6; outline: 2px solid var(--gold); }
.lb .rk { width: 30px; text-align: center; font-family: var(--display); }
.lb .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .kl { color: var(--ink-2); font-size: .85rem; }
.lb .sc { color: var(--brand); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

.loading { display: grid; place-items: center; min-height: 40vh; color: var(--ink-2); font-weight: 800; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.quiz .loading { color: #d8cff5; }
.quiz .spinner { border-color: rgba(255, 255, 255, .15); border-top-color: var(--gold); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--deep); color: #fff;
  padding: 12px 18px; border-radius: 14px; font-weight: 800; z-index: 70; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
footer.foot { text-align: center; color: var(--ink-2); font-size: .85rem; padding: 0 16px 28px; }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes ringfill { from { stroke-dashoffset: var(--c0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ===== Админка ===== */
.admin-top { background: var(--deep); color: #fff; }
.admin-top .wrap { display: flex; align-items: center; gap: 12px; padding-top: 14px; padding-bottom: 14px; flex-wrap: wrap; }
.admin-top h1 { font-family: var(--display); font-size: 1.15rem; margin: 0; flex: 1; }
.admin-top .btn { min-height: 42px; padding: 8px 14px; font-size: .95rem; }
.a-chapter { background: #fff; border-radius: 20px; box-shadow: var(--shadow); padding: 14px; margin: 18px 0; }
.a-chapter header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.a-chapter h2 { font-family: var(--display); font-size: 1rem; margin: 0; flex: 1; min-width: 200px; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: .88rem; border-radius: 12px; box-shadow: 0 3px 0 #4a23b0; }
.btn.sm.ghost { box-shadow: 0 3px 0 var(--line); }
.btn.sm.danger { background: #fff0f0; color: var(--bad); box-shadow: 0 3px 0 #f3c9ca; }
.a-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 6px; border-top: 1px solid var(--line); }
.a-row .t { font-weight: 800; }
.a-row .t small { display: block; color: var(--ink-2); font-weight: 700; }
.a-row .acts { display: flex; gap: 8px; align-items: center; }
.switch { position: relative; width: 58px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: #d6d0e4; border-radius: 99px; transition: background .2s; }
.switch span::after { content: ''; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(26px); }
.switch input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 2px; }
.st-open { color: var(--ok); font-weight: 900; }
.st-closed { color: #8a849c; font-weight: 900; }
.modal { position: fixed; inset: 0; background: rgba(20, 10, 45, .55); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto; }
.modal .box { background: #fff; border-radius: 22px; width: 100%; max-width: 980px; padding: 18px; margin: 10px 0 40px; }
.modal .box header { display: flex; gap: 10px; align-items: flex-start; }
.modal .box h2 { font-family: var(--display); font-size: 1.1rem; margin: 0; flex: 1; }
.tabs { display: flex; gap: 6px; margin: 14px 0; flex-wrap: wrap; }
.tabs button { border: 0; background: var(--bg); border-radius: 12px; padding: 8px 14px; font-weight: 800; }
.tabs button.on { background: var(--brand); color: #fff; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar label { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { color: var(--ink-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr.unfinished td { color: #9b95ad; }
.del { border: 0; background: none; color: var(--bad); font-size: 1.1rem; padding: 4px 8px; }
.qstat { border: 2px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; }
.qstat .top { display: flex; gap: 10px; align-items: baseline; }
.qstat .pct { font-family: var(--display); font-weight: 800; font-size: 1.2rem; min-width: 64px; }
.qstat .pct.lo { color: var(--bad); } .qstat .pct.mid { color: #c98500; } .qstat .pct.hi { color: var(--ok); }
.qstat .qq { font-weight: 800; flex: 1; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.bar i { display: block; height: 100%; background: var(--brand); }
.opts { display: grid; gap: 4px; font-size: .9rem; }
.opts div { display: flex; gap: 8px; }
.opts .c { color: var(--ok); font-weight: 800; }
.opts .n { margin-left: auto; color: var(--ink-2); font-weight: 700; }
.login-box { max-width: 380px; margin: 60px auto; }
