/* Bài tập Kèm Con — giấy sáng cho giao diện, bảng phấn cho đề bài (giống video) */
:root {
  --giay: #f7f3ea;
  --the: #ffffff;
  --muc: #23272a;
  --mo: #5f6870;
  --vien: #e4ddcd;
  --bang: #22382f;
  --bang-vien: #6b4a2b;
  --phan: #f4f1e6;
  --chinh: #1f7a4d;
  --chinh-dam: #155c39;
  --nhan: #f2c14e;
  --dung: #2f9e44;
  --sai: #e03131;
  /* màu nhấn trên nền sáng */
  --vang: #b7791f;
  --hong: #d6336c;
  --xanh: #1c7ed6;
  --bo: 14px;
  --bong: 0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(60,40,10,.07);
  --dau-cao: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--giay);
  color: var(--muc);
  font: 17px/1.55 "Be Vietnam Pro", system-ui, sans-serif;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; }
b { font-weight: 800; }
.nho { color: var(--mo); font-size: .92em; }
.vang { color: var(--vang); } .hong { color: var(--hong); } .xanh { color: var(--xanh); }

/* ── Đầu trang ── */
.dau {
  position: sticky; top: 0; z-index: 20;
  height: var(--dau-cao);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: var(--the);
  border-bottom: 1px solid var(--vien);
}
.thuong-hieu { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--muc); font-weight: 800; font-size: 19px; }
.thuong-hieu img { width: 36px; height: 36px; border-radius: 50%; }
.dau-phu { color: var(--mo); }
.ten-bai { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; padding-left: 14px; border-left: 1px solid var(--vien); }
.ten-bai small { color: var(--mo); font-size: 13px; }
.ten-bai b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Nút ── */
.nut {
  border: 0; border-radius: 999px; cursor: pointer;
  padding: 10px 18px; font-weight: 700;
  transition: transform .08s, background .15s, box-shadow .15s;
}
.nut:active { transform: translateY(1px); }
.nut:focus-visible, .nut-chon:focus-visible, .the-dang:focus-visible, [role=tab]:focus-visible { outline: 3px solid var(--nhan); outline-offset: 2px; }
.nut.chinh { background: var(--chinh); color: #fff; box-shadow: 0 3px 0 var(--chinh-dam); }
.nut.chinh:hover { background: var(--chinh-dam); }
.nut.phu { background: #efe9dc; }
.nut.phu:hover { background: #e6dfcd; }
.nut:disabled { opacity: .5; cursor: default; }
.nut.to { font-size: 19px; padding: 14px 26px; }
.nut-video { background: var(--bang); color: var(--phan); white-space: nowrap; }
.nut-hang { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.nut-hang.giua { justify-content: center; }

/* ── Khung 2 cột ── */
.khung {
  display: grid;
  grid-template-columns: minmax(340px, 41%) 1fr;
  max-width: 1380px; margin: 0 auto;
}
.tai-lieu {
  position: sticky; top: var(--dau-cao);
  height: calc(100vh - var(--dau-cao));
  display: flex; flex-direction: column;
  border-right: 1px solid var(--vien);
  background: #fbf8f1;
}
.tai-lieu-dau { display: flex; align-items: center; gap: 8px; padding: 12px 16px 0; }
.tab { display: flex; gap: 6px; flex: 1; }
.tab button {
  flex: 1; border: 0; cursor: pointer; padding: 10px 12px; border-radius: 10px 10px 0 0;
  background: transparent; color: var(--mo); font-weight: 700; border-bottom: 3px solid transparent;
}
.tab button[aria-selected=true] { color: var(--muc); border-bottom-color: var(--chinh); background: var(--the); }
.dong-tai-lieu { display: none; }
.tai-lieu-than { overflow-y: auto; padding: 16px; flex: 1; overscroll-behavior: contain; }
.bai-tap { padding: 24px clamp(16px, 3vw, 40px) 120px; min-width: 0; }

/* ── Thẻ ── */
.the {
  background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo);
  box-shadow: var(--bong); padding: 22px;
}
.the-kt {
  background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo);
  padding: 16px 18px; margin-bottom: 14px; scroll-margin-top: 12px;
}
.the-kt h3 { margin: 0 0 8px; font-size: 18px; }
.the-kt p { margin: 8px 0; }
.the-kt.nen { background: #f2f7f3; border-color: #cfe3d6; }
.nhan { display: inline-block; font-size: 12px; font-weight: 800; color: var(--chinh-dam); background: #d7ecdf; padding: 2px 8px; border-radius: 999px; margin-right: 8px; vertical-align: 2px; }
.the-kt.nhay { animation: nhay 1.6s ease-out; }
@keyframes nhay { 0%, 40% { box-shadow: 0 0 0 4px var(--nhan); } 100% { box-shadow: 0 0 0 0 transparent; } }
.quy-tac { padding-left: 22px; margin: 6px 0 12px; }
.quy-tac li { margin: 4px 0; }
.bang-nhin { border-collapse: collapse; width: 100%; font-size: 15px; }
.bang-nhin th, .bang-nhin td { border: 1px solid var(--vien); padding: 6px 10px; text-align: left; }
.bang-nhin th { background: #f5efe2; }
.anh-vd { border-radius: 10px; max-height: 160px; margin: 0 auto 10px; }

/* thử hàng của số */
.thu-hang label { display: block; font-weight: 600; }
.thu-hang input { font: 700 20px "Playpen Sans", cursive; width: 9ch; padding: 4px 10px; margin-left: 6px; border: 2px solid var(--vien); border-radius: 8px; }
.bang-hang { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.o-hang { display: flex; flex-direction: column; align-items: center; min-width: 64px; padding: 6px 4px; background: var(--bang); color: var(--phan); border-radius: 8px; }
.o-hang .cs { font: 700 28px "Playpen Sans", cursive; }
.o-hang small { font-size: 12px; opacity: .85; }

/* ── Bảng phấn ── */
.bang {
  --vang: #ffd75e; --hong: #ff9fb2; --xanh: #8fd3ff;
  background: var(--bang); color: var(--phan);
  border: 6px solid var(--bang-vien); border-radius: 10px;
  font-family: "Playpen Sans", cursive; font-weight: 500;
  padding: 14px 18px;
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.05), transparent 60%);
}
.bang b { font-weight: 700; }
.bang-de .de { font-size: clamp(20px, 2.4vw, 26px); margin: 0; line-height: 1.5; }
.bang-dong { font-size: 22px; border-width: 4px; padding: 8px 14px; }
.bang-hinh { margin-top: 8px; }
.bang.bang-hinh { padding: 6px 10px; border-width: 4px; }
.so { white-space: nowrap; }
.cs.vang, .cs.hong { font-weight: 700; }
.cs.vang { color: var(--vang); text-decoration: underline 3px; text-underline-offset: 5px; }
.cs.hong { color: var(--hong); }
.kq { color: var(--vang); font-weight: 700; border: 2px solid var(--vang); border-radius: 999px; padding: 0 10px; white-space: nowrap; }

/* tia số */
.tia-so { width: 100%; max-width: 560px; height: auto; display: block; margin: 0 auto; color: var(--muc); }
.bang .tia-so { color: var(--phan); }
.ts-truc, .ts-vach { stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.ts-mui { fill: currentColor; }
.ts-nhan { fill: currentColor; font: 600 20px "Playpen Sans", cursive; text-anchor: middle; }
.ts-nhan.vang { fill: var(--vang); font-weight: 700; font-size: 22px; }
.ts-nho { font: 700 18px "Playpen Sans", cursive; text-anchor: middle; }
.ts-nho.hong { fill: var(--hong); } .ts-nho.xanh { fill: var(--xanh); }
.ts-diem { fill: var(--vang); stroke: currentColor; stroke-width: 2; }
.ts-doan { stroke-width: 10; stroke-linecap: round; opacity: .75; }
.ts-doan.hong { stroke: var(--hong); } .ts-doan.xanh { stroke: var(--xanh); }

/* ── Màn mở đầu ── */
.mo-dau { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: center; }
.mo-dau img { border-radius: 12px; }
.cau-hoi-mo { font-size: 19px; margin: 0 0 16px; }
.tieu-de-nho { font-size: 18px; margin: 28px 0 12px; }
.luoi-dang { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.the-dang {
  text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  background: var(--the); border: 1px solid var(--vien); border-radius: 12px; padding: 14px 16px;
  transition: border-color .15s, transform .1s;
}
.the-dang:hover { border-color: var(--chinh); transform: translateY(-1px); }
.the-dang span { color: var(--mo); font-size: 14px; }

/* ── Câu hỏi ── */
.cau-dau { color: var(--mo); font-size: 15px; margin-bottom: 12px; }
.cham-hang { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.cham { width: 14px; height: 14px; border-radius: 50%; background: #e3dccb; display: inline-block; }
.cham.phu { width: 9px; height: 9px; margin-top: 2.5px; }
.cham.dang { box-shadow: 0 0 0 3px var(--nhan); }
.cham.dung { background: var(--dung); } .cham.tam { background: #f59f00; } .cham.sai { background: var(--sai); }
.tra-loi { margin-top: 18px; }
.o-so { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.o-so input {
  font: 700 26px "Playpen Sans", cursive; width: 10ch; padding: 8px 14px;
  border: 3px solid var(--vien); border-radius: 12px; background: #fffdf8;
}
.o-so input:focus { outline: none; border-color: var(--chinh); }
.o-so input.dung { border-color: var(--dung); background: #ebfbee; }
.o-so input.sai { border-color: var(--sai); animation: lac .35s; }
.don-vi { font-weight: 700; font-size: 20px; }
@keyframes lac { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.lua-chon { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.nut-chon {
  font: 700 24px "Playpen Sans", cursive; padding: 14px; cursor: pointer;
  background: #fffdf8; border: 3px solid var(--vien); border-radius: 14px;
  transition: border-color .15s, background .15s;
}
.nut-chon:hover:not(:disabled) { border-color: var(--chinh); }
.nut-chon.dung { border-color: var(--dung); background: #ebfbee; color: #1b6e2c; }
.nut-chon.sai { border-color: var(--sai); background: #fff0f0; color: #a61e1e; animation: lac .35s; }
.nut-chon:disabled:not(.dung):not(.sai) { opacity: .55; }
.phan-hoi { margin-top: 14px; font-weight: 700; min-height: 1.5em; }
.phan-hoi.dung { color: var(--dung); font-size: 20px; animation: nay .4s; }
.phan-hoi.sai { color: var(--sai); }
.phan-hoi.nhac { color: var(--vang); }
@keyframes nay { 50% { transform: scale(1.06); } }
.goi-y p { background: #fff8e1; border-left: 4px solid var(--nhan); padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.phu-tro { margin-top: 8px; }
.loi-giai { margin-top: 18px; border-top: 2px dashed var(--vien); padding-top: 8px; }
.loi-giai h3 { margin: 6px 0 10px; }
.buoc { margin-bottom: 12px; }
.so-buoc { display: inline-block; font-size: 12px; font-weight: 800; color: var(--chinh-dam); background: #d7ecdf; padding: 1px 8px; border-radius: 999px; margin-bottom: 6px; }
.buoc .loi { margin: 6px 0 0; }
.buoc .bang + .loi { margin-top: 8px; }

/* ── Kết quả ── */
.ket-qua { text-align: center; }
.ket-qua h2 { margin: 6px 0; font-size: 30px; }
.sao-to { font-size: 54px; color: var(--nhan); letter-spacing: 6px; }
.sao-to span { color: #e3dccb; }

/* ── Trang chủ ── */
.trang-chu { max-width: 980px; margin: 0 auto; padding: 32px 20px 80px; }
.trang-chu h1 { margin: 0 0 6px; font-size: clamp(24px, 4vw, 34px); }
.nhom-lop h2 { margin: 28px 0 12px; }
.luoi-bai { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.the-bai {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit;
  background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 12px; box-shadow: var(--bong);
}
.the-bai:hover { border-color: var(--chinh); }
.the-bai img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; }
.the-bai div { display: flex; flex-direction: column; }
.the-bai small { color: var(--mo); }
.sao { color: var(--nhan); letter-spacing: 2px; }

/* ── Video ── */
.hop-video { border: 0; border-radius: var(--bo); padding: 14px; width: min(960px, 94vw); background: var(--the); }
.hop-video::backdrop { background: rgba(0,0,0,.6); }
.hop-video iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 10px; display: block; }
.hop-video form { text-align: right; margin-top: 10px; }
.hop-video code { background: #f1ece0; padding: 1px 5px; border-radius: 4px; }

.mo-tai-lieu { display: none; }

/* ── Điện thoại / máy tính bảng dọc: tài liệu thành ngăn kéo từ dưới lên ── */
@media (max-width: 900px) {
  .khung { display: block; }
  .ten-bai b { font-size: 16px; }
  .nut-video { padding: 8px 12px; font-size: 14px; }
  .dau-phu { display: none; }
  .tai-lieu {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30;
    height: 72vh; border: 0; border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgba(0,0,0,.18);
    transform: translateY(105%); transition: transform .28s ease;
  }
  .mo-tl .tai-lieu { transform: none; }
  .dong-tai-lieu { display: block; border: 0; background: #efe9dc; border-radius: 50%; width: 36px; height: 36px; cursor: pointer; }
  /* thanh đáy cố định: không đè lên nút trong bài (nội dung chừa đủ chỗ phía dưới) */
  .mo-tai-lieu {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    border: 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); font-weight: 800; cursor: pointer;
    background: var(--bang); color: var(--phan); box-shadow: 0 -4px 14px rgba(0,0,0,.15);
  }
  .mo-tl .mo-tai-lieu { display: none; }
  .bai-tap { padding: 16px 16px 96px; }
  .mo-dau { grid-template-columns: 1fr; }
  .mo-dau img { max-height: 200px; margin: 0 auto; }
  .the { padding: 16px; }
}
@media (max-width: 480px) {
  .thuong-hieu span { display: none; }
  .ten-bai { padding-left: 10px; }
  .lua-chon.bon { grid-template-columns: 1fr 1fr; }
  .nut-chon { font-size: 21px; padding: 12px 8px; }
}
/* ════════════ Hiệu ứng (16/11): Lottie, đề, chọn nhiều ════════════ */
.nut-tieng { border: 0; background: #efe9dc; border-radius: 50%; width: 40px; height: 40px; cursor: pointer; font-size: 18px; flex: none; }
.nut:not(:disabled):hover { transform: translateY(-1px); }
.nut.chinh:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--chinh-dam); }

/* Lottie một lần */
.fx { position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -50%); }
.fx.ca-man { inset: 0; transform: none; width: 100vw; height: 100vh; }
.toast {
  position: fixed; left: 50%; top: 84px; z-index: 70; transform: translateX(-50%);
  background: #2b2141; color: #ffd75e; font-weight: 800; padding: 10px 20px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: toast 1.9s ease both;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -16px) scale(.8); } 12%, 80% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -10px); } }

/* Vào màn: thẻ trượt lên, nút bật ra lần lượt */
.vao { animation: vao .38s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes vao { from { opacity: 0; transform: translateY(14px) scale(.985); } }
.vao .nut-chon, .the-de, .the-dang { animation: bat .4s cubic-bezier(.3,1.5,.5,1) both; animation-delay: var(--tre, 0ms); }
@keyframes bat { from { opacity: 0; transform: translateY(10px) scale(.92); } }
.buoc.moi { animation: vao .35s ease both; animation-delay: var(--tre, 0ms); }
.goi-y p.moi { animation: vao .3s ease both; }
.phan-hoi.sai { animation: lac .35s; }
.cham { transition: background .2s; }
.cham.dang { animation: nhip 1.2s ease-in-out infinite; }
@keyframes nhip { 50% { box-shadow: 0 0 0 6px rgba(242,193,78,.35); } }
.cham.bat { animation: chamBat .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes chamBat { 0% { transform: scale(.3); } 60% { transform: scale(1.5); } }
.nut-chon { transition: border-color .15s, background .15s, transform .1s, box-shadow .1s; }
.nut-chon:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 4px 0 var(--vien); }
.nut-chon.dung { animation: dungNay .45s cubic-bezier(.3,1.8,.5,1); }
@keyframes dungNay { 40% { transform: scale(1.08); } }
.o-so input.dung { animation: dungNay .45s; }

/* Chọn nhiều */
.chi-dan { margin: 0 0 8px; }
.lua-chon.ba { grid-template-columns: repeat(3, 1fr); }
.chip[aria-pressed=true] { border-color: var(--xanh); background: #e7f3ff; color: #134e8a; box-shadow: inset 0 0 0 2px var(--xanh); }
.chip[aria-pressed=true]::after, .chip.dung::after { content: " ✓"; }
.chip.thieu { border-style: dashed; border-color: var(--dung); color: #1b6e2c; }

/* Ô trống trong số (dạng điền chữ số) */
.o-trong { display: inline-block; width: .8em; height: 1.05em; vertical-align: -.15em; margin: 0 .06em; border: 3px dashed var(--vang); border-radius: 6px; animation: nhipO 1.4s ease-in-out infinite; }
@keyframes nhipO { 50% { background: rgba(255,215,94,.18); } }
.ts-vung { fill: rgba(143,211,255,.22); stroke: var(--xanh); stroke-width: 2; }
.the-kt .ts-vung { fill: rgba(28,126,214,.12); }

/* Màn mở đầu: nút bắt đầu có bàn tay chỉ */
.bat-dau-boc { position: relative; display: inline-block; }
.tay-chi { position: absolute; right: -34px; bottom: -40px; width: 72px; height: 72px; pointer-events: none; }
.tieu-de-nho small { font-weight: 400; color: var(--mo); font-size: 14px; }

/* Các đề */
.luoi-de { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.the-de {
  text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; position: relative;
  background: var(--the); border: 2px solid var(--vien); border-radius: 14px; padding: 14px 16px 12px;
  box-shadow: 0 3px 0 var(--vien); transition: transform .12s, border-color .15s, box-shadow .12s;
}
.the-de:hover { transform: translateY(-2px); border-color: var(--chinh); box-shadow: 0 5px 0 #cfe3d6; }
.the-de:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--vien); }
.the-de.khoa { background: #f3efe6; color: var(--mo); }
.the-de.khoa:hover { border-color: var(--vien); box-shadow: 0 3px 0 var(--vien); }
.the-de.goi-y-de { border-color: var(--nhan); animation: bat .4s cubic-bezier(.3,1.5,.5,1) both, sang 2s ease-in-out infinite; animation-delay: var(--tre, 0ms), 1s; }
@keyframes sang { 50% { box-shadow: 0 3px 0 var(--vien), 0 0 0 5px rgba(242,193,78,.35); } }
.de-dau { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.de-dau b { font-size: 19px; }
.muc { font-style: normal; font-size: 12px; font-weight: 800; padding: 2px 9px; border-radius: 999px; background: #d7ecdf; color: var(--chinh-dam); white-space: nowrap; }
.muc-1, .muc-2 { background: #dbeafe; color: #1e4f8f; }
.muc-3 { background: #ffe8cc; color: #a3500b; }
.muc-4 { background: #f3d9fa; color: #7b2a8f; }
.de-mota { font-size: 14px; color: var(--mo); flex: 1; }
.de-chan { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.de-chan .sao { font-size: 20px; }
.sao-xam { color: #e3dccb; }
.o-khoa { font-size: 20px; display: inline-block; width: 28px; text-align: center; }

/* Kết quả */
.ten-de-kq { margin: 0; }
.ruong { width: 150px; height: 150px; margin: -6px auto -12px; }
.hang-sao { display: flex; justify-content: center; gap: 6px; margin: 4px 0 2px; }
.o-sao { width: 70px; height: 70px; display: grid; place-items: center; font-size: 52px; color: #e3dccb; line-height: 1; }
.chuoi-kq { color: #a3500b; margin: 2px 0; }
.mo-khoa, .cao-thu {
  display: flex; align-items: center; justify-content: center; gap: 6px; margin: 10px auto; padding: 6px 16px 6px 6px;
  background: #fff8e1; border: 2px solid var(--nhan); border-radius: 999px; width: fit-content; animation: vao .4s 1.9s both;
}
.lottie-khoa { width: 56px; height: 56px; }
.cao-thu { flex-direction: column; border-radius: 16px; padding: 8px 18px 12px; animation-delay: 2.2s; }
.cao-thu span { width: 110px; height: 110px; }
.cao-thu small { color: var(--mo); }

/* Trang chủ */
.the-bai { transition: transform .12s, border-color .15s; animation: bat .4s cubic-bezier(.3,1.5,.5,1) both; animation-delay: var(--tre, 0ms); }
.the-bai:hover { transform: translateY(-3px); }
.de-nho { font-size: 13px; color: var(--mo); }

@media (max-width: 900px) {
  .tay-chi { right: -18px; bottom: -36px; width: 60px; height: 60px; }
}
@media (max-width: 480px) {
  .lua-chon.ba { grid-template-columns: repeat(2, 1fr); }
  .luoi-de { grid-template-columns: 1fr 1fr; gap: 10px; }
  .the-de { padding: 12px; }
  .de-mota { display: none; }
  .nut-tieng { width: 36px; height: 36px; }
  .an-dt { display: none; }
  .dau { gap: 10px; padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
