/* ============================================================
   Thi thử HSK — giao diện phòng thi (exam.css)
   ============================================================ */
:root {
  --ex-red: #c84b31;
  --ex-red-soft: #fbeae5;
  --ex-navy: #2f3c7e;
  --ex-navy-soft: #e8ecf8;
  --ex-green: #1f9254;
  --ex-green-soft: #e8f7ef;
  --ex-bg: #f4f6fb;
  --ex-card: #ffffff;
  --ex-ink: #2b2420;
  --ex-mid: #6b625c;
  --ex-soft: #a39a92;
  --ex-line: #e6e3dc;
  --ex-chip: #eef0f4;
  --ex-radius: 22px;
  --ex-radius-sm: 14px;
  --ex-shadow: 0 8px 24px rgba(32, 30, 28, 0.08);
  --font-vn: 'Be Vietnam Pro', 'Segoe UI', system-ui, sans-serif;
  --font-zh: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-vn);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ex-ink);
  background: var(--ex-bg);
  -webkit-font-smoothing: antialiased;
}
.hanzi, .zh { font-family: var(--font-zh); }
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--ex-navy); }

/* ---------- Top bar ---------- */
.ex-top {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 12px; padding: 12px 24px;
  background: rgba(244, 246, 251, 0.92); backdrop-filter: blur(8px);
}
.ex-top h1 { margin: 0; font-size: 1.35rem; font-weight: 700; text-align: center; white-space: nowrap; }
.ex-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; border: none;
  background: var(--ex-card); color: var(--ex-ink); font-weight: 600; font-size: 0.95rem;
  box-shadow: var(--ex-shadow); text-decoration: none;
}
.ex-pill:hover { background: #fff8f4; }
.ex-top-right { display: flex; justify-content: flex-end; position: relative; }
.ex-menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 240px;
  background: var(--ex-card); border-radius: 18px; box-shadow: var(--ex-shadow);
  padding: 16px; z-index: 60;
}
.ex-menu h4 { margin: 0 0 10px; font-size: 1rem; }
.ex-menu label { display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; color: var(--ex-mid); margin: 8px 0; gap: 8px; }
.ex-menu input[type=range] { width: 100%; accent-color: var(--ex-navy); }
.ex-menu .chip { background: var(--ex-chip); border-radius: 8px; padding: 2px 8px; font-size: 0.8rem; font-weight: 700; color: var(--ex-ink); }

/* ---------- Layout ---------- */
.ex-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px;
  padding: 8px 24px 40px; max-width: 1480px; margin: 0 auto;
}
.ex-main { min-width: 0; }
.ex-side { position: sticky; top: 74px; align-self: start; display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 90px); }

/* ---------- Section header ---------- */
.ex-sec-head {
  display: flex; align-items: center; gap: 14px;
  background: var(--ex-navy-soft); border-radius: var(--ex-radius);
  padding: 14px 22px; margin: 0 0 18px; font-weight: 700; font-size: 1.1rem;
}
.ex-sec-icon {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ex-navy); color: #fff; flex-shrink: 0;
}
.ex-sec-icon svg { width: 22px; height: 22px; }
.ex-sec-head .ex-info { margin-left: auto; color: var(--ex-mid); display: inline-flex; }
.ex-sec-head .ex-info svg { width: 22px; height: 22px; }

/* Audio bar (ghim) */
.ex-audio {
  position: sticky; top: 66px; z-index: 40;
  background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow);
  padding: 12px 20px; margin-bottom: 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.ex-audio audio { flex: 1 1 320px; height: 40px; }
.ex-audio .ex-audio-label { font-weight: 700; font-size: 0.9rem; color: var(--ex-navy); white-space: nowrap; }
.ex-audio .ex-audio-note { flex-basis: 100%; font-size: 0.8rem; color: var(--ex-mid); margin-top: -4px; }

