/* Tiếng Anh Đại học: shared styles.
   Colours: grays, text and accent come from Eric's Additional CSS (--tm-*);
   status colours and dark values come from Apple's HIG system colours. */

:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Helvetica", system-ui, "Roboto", "Segoe UI", "Arial", sans-serif;

  --page: #f5f5f7;            /* --tm-color-background-almost-white */
  --card: #fff;               /* --tm-white */
  --text: #1d1d1f;            /* --tm-color-primary-text */
  --text-2: #6e6e73;          /* --tm-color-gray-secondary-text */
  --line: #d2d2d7;            /* --tm-color-gray-border */
  --control-line: #86868b;    /* --tm-color-form-control-border */
  --fill: rgb(242, 242, 247); /* systemGray6 light */
  --fill-2: rgb(229, 229, 234); /* systemGray5 light */
  --accent: #0071e3;          /* --tm-color-accent */
  --accent-hover: #0077ed;
  --accent-active: #006edb;
  --accent-soft: rgba(0, 113, 227, 0.08);
  --on-accent: #fff;
  --good: #008932;            /* Apple green, increased contrast (text-safe on white) */
  --good-soft: rgba(52, 199, 89, 0.12);
  --bad: #e9152d;             /* Apple red, increased contrast */
  --bad-soft: rgba(255, 56, 60, 0.1);
  --warn: #c55300;            /* Apple orange, increased contrast */
  --warn-soft: rgba(255, 141, 40, 0.12);
  --glass: rgba(250, 250, 252, 0.72);
  --glass-edge: rgba(0, 0, 0, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.6);
  --scrim: rgba(0, 0, 0, 0.32);
  --focus: #0071e3;

  --r-card: 18px;
  --r-row: 12px;
  --r-chip: 8px;
  --r-dialog: 24px;

  --content: min(980px, calc(100% - 48px));
  --edge: 44px;
  --bar-h: 52px;
}
@media only screen and (max-width: 1068px) { :root { --edge: 36px; } }
@media only screen and (max-width: 734px) { :root { --content: 87.5%; --edge: 32px; } }

