:root {
  --desk: #e7ecf1;
  --paper: #ffffff;
  --ink: #172033;
  --ink-2: #44506a;
  --muted: #6b778c;
  --rule: #d3dfeb;
  --line: #dbe2ea;
  --navy: #1d3a6e;
  --navy-soft: #e6edf7;
  --red: #c1121f;
  --red-soft: #fbe7e8;
  --green: #1f7a4d;
  --green-soft: #e4f3ea;
  --amber: #9a5b00;
  --amber-soft: #fdf1dc;
  --sans: 'Be Vietnam Pro', system-ui, sans-serif;
  --text: 'Literata', Georgia, serif;
  --pen: 'Patrick Hand', 'Comic Sans MS', cursive;
  --sheet-lh: 34px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--desk); color: var(--ink); font: 15px/1.6 var(--sans); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* thanh trên */
.top { background: var(--ink); color: #fff; }
.top-in { max-width: 1240px; margin: 0 auto; padding: 0 20px; display: flex; align-items: stretch; gap: 28px; min-height: 52px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .mark { font: 22px/1 var(--pen); color: #ff8a92; transform: rotate(-6deg); }
.nav { display: flex; gap: 2px; overflow-x: auto; }
.nav a { display: flex; align-items: center; padding: 0 14px; color: #b9c3d6; text-decoration: none; font-weight: 500; border-bottom: 3px solid transparent; white-space: nowrap; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: #ff8a92; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 20px 96px; }

h1 { font: 600 28px/1.2 var(--text); margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font: 600 18px/1.3 var(--sans); margin: 0 0 10px; }
.lead { color: var(--ink-2); margin: 0 0 24px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; align-items: start; }
.panel { background: var(--paper); border-radius: 6px; padding: 20px 22px; box-shadow: 0 1px 0 #cfd7e0; }
.panel + .panel { margin-top: 16px; }
.section { margin-top: 28px; }

/* nút + ô nhập */
.btn { text-decoration: none; display: inline-block; color: var(--ink); border: 1px solid #c5cfdb; background: var(--paper); padding: 8px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--navy); color: var(--navy); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: #142b54; color: #fff; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.quiet { border-color: transparent; background: none; color: var(--muted); font-weight: 500; }
.btn.quiet:hover { color: var(--red); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.mic.on { background: var(--red); border-color: var(--red); color: #fff; }
.tabs { display: inline-flex; background: #d8e0e9; border-radius: 7px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 5px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.tabs button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(23,32,51,.15); }
input[type=text], input[type=password], textarea, select { width: 100%; border: 1px solid #c5cfdb; border-radius: 6px; padding: 9px 12px; background: #fff; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-soft); }
label.f { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; color: var(--ink-2); }

/* đề bài: in như đề thi */
.question { background: var(--paper); border: 1.5px solid var(--ink); padding: 18px 22px; position: relative; }
.question .qhead { display: flex; gap: 12px; align-items: baseline; border-bottom: 1px solid var(--ink); padding-bottom: 8px; margin-bottom: 12px; }
.question .qhead b { font: 700 15px var(--sans); }
.question .qtext { font: 16px/1.65 var(--text); white-space: pre-wrap; }
.question table { border-collapse: collapse; margin: 12px 0 4px; font: 14px var(--sans); }
.question caption { text-align: left; font-weight: 700; padding: 2px 0 6px; }
.question td { border: 1px solid #9aa6b8; padding: 4px 10px; font-variant-numeric: tabular-nums; }
.question tr:first-child td { background: #eef2f6; font-weight: 600; }
.question textarea { font: 15px/1.6 var(--text); min-height: 140px; }

/* tờ giấy làm bài */
.sheet {
  background-color: var(--paper);
  background-image: linear-gradient(to right, transparent 54px, #efb3b8 54px, #efb3b8 55.5px, transparent 55.5px),
                    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--sheet-lh) - 1px), var(--rule) calc(var(--sheet-lh) - 1px), var(--rule) var(--sheet-lh));
  background-position: 0 0, 0 18px;
  padding: 18px 28px 40px 74px;
  box-shadow: 0 1px 0 #cfd7e0, 0 10px 30px -18px rgba(23,32,51,.35);
  min-height: 520px;
  position: relative;
}
.sheet textarea, .sheet .essay {
  display: block; width: 100%; border: 0; outline: none; box-shadow: none; background: transparent; padding: 0; resize: none;
  font: 17px/var(--sheet-lh) var(--text); color: var(--ink); white-space: pre-wrap; word-wrap: break-word; min-height: 480px;
}
.sheet textarea:focus { box-shadow: none; }
.sheet-foot { display: flex; gap: 18px; align-items: center; padding: 10px 2px; color: var(--muted); font-size: 13px; }
.sheet-foot b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sheet-foot .warn { color: var(--amber); }
.sheet-foot .over { color: var(--red); }

/* bút đỏ giám khảo */
mark.err { background: none; color: inherit; text-decoration: underline wavy var(--red); text-decoration-thickness: 1.5px; text-underline-offset: 5px; cursor: pointer; }
mark.err.on { background: var(--red-soft); }
sup.pen { font: 15px/1 var(--pen); color: var(--red); margin-left: 1px; cursor: pointer; }
.margin-notes { list-style: none; margin: 0; padding: 0; }
.margin-notes li { padding: 10px 0 12px; border-bottom: 1px dashed #d6dbe2; cursor: pointer; }
.margin-notes li.on { background: var(--red-soft); margin: 0 -10px; padding-left: 10px; padding-right: 10px; }
.margin-notes .no { font: 18px/1 var(--pen); color: var(--red); margin-right: 6px; }
.margin-notes .fix { font: 20px/1.25 var(--pen); color: var(--red); }
.margin-notes .was { color: var(--muted); text-decoration: line-through; font: 14px var(--text); }
.margin-notes .why { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; }
.tag { display: inline-block; font-size: 11.5px; padding: 0 7px; border-radius: 3px; background: var(--navy-soft); color: var(--navy); font-weight: 600; }

/* ô điểm như phiếu chấm */
.scorebox { display: inline-grid; grid-auto-flow: column; border: 1.5px solid var(--ink); background: var(--paper); }
.scorebox > div { padding: 6px 16px 8px; border-left: 1px solid var(--ink); text-align: center; min-width: 78px; }
.scorebox > div:first-child { border-left: 0; }
.scorebox .k { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.scorebox .v { font: 34px/1.05 var(--pen); color: var(--red); }
.scorebox .all { background: var(--ink); color: #fff; min-width: 104px; }
.scorebox .all .k { color: #c7cfdd; }
.scorebox .all .v { color: #ff8a92; font-size: 44px; }

.crit { padding: 12px 0; border-top: 1px solid var(--line); }
.crit:first-child { border-top: 0; padding-top: 0; }
.crit .h { display: flex; gap: 10px; align-items: baseline; }
.crit .h b { font-size: 14px; }
.crit .h .b { font: 22px/1 var(--pen); color: var(--red); }
ul.plain { margin: 0; padding-left: 18px; } ul.plain li + li { margin-top: 5px; }
.rewrite { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.rewrite > div { font: 15.5px/1.7 var(--text); padding: 14px 16px; border-radius: 4px; white-space: pre-wrap; }
.rewrite .before { background: #f1f4f7; color: var(--ink-2); }
.rewrite .after { background: var(--green-soft); }
.vocab td { padding: 8px 10px 8px 0; vertical-align: top; border-bottom: 1px solid var(--line); }
.vocab td:first-child { font-weight: 700; white-space: nowrap; }
.vocab em { font-family: var(--text); color: var(--ink-2); }

/* chat */
.chat { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 10px; position: relative; }
.msg.me { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 3px; white-space: pre-wrap; }
.msg.ai { align-self: flex-start; background: var(--paper); border-bottom-left-radius: 3px; box-shadow: 0 1px 0 #cfd7e0; }
.msg.ai p { margin: 0 0 8px; } .msg.ai p:last-child { margin-bottom: 0; }
.msg.ai ul, .msg.ai ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.ai em { color: var(--ink-2); }
.msg .say { position: absolute; right: -34px; bottom: 2px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; }
.msg .say:hover { color: var(--navy); }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 14px; position: sticky; bottom: 12px; background: var(--desk); padding: 8px 0; }
.composer textarea { min-height: 48px; max-height: 180px; resize: vertical; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 2px; }
.chip { border: 1px solid #c5cfdb; background: var(--paper); border-radius: 99px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.chip:hover { border-color: var(--navy); color: var(--navy); }
.typing { color: var(--muted); font-style: italic; }

/* phòng thi nói */
.room { background: var(--ink); color: #fff; border-radius: 8px; padding: 28px; min-height: 360px; display: flex; flex-direction: column; gap: 18px; }
.room .part { color: #9fb0cc; font-weight: 600; font-size: 13px; }
.room .ask { font: 24px/1.4 var(--text); max-width: 46ch; }
.room .cue { background: #fff; color: var(--ink); padding: 16px 20px; border-radius: 4px; max-width: 560px; }
.room .cue b { font: 600 18px var(--text); display: block; margin-bottom: 8px; }
.room .live { font: 16px/1.6 var(--text); color: #e7ecf5; min-height: 60px; border-left: 3px solid #ff8a92; padding-left: 12px; white-space: pre-wrap; }
.room .live i { color: #8fa0bb; }
.room .clock { font: 40px/1 var(--pen); color: #ff8a92; font-variant-numeric: tabular-nums; }
.room textarea { background: #22304b; border-color: #3a4a69; color: #fff; }
.room .btn { background: #22304b; border-color: #3a4a69; color: #fff; }
.room .btn.primary { background: #fff; color: var(--ink); border-color: #fff; }
.room .btn.red { background: var(--red); border-color: var(--red); }
.steps { display: flex; gap: 6px; }
.steps i { width: 26px; height: 4px; border-radius: 2px; background: #3a4a69; }
.steps i.done { background: #ff8a92; }

/* luyện */
.drill li { padding: 14px 0; border-bottom: 1px solid var(--line); list-style: none; }
.drill ol { margin: 0; padding: 0; }
.drill .s { font: 16px/1.6 var(--text); margin-bottom: 6px; }
.drill .res { margin-top: 6px; font-size: 14px; }
.ok { color: var(--green); font-weight: 700; } .no { color: var(--red); font-weight: 700; }

/* tiến bộ */
table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: 12.5px; color: var(--muted); font-weight: 600; }
table.list tr.go { cursor: pointer; } table.list tr.go:hover td { background: #f5f8fb; }
.num, table.list .num { font-variant-numeric: tabular-nums; text-align: right; }
.bandcell { font: 20px/1 var(--pen); color: var(--red); }
.bar { height: 8px; background: #e3e9ef; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--red); }
svg.chart text { font: 11px var(--sans); fill: var(--muted); }

/* khác */
.empty { padding: 28px; text-align: center; color: var(--muted); }
.notice { background: var(--amber-soft); color: #5e3800; padding: 10px 14px; border-radius: 6px; font-size: 14px; }
.wait { display: flex; gap: 12px; align-items: center; color: var(--ink-2); padding: 18px 0; }
.spin { width: 18px; height: 18px; border: 2px solid #c5cfdb; border-top-color: var(--red); border-radius: 50%; animation: s .8s linear infinite; flex: none; }
@keyframes s { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 6px; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--red); }

@media (max-width: 900px) {
  .cols, .rewrite { grid-template-columns: 1fr; }
  .top-in { gap: 12px; }
  .brand span:last-child { display: none; }
  .sheet { padding-left: 64px; padding-right: 16px; }
  .sheet { background-image: linear-gradient(to right, transparent 46px, #efb3b8 46px, #efb3b8 47.5px, transparent 47.5px), repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--sheet-lh) - 1px), var(--rule) calc(var(--sheet-lh) - 1px), var(--rule) var(--sheet-lh)); padding-left: 58px; }
  .scorebox > div { padding: 6px 10px; min-width: 58px; }
  .msg .say { position: static; display: block; margin-top: 4px; }
  .msg { max-width: 96%; }
}
