:root {
  --indigo: #241459; --indigo-2: #3B2A85; --indigo-soft: #ECE9F7;
  --teal: #02C4A9; --teal-dark: #00977F; --teal-soft: #DDF7F2;
  --yellow: #FEC104; --yellow-soft: #FFF3CC;
  --cream: #FDF8F3; --white: #FFFFFF; --ink: #241459; --muted: #6E6A8C;
  --red: #F0506E; --red-soft: #FDE4E9;
  --radius: 22px; --shadow: 0 6px 0 rgba(36,20,89,.08), 0 10px 28px rgba(36,20,89,.10);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--cream); color: var(--ink); }
body { font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 17px; overscroll-behavior: none; }
h1, h2, h3, .display { font-family: 'Baloo 2', 'Nunito', system-ui, sans-serif; margin: 0; line-height: 1.15; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
#app { max-width: 520px; margin: 0 auto; min-height: 100%; position: relative; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; padding: calc(14px + var(--safe-top)) 18px calc(18px + var(--safe-bot)); gap: 14px; animation: fadeIn .28s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.center { align-items: center; justify-content: center; text-align: center; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* --- Top bar --- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.topbar h2 { font-size: 22px; flex: 1; }
.icon-btn { width: 46px; height: 46px; border-radius: 16px; background: var(--white); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 22px; flex: none; }
.icon-btn:active { transform: translateY(2px); }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--white); border-radius: 999px; padding: 6px 12px; font-weight: 800; box-shadow: var(--shadow); font-size: 16px; }

/* --- Buttons --- */
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 58px; border-radius: 20px; font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 21px; padding: 10px 18px; transition: transform .08s; }
.btn:active { transform: translateY(3px); }
.btn-primary { background: var(--teal); color: #fff; box-shadow: 0 5px 0 var(--teal-dark); }
.btn-indigo { background: var(--indigo); color: #fff; box-shadow: 0 5px 0 #120A33; }
.btn-yellow { background: var(--yellow); color: var(--indigo); box-shadow: 0 5px 0 #D59F00; }
.btn-ghost { background: var(--white); color: var(--indigo); box-shadow: var(--shadow); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-sm { min-height: 46px; font-size: 17px; border-radius: 16px; width: auto; }

/* --- Cards --- */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-title { font-family: 'Baloo 2'; font-weight: 700; font-size: 19px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 112px; position: relative; overflow: hidden; }
.tile .ti { font-size: 30px; }
.tile b { font-family: 'Baloo 2'; font-size: 18px; line-height: 1.1; }
.tile small { color: var(--muted); font-size: 13px; }
.tile.locked { opacity: .55; }
.tile .lock { position: absolute; right: 12px; top: 10px; font-size: 16px; }

/* --- Bilvoy mascot + bubble --- */
.mascot { width: 120px; height: 120px; border-radius: 50%; background: var(--cream); object-fit: cover; animation: bob 3s ease-in-out infinite; }
.mascot.sm { width: 74px; height: 74px; }
.mascot.lg { width: 170px; height: 170px; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-6px) rotate(1deg); } }
.mascot.happy { animation: hop .5s ease 2; }
@keyframes hop { 0%,100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-18px) scale(1.06); } }
.speak { display: flex; align-items: flex-end; gap: 8px; }
.bubble { background: var(--white); border-radius: 22px 22px 22px 6px; padding: 12px 16px; box-shadow: var(--shadow); font-weight: 700; font-size: 18px; position: relative; flex: 1; }

