/* Học Vui giao diện v2: phong cách trò chơi, tham khảo tiethocvui.vn. Bản v1 lưu ở luu_cu\giao_dien_v1. */
:root {
  --bg: #f6f5ff;
  --card: #ffffff;
  --ink: #1e2140;
  --muted: #6b6f8e;
  --line: #e4e2f3;
  --brand: #5b4cdb;
  --brand-dark: #4335b8;
  --brand-soft: #ecebff;
  --brand-ink: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --bad: #e5484d;
  --bad-bg: #ffe4e6;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --c0: #ef4f5f;  /* 4 màu đáp án */
  --c1: #3b82f6;
  --c2: #22a565;
  --c3: #b45309;  /* cam đậm: chữ trắng đạt tương phản khoảng 5:1 */
  --tape: #ffd466;
  --paper-line: #dfe6f3;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(48, 40, 140, .08);
  --head: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif;
}
[hidden] { display: none !important; }  /* để thuộc tính hidden thắng display của .btn */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14152b;
    --card: #1f2142;
    --ink: #eceaff;
    --muted: #a3a6c8;
    --line: #34376a;
    --brand: #8b7dff;
    --brand-dark: #6c5ce7;
    --brand-soft: #2c2b5a;
    --ok: #4ade80;
    --ok-bg: #14532d;
    --bad: #fb7185;
    --bad-bg: #5b1a2a;
    --warn: #fbbf24;
    --warn-bg: #5c3a0c;
    --paper-line: #25284d;
    --shadow: 0 6px 18px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--brand); }
h1, h2, h3, .head { font-family: var(--head); line-height: 1.2; }
h1 { font-size: 28px; font-weight: 800; margin: 6px 0 12px; }
h2 { font-size: 21px; font-weight: 700; margin: 22px 0 8px; }

/* Thanh trên cùng */
#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
#brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font: 800 22px/1 var(--head); text-decoration: none; }
#brand::before {
  content: ""; width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--brand) url("icon.svg") center / cover;
}
#userbox { font-size: 14px; text-align: right; color: var(--muted); display: flex; align-items: center; gap: 8px; }
#userbox b { color: var(--ink); }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* Nút: nổi khối, ấn xuống thì lún */
.btn {
  display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 14px; padding: 12px 18px;
  font: 700 17px/1.3 "Be Vietnam Pro", system-ui, sans-serif; cursor: pointer; text-decoration: none; text-align: center;
  background: var(--brand); color: var(--brand-ink); min-height: 50px;
  box-shadow: 0 4px 0 var(--brand-dark); transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--brand-dark); }
.btn.ghost { background: var(--card); color: var(--ink); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn.small { padding: 6px 12px; min-height: 38px; font-size: 14px; box-shadow: 0 3px 0 var(--brand-dark); }
.btn.ghost.small { box-shadow: 0 3px 0 var(--line); }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.btn:disabled { opacity: .45; cursor: default; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 0; }
input, select {
  font: inherit; padding: 13px 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--brand); }
label { display: block; margin: 12px 0 6px; font-weight: 600; }

/* Trang đăng nhập: nền giấy kẻ ô như vở */
.paper {
  margin: -16px -16px 0; padding: 20px 16px 24px; min-height: calc(100vh - 56px);
  background:
    linear-gradient(90deg, transparent 38px, #f3a5b4 38px, #f3a5b4 40px, transparent 40px),
    repeating-linear-gradient(var(--bg) 0 31px, var(--paper-line) 31px 32px);
}
.paper > * { max-width: 520px; margin-left: auto; margin-right: auto; }
.hero { font: 800 40px/1.1 var(--head); margin: 18px 0 6px; padding-left: 36px; }
.hero + p { padding-left: 36px; margin-top: 0; }

.list-btn {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); border-radius: 16px;
  padding: 12px 14px; margin: 10px 0; font: inherit; font-weight: 600; text-align: left; cursor: pointer;
  text-decoration: none; box-shadow: 0 3px 0 var(--line);
}
.list-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }

