:root {
  --cream: #FFF4DC;
  --paper: #FFFBF0;
  --crust: #A9541A;
  --crust-dark: #7A3A0E;
  --ink: #3B2413;
  --muted: #8A6F58;
  --mustard: #FFC533;
  --mustard-dark: #D99A00;
  --red: #E5484D;
  --red-dark: #B8323A;
  --green: #2E9E5B;
  --green-soft: #DDF4E4;
  --blue-soft: #E3EEFF;
  --line: #EBD9B4;
  --radius: 20px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Baloo 2", "Nunito", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: #F3DFB0;
  color: var(--ink);
  font: 500 16px/1.45 var(--font);
  overscroll-behavior-y: none;
}
#app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
h1, h2 { font-family: var(--display); margin: 0; line-height: 1.15; }
h1 { font-size: 30px; }
h2 { font-size: 20px; margin: 22px 0 10px; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- buttons & fields ---------- */
.btn {
  display: block; width: 100%; min-height: 52px; padding: 12px 18px;
  border-radius: 16px; background: #fff; border: 2px solid var(--line);
  box-shadow: 0 4px 0 var(--line);
  font-weight: 800; font-size: 17px; text-align: center;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--mustard); border-color: var(--mustard-dark); box-shadow: 0 4px 0 var(--mustard-dark); }
