:root {
  --navy: #1c3a5e;
  --blue: #2b6fb3;
  --blue-soft: #eaf2fb;
  --green: #2d8a4e;
  --green-soft: #e9f6ee;
  --red: #c0392b;
  --red-soft: #fdeeec;
  --amber: #c97a10;
  --amber-soft: #fff4e2;
  --ink: #1f2733;
  --muted: #5d6878;
  --line: #d9e1ec;
  --bg: #f3f6fa;
  --card: #ffffff;
  --hl: #ffe680;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 70, .06), 0 4px 14px rgba(20, 40, 70, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.5;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 460px; }

/* ---------- chung ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
h1 { font-size: 28px; margin: 4px 0 12px; color: var(--navy); line-height: 1.25; }
h2 { font-size: 21px; margin: 0 0 12px; color: var(--navy); }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  min-height: 48px; padding: 10px 20px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; color: var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--blue); }
.btn.big { min-height: 60px; font-size: 20px; padding: 12px 28px; }
.btn:disabled { opacity: .45; cursor: default; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; min-height: 50px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
.field input:focus { outline: 3px solid #b8d4f2; border-color: var(--blue); }
.err { color: var(--red); font-weight: 600; min-height: 1.5em; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--navy); color: #fff; }
.topbar .brand { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.topbar .btn { min-height: 40px; padding: 6px 14px; background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; flex: none;
}

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 50;
  background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 12px; font-weight: 700;
  box-shadow: 0 8px 28px rgba(0,0,0,.25); max-width: calc(100% - 32px); text-align: center;
}
.toast.warn { background: var(--amber); }
.toast.bad { background: var(--red); }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 18px; padding: 24px; max-width: 460px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.3); }

/* ---------- chọn hồ sơ & PIN ---------- */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
.profile {
  background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 20px 10px; text-align: center; font-weight: 700;
}
.profile .avatar { width: 72px; height: 72px; font-size: 30px; margin-bottom: 8px; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 18px 0; }
.pin-dots i { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--navy); }
.pin-dots i.on { background: var(--navy); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 0 auto; }
.keypad button { min-height: 68px; font-size: 26px; font-weight: 700; border-radius: 16px; border: 1.5px solid var(--line); background: #fff; }
.keypad button:active { background: var(--blue-soft); }

/* ---------- trang chủ ---------- */
.hero { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.countdown { background: var(--amber-soft); color: var(--amber); border-radius: 12px; padding: 8px 14px; font-weight: 700; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.mode { display: flex; flex-direction: column; gap: 8px; }
.mode h2 { margin: 0; }
.mode .btn { margin-top: auto; }
.tag { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: var(--blue-soft); color: var(--blue); }
.tag.soon { background: #eef0f3; color: var(--muted); }

table.list { width: 100%; border-collapse: collapse; font-size: 16px; }
table.list th { text-align: left; font-size: 14px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1.5px solid var(--line); }
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--blue-soft); }

/* ---------- màn thi ---------- */
.exam { min-height: 100vh; display: flex; flex-direction: column; }
.exam-top { position: sticky; top: 0; z-index: 20; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 24px; padding: 2px 14px; border-radius: 10px;
  background: rgba(255,255,255,.14);
}
.timer.warn { background: #f5b13d; color: #2a1b00; }
.timer.danger { background: #e2453a; color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.seg { display: inline-flex; background: rgba(255,255,255,.12); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; color: #fff; padding: 6px 12px; border-radius: 8px; font-weight: 700; min-height: 38px; }
.seg button.on { background: #fff; color: var(--navy); }

.exam-body { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; max-width: 1180px; margin: 0 auto; padding: 16px; width: 100%; flex: 1; }
@media (max-width: 900px) { .exam-body { grid-template-columns: minmax(0, 1fr); } }

.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qnum { background: var(--navy); color: #fff; font-weight: 800; border-radius: 10px; padding: 4px 14px; }
.flag { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; min-height: 44px; padding: 4px 14px; font-weight: 700; color: var(--muted); }
.flag.on { background: var(--amber-soft); border-color: #efc884; color: var(--amber); }

.qtext { font-size: 21px; line-height: 1.55; }
.qtext .en { font-weight: 700; }
.qtext .vi { font-style: italic; color: #3c4a63; margin-top: 4px; }
.qtext .w { border-radius: 4px; cursor: pointer; padding: 1px 0; -webkit-tap-highlight-color: transparent; }
.qtext .w.hl { background: var(--hl); box-shadow: inset 0 -3px 0 #e0a800; }
.hl-tip { font-size: 14px; color: var(--muted); margin-top: 6px; }
.qfig { margin: 14px 0; overflow-x: auto; }
.qfig svg { max-width: 100%; height: auto; }
.qfig > svg { display: block; margin: 0 auto; }
.qfig .fig { display: flex; justify-content: center; }
.eq { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: .5px; margin: 12px 0; }

.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.opts.svg { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.opt {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; text-align: left; font-size: 21px; font-weight: 600;
}
.opt .k {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--navy); color: var(--navy); font-weight: 800; font-size: 19px;
}
.opt .v svg { max-width: 100%; height: auto; display: block; }
.opt.on { border-color: var(--blue); background: var(--blue-soft); }
.opt.on .k { background: var(--blue); border-color: var(--blue); color: #fff; }
.opt.right { border-color: var(--green); background: var(--green-soft); }
.opt.right .k { background: var(--green); border-color: var(--green); color: #fff; }
.opt.wrong { border-color: var(--red); background: var(--red-soft); }
.opt.wrong .k { background: var(--red); border-color: var(--red); color: #fff; }

.computed { margin-top: 18px; padding: 14px; border-radius: 14px; background: #f7f9fc; border: 1.5px dashed #b9c6d8; }
.computed label { font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.computed input { width: 140px; min-height: 48px; font-size: 22px; font-weight: 700; text-align: center; border: 1.5px solid var(--line); border-radius: 10px; }
.computed .msg { margin-top: 8px; font-weight: 600; font-size: 16px; }
.computed .msg.warn { color: var(--amber); }
.computed .msg.ok { color: var(--green); }

.qnav { display: flex; gap: 12px; margin-top: 18px; }
.qnav .btn { flex: 1; }

.side { display: flex; flex-direction: column; gap: 16px; }
.grid25 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.cell {
  position: relative; aspect-ratio: 1; min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 700; font-size: 17px;
}
.cell.done { background: var(--blue); border-color: var(--blue); color: #fff; }
.cell.cur { outline: 3px solid var(--navy); outline-offset: 1px; }
.cell.flag::after { content: "★"; position: absolute; top: -9px; right: -6px; color: #e08e2c; font-size: 17px; text-shadow: 0 0 2px #fff; }
.cell.right { background: var(--green); border-color: var(--green); color: #fff; }
.cell.wrong { background: var(--red); border-color: var(--red); color: #fff; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 4px; border: 1.5px solid var(--line); }

.steps { background: #eef7f9; border-left: 5px solid #0f7b8a; }
.steps h3 { margin: 0 0 6px; font-size: 17px; color: #0f5b66; display: flex; align-items: center; }
.steps h3 button { margin-left: auto; white-space: nowrap; border: 0; background: none; color: #0f7b8a; font-weight: 700; font-size: 15px; min-height: 36px; }
.steps ol { margin: 0; padding-left: 22px; font-size: 16px; }
.steps .tip { margin-top: 8px; font-size: 15px; background: #fff; border-radius: 8px; padding: 8px 10px; color: #164a52; }
.save-state { font-size: 13px; color: rgba(255,255,255,.75); }

/* ---------- kết quả ---------- */
.scorebox { display: flex; gap: 16px; flex-wrap: wrap; align-items: stretch; }
.big-score { background: var(--navy); color: #fff; border-radius: 16px; padding: 16px 28px; text-align: center; }
.big-score b { display: block; font-size: 56px; line-height: 1; }
.stat { flex: 1; min-width: 110px; border-radius: 14px; padding: 12px; text-align: center; border: 1.5px solid var(--line); background: #fff; }
.stat b { display: block; font-size: 30px; line-height: 1.1; }
.stat.good b { color: var(--green); } .stat.bad b { color: var(--red); } .stat.warn b { color: var(--amber); }
.bar { height: 12px; background: #e6ebf2; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.alert { border-radius: 14px; padding: 14px 16px; font-weight: 600; }
.alert.warn { background: var(--amber-soft); color: #7a4a05; border: 1.5px solid #efc884; }
.alert.good { background: var(--green-soft); color: #1d5e35; border: 1.5px solid #9fd3b0; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { min-height: 42px; border-radius: 99px; border: 1.5px solid var(--line); background: #fff; padding: 4px 16px; font-weight: 700; }
.tabs button.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.review-q { border-top: 1.5px solid var(--line); padding-top: 18px; margin-top: 18px; }
.review-q:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.verdict { font-weight: 700; margin-top: 12px; display: flex; gap: 16px; flex-wrap: wrap; font-size: 16px; }
.solution { margin-top: 12px; background: #f2f9f4; border-left: 5px solid var(--green); border-radius: 8px; padding: 10px 14px; font-size: 17px; }
.chart svg { width: 100%; height: auto; }

@media (max-width: 560px) {
  body { font-size: 17px; }
  .wrap { padding: 12px; }
  .qtext { font-size: 19px; }
  .opt { font-size: 19px; min-height: 56px; }
  .topbar .brand { display: none; }
  .timer { font-size: 20px; }
}
.modes > .card + .card { margin-top: 0; }

/* ---------- giấy nháp ---------- */
#qcard { position: relative; }
.draft-cv { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 5; border-radius: var(--radius); }
.drafting .draft-cv { touch-action: none; cursor: crosshair; }
.drafting { outline: 3px dashed #8fb5e3; outline-offset: 2px; }
.draft-space {
  height: 340px; margin-top: 16px; border-radius: 12px; border: 1.5px dashed #c3cede;
  background: repeating-linear-gradient(#fff 0 31px, #e8edf4 31px 32px);
  display: flex; align-items: flex-start; justify-content: flex-end; padding: 6px 10px; color: #9aa6b6; font-size: 14px;
}
.draft-space[hidden] { display: none; }
.draftbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30; display: none; gap: 6px;
  background: var(--navy); padding: 8px; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: calc(100% - 24px); flex-wrap: wrap; justify-content: center;
}
.draftbar.show { display: flex; }
.draftbar button {
  min-height: 46px; border: 0; border-radius: 11px; padding: 6px 14px; background: rgba(255,255,255,.12); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.draftbar button i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px solid #fff; }
.draftbar button.on { background: #fff; color: var(--navy); }
.draftbar button.done { background: var(--green); }
.qhead .flag + .flag, #draftSlot + .flag { margin-left: 0; }
#draftSlot .flag.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue); }

/* ---------- luyện tập ---------- */
.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.topics .card { margin: 0; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; border: 2px solid transparent; }
.topics .card:hover { border-color: #b8d4f2; }
.streak { display: inline-flex; gap: 4px; vertical-align: -2px; }
.streak i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--green); display: inline-block; }
.streak i.on { background: var(--green); }
.mode a.btn { margin-top: auto; }
