:root {
  --nen: #f7f7f5; --khung: #ffffff; --chu: #1f2328; --mo: #6b7280; --vien: #e5e7eb;
  --nguoi: #e8f0fe; --bot: #ffffff; --chip: #f1f3f5; --chip-chu: #1a5cff; --nhan: #1a5cff; --nhan-chu: #fff;
  --ma: #f1f3f5; --bong: 0 1px 2px rgba(0,0,0,.06);
  --db: #c62828; --db-nen: #fff1f1; --lap: #b45309; --xanh: #15803d;
  --q1: #dbeafe; --q2: #93c5fd; --q3: #3b82f6; --q4: #1d4ed8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nen: #0f1115; --khung: #161a20; --chu: #e6e8eb; --mo: #9aa3ad; --vien: #262c35;
    --nguoi: #1e2a3d; --bot: #161a20; --chip: #1c2230; --chip-chu: #8ab4ff; --nhan: #3b7cff; --nhan-chu: #fff;
    --ma: #0f131a; --bong: none;
    --db: #ff7a7a; --db-nen: #2a1719; --lap: #f5b263; --xanh: #4ade80;
    --q1: #1e2a3d; --q2: #1e3a8a; --q3: #2563eb; --q4: #60a5fa;
  }
}
:root[data-theme="dark"] {
  --nen: #0f1115; --khung: #161a20; --chu: #e6e8eb; --mo: #9aa3ad; --vien: #262c35;
  --nguoi: #1e2a3d; --bot: #161a20; --chip: #1c2230; --chip-chu: #8ab4ff; --nhan: #3b7cff; --nhan-chu: #fff;
  --ma: #0f131a; --bong: none;
  --db: #ff7a7a; --db-nen: #2a1719; --lap: #f5b263; --xanh: #4ade80;
  --q1: #1e2a3d; --q2: #1e3a8a; --q3: #2563eb; --q4: #60a5fa;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--nen); color: var(--chu); font: 16px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh; }
.an { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.dau { position: sticky; top: 0; background: var(--nen); border-bottom: 1px solid var(--vien); z-index: 2; }
.dau-trong { max-width: 760px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; }
.ten { font-weight: 600; }
.dau-phai { display: flex; gap: 8px; align-items: center; }
.tk-ten { color: var(--mo); font-size: 13px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nut-nho { background: none; border: 1px solid var(--vien); color: var(--mo); border-radius: 8px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.khung { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px 8px; }
.chao { text-align: center; margin: 12vh 0 24px; }
.chao h1 { font-size: 22px; font-weight: 600; margin: 0 0 8px; }
.chao p { color: var(--mo); margin: 0 0 16px; }
.mau { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { background: var(--chip); color: var(--chip-chu); border: 1px solid var(--vien); border-radius: 999px; padding: 7px 12px;
  font-size: 14px; cursor: pointer; }
.chip:hover { filter: brightness(.96); }
.tin { display: flex; flex-direction: column; gap: 12px; }
.dong { display: flex; flex-direction: column; }
.dong.nguoi { align-items: flex-end; }
.bong-bong { max-width: min(92%, 640px); padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--bong); }
.nguoi .bong-bong { background: var(--nguoi); border-bottom-right-radius: 4px; }
.bot .bong-bong { background: var(--bot); border: 1px solid var(--vien); border-bottom-left-radius: 4px; }
.bong-bong pre { font: 13.5px/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--ma); padding: 8px 10px; border-radius: 8px;
  margin: 6px 0; overflow-x: auto; white-space: pre; }
.bong-bong code { font: 14px ui-monospace, Menlo, Consolas, monospace; background: var(--ma); padding: 0 4px; border-radius: 4px; }
.goi-y { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dang { color: var(--mo); font-size: 14px; padding: 6px 2px; }
.dang::after { content: ""; display: inline-block; width: 10px; animation: cham 1.2s steps(4, end) infinite; }
@keyframes cham { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.loi .bong-bong { border-color: #e0b4b4; }
.chan { position: sticky; bottom: 0; background: var(--nen); border-top: 1px solid var(--vien); padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.nhap { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--khung);
  border: 1px solid var(--vien); border-radius: 16px; padding: 6px 6px 6px 8px; box-shadow: var(--bong); }
.nut-lenh { flex: none; width: 34px; height: 34px; margin-bottom: 3px; border: 1px solid var(--vien); border-radius: 10px;
  background: var(--chip); color: var(--chip-chu); font: 600 16px/1 ui-monospace, Menlo, Consolas, monospace; cursor: pointer; }
.nut-lenh[aria-expanded="true"] { background: var(--nhan); color: var(--nhan-chu); border-color: var(--nhan); }
.menu-lenh { max-width: 760px; margin: 0 auto 6px; padding: 4px; background: var(--khung); border: 1px solid var(--vien);
  border-radius: 12px; box-shadow: var(--bong); max-height: 45vh; overflow-y: auto; }
.lenh-muc { display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left; background: none; border: none;
  color: var(--chu); font: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.lenh-muc:hover, .lenh-muc.chon { background: var(--chip); }
.lenh-ten { flex: none; min-width: 86px; font: 600 14px ui-monospace, Menlo, Consolas, monospace; color: var(--chip-chu); }
.lenh-mo-ta { color: var(--mo); font-size: 14px; }
.nhap textarea { flex: 1; border: none; background: transparent; color: var(--chu); font: inherit; resize: none; max-height: 140px;
  padding: 8px 0; outline: none; }
.nut-gui { width: 40px; height: 40px; border: none; border-radius: 12px; background: var(--nhan); color: var(--nhan-chu); font-size: 16px; cursor: pointer; }
.nut-gui:disabled { opacity: .5; cursor: default; }
.luu-y { max-width: 760px; margin: 6px auto 0; color: var(--mo); font-size: 12px; text-align: center; }
.luu-y a { color: var(--chip-chu); }
/* Giới thiệu: cửa sổ toàn màn hình (<dialog>) trên trang chat; trang /gioi-thieu đứng riêng dựng y hệt.
   Thanh trên dính (sticky) nên nút đóng luôn thấy được khi cuộn. */
.trang-phu { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0;
  border: none; background: var(--nen); color: var(--chu); overflow-y: auto; overscroll-behavior: contain; }
.trang-phu::backdrop { background: var(--nen); }
html.khoa-cuon { overflow: hidden; }
@media (prefers-reduced-motion: no-preference) {
  .trang-phu[open] { animation: hien-trang .18s ease-out; }
  @keyframes hien-trang { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
}
.dau .ten:is(h1, h2) { margin: 0; font-size: 16px; line-height: 1.45; }
.nut-dong { flex: none; width: 40px; height: 40px; margin: -6px -8px -6px 8px; padding: 0; border: none; border-radius: 10px;
  background: none; color: var(--mo); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.nut-dong:hover { background: var(--chip); color: var(--chu); }
.nut-dong:focus-visible { outline: 2px solid var(--nhan); outline-offset: 2px; }
.bai { padding-top: 20px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
.bai h2 { font-size: 17px; margin: 22px 0 8px; }
.bai p, .bai li { margin: 0 0 8px; }
.bai ul { padding-left: 20px; margin: 0; }
.bai a { color: var(--chip-chu); }
.bai .cap-nhat { color: var(--mo); font-size: 13px; margin-top: 20px; }
a.nut-nho { text-decoration: none; }
.xac-thuc { max-width: 760px; margin: 0 auto 8px; text-align: center; color: var(--mo); font-size: 14px; }
.xac-thuc p { margin: 0 0 6px; }
.xac-thuc > div { display: flex; justify-content: center; min-height: 65px; }
.dang-nhap { max-width: 760px; margin: 0 auto 8px; text-align: center; color: var(--mo); font-size: 14px; }
.dang-nhap p { margin: 0 0 8px; }
.dang-nhap > div { display: flex; justify-content: center; margin-bottom: 8px; }
.dang-nhap > div:empty { display: none; }
.nut-google { display: inline-block; padding: 9px 18px; border: 1px solid var(--vien); border-radius: 999px; background: var(--khung);
  color: var(--chu); font-size: 14px; font-weight: 600; text-decoration: none; box-shadow: var(--bong); }
.nut-google:hover { filter: brightness(.97); }

/* ---- kênh web: thẻ kết quả, bảng nhỏ, số bấm được (HTML do bot/dinh_dang.py sinh, kenh="web") ---- */
.bong-bong .kq, .bong-bong table, .bong-bong .goi { white-space: normal; }
.bong-bong { font-variant-numeric: tabular-nums; }
.bam, .lo { color: inherit; text-decoration: none; cursor: pointer; }
.bam { border-bottom: 1px dotted var(--chip-chu); }
.bam:hover, .lo:hover { color: var(--chip-chu); }
.kq { margin-top: 6px; }
.db { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; background: var(--db-nen);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; }
.db .nhan { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--db); font-weight: 600; }
.db .so { font-size: 30px; font-weight: 700; letter-spacing: .04em; line-height: 1; }
.db .lo2 { color: var(--db); }
.de { font-size: 13px; color: var(--db); border: 1px solid var(--db); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.de b { font-size: 16px; }
.giai { display: grid; grid-template-columns: 30px 1fr; gap: 8px; align-items: baseline; padding: 5px 0; border-top: 1px solid var(--vien); }
.giai .nhan { font-size: 12px; color: var(--mo); font-weight: 600; }
.cac-so { display: grid; gap: 4px 14px; justify-content: start; }
.cot-1 .cac-so { grid-template-columns: repeat(1, max-content); }
.cot-2 .cac-so { grid-template-columns: repeat(2, max-content); }
.cot-3 .cac-so { grid-template-columns: repeat(3, max-content); }
.cot-4 .cac-so { grid-template-columns: repeat(4, max-content); }
@media (max-width: 360px) { .cot-4 .cac-so { grid-template-columns: repeat(2, max-content); } }
.so { font-size: 17px; letter-spacing: .03em; }
.lo2 { font-weight: 700; }
.muc { font-size: 13px; color: var(--mo); font-weight: 600; margin: 12px 0 6px; }
.lo-to { display: flex; flex-wrap: wrap; gap: 6px; }
.lo { background: var(--ma); border-radius: 8px; padding: 4px 0; min-width: 40px; text-align: center; font-weight: 600; font-size: 15px; }
.lo sup { font-size: 10px; color: var(--lap); margin-left: 2px; }
.bong-bong table { border-collapse: collapse; width: 100%; margin: 4px 0; font-size: 14px; }
.bong-bong th, .bong-bong td { padding: 4px 6px; border-top: 1px solid var(--vien); text-align: left; vertical-align: top; }
.bong-bong thead th { border-top: none; font-size: 12px; color: var(--mo); text-transform: uppercase; letter-spacing: .06em; }
.dd tbody th, .ts tbody th { width: 30px; color: var(--mo); font-weight: 600; text-align: center; }
.dd thead th:first-child, .ts thead th:first-child { width: 30px; }
.dd td { letter-spacing: .04em; }
.ds th { width: 1%; white-space: nowrap; font-weight: 600; text-align: left; color: var(--chu); padding-right: 16px; }
.ds td { color: var(--chu); }
.ts { font-size: 13px; }
.ts th, .ts td { padding: 3px 4px; text-align: center; }
.ts thead th { text-align: center; }
.bong-bong tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--ma) 60%, transparent); }
.goi { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.goi .dau { color: var(--mo); font-size: 13px; }
.goi .m { background: var(--ma); border-radius: 8px; padding: 3px 8px; font-size: 14px; }

/* ---- đợt 1 soát màn hình: tiêu đề cột, chú giải, ô số lớn, ăn/trượt, chân mờ ---- */
.ds tr.td th, .ds tr.td td { color: var(--mo); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  border-top: none; padding-top: 2px; padding-bottom: 2px; }
.bong-bong tbody tr.td th { text-align: left; }
.chu-thich { color: var(--mo); font-size: 13px; font-weight: 400; }
.chan-mo { color: var(--mo); font-size: 12.5px; }
.o-so { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.o { background: var(--ma); border-radius: 10px; padding: 8px 10px; display: grid; gap: 2px; min-width: 0; }
.o .nhan { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--mo); }
.o .gia { font-size: 22px; font-weight: 700; line-height: 1.1; }
.o .gia small { font-size: 12px; font-weight: 500; color: var(--mo); }
.o .phu { font-size: 12px; color: var(--mo); }
tr.trung .dau-an { color: var(--xanh); font-weight: 600; }
tr.truot td { color: var(--mo); }
.bong-bong tbody tr.dang th, .bong-bong tbody tr.dang td { background: var(--db-nen); }
.m.bam { border-bottom: none; }

/* ---- đợt 2 soát màn hình: khối thống kê nhanh, bảng tần suất bậc màu, thanh đầu/đuôi, hướng dẫn bấm được ---- */
[data-lenh], [data-hoi] { cursor: pointer; }
.khoi-dau { display: flex; align-items: baseline; gap: 8px; margin: 12px 0 4px; padding-top: 8px; border-top: 1px solid var(--vien); }
.khoi-dau b { white-space: nowrap; }
.khoi-dau .chu-thich { flex: 1 1 auto; min-width: 0; }
.khoi-dau .xem-du { margin-left: auto; color: var(--chip-chu); font-size: 13px; white-space: nowrap; text-decoration: none; }
.ts td.q1 { background: var(--q1); } .ts td.q2 { background: var(--q2); }
.ts td.q3 { background: var(--q3); } .ts td.q4 { background: var(--q4); }
.ts td.q3 .ts-o, .ts td.q4 .ts-o { color: #fff; }
.ts .ts-o { color: inherit; text-decoration: none; display: block; }
.thanh-goi { display: grid; gap: 3px; margin: 4px 0; }
.thanh { display: grid; grid-template-columns: 16px 1fr 34px; gap: 8px; align-items: center; font-size: 13px; }
.thanh .k { color: var(--mo); text-align: center; }
.thanh .bar { height: 10px; background: var(--ma); border-radius: 5px; overflow: hidden; }
.thanh .fill { display: block; height: 100%; background: var(--nhan); border-radius: 5px; }
.fill.b0 { width: 10%; } .fill.b1 { width: 20%; } .fill.b2 { width: 30%; } .fill.b3 { width: 40%; } .fill.b4 { width: 50%; }
.fill.b5 { width: 60%; } .fill.b6 { width: 70%; } .fill.b7 { width: 80%; } .fill.b8 { width: 90%; } .fill.b9 { width: 100%; }
.thanh .v { text-align: right; }
