:root {
  --navy: #16244f;
  --navy-2: #22377a;
  --blue: #2f5fd0;
  --sky: #8ec5ff;
  --ice: #e8f3ff;
  --gold: #f4c24f;
  --gold-2: #c98a1c;
  --cream: #fff8ea;
  --parch: #f6ead0;
  --ink: #2b2140;
  --ok: #3aa676;
  --soft-red: #d9806b;
  --shadow: 0 6px 18px rgba(10, 20, 60, .35);
  --r: 18px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--navy); color: var(--ink); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
button { font-family: inherit; }
img { user-select: none; -webkit-user-drag: none; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#world { position: absolute; left: 0; top: 0; width: 1024px; height: 1536px; transform-origin: 0 0; will-change: transform; }
#bg { position: absolute; left: 0; top: 0; width: 1024px; height: 1536px; display: block; }
#world.night #bg { filter: none; }

/* hotspots */
.hot { position: absolute; border-radius: 40px; cursor: pointer; }
.hot .tag {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, 6px);
  background: rgba(22, 36, 79, .82); color: #fff; font-weight: 800; font-size: 26px;
  padding: 6px 16px; border-radius: 999px; white-space: nowrap; border: 2px solid rgba(244, 194, 79, .8);
  pointer-events: none; box-shadow: var(--shadow);
}
.hot.locked .tag { background: rgba(40, 40, 70, .7); border-color: rgba(255,255,255,.35); }
.hot.pulse .tag { animation: tagPulse 1.6s ease-in-out infinite; }
@keyframes tagPulse { 50% { transform: translate(-50%, -2px) scale(1.06); } }

/* actors */
.actor { position: absolute; transform: translate(-50%, -100%); transition: left 1.1s cubic-bezier(.45,.05,.4,1), top 1.1s cubic-bezier(.45,.05,.4,1); }
#vika img { height: 300px; display: block; }
#vika.walk img { animation: bob .32s ease-in-out infinite; }
#vika.flip img { transform: scaleX(-1); }
@keyframes bob { 50% { transform: translateY(-8px) rotate(1deg); } }
#vika.flip.walk img { animation: bobFlip .32s ease-in-out infinite; }
@keyframes bobFlip { 0%,100% { transform: scaleX(-1); } 50% { transform: scaleX(-1) translateY(-8px); } }

