/*
 * Giao diện "bậc thang": ba vạch tăng dần (teal, hổ phách, tím) là mô-típ xuyên suốt, từ logo, dải dưới header,
 * tới huy hiệu độ khó. Nền xanh lam rất nhạt, thẻ trắng bo tròn, nút bấm dày dặn cho cảm giác "bấm là có phản hồi".
 * Font Nunito (OFL) được vendor trong frontend/vendor/, không tải gì từ CDN. Dark mode theo hệ điều hành.
 * Mọi chuyển động nằm trong @media (prefers-reduced-motion: no-preference) và chỉ animate transform/opacity.
 */
@font-face {
  font-family: "Nunito"; font-style: normal; font-weight: 200 1000; font-display: swap;
  src: url("vendor/nunito-vietnamese-wght.woff2") format("woff2-variations"), url("vendor/nunito-vietnamese-wght.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: "Nunito"; font-style: normal; font-weight: 200 1000; font-display: swap;
  src: url("vendor/nunito-latin-wght.woff2") format("woff2-variations"), url("vendor/nunito-latin-wght.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light dark;
  --bg: #f4f6fc;
  --surface: #ffffff;
  --surface-2: #edf0fa;
  --ink: #1b2340;
  --muted: #525d7d;
  --line: #dbe1f0;
  --accent: #3d57d6;
  --accent-deep: #2c42ad;
  --accent-ink: #ffffff;
  --accent-soft: #e5eafc;
  --info-bg: #e5eafc;
  --info: #2c42ad;
  --ok: #17753a;
  --ok-bg: #def4e3;
  --bad: #c0301c;
  --bad-bg: #fde7e2;
  /* ba mức độ khó: ink = chữ, bg = nền huy hiệu, line = viền/vạch/dải (>= 3:1 trên nền) */
  --easy-ink: #0a6670;   --easy-bg: #d6f2f3;   --easy-line: #0b8a94;
  --medium-ink: #7a4700; --medium-bg: #ffefc4; --medium-line: #b57000;
  --hard-ink: #6b2bb8;   --hard-bg: #eee3fc;   --hard-line: #8a4fd9;
  --code: #eef1fb;
  --zebra: #f7f9fe;
  --focus: #3d57d6;
  --shadow: 0 1px 2px rgba(27, 35, 64, .05), 0 8px 20px -14px rgba(27, 35, 64, .28);
  --shadow-up: 0 12px 24px -12px rgba(27, 35, 64, .38);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1527;
    --surface: #182038;
    --surface-2: #212b4a;
    --ink: #e8ecf8;
    --muted: #a5afc8;
    --line: #2d3860;
    --accent: #8ea2ff;
    --accent-deep: #6f86f5;
    --accent-ink: #0f1527;
    --accent-soft: #263261;
    --info-bg: #263261;
    --info: #b3c0ff;
    --ok: #6fdc92;
    --ok-bg: #143325;
    --bad: #ff8f7c;
    --bad-bg: #3d1d1b;
    --easy-ink: #6fe0e8;   --easy-bg: #0f3b41;   --easy-line: #2fb8c4;
    --medium-ink: #ffcd5e; --medium-bg: #42310a; --medium-line: #e0a124;
    --hard-ink: #cfa9ff;   --hard-bg: #33214f;   --hard-line: #a878f0;
    --code: #121a30;
    --zebra: #1c2542;
    --focus: #8ea2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-up: 0 12px 24px -12px rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }   /* thanh mock dính trên cùng không che phần tử đang focus */
a, button, summary, label, .chip { touch-action: manipulation; -webkit-tap-highlight-color: rgba(61, 87, 214, .15); }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--sans);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 50; border-radius: 0 0 10px 0; }
.skip:focus { left: 8px; top: 8px; }
/* thuộc tính hidden luôn thắng các lớp đặt display (vd .btn inline-flex, .ask-sugg flex) */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */
.topbar {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px;
  padding: 12px 18px 14px; background: var(--surface);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: linear-gradient(90deg, var(--easy-line) 0 33.34%, var(--medium-line) 0 66.67%, var(--hard-line) 0);
}
.brand { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; text-decoration: none; letter-spacing: -0.01em; }
.brand-mark { flex: 0 0 auto; }
.nav { display: flex; gap: 4px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: thin; overscroll-behavior-x: contain; padding: 2px; }
.nav a { flex: 0 0 auto; white-space: nowrap; padding: 6px 12px; border-radius: 999px; color: var(--ink); text-decoration: none; font-weight: 700; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 800; }

main { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 24px 18px 32px; outline: none; }
main:focus-visible { outline: none; }   /* main chỉ nhận focus bằng code sau khi đổi trang; không vẽ viền focus quanh cả trang */
/* trang bài và câu hỏi dùng hết bề ngang màn hình (cột AI nằm cạnh nội dung) */
main.wide { max-width: none; padding: 12px clamp(16px, 1.6vw, 28px) 32px; }
.disclaimer {
  padding: 14px 18px 18px; color: var(--muted); font-size: 13.5px; text-align: center; max-width: 900px; margin: 0 auto;
}
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.02em; font-weight: 800; }
h2 { font-size: 18px; line-height: 1.3; margin: 0 0 10px; letter-spacing: -0.01em; font-weight: 800; }
h3 { font-size: 15px; margin: 0 0 6px; font-weight: 800; }
h1, h2 { text-wrap: balance; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- nút ---------- */
.btn {
  font: inherit; font-weight: 700; padding: 8px 16px; border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); min-height: 40px; touch-action: manipulation; text-decoration: none;
  box-shadow: 0 2px 0 var(--line);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 3px 0 var(--accent-deep); }
