:root {
  --bg: #f4f5f1; --card: #ffffff; --ink: #18201c; --muted: #5d6762; --line: #e4e7e1; --sunk: #eef0eb;
  --acc: #0f6b52; --acc-ink: #ffffff; --acc-soft: #e1f1ea; --red: #c43440; --red-soft: #fbe6e8;
  --gold: #fff0b3; --tip: #e9f2fc; --tip-ink: #1d4c82; --mn: #f3eafb; --mn-ink: #5a2c80;
  --note: #fdf1e3; --note-ink: #874a0b;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 14px rgba(20, 30, 25, .05);
  --r: 16px; --nav-h: 64px;
  font-family: "Noto Sans Bengali", "Kohinoor Bangla", "Hind Siliguri", "Nirmala UI", "Vrinda", system-ui, sans-serif;
}
[data-theme=dark] {
  --bg: #0f1312; --card: #171d1a; --ink: #e7ebe8; --muted: #98a29d; --line: #263029; --sunk: #131816;
  --acc: #52c79d; --acc-ink: #0b1a14; --acc-soft: #183a2d; --red: #ff6f7a; --red-soft: #3a1d21;
  --gold: #4b4216; --tip: #18283a; --tip-ink: #a9ccf4; --mn: #2a2136; --mn-ink: #d9bcf6;
  --note: #382a18; --note-ink: #f2c690;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 17px; line-height: 1.7; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
[data-fs=s] body { font-size: 15px; }
[data-fs=l] body { font-size: 19px; }
a { color: var(--acc); text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
mark { background: var(--gold); color: inherit; padding: 0 3px; border-radius: 4px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); }
.top h1 { flex: 1; margin: 0 4px; font-size: 1.06em; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .back, .top .search-btn { background: none; border: 0; color: var(--ink); width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; }
.top .back:hover, .top .search-btn:hover { background: var(--sunk); }
.top .back { display: none; }
.top .back.show { display: grid; }
.readbar { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; opacity: 0; transition: opacity .2s; }
.readbar.on { opacity: 1; }
.readbar i { display: block; height: 100%; width: 0; background: var(--acc); border-radius: 0 3px 3px 0; }

/* bottom nav / desktop sidebar */
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 6px 6px env(safe-area-inset-bottom); background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); border-radius: 14px; }
.nav a svg { width: 22px; height: 22px; padding: 2px 14px; box-sizing: content-box; border-radius: 999px; transition: background .2s; }
.nav a.on { color: var(--acc); font-weight: 700; }
.nav a.on svg { background: var(--acc-soft); }
main { max-width: 820px; margin: 0 auto; padding: 16px 14px calc(var(--nav-h) + 30px); animation: in .25s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 84px 12px 12px; border-top: 0; border-right: 1px solid var(--line); background: var(--card); }
  .nav a { flex: 0; flex-direction: row; gap: 12px; justify-content: flex-start; padding: 10px 14px; font-size: 16px; }
  .nav a svg { padding: 0; background: none !important; }
  .nav a:hover { background: var(--sunk); }
  .nav a.on { background: var(--acc-soft); }
  .top { padding-left: 234px; }
  main { margin-left: 220px; margin-right: auto; max-width: 880px; padding: 28px 36px 60px; }
  @media (min-width: 1300px) { main { margin-left: calc(220px + (100vw - 220px - 880px) / 2); } }
}

.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin: 0 0 12px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); color: var(--ink); }
.stat b { display: block; font-size: 1.55em; line-height: 1.3; color: var(--acc); }
.stat small { color: var(--muted); }
a.stat, a.cat, a.topic { transition: transform .15s, border-color .15s; }
a.stat:hover, a.cat:hover, a.topic:hover { border-color: color-mix(in srgb, var(--acc) 45%, var(--line)); }
a.stat:active, a.cat:active, a.topic:active { transform: scale(.985); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 20px; border-radius: 14px;
  border: 1px solid var(--acc); background: var(--acc); color: var(--acc-ink); font-weight: 600; transition: transform .1s, filter .15s; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--acc); }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