/* --- Home --- */
.hero { background: linear-gradient(160deg, var(--indigo) 0%, var(--indigo-2) 100%); color: #fff; border-radius: 28px; padding: 18px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hero::after { content: '✦'; position: absolute; right: 18px; top: 8px; color: var(--yellow); font-size: 26px; }
.hero .mascot { background: #fff; border: 4px solid rgba(255,255,255,.25); }
.hero h2 { font-size: 19px; }
.hero .mascot { width: 88px; height: 88px; flex: none; }
.hero p { margin: 4px 0 0; opacity: .9; }
.ring { width: 64px; height: 64px; flex: none; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; overflow: hidden; flex: none; border: 3px solid #fff; box-shadow: var(--shadow); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* --- Map --- */
.stage { background: var(--white); border-radius: 26px; box-shadow: var(--shadow); padding: 14px 14px 18px; }
.stage-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.stage-num { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-family: 'Baloo 2'; font-weight: 800; font-size: 20px; flex: none; }
.stage-head b { font-family: 'Baloo 2'; font-size: 19px; display: block; line-height: 1.1; }
.path { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.node-row { display: flex; }
.node { width: 72px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.node .dot { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; font-family: 'Baloo 2'; font-weight: 800; font-size: 19px; color: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.15); position: relative; }
.node.locked .dot { background: #E4E1EE !important; color: #A9A4C2; box-shadow: 0 5px 0 #CFCBE0; }
.node.current .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 5px 0 rgba(0,0,0,.15), 0 0 0 0 rgba(2,196,169,.6); } 70% { box-shadow: 0 5px 0 rgba(0,0,0,.15), 0 0 0 16px rgba(2,196,169,0); } 100% { box-shadow: 0 5px 0 rgba(0,0,0,.15), 0 0 0 0 rgba(2,196,169,0); } }
.node .stars { font-size: 12px; letter-spacing: -1px; min-height: 14px; }
.node small { font-size: 11px; text-align: center; color: var(--muted); max-width: 84px; line-height: 1.15; }
.node.exam .dot { border-radius: 20px; }

/* --- Problem --- */
.progress { height: 14px; background: var(--indigo-soft); border-radius: 99px; overflow: hidden; flex: 1; }
.screen > .progress, .card > .progress { flex: 0 0 14px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), #36DCC4); border-radius: 99px; transition: width .35s; }
.problem { background: var(--white); border-radius: 26px; box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; align-items: center; }
.terms { font-family: 'Baloo 2'; font-weight: 800; font-size: 38px; line-height: 1.12; text-align: right; min-width: 120px; font-variant-numeric: tabular-nums; }
.terms div { display: flex; justify-content: flex-end; gap: 6px; }
.terms .sign { color: var(--teal-dark); min-width: 22px; text-align: center; }
.terms .sign.minus { color: var(--red); }
.terms hr { border: 0; border-top: 4px solid var(--indigo); margin: 6px 0; border-radius: 4px; }
.answer-box { font-family: 'Baloo 2'; font-weight: 800; font-size: 40px; min-width: 150px; min-height: 64px; border-radius: 18px; border: 3px dashed #CFCBE0; display: grid; place-items: center; padding: 0 14px; background: var(--cream); }
.answer-box.ok { border: 3px solid var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.answer-box.bad { border: 3px solid var(--red); background: var(--red-soft); color: var(--red); animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.key { height: 58px; border-radius: 18px; background: var(--white); box-shadow: 0 4px 0 #DAD6EA; font-family: 'Baloo 2'; font-weight: 800; font-size: 26px; }
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 #DAD6EA; }
.key.go { background: var(--teal); color: #fff; box-shadow: 0 4px 0 var(--teal-dark); }
.key.del { background: var(--indigo-soft); }
.formula-card { background: var(--yellow-soft); border: 3px solid var(--yellow); border-radius: 22px; padding: 10px 16px; text-align: center; }
.formula-card .f { font-family: 'Baloo 2'; font-weight: 800; font-size: 34px; color: var(--indigo); white-space: nowrap; }
.formula-card .s { font-size: 15px; font-weight: 700; color: var(--indigo-2); }
.pop { animation: popIn .35s cubic-bezier(.2,1.6,.4,1); }
@keyframes popIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* --- Abacus --- */
.abacus-wrap { display: flex; justify-content: center; position: relative; }
.abacus { width: 100%; max-width: 480px; height: auto; max-height: 36vh; touch-action: manipulation; user-select: none; }
.modal .abacus { max-height: 28vh; }
.abacus .bead { transition: transform .14s cubic-bezier(.3,.7,.4,1); cursor: pointer; }
.abacus .colhl { transition: opacity .2s; }
.abacus .lbl { font-family: 'Baloo 2'; font-weight: 800; font-size: 22px; }
.abacus-value { font-family: 'Baloo 2'; font-weight: 800; font-size: 22px; color: var(--indigo); }
.shake-col { animation: shake .35s; }

/* --- Results --- */
.big-stars { display: flex; gap: 6px; justify-content: center; }
.big-stars span:nth-child(2) { transform-origin: center; margin-top: -14px; }
.big-stars span { display: inline-block; animation: starIn .5s cubic-bezier(.2,1.6,.4,1) both; }
.big-stars span.off { filter: grayscale(1); opacity: .25; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.stat { background: var(--white); border-radius: 18px; box-shadow: var(--shadow); padding: 10px; text-align: center; }
.stat b { display: block; font-family: 'Baloo 2'; font-size: 26px; color: var(--indigo); }
.stat small { color: var(--muted); font-size: 13px; }

/* --- Flash --- */
.flash-num { font-family: 'Baloo 2'; font-weight: 800; font-size: 120px; line-height: 1; color: var(--indigo); min-height: 140px; display: grid; place-items: center; }
.flash-num.minus { color: var(--red); }
.flash-num.show { animation: popIn .18s ease; }
.mental-card { transition: opacity .4s, transform .4s; }

/* --- Timer --- */
.stopwatch { font-family: 'Baloo 2'; font-weight: 800; font-size: 52px; font-variant-numeric: tabular-nums; color: var(--indigo); }
.checks { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.checks span { min-width: 30px; height: 30px; border-radius: 10px; background: var(--indigo-soft); display: grid; place-items: center; font-weight: 800; font-size: 13px; padding: 0 6px; }
.checks span.ok { background: var(--teal); color: #fff; }

/* --- Forms / onboarding --- */
.input { width: 100%; height: 58px; border-radius: 18px; border: 3px solid #E4E1EE; background: var(--white); padding: 0 16px; font: inherit; font-size: 20px; font-weight: 700; color: var(--ink); outline: none; }
.input:focus { border-color: var(--teal); }
.label { font-weight: 800; font-size: 15px; color: var(--muted); margin-bottom: 6px; display: block; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice { border-radius: 18px; background: var(--white); box-shadow: var(--shadow); padding: 12px 6px; font-weight: 800; border: 3px solid transparent; }
.choice.on { border-color: var(--teal); background: var(--teal-soft); }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 8px 0; }
.pin-dots i { width: 20px; height: 20px; border-radius: 50%; background: #E4E1EE; }
.pin-dots i.on { background: var(--indigo); }
.slide-dots { display: flex; gap: 8px; justify-content: center; }
.slide-dots i { width: 10px; height: 10px; border-radius: 9px; background: #DAD6EA; transition: width .2s; }
.slide-dots i.on { width: 28px; background: var(--teal); }

/* --- Modal --- */
.modal-bg { position: fixed; inset: 0; background: rgba(36,20,89,.45); display: grid; place-items: center; padding: 20px; z-index: 50; animation: fadeIn .2s; }
.modal { background: var(--cream); border-radius: 28px; padding: 22px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); }

/* --- Parent --- */
.bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 10px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars i { width: 100%; background: var(--teal); border-radius: 8px 8px 4px 4px; min-height: 4px; }
.bars i.today { background: var(--indigo); }
.bars small { font-size: 12px; color: var(--muted); font-weight: 700; }
.list { display: flex; flex-direction: column; gap: 8px; }
.li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--cream); border-radius: 14px; }
.li b { flex: 1; }
.switch { width: 52px; height: 30px; border-radius: 99px; background: #DAD6EA; position: relative; flex: none; transition: background .2s; }
.switch::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--teal); }
.switch.on::after { left: 25px; }
.seg { display: flex; background: var(--indigo-soft); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 10px; font-weight: 800; font-size: 14px; }
.seg button.on { background: var(--white); box-shadow: 0 2px 6px rgba(36,20,89,.12); }

/* --- Certificate --- */
.cert { background: #fff; border-radius: 22px; padding: 20px; border: 6px solid var(--yellow); box-shadow: var(--shadow); text-align: center; position: relative; width: 100%; }
.cert::before { content: ''; position: absolute; inset: 6px; border: 2px dashed var(--teal); border-radius: 14px; pointer-events: none; }
.cert h3 { font-size: 26px; color: var(--indigo); }
.cert .name { font-family: 'Baloo 2'; font-size: 32px; color: var(--teal-dark); font-weight: 800; }

/* --- Stickers --- */
.stickers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.sticker { aspect-ratio: 1; border-radius: 18px; background: var(--white); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 30px; }
.sticker.off { background: #EEECF5; box-shadow: none; filter: grayscale(1); opacity: .35; }

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
.toast { position: fixed; left: 50%; top: calc(18px + var(--safe-top)); transform: translateX(-50%); background: var(--indigo); color: #fff; padding: 12px 18px; border-radius: 16px; font-weight: 800; z-index: 60; animation: popIn .3s; box-shadow: var(--shadow); max-width: 90%; text-align: center; }
@media (min-width: 700px) { body { background: #EFE9F7; } #app { background: var(--cream); box-shadow: 0 0 60px rgba(36,20,89,.12); min-height: 100vh; } }
