:root {
  --paper: #fff7ea;
  --paper-2: #fdebd0;
  --card: #ffffff;
  --ink: #2a1c13;
  --ink-2: #6b5546;
  --line: #ecd8bd;
  --orange: #ee7a1f;
  --orange-d: #c95f0c;
  --plum: #4a2c63;
  --plum-l: #ece3f5;
  --green: #2e7d4f;
  --green-l: #e3f3e8;
  --red: #c23b2a;
  --shadow: 0 10px 30px rgba(74, 44, 20, .12);
  --radius: 18px;
  --head: 'Rubik', system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 17px/1.55 var(--body);
  background-image: radial-gradient(circle at 10% 0%, #ffe6c4 0, transparent 40%), radial-gradient(circle at 100% 30%, #f3e6ff 0, transparent 35%);
  background-attachment: fixed;
}
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: var(--head); line-height: 1.15; margin: 0 0 .5em; }
h2 { font-size: clamp(26px, 3.4vw, 38px); }
a { color: var(--plum); }
section { max-width: 1180px; margin: 0 auto; padding: 56px 20px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 700 16px var(--body); padding: 13px 22px; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  text-decoration: none; cursor: pointer; transition: transform .12s, box-shadow .12s;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .4; cursor: default; transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn-primary { background: var(--orange); color: #fff; }
.btn-plum { background: var(--plum); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; }
.btn-round { width: 52px; height: 52px; padding: 0; font-size: 22px; }
.btn-sm { padding: 8px 14px; font-size: 14px; box-shadow: 0 3px 0 var(--ink); }
.linklike { background: none; border: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; font: inherit; font-size: 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: rgba(255, 247, 234, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 800 22px var(--head); color: var(--ink); text-decoration: none; }
.brand-coin {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffd77a, #e9a21b); border: 2px solid var(--ink); font-size: 18px;
}
.topnav { display: flex; gap: 18px; margin-left: auto; }
.topnav a { color: var(--ink); text-decoration: none; font-weight: 700; }
.topnav a:hover { color: var(--orange-d); }
.access-pill { font-size: 13px; font-weight: 800; padding: 6px 12px; border-radius: 999px; background: var(--plum-l); color: var(--plum); white-space: nowrap; }
.access-pill.open { background: var(--green-l); color: var(--green); }

/* ---------- cover (first screen) ---------- */
.cover { display: grid; grid-template-columns: minmax(0, 430px) minmax(0, 1fr); gap: 48px; align-items: center; padding-top: 28px; }
.eyebrow { font-weight: 800; color: var(--orange-d); text-transform: uppercase; letter-spacing: .06em; font-size: 13px; margin: 0 0 12px; }
.cover h1 { font-size: clamp(34px, 5vw, 58px); }
.lead { font-size: 19px; color: var(--ink-2); max-width: 36em; }
.cover-cta { display: flex; flex-wrap: wrap; gap: 14px; margin: 26px 0 12px; }
.btn-xl { font-size: 19px; padding: 16px 28px; }
.cover-sub { color: var(--ink-2); font-weight: 700; margin: 0; }
.cover-art { position: relative; margin: 0; }
.cover-art img {
  width: 100%; border-radius: 14px; border: 3px solid var(--ink); box-shadow: 10px 12px 0 var(--orange);
  transform: rotate(-1.5deg); background: var(--paper-2); aspect-ratio: 900 / 1272; object-fit: cover;
}
.cover-play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 96px; height: 96px; border-radius: 50%;
  border: 3px solid var(--ink); background: var(--orange); color: #fff; font-size: 38px; padding-left: 8px; cursor: pointer;
  box-shadow: 0 6px 0 var(--ink); transition: transform .12s;
}
.cover-play:hover { transform: translate(-50%, -50%) scale(1.06); }

/* ---------- table of contents ---------- */
.toc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.toc .chapter { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; }

/* ---------- game promo ---------- */
.game-card {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 36px; align-items: center;
  background: linear-gradient(135deg, #fff1dc, #ffe1b8); border: 3px solid var(--ink); border-radius: 26px; padding: 36px; box-shadow: 8px 10px 0 var(--plum);
}
.game-points { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 8px; font-weight: 700; }
.game-note { margin: 0; font-size: 15px; color: var(--ink-2); }
.game-shot { display: block; border-radius: 16px; overflow: hidden; border: 3px solid var(--ink); transform: rotate(1.5deg); transition: transform .2s; background: #fff; }
.game-shot:hover { transform: rotate(0) scale(1.02); }
.game-shot img { width: 100%; height: auto; }

/* ---------- how ---------- */
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.steps li { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 22px; }
.steps h3 { font-size: 19px; margin-top: 12px; }
.steps p { margin: 0; color: var(--ink-2); font-size: 15px; }
.step-n { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--plum); color: #fff; font: 800 20px var(--head); }

/* ---------- comic mode ---------- */
body.mode-open { overflow: hidden; }
.comic-mode { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: #1d140e; color: #fff; }
.cm-top, .cm-bottom { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #2a1d14; }
.cm-top { border-bottom: 1px solid #3d2b1e; }
.cm-bottom { border-top: 1px solid #3d2b1e; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.cm-icon { width: 44px; height: 44px; border-radius: 12px; border: 0; background: #3d2b1e; color: #fff; font-size: 28px; line-height: 1; cursor: pointer; }
.cm-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cm-title b { font: 700 17px var(--head); }
.cm-title span { font-size: 14px; color: #d9c4b0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-pill { font-size: 13px; font-weight: 800; padding: 6px 10px; border-radius: 999px; background: #3d2b1e; color: #ffd58f; }
.cm-stage { flex: 1; overflow: auto; padding: 16px; display: flex; justify-content: center; align-items: flex-start; overscroll-behavior: contain; }
.viewer-frame {
  --fit-w: .7;
  position: relative; margin: auto; touch-action: pan-y;
  /* ширина подбирается так, чтобы все блоки экрана поместились по высоте, но не уже 300px */
  width: min(100%, 860px, max(300px, calc((100dvh - 170px) * var(--fit-w))));
}
.panels { display: flex; flex-direction: column; gap: 10px; }
.panel { position: relative; overflow: hidden; border-radius: 6px; background: #3d2b1e; }
.panel img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; user-select: none; animation: fadein .25s; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.viewer-frame.is-locked .panel img { filter: blur(16px) saturate(.6); transform: scale(1.08); }
[hidden] { display: none !important; }
.locked-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(29, 20, 14, .35); }
.lock-card { background: var(--card); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--radius); padding: 26px; max-width: 360px; text-align: center; box-shadow: var(--shadow); }
.lock-card p { color: var(--ink-2); font-size: 15px; }
.lock-ico { font-size: 40px; }
.viewer-progress { flex: 1; height: 8px; border-radius: 99px; background: #3d2b1e; overflow: hidden; }
.viewer-progress i { display: block; height: 100%; width: 0; background: var(--orange); transition: width .3s; }
.comic-mode .btn { border-color: #000; }
.comic-mode .btn-round { background: #3d2b1e; color: #fff; }
.viewer-next { min-width: 140px; height: 52px; }

/* ---------- lesson buttons ---------- */
.chapter { margin-bottom: 8px; }
.chapter-title { font: 700 13px var(--head); text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); padding: 8px 8px 4px; }
.lesson-btn {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; font: 600 14px var(--body);
  background: none; border: 0; border-radius: 10px; padding: 7px 8px; cursor: pointer; color: var(--ink);
}
.lesson-btn:hover { background: var(--paper); }
.lesson-btn.current { background: var(--paper-2); outline: 2px solid var(--orange); }
.lesson-btn .dot { flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--paper-2); }
.lesson-btn.read .dot { background: var(--green); color: #fff; }
.lesson-btn.locked { color: #a8968a; }
.lesson-btn.locked .dot { background: #eee5dc; }
.lesson-btn .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quest-btn { background: var(--plum-l); color: var(--plum); font-weight: 800; margin-top: 2px; }
.quest-btn .dot { background: var(--plum); color: #fff; }
.quest-btn.done .dot { background: var(--green); }
.quest-btn.locked { background: #f4f0f7; color: #a79bb3; }
.quest-btn.locked .dot { background: #d9d0e2; }

/* ---------- admin ---------- */
.admin-fab { position: fixed; right: 18px; bottom: 18px; z-index: 30; width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); font-size: 24px; cursor: pointer; box-shadow: var(--shadow); }
.admin-form { display: grid; gap: 14px; }
.admin-form label { display: grid; gap: 6px; font-weight: 700; font-size: 15px; }
.admin-form input { font: 700 17px var(--body); padding: 10px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; }
.admin-note { color: var(--ink-2); font-size: 14px; }

/* ---------- progress ---------- */
.progress-grid { display: grid; grid-template-columns: 1.05fr 1fr 1fr; gap: 20px; }
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card h3 { font-size: 20px; }
.ring-card { display: grid; grid-template-columns: 130px 1fr; gap: 14px 18px; align-items: center; }
.ring { width: 130px; height: 130px; transform: rotate(-90deg); grid-row: 1; }
.ring circle { fill: none; stroke-width: 12; }
.ring-bg { stroke: var(--paper-2); }
.ring-fg { stroke: var(--orange); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .6s; }
.ring-text b { display: block; font: 800 38px var(--head); }
.ring-text span { color: var(--ink-2); font-size: 14px; }
.kpis { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.kpis div { background: var(--paper); border-radius: 12px; padding: 8px; text-align: center; }
.kpis dt { font-size: 12px; color: var(--ink-2); }
.kpis dd { margin: 0; font: 800 20px var(--head); }
.level { grid-column: 1 / -1; margin: 0; font-weight: 800; color: var(--plum); }
.skills, .quests { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.skill-row { display: flex; justify-content: space-between; font-size: 15px; font-weight: 700; }
.skill-row span { color: var(--ink-2); font-weight: 600; }
.bar { height: 10px; border-radius: 99px; background: var(--paper-2); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), #f5b13d); border-radius: 99px; transition: width .6s; }
.quests li { display: flex; align-items: center; gap: 12px; }
.badge { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: #eee5dc; filter: grayscale(1); opacity: .6; }
.badge.on { background: radial-gradient(circle at 35% 30%, #ffe08a, #f0a92a); filter: none; opacity: 1; border: 2px solid var(--ink); }
.quests b { display: block; font-size: 15px; }
.quests small { color: var(--ink-2); }
.quests .btn { margin-left: auto; }
.reset-row { text-align: right; margin: 12px 0 0; }

/* ---------- unlock ---------- */
.unlock-body { display: grid; gap: 18px; }
.gz-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.gz-step { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.gz-step h3 { font-size: 19px; margin: 0; }
.gz-step p { margin: 0; color: var(--ink-2); font-size: 15px; }
.gz-step .btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 6px; }
.gz-step.done { border-color: var(--green); background: var(--green-l); }
.gz-step .num { font: 800 14px var(--head); color: var(--orange-d); text-transform: uppercase; letter-spacing: .05em; }
.promo-form { display: flex; gap: 8px; flex-wrap: wrap; }
.promo-form input {
  flex: 1 1 160px; min-width: 0; font: 700 16px var(--body); letter-spacing: .06em; text-transform: uppercase;
  padding: 12px 14px; border: 2px solid var(--ink); border-radius: 12px; background: var(--paper);
}
.promo-msg { font-size: 14px; min-height: 1.4em; margin: 0; }
.promo-msg.err { color: var(--red); }
.promo-msg.ok { color: var(--green); }
.open-banner { background: var(--green-l); border: 2px solid var(--green); border-radius: var(--radius); padding: 22px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.open-banner p { margin: 0; flex: 1 1 260px; }

/* ---------- modals ---------- */
.modal {
  border: 3px solid var(--ink); border-radius: 22px; padding: 28px; width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 32px); overflow: auto; background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(42, 28, 19, .55); }
.modal-x { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 30px; line-height: 1; cursor: pointer; color: var(--ink-2); }
.modal .gz-steps { grid-template-columns: 1fr; }
.modal-quest { width: min(620px, calc(100vw - 24px)); }
.q-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.q-head .badge { width: 54px; height: 54px; font-size: 28px; }
.q-progress { display: flex; gap: 6px; margin: 14px 0 18px; }
.q-progress i { flex: 1; height: 6px; border-radius: 99px; background: var(--line); }
.q-progress i.on { background: var(--orange); }
.q-text { font: 700 20px var(--head); margin: 0 0 14px; }
.q-opts { display: grid; gap: 10px; }
.q-opt {
  text-align: left; font: 700 16px var(--body); padding: 14px 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); cursor: pointer; color: var(--ink);
}
.q-opt:hover:not(:disabled) { border-color: var(--orange); }
.q-opt.right { border-color: var(--green); background: var(--green-l); }
.q-opt.wrong { border-color: var(--red); background: #fbe7e4; }
.q-opt:disabled { cursor: default; }
.q-explain { margin: 14px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--plum-l); font-size: 15px; }
.q-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.q-result { text-align: center; }
.q-result .big { font: 800 56px var(--head); color: var(--plum); margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700; transition: .25s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { text-align: center; color: var(--ink-2); font-size: 14px; padding: 30px 16px 40px; border-top: 1px solid var(--line); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .cover { grid-template-columns: 1fr; gap: 28px; }
  .cover-art { max-width: 340px; margin: 0 auto; width: 100%; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .progress-grid { grid-template-columns: 1fr; }
  .gz-steps { grid-template-columns: 1fr; }
  .game-card { grid-template-columns: 1fr; padding: 24px; }
  .game-shot { order: -1; }
}
@media (max-width: 600px) {
  section { padding: 36px 16px; }
  .topbar { gap: 10px; padding: 10px 16px; }
  .topnav { display: none; }
  .access-pill { margin-left: auto; }
  .steps { grid-template-columns: 1fr; }
  .ring-card { grid-template-columns: 100px 1fr; }
  .ring { width: 100px; height: 100px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 22px 18px; }
  .cm-stage { padding: 10px 8px; }
  .viewer-next { min-width: 0; flex: none; }
  .cover h1 { font-size: 32px; }
  .btn-xl { width: 100%; }
  .game-card { padding: 18px; border-radius: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ---------- уровни, опыт, буквы ответов (общие для всех дизайнов) ---------- */
.q-opt { display: flex; align-items: center; gap: 14px; }
.q-let { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-weight: 900; font-size: 15px; color: #1d1430; }
.q-let-0 { background: #ffe14d; } .q-let-1 { background: #ff2fae; color: #fff; } .q-let-2 { background: #a76bff; color: #fff; } .q-let-3 { background: #5aa9ff; }
.q-opt.right .q-let { background: var(--green); color: #fff; }
.q-opt.wrong .q-let { background: var(--red); color: #fff; }
.q-kicker { font-weight: 700; color: var(--ink-2); }
.q-title { margin: 0; }
.q-xp { display: grid; gap: 10px; margin: 16px auto 6px; max-width: 420px; text-align: left; }
.q-xp-gain { justify-self: center; font: 800 18px var(--head); color: var(--green); background: var(--green-l); padding: 6px 14px; border-radius: 999px; animation: xp-in .5s ease-out; }
.q-xp-gain.is-muted { color: var(--ink-2); background: var(--paper-2); font-size: 14px; }
.q-xp-up { justify-self: center; font: 800 17px var(--head); color: var(--plum); }
.lvl { display: grid; gap: 6px; }
.lvl-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 15px; }
.lvl-head span { color: var(--ink-2); font-weight: 700; font-size: 14px; }
.lvl-bar { height: 14px; border-radius: 99px; background: var(--paper-2); overflow: hidden; box-shadow: inset 0 2px 3px #0002; }
.lvl-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--orange), #ffd23f); transition: width .9s cubic-bezier(.2, .8, .2, 1); }
.lvl small { color: var(--ink-2); font-weight: 600; }
.level .lvl { margin-top: 4px; }
/* в читалке */
.cm-level { display: flex; align-items: center; gap: 8px; background: #3d2b1e; padding: 6px 12px; border-radius: 999px; color: #ffd58f; font-size: 13px; white-space: nowrap; }
.cm-level b { font-weight: 800; }
.cm-level small { color: #d9c4b0; font-weight: 700; }
.cm-lbar { width: 90px; height: 8px; border-radius: 99px; background: #00000055; overflow: hidden; }
.cm-lbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange), #ffd23f); transition: width .6s; }
@media (max-width: 600px) { .cm-level small { display: none; } .cm-lbar { width: 54px; } }
.xp-pop { position: absolute; left: 50%; top: 74px; z-index: 5; transform: translateX(-50%); background: #ffd23f; color: #2a1d14; font: 800 16px var(--head);
  padding: 8px 16px; border-radius: 999px; box-shadow: 0 8px 20px #0006; pointer-events: none; animation: xp-pop 1.6s ease-out forwards; white-space: nowrap; }
@keyframes xp-pop { 0% { opacity: 0; transform: translate(-50%, 14px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -26px); } }
@keyframes xp-in { from { transform: scale(.6); opacity: 0; } }
/* окно «Новый уровень» */
.modal-level { width: min(440px, calc(100vw - 24px)); text-align: center; overflow: hidden; }
.lvl-up { position: relative; }
.lvl-burst { position: absolute; inset: -30px 0 auto; font-size: 120px; opacity: .14; animation: lvl-spin 6s linear infinite; pointer-events: none; }
@keyframes lvl-spin { to { transform: rotate(360deg); } }
.lvl-icon { position: relative; width: 96px; height: 96px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; font-size: 52px;
  background: radial-gradient(circle at 35% 30%, #ffe08a, #f0a92a); border: 3px solid var(--ink); animation: lvl-pop .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes lvl-pop { from { transform: scale(.2); } }
.lvl-kicker { margin: 0; font: 800 14px var(--head); letter-spacing: .1em; text-transform: uppercase; color: var(--orange-d); }
.modal-level h2 { margin: 4px 0 16px; }
.modal-level .lvl { text-align: left; }