@media (prefers-color-scheme: dark) {
  :root {
    --page: #000;
    --card: #1c1c1e;          /* systemGray6 dark, elevated surface */
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --line: #424245;
    --control-line: #6e6e73;
    --fill: rgb(44, 44, 46);
    --fill-2: rgb(58, 58, 60);
    --accent: #2997ff;
    --accent-hover: #47a6ff;
    --accent-active: #1a8cff;
    --accent-soft: rgba(41, 151, 255, 0.16);
    --on-accent: #fff;
    --good: #30d158;
    --good-soft: rgba(48, 209, 88, 0.16);
    --bad: #ff4245;
    --bad-soft: rgba(255, 66, 69, 0.16);
    --warn: #ff9230;
    --warn-soft: rgba(255, 146, 48, 0.16);
    --glass: rgba(28, 28, 30, 0.72);
    --glass-edge: rgba(255, 255, 255, 0.12);
    --glass-highlight: rgba(255, 255, 255, 0.08);
    --scrim: rgba(0, 0, 0, 0.56);
    --focus: #2997ff;
  }
}
@media (prefers-contrast: more) {
  :root { --text-2: #424245; --line: #86868b; --glass: rgba(250, 250, 252, 0.94); --accent: #0058b0; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root { --text-2: #d2d2d7; --line: #86868b; --glass: rgba(28, 28, 30, 0.96); --accent: #5cb8ff; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: max(17px, 1rem);
  line-height: 1.4705882353;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Typography (from Eric's Additional CSS) ---------- */
.typography-headline { font-size: 48px; line-height: 1.08349; font-weight: 600; letter-spacing: -0.003em; }
.typography-headline-reduced { font-size: 40px; line-height: 1.1; font-weight: 600; letter-spacing: 0; }
.typography-eyebrow-super { font-size: 32px; line-height: 1.125; font-weight: 600; letter-spacing: 0.004em; }
.typography-eyebrow-elevated { font-size: 28px; line-height: 1.14286; font-weight: 600; letter-spacing: 0.007em; }
.typography-eyebrow-reduced { font-size: 21px; line-height: 1.19048; font-weight: 600; letter-spacing: 0.011em; }
.typography-intro { font-size: 21px; line-height: 1.381; font-weight: 400; letter-spacing: 0.011em; }
.typography-body-reduced { font-size: 14px; line-height: 1.42859; font-weight: 400; letter-spacing: -0.016em; }
.typography-caption { font-size: 12px; line-height: 1.33337; font-weight: 400; letter-spacing: -0.01em; }
@media only screen and (max-width: 1068px) {
  .typography-headline { font-size: 40px; line-height: 1.1; letter-spacing: 0; }
  .typography-headline-reduced { font-size: 32px; line-height: 1.125; letter-spacing: 0.004em; }
  .typography-eyebrow-super { font-size: 28px; line-height: 1.14286; letter-spacing: 0.007em; }
  .typography-eyebrow-elevated { font-size: 24px; line-height: 1.16667; letter-spacing: 0.009em; }
}
@media only screen and (max-width: 734px) {
  .typography-headline { font-size: 32px; line-height: 1.125; letter-spacing: 0.004em; }
  .typography-headline-reduced { font-size: 28px; line-height: 1.14286; letter-spacing: 0.007em; }
  .typography-eyebrow-super { font-size: 24px; line-height: 1.16667; letter-spacing: 0.009em; }
  .typography-eyebrow-elevated { font-size: 21px; line-height: 1.19048; letter-spacing: 0.011em; }
  .typography-eyebrow-reduced { font-size: 19px; line-height: 1.21053; letter-spacing: 0.012em; }
  .typography-intro { font-size: 19px; line-height: 1.4211; letter-spacing: 0.012em; }
}
.secondary { color: var(--text-2); }

/* ---------- Layout ---------- */
.content { width: var(--content); margin-inline: auto; }
main { padding-block: var(--edge); }
.stack-48 > * + * { margin-top: 48px; }
.stack-24 > * + * { margin-top: 24px; }
.stack-12 > * + * { margin-top: 12px; }

/* ---------- Glass bar (controls float above content) ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
}
.bar-inner { width: var(--content); margin-inline: auto; height: var(--bar-h); display: flex; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; font-size: 17px; letter-spacing: -0.022em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 24px; height: 24px; flex: none; }
.nav { margin-left: auto; display: flex; gap: 24px; }
.nav a { color: var(--text); font-size: 14px; letter-spacing: -0.016em; opacity: 0.8; }
.nav a:hover { opacity: 1; text-decoration: none; }
.nav a[aria-current="page"] { opacity: 1; font-weight: 600; }
@media (prefers-reduced-transparency: reduce) { .bar { background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; } }
@media (forced-colors: active) { .bar { -webkit-backdrop-filter: none; backdrop-filter: none; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 22px;
  border-radius: 980px; border: 1px solid transparent;
  font-size: 17px; font-weight: 400; line-height: 1.2; text-decoration: none; white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-plain { background: var(--fill); color: var(--text); }
.btn-plain:hover { background: var(--fill-2); }
.btn-plain:active { background: var(--line); }
.btn-small { min-height: 36px; padding: 6px 16px; font-size: 14px; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); }
.link-btn:hover { text-decoration: underline; }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: inline-grid; place-items: center;
  border-radius: 50%; border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--fill); }
.icon-btn:active { background: var(--fill-2); }
.icon { width: 1em; height: 1em; flex: none; }
.icon-btn .icon { width: 20px; height: 20px; }

/* ---------- Cards and rows ---------- */
.card { background: var(--card); border-radius: var(--r-card); padding: 36px; }
@media only screen and (max-width: 734px) { .card { padding: 24px; } }
.list { background: var(--card); border-radius: var(--r-card); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 18px 24px; color: var(--text); }
.list-row + .list-row { border-top: 1px solid var(--line); }
a.list-row:hover { background: var(--fill); text-decoration: none; }
a.list-row:active { background: var(--fill-2); }
.list-row .grow { flex: 1; min-width: 0; }
.chevron { color: var(--text-2); width: 14px; height: 14px; }
.chip { display: inline-block; padding: 2px 8px; border-radius: var(--r-chip); background: var(--fill); color: var(--text-2); font-size: 12px; line-height: 1.5; letter-spacing: -0.01em; white-space: nowrap; }
.chip-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Home ---------- */
.hero { text-align: center; padding-block: 48px 24px; }
.hero .typography-intro { max-width: 36em; margin: 12px auto 0; color: var(--text-2); }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 36px; }
.section-head { margin-bottom: 24px; }
.section-head p { margin-top: 12px; color: var(--text-2); max-width: 40em; }
.layout-table { width: 100%; border-collapse: collapse; }
.layout-table th, .layout-table td { text-align: left; vertical-align: top; padding: 18px 24px; }
.layout-table tr + tr th, .layout-table tr + tr td { border-top: 1px solid var(--line); }
.layout-table th { width: 7.5em; white-space: nowrap; font-weight: 600; }
.layout-table td p + p { margin-top: 4px; }
@media only screen and (max-width: 734px) {
  .layout-table th, .layout-table td { display: block; width: auto; padding: 0 24px; }
  .layout-table th { padding-top: 18px; }
  .layout-table td { padding-bottom: 18px; border-top: 0 !important; }
}
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.fact { background: var(--card); border-radius: var(--r-card); padding: 24px; }
.fact strong { display: block; font-size: 32px; line-height: 1.125; font-weight: 600; letter-spacing: 0.004em; }
@media only screen and (max-width: 734px) {
  .facts { grid-template-columns: 1fr; }
  .facts.compact { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .facts.compact .fact { padding: 18px 12px; font-size: 14px; line-height: 1.42859; letter-spacing: -0.016em; }
  .facts.compact .fact strong { font-size: 24px; line-height: 1.16667; letter-spacing: 0.009em; }
}
.empty { padding: 36px 24px; text-align: center; color: var(--text-2); }

/* ---------- Exam ---------- */
.exam-bar .bar-inner { gap: 12px; }
.exam-bar .title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.016em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exam-bar .group { display: flex; align-items: center; gap: 8px; }
@media only screen and (max-width: 734px) {
  .exam-bar .title { visibility: hidden; }
  .section-card { padding: 18px; }
  .passage { padding: 18px; }
}
.timer { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 4.2ch; text-align: right; }
.timer.low { color: var(--bad); }
.progress-btn { font-variant-numeric: tabular-nums; }

.exam-intro { max-width: 640px; margin-inline: auto; text-align: center; }
.exam-intro .facts { margin-top: 36px; text-align: left; }
.segmented { display: inline-flex; padding: 2px; border-radius: 10px; background: var(--fill); gap: 2px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; padding: 6px 18px; border-radius: 8px; font-size: 14px; letter-spacing: -0.016em; cursor: pointer; transition: background-color 0.2s ease; }
.segmented input:checked + span { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.segmented input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
.mode-note { margin-top: 12px; color: var(--text-2); font-size: 14px; letter-spacing: -0.016em; min-height: 3em; }

.section-card { background: var(--card); border-radius: var(--r-card); padding: 36px; scroll-margin-top: calc(var(--bar-h) + 24px); }
@media only screen and (max-width: 734px) { .section-card { padding: 24px; } }
.section-card + .section-card { margin-top: 24px; }
.instruction { font-size: 14px; line-height: 1.42859; letter-spacing: -0.016em; color: var(--text-2); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 36px; margin-top: 24px; align-items: start; }
.split .passage { position: sticky; top: calc(var(--bar-h) + 24px); max-height: calc(100vh - var(--bar-h) - 48px); overflow: auto; }
@media only screen and (max-width: 1068px) {
  .split { grid-template-columns: 1fr; gap: 24px; }
  .split .passage { position: static; max-height: none; overflow: visible; }
}
.passage { background: var(--fill); border-radius: var(--r-row); padding: 24px; }
.passage h3 { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
/* As on the official paper, words a question asks about are underlined and bold. */
.passage u, .q-stem u, .items u, .option u { font-weight: 600; text-underline-offset: 3px; }
.passage p + p { margin-top: 12px; }
.blank { display: inline-block; min-width: 3.2em; padding: 0 6px; border-bottom: 2px solid var(--control-line); font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; transition: background-color 0.2s ease, border-color 0.2s ease; border-radius: 4px 4px 0 0; }
.blank.filled { border-color: var(--accent); }
.blank.current { background: var(--accent-soft); border-color: var(--accent); }
.single .questions { margin-top: 24px; }

.question { border: 0; margin: 0; padding: 0; min-width: 0; scroll-margin-top: calc(var(--bar-h) + 24px); }
.question + .question { margin-top: 36px; }
.q-head { display: flex; gap: 8px; align-items: baseline; padding: 0; margin-bottom: 12px; }
.q-num { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.q-stem { flex: 1; }
.items { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.frame { margin: 0 0 6px; padding-inline: 12px; }
.items + .frame { margin: -6px 0 12px; }
.items li { background: var(--fill); border-radius: var(--r-chip); padding: 8px 12px; }
.options { display: grid; gap: 8px; }
.option {
  position: relative; display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--r-row);
  background: var(--card); cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.option:hover { border-color: var(--control-line); }
.option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.option .letter {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--control-line); font-size: 14px; font-weight: 600; letter-spacing: 0; margin-top: -2px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.option .text { flex: 1; min-width: 0; }
.option .mark { flex: none; display: none; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; letter-spacing: -0.016em; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .letter { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.locked .option { cursor: default; }
.locked .option input { cursor: default; }
.locked .option:hover { border-color: var(--line); }
.option.is-correct { border-color: var(--good); background: var(--good-soft); }
.option.is-correct .letter { background: var(--good); border-color: var(--good); color: #fff; }
.option.is-correct .mark { display: inline-flex; color: var(--good); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.is-wrong .letter { background: var(--bad); border-color: var(--bad); color: #fff; }
.option.is-wrong .mark { display: inline-flex; color: var(--bad); }

.feedback { margin-top: 12px; padding: 18px; border-radius: var(--r-row); background: var(--fill); }
.feedback .verdict { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.feedback .verdict.good { color: var(--good); }
.feedback .verdict.bad { color: var(--bad); }
.feedback .verdict.none { color: var(--text-2); }
.feedback .explain { margin-top: 6px; }
.feedback .explain p + p { margin-top: 6px; }
.feedback .changes { margin-top: 12px; padding: 12px; border-radius: var(--r-chip); background: var(--warn-soft); color: var(--text); font-size: 14px; letter-spacing: -0.016em; }
.feedback .changes strong { color: var(--warn); }
.feedback .more { margin-top: 12px; font-size: 14px; letter-spacing: -0.016em; }

.exam-footer { display: flex; justify-content: center; margin-top: 36px; }

/* ---------- Results ---------- */
.score { text-align: center; }
.score-number { font-size: 96px; line-height: 1.04167; font-weight: 600; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.score-number small { font-size: 32px; color: var(--text-2); font-weight: 600; letter-spacing: 0.004em; }
@media only screen and (max-width: 734px) { .score-number { font-size: 64px; } .score-number small { font-size: 24px; } }
.breakdown .list-row { padding-block: 14px; }
.meter { width: 96px; height: 6px; border-radius: 3px; background: var(--fill-2); overflow: hidden; flex: none; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.review-controls { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Dialogs ---------- */
dialog {
  border: 0; padding: 0; color: var(--text); background: var(--card);
  border-radius: var(--r-dialog); width: min(420px, calc(100% - 32px)); max-height: calc(100% - 64px);
  box-shadow: 0 0 0 1px var(--glass-edge), 0 24px 48px rgba(0, 0, 0, 0.18);
}
dialog::backdrop { background: var(--scrim); }
.dialog-body { padding: 24px; }
.dialog-body h2 { font-size: 21px; line-height: 1.19048; font-weight: 600; letter-spacing: 0.011em; }
.dialog-body p { margin-top: 8px; color: var(--text-2); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.dialog-actions .btn { width: 100%; }
.nav-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 18px; }
.nav-grid a {
  display: grid; place-items: center; height: 40px; border-radius: 10px; background: var(--fill);
  color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: 0;
}
.nav-grid a:hover { background: var(--fill-2); text-decoration: none; }
.nav-grid a.done { background: var(--accent); color: var(--on-accent); }
.nav-grid a.good { background: var(--good); color: #fff; }
.nav-grid a.bad { background: var(--bad); color: #fff; }
@media only screen and (max-width: 734px) { .nav-grid { grid-template-columns: repeat(5, 1fr); } }
.legend { display: flex; gap: 18px; margin-top: 18px; font-size: 12px; color: var(--text-2); letter-spacing: -0.01em; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--fill-2); }
.legend .l-done::before { background: var(--accent); }

/* ---------- Similar questions ---------- */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper .count { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 14px; letter-spacing: -0.016em; }

/* ---------- Footer ---------- */
.site-footer { padding-block: 0 var(--edge); }
.site-footer .content { border-top: 1px solid var(--line); padding-top: 18px; color: var(--text-2); font-size: 12px; line-height: 1.33337; letter-spacing: -0.01em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .bar, .site-footer, .exam-footer { display: none; }
  body { background: #fff; }
}
