[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }

body.young {
  --paper: #EEF0F7; --surface: #FFFFFF; --ink: #1F1D47; --muted: #5F5E80; --line: #D9DBEA;
  --ok: #00A95C; --ok-text: #00703F; --ok-soft: #DDF3E7; --bad: #E2435A; --bad-text: #B4233B; --bad-soft: #FBE3E7;
  --field-line: #8688A8; --btn: #1F1D47; --btn-text: #FFFFFF;
  --fs: 1.25rem; --r: 16px;
}
body.teen {
  --paper: #1F1D47; --surface: #2A2862; --ink: #F1EFFA; --muted: #A9A6CF; --line: #3D3A7C;
  --ok: #5BE38F; --ok-text: #5BE38F; --ok-soft: #1F4A4A; --bad: #FF7A8A; --bad-text: #FF8E9B; --bad-soft: #4A2850;
  --field-line: #7D7ABE; --btn: #F1EFFA; --btn-text: #1F1D47;
  --fs: 1.0625rem; --r: 12px;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--paper); color: var(--ink);
  font-family: 'Jost', 'Futura', 'Century Gothic', system-ui, -apple-system, sans-serif;
  font-size: var(--fs); line-height: 1.45; font-weight: 400;
  font-feature-settings: 'tnum' 0; overflow-x: hidden;
}
#app { display: block; max-width: 600px; margin: 0 auto; padding: 14px 18px 48px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; line-height: 1.05; }
h1 { font-size: 2.3em; }
h2 { font-size: 1.6em; }
h3 { font-size: 1.05em; letter-spacing: 0; }
p { margin: 0; }
svg { display: block; }
.ic { flex: none; }

