:root {
  --bg-top: #eaf4ff;
  --bg-bottom: #fff4e6;
  --ink: #1d1b3a;
  --muted: #6b6890;
  --panel: #ffffff;
  --line: #ece8ff;
  --accent: #7c5cff;
  --accent-dark: #5a3ce0;
  --good: #22c55e;
  --bad: #ff5d73;
  --star: #ffc93c;
  --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-top: #1a1640;
    --bg-bottom: #2a1b3d;
    --ink: #f3f1ff;
    --muted: #b7b2d9;
    --panel: #231f4a;
    --line: #342e66;
  }
}
:root[data-theme="dark"] {
  --bg-top: #1a1640;
  --bg-bottom: #2a1b3d;
  --ink: #f3f1ff;
  --muted: #b7b2d9;
  --panel: #231f4a;
  --line: #342e66;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; cursor: pointer; }
svg { display: block; }

.app {
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; gap: 12px; flex: none; }
.stars { display: flex; gap: 2px; min-width: 150px; }
.stars svg { width: 26px; height: 26px; color: #d9d4f5; transition: color .3s, transform .3s; }
.stars svg.on { color: var(--star); animation: pop .5s ease; }
@keyframes pop { 50% { transform: scale(1.45) rotate(12deg); } }
.progress { flex: 1; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #a98bff, var(--accent)); border-radius: 5px; transition: width .5s ease; }

.stage {
  flex: none;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 0 6px;
  position: relative;
}
.mia { width: 124px; height: 124px; }
.mia-shadow { fill: rgba(29, 27, 58, .12); }
.mia-body { transform-origin: 80px 140px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.mia-eyes { transform-origin: 80px 76px; animation: blink 4.5s infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
.mia-mouth { transform-origin: 80px 104px; transform: scaleY(.45); transition: transform .08s; }
.mia.talking .mia-mouth { animation: talk .22s ease-in-out infinite alternate; }
@keyframes talk { from { transform: scaleY(.3); } to { transform: scaleY(1.5) scaleX(.85); } }
.mia.happy .mia-body { animation: jump .6s ease 2; }
@keyframes jump { 40% { transform: translateY(-18px) rotate(-4deg); } 70% { transform: translateY(0) rotate(3deg); } }
.mia.listening .mia-body { animation: listen 1s ease-in-out infinite; }
@keyframes listen { 50% { transform: rotate(-5deg) scale(1.03); } }

.bubble {
  margin-top: 6px;
  max-width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 6px 20px rgba(76, 58, 160, .12);
  font-size: 19px; font-weight: 700; line-height: 1.35;
  text-align: center;
  position: relative;
}
.bubble::before {
  content: ""; position: absolute; top: -8px; left: 50%; margin-left: -9px;
  border: 9px solid transparent; border-top: 0; border-bottom-color: var(--panel);
}
.bubble .en { color: var(--accent); }
.heard {
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(124, 92, 255, .1);
  color: var(--muted);
  font-size: 15px; font-weight: 700;
}
.heard.ok { background: rgba(34, 197, 94, .15); color: #15803d; }
.heard.no { background: rgba(255, 93, 115, .12); color: #c2344a; }

.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; }
.screen h1 { margin: 0; font-size: 32px; font-weight: 900; }
.screen p { margin: 0; font-size: 18px; color: var(--muted); font-weight: 700; line-height: 1.4; max-width: 400px; }
.screen p.small { font-size: 13px; font-weight: 600; opacity: .8; }

.big-btn {
  min-width: 230px; height: 64px;
  padding: 0 28px;
  border: 0; border-radius: 32px;
  background: var(--accent); color: #fff;
  font-size: 22px; font-weight: 900;
  box-shadow: 0 8px 0 var(--accent-dark), 0 14px 24px rgba(92, 60, 224, .35);
  transition: transform .08s, box-shadow .08s;
}
.big-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--accent-dark), 0 6px 12px rgba(92, 60, 224, .3); }

.card-big {
  width: min(58vw, 230px, 30vh); aspect-ratio: 1;
  border-radius: 32px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(76, 58, 160, .14);
  padding: 18px;
  animation: cardIn .45s cubic-bezier(.2, 1.4, .4, 1);
}
.card-big svg { width: 100%; height: 100%; }
@keyframes cardIn { from { transform: scale(.6) rotate(-8deg); opacity: 0; } }
.word { display: flex; flex-direction: column; align-items: center; }
.word b { font-size: 44px; font-weight: 900; color: var(--accent); letter-spacing: .02em; line-height: 1; }
.word span { font-size: 18px; color: var(--muted); font-weight: 800; }

.row { display: flex; align-items: center; justify-content: center; gap: 22px; }
.mic-btn {
  width: 104px; height: 104px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 15px; font-weight: 900;
  box-shadow: 0 7px 0 var(--accent-dark), 0 12px 24px rgba(92, 60, 224, .35);
  position: relative;
}
.mic-btn svg { width: 38px; height: 38px; }
.mic-btn:disabled { background: #b9aef5; box-shadow: 0 7px 0 #9d8fe6; cursor: default; }
.mic-btn.rec { background: var(--bad); box-shadow: 0 7px 0 #d9364d, 0 0 0 0 rgba(255, 93, 115, .5); animation: rec 1s infinite; }
@keyframes rec { 70% { box-shadow: 0 7px 0 #d9364d, 0 0 0 22px rgba(255, 93, 115, 0); } }
.mic-btn.busy::after {
  content: ""; position: absolute; inset: -8px;
  border-radius: 50%; border: 4px solid transparent; border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.round-btn {
  width: 58px; height: 58px; border-radius: 50%;
  border: 3px solid var(--line); background: var(--panel); color: var(--accent);
  display: grid; place-items: center;
}
.round-btn svg { width: 26px; height: 26px; }
.round-spacer { width: 58px; }

.task { font-size: 22px !important; color: var(--ink) !important; font-weight: 900 !important; }
.task .en { color: var(--accent); }
.trace-wrap {
  width: min(78vw, 320px, 42vh); aspect-ratio: 1;
  border-radius: 28px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(76, 58, 160, .14);
  overflow: hidden;
  touch-action: none;
}
.trace-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.meter { width: 150px; height: 14px; border-radius: 7px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #86efac, var(--good)); transition: width .2s; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(100%, 340px); }
.grid button {
  aspect-ratio: 1;
  border: 4px solid transparent; border-radius: 26px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(76, 58, 160, .12);
  padding: 14px;
  transition: transform .1s, border-color .2s;
}
.grid button:active { transform: scale(.95); }
.grid button svg { width: 100%; height: 100%; }
.grid button.right { border-color: var(--good); animation: pop .5s; }
.grid button.wrong { border-color: var(--bad); animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.talk-log {
  width: 100%; flex: 1; min-height: 0;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px;
}
.talk-log .msg { max-width: 85%; padding: 9px 14px; border-radius: 18px; font-size: 17px; font-weight: 700; text-align: left; line-height: 1.35; }
.talk-log .kid { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.talk-log .ai { align-self: flex-start; background: var(--panel); border-bottom-left-radius: 6px; box-shadow: 0 4px 14px rgba(76, 58, 160, .1); }
.talk-log .hint { align-self: center; color: var(--muted); font-size: 15px; font-weight: 700; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 16px; font-weight: 800; text-decoration: underline; padding: 8px; }

.end-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(100%, 360px); }
.end-cards svg { width: 100%; aspect-ratio: 1; background: var(--panel); border-radius: 18px; padding: 8px; box-shadow: 0 6px 16px rgba(76, 58, 160, .1); }

@media (max-height: 700px) {
  .mia { width: 92px; height: 92px; }
  .bubble { font-size: 17px; padding: 10px 14px; min-height: 44px; }
  .word b { font-size: 36px; }
  .mic-btn { width: 88px; height: 88px; }
}

/* ---------------- домашка ---------------- */
.big-btn.alt { background: #ffb020; box-shadow: 0 8px 0 #d98a00, 0 14px 24px rgba(217, 138, 0, .3); color: #3b2500; }
.big-btn.alt:active { box-shadow: 0 2px 0 #d98a00, 0 6px 12px rgba(217, 138, 0, .3); }
.file-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
label.big-btn { line-height: 64px; }

.loader { display: flex; gap: 10px; }
.loader i { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); animation: hop 1s ease-in-out infinite; }
.loader i:nth-child(2) { animation-delay: .15s; } .loader i:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 50% { transform: translateY(-14px); opacity: .6; } }

.hw-check { justify-content: flex-start; overflow-y: auto; padding-top: 6px; }
.hw-check h1 { font-size: 24px; }
.hw-list {
  width: 100%; margin: 0; padding: 14px 16px 14px 40px;
  background: var(--panel); border-radius: 20px; box-shadow: 0 6px 18px rgba(76, 58, 160, .1);
  text-align: left; font-size: 17px; font-weight: 700; line-height: 1.45;
}
.hw-list li + li { margin-top: 6px; }

.hw-task { justify-content: flex-start; gap: 10px; padding-top: 4px; }
.hw-title { font-size: 14px !important; margin: 0; color: var(--muted); }
.hw-text {
  width: 100%;
  padding: 14px 18px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(76, 58, 160, .1);
  font-size: 24px; font-weight: 800; line-height: 1.35;
  overflow-wrap: anywhere;
}
.hw-text .gap { display: inline-block; min-width: .8em; border-bottom: 3px solid var(--muted); color: var(--good); }
.hw-text .gap.current { border-color: var(--accent); animation: blinkGap 1s infinite; }
@keyframes blinkGap { 50% { border-color: transparent; } }

.answer-box {
  min-width: 140px; height: 58px;
  padding: 0 20px;
  border-radius: 18px; border: 3px dashed var(--accent);
  display: grid; place-items: center;
  font-size: 34px; font-weight: 900; color: var(--accent);
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 300px); }
.keypad button {
  height: 52px; border: 0; border-radius: 16px;
  background: var(--panel); color: var(--ink);
  font-size: 26px; font-weight: 900;
  box-shadow: 0 4px 0 var(--line);
}
.keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.keypad button.ok { background: var(--good); color: #fff; box-shadow: 0 4px 0 #15803d; font-size: 20px; }

.mic-btn.small { width: 76px; height: 76px; font-size: 12px; }
.mic-btn.small svg { width: 28px; height: 28px; }
.hw-actions .round-btn { font-size: 26px; font-weight: 900; }

.letters { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.letters button {
  width: 68px; height: 68px; border: 0; border-radius: 20px;
  background: var(--panel); color: var(--accent);
  font-size: 34px; font-weight: 900;
  box-shadow: 0 5px 0 var(--line);
}
.letters button.right { background: var(--good); color: #fff; }
.letters button.wrong { background: var(--bad); color: #fff; animation: shake .4s; }

.dots { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; max-width: 340px; }
.dot { width: 40px; height: 40px; border-radius: 50%; border: 0; padding: 0; transition: transform .15s, opacity .25s, background .2s; }
.dot.a { background: #c9bdff; } .dot.b { background: #ffd08a; }
.dot.on { transform: scale(1.12); }
.dot.a.on { background: var(--accent); } .dot.b.on { background: #ff9f1c; }
.dot.gone { opacity: .15; transform: scale(.7); }
.dots-counter { width: 100%; text-align: center; font-size: 30px; font-weight: 900; color: var(--accent); min-height: 38px; }

.hw-report { justify-content: flex-start; overflow-y: auto; padding-top: 6px; }
.report { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.report li {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 10px 14px; border-radius: 16px; background: var(--panel);
  text-align: left; font-size: 15px; font-weight: 700;
  border-left: 6px solid var(--good);
}
.report li b { font-size: 13px; color: var(--muted); text-align: right; flex: none; max-width: 45%; }
.report li.hinted { border-left-color: var(--star); }
.report li.shown { border-left-color: var(--bad); }
.report li.self { border-left-color: var(--line); }
body.hw-mode .mia { width: 76px; height: 76px; }
body.hw-mode .stage { padding: 4px 0 2px; }
body.hw-mode .bubble { font-size: 16px; min-height: 0; padding: 8px 14px; }
body.hw-mode .hw-task { overflow-y: auto; justify-content: flex-start; }
body.hw-mode .keypad button { height: 48px; font-size: 24px; }
body.hw-mode .dot { width: 34px; height: 34px; }
body.hw-mode .hw-text { font-size: 22px; padding: 10px 14px; }
.keypad.wait, .letters.wait { opacity: .45; pointer-events: none; transition: opacity .2s; }
