:root{
  --line:#c7e6ff;
  --head:#eaf5ff;
  --accent:#007bff;
  --ink:#0f172a
}

html,body{
  height:100%;
  background:#f3f6fb
}

body{
  margin:0;
  display:flex;
  justify-content:center;
  align-items:flex-start;
  padding:12px;
  overflow-x:hidden
}

.sheet{
  background:#fff;
  width:100%;
  max-width:794px;
  min-height:70vh;
  box-shadow:0 8px 28px rgba(0,0,0,.08);
  border:1px solid #e9eef5;
  border-radius:12px;
  padding:12px 12px 24px;
  box-sizing:border-box;
  position:relative;
  transition:margin-left .25s ease;
}

.drawer{
  position:fixed;
  top:12px;
  left:12px;
  bottom:12px;
  width:220px;
  z-index:40;
  background:#ffffff;
  border:1px solid #e9eef5;
  border-radius:12px;
  box-shadow:0 12px 24px rgba(15,23,42,.12);
  display:flex;
  flex-direction:column;
  transform:translateX(-110%);
  transition:transform .25s ease;
}

.drawer.open{
  transform:translateX(0);
}

.drawer .head{
  padding:10px 12px;
  border-bottom:1px solid #eef3fb;
  font-weight:800;
  color:#0b4ea3
}

.drawer .list{
  padding:10px;
  overflow-y:auto;
  flex:1
}

.nav-pill{
  width:100%;
  text-align:left;
  display:block;
  margin:6px 0;
  border:1px solid #dfefff;
  border-radius:10px;
  padding:8px 12px;
  background:#f6faff;
  cursor:pointer;
  color:#0645ad;
  font-weight:700;
  font-size:14px
}

.nav-pill.active{
  background:#007bff;
  color:#fff;
  border-color:#2a72f6
}

.nav-pill:hover{
  filter:brightness(.98)
}

.hamburger{
  position:fixed;
  top:16px;
  left:16px;
  z-index:50;
  width:40px;
  height:40px;
  border-radius:10px;
  border:1px solid #dfefff;
  background:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:0 6px 16px rgba(0,0,0,.12);
  cursor:pointer
}

.hamburger span{
  display:block;
  width:18px;
  height:2px;
  background:#1f2a44;
  position:relative
}

.hamburger span::before,
.hamburger span::after{
  content:"";
  position:absolute;
  left:0;
  width:18px;
  height:2px;
  background:#1f2a44
}

.hamburger span::before{
  top:-6px
}

.hamburger span::after{
  top:6px
}

.scrim{
  position:fixed;
  inset:0;
  background:rgba(15,23,42,.35);
  opacity:0;
  visibility:hidden;
  transition:opacity .2s ease,visibility .2s ease;
  z-index:30
}

.scrim.show{
  opacity:1;
  visibility:visible
}

.topbar{
  display:none
}

.sheet header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  border-bottom:2px solid var(--line);
  padding:6px 0 12px
}

.brand h1{
  margin:0;
  font-size:20px;
  color:#e02424;
  text-align:center
}

.timer-box{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:6px
}

.timer-title{
  font-weight:700;
  color:#333
}

.timer{
  font-weight:800;
  font-size:20px;
  background:#fff;
  border:1px solid #dfefff;
  padding:6px 10px;
  border-radius:10px;
  box-shadow:0 2px 6px rgba(0,0,0,.06)
}

.timer span{
  display:inline-block;
  min-width:28px;
  text-align:center
}

.timer small{
  opacity:.75;
  margin-left:2px;
  margin-right:6px
}

.guide{
  margin:12px 0;
  padding:10px 12px;
  background:var(--head);
  border:1px dashed var(--line);
  border-radius:8px;
  font-size:14px;
  text-align:right
}

.q{
  position:relative;
  border:1px solid var(--line);
  border-radius:8px;
  background:#f0f8ff;
  margin:10px 0;
  padding:12px 12px;
  transition:background-color .2s,border-color .2s
}

.q.correct{
  background:#eaffea;
  border-color:#66BB6A
}

.q.incorrect{
  background:#ffeaea;
  border-color:#f0a6a6
}

.q-title{
  font-weight:700;
  margin-bottom:6px
}

.q-body{
  font-size:18px;
  word-wrap:break-word;
  word-break:break-word
}

.options{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:6px;
  margin-top:8px
}

.opt{
  display:flex;
  align-items:center;
  gap:8px;
  background:#fff;
  border:1px solid #dfefff;
  border-radius:8px;
  padding:8px 10px;
  cursor:pointer;
  user-select:none
}

.opt input{
  accent-color:var(--accent)
}

.fillin{
  margin-top:8px;
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap
}

.fillin input{
  width:160px;
  max-width:60vw;
  padding:8px 10px;
  border-radius:8px;
  border:1px solid #d9e7ff;
  outline:none
}

.help-pin{
  position:absolute;
  top:10px;
  right:10px;
  width:26px;
  height:26px;
  border-radius:50%;
  background:#ff4d4f;
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  text-decoration:none;
  font-weight:800;
  box-shadow:0 2px 8px rgba(0,0,0,.18)
}