.btn-primary:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.06); }
.btn-accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); box-shadow: 0 3px 0 var(--accent); }
.btn-ghost { background: transparent; box-shadow: none; }
.btn:active:not(:disabled) { box-shadow: none; }
.kbd { font: 11px var(--mono); padding: 1px 5px; border: 1px solid currentColor; border-radius: 5px; opacity: .8; margin-left: 6px; }

/* ---------- danh sách ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 18px; }
.page-head .lead { margin: 0; max-width: 62ch; }
.meter { min-width: min(100%, 260px); flex: 0 1 320px; }
.meter-t { display: flex; justify-content: space-between; gap: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.meter .bar { height: 12px; margin-top: 6px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.sum-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.sum-card .t { font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
.sum-card .n { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }
.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin-top: 8px; }
.bar i { display: block; height: 100%; transform-origin: left center; }
.bar .p { background: var(--ok); } .bar .f { background: var(--bad); }
.filters { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-bottom: 14px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips > span.lbl { color: var(--muted); font-size: 14px; font-weight: 700; margin-right: 2px; }
.chip {
  touch-action: manipulation; min-height: 32px; font: inherit; font-size: 14px; font-weight: 700; padding: 4px 13px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.d-easy, .chip.d-medium, .chip.d-hard { background: var(--d-bg); color: var(--d-ink); border-color: var(--d-line); }
.chip.d-easy[aria-pressed="true"], .chip.d-medium[aria-pressed="true"], .chip.d-hard[aria-pressed="true"] { background: var(--d-ink); color: var(--d-bg); border-color: var(--d-ink); }
.chip.d-easy[aria-pressed="true"] .lv i, .chip.d-medium[aria-pressed="true"] .lv i, .chip.d-hard[aria-pressed="true"] .lv i { border-color: var(--d-bg); }
.chip.d-easy[aria-pressed="true"] .lv i.on, .chip.d-medium[aria-pressed="true"] .lv i.on, .chip.d-hard[aria-pressed="true"] .lv i.on { background: var(--d-bg); }

/* màu độ khó: gán --d-* theo class d-easy / d-medium / d-hard */
.d-easy { --d-ink: var(--easy-ink); --d-bg: var(--easy-bg); --d-line: var(--easy-line); }
.d-medium { --d-ink: var(--medium-ink); --d-bg: var(--medium-bg); --d-line: var(--medium-line); }
.d-hard { --d-ink: var(--hard-ink); --d-bg: var(--hard-bg); --d-line: var(--hard-line); }
.dpill {
  display: inline-flex; align-items: center; gap: 7px; padding: 1px 11px 1px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--d-bg); color: var(--d-ink); border: 1px solid var(--d-line); font-size: 13px; font-weight: 800; line-height: 1.5;
}
.lv { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.lv i { width: 4px; border-radius: 2px; border: 1px solid var(--d-line); background: transparent; }
.lv i.on { background: var(--d-line); }
.lv i:nth-child(1) { height: 5px; } .lv i:nth-child(2) { height: 8px; } .lv i:nth-child(3) { height: 12px; }

.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.task-list > li { position: relative; border-radius: 14px; }
.task-list > li::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: var(--shadow-up); opacity: 0; pointer-events: none;
}
.task-list > li:hover::after { opacity: 1; }
.task-row {
  position: relative; overflow: hidden; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 14px; align-items: center;
  padding: 12px 16px 12px 20px; color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.task-row::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--d-line, var(--line)); }