#dragon { cursor: pointer; }
#dragon-img { height: 230px; display: block; transform-origin: 50% 100%; animation: breathe 3.2s ease-in-out infinite; }
#dragon.sleep #dragon-img { height: 170px; animation: breatheSlow 4.5s ease-in-out infinite; }
#dragon.happy #dragon-img { animation: hop .45s ease-out 2; }
#dragon.tilt #dragon-img { animation: tilt 1s ease-in-out 1; }
#dragon.eat #dragon-img { animation: chomp .3s ease-in-out 4; }
@keyframes breathe { 0%,100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }
@keyframes breatheSlow { 0%,100% { transform: scale(1, 1); } 50% { transform: scale(1.03, .96); } }
@keyframes hop { 0% { transform: translateY(0); } 40% { transform: translateY(-38px) scale(1.04); } 100% { transform: translateY(0); } }
@keyframes tilt { 30%, 70% { transform: rotate(-9deg); } }
@keyframes chomp { 50% { transform: scale(1.06, .94) translateY(4px); } }
.zzz { position: absolute; right: 10px; top: 0; font-size: 44px; font-weight: 900; color: #fff; text-shadow: 0 2px 6px #0008; animation: zz 2.4s ease-in-out infinite; pointer-events: none; }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 10px) scale(.7); } 40% { opacity: 1; } 100% { opacity: 0; transform: translate(30px, -60px) scale(1.2); } }
.heart { position: absolute; font-size: 46px; pointer-events: none; animation: heart 1.2s ease-out forwards; }
@keyframes heart { to { transform: translateY(-120px) scale(1.4); opacity: 0; } }

#needs { position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -6px); display: flex; gap: 8px; }
.need { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: conic-gradient(var(--c) calc(var(--v) * 1%), rgba(255,255,255,.25) 0); box-shadow: var(--shadow); }
.need span { width: 46px; height: 46px; border-radius: 50%; background: var(--cream); display: grid; place-items: center; }
.need.low span { animation: needPulse 1s ease-in-out infinite; }
@keyframes needPulse { 50% { transform: scale(1.12); } }

.bubble { position: absolute; left: 50%; bottom: calc(100% + 70px); transform: translateX(-50%); background: #fff; color: var(--ink); font-weight: 800; font-size: 30px; padding: 12px 20px; border-radius: 24px; white-space: nowrap; box-shadow: var(--shadow); }
.bubble::after { content: ''; position: absolute; left: 50%; top: 100%; border: 12px solid transparent; border-top-color: #fff; transform: translateX(-50%); }

/* beds */
.bed { position: absolute; width: 120px; height: 90px; transform: translate(-50%, -50%); display: grid; place-items: center; cursor: pointer; }
.bed .plot { position: absolute; inset: 14px 6px 6px; border-radius: 14px; background: rgba(90, 58, 30, .55); border: 3px solid rgba(255, 220, 160, .55); }
.bed img { position: relative; width: 74px; filter: drop-shadow(0 4px 4px #0006); }
.bed.ready img { animation: readyBounce 1.1s ease-in-out infinite; }
@keyframes readyBounce { 50% { transform: translateY(-10px) scale(1.08); } }
.bed .sprout { position: relative; font-size: 42px; }
.bed .time { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); background: rgba(22,36,79,.85); color: #fff; font-weight: 800; font-size: 20px; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.bed .plus { position: relative; font-size: 40px; color: #fff; font-weight: 900; text-shadow: 0 2px 6px #000a; }

/* HUD */
#hud { position: absolute; top: calc(env(safe-area-inset-top) + 8px); left: 6px; right: 6px; display: flex; gap: 4px; align-items: center; pointer-events: none; }
.pill { pointer-events: auto; display: flex; align-items: center; gap: 6px; background: rgba(22, 36, 79, .86); border: 2px solid rgba(244, 194, 79, .7); color: #fff; border-radius: 999px; padding: 3px 10px 3px 4px; box-shadow: var(--shadow); font-weight: 800; font-size: 15px; }
.pill img { width: 26px; height: 26px; object-fit: contain; }
.pill.energy { flex: 1; min-width: 0; }
.pill .bar { flex: 1; height: 10px; border-radius: 6px; background: rgba(255,255,255,.18); overflow: hidden; min-width: 30px; }
.pill .bar i { display: block; height: 100%; width: 50%; background: linear-gradient(90deg, #7fd4ff, #d7f3ff); border-radius: 6px; transition: width .4s; }
.pill .col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pill small { font-size: 9px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1; }
.pill.level { position: relative; padding-right: 12px; }
.pill.level span { color: var(--gold); font-size: 18px; margin-left: 6px; }
.pill.level .xp { position: absolute; left: 10px; right: 10px; bottom: -4px; height: 4px; border-radius: 3px; background: rgba(255,255,255,.2); overflow: hidden; }
.pill.level .xp i { display: block; height: 100%; background: var(--gold); width: 0; }

#banner { position: absolute; top: calc(env(safe-area-inset-top) + 50px); z-index: 5; left: 50%; transform: translateX(-50%); background: rgba(22,36,79,.9); color: #fff; padding: 8px 16px; border-radius: 14px; font-weight: 800; font-size: 15px; text-align: center; border: 2px solid rgba(142,197,255,.6); box-shadow: var(--shadow); max-width: 92vw; }

#dock { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 10px); left: 8px; right: 8px; display: flex; gap: 8px; justify-content: center; }
#dock button { position: relative; flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px 8px; border-radius: 20px; border: 3px solid var(--gold); background: linear-gradient(#2a4596, var(--navy)); color: #fff; font-weight: 800; font-size: 12px; box-shadow: var(--shadow); }
#dock button img { width: 38px; height: 38px; object-fit: contain; }
#dock button.small { flex: 0 0 46px; font-size: 22px; justify-content: center; opacity: .75; }
#dock em { position: absolute; top: -6px; right: -4px; background: #e8574a; color: #fff; font-style: normal; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; animation: needPulse 1s infinite; }

#toast { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 100px); transform: translateX(-50%); background: var(--cream); border: 3px solid var(--gold); color: var(--ink); padding: 10px 18px; border-radius: 18px; font-weight: 800; box-shadow: var(--shadow); max-width: 90vw; text-align: center; z-index: 60; }

/* overlays & modals */
.overlay { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(8, 14, 40, .55); padding: calc(env(safe-area-inset-top) + 8px) 8px calc(env(safe-area-inset-bottom) + 8px); }
#start { background: radial-gradient(circle at 50% 40%, #2a4ca8, #0b1434); }
.start-card { text-align: center; color: #fff; }
.start-card img { width: 210px; animation: breathe 3s ease-in-out infinite; }
.start-card h1 { font-size: 40px; margin: 8px 0 22px; text-shadow: 0 3px 10px #0008; letter-spacing: .5px; }

.modal { position: relative; width: min(94vw, 520px); max-height: 100%; overflow: auto; background: var(--parch); border: 4px solid var(--gold); border-radius: 26px; padding: 18px 18px 20px; box-shadow: 0 20px 50px rgba(0,0,0,.5); animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.modal h2 { margin: 0 0 10px 0; font-size: 22px; font-weight: 900; color: var(--navy); }
.modal .close { position: sticky; top: 0; float: right; margin: -6px -6px 0 8px; z-index: 3; box-shadow: 0 2px 8px rgba(0,0,0,.3); width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--navy); color: #fff; font-size: 20px; font-weight: 900; }
.modal p { margin: 6px 0 10px; font-size: 18px; line-height: 1.4; font-weight: 700; }
.muted { color: #6b5b46; font-size: 14px !important; font-weight: 700; }

.btn { border: 0; border-radius: 16px; background: linear-gradient(#3f74e8, #2449a8); color: #fff; font-weight: 900; font-size: 18px; padding: 12px 18px; box-shadow: 0 4px 0 #17306f, var(--shadow); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #17306f; }
.btn.gold { background: linear-gradient(#ffd56b, #e2a52a); color: #4a2f00; box-shadow: 0 4px 0 #9b6a10, var(--shadow); }
.btn.ghost { background: rgba(22,36,79,.12); color: var(--navy); box-shadow: none; }
.btn.big { font-size: 22px; padding: 16px 30px; }
.btn[disabled] { opacity: .45; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card { background: var(--cream); border-radius: 18px; padding: 12px; border: 2px solid rgba(201,138,28,.35); }
.card.choice { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.card.choice img { width: 56px; height: 56px; object-fit: contain; }
.card.choice b { display: block; font-size: 17px; }
.card.choice small { color: #6b5b46; font-weight: 700; }
.card.choice.off { opacity: .5; }

/* owl */
.owl { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; }
.owl img { width: 74px; flex: 0 0 auto; }
.owl .say { background: #fff; border-radius: 16px; padding: 10px 12px; font-weight: 800; font-size: 16px; line-height: 1.35; border: 2px solid #d9c7a0; position: relative; }
.owl .say.rule { background: #e9f2ff; border-color: #9cc0ff; }
.owl .say.steps { background: #fff7dd; }

/* task */
.task-text { font-size: 20px !important; }
.answers { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 12px 0; }
.answers label { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.answers input { flex: 1; min-width: 0; width: 100%; font: 900 26px var(--font); padding: 10px 12px; border-radius: 14px; border: 3px solid #c9b48a; background: #fff; text-align: center; color: var(--navy); }
.answers input:focus { outline: none; border-color: var(--blue); }
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 6px 0 12px; }
.keypad button { font: 900 22px var(--font); padding: 10px 0; border-radius: 12px; border: 0; background: #fff; color: var(--navy); box-shadow: 0 3px 0 #c9b48a; }
.keypad button.wide { grid-column: span 2; background: #f1e3c2; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* sentence game */
.sentence { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; }
.word { font: 900 22px var(--font); padding: 10px 14px; border-radius: 14px; background: #fff; border: 3px solid #d9c7a0; color: var(--ink); position: relative; }
.word.sel { border-color: var(--blue); }
.word.subj { border-color: var(--ok); }
.word.subj::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 4px; height: 3px; background: var(--ink); }
.word.pred::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 2px; height: 8px; border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }
.word.pred { border-color: var(--ok); }
.word.focus { background: #fff1b8; border-color: var(--gold-2); }
.opts { display: grid; gap: 8px; margin: 8px 0; }
.opts button { font: 800 18px var(--font); padding: 12px; border-radius: 14px; border: 3px solid #d9c7a0; background: #fff; color: var(--ink); text-align: left; }
.opts button.right { border-color: var(--ok); background: #e5f6ec; }
.opts button.picked { border-color: var(--blue); }
.lens { display: flex; gap: 10px; align-items: center; font-weight: 900; color: var(--navy); margin-top: 10px; }
.lens .ic { font-size: 26px; }

/* English */
.mic { width: 110px; height: 110px; border-radius: 50%; border: 5px solid #fff; background: radial-gradient(circle at 40% 35%, #8e7bff, #4b2fc0); color: #fff; font-size: 46px; box-shadow: 0 0 0 8px rgba(124, 104, 255, .25), var(--shadow); }
.mic.rec { animation: rec 1s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 18px rgba(124,104,255,.15), var(--shadow); } }
.say-en { font-size: 26px; font-weight: 900; color: var(--navy); text-align: center; margin: 8px 0; }
.stars { color: var(--gold-2); font-size: 22px; letter-spacing: 2px; }
.play { border: 0; background: var(--navy); color: #fff; border-radius: 50%; width: 46px; height: 46px; font-size: 20px; }

/* list items */
.item-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.item { background: var(--cream); border-radius: 16px; padding: 8px; text-align: center; font-weight: 800; font-size: 13px; border: 2px solid rgba(201,138,28,.35); }
.item img { width: 56px; height: 56px; object-fit: contain; display: block; margin: 0 auto 4px; }
.item b { font-size: 18px; color: var(--navy); }

.pattern { display: flex; gap: 8px; justify-content: center; margin: 14px 0; flex-wrap: wrap; }
.dot { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: var(--shadow); }
.dot.q { background: #fff; display: grid; place-items: center; font-weight: 900; font-size: 24px; color: var(--navy); }

/* parent */
.parent-section { margin: 12px 0; }
.parent-section h3 { margin: 6px 0; font-size: 16px; color: var(--navy); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 15px; padding: 4px 0; }
.check input { width: 20px; height: 20px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stats td { padding: 4px 6px; border-bottom: 1px solid #e2d3b0; }
.field { width: 100%; font: 700 16px var(--font); padding: 10px; border-radius: 12px; border: 2px solid #c9b48a; margin: 4px 0 8px; background: #fff; }

.confetti { position: absolute; width: 12px; height: 12px; border-radius: 2px; pointer-events: none; animation: conf 1.4s ease-out forwards; z-index: 70; }
@keyframes conf { to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }

/* жесты: масштаб страницы браузера отключён, свой масштаб — у карты */
html, body { touch-action: none; position: fixed; inset: 0; }
.modal, .modal * { touch-action: pan-y; }

/* разговор с драконом */
.dlg-line { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 18px; padding: 10px 12px; border: 2px solid #d9c7a0; }
.dlg-prompt { margin: 14px 0 4px !important; font-size: 15px !important; color: #6b5b46; }
.dlg-answer { display: flex; gap: 10px; align-items: center; justify-content: center; background: #e9f2ff; border: 2px solid #9cc0ff; border-radius: 16px; padding: 10px 12px; font-size: 22px; color: var(--navy); }
.play.small { width: 40px; height: 40px; font-size: 18px; flex: 0 0 auto; }
.link { border: 0; background: none; color: var(--blue); font: 800 14px var(--font); padding: 2px 0; text-decoration: underline; }

/* задания обучения */
#quest { position: absolute; top: calc(env(safe-area-inset-top) + 50px); left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; background: rgba(255, 248, 234, .96); border: 3px solid var(--gold); border-radius: 18px; padding: 6px 10px 6px 6px; box-shadow: var(--shadow); z-index: 6; animation: pop .3s ease-out; }
#quest img { width: 44px; flex: 0 0 auto; }
#quest b { display: block; font-size: 11px; color: #8a6a2a; text-transform: uppercase; letter-spacing: .5px; }
#quest span { font-size: 14px; font-weight: 800; line-height: 1.25; }
.hot.pulse::after { content: ''; position: absolute; inset: 0; border-radius: 40px; border: 6px solid rgba(244, 194, 79, .9); animation: ring 1.4s ease-in-out infinite; pointer-events: none; }
@keyframes ring { 50% { transform: scale(1.05); opacity: .35; } }

/* вступление */
.intro { position: absolute; inset: 0; z-index: 80; background: #0b1434; overflow: hidden; transition: opacity .7s; }
.intro.out { opacity: 0; }
.intro-img { position: absolute; inset: -6%; width: 112%; height: 112%; object-fit: cover; opacity: 0; transition: opacity 1.2s ease; }
.intro-img.on { opacity: 1; }
.intro-img.move-in.on { animation: kbIn 11s ease-out forwards; }
.intro-img.move-out.on { animation: kbOut 11s ease-out forwards; }
.intro-img.move-up.on { animation: kbUp 11s ease-out forwards; }
.intro-img.move-left.on { animation: kbLeft 11s ease-out forwards; }
@keyframes kbIn { from { transform: scale(1); } to { transform: scale(1.12); } }
@keyframes kbOut { from { transform: scale(1.14); } to { transform: scale(1); } }
@keyframes kbUp { from { transform: translateY(3%) scale(1.06); } to { transform: translateY(-3%) scale(1.06); } }
@keyframes kbLeft { from { transform: translateX(3%) scale(1.06); } to { transform: translateX(-3%) scale(1.06); } }
.intro-cap { position: absolute; left: 14px; right: 14px; bottom: calc(env(safe-area-inset-bottom) + 34px); color: #fff; font-size: 21px; font-weight: 800; line-height: 1.4; text-align: center; padding: 14px 16px; border-radius: 18px; background: rgba(10, 18, 50, .62); text-shadow: 0 2px 6px #000a; opacity: 0; transform: translateY(10px); transition: opacity .8s, transform .8s; }
.intro-cap.on { opacity: 1; transform: none; }
.intro-skip { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; border: 0; border-radius: 999px; background: rgba(10, 18, 50, .6); color: #fff; font: 800 15px var(--font); padding: 8px 14px; }
.intro-dots { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 14px); left: 0; right: 0; display: flex; gap: 6px; justify-content: center; }
.intro-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,.35); }
.intro-dots i.on { background: var(--gold); }
@media (prefers-reduced-motion: reduce) { .intro-img.on { animation: none !important; } }

/* Книга знаний */
.book-tabs { gap: 6px; flex-wrap: wrap; margin: 6px 0 10px; }
.book-tabs .btn { flex: 1 1 40%; padding: 8px 6px; font-size: 14px; }
.book-list { display: flex; flex-direction: column; gap: 8px; }
.book-list h3 { margin: 10px 0 2px; font-size: 16px; color: var(--ink, #1b3a63); }
.book-page p { margin: 6px 0 0; line-height: 1.4; }
.book-ex { background: rgba(120,180,255,.15); border-radius: 10px; padding: 6px 8px; font-size: 14px; }
.book-locked { opacity: .55; display: flex; flex-direction: column; gap: 2px; }
.book-en { display: flex; gap: 10px; align-items: center; }
.book-en + .book-en { margin-top: 6px; }
.book-en small, .book-page small { display: block; font-weight: 600; opacity: .75; }
.book-page > b { display: block; font-size: 18px; color: var(--navy); }
.book-page > p { font-size: 15px; font-weight: 600; }
.book-page > .book-ex { font-size: 14px; }
