:root {
  --blue: #2e75b6;
  --blue-d: #1f4e79;
  --bg: #eef4fb;
  --card: #ffffff;
  --green: #2e8b57;
  --red: #d64545;
  --amber: #e0a020;
  --line: #d6e4f7;
  --text: #1a2433;
  --muted: #6b7a90;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; box-shadow: 0 2px 6px rgba(0,0,0,.15);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-weight: 700; font-size: 19px; display: flex; gap: 8px; align-items: center; }
.topbar .who { font-size: 14px; display: flex; gap: 14px; align-items: center; }
.topbar button {
  background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.4);
  padding: 6px 12px; border-radius: 8px; font-size: 13px;
}
.container { max-width: 980px; margin: 0 auto; padding: 22px 18px 60px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { color: var(--blue); cursor: pointer; text-decoration: none; }
h1 { font-size: 24px; margin: 6px 0 18px; }
h2 { font-size: 19px; margin: 0 0 12px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); padding: 34px 30px; border-radius: 16px;
  box-shadow: 0 12px 30px rgba(31,78,121,.18); width: 340px; text-align: center;
}
.login-card .logo { font-size: 40px; }
.login-card h1 { font-size: 22px; margin: 8px 0 2px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
input[type=text], input[type=password] {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 9px; font-size: 15px; margin-bottom: 12px;
}
.btn {
  background: var(--blue); color: #fff; border: none; padding: 11px 16px;
  border-radius: 9px; font-size: 15px; font-weight: 600; width: 100%;
}
.btn:hover { background: var(--blue-d); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 14px; }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.amber { background: var(--amber); }
.btn.ai { background: linear-gradient(135deg,#8b5cf6,#6a30b8); }
.btn.ai:hover { background: linear-gradient(135deg,#7c3aed,#5a20a8); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.err { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* ---------- dashboard cards ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill,minmax(210px,1fr)); gap: 16px; }
.tile {
  background: var(--card); border-radius: 14px; padding: 20px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(31,78,121,.08); border: 1px solid var(--line);
  transition: transform .12s, box-shadow .12s; position: relative;
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(31,78,121,.16); }
.tile .ico { font-size: 34px; }
.tile h3 { margin: 10px 0 4px; font-size: 17px; }
.tile p { margin: 0; color: var(--muted); font-size: 13px; }
.badge {
  position: absolute; top: 12px; right: 12px; background: var(--red); color: #fff;
  border-radius: 20px; padding: 2px 9px; font-size: 12px; font-weight: 700;
}

/* ---------- selection lists ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.sticky-toolbar {
  position: sticky; top: 56px; z-index: 5;
  background: var(--bg); padding: 10px 0; box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.toolbar .ncount { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.toolbar .ncount input[type=number] {
  width: 64px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin: 0; font-size: 14px;
}
.checks { display: grid; grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); gap: 8px; }
.check {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; cursor: pointer; background: #fbfdff; font-size: 14px;
}
.check:hover { background: #f0f6fd; }
.check input { width: 17px; height: 17px; }
.check .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.part-title { margin: 16px 0 8px; font-weight: 700; color: var(--blue-d); font-size: 14px; }

/* ---------- flashcards ---------- */
.fc-stage { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.flashcard {
  width: 100%; max-width: 520px; height: 280px; perspective: 1200px; cursor: pointer;
}
.fc-inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-face {
  position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
  border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; box-shadow: 0 8px 22px rgba(31,78,121,.16);
}
.fc-front { background: linear-gradient(135deg,#3a86c8,#1f4e79); color: #fff; }
.fc-front .word { font-size: 40px; font-weight: 700; }
.fc-front .pos { margin-top: 8px; opacity: .85; font-style: italic; }
.fc-front .hint { margin-top: 22px; font-size: 13px; opacity: .8; }
.fc-back { background: #fff; color: var(--text); transform: rotateY(180deg); border: 2px solid var(--blue); }
.fc-back .meaning { font-size: 26px; font-weight: 700; color: var(--blue-d); }
.fc-back .related { margin-top: 6px; color: var(--muted); font-size: 14px; }
.fc-back .ex { margin-top: 18px; font-style: italic; }
.fc-back .ex .en { color: #333; }
.fc-nav { display: flex; gap: 12px; align-items: center; }
.fc-counter { font-size: 14px; color: var(--muted); min-width: 80px; text-align: center; }

/* ---------- theory ---------- */
.theory-sec { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
.theory-sec .code { color: var(--blue); font-weight: 700; }
.theory-sec h3 { margin: 4px 0 14px; }
.block { margin-bottom: 12px; }
.block .label { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.block.when .label { color: var(--green); }
.block.formula .label { color: var(--blue); }
.block.note .label { color: var(--amber); }
.block .content { white-space: pre-wrap; line-height: 1.55; }
.ex-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.ex-table td { border: 1px solid var(--line); padding: 7px 10px; font-size: 14px; vertical-align: top; }
.ex-table td.en { font-weight: 600; }
.ex-table td.vi { color: var(--muted); }

/* ---------- quiz ---------- */
.qcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 14px; }
.qcard .qnum { color: var(--muted); font-size: 13px; }
.qcard .prompt { font-size: 17px; font-weight: 600; margin: 4px 0 6px; }
.qcard .sub { white-space: pre-wrap; color: #333; background: #f6faff; border-left: 3px solid var(--blue); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.opts { display: grid; gap: 9px; }
.opt {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line); border-radius: 9px; padding: 11px 14px; cursor: pointer;
  background: #fff; font-size: 15px; text-align: left;
}
.opt input[type=radio] { width: 18px; height: 18px; accent-color: var(--blue); cursor: pointer; flex: none; }
.opt:hover { border-color: var(--blue); background: #f4f9ff; }
.opt.sel { border-color: var(--blue); background: #e3f0fd; font-weight: 600; }
.opt.correct { border-color: var(--green); background: #e7f6ec; }
.opt.wrong { border-color: var(--red); background: #fbe9e9; }
.explanation { margin-top: 8px; padding: 8px 12px; background: #fff8e1; border-left: 3px solid var(--amber); border-radius: 6px; font-size: 14px; color: #5a4a1a; }
.wrong-review { border-left: 4px solid var(--red); }
.tokens { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.token { background: #e3f0fd; border: 1px solid var(--blue); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.token.used { opacity: .35; pointer-events: none; }
.answer-line { min-height: 44px; border: 1.5px dashed var(--blue); border-radius: 9px; padding: 8px 12px; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.answer-line .token { background: var(--blue); color: #fff; }
.verdict { font-weight: 700; margin-top: 8px; }
.verdict.ok { color: var(--green); }
.verdict.no { color: var(--red); }
.solution { font-size: 14px; color: var(--blue-d); margin-top: 4px; }

/* ---------- result ---------- */
.score-big { font-size: 46px; font-weight: 800; color: var(--blue-d); }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(150px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; }
.stat-box .num { font-size: 30px; font-weight: 800; color: var(--blue-d); }
.stat-box .lbl { color: var(--muted); font-size: 13px; margin-top: 4px; }
table.data { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; font-size: 14px; }
table.data th { background: #f0f6fd; color: var(--blue-d); }
.pill { display: inline-block; background: var(--red); color: #fff; border-radius: 12px; padding: 1px 8px; font-size: 12px; }
.pill.gray { background: var(--muted); }
.muted { color: var(--muted); }
.chip { display: inline-block; border-radius: 11px; padding: 1px 8px; font-size: 11px; font-weight: 700; vertical-align: middle; }
.chip.new { background: #e6e9ef; color: #5a6677; }
.chip.weak { background: #fdeccf; color: #9a6b08; }
.chip.solid { background: #d8f0e0; color: #1d7a45; }
.chip.ai { background: #e7defb; color: #6a30b8; }

/* ---------- reading ---------- */
.passage-card { background: #fffef7; border: 1px solid #ecdfa6; border-left: 4px solid var(--amber); border-radius: 12px; padding: 16px 20px; margin-bottom: 14px; }
.passage-title { font-weight: 700; color: var(--blue-d); margin-bottom: 8px; }
.passage-text { line-height: 1.7; font-size: 15.5px; white-space: pre-wrap; }
.passage-vi { margin-top: 10px; padding: 10px 12px; background: #f6faff; border-radius: 8px; color: var(--muted); line-height: 1.6; }
.row-actions { display: flex; gap: 6px; }
.center { text-align: center; }
.mt { margin-top: 16px; }

/* ---------- tablet (768-1024px, iPad chan dung/ngang) ---------- */
@media (max-width: 1024px) {
  .container { padding: 18px 14px 50px; max-width: 100%; }
  .checks { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .toolbar { gap: 8px; }
  .sticky-toolbar { top: 52px; padding: 8px 0; }
  .qcard { padding: 15px 16px; }
  .opt { padding: 12px 14px; font-size: 15.5px; }
  .fc-stage .flashcard { max-width: 100%; height: 240px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); }
  table.data { display: block; overflow-x: auto; white-space: nowrap; }
}
