:root {
  --bg: #f6f3e7;
  --surface: #fffdf7;
  --surface-2: #faf8ef;
  --line: #e7e2cf;
  --ink: #2c3624;
  --ink-2: #4d5643;
  --muted: #858a77;
  --matcha: #6f8f4e;
  --matcha-deep: #4f6c36;
  --matcha-soft: #e3ebd2;
  --matcha-tint: #f0f4e5;
  --amber: #b07e27;
  --amber-soft: #f7ecd3;
  --red: #bd5a43;
  --red-soft: #f7e2da;
  --blue: #5a7d8c;
  --blue-soft: #e1ecef;
  --shadow: 0 1px 2px rgba(60, 70, 40, .05), 0 6px 22px rgba(60, 70, 40, .06);
  --shadow-lg: 0 18px 50px rgba(50, 60, 30, .18);
  --r: 18px;
  --r-sm: 11px;
  --ease: cubic-bezier(.22, .8, .3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
a { color: var(--matcha-deep); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 14px; }
.stack-sm { display: grid; gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Hiệu ứng ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.page { animation: fadeUp .45s var(--ease) both; }
.stagger > * { animation: fadeUp .5s var(--ease) both; }
.stagger > *:nth-child(2) { animation-delay: .05s; }
.stagger > *:nth-child(3) { animation-delay: .1s; }
.stagger > *:nth-child(4) { animation-delay: .15s; }
.stagger > *:nth-child(5) { animation-delay: .2s; }
.stagger > *:nth-child(n+6) { animation-delay: .25s; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ── Thanh trên ── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(246, 243, 231, .82);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .25s, box-shadow .25s;
}
.topbar.scrolled { border-color: var(--line); box-shadow: 0 4px 18px rgba(60, 70, 40, .05); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); font-size: 1.02rem; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 10px; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.nav a.navlink {
  padding: 8px 13px; border-radius: 999px; color: var(--ink-2); font-weight: 500; font-size: .92rem; white-space: nowrap;
  transition: background .2s, color .2s;
}
.nav a.navlink:hover { background: var(--matcha-tint); }
.nav a.navlink.on { background: var(--matcha-soft); color: var(--matcha-deep); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--matcha); color: #fff; font-weight: 600; font-size: .9rem; border: 0; cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s;
}
.avatar:hover { transform: scale(1.05); box-shadow: 0 0 0 4px var(--matcha-soft); }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 6px; animation: pop .22s var(--ease);
}
.menu-pop .who { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-pop button {
  display: flex; width: 100%; gap: 10px; align-items: center; padding: 9px 12px; border: 0; background: none;
  border-radius: 9px; cursor: pointer; text-align: left; transition: background .15s;
}
.menu-pop button:hover { background: var(--matcha-tint); }

.container { max-width: 1180px; margin: 0 auto; padding: 22px 20px 70px; }

/* ── Nút & ô nhập ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 17px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 550; font-size: .92rem; white-space: nowrap; color: var(--ink);
  transition: background .2s, border-color .2s, transform .15s var(--ease), box-shadow .2s, opacity .2s;
}
.btn:hover { border-color: #d6d0b8; background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.primary { background: var(--matcha); border-color: var(--matcha); color: #fff; box-shadow: 0 4px 14px rgba(111, 143, 78, .28); }
.btn.primary:hover { background: var(--matcha-deep); border-color: var(--matcha-deep); }
.btn.soft { background: var(--matcha-soft); border-color: transparent; color: var(--matcha-deep); }
.btn.soft:hover { background: #d6e2bf; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--matcha-tint); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: transparent; }
.btn.sm { padding: 6px 12px; font-size: .84rem; }
.btn.icon { padding: 8px; width: 36px; height: 36px; }
.btn.block { width: 100%; }

label.field { display: grid; gap: 6px; font-size: .86rem; font-weight: 550; color: var(--ink-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  font-size: .95rem; font-weight: 400; color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--matcha); box-shadow: 0 0 0 4px rgba(111, 143, 78, .14); }
textarea.input { resize: vertical; min-height: 80px; }
.hint { font-size: .78rem; color: var(--muted); font-weight: 400; }

/* Công tắc */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: .9rem; }
.switch input { display: none; }
.switch i {
  width: 40px; height: 23px; border-radius: 99px; background: #d9d5c3; position: relative; flex: none; transition: background .25s;
}
.switch i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18); transition: transform .25s var(--ease);
}
.switch input:checked + i { background: var(--matcha); }
.switch input:checked + i::after { transform: translateX(17px); }

