:root {
  --nen: #f6f4ef;
  --the: #ffffff;
  --chu: #1d2433;
  --nhat: #5d6577;
  --vien: #e2ddd2;
  --chinh: #1f3a5f;
  --chinh-2: #2d5a8f;
  --nhan: #f2b134;
  --dung: #1f9d55;
  --sai: #d64545;
  --A: #6d4bd1;
  --B: #1b84c4;
  --C: #e07a1f;
  --D: #c2387c;
  --bo: 14px;
  --bong: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--nen); color: var(--chu); font-size: 16px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--chinh-2); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; }
button, input, select, textarea { font: inherit; color: inherit; }
.loading { padding: 40px; text-align: center; color: var(--nhat); }

/* thanh trên */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--chinh); color: #fff;
}
.logo { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.logo b { color: var(--nhan); }
.logo-o { width: 22px; height: 22px; border-radius: 5px; background:
  linear-gradient(#1f3a5f,#1f3a5f) 4px 4px/6px 6px no-repeat, linear-gradient(#1f3a5f,#1f3a5f) 12px 12px/6px 6px no-repeat, #fff; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; align-items: center; }
#nav a, #nav button {
  color: #dfe7f2; text-decoration: none; padding: 6px 10px; border-radius: 8px; background: none; border: 0; cursor: pointer; font-size: .95rem;
}
#nav a:hover, #nav button:hover, #nav a.on { background: rgba(255,255,255,.14); color: #fff; }
#nav .ava { width: 28px; height: 28px; border-radius: 50%; vertical-align: middle; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
main.rong { max-width: none; padding: 0; }

/* khối */
.khoi { background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 18px; box-shadow: var(--bong); margin-bottom: 16px; }
.luoi { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.hang { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hang.giua { justify-content: space-between; }
.nho { font-size: .88rem; color: var(--nhat); }
.ghi-chu { background: #fff8e6; border: 1px solid #f4dfa6; border-radius: 10px; padding: 10px 12px; font-size: .93rem; }
.trong { text-align: center; color: var(--nhat); padding: 26px 10px; }

/* nút */
.nut {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--vien); background: #fff; cursor: pointer; text-decoration: none; color: var(--chu); font-weight: 600; font-size: .95rem;
  min-height: 42px;
}
.nut:hover { border-color: #c9c2b2; }
.nut.chinh { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.nut.chinh:hover { background: var(--chinh-2); }
.nut.vang { background: var(--nhan); border-color: var(--nhan); color: #2b2205; }
.nut.do { color: var(--sai); }
.nut.to { padding: 14px 22px; font-size: 1.05rem; border-radius: 12px; }
.nut:disabled { opacity: .5; cursor: default; }

/* ô nhập */
label.o { display: block; margin-bottom: 12px; }
label.o > span { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
input[type=text], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--vien); border-radius: 10px; background: #fff; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--chinh-2); outline-offset: 0; border-color: transparent; }

/* thẻ danh sách */
.muc { background: #fff; border: 1px solid var(--vien); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--bong); }
.muc h3 { margin: 0; }
.muc .hang { margin-top: auto; }

/* trang đăng nhập */
.chao { display: grid; gap: 24px; grid-template-columns: 1.1fr .9fr; align-items: center; padding: 20px 0; }
.chao h1 { font-size: 2.2rem; }
.chao .buoc { display: grid; gap: 10px; margin: 18px 0; }
.chao .buoc div { display: flex; gap: 10px; align-items: flex-start; }
.chao .so { flex: 0 0 30px; height: 30px; border-radius: 50%; background: var(--chinh); color: #fff; display: grid; place-items: center; font-weight: 700; }
.minh-hoa { background: #fff; border-radius: 18px; border: 1px solid var(--vien); padding: 18px; box-shadow: var(--bong); }
@media (max-width: 760px) { .chao { grid-template-columns: 1fr; } .chao h1 { font-size: 1.7rem; } }

/* soạn câu hỏi */
.cau { border: 1px solid var(--vien); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: #fff; }
.cau .dau { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.cau .stt { font-weight: 800; color: var(--chinh); }
.da { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 600px) { .da { grid-template-columns: 1fr; } }
.da label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--vien); border-radius: 10px; padding: 4px 8px; }
.da label input[type=text] { border: 0; min-height: 36px; padding: 4px; }
.da label input[type=text]:focus { outline: none; }
.da label.dung { border-color: var(--dung); background: #eefaf2; }
.da .chu { font-weight: 800; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; color: #fff; flex: 0 0 26px; }
.cA { background: var(--A); } .cB { background: var(--B); } .cC { background: var(--C); } .cD { background: var(--D); }
.anh-cau { max-width: 260px; max-height: 180px; border-radius: 8px; border: 1px solid var(--vien); display: block; margin: 6px 0; }

/* bảng */
.bang-wrap { overflow-x: auto; }
table.bang { border-collapse: collapse; width: 100%; font-size: .93rem; background: #fff; }
.bang th, .bang td { border: 1px solid var(--vien); padding: 6px 8px; text-align: center; white-space: nowrap; }
.bang th { background: #f1ede4; position: sticky; top: 0; }
.bang td.ten { text-align: left; }
.bang td.d { background: #e5f6ec; color: var(--dung); font-weight: 700; }
.bang td.s { background: #fbe9e9; color: var(--sai); font-weight: 700; }

/* ======= MÀN CHIẾU ======= */
.chieu { min-height: calc(100vh - 52px); display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 0; background: #f9f7f2; }
.chieu .trai { padding: 22px 28px; display: flex; flex-direction: column; gap: 16px; border-right: 1px solid var(--vien); }
.chieu .phai { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.chieu .so-cau { font-weight: 700; color: var(--nhat); }
.chieu .de { font-size: clamp(1.4rem, 2.6vw, 2.4rem); font-weight: 700; line-height: 1.3; }
.chieu .de img { max-height: 32vh; max-width: 100%; border-radius: 10px; display: block; margin-top: 10px; }
.chieu .lua-chon { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chieu .lc { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--vien); border-radius: 14px; padding: 12px 14px; font-size: clamp(1rem, 1.8vw, 1.5rem); font-weight: 600; position: relative; overflow: hidden; }
.chieu .lc .chu { flex: 0 0 44px; height: 44px; border-radius: 10px; color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 1.4rem; }
.chieu .lc.dung { border-color: var(--dung); background: #eafaf0; }
.chieu .lc.mo { opacity: .45; }
.chieu .lc .dem { margin-left: auto; font-weight: 800; font-size: 1.3rem; }
.chieu .lc .thanh { position: absolute; left: 0; bottom: 0; height: 6px; background: currentColor; opacity: .35; transition: width .4s; }
.chieu .dieu-khien { display: flex; gap: 10px; flex-wrap: wrap; margin-top: auto; align-items: center; }
.chieu .tien-do { font-size: 1.15rem; font-weight: 700; }
.chieu .tien-do b { font-size: 1.6rem; color: var(--chinh); }
.o-hs { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; align-content: start; }
.hs { border-radius: 9px; padding: 5px 8px; background: #fff; border: 1px solid var(--vien); font-size: .88rem; line-height: 1.25; display: flex; gap: 6px; align-items: center; min-height: 38px; }
.hs .s { font-weight: 800; color: var(--nhat); min-width: 18px; }
.hs .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs .k { font-weight: 800; }
.hs.roi { background: #e3edf9; border-color: #b9d0ec; }
.hs.roi .k::after { content: '✓'; color: var(--chinh-2); }
.hs.co .k::after { content: none; }
.hs.d { background: #e5f6ec; border-color: #9fd8b5; }
.hs.sa { background: #fbe9e9; border-color: #efb4b4; }
.chua-gio { font-size: .95rem; }
.qr-dt { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid var(--vien); border-radius: 12px; padding: 10px; }
.qr-dt .q { width: 110px; height: 110px; flex: 0 0 110px; }
@media (max-width: 900px) { .chieu { grid-template-columns: 1fr; } .chieu .trai { border-right: 0; } }

/* ======= MÀN QUÉT (điện thoại) ======= */
.quet { position: fixed; inset: 0; background: #000; color: #fff; display: flex; flex-direction: column; z-index: 50; }
.quet .tren, .quet .duoi { padding: 10px 12px; background: rgba(10, 18, 30, .92); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quet .tren { padding-top: max(10px, env(safe-area-inset-top)); }
.quet .duoi { padding-bottom: max(10px, env(safe-area-inset-bottom)); justify-content: space-between; }
.quet .khung { position: relative; flex: 1; overflow: hidden; }
.quet video, .quet canvas.phu { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.quet .dem { font-size: 1.3rem; font-weight: 800; }
.quet .dem b { color: var(--nhan); }
.quet .nut { min-height: 46px; }
.quet .nut.toi { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.2); color: #fff; }
.quet .bao { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 6px 12px; border-radius: 99px; font-size: .9rem; white-space: nowrap; }
.quet .ds-chua { max-height: 30vh; overflow: auto; font-size: .9rem; width: 100%; color: #ffd98a; }
.quet input[type=range] { width: 120px; }

/* ======= IN THẺ ======= */
.trang-in { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.to-giay { background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.15); position: relative; overflow: hidden; }
.to-giay.a4 { width: 210mm; height: 297mm; }
.to-giay.a5x2 { width: 210mm; height: 297mm; display: grid; grid-template-rows: 1fr 1fr; }
.the { position: relative; width: 100%; height: 100%; color: #222; }
.a5x2 .the + .the { border-top: 1px dashed #bbb; }
.the .qr { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.the .qr svg { width: 100%; height: 100%; display: block; }
.the .ch { position: absolute; font-weight: 800; color: #444; display: grid; place-items: center; border: 2px solid #999; border-radius: 50%; }
.the .ten-in { position: absolute; left: 0; right: 0; text-align: center; font-weight: 700; color: #333; }
.the .huong-dan { position: absolute; left: 0; right: 0; text-align: center; color: #999; }
.the .lop-in { position: absolute; left: 0; right: 0; text-align: center; color: #666; font-weight: 600; }
/* A4: mã 172mm */
.a4 .the .qr { width: 172mm; height: 172mm; }
.a4 .the .ch { width: 13mm; height: 13mm; font-size: 8mm; }
.a4 .the .ch.A { left: calc(50% - 6.5mm); top: 46mm; }
.a4 .the .ch.C { left: calc(50% - 6.5mm); bottom: 46mm; transform: rotate(180deg); }
.a4 .the .ch.B { right: 5mm; top: calc(50% - 6.5mm); transform: rotate(90deg); }
.a4 .the .ch.D { left: 5mm; top: calc(50% - 6.5mm); transform: rotate(-90deg); }
.a4 .the .ten-in { bottom: 16mm; font-size: 9mm; }
.a4 .the .lop-in { top: 14mm; font-size: 6mm; }
.a4 .the .huong-dan { bottom: 8mm; font-size: 3.4mm; }
/* A5 (2 thẻ / tờ A4): mỗi thẻ 210 × 148.5mm, mã 104mm */
.a5x2 .the .qr { width: 104mm; height: 104mm; }
.a5x2 .the .ch { width: 11mm; height: 11mm; font-size: 7mm; }
.a5x2 .the .ch.A { left: calc(50% - 5.5mm); top: 9mm; }
.a5x2 .the .ch.C { left: calc(50% - 5.5mm); bottom: 9mm; transform: rotate(180deg); }
.a5x2 .the .ch.B { right: 40mm; top: calc(50% - 5.5mm); transform: rotate(90deg); }
.a5x2 .the .ch.D { left: 40mm; top: calc(50% - 5.5mm); transform: rotate(-90deg); }
.a5x2 .the .ten-in { left: 6mm; right: auto; top: 8mm; width: 44mm; text-align: left; font-size: 5mm; }
.a5x2 .the .lop-in { display: none; }
.a5x2 .the .huong-dan { left: auto; right: 6mm; top: 8mm; width: 42mm; text-align: right; font-size: 3mm; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .topbar, .khong-in, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .trang-in { gap: 0; }
  .to-giay { box-shadow: none; break-after: page; page-break-after: always; }
  .to-giay:last-child { break-after: auto; page-break-after: auto; }
}

@media (max-width: 640px) { .hang-tt { grid-template-columns: 1fr !important; } }

/* ======= ĐIỆN THOẠI ======= */
.topbar { padding-top: max(10px, env(safe-area-inset-top)); }
.logo-i { width: 26px; height: 26px; border-radius: 6px; }
@media (max-width: 760px) {
  .nc { display: none; }
  .topbar { flex-wrap: nowrap; gap: 6px; padding-left: 12px; padding-right: 8px; }
  .logo { white-space: nowrap; font-size: 1.02rem; }
  #nav { flex-wrap: nowrap; gap: 0; }
  #nav a, #nav button { font-size: 1.1rem; padding: 6px 7px; }
  main { padding: 14px 12px 50px; }
  h1 { font-size: 1.4rem; }
  .khoi { padding: 14px; }
}
.dt-chu { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; }
.nut-cam {
  align-self: center; width: min(68vw, 260px); aspect-ratio: 1; border-radius: 50%; margin: 18px 0 6px;
  background: radial-gradient(circle at 35% 30%, #3d6aa3, var(--chinh) 70%); color: #fff; text-decoration: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 10px 30px rgba(31, 58, 95, .35), inset 0 0 0 8px rgba(255, 255, 255, .12);
  font-size: 1.15rem; letter-spacing: .04em; -webkit-tap-highlight-color: transparent;
}
.nut-cam:active { transform: scale(.97); }
.nut-cam b { background: var(--nhan); color: #2b2205; padding: 6px 14px; border-radius: 99px; font-size: 1rem; }
.dt-luoi { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dt-luoi a, .dt-luoi button {
  display: flex; align-items: center; gap: 10px; padding: 14px; border-radius: 14px; background: #fff; border: 1px solid var(--vien);
  text-decoration: none; color: var(--chu); font-size: 1.5rem; box-shadow: var(--bong); cursor: pointer; text-align: left;
}
.dt-luoi span { font-size: .98rem; font-weight: 600; line-height: 1.25; }
.dt-luoi small { font-weight: 400; color: var(--nhat); }
.dt-buoi { display: block; background: #fff; border: 1px solid var(--vien); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; color: var(--chu); text-decoration: none; }

/* màn quét: đề câu hỏi + bảng kết quả trên điện thoại */
.quet .de-dt { width: 100%; font-size: .92rem; color: #cfd9e8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quet .de-dt:empty { display: none; }
.kq-dt { position: absolute; inset: 0; overflow: auto; background: var(--nen); color: var(--chu); padding: 14px 12px 20px; }
.kq-de { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; }
.kq-tom { color: var(--nhat); margin-bottom: 10px; }
.kq-cot { display: grid; gap: 6px; margin-bottom: 12px; }
.kq-dong { display: grid; grid-template-columns: 30px minmax(0, 1fr) 34% 30px; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--vien); border-radius: 10px; padding: 6px 8px; }
.kq-dong.dung { border-color: var(--dung); background: #eafaf0; }
.kq-dong .chu { width: 28px; height: 28px; border-radius: 7px; color: #fff; display: grid; place-items: center; font-weight: 800; }
.kq-nhan { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kq-thanh { height: 10px; background: #eee8dc; border-radius: 99px; overflow: hidden; }
.kq-thanh i { display: block; height: 100%; border-radius: 99px; }
.kq-hs { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.hs.co .k::after { content: none; }

/* thông báo nhỏ */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: var(--bong); max-width: calc(100% - 32px); }
