:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7c;
  --line: #dde3ea;
  --brand: #12395f;
  --brand-2: #1f6f8b;
  --accent: #e8a33d;
  --ok: #1d8a52;
  --bad: #c43d3d;
  --soft: #eaf2f7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,32,56,.06), 0 4px 16px rgba(16,32,56,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.55;
}
.hidden { display: none !important; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
a { color: var(--brand-2); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.logo { background: var(--accent); color: var(--brand); font-weight: 700; padding: 2px 8px; border-radius: 6px; letter-spacing: .5px; }
.steps { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.step { font-size: .82rem; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.1); color: rgba(255,255,255,.75); white-space: nowrap; }
.step.active { background: #fff; color: var(--brand); font-weight: 600; }
.step.done { background: rgba(255,255,255,.22); color: #fff; }
.step.done::before { content: '✓ '; }
.timer { font-variant-numeric: tabular-nums; background: rgba(255,255,255,.12); padding: 4px 12px; border-radius: 8px; white-space: nowrap; }
.timer.warn { background: var(--bad); }
.tlabel { font-size: .8rem; opacity: .8; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 80px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 18px; }
.narrow { max-width: 760px; margin-left: auto; margin-right: auto; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

/* ---------- buttons & form ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  padding: 10px 20px; border-radius: 10px; background: var(--brand-2); color: #fff;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #e3e9ef; color: var(--ink); }
.btn.accent { background: var(--accent); color: #1b2430; }
.btn.danger { background: var(--bad); }
.btn.big { font-size: 1.05rem; padding: 13px 26px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: .92rem; }
.field input, .field select {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.overview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.ov { background: var(--soft); border-radius: 10px; padding: 12px 14px; }
.ov b { display: block; color: var(--brand); }
@media (max-width: 760px) { .overview { grid-template-columns: 1fr 1fr; } }

.notice { background: #fff7e8; border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin: 12px 0; }
.notice.err { background: #fdeeee; border-color: var(--bad); }
.notice.ok { background: #e9f6ef; border-color: var(--ok); }

/* ---------- part tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .9rem; }
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tab .cnt { font-size: .78rem; opacity: .75; margin-left: 4px; }

/* ---------- reading split ---------- */
.split { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
.split .pane { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.split .passage { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow-y: auto; }
.split .questions { min-height: 300px; }
@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .split .passage { position: static; max-height: none; }
}
.ptitle { text-align: center; color: var(--brand); }
.ptitle small { font-size: .8em; font-weight: 500; }
.psub { text-align: center; }
.foot { font-size: .85rem; color: var(--muted); }
.pimg { display: block; max-width: 100%; margin: 10px auto 14px; border-radius: 6px; }
.pn { display: inline-block; min-width: 1.6em; font-weight: 700; color: var(--brand-2); }
.passage h4 { margin: 1em 0 .3em; color: var(--brand); }
.cols2 h4:first-child { margin-top: 0; }
.scrollx { overflow-x: auto; }

/* ---------- question blocks ---------- */
.group { margin-bottom: 26px; }
.instr { background: var(--soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: .95rem; }
.optbox { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 14px; margin-bottom: 12px; font-size: .93rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 14px; }
.optbox b { color: var(--brand); margin-right: 6px; }
.q { padding: 10px 0; border-bottom: 1px solid #eef1f4; }
.q:last-child { border-bottom: 0; }
.qn { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 6px; background: var(--brand); color: #fff; font-size: .8rem; font-weight: 700; margin-right: 8px; vertical-align: middle; }
.qtext { display: inline; }
.qline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 6px 10px; border-radius: 8px; cursor: pointer; margin: 2px 0; }
.choice:hover { background: #f3f6f9; }
.choice input { margin-top: 5px; }
.choice b { color: var(--brand); min-width: 1.1em; }
input.gap, select.gap {
  font: inherit; font-size: .95rem; padding: 5px 8px; border: 1px solid #b9c5d2; border-radius: 6px; background: #fbfdff;
  min-width: 120px;
}
input.gap:focus, select.gap:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
input.gap.wide { min-width: 220px; width: 100%; max-width: 360px; }
.inline-q { white-space: nowrap; }
.inline-q .qn { margin-right: 4px; }
table.qtable { width: 100%; border-collapse: collapse; font-size: .93rem; margin-bottom: 8px; }
table.qtable th, table.qtable td { border: 1px solid var(--line); padding: 8px 10px; vertical-align: top; text-align: left; }
table.qtable th { background: #eef3f8; }
.notes, .notes ul { margin: 0; padding-left: 1.2em; }
.notes li { margin: 6px 0; }
.sentences li { margin: 10px 0; }
.summary { background: #fafcfe; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.summary p { line-height: 2.1; }

/* ---------- listening player ---------- */
.player { display: flex; align-items: center; gap: 14px; background: var(--brand); color: #fff; padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px; flex-wrap: wrap; }
.player .btn { background: var(--accent); color: var(--brand); }
.progress { flex: 1; min-width: 160px; height: 8px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s linear; }
.plays { font-size: .9rem; opacity: .9; white-space: nowrap; }

/* ---------- writing ---------- */
.taskcards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 860px) { .taskcards { grid-template-columns: 1fr; } }
.taskcard { border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; background: #fff; cursor: pointer; display: flex; flex-direction: column; gap: 8px; transition: border-color .15s; }
.taskcard:hover { border-color: var(--brand-2); }
.taskcard .lvl { font-size: .8rem; font-weight: 600; color: var(--brand-2); text-transform: uppercase; letter-spacing: .3px; }
.taskcard .topic { font-weight: 600; }
.essay-wrap { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
@media (max-width: 900px) { .essay-wrap { grid-template-columns: 1fr; } }
textarea.essay { width: 100%; min-height: 460px; font: inherit; font-size: 1rem; line-height: 1.7; padding: 16px; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
textarea.essay:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
.prompt-box { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--brand); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.wc { font-variant-numeric: tabular-nums; font-weight: 600; }
.wc.low { color: var(--bad); }
.guide { font-size: .9rem; }
.guide li { margin: 4px 0; }

/* ---------- speaking ---------- */
.stage { text-align: center; padding: 34px 24px; }
.stage .part-label { display: inline-block; background: var(--soft); color: var(--brand); font-weight: 700; padding: 4px 12px; border-radius: 999px; font-size: .85rem; margin-bottom: 14px; }
.stage .question { font-size: 1.45rem; font-weight: 600; max-width: 760px; margin: 0 auto 18px; line-height: 1.4; }
.stage .sub { color: var(--muted); margin-bottom: 18px; }
.cuecard { text-align: left; max-width: 560px; margin: 0 auto 20px; border: 2px solid var(--brand); border-radius: 12px; padding: 18px 22px; background: #fbfdff; }
.cuecard h3 { color: var(--brand); }
.cuecard ul { margin: 6px 0; }
.recdot { display: inline-flex; align-items: center; gap: 8px; color: var(--bad); font-weight: 600; }
.recdot::before { content: ''; width: 12px; height: 12px; border-radius: 50%; background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.bigclock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); margin: 6px 0 14px; }
.meter { width: 260px; height: 10px; background: #e6ebf0; border-radius: 99px; margin: 12px auto; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--accent)); transition: width .08s; }
.notes-area { width: 100%; min-height: 110px; font: inherit; padding: 10px; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- results ---------- */
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
@media (max-width: 760px) { .result-grid { grid-template-columns: 1fr 1fr; } }
.rbox { background: var(--soft); border-radius: 10px; padding: 14px; text-align: center; }
.rbox .k { font-size: .85rem; color: var(--muted); }
.rbox .v { font-size: 1.8rem; font-weight: 700; color: var(--brand); }
.rbox .c { font-size: .85rem; font-weight: 600; }
.spinner { width: 34px; height: 34px; border: 4px solid #d6e0ea; border-top-color: var(--brand-2); border-radius: 50%; animation: spin .9s linear infinite; margin: 10px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,25,40,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 14px; max-width: 480px; width: 100%; padding: 22px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.footer-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .steps { order: 3; flex-basis: 100%; }
  .card { padding: 18px 16px; }
  .stage .question { font-size: 1.2rem; }
}
.passage table.qtable { font-size: .84rem; } .passage table.qtable td, .passage table.qtable th { padding: 6px 7px; }
