:root {
  --bg: #FFF8EC; --card: #fff; --ink: #1F2340; --muted: #6A6E8C; --line: #EADFC6;
  --pri: #4B3FD8; --pri-d: #3629B3; --sun: #FFB020; --sun-d: #E08A00; --teal: #19B6C8; --pink: #E4577F;
  --green: #1E9B63; --green-bg: #DDF5E8; --red: #C23A3A; --red-bg: #FDE6E6; --night: #12163B;
  --r: 18px; --tab: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { color-scheme: light; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.55rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .7em; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
[hidden] { display: none !important; }

/* shell */
#hdr {
  position: sticky; top: 0; z-index: 20; max-width: 480px; margin: 0 auto; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: var(--bg);
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; flex: 1; letter-spacing: -.2px; }
.logo svg { width: 28px; height: 28px; }
.logo small { font-weight: 700; color: var(--pri); background: #E8E5FF; border-radius: 8px; padding: 1px 7px; font-size: .62rem; letter-spacing: .5px; text-transform: uppercase; }
.langbtn, .iconbtn {
  min-width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center;
}
.langbtn { padding: 0 10px; }
.iconbtn svg { width: 22px; height: 22px; }
#app { max-width: 480px; margin: 0 auto; padding: 4px 14px calc(var(--tab) + 28px + env(safe-area-inset-bottom)); }
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 2px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom);
}
#tabs .in { display: flex; width: 100%; max-width: 480px; }
#tabs a {
  flex: 1; min-height: var(--tab); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 700;
}
#tabs a svg { width: 26px; height: 26px; }
#tabs a.on { color: var(--pri); }
body.in-lesson #tabs { display: none; }
body.in-lesson #app { padding-bottom: 130px; }

