:root {
  --bench: #ECF0EE;
  --surface: #FFFFFF;
  --ink: #16202A;
  --ink-2: #4E5A64;
  --ink-3: #7A858D;
  --line: #CBD4D0;
  --line-soft: #DEE4E1;

  --litmus: #2D57C8;
  --litmus-ink: #FFFFFF;
  --litmus-soft: #E2E9FB;
  --phenol: #C2266A;
  --phenol-soft: #FBE3EE;
  --ok: #1B7A4C;
  --ok-soft: #DCF0E4;
  --bad: #BE3223;
  --bad-soft: #FBE2DE;
  --warn: #A3650F;
  --warn-soft: #FAEED6;

  --y0: #2D57C8; --y0-soft: #E2E9FB;
  --y1: #1B7A4C; --y1-soft: #DCF0E4;
  --y2: #C2266A; --y2-soft: #FBE3EE;
  --y3: #A3650F; --y3-soft: #FAEED6;
  --y4: #6A4DB6; --y4-soft: #ECE6F8;

  --sheet-filter: none;
  --bar-h: 60px;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bench: #0F1519;
    --surface: #172026;
    --ink: #E3E9E6;
    --ink-2: #A3AFB6;
    --ink-3: #78858D;
    --line: #2C3841;
    --line-soft: #222C33;

    --litmus: #86A6FF;
    --litmus-ink: #0F1519;
    --litmus-soft: #1D2A4A;
    --phenol: #FF7DB0;
    --phenol-soft: #3D1A2A;
    --ok: #5DCB92;
    --ok-soft: #133826;
    --bad: #FF8A7A;
    --bad-soft: #43201B;
    --warn: #F0B45A;
    --warn-soft: #3A2A12;

    --y0: #86A6FF; --y0-soft: #1D2A4A;
    --y1: #5DCB92; --y1-soft: #133826;
    --y2: #FF7DB0; --y2-soft: #3D1A2A;
    --y3: #F0B45A; --y3-soft: #3A2A12;
    --y4: #B9A4F5; --y4-soft: #2A2244;

    /* Bản scan đen trắng: đảo màu để đọc dễ chịu trên nền tối. */
    --sheet-filter: invert(0.9) hue-rotate(180deg);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bench);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--litmus); }
img { max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--litmus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Nút ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--litmus); border-color: var(--litmus); color: var(--litmus-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }

