:root {
  --bg: #fff8ee;
  --card: #ffffff;
  --ink: #2b2d42;
  --muted: #6b6f85;
  --line: #ece3d4;
  --brand: #ff7a45;
  --brand-dark: #e85d2a;
  --blue: #3a86ff;
  --green: #2bb673;
  --green-bg: #e3f8ec;
  --red: #ef476f;
  --red-bg: #fde6ec;
  --yellow: #ffbe0b;
  --yellow-bg: #fff4cc;
  --purple: #8338ec;
  --radius: 18px;
  --shadow: 0 4px 0 rgba(0,0,0,.06), 0 8px 24px rgba(80,60,20,.08);
  font-size: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .brand, .btn, .big-num { font-family: "Baloo 2", "Nunito", sans-serif; }
h1 { font-size: 1.9rem; margin: .2em 0 .4em; line-height: 1.2; }
h2 { font-size: 1.4rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1em 0 .4em; }
a { color: var(--blue); }
img { max-width: 100%; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 2px solid var(--line);
}
.brand { font-size: 1.35rem; font-weight: 800; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 6px; }
.logo { font-size: 1.6rem; }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.grade-badge { background: var(--blue); color: #fff; padding: 2px 12px; border-radius: 99px; font-weight: 800; cursor: pointer; }
.grade-badge:empty { display: none; }
.stars { background: var(--yellow-bg); padding: 2px 12px; border-radius: 99px; font-weight: 800; }

main { max-width: 960px; margin: 0 auto; padding: 16px 16px 80px; }

/* cards & grids */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink);
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
  border: 3px solid transparent; transition: transform .1s, border-color .1s; cursor: pointer;
}
.tile:hover { transform: translateY(-2px); border-color: var(--brand); }
.tile .emoji { font-size: 2.2rem; line-height: 1; }
.tile .t { font-family: "Baloo 2", sans-serif; font-weight: 800; font-size: 1.15rem; line-height: 1.2; }
.tile .s { color: var(--muted); font-size: .85rem; }
.tile.big { padding: 22px; }
.tile.c1 { background: #fff1e8; } .tile.c2 { background: #e8f1ff; } .tile.c3 { background: #eafaf1; } .tile.c4 { background: #f3ecff; }
.tile.disabled { opacity: .45; pointer-events: none; }

.hero { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.hero .owl { font-size: 4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 14px; padding: 10px 22px; font-size: 1.1rem; font-weight: 800;
  background: var(--brand); color: #fff; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 0 var(--brand-dark); transition: transform .05s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.blue { background: var(--blue); box-shadow: 0 4px 0 #2563c9; }
.btn.green { background: var(--green); box-shadow: 0 4px 0 #1d8a55; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* progress */
.bar { height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }
.pill { display: inline-block; padding: 1px 10px; border-radius: 99px; font-size: .8rem; font-weight: 800; background: var(--line); color: var(--ink); }
.pill.green { background: var(--green-bg); color: #137a48; }
.pill.red { background: var(--red-bg); color: #b0244a; }
.pill.yellow { background: var(--yellow-bg); color: #8a6400; }

/* lesson content */
.lesson-part { margin-bottom: 18px; }
.lesson-part h3 { color: var(--brand-dark); }
.vd { background: #eef5ff; border-left: 6px solid var(--blue); padding: 10px 14px; border-radius: 10px; margin: 10px 0; }
.meo { background: var(--yellow-bg); border-left: 6px solid var(--yellow); padding: 10px 14px; border-radius: 10px; margin: 10px 0; }
.chu-y { background: var(--red-bg); border-left: 6px solid var(--red); padding: 10px 14px; border-radius: 10px; margin: 10px 0; }
.lesson-part table { border-collapse: collapse; margin: 8px 0; }
.lesson-part td, .lesson-part th { border: 1px solid var(--line); padding: 4px 10px; text-align: center; }
.lesson-part th { background: #fff1e8; }
pre.cot { font-family: "Courier New", monospace; font-size: 1.2rem; line-height: 1.35; background: #fff; display: inline-block; padding: 6px 14px; border-radius: 8px; border: 1px dashed var(--line); text-align: right; }
.lesson-part svg { max-width: 100%; height: auto; }

/* question */
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.q-num { font-family: "Baloo 2"; font-weight: 800; font-size: 1.1rem; background: var(--brand); color: #fff; border-radius: 12px; padding: 0 12px; }
.q-text { font-size: 1.25rem; font-weight: 600; margin: 6px 0 12px; white-space: pre-line; }
.q-img { display: block; margin: 8px auto 14px; max-height: 420px; background: #fff; border-radius: 10px; border: 1px solid var(--line); padding: 6px; }
.choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choice {
  display: flex; align-items: center; gap: 10px; font-size: 1.2rem; font-weight: 700; text-align: left;
  background: #fff; border: 3px solid var(--line); border-radius: 14px; padding: 10px 14px; cursor: pointer; color: var(--ink);
  font-family: inherit;
}
.choice .letter { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--line); font-family: "Baloo 2"; font-weight: 800; flex: none; }
.choice:hover { border-color: var(--blue); }
.choice.sel { border-color: var(--blue); background: #eef5ff; }
.choice.sel .letter { background: var(--blue); color: #fff; }
.choice.right { border-color: var(--green); background: var(--green-bg); }
.choice.right .letter { background: var(--green); color: #fff; }
.choice.wrong { border-color: var(--red); background: var(--red-bg); }
.choice.wrong .letter { background: var(--red); color: #fff; }
.choice[disabled] { cursor: default; }
.num-answer { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.num-answer input {
  font-size: 1.5rem; font-weight: 800; width: 220px; max-width: 100%; padding: 8px 14px; border-radius: 14px;
  border: 3px solid var(--line); font-family: "Baloo 2", sans-serif; text-align: center;
}
.num-answer input:focus { outline: none; border-color: var(--blue); }
.num-answer input.right { border-color: var(--green); background: var(--green-bg); }
.num-answer input.wrong { border-color: var(--red); background: var(--red-bg); }
.unit { font-weight: 700; font-size: 1.15rem; }
.feedback { margin-top: 14px; padding: 12px 16px; border-radius: 14px; font-weight: 600; }
.feedback.ok { background: var(--green-bg); }
.feedback.no { background: var(--red-bg); }
.feedback .fb-title { font-family: "Baloo 2"; font-size: 1.3rem; font-weight: 800; }
.q-nav { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* exam */
.exam-top { position: sticky; top: 56px; z-index: 5; background: var(--bg); padding: 8px 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.timer { font-family: "Baloo 2"; font-size: 1.4rem; font-weight: 800; background: #fff; border-radius: 12px; padding: 2px 14px; box-shadow: var(--shadow); }
.timer.low { color: var(--red); }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.navgrid button {
  height: 40px; border-radius: 10px; border: 2px solid var(--line); background: #fff; font-weight: 800; cursor: pointer; font-family: inherit; color: var(--ink);
}
.navgrid button.done { background: #dbe8ff; border-color: var(--blue); }
.navgrid button.cur { outline: 3px solid var(--brand); outline-offset: 1px; }
.navgrid button.right { background: var(--green-bg); border-color: var(--green); }
.navgrid button.wrong { background: var(--red-bg); border-color: var(--red); }

.score-box { text-align: center; }
.big-num { font-size: 3.4rem; font-weight: 800; line-height: 1; color: var(--brand); }
.review-item { border-top: 2px dashed var(--line); padding-top: 14px; margin-top: 14px; }

/* plan */
.week { margin-bottom: 14px; }
.days { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.day { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.day.done { background: var(--green-bg); border-color: var(--green); }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 3px #ffd9c7; }
.day input { width: 22px; height: 22px; margin-top: 3px; accent-color: var(--green); flex: none; }
.day .dn { font-weight: 800; }

table.stats { width: 100%; border-collapse: collapse; }
table.stats td, table.stats th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }

/* confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 600px) {
  :root { font-size: 16px; }
  .card { padding: 16px; }
  .choices { grid-template-columns: 1fr 1fr; }
  .exam-top { top: 52px; }
}
@media print { .topbar, .q-nav, .btn { display: none; } }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .85em; line-height: 1.05; margin: 0 2px; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 2px; }

/* bottom navigation (mobile-first) */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 2px 8px;
  text-decoration: none; color: var(--muted); font-weight: 800; font-size: .72rem;
}
.bottomnav a span { font-size: 1.45rem; line-height: 1.2; filter: grayscale(.6); }
.bottomnav a.active { color: var(--brand-dark); }
.bottomnav a.active span { filter: none; transform: scale(1.12); }
body.exam-mode .bottomnav { display: none; }
main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.years { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
@media (min-width: 900px) {
  .bottomnav { left: 50%; right: auto; transform: translateX(-50%); width: 560px; bottom: 14px; border: 2px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
}
@media (max-width: 600px) {
  h1 { font-size: 1.5rem; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 14px; }
  .tile .emoji { font-size: 1.8rem; }
  .tile .t { font-size: 1.02rem; }
  .hero .owl { font-size: 2.6rem; }
  .q-text { font-size: 1.12rem; }
  .q-img { max-height: 320px; }
  .btn { padding: 10px 16px; font-size: 1rem; }
  .q-nav .btn { flex: 1; }
  .num-answer input { width: 100%; }
  .brand { font-size: 1.1rem; }
  table.stats td, table.stats th { padding: 6px 3px; font-size: .88rem; }
}

/* lesson card deck */
.dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); cursor: pointer; transition: all .2s; }
.dots i.past { background: #ffc9b0; }
.dots i.on { background: var(--brand); width: 26px; border-radius: 99px; }
.deck-card { min-height: 380px; animation: cardIn .25s ease; }
@keyframes cardIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.deck-card h2 { margin-top: 0; }
.card-emoji { font-size: 3rem; line-height: 1; margin-bottom: 6px; }
.card-body { font-size: 1.1rem; }
.deck-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.big-list { padding-left: 0; list-style: none; font-size: 1.15rem; }
.big-list li { background: #fff8ee; border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.lead { font-size: 1.12rem; }
.anim-stage { background: #fffdf8; border: 2px dashed var(--line); border-radius: 16px; padding: 12px; text-align: center; overflow-x: auto; }
.anim-note { margin: 12px 0; font-size: 1.12rem; background: #eef5ff; border-left: 6px solid var(--blue); border-radius: 10px; padding: 10px 14px; animation: cardIn .25s ease; }
.anim-ctl { margin-top: 4px; }
svg.fig { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; }
svg.fig-sq { max-width: 300px; }
.eq { font-family: "Baloo 2", sans-serif; font-size: 1.6rem; font-weight: 800; margin-top: 10px; color: var(--ink); }
.eq .du { color: var(--red); }
.terms { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.terms span { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 4px 10px; font-size: .95rem; }
.rule { background: var(--yellow-bg); border-radius: 14px; padding: 12px 16px; margin: 10px 0; font-size: 1.1rem; }
.table-wrap { overflow-x: auto; }
table.mini { border-collapse: collapse; margin: 8px 0; font-size: 1.02rem; }
table.mini td, table.mini th { border: 2px solid var(--line); padding: 8px 10px; text-align: left; }
table.mini th { background: #fff1e8; }
table.mini td.hl { background: var(--green-bg); font-weight: 800; }
table.mini td.no { color: var(--muted); text-decoration: line-through; }
.problem { background: #fff1e8; border-radius: 14px; padding: 12px 16px; font-size: 1.12rem; margin-bottom: 10px; }
ol.steps { padding-left: 1.3em; font-size: 1.1rem; }
ol.steps li { margin: 8px 0; animation: cardIn .25s ease; }
.sources { margin-top: 18px; text-align: left; font-size: .9rem; }
/* long division (đặt tính chia) */
.ld { display: inline-flex; font-family: "Courier New", monospace; font-size: 1.9rem; font-weight: 700; line-height: 1.25; text-align: left; }
.ld-left { padding-right: 10px; white-space: pre; }
.ld-left .ld-line { text-decoration: underline; text-underline-offset: 6px; }
.ld-right { border-left: 3px solid var(--ink); }
.ld-divisor { border-bottom: 3px solid var(--ink); padding: 0 12px; }
.ld-q { padding: 0 12px; color: var(--brand-dark); }
@media (max-width: 600px) {
  .deck-card { min-height: 0; }
  .ld { font-size: 1.6rem; }
  .eq { font-size: 1.3rem; }
  .deck-nav .btn { flex: 1; }
}
@media (max-width: 600px) {
  .num-answer { flex-wrap: nowrap; }
  .num-answer input { width: auto; flex: 1; min-width: 0; }
}

/* vertical lesson page */
.lesson-hero { display: flex; gap: 14px; align-items: flex-start; margin: 8px 0 14px; }
.lesson-emoji { font-size: 3.2rem; line-height: 1; }
.lesson-hero h1 { margin: 0 0 6px; }
.lesson-sec { scroll-margin-top: 70px; }
.sec-title { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.sec-num { flex: none; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 1.05rem; }
.frame { position: relative; margin-bottom: 14px; }
.frame-num { position: absolute; top: 8px; left: 8px; z-index: 1; width: 26px; height: 26px; border-radius: 50%; background: var(--blue); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: .9rem; }
.compact-anim { display: grid; gap: 12px; grid-template-columns: auto 1fr; align-items: start; }
.compact-anim .anim-stage { padding: 16px 20px; }
.qblock { border-top: 2px dashed var(--line); padding-top: 14px; margin-top: 14px; }
.qblock:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
@media (max-width: 600px) { .compact-anim { grid-template-columns: 1fr; } }
.topic-head { margin-top: 1.4em; }
.plan-links a { display: inline-block; margin: 2px 6px 0 0; }
