:root {
  --bg: #f5f7fb; --surface: #fff; --ink: #1d2433; --ink2: #5b6475; --line: #e2e6ee;
  --pri: #1f5fbf; --pri-2: #e8f0fc; --ok: #13804b; --ok-bg: #e5f5ec; --bad: #c62f2f; --bad-bg: #fdecec;
  --part: #a86400; --part-bg: #fff3dc;
  --seq-1: #b9d3f5; --seq-2: #5e9be6; --seq-3: #1f5fbf;    /* thang một sắc độ cho tỉ lệ đúng */
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,60,.06), 0 2px 8px rgba(20,30,60,.05);
  font-size: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.55; }
a { color: var(--pri); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: .2em 0 .6em; } h2 { font-size: 1.35rem; } h3 { font-size: 1.08rem; }
code { background: #eef1f6; padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.hidden { display: none !important; }
.muted { color: var(--ink2); } .small { font-size: .86rem; } .center { text-align: center; margin: 1rem 0; } .nowrap { white-space: nowrap; }

/* khung */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .55rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--ink); white-space: nowrap; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--pri); color: #fff; font-family: serif; }
#nav { margin-left: auto; display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
#nav a:not(.btn) { padding: .35rem .6rem; border-radius: 6px; color: var(--ink2); }
#nav a.active, #nav a:not(.btn):hover { background: var(--pri-2); color: var(--pri); text-decoration: none; }
.who { font-size: .85rem; color: var(--ink2); padding: 0 .4rem; }
.menu-btn { display: none; margin-left: auto; background: none; border: 0; font-size: 1.4rem; }
main { max-width: 1180px; margin: 1.2rem auto; padding: 0 1rem; }
.foot { text-align: center; color: var(--ink2); font-size: .8rem; padding: 2rem 0; }
.setup-warn { background: #fff3dc; padding: .6rem 1rem; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow { max-width: 560px; margin: 1.5rem auto; }
.card.error { border-color: var(--bad); color: var(--bad); }
.note { background: var(--part-bg); border-color: #f0d9a8; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.grid-ed { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; align-items: start; }
.row { display: flex; gap: .5rem; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; flex-wrap: wrap; } .row.end { justify-content: flex-end; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; } .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
.loading { padding: 2rem; text-align: center; color: var(--ink2); }

/* biểu mẫu */
label { display: block; font-size: .9rem; margin-bottom: .7rem; color: var(--ink2); }
label.inline { display: inline-flex; align-items: center; gap: .3rem; margin-right: 1rem; color: var(--ink); }
input, select, textarea { font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid #cfd5e1; border-radius: 7px; background: #fff; color: var(--ink); margin-top: .2rem; }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; accent-color: var(--pri); }
.row input, .row select, .filters input, .filters select { margin-top: 0; width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri-2); border-color: var(--pri); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .5rem 1rem; border-radius: 7px; border: 1px solid var(--pri); background: var(--pri); color: #fff; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { filter: brightness(1.07); } .btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: #fff; color: var(--pri); } .btn.danger { background: #fff; color: var(--bad); border-color: #f0b8b8; }
.btn.sm { padding: .28rem .65rem; font-size: .86rem; } .btn.big { padding: .75rem 2rem; font-size: 1.05rem; } .btn.block { width: 100%; margin-top: .4rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: .5rem .9rem; font: inherit; color: var(--ink2); border-bottom: 2px solid transparent; cursor: pointer; }
.tab.active { color: var(--pri); border-color: var(--pri); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; }
.filters select { max-width: 260px; }

/* bảng */
.tbl-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.list th, table.list td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { color: var(--ink2); font-weight: 600; background: #fafbfd; }
tr.clickable { cursor: pointer; } tr.clickable:hover { background: #f6f9ff; }

/* chip, badge */
.chip { display: inline-block; padding: .05rem .5rem; border-radius: 99px; background: var(--pri-2); color: var(--pri); font-size: .78rem; font-weight: 600; margin-right: .25rem; }
.chip.ghost { background: #f0f2f6; color: var(--ink2); }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.part { background: var(--part-bg); color: var(--part); }
.badge { display: inline-block; min-width: 3em; text-align: center; padding: .1rem .4rem; border-radius: 6px; font-weight: 700; font-size: .85rem; }
.badge.low { background: var(--bad-bg); color: var(--bad); }

/* chỉ số */
.stats-row { display: flex; flex-wrap: wrap; gap: .8rem; margin: .5rem 0 1rem; }
.stat { flex: 1 1 120px; background: #fafbfd; border: 1px solid var(--line); border-radius: 9px; padding: .7rem .9rem; color: var(--ink); text-decoration: none !important; }
.stat-v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; } .stat-l { font-size: .82rem; color: var(--ink2); }
.stat.ok .stat-v { color: var(--ok); } .stat.bad .stat-v { color: var(--bad); }

/* trang chủ */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 2rem; align-items: center; margin: 1.5rem 0 2rem; }
.hero h1 { font-size: 2.1rem; }
.lookup .row input { flex: 1; }

/* câu hỏi */
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: .9rem; scroll-margin-top: 70px; }
.q-head { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-bottom: .5rem; }
.q-num { font-weight: 700; color: var(--pri); margin-right: .4rem; }
.q-stem { margin-bottom: .6rem; }
.tex { overflow-wrap: anywhere; } .tex .katex { font-size: 1.07em; }
.opts { display: grid; gap: .4rem; }
.opt { display: flex; gap: .55rem; align-items: baseline; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin: 0; color: var(--ink); font-size: 1rem; }
.opt:hover { background: #f7f9fd; } .opt.chosen { border-color: var(--pri); background: var(--pri-2); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); } .opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt-lab { font-weight: 700; min-width: 1.6em; }
table.tf { border-collapse: collapse; width: 100%; } table.tf td, table.tf th { border: 1px solid var(--line); padding: .4rem .5rem; } table.tf td:first-child { width: 2.5em; } table.tf td:nth-child(n+3) { text-align: center; width: 3.5em; }
table.tf th { background: #fafbfd; font-weight: 600; font-size: .88rem; }
tr.right td { background: var(--ok-bg); } tr.wrong td { background: var(--bad-bg); }
table.tf input { transform: scale(1.25); }
.short label { color: var(--ink); display: flex; align-items: center; gap: .5rem; }
.short input { max-width: 260px; }
.ans-inline { display: inline-block; margin: .3rem 0; padding: .15rem .55rem; background: var(--ok-bg); color: var(--ok); border-radius: 6px; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: .5rem; } .m-item { display: flex; gap: .4rem; padding: .25rem 0; }
.m-ans { display: flex; flex-wrap: wrap; gap: .8rem; } .m-ans label { color: var(--ink); margin: 0; padding: .2rem .4rem; border-radius: 6px; } .m-ans select { width: auto; }
.m-ans label.right { background: var(--ok-bg); } .m-ans label.wrong { background: var(--bad-bg); }
textarea.essay-in { min-height: 8em; }
.essay-resp { background: #fafbfd; border: 1px dashed var(--line); padding: .5rem .7rem; border-radius: 8px; margin-bottom: .4rem; }
details.sol { margin-top: .6rem; background: #f7faff; border-left: 3px solid var(--pri); padding: .4rem .8rem; border-radius: 0 8px 8px 0; }
details.sol summary { cursor: pointer; font-weight: 600; color: var(--pri); }
.comment { margin-top: .5rem; color: var(--part); }
.fig { max-width: min(100%, 420px); display: block; margin: .4rem auto; }
.exfig { float: right; margin: 0 0 .5rem 1rem; max-width: 45%; }
.exfig .fig { margin: 0; }
.fig-missing { display: inline-block; padding: .3rem .6rem; border: 1px dashed #c9cfda; color: var(--ink2); font-size: .82rem; border-radius: 6px; }
.tex-list { padding-left: 1.2rem; margin: .3rem 0; } .tex-list.ord { list-style: none; padding-left: .3rem; }
.tex-list.cols { display: grid; gap: .2rem 1.5rem; } .cols-2 { grid-template-columns: repeat(2, 1fr); } .cols-3 { grid-template-columns: repeat(3, 1fr); } .cols-4 { grid-template-columns: repeat(4, 1fr); }
.li-lab { font-weight: 600; }
.tex-table { border-collapse: collapse; margin: .4rem auto; } .tex-table td { border: 1px solid #aab2c0; padding: .25rem .6rem; text-align: center; }
.blank { display: inline-block; min-width: 3em; border-bottom: 1px dotted var(--ink2); text-align: center; color: var(--pri); }
.fbox { border: 1px solid var(--ink); padding: 0 .3em; } .circ { border: 1px solid var(--ink); border-radius: 50%; padding: 0 .35em; }
.dots { color: var(--ink2); letter-spacing: 1px; }
.q-actions { margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--line); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.q::after { content: ""; display: block; clear: both; }
pre.raw { background: #1e2433; color: #e8ecf5; padding: .8rem; border-radius: 8px; overflow: auto; max-height: 60vh; font-size: .82rem; white-space: pre-wrap; }
.warn-text { color: var(--part); }
details.bad-q { border-bottom: 1px solid var(--line); padding: .35rem 0; } details.bad-q summary { cursor: pointer; font-size: .9rem; }

/* làm bài */
.take { display: grid; grid-template-columns: 1fr 260px; gap: 1rem; align-items: start; }
.take-side { position: sticky; top: 70px; }
.timer { font-size: 2rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; color: var(--pri); }
.timer.warn { color: var(--bad); }
.save-st { text-align: center; margin-bottom: .6rem; min-height: 1.3em; }
.navgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; margin-bottom: .8rem; }
.navgrid a { display: grid; place-items: center; height: 2rem; border: 1px solid var(--line); border-radius: 6px; color: var(--ink2); text-decoration: none; font-size: .86rem; }
.navgrid a.done { background: var(--pri); border-color: var(--pri); color: #fff; }
.result-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.big-score { font-size: 1.2rem; text-align: right; } .big-score span { font-size: 2.6rem; font-weight: 800; color: var(--pri); }
.grade-box { margin-top: .6rem; padding: .6rem; background: var(--part-bg); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.grade-box input { width: auto; margin: 0; } .grade-box input[name=cmt] { flex: 1; min-width: 200px; }

/* danh sách */
.exam-item { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.exam-item:last-child { border-bottom: 0; }
.class-card { color: var(--ink); text-decoration: none !important; } .class-card:hover { border-color: var(--pri); }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 2px; color: var(--pri); font-size: 1.05em; }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .45rem; }
.lesson-btn { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; font: inherit; cursor: pointer; color: var(--ink); }
.lesson-btn:hover { border-color: var(--pri); background: var(--pri-2); }
.profile-head { display: flex; gap: 1rem; align-items: center; }
.avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--pri); color: #fff; display: grid; place-items: center; font-size: 1.8rem; font-weight: 700; flex: none; }

/* đề xuất */
.rec-list { display: grid; gap: .7rem; }
.rec { border: 1px solid var(--line); border-left: 4px solid var(--bad); border-radius: 8px; padding: .6rem .8rem; }
.rec p { margin: .35rem 0; font-size: .93rem; }
.rec-levels { margin-top: .3rem; } .rec-levels .chip.bad { background: var(--bad-bg); color: var(--bad); }
.good-note { color: var(--ok); }

/* soạn đề */
.ed-item { display: flex; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.ed-ctrl { display: flex; align-items: center; gap: .2rem; flex: none; }
.ed-ctrl button { border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; padding: .1rem .4rem; }
.ed-ctrl button.danger { color: var(--bad); }
.ed-ctrl input { width: 4.2em; margin: 0; padding: .2rem .3rem; }
.ed-q { cursor: pointer; flex: 1; min-width: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: .92rem; }
.pick-list { max-height: 65vh; overflow: auto; margin-top: .6rem; }
.pick { display: flex; gap: .5rem; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: .45rem 0; }
.savebar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: .7rem 1rem; display: flex; justify-content: flex-end; gap: 1rem; align-items: center; margin: 0 -1rem; box-shadow: 0 -2px 8px rgba(20,30,60,.05); }

/* biểu đồ */
.viz-root { color: var(--ink); font-variant-numeric: tabular-nums; }
.vcol { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid #c9cfda; }
.vcol-slot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; cursor: default; }
.vcol-slot:hover .vcol-bar { background: var(--seq-3); }
.vcol-bar { width: 72%; max-width: 44px; background: var(--seq-2); border-radius: 4px 4px 0 0; min-height: 0; }
.vcol-val { font-size: .75rem; color: var(--ink2); }
.vcol-axis { display: flex; gap: 2px; } .vcol-axis span { flex: 1; text-align: center; font-size: .72rem; color: var(--ink2); }
.viz-cap { font-size: .78rem; color: var(--ink2); margin-top: .3rem; text-align: center; }
.hbars { display: grid; gap: .35rem; }
.hbar-row { display: grid; grid-template-columns: minmax(140px, 40%) 1fr 3.2em; gap: .6rem; align-items: center; font-size: .88rem; }
.hbar-lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; background: #eef1f6; border-radius: 4px; overflow: hidden; display: inline-block; width: 100%; vertical-align: middle; }
td .hbar-track { width: 70%; }
.hbar-fill { height: 100%; border-radius: 0 4px 4px 0; }
.hbar-fill.low { background: var(--seq-1); } .hbar-fill.mid { background: var(--seq-2); } .hbar-fill.high { background: var(--seq-3); }
.hbar-num { text-align: right; font-weight: 600; }
.right-t { color: var(--ok); font-weight: 700; }
.viz-tip { position: fixed; z-index: 100; display: none; pointer-events: none; background: #1d2433; color: #fff; padding: .35rem .6rem; border-radius: 6px; font-size: .8rem; max-width: 280px; }

/* hộp thoại, thông báo */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,20,35,.45); z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal { background: #fff; border-radius: 12px; padding: 1.3rem; width: min(480px, 100%); max-height: 90vh; overflow: auto; position: relative; }
.modal.wide { width: min(900px, 100%); }
.modal-x { position: absolute; right: .6rem; top: .4rem; border: 0; background: none; font-size: 1.5rem; cursor: pointer; color: var(--ink2); }
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 200; display: grid; gap: .5rem; }
.toast { background: #1d2433; color: #fff; padding: .65rem 1rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; transition: opacity .4s; }
.toast.ok { background: var(--ok); } .toast.error { background: var(--bad); } .toast.out { opacity: 0; }

@media (max-width: 860px) {
  .grid2, .grid-ed, .hero, .take { grid-template-columns: 1fr; }
  .row4 { grid-template-columns: 1fr 1fr; } .row2 { grid-template-columns: 1fr; }
  .take-side { position: static; order: -1; }
  .menu-btn { display: block; }
  #nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: #fff; flex-direction: column; align-items: stretch; padding: .5rem; border-bottom: 1px solid var(--line); }
  #nav.open { display: flex; }
  .exfig { float: none; max-width: 100%; margin: .4rem 0; }
  .cols-3, .cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media print { .topbar, .take-side, .savebar, .foot { display: none; } }
