:root {
  --bg: #f4f0ff;
  --card: #ffffff;
  --ink: #2a1f4d;
  --muted: #7a6fa0;
  --primary: #7c5cff;
  --primary-dark: #5b3fe0;
  --good: #2ec27e;
  --warn: #ff9f1c;
  --danger: #ff4d6d;
  --shadow: 0 6px 0 rgba(42, 31, 77, 0.15);
}

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

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

body {
  background: var(--bg);
  background-image: radial-gradient(circle at 20% 10%, #ffe3f1 0, transparent 40%),
    radial-gradient(circle at 90% 80%, #dff4ff 0, transparent 40%);
  color: var(--ink);
  font-family: "Baloo 2", "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  overflow-x: hidden;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
}

.icon-btn {
  width: 48px; height: 48px; border-radius: 14px; border: 0;
  background: var(--card); box-shadow: var(--shadow); font-size: 24px; cursor: pointer;
}

.stars {
  background: var(--card); box-shadow: var(--shadow);
  padding: 6px 18px; border-radius: 999px; font-weight: 800; font-size: 22px;
}
.stars.bump { animation: bump 0.5s; }

main { max-width: 560px; margin: 0 auto; padding: 0 16px 32px; }

.screen { display: none; flex-direction: column; align-items: center; gap: 16px; animation: pop 0.25s; }
.screen.active { display: flex; }

h1 { font-size: 30px; margin: 8px 0 0; text-align: center; line-height: 1.15; }
h2 { font-size: 20px; margin: 8px 0 0; align-self: flex-start; }
.sub { color: var(--muted); text-align: center; margin: 0; font-size: 20px; }
.hint { color: var(--muted); font-size: 15px; text-align: center; }
.hidden { display: none !important; }

/* Nhân vật khối vuông */
.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 8px; }
.avatar-wrap { width: 180px; height: 200px; position: relative; }
.avatar-wrap svg { width: 100%; height: 100%; animation: bob 2.4s ease-in-out infinite; }
.avatar-acc { position: absolute; font-size: 54px; line-height: 1; left: 50%; transform: translateX(-50%); }
.avatar-acc.hat { top: -18px; }
.avatar-acc.face { top: 38px; font-size: 48px; }
.avatar-acc.pet { top: auto; bottom: 0; left: auto; right: -30px; transform: none; font-size: 46px; }

.bubble {
  background: var(--card); border-radius: 22px; padding: 14px 18px; box-shadow: var(--shadow);
  font-size: 21px; text-align: center; position: relative; max-width: 420px;
}
.bubble::before {
  content: ""; position: absolute; top: -12px; left: 50%; margin-left: -12px;
  border: 12px solid transparent; border-top: 0; border-bottom-color: var(--card);
}

.big-btn {
  width: 100%; max-width: 420px; border: 0; border-radius: 22px; padding: 18px 20px;
  font: inherit; font-size: 24px; font-weight: 800; cursor: pointer; color: #fff;
  box-shadow: var(--shadow); text-align: center; text-decoration: none; display: block;
  transition: transform 0.1s;
}
.big-btn:active, .round-btn:active, .channel-card:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(42,31,77,.15); }
.big-btn.primary { background: var(--primary); }
.big-btn.secondary { background: var(--card); color: var(--ink); }
.big-btn.danger { background: var(--danger); }