/* ---------- Cards ---------- */
.ex-part-intro { color: var(--ex-mid); font-size: 0.9rem; margin: 4px 4px 12px; }
.ex-card {
  background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow);
  padding: 18px 22px 22px; margin-bottom: 16px; scroll-margin-top: 130px;
}
.ex-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.ex-card-head h3 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.ex-card-head .ex-flag { margin-left: auto; color: var(--ex-soft); display: inline-flex; }
.ex-card-head .ex-flag svg { width: 22px; height: 22px; }
.ex-card.is-correct { box-shadow: 0 0 0 2px var(--ex-green) inset, var(--ex-shadow); }
.ex-card.is-wrong { box-shadow: 0 0 0 2px var(--ex-red) inset, var(--ex-shadow); }
.ex-card.is-skip { box-shadow: 0 0 0 2px #e0b400 inset, var(--ex-shadow); }

/* judge with picture */
.ex-judge { display: flex; align-items: center; gap: 24px; }
.ex-judge img { width: 200px; height: 200px; object-fit: cover; border-radius: 14px; background: #fff; border: 1px solid var(--ex-line); }
.ex-judge-btns { margin-left: auto; display: flex; flex-direction: column; gap: 12px; width: 200px; }
.ex-tf {
  height: 56px; border-radius: 14px; border: 2px solid transparent; background: var(--ex-chip);
  font-size: 1.5rem; font-weight: 800; color: var(--ex-ink); display: grid; place-items: center;
}
.ex-tf:hover { border-color: var(--ex-navy); }
.ex-tf.sel { background: var(--ex-navy-soft); border-color: var(--ex-navy); color: var(--ex-navy); }
.ex-tf.ok { background: var(--ex-green-soft); border-color: var(--ex-green); color: var(--ex-green); }
.ex-tf.bad { background: var(--ex-red-soft); border-color: var(--ex-red); color: var(--ex-red); }

/* picture grid A–F */
.ex-pics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.ex-pic { position: relative; }
.ex-pic img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 14px; border: 1px solid var(--ex-line); background: #fff; display: block; }
.ex-pic-k, .ex-opt-k {
  position: absolute; left: 0; top: 0; width: 34px; height: 34px; border-radius: 12px 0 12px 0;
  background: #6f6a66; color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 1rem;
}
.ex-example { font-size: 0.85rem; color: var(--ex-mid); margin: 0 0 12px; padding: 8px 12px; background: var(--ex-bg); border-radius: 10px; }
.ex-example .zh { font-weight: 600; color: var(--ex-ink); }

/* matching rows */
.ex-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--ex-line); }
.ex-row:first-of-type { border-top: none; }
.ex-row-n { font-weight: 700; font-size: 1.05rem; }
.ex-row-text { min-width: 0; }
.ex-letters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ex-letter {
  width: 46px; height: 46px; border-radius: 12px; border: 2px solid transparent; background: var(--ex-chip);
  font-weight: 700; font-size: 1.05rem; color: var(--ex-ink);
}
.ex-letter:hover { border-color: var(--ex-navy); }
.ex-letter.sel { background: var(--ex-navy-soft); border-color: var(--ex-navy); color: var(--ex-navy); }
.ex-letter.ok { background: var(--ex-green-soft); border-color: var(--ex-green); color: var(--ex-green); }
.ex-letter.bad { background: var(--ex-red-soft); border-color: var(--ex-red); color: var(--ex-red); }

/* pinyin + hanzi text */
.ex-text .py { font-size: 0.78rem; color: var(--ex-mid); font-family: var(--font-vn); white-space: pre-line; }
.ex-text .zh { font-size: 1.25rem; font-weight: 500; letter-spacing: 0.04em; white-space: pre-line; line-height: 1.6; }
body.py-off .ex-text .py { display: none; }

/* MC options */
.ex-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.ex-opt {
  position: relative; border-radius: 14px; border: 2px solid transparent; background: var(--ex-chip);
  padding: 18px 16px 14px 44px; text-align: center; min-height: 74px;
}
.ex-opt:hover { border-color: var(--ex-navy); }
.ex-opt.sel { background: var(--ex-navy-soft); border-color: var(--ex-navy); }
.ex-opt.sel .ex-opt-k { background: var(--ex-navy); }
.ex-opt.ok { background: var(--ex-green-soft); border-color: var(--ex-green); }
.ex-opt.ok .ex-opt-k { background: var(--ex-green); }
.ex-opt.bad { background: var(--ex-red-soft); border-color: var(--ex-red); }
.ex-opt.bad .ex-opt-k { background: var(--ex-red); }
.ex-opt .py { font-size: 0.76rem; color: var(--ex-mid); }
.ex-opt .zh { font-size: 1.2rem; font-weight: 500; }