button, .btn {
  font: inherit; color: inherit; cursor: pointer; min-height: 48px; min-width: 48px;
  border: 0; border-radius: var(--r); padding: 10px 18px; background: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:focus-visible, .btn:focus-visible, input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
button:disabled { cursor: default; }
.primary { background: var(--btn); color: var(--btn-text); font-weight: 500; min-height: 58px; font-size: 1.02em; transition: transform .1s; }
.primary:active { transform: scale(.98); }
.secondary { border: 2px solid var(--line); font-weight: 500; }
.quiet { color: var(--muted); font-weight: 500; }
.wide { width: 100%; }

/* Шапка */
.topbar { display: flex; align-items: center; gap: 6px; margin: 0 -8px 18px; min-height: 48px; }
.topbar .spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 10px; font-weight: 500; min-width: 0; padding: 0 8px; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool { color: var(--ink); }

/* Старт */
.start { display: grid; gap: 22px; padding-top: 2vh; }
.start .art { width: 160px; height: 160px; }
.start .plot { color: var(--muted); font-size: 1.05em; max-width: 30ch; }
.field { display: grid; gap: 8px; }
.label { font-weight: 500; font-size: .9em; color: var(--muted); }
.text-input {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 2px solid var(--field-line); border-radius: var(--r); padding: 12px 16px; min-height: 56px;
}
.text-input::placeholder { color: var(--muted); opacity: 1; }
.text-input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.order-answer.wrong { border-color: var(--bad); }
.text-input:focus { border-color: var(--ink); outline: none; }
.heroes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.heroes button { background: var(--surface); border: 2px solid transparent; padding: 10px; aspect-ratio: 1; }
.heroes button svg { width: 100%; height: auto; max-width: 56px; }
.heroes button[aria-pressed="true"] { border-color: var(--ink); }

/* Вступление */
.intro { display: grid; gap: 22px; padding-top: 4vh; }
.intro .lines { display: grid; gap: 12px; font-size: 1.15em; max-width: 34ch; }
.intro .lines p { opacity: 0; animation: rise .6s forwards; }
.intro .row { display: flex; gap: 10px; }

/* Карта */
.map-title { display: grid; gap: 16px; margin-bottom: 22px; }
.collection { display: flex; gap: 8px; align-items: center; }
.collection .slot { width: 44px; height: 44px; border-radius: 12px; border: 2px dashed var(--line); display: grid; place-items: center; }
.collection .slot.got { border: 2px solid transparent; background: var(--surface); }
.collection .count { margin-left: 6px; color: var(--muted); font-size: .9em; font-variant-numeric: tabular-nums; }
.route { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; position: relative; }
.route::before { content: ''; position: absolute; left: 36px; top: 30px; bottom: 30px; border-left: 2px dashed var(--line); }
.stop {
  position: relative; width: 100%; text-align: left; justify-content: flex-start; gap: 16px;
  background: var(--surface); padding: 10px 14px 10px 10px; border: 2px solid transparent;
}
.stop .thumb { width: 54px; height: 54px; flex: none; border-radius: 10px; background: var(--paper); display: grid; place-items: center; overflow: hidden; }
.stop .thumb svg { width: 76%; height: 76%; }
.stop .txt { display: grid; gap: 1px; min-width: 0; flex: 1; }
.stop .t { font-weight: 600; font-size: 1.02em; line-height: 1.2; }
.stop .s { color: var(--muted); font-size: .82em; }
.stop .state { flex: none; color: var(--muted); }
.stop.open { border-color: var(--ink); }
.stop.done .state { color: var(--ok-text); }
.stop.locked { background: var(--paper); border: 2px dashed var(--line); }
.stop.locked .thumb { filter: grayscale(1); opacity: .35; }
body.teen .stop.locked .thumb { opacity: .6; }
body.teen .stop.locked .t, body.teen .stop.locked .s { opacity: .8; }
.stop.locked .t, .stop.locked .s { opacity: .8; }
.stop.locked .t, .stop.locked .s { opacity: .55; }
.stop .here { position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; }

/* Задание */
.task-head { display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 14px; margin-bottom: 14px; }
.counter { font-weight: 700; font-size: 4.2em; line-height: .8; letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.counter small { font-size: .32em; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.task-head .about { display: grid; gap: 2px; min-width: 0; padding-bottom: 2px; }
.task-head .lvl { font-weight: 600; line-height: 1.15; }
.task-head .skill { color: var(--muted); font-size: .82em; }
.task-head .scene svg { width: 64px; height: 64px; }
.steps { display: flex; gap: 4px; margin-bottom: 18px; }
.steps i { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps i.done { background: var(--ink); }
.steps i.now { background: var(--ink); opacity: .45; height: 10px; margin-top: -2px; }
.streak { color: var(--muted); font-size: .85em; font-weight: 500; min-height: 1.4em; margin: -8px 0 10px; }
.streak b { color: var(--ink); font-weight: 600; }
.story { color: var(--muted); font-size: .95em; margin-bottom: 16px; max-width: 40ch; }

.task { display: grid; gap: 18px; }
.prompt-row { display: flex; gap: 8px; align-items: flex-start; }
.prompt { flex: 1; font-size: 1.22em; font-weight: 500; line-height: 1.35; }
.listen { color: var(--ink); margin: -8px -10px 0 0; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.options.long { grid-template-columns: 1fr; }
.opt {
  background: var(--surface); border: 2px solid var(--line); font-weight: 500; font-size: 1.05em;
  min-height: 64px; padding: 12px; text-align: center; overflow-wrap: anywhere; line-height: 1.2;
}
.options.long .opt { justify-content: flex-start; text-align: left; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad-text); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok-text); }
.tf { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tf .opt { min-height: 88px; font-size: 1.15em; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: grid; gap: 10px; align-content: start; }
.match .opt { min-height: 56px; font-size: 1em; }
.match .opt.sel { border-color: var(--ink); }
.match .opt.paired { color: var(--ink); border-style: solid; }
.match .opt.paired::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--pc); flex: none; }

.order-answer {
  min-height: 72px; display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; padding: 10px;
  border-bottom: 2px solid var(--ink);
}
.order-answer:empty::before { content: attr(data-empty); color: var(--muted); font-size: .9em; align-self: center; }
.order-bank { display: flex; flex-wrap: wrap; gap: 8px; }
.tile { background: var(--surface); border: 2px solid var(--line); font-weight: 500; padding: 8px 16px; font-size: 1.05em; }
.order-answer .tile { border-color: var(--ink); }

.input-row { display: flex; gap: 8px; }
.input-row .text-input { flex: 1; min-width: 0; font-size: 1.15em; }
.input-row .primary { min-height: 56px; }

.feedback { padding: 14px 16px; border-radius: var(--r); display: grid; gap: 4px; border-left: 0; }
.feedback .head { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.feedback.ok { background: var(--ok-soft); }
.feedback.ok .head { color: var(--ok-text); }
.feedback.bad { background: var(--bad-soft); }
.feedback.bad .head { color: var(--bad-text); }
.feedback.info { background: var(--surface); border: 2px solid var(--line); }
.help-row { display: flex; gap: 8px; flex-wrap: wrap; }

.teacher-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 8px 10px; margin-bottom: 16px; border-radius: 12px; background: #FFF2B3; color: #3D3300; font-size: .9375rem; }
.teacher-bar strong { font-weight: 600; margin-right: 4px; }
.teacher-bar button { min-height: 44px; padding: 4px 12px; font-size: .9375rem; background: #fff; color: #3D3300; font-weight: 500; border-radius: 8px; }

/* Финал */
.vault { display: flex; gap: 8px; margin-bottom: 18px; }
.vault span { flex: 1; height: 54px; border-radius: 12px; border: 2px dashed var(--line); display: grid; place-items: center; }
.vault span.on { border: 2px solid transparent; background: var(--surface); }
.vault span svg { width: 30px; height: 30px; }

.finale { display: grid; gap: 18px; padding-top: 3vh; }
.finale .mosaic { width: min(260px, 70vw); height: auto; }
.finale .mosaic .piece { transform-box: fill-box; transform-origin: center; animation: drop .7s calc(var(--i) * .22s) both cubic-bezier(.2, 1.4, .4, 1); }

/* Итоги */
.results { display: grid; gap: 22px; }
.skills { display: grid; }
.skill-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 2px solid var(--line); }
.skill-row:last-child { border-bottom: 0; }
.score { display: flex; gap: 5px; flex: none; }
.score i { width: .7em; height: .7em; border-radius: 50%; border: 2px solid var(--ink); }
.score i.on { background: var(--ink); }
.review { display: grid; }
.review-item { display: grid; gap: 4px; padding: 12px 0; border-bottom: 2px solid var(--line); }
.review-item:last-child { border-bottom: 0; }
.review-item .q { font-weight: 500; }
.review-item .a { color: var(--ok-text); font-weight: 600; }
.review-item .n { color: var(--muted); font-size: .85em; }
.share { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.share .wide { grid-column: 1 / -1; }

/* Награда */
.overlay { position: fixed; inset: 0; background: rgba(20, 18, 50, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.award { width: min(420px, 100%); display: grid; gap: 14px; background: var(--surface); color: var(--ink); border-radius: 24px; padding: 28px 24px 20px; justify-items: start; }
.award .badge { position: relative; width: 196px; height: 120px; }
.award .badge svg { position: absolute; }
.award .badge svg:first-child { left: 0; top: 0; width: 120px; height: 120px; }
.award .badge svg:last-child { right: 0; bottom: 0; width: 64px; height: 64px; }
.award .kind { color: var(--muted); font-weight: 500; }
.award .name { font-size: 2.2em; font-weight: 700; letter-spacing: -0.03em; line-height: 1; overflow-wrap: anywhere; }
.award .for { color: var(--muted); font-size: .95em; }

.gain { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 30; }
.gain svg { width: 140px; height: 140px; animation: gain 1.2s forwards; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 15; width: 100%; height: 100%; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--btn); color: var(--btn-text); padding: 12px 18px; border-radius: 12px; font-weight: 500; z-index: 50; max-width: calc(100% - 32px); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.shake { animation: shake .35s; }
.pulse { animation: pulse .35s; }
.enter { animation: rise .35s both; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes pulse { 50% { transform: scale(1.03); } }
@keyframes drop { from { opacity: 0; transform: translateY(-40px) rotate(-40deg) scale(.6); } to { opacity: 1; transform: none; } }
@keyframes gain { 0% { transform: scale(.2) rotate(-90deg); opacity: 0; } 40% { transform: scale(1.1) rotate(10deg); opacity: 1; } 70% { transform: scale(1); opacity: 1; } 100% { transform: translateY(-40vh) scale(.3); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .intro .lines p { opacity: 1; }
}
@media (max-width: 380px) {
  body.young { --fs: 1.125rem; }
  .counter { font-size: 3.6em; }
}

h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }

/* Планшет и компьютер: крупнее и просторнее, задание остаётся в удобной колонке */
@media (min-width: 720px) {
  body.young { --fs: 1.375rem; }
  body.teen { --fs: 1.1875rem; }
  #app { max-width: 720px; padding: 28px 32px 64px; }
  .start { grid-template-columns: 1fr 200px; column-gap: 40px; align-items: start; padding-top: 6vh; }
  .start > .art { grid-column: 2; grid-row: 1 / span 3; width: 200px; height: 200px; }
  .start > .art svg { width: 200px; height: 200px; }
  .start > *:not(.art) { grid-column: 1; }
  .start > .field, .start > .primary, .start > .secondary { grid-column: 1 / -1; }
  .heroes { grid-template-columns: repeat(8, 1fr); }
  .route { gap: 14px; }
  .route::before { left: 40px; }
  .stop { padding: 12px 18px 12px 12px; }
  .stop .thumb { width: 60px; height: 60px; }
  .task-head .scene svg { width: 88px; height: 88px; }
  .options:not(.long) { grid-template-columns: repeat(4, 1fr); }
  .tf .opt { min-height: 110px; }
  .finale { grid-template-columns: auto 1fr; column-gap: 40px; align-items: center; }
  .finale > svg { grid-row: 1 / span 3; }
  .award { width: min(480px, 100%); }
}
@media (min-width: 1100px) {
  #app { max-width: 820px; }
}
@media (hover: hover) {
  .opt:not(:disabled):hover, .tile:hover, .stop:not(:disabled):hover, .heroes button:hover { border-color: var(--ink); }
  .primary:hover { filter: brightness(1.15); }
}

/* Разложи по группам */
.sort-pool { display: flex; flex-wrap: wrap; gap: 8px; min-height: 56px; }
.card-chip { background: var(--surface); border: 2px solid var(--line); font-weight: 500; padding: 8px 14px; font-size: 1.02em; }
.card-chip.sel { border-color: var(--ink); transform: translateY(-2px); }
.card-chip.placed { border-color: transparent; background: var(--paper); padding: 4px 10px; min-height: 44px; font-size: .9em; }
.sort-bins { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.sort-bins.n3 { grid-template-columns: 1fr 1fr 1fr; }
.bin { display: flex; flex-direction: column; gap: 8px; min-height: 120px; padding: 8px; border: 2px dashed var(--bc); border-radius: var(--r); background: color-mix(in srgb, var(--bc) 10%, transparent); text-align: center; cursor: pointer; }
.bin-name { font-weight: 600; line-height: 1.2; width: 100%; min-height: 44px; }
.card-chip.placed { display: inline-block; }
.bin-items { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
@media (max-width: 420px) { .sort-bins.n3 { grid-template-columns: 1fr; } .bin { min-height: 84px; } }

/* Финал: страж */
.boss { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding: 10px 12px; border-radius: var(--r); background: var(--surface); }
.boss svg { flex: none; transform-origin: 50% 90%; width: clamp(72px, 14vw, 120px); height: auto; }
.boss-info { display: grid; gap: 8px; flex: 1; min-width: 0; }
.boss-name { font-weight: 600; line-height: 1.2; }
.boss-hp { display: flex; gap: 4px; }
.boss-hp i { flex: 1; height: 12px; border-radius: 4px; background: var(--ink); transition: background .3s, transform .3s; }
.boss-hp i.gone { background: var(--line); transform: scaleY(.5); }
.bosshit { animation: bosshit .45s; }
.bosstaunt { animation: bosstaunt .5s; }
@keyframes bosshit { 30% { transform: translateX(8px) rotate(6deg) scale(.92); filter: brightness(1.6); } 60% { transform: translateX(-4px) rotate(-3deg); } }
@keyframes bosstaunt { 25% { transform: scale(1.1, .9); } 50% { transform: scale(.95, 1.08); } 75% { transform: scale(1.05, .95); } }
.redo-done { display: flex; gap: 8px; align-items: center; color: var(--ok-text); font-weight: 600; }

/* Формулировки и кнопки не переносим по слогам. Только в узких карточках ответов длинное слово делится с дефисом */
body { overflow-wrap: anywhere; }
.task-head { grid-template-columns: auto minmax(0, 1fr) auto; }
.prompt, .stop .txt, .task-head .about, .boss-info, .skill-row > span:first-child, .intro .lines, .start, .finale, .review-item, .feedback { min-width: 0; }
.skill-row > span:first-child { flex: 1; }
.opt, .card-chip, .bin-name, .match .opt { overflow-wrap: anywhere; -webkit-hyphens: auto; hyphens: auto; min-width: 0; }
.tile { overflow-wrap: anywhere; min-width: 0; }
.primary, .secondary, .quiet { -webkit-hyphens: none; hyphens: none; }
.options, .tf, .match, .sort-bins { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.options.long { grid-template-columns: minmax(0, 1fr); }
.sort-bins.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 420px) { .sort-bins.n3 { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 720px) { .options:not(.long) { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.match .col { min-width: 0; }

/* Итоги: главное сверху, разбор по запросу */
.res-sum { display: grid; gap: 2px; padding: 14px 16px; border-radius: var(--r); background: var(--surface); }
.res-num { font-size: 2.4em; font-weight: 700; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.res-sub { color: var(--muted); font-size: .9em; }
details.review > summary { cursor: pointer; font-weight: 600; min-height: 48px; display: flex; align-items: center; gap: 8px; list-style: none; }
details.review > summary::-webkit-details-marker { display: none; }
details.review > summary::after { content: '+'; margin-left: auto; font-size: 1.4em; color: var(--muted); }
details.review[open] > summary::after { content: '−'; }

.finale .mosaic { overflow: visible; }
.finale h1 { font-size: clamp(1.6em, 9vw, 2.3em); overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
.award .name { overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
.share { grid-template-columns: repeat(auto-fit, minmax(9em, 1fr)); }
.share .btn { overflow-wrap: normal; -webkit-hyphens: none; hyphens: none; }
body.teen :focus-visible { outline-color: var(--accent2); }
@media (max-width: 380px) { .task-head .scene { display: none; } .task-head { grid-template-columns: auto minmax(0, 1fr); } .start .art { width: 96px; height: 96px; } .start .art svg { width: 96px; height: 96px; } .start h1 { font-size: 1.9em; } }
.counter { min-width: 2.2ch; }
@media (min-width: 720px) { .match { max-width: 560px; } .match .opt { min-height: 64px; } .tf { max-width: 480px; } }
.boss-hp { max-width: 360px; }

@media (max-width: 759px) { .counter { font-size: 3.2em; } }
input[type=checkbox] { width: 24px; height: 24px; }