.actions{
  display:flex;
  gap:12px;
  justify-content:center;
  margin-top:18px;
  flex-wrap:wrap
}

.btn{
  padding:10px 18px;
  border-radius:9999px;
  border:1px solid rgba(0,0,0,.08);
  box-shadow:0 6px 14px rgba(0,0,0,.12);
  background:#fff;
  cursor:pointer;
  font-weight:700
}

.btn.primary{
  background:var(--accent);
  color:#fff;
  border-color:#317ef6
}

.btn:disabled{
  opacity:.6;
  cursor:not-allowed
}

.btn:active{
  transform:translateY(1px)
}

.score{
  margin-top:12px;
  text-align:center;
  font-weight:800;
  font-size:18px
}

.loading{
  margin:16px 0;
  text-align:center;
  opacity:.8
}

.error-box{
  margin:16px 0;
  padding:12px;
  border-radius:8px;
  background:#fff3f3;
  border:1px solid #f0b6b6;
  color:#b42318;
  font-size:14px;
  line-height:1.5
}

.hidden{
  display:none !important;
}

@media print{
  body{
    background:#fff;
    padding:0
  }

  .sheet{
    box-shadow:none;
    border:none;
    border-radius:0;
    padding:0;
    margin-left:0
  }

  .actions,
  .guide,
  .hamburger,
  .drawer,
  .scrim{
    display:none
  }
}

/* ====== ĐƯA PHẦN TÊN SỐ CÂU TRONG ĐỀ CÙNG DÒNG BIỂU TƯỢNG SUMMARY ====== */

/* Dòng tiêu đề câu hỏi */
.q-title{
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
  font-weight:700;
  margin-bottom:1px;
}

/* Số câu, ví dụ: Câu 1 */
.q-title > span{
  display:inline;
}

/* Hỗ trợ cả JSON cũ và mới: firstBox, enBox, viBox */
.q-title details.firstBox,
.q-title details.enBox,
.q-title details.viBox{
  display:inline-block;
  font-weight:normal;
  margin:0;
  padding:0;
}

/* Nút summary: biểu tượng 🌐 */
.q-title details.firstBox summary,
.q-title details.enBox summary,
.q-title details.viBox summary{
  cursor:pointer;
  list-style:none;
  display:inline-block;
  color:#0b7dda;
  font-weight:700;
}

/* Ẩn marker mặc định của details */
.q-title details.firstBox summary::-webkit-details-marker,
.q-title details.enBox summary::-webkit-details-marker,
.q-title details.viBox summary::-webkit-details-marker{
  display:none;
}

/* Mũi tên khi đóng */
.q-title details.firstBox summary::before,
.q-title details.enBox summary::before,
.q-title details.viBox summary::before{
  content:"▶ ";
}

/* Mũi tên khi mở */
.q-title details.firstBox[open] summary::before,
.q-title details.enBox[open] summary::before,
.q-title details.viBox[open] summary::before{
  content:"▼ ";
}

/* Khi mở details thì phần nội dung bung xuống dòng dưới */
.q-title details.firstBox[open],
.q-title details.enBox[open],
.q-title details.viBox[open]{
  display:block;
  width:100%;
  margin-top:1px;
  padding:2px 6px !important;
  background:#ffffff;
  border:1px dashed #c7e6ff;
  border-radius:8px;
}

/* Nội dung bên trong details */
.q-title .firstText,
.q-title .enText,
.q-title .viText{
  display:block;
  margin-top:1px;
  color:#0b7dda;
  font-weight:normal;
  line-height:1.6;
}

/* thu nhỏ danh sách bài test */

/* ===== Sidebar phải: mặc định thu nhỏ, bấm mới mở ===== */