/* Chọn chế độ truy cập */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg label {
  border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; background: #fff;
  display: grid; gap: 3px; transition: border-color .2s, background .2s;
}
.seg label b { font-size: .92rem; }
.seg label span { font-size: .76rem; color: var(--muted); font-weight: 400; }
.seg input { display: none; }
.seg label:has(input:checked) { border-color: var(--matcha); background: var(--matcha-tint); }

/* ── Thẻ ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 22px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 99px;
  font-size: .73rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap;
}
.badge.public { background: var(--matcha-soft); color: var(--matcha-deep); border-color: transparent; }
.badge.password { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.badge.members { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.badge.off { background: #eceae2; color: var(--muted); border-color: transparent; }

/* ── Trang chủ ── */
.hero {
  position: relative; overflow: hidden; border-radius: 26px; padding: 38px 34px;
  background: radial-gradient(120% 140% at 100% 0%, #dfe9c9 0%, transparent 55%), linear-gradient(135deg, #f0f4e5, #fbf8ec);
  border: 1px solid var(--line); margin-bottom: 28px;
}
.hero::after {
  content: '🍃'; position: absolute; right: 28px; bottom: -14px; font-size: 120px; opacity: .13; transform: rotate(-18deg);
}
.hero h1 { font-size: clamp(1.45rem, 3.4vw, 2.1rem); margin-bottom: 8px; }
.hero p { margin: 0; color: var(--ink-2); max-width: 640px; }
.hero .hello { color: var(--matcha-deep); font-weight: 600; font-size: .9rem; margin-bottom: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.course {
  display: flex; flex-direction: column; gap: 12px; padding: 22px; color: var(--ink); cursor: pointer;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease), border-color .3s;
}
.course:hover { transform: translateY(-4px); box-shadow: 0 16px 36px rgba(60, 70, 40, .12); border-color: #d8e2c3; }
.course .ic {
  width: 52px; height: 52px; border-radius: 15px; background: var(--matcha-tint); display: grid; place-items: center; font-size: 27px;
}
.course h3 { font-size: 1.08rem; }
.course p { margin: 0; color: var(--muted); font-size: .9rem; flex: 1; }
.bar { height: 7px; border-radius: 99px; background: #ebe7d6; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #8aab65, var(--matcha)); border-radius: 99px; transition: width .7s var(--ease); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 46px; margin-bottom: 10px; }

/* ── Trang bài học ── */
.crumbs { display: flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--muted); margin-bottom: 16px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); transition: color .2s; }
.crumbs a:hover { color: var(--matcha-deep); }
.learn { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
.steps { position: sticky; top: 76px; padding: 16px; max-height: calc(100vh - 96px); overflow: auto; }
.steps-head { padding: 4px 6px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.steps-head h2 { font-size: 1.02rem; display: flex; gap: 8px; align-items: center; }
.step {
  display: flex; gap: 11px; align-items: flex-start; padding: 10px; border-radius: 12px; cursor: pointer;
  color: var(--ink-2); font-size: .9rem; transition: background .2s, color .2s; border: 0; background: none; width: 100%; text-align: left;
}
.step:hover { background: var(--matcha-tint); }
.step.on { background: var(--matcha-soft); color: var(--ink); font-weight: 600; }
.step .dot {
  width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid #cfd6bf; flex: none; display: grid; place-items: center;
  font-size: .72rem; font-weight: 600; color: var(--muted); background: #fff; transition: all .3s var(--ease);
}
.step.done .dot { background: var(--matcha); border-color: var(--matcha); color: #fff; }
.step.on .dot { border-color: var(--matcha); color: var(--matcha-deep); }
.step.done.on .dot { color: #fff; }
.step .t { padding-top: 2px; }

.lesson { padding: 34px 40px; min-height: 60vh; }
.lesson-head { margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.lesson-head h1 { font-size: clamp(1.3rem, 3vw, 1.75rem); }
.lesson-foot { margin-top: 36px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fade-swap { animation: fadeUp .4s var(--ease) both; }
.mobile-steps { display: none; }

/* Nội dung bài */
.prose { font-size: 1rem; line-height: 1.75; color: var(--ink); overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose h2 { font-size: 1.3rem; margin: 1.6em 0 .5em; }
.prose h3 { font-size: 1.1rem; margin: 1.5em 0 .45em; color: var(--matcha-deep); }
.prose h4 { font-size: 1rem; margin: 1.2em 0 .4em; }
.prose p { margin: .7em 0; }
.prose ul, .prose ol { padding-left: 1.4em; margin: .6em 0; }
.prose li { margin: .3em 0; }
.prose li::marker { color: var(--matcha); font-weight: 600; }
.prose img { border-radius: 14px; margin: 14px 0; border: 1px solid var(--line); height: auto; }
.prose blockquote { margin: 1em 0; padding: 10px 18px; border-left: 4px solid var(--matcha); background: var(--matcha-tint); border-radius: 0 12px 12px 0; color: var(--ink-2); }
.prose hr { border: 0; border-top: 1px dashed var(--line); margin: 1.8em 0; }
.prose table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: .92rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 8px 12px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose mark { background: #f3e6a8; padding: 0 3px; border-radius: 3px; }
.prose a { text-decoration: underline; text-underline-offset: 3px; }
.prose iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 14px; margin: 14px 0; background: #000; }
.prose .callout { padding: 12px 18px; border-radius: 14px; margin: 1em 0; border: 1px solid transparent; }
.prose .callout > :first-child { margin-top: 0; }
.prose .callout > :last-child { margin-bottom: 0; }
.prose .callout.tip { background: var(--matcha-tint); border-color: var(--matcha-soft); }
.prose .callout.warn { background: var(--amber-soft); border-color: #efdcb0; }
.prose .callout.note { background: var(--blue-soft); border-color: #cfdfe4; }

/* ── Khoá / đăng nhập ── */
.center-card { max-width: 420px; margin: 7vh auto 0; padding: 34px 30px; text-align: center; }
.center-card .lock { font-size: 44px; margin-bottom: 8px; }
.center-card h1 { font-size: 1.35rem; margin-bottom: 6px; }
.center-card form { text-align: left; margin-top: 22px; }

/* ── Quản trị ── */
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; padding: 4px; background: #ece8d8; border-radius: 999px; width: fit-content; max-width: 100%; overflow-x: auto; margin-bottom: 20px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 8px 16px; border-radius: 99px; color: var(--ink-2); font-weight: 550; font-size: .9rem; white-space: nowrap; transition: background .25s, color .25s, box-shadow .25s; }
.tabs a.on { background: var(--surface); color: var(--matcha-deep); box-shadow: 0 2px 8px rgba(60, 70, 40, .1); }

.list { display: grid; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 15px; transition: box-shadow .25s, border-color .25s, transform .25s var(--ease), opacity .2s;
}
.item:hover { box-shadow: var(--shadow); border-color: #ddd7c0; }
.item .ic { width: 42px; height: 42px; border-radius: 12px; background: var(--matcha-tint); display: grid; place-items: center; font-size: 22px; flex: none; }
.item.dim { opacity: .62; }
.item.dragging { opacity: .4; }
.item.over { border-color: var(--matcha); box-shadow: 0 0 0 3px var(--matcha-soft); }
.grip { cursor: grab; color: #b8b39f; padding: 4px; user-select: none; font-size: 18px; line-height: 1; }
.item.clickable { cursor: pointer; }

.editor-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.editor-side { display: grid; gap: 16px; position: sticky; top: 76px; }
.lesson-list .item { padding: 10px 12px; gap: 10px; cursor: pointer; }
.lesson-list .item.on { border-color: var(--matcha); background: var(--matcha-tint); }
.lesson-list .num { width: 24px; height: 24px; border-radius: 50%; background: var(--matcha-soft); color: var(--matcha-deep); font-size: .74rem; font-weight: 700; display: grid; place-items: center; flex: none; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 3px; padding: 8px; border: 1px solid var(--line); border-bottom: 0;
  border-radius: 14px 14px 0 0; background: var(--surface-2); position: sticky; top: 64px; z-index: 5;
}
.toolbar button {
  min-width: 34px; height: 34px; padding: 0 9px; border: 0; background: none; border-radius: 8px; cursor: pointer;
  font-size: .86rem; color: var(--ink-2); transition: background .15s;
}
.toolbar button:hover { background: var(--matcha-soft); }
.toolbar .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.rich {
  min-height: 420px; padding: 22px 24px; border: 1px solid var(--line); border-radius: 0 0 14px 14px; background: #fff; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.rich:focus { border-color: var(--matcha); box-shadow: 0 0 0 4px rgba(111, 143, 78, .1); }
.rich.dropping { border-color: var(--matcha); background: var(--matcha-tint); }

.users-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.users-table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 0 14px 10px; }
.users-table td { padding: 13px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
.users-table tr { transition: background .2s; }
.users-table tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.prog-cell { min-width: 140px; }
.prog-cell .bar { margin-top: 5px; }

.pw-box { font-family: ui-monospace, Consolas, monospace; font-size: 1.4rem; letter-spacing: .12em; background: var(--matcha-tint); border-radius: 14px; padding: 14px; text-align: center; color: var(--matcha-deep); font-weight: 700; }

/* ── Modal & thông báo ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(40, 46, 30, .35); z-index: 60; display: grid; place-items: center; padding: 18px;
  animation: fadeIn .2s ease; backdrop-filter: blur(3px);
}
.modal { width: min(480px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 22px; padding: 26px; box-shadow: var(--shadow-lg); animation: pop .3s var(--ease); }
.modal h2 { font-size: 1.15rem; margin-bottom: 16px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-back.closing { animation: fadeIn .18s ease reverse forwards; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 99px; font-size: .9rem; box-shadow: var(--shadow-lg);
  animation: pop .3s var(--ease); transition: opacity .3s, transform .3s;
}
.toast.err { background: var(--red); }
.toast.out { opacity: 0; transform: translateY(8px); }

.spinner { width: 28px; height: 28px; border: 3px solid var(--matcha-soft); border-top-color: var(--matcha); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 900px) {
  .learn { grid-template-columns: 1fr; }
  .steps { display: none; }
  .mobile-steps { display: block; margin-bottom: 14px; }
  .mobile-steps summary {
    list-style: none; cursor: pointer; padding: 13px 16px; display: flex; align-items: center; gap: 10px; font-weight: 600;
  }
  .mobile-steps summary::-webkit-details-marker { display: none; }
  .mobile-steps summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .25s var(--ease); }
  .mobile-steps[open] summary::after { transform: rotate(180deg); }
  .mobile-steps .list-in { padding: 0 8px 8px; animation: fadeUp .3s var(--ease); }
  .lesson { padding: 22px 18px; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .toolbar { top: 58px; }
}
@media (max-width: 600px) {
  .topbar-in { padding: 10px 14px; }
  .container { padding: 16px 14px 60px; }
  .hero { padding: 26px 20px; border-radius: 20px; }
  .nav a.navlink.hide-sm { display: none; }
  .seg { grid-template-columns: 1fr; }
  .pad { padding: 18px; }
  .rich { padding: 16px; }
  .lesson-foot .btn { flex: 1; }
  .users-table .hide-sm { display: none; }
}
.pw-cell { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--matcha-deep); letter-spacing: .06em; display: inline-block; min-width: 86px; }

/* Cột grid không bị chữ dài (nowrap/ellipsis) đẩy rộng ra */
.learn > *, .editor-layout > * { min-width: 0; }
.editor-side, .list { grid-template-columns: minmax(0, 1fr); }