/* Ô biểu tượng môn học */
.ico {
  flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  background: var(--sc, var(--brand)); color: #fff;
}
.ico svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.lg { width: 52px; height: 52px; border-radius: 16px; }
.subjects { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.subjects .list-btn { margin: 0; flex-direction: column; align-items: flex-start; padding: 14px; }
.subjects .list-btn b { font: 700 18px/1.2 var(--head); }

.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 300px; margin: 16px auto; }
.pinpad button {
  font: 700 26px/1 var(--head); padding: 16px 0; border-radius: 18px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); box-shadow: 0 4px 0 var(--line); cursor: pointer;
}
.pinpad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.pinpad button[data-k="Xoá"] { font-size: 18px; }
.pindots { display: flex; justify-content: center; gap: 16px; margin: 14px 0; }
.pindots span { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--brand); }
.pindots span.on { background: var(--brand); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font: 800 28px/1.1 var(--head); color: var(--brand); }
.stat:nth-child(2) b { color: var(--c2); }
.stat:nth-child(3) b { color: var(--c3); }
.exam { display: flex; gap: 12px; align-items: center; }
.exam .days { font: 800 30px/1 var(--head); color: var(--sc, var(--brand)); }
.bar { height: 10px; background: var(--brand-soft); border-radius: 5px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--sc, var(--ok)); border-radius: 5px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--brand-soft); color: var(--ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.lesson-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* Màn chơi: ẩn thanh trên, như tiethocvui.vn/play */
body.playing #topbar { display: none; }
.hud { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.hud .pill { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; text-decoration: none; }
.progress { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; font-size: 15px; }
.progress b { white-space: nowrap; }
.progress .bar { flex: 1; margin: 0; }
.progress .bar > i { background: var(--brand); transition: width .3s; }
.clock { position: relative; width: 48px; height: 48px; flex: none; }
.clock svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.clock circle { fill: var(--card); stroke: var(--brand-soft); stroke-width: 4; }
.clock .arc { fill: none; stroke: #0ea5e9; stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear; }
.clock span { position: absolute; inset: 0; display: grid; place-items: center; font: 800 17px/1 var(--head); }
.clock.low .arc { stroke: var(--bad); }
.clock.low span { color: var(--bad); }
.q-card { background: var(--card); border-radius: var(--radius); padding: 18px 16px; margin: 6px 0 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.q-text { font: 700 21px/1.4 var(--head); margin: 0; overflow-x: auto; text-align: center; }
.q-text.long { font: 600 18px/1.5 "Be Vietnam Pro", system-ui, sans-serif; text-align: left; }
.q-fig { text-align: center; margin: 4px 0 10px; }
.q-fig svg { max-width: 100%; height: auto; color: var(--ink); }

/* Đáp án 4 màu */
.choices { display: grid; grid-template-columns: 1fr; gap: 10px; }
.choices.grid2 { grid-template-columns: 1fr 1fr; }
.choice {
  position: relative; display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  color: #fff; border: 0; border-radius: 16px; padding: 12px 14px; font: 600 17px/1.35 "Be Vietnam Pro", system-ui, sans-serif;
  cursor: pointer; min-height: 58px; background: var(--cc); box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
  transition: opacity .2s, transform .08s;
}
.choice:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .18); }
.choice.c0 { --cc: var(--c0); } .choice.c1 { --cc: var(--c1); } .choice.c2 { --cc: var(--c2); } .choice.c3 { --cc: var(--c3); }
.choice .lbl {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .28); font-weight: 800; font-size: 15px;
}
.choice .katex { color: #fff; }
.choice:disabled { cursor: default; }
.choices.done .choice { opacity: .35; }
.choices.done .choice.correct, .choices.done .choice.wrong { opacity: 1; }
.choice.correct { outline: 4px solid var(--ok); outline-offset: 2px; }
.choice.wrong { outline: 4px solid var(--bad); outline-offset: 2px; }
.choice .mark { margin-left: auto; flex: none; width: 28px; height: 28px; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.choice .mark svg { width: 18px; height: 18px; fill: none; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.choice.correct .mark svg { stroke: var(--ok); }
.choice.wrong .mark svg { stroke: var(--bad); }

/* Đúng / Sai */
.tf-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px; margin: 10px 0; background: var(--card); }
.tf-row .grow { overflow-x: auto; }
.tf-row > b { color: var(--brand); }
.tf-row button {
  min-width: 58px; min-height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  font: 700 15px/1 "Be Vietnam Pro", system-ui, sans-serif; cursor: pointer;
}
.tf-row button.yes { color: var(--c2); }
.tf-row button.no { color: var(--c0); }
.tf-row button.yes.sel { background: var(--c2); border-color: var(--c2); color: #fff; }
.tf-row button.no.sel { background: var(--c0); border-color: var(--c0); color: #fff; }
.tf-row.correct { border-color: var(--ok); background: var(--ok-bg); }
.tf-row.wrong { border-color: var(--bad); background: var(--bad-bg); }

/* Khung nhận xét màu đặc, nút Câu tiếp trắng ở trong */
.feedback { border-radius: 18px; padding: 16px; margin: 16px 0 6px; color: #fff; text-align: center; box-shadow: 0 5px 0 rgba(0, 0, 0, .15); }
.feedback > b { font: 800 24px/1.2 var(--head); display: block; margin-bottom: 6px; }
.feedback.ok { background: #1f9d55; }
.feedback.bad { background: #e5484d; }
.feedback .katex { color: #fff; }
.feedback .source { color: rgba(255, 255, 255, .85); }
.feedback .btn.next { background: #fff; color: #1e2140; box-shadow: 0 4px 0 rgba(0, 0, 0, .2); margin-top: 12px; min-width: 160px; }
.source { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* Thẻ ôn lý thuyết */
.flash { position: relative; min-height: 260px; display: flex; flex-direction: column; justify-content: center; cursor: pointer; padding: 26px 18px 18px; }
.flash::before { content: ""; position: absolute; top: -10px; left: 50%; width: 80px; height: 20px; margin-left: -40px; background: var(--tape); border-radius: 4px; transform: rotate(-2deg); }
.flash ul { margin: 8px 0; padding-left: 22px; }
.flash li { margin: 4px 0; }
.flash .q-text { text-align: center; }

.result-big { font: 800 56px/1 var(--head); color: var(--brand); text-align: center; margin: 10px 0; }

.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pop { animation: pop .3s; }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; max-width: 90vw; font-weight: 600;
}
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; width: 100vw; height: 100vh; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
tr.me td { font-weight: 700; color: var(--brand); }
.rank { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft); font-weight: 800; font-size: 13px; }
tr:nth-child(2) .rank { background: #ffd466; color: #5c4400; }
tr:nth-child(3) .rank { background: #d9dde8; color: #3a4152; }
tr:nth-child(4) .rank { background: #f3c19a; color: #5a2e0c; }
.scroll-x { overflow-x: auto; }
.tf-row .badge.ans { flex-basis: 100%; text-align: right; background: var(--card); color: var(--ink); border: 1px solid var(--line); }

/* Trang chủ: ô môn học có số ngày còn lại */
.subjects .tile { gap: 6px; }
.subjects .tile .days { font: 800 26px/1 var(--head); color: var(--sc, var(--brand)); }
.subjects .tile .bar { margin-top: 4px; }
.subjects .tile .bar > i { background: var(--sc, var(--brand)); }
/* Trang môn: hai cách ôn */
.card.mode { border-top: 5px solid var(--sc, var(--brand)); }
.card.mode h2 { margin-top: 0; }
.note { background: var(--warn-bg); color: var(--ink); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.grp h3 { margin: 14px 0 0; font-family: inherit; font-weight: 600; }
.grp:first-child h3 { margin-top: 0; }
#brand { white-space: nowrap; }
#userbox { min-width: 0; }
#userbox > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Kiểm tra thử */
.exam-item { border-top: 1px solid var(--line); padding: 10px 0; }
.exam-item:first-of-type { border-top: 0; }
.exam-head { position: sticky; top: 0; z-index: 6; display: flex; gap: 8px; align-items: center; justify-content: space-between;
  background: var(--bg); padding: 8px 0; margin: -16px 0 8px; border-bottom: 1px solid var(--line); }
.clock-txt { font: 800 18px/1 var(--head); }
.clock-txt.low { background: var(--bad); color: #fff; border-color: var(--bad); }
.qb .exam-de { margin: 8px 0; font-weight: 600; overflow-x: auto; }
.passage { white-space: normal; line-height: 1.6; }
.opts { display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: var(--card); color: var(--ink);
  border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; font: inherit; cursor: pointer; }
.opt .lbl { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); font-weight: 800; }
.opt.sel { border-color: var(--brand); background: var(--brand-soft); }
.opt.sel .lbl { background: var(--brand); color: #fff; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrongpick { border-color: var(--bad); background: var(--bad-bg); }
.rubric { background: var(--brand-soft); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.rubric ul { margin: 6px 0 0; padding-left: 20px; }

/* Sửa theo báo cáo dùng thử */
.tf-row .grow { min-width: 0; flex: 1 1 140px; }
.nw { white-space: nowrap; }
.err { background: var(--bad-bg); color: var(--ink); border: 2px solid var(--bad); border-radius: 12px; padding: 10px 12px; margin: 12px 0 0; }
.btn.off { opacity: .55; pointer-events: none; box-shadow: none; }
.hud .pill, .exam-head .pill { min-height: 40px; display: inline-flex; align-items: center; }
main > p > a[href^="#"]:only-child { display: inline-block; padding: 10px 4px; }
.lesson-actions .btn.small { min-height: 44px; }
textarea { font: inherit; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); color: var(--ink); width: 100%; }
details.card summary { cursor: pointer; }
.rv { border-top: 1px solid var(--line); padding: 10px 0; }
.ok-text { color: var(--ok); font-weight: 700; margin-top: 4px; }
.scroll-x table { min-width: 520px; }  /* bảng rộng thì cuộn ngang trong thẻ, chữ không bị bóp */
.scroll-x th { white-space: nowrap; }
@media (prefers-color-scheme: dark) {
  .subjects .tile .days, .exam .days { color: color-mix(in srgb, var(--sc, var(--brand)) 60%, #ffffff); }
}
