:root {
  --ground: #e9f3ff;
  --surface: #ffffff;
  --ink: #1d2b4f;
  --accent: #ff7a3d;
  --accent-ink: #ffffff;
  --soft: #d4e6ff;
  --good: #3fae6a;
  --good-bg: #d9f5e3;
  --nudge: #ffe9b8;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --gutter: 20px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 22px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px var(--gutter) 48px;
}

.view { animation: rise 240ms var(--ease-out); }
.view[hidden] { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

h1, h2 { line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 24px; }
h1 { font-size: clamp(34px, 8vw, 56px); }
h2 { font-size: clamp(30px, 7vw, 44px); }

/* кнопки */
button { font: inherit; color: inherit; cursor: pointer; border: 0; touch-action: manipulation; }

.btn {
  min-height: 64px;
  padding: 12px 28px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 22px;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}
.btn-soft { background: var(--soft); color: var(--ink); }
.btn:active, .back:active, .story-card:active, .option:active { transform: scale(0.97); }
.btn:focus-visible, .back:focus-visible, .story-card:focus-visible, .option:focus-visible {
  outline: 4px solid var(--ink);
  outline-offset: 3px;
}

.back {
  white-space: nowrap;
  background: transparent;
  font-weight: 800;
  font-size: 20px;
  min-height: 48px;
  padding: 6px 16px 6px 0;
  transition: transform 160ms var(--ease-out);
}

.row { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; }

/* главная */
.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}
.story-card {
  width: 100%;
  min-height: 120px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  background: var(--surface);
  border-radius: 28px;
  text-align: left;
  font-weight: 800;
  font-size: 26px;
  line-height: 1.15;
  transition: transform 160ms var(--ease-out);
}
.story-card .big { font-size: 56px; line-height: 1; width: 64px; text-align: center; flex: none; }

.sections { display: flex; gap: 10px; margin-bottom: 20px; }
.section {
  flex: 1;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.1;
  border-radius: 22px;
  background: var(--surface);
  font-weight: 800;
  font-size: 22px;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}
.section { font-size: 16px; padding: 8px 2px; }
.section span { font-size: 32px; }
.section.on { background: var(--accent); color: var(--accent-ink); }
.section:active { transform: scale(0.97); }
.section:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }

.visual {
  background: var(--surface);
  border-radius: 28px;
  padding: 20px;
  margin: 8px 0 16px;
  font-size: clamp(40px, 11vw, 64px);
  line-height: 1.3;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.visual { white-space: pre-line; }
.visual.small { font-size: clamp(28px, 8vw, 44px); }

[hidden] { display: none !important; }

.option.hint { outline: 4px solid var(--good); outline-offset: -4px; animation: glow 700ms var(--ease-out) 2; }
@keyframes glow { 50% { background: var(--good-bg); } }

.train-lead { font-size: 22px; margin: 0 0 20px; }
.btn-go { width: 100%; min-height: 84px; font-size: 28px; margin-bottom: 24px; }
.levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.levels li {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: 22px; padding: 14px 18px;
  font-weight: 800; font-size: 20px;
}
.lv-icon { font-size: 30px; width: 40px; text-align: center; flex: none; }
.lv-name { flex: 1; line-height: 1.15; }
.lv-dots { display: flex; gap: 6px; flex: none; }
.lv-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--soft); }
.lv-dots i.on { background: var(--good); }

.story-card .name { flex: 1; }
.story-card .badge { font-size: 32px; flex: none; }
.story-card.is-done { background: var(--good-bg); }

.progress { margin: -8px 0 10px; font-weight: 800; font-size: 24px; }
.bar { height: 14px; border-radius: 999px; background: var(--soft); overflow: hidden; margin-bottom: 20px; }
.bar-fill { height: 100%; background: var(--good); transform-origin: left; transform: scaleX(0); transition: transform 400ms var(--ease-out); }

.tabs { display: flex; gap: 10px; margin-bottom: 18px; }
.tab {
  flex: 1;
  min-height: 56px;
  border-radius: 999px;
  background: var(--soft);
  font-weight: 800;
  font-size: 22px;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}
.tab.on { background: var(--ink); color: #fff; }
.tab:active { transform: scale(0.97); }
.tab:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }

.empty { grid-column: 1 / -1; font-weight: 800; font-size: 26px; padding: 24px 0; }

/* текст рассказа */
.story-text {
  background: var(--surface);
  border-radius: 28px;
  padding: 28px;
  margin: 0 0 24px;
  font-size: clamp(26px, 5.5vw, 34px);
  line-height: 1.5;
  max-width: 28em;
}

/* вопросы */
.quiz-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin-bottom: 8px; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; flex: 1; justify-content: center; }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--soft); transition: background-color 200ms ease; }
.dot.now { background: var(--ink); }
.dot.done { background: var(--good); }
.stars { flex-basis: 100%; min-height: 34px; font-size: 22px; line-height: 1.5; white-space: nowrap; }

.question { margin: 12px 0 16px; }

.options { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 14px; }
.option {
  width: 100%;
  min-height: 88px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  background: var(--surface);
  border-radius: 28px;
  text-align: left;
  font-weight: 800;
  font-size: 28px;
  transition: transform 160ms var(--ease-out), background-color 160ms ease;
}
.option .big { font-size: 48px; line-height: 1; width: 56px; text-align: center; flex: none; }
.option.wrong { background: var(--nudge); animation: shake 320ms var(--ease-out); }
.option.right { background: var(--good-bg); }
.option:disabled { cursor: default; }
.option:disabled:not(.right) { opacity: 0.6; }
.option.right:disabled { opacity: 1; }

@keyframes shake {
  20% { transform: translateX(-8px); }
  45% { transform: translateX(7px); }
  70% { transform: translateX(-4px); }
  100% { transform: none; }
}

.hint { min-height: 2.2em; margin: 20px 0 0; font-weight: 800; font-size: 26px; }

/* финал */
.end { text-align: center; padding-top: 24px; }
.end-emoji { font-size: 96px; line-height: 1; margin-bottom: 12px; animation: pop 420ms var(--ease-out); }
.end-stars { font-size: 48px; margin: 0 0 28px; letter-spacing: 6px; }
.end .row { justify-content: center; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: none; }
}

@media (hover: hover) and (pointer: fine) {
  .story-card:hover, .option:not(:disabled):hover { transform: translateY(-3px); }
  .btn:hover { filter: brightness(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  .view, .end-emoji { animation: none; }
  .option.wrong { animation: none; }
  * { transition-duration: 0ms !important; }
}
