:root {
  --p: #6c4fd8; --p2: #8f78ec; --pl: #efeaff; --bg: #f6f4ff; --card: #fff; --ink: #24213a; --mut: #6f6b86;
  --ok: #1e9e5a; --okl: #e3f7ec; --bad: #d9534f; --badl: #fdecec; --warn: #fff4d6; --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Kannada", sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--mut); } .small { font-size: 14px; } .strong { font-weight: 650; } .center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--p); color: #fff; box-shadow: 0 2px 10px #0002; }
.topbar h1 { flex: 1; font-size: 19px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { display: flex; gap: 6px; align-items: center; }
.logo { font-size: 22px; }
.icon-btn { background: #ffffff22; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 12px; font-size: 20px; cursor: pointer; flex: none; }
.content { max-width: 720px; margin: 0 auto; padding: 16px 14px 110px; }
h2 { font-size: 19px; margin: 22px 4px 10px; }
h3 { font-size: 17px; margin: 0 0 6px; }

.card { display: block; background: var(--card); border-radius: var(--r); padding: 16px; margin: 0 0 12px; box-shadow: 0 1px 3px #2a1f6a14, 0 4px 14px #2a1f6a0c; }
.card p:first-child { margin-top: 0; } .card p:last-child { margin-bottom: 0; }
.card.warn { background: var(--warn); }
.banner { background: var(--warn); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 15px; }
.hero { display: flex; align-items: center; gap: 16px; background: linear-gradient(135deg, var(--p), var(--p2)); color: #fff; border-radius: var(--r); padding: 16px 18px; margin-bottom: 12px; }
.hero .muted { color: #fff; opacity: .85; } .hero p { margin: 0; flex: 1; }
.big { font-size: 28px; font-weight: 750; }
.continue { border-left: 5px solid var(--p); }
.book { display: flex; align-items: center; gap: 14px; }
.book-icon { font-size: 30px; width: 52px; height: 52px; display: grid; place-items: center; background: var(--pl); border-radius: 14px; }
.bar { height: 7px; background: var(--pl); border-radius: 9px; margin-top: 8px; overflow: hidden; } .bar i { display: block; height: 100%; background: var(--p); border-radius: 9px; }
.pct { font-weight: 700; color: var(--p); }
.empty { text-align: center; color: var(--mut); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 2px solid var(--pl); background: #fff; font-weight: 600; cursor: pointer; text-align: center; }
.btn.primary { background: var(--p); color: #fff; border-color: var(--p); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: transparent; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 15px; }
.btn:disabled { opacity: .5; }
.btn:active, .opt:active, .chip:active { transform: scale(.97); }

label { display: block; font-size: 14px; color: var(--mut); margin: 8px 0; }
label.check { display: flex; gap: 10px; align-items: center; color: var(--ink); font-size: 16px; }
input[type=text], input[type=password], input:not([type]), select, textarea { display: block; width: 100%; margin-top: 4px; padding: 12px 14px; border: 2px solid #e3def7; border-radius: 12px; background: #fff; font-size: 17px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--p); }
input[type=range] { width: 100%; accent-color: var(--p); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--p); }
textarea { resize: vertical; margin: 10px 0; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; } .thumbs img { width: 72px; height: 96px; object-fit: cover; border-radius: 8px; border: 2px solid var(--pl); }

.chapter summary { font-weight: 650; cursor: pointer; list-style: none; display: flex; gap: 10px; align-items: center; }
.chapter summary::-webkit-details-marker { display: none; }
.chnum { background: var(--pl); color: var(--p); width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-size: 15px; flex: none; }
.chapter ul { list-style: none; padding: 0; margin: 12px 0; }
.topic { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid #f0edf9; }
.topic .st { width: 24px; text-align: center; }
.chip { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--pl); color: var(--p); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.alt { background: #fff1db; color: #b26a00; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chapter-edit ul { padding-left: 0; list-style: none; margin: 6px 0 0; } .topics-edit li { display: flex; align-items: center; padding: 4px 0; font-size: 15px; }
.x { border: 0; background: none; color: var(--mut); font-size: 16px; cursor: pointer; padding: 4px 8px; }

.lesson-tools { margin-bottom: 12px; }
.speak { border: 0; background: var(--pl); color: var(--p); border-radius: 12px; min-height: 40px; padding: 6px 12px; font-size: 16px; font-weight: 600; cursor: pointer; flex: none; }
.speak.on { background: var(--p); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .7; } }
.intro { background: var(--pl); font-size: 18px; }
.lesson-sec h3 { color: var(--p); }
.visual { margin: 14px 0 0; text-align: center; }
.visual img, .visual canvas { max-width: 100%; border-radius: 12px; background: #fff; border: 1px solid #eee; }
.visual figcaption { font-size: 14px; color: var(--mut); margin-top: 6px; }
.visual table { border-collapse: collapse; margin: 0 auto; font-size: 16px; }
.visual th, .visual td { border: 1px solid #e3def7; padding: 8px 12px; } .visual th { background: var(--pl); }
.key { background: #fffbe8; } .life { background: #eaf7ff; }
.key ul { margin: 0; padding-left: 20px; }

.opts { display: grid; gap: 8px; margin: 12px 0; }
.opt { text-align: left; padding: 12px 14px; border-radius: 12px; border: 2px solid #e3def7; background: #fff; cursor: pointer; font-size: 17px; min-height: 48px; }
.opt p { margin: 0; }
.opt.sel { border-color: var(--p); background: var(--pl); }
.opt.right { border-color: var(--ok); background: var(--okl); } .opt.wrong { border-color: var(--bad); background: var(--badl); }
.why { background: #f7f6fc; border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.end-actions { margin-top: 18px; }

.problem .q { font-size: 19px; margin: 8px 0 12px; }
.answer-row { display: flex; align-items: center; gap: 8px; } .unit { font-weight: 600; color: var(--mut); }
.feedback { border-radius: 12px; margin-top: 10px; } .feedback:empty { display: none; }
.feedback.good { background: var(--okl); padding: 12px 14px; color: #146b3d; } .feedback.bad { background: var(--badl); padding: 12px 14px; color: #8a2f2c; }
.help-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hint { background: #fffbe8; border-radius: 10px; padding: 10px 12px; margin-top: 10px; font-size: 16px; }
.walk { background: #f7f6fc; border-radius: 12px; padding: 12px; margin: 12px 0; }
.walk h4 { margin: 0 0 8px; }
.step { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed #ddd8f2; animation: fadein .35s; }
.step .n { background: var(--p); color: #fff; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; flex: none; margin-top: 2px; }
.step p { margin: 0 0 4px; }
.final { background: var(--okl); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
.dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 12px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: #ddd8f2; } .dots i.cur { background: var(--p); } .dots i.ok { background: var(--ok); } .dots i.bad { background: #f0a19e; }
.summary { text-align: center; padding: 26px 16px; }
.good-b { border-left: 5px solid var(--ok); } .bad-b { border-left: 5px solid var(--bad); }
.seg { display: flex; gap: 6px; background: var(--pl); padding: 4px; border-radius: 14px; margin: 8px 0; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 6px; border-radius: 10px; font-weight: 600; color: var(--p); cursor: pointer; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px #0001; }
.clock { background: #ffffff22; padding: 6px 10px; border-radius: 10px; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #fff; border-radius: var(--r); padding: 14px 8px; text-align: center; box-shadow: 0 1px 3px #2a1f6a14; }
.stat b { display: block; font-size: 26px; color: var(--p); } .stat span { font-size: 13px; color: var(--mut); }
.test-row { display: flex; }
.score { font-weight: 750; padding: 6px 12px; border-radius: 10px; } .score.good { background: var(--okl); color: var(--ok); } .score.mid { background: #fff1db; color: #b26a00; } .score.low { background: var(--badl); color: var(--bad); }

.drawer { position: fixed; inset: 0; background: #1a133a66; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.drawer-panel { background: var(--bg); width: 100%; max-width: 720px; height: 85vh; border-radius: 22px 22px 0 0; display: flex; flex-direction: column; animation: up .25s; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.drawer-head { padding: 10px 12px 10px 18px; border-bottom: 1px solid #e6e1f7; } .drawer-head .icon-btn { background: var(--pl); color: var(--p); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; background: #fff; box-shadow: 0 1px 3px #0001; }
.msg p { margin: 0 0 6px; } .msg p:last-of-type { margin: 0; }
.msg.user { align-self: flex-end; background: var(--p); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; border-bottom-left-radius: 4px; } .msg .speak { margin-top: 6px; min-height: 32px; padding: 2px 10px; }
.typing { color: var(--mut); animation: pulse 1s infinite; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid #e6e1f7; background: #fff; }
.chat-input textarea { margin: 0; min-height: 48px; max-height: 120px; }
.mic { background: var(--pl) !important; color: var(--p) !important; width: 48px; height: 48px; } .mic.on { background: var(--bad) !important; color: #fff !important; animation: pulse 1s infinite; }

nav.bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: space-around; background: #fff; border-top: 1px solid #e6e1f7; padding: 6px 0; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
nav.bottom a { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--mut); padding: 4px 18px; border-radius: 12px; }
nav.bottom a span { font-size: 21px; } nav.bottom a.active { color: var(--p); background: var(--pl); }

.loading { text-align: center; padding: 50px 10px; color: var(--mut); }
.spinner { width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 50%; border: 5px solid var(--pl); border-top-color: var(--p); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: #2a2445; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; transition: .3s; z-index: 30; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.katex { font-size: 1.08em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
