:root {
  --bg: #f5f7fa; --card: #fff; --ink: #1b2430; --mid: #5c6b7a; --line: #dfe5ec;
  --primary: #1f5f8b; --primary-ink: #fff; --ok: #1e7b45; --ok-bg: #e6f4ec; --bad: #b3261e; --bad-bg: #fbe9e7;
  --flag: #b7791f; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --card: #1a2129; --ink: #e8edf2; --mid: #9aa8b6; --line: #2a333d;
    --primary: #5aa9e6; --primary-ink: #0b1620; --ok: #6fcf97; --ok-bg: #16301f; --bad: #f28b82; --bad-bg: #3a1c1a; --flag: #f6c453; }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; min-height: 100vh; }
button { font: inherit; color: inherit; }
.muted { color: var(--mid); font-size: .9rem; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 16px;
  background: var(--primary); color: var(--primary-ink); }
.topbar__brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.topbar__user { margin-left: auto; font-size: .85rem; opacity: .9; }

.app { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }
h1 { font-size: 1.3rem; margin-bottom: 4px; }
h2 { font-size: 1.05rem; margin: 20px 0 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card__meta { display: flex; flex-wrap: wrap; gap: 6px 12px; color: var(--mid); font-size: .85rem; margin: 6px 0 12px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; background: var(--ok-bg); color: var(--ok); }
.chip--off { background: var(--line); color: var(--mid); }
.row { display: flex; flex-wrap: wrap; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn--small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: default; }
.progress { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* Màn câu hỏi */
.qhead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--mid); font-size: .9rem; }
.qhead .timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.qtext { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; white-space: pre-wrap; }
.qhint { color: var(--mid); font-size: .85rem; margin-bottom: 12px; }
.opts { list-style: none; display: grid; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 12px 14px; min-height: 52px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; }
.opt__key { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.opt.is-picked { border-color: var(--primary); }
.opt.is-picked .opt__key { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.opt.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.explain { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--card); border-left: 4px solid var(--primary); font-size: .95rem; }
.explain.ok { border-left-color: var(--ok); }
.explain.bad { border-left-color: var(--bad); }

/* Thanh điều hướng dưới, dễ bấm bằng ngón cái */
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto auto 1fr; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.bottombar .btn { width: 100%; }
.flag.is-on { color: var(--flag); border-color: var(--flag); }

/* Bảng chọn nhanh câu */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; }
.grid button { min-height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; }
.grid .is-done { background: var(--line); }
.grid .is-current { outline: 2px solid var(--primary); }
.grid .is-ok { background: var(--ok-bg); color: var(--ok); }
.grid .is-bad { background: var(--bad-bg); color: var(--bad); }
.grid .is-flag { box-shadow: inset 0 -3px 0 var(--flag); }
dialog { margin: auto auto 0; width: 100%; max-width: 720px; border: 0; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }

.score { font-size: 2.4rem; font-weight: 800; }
.score.pass { color: var(--ok); }
.score.fail { color: var(--bad); }
table.hist { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.hist td, table.hist th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }

/* ---- Bổ sung: các dạng câu hỏi, màn tạo bài, review, phân tích ---- */
.qhead .timer.is-low { color: var(--bad); }
.qsec { display: inline-block; font-size: .75rem; color: var(--primary); background: var(--line); border-radius: 999px; padding: 2px 8px; margin: 10px 0 6px; }
.case { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--flag); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.case summary { cursor: pointer; font-weight: 600; }
.case p { margin-top: 8px; font-size: .95rem; }

.fills { display: grid; gap: 12px; }
.fill { display: grid; gap: 6px; }
.fill__label { font-size: .9rem; color: var(--mid); }
.fill input { min-height: 48px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; }
.fill input:focus { outline: none; border-color: var(--primary); }
.fill.is-correct input { border-color: var(--ok); background: var(--ok-bg); }
.fill.is-wrong input { border-color: var(--bad); background: var(--bad-bg); }

.dd { display: grid; gap: 14px; }
.dd-pool { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border: 1.5px dashed var(--line); border-radius: 10px; }
.dd-item { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--primary); background: var(--card); color: var(--primary); font-weight: 600; cursor: grab; }
.dd-item.is-sel { background: var(--primary); color: var(--primary-ink); }
.dd-targets { list-style: none; display: grid; gap: 10px; }
.dd-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; }
.dd-target { font-size: .95rem; }
.dd-slot { min-height: 48px; padding: 6px 10px; border-radius: 10px; border: 1.5px dashed var(--line); background: var(--card); cursor: pointer; color: var(--mid); }
.dd-slot:not(:empty) { color: var(--ink); }
.dd-slot.is-correct { border: 1.5px solid var(--ok); background: var(--ok-bg); }
.dd-slot.is-wrong { border: 1.5px solid var(--bad); background: var(--bad-bg); }

.hot { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.hot img { display: block; width: 100%; height: auto; }
.hot__area { position: absolute; border: 2px dashed rgba(31, 95, 139, .45); border-radius: 6px; background: transparent; cursor: pointer; }
.hot__area.is-picked { border: 3px solid var(--primary); background: rgba(31, 95, 139, .15); }
.hot__area.is-correct { border: 3px solid var(--ok); background: rgba(30, 123, 69, .18); }
.hot__area.is-wrong { border: 3px solid var(--bad); background: rgba(179, 38, 30, .15); }

.choice { display: flex; gap: 10px; align-items: center; min-height: 44px; cursor: pointer; }
.choice input[type=radio], .choice input[type=checkbox] { width: 20px; height: 20px; flex: none; }
.choice small { color: var(--mid); }
.choice.is-disabled { opacity: .5; }
.subchoices { padding-left: 30px; }
.num { width: 72px; min-height: 36px; padding: 0 8px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0 12px; font-size: .8rem; color: var(--mid); }
.lg::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--line); border-radius: 3px; }
.lg--done::before { background: var(--line); }
.lg--flag::before { box-shadow: inset 0 -3px 0 var(--flag); }

