:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #1b2330;
  --muted: #5d6878;
  --line: #dde3ec;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fc;
  --ok: #1d7a46;
  --ok-soft: #e5f5ec;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c; --card: #1a2029; --ink: #e6eaf0; --muted: #9aa5b5; --line: #2c3542;
    --accent: #6ea2f0; --accent-ink: #0d1420; --accent-soft: #1d2b42;
    --ok: #5fcf8f; --ok-soft: #173225; --bad: #f08a80; --bad-soft: #3a1d1b; --warn: #f0c060; --warn-soft: #3a2f15;
  }
}
:root[data-theme="dark"] {
  --bg: #11151c; --card: #1a2029; --ink: #e6eaf0; --muted: #9aa5b5; --line: #2c3542;
  --accent: #6ea2f0; --accent-ink: #0d1420; --accent-soft: #1d2b42;
  --ok: #5fcf8f; --ok-soft: #173225; --bad: #f08a80; --bad-soft: #3a1d1b; --warn: #f0c060; --warn-soft: #3a2f15;
}

* { box-sizing: border-box; }
body { margin: 0; padding-bottom: 84px; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
.top { padding: 28px 0 8px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--accent); }
.brand h1 { color: var(--ink); }
.sub { margin: 4px 0 0; color: var(--muted); }
.banner { margin-top: 12px; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 20px; margin: 16px 0; }
h2 { margin: 0 0 14px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
h2 small { color: var(--muted); font-weight: 400; font-size: 13px; }
.n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; }
.span2 { grid-column: span 2; }
.span4 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
label small { font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); align-self: end; padding-bottom: 8px; }
label.check input { width: auto; }