[data-theme=dark] .btn.red { color: #1d0b0d; }
.btn:disabled { opacity: .45; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: .86em; }
h2 { font-size: 1.15em; margin: 24px 0 10px; }
.sec-title { display: flex; justify-content: space-between; align-items: baseline; }

/* home: streak + week */
.week { display: flex; gap: 18px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.week-h { display: flex; gap: 26px; }
.week-h b { display: block; font-size: 1.55em; line-height: 1.3; }
.week-h small { color: var(--muted); }
.week-h .fire b { color: #d9731a; }
.bars { display: flex; gap: 8px; align-items: flex-end; height: 64px; }
.bars div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; width: 22px; }
.bars i { display: block; width: 100%; min-height: 4px; border-radius: 6px; background: var(--acc-soft); }
.bars i.on { background: var(--acc); }
.bars span { font-size: 11px; color: var(--muted); line-height: 1.6; }
.bars .today span { color: var(--acc); font-weight: 700; }

.cats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.cat { display: block; position: relative; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; color: var(--ink); box-shadow: var(--shadow); }
.cat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--acc)); }
.cat:nth-child(2) { --c: #2f6fb5; }
.cat:nth-child(3) { --c: #9a4fc2; }
.cat b { font-size: 1.15em; }
.bar { height: 7px; background: var(--sunk); border-radius: 7px; overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; background: var(--c, var(--acc)); border-radius: 7px; transition: width .4s ease; }

.topic { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 8px; color: var(--ink); }
.topic .n { flex: 0 0 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--acc-soft); color: var(--acc); font-size: 14px; font-weight: 700; }
.topic.done .n { background: var(--acc); color: var(--acc-ink); }
.topic .t { flex: 1; min-width: 0; }
.topic .t b { display: block; font-weight: 600; }
.topic .t small { color: var(--muted); font-size: .8em; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lecture-h { font-size: .82em; font-weight: 600; color: var(--muted); margin: 18px 4px 6px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 0 0 16px; padding: 4px; position: sticky; top: 60px; z-index: 4;
  background: var(--sunk); border: 1px solid var(--line); border-radius: 14px; scrollbar-width: none; box-shadow: 0 -12px 0 var(--bg); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: 1 0 auto; text-align: center; padding: 6px 14px; border-radius: 10px; color: var(--muted); font-size: .9em; font-weight: 600; white-space: nowrap; }
.tabs a.on { background: var(--card); color: var(--acc); box-shadow: var(--shadow); }

/* learn blocks */
.learn h3 { font-size: 1.12em; margin: 28px 0 8px; padding-left: 12px; border-left: 4px solid var(--acc); line-height: 1.5; }
.learn p { margin: 8px 0; }
.learn ul { padding-left: 22px; margin: 8px 0; }
.learn li { margin: 4px 0; }
.box { border-radius: 14px; padding: 12px 16px; margin: 14px 0; }
.box .lbl { display: block; font-size: .78em; font-weight: 700; margin-bottom: 2px; opacity: .85; }
.box.tip { background: var(--tip); color: var(--tip-ink); }
.box.note { background: var(--note); color: var(--note-ink); }
.box.mn { background: var(--mn); color: var(--mn-ink); }
.box.mn .mtext { font-size: 1.12em; font-weight: 700; }
.tbl { overflow-x: auto; margin: 14px 0; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: .9em; background: var(--card); }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--acc-soft); color: var(--acc); font-weight: 700; white-space: nowrap; }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--sunk) 60%, transparent); }
tr:last-child td { border-bottom: 0; }
.tl { list-style: none; padding: 0 0 0 18px !important; border-left: 3px solid var(--acc-soft); margin: 14px 0 14px 6px !important; }
.tl li { position: relative; margin: 0 0 12px !important; }
.tl li::before { content: ""; position: absolute; left: -26px; top: 8px; width: 13px; height: 13px; border-radius: 50%; background: var(--acc); border: 3px solid var(--bg); }
.tl .when { font-weight: 700; color: var(--acc); display: block; font-size: .9em; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree { margin: 14px 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; overflow-x: auto; box-shadow: var(--shadow); }
.tree ul { padding-left: 22px !important; margin: 0 !important; }
.tree li { position: relative; padding: 4px 0 4px 14px; margin: 0 !important; }
.tree ul > li::before { content: ""; position: absolute; left: -8px; top: 0; bottom: 0; border-left: 2px solid var(--line); }
.tree ul > li:last-child::before { bottom: auto; height: 20px; }
.tree ul > li::after { content: ""; position: absolute; left: -8px; top: 20px; width: 18px; border-top: 2px solid var(--line); }
.tree .node { display: inline-block; padding: 3px 12px; border-radius: 9px; background: var(--acc-soft); color: var(--ink); font-size: .9em; }
.tree > li > .node { background: var(--acc); color: var(--acc-ink); font-weight: 700; }
.bd { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin: 12px 0; }
.bd > div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow); }
.bd .w { font-size: 1.18em; font-weight: 700; }
.bd .eq { margin-top: 2px; }
.bd .eq span { display: inline-block; padding: 0 8px; margin: 2px 0; border-radius: 7px; background: var(--acc-soft); }
.bd .eq .op { background: none; color: var(--muted); padding: 0 2px; }
.bd .rule { display: block; font-size: .78em; color: var(--muted); margin-top: 4px; }
.cmp { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin: 12px 0; }
.cmp > div { background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--acc); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.cmp > div:nth-child(2) { border-top-color: #2f6fb5; }
.cmp > div:nth-child(3) { border-top-color: #9a4fc2; }
.cmp b { display: block; color: var(--acc); margin-bottom: 4px; }
.cmp ul { padding-left: 18px !important; }
.steps { counter-reset: s; list-style: none; padding: 0 !important; }
.steps li { counter-increment: s; position: relative; padding-left: 42px; min-height: 30px; margin: 8px 0 !important; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 1px; width: 28px; height: 28px; border-radius: 9px; background: var(--acc); color: var(--acc-ink); display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.learn-end { margin-top: 32px; text-align: center; }
.toggles { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 10px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: .88em; color: var(--muted); }
.toggle input { accent-color: var(--acc); width: 18px; height: 18px; }
.nextprev { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; text-align: left; }
.nextprev a { display: block; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); font-size: .9em; }
.nextprev a small { display: block; color: var(--muted); font-size: .8em; }
.nextprev a.nx { text-align: right; grid-column: 2; }

/* self-test: highlighted facts and mnemonics hidden until tapped */
.learn.hide mark, .learn.hide .mtext { color: transparent; background: var(--line); cursor: pointer; border-radius: 5px; user-select: none; }
.learn.hide mark b, .learn.hide .mtext b { color: transparent; }
.learn.hide .mtext { display: inline-block; padding: 0 8px; }
.learn.hide mark.rev, .learn.hide .mtext.rev, .learn.hide .rev b { color: inherit; user-select: auto; }
.learn.hide mark.rev { background: var(--gold); }
.learn.hide .mtext.rev { background: transparent; padding: 0; }

/* quiz */
.q { font-size: 1.06em; font-weight: 600; margin-bottom: 14px; }
.q .src { display: inline-block; font-size: 12px; font-weight: 500; background: var(--gold); padding: 0 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); min-height: 52px; transition: border-color .15s, background .15s, transform .1s; }
.opt:not(:disabled):hover { border-color: color-mix(in srgb, var(--acc) 50%, var(--line)); }
.opt:not(:disabled):active { transform: scale(.99); }
.opt .k { flex: 0 0 28px; height: 28px; border-radius: 9px; background: var(--sunk); display: grid; place-items: center; font-size: 14px; font-weight: 700; color: var(--muted); }
.opt.ok { border-color: var(--acc); background: var(--acc-soft); }
.opt.ok .k { background: var(--acc); color: var(--acc-ink); }
.opt.bad { border-color: var(--red); background: var(--red-soft); animation: shake .3s; }
.opt.bad .k { background: var(--red); color: #fff; }
.opt.pick { border-color: var(--acc); background: var(--acc-soft); }
.opt.pick .k { background: var(--acc); color: var(--acc-ink); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.expl { margin-top: 12px; padding: 12px 16px; border-radius: 14px; background: var(--tip); color: var(--tip-ink); font-size: .9em; animation: in .2s ease-out; }
.prog { display: flex; justify-content: space-between; color: var(--muted); font-size: .84em; margin-bottom: 8px; }
.prog .hot { color: #d9731a; font-weight: 700; }
.score-big { font-size: 46px; font-weight: 800; color: var(--acc); text-align: center; }
.keys-hint { display: none; text-align: center; margin-top: 10px; }
@media (hover: hover) and (pointer: fine) { .keys-hint { display: block; } }
kbd { font: inherit; font-size: 12px; padding: 0 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--card); }
.ring { --p: 0; width: 132px; height: 132px; margin: 4px auto 10px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--acc) calc(var(--p) * 1%), var(--sunk) 0); }
.ring div { width: 106px; height: 106px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-size: 26px; font-weight: 800; color: var(--acc); }

/* flash */
.flash { perspective: 1000px; margin: 8px 0 16px; cursor: pointer; touch-action: pan-y; user-select: none; }
.flash.drag { transition: none; }
.flash.snap { transition: transform .2s; }
.flash .in { position: relative; min-height: 240px; transition: transform .45s; transform-style: preserve-3d; }
.flash.flip .in { transform: rotateY(180deg); }
.flash .side { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-items: center; text-align: center;
  padding: 24px; border-radius: 22px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 1.18em; overflow: auto; }
.flash .back { transform: rotateY(180deg); background: var(--acc-soft); font-weight: 600; }
.flash .hint { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 12px; color: var(--muted); font-weight: 400; }
.flash .stamp { position: absolute; top: 14px; padding: 2px 12px; border-radius: 8px; font-size: 14px; font-weight: 700; opacity: 0; z-index: 2; pointer-events: none; }
.flash .stamp.k { right: 14px; background: var(--acc); color: var(--acc-ink); }
.flash .stamp.a { left: 14px; background: var(--red); color: #fff; }
@media (prefers-reduced-motion: reduce) { .flash .in, main, .expl, .opt.bad { transition: none; animation: none; } }

textarea { width: 100%; min-height: 110px; font: inherit; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--sunk); color: var(--ink); }
textarea:focus { background: var(--card); }
.model { margin-top: 12px; padding: 12px 16px; border-radius: 14px; background: var(--acc-soft); animation: in .2s ease-out; }
input[type=search], select { width: 100%; font: inherit; padding: 11px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.chip.on { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 14px; }
.seg button { border: 0; background: none; padding: 6px 16px; border-radius: 10px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--acc); box-shadow: var(--shadow); }
.timer { position: sticky; top: 64px; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px;
  padding: 8px 12px; font-weight: 700; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.timer button { border: 1px solid var(--line); background: var(--sunk); border-radius: 10px; padding: 2px 12px; font-size: .86em; }
.qnav { display: none; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; width: 100%; max-height: 40vh; overflow: auto; padding-top: 8px; }
.timer.open { flex-wrap: wrap; }
.timer.open .qnav { display: grid; }
.qnav a { display: grid; place-items: center; height: 36px; border-radius: 9px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600; }
.qnav a.a { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.exam-q { scroll-margin-top: 130px; }
.res-hit { padding: 12px 4px; border-bottom: 1px solid var(--line); display: block; color: var(--ink); }
.res-hit small { color: var(--muted); display: block; }
:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }
.say{border:0;background:var(--chip,rgba(0,0,0,.06));border-radius:999px;padding:4px 9px;margin-left:8px;font-size:.9em;cursor:pointer;vertical-align:middle}
.flash .say{position:absolute;top:10px;right:10px;margin:0}
.q b{text-decoration:underline;text-underline-offset:3px}