.bar { display: inline-block; width: 90px; height: 8px; margin-right: 8px; vertical-align: middle; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); }
.bar span.weak { background: var(--bad); }
td.ok { color: var(--ok); font-weight: 700; }
td.bad { color: var(--bad); font-weight: 700; }
.review summary { cursor: pointer; }
.review.is-bad { border-left: 4px solid var(--bad); }
.review > p, .review > .explain, .review > .case { margin-top: 8px; }
.bottombar .btn--small { padding: 0 10px; font-size: .85rem; }
.bottombar { grid-template-columns: 1fr auto auto 1fr; }
.bottombar .btn { white-space: nowrap; padding: 0 10px; font-size: .9rem; }
.topbar__login { color: inherit; font-weight: 600; text-decoration: underline; }
.notice { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 10px; padding: 10px 14px; margin: 8px 0 14px; font-size: .9rem; }

/* ---- Ôn tập: hiệu ứng đúng/sai, đáp án to, tự sang câu ---- */
.autonext { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--mid); cursor: pointer; white-space: nowrap; }
.autonext input { width: 18px; height: 18px; }
.fx-sos { position: fixed; inset: 0; z-index: 60; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 0 10px rgba(220, 38, 38, .9); background: rgba(220, 38, 38, .12);
  animation: pl-sos .6s step-end 1; }
@keyframes pl-sos { 0% { opacity: 1; } 16.66% { opacity: 0; } 33.33% { opacity: 1; } 50% { opacity: 0; } 66.66% { opacity: 1; } 83.33% { opacity: 0; } 100% { opacity: 0; } }
.fx-confetti { position: fixed; z-index: 60; width: 9px; height: 13px; margin: -6px 0 0 -4px; border-radius: 2px; pointer-events: none;
  transform: translate(0, 0) rotate(0deg); opacity: 1; transition: transform .35s cubic-bezier(.2,.7,.3,1), opacity .35s ease-in; }
.fx-pulse { animation: pl-pulse .6s ease-out; }
@keyframes pl-pulse { 0% { box-shadow: 0 0 0 0 rgba(30, 123, 69, .55); } 100% { box-shadow: 0 0 0 14px rgba(30, 123, 69, 0); } }
.answer-big { margin-top: 16px; padding: 18px; border-radius: 14px; border: 2px solid var(--primary); background: var(--card); animation: pl-pop .25s ease-out; }
.answer-big.ok { border-color: var(--ok); background: var(--ok-bg); }
.answer-big.bad { border-color: var(--bad); background: var(--bad-bg); }
.answer-big__head { font-weight: 800; font-size: 1.05rem; margin-bottom: 6px; }
.answer-big.ok .answer-big__head { color: var(--ok); }
.answer-big.bad .answer-big__head { color: var(--bad); }
.answer-big__ans { font-size: 1.45rem; font-weight: 800; line-height: 1.3; white-space: pre-line; }
.answer-big__exp { margin-top: 10px; font-size: .95rem; }
@keyframes pl-pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .answer-big, .fx-pulse { animation: none; } .fx-sos, .fx-confetti { display: none; } }

/* ---- Bố cục gọn khi làm bài: ít cuộn hơn trên điện thoại ---- */
:root { --target-size: 36px; }
@media (pointer: coarse) { :root { --target-size: 44px; } }
html { scroll-padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
body.in-session .topbar { height: 40px; }
body.in-session .topbar__brand { font-size: .95rem; }
body.in-session .app { padding-top: 8px; }
.qhead { margin-bottom: 2px; font-size: .85rem; min-height: 28px; }
.qhead + .progress { height: 4px; margin: 2px 0 8px; }
.qmeta { color: var(--mid); font-size: .78rem; margin: 0 0 2px; }
.qtext { font-size: 1rem; line-height: 1.45; margin-bottom: 8px; text-wrap: pretty; }
.opts { gap: 6px; }
.opt { min-height: var(--target-size); padding: 8px 12px; gap: 10px; font-size: .95rem; line-height: 1.35; align-items: center; }
.opt__key { width: 24px; height: 24px; font-size: .75rem; }
.case { margin: 4px 0 8px; padding: 8px 12px; }
.case summary { font-size: .9rem; min-height: var(--target-size); display: flex; align-items: center; }
.case__body { margin-top: 6px; max-height: 26vh; overflow: auto; font-size: .88rem; line-height: 1.45; }
.fills { gap: 8px; }
.fill input { min-height: var(--target-size); }
.dd { gap: 8px; }
.dd-pool { padding: 6px; gap: 6px; }
.dd-item { min-height: var(--target-size); padding: 0 12px; }
.dd-targets { gap: 6px; }
.dd-slot { min-height: var(--target-size); padding: 4px 8px; }
.dd-target { font-size: .88rem; line-height: 1.3; }
.hot { max-inline-size: min(100%, 63vh); margin-inline: auto; }
.answer-big { margin-top: 10px; padding: 10px 14px; }
.answer-big__head { font-size: .9rem; margin-bottom: 2px; }
.answer-big__ans { font-size: 1.15rem; }
.answer-big__exp { margin-top: 6px; font-size: .86rem; line-height: 1.45; }
.bottombar { padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); gap: 6px; }
.bottombar .btn { min-height: var(--target-size); }
