:root {
  --pink: #ff5c8a; --pink-soft: #ffe3ec;
  --orange: #ff9f1c; --orange-soft: #fff0d9;
  --yellow: #ffd23f; --yellow-soft: #fff8d6;
  --teal: #12b5a5; --teal-soft: #d9f7f3;
  --blue: #3a86ff; --blue-soft: #e1edff;
  --purple: #8b5cf6; --purple-soft: #efe7ff;
  --green: #22c55e; --green-soft: #dcfce7;
  --red: #ef4444; --red-soft: #fee2e2;
  --ink: #2b2140; --ink-2: #5b5370; --line: #eadff0;
  --bg: #fff8f2; --card: #ffffff;
  --radius: 22px; --shadow: 0 6px 0 rgba(43,33,64,.08), 0 10px 26px rgba(43,33,64,.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  background-image: radial-gradient(circle at 8% 12%, #ffe3ec 0 110px, transparent 111px),
                    radial-gradient(circle at 95% 30%, #d9f7f3 0 140px, transparent 141px),
                    radial-gradient(circle at 15% 95%, #fff0d9 0 160px, transparent 161px);
  background-attachment: fixed;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 19px; line-height: 1.5; min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: linear-gradient(90deg, #ff5c8a, #ff8a5c 55%, #ffb31c);
  color: #fff; box-shadow: 0 4px 14px rgba(255,92,138,.35);
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; color: #fff; text-align: left; min-width: 0; }
.logo { font-size: 38px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.15)); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text b { font-size: 26px; font-weight: 900; letter-spacing: .3px; line-height: 1.1; }
.brand-text .nine { display: inline-block; background: #fff; color: var(--pink); border-radius: 10px; padding: 0 7px; margin-left: 3px; }
.brand-text small { font-size: 13px; font-weight: 700; opacity: .95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { font-weight: 800; font-size: 15px; text-align: right; flex-shrink: 0; }
.who button { background: rgba(255,255,255,.25); border: 2px solid rgba(255,255,255,.7); color: #fff; border-radius: 999px; padding: 4px 12px; font-weight: 800; font-size: 14px; }

/* ---------- layout ---------- */
.app { max-width: 920px; margin: 0 auto; padding: 18px 16px 60px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; border: 2px solid var(--line); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h1 { font-size: 30px; font-weight: 900; }
h2 { font-size: 25px; font-weight: 900; }
h3 { font-size: 21px; font-weight: 800; }
.muted { color: var(--ink-2); }
.center { text-align: center; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
.spacer { height: 14px; }
.crumbs { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.back { background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 8px 16px; font-weight: 800; font-size: 17px; box-shadow: 0 3px 0 var(--line); }
.back:active { transform: translateY(2px); box-shadow: none; }
.crumb-title { font-weight: 900; font-size: 20px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 18px; padding: 14px 22px; font-weight: 900; font-size: 20px; color: #fff;
  background: var(--pink); box-shadow: 0 5px 0 #d63d6a; transition: transform .08s, box-shadow .08s, filter .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.teal { background: var(--teal); box-shadow: 0 5px 0 #0b8a7d; }
.btn.blue { background: var(--blue); box-shadow: 0 5px 0 #2563cc; }
.btn.orange { background: var(--orange); box-shadow: 0 5px 0 #d97f00; }
.btn.purple { background: var(--purple); box-shadow: 0 5px 0 #6d3fd6; }
.btn.green { background: var(--green); box-shadow: 0 5px 0 #15963f; }
.btn.light { background: #fff; color: var(--ink); border: 2px solid var(--line); box-shadow: 0 5px 0 var(--line); }
.btn.big { font-size: 23px; padding: 16px 30px; min-height: 64px; }
.btn.wide { width: 100%; }
.sound { width: 64px; height: 64px; min-height: 64px; padding: 0; border-radius: 50%; font-size: 30px; }
.sound.small { width: 50px; height: 50px; min-height: 50px; font-size: 23px; }

/* ---------- login ---------- */
.login { max-width: 520px; margin: 20px auto; text-align: center; }
.hana-big { font-size: 84px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }
.field { text-align: left; margin: 14px 0; }
.field label { display: block; font-weight: 800; margin-bottom: 6px; }
.input {
  width: 100%; border: 3px solid var(--line); border-radius: 16px; padding: 14px 16px; font-size: 22px; font-weight: 700;
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px var(--blue-soft); }

/* ---------- home tiles ---------- */
.hello { margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.tile {
  border: 0; border-radius: 26px; padding: 22px 18px; text-align: left; color: #fff; min-height: 170px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px; position: relative; overflow: hidden;
  box-shadow: 0 7px 0 rgba(0,0,0,.14); transition: transform .1s;
}
.tile:active { transform: translateY(4px); }
.tile .ico { font-size: 52px; line-height: 1; }
.tile b { font-size: 25px; font-weight: 900; line-height: 1.15; }
.tile span { font-size: 16px; font-weight: 700; opacity: .96; }
.tile::after { content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.18); }
.t-pink { background: linear-gradient(135deg, #ff5c8a, #ff8fab); }
.t-teal { background: linear-gradient(135deg, #12b5a5, #4fd1c5); }
.t-blue { background: linear-gradient(135deg, #3a86ff, #6aa8ff); }
.t-orange { background: linear-gradient(135deg, #ff9f1c, #ffc15e); }

/* ---------- unit grid ---------- */
.units { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.unit {
  background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 14px; text-align: left;
  box-shadow: 0 5px 0 var(--line); display: flex; flex-direction: column; gap: 4px; min-height: 118px;
}
.unit:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.unit .num { font-size: 15px; font-weight: 900; color: #fff; border-radius: 999px; padding: 2px 12px; align-self: flex-start; }
.unit b { font-size: 18px; line-height: 1.2; }
.unit small { font-size: 14px; color: var(--ink-2); font-weight: 700; }
.c0 { background: var(--pink); } .c1 { background: var(--orange); } .c2 { background: var(--teal); }
.c3 { background: var(--blue); } .c4 { background: var(--purple); } .c5 { background: var(--green); }

.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.set {
  background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 16px; text-align: left; box-shadow: 0 5px 0 var(--line);
}
.set b { display: block; font-size: 21px; font-weight: 900; }
.set small { color: var(--ink-2); font-weight: 700; font-size: 15px; }
.set.done { border-color: var(--green); box-shadow: 0 5px 0 #a7e8bf; }
.set.done b::after { content: " ✅"; }
.set-groups { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.set-groups i { font-style: normal; font-size: 13px; font-weight: 800; background: var(--teal-soft); color: #0b7a6f; border-radius: 999px; padding: 2px 9px; }
.group-chip { display: inline-block; background: var(--teal-soft); color: #0b7a6f; font-weight: 900; font-size: 16px; border-radius: 999px; padding: 4px 14px; margin-bottom: 12px; }
.set.random { background: var(--yellow-soft); border-color: #ffe07a; box-shadow: 0 5px 0 #ffe07a; }

.modes { display: grid; gap: 14px; }
.mode {
  display: flex; align-items: center; gap: 16px; text-align: left; background: #fff; border: 3px solid var(--line);
  border-radius: 20px; padding: 16px 18px; box-shadow: 0 5px 0 var(--line);
}
.mode:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.mode .mi { font-size: 40px; width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; flex-shrink: 0; }
.mode b { display: block; font-size: 21px; font-weight: 900; line-height: 1.2; }
.mode small { font-size: 15.5px; color: var(--ink-2); font-weight: 700; }

/* ---------- flashcard ---------- */
.progress { height: 16px; background: #fff; border: 2px solid var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 14px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--orange), var(--yellow)); border-radius: 999px; transition: width .35s; }
.counter { font-weight: 900; color: var(--ink-2); font-size: 18px; }
.flash { text-align: center; padding: 30px 20px; background: linear-gradient(180deg, #fff, #fff8fb); border: 3px solid #ffd0de; }
.flash .word { font-size: clamp(40px, 9vw, 68px); font-weight: 900; color: var(--pink); line-height: 1.1; word-break: break-word; margin: 6px 0; }
.flash .ipa { font-size: clamp(22px, 4.5vw, 30px); color: var(--blue); font-weight: 700; font-family: "Segoe UI", "Lucida Sans Unicode", "Arial Unicode MS", system-ui, sans-serif; }
.flash .vi { font-size: clamp(26px, 5.5vw, 38px); font-weight: 900; color: var(--teal); margin: 12px 0 6px; }
.flash .ex { font-size: clamp(18px, 3.6vw, 23px); background: var(--yellow-soft); border-radius: 16px; padding: 12px 14px; margin-top: 16px; display: flex; gap: 10px; align-items: center; justify-content: center; text-align: left; }
.flash .ex-vi { display: block; color: var(--ink-2); font-weight: 700; font-size: .88em; margin-top: 4px; }
.steps { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 16px; }
.step { background: var(--orange-soft); color: #b45f00; border: 2px solid #ffd59a; border-radius: 999px; padding: 6px 14px; font-weight: 900; font-size: 17px; }
.step.ok { background: var(--green-soft); color: #11743a; border-color: #8fdcaa; }
.step.ok::after { content: " ✅"; }
.say-tip { font-weight: 800; color: var(--purple); margin-top: 14px; min-height: 30px; font-size: 20px; }
.flash-nav { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; margin-top: 16px; }

/* ---------- quiz ---------- */
.q-card { text-align: center; padding: 26px 20px; }
.q-label { display: inline-block; background: var(--purple-soft); color: var(--purple); font-weight: 900; border-radius: 999px; padding: 4px 14px; font-size: 16px; margin-bottom: 10px; }
.q-big { font-size: clamp(34px, 7.5vw, 54px); font-weight: 900; color: var(--pink); line-height: 1.15; word-break: break-word; }
.q-vi { font-size: clamp(28px, 6vw, 42px); font-weight: 900; color: var(--teal); line-height: 1.2; }
.q-ipa { font-size: 24px; color: var(--blue); font-weight: 700; }
.q-hint { font-size: clamp(24px, 5vw, 34px); letter-spacing: 6px; font-weight: 900; color: var(--orange); margin: 8px 0; font-family: "Consolas", "Courier New", monospace; word-break: break-word; }
.q-text { font-size: clamp(21px, 4.2vw, 26px); font-weight: 700; text-align: left; white-space: pre-line; line-height: 1.55; }
.q-text .gap { display: inline-block; min-width: 90px; border-bottom: 3px solid var(--pink); margin: 0 4px; }
.sec-title { font-weight: 900; color: var(--blue); font-size: 18px; text-align: left; margin-bottom: 8px; }
.box { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; background: var(--orange-soft); border: 2px dashed var(--orange); border-radius: 16px; padding: 10px; margin: 10px 0 14px; }
.box span { background: #fff; border-radius: 10px; padding: 4px 12px; font-weight: 800; font-size: 18px; }
.answer-row { display: flex; gap: 10px; margin-top: 18px; }
.answer-row .input { text-align: center; font-size: 26px; }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.opts.one { grid-template-columns: 1fr; }
.opt {
  background: #fff; border: 3px solid var(--line); border-radius: 18px; padding: 16px 14px; font-size: 22px; font-weight: 800;
  box-shadow: 0 5px 0 var(--line); min-height: 70px; text-align: center; word-break: break-word; line-height: 1.25;
}
.opt:hover:not(:disabled) { border-color: var(--blue); }
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.opt .k { display: inline-block; width: 30px; height: 30px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-size: 16px; line-height: 30px; margin-right: 6px; vertical-align: middle; }
.opt.right { background: var(--green-soft); border-color: var(--green); box-shadow: 0 5px 0 #8fdcaa; }
.opt.wrong { background: var(--red-soft); border-color: var(--red); box-shadow: 0 5px 0 #f5a3a3; }
.opt:disabled { cursor: default; }
.err-sent { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.err-sent .opt { font-size: 21px; min-height: 60px; padding: 10px 14px; }
.feedback { margin-top: 16px; border-radius: 18px; padding: 14px 16px; font-weight: 800; font-size: 21px; text-align: left; }
.feedback.ok { background: var(--green-soft); color: #11743a; border: 2px solid #8fdcaa; }
.feedback.no { background: var(--red-soft); color: #b42323; border: 2px solid #f5a3a3; }
.feedback .ans { color: var(--ink); }
.next-row { margin-top: 16px; }

/* ---------- result ---------- */
.result { text-align: center; }
.score-ring { width: 170px; height: 170px; border-radius: 50%; margin: 8px auto 16px; display: grid; place-items: center;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--red-soft) 0); }
.score-ring > div { width: 132px; height: 132px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 900; font-size: 40px; line-height: 1; }
.score-ring small { display: block; font-size: 15px; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.stat { border-radius: 18px; padding: 14px; font-weight: 900; font-size: 20px; }
.stat b { display: block; font-size: 40px; line-height: 1.1; }
.stat.ok { background: var(--green-soft); color: #11743a; }
.stat.no { background: var(--red-soft); color: #b42323; }
.wrong-list { text-align: left; margin-top: 10px; display: grid; gap: 10px; }
.wrong-item { border: 2px solid #f5c2c2; background: #fffafa; border-radius: 16px; padding: 12px 14px; font-size: 18px; }
.wrong-item .wq { font-weight: 800; white-space: pre-line; }
.wrong-item .wa { color: var(--red); font-weight: 800; }
.wrong-item .wc { color: #11743a; font-weight: 900; }
.send-status { font-size: 15px; color: var(--ink-2); margin-top: 10px; font-weight: 700; }

/* ---------- grammar ---------- */
.g-item { margin-bottom: 18px; border-left: 8px solid var(--blue); }
.g-item h3 { color: var(--blue); }
.g-use { font-size: 19px; }
.formula { background: var(--purple-soft); border-radius: 16px; padding: 12px 16px; margin: 12px 0; }
.formula div { font-weight: 900; color: #5b2bc4; font-size: 19.5px; padding: 3px 0; }
.ex-list { display: grid; gap: 10px; margin: 12px 0; }
.ex-item { display: flex; gap: 12px; align-items: flex-start; background: var(--yellow-soft); border-radius: 16px; padding: 10px 12px; }
.ex-item .en { font-weight: 800; font-size: 19.5px; }
.ex-item .vi { color: var(--ink-2); font-size: 17px; font-weight: 700; }
.note { background: var(--red-soft); border-radius: 16px; padding: 10px 14px; }
.note div { font-weight: 700; font-size: 17.5px; padding: 2px 0; }
.note div::before { content: "⚠️ "; }

/* ---------- praise overlay ---------- */
.praise { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(255, 240, 246, .82); backdrop-filter: blur(3px); padding: 16px; }
.praise-card { background: #fff; border-radius: 30px; padding: 30px 26px; text-align: center; max-width: 460px; width: 100%;
  border: 4px solid var(--pink); box-shadow: 0 16px 50px rgba(255,92,138,.35); animation: pop .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.praise-card .hana { font-size: 80px; line-height: 1; animation: bob 1.4s ease-in-out infinite; }
.praise-card h2 { color: var(--pink); font-size: 32px; margin: 10px 0 6px; }
.praise-card p { font-size: 22px; font-weight: 800; margin: 0 0 16px; color: var(--ink); }
.confetti { position: fixed; top: -40px; font-size: 30px; pointer-events: none; z-index: 101; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 800; z-index: 120; max-width: calc(100% - 32px); text-align: center; }

@media (max-width: 640px) {
  body { font-size: 18px; }
  .app { padding: 14px 16px 50px; }
  .card { padding: 18px 16px; }
  .tiles { grid-template-columns: 1fr; gap: 12px; }
  .tile { min-height: 120px; flex-direction: row; align-items: center; justify-content: flex-start; gap: 14px; }
  .tile .ico { font-size: 46px; }
  .tile-text { display: flex; flex-direction: column; }
  .units { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .opts { grid-template-columns: 1fr; }
  .brand-text b { font-size: 22px; white-space: nowrap; }
  .brand-text small { font-size: 12px; white-space: normal; line-height: 1.25; }
  .who .nm { display: none; }
  .who button { padding: 4px 10px; font-size: 13px; }
  .logo { font-size: 32px; }
  .answer-row { flex-direction: column; }
  .flash-nav { grid-template-columns: 1fr 1.4fr; }
}
@media (min-width: 641px) { .tile-text { display: flex; flex-direction: column; gap: 4px; } }

.term { margin: 22px 0 12px; font-size: 22px; color: var(--blue); }
.unit-prog { color: var(--teal) !important; font-weight: 800 !important; }


/* ---------- quản trị ---------- */
.teacher-link { text-align: center; margin-top: 26px; }
.teacher-link button { background: none; border: 2px dashed var(--line); border-radius: 999px; padding: 8px 18px; color: var(--ink-2); font-weight: 800; font-size: 15px; }
.teacher-link button:hover { border-color: var(--blue); color: var(--blue); }
.app:has(.admin-filters) { max-width: 1200px; }
.admin-filters { padding: 16px; }
.af-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.af-grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 800; font-size: 14px; color: var(--ink-2); }
.af-wide { grid-column: span 2; }
.sel { border: 2px solid var(--line); border-radius: 12px; padding: 9px 10px; font-size: 16px; font-weight: 700; background: #fff; width: 100%; min-width: 0; }
.sel:focus { outline: none; border-color: var(--blue); }
.admin-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.stat-box { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px; font-weight: 800; color: var(--ink-2); font-size: 14px; text-align: center; }
.stat-box b { display: block; font-size: 28px; color: var(--pink); line-height: 1.1; }
.table-wrap { overflow-x: auto; background: #fff; border-radius: 16px; border: 2px solid var(--line); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.admin-table th { background: var(--blue-soft); color: #1e4fa8; text-align: left; padding: 10px; font-weight: 900; position: sticky; top: 0; white-space: nowrap; }
.admin-table td { padding: 9px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.admin-table tr:hover td { background: #fffaf3; }
.admin-table small { color: var(--ink-2); font-weight: 700; }
.nowrap { white-space: nowrap; }
.num-c { text-align: center; font-weight: 800; }
.score-pill { display: inline-block; min-width: 42px; border-radius: 999px; padding: 2px 8px; font-weight: 900; background: #eee; }
.sc-hi { background: var(--green-soft); color: #11743a; } .sc-mid { background: var(--yellow-soft); color: #9a6a00; } .sc-lo { background: var(--red-soft); color: #b42323; }
.mini { border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 4px 10px; font-weight: 800; font-size: 13px; white-space: nowrap; }
.detail-box { max-height: 50vh; overflow: auto; background: var(--red-soft); border-radius: 12px; padding: 10px 12px; font-size: 15px; font-weight: 700; }
.detail-box div { padding: 3px 0; border-bottom: 1px dashed #f5b7b7; }
@media (max-width: 760px) {
  .af-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-table { font-size: 14px; }
}
