:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2730; --muted: #667784; --line: #e2e7ec;
  --pri: #0f4c5c; --pri2: #1b7a8c; --acc: #e36414; --good: #2a9d5c; --ok: #d9a400; --weak: #d1495b;
  --radius: 14px; --shadow: 0 1px 3px rgba(16,40,60,.08), 0 4px 14px rgba(16,40,60,.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--pri2); }
h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.25rem; margin: .2rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .6rem; }
.card h3:first-child { margin-top: 0; }
main { max-width: 900px; margin: 0 auto; padding: 16px 14px calc(90px + env(safe-area-inset-bottom)); }

/* Header + nav */
.top { position: sticky; top: 0; z-index: 10; background: var(--pri); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { color: #fff; text-decoration: none; font-weight: 700; display: flex; gap: 8px; align-items: center; }
nav { display: flex; gap: 4px; }
nav a { color: #cfe3e8; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .92rem; display: flex; gap: 6px; align-items: center; }
nav a.on, nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
@media (max-width: 760px) {
  .top { justify-content: center; }
  nav { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); justify-content: space-around; padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); gap: 0; }
  nav a { flex-direction: column; gap: 0; color: var(--muted); font-size: .7rem; padding: 4px 6px; }
  nav a span { font-size: 1.25rem; }
  nav a.on, nav a:hover { background: none; color: var(--pri); font-weight: 600; }
}

/* Cards & layout */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.accent { border-left: 4px solid var(--acc); }
.center { text-align: center; }
.grid2, .grid3 { display: grid; gap: 12px; margin-bottom: 14px; }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid2 > .card, .grid3 > .card { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.muted { color: var(--muted); font-size: .92rem; }
.hello { margin-top: 0; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; font-size: .95rem; }
label { display: block; margin: 10px 0; font-size: .95rem; }
label .inp { margin-top: 4px; }

/* Buttons */
.btn { appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 44px; }
.btn:hover { border-color: var(--pri2); }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:hover { background: var(--pri2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.btn.block { width: 100%; margin-top: 10px; }
.btn.danger { color: var(--weak); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.mic { background: var(--acc); border-color: var(--acc); color: #fff; font-size: 1.05rem; padding: 14px 22px; }
.btn.mic.live { background: var(--weak); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(209,73,91,.18); } }
.icon { border: 0; background: none; font-size: 1.15rem; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.icon:hover { background: var(--bg); }
.tile { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 2px; font: inherit; color: inherit; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--pri2); }
.tile span { font-size: 1.5rem; } .tile small { color: var(--muted); }
.tile.big { padding: 18px; }

/* Progress & tags */
.pbar { height: 10px; background: #e8edf1; border-radius: 99px; overflow: hidden; flex: 1; min-width: 60px; }
.pbar i { display: block; height: 100%; background: var(--pri2); border-radius: 99px; transition: width .3s; }
.pbar.good i { background: var(--good); } .pbar.ok i { background: var(--ok); } .pbar.weak i { background: var(--weak); }
.tag { font-size: .78rem; padding: 2px 8px; border-radius: 99px; background: #eef1f4; color: var(--muted); white-space: nowrap; font-weight: 600; }
.tag.good { background: #e3f5ea; color: var(--good); } .tag.ok { background: #fdf4d8; color: #9a7500; } .tag.weak { background: #fbe5e8; color: var(--weak); }
b.good, .good { color: var(--good); } b.ok { color: #9a7500; } b.weak, small.weak { color: var(--weak); }
.big { font-size: 3rem; font-weight: 800; color: var(--pri); }
.big.good { color: var(--good); } .big.ok { color: #9a7500; } .big.weak { color: var(--weak); }
.banner { background: #fff6e8; border: 1px solid #f6d9ae; padding: 10px 12px; border-radius: 10px; margin: 10px 0; }
.banner.good { background: #e8f6ee; border-color: #bfe5cd; }
.skillrow, .tagrow { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.skillrow > span:first-child { width: 110px; } .skillrow b { width: 44px; text-align: right; }
.skillrow small { width: 140px; }
@media (max-width: 520px) { .skillrow > span:first-child { width: 96px; } .skillrow small { width: auto; flex: 1; } }
.tagrow span { flex: 1; min-width: 160px; }
.skillgrid { display: grid; gap: 6px; text-align: left; margin: 12px 0; }
.skillgrid div { display: flex; align-items: center; gap: 10px; } .skillgrid span { width: 110px; }

/* Lists */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 8px 16px; border-radius: 99px; background: #fff; text-decoration: none; color: var(--ink); font-weight: 700; border: 1px solid var(--line); }
.tabs a.on { background: var(--pri); color: #fff; border-color: var(--pri); }
.list { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.lrow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.lrow:hover { background: #f7fafb; }
.lrow.dim { opacity: .55; }
.lrow.review { background: #f2f8f9; } .lrow.final { background: #fff4ea; }
.num { width: 30px; height: 30px; border-radius: 50%; background: #e7f0f2; color: var(--pri); display: grid; place-items: center; font-weight: 700; flex: none; font-size: .9rem; }
.lt { flex: 1; display: flex; flex-direction: column; } .lt small { color: var(--muted); }
.secgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.sec { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; border: 1px solid transparent; }
.sec:hover { border-color: var(--pri2); }
.si { font-size: 1.6rem; }

/* Lesson content */
.vlist { display: grid; gap: 6px; margin: 10px 0; }
.vrow { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border-radius: 10px; background: #f7f9fa; }
.gram { background: #f4f9fa; border-radius: 10px; padding: 4px 14px; }
.gram table { border-collapse: collapse; margin: 8px 0; } .gram td, .gram th { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.exs p { margin: 6px 0; }
.passage, .model { background: #fbfaf6; border-left: 3px solid var(--ok); padding: 12px 14px; border-radius: 6px; white-space: pre-wrap; }
.model { border-left-color: var(--good); }
details { margin: 8px 0; } summary { cursor: pointer; color: var(--pri2); font-weight: 600; }
.ctx p { background: #fbfaf6; padding: 10px; border-radius: 8px; font-size: .95rem; }
.tr { line-height: 1.8; }

/* Quiz */
.qtop { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qhead { margin-bottom: 8px; }
.chip { font-size: .8rem; padding: 3px 10px; border-radius: 99px; background: #e7f0f2; color: var(--pri); font-weight: 700; }
.q { font-size: 1.12rem; font-weight: 600; margin: 8px 0 12px; }
.target { font-size: 1.25rem; font-weight: 700; color: var(--pri); background: #f2f8f9; padding: 12px; border-radius: 10px; }
.opts { display: grid; gap: 8px; }
.opt { text-align: left; border: 2px solid var(--line); background: #fff; padding: 12px 14px; border-radius: 12px; font: inherit; cursor: pointer; color: inherit; }
.opt:hover:not(:disabled) { border-color: var(--pri2); }
.opt.right, .inp.right { border-color: var(--good); background: #e8f6ee; }
.opt.wrong, .inp.wrong { border-color: var(--weak); background: #fbe9eb; }
.opt:disabled { cursor: default; }
.inp { width: 100%; border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: #fff; color: inherit; }
.inp:focus { outline: none; border-color: var(--pri2); }
textarea.inp { resize: vertical; margin-bottom: 8px; }
.row .inp { flex: 1; }
.blank { display: inline-block; min-width: 60px; border-bottom: 2px solid var(--pri2); color: transparent; }
.audio { display: flex; gap: 8px; margin: 8px 0 12px; flex-wrap: wrap; }
.built, .pool { display: flex; flex-wrap: wrap; gap: 8px; min-height: 50px; padding: 10px; border-radius: 10px; margin-bottom: 10px; }
.built { background: #f2f8f9; border: 2px dashed #bcd7dd; }
.wchip { border: 1px solid var(--line); background: #fff; padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; color: inherit; }
.wchip.on { background: var(--pri); color: #fff; border-color: var(--pri); }
.fb { border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.fb.ok { background: #e8f6ee; border: 1px solid #bfe5cd; } .fb.bad { background: #fdecee; border: 1px solid #f2c3ca; }
.fb p { margin: 6px 0; }
.ex { font-size: .95rem; }
.w-ok { color: var(--good); font-weight: 600; } .w-miss { color: var(--weak); text-decoration: underline wavy; font-weight: 600; }
.said { font-style: italic; color: var(--muted); min-height: 1.4em; }
.issues { margin: 6px 0; padding-left: 20px; color: #8a4b00; }
.selfcheck { background: #fff; border-radius: 10px; padding: 10px; margin: 10px 0; }
.selfcheck label { margin: 4px 0; } .selfcheck input { margin-right: 6px; }
.rev { border-bottom: 1px dashed var(--line); padding: 6px 0; } .rev p { margin: 2px 0; }

/* Settings */
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day { margin: 0; } .day input { display: none; }
.day span { display: inline-block; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; font-weight: 600; }
.day input:checked + span { background: var(--pri); color: #fff; border-color: var(--pri); }
.opt-block { background: #f7f9fa; border-radius: 10px; padding: 12px; margin: 10px 0; }
.opt-block p { margin: 4px 0 8px; }

/* Chart */
.chart { position: relative; display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-bottom: 22px; margin: 10px 0; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.chart .col i { width: 70%; background: var(--pri2); border-radius: 6px 6px 0 0; min-height: 2px; }
.chart .col i.good { background: var(--good); }
.chart .col small { position: absolute; bottom: -20px; font-size: .68rem; color: var(--muted); white-space: nowrap; }
.chart { margin-top: 26px; }
.chart .goal { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--acc); pointer-events: none; }
.chart .goal span { position: absolute; right: 0; top: -18px; font-size: .7rem; color: var(--acc); }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1c2730; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }
@media (min-width: 761px) { .toast { bottom: 24px; } }

/* Đăng nhập */
body.auth nav { display: none; }
.login { max-width: 420px; margin: 24px auto; }
.login h1 { margin: 8px 0 2px; }
.login .tabs { justify-content: center; margin: 14px 0 4px; }
.err { color: var(--weak); min-height: 1.2em; font-size: .92rem; }
.sync { font-size: .85rem; color: var(--good); } .sync.err { color: var(--weak); }
/* Mục tiêu, lý thuyết, điều hướng bài */
.goals { background: #eef7f0; border: 1px solid #c9e7d3; border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.goals ul { margin: 6px 0 0; padding-left: 20px; } .goals li { margin: 3px 0; }
.theory { background: #f4f8fb; border-left: 3px solid var(--pri2); border-radius: 6px; padding: 4px 14px; margin-bottom: 8px; }
.lnav { display: flex; justify-content: space-between; gap: 8px; margin: 4px 0 14px; flex-wrap: wrap; }
.lnav .btn { max-width: 48%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; line-height: 22px; }
.qtop .btn.sm { min-height: 32px; padding: 4px 10px; font-size: .82rem; white-space: nowrap; }
@media (max-width: 520px) { .qtop { flex-wrap: wrap; } .qtop .pbar { order: 9; flex-basis: 100%; } .lnav .btn { max-width: 100%; } }
/* Hộp lý thuyết khi đang làm bài */
.modal { position: fixed; inset: 0; background: rgba(15,30,40,.45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal-card { background: #fff; width: 100%; max-width: 720px; max-height: 85vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px 18px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 761px) { .modal { align-items: center; } .modal-card { border-radius: 16px; } }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
/* Danh sách bài học theo trình độ */
.lvhead h2 { margin: 0; }
.lvhead details { margin-top: 10px; }
.listhead { margin: 18px 4px 8px; }
.parthead { background: #f1f4f6; color: var(--muted); font-size: .82rem; font-weight: 700; padding: 6px 14px; text-transform: uppercase; letter-spacing: .03em; }
.list.flat { box-shadow: none; border: 1px solid var(--line); margin: 8px 0 0; }
.card .row.between h3 { margin: 0; }
/* Tên người học trên thanh trên cùng */
.top .me { margin-left: auto; margin-right: 12px; display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; padding: 4px 10px 4px 4px; border-radius: 99px; background: rgba(255,255,255,.12); max-width: 46vw; }
.top .me[hidden] { display: none; }
.me .av { width: 30px; height: 30px; border-radius: 50%; background: var(--acc); display: grid; place-items: center; font-weight: 700; flex: none; }
.me .nm { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.me .nm b, .me .nm small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .nm small { color: #cfe3e8; font-size: .72rem; }
@media (max-width: 760px) { .top { justify-content: space-between; } .top .me { margin: 0; } }
.updbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: #1c2730; color: #fff; padding: 8px 10px 8px 16px; border-radius: 12px; z-index: 70; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow); }
@media (min-width: 761px) { .updbar { bottom: 20px; } }
label small.muted { display: block; margin-top: 3px; font-size: .8rem; }