/* word bank / sentence bank */
.ex-bank { display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 12px 16px; background: var(--ex-bg); border-radius: 14px; margin-bottom: 14px; }
.ex-bank-item { display: flex; align-items: baseline; gap: 8px; }
.ex-bank-item b { color: var(--ex-navy); }
.ex-bank-item.used { opacity: 0.45; }
.ex-bank-item .py { font-size: 0.74rem; color: var(--ex-mid); display: block; }
.ex-bank-item .zh { font-size: 1.15rem; }
.ex-bank.sent { flex-direction: column; gap: 8px; }

/* judge text */
.ex-star { margin-top: 10px; padding: 10px 14px; border-left: 4px solid var(--ex-red); background: #fff8f4; border-radius: 0 12px 12px 0; }
.ex-star .zh::before { content: '★ '; color: var(--ex-red); }
.ex-judge-text { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 20px; align-items: center; }

/* explanation after submit */
.ex-explain { margin-top: 14px; padding: 12px 16px; border-radius: 12px; background: var(--ex-bg); font-size: 0.92rem; }
.ex-explain .zh { font-size: 1.05rem; white-space: pre-line; }
.ex-explain .vn { color: var(--ex-mid); margin-top: 4px; white-space: pre-line; }
.ex-explain .ans { font-weight: 700; color: var(--ex-green); }

/* ---------- Sidebar ---------- */
.ex-timer-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--ex-navy-soft); border-radius: var(--ex-radius); padding: 12px 16px;
}
.ex-timer { font-size: 1.15rem; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.ex-timer svg { width: 20px; height: 20px; }
.ex-timer.low { color: var(--ex-red); }
.ex-btn-primary {
  background: var(--ex-navy); color: #fff; border: none; border-radius: 12px; padding: 10px 20px;
  font-weight: 700; font-size: 1rem;
}
.ex-btn-primary:hover { background: #253062; }
.ex-btn-ghost { background: var(--ex-chip); color: var(--ex-ink); border: none; border-radius: 12px; padding: 10px 20px; font-weight: 700; font-size: 1rem; }
.ex-nav { background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow); padding: 18px 20px; overflow: auto; }
.ex-nav h3 { margin: 0 0 6px; font-size: 1.1rem; padding-bottom: 8px; border-bottom: 1px solid var(--ex-line); }
.ex-nav h4 { margin: 12px 0 8px; font-size: 0.95rem; font-weight: 600; color: var(--ex-ink); }
.ex-nav-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 8px; }
.ex-dot {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid transparent; background: var(--ex-chip);
  font-weight: 600; font-size: 0.9rem; color: var(--ex-ink); display: grid; place-items: center; margin: 0 auto;
}
.ex-dot:hover { border-color: var(--ex-navy); }
.ex-dot.done { background: var(--ex-navy-soft); border-color: var(--ex-navy); color: var(--ex-navy); }
.ex-dot.ok { background: var(--ex-green-soft); border-color: var(--ex-green); color: var(--ex-green); }
.ex-dot.bad { background: var(--ex-red-soft); border-color: var(--ex-red); color: var(--ex-red); }
.ex-nav-legend { display: flex; gap: 14px; font-size: 0.78rem; color: var(--ex-mid); margin-top: 12px; flex-wrap: wrap; }
.ex-nav-legend span::before { content: ''; display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; background: var(--ex-chip); border: 2px solid transparent; }
.ex-nav-legend .l-done::before { background: var(--ex-navy-soft); border-color: var(--ex-navy); }

