/*
 * File:        css/style.css
 * Description: Giao diện website test IQ/EQ: token màu sáng/tối, bố cục responsive, in kết quả
 *
 * Change history:
 * 2026-11-16 | ManhNV | IQEQ-1 | Tạo mới: token, trang chủ, bài làm (đếm ngược, câu hình), kết quả, chế độ tối, bản in
 */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f7;
  --text: #1c2033;
  --muted: #5b6178;
  --border: #dde1ec;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --primary-soft: #e8e7fd;
  --iq: #4f46e5;
  --eq: #0f9d7a;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --strong: #15803d;
  --moderate: #b45309;
  --develop: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 45, .06), 0 4px 16px rgba(20, 24, 45, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c;
    --surface: #1a1d2a;
    --surface-2: #242838;
    --text: #e8eaf3;
    --muted: #a0a6bd;
    --border: #2f3448;
    --primary: #8b85ff;
    --primary-text: #11131c;
    --primary-soft: #2a2950;
    --iq: #8b85ff;
    --eq: #3ccfa6;
    --ok: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --strong: #4ade80;
    --moderate: #fbbf24;
    --develop: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
h2 { font-size: 1.25rem; }
p { margin: 0 0 .75em; }

a { color: var(--primary); }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip-link:focus { left: 16px; }

.container { width: 100%; max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
.container:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: .9rem; }

/* ---------- header / footer ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 880px; width: 100%; margin: 0 auto; padding: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand-mark { color: var(--primary); }
.lang { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.lang-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .85rem;
  padding: 6px 14px; border-radius: 999px; cursor: pointer; min-height: 36px;
}
.lang-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.site-footer { max-width: 880px; width: 100%; margin: 0 auto; padding: 16px 16px 32px; font-size: .85rem; color: var(--muted); border-top: 1px solid var(--border); }

/* ---------- chung ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; min-height: 44px; padding: 10px 18px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: .85rem; }

.alert { background: var(--warn-soft); color: var(--text); border-left: 4px solid var(--warn); padding: 10px 14px; border-radius: 8px; }
.alert[hidden] { display: none; }

.lead { font-size: 1.08rem; color: var(--muted); }

/* ---------- trang chủ ---------- */
.hero { padding: 16px 0 24px; }
.features { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.features li { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.check { color: var(--ok); font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.test-card { display: flex; flex-direction: column; border-top: 4px solid var(--iq); }
.test-card.test-eq { border-top-color: var(--eq); }
.test-card .btn { margin-top: auto; align-self: flex-start; }
.test-eq .btn-primary { background: var(--eq); border-color: var(--eq); }
.card-tag { font-weight: 800; font-size: .8rem; letter-spacing: .08em; color: var(--iq); margin-bottom: 6px; }
.test-eq .card-tag { color: var(--eq); }
.meta { color: var(--muted); font-size: .9rem; }
.last ul { margin: 0; padding-left: 20px; }

/* ---------- bài làm ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.quiz-top.sticky { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; }
.timer-wrap { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.timer.warn { color: var(--bad); }

.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress-bar { height: 100%; background: var(--primary); transition: width .2s ease; }

fieldset { margin: 0; min-width: 0; }
.question { padding: 24px; }
.question legend { float: left; width: 100%; padding: 0; margin-bottom: 8px; }
.question legend + * { clear: both; }
.q-count { color: var(--muted); font-size: .9rem; font-weight: 600; }
.q-text { font-size: 1.2rem; font-weight: 600; clear: both; overflow-wrap: anywhere; }

.options { display: grid; gap: 10px; margin-top: 12px; }
.option {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 48px;
  border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--surface);
}
.option:hover { border-color: var(--primary); }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option-key {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 700; font-size: .85rem;
}
.option-text { font-size: 1.05rem; }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.option:has(input:checked) .option-key { background: var(--primary); color: var(--primary-text); }
.option:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

.quiz-nav { display: flex; justify-content: space-between; gap: 12px; margin: 16px 0; }
.quiz-nav.end { justify-content: flex-end; }

.dots { display: flex; flex-wrap: wrap; gap: 6px; }
.dot {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.dot.done { background: var(--primary-soft); color: var(--primary); border-color: transparent; font-weight: 600; }
.dot.current { border: 2px solid var(--primary); color: var(--text); }

/* Đếm ngược từng câu */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.countdown { position: relative; width: 48px; height: 48px; flex: none; }
.ring { display: block; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--primary); transition: stroke-dashoffset .2s linear; }
.ring-num { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.countdown.warn .ring-fg { stroke: var(--bad); }
.countdown.warn .ring-num { color: var(--bad); }
@media (prefers-reduced-motion: reduce) { .ring-fg { transition: none; } }

/* Câu hình */
.fig { display: block; max-width: 100%; height: auto; color: var(--text); }
.q-figure { display: block; margin: 4px 0 8px; overflow-x: auto; }
.q-figure .fig { max-width: 100%; }
.fig-options { grid-template-columns: repeat(4, 1fr); }
.fig-options .option { flex-direction: column; justify-content: center; padding: 10px 6px; }
.fig-wrap { display: inline-flex; }
.fig-wrap .fig { width: 60px; height: 60px; }
.option.locked { cursor: not-allowed; opacity: .7; }
.option.locked:hover { border-color: var(--border); }
.dot.locked { text-decoration: line-through; opacity: .6; }
.small-fig .fig { max-height: 70px; width: auto; }
.review-ans { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.review-ans .fig-wrap .fig { width: 40px; height: 40px; }

/* Likert */
.likert-list { display: grid; gap: 12px; }
.likert-item legend { float: left; width: 100%; padding: 0; font-weight: 600; margin-bottom: 12px; }
.likert-item legend + * { clear: both; }
.q-num { color: var(--muted); }
.likert { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.likert-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 8px 4px; border-radius: 10px; cursor: pointer; border: 1.5px solid transparent;
}
.likert-opt:hover { background: var(--surface-2); }
.likert-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.likert-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); }
.likert-label { font-size: .78rem; color: var(--muted); line-height: 1.25; }
.likert-opt:has(input:checked) { border-color: var(--eq); background: var(--surface-2); }
.likert-opt:has(input:checked) .likert-dot { border-color: var(--eq); background: var(--eq); box-shadow: inset 0 0 0 3px var(--surface); }
.likert-opt:has(input:checked) .likert-label { color: var(--text); font-weight: 600; }
.likert-opt:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- kết quả ---------- */
.score-card { text-align: center; margin-bottom: 16px; }
.score-label { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; font-size: .85rem; margin: 0; }
.score-big { font-size: clamp(3.5rem, 12vw, 5rem); font-weight: 800; line-height: 1.1; margin: 4px 0; font-variant-numeric: tabular-nums; }
.score-max { font-size: 1.4rem; color: var(--muted); font-weight: 600; }
.band { font-weight: 700; }
.band-veryHigh, .band-high, .band-strong { color: var(--strong); }
.band-average, .band-moderate { color: var(--moderate); }
.band-low, .band-develop { color: var(--develop); }

.scale { max-width: 420px; margin: 16px auto; }
.scale-track { position: relative; height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--develop), var(--moderate) 40%, var(--strong)); }
.scale-marker { position: absolute; top: 50%; width: 18px; height: 18px; margin-left: -9px; transform: translateY(-50%); border-radius: 50%; background: var(--surface); border: 3px solid var(--text); }
.scale-labels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 6px; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }

.review summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.review-list { padding-left: 0; list-style: none; margin: 12px 0 0; display: grid; gap: 10px; }
.review-item { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); border-left: 4px solid var(--ok); }
.review-item.bad { border-left-color: var(--bad); }
.review-item p { margin: 0 0 4px; }
.review-q { font-weight: 600; overflow-wrap: anywhere; }
.review-item .mark { margin-right: 6px; }
.review-item.ok .mark { color: var(--ok); }
.review-item.bad .mark { color: var(--bad); }

.domains { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; }
.domain-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.band-strong { background: var(--strong); }
.bar-fill.band-moderate { background: var(--moderate); }
.bar-fill.band-develop { background: var(--develop); }

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 520px) {
  .likert { gap: 2px; }
  .likert-label { font-size: .68rem; }
  .question { padding: 18px; }
  .q-text { font-size: 1.1rem; }
  .fig-options { grid-template-columns: repeat(2, 1fr); }
  .actions .btn { flex: 1 1 100%; }
}

/* ---------- in ---------- */
@media print {
  .site-header, .no-print, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; }
  details.review { display: none; }
}