.link {
  border: 0; background: none; padding: 4px 0; cursor: pointer;
  color: var(--ink-2); font-size: 14px; text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { color: var(--ink); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 999px;
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Ô nguyên tố ---------- */

.tile {
  --c: var(--y0); --c-soft: var(--y0-soft);
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  aspect-ratio: 1 / 1.08;
  padding: 8px 9px 9px;
  border: 1.5px solid var(--c);
  border-radius: 6px;
  background: var(--c-soft);
  color: var(--ink);
  text-decoration: none;
  overflow: hidden;
}
.tile.y1 { --c: var(--y1); --c-soft: var(--y1-soft); }
.tile.y2 { --c: var(--y2); --c-soft: var(--y2-soft); }
.tile.y3 { --c: var(--y3); --c-soft: var(--y3-soft); }
.tile.y4 { --c: var(--y4); --c-soft: var(--y4-soft); }

.t-z { font-size: 13px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.t-badge {
  position: absolute; top: 7px; right: 8px;
  font-size: 11px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--c);
}
.t-sym {
  align-self: center;
  font-size: clamp(24px, 3.2vw, 34px); font-weight: 800; line-height: 1;
  letter-spacing: -0.02em;
  color: var(--c);
}
.t-name {
  font-size: 11.5px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.t-yr { margin-top: 2px; font-size: 10.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

a.tile:hover, a.tile:focus-visible { background: var(--c); color: var(--surface); }
a.tile:hover .t-sym, a.tile:hover .t-badge, a.tile:hover .t-yr,
a.tile:focus-visible .t-sym, a.tile:focus-visible .t-badge, a.tile:focus-visible .t-yr { color: var(--surface); }

.tile.is-soon {
  background: transparent;
  border-style: dashed;
  border-color: var(--line);
  color: var(--ink-3);
}
.tile.is-soon .t-sym { color: var(--ink-3); opacity: 0.55; }
.tile.is-soon .t-yr { color: var(--ink-3); }

.tile.big {
  width: 148px; flex: none;
  padding: 12px 14px 14px;
  border-width: 2px;
}
.tile.big .t-z { font-size: 17px; }
.tile.big .t-sym { font-size: 58px; }
.tile.big .t-name { font-size: 15px; }
.tile.big .t-yr { font-size: 13px; }

/* ---------- Trang chủ ---------- */

.home {
  max-width: 1080px; margin: 0 auto;
  padding: 56px 24px 64px;
}
.home-head { max-width: 640px; }
.home-head h1 {
  font-size: clamp(34px, 5.4vw, 56px); font-weight: 800; line-height: 1.04;
  letter-spacing: -0.03em;
}
.lede { margin-top: 14px; font-size: 17px; color: var(--ink-2); max-width: 60ch; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  margin: 32px 0 14px; padding: 0; list-style: none;
  font-size: 13px; color: var(--ink-2);
}
.legend li { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.legend .y0 { --c: var(--y0); } .legend .y1 { --c: var(--y1); } .legend .y2 { --c: var(--y2); }
.legend .y3 { --c: var(--y3); } .legend .y4 { --c: var(--y4); }

.ptable {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin: 0; padding: 0; list-style: none;
}
.ptable li { min-width: 0; }

.foot { margin-top: 36px; font-size: 13px; color: var(--ink-3); }

.home-links {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-top: 18px; font-size: 14.5px; color: var(--ink-2);
}

/* ---------- Họ tên & đồng bộ máy chủ ---------- */

.who { display: grid; gap: 6px; margin-top: 28px; max-width: 420px; }
.who label, .kq-field label { font-size: 15px; font-weight: 600; }
.who input, .kq-field input, .sync-name input {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
  font-size: 16px; font-weight: 600;
}
.who input:focus, .kq-field input:focus, .sync-name input:focus {
  border-color: var(--litmus); outline: none; box-shadow: 0 0 0 3px var(--litmus-soft);
}
.who input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.who-err { font-size: 14px; font-weight: 600; color: var(--bad); }
.who-now { margin-top: 28px; color: var(--ink-2); }
.who + .setup { margin-top: 16px; }

.sync { margin-top: 10px; }
.sync-line { font-size: 14.5px; color: var(--ink-2); }
.sync-line .link { margin-left: 6px; font-size: 14.5px; }
.sync-ok { color: var(--ok); }
.sync-busy { color: var(--litmus); }
.sync-err { color: var(--bad); }
.sync-name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 14.5px; color: var(--ink-2); }
.sync-name input { width: min(260px, 100%); height: 40px; }

/* ---------- Trang kết quả đã lưu ---------- */

.kq-wrap { max-width: 980px; margin: 0 auto; padding: 24px 24px 64px; }
.kq-title { margin-top: 20px; font-size: clamp(28px, 4vw, 40px); font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.kq-wrap .lede { font-size: 16px; }

.kq-tabs {
  display: inline-flex; gap: 4px; margin-top: 24px; padding: 4px;
  border-radius: 999px; background: var(--line-soft);
}
.kq-tabs a {
  padding: 8px 18px; border-radius: 999px;
  color: var(--ink-2); font-size: 14.5px; font-weight: 600; text-decoration: none;
}
.kq-tabs a:hover { color: var(--ink); }
.kq-tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(10, 16, 20, 0.12); }

.kq-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-top: 20px; }
.kq-field { display: grid; gap: 6px; flex: 1 1 260px; max-width: 420px; }

.kq-list { margin-top: 28px; }
.kq-empty { padding: 20px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--ink-2); }
.kq-err { border-color: var(--bad); color: var(--bad); }
.kq-summary { margin-bottom: 10px; font-size: 14.5px; color: var(--ink-2); }

.kq-table {
  --kq-cols: minmax(130px, 1.3fr) minmax(170px, 1.8fr) 110px 140px 150px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.kq-table.kq-no-who { --kq-cols: minmax(190px, 2fr) 120px 150px 160px; }
.kq-row {
  display: grid; grid-template-columns: var(--kq-cols); align-items: center; gap: 12px;
  padding: 11px 16px; border-top: 1px solid var(--line-soft);
  font-size: 14.5px; font-variant-numeric: tabular-nums;
}
.kq-row > span { min-width: 0; }
.kq-head { border-top: 0; background: var(--line-soft); font-size: 13px; font-weight: 600; color: var(--ink-2); }
.kq-who a { color: var(--ink); font-weight: 700; text-decoration: none; }
.kq-who a:hover { text-decoration: underline; }
.kq-exam a { font-weight: 700; }
.kq-exam small { color: var(--ink-2); font-size: 13.5px; }
.kq-score strong { font-size: 16px; }
.kq-time, .kq-date { color: var(--ink-2); }

/* ---------- Trang giới thiệu đề ---------- */

.intro-wrap { max-width: 880px; margin: 0 auto; padding: 24px 24px 64px; }
.back {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: -8px; padding: 6px 8px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 15px;
}
.back:hover { color: var(--ink); background: var(--line-soft); }
.back svg { width: 18px; height: 18px; }

.intro { display: flex; gap: 32px; align-items: flex-start; margin-top: 28px; }
.intro-body { flex: 1; min-width: 0; }
.intro-body h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.intro-sub { margin-top: 8px; color: var(--ink-2); }

.structure {
  width: 100%; margin-top: 28px;
  border-collapse: collapse; font-size: 15px;
}
.structure th, .structure td { padding: 10px 0; border-bottom: 1px solid var(--line); text-align: left; }
.structure th { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.structure td.num, .structure th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 16px; }
.structure tfoot td { font-weight: 700; border-bottom: 0; }

.setup { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; margin-top: 28px; }
.duration { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 15px; }
.duration input {
  width: 76px; height: 44px; padding: 0 10px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
  font-weight: 600; text-align: center; font-variant-numeric: tabular-nums;
}
.setup-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.history { margin-top: 36px; }
.history h2 { font-size: 15px; font-weight: 700; }
.history ol { margin: 8px 0 0; padding: 0; list-style: none; }
.history li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft);
  font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.history li strong { color: var(--ink); }

/* ---------- Thanh trên cùng khi làm bài ---------- */

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  height: var(--bar-h); padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.bar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; margin-right: auto; }
.bar-title strong { font-size: 16px; font-weight: 800; }
.bar-title span { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.timer {
  display: inline-flex; align-items: center; gap: 4px;
  height: 40px; padding: 0 4px 0 12px;
  border-radius: 999px;
  background: var(--litmus-soft); color: var(--litmus);
  font-weight: 700; font-variant-numeric: tabular-nums;
  transition: background-color .6s, color .6s;
}
.timer[data-level="low"] { background: var(--warn-soft); color: var(--warn); }
.timer[data-level="crit"] { background: var(--phenol-soft); color: var(--phenol); }
.timer .clock { min-width: 4.2ch; text-align: right; font-size: 16px; }
.timer button {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 999px; background: transparent; color: inherit; cursor: pointer;
}
.timer button:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
.timer svg { width: 18px; height: 18px; }
.done-pill {
  display: inline-flex; align-items: center; height: 36px; padding: 0 14px;
  border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-weight: 700; font-size: 14px;
}

.progress-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums;
}
.progress-btn svg { width: 18px; height: 18px; }

/* ---------- Bố cục làm bài ---------- */

.layout {
  position: relative;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 32px;
  max-width: 1160px; margin: 0 auto; padding: 24px 24px 96px;
}

.nav {
  position: sticky; top: calc(var(--bar-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--bar-h) - 48px); overflow: auto;
}
.nav-head { display: none; }
.nav-part + .nav-part { margin-top: 18px; }
.nav-part p { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  position: relative;
  width: 38px; height: 38px;
  border: 1.5px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip[data-state="done"] { background: var(--ink); border-color: var(--ink); color: var(--bench); }
.chip[data-state="partial"] { background: var(--line-soft); border-color: var(--ink-2); }
.chip[data-state="ok"] { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.chip[data-state="bad"] { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.chip[data-state="part"] { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.chip[data-state="none"] { border-style: dashed; color: var(--ink-3); }
.chip[data-state="self"] { background: var(--litmus-soft); border-color: var(--litmus); color: var(--litmus); }
.chip[data-state="pending"] { border-style: dashed; border-color: var(--litmus); color: var(--litmus); }
.chip[data-flag="1"]::after {
  content: ""; position: absolute; top: -4px; right: -4px;
  width: 10px; height: 10px; border-radius: 999px;
  background: var(--phenol); border: 2px solid var(--bench);
}

.nav-legend { margin-top: 20px; display: grid; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.nav-legend span { display: inline-flex; align-items: center; gap: 8px; }
.sw { flex: none; width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid var(--line); background: var(--surface); }
.sw-done { background: var(--ink); border-color: var(--ink); }
.sw-flag { width: 10px; height: 10px; margin: 0 2px; border: 0; border-radius: 999px; background: var(--phenol); }
.sw-ok { background: var(--ok); border-color: var(--ok); }
.sw-bad { background: var(--bad-soft); border-color: var(--bad); }
.sw-part { background: var(--warn-soft); border-color: var(--warn); }

.paper { min-width: 0; max-width: 860px; }

.group-title {
  margin: 40px 0 0;
  font-size: 24px; font-weight: 800; letter-spacing: -0.015em;
}
.group-title:first-child, .result + .group-title { margin-top: 0; }
.group-title small { font-size: 15px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; margin-left: 6px; }

.part { margin-top: 22px; }
.part-head { padding: 0 2px 12px; }
.part-head h3 { font-size: 17px; font-weight: 700; }
.part-head h3 small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
.part-note { margin-top: 2px; font-size: 14.5px; color: var(--ink-2); }
.zoom-hint { display: none; margin-top: 4px; font-size: 13.5px; color: var(--ink-3); }

/* ---------- Thẻ câu hỏi ---------- */

.q {
  scroll-margin-top: calc(var(--bar-h) + 16px);
  margin-top: 14px;
  padding: 18px 20px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.q-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.q-head h4 { font-size: 16px; font-weight: 800; }
.q-pts { font-size: 13.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.q-verdict { display: contents; }
.q-head .flag { margin-left: auto; }

.flag {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px; border-radius: 999px;
  border: 1.5px solid transparent; background: transparent; cursor: pointer;
  color: var(--ink-3); font-size: 13px; font-weight: 600;
}
.flag svg { width: 16px; height: 16px; }
.flag:hover { color: var(--ink); background: var(--line-soft); }
.flag[aria-pressed="true"] { color: var(--phenol); border-color: var(--phenol); background: var(--phenol-soft); }

.verdict {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px; border-radius: 999px;
  font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.part { background: var(--warn-soft); color: var(--warn); }
.verdict.none { background: var(--line-soft); color: var(--ink-2); }
.verdict.self { background: var(--litmus-soft); color: var(--litmus); }
.verdict.pending { border: 1.5px dashed var(--litmus); color: var(--litmus); }

.sheet {
  margin: 14px 0 0;
  padding: 10px 6px;
  background: #fff;
  border-radius: 8px;
  cursor: zoom-in;
  filter: var(--sheet-filter);
}
.sheet img { display: block; width: 100%; height: auto; }

/* Trả lời */
.answer { margin-top: 16px; }

.mcq { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; border: 0; }
.opt { position: relative; cursor: pointer; }
.opt input, .seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt span {
  display: grid; place-items: center;
  width: 52px; height: 48px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--surface);
  font-weight: 800; font-size: 18px;
}
.opt:hover span { border-color: var(--ink-3); }
.opt input:checked + span { background: var(--litmus); border-color: var(--litmus); color: var(--litmus-ink); }
.opt input:focus-visible + span, .seg input:focus-visible + span { outline: 3px solid var(--litmus); outline-offset: 2px; }
.opt input:disabled, .seg input:disabled { cursor: default; }
.is-review .opt, .is-review .seg { cursor: default; }
.is-review .opt:hover span { border-color: var(--line); }

.opt.is-key span, .opt.is-key input:checked + span { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.opt.is-wrong input:checked + span { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }

.clear { margin-top: 8px; }

.tf { display: grid; gap: 8px; }
.tf-row {
  display: grid; grid-template-columns: 34px auto auto 1fr; align-items: center; gap: 8px;
}
.tf-l { font-weight: 800; font-size: 16px; }
.seg { position: relative; cursor: pointer; }
.seg span {
  display: grid; place-items: center;
  min-width: 76px; height: 42px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
  font-weight: 700; font-size: 15px;
}
.seg:hover span { border-color: var(--ink-3); }
.seg input:checked + span { background: var(--litmus); border-color: var(--litmus); color: var(--litmus-ink); }
.seg.is-key span, .seg.is-key input:checked + span { border-color: var(--ok); color: var(--ok); }
.seg.is-key input:checked + span { background: var(--ok); color: var(--surface); }
.seg.is-wrong input:checked + span { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.tf-v { font-size: 13.5px; font-weight: 600; padding-left: 4px; }
.tf-v.ok { color: var(--ok); }
.tf-v.bad { color: var(--bad); }

.short { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.short > span { font-weight: 700; }
.short input {
  width: 180px; height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.short input:focus { border-color: var(--litmus); outline: none; box-shadow: 0 0 0 3px var(--litmus-soft); }
.short input[readonly] { background: transparent; }
.short.is-ok input { border-color: var(--ok); color: var(--ok); }
.short.is-bad input { border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.hint { margin-top: 8px; font-size: 13.5px; color: var(--ink-3); }
.key { margin-top: 10px; font-size: 15px; }
.key strong { color: var(--ok); font-size: 17px; }

.notes { display: grid; gap: 6px; }
.notes > span { font-weight: 600; font-size: 14.5px; }
.notes em { font-style: normal; font-weight: 400; color: var(--ink-3); }
.notes textarea {
  width: 100%; min-height: 84px; padding: 10px 12px; resize: vertical;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface);
  line-height: 1.5;
}
.notes textarea:focus { border-color: var(--litmus); outline: none; box-shadow: 0 0 0 3px var(--litmus-soft); }
.notes-read { white-space: pre-wrap; padding: 10px 12px; border-left: 3px solid var(--line); color: var(--ink-2); font-size: 15px; }

.self {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 16px; padding: 12px 14px;
  border-radius: 10px; background: var(--litmus-soft);
}
.self label { font-weight: 700; color: var(--ink); }
.self input {
  width: 84px; height: 42px; padding: 0 10px;
  border: 1.5px solid var(--litmus); border-radius: 8px; background: var(--surface);
  font-weight: 700; font-size: 17px; text-align: center; font-variant-numeric: tabular-nums;
}
.self .max { font-weight: 600; color: var(--ink-2); }
.self .quick { display: flex; gap: 6px; margin-left: auto; }
.self .quick button {
  height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-size: 13px; font-weight: 600;
}

/* Lời giải */
.sol { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.sol summary {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; list-style: none;
  font-weight: 700; color: var(--litmus); font-size: 15px;
}
.sol summary::-webkit-details-marker { display: none; }
.sol summary svg { width: 18px; height: 18px; transition: transform .2s; }
.sol[open] summary svg { transform: rotate(90deg); }
.sol .sheet { margin-top: 10px; }

/* ---------- Kết quả ---------- */

.result {
  margin-bottom: 40px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.r-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.r-label { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.r-score { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; }
.r-score strong { font-size: clamp(48px, 8vw, 72px); font-weight: 800; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.r-score span { font-size: 22px; font-weight: 700; color: var(--ink-2); }
.r-note { margin-top: 8px; font-size: 14.5px; color: var(--ink-2); }
.r-note.pending { color: var(--litmus); font-weight: 600; }
.r-time { font-size: 14px; color: var(--ink-2); text-align: right; }
.r-time strong { display: block; font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; }

.r-parts { margin: 22px 0 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.r-parts li { display: grid; grid-template-columns: minmax(150px, 220px) 1fr auto; align-items: center; gap: 14px; font-size: 14.5px; }
.r-parts .name { font-weight: 600; }
.r-parts .val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter { display: block; height: 10px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 999px; background: var(--litmus); }
.meter-self i { background: var(--y4); }

.r-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

/* ---------- Tạm dừng ---------- */

.layout.is-paused .paper, .layout.is-paused .nav { filter: blur(14px); pointer-events: none; user-select: none; }
.pause-veil {
  position: fixed; inset: var(--bar-h) 0 0 0; z-index: 15;
  display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bench) 55%, transparent);
}
.pause-card {
  max-width: 380px; padding: 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.pause-card h2 { font-size: 22px; font-weight: 800; }
.pause-card p { margin: 8px 0 20px; color: var(--ink-2); }

/* ---------- Hộp thoại ---------- */

dialog { border: 0; padding: 0; color: var(--ink); }
dialog::backdrop { background: rgba(10, 16, 20, 0.55); }

.confirm {
  width: min(440px, calc(100vw - 32px));
  border-radius: 14px; background: var(--surface);
}
.confirm form { padding: 24px; }
.confirm-title { font-size: 20px; font-weight: 800; }
.confirm-body { margin-top: 10px; color: var(--ink-2); white-space: pre-line; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; flex-wrap: wrap; }

.zoom {
  width: 100vw; height: 100vh; max-width: none; max-height: none;
  background: transparent; overflow: auto;
}
.zoom::backdrop { background: rgba(10, 16, 20, 0.85); }
.zoom img {
  display: block; margin: 56px auto 24px;
  width: auto; max-width: none; background: #fff; border-radius: 6px;
  filter: var(--sheet-filter);
}
.zoom-close {
  position: fixed; top: 12px; right: 12px; z-index: 1;
  width: 44px; height: 44px; border-radius: 999px; border: 0;
  background: var(--surface); color: var(--ink); font-size: 26px; line-height: 1; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bench);
  font-weight: 600; font-size: 15px;
}

.empty { max-width: 560px; margin: 0 auto; padding: 80px 24px; }
.empty h1 { font-size: 28px; font-weight: 800; margin: 16px 0 8px; }
.empty p { color: var(--ink-2); margin-bottom: 20px; }

/* ---------- Màn hình hẹp ---------- */

.only-narrow { display: none; }

@media (max-width: 1020px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 20px; }
  .paper { margin: 0 auto; width: 100%; }
  .only-narrow { display: inline-flex; }
  .nav {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 30;
    max-height: 72vh;
    padding: 0 20px 24px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(10, 16, 20, 0.18);
    transform: translateY(105%);
    transition: transform .25s ease;
    visibility: hidden;
  }
  body.nav-open .nav { transform: none; visibility: visible; }
  .nav-head {
    position: sticky; top: 0; z-index: 1;
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0 12px; background: var(--surface);
  }
  .nav-head strong { font-size: 16px; }
  .chip { width: 44px; height: 44px; }
}

@media (max-width: 860px) {
  .ptable { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  :root { --bar-h: 56px; }
  .home { padding: 36px 16px 48px; }
  .ptable { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .ptable .tile { aspect-ratio: auto; min-height: 112px; padding: 7px 7px 8px; }
  .t-sym { margin: 6px 0 4px; }
  .t-name { font-size: 10.5px; }
  .t-yr { font-size: 9.5px; }
  .zoom-hint { display: block; }
  .zoom img { width: 190vw; }
  .intro-wrap { padding: 16px 16px 48px; }
  .intro { flex-direction: column; gap: 20px; }
  .tile.big { width: 132px; aspect-ratio: auto; }
  .tile.big .t-sym { font-size: 44px; }
  .bar { gap: 6px; padding: 0 8px 0 4px; }
  .bar-title span { display: none; }
  .bar .btn { padding: 0 14px; min-height: 40px; }
  .progress-btn .label { display: none; }
  .timer { padding-left: 10px; }
  .layout { padding: 16px 12px 80px; }
  .q { padding: 14px 12px 16px; border-radius: 10px; }
  .q > .sheet, .sol .sheet { margin-left: -10px; margin-right: -10px; padding: 6px 0; border-radius: 0; }
  .group-title { font-size: 21px; }
  .opt span { width: 58px; }
  .tf-row { grid-template-columns: 28px 1fr 1fr; }
  .tf-v { grid-column: 2 / -1; padding-left: 0; }
  .seg span { min-width: 0; }
  .result { padding: 18px 16px; }
  .r-parts li { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .r-parts .meter { grid-column: 1 / -1; grid-row: 2; }
  .r-time { text-align: left; }
  .self .quick { margin-left: 0; }

  .kq-wrap { padding: 16px 16px 48px; }
  .kq-head { display: none; }
  .kq-row, .kq-table.kq-no-who .kq-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "who who" "exam score" "time date";
    gap: 4px 12px; padding: 12px 14px;
  }
  .kq-row:nth-child(2) { border-top: 0; }
  .kq-who { grid-area: who; }
  .kq-exam { grid-area: exam; }
  .kq-score { grid-area: score; text-align: right; }
  .kq-time { grid-area: time; font-size: 13px; }
  .kq-date { grid-area: date; font-size: 13px; text-align: right; }
  .kq-table.kq-no-who .kq-row { grid-template-areas: "exam score" "time date"; }
}

@media (max-width: 380px) {
  .ptable { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
