:root {
  --bg1: #6a5cff;
  --bg2: #4f8bff;
  --bg3: #39c6ff;
  --ink: #232046;
  --ink-soft: #5b5878;
  --card: #ffffff;
  --line: #e8e6f7;
  --ok: #22b573;
  --ok-soft: #e2f7ec;
  --bad: #ef4d5a;
  --bad-soft: #fde7e9;
  --accent: #5b6cff;
  --accent-2: #ff8a3d;
  --gold: #ffc83d;
  --radius: 22px;
  --shadow: 0 12px 30px rgba(30, 24, 90, .18);
  --shadow-sm: 0 4px 12px rgba(30, 24, 90, .12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: 'Baloo 2', 'Comic Sans MS', 'Trebuchet MS', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 48%, var(--bg3) 100%);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(2px);
  opacity: .35;
  pointer-events: none;
  z-index: 0;
}
body::before { width: 320px; height: 320px; background: #ffd166; top: -120px; right: -90px; }
body::after  { width: 260px; height: 260px; background: #7ef0d4; bottom: -110px; left: -80px; }

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding-top: var(--safe-top);
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.icon-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 15px;
  background: rgba(255, 255, 255, .22);
  backdrop-filter: blur(6px);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn.off { opacity: .45; }

.profile-chip {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  border-radius: 16px;
  padding: 7px 12px 7px 8px;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-align: left;
  min-width: 0;
  transition: transform .12s ease;
}
.profile-chip:active { transform: scale(.97); }
.chip-avatar {
  font-size: 24px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #eef0ff;
  flex: 0 0 auto;
}
.chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.chip-name {
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-pts { font-size: 12px; color: var(--ink-soft); font-weight: 600; }

/* ---------- screens ---------- */
#main { flex: 1 1 auto; padding: 4px 12px calc(20px + var(--safe-bottom)); }
.screen { display: none; animation: fadeIn .25s ease; }
.screen.active { display: block; }

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

.screen-title {
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  text-align: center;
  margin: 6px 0 14px;
  text-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.screen-sub {
  color: rgba(255,255,255,.9);
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  margin: -8px 0 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 58px;
  padding: 12px 18px;
  border: none;
  border-radius: 18px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 0 rgba(0,0,0,.12);
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease, filter .2s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.btn.secondary { background: #eceaff; color: var(--accent); box-shadow: 0 6px 0 #d9d6ff; }
.btn.warm { background: var(--accent-2); box-shadow: 0 6px 0 #e0712c; }
.btn.ghost { background: transparent; color: #fff; box-shadow: none; border: 2px solid rgba(255,255,255,.6); }
.btn:disabled { filter: grayscale(.4) opacity(.7); cursor: default; }

/* ---------- profiles ---------- */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.profile-card {
  position: relative;
  border: none;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 12px 16px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: var(--ink);
  transition: transform .12s ease;
}
.profile-card:active { transform: scale(.96); }
.profile-card .avatar {
  font-size: 46px;
  width: 84px;
  height: 84px;
  margin: 0 auto 8px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: #eef0ff;
}
.profile-card .pname { font-size: 19px; font-weight: 800; }
.profile-card .pmeta { font-size: 13px; color: var(--ink-soft); font-weight: 600; margin-top: 2px; }
.profile-card .del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: #f2f1fa;
  color: #9a97b5;
  font-size: 15px;
  cursor: pointer;
}
.profile-card.add {
  border: 3px dashed #cfd3ff;
  background: rgba(255,255,255,.75);
}
.profile-card.add .avatar { background: transparent; font-size: 40px; color: var(--accent); }

/* ---------- levels ---------- */
.level-card {
  display: flex;
  align-items: center;
  gap: 14px;
  border: none;
  width: 100%;
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  transition: transform .12s ease;
}
.level-card:active { transform: scale(.97); }
.level-badge {
  flex: 0 0 auto;
  width: 62px;
  height: 62px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 30px;
  color: #fff;
}
.level-info { flex: 1 1 auto; min-width: 0; }
.level-info h3 { margin: 0 0 2px; font-size: 19px; font-weight: 800; }
.level-info p { margin: 0; font-size: 13.5px; color: var(--ink-soft); font-weight: 600; }
.level-best {
  flex: 0 0 auto;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 700;
}
.level-best .b { font-size: 20px; color: var(--accent); display: block; }

.lang-switch {
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, .92);
  border-radius: 18px;
  padding: 6px;
  margin: 0 0 14px;
  box-shadow: var(--shadow-sm);
}
.lang-switch .lang-btn {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 13px;
  padding: 11px 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.lang-switch .lang-btn .lf { font-size: 18px; }
.lang-switch .lang-btn.sel { background: var(--accent); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, .12); }
.lang-switch .lang-btn:active { transform: scale(.97); }

/* ---------- quiz ---------- */
.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-weight: 800;
  margin-bottom: 10px;
}
.quiz-head .score-pill {
  background: rgba(255,255,255,.22);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 17px;
}
.dots { display: flex; gap: 5px; }
.dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,255,255,.35);
  transition: transform .2s ease, background .2s ease;
}
.dots i.done-ok { background: #8effc4; }
.dots i.done-bad { background: #ff9aa4; }
.dots i.now { background: #fff; transform: scale(1.35); }

.question-card { text-align: center; }
.prompt-pl {
  font-size: 22px;
  font-weight: 800;
  margin: 2px 0 14px;
}

.question-visual {
  min-height: 160px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}
.big-emoji { font-size: clamp(76px, 26vw, 130px); line-height: 1; animation: pop .35s ease; }
.color-disc {
  width: clamp(110px, 34vw, 160px);
  height: clamp(110px, 34vw, 160px);
  border-radius: 50%;
  box-shadow: inset 0 -8px 18px rgba(0,0,0,.18), 0 10px 20px rgba(0,0,0,.15);
  border: 6px solid #e9e9f5;
  animation: pop .35s ease;
}
.count-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 340px;
}
.count-grid span { font-size: clamp(38px, 12vw, 56px); line-height: 1; animation: pop .3s ease backwards; }

.listen-badge {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: linear-gradient(160deg, #7c8bff, #5b6cff);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 62px;
  box-shadow: 0 10px 24px rgba(91,108,255,.4);
  cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 10px 24px rgba(91,108,255,.4); }
  50% { transform: scale(1.06); box-shadow: 0 14px 30px rgba(91,108,255,.55); }
}

.options { display: grid; gap: 10px; }
.options.images { grid-template-columns: repeat(2, 1fr); }
.options.words { grid-template-columns: 1fr; }

.option {
  position: relative;
  border: 3px solid var(--line);
  background: #fbfbff;
  border-radius: 18px;
  padding: 14px 44px 14px 14px;
  min-height: 66px;
  font-family: inherit;
  font-size: 21px;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.option:active { transform: scale(.97); }
.option.image-opt { padding: 14px; min-height: 108px; font-size: 58px; }
.option .spk {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: #eef0ff;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.option.correct { border-color: var(--ok); background: var(--ok-soft); animation: pop .3s ease; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .4s ease; }
.option.dim { opacity: .5; }
.option:disabled { cursor: default; }
.option.reading {
  border-color: var(--accent);
  background: #eef0ff;
  animation: readPulse 0.9s ease-in-out infinite;
}
@keyframes readPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(91, 108, 255, .18); }
  50% { box-shadow: 0 0 0 8px rgba(91, 108, 255, .10); }
}

.replay-row { display: flex; gap: 10px; margin-top: 14px; }
.replay-row .btn { min-height: 50px; font-size: 17px; }

@keyframes pop {
  0% { transform: scale(.6); opacity: 0; }
  70% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* ---------- feedback toast ---------- */
.feedback {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%) scale(.4);
  font-size: 30px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,.3);
  pointer-events: none;
  opacity: 0;
  z-index: 40;
  white-space: nowrap;
}
.feedback.show {
  animation: fbPop .9s ease forwards;
}
@keyframes fbPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -120%) scale(1); }
}

/* ---------- result ---------- */
.result-card { text-align: center; }
.result-emoji { font-size: 84px; animation: pop .5s ease; }
.result-title { font-size: 27px; font-weight: 800; margin: 6px 0; }
.result-score { font-size: 54px; font-weight: 800; color: var(--accent); line-height: 1; }
.result-score small { font-size: 22px; color: var(--ink-soft); }
.result-line { font-size: 17px; font-weight: 600; color: var(--ink-soft); margin: 8px 0 0; }
.stars { font-size: 44px; letter-spacing: 6px; margin: 10px 0 4px; }
.stars .off { opacity: .22; filter: grayscale(1); }

.practice-list { text-align: left; }
.practice-list h4 { margin: 4px 0 10px; font-size: 17px; }
.practice-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #f6f6ff;
  margin-bottom: 8px;
  font-weight: 700;
}
.practice-item .pe { font-size: 28px; }
.practice-item .pt { flex: 1; }
.practice-item .pt small { display: block; font-weight: 600; color: var(--ink-soft); }
.practice-item .spk {
  border: none;
  background: #e7e8ff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(25, 20, 70, .5);
  display: grid;
  place-items: center;
  padding: 18px;
  backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-box {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: pop .25s ease;
}
.modal-box h3 { margin: 0 0 14px; font-size: 22px; }
.modal-box label { display: block; font-weight: 700; font-size: 14px; margin: 12px 0 6px; }
.modal-box input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
}
.modal-box input[type="text"]:focus { outline: none; border-color: var(--accent); }
.picker { display: flex; flex-wrap: wrap; gap: 8px; }
.picker button {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 3px solid transparent;
  background: #f4f4ff;
  font-size: 26px;
  cursor: pointer;
}
.picker.colors button { border-radius: 50%; }
.picker button.sel { border-color: var(--accent); background: #e9ebff; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- fx + toast ---------- */
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}
.confetti {
  position: fixed;
  will-change: transform, opacity;
  font-weight: 800;
  pointer-events: none;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(35, 32, 70, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 70;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.hidden { display: none !important; }

/* ---------- voice settings ---------- */
.modal-box.settings { max-height: 90dvh; overflow-y: auto; }
.field { margin: 14px 0; }
.field > label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.seg { display: flex; background: #f1f0fb; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 6px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.seg button.sel { background: #fff; color: var(--accent); box-shadow: var(--shadow-sm); }
.row { display: flex; gap: 8px; align-items: center; }
.row select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
}
.row select:focus { outline: none; border-color: var(--accent); }
.btn.small { width: auto; flex: 0 0 auto; min-height: 46px; padding: 8px 16px; font-size: 15px; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
.hint { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; margin: 8px 0 0; line-height: 1.4; }

@media (min-width: 480px) {
  .screen-title { font-size: 27px; }
}
