:root {
  --pri: #2563eb;
  --pri-d: #1e3a8a;
  --pri-l: #eff6ff;
  --acc: #7c3aed;
  --green: #10b981;
  --green-d: #047857;
  --amber: #f59e0b;
  --red: #ef4444;
  --red-d: #b91c1c;
  --bg: #f4f7ff;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --line: #e2e8f0;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(15, 23, 42, .07);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
  --tb: 62px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% -10%, #dbeafe 0%, transparent 60%),
    radial-gradient(800px 420px at 100% 0%, #ede9fe 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 4px 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.topbar-in {
  max-width: 1180px; margin: 0 auto; height: var(--tb);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; flex: 1 1 auto; }
.brand-ico {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; overflow: hidden; flex: none;
  background: linear-gradient(135deg, var(--pri), var(--acc)); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .28);
}
.brand-ico img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-txt b { font-size: 18.5px; font-weight: 800; color: var(--pri-d); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-txt small { font-size: 11.5px; color: var(--ink-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-acts { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---------- Layout & Buttons ---------- */
.container {
  max-width: 1180px; margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(36px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 700; font-size: 14.5px;
  transition: transform .12s, filter .12s; white-space: nowrap;
}
@media (hover: hover) {
  .btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-pri { background: linear-gradient(135deg, var(--pri), #1d4ed8); color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .26); }
.btn-acc { background: linear-gradient(135deg, var(--acc), #5b21b6); color: #fff; }
.btn-green { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.btn-amber { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.btn-red { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-lg { padding: 13px 24px; font-size: 16px; border-radius: 14px; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid rgba(226, 232, 240, .85); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--pri-l); color: var(--pri-d); }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-red { background: #fee2e2; color: #991b1b; }
.muted { color: var(--ink-2); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }

/* ---------- Student Entry Hero ---------- */
.entry-wrap { max-width: 560px; margin: 24px auto; }
.entry-hero {
  background: linear-gradient(135deg, var(--pri-d) 0%, var(--pri) 58%, var(--acc) 100%);
  color: #fff; border-radius: 26px; padding: 32px 24px; text-align: center;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .18);
}
.stu-banner {
  background: linear-gradient(135deg, var(--pri-d), var(--pri)); color: #fff;
  border-radius: 22px; padding: 20px 22px; margin-bottom: 18px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px;
}
.lic-banner {
  background: #fef2f2; border: 1.5px solid #fca5a5; color: #991b1b;
  border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; font-weight: 700; font-size: 14px; text-align: center;
}
.lic-banner.warn { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 12px; }
.theme-opt {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 12px; text-align: left;
  display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 13px;
}
.theme-opt.on { border-color: var(--pri); background: var(--pri-l); }
.theme-dots { display: flex; gap: 5px; }
.theme-dots i { width: 20px; height: 20px; border-radius: 50%; display: block; border: 1px solid rgba(0, 0, 0, .12); }
.key-code { font: 800 15px ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; color: var(--pri-d); background: var(--pri-l); padding: 4px 10px; border-radius: 8px; }
.site-foot { text-align: center; font-size: 12.5px; color: var(--ink-2); margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); }
.entry-hero .ico { font-size: 56px; margin-bottom: 8px; }
.entry-hero h1 { margin: 0 0 8px; font-size: clamp(22px, 4.5vw, 30px); font-weight: 800; }
.entry-hero p { margin: 0 0 22px; opacity: .92; font-size: 14.5px; line-height: 1.5; }
.code-form { display: flex; gap: 8px; max-width: 420px; margin: 0 auto; }
.code-form input {
  flex: 1; min-width: 0; border: 0; border-radius: 14px; padding: 13px 16px;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 18px;
  letter-spacing: 2px; text-transform: uppercase; text-align: center;
}
.sample-codes { margin-top: 16px; font-size: 13px; opacity: .92; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; align-items: center; }
.sample-btn { border: 1px solid rgba(255, 255, 255, .38); background: rgba(255, 255, 255, .15); color: #fff; border-radius: 999px; padding: 4px 11px; font-size: 12.5px; font-weight: 700; }
.sample-btn:hover { background: rgba(255, 255, 255, .28); }

/* ---------- Student Portal ---------- */
.stu-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat-pill { background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .24); border-radius: 14px; padding: 8px 14px; text-align: center; min-width: 90px; }
.stat-pill b { display: block; font-size: 18px; }
.stat-pill small { font-size: 11.5px; opacity: .88; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 13.5px; color: var(--ink-2); }
.chip.on { background: var(--pri); color: #fff; border-color: var(--pri); }

.quiz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 16px; }
.qcard {
  background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px;
}
.qcard h3 { margin: 0; font-size: 17px; line-height: 1.3; }
.qcard p { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; flex: 1; }

/* ---------- Practice Screen: Giao diện Trang Vở Học Sinh ---------- */
.exam-wrap { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.prog-bar { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.prog-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pri), var(--green)); transition: width .25s ease; }

.nb-topbar {
  position: sticky; top: calc(var(--tb) + 6px); z-index: 20;
  background: rgba(255, 253, 247, .96); backdrop-filter: blur(8px);
  border: 1px solid #e5dcc5; border-radius: 16px; padding: 10px 14px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .08);
  display: flex; flex-direction: column; gap: 8px;
}
.nb-topbar-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.nb-qblock {
  padding: 18px 0 20px;
  border-bottom: 1.5px dashed rgba(59, 130, 246, .26);
  scroll-margin-top: 170px;
}
.nb-qblock:last-of-type { border-bottom: 0; }
.nb-qtitle {
  margin: 0 0 12px;
  font-size: clamp(16.5px, 2.2vw, 19.5px);
  line-height: 1.6;
  font-weight: 700;
  color: #1e293b;
}
.nb-qbadge {
  display: inline-block; color: #1d4ed8; font-weight: 800; margin-right: 6px;
}
.nb-opts-2col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 9px;
}
@media (max-width: 640px) {
  .nb-opts-2col { grid-template-columns: 1fr; }
}
.nb-sheet {
  position: relative;
  background-color: #fffdf7;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 33px,
    rgba(59, 130, 246, .13) 33px,
    rgba(59, 130, 246, .13) 34px
  );
  border-radius: 18px;
  border: 1px solid #e5dcc5;
  box-shadow:
    0 2px 0 #f3ebd8,
    0 6px 0 -2px #fffdf7,
    0 7px 0 -2px #e5dcc5,
    0 14px 32px rgba(15, 23, 42, .09);
  padding: 26px 28px 28px 66px;
  overflow: hidden;
}
/* Đường lề đỏ bên trái trang vở */
.nb-sheet::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 46px;
  width: 2px;
  background: rgba(239, 68, 68, .36);
  pointer-events: none;
}
/* Lỗ gáy vở tinh tế */
.nb-sheet::after {
  content: '';
  position: absolute;
  top: 24px; bottom: 24px; left: 15px;
  width: 14px;
  background: radial-gradient(circle at 7px 7px, #e2e8f0 5px, #cbd5e1 6px, transparent 6.5px) 0 0 / 14px 48px repeat-y;
  pointer-events: none;
}

.nb-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding-bottom: 12px; margin-bottom: 14px;
  border-bottom: 1.5px dashed rgba(59, 130, 246, .28);
}
.nb-qnum {
  font-size: 13.5px; font-weight: 800; color: #1d4ed8;
  letter-spacing: .4px; display: inline-flex; align-items: center; gap: 6px;
}
.nb-nav {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
}
.nb-dot {
  width: 32px; height: 32px; border-radius: 999px;
  border: 1.5px solid #cbd5e1; background: rgba(255, 255, 255, .92);
  font-size: 13px; font-weight: 700; color: var(--ink-2);
  display: grid; place-items: center; transition: all .15s;
}
.nb-dot:hover { border-color: var(--pri); color: var(--pri); }
.nb-dot.done { background: #dbeafe; border-color: #3b82f6; color: #1e40af; }
.nb-dot.cur { background: var(--pri); border-color: var(--pri); color: #fff; box-shadow: 0 3px 10px rgba(37, 99, 235, .3); transform: scale(1.06); }

.nb-question {
  margin: 0 0 18px;
  font-size: clamp(18px, 2.5vw, 22px);
  line-height: 1.6;
  font-weight: 700;
  color: #1e293b;
}
.q-img { display: block; max-width: 100%; max-height: 280px; margin: 12px auto 16px; border-radius: 12px; border: 1px solid #e5dcc5; box-shadow: var(--shadow-sm); object-fit: contain; background: #fff; }
.q-ed-img { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.q-ed-img img { max-height: 96px; max-width: 180px; border-radius: 10px; border: 1px solid var(--line); object-fit: contain; background: #fff; }
.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.astat { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px; text-align: center; box-shadow: var(--shadow-sm); }
.astat b { display: block; font-size: 24px; color: var(--pri-d); }
.astat small { color: var(--ink-2); font-size: 12.5px; font-weight: 600; }

.nb-opts { display: flex; flex-direction: column; gap: 10px; }
.nb-opt {
  width: 100%;
  border: 1.5px solid #d6deea;
  background: rgba(255, 255, 255, .86);
  border-radius: 14px;
  padding: 13px 16px;
  display: flex; align-items: center; gap: 14px;
  text-align: left;
  font-size: 16px; font-weight: 600; color: #1e293b;
  transition: border-color .15s, background .15s, transform .12s, box-shadow .15s;
}
@media (hover: hover) {
  .nb-opt:hover {
    border-color: var(--pri);
    background: #f0f6ff;
    transform: translateX(3px);
  }
}
.nb-opt .otxt, .nb-qtitle { overflow-wrap: anywhere; }
.nb-opt .okey {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid #94a3b8;
  background: #fff; color: #334155;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14.5px; flex: none;
  transition: all .15s;
}
.nb-opt .otxt { flex: 1; line-height: 1.45; }
.nb-opt .ochk { font-size: 16px; font-weight: 800; color: var(--pri); opacity: 0; transition: opacity .15s; }
.nb-opt.picked {
  border-color: #1d4ed8;
  background: rgba(37, 99, 235, .1);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .16);
}
.nb-opt.picked .okey {
  background: #1d4ed8; border-color: #1d4ed8; color: #fff;
  box-shadow: 0 2px 8px rgba(29, 78, 216, .35);
}
.nb-opt.picked .ochk { opacity: 1; }

.nb-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 22px; padding-top: 14px;
  border-top: 1.5px dashed rgba(59, 130, 246, .25);
}
.nb-stamp {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  border: 3px solid #dc2626; color: #dc2626; border-radius: 16px;
  padding: 8px 22px; transform: rotate(-3deg);
  background: rgba(254, 242, 242, .85); margin: 8px 0 12px;
}
.nb-stamp b { font-size: 30px; line-height: 1.1; }
.nb-stamp small { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; }
.nb-rev-item {
  padding: 14px 0;
  border-bottom: 1px dashed rgba(59, 130, 246, .26);
}
.nb-rev-item:last-child { border-bottom: 0; }
.explain-box { background: #fefce8; border: 1.5px solid #fde047; color: #713f12; border-radius: 12px; padding: 10px 14px; font-size: 14px; line-height: 1.5; }
.explain-box.bad { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }

/* ---------- Teacher Dashboard ---------- */
.t-tabs {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px;
  scrollbar-width: none;
}
.t-tabs::-webkit-scrollbar { display: none; }
.t-tab {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 14px;
  padding: 10px 16px; font-weight: 700; font-size: 14px; color: var(--ink-2);
}
.t-tab.on { background: var(--pri); color: #fff; border-color: var(--pri); box-shadow: 0 4px 12px rgba(37, 99, 235, .25); }

.stu-list { display: flex; flex-direction: column; gap: 12px; }
.stu-card {
  background: #fff; border-radius: 16px; padding: 16px; border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
}
.stu-main { display: flex; align-items: center; gap: 12px; min-width: 220px; flex: 1; }
.stu-av { width: 46px; height: 46px; border-radius: 50%; background: var(--pri-l); display: grid; place-items: center; font-size: 24px; flex: none; }
.stu-info { min-width: 0; }
.stu-info b { font-size: 16px; }
.stu-info .sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.stu-prog { min-width: 170px; flex: 0 1 220px; }
.stu-prog-txt { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; margin-bottom: 4px; }

/* Checklist gán bộ đề cho từng học sinh */
.check-list { display: flex; flex-direction: column; gap: 8px; max-height: 56vh; overflow-y: auto; margin: 10px 0 14px; padding-right: 2px; }
.check-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; cursor: pointer; transition: border-color .15s, background .15s;
}
.check-item.on { border-color: var(--pri); background: var(--pri-l); }
.check-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--pri); flex: none; cursor: pointer; }
.check-item .ci-body { flex: 1; min-width: 0; }
.check-item .ci-body b { display: block; font-size: 14.5px; }
.check-item .ci-body small { color: var(--ink-2); font-size: 12px; }

/* Progress table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ptable { width: 100%; border-collapse: collapse; min-width: 620px; font-size: 14px; }
.ptable th, .ptable td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.ptable th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); background: #f8fafc; }

/* Forms & Quiz Editor */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 13.5px; margin-bottom: 10px; }
.field input, .field select, .field textarea {
  border: 1px solid #cbd5e1; border-radius: 12px; padding: 10px 12px; background: #fff; font-size: 15px; font-weight: 500;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--pri); border-color: var(--pri); }
.q-editor { background: #f8fafc; border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.q-editor-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.opt-in-row { display: flex; align-items: center; gap: 6px; }
.opt-in-row input[type="radio"] { width: 20px; height: 20px; accent-color: var(--green); flex: none; }
.opt-in-row input[type="text"] { flex: 1; min-width: 0; }
.av-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.av-pick button { border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 20px; aspect-ratio: 1; }
.av-pick button.on { border-color: var(--pri); background: var(--pri-l); box-shadow: 0 0 0 2px var(--pri); }

.subj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.subj-card { background: #fff; border-radius: 16px; padding: 14px 16px; border: 1px solid var(--line); border-left: 6px solid var(--sc, var(--pri)); display: flex; align-items: center; justify-content: space-between; gap: 10px; box-shadow: var(--shadow-sm); }

/* ---------- Modal & Toast ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(15, 23, 42, .52); backdrop-filter: blur(4px);
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.modal-card {
  width: min(540px, 100%); max-height: calc(100dvh - 24px); overflow: auto;
  background: #fff; border-radius: 22px; padding: 22px; box-shadow: 0 20px 50px rgba(15, 23, 42, .28);
}
.modal-card.wide { width: min(680px, 100%); }
.modal-card h3 { margin: 0 0 12px; font-size: 20px; color: var(--pri-d); }
#toasts { position: fixed; z-index: 70; left: 50%; top: calc(var(--tb) + 12px + env(safe-area-inset-top)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 400px); pointer-events: none; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 14px; font-weight: 700; font-size: 14px; text-align: center; box-shadow: var(--shadow); }
.toast.ok { background: var(--green-d); }
.toast.err { background: var(--red-d); }

/* ---------- Layout Picker & 4 Customizable School Layouts ---------- */
.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-bottom: 14px; }
.layout-opt {
  border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 12px; text-align: left;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, background .15s;
}
.layout-opt.on { border-color: var(--pri); background: var(--pri-l); }
.layout-opt b { font-size: 13.5px; color: var(--ink); }
.layout-opt small { font-size: 12px; color: var(--ink-2); line-height: 1.35; font-weight: 500; }
.lay-thumb {
  height: 46px; border-radius: 8px; background: #f1f5f9; border: 1px solid #cbd5e1;
  padding: 5px; display: flex; gap: 4px; overflow: hidden;
}
.lay-thumb i { display: block; border-radius: 4px; background: var(--pri); opacity: .75; }
.lay-thumb.t-classic { flex-direction: column; align-items: center; justify-content: center; }
.lay-thumb.t-classic i { width: 52%; height: 22px; }
.lay-thumb.t-split i:first-child { flex: 1; background: var(--pri-d); }
.lay-thumb.t-split i:last-child { flex: 1; background: #fff; border: 1.5px solid var(--pri); opacity: 1; }
.lay-thumb.t-campus { flex-direction: column; padding: 0; }
.lay-thumb.t-campus i:first-child { height: 24px; border-radius: 0; background: linear-gradient(90deg, var(--pri-d), var(--acc)); }
.lay-thumb.t-campus i:last-child { height: 14px; margin: 2px 6px; background: #fff; border: 1px solid #cbd5e1; opacity: 1; }
.lay-thumb.t-kids { background: #fef9c3; border-color: #fde047; align-items: center; justify-content: space-around; }
.lay-thumb.t-kids i { width: 28%; height: 26px; border-radius: 12px; background: var(--acc); }

/* Layout 2: split-hero */
.entry-split {
  display: grid; grid-template-columns: 1.15fr 1fr; gap: 22px; align-items: stretch;
  max-width: 980px; margin: 18px auto;
}
.entry-split-brand {
  background: linear-gradient(135deg, var(--pri-d), var(--pri));
  color: #fff; border-radius: 26px; padding: 32px 28px;
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.entry-split-brand.has-bg { background-size: cover; background-position: center; }
.entry-split-brand.has-bg::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(15, 23, 42, .76), rgba(30, 58, 138, .62));
}
.entry-split-brand > * { position: relative; z-index: 1; }
.entry-split-brand h1 { margin: 0; font-size: clamp(24px, 3.4vw, 34px); line-height: 1.2; }
.entry-split-brand p { margin: 0; opacity: .92; font-size: 15px; line-height: 1.55; }
.entry-split-form {
  background: #fff; border-radius: 26px; padding: 30px 26px; border: 1px solid var(--line);
  box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: center;
}
.entry-split-form .code-form { max-width: none; margin: 0; }
.entry-split-form .code-form input { border: 2px solid var(--line); background: #f8fafc; }
.entry-split-form .code-form input:focus { border-color: var(--pri); background: #fff; }
.entry-split-form .sample-codes { color: var(--ink-2); justify-content: flex-start; }
.entry-split-form .sample-btn { background: var(--pri-l); color: var(--pri-d); border-color: transparent; }

.stu-split { display: grid; grid-template-columns: 290px 1fr; gap: 20px; align-items: start; }
.stu-side {
  position: sticky; top: calc(var(--tb) + 16px);
  background: linear-gradient(160deg, var(--pri-d), var(--pri));
  color: #fff; border-radius: 22px; padding: 22px 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.stu-side .stu-stats { flex-direction: column; }
.stu-side .stat-pill { display: flex; align-items: center; justify-content: space-between; text-align: left; }

/* Layout 3: campus-banner */
.campus-hero {
  border-radius: 24px; overflow: hidden; margin-bottom: 20px; background: #fff;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.campus-cover {
  height: 210px; background: linear-gradient(125deg, var(--pri-d) 0%, var(--pri) 55%, var(--acc) 100%);
  background-size: cover; background-position: center; position: relative;
}
.campus-cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(15, 23, 42, .65), transparent 60%);
}
.campus-body { padding: 0 24px 26px; margin-top: -42px; position: relative; z-index: 2; }
.campus-emblem {
  width: 78px; height: 78px; border-radius: 20px; background: #fff; padding: 6px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .18); display: grid; place-items: center;
  font-size: 38px; overflow: hidden; margin-bottom: 10px;
}
.campus-emblem img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; }
body.lay-campus-banner .quiz-grid { grid-template-columns: 1fr; gap: 12px; }
body.lay-campus-banner .qcard {
  flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-left: 6px solid var(--pri);
}
body.lay-campus-banner .qcard-body { flex: 1 1 320px; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }
body.lay-campus-banner .qcard-act { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 170px; }

/* Layout 4: kids-playful */
body.lay-kids-playful {
  background:
    radial-gradient(circle at 18px 18px, rgba(37, 99, 235, .09) 2.5px, transparent 0) 0 0 / 34px 34px,
    linear-gradient(180deg, #fffbeb 0%, #eff6ff 55%, #fdf2f8 100%);
}
body.lay-kids-playful .card,
body.lay-kids-playful .qcard,
body.lay-kids-playful .q-box {
  border-radius: 28px; border: 2.5px solid #e2e8f0;
  box-shadow: 0 8px 0 rgba(15, 23, 42, .08);
}
body.lay-kids-playful .entry-hero {
  border-radius: 34px; border: 4px solid rgba(255, 255, 255, .45);
  box-shadow: 0 12px 0 rgba(15, 23, 42, .15);
}
body.lay-kids-playful .stu-banner {
  border-radius: 30px; box-shadow: 0 8px 0 rgba(15, 23, 42, .12);
}
body.lay-kids-playful .btn {
  border-radius: 999px; box-shadow: 0 4px 0 rgba(15, 23, 42, .18);
}
body.lay-kids-playful .chip { border-radius: 999px; border-width: 2px; }

/* ---------- Responsive: PC · iPad (Tablet) · Mobile ---------- */

/* iPad Landscape & Small Desktop (821px – 1024px) */
@media (max-width: 1024px) {
  .container { padding: 18px max(14px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .quiz-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .stu-split { grid-template-columns: 250px 1fr; gap: 16px; }
  .entry-split { gap: 16px; }
  .nb-sheet { padding: 22px 22px 24px 56px; }
  .nb-sheet::before { left: 38px; }
  .nb-sheet::after { left: 11px; }
}

/* iPad Portrait & Large Tablets (641px – 820px) */
@media (max-width: 820px) {
  .entry-split, .stu-split { grid-template-columns: 1fr; }
  .stu-side { position: static; }
  .stu-side .stu-stats { flex-direction: row; }
  .stu-side .stat-pill { flex: 1; flex-direction: column; text-align: center; }
  .campus-cover { height: 160px; }
  .admin-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Mobile Portrait (≤ 640px) */
@media (max-width: 640px) {
  :root { --tb: 58px; }
  .hide-sm { display: none !important; }
  .top-acts { gap: 6px; max-width: 65%; }
  .top-acts .btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .container { padding: 14px max(12px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .brand-txt small { display: none; }
  .brand-txt b { font-size: 16.5px; }
  .card { padding: 14px; border-radius: 16px; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; padding: 6px 11px; }
  .chip, .t-tab { min-height: 38px; }

  /* Tránh iOS Safari tự zoom khi gõ ô nhập liệu */
  .field input, .field select, .field textarea, #tStuSearch, #licKeyIn { font-size: 16px !important; }

  .entry-wrap { margin: 10px auto; }
  .entry-hero { padding: 24px 16px; border-radius: 22px; }
  .entry-split-brand, .entry-split-form { padding: 22px 18px; border-radius: 20px; }
  .code-form { flex-direction: column; }
  .code-form input { width: 100%; }
  .code-form .btn { width: 100%; }

  .stu-banner { padding: 16px; border-radius: 18px; }
  .stu-banner > .row:last-child { width: 100%; flex-direction: column; align-items: stretch; }
  .stu-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; width: 100%; }
  .stat-pill { min-width: 0; padding: 8px 6px; }
  .stat-pill b { font-size: 16px; }
  .stat-pill small { font-size: 11px; }

  .quiz-grid, .q-editor-opts, .subj-grid { grid-template-columns: 1fr; }
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .astat { padding: 12px 8px; }
  .astat b { font-size: 20px; }
  .layout-grid, .theme-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .layout-opt { padding: 10px; }
  .layout-opt small { display: none; }

  .stu-card { flex-direction: column; align-items: stretch; padding: 14px; }
  .stu-main { min-width: 0; }
  .stu-prog { flex: auto; min-width: 0; }

  /* Trang vở tối ưu cho Mobile */
  .nb-topbar { padding: 8px 10px; border-radius: 14px; gap: 6px; }
  .nb-topbar-row b { font-size: 14px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; order: -1; flex: 1 0 100%; }
  .nb-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 2px 0; }
  .nb-nav::-webkit-scrollbar { display: none; }
  .nb-dot { flex: none; width: 34px; height: 34px; }
  .nb-qblock { scroll-margin-top: 200px; padding: 14px 0 16px; }
  .nb-sheet { padding: 16px 14px 20px 26px; border-radius: 16px; }
  .nb-sheet::before { left: 15px; }
  .nb-sheet::after { display: none; }
  .nb-opt { padding: 12px; font-size: 15px; min-height: 50px; gap: 10px; }
  .nb-opt .okey { width: 30px; height: 30px; font-size: 13.5px; }
  .nb-foot .btn { width: 100%; }

  /* Modal dạng Bottom Sheet thân thiện ngón tay cái */
  .modal { align-items: end; padding: max(10px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .modal-card { padding: 18px 16px; border-radius: 22px 22px 16px 16px; max-height: 90dvh; }
  .modal-card h3 { font-size: 18px; }

  body.lay-campus-banner .qcard-act { width: 100%; align-items: stretch; }
  .campus-cover { height: 130px; }
  .campus-body { padding: 0 16px 20px; }
}

/* Điện thoại màn nhỏ (≤ 390px: iPhone SE / Android nhỏ) */
@media (max-width: 390px) {
  :root { --tb: 54px; }
  .brand-ico { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }
  .brand-txt b { font-size: 15px; }
  .top-acts { gap: 5px; }
  .top-acts .btn-sm { padding: 6px 8px; font-size: 12px; }
  .layout-grid, .theme-grid { grid-template-columns: 1fr; }
}

/* Mobile xoay ngang (Landscape) */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --tb: 46px; }
  .nb-topbar { position: static; }
  .nb-opts-2col { grid-template-columns: 1fr 1fr; }
  .nb-opt { min-height: 44px; padding: 9px 12px; font-size: 14px; }
}