.task-row:hover { border-color: var(--d-line, var(--accent)); }
.task-row:focus-visible { outline-offset: -3px; }
.task-title { font-weight: 800; font-size: 16.5px; }
.task-meta { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 14px; align-items: center; }
.task-side { grid-row: 1 / span 2; grid-column: 3; display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.status { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 13px; font-weight: 800; border: 2px dashed var(--line); color: transparent; grid-row: 1 / span 2; }
.status.passed { background: var(--ok); border: 2px solid var(--ok); color: var(--surface); }
.status.failed { border: 2px solid var(--bad); color: var(--bad); }
.tag { font-size: 13px; padding: 0 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.badge { font-size: 13px; font-weight: 800; padding: 0 9px; border-radius: 6px; background: var(--info-bg); color: var(--info); }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty.task-list { display: block; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }

/* ---------- trang bài ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.crumbs .nav-btns { display: flex; gap: 8px; }
.task-head { margin-bottom: 16px; }
.task-head .task-meta { grid-column: auto; margin-top: 6px; }
.workspace { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 18px; align-items: start; }
.col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; min-width: 0; align-content: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; min-width: 0; box-shadow: var(--shadow); }
.panel > h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.prose { overflow-wrap: anywhere; max-width: 78ch; line-height: 1.65; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 22px; }
.prose code, code.inline { font: 13.5px var(--mono); background: var(--code); padding: 1px 6px; border-radius: 6px; }
.prose pre { background: var(--code); padding: 10px 12px; border-radius: 10px; overflow: auto; font: 13.5px/1.55 var(--mono); max-width: 100%; }
.prose pre code { background: none; padding: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 16px 0 6px; line-height: 1.3; font-weight: 800; letter-spacing: -0.01em; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: 20px; } .prose h2 { font-size: 17px; color: var(--accent); } .prose h3 { font-size: 15.5px; } .prose h4 { font-size: 15px; }
/* heading do AI viết (đã hạ cấp trong mdSafe): kiểu chữ theo cấp gốc */
.prose .mh1 { font-size: 18px; } .prose .mh2 { font-size: 17px; color: var(--accent); } .prose .mh3 { font-size: 15.5px; color: var(--ink); } .prose .mh4 { font-size: 15px; color: var(--ink); }
.prose li { margin-bottom: 3px; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.prose th, .prose td { padding: 6px 12px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); font-weight: 800; white-space: nowrap; }
.prose tbody tr:nth-child(even) td { background: var(--zebra); }
.prose td code, .prose th code { white-space: nowrap; }
.prose blockquote { margin: 0 0 10px; padding: 4px 14px; border-left: 4px solid var(--line); color: var(--muted); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.schema details { border-top: 1px solid var(--line); padding: 8px 0; }
.schema details:first-of-type { border-top: 0; }
.schema summary { cursor: pointer; font-weight: 700; display: flex; gap: 8px; align-items: baseline; }
.schema summary .rc { color: var(--muted); font-weight: 400; font-size: 14px; }
.cols { list-style: none; margin: 8px 0; padding: 0; font: 13.5px var(--mono); display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 2px 14px; }
.cols .ty { color: var(--muted); }
.hints { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 8px; }
.hint { padding: 9px 13px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 12px 12px 0; }
.hint b { display: block; font-size: 13px; color: var(--accent); }

.editor-wrap { border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.editor-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.CodeMirror { height: 300px; font: 14px/1.6 var(--mono); background: var(--surface); color: var(--ink); }
.CodeMirror-gutters { background: var(--surface-2); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: var(--muted); }
.CodeMirror-cursor { border-left: 2px solid var(--ink); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--accent-soft); }
.cm-s-default .cm-keyword { color: #2c42ad; font-weight: 700; } .cm-s-default .cm-builtin { color: #7a3e9d; }
.cm-s-default .cm-string, .cm-s-default .cm-string-2 { color: #17704a; } .cm-s-default .cm-number { color: #a85b00; }
.cm-s-default .cm-comment { color: var(--muted); font-style: italic; } .cm-s-default .cm-variable-2, .cm-s-default .cm-variable { color: var(--ink); }
.cm-s-default .cm-atom { color: #a85b00; } .cm-s-default .cm-operator { color: var(--ink); } .cm-s-default .cm-bracket { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .cm-s-default .cm-keyword { color: #9db0ff; } .cm-s-default .cm-builtin { color: #d9b4f5; }
  .cm-s-default .cm-string, .cm-s-default .cm-string-2 { color: #6fdc92; } .cm-s-default .cm-number, .cm-s-default .cm-atom { color: #f5bd6e; }
}
.cm-error-line { background: var(--bad-bg) !important; }
.cm-error-mark { text-decoration: underline wavy var(--bad); text-underline-offset: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; align-items: center; }
.actions .spacer { flex: 1; }

.result { margin-top: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
.meta-line { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 14px; }
.notice { background: var(--info-bg); color: var(--info); padding: 9px 13px; border-radius: 12px; font-size: 14px; font-weight: 600; }
.errbox { border: 1.5px solid var(--bad); background: var(--bad-bg); border-radius: 12px; padding: 11px 14px; overflow-wrap: anywhere; }
.errbox .msg { font-weight: 800; color: var(--bad); }
.errbox dl { margin: 6px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; }
.errbox dt { color: var(--muted); } .errbox dd { margin: 0; }
.scroll { overflow: auto; overscroll-behavior: contain; max-height: 360px; border: 1px solid var(--line); border-radius: 12px; max-width: 100%; }
table.grid { border-collapse: collapse; width: 100%; font: 13.5px var(--mono); }
table.grid th, table.grid td { padding: 6px 11px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid tbody tr:nth-child(even) td { background: var(--zebra); }
table.grid th { position: sticky; top: 0; background: var(--surface-2); z-index: 1; font-weight: 700; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.null { color: var(--muted); font-style: italic; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid td.rn, table.grid th.rn { color: var(--muted); text-align: right; width: 1%; }

/* kết quả nộp bài */
.verdict { border-radius: var(--r); padding: 14px 16px; border: 1.5px solid; display: flex; gap: 14px; align-items: flex-start; }
.verdict.ok { background: var(--ok-bg); border-color: var(--ok); }
.verdict.no { background: var(--bad-bg); border-color: var(--bad); }
.v-ico { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 800; line-height: 1; }
.verdict.ok .v-ico { background: var(--ok); color: var(--surface); }
.verdict.no .v-ico { background: var(--bad); color: var(--surface); }
.v-body { min-width: 0; flex: 1; }
.verdict .vt { font-size: 20px; font-weight: 800; line-height: 1.3; }
.verdict.ok .vt { color: var(--ok); } .verdict.no .vt { color: var(--bad); }
.diff-box { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.diff-box > p { margin: 0; line-height: 1.5; }
.diff-box code.inline + code.inline { margin-left: 2px; }
.diff-box h3 { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { font-size: 13px; font-weight: 800; padding: 0 9px; border-radius: 999px; }
.pill.miss { background: var(--info-bg); color: var(--info); } .pill.extra { background: var(--bad-bg); color: var(--bad); }
.solution pre { background: var(--code); border-radius: 12px; padding: 12px 14px; overflow: auto; font: 13.5px/1.55 var(--mono); margin: 0 0 12px; }
.solution ul { padding-left: 20px; margin: 0; }
.solution h3 { margin-top: 14px; }

dialog { border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink); padding: 22px 24px; max-width: min(92vw, 440px); box-shadow: var(--shadow-up); }
dialog::backdrop { background: rgba(10, 16, 36, .6); }
dialog h2 { margin-bottom: 6px; } dialog p { margin: 0 0 16px; color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60; max-width: 90vw; font-weight: 700; }

/* trạng thái đang tải */
.loading { display: flex; align-items: center; gap: 10px; }
.spin { flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); }

/* ---------- vòng 2: lý thuyết, mock, tiến độ ---------- */
.workspace.single { grid-template-columns: minmax(0, 1fr); max-width: 900px; }
.narrow { max-width: 640px; }
.panel.inner { background: var(--surface-2); border-color: transparent; box-shadow: none; }
textarea.answer, textarea.ask-q {
  width: 100%; min-height: 200px; resize: vertical; font: 16px/1.6 var(--sans); color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px;
}
textarea.answer:focus-visible, textarea.ask-q:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
textarea.answer.mono { font: 13.5px/1.5 var(--mono); min-height: 120px; }
.result-stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.pts { padding: 9px 13px; border-radius: 12px; border-left: 4px solid var(--line); background: var(--surface-2); }
.pts h3 { margin: 0 0 4px; } .pts ul { margin: 0; padding-left: 20px; }
.pts.good { border-left-color: var(--ok); } .pts.miss { border-left-color: var(--accent); } .pts.bad { border-left-color: var(--bad); }
.rubric { border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 14px; margin: 0 0 8px; min-width: 0; }
.rubric legend { font-weight: 800; padding: 0 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 3px; flex: 0 0 auto; accent-color: var(--accent); }
.live-score { font-size: 20px; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: max-content minmax(0, 120px); gap: 10px 14px; align-items: center; margin-bottom: 8px; }
.form-grid label { font-weight: 700; }
.form-grid input { font: inherit; padding: 8px 11px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); width: 100%; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ans-pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--code); padding: 11px 14px; border-radius: 12px; font: 13.5px/1.5 var(--mono); margin: 0 0 8px; max-width: 100%; overflow: auto; }

/* mock: giữ tĩnh, không chuyển động gần đồng hồ */
.mock-bar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.mock-bar-l, .mock-bar-r { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.timer { font: 800 26px var(--mono); font-variant-numeric: tabular-nums; letter-spacing: .02em; min-width: 5.2ch; }
.timer.low { color: var(--bad); }
.mock-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 16px; align-items: start; }
.mock-content { min-width: 0; }
.mock-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; position: sticky; top: 80px; }
.mock-item { width: 100%; display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; gap: 0 8px; text-align: left; font: inherit; padding: 7px 11px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); cursor: pointer; touch-action: manipulation; }
.mock-item:hover { border-color: var(--accent); }
.mock-item.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); background: var(--accent-soft); }
.mock-item .mn { grid-row: 1 / span 2; font-weight: 800; align-self: center; font-variant-numeric: tabular-nums; }
.mock-item .mt { font-weight: 700; font-size: 14px; white-space: nowrap; } .mock-item .mm { font-size: 13px; color: var(--muted); }
.score-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.score-big { font-size: 60px; line-height: 1; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: var(--accent); }
.score-big span { font-size: 24px; color: var(--muted); font-weight: 600; margin-left: 2px; }
.sum-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sum-row { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.sum-row.weak { border-left: 4px solid var(--bad); }
.sum-row summary { display: flex; gap: 10px; align-items: center; padding: 9px 14px; cursor: pointer; flex-wrap: wrap; }
.sr-n { font-weight: 800; min-width: 1.5ch; } .sr-t { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; } .sr-s { font-weight: 800; font-variant-numeric: tabular-nums; }
.sum-detail { padding: 4px 16px 14px; border-top: 1px solid var(--line); }

/* tiến độ và cần làm lại */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { position: relative; display: grid; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; color: inherit; text-decoration: none; box-shadow: var(--shadow); }
a.stat::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: var(--shadow-up); opacity: 0; pointer-events: none; }
a.stat:hover::after { opacity: 1; }
a.stat:hover { border-color: var(--accent); }
.stat-v { font-size: 34px; line-height: 1.15; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--accent); }
.stat-l { font-weight: 700; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; align-items: start; }
.grp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.grp-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grp-t { font-weight: 700; } .grp-n { font-variant-numeric: tabular-nums; color: var(--muted); }
.bar.big { height: 14px; margin: 5px 0; } .bar .a { background: var(--accent); opacity: .45; }
.ok-t { color: var(--ok); font-weight: 800; } .bad-t { color: var(--bad); font-weight: 800; }
.reason { color: var(--bad); font-weight: 700; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .mock-layout { grid-template-columns: minmax(0, 1fr); } .mock-nav { position: static; grid-auto-flow: column; grid-auto-columns: minmax(124px, 1fr); overflow-x: auto; padding-bottom: 4px; }
}
@media (max-width: 560px) {
  main { padding: 16px 14px 24px; }
  h1 { font-size: 23px; }
  .task-row { grid-template-columns: 28px minmax(0, 1fr); padding-right: 12px; }
  .task-side { grid-row: auto; grid-column: 2; justify-content: flex-start; }
  .brand span { font-size: 15px; }
  .kbd { display: none; }
  .CodeMirror { height: 260px; }
  .actions .btn { flex: 1 1 auto; }
  .nav a { padding: 6px 10px; font-size: 15px; }
  .timer { font-size: 21px; }
  .score-big { font-size: 46px; }
  .mock-bar { position: static; }
  .verdict { padding: 12px; gap: 10px; } .v-ico { width: 34px; height: 34px; font-size: 19px; }
}

/* ---------- hội thoại trong cột AI ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; margin: 0 0 12px; }
.chat:empty { display: none; }
.cmsg { max-width: min(94%, 72ch); padding: 10px 14px 11px; border-radius: 14px; overflow-wrap: anywhere; min-width: 0; }
.cmsg .who { display: block; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 2px; letter-spacing: .01em; }
.cmsg.me { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.cmsg.me .cmsg-text { white-space: pre-wrap; }
.cmsg.ai { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; max-width: 100%; }
.cmsg.ai .prose { max-width: none; }
.cmsg.ai .prose pre { background: var(--surface); }
.ask-sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.ask-sugg .chip { text-align: left; }
.ask-status:empty { display: none; }
.ask-status { margin-bottom: 10px; }
textarea.ask-q { min-height: 64px; max-height: 160px; }

/* ---------- trang Cài đặt (nhập API key) ---------- */
.settings .ai-state { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; padding: 4px 14px 4px 10px; border-radius: 999px; margin-bottom: 10px; border: 1.5px solid; }
.settings .ai-state.on { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.settings .ai-state.off { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0 0 12px; font-size: 15px; }
.kv dt { color: var(--muted); font-weight: 700; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.kv dd.mono { font-family: var(--mono); font-size: 14px; line-height: 22.5px; }
.set-note:empty { display: none; }
.set-note { display: grid; gap: 8px; margin-bottom: 12px; }
.key-form { border-top: 1px solid var(--line); padding-top: 14px; }
.key-form .lbl { display: block; font-weight: 800; margin-bottom: 6px; }
.key-row { display: flex; gap: 8px; align-items: stretch; }
.key-row .btn { flex: 0 0 auto; min-width: 64px; }
input.text-in { flex: 1 1 auto; min-width: 0; width: 100%; font: 16px/1.4 var(--sans); color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 14px; }
input.text-in.mono { font-family: var(--mono); font-size: 15px; letter-spacing: .02em; }
input.text-in:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--accent); }
.field-hint { margin: 6px 0 0; }
.btn-danger { color: var(--bad); }
.btn-danger:hover:not(:disabled) { border-color: var(--bad); }
.set-list { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
@media (max-width: 560px) {
  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; } .kv dd { margin-bottom: 8px; }
}

/* ---------- bố cục học tập: nội dung + cột AI ---------- */
.task-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-areas: "top top" "left mid"; gap: 14px 20px; align-items: start; }
.task-top { grid-area: top; min-width: 0; }
.task-top .crumbs { margin-bottom: 10px; }
.task-top .task-head { margin-bottom: 4px; }
.task-layout > .col-left { grid-area: left; } .task-layout > .col-mid { grid-area: mid; } .task-layout > .col-main { grid-area: main; }
.task-layout.has-dock { grid-template-columns: clamp(290px, 22vw, 480px) minmax(0, 1fr) clamp(350px, 27vw, 600px); grid-template-areas: "top top ai" "left mid ai"; }
.task-layout.theory { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; max-width: 900px; margin: 0 auto; }
.task-layout.theory.has-dock { grid-template-columns: minmax(0, 1100px) clamp(380px, 30vw, 560px); grid-template-areas: "top ai" "main ai"; max-width: none; justify-content: center; }
/* vùng lưới kéo dài xuống đáy trang (xem syncDock trong app.js) để cột AI không bị đẩy lên dưới header khi cuộn hết trang */
.task-layout.has-dock { margin-bottom: calc(-1 * var(--foot-h, 0px)); }
.task-layout.has-dock > .col-left, .task-layout.has-dock > .col-mid, .task-layout.has-dock > .col-main { padding-bottom: var(--foot-h, 0px); }
body.ai-docked .disclaimer { padding-right: calc(var(--ai-w, 0px) + 40px); }
@media (max-width: 1000px) { .task-layout:not(.theory) { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "left" "mid"; } }
@media (min-width: 1100px) { .topbar { position: sticky; top: 0; z-index: 40; } }
@media (max-width: 1279px) { main.wide { padding-bottom: 88px; } }
@media (max-width: 1599px) { .task-layout.has-dock .col-mid .actions .kbd { display: none; } }

.ai-col { grid-area: ai; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.ai-col.docked {
  z-index: 5; position: sticky; top: calc(var(--head-h, 68px) + 12px); align-self: start;
  height: calc(100vh - var(--head-h, 68px) - 24px); height: calc(100dvh - var(--head-h, 68px) - 24px);
}
.ai-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.ai-head h2 { margin: 0; display: flex; flex-direction: column; gap: 0; font-size: 17px; line-height: 1.25; }
.ai-head .ai-model { font-weight: 600; overflow-wrap: anywhere; }
.ai-col.docked .ai-close { display: none; }
.ai-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: grid; gap: 18px; align-content: start; grid-template-columns: minmax(0, 1fr); }
.ai-scroll:focus-visible { outline-offset: -3px; }
.ai-off { padding: 2px 0; }
.ai-note { margin: 0; }
.ask-thread h3, .ex-card h3 { font-size: 15.5px; }
.ex-card { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 14px; padding: 14px 16px 12px; min-width: 0; }
.ex-card h3 { margin: 0 0 8px; }
.ex-body .prose { max-width: none; font-size: 15.5px; }
.ex-body .prose .mh2:first-child { margin-top: 0; }
.ex-meta { margin-top: 10px; }
.ex-meta:empty { display: none; }
.ex-stale { color: var(--info); font-weight: 700; }
.ex-actions { margin-top: 10px; }
.ex-actions:not(:has(.btn:not([hidden]))) { display: none; }
.ask-form { flex: none; padding: 10px 14px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.ask-form .actions { margin-top: 8px; }

/* dưới breakpoint: cột AI là ngăn kéo mở bằng nút nổi */
.ai-col:not(.docked) { position: fixed; z-index: 60; right: 0; top: 0; bottom: var(--kb, 0px); width: min(460px, 100vw); border-radius: 0; border-width: 0 0 0 1px; visibility: hidden; transform: translateX(100%); box-shadow: -14px 0 32px -14px rgba(0, 0, 0, .45); }
.ai-col:not(.docked).open { visibility: visible; transform: none; }
.ai-backdrop { position: fixed; inset: 0; z-index: 55; background: rgba(8, 12, 28, .5); opacity: 0; visibility: hidden; }
.ai-backdrop.open { opacity: 1; visibility: visible; }
.ai-fab { position: fixed; right: 16px; bottom: 16px; z-index: 50; padding: 12px 20px 12px 16px; border-radius: 999px; font-size: 16px; box-shadow: 0 3px 0 var(--accent-deep), 0 12px 24px -10px rgba(0, 0, 0, .55); }
.ai-fab-ico { font-size: 18px; line-height: 1; }
.ai-dot { position: absolute; top: -3px; right: -3px; width: 14px; height: 14px; border-radius: 50%; background: var(--medium-line); border: 2.5px solid var(--surface); }
body.ai-open { overflow: hidden; }
@media (max-width: 600px) {
  .ai-col:not(.docked) { left: 0; right: 0; top: 36px; width: auto; border-width: 1px 0 0; border-radius: 18px 18px 0 0; transform: translateY(100%); }
  .ai-col:not(.docked).open { transform: none; }
}

/* ---------- Sổ tay ---------- */
.nb-stats { margin-bottom: 14px; }
.nb-filters { margin-bottom: 8px; }
.nb-search { flex: 1 1 260px; min-width: 220px; max-width: 460px; }
.nb-count { margin: 0 0 12px; }
.nb-group { margin-bottom: 26px; }
.nb-group > h2 { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.nb-items { display: grid; gap: 10px; }
.nb-item { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.nb-item::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--d-line, var(--line)); }
.nb-item[open] { border-color: var(--d-line, var(--accent)); }
.nb-item > summary { list-style: none; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto 18px; gap: 4px 14px; align-items: center; padding: 12px 16px 12px 22px; cursor: pointer; }
.nb-item > summary::-webkit-details-marker { display: none; }
.nb-item > summary::after { content: "▾"; color: var(--muted); font-size: 14px; }
.nb-item[open] > summary::after { content: "▴"; }
.nb-item > summary:hover { background: var(--zebra); }
.nb-item > summary:focus-visible { outline-offset: -3px; }
.nb-t { font-weight: 800; font-size: 16.5px; min-width: 0; overflow-wrap: anywhere; }
.nb-m { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; justify-content: flex-end; }
.nb-body { display: grid; gap: 16px; padding: 14px 22px 18px; border-top: 1px solid var(--line); }
.nb-sec h3 { font-size: 15.5px; margin: 0 0 6px; }
.nb-sec h4 { font-size: 14.5px; margin: 10px 0 4px; }
.nb-sec .ans-pre { margin-bottom: 6px; max-height: 360px; }
.ans-text { font-family: var(--sans); font-size: 15.5px; line-height: 1.6; }
.nb-points { margin: 0 0 8px; padding-left: 22px; }
.ex-block .ex-body .prose { max-width: 90ch; }
@media (max-width: 700px) {
  .nb-item > summary { grid-template-columns: 28px minmax(0, 1fr) 18px; padding-right: 12px; }
  .nb-m { grid-column: 2 / span 2; grid-row: 2; justify-content: flex-start; }
  .nb-body { padding: 12px 14px 16px 18px; }
}

/* ---------- trang chủ "Học" ---------- */
.home-hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 28px; margin-bottom: 16px; }
.home-hero h1 { margin-bottom: 4px; }
.home-hero .lead { margin: 0; max-width: 56ch; }
.home-first-note { margin: 0; max-width: 40ch; }
.home-stats { display: flex; flex-wrap: wrap; gap: 10px; }
.home-stat { display: grid; gap: 0; min-width: 150px; padding: 10px 16px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.home-stat-v { font-size: 26px; line-height: 1.2; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.home-stat-l { font-weight: 700; font-size: 14.5px; }
.home-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; margin-bottom: 14px; padding: 12px 16px; border-radius: var(--r); background: var(--medium-bg); color: var(--medium-ink); border: 1.5px solid var(--medium-line); }
.home-banner .btn { flex: 0 0 auto; }
.home-ai-note { margin: 0 0 14px; }
.home-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; margin-bottom: 16px; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); gap: 16px; margin-bottom: 16px; align-items: start; }
.home-card { position: relative; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow); }
.home-card h2 { font-size: 17px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.home-action { overflow: hidden; display: flex; flex-direction: column; gap: 8px; padding-left: 24px; }
.home-action::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--d-line, var(--accent)); }
.home-action .actions { margin-top: auto; padding-top: 6px; }
.home-label { font-size: 13.5px; font-weight: 800; color: var(--muted); letter-spacing: .01em; }
.home-title { font-size: 20px; line-height: 1.3; margin: 0; display: block; }
.home-title-link { color: var(--ink); text-decoration: none; }
.home-title-link:hover { text-decoration: underline; text-underline-offset: 4px; }
.home-action .task-meta { grid-column: auto; }
.home-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.home-row { position: relative; display: grid; gap: 3px; padding: 9px 12px 9px 16px; border-radius: 12px; background: var(--surface-2); color: inherit; text-decoration: none; overflow: hidden; }
.home-row::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--d-line, var(--line)); }
.home-row:hover { background: var(--zebra); outline: 1.5px solid var(--d-line, var(--accent)); }
.home-row-t { font-weight: 700; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.home-row-m { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.home-progress { margin-bottom: 8px; }
.home-prog-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 12px 32px; }
.home-prog-cols h3 { font-size: 15.5px; margin-bottom: 8px; }
@media (max-width: 560px) { .home-stat { flex: 1 1 140px; } .home-action { padding-left: 22px; } }

/* ---------- chuyển động: chỉ khi người dùng không bật "giảm chuyển động"; chỉ transform và opacity ---------- */
@media (prefers-reduced-motion: no-preference) {
  .btn, .chip { transition: transform .15s ease-out; }
  .btn:active:not(:disabled) { transform: translateY(2px) scale(.98); }
  .chip:active { transform: scale(.94); }
  .btn-primary:active:not(:disabled), .btn-accent:active:not(:disabled) { transform: translateY(3px) scale(.98); }
  .task-list > li, a.stat { transition: transform .18s ease-out; }
  .task-list > li::after, a.stat::after { transition: opacity .18s ease-out; }
  .task-list > li:hover, a.stat:hover { transform: translateY(-2px); }
  .mock-item { transition: transform .15s ease-out; }
  .mock-item:active { transform: scale(.98); }

  /* trang mới hiện mờ dần, các khối trên cùng so le nhẹ; mock-bar (đồng hồ) và nội dung mock giữ tĩnh */
  #app > :not(.loading):not(.mock-bar) { animation: rise .32s ease-out both; }
  #app > :nth-child(2) { animation-delay: .04s; } #app > :nth-child(3) { animation-delay: .08s; }
  #app > :nth-child(4) { animation-delay: .12s; } #app > :nth-child(n+5) { animation-delay: .16s; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  /* trang bài/câu hỏi: chính khối bố cục không có animation (phần tử đang animate transform/opacity sẽ thành "khối chứa" và nhốt z-index
     của cột AI dạng ngăn kéo, position: fixed); các khối con tự mờ dần, riêng cột AI đứng yên */
  #app > .task-layout:not(.loading):not(.mock-bar) { animation: none; }
  #app > .task-layout > :not(.ai-col) { animation: fade-in .32s ease-out both; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

  /* thanh tiến độ chạy tới giá trị (width đã đặt sẵn, chỉ scaleX chạy) */
  .bar i { animation: grow .7s cubic-bezier(.2, .7, .2, 1) both; }
  .bar i + i { animation-delay: .12s; }
  @keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

  .chip[aria-pressed="true"] { animation: chip-pop .28s ease-out; }
  @keyframes chip-pop { 0% { transform: scale(.9); } 60% { transform: scale(1.06); } 100% { transform: scale(1); } }

  .verdict, .errbox, .cmsg { animation: appear .22s ease-out; }
  @keyframes appear { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  .verdict.ok .v-ico { animation: pop .5s cubic-bezier(.2, 1.5, .4, 1) .05s both; }
  @keyframes pop { from { opacity: 0; transform: scale(.3) rotate(-25deg); } to { opacity: 1; transform: none; } }

  .ai-col:not(.docked) { transition: transform .24s ease-out, visibility 0s linear .24s; }
  .ai-col:not(.docked).open { transition: transform .24s ease-out, visibility 0s; }
  .ai-backdrop { transition: opacity .2s ease-out, visibility 0s linear .2s; }
  .ai-backdrop.open { transition: opacity .2s ease-out, visibility 0s; }
  .ai-dot { animation: dot-pop .5s ease-out 2; }
  @keyframes dot-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }

  .toast { animation: toast-in .22s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translateX(-50%); } }

  .spin { animation: spin .8s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
}
/* lớp pháo giấy (JS chỉ tạo khi không bật giảm chuyển động) */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; width: 9px; height: 13px; border-radius: 2px; opacity: 0; }

/* điện thoại: ô nhập cỡ chữ >= 16px để iOS không tự phóng to trang khi chạm vào ô; ô ẩn của CodeMirror cũng vậy */
@media (max-width: 600px) { input, textarea, select, input.text-in, input.text-in.mono { font-size: 16px; } }
.CodeMirror textarea { font-size: 16px; }
@media (max-width: 600px) { .CodeMirror { font-size: 16px; } }   /* Android/iOS nhập qua vùng contenteditable của editor: cũng cần >= 16px */