/* Result panel */
.ex-result { background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow); padding: 18px 20px; }
.ex-result h3 { margin: 0; font-size: 1.05rem; }
.ex-result .date { color: var(--ex-mid); font-size: 0.85rem; margin-bottom: 8px; }
.ex-ring { position: relative; width: 190px; height: 190px; margin: 6px auto 10px; }
.ex-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ex-ring circle { fill: none; stroke-width: 12; stroke-linecap: round; }
.ex-ring .track { stroke: #e9e9ec; }
.ex-ring .bar { stroke: var(--ex-red); transition: stroke-dashoffset 0.8s ease; }
.ex-ring.pass .bar { stroke: var(--ex-green); }
.ex-ring-txt { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ex-ring-txt b { font-size: 2.2rem; color: var(--ex-red); line-height: 1; }
.ex-ring.pass .ex-ring-txt b { color: var(--ex-green); }
.ex-ring-txt span { font-size: 0.8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--ex-red-soft); color: var(--ex-red); margin-top: 6px; }
.ex-ring.pass .ex-ring-txt span { background: var(--ex-green-soft); color: var(--ex-green); }
.ex-stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 8px; margin-top: 6px; }
.ex-stats small { display: block; color: var(--ex-mid); font-size: 0.8rem; }
.ex-stats b { font-size: 1.3rem; }
.ex-result-actions { display: flex; gap: 10px; margin-top: 14px; }
.ex-result-actions > * { flex: 1; text-align: center; text-decoration: none; }
.ex-breakdown { background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow); padding: 14px 20px; }
.ex-bd-sec { font-weight: 700; display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.ex-bd-row { display: grid; grid-template-columns: 120px 1fr 44px; align-items: center; gap: 10px; font-size: 0.85rem; color: var(--ex-mid); margin: 6px 0; }
.ex-bar { height: 8px; border-radius: 999px; background: #e9e9ec; overflow: hidden; }
.ex-bar i { display: block; height: 100%; background: var(--ex-navy); border-radius: 999px; }
.ex-bar.big { height: 10px; }

/* ---------- Modal ---------- */
.ex-modal-bg { position: fixed; inset: 0; background: rgba(20, 20, 28, 0.55); z-index: 100; display: grid; place-items: center; padding: 20px; }
.ex-modal { background: var(--ex-card); border-radius: 22px; padding: 26px 28px 22px; width: min(560px, 100%); box-shadow: var(--ex-shadow); }
.ex-modal h3 { margin: 0 0 6px; font-size: 1.25rem; }
.ex-modal p { margin: 0 0 20px; color: var(--ex-mid); }
.ex-modal-actions { display: flex; justify-content: flex-end; gap: 12px; }
.ex-modal-actions button { padding: 12px 28px; border-radius: 999px; font-size: 1rem; }

/* next-section bar */
.ex-next {
  display: flex; align-items: center; gap: 14px; background: var(--ex-navy-soft); border-radius: var(--ex-radius);
  padding: 12px 22px; margin: 10px 0 28px; font-weight: 700; font-size: 1.05rem;
}
.ex-next button { margin-left: auto; background: var(--ex-card); border: 1px solid var(--ex-navy); color: var(--ex-navy); border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 0.95rem; }

/* ---------- Danh sách đề ---------- */
.ex-index { max-width: 1100px; margin: 0 auto; padding: 20px 24px 60px; }
.ex-index-head { display: flex; align-items: center; gap: 14px; margin: 8px 0 22px; }
.ex-index-head h1 { margin: 0; font-size: 1.7rem; }
.ex-level { margin-bottom: 26px; }
.ex-level h2 { font-size: 1.15rem; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.ex-level h2 .tag { font-size: 0.75rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--ex-chip); color: var(--ex-mid); }
.ex-tests { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.ex-test {
  background: var(--ex-card); border-radius: var(--ex-radius); box-shadow: var(--ex-shadow); padding: 18px 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.ex-test h3 { margin: 0; font-size: 1.1rem; }
.ex-test .meta { color: var(--ex-mid); font-size: 0.88rem; }
.ex-test .last { font-size: 0.85rem; color: var(--ex-mid); }
.ex-test .last b { color: var(--ex-ink); }
.ex-test .actions { margin-top: auto; display: flex; gap: 10px; }
.ex-test .actions a { flex: 1; text-align: center; text-decoration: none; }
.ex-test.soon { opacity: 0.6; }
.ex-btn-link { display: inline-block; background: var(--ex-navy); color: #fff; border-radius: 12px; padding: 10px 16px; font-weight: 700; text-decoration: none; }
.ex-btn-link.ghost { background: var(--ex-chip); color: var(--ex-ink); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .ex-layout { grid-template-columns: 1fr; padding: 8px 12px 40px; }
  .ex-side { position: static; max-height: none; order: -1; }
  .ex-nav { max-height: 260px; }
  .ex-top { grid-template-columns: auto 1fr auto; padding: 10px 12px; }
  .ex-top h1 { font-size: 1.05rem; }
  .ex-judge { flex-wrap: wrap; }
  .ex-judge img { width: 150px; height: 150px; }
  .ex-judge-btns { width: 100%; flex-direction: row; }
  .ex-judge-btns .ex-tf { flex: 1; }
  .ex-judge-text { grid-template-columns: 1fr; }
  .ex-row { grid-template-columns: 36px minmax(0, 1fr); }
  .ex-row .ex-letters { grid-column: 1 / -1; justify-content: flex-start; }
  .ex-audio { top: 58px; }
  .ex-card { padding: 14px 14px 18px; scroll-margin-top: 150px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } .ex-ring .bar { transition: none; } }
