:root {
  --bg: #fff6fa;
  --paper: #ffffff;
  --ink: #3b2a4a;
  --ink-soft: #6f5d7e;
  --pink: #ff4f93;
  --pink-soft: #ffe0ec;
  --lilac: #ece4ff;
  --lilac-deep: #7a5cd6;
  --mint: #d8f5e6;
  --mint-deep: #1f8a55;
  --rose: #ffe3e3;
  --rose-deep: #c43b3b;
  --steel: #cfd8e6;
  --gold: #c9a24b;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 0 rgba(59, 42, 74, .06), 0 10px 30px -12px rgba(122, 92, 214, .28);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, var(--lilac), transparent 60%),
    radial-gradient(900px 400px at -10% 110%, var(--pink-soft), transparent 60%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
}

code, pre, textarea, .kbd { font-family: var(--mono); }
code { background: var(--lilac); padding: .08em .38em; border-radius: 6px; font-size: .92em; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px clamp(16px, 3vw, 32px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center; font-size: 22px;
  background: var(--paper); border-radius: 14px; box-shadow: var(--shadow);
}
h1 { font-size: clamp(1.05rem, .9rem + .8vw, 1.4rem); margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--ink-soft); font-size: .85rem; }
.score {
  display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 1.05rem;
  background: var(--paper); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.fish { display: inline-block; }
.score.bump .fish { animation: bump .6s var(--ease); }
@keyframes bump { 40% { transform: scale(1.5) rotate(-15deg); } }

/* ---------- layout ---------- */
.layout {
  display: grid; gap: 20px;
  grid-template-columns: 240px minmax(0, 1fr) 280px;
  padding: 0 clamp(16px, 3vw, 32px) 40px;
  max-width: 1440px; margin: 0 auto; align-items: start;
}
.card {
  background: var(--paper); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 20px 22px;
}
.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- map ---------- */
.map { position: sticky; top: 16px; }
.map-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); margin: 4px 0 10px 6px; }
.level-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.level-list button {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: var(--ink); font: inherit; font-size: .92rem;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background .15s var(--ease), transform .15s var(--ease);
}
.level-list button:hover { background: rgba(255, 255, 255, .7); }
.level-list button[aria-current="step"] { background: var(--paper); box-shadow: var(--shadow); font-weight: 700; }
.dot {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: .72rem; font-weight: 800; background: var(--lilac); color: var(--lilac-deep);
}
.done .dot { background: var(--mint); color: var(--mint-deep); }
.sandbox-btn { margin-top: 12px; width: 100%; }