@media (min-width: 992px) {
  body {
    justify-content: center;
  }

  body.nav-collapsed {
    padding-right: 12px;
    overflow-x: hidden;
  }

  body:not(.nav-collapsed) {
    padding-right: 174px;
    overflow-x: hidden;
  }

  .drawer {
    position: fixed;
    top: 12px;
    right: 12px;
    left: auto;
    bottom: 12px;
    width: 150px;
    height: auto;
    z-index: 1001;
    background: #ffffff;
    border: 1px solid #e9eef5;
    border-radius: 12px;
    box-shadow: 0 12px 24px rgba(15,23,42,.12);
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform .18s ease, opacity .18s ease;
  }

  body.nav-collapsed .drawer {
    transform: translateX(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }

  .side-toggle {
    position: fixed;
    top: 78px;
    right: 8px;
    z-index: 9999;
    width: 38px;
    height: 42px;
    border: 1px solid #d6d6d6;
    border-radius: 10px;
    background: #fff;
    color: red;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
  }

  body:not(.nav-collapsed) .side-toggle {
    right: 170px;
  }

  .hamburger {
    display: none;
  }

  .sheet {
    width: 100%;
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
    transition: max-width .18s ease;
  }

  body.nav-collapsed .sheet {
    max-width: 1120px;
  }

  body:not(.nav-collapsed) .sheet {
    max-width: 980px;
  }
}

@media (max-width: 991px) {
  .side-toggle {
    display: none;
  }
}

/* ===== Sidebar trái: mở/thu gọn tối ưu ===== */

@media (min-width: 992px) {
  :root {
    --side-w: 240px;   /* độ rộng thanh trái: muốn nhỏ hơn nữa thì chỉnh 220px hoặc 230px */
    --side-gap: 12px;  /* khoảng cách giữa thanh trái và bài test */
    --page-pad: 12px;
  }

  body {
    display: block;
    padding: var(--page-pad);
    overflow-x: hidden;
  }

  .hamburger {
    display: none;
  }

  .drawer {
    position: fixed;
    top: var(--page-pad);
    left: var(--page-pad);
    right: auto;
    bottom: var(--page-pad);
    width: var(--side-w);
    height: auto;
    z-index: 1001;
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    transition: transform .18s ease, opacity .18s ease;
  }

  body.nav-collapsed .drawer {
    transform: translateX(calc(-100% - 24px));
    opacity: 0;
    pointer-events: none;
  }

  .side-toggle {
    position: fixed;
    top: 46px;          /* đẩy nút lên trên */
    left: 6px;
    z-index: 9999;
    width: 30px;        /* nút nhỏ hơn */
    height: 34px;
    border: 1px solid #d6d6d6;
    border-radius: 8px;
    background: #fff;
    color: #222;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.16);
  }

  body:not(.nav-collapsed) .side-toggle {
    left: calc(var(--side-w) + var(--page-pad) - 6px); color: #e02424; /* nút × sát thanh trái hơn màu đỏ */
  }

  /* Khi mở thanh trái: bài test chiếm toàn bộ phần còn lại */
  body:not(.nav-collapsed) .sheet {
    width: calc(100vw - var(--side-w) - var(--side-gap) - var(--page-pad) * 3);
    max-width: none;
    margin-left: calc(var(--side-w) + var(--side-gap) + var(--page-pad));
    margin-right: var(--page-pad);
  }

  /* Khi thu thanh trái: bài test rộng khoảng 80% màn hình */
  body.nav-collapsed .sheet {
    width: 80vw;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
  }

  /* Làm nút trong thanh trái gọn hơn để hợp với sidebar nhỏ */
  .nav-pill {
    font-size: 13px;
    padding: 7px 9px;
  }

  .drawer .head {
    font-size: 16px;
    padding: 9px 10px;
  }

  .drawer .list {
    padding: 8px;
  }
}

@media (max-width: 991px) {
  .side-toggle {
    display: none;
  }
}

/* ===== Hiển thị MathJax trong câu hỏi và lựa chọn ===== */
.q-body,
.opt > span {
  line-height: 1.65;
}

.q-body details.viBox,
.q-body details.enBox,
.q-body details.firstBox {
  display: inline;
}

.q-body details.viBox > summary,
.q-body details.enBox > summary,
.q-body details.firstBox > summary {
  display: inline-block;
  cursor: pointer;
  list-style: none;
  color: #0b7dda;
  font-weight: 700;
  margin-right: 4px;
}

.q-body details.viBox > summary::-webkit-details-marker,
.q-body details.enBox > summary::-webkit-details-marker,
.q-body details.firstBox > summary::-webkit-details-marker {
  display: none;
}

.q-body details.viBox > summary::before,
.q-body details.enBox > summary::before,
.q-body details.firstBox > summary::before {
  content: "▶ ";
}

.q-body details.viBox[open] > summary::before,
.q-body details.enBox[open] > summary::before,
.q-body details.firstBox[open] > summary::before {
  content: "▼ ";
}

.q-body details.viBox[open],
.q-body details.enBox[open],
.q-body details.firstBox[open] {
  display: block;
  margin: 4px 0;
  padding: 5px 8px;
  background: #fff;
  border: 1px dashed #c7e6ff;
  border-radius: 8px;
}

.q-body mjx-container,
.options mjx-container,
.solution mjx-container {
  max-width: 100%;
  font-size: 100% !important;
  line-height: normal;
  word-break: normal;
  overflow-wrap: normal;
}

.q-body mjx-container[jax="SVG"],
.options mjx-container[jax="SVG"],
.solution mjx-container[jax="SVG"] {
  vertical-align: middle;
}

.q-body mjx-container[display="true"],
.options mjx-container[display="true"],
.solution mjx-container[display="true"] {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 0;
  margin: 5px 0;
}

.q-body mjx-container svg,
.options mjx-container svg,
.solution mjx-container svg {
  max-width: 100%;
  height: auto;
}

.opt > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

#questions.mathjax-error::before {
  content: "Không tải được MathJax. Hãy kiểm tra kết nối CDN hoặc bộ nhớ đệm của trình duyệt.";
  display: block;
  margin: 10px 0;
  padding: 10px 12px;
  color: #b42318;
  background: #fff3f3;
  border: 1px solid #f0b6b6;
  border-radius: 8px;
  font-size: 14px;
}

