/* SpeakUp — giao diện "vở ô li": giấy kẻ ô, mực tím, bút đỏ của cô giáo */
:root {
  --paper: #F4F7FC;
  --sheet: #FFFFFF;
  --grid: #E1E8F5;
  --grid-strong: #CFD9EC;
  --margin: #F2B8B4;
  --ink: #4B2E83;         /* mực tím */
  --ink-soft: #EEE8F8;
  --red: #C8322B;         /* bút đỏ chấm bài */
  --red-soft: #FBE9E7;
  --green: #1E7A4C;
  --green-soft: #E3F3EA;
  --text: #1F1B2D;
  --muted: #676279;
  --line: #D5DCEB;
  --shadow: 0 1px 0 #D5DCEB, 0 8px 24px -16px rgba(40, 30, 90, .25);

  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif", "Charis SIL", "Doulos SIL", Georgia, serif;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;

  --r-sm: 6px;
  --r-md: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15132A;
    --sheet: #1D1A35;
    --grid: #221F3B;
    --grid-strong: #2B2849;
    --margin: #5A2A3A;
    --ink: #BCA8F2;
    --ink-soft: #2C2650;
    --red: #FF7A6E;
    --red-soft: #3A1F2A;
    --green: #6FD3A0;
    --green-soft: #183326;
    --text: #ECE9F6;
    --muted: #A49FBA;
    --line: #34305A;
    --shadow: 0 1px 0 #2B2849, 0 10px 30px -18px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 1.6em; }
h4 { font-size: .95rem; margin: 1.4em 0 .5em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: var(--sheet); padding: 8px 12px; z-index: 9; }

/* ---------- thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { display: block; font-size: 1.15rem; letter-spacing: -.01em; color: var(--ink); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--red);
  background: radial-gradient(circle, var(--ink) 0 34%, transparent 36%);
  transform: rotate(-8deg);
}
.tagline { display: block; font-size: .78rem; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: var(--r-sm);
  font-weight: 500; color: var(--muted);
}
.tab:hover { color: var(--text); background: var(--ink-soft); }
.tab[aria-current="page"] { color: var(--ink); background: var(--ink-soft); font-weight: 600; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--sheet); }
.lang button { border: 0; background: none; padding: 4px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }

.banner { max-width: 1180px; margin: 14px auto 0; padding: 10px 16px; border-radius: var(--r-sm); font-size: .9rem; }
.banner.info { background: var(--ink-soft); color: var(--ink); }
.banner.warn { background: var(--red-soft); color: var(--red); }

/* ---------- bố cục ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.view { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; }
.view.single { grid-template-columns: minmax(0, 860px); justify-content: center; }
.view[hidden] { display: none; }

.side h2 { font-size: .95rem; color: var(--muted); font-weight: 600; margin: 4px 0 10px; }
.pick-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.pick {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 1px solid transparent; background: none; padding: 10px 12px; border-radius: var(--r-md);
}
.pick:hover { background: var(--sheet); border-color: var(--line); }
.pick.active { background: var(--sheet); border-color: var(--ink); box-shadow: inset 3px 0 0 var(--ink); }
.pick-icon { font-size: 1.35rem; width: 28px; text-align: center; }
.pick-text b { display: block; font-weight: 600; font-size: .95rem; }
.pick-text small { color: var(--muted); font-size: .78rem; }

/* tờ giấy có lề đỏ */
.sheet {
  position: relative;
  background: var(--sheet);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
  padding: 28px 32px 32px 64px;
  min-height: 320px;
}
.sheet::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 40px;
  width: 2px; background: var(--margin);
}
.sheet-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.sheet-head h2, .sheet-head h3 { margin: 0; }
.empty { color: var(--muted); padding: 40px 0; }
.rule { border: 0; border-top: 1px dashed var(--grid-strong); margin: 36px 0 28px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.dots { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0; }
.dots button {
  width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line);
  background: none; font-size: .8rem; font-weight: 600; color: var(--muted);
}
.dots button.cur { border-color: var(--ink); color: var(--ink); background: var(--ink-soft); }
.dots button.pass { border-color: var(--green); color: var(--green); }
.dots button.fail { border-color: var(--red); color: var(--red); }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--sheet);
  padding: 8px 14px; border-radius: var(--r-sm); font-weight: 500; font-size: .9rem;
}
.btn:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ink { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.btn.ink:hover:not(:disabled) { color: var(--sheet); filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: .82rem; }

.rec {
  display: inline-flex; align-items: center; gap: 10px;
  border: 0; border-radius: 999px; padding: 10px 20px 10px 12px;
  background: var(--red); color: #fff; font-weight: 600;
  box-shadow: 0 6px 16px -8px var(--red);
}
.rec-dot { width: 22px; height: 22px; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.rec-dot::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.rec.on .rec-dot::after { border-radius: 2px; }
.rec.on { animation: pulse 1.4s ease-out infinite; }
.rec:disabled { opacity: .6; cursor: progress; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 45%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

/* ---------- thẻ luyện tập ---------- */
.card { margin-top: 8px; }
.target {
  font-size: clamp(1.4rem, 2.6vw, 1.9rem); font-weight: 600; line-height: 1.45;
  letter-spacing: -.01em; margin: 0 0 6px; max-width: 30ch;
}
.card.compact .target { font-size: 1.15rem; max-width: none; }
.vi { font-style: italic; color: var(--ink); margin: 0 0 6px; }
.ipa-line { font-family: var(--serif); font-size: 1.1rem; color: var(--muted); margin: 6px 0; }
.w.bad {
  color: var(--red);
  text-decoration: underline wavy var(--red);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 7px;
  cursor: help;
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.controls .spacer { flex: 1; }
.card.compact .controls { margin-top: 10px; }
.card.compact .controls .btn span { display: none; }
.card.busy .target { opacity: .55; }

.meter { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: .85rem; color: var(--muted); }
.meter-bar { width: 140px; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--red); transform-origin: left; transform: scaleX(0); transition: transform 60ms linear; }
.meter-time { font-variant-numeric: tabular-nums; min-width: 3.5em; }

/* ---------- kết quả: điểm khoanh bút đỏ ---------- */
.result:empty { display: none; }
.result { margin-top: 24px; padding-top: 20px; border-top: 1px dashed var(--grid-strong); }
.result-head { display: flex; align-items: center; gap: 20px; }
.grade { position: relative; width: 104px; height: 104px; flex: none; display: grid; place-items: center; }
.grade svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.grade .pen {
  fill: none; stroke: var(--red); stroke-width: 3.2; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: 0;
}
.grade-num { font-family: var(--hand); font-size: 3rem; line-height: 1; color: var(--red); transform: rotate(-6deg); }
.result.reveal .pen { animation: draw .7s cubic-bezier(.6, .1, .3, 1) both; }
.result.reveal .grade-num { animation: stamp .35s .45s ease-out both; }
@keyframes draw { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
@keyframes stamp { from { opacity: 0; transform: rotate(-6deg) scale(1.3); } to { opacity: 1; transform: rotate(-6deg) scale(1); } }
.grade-label { font-family: var(--hand); font-size: 1.5rem; color: var(--red); margin: 0; line-height: 1.2; }
.heard { margin: 4px 0; }
.lbl { color: var(--muted); font-size: .85rem; }
.result-meta p.small { margin: 0; }

.errors { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.errors li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px;
  padding: 8px 12px; border-radius: var(--r-sm); background: var(--red-soft);
}
.word-btn { border: 0; background: none; padding: 0; font-weight: 700; color: var(--text); text-decoration: underline dotted var(--muted); text-underline-offset: 4px; }
.word-btn:hover { color: var(--ink); }
.ipa { font-family: var(--serif); font-size: 1.05rem; }
.ipa.ok { color: var(--green); }
.ipa.wrong, em.wrong { color: var(--red); }
.conf { margin-left: auto; font-size: .78rem; color: var(--muted); }
.praise { font-family: var(--hand); font-size: 1.3rem; color: var(--green); margin: 0; }

.tips { margin-top: 8px; }
.tip { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.tip:last-child { border-bottom: 0; }
.tip p { margin: 0 0 2px; }
.tip-phone {
  flex: none; min-width: 52px; height: 36px; padding: 0 8px; display: grid; place-items: center;
  font-family: var(--serif); font-size: 1.1rem; color: var(--ink); background: var(--ink-soft); border-radius: var(--r-sm);
}

.pager { display: flex; justify-content: space-between; margin-top: 28px; }

/* ---------- hội thoại ---------- */
.chat { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.bubble { max-width: 88%; padding: 12px 16px; border-radius: 14px; border: 1px solid var(--line); }
.bubble .who { display: block; font-size: .78rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.bubble.theirs { align-self: flex-start; background: var(--paper); border-top-left-radius: 4px; }
.bubble.mine { align-self: flex-end; background: var(--ink-soft); border-color: transparent; border-top-right-radius: 4px; }
.bubble.current { border-color: var(--ink); }
.bubble .target { font-size: 1.05rem; max-width: none; }
.bubble .card { margin-top: 0; }
.bubble .result { margin-top: 14px; }
.bubble .grade { width: 80px; height: 80px; }
.bubble .grade-num { font-size: 2.3rem; }
.line-foot { display: flex; align-items: center; gap: 8px; }
.next-line { margin-top: 12px; }
.mini-score { font-family: var(--hand); color: var(--red); font-size: 1.3rem; border: 2px solid var(--red); border-radius: 50%; padding: 0 8px; }
.mini-score.big { font-size: 1.8rem; padding: 2px 12px; }
.done { text-align: center; font-weight: 600; margin-top: 12px; }

/* ---------- nói tự do ---------- */
.free-form { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.free-form textarea {
  flex: 1 1 320px; resize: vertical; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--paper); font-size: 1.05rem;
}
.talk { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.talk-out { flex: 1; min-width: 240px; }
.talk-out .lbl { margin: 0; }
.talk-text { font-size: 1.25rem; font-weight: 600; margin: 2px 0 10px; }

/* ---------- tiến độ ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0; }
.stats div { padding: 14px 16px; border-radius: var(--r-md); background: var(--paper); }
.stats dt { font-size: .82rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.8rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding: 8px 0 22px; border-bottom: 1px solid var(--line); }
.bar { flex: 1; max-width: 42px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.bar span { width: 100%; background: var(--ink); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar small { position: absolute; bottom: -20px; font-size: .7rem; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.weak { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.weak li { display: flex; gap: 12px; align-items: flex-start; }
.weak.words li { justify-content: space-between; border-bottom: 1px solid var(--grid); padding-bottom: 6px; }
.history { width: 100%; border-collapse: collapse; }
.history td { padding: 10px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.h-score { font-family: var(--hand); font-size: 1.4rem; width: 48px; text-align: center; }
.h-score.pass { color: var(--green); }
.h-score.fail { color: var(--red); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: min(560px, calc(100% - 32px));
  background: var(--text); color: var(--paper); padding: 12px 18px; border-radius: var(--r-md);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 10; font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- di động ---------- */
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .lang { margin-left: auto; }
  main { padding: 16px; }
  .view, .view.single { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; }
  .tab { white-space: nowrap; }
  .side .pick-list { grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); overflow-x: auto; padding-bottom: 6px; }
  .sheet { padding: 20px 16px 24px 36px; }
  .sheet::before { left: 20px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .bubble { max-width: 100%; }
  .controls .spacer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- khẩu hình miệng ---------- */
.mouth { display: block; width: 100%; height: auto; }
.mouth .m-skin { fill: #F5DAC6; }
.mouth .m-nose { fill: none; stroke: #DDA98E; stroke-width: 2.5; stroke-linecap: round; }
.mouth .m-cavity { fill: #3D1621; }
.mouth .m-lips { fill: #C9606B; }
.mouth .m-lipline { fill: none; stroke: #93374A; stroke-width: 1.4; }
.mouth .m-teeth { fill: #FFFDF6; stroke: #E6D8C4; stroke-width: .8; }
.mouth .m-tongue { fill: #DD7381; }
.mouth .m-tongue.tip { fill: #EE8F9B; }
.mouth.mini { width: 64px; border-radius: 8px; }
.mouth.heard .m-lips { fill: #B9707A; }

/* ---------- khung đăng nhập / ẩn hiện ---------- */
body.booting #auth, body.booting .app-only { display: none !important; }
body:not(.authed) .app-only { display: none !important; }
.top-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.tabs + .top-right { margin-left: 0; }
.user { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: .85rem; color: var(--muted); white-space: nowrap; }

.auth {
  max-width: 1080px; margin: 0 auto; padding: 56px 24px;
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 420px); gap: 48px; align-items: center;
}
.auth-copy h1 { font-size: clamp(2rem, 4.4vw, 3.1rem); line-height: 1.12; letter-spacing: -.02em; margin: 0 0 16px; color: var(--ink); max-width: 14ch; }
.auth-copy p { font-size: 1.1rem; color: var(--muted); max-width: 42ch; margin: 0 0 28px; }
.auth-mouths { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; max-width: 460px; }
.auth-mouths figure { margin: 0; text-align: center; }
.auth-mouths .mouth.mini { width: 100%; }
.auth-mouths figcaption { font-family: var(--serif); color: var(--ink); font-size: .95rem; margin-top: 4px; }
.auth-form { display: grid; gap: 14px; min-height: 0; }
.auth-form h2 { margin: 0 0 4px; }
.auth-form:not(.register) .reg-only { display: none; }
.field { display: grid; gap: 4px; font-size: .88rem; font-weight: 500; }
.field input, .field select, select#chatTopic {
  padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--paper); font-size: 1rem; font-weight: 400; min-width: 0;
}
.field input:focus, .field select:focus, .chat-compose input:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); }
.form-error { color: var(--red); margin: 0; min-height: 1.2em; font-size: .9rem; }
.btn.wide { justify-content: center; padding: 12px; font-size: 1rem; }
.link { border: 0; background: none; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; padding: 4px; justify-self: center; font-size: .9rem; }
.note { background: var(--ink-soft); color: var(--ink); padding: 10px 14px; border-radius: var(--r-sm); font-size: .9rem; }

.pick-sep { font-size: .82rem; color: var(--ink); font-weight: 600; padding: 14px 12px 4px; }
.scenario { margin: -6px 0 10px; }
.btn.on { border-color: var(--ink); color: var(--ink); background: var(--ink-soft); }

/* ---------- bảng khẩu hình ---------- */
.mouth-panel {
  display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start;
  margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper);
}
.mouth-stage .mouth { border-radius: 14px; }
.mouth-caption { margin: 0 0 10px; display: grid; gap: 2px; }
.cap-phone { font-family: var(--serif); font-size: 1.5rem; color: var(--ink); line-height: 1.2; }
.mouth-words { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 14px; }
.mw { display: grid; gap: 4px; }
.mw b { font-size: .8rem; color: var(--muted); font-weight: 600; }
.mw > span { display: flex; gap: 2px; }
.ph {
  min-width: 30px; height: 32px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--sheet); font-family: var(--serif); font-size: 1rem;
}
.ph:hover { border-color: var(--ink); }
.ph.on { background: var(--ink); color: var(--sheet); border-color: var(--ink); }

.err-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px; }
.errors li { display: block; }
.errors .cmp { padding: 2px 8px; font-size: .78rem; }
.cmp-box { margin-top: 10px; }
.mouth-compare { display: flex; flex-wrap: wrap; gap: 14px; }
.mouth-compare figure { margin: 0; background: var(--sheet); border-radius: var(--r-sm); padding: 10px; max-width: 320px; }
.mouth-compare .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mouth-compare .mouth { width: 130px; border-radius: 10px; }
.mouth-compare figcaption { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.mouth-compare b.ok { color: var(--green); font-family: var(--serif); font-size: 1rem; }
.mouth-compare b.wrong { color: var(--red); font-family: var(--serif); font-size: 1rem; }
.mouth-compare p { margin: 8px 0 0; }
.mouth-none { width: 130px; aspect-ratio: 200 / 125; display: grid; place-items: center; background: var(--grid); border-radius: 10px; color: var(--muted); }
.tip-visual { flex: none; display: grid; gap: 4px; justify-items: center; }
.tip-visual .tip-phone { min-width: 0; height: auto; padding: 2px 8px; font-size: .95rem; }

/* ---------- AI gợi ý ---------- */
.ai-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 18px 0 24px; }
.ai-form .grow { flex: 1 1 260px; }
.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.ai-grid.loading { opacity: .5; pointer-events: none; }
.ai-card {
  display: flex; flex-direction: column; gap: 8px; padding: 16px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sheet);
}
.ai-card header { display: flex; gap: 12px; align-items: center; }
.ai-card h3 { margin: 0; font-size: 1.02rem; }
.ai-icon { font-size: 1.8rem; }
.ai-card p { margin: 0; }
.phrases { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; display: grid; gap: 4px; }
.ai-card footer { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }
.ai-card .del { margin-left: auto; color: var(--muted); }

/* ---------- trò chuyện AI ---------- */
.chat-sheet { display: flex; flex-direction: column; }
#chatTopic { max-width: 260px; }
.chat-opts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .85rem; color: var(--muted); margin: 4px 0 12px; }
.chat-opts input { accent-color: var(--ink); }
.chat-log {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 300px; max-height: 56vh; overflow-y: auto; padding: 12px 4px; scroll-behavior: smooth;
}
.chat-log .bubble .target { font-size: 1.05rem; margin: 0 0 4px; }
.chat-log .bubble .vi { margin: 0 0 4px; font-size: .95rem; }
.bubble.mine { position: relative; }
.bubble.mine .mini-score { float: right; margin: -2px -4px 0 10px; cursor: pointer; background: none; }
.correction { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--red); background: var(--sheet); border-radius: 0 6px 6px 0; }
.correction p { margin: 0; }
.correction s { color: var(--red); }
.correction b { color: var(--green); }
.typing { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.typing span:not(.sr) { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.chat-hints { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 8px; margin: 6px 0 10px; }
.hint { border: 1px dashed var(--ink); background: none; color: var(--ink); padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
.hint:hover { background: var(--ink-soft); }
.chat-input { display: flex; gap: 16px; align-items: center; border-top: 1px dashed var(--grid-strong); padding-top: 14px; }
.mic {
  position: relative; flex: none; width: 72px; height: 72px; border-radius: 50%; border: 0;
  background: var(--red); color: #fff; font-size: 1.7rem; box-shadow: 0 8px 20px -10px var(--red);
}
.mic .mic-ring { position: absolute; inset: -6px; border-radius: 50%; border: 2px solid transparent; }
.mic.on .mic-ring { border-color: var(--red); animation: ring 1.3s ease-out infinite; }
@keyframes ring { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
.chat-compose { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.live { margin: 0; font-weight: 600; color: var(--ink); min-height: 1.5em; overflow-wrap: anywhere; }
#chatForm { display: flex; gap: 8px; }
#chatForm input { flex: 1; min-width: 0; width: 100%; padding: 9px 12px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--paper); }

@media (max-width: 860px) {
  .auth { grid-template-columns: minmax(0, 1fr); padding: 28px 16px; gap: 28px; }
  .auth-mouths { grid-template-columns: repeat(6, 1fr); }
  .mouth-panel { grid-template-columns: minmax(0, 1fr); }
  .mouth-stage { max-width: 240px; }
  .user-name { display: none; }
  .chat-log { max-height: 50vh; }
  .mic { width: 60px; height: 60px; }
}

.banner.warn { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.banner.warn span { color: var(--text); }
.banner.warn .btn { margin-left: auto; }

/* thanh trên: 6 tab — giữ nhãn trên 1 dòng, xuống hàng riêng khi màn hình hẹp */
.tab { white-space: nowrap; }
.brand { flex: none; }
.tagline { white-space: nowrap; }
@media (max-width: 1460px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .top-right { margin-left: auto; }
}

/* ---------- sửa phát âm & ngữ pháp ---------- */
.fix-input { display: flex; gap: 18px; align-items: flex-start; margin: 18px 0 8px; }
.fix-compose { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.fix-compose textarea {
  width: 100%; resize: vertical; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--paper); font-size: 1.05rem;
}
#fixResult:empty { display: none; }
#fixResult { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--grid-strong); }
.fix-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
.fix-sec h3 { margin-top: 0; }
.fix-sec .result { margin-top: 0; padding-top: 0; border-top: 0; }
.fix-line { font-size: 1.15rem; line-height: 1.6; margin: 0 0 10px; }
.fix-line .lbl { display: block; font-size: .8rem; }
.ok-line { color: var(--green); font-weight: 600; }
.g-wrong { color: var(--red); text-decoration: line-through; text-decoration-thickness: 2px; }
.g-fix { color: var(--green); font-weight: 700; background: var(--green-soft); border-radius: 4px; padding: 0 3px; }
.g-errors { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.g-errors li { padding: 10px 12px; border-radius: var(--r-sm); background: var(--red-soft); display: grid; gap: 4px; }
.g-errors li > span:nth-child(2) { font-weight: 500; }
.g-errors s { color: var(--red); }
.g-errors b { color: var(--green); }
.g-errors p { margin: 0; font-size: .92rem; }
.g-type {
  justify-self: start; display: inline-block; font-size: .75rem; font-weight: 600; color: var(--ink);
  background: var(--ink-soft); border-radius: 999px; padding: 1px 9px;
}
.g-type.soft { font-weight: 500; }
.alts { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.alts li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* huấn luyện phát âm */
.coach-btn { margin-top: 12px; }
.coach-box { margin-top: 12px; display: grid; gap: 12px; }
.coach-summary { margin: 0; font-weight: 500; color: var(--ink); }
.coach-item { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; background: var(--sheet); display: grid; gap: 8px; }
.coach-item header { display: flex; gap: 14px; align-items: flex-start; }
.coach-item h4 { margin: 0 0 4px; color: var(--text); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: 1rem; }
.coach-item p { margin: 0; }
.coach-fix { background: var(--green-soft); padding: 8px 10px; border-radius: var(--r-sm); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pair-chip { border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 4px 12px; font-size: .88rem; }
.pair-chip b { color: var(--green); }
.pair-chip:hover { border-color: var(--ink); }
.drill-slot:empty { display: none; }
.drill-slot { border-top: 1px dashed var(--grid-strong); padding-top: 10px; }

/* thống kê ngữ pháp */
.g-bars { display: grid; gap: 6px; max-width: 520px; }
.g-bar { display: grid; grid-template-columns: 130px 1fr 32px; gap: 10px; align-items: center; }
.g-bar .g-type { justify-self: stretch; text-align: center; }
.g-track { height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.g-track i { display: block; height: 100%; background: var(--red); }
.g-recent { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; font-size: .92rem; }
.g-recent s { color: var(--red); }
.g-recent b { color: var(--green); font-weight: 600; }

@media (max-width: 860px) {
  .fix-grid { grid-template-columns: minmax(0, 1fr); }
  .g-bar { grid-template-columns: 110px 1fr 28px; }
}
.user .btn { white-space: nowrap; }

/* ---------- phòng học AI ---------- */
.view.single.wide { grid-template-columns: minmax(0, 1120px); }
.lobby { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 32px; align-items: start; }
.lobby-copy h2 { font-size: 1.6rem; color: var(--ink); }
.lobby-copy > p { font-size: 1.05rem; }
.lobby-how { padding-left: 20px; display: grid; gap: 6px; margin: 0 0 16px; }
.lobby-form { display: grid; gap: 12px; padding: 18px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); }
.lobby-tutor { display: grid; justify-items: center; gap: 6px; font-weight: 600; color: var(--ink); }
.lobby-tutor .mouth { width: 170px; border-radius: 16px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { accent-color: var(--ink); }
.past { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.past li { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: .9rem; }
.past .mini-score { font-size: 1.1rem; }

.meet { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); gap: 20px; }
.meet-stage { display: grid; gap: 12px; align-content: start; background: #231B3D; border-radius: 16px; padding: 14px; color: #F3F0FB; }
.tiles { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.tile {
  position: relative; border-radius: 12px; background: #2F2652; min-height: 260px;
  display: grid; place-items: center; overflow: hidden; outline: 3px solid transparent; transition: outline-color .2s;
}
.tile.talking { outline-color: #8C6FE0; }
.tile.you.talking { outline-color: var(--red); }
.tile-mouth { width: 82%; max-width: 360px; }
.tile-mouth .mouth { border-radius: 14px; }
.tile-label { position: absolute; left: 10px; bottom: 10px; font-size: .85rem; font-weight: 600; background: rgba(0,0,0,.35); padding: 3px 10px; border-radius: 999px; }
.tile-state { position: absolute; right: 10px; top: 10px; font-size: .78rem; color: #CFC6EE; }
.you-avatar { position: relative; width: 112px; height: 112px; display: grid; place-items: center; }
.you-ring { position: absolute; inset: 0; border-radius: 50%; background: rgba(200, 50, 43, .35); transition: transform 70ms linear; }
.you-initials { position: relative; width: 100px; height: 100px; border-radius: 50%; display: grid; place-items: center; background: #F5DAC6; color: #4B2E83; font-size: 2rem; font-weight: 700; }
.caption { min-height: 3.2em; text-align: center; font-size: 1.15rem; font-weight: 500; line-height: 1.45; padding: 0 8px; }
.caption small { display: block; font-size: .92rem; color: #CFC6EE; font-style: italic; font-weight: 400; }
.repeat-banner { background: #FFF6D6; color: #3B2F00; border-radius: 10px; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 1.05rem; }
.repeat-banner .lbl { color: #6B5A10; }
.repeat-banner .btn { background: #fff; }
.meet-controls { display: flex; justify-content: center; align-items: center; gap: 12px; padding-top: 4px; }
.timer { font-variant-numeric: tabular-nums; color: #CFC6EE; margin-right: auto; min-width: 54px; }
.ctl { border: 0; border-radius: 999px; min-width: 48px; height: 48px; padding: 0 16px; background: #3D3366; color: #fff; font-size: 1.15rem; }
.ctl:hover:not(:disabled) { background: #4C4180; }
.ctl:disabled { opacity: .4; cursor: default; }
.ctl.off { background: #6B6680; text-decoration: line-through; }
.ctl.end { background: var(--red); font-size: .95rem; font-weight: 600; margin-left: auto; }
.meet-side { display: flex; flex-direction: column; min-height: 0; }
.meet-side h3 { margin: 0 0 8px; }
.meet-log { flex: 1; max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.ml { padding: 8px 12px; border-radius: 10px; background: var(--paper); font-size: .95rem; }
.ml > b { font-size: .78rem; color: var(--muted); }
.ml p { margin: 2px 0; }
.ml.you { background: var(--ink-soft); }
.ml.you.has-fix { box-shadow: inset 3px 0 0 var(--red); }
.ml .mini-score { float: right; cursor: pointer; background: none; font-size: 1.05rem; }
.ml .correction { margin-top: 6px; }
.ml .ok { color: var(--green); }
.ml .wrong { color: var(--red); }
.hint.static { cursor: default; }

@media (max-width: 960px) {
  .lobby { grid-template-columns: minmax(0, 1fr); }
  .meet { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile { min-height: 170px; }
  .you-avatar { width: 84px; height: 84px; }
  .you-initials { width: 74px; height: 74px; font-size: 1.5rem; }
  .meet-log { max-height: 340px; }
  .ctl-label { display: none; }
}

.meet-stage { align-self: start; }
.tile-label { max-width: calc(100% - 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
a.btn { text-decoration: none; color: inherit; }

/* thanh trên: luôn đặt các tab ở hàng riêng (nhiều mục) */
.topbar { flex-wrap: wrap; row-gap: 6px; }
.tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; scrollbar-width: thin; }
.top-right { margin-left: auto; }

/* ---------- từ vựng ---------- */
.v-stats { display: flex; gap: 8px; margin: 0; flex-wrap: wrap; }
.v-stats div { background: var(--paper); border-radius: var(--r-sm); padding: 6px 12px; min-width: 88px; }
.v-stats dt { font-size: .72rem; color: var(--muted); }
.v-stats dd { margin: 0; font-size: 1.3rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.v-stats .hot dd { color: var(--red); }
.v-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 4px 0 18px; overflow-x: auto; }
.v-tabs button { border: 0; background: none; padding: 10px 14px; font-weight: 500; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.v-tabs button[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.v-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: .75rem; }
.v-kind { font-size: .75rem; color: var(--muted); font-style: italic; }
.v-mark { background: #FFF3B0; color: inherit; border-radius: 3px; padding: 0 2px; }
.v-done { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 30px 0; }
.praise.big { font-size: 1.8rem; }
.row.center, .center { justify-content: center; text-align: center; }
kbd { font-family: var(--sans); font-size: .7rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); background: var(--sheet); }

/* thẻ ghi nhớ */
.v-progress { display: flex; align-items: center; gap: 12px; font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.v-bar { flex: 1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.v-bar i { display: block; height: 100%; background: var(--ink); transition: width .3s; }
.flashcard { position: relative; max-width: 640px; min-height: 300px; margin: 0 auto; perspective: 1200px; cursor: pointer; }
.fc-face {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center;
  padding: 28px 32px; border-radius: 16px; background: var(--sheet); border: 1px solid var(--line);
  box-shadow: 0 1px 0 var(--line), 0 18px 40px -26px rgba(40, 30, 90, .45);
  backface-visibility: hidden; transition: transform .45s cubic-bezier(.4, .2, .2, 1);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px); background-size: 100% 30px;
}
.fc-back { transform: rotateY(180deg); align-content: center; }
.flashcard.flipped .fc-front { transform: rotateY(-180deg); }
.flashcard.flipped .fc-back { transform: rotateY(0); }
.flashcard.flipped { min-height: 340px; }
.fc-term { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 700; color: var(--ink); margin: 0; line-height: 1.15; }
.fc-term.small-term { font-size: 1.4rem; }
.fc-term.mid { font-size: 1.6rem; }
.fc-meaning { font-size: 1.4rem; font-weight: 600; margin: 4px 0; }
.fc-ex { margin: 0; font-size: 1.02rem; max-width: 48ch; }
.fc-ipa { margin: 0; }
.fc-actions { display: flex; justify-content: center; gap: 10px; margin: 18px auto 10px; max-width: 640px; flex-wrap: wrap; }
.gbtn { flex: 1; min-width: 110px; border: 1px solid var(--line); background: var(--sheet); border-radius: var(--r-md); padding: 10px; display: grid; gap: 2px; justify-items: center; }
.gbtn b { font-size: 1rem; }
.gbtn small { color: var(--muted); font-size: .8rem; }
.gbtn.g1 { border-color: var(--red); } .gbtn.g1 b { color: var(--red); }
.gbtn.g3 b { color: #B7791F; }
.gbtn.g4 { border-color: var(--green); } .gbtn.g4 b { color: var(--green); }
.gbtn.g5 b { color: var(--ink); }
.gbtn:hover { background: var(--paper); }

/* sổ từ */
.v-add { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.v-add > input { flex: 1 1 300px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); font-size: 1rem; }
.v-preview, .v-edit { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; border: 1px dashed var(--grid-strong); border-radius: var(--r-md); }
.v-preview .wide, .v-edit .wide { grid-column: 1 / -1; }
.v-edit input, .v-preview input { width: 100%; }
.v-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.v-filters input { flex: 0 1 260px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--sheet); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: .85rem; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }
.v-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.v-list > li { display: grid; grid-template-columns: minmax(0, 1fr) 180px auto; gap: 6px 16px; align-items: center; padding: 12px 14px; border: 1px solid var(--grid); border-radius: var(--r-md); background: var(--sheet); }
.v-list .v-slot { grid-column: 1 / -1; }
.v-list .v-slot:empty { display: none; }
.v-main p { margin: 0 0 2px; }
.v-term { font-size: 1.08rem; color: var(--ink); }
.v-mean { font-weight: 500; }
.v-meta { display: grid; gap: 4px; justify-items: start; }
.v-acts { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.v-st { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--grid); color: var(--muted); }
.v-st.st-new { background: var(--ink-soft); color: var(--ink); }
.v-st.st-learning { background: #FFF1D6; color: #8A5A00; }
.v-st.st-known { background: #E0F0FF; color: #1D5A8C; }
.v-st.st-mastered { background: var(--green-soft); color: var(--green); }
.v-st.st-bad { background: var(--red-soft); color: var(--red); }
.v-strength { width: 120px; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.v-strength i { display: block; height: 100%; background: var(--green); }
.pack-items > li { grid-template-columns: minmax(0, 1fr) auto; }

/* kho */
.lib-tabs { margin-bottom: 14px; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.pack { display: grid; gap: 8px; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sheet); }
.pack h3 { margin: 0; font-size: 1rem; }
.pack p { margin: 0; }
.pack-icon { font-size: 1.8rem; }
.pack .v-strength { width: 100%; }

/* đặt câu */
.sent-target { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 16px; align-items: start; margin: 12px 0; }
.sent-target select { width: 100%; }
.sent-card { padding: 14px 16px; border-radius: var(--r-md); background: var(--paper); border-left: 4px solid var(--ink); }
.sent-card p { margin: 0 0 4px; }
.sent-card details summary { cursor: pointer; color: var(--ink); }
#sResult:empty { display: none; }
#sResult { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--grid-strong); }
#sResult.reveal .pen { animation: draw .7s cubic-bezier(.6, .1, .3, 1) both; }

/* trò chơi */
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.game-card { display: grid; gap: 6px; align-content: start; padding: 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--sheet); }
.game-card h3 { margin: 0; font-size: 1.05rem; }
.game-card p { margin: 0; }
.game-icon { font-size: 2rem; }
.game-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding-bottom: 12px; border-bottom: 1px dashed var(--grid-strong); margin-bottom: 18px; }
.game-head h3 { margin: 0 auto 0 0; }
.g-stat { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.g-stat b { color: var(--ink); font-size: 1.1rem; }
.g-stat.bump b { animation: bump .35s ease-out; display: inline-block; }
@keyframes bump { 40% { transform: scale(1.35); color: var(--green); } }
.game-stage { min-height: 300px; }
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 720px; margin: 0 auto; }
.m-col { display: grid; gap: 8px; align-content: start; }
.m-tile { min-height: 52px; padding: 10px 12px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--sheet); font-size: .98rem; text-align: center; transition: transform .12s, opacity .25s; }
.m-tile.m-en { font-weight: 600; color: var(--ink); }
.m-tile.sel { border-color: var(--ink); background: var(--ink-soft); transform: scale(1.02); }
.m-tile.done { border-color: var(--green); background: var(--green-soft); color: var(--green); opacity: .45; pointer-events: none; }
.m-tile.bad { border-color: var(--red); background: var(--red-soft); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.q-big { display: grid; justify-items: center; gap: 6px; margin-bottom: 18px; text-align: center; }
.q-big p { margin: 0; }
.big-play { width: 92px; height: 92px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; font-size: 2rem; box-shadow: 0 10px 24px -12px var(--ink); }
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 640px; margin: 0 auto; }
.opt { padding: 14px; border-radius: var(--r-md); border: 1.5px solid var(--line); background: var(--sheet); font-size: 1rem; }
.opt.en { font-weight: 600; color: var(--ink); }
.opt:hover:not(:disabled) { border-color: var(--ink); }
.opt.right { border-color: var(--green); background: var(--green-soft); color: var(--green); }
.opt.wrong-opt { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.reveal-term { text-align: center; font-size: 1.1rem; margin: 14px 0 6px; }
.reveal-term.ok { color: var(--green); }
.reveal-term.wrong { color: var(--red); }
.spell { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; flex-wrap: wrap; }
.spell input { flex: 1 1 240px; padding: 12px 14px; font-size: 1.2rem; border: 1.5px solid var(--line); border-radius: var(--r-md); background: var(--paper); }
.spell-hint { text-align: center; font-family: var(--serif); letter-spacing: .25em; font-size: 1.3rem; color: var(--ink); min-height: 1.5em; }
.cloze { font-size: 1.35rem; text-align: center; max-width: 40ch; margin: 10px auto 6px; line-height: 1.6; }
.gap { display: inline-block; min-width: 90px; border-bottom: 3px solid var(--ink); color: var(--ink); }
.speak-row { display: flex; justify-content: center; align-items: center; gap: 16px; margin-bottom: 12px; }
.g-missed { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; text-align: left; }

@media (max-width: 860px) {
  .v-list > li { grid-template-columns: minmax(0, 1fr); }
  .v-acts { justify-content: flex-start; }
  .sent-target { grid-template-columns: minmax(0, 1fr); }
  .v-preview, .v-edit { grid-template-columns: minmax(0, 1fr); }
  .opts { grid-template-columns: minmax(0, 1fr); }
  .match { gap: 8px; }
  .m-tile { font-size: .88rem; padding: 8px; }
  .flashcard { min-height: 280px; }
}
@media (prefers-reduced-motion: reduce) { .fc-face { transition: none; } }

@media (hover: none) { kbd, .fc-keys { display: none; } }

/* ---------- trình soạn nội dung (dùng chung) ---------- */
.ce-form { display: grid; gap: 14px; }
.ce-field { display: grid; gap: 5px; min-width: 0; }
.ce-label { font-size: .85rem; font-weight: 600; color: var(--text); }
.ce-field input:not([type=checkbox]), .ce-field textarea, .ce-field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--sheet); font: inherit; font-size: .93rem; color: var(--text);
}
.ce-field textarea { resize: vertical; line-height: 1.5; }
.ce-field input:focus, .ce-field textarea:focus, .ce-field select:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); }
.ce-field.invalid input, .ce-field.invalid textarea, .ce-field.invalid .ce-table-wrap { border-color: var(--red); outline-color: var(--red); }
.ce-field.invalid .ce-label { color: var(--red); }
.req { color: var(--red); font-weight: 700; }
.ce-form.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.ce-form.compact .ce-rows, .ce-form.compact .ce-textarea, .ce-form.compact .ce-lines, .ce-form.compact .ce-foot, .ce-form.compact .ce-field:has(.ce-rows) { grid-column: 1 / -1; }
.ce-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); max-height: 52vh; overflow-y: auto; }
.ce-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.ce-table th { position: sticky; top: 0; background: var(--paper); text-align: left; font-size: .75rem; color: var(--muted); padding: 6px 6px; font-weight: 600; z-index: 1; }
.ce-table td { padding: 3px 4px; border-top: 1px solid var(--grid); }
.ce-table input, .ce-table select { width: 100%; min-width: 110px; padding: 6px 8px; border: 1px solid transparent; border-radius: 4px; font: inherit; background: transparent; }
.ce-table input:hover, .ce-table select:hover { border-color: var(--line); }
.ce-table input:focus, .ce-table select:focus { border-color: var(--ink); outline: none; background: var(--sheet); }
.ce-n { width: 30px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.ce-act { width: 84px; white-space: nowrap; text-align: right; }
.ce-ib { border: 0; background: none; width: 24px; height: 26px; border-radius: 4px; color: var(--muted); cursor: pointer; }
.ce-ib:hover:not(:disabled) { background: var(--ink-soft); color: var(--ink); }
.ce-ib.del:hover { background: var(--red-soft); color: var(--red); }
.ce-ib:disabled { opacity: .3; cursor: default; }
.ce-rows-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.ce-rows-foot .muted { margin-left: auto; }
.ce-bulk { margin-top: 8px; padding: 10px; border: 1px dashed var(--line); border-radius: var(--r-sm); background: var(--paper); display: grid; gap: 8px; }
.ce-bulk p { margin: 0; }
.ce-bulk textarea { font-family: ui-monospace, monospace; font-size: .85rem; }
.ce-foot { align-items: center; }
.ce-msg { color: var(--red); }

.ce-modal { border: 0; border-radius: var(--r-md); padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(20, 15, 40, .35); color: var(--text); background: var(--sheet); }
.ce-modal.wide { width: min(1040px, calc(100vw - 24px)); }
.ce-modal::backdrop { background: rgba(20, 15, 40, .4); }
.ce-modal-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; background: var(--sheet); border-bottom: 1px solid var(--grid); }
.ce-modal-head h2 { margin: 0; font-size: 1.12rem; }
.ce-modal-body { padding: 16px 20px 20px; }

/* trạng thái nội dung */
.vis { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.vis-private { background: var(--paper); color: var(--muted); border: 1px solid var(--line); }
.vis-pending { background: #FFF3D6; color: #8A5A00; }
.vis-public { background: var(--green-soft); color: var(--green); }
.vis-rejected { background: var(--red-soft); color: var(--red); }
.vis-hidden { background: var(--grid); color: var(--muted); }
.announce { background: #FFF6D6; color: #3B2F00; border-bottom: 1px solid #F0DFA0; padding: 8px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: center; }
.announce button { border: 0; background: none; cursor: pointer; color: inherit; font-size: 1rem; }
@media (max-width: 640px) {
  .ce-form.compact { grid-template-columns: minmax(0, 1fr); }
  .ce-modal-body { padding: 14px; }
}

/* ---------- nội dung của người học ---------- */
.uc-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 12px; margin: 0 0 14px; background: var(--paper); border: 1px solid var(--grid); border-radius: var(--r-sm); }
.uc-acts { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.btn.danger:hover { color: var(--red); border-color: var(--red); }
.pick-new { border: 1px dashed var(--line); }
.pick-new .pick-icon { color: var(--ink); font-weight: 700; }
.pick-text small .vis { margin-left: 2px; }
.lib-top { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.lib-top .lib-tabs { margin: 0; }
.chip-btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .84rem; color: var(--text); cursor: pointer; }
.chip-btn:hover { border-color: var(--ink); color: var(--ink); }
.chip-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--sheet); }
.mini-btn { border: 1px solid var(--line); background: var(--sheet); border-radius: 6px; padding: 0 6px; height: 24px; font-size: .8rem; line-height: 1; cursor: pointer; color: var(--ink); vertical-align: middle; }
.mini-btn:hover { background: var(--ink-soft); border-color: var(--ink); }
.badge-t { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--ink-soft); color: var(--ink); font-size: .74rem; font-weight: 600; white-space: nowrap; }

/* ---------- Luyện viết ---------- */
.w-lead { margin: -6px 0 6px; max-width: 70ch; }
.w-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.w-types { margin-bottom: 16px; }
.w-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.w-card { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; background: var(--sheet); }
.w-card:hover { border-color: var(--ink); }
.w-card h3 { margin: 0; font-size: 1.02rem; }
.w-meta { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.w-ptext { margin: 0; font-family: var(--serif); font-size: .9rem; color: var(--text); display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; flex: 1; }
.w-card .row { margin-top: auto; }
.w-cbar .uc-bar { margin: 0; padding: 6px 8px; }
.w-guide h3 { margin: 4px 0 8px; }
.w-intro { max-width: 75ch; }
.w-guide h4, .w-side h4 { margin: 18px 0 8px; font-size: .92rem; }
.w-struct { margin: 0; padding-left: 22px; display: grid; gap: 10px; }
.w-struct li { display: grid; gap: 2px; }
.w-struct span { font-size: .9rem; }
.w-struct em { font-family: var(--serif); color: var(--ink); font-size: .9rem; }
.w-tips { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: .9rem; }
.w-phrases { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-phrases li { display: grid; gap: 1px; padding: 6px 10px; border-radius: var(--r-sm); background: var(--paper); }
.w-ph-en { font-family: var(--serif); }
.w-essays { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.w-essays li { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); }
.w-e-main { display: grid; gap: 2px; min-width: 0; }
.w-e-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-band { font-family: var(--hand); font-size: 1.5rem; text-align: center; color: var(--muted); }
.w-band.good, .w-overall > b.good, .w-crit-s.good { color: var(--green); }
.w-band.mid, .w-overall > b.mid, .w-crit-s.mid { color: #B7791F; }
.w-band.low, .w-overall > b.low, .w-crit-s.low { color: var(--red); }

.w-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.w-main { display: grid; gap: 10px; min-width: 0; }
.w-prompt { background: var(--paper); border-left: 3px solid var(--ink); border-radius: var(--r-sm); padding: 10px 14px; }
.w-prompt p { margin: 0; font-family: var(--serif); }
.w-prompt .w-plabel { font-family: var(--sans); font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.w-prompt details { margin-top: 6px; }
.w-prompt summary { cursor: pointer; color: var(--ink); }
.w-title-in { font: inherit; font-size: 1.1rem; font-weight: 600; border: 0; border-bottom: 1px solid var(--line); padding: 6px 2px; background: transparent; color: var(--text); }
.w-title-in:focus { outline: none; border-color: var(--ink); }
.w-editor {
  width: 100%; min-height: 420px; resize: vertical; padding: 16px 18px; font-family: var(--serif); font-size: 1.02rem; line-height: 1.75;
  border: 1px solid var(--line); border-radius: var(--r-md); color: var(--text);
  background: var(--sheet) repeating-linear-gradient(transparent 0 calc(1.75em - 1px), var(--grid) calc(1.75em - 1px) 1.75em);
  background-attachment: local; background-position: 0 15px;
}
.w-editor:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); }
.w-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; font-size: .88rem; }
.w-count.ok b { color: var(--green); }
.w-meter { flex: 1 1 120px; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; min-width: 80px; }
.w-meter i { display: block; height: 100%; background: var(--ink); width: 0; transition: width .2s; }
.w-meter i.done { background: var(--green); }
#wTimer.on { border-color: var(--red); color: var(--red); }
.w-submit { align-items: center; }
.w-side { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; background: var(--sheet); }
.w-side-tabs { display: flex; width: 100%; }
.w-side-tabs button { flex: 1; }
.w-side .w-struct { padding-left: 18px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--grid-strong); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.w-rtitle { margin: 0 0 10px; font-size: 1.25rem; }
.w-score { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 14px; }
.w-overall { display: grid; align-content: center; justify-items: center; text-align: center; gap: 2px; border-right: 1px dashed var(--grid-strong); padding-right: 12px; }
.w-overall > b { font-family: var(--hand); font-size: 3.4rem; line-height: 1; }
.w-crits { display: grid; gap: 10px; }
.w-crit { display: grid; grid-template-columns: 170px 40px minmax(60px, 1fr); gap: 2px 10px; align-items: center; }
.w-crit > .small { grid-column: 1 / -1; }
.w-crit-l { font-weight: 600; font-size: .9rem; }
.w-crit-s { font-family: var(--hand); font-size: 1.35rem; text-align: right; }
.w-crit-bar { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.w-crit-bar i { display: block; height: 100%; background: var(--ink); }
.w-crit-bar i.good { background: var(--green); } .w-crit-bar i.mid { background: #D69E2E; } .w-crit-bar i.low { background: var(--red); }
.w-text { font-family: var(--serif); font-size: 1rem; line-height: 1.8; padding: 14px 18px; border: 1px solid var(--grid); border-radius: var(--r-md); background: var(--sheet); }
.w-text p { margin: 0 0 12px; }
.w-text p:last-child { margin: 0; }
.w-err { background: transparent; color: inherit; text-decoration: underline wavy var(--red); text-underline-offset: 4px; cursor: pointer; border-radius: 3px; }
.w-err:hover, .w-err:focus { background: var(--red-soft); outline: none; }
.w-err sup { color: var(--red); font-family: var(--sans); font-size: .62rem; font-weight: 700; margin-left: 1px; }
.w-pop { position: sticky; bottom: 12px; margin-top: 10px; padding: 10px 14px; background: #FFF6D6; color: #3B2F00; border-radius: var(--r-sm); box-shadow: var(--shadow); font-size: .92rem; }
.w-errlist { margin: 14px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; counter-reset: e; }
.w-errlist li { counter-increment: e; display: grid; grid-template-columns: 28px auto minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.w-errlist li::before { content: counter(e); font-weight: 700; color: var(--red); text-align: right; }
.w-errlist li:hover, .w-errlist li.on { background: var(--paper); }
.w-diff del { color: var(--red); background: var(--red-soft); text-decoration: line-through; border-radius: 3px; padding: 0 2px; }
.w-diff ins { color: var(--green); background: var(--green-soft); text-decoration: none; border-radius: 3px; padding: 0 2px; font-weight: 600; }
.w-rt-tools { align-items: center; justify-content: space-between; margin-bottom: 8px; }
.w-h3 { font-size: 1rem; margin: 22px 0 10px; }
.w-sents { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-sents li { font-family: var(--serif); font-size: .95rem; }
.w-slot:not(:empty) { margin-top: 6px; font-family: var(--sans); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.w-fb { border-radius: var(--r-md); padding: 12px 16px; }
.w-fb h4 { margin: 0 0 8px; }
.w-fb ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: .92rem; }
.w-fb.good { background: var(--green-soft); }
.w-fb.todo { background: #FFF6D6; }
.w-pfb { margin: 16px 0 0; padding-left: 22px; display: grid; gap: 12px; }
.w-pfb p { margin: 0; }
.w-pquote { font-family: var(--serif); color: var(--muted); font-size: .88rem; border-left: 2px solid var(--grid-strong); padding-left: 10px; margin-bottom: 4px !important; }
.w-up { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.w-up li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--grid); border-radius: var(--r-sm); }
.w-up li > .small { grid-column: 1; }
.w-up li > .btn { grid-row: 1 / span 2; grid-column: 2; }
.w-up s { color: var(--red); }
.w-up b { color: var(--green); font-family: var(--serif); }

@media (max-width: 960px) {
  .w-layout { grid-template-columns: minmax(0, 1fr); }
  .w-side { position: static; max-height: none; }
  .w-score { grid-template-columns: minmax(0, 1fr); }
  .w-overall { border-right: 0; border-bottom: 1px dashed var(--grid-strong); padding: 0 0 12px; }
}
@media (max-width: 640px) {
  .w-crit { grid-template-columns: minmax(0, 1fr) 40px; }
  .w-crit-bar { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .w-essays li { grid-template-columns: 44px minmax(0, 1fr); }
  .w-essays li > .row { grid-column: 1 / -1; }
  .w-editor { min-height: 320px; padding: 12px; }
  .uc-acts { margin-left: 0; }
}

/* đăng ký chờ duyệt & cảnh báo trang không an toàn */
.auth-ok { display: grid; gap: 4px; padding: 12px 14px; border-radius: var(--r-sm); background: var(--green-soft); color: var(--green); font-size: .92rem; }
.auth-ok span { color: var(--text); }
.secure-warn { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; justify-content: center; padding: 10px 16px; background: var(--red-soft); color: #7A1D18; border-bottom: 1px solid #F2C4BF; font-size: .9rem; text-align: center; }
.secure-warn .btn { text-decoration: none; }
