/* Luyện HSG Toán 9 — giao diện "vở kẻ ngang, mực tím, bút đỏ của thầy"; đẹp trên điện thoại, máy tính bảng, máy tính */
:root {
  --giay: #fbfcfe;
  --o-li: #e3ecf7;
  --muc: #5b3fa0;        /* mực tím */
  --muc-nhat: #ece6f8;
  --chu: #1e2235;
  --phu: #5d6378;
  --dung: #1f8a4c;
  --dung-nhat: #e3f4ea;
  --but-do: #c62828;     /* bút đỏ của thầy */
  --do-nhat: #fdeaea;
  --cam: #d9730d;
  --cam-nhat: #fdf0e1;
  --da-quang: #ffe58f;   /* bút dạ quang */
  --vien: #d7deea;
  --bo: 14px;
  --font: "Be Vietnam Pro", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.55; color: var(--chu);
  background: var(--giay);
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; height: auto; }
a { color: var(--muc); }
:focus-visible { outline: 3px solid var(--da-quang); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.khung { max-width: 760px; margin: 0 auto; padding: 16px 16px 96px; }
.an { display: none !important; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 4px 0 12px; }
h2 { font-size: 1.2rem; line-height: 1.3; margin: 22px 0 8px; }
h3 { font-size: 1.05rem; margin: 16px 0 6px; }
p { margin: 6px 0; }
.nho { font-size: .9rem; color: var(--phu); }

/* nút */
.nut {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 2px solid var(--muc);
  background: #fff; color: var(--muc); font-weight: 600; cursor: pointer; text-decoration: none;
}
.nut.chinh { background: var(--muc); color: #fff; }
.nut.lon { width: 100%; min-height: 58px; font-size: 1.1rem; }
.nut.phu { border-color: var(--vien); color: var(--chu); }
.nut.nho-gon { min-height: 44px; padding: 6px 12px; font-size: .95rem; }
.nut:disabled { opacity: .5; cursor: default; }
.hang-nut { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* thanh dưới */
.thanh-duoi {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--vien);
  display: flex; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20;
}
.thanh-duoi a {
  flex: 1; text-align: center; text-decoration: none; color: var(--phu); font-size: .8rem; padding: 6px 2px;
  min-height: 48px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.thanh-duoi a .bieu-tuong { font-size: 1.3rem; line-height: 1; }
.thanh-duoi a.dang { color: var(--muc); font-weight: 700; }
.cham-do { position: absolute; top: 4px; right: 28%; width: 9px; height: 9px; border-radius: 50%; background: var(--but-do); }

/* đăng nhập */
.dang-nhap { max-width: 400px; margin: 10vh auto 0; padding: 0 20px; }
.dang-nhap h1 { color: var(--muc); }
.o-nhap { width: 100%; min-height: 52px; padding: 10px 14px; border: 2px solid var(--vien); border-radius: 12px; background: #fff; font-size: 1.1rem; }
.o-nhap:focus { border-color: var(--muc); outline: none; }
label.nhan { display: block; font-weight: 600; margin: 14px 0 6px; }
.bao-loi { color: var(--but-do); margin-top: 10px; min-height: 1.4em; }

/* Hôm nay */
.chao { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.dem-nguoc { text-align: right; }
.dem-nguoc b { display: block; font-size: 2.6rem; line-height: 1; color: var(--muc); font-weight: 800; }
.dem-nguoc span { font-size: .85rem; color: var(--phu); }
.dai-chi-so { display: flex; gap: 10px; margin: 16px 0 8px; }
.chi-so { flex: 1; border: 2px solid var(--vien); border-radius: var(--bo); padding: 10px 12px; background: #fff; }
.chi-so b { display: block; font-size: 1.6rem; line-height: 1.1; }
.chi-so span { font-size: .85rem; color: var(--phu); }
.thong-bao-lo-trinh { border-left: 5px solid var(--cam); background: var(--cam-nhat); padding: 10px 14px; border-radius: 0 12px 12px 0; margin: 12px 0; }
.thong-bao-lo-trinh.tot { border-color: var(--dung); background: var(--dung-nhat); }
.khoi { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--vien); }
.khoi .dau { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--vien); display: grid; place-items: center; font-weight: 700; flex: none; }
.khoi.xong .dau { background: var(--dung); border-color: var(--dung); color: #fff; }
.khoi.tiep .dau { border-color: var(--muc); color: var(--muc); }
.khoi .ten { flex: 1; }
.khoi .ten small { display: block; color: var(--phu); }
.thanh-tien { height: 8px; background: var(--o-li); border-radius: 8px; overflow: hidden; margin-top: 4px; }
.thanh-tien i { display: block; height: 100%; background: var(--muc); }
.nghi { text-align: center; padding: 28px 16px; border: 3px dashed var(--cam); border-radius: var(--bo); background: var(--cam-nhat); margin: 16px 0; }
.nghi b { font-size: 2.4rem; display: block; color: var(--cam); }

/* trang vở kẻ ngang có lề đỏ: thứ đáng nhớ nhất của ứng dụng */
.trang-vo {
  position: relative; background: #fff;
  border: 1px solid var(--vien); border-radius: 6px 14px 14px 6px;
  padding: 4px 18px 14px 52px; font-size: 1.08rem; box-shadow: 0 1px 0 var(--vien);
}
.trang-vo::before { content: ""; position: absolute; top: 0; bottom: 0; left: 38px; width: 2px; background: #ef9a9a; }
.dong { border-bottom: 1px solid #c3d3ee; padding: 9px 0 6px; min-height: 2.5em; line-height: 1.7; }
.dong.trong { min-height: 0; padding: 3px 0; border-bottom: 0; }
.dong.nho { font-size: .85rem; color: var(--phu); min-height: 0; }
.de-bai { color: var(--chu); }
.nhan-bai { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: .85rem; color: var(--phu); margin-bottom: 8px; }
.the-nho { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--muc-nhat); color: var(--muc); font-weight: 600; font-size: .8rem; }
.sao { color: var(--cam); letter-spacing: 1px; }
.buoc-da-lam { position: relative; color: var(--muc); }
.buoc-da-lam .dau-tick { position: absolute; left: -36px; top: 8px; font-weight: 800; color: var(--dung); font-size: 1.15rem; }
.buoc-da-lam.xem .dau-tick { color: var(--cam); }
.buoc-da-lam .tl { font-family: "Kalam", "Comic Sans MS", cursive, var(--font); font-size: 1.15rem; }
.buoc-da-lam .gt { color: var(--phu); font-size: .95rem; }
.buoc-hien-tai { margin-top: 10px; }
.buoc-hien-tai .hoi { font-weight: 600; margin-bottom: 10px; }
.so-buoc { font-size: .8rem; color: var(--phu); padding-top: 6px; }
.ban-phim { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-top: 8px; max-width: 460px; }
.ban-phim button { min-width: 0; min-height: 44px; border: 1px solid var(--vien); border-radius: 10px; background: #fff; font-weight: 600; cursor: pointer; }
.lua-chon { display: grid; gap: 10px; }
.lua-chon button {
  text-align: left; min-height: 52px; padding: 10px 14px; border: 2px solid var(--vien); border-radius: 12px; background: #fff; cursor: pointer;
}
.lua-chon button.chon { border-color: var(--muc); background: var(--muc-nhat); }
.sap-xep { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sap-xep li { display: flex; align-items: center; gap: 8px; border: 2px solid var(--vien); border-radius: 12px; background: #fff; padding: 8px; }
.sap-xep li.bo { opacity: .45; text-decoration: line-through; }
.sap-xep li .nd { flex: 1; }
.sap-xep li button { min-width: 44px; min-height: 44px; border: 1px solid var(--vien); border-radius: 10px; background: #fff; }
.phan-hoi { margin-top: 12px; padding: 10px 14px; border-radius: 12px; }
.phan-hoi.sai { background: var(--do-nhat); color: var(--but-do); border-left: 5px solid var(--but-do); }
.phan-hoi.dung { background: var(--dung-nhat); color: var(--dung); border-left: 5px solid var(--dung); }
.phan-hoi.goi-y { background: #fffbea; color: #7a5b00; border-left: 5px solid var(--da-quang); }
.dong-ho { font-weight: 800; color: var(--cam); }

/* kết quả bài */
.ket-qua { margin-top: 16px; border: 2px solid var(--muc); border-radius: var(--bo); padding: 14px 16px; background: #fff; }
.ket-qua .diem-to { font-size: 2.2rem; font-weight: 800; color: var(--muc); line-height: 1; }
.loi-giai { margin: 10px 0 0; padding-left: 22px; }
.loi-giai li { margin: 6px 0; }
.loi-giai small { color: var(--phu); }
.nhac-vo { margin-top: 10px; padding: 8px 12px; background: var(--da-quang); border-radius: 8px; font-weight: 600; }

/* học mới */
.the-ct { border: 2px solid var(--vien); border-radius: 12px; padding: 10px 14px; margin: 8px 0; background: #fff; }
.the-ct summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.the-ct .vd { color: var(--muc); margin-top: 6px; }
.y-tuong { border-left: 5px solid var(--muc); background: var(--muc-nhat); padding: 10px 14px; border-radius: 0 12px 12px 0; }
.ds-buoc { padding-left: 22px; }
.loi-hay-gap li { color: var(--but-do); }
.vi-du { margin: 14px 0; }
.dong-vd .vs { color: var(--phu); font-size: .9rem; font-style: italic; }

/* xếp hạng */
.tab { display: flex; gap: 8px; margin: 8px 0 14px; }
.tab button { flex: 1; min-height: 44px; border: 2px solid var(--vien); border-radius: 12px; background: #fff; font-weight: 600; }
.tab button.dang { border-color: var(--muc); background: var(--muc); color: #fff; }
.hang-cua-em b { font-size: 2.4rem; line-height: 1; color: var(--muc); font-weight: 800; }
.tang { color: var(--dung); font-weight: 700; }
.giam { color: var(--but-do); font-weight: 700; }
.bieu-do { display: flex; align-items: flex-end; gap: 4px; height: 220px; padding: 26px 4px 0; border-bottom: 2px solid var(--chu); margin: 16px 0 6px; overflow-x: auto; }
.cot { flex: 1 0 14px; min-width: 14px; max-width: 44px; background: #cfd6e3; border-radius: 6px 6px 0 0; position: relative; }
.cot.toi { background: var(--muc); }
.cot .gt { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: .72rem; color: var(--phu); white-space: nowrap; }
.cot.toi .gt { color: var(--muc); font-weight: 800; }
.ten-cot { display: flex; gap: 4px; padding: 0 4px; }
.ten-cot span { flex: 1 0 14px; min-width: 14px; max-width: 44px; font-size: .7rem; color: var(--phu); text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ten-cot span.toi { color: var(--muc); font-weight: 800; }
.viec-can-lam { background: var(--da-quang); padding: 10px 14px; border-radius: 12px; font-weight: 600; margin: 12px 0; }

/* tiến độ */
.cd { margin: 14px 0; }
.dang-td { border: 2px solid var(--vien); border-radius: 12px; padding: 10px 12px; margin: 8px 0; background: #fff; }
.dang-td.chua { opacity: .55; }
.chip { display: inline-block; padding: 4px 10px; margin: 4px 4px 0 0; border-radius: 999px; font-size: .82rem; border: 1px solid var(--vien); background: #fff; }
.chip.chua_hoc { background: #f2f4f8; }
.chip.dang_hoc { background: #fff6d6; border-color: #f0d36b; }
.chip.vung { background: var(--dung-nhat); border-color: #9fd5b4; color: var(--dung); }
.chip.can_on { background: var(--cam-nhat); border-color: #f2b77a; color: var(--cam); }

/* giáo viên */
.so-lon { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.so-lon .o { border-radius: var(--bo); padding: 12px 14px; color: #fff; }
.so-lon .o b { display: block; font-size: 2.3rem; line-height: 1; font-weight: 800; }
.so-lon .o span { font-size: .9rem; opacity: .95; }
.o.xanh { background: var(--dung); } .o.do { background: var(--but-do); } .o.cam { background: var(--cam); } .o.tim { background: var(--muc); }
.dong-hs { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--vien); cursor: pointer; min-height: 56px; }
.dong-hs .cham { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.cham.xanh { background: var(--dung); } .cham.do { background: var(--but-do); } .cham.cam { background: var(--cam); } .cham.tim { background: var(--muc); }
.dong-hs .ten { flex: 1; min-width: 0; }
.dong-hs .ten small { display: block; color: var(--phu); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viec { font-size: .82rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.viec.xanh { background: var(--dung-nhat); color: var(--dung); } .viec.do { background: var(--do-nhat); color: var(--but-do); }
.viec.cam { background: var(--cam-nhat); color: var(--cam); } .viec.tim { background: var(--muc-nhat); color: var(--muc); }
.bang { width: 100%; border-collapse: collapse; font-size: .92rem; }
.bang th, .bang td { padding: 8px 6px; border-bottom: 1px solid var(--vien); text-align: left; vertical-align: top; }
.cuon-ngang { overflow-x: auto; }
.dv-cau { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--vien); }
.dv-cau .nd { flex: 1; font-size: .92rem; }
.dv-cau button { min-width: 64px; min-height: 44px; border-radius: 10px; border: 2px solid var(--vien); background: #fff; font-weight: 700; }
.dv-cau button.dung { border-color: var(--dung); background: var(--dung); color: #fff; }
.the-pin { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.the-pin div { border: 2px dashed var(--muc); border-radius: 12px; padding: 10px 12px; }
.the-pin b { font-size: 1.3rem; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--chu); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; max-width: 90vw; }
.bao-cao-loi { color: var(--but-do); font-size: .9rem; white-space: pre-wrap; }
/* ---------- bố cục chung ---------- */
.bo-cuc { display: grid; gap: 4px 32px; grid-template-areas: "phu" "chinh"; }
.bo-cuc > .chinh { grid-area: chinh; min-width: 0; }
.bo-cuc > .phu { grid-area: phu; min-width: 0; }
.luoi-the { display: grid; gap: 10px; }
.luoi-the .dong-hs { border: 1px solid var(--vien); border-radius: 12px; background: #fff; padding: 10px 12px; min-height: 0; }
.luoi-2 { display: grid; gap: 0 32px; }
.luoi-2 > * { min-width: 0; }
.chi-so b small { font-weight: 600; }

/* ---------- điện thoại ---------- */
@media (max-width: 559px) {
  .trang-vo { padding-left: 40px; padding-right: 14px; }
  .trang-vo::before { left: 28px; }
  .buoc-da-lam .dau-tick { left: -30px; }
  .hanh-dong .nut.chinh { flex: 1 1 100%; }
  .hanh-dong .nut.phu { flex: 1 1 0; padding: 6px 8px; }
  .thanh-duoi a { font-size: .72rem; white-space: nowrap; }
  .chi-so { padding: 8px 10px; }
  .chi-so b { font-size: 1.4rem; }
  .chi-so span { font-size: .76rem; line-height: 1.3; display: block; }
}
@media (min-width: 640px) { .so-lon { grid-template-columns: repeat(4, 1fr); } }

/* ---------- máy tính bảng (dọc) trở lên ---------- */
@media (min-width: 700px) {
  body { font-size: 18px; }
  .khung { max-width: 900px; padding: 28px 32px 110px; }
  h1 { font-size: 1.7rem; }
  .trang-vo { font-size: 1.12rem; padding-left: 60px; }
  .trang-vo::before { left: 44px; }
  .buoc-da-lam .dau-tick { left: -40px; }
  .bieu-do { height: 280px; gap: 6px; }
  .thanh-duoi { justify-content: center; }
  .thanh-duoi a { flex: 0 1 132px; font-size: .85rem; }
  .luoi-the { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dang-nhap { margin-top: 14vh; padding: 32px 36px; background: #fff; border: 1px solid var(--vien); border-radius: 18px; box-shadow: 0 10px 30px rgba(30, 34, 53, .06); }
}

/* ---------- máy tính và máy tính bảng ngang: thanh điều hướng bên trái ---------- */
@media (min-width: 1024px) {
  body.co-nav { padding-left: 236px; }
  .thanh-duoi {
    top: 0; bottom: 0; right: auto; width: 236px; flex-direction: column; justify-content: flex-start; align-items: stretch;
    gap: 4px; border-top: 0; border-right: 1px solid var(--vien); padding: 22px 14px;
  }
  .thanh-duoi::before { content: attr(data-ten); display: block; font-weight: 800; font-size: 1.15rem; color: var(--muc); padding: 0 12px 18px; }
  .thanh-duoi a { flex: none; flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px;
                  font-size: 1rem; padding: 10px 14px; border-radius: 12px; min-height: 46px; color: var(--chu); }
  .thanh-duoi a:hover { background: #f3f1fa; }
  .thanh-duoi a.dang { background: var(--muc-nhat); color: var(--muc); }
  .thanh-duoi a .bieu-tuong { font-size: 1.25rem; width: 26px; text-align: center; }
  .cham-do { position: static; margin-left: auto; }
  .khung { padding-bottom: 48px; max-width: 1000px; }
  body.trang-gv .khung { max-width: 1200px; }
  .bo-cuc { grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "chinh phu"; align-items: start; }
  .bo-cuc > .phu { position: sticky; top: 24px; }
  .bo-cuc > .phu .dai-chi-so { flex-direction: column; margin-top: 0; }
  .bo-cuc > .phu .chi-so { display: flex; align-items: baseline; gap: 12px; }
  .bo-cuc > .phu .chi-so b { font-size: 2rem; }
  .luoi-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .luoi-td { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; align-items: start; }
  .cot, .ten-cot span { max-width: 64px; }
  .dong-hs:hover { background: #f6f4fc; }
  .toast { bottom: 32px; }
  body.trang-gv .o-nhap { max-width: 560px; }
  body.trang-gv textarea.o-nhap { max-width: none; }
}
@media (min-width: 1400px) {
  body.trang-hs .khung { max-width: 1060px; }
}
@media print {
  .thanh-duoi, .khong-in, .hang-nut { display: none !important; }
  body { background: #fff; }
  .the-pin div { break-inside: avoid; }
}