:root {
  --ink: #1b2430;
  --ink-2: #4a5566;
  --ink-3: #7b8594;
  --paper: #fbfaf7;
  --card: #ffffff;
  --line: #e4e1da;
  --navy: #1d3557;
  --navy-2: #284b78;
  --accent: #c8553d;
  --ok: #2a7d4f;
  --bad: #b3392f;
  --warn: #b7791f;
  --hl: #fff3c4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --serif: "Georgia", "Times New Roman", "Songti SC", serif;
  --sans: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.55; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 20; height: 56px; display: flex; align-items: center; gap: 16px; padding: 0 20px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand b { display: block; font-size: 14px; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; opacity: .7; }
.logo { width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--navy); display: grid; place-items: center; font-family: var(--serif); font-weight: 700; }
.stage-name { flex: 1; text-align: center; font-weight: 600; letter-spacing: .3px; }
.top-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 6px; }
.timer.low { background: var(--accent); }
.save-state { opacity: .75; font-size: 12px; }
.who { opacity: .9; }

main { min-height: calc(100vh - 56px); }
.loading { padding: 80px; text-align: center; color: var(--ink-3); }
.wrap { max-width: 860px; margin: 0 auto; padding: 40px 24px 80px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 32px; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; margin: 0 0 6px; color: var(--navy); }
h2 { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 16px; margin: 18px 0 8px; }
.muted { color: var(--ink-3); }
.lead { color: var(--ink-2); font-size: 16px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--navy); background: var(--navy); color: #fff; padding: 10px 20px; border-radius: 8px; font-weight: 600; }
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: #eef2f8; }
.btn.danger { background: var(--accent); border-color: var(--accent); }
.btn.big { padding: 14px 28px; font-size: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.field { display: block; margin: 14px 0; }
.field span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.field input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.field input:focus, textarea:focus, select:focus, .gap:focus { outline: 2px solid #9bb3d6; outline-offset: 1px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }

.plan { width: 100%; border-collapse: collapse; margin: 16px 0; }
.plan td, .plan th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.plan th { font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.notice { background: #f2f5fa; border-left: 3px solid var(--navy); padding: 12px 16px; border-radius: 6px; color: var(--ink-2); margin: 16px 0; }
.notice.warn { background: #fdf6e9; border-color: var(--warn); }
ul.tight { margin: 6px 0; padding-left: 20px; }

/* ── exam layout ── */
.exam { display: flex; flex-direction: column; height: calc(100vh - 56px); }
.subbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: #fff; padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--ink-2); }
.tab.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-left: 6px; vertical-align: middle; }
.split { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.pane { overflow: auto; padding: 24px 28px 60px; }
.pane + .pane { border-left: 1px solid var(--line); background: #fff; }
.single { flex: 1; overflow: auto; }
.single .inner { max-width: 880px; margin: 0 auto; padding: 24px 28px 80px; }

.passage h2 { margin-bottom: 4px; }
.passage p { font-family: var(--serif); font-size: 16.5px; line-height: 1.75; margin: 0 0 14px; }
.passage .pl { font-family: var(--sans); font-weight: 700; color: var(--navy); margin-right: 8px; }
mark.u { background: var(--hl); }

.group { margin: 0 0 28px; }
.group .gh { font-weight: 700; color: var(--navy); font-size: 14px; margin-bottom: 4px; }
.group .gi { font-size: 14px; color: var(--ink-2); margin-bottom: 12px; font-style: italic; }
.q { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed #efece6; }
.qn { flex: none; min-width: 28px; height: 24px; border-radius: 5px; background: #eef1f6; color: var(--navy); font-weight: 700; font-size: 13px; display: grid; place-items: center; margin-top: 1px; }
.q.answered .qn { background: var(--navy); color: #fff; }
.qbody { flex: 1; }
.opts { display: grid; gap: 4px; margin-top: 6px; }
.opt { display: flex; gap: 8px; align-items: flex-start; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.opt:hover { background: #f4f6fa; }
.opt input { margin-top: 4px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 8px 0 14px; background: #fcfcfb; font-size: 14px; }
.box div { padding: 2px 0; }
select.pick { padding: 4px 8px; border: 1px solid #b9c3d3; border-radius: 6px; background: #fff; min-width: 90px; }
.gap { display: inline-block; width: 150px; padding: 2px 6px; border: none; border-bottom: 2px solid #9aa7bb; background: #f6f8fb; border-radius: 3px 3px 0 0; }
.gapn { font-weight: 700; color: var(--navy); font-size: 12px; margin-right: 3px; }
.form-lines { border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; background: #fff; }
.form-lines .fl { padding: 7px 0; border-bottom: 1px dotted #ebe7df; }
.form-lines .fl:last-child { border-bottom: none; }
.form-title { font-weight: 700; text-align: center; margin-bottom: 8px; color: var(--navy); }
.summary-text { font-family: var(--serif); font-size: 16px; line-height: 2.1; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; }

.navbar { display: flex; gap: 4px; padding: 8px 12px; background: #fff; border-top: 1px solid var(--line); overflow-x: auto; align-items: center; }
.navbar .nb { flex: none; width: 30px; height: 28px; border: 1px solid var(--line); border-radius: 5px; background: #fff; font-size: 12px; color: var(--ink-2); }
.navbar .nb.done { background: var(--navy); color: #fff; border-color: var(--navy); }
.navbar .sep { width: 10px; flex: none; }

/* listening player */
.player { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: #f2f5fa; border-bottom: 1px solid var(--line); }
.player .pi { font-size: 13px; color: var(--ink-2); flex: 1; }
.player .bar { height: 6px; background: #dde3ec; border-radius: 3px; overflow: hidden; flex: 2; }
.player .bar i { display: block; height: 100%; background: var(--navy); width: 0; transition: width .5s linear; }
.vol { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }

/* writing */
.task-prompt { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; margin-bottom: 14px; }
.task-prompt p { margin: 0 0 8px; }
textarea.essay { width: 100%; min-height: 55vh; resize: vertical; padding: 14px 16px; border: 1px solid #c9d1dd; border-radius: 8px; font-family: var(--serif); font-size: 16px; line-height: 1.7; background: #fff; }
.wc { font-size: 13px; color: var(--ink-3); margin-top: 6px; text-align: right; }
.wc.short { color: var(--warn); }
.chart { width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* speaking */
.speak-stage { text-align: center; padding: 24px 0; }
.examiner { display: inline-flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: 999px; background: #eef2f8; color: var(--navy); font-weight: 600; }
.examiner .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--navy); }
.examiner.talking .pulse { animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(29,53,87,.5);} 100% { box-shadow: 0 0 0 12px rgba(29,53,87,0);} }
.qtext { font-family: var(--serif); font-size: 21px; color: var(--ink); max-width: 640px; margin: 22px auto; line-height: 1.5; }
.rec-btn { width: 96px; height: 96px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; box-shadow: 0 6px 18px rgba(200,85,61,.35); }
.rec-btn.on { background: var(--bad); animation: recpulse 1.2s infinite; }
@keyframes recpulse { 0% { box-shadow: 0 0 0 0 rgba(179,57,47,.5);} 100% { box-shadow: 0 0 0 18px rgba(179,57,47,0);} }
.rec-time { font-variant-numeric: tabular-nums; font-size: 22px; margin-top: 12px; font-weight: 700; }
.meter { width: 220px; height: 8px; background: #e7e3dc; border-radius: 4px; margin: 12px auto; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .08s; }
.cue { text-align: left; max-width: 520px; margin: 16px auto; background: #fffdf5; border: 1px solid #eadfba; border-radius: 10px; padding: 18px 22px; font-family: var(--serif); font-size: 17px; }
.cue ul { margin: 6px 0; }
.notes { width: 100%; max-width: 520px; min-height: 110px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.steps { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.steps i { width: 26px; height: 6px; border-radius: 3px; background: #e2ded6; }
.steps i.done { background: var(--navy); }
.steps i.cur { background: var(--accent); }

/* result */
.bands { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 20px 0; }
.band { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px; text-align: center; }
.band b { display: block; font-family: var(--serif); font-size: 34px; color: var(--navy); line-height: 1.1; }
.band small { color: var(--ink-3); }
.overall { text-align: center; padding: 24px; background: var(--navy); color: #fff; border-radius: 12px; }
.overall b { font-family: var(--serif); font-size: 56px; display: block; line-height: 1; }
.fb { margin: 18px 0; }
.fb h3 { color: var(--navy); }
.crit { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.crit span { background: #eef2f8; color: var(--navy); border-radius: 6px; padding: 3px 9px; font-size: 13px; }
.corr { font-size: 14px; border-left: 3px solid var(--line); padding: 4px 10px; margin: 6px 0; }
.corr s { color: var(--bad); }
.corr ins { color: var(--ok); text-decoration: none; font-weight: 600; }
.grid40 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.grid40 span { text-align: center; font-size: 12px; padding: 4px 0; border-radius: 4px; }
.grid40 .y { background: #e3f1e8; color: var(--ok); }
.grid40 .n { background: #f8e4e2; color: var(--bad); }
.spinner { width: 42px; height: 42px; border: 4px solid #dde3ec; border-top-color: var(--navy); border-radius: 50%; animation: spin 1s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; background: rgba(20,28,40,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; max-width: 480px; width: 100%; padding: 24px; box-shadow: var(--shadow); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .pane + .pane { border-left: none; border-top: 1px solid var(--line); }
  .exam { height: auto; }
  .bands { grid-template-columns: repeat(2, 1fr); }
  .stage-name { display: none; }
  .brand small { display: none; }
}
@media print { .topbar, .navbar, .subbar { display: none; } }

.lang-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; overflow: hidden; }
.lang-switch button { background: transparent; color: #fff; border: none; padding: 3px 10px; font-size: 12px; opacity: .75; }
.lang-switch button.on { background: #fff; color: var(--navy); opacity: 1; font-weight: 600; }
.lang-switch button { white-space: nowrap; }
@media (max-width: 900px) { .save-state { display: none; } .topbar { gap: 8px; padding: 0 10px; } }
@media (max-width: 900px) { .player { flex-wrap: wrap; } .player .bar { flex-basis: 100%; order: 3; } }
