/* Hướng bố cục: thanh trên cùng cố định, nội dung một cột rộng 1040px; bài làm của học sinh là "tờ giấy thi" có lề đỏ.
   Màu: mực tím cho thao tác (bút của học sinh), mực đỏ chỉ dành cho điểm, lời phê và thao tác xóa (bút của thầy cô). */
:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1b2236;
  --muted: #5a6479;
  --rule: #dde3f0;
  --blue: #3a3fb4;
  --blue-soft: #e8e9fb;
  --blue-ink: #ffffff;
  --red: #c8302b;
  --red-soft: #fbe9e8;
  --ok: #1d7f55;
  --ok-soft: #e1f3ea;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --shadow: 0 1px 2px rgba(27, 34, 54, .06), 0 4px 14px rgba(27, 34, 54, .05);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hand: "Patrick Hand", "Be Vietnam Pro", "Segoe Print", cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141d;
    --card: #181c28;
    --ink: #e7eaf4;
    --muted: #98a2b8;
    --rule: #2a3144;
    --blue: #99a0ff;
    --blue-soft: #232748;
    --blue-ink: #10122b;
    --red: #ff7b70;
    --red-soft: #3a1f23;
    --ok: #52c493;
    --ok-soft: #173126;
    --warn: #e5b75c;
    --warn-soft: #382c14;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11141d;
  --card: #181c28;
  --ink: #e7eaf4;
  --muted: #98a2b8;
  --rule: #2a3144;
  --blue: #99a0ff;
  --blue-soft: #232748;
  --blue-ink: #10122b;
  --red: #ff7b70;
  --red-soft: #3a1f23;
  --ok: #52c493;
  --ok-soft: #173126;
  --warn: #e5b75c;
  --warn-soft: #382c14;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { text-wrap: balance; margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Thanh trên cùng ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px; cursor: pointer; border-radius: 8px; }
.brand svg { width: 26px; height: 26px; color: var(--red); }
.brand-name { font-family: var(--hand); font-size: 28px; line-height: 1; color: var(--red); letter-spacing: .01em; }
.bar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- Nút và điều khiển ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink);
  font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--blue) 50%, var(--rule)); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--blue-soft); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg, .ico { width: 16px; height: 16px; flex: none; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.inp, select.inp, textarea.inp {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink);
}
textarea.inp { min-height: 84px; resize: vertical; line-height: 1.5; }
.inp:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--blue); flex: none; }