/* Chọn kênh */
.channel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; }
.channel-card {
  border: 0; border-radius: 24px; padding: 18px 8px; color: #fff; font: inherit;
  font-size: 21px; font-weight: 800; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.channel-card .ce { font-size: 56px; line-height: 1.1; }
.channel-card .cs { font-size: 15px; font-weight: 500; opacity: 0.9; }

/* Tập nói */
.progress { width: 100%; height: 14px; background: #e3dcff; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--good); transition: width 0.4s; }

.line-card {
  width: 100%; background: var(--card); border-radius: 28px; box-shadow: var(--shadow);
  padding: 20px 16px; text-align: center;
}
.line-emoji { font-size: 76px; line-height: 1.1; }
.line-en { font-size: 34px; font-weight: 800; line-height: 1.2; margin-top: 6px; }
.line-en .w { display: inline-block; padding: 0 3px; border-radius: 8px; transition: background 0.2s, color 0.2s; }
.line-en .w.hit { color: var(--good); }
.line-en .w.miss { color: #b9b0d6; }
.line-en .w.speaking { background: #fff1a8; }
.line-vi { color: var(--muted); font-size: 19px; margin-top: 6px; }

.feedback { min-height: 38px; font-size: 26px; font-weight: 800; text-align: center; }
.feedback.good { color: var(--good); }
.feedback.try { color: var(--warn); }
.heard { min-height: 22px; color: var(--muted); font-size: 15px; text-align: center; margin-top: -10px; }

.practice-actions { display: flex; gap: 18px; align-items: center; justify-content: center; }
.round-btn {
  border: 0; border-radius: 50%; cursor: pointer; box-shadow: var(--shadow); font-size: 30px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: inherit;
  width: 78px; height: 78px; background: var(--card); color: var(--ink);
}
.round-btn span { font-size: 14px; font-weight: 700; }
.round-btn.mic { width: 116px; height: 116px; font-size: 48px; background: var(--danger); color: #fff; }
.round-btn.mic.listening { animation: pulse 1s infinite; background: #ff2d55; }

/* Phòng quay */
.studio { position: relative; width: 100%; aspect-ratio: 3 / 4; background: #1b1530; border-radius: 26px; overflow: hidden; box-shadow: var(--shadow); }
.studio video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.rec-dot { position: absolute; top: 12px; left: 14px; color: #fff; background: var(--danger); padding: 2px 10px; border-radius: 10px; font-weight: 800; display: none; animation: blink 1s infinite; }
.rec-dot.on { display: block; }
.prompter {
  position: absolute; left: 10px; right: 10px; bottom: 12px; color: #fff; text-align: center;
  font-size: 28px; font-weight: 800; background: rgba(0,0,0,0.45); border-radius: 18px; padding: 10px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.prompter small { display: block; font-size: 16px; font-weight: 500; opacity: 0.85; }
.studio-actions, .studio-result { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.studio-result video { width: 100%; border-radius: 20px; background: #000; }

/* Cửa hàng */
.color-row { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; }
.color-dot { width: 48px; height: 48px; border-radius: 14px; border: 4px solid transparent; cursor: pointer; box-shadow: var(--shadow); }
.color-dot.sel { border-color: var(--ink); }
.shop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; }
.shop-item {
  background: var(--card); border: 4px solid transparent; border-radius: 20px; padding: 10px 4px;
  font: inherit; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center;
}
.shop-item .se { font-size: 40px; }
.shop-item .sn { font-size: 14px; line-height: 1.2; text-align: center; }
.shop-item .sc { font-size: 15px; font-weight: 800; color: var(--primary-dark); }
.shop-item.locked { opacity: 0.55; }
.shop-item.worn { border-color: var(--good); }

/* Phụ huynh */
#parent-gate, #parent-panel { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }
#gate-answer { font: inherit; font-size: 26px; padding: 10px 14px; border-radius: 16px; border: 3px solid #d8cfff; width: 180px; text-align: center; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.stat { background: var(--card); border-radius: 18px; padding: 12px; box-shadow: var(--shadow); text-align: center; }
.stat b { display: block; font-size: 30px; }
.stat span { color: var(--muted); font-size: 15px; }
.week { display: flex; gap: 8px; align-items: flex-end; width: 100%; height: 140px; background: var(--card); border-radius: 18px; padding: 12px; box-shadow: var(--shadow); }
.day { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 13px; color: var(--muted); }
.day .bar { width: 100%; background: var(--primary); border-radius: 8px 8px 4px 4px; min-height: 3px; }

/* Phiêu lưu cùng Bloxy */
.scene { position: relative; width: 100%; height: 120px; background: linear-gradient(180deg, #cfeaff, #e9fbe8); border-radius: 26px; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.scene-emoji { font-size: 64px; line-height: 1; letter-spacing: 6px; animation: bob 2.4s ease-in-out infinite; }
.mini-avatar { position: absolute; left: 6px; bottom: -6px; width: 70px; height: 78px; }
.mini-avatar svg { width: 100%; height: 100%; }
.mini-avatar .avatar-acc { font-size: 22px; }
.mini-avatar .avatar-acc.hat { top: -8px; }
.mini-avatar .avatar-acc.face { top: 14px; font-size: 18px; }
.mini-avatar .avatar-acc.pet { display: none; }

.talk { width: 100%; background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 16px; font-size: 22px; line-height: 1.45; min-height: 90px; }
.talk:empty { display: none; }
.talk p { margin: 0; }
.seg { border-radius: 8px; padding: 0 2px; transition: background 0.2s; }
.seg.en { color: var(--primary-dark); font-weight: 800; background: #efe9ff; padding: 0 6px; }
.seg.now { background: #fff1a8; }

.try-card { width: 100%; display: flex; align-items: center; gap: 10px; background: #fff7d6; border: 3px dashed #ffcf4a; border-radius: 20px; padding: 10px 14px; }
.try-label { font-size: 16px; color: var(--muted); white-space: nowrap; }
.try-phrase { flex: 1; font-size: 26px; font-weight: 800; color: var(--primary-dark); line-height: 1.2; }
.icon-btn.small { width: 42px; height: 42px; font-size: 20px; flex: none; }

.choices { width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.choices:empty { display: none; }
.choice { width: 100%; max-width: 420px; display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; align-items: center; text-align: left; background: var(--card); border: 0; border-radius: 18px; padding: 8px 12px; box-shadow: var(--shadow); font: inherit; cursor: pointer; }
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(42,31,77,.15); }
.c-emoji { grid-row: span 2; font-size: 36px; }
.c-vi { font-size: 19px; font-weight: 700; line-height: 1.2; }
.c-en { font-size: 16px; color: var(--primary-dark); font-weight: 700; }

.adv-status { min-height: 28px; font-size: 19px; font-weight: 700; text-align: center; color: var(--muted); }
.adv-status.thinking { animation: blink 1.2s infinite; }
.adv-status.good { color: var(--good); }
.adv-status.try { color: var(--warn); }
.lang-pill { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; margin-top: -12px; }

/* Góc phụ huynh: phần AI */
.alert { width: 100%; background: #fff0f3; border: 2px solid var(--danger); border-radius: 16px; padding: 12px; font-size: 16px; }
.link-btn { border: 0; background: none; color: var(--primary-dark); text-decoration: underline; font: inherit; font-size: 15px; cursor: pointer; padding: 6px 0 0; }
.level-row { display: flex; gap: 10px; width: 100%; }
.level-btn { flex: 1; height: 48px; border-radius: 14px; border: 3px solid transparent; background: var(--card); box-shadow: var(--shadow); font: inherit; font-size: 22px; font-weight: 800; cursor: pointer; }
.level-btn.sel { background: var(--primary); color: #fff; }
.words { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.word { background: var(--card); border-radius: 10px; padding: 2px 10px; font-size: 16px; box-shadow: 0 2px 0 rgba(42,31,77,.1); }
.form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 16px; color: var(--muted); }
.form input[type=text], .form input[type=url], .form input[type=password], .form input[type=number] { font: inherit; font-size: 18px; padding: 10px 12px; border-radius: 14px; border: 3px solid #d8cfff; color: var(--ink); background: #fff; width: 100%; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); }
.form label.check input { width: 24px; height: 24px; }
.log { width: 100%; background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); font-size: 15px; max-height: 320px; overflow-y: auto; }
.log p { margin: 0 0 6px; }
.log p.be { color: var(--primary-dark); }

/* Thanh âm lượng khi bé nói */
.meter { width: 70%; max-width: 280px; height: 14px; background: #e3dcff; border-radius: 99px; overflow: hidden; margin-top: -8px; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--good), #ffd23f, var(--danger)); transition: width 0.08s; }

/* Góc phụ huynh: sổ theo dõi, chế độ, các buổi */
.mode-switch { display: flex; gap: 10px; width: 100%; }
.mode-btn { flex: 1; border: 3px solid transparent; border-radius: 16px; padding: 10px 6px; background: var(--card); box-shadow: var(--shadow); font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; color: var(--ink); }
.mode-btn.sel { border-color: var(--primary); background: #efe9ff; }
.notebook { width: 100%; background: var(--card); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); font-size: 16px; }
.notebook p { margin: 0 0 6px; }
.nb-summary { background: #f2fbf5; border-left: 5px solid var(--good); padding: 8px 10px; border-radius: 10px; }
.edit-panel { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.edit-panel textarea { font: inherit; font-size: 17px; padding: 10px 12px; border-radius: 14px; border: 3px solid #d8cfff; width: 100%; resize: vertical; color: var(--ink); }
.locks { display: flex; flex-direction: column; gap: 8px; }
.locks label.check { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.locks input { width: 22px; height: 22px; flex: none; }
.level-btn:disabled { opacity: 0.6; cursor: default; }
.sessions { width: 100%; background: var(--card); border-radius: 18px; padding: 10px; box-shadow: var(--shadow); overflow-x: auto; }
.sessions table { width: 100%; border-collapse: collapse; font-size: 15px; text-align: center; }
.sessions th { color: var(--muted); font-weight: 600; padding: 4px; }
.sessions td { padding: 4px; border-top: 1px solid #eee8ff; }

.voice-warn { width: 100%; margin: -6px 0 0; background: #fff4e5; border-radius: 14px; padding: 8px 12px; font-size: 15px; color: #8a5300; }
.hint.version { font-size: 13px; opacity: 0.7; margin-top: -6px; }

/* Pháo giấy */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.confetti i { position: absolute; top: -40px; font-style: normal; font-size: 30px; animation: fall 1.6s ease-in forwards; }

@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes bump { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.3); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,45,85,.6); } 100% { box-shadow: 0 0 0 26px rgba(255,45,85,0); } }
@keyframes blink { 50% { opacity: 0.4; } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.8; } }

@media (max-width: 380px) {
  .line-en { font-size: 28px; }
  .round-btn.mic { width: 100px; height: 100px; }
}