.btn.primary:active { box-shadow: 0 0 0 var(--mustard-dark); }
.btn.danger { color: var(--red-dark); margin-top: 16px; }
.btn.small { width: auto; min-height: 48px; padding: 8px 18px; }
.chip-btn {
  min-height: 44px; padding: 6px 16px; border-radius: 999px; background: #fff;
  border: 2px solid var(--line); box-shadow: 0 3px 0 var(--line); font-weight: 800;
}
.chip-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; font-size: 20px; font-weight: 800; color: var(--muted); }
.field { display: block; margin: 16px 0; }
.field > span { display: block; font-weight: 800; margin-bottom: 8px; }
input[type=text], select {
  width: 100%; min-height: 50px; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; outline: none;
}
input[type=text]:focus, select:focus { border-color: var(--mustard-dark); }
input[type=range] { width: 100%; accent-color: var(--crust); height: 44px; }
.switch { display: flex; align-items: center; gap: 12px; min-height: 48px; font-weight: 700; }
.switch input { width: 24px; height: 24px; accent-color: var(--crust); }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.levels button {
  min-height: 56px; border-radius: 14px; background: #fff; border: 2px solid var(--line);
  box-shadow: 0 3px 0 var(--line); font-weight: 800; line-height: 1.1;
}
.levels button small { display: block; font-size: 10px; font-weight: 700; color: var(--muted); }
.levels button.on { background: var(--mustard); border-color: var(--mustard-dark); box-shadow: 0 3px 0 var(--mustard-dark); }
.muted { color: var(--muted); }
.small { font-size: 13px; margin-top: 16px; }
.card { background: var(--paper); border: 2px solid var(--line); border-radius: var(--radius); padding: 6px 16px 16px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

/* ---------- Brezi ---------- */
.brezi { display: block; width: 120px; height: 130px; flex: none; }
.brezi.big { width: 170px; height: 184px; margin: 0 auto; }
.brezi.mini { width: 46px; height: 50px; }
.brezi svg { width: 100%; height: 100%; overflow: visible; display: block; }
.brezi .body { animation: bob 2.6s ease-in-out infinite; transform-origin: 60px 120px; }
.brezi .lid { transform-origin: center; transform-box: fill-box; animation: blink 4.2s infinite; }
.brezi .mouth-open, .brezi .mouth-o, .brezi .sweat, .brezi .dots { display: none; }
.brezi[data-mood=talking] .mouth-smile { display: none; }
.brezi[data-mood=talking] .mouth-open { display: block; animation: chew .28s ease-in-out infinite alternate; transform-origin: center; transform-box: fill-box; }
.brezi[data-mood=listening] .mouth-smile { display: none; }
.brezi[data-mood=listening] .mouth-o { display: block; }
.brezi[data-mood=listening] .body { animation: lean 1s ease-in-out infinite; }
.brezi[data-mood=thinking] .pupil { transform: translate(2px, -3px); }
.brezi[data-mood=thinking] .dots { display: block; }
.brezi[data-mood=thinking] .dots circle { animation: dot 1s infinite; }
.brezi[data-mood=thinking] .dots circle:nth-child(2) { animation-delay: .15s; }
.brezi[data-mood=thinking] .dots circle:nth-child(3) { animation-delay: .3s; }
.brezi[data-mood=happy] .body { animation: hop .5s ease-in-out infinite; }
.brezi[data-mood=oops] .sweat { display: block; }
.brezi[data-mood=oops] .body { animation: shake .4s ease-in-out 2; }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-1.5deg); } }
@keyframes hop { 50% { transform: translateY(-10px) rotate(3deg); } }
@keyframes lean { 50% { transform: rotate(4deg); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(0); } 97% { transform: scaleY(1); } }
@keyframes chew { from { transform: scaleY(.35); } to { transform: scaleY(1); } }
@keyframes dot { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

/* ---------- onboarding ---------- */
.onboard { max-width: 400px; margin: 0 auto; padding-top: 12px; }
.onboard h1 { text-align: center; margin-top: 8px; }
.lead { text-align: center; color: var(--muted); margin: 8px 0 12px; }

/* ---------- home ---------- */
.topbar { display: flex; align-items: center; gap: 10px; }
.stat { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 4px 14px; border-radius: 999px; background: var(--paper); border: 2px solid var(--line); font-size: 17px; }
.topbar .chip-btn { margin-left: auto; }
.hero { display: flex; align-items: center; gap: 6px; margin: 14px 0 6px; }
.bubble {
  position: relative; flex: 1; background: #fff; border: 2px solid var(--line);
  border-radius: 18px; padding: 12px 14px; box-shadow: 0 4px 0 var(--line);
}
.bubble::before {
  content: ""; position: absolute; left: -10px; top: 50%; width: 16px; height: 16px;
  background: #fff; border-left: 2px solid var(--line); border-bottom: 2px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}
.bubble .de { font-weight: 800; font-size: 17px; }
.bubble .en { color: var(--muted); font-size: 14px; margin-top: 2px; }
.goal { background: var(--paper); border: 2px solid var(--line); border-radius: 16px; padding: 10px 14px 12px; margin-top: 12px; }
.goal-head { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.bar { height: 14px; border-radius: 999px; background: #F2E3BF; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--mustard), #FF9F1C); transition: width .5s; }
.install {
  width: 100%; min-height: 48px; margin-top: 12px; border-radius: 16px; font-weight: 800;
  background: var(--ink); color: #fff;
}
.install-tip { margin-top: 12px; padding: 10px 14px; border-radius: 14px; background: var(--blue-soft); font-size: 14px; }
.scenes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.scene {
  position: relative; text-align: left; padding: 14px 12px 12px; min-height: 124px; border-radius: var(--radius);
  background: var(--c, #fff); border: 2px solid rgba(59, 36, 19, .12); box-shadow: 0 5px 0 rgba(59, 36, 19, .14);
  transition: transform .08s, box-shadow .08s;
}
.scene:active { transform: translateY(5px); box-shadow: none; }
.scene .emoji { font-size: 34px; line-height: 1; display: block; }
.scene b { display: block; font-family: var(--display); font-size: 18px; margin-top: 6px; line-height: 1.1; }
.scene small { color: rgba(59, 36, 19, .7); font-weight: 700; }
.scene .tick { position: absolute; top: 10px; right: 10px; font-size: 13px; background: #fff; border-radius: 999px; padding: 2px 8px; font-weight: 800; }

/* ---------- chat ---------- */
#screen-chat { display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 0; overflow: hidden; }
.chatbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 2px solid var(--line); background: var(--paper); }
.chat-title { flex: 1; min-width: 0; line-height: 1.2; }
.chat-title b { display: block; font-family: var(--display); font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title span { font-size: 13px; color: var(--muted); font-weight: 700; }
.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; border-radius: 18px; padding: 10px 14px; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.9) translateY(8px); opacity: 0; } }
.msg.tutor { align-self: flex-start; background: #fff; border: 2px solid var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--crust); color: #fff; border-bottom-right-radius: 6px; }
.msg .de { font-size: 18px; font-weight: 700; }
.msg .en { font-size: 14px; color: var(--muted); margin-top: 4px; }
.msg .tools { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tool { min-height: 36px; min-width: 44px; padding: 4px 10px; border-radius: 999px; background: var(--cream); font-size: 14px; font-weight: 800; }
.tool:active { background: var(--line); }
.vocab { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.word-chip { min-height: 36px; padding: 4px 10px; border-radius: 12px; background: var(--blue-soft); font-size: 14px; font-weight: 700; text-align: left; }
.word-chip.saved { background: var(--green-soft); }
.note { align-self: flex-end; max-width: 92%; border-radius: 16px; padding: 10px 12px; font-size: 14.5px; animation: pop .25s ease-out; }
.note.good { background: var(--green-soft); }
.note.fix { background: #FFE9D6; border: 2px dashed #F0B98A; }
.note b { display: block; }
.note .fixed { font-size: 16px; font-weight: 800; margin: 2px 0; }
.note .tip { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(59, 36, 19, .15); }
.note .xp { float: right; font-weight: 800; color: var(--crust); margin-left: 8px; }
.typing { align-self: flex-start; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 12px 16px; display: flex; gap: 5px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--crust); animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.hints { padding: 8px 12px; background: var(--paper); border-top: 2px solid var(--line); display: flex; flex-direction: column; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.hints p { font-size: 13px; font-weight: 800; color: var(--muted); }
.hint { text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 8px 12px; min-height: 48px; }
.hint b { display: block; } .hint span { font-size: 13px; color: var(--muted); }
.typebar { display: flex; gap: 8px; padding: 8px 12px; background: var(--paper); border-top: 2px solid var(--line); }
.typebar input { flex: 1; min-width: 0; }
.controls { display: flex; align-items: center; justify-content: space-around; padding: 10px 12px 0; background: var(--paper); border-top: 2px solid var(--line); }
.side-btn { width: 72px; min-height: 56px; font-size: 13px; font-weight: 800; color: var(--muted); border-radius: 14px; }
.side-btn span { display: block; font-size: 24px; }
.side-btn.on { background: var(--cream); color: var(--ink); }
.mic {
  position: relative; width: 84px; height: 84px; border-radius: 50%;
  background: var(--red); box-shadow: 0 6px 0 var(--red-dark); font-size: 36px;
  transition: transform .08s, box-shadow .08s, background .2s;
}
.mic:active { transform: translateY(6px); box-shadow: none; }
.mic .ring { position: absolute; inset: -6px; border-radius: 50%; border: 4px solid var(--red); opacity: 0; transform: scale(var(--vol, 1)); }
.mic.rec { background: var(--ink); box-shadow: 0 6px 0 #000; }
.mic.rec .ring { opacity: .7; border-color: var(--red); transition: transform .08s; }
.mic.rec .mic-icon { display: none; }
.mic.rec::after { content: ""; position: absolute; inset: 28px; border-radius: 8px; background: var(--red); }
.mic.busy { background: #C9B79B; box-shadow: 0 6px 0 #A8977C; pointer-events: none; }
.mic-label { text-align: center; font-size: 13px; font-weight: 800; color: var(--muted); background: var(--paper); padding: 6px 0 calc(10px + env(safe-area-inset-bottom)); }

/* ---------- words ---------- */
.pagehead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.words { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.words li { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 14px; }
.words .w { flex: 1; min-width: 0; }
.words .w b { display: block; font-size: 17px; transition: filter .2s; }
.words .w span { font-size: 14px; color: var(--muted); }
.words.quiz .w b { filter: blur(7px); }
.words.quiz li.peek .w b { filter: none; }

/* ---------- tab bar, modal, toast ---------- */
.tabbar { display: flex; background: var(--paper); border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; min-height: 60px; font-size: 12px; font-weight: 800; color: var(--muted); }
.tabbar button span { display: block; font-size: 22px; filter: grayscale(1); opacity: .6; }
.tabbar button.on { color: var(--ink); }
.tabbar button.on span { filter: none; opacity: 1; }
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(59, 36, 19, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 480px; background: var(--cream); border-radius: 26px 26px 0 0;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); text-align: center; animation: rise .3s ease-out;
  max-height: 92dvh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet .brezi { margin: 0 auto; }
.sheet h1 { margin: 6px 0; }
.sheet .btn { margin-top: 10px; }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 6px; }
.results div { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 10px 4px; }
.results b { display: block; font-family: var(--display); font-size: 26px; line-height: 1; }
.results span { font-size: 12px; font-weight: 800; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 14px; font-weight: 700; font-size: 14px;
  max-width: min(92vw, 440px); text-align: center; animation: pop .2s ease-out;
}
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
#confetti span { position: absolute; top: -40px; font-size: 26px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (min-width: 520px) {
  body { padding: 0; }
  #app { box-shadow: 0 0 60px rgba(59, 36, 19, .25); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ---------- learning path ---------- */
.unit { margin-top: 20px; }
.unit-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--c, #fff); border: 2px solid rgba(59, 36, 19, .12); box-shadow: 0 4px 0 rgba(59, 36, 19, .12);
}
.unit-head .emoji { font-size: 34px; line-height: 1; }
.unit-head small { display: block; font-size: 12px; font-weight: 800; color: rgba(59, 36, 19, .65); text-transform: uppercase; letter-spacing: .04em; }
.unit-head b { display: block; font-family: var(--display); font-size: 20px; line-height: 1.1; }
.unit-head span:not(.emoji) { font-size: 14px; font-weight: 700; color: rgba(59, 36, 19, .7); }
.path { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 22px 0 6px; }
.node-wrap { position: relative; display: flex; flex-direction: column; align-items: center; width: 190px; text-align: center; transform: translateX(var(--dx, 0)); }
.node-wrap b { font-size: 14px; font-weight: 800; margin-top: 12px; line-height: 1.2; }
.node-wrap > span:last-child { font-size: 12px; font-weight: 700; color: var(--muted); }
.node {
  width: 76px; height: 68px; border-radius: 50%; font-size: 28px; font-weight: 800; color: #fff;
  background: var(--mustard); box-shadow: 0 7px 0 var(--mustard-dark); transition: transform .08s, box-shadow .08s;
}
.node:active { transform: translateY(7px); box-shadow: none; }
.node.rp { border-radius: 24px; }
.node.done { background: var(--green); box-shadow: 0 7px 0 #1F7A44; }
.node.locked { background: #E6D8BC; box-shadow: 0 7px 0 #CDBD9C; font-size: 22px; filter: grayscale(1); opacity: .8; }
.node.next { animation: glow 1.6s ease-in-out infinite; color: var(--ink); }
.node.next.rp { background: var(--red); box-shadow: 0 7px 0 var(--red-dark); }
@keyframes glow { 0%, 100% { outline: 0 solid rgba(255, 197, 51, .6); outline-offset: 2px; } 50% { outline: 9px solid rgba(255, 197, 51, .25); outline-offset: 4px; } }
.start-tag {
  position: absolute; top: -26px; z-index: 1; padding: 2px 12px; border-radius: 10px; background: #fff; border: 2px solid var(--line);
  font-size: 13px; font-weight: 800; color: var(--crust); animation: bob 1.4s ease-in-out infinite;
}

/* ---------- lessons ---------- */
.msg.teach .de { font-size: 16.5px; font-weight: 700; }
.msg .coach { margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: #FFF3C9; font-size: 14px; font-weight: 700; }
.say {
  align-self: stretch; text-align: center; border-radius: 20px; padding: 12px 14px 14px; animation: pop .25s ease-out;
  background: var(--mustard); border: 2px solid var(--mustard-dark); box-shadow: 0 4px 0 var(--mustard-dark);
}
.say small { display: block; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--crust-dark); }
.say b { display: block; font-family: var(--display); font-size: 25px; line-height: 1.15; margin: 4px 0 2px; }
.say > span { font-size: 14px; font-weight: 700; color: var(--crust-dark); }
.say .tools { display: flex; justify-content: center; gap: 6px; margin-top: 10px; }
.say .tool { background: #fff; }
.tabbar button { min-width: 0; }