/* ---------- Thẻ, chip, tab ---------- */
.card { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card-link { cursor: pointer; text-align: left; width: 100%; }
.card-link:hover { border-color: color-mix(in srgb, var(--blue) 55%, var(--rule)); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.plain { background: transparent; border: 1px solid var(--rule); color: var(--muted); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .14em; font-weight: 700; font-size: 15px; background: var(--blue-soft); color: var(--blue); padding: 2px 10px; border-radius: 6px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); background: none; border: 0; padding: 4px 0; cursor: pointer; font-weight: 550; }
.crumb:hover { color: var(--ink); }
.empty { border: 1.5px dashed var(--rule); border-radius: 12px; padding: 32px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 4px; }
.banner { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-weight: 550; }
.banner.red { background: var(--red-soft); color: var(--red); }

/* ---------- Danh sách bài ---------- */
.list { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: 12px; background: var(--card); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; padding: 14px 16px; border-top: 1px solid var(--rule); }
.item:first-child { border-top: 0; }
.item .title { font-weight: 600; }
.item .meta { display: flex; gap: 6px 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.item .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* ---------- Bảng ---------- */
.scroll { overflow-x: auto; border: 1px solid var(--rule); border-radius: 12px; background: var(--card); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
.tbl th { font-size: 12.5px; font-weight: 650; color: var(--muted); background: color-mix(in srgb, var(--blue-soft) 45%, var(--card)); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl td.c, .tbl th.c { text-align: center; }
.mark { font-family: var(--hand); font-size: 20px; color: var(--red); line-height: 1; }

/* ---------- Thống kê ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; }
.tile .k { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.hist { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; align-items: end; height: 150px; padding-top: 18px; }
.hist .col { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; min-width: 0; }
.hist .bar-fill { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--blue); }
.hist .n { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.hist-x { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; font-size: 11.5px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; margin-top: 6px; }
.meter { height: 8px; border-radius: 99px; background: var(--rule); overflow: hidden; min-width: 80px; }
.meter > i { display: block; height: 100%; background: var(--blue); }
.meter.low > i { background: var(--red); }
.meter.mid > i { background: var(--warn); }
.meter.hi > i { background: var(--ok); }

/* ---------- Điểm viết tay bằng bút đỏ ---------- */
.score-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.score {
  display: inline-flex; align-items: baseline; justify-content: center; gap: 2px;
  min-width: 112px; padding: 18px 22px 12px; border: 3px solid var(--red); border-radius: 50%/46%;
  color: var(--red); font-family: var(--hand); transform: rotate(-4deg);
}
.score b { font-size: 58px; line-height: 1; font-weight: 400; }
.score span { font-size: 22px; }
.remark { font-family: var(--hand); font-size: 22px; color: var(--red); line-height: 1.3; max-width: 52ch; }

/* ---------- Tờ giấy thi ---------- */
.paper {
  position: relative; background: var(--card); border: 1px solid var(--rule); border-radius: 12px;
  padding: 24px 24px 24px 56px; box-shadow: var(--shadow);
}
.paper::before { content: ""; position: absolute; top: 0; bottom: 0; left: 36px; width: 2px; background: color-mix(in srgb, var(--red) 55%, transparent); }
.sec-title { font-weight: 700; font-size: 14px; letter-spacing: .02em; color: var(--blue); margin: 28px 0 12px; }
.sec-title:first-child { margin-top: 0; }
.q { padding: 16px 0; border-top: 1px dashed var(--rule); scroll-margin-top: 90px; }
.sec-title + .q { border-top: 0; padding-top: 0; }
.q-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 8px; }
.q-no { font-weight: 700; color: var(--blue); white-space: nowrap; }
.q-pts { font-size: 12.5px; color: var(--muted); }
.q-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.rimg { max-width: 100%; max-height: 360px; vertical-align: middle; border-radius: 6px; border: 1px solid var(--rule); margin: 4px 0; background: #fff; }
.q-img { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--rule); margin: 10px 0; }
.opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%; padding: 10px 12px; border: 1.5px solid var(--rule); border-radius: 10px; background: var(--card); cursor: pointer; }
.opt:hover { border-color: color-mix(in srgb, var(--blue) 55%, var(--rule)); }
.opt .ltr { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; border: 1.5px solid var(--rule); color: var(--muted); }
.opt.on { border-color: var(--blue); background: var(--blue-soft); }
.opt.on .ltr { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.opt.good { border-color: var(--ok); background: var(--ok-soft); }
.opt.bad { border-color: var(--red); background: var(--red-soft); }
.opt.static { cursor: default; }
.tf-row { display: grid; grid-template-columns: 1fr auto; gap: 10px 14px; align-items: center; padding: 8px 0; border-top: 1px solid var(--rule); }
.tf-row:first-of-type { border-top: 0; }
.seg { display: inline-flex; border: 1.5px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 6px 14px; min-height: 34px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1.5px solid var(--rule); }
.seg button.on { background: var(--blue); color: var(--blue-ink); }
.seg button.on.neg { background: var(--red); color: #fff; }
.lined {
  line-height: 28px; padding: 0 12px; min-height: 140px;
  background-image: repeating-linear-gradient(transparent, transparent 27px, var(--rule) 27px, var(--rule) 28px);
  background-attachment: local; background-color: var(--card);
}
.files { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.file { position: relative; width: 112px; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--card); font-size: 12px; }
.file img { display: block; width: 100%; height: 84px; object-fit: cover; background: var(--blue-soft); }
.file .fname { padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; line-height: 1; }
.file .doc { height: 84px; display: grid; place-items: center; font-weight: 700; color: var(--red); background: var(--red-soft); }
.take-bar {
  position: sticky; top: 56px; z-index: 15; display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 16px; background: var(--card); border: 1px solid var(--rule); border-radius: 12px; box-shadow: var(--shadow);
}
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; }
.timer.low { color: var(--red); }
.navgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.navchip { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1.5px solid var(--rule); background: var(--card); font-size: 13px; font-weight: 650; color: var(--muted); cursor: pointer; text-decoration: none; }
.navchip.done { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }
.attach { margin-bottom: 20px; padding: 14px; border: 1px solid var(--rule); border-radius: 10px; background: color-mix(in srgb, var(--blue-soft) 35%, var(--card)); }
.attach img { display: block; max-width: 100%; border-radius: 6px; margin-top: 10px; }

/* ---------- Trình soạn đề ---------- */
.qe { border: 1px solid var(--rule); border-radius: 12px; background: var(--card); padding: 16px; }
.qe-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.qe-head .no { font-weight: 700; color: var(--blue); }
.qe-head select { width: auto; min-width: 150px; }
.qe-head .pts { width: 86px; }
.opt-edit { display: flex; align-items: center; gap: 8px; }
.opt-edit .key { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1.5px solid var(--rule); background: var(--card); font-weight: 700; color: var(--muted); cursor: pointer; }
.opt-edit .key.on { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ---------- Hộp thoại, thông báo ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(10, 13, 22, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.dialog { width: min(560px, 100%); background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.dialog.wide { width: min(760px, 100%); }
.dialog h2 { margin-bottom: 12px; }
.dialog .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; max-width: min(92vw, 520px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 550; box-shadow: var(--shadow); }
.toast.err { background: var(--red); color: #fff; }
pre.help { margin: 0; padding: 12px; border-radius: 8px; background: var(--blue-soft); color: var(--ink); font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--rule); border-top-color: var(--blue); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.splash { min-height: 60vh; display: grid; place-items: center; text-align: center; color: var(--muted); gap: 12px; }

@media (max-width: 640px) {
  .wrap { padding: 16px 14px 56px; }
  .bar { padding: 8px 12px; }
  h1 { font-size: 22px; }
  .paper { padding: 18px 16px 18px 40px; }
  .paper::before { left: 24px; }
  .take-bar { top: 52px; }
  .item .actions { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- công thức toán (KaTeX) ---------- */
.katex { font-size: 1.08em; }
.katex-display { margin: .5em 0; padding: 2px 0; overflow-x: auto; overflow-y: hidden; }
.q-text .katex-display, .opt .katex-display { text-align: left; }
code, .tex-src { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--blue-soft); padding: 1px 5px; border-radius: 4px; }
.mpv { margin-top: 12px; padding: 10px 12px; border: 1.5px dashed var(--rule); border-radius: 10px; background: color-mix(in srgb, var(--blue-soft) 35%, var(--card)); }
.mpv[hidden] { display: none; }
.mpv-t { display: block; font-size: 12px; font-weight: 650; color: var(--muted); margin-bottom: 6px; }
.mpv-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; margin-top: 8px; }

/* ---------- Nhập đề từ Word / LaTeX ---------- */
.qi-info { margin: 0 0 10px; padding: 10px 12px; border-radius: 8px; background: var(--blue-soft); color: var(--ink); }
.qi-info[hidden] { display: none; }
.qi-warn { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.5; color: var(--warn); }
.qi-warn li + li { margin-top: 2px; }
.qi-guide { margin-bottom: 4px; }
.qi-guide > summary { cursor: pointer; font-size: 13px; color: var(--blue); font-weight: 600; }
.qi-guide pre.help { margin-top: 8px; }

/* ---------- chọn số mã đề trong hộp nhập đề ---------- */
.qi-ver { margin-top: 12px; }

/* ---------- Mã đề và in đề: tờ giấy luôn trắng, chữ đen (cả khi giao diện tối) ---------- */
.pv-papers { display: flex; flex-direction: column; gap: 20px; }
.pv-paper { background: #fff; color: #111; border: 1px solid var(--rule); border-radius: 12px; padding: 28px 34px; box-shadow: var(--shadow); font-size: 15px; line-height: 1.55; }
.pv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 10px; border-bottom: 2px solid #111; }
.pv-school { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; }
.pv-title { font-size: 20px; font-weight: 700; margin-top: 2px; }
.pv-meta { font-size: 13px; color: #444; }
.pv-code { border: 2px solid #111; padding: 4px 16px; text-align: center; min-width: 96px; }
.pv-code span { display: block; font-size: 12px; }
.pv-code b { display: block; font-size: 28px; line-height: 1.1; }
.pv-name { margin: 12px 0 6px; }
.pv-ins { margin: 6px 0 10px; }
.pv-sec { font-size: 15px; font-weight: 700; margin: 18px 0 6px; break-after: avoid; }
.pv-q { margin: 10px 0; break-inside: avoid; }
.pv-qt { white-space: pre-wrap; }
.pv-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 2px 20px; margin-top: 4px; padding-left: 14px; }
.pv-items { margin-top: 4px; padding-left: 14px; display: flex; flex-direction: column; gap: 2px; }
.pv-line { margin-top: 6px; color: #444; }
.pv-end { text-align: center; font-weight: 700; margin-top: 20px; }
.pv-paper .q-img { max-height: 280px; }
.pv-keytitle { font-size: 18px; margin-bottom: 10px; }
.pv-keyblock { margin: 14px 0; break-inside: avoid; }
.pv-keyblock h3 { font-size: 15px; margin-bottom: 6px; }
.pv-krow { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0; }
.pv-kl { min-width: 62px; font-weight: 600; padding-top: 4px; }
.pv-cells { display: flex; flex-wrap: wrap; gap: 4px; }
.pv-cell { display: inline-flex; flex-direction: column; align-items: center; min-width: 38px; padding: 2px 6px; border: 1px solid #888; border-radius: 4px; }
.pv-cell i { font-style: normal; font-size: 10px; color: #555; line-height: 1.2; }
.pv-cell b { font-size: 14px; line-height: 1.3; }
.pv-wrap[data-mode="exam"] .pv-key, .pv-wrap[data-mode="key"] .pv-papers { display: none; }
@media print {
  @page { size: A4; margin: 14mm 14mm 16mm; }
  html, body { background: #fff !important; }
  #bar, .no-print, .toast, #toasts, #overlay { display: none !important; }
  main, #main { padding: 0 !important; max-width: none !important; }
  .pv-wrap { gap: 0 !important; }
  .pv-paper { border: 0; border-radius: 0; box-shadow: none; padding: 0; font-size: 12pt; }
  .pv-papers { gap: 0; }
  .pv-exam { break-after: page; }
  .pv-exam:last-child { break-after: auto; }
  .pv-key { break-before: page; }
  .pv-wrap[data-mode="key"] .pv-key { break-before: auto; }
  .pv-wrap[data-mode="exam"] .pv-exam:last-child { break-after: auto; }
  .pv-cell { border-color: #000; }
}

.bulkbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-height: 34px; }
.tbl input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; vertical-align: middle; }
.tbl td.c, .tbl th.c { width: 44px; }

/* Phân bố lựa chọn trong bảng thống kê từng câu */
.dists { display: grid; gap: 3px; }
.dist { display: grid; grid-template-columns: 22px 1fr minmax(46px, auto); align-items: center; gap: 6px; font-size: 13px; }
.dist .num { white-space: nowrap; }
.dist b { text-align: center; color: var(--muted, #6b7280); }
.dist .dbar { display: block; height: 8px; border-radius: 4px; background: rgba(120, 120, 140, .16); overflow: hidden; }
.dist .dbar i { display: block; height: 100%; background: #9aa3c4; border-radius: 4px; }
.dist.ok .dbar i { background: #2f9e6b; }
.dist.ok b { color: #1f7a50; }
.dist.bad .dbar i { background: #d64545; }
.dist.bad b { color: #b3261e; }

/* Thanh mời cài ứng dụng (chỉ bản tự chạy tạo ra thanh này) */
.pwa-banner {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  width: min(94vw, 560px); display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); color: var(--ink); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
}
.pwa-banner img { border-radius: 10px; flex: none; }
.pwa-text { flex: 1; min-width: 0; display: grid; gap: 2px; font-size: 13px; line-height: 1.4; }
.pwa-text span { color: var(--muted); }
.pwa-actions { display: flex; gap: 8px; flex: none; }
@media (max-width: 520px) { .pwa-banner { flex-wrap: wrap; } .pwa-actions { width: 100%; justify-content: flex-end; } }
body:has(.take-bar) .pwa-banner { display: none; }      /* không làm phiền lúc đang làm bài */
@media print { .pwa-banner { display: none; } }

/* Bảng trong nội dung câu hỏi (các dòng | ô | ô |) */
.rtbl { border-collapse: collapse; margin: 8px 0; max-width: 100%; white-space: normal; }
.rtbl th, .rtbl td { border: 1px solid var(--rule); padding: 4px 10px; text-align: center; vertical-align: middle; }
.rtbl th { background: var(--card); font-weight: 700; }

/* Nhân bản đề và xuất Word */
.cl-list { display: grid; gap: 4px; max-height: 240px; overflow: auto; margin-top: 8px; padding: 6px; border: 1px solid var(--rule); border-radius: 10px; }
.cl-row { display: flex; gap: 8px; align-items: baseline; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.cl-row:hover { background: var(--card); }
.cl-row .cl-ex { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cl-rng { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cl-rng .inp { width: 76px; }
.sol-edit { margin-top: 12px; }
.sol-edit > summary { cursor: pointer; font-weight: 600; }
.qe.cloned { border-left: 4px solid #d98a00; }