/* ---------- hero ---------- */
.hero { display: flex; align-items: flex-end; gap: 14px; }
.kitten { width: clamp(110px, 16vw, 168px); flex: none; filter: drop-shadow(0 10px 14px rgba(122, 92, 214, .25)); overflow: visible; }
.kitten .eyes-happy, .kitten .eyes-sad { opacity: 0; }
.kitten.happy .eyes-normal, .kitten.sad .eyes-normal { opacity: 0; }
.kitten.happy .eyes-happy, .kitten.sad .eyes-sad { opacity: 1; }
.kitten .head { transform-origin: 96px 120px; animation: idle 4s ease-in-out infinite; }
.kitten .tail { transform-origin: 58px 182px; animation: tail 2.4s ease-in-out infinite; }
.kitten .sword { transform-origin: 157px 186px; }
.kitten.happy .sword { animation: raise .9s var(--ease); }
.kitten.happy { animation: hop .6s var(--ease); }
.kitten.sad { animation: shake .45s var(--ease); }
@keyframes idle { 50% { transform: rotate(-3deg); } }
@keyframes tail { 50% { transform: rotate(10deg); } }
@keyframes hop { 40% { transform: translateY(-14px); } }
@keyframes raise { 40% { transform: rotate(-24deg); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.bubble {
  position: relative; flex: 1; background: var(--paper); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 30px; font-size: 1rem;
}
.bubble::before {
  content: ""; position: absolute; left: -10px; bottom: 22px; width: 22px; height: 22px;
  background: var(--paper); transform: rotate(45deg); border-radius: 4px;
}
.bubble.pop { animation: pop .35s var(--ease); }
@keyframes pop { from { transform: scale(.96); opacity: .4; } }

/* ---------- quest ---------- */
.chapter { margin: 0; color: var(--lilac-deep); font-weight: 700; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; }
.quest h2 { margin: 2px 0 8px; font-size: clamp(1.3rem, 1.1rem + .8vw, 1.7rem); letter-spacing: -.01em; }
.task { margin: 0 0 12px; font-size: 1.04rem; }
.scroll { background: #fffaf0; border: 1px dashed #ecd9a8; border-radius: var(--radius-md); padding: 10px 14px; }
.scroll summary { cursor: pointer; font-weight: 700; }
.scroll p { margin: 8px 0; }
.example {
  margin: 8px 0; padding: 10px 12px; background: var(--ink); color: #f6eefe; border-radius: var(--radius-sm);
  overflow-x: auto; font-size: .88rem; white-space: pre-wrap;
}

/* ---------- editor ---------- */
.editor-label { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 8px; gap: 8px; }
.kbd { font-size: .72rem; font-weight: 500; color: var(--ink-soft); background: var(--lilac); padding: 2px 8px; border-radius: 6px; }
.editor {
  width: 100%; min-height: 120px; resize: vertical; padding: 14px; font-size: 1rem; line-height: 1.5;
  border-radius: var(--radius-md); border: 2px solid var(--lilac); background: #fdfbff; color: var(--ink);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.editor:focus { outline: none; border-color: var(--lilac-deep); box-shadow: 0 0 0 4px rgba(122, 92, 214, .15); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button { font: inherit; }
.primary, .ghost, .next {
  border: 0; cursor: pointer; border-radius: 12px; padding: 10px 16px; font-weight: 700; font-size: .95rem;
  transition: transform .12s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
  min-height: 44px;
}
.primary { background: var(--pink); color: #fff; box-shadow: 0 6px 16px -6px rgba(255, 79, 147, .7); }
.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 20px -8px rgba(255, 79, 147, .8); }
.ghost { background: var(--lilac); color: var(--lilac-deep); }
.ghost:hover { background: #e2d7ff; }
.ghost.small { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.next { background: var(--mint-deep); color: #fff; margin-left: auto; }
.primary:active, .ghost:active, .next:active { transform: translateY(1px) scale(.98); }
:focus-visible { outline: 3px solid var(--lilac-deep); outline-offset: 2px; }
.hint { margin-top: 12px; padding: 10px 14px; background: #fff8e1; border-radius: var(--radius-sm); white-space: pre-wrap; font-family: var(--mono); font-size: .9rem; }
.reveal { margin-top: 8px; }

/* ---------- results ---------- */
.feedback { padding: 12px 14px; border-radius: var(--radius-md); font-weight: 600; }
.feedback.ok { background: var(--mint); color: var(--mint-deep); }
.feedback.bad { background: var(--rose); color: var(--rose-deep); }
.feedback.info { background: var(--lilac); color: var(--lilac-deep); }
.feedback:empty { display: none; }
.results { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--lilac); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 8px 12px; text-align: left; white-space: nowrap; }
th { background: var(--lilac); color: var(--lilac-deep); font-family: var(--mono); font-size: .8rem; position: sticky; top: 0; }
tbody tr:nth-child(even) { background: #fbf8ff; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); font-size: .88rem; margin: 0; }

/* ---------- schema ---------- */
.schema { position: sticky; top: 16px; padding: 14px 16px; }
.schema summary { cursor: pointer; font-weight: 700; }
.tbl { margin-top: 12px; }
.tbl h3 { margin: 0 0 4px; font-family: var(--mono); font-size: .92rem; color: var(--pink); }
.tbl ul { list-style: none; margin: 0; padding: 0; font-family: var(--mono); font-size: .8rem; }
.tbl li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px dotted #eee; }
.tbl li span:last-child { color: var(--ink-soft); }
.tbl-desc { margin: 0 0 4px; font-size: .78rem; color: var(--ink-soft); }

/* ---------- injection ---------- */
.tower { display: flex; flex-direction: column; gap: 10px; }
.tower-head { font-weight: 800; background: #2d2338; color: #ffd27a; padding: 10px 14px; border-radius: var(--radius-md); }
.tower label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .9rem; }
.tower input {
  font-family: var(--mono); font-size: 1rem; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 2px solid var(--lilac); min-height: 44px;
}
.tower input:focus { outline: none; border-color: var(--lilac-deep); }
.code-caption { margin: 4px 0 0; color: var(--ink-soft); font-size: .85rem; }
.live-sql { margin: 0; padding: 12px; background: var(--ink); color: #f6eefe; border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-word; font-size: .88rem; }
.live-sql .inj { background: #ff4f93; color: #fff; border-radius: 3px; }

/* ---------- quiz ---------- */
.quiz { display: grid; gap: 10px; }
.quiz button {
  text-align: left; border: 2px solid var(--lilac); background: #fdfbff; border-radius: var(--radius-md);
  padding: 12px 14px; cursor: pointer; color: var(--ink); transition: border-color .15s var(--ease), transform .12s var(--ease);
}
.quiz button:hover { border-color: var(--lilac-deep); }
.quiz pre { margin: 0; font-size: .84rem; white-space: pre-wrap; word-break: break-word; }
.quiz .why { display: block; margin-top: 8px; font-family: var(--font); font-size: .9rem; }
.quiz button.right { border-color: var(--mint-deep); background: var(--mint); }
.quiz button.wrong { border-color: var(--rose-deep); background: var(--rose); }

/* ---------- finale ---------- */
.finale { position: relative; overflow: hidden; text-align: center; background: linear-gradient(160deg, #fff, var(--pink-soft)); }
.finale h2 { font-size: clamp(1.4rem, 1.1rem + 1.4vw, 2.1rem); margin-top: 0; }
.confetti { position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(circle, var(--pink) 3px, transparent 4px),
    radial-gradient(circle, var(--lilac-deep) 3px, transparent 4px),
    radial-gradient(circle, var(--gold) 3px, transparent 4px);
  background-size: 90px 90px, 120px 120px, 70px 70px;
  background-position: 0 0, 40px 60px, 20px 30px;
  opacity: .35; animation: fall 6s linear infinite; }
@keyframes fall { to { background-position: 0 360px, 40px 540px, 20px 310px; } }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .schema { grid-column: 2; position: static; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .map { position: static; }
  .map-title { display: none; }
  .level-list { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 6px; scroll-snap-type: x mandatory; }
  .level-list li { flex: none; scroll-snap-align: start; }
  .level-list button { white-space: nowrap; background: rgba(255, 255, 255, .6); }
  .level-list .lbl { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
  .schema { grid-column: 1; order: 3; }
  .sandbox-btn { margin-top: 6px; }
  .hero { align-items: flex-start; }
  .bubble { margin-bottom: 0; font-size: .95rem; }
  .bubble::before { bottom: auto; top: 26px; }
  .card { padding: 16px; }
  .sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ================= v2: персонажи, уроки, разбор ================= */
.top-right { display: flex; align-items: center; gap: 10px; }

/* реплика с говорящим */
.bubble p { margin: 0; }
.speaker { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.speaker[hidden] { display: none; }
.speaker b { font-size: .92rem; }
.speaker .role { font-size: .78rem; color: var(--ink-soft); }
.avatar { width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center; background: var(--lilac); border-radius: 50%; overflow: visible; }
.avatar svg { width: 34px; height: 34px; overflow: visible; }
.avatar-lg { width: 52px; height: 52px; background: #fff; }
.avatar-lg svg { width: 44px; height: 44px; }
.avatar-xl { width: 96px; height: 96px; }
.avatar-xl svg { width: 80px; height: 80px; }

/* меч: картон → Когтемеч */
.kitten .cape { transform-origin: 92px 160px; animation: cape 3s ease-in-out infinite; }
@keyframes cape { 50% { transform: skewX(-4deg); } }
.kitten.legendary .blade { fill: #eef3fb; stroke: #8a97b0; }
.kitten.legendary .cardboard { display: none; }
.kitten.legendary .sword { filter: drop-shadow(0 0 6px #ffe27a) drop-shadow(0 0 12px rgba(255, 226, 122, .6)); }

/* урок */
.lesson { display: grid; gap: 10px; margin: 6px 0 14px; }
.lesson[hidden] { display: none; }
.lesson p { margin: 0; }
.lesson-what { font-size: 1.04rem; }
.lesson-analogy { background: #fff8e6; border-radius: var(--radius-md); padding: 10px 14px; }
.lesson-example { background: #faf7ff; border: 1px solid var(--lilac); border-radius: var(--radius-md); padding: 12px; display: grid; gap: 10px; }
.lesson-example[hidden] { display: none; }
.lesson-example .example { margin: 0; }
.read { margin: 0; display: grid; gap: 4px; }
.read-row { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: 12px; align-items: baseline; }
.read dt { font-family: var(--mono); font-size: .85rem; color: var(--lilac-deep); font-weight: 700; }
.read dd { margin: 0; font-size: .92rem; }
.lesson-note { font-size: .92rem; color: #8a5a00; }
.lesson-note[hidden] { display: none; }
.lesson-why { font-size: .9rem; color: var(--ink-soft); }
.task-box { border-top: 2px dashed var(--pink-soft); padding-top: 12px; }
.task-label { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--pink); }
.task-box .task { margin: 4px 0 0; }

/* символы */
.symbols { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sym { font-family: var(--mono); font-size: .9rem; min-width: 40px; min-height: 36px; padding: 4px 10px; border-radius: 9px; border: 1px solid var(--lilac); background: #fff; color: var(--ink); cursor: pointer; }
.sym:hover { border-color: var(--lilac-deep); }
.sym.kw { color: var(--lilac-deep); font-weight: 700; font-size: .8rem; }

/* подсказка мага */
.hint { display: flex; gap: 10px; align-items: flex-start; font-family: var(--font); white-space: normal; }
.hint-body { min-width: 0; }
.hint-body b { display: block; font-size: .82rem; color: #8a5a00; margin-bottom: 2px; }
.hint-body p { margin: 0; }
.hint-body pre { margin: 0; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; font-size: .9rem; }

/* обратная связь */
.feedback { display: flex; gap: 12px; align-items: flex-start; }
.feedback .fb-text { display: grid; gap: 4px; min-width: 0; }
.fb-title { font-size: 1.02rem; }
.feedback.err { background: #fff1e6; color: #7a3b12; }
.feedback .raw { font-weight: 400; font-size: .82rem; }
.feedback .raw summary { cursor: pointer; opacity: .8; }
.feedback .raw code { display: block; margin-top: 4px; background: rgba(255, 255, 255, .7); word-break: break-word; }
.steps { margin-top: 12px; background: #faf7ff; border-radius: var(--radius-md); padding: 12px 16px; }
.steps[hidden] { display: none; }
.steps-title { margin: 0 0 6px; font-weight: 800; }
.steps ol { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
.steps-note { margin: 8px 0 0; font-size: .85rem; color: var(--ink-soft); }

/* карта по главам */
.map-chapter { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 10px 0 2px 10px; }
.map-chapter:first-child { margin-top: 0; }

/* схема: кликабельные имена */
.schema-tip { margin: 8px 0 0; font-size: .78rem; color: var(--ink-soft); }
.tbl-name, .col { font: inherit; border: 0; background: none; padding: 0; cursor: pointer; text-align: left; }
.tbl-name { font-family: var(--mono); font-size: .92rem; font-weight: 700; color: var(--pink); }
.col { font-family: var(--mono); font-size: .8rem; color: var(--ink); }
.tbl-name:hover, .col:hover { text-decoration: underline; }

/* вступление */
.intro { position: fixed; inset: 0; background: rgba(46, 33, 64, .45); display: grid; place-items: center; padding: 16px; z-index: 10; backdrop-filter: blur(3px); }
.intro[hidden] { display: none; }
.intro-card { background: #fff; border-radius: 24px; padding: 24px; max-width: 480px; width: 100%; text-align: center; box-shadow: 0 30px 60px -20px rgba(46, 33, 64, .5); animation: pop .3s var(--ease); }
.intro-card h2 { margin: 10px 0 6px; }
.intro-card p { margin: 0 0 12px; }
.intro-card .table-wrap { text-align: left; margin-bottom: 12px; }
.intro-card .actions { justify-content: space-between; }
.intro-dots { display: flex; justify-content: center; gap: 6px; }
.intro-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--lilac); }
.intro-dots span.on { background: var(--pink); }

@media (max-width: 820px) {
  .map-chapter { display: none; }
  .read-row { grid-template-columns: minmax(0, 46%) 1fr; gap: 8px; }
  .read dt { word-break: break-word; }
  .top-right .ghost.small { padding: 6px 10px; font-size: .78rem; min-height: 36px; }
}

.hint[hidden], .feedback:empty { display: none; }

/* ===== v3: итог в карточке, пример под примером ===== */
.win-line { display: flex; gap: 12px; align-items: flex-start; margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-md); background: #fff7fb; border: 1px solid var(--pink-soft); }
.win-line[hidden] { display: none; }
.win-text b { font-size: .85rem; color: var(--pink); }
.win-text p { margin: 2px 0 0; }
.win-text .next { margin: 10px 0 0; }
@media (max-width: 820px) { .speaker .role { display: none; } }
.example-out { display: grid; gap: 8px; }
.example-out[hidden] { display: none; }
.example-out .muted { margin: 0; }
.read-box summary { cursor: pointer; font-weight: 700; font-size: .9rem; color: var(--lilac-deep); }
.read-box[open] summary { margin-bottom: 8px; }
.read-box[hidden] { display: none; }
.read-box .lesson-why { margin: 8px 0 0; }