/* structure rows */
.sec { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.sec-head { display: grid; grid-template-columns: minmax(0, 1fr) 110px 130px; gap: 12px; align-items: end; }
.sec-title { font-weight: 650; }
.sec-title small { display: block; color: var(--muted); font-weight: 400; font-size: 12.5px; }
details.help { margin-top: 2px; font-weight: 400; }
details.help summary { cursor: pointer; color: var(--accent); font-size: 12.5px; width: max-content; }
details.help p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
details.help .exbox { margin-top: 6px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; font-size: 13px; line-height: 1.6; color: var(--ink); }
.sec .toggle { margin-top: 8px; font-size: 13px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.per { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; margin-top: 10px; }
.per label { font-weight: 500; font-size: 12px; }
.per input { padding: 6px 8px; }
.essay-rows { display: grid; gap: 8px; margin-top: 10px; }
.essay-row { display: grid; grid-template-columns: 70px 100px minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13.5px; }
.essay-row .lbl { font-weight: 600; }
.sec.off { opacity: .55; }

.total { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.total .row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.total .row span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.total .sum { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 16px; }
.total .sum.ok span:last-child { color: var(--ok); }
.total .sum.bad span:last-child { color: var(--bad); }
.total .formula { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-word; }

details.adv { margin-top: 14px; }
details.adv summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-bottom: 10px; }

.go { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; }
.go label { min-width: 220px; }
button { font: inherit; border-radius: 9px; padding: 10px 18px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 13px; }

.jobs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.job { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.job .name { font-weight: 650; }
.job .st { font-size: 13.5px; color: var(--muted); min-width: 0; }
.job .st .warn { color: var(--warn); display: block; }
.job.done { background: var(--ok-soft); border-color: transparent; }
.job.err { background: var(--bad-soft); border-color: transparent; }
.job.err .st { color: var(--bad); }
.job .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.job .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.job button { padding: 6px 12px; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.drive-out { margin-bottom: 14px; padding: 14px 16px; border-radius: 10px; background: var(--accent-soft); }
.drive-out.err { background: var(--bad-soft); color: var(--bad); }
.drive-out .link-title { font-weight: 650; margin-bottom: 8px; }
.drive-out .link-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.drive-out .link-row a { flex: 1 1 260px; min-width: 0; word-break: break-all; font-size: 15px; }
.drive-out .link-row button { padding: 7px 14px; font-size: 13.5px; }
.drive-out .mail { margin-top: 8px; font-size: 14px; color: var(--muted); }
.drive-out a { color: var(--accent); font-weight: 600; }
.foot { color: var(--muted); font-size: 13px; padding-bottom: 32px; }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: 1 / -1; }
  .sec-head { grid-template-columns: minmax(0, 1fr) 1fr; }
  .sec-title { grid-column: 1 / -1; }
  .essay-row { grid-template-columns: 56px 84px minmax(0, 1fr); }
  .job { grid-template-columns: 64px minmax(0, 1fr); }
}
.go label.sets { min-width: 0; width: 150px; }
details.ex { margin-top: 6px; font-weight: 400; }
details.ex summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
details.ex div { margin-top: 6px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; font-size: 13px; line-height: 1.6; color: var(--ink); }
.go .hint.full { flex-basis: 100%; margin: 0; order: 9; }
.go label.email { flex: 1 1 240px; }

/* sticky action bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
.bar-in { display: flex; align-items: center; gap: 14px; }
.bar-total { display: flex; flex-direction: column; line-height: 1.25; margin-right: auto; font-size: 13px; color: var(--muted); }
.bar-total b { font-size: 16px; }
.bar-total b.ok { color: var(--ok); }
.bar-total b.bad { color: var(--bad); }
.bar .hint { text-align: right; }
@media (max-width: 640px) { .bar .hint { display: none; } }

/* ---- type scale: 16 body/inputs/buttons · 14 labels · 13 secondary · 18 section titles ---- */
body { font-size: 16px; }
input, select, textarea { padding: 10px 12px; font-size: 16px; }
label { font-size: 14px; }
h2 { font-size: 18px; }
button { padding: 10px 18px; font-size: 16px; }
.bar button.primary { padding: 12px 28px; font-size: 17px; }
.hint { font-size: 13px; }
.go-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.go-row label.sets { width: 140px; }
.go-row label.email { flex: 1 1 260px; }
.go-row label[id=codeWrap] { flex: 1 1 200px; }
details.more > summary { cursor: pointer; font-weight: 650; font-size: 16px; color: var(--accent); }
details.more[open] > summary { margin-bottom: 14px; }
details.more summary small { color: var(--muted); font-weight: 400; }
.job .why { display: block; font-size: 13.5px; opacity: .85; margin-top: 2px; }
.ok-big { text-align: center; padding: 8px 0; }
.ok-big .t { font-size: 20px; font-weight: 700; color: var(--ok); margin-bottom: 12px; }
.big-btn { display: inline-block; background: var(--accent); color: var(--accent-ink) !important; padding: 14px 26px; border-radius: 12px; font-size: 18px; font-weight: 700; text-decoration: none; }
.drive-out .mail.small { font-size: 14px; }
@media (max-width: 640px) { .go-row label.sets { width: 100%; } }
[hidden] { display: none !important; }

/* 3-step progress per set */
.steps { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 6px; }
.steps li { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 4px; border-radius: 99px; font-size: 14px; background: var(--line); color: var(--muted); }
.steps li b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--card); font-size: 12.5px; }
.steps li.on { background: #ffe58a; color: #5c4300; font-weight: 700; }
.steps li.on b { background: #f5b800; color: #fff; }
.steps li.ok { background: var(--ok-soft); color: var(--ok); }
.steps li.ok b { background: var(--ok); color: #fff; }
.steps li.ok b::before { content: "✓"; }
.steps li.ok b { font-size: 0; } .steps li.ok b::before { font-size: 13px; }
.steps li.bad { background: var(--bad-soft); color: var(--bad); font-weight: 700; }
.job .st .warn { background: var(--warn-soft); border-radius: 6px; padding: 4px 8px; margin-top: 4px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .steps li.on { background: #5a4600; color: #ffe58a; } }
.job { grid-template-columns: 70px minmax(0, 1fr); }
@media (max-width: 640px) {
  .essay-row { grid-template-columns: 56px minmax(0, 1fr); }
  .essay-row .lbl { grid-row: span 2; align-self: start; padding-top: 12px; }
  .essay-row input:last-child { grid-column: 2; }
}
.card.go { display: block; }
.go label, .go-row label { min-width: 0; }
#jobs:empty::before { content: "Chưa có kết quả. Điền thông tin ở trên rồi bấm “Soạn đề”."; color: var(--muted); }

.ok-big.part { color: var(--warn); }
.job .st .warn { font-size: 13px; }
.job .st { font-size: 14px; }
.ok-big { font-size: 20px; font-weight: 700; color: var(--ok); margin-bottom: 12px; }