/* basics */
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--r); padding: 14px; margin: 0 0 12px; }
.card.hero { background: linear-gradient(135deg, #4B3FD8, #7A5CF2); color: #fff; border: 0; }
.card.hero .muted { color: #D9D4FF; }
.card.night { background: var(--night); color: #fff; border: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 10px 20px; border-radius: 16px;
  border: 0; font-weight: 800; background: #fff; border: 2px solid var(--line); text-decoration: none; color: var(--ink); text-align: center;
}
.btn.pri { background: var(--pri); color: #fff; border-color: var(--pri); box-shadow: 0 4px 0 var(--pri-d); }
.btn.pri:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pri-d); }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; box-shadow: 0 4px 0 #14794c; }
.btn.sun { background: var(--sun); border-color: var(--sun); box-shadow: 0 4px 0 var(--sun-d); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 44px; padding: 6px 14px; font-size: .92rem; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .45; box-shadow: none; transform: none; cursor: default; }
.row { display: flex; gap: 10px; margin: 10px 0; flex-wrap: wrap; } .row > .btn { flex: 1; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 14px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-weight: 800; }
.chip.on { background: var(--pri); color: #fff; border-color: var(--pri); }
.chip.layer-a.on { background: var(--sun); border-color: var(--sun-d); color: var(--ink); }
.chip.layer-d.on { background: var(--teal); border-color: #0E8CA0; color: var(--ink); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.badge { display: inline-block; font-size: .72rem; font-weight: 800; border-radius: 8px; padding: 2px 8px; background: #EFEAFB; color: var(--pri); }
.badge.cls { background: #E8F7FA; color: #0B7A8A; }
.badge.soon { background: #F1EEE6; color: var(--muted); }
.badge.draft { background: #FFF0CC; color: #8A5B00; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 12px; min-height: 64px;
}
.item:active { background: #FBF3E0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 800; }
.item .sub { font-size: .82rem; color: var(--muted); }
.star { width: 30px; height: 30px; flex: none; }
.big-cta { display: block; width: 100%; text-align: left; border: 0; border-radius: 22px; padding: 18px; color: #fff; background: linear-gradient(135deg, #E4577F, #F58A4B); box-shadow: 0 5px 0 #B8395F; margin-bottom: 14px; }
.big-cta:active { transform: translateY(3px); box-shadow: 0 2px 0 #B8395F; }
.big-cta h2 { font-size: 1.4rem; margin-bottom: 4px; }
.big-cta p { margin: 0; opacity: .95; }

/* fractions */
.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; margin: 0 .12em; font-weight: 800; }
.fr > span:first-child { border-bottom: 2.5px solid currentColor; padding: 0 .2em .06em; }
.fr > span:last-child { padding: .06em .2em 0; }
.bigfr { font-size: 1.5rem; font-weight: 800; }
.blank { display: inline-block; min-width: 1.2em; padding: 0 .25em; border-radius: 8px; background: #FFF0CC; border: 2px dashed var(--sun-d); text-align: center; }
.blank.filled { background: #E8E5FF; border: 2px solid var(--pri); color: var(--pri); }

/* lesson shell */
.lhead { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; }
.dots { flex: 1; display: flex; gap: 5px; }
.dots i { flex: 1; height: 8px; border-radius: 6px; background: #E8DEC4; }
.dots i.done { background: var(--green); } .dots i.cur { background: var(--pri); }
.stagetitle { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; }
.stagetitle .num { width: 30px; height: 30px; border-radius: 50%; background: var(--pri); color: #fff; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.stagetitle h2 { margin: 0; }
.lfoot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(255,248,236,.96); border-top: 2px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: center;
}
.lfoot .in { width: 100%; max-width: 480px; display: flex; gap: 10px; }
.lfoot .btn { flex: 1; }
.scene { width: 100%; height: auto; display: block; border-radius: 18px; margin-bottom: 10px; }
.story { font-size: 1.08rem; }
.wprompt { font-weight: 700; margin: 0 0 10px; font-size: 1.02rem; }
.taskhead { font-size: .78rem; font-weight: 800; color: var(--pri); text-transform: uppercase; letter-spacing: .6px; margin: 4px 0; }
.bar-svg, .grid-svg, .viz, .pic { width: 100%; height: auto; display: block; background: #fff; border: 2px solid var(--line); border-radius: 16px; }
.bar-svg { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.grid-svg { touch-action: none; user-select: none; -webkit-user-select: none; max-width: 340px; margin: 0 auto 6px; }
.pic { margin: 6px 0 10px; }
.svg-lab { font-family: inherit; }
.cap { min-height: 3.2rem; margin: 8px 0 4px; display: flex; flex-direction: column; justify-content: center; }
.capt { font-weight: 600; color: var(--ink); }
.msg { border-radius: 14px; padding: 0; margin: 6px 0; font-weight: 700; }
.msg.ok, .msg.warn { padding: 10px 12px; }
.msg.ok { background: var(--green-bg); color: #0F6B43; }
.msg.warn { background: #FFF0CC; color: #7A4F00; }
.note { background: #E8F7FA; border-radius: 14px; padding: 10px 12px; margin-top: 10px; font-weight: 600; }
.say { font-weight: 700; }
.expr { font-size: 1.5rem; font-weight: 800; padding: 14px 6px; text-align: center; background: #fff; border: 2px solid var(--line); border-radius: 16px; margin: 8px 0; line-height: 1.9; }
.fitlist { list-style: none; margin: 8px 0 0; padding: 0; font-size: .9rem; font-weight: 700; }
.fitlist li { padding: 2px 0; }
.fitlist li.ok { color: var(--green); } .fitlist li.no { color: var(--red); }
.fitlist li::before { content: "✓ "; } .fitlist li.no::before { content: "✗ "; }

/* slider */
.slider { margin: 10px 0; }
.sl-out { font-weight: 800; text-align: center; margin-bottom: 2px; }
.sl-row { display: flex; align-items: center; gap: 8px; }
.sl-btn, .st-btn { width: 48px; height: 48px; flex: none; border-radius: 50%; border: 2px solid var(--line); background: #fff; font-size: 1.5rem; font-weight: 800; line-height: 1; }
.sl-btn:active, .st-btn:active { background: #FBF3E0; }
.sl-btn[disabled], .st-btn[disabled], input[disabled] { opacity: .4; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; height: 44px; background: transparent; margin: 0; min-width: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 12px; border-radius: 8px; background: #E8DEC4; }
input[type=range]::-moz-range-track { height: 12px; border-radius: 8px; background: #E8DEC4; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 40px; height: 40px; margin-top: -14px; border-radius: 50%; background: var(--sun); border: 4px solid var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.2); }
input[type=range]::-moz-range-thumb { width: 32px; height: 32px; border-radius: 50%; background: var(--sun); border: 4px solid var(--ink); }
.steppers { display: flex; gap: 14px; justify-content: center; margin: 6px 0; flex-wrap: wrap; }
.stepper { text-align: center; }
.st-lab { font-size: .78rem; font-weight: 800; color: var(--muted); margin-bottom: 2px; }
.st-row { display: flex; align-items: center; gap: 6px; }
.st-val { min-width: 54px; font-size: 1.6rem; font-weight: 800; padding: 2px 6px; border-radius: 12px; background: #fff; border: 2px solid var(--line); }

/* 3 ways */
.tabs3 { display: flex; gap: 8px; margin-bottom: 8px; }
.tab3 { flex: 1; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 2px solid var(--line); background: #fff; border-radius: 14px; font-size: .74rem; font-weight: 800; padding: 4px; position: relative; }
.tab3.on { border-color: var(--pri); background: #F1EFFF; }
.tab3.done::after { content: "✓"; position: absolute; top: 2px; right: 6px; color: var(--green); font-weight: 900; }
.micon { width: 40px; height: 28px; }
.vizbox { min-height: 120px; }
.vizcap { min-height: 3.4rem; font-weight: 700; margin: 8px 0; font-size: 1.05rem; }
.symsteps { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 14px; min-height: 190px; font-size: 1.3rem; font-weight: 700; }
.symline { margin: 8px 0; } .symline small { font-size: .85rem; font-weight: 600; color: var(--muted); }
.symline b { color: var(--pri); }
.pop { animation: pop .35s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes pop { 0% { opacity: 0; transform: scale(.7); } 100% { opacity: 1; transform: scale(1); } }

/* quiz */
.optbtn { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 58px; font-size: 1.15rem; font-weight: 800; background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 8px; }
.optbtn:active { background: #F1EFFF; border-color: var(--pri); }
.optbtn.notsure { font-weight: 700; color: var(--muted); border-style: dashed; font-size: .98rem; }
.optbtn.picked { border-color: var(--pri); background: #F1EFFF; }
.optpic { width: 140px; height: 50px; }
.optgrid { display: grid; gap: 10px; }
.optgrid.two { grid-template-columns: 1fr 1fr; }
.chain { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chain span { font-size: .78rem; font-weight: 800; border-radius: 999px; padding: 3px 10px; background: #fff; border: 2px solid var(--line); }
.chain .ok { background: var(--green-bg); border-color: #9ADBB9; color: #0F6B43; }
.chain .gap { background: #FFF0CC; border-color: #F0C466; color: #7A4F00; }

/* path ladder */
.ladder { position: relative; display: flex; flex-direction: column; gap: 0; margin: 12px 0; }
.rung { display: flex; gap: 12px; align-items: stretch; }
.rail { width: 34px; display: flex; flex-direction: column; align-items: center; flex: none; }
.rail .line { flex: 1; width: 4px; background: repeating-linear-gradient(#C9BDF7 0 6px, transparent 6px 11px); }
.rung:first-child .rail .line.up, .rung:last-child .rail .line.down { visibility: hidden; }
.rung .card { flex: 1; margin: 6px 0; }
.rung .card.next { border-color: var(--pri); box-shadow: 0 4px 0 #CFC9FA; }
.rung .card.done { background: #F2FBF6; border-color: #A9DEC2; }
.rung .card.target { border-style: dashed; }
.ref { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* map */
.mapwrap { background: radial-gradient(ellipse at 50% 20%, #232a6b, var(--night) 70%); border-radius: 22px; overflow: hidden; padding: 6px 0; margin: 0 0 12px; }
.mapsvg { width: 100%; height: auto; display: block; }
.mapsvg text { font-family: inherit; }
.mnode { cursor: pointer; }
.mnode:focus { outline: none; }
.pulse { animation: pulse 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.9); } 50% { opacity: 1; transform: scale(1.15); } }
.twinkle { animation: tw 3s ease-in-out infinite; }
@keyframes tw { 0%,100% { opacity: .9; } 50% { opacity: .45; } }
.dash { animation: dash 1.2s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -16; } }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: .76rem; font-weight: 700; color: var(--muted); margin: 6px 0 12px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend svg { width: 16px; height: 16px; }
.sheetbg { position: fixed; inset: 0; background: rgba(18,22,59,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 480px; border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 86vh; overflow: auto; animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin-top: 2px; }
.sheet .x { float: right; }
.sheet .sec { margin-top: 14px; }
.sheet .sec h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.refrow { font-size: .92rem; padding: 3px 0; }
.seg { display: flex; gap: 6px; margin: 6px 0 10px; }
.seg .chip { flex: 1; justify-content: center; }

/* parent report */
.phone { background: #E5DDD5; border-radius: 22px; padding: 14px 10px; border: 2px solid var(--line); margin-bottom: 12px; }
.phone .who { font-size: .8rem; color: #54656F; text-align: center; margin-bottom: 8px; font-weight: 700; }
.bubble { background: #DCF8C6; border-radius: 14px 14px 4px 14px; padding: 12px 14px; font-size: .95rem; box-shadow: 0 1px 1px rgba(0,0,0,.15); white-space: pre-wrap; line-height: 1.5; margin-left: 18px; }
.bubble .time { display: block; text-align: right; font-size: .68rem; color: #667781; margin-top: 4px; }
.bar-mini { display: flex; gap: 4px; margin: 6px 0; }
.bar-mini i { flex: 1; height: 26px; border-radius: 6px; background: #E8DEC4; position: relative; }
.bar-mini i.on { background: var(--sun); }

/* celebration */
.celebrate { text-align: center; padding: 10px 0; }
.celebrate svg { width: 150px; height: 150px; }
.starburst { animation: burst .8s cubic-bezier(.2,1.4,.4,1) both; transform-origin: center; }
@keyframes burst { 0% { transform: scale(0) rotate(-40deg); } 100% { transform: scale(1) rotate(0); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 520px) { #app { padding-top: 12px; } }

/* ===== roles: welcome, accounts, textbook, parent, teacher ===== */
.center { text-align: center; }
.rolechip { display: inline-flex; align-items: center; gap: 4px; min-height: 36px; padding: 0 10px; border-radius: 999px; background: #E8E5FF; color: var(--pri); font-weight: 800; font-size: .78rem; text-decoration: none; }
.rolechip svg { width: 16px; height: 16px; }
.welcome { text-align: center; padding-top: 10px; }
.wlogo { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: 1.3rem; margin-bottom: 6px; }
.wlogo svg { width: 36px; height: 36px; }
.welcome h1 { font-size: 1.6rem; margin-top: 8px; }
.rolecards { display: flex; flex-direction: column; gap: 12px; margin: 14px 0 10px; }
.rolecard {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; border: 2px solid var(--line); border-radius: 20px; padding: 16px; min-height: 92px; background: #fff;
  box-shadow: 0 4px 0 var(--line);
}
.rolecard:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.rolecard .emo { font-size: 2rem; width: 54px; height: 54px; display: inline-flex; align-items: center; justify-content: center; border-radius: 16px; flex: none; }
.rolecard.r-student .emo { background: #E8E5FF; } .rolecard.r-parent .emo { background: #FFE3EA; } .rolecard.r-teacher .emo { background: #DDF5E8; }
.rolecard .grow { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.rolecard b { font-size: 1.1rem; }
.rolecard .d { color: var(--muted); font-size: .9rem; line-height: 1.3; }
.rolecard .go { font-size: 1.8rem; color: var(--muted); }
.linkbtn { display: block; margin: 8px auto; background: none; border: 0; color: var(--pri); font-weight: 800; text-decoration: underline; min-height: 44px; }
.back { background: none; border: 0; font-weight: 800; color: var(--pri); min-height: 44px; padding: 0 4px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.field .lbl { font-weight: 800; font-size: .92rem; }
.field input[type=text], .field input[type=password] { font: inherit; padding: 12px; border: 2px solid var(--line); border-radius: 12px; width: 100%; min-height: 48px; background: #fff; color: var(--ink); }
.field input:focus { outline: 3px solid #C7C0FF; border-color: var(--pri); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 12px; font-size: .92rem; }
.check input { width: 24px; height: 24px; flex: none; margin-top: 2px; }
.err { color: var(--red); font-weight: 700; min-height: 1.2em; margin: 0 0 8px; }
.soon { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.clsrow { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; margin: 6px -2px; scrollbar-width: none; }
.clsrow .chip { flex: none; min-width: 44px; justify-content: center; }
.card.onb { border-color: var(--pri); }
.emo { font-size: 1.5rem; }
.item.static { cursor: default; }
.bookh { margin-top: 18px; font-size: 1.05rem; }
.chn { flex: none; width: 34px; height: 34px; border-radius: 10px; background: #EFEAFB; color: var(--pri); font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.item.chap { min-height: 60px; }
.dot-none { width: 30px; height: 30px; flex: none; }
.dots { display: flex; gap: 6px; margin-top: 6px; }
.dot { width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 800; border: 2px solid var(--ink); }
.dot.lv0 { background: #fff; border-style: dashed; border-color: #8C88A0; color: #8C88A0; }
.dot.lv1 { background: #FF9F43; }
.dot.lv2 { background: #FFD66B; }
.dot.lv3 { background: #FFF3B0; border-color: #E08A00; box-shadow: 0 0 0 2px #FFE88A; }
.code { font: 800 1.6rem ui-monospace, Menlo, monospace; letter-spacing: 3px; background: #F4F1FF; border-radius: 12px; padding: 10px 14px; display: inline-block; color: var(--pri); }
details.faq summary { font-weight: 800; cursor: pointer; min-height: 32px; }
.btn.danger { color: var(--red); border-color: #F3C6C6; margin-top: 14px; }
a.pdflink { color: var(--pri); font-weight: 700; }
a.btn { text-decoration: none; }
.sheet h2 { margin-top: 4px; }

@media (max-width: 460px) { .logo small { display: none; } .rolechip { padding: 0 8px; } }
