/* ═══════════════════════════════════════════════════════════════════════════
   IQ Test — Shell: reset, type, buttons, cards, nav bar, footer.
   Reads tokens from tokens.css only. No color value is written directly here.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset ──────────────────────────────────────────────────────────────────
   Bootstrap used to carry this. Dropping it — roughly 230 KB over a CDN for
   a handful of utility classes — means normalizing exactly what is needed. */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

body {
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    color: var(--ink);
    background: var(--paper);
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

main { flex: 1 0 auto; }

img, svg, video, canvas { max-width: 100%; display: block; }
img, video { height: auto; }

input, button, textarea, select { font: inherit; color: inherit; }

a { color: var(--brand); text-underline-offset: .18em; }
a:hover { color: var(--brand-ink); }

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: var(--lh-tight);
    letter-spacing: var(--track-tight);
    text-wrap: balance;
}

/* Keyboard focus: thick ring, offset outward so it reads on any ground */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}
/* WCAG 2.4.11 — a sticky nav bar must not cover the focused element */
:where(a, button, input, select, textarea, [tabindex]) { scroll-margin-top: 84px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* [hidden] has to win: components set display, which swallows the HTML hidden
   attribute and leaves the element on screen (the Overview badge once showed 0). */
[hidden] { display: none !important; }

/* ── Layout ────────────────────────────────────────────────────────────── */
.wrap         { width: 100%; max-width: var(--wrap);        margin-inline: auto; padding-inline: var(--gutter); }
.wrap--narrow { width: 100%; max-width: var(--wrap-narrow); margin-inline: auto; padding-inline: var(--gutter); }
/* Old name, kept for pages not migrated yet */
.container-narrow { width: 100%; max-width: var(--wrap-narrow); margin-inline: auto; padding-inline: var(--gutter); }

.stack   { display: flex; flex-direction: column; }
.stack-4 { gap: var(--s4); } .stack-5 { gap: var(--s5); }
.stack-6 { gap: var(--s6); } .stack-7 { gap: var(--s7); }

.skip-link {
    position: absolute; left: var(--s4); top: -100px;
    background: var(--brand); color: var(--ink-invert);
    padding: var(--s3) var(--s5); border-radius: 0 0 var(--r-md) var(--r-md);
    z-index: var(--z-toast); font-weight: 600; text-decoration: none;
    transition: top var(--dur-fast) var(--ease);
}
.skip-link:focus { top: 0; color: var(--ink-invert); }

/* ── Type ──────────────────────────────────────────────────────────────── */
.eyebrow {
    font-family: var(--font-body);
    font-size: var(--fs-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: var(--track-caps);
    color: var(--ink-3);
}
.lede    { font-size: var(--fs-md); color: var(--ink-2); max-width: var(--measure); }
.prose   { max-width: var(--measure); color: var(--ink-2); }
.prose p { margin-bottom: var(--s4); }
.prose p:last-child { margin-bottom: 0; }
.prose strong { color: var(--ink); font-weight: 600; }

/* A page body from admin > Posts & Page (helper\iq_page::body). The admin
   editor strips the inline styles and wrappers the seeded pages carried, so
   the frame and the type live here: a body saved in the editor - plain
   headings and paragraphs - comes out the same as one written by hand.
   :where() keeps these weaker than any class inside the body (the contact
   form, the IQ scale widgets, .eyebrow, .lede). */
.page-body { padding-block: var(--s9) var(--s11); }
.page-body :where(h1) { font-size: var(--fs-xl); margin: var(--s3) 0 var(--s2); }
.page-body :where(h2) { font-size: var(--fs-lg); margin: var(--s8) 0 var(--s3); }
.page-body :where(h3) { font-size: var(--fs-md); margin: var(--s6) 0 var(--s2); }
.page-body :where(p, ul, ol) { margin: 0 0 var(--s4); max-width: var(--measure); color: var(--ink-2); }
.page-body :where(ul, ol) { padding-left: 1.25em; }
.page-body :where(li) { margin-bottom: var(--s2); }
.page-body :where(strong) { color: var(--ink); font-weight: 600; }
.muted   { color: var(--ink-3); font-size: var(--fs-sm); }
.num     { font-variant-numeric: tabular-nums; }

/* ── Buttons ────────────────────────────────────────────────────────────────
   A modest radius rather than pill shapes: the product should read as a
   measuring instrument, not a quiz game. */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
    min-height: 44px; padding: var(--s3) var(--s6);
    font-size: var(--fs-sm); font-weight: 600; font-family: var(--font-body);
    border-radius: var(--r-sm); border: 1px solid transparent;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
}
.btn--lg    { min-height: 52px; padding: var(--s4) var(--s7); font-size: var(--fs-md); }
.btn--sm    { min-height: 36px; padding: var(--s2) var(--s4); font-size: var(--fs-xs); }
.btn--block { width: 100%; }

.btn--primary { background: var(--brand); color: var(--ink-invert); }
.btn--primary:hover:not(:disabled) { background: var(--brand-ink); color: var(--ink-invert); }

.btn--ghost { background: var(--surface); color: var(--brand); border-color: var(--line-strong); }
.btn--ghost:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-wash); color: var(--brand-ink); }

.btn--quiet { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn--quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: var(--s7) var(--s6);
    box-shadow: var(--shadow-1);
}
.card__title {
    font-family: var(--font-display); font-size: var(--fs-lg);
    font-weight: 600; color: var(--ink); margin-bottom: var(--s5);
}

.chip {
    display: inline-flex; align-items: center; gap: var(--s2);
    padding: 3px var(--s3); border-radius: var(--r-pill);
    font-size: var(--fs-xs); font-weight: 600;
    background: var(--brand-wash); color: var(--brand-ink);
    border: 1px solid var(--brand-line);
}
.chip--signal { background: var(--signal-wash); color: var(--signal); border-color: var(--signal); }
.chip--good   { background: var(--good-wash);   color: var(--good);   border-color: var(--good); }

.divider { height: 1px; background: var(--line); border: 0; margin: var(--s7) 0; }

.visually-hidden {
    position: absolute !important; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ═══ Nav bar ════════════════════════════════════════════════════════════ */
.nav {
    position: sticky; top: 0; z-index: var(--z-nav);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.nav__inner {
    max-width: var(--wrap); margin-inline: auto;
    padding: 0 var(--gutter);
    display: flex; align-items: center; gap: var(--s4);
    min-height: 64px;
}
.nav__brand {
    display: inline-flex; align-items: center; gap: var(--s3);
    text-decoration: none; color: var(--ink);
    font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600;
    letter-spacing: var(--track-tight); flex-shrink: 0;
}
.nav__brand img { height: 36px; width: auto; }
/* The brand mark, in the nav and again in the footer. It used to be the two
   letters "IQ" in a teal box; it is now the distribution mark, which paints its
   own tile and rounds its own corners - so all that is left here is a size.
   The drawing lives in themes/iq_test/layout/_brand_mark.php and takes its two
   colours from --brand and --ink-invert, which is how it follows dark mode. */
.nav__mark { width: 26px; height: 26px; flex-shrink: 0; }
.nav__mark svg { display: block; width: 100%; height: 100%; }

.nav__menu {
    /* Pushed right, beside the actions: the free space sits after the brand. */
    list-style: none; margin: 0 var(--s4) 0 auto; padding: 0;
    display: flex; align-items: center; gap: var(--s1);
}
.nav__item { position: relative; }
.nav__link {
    display: block; padding: var(--s2) var(--s3);
    color: var(--ink-2); text-decoration: none;
    font-size: var(--fs-sm); font-weight: 500; border-radius: var(--r-sm);
    transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
    white-space: nowrap;
}
.nav__link:hover { color: var(--ink); background: var(--surface-2); }
.nav__link[aria-current="page"] { color: var(--brand); font-weight: 600; }

.nav__dropdown {
    display: none; position: absolute; top: calc(100% + 4px); left: 0;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--r-md); box-shadow: var(--shadow-2);
    list-style: none; padding: var(--s2) 0; margin: 0; min-width: 200px;
}
/* Bridges the 4px gap above the list: crossing it left the item's :hover and
   shut the dropdown before the pointer reached it. */
.nav__dropdown::before { content: ""; position: absolute; left: 0; right: 0; top: -6px; height: 6px; }
.nav__item--drop:hover .nav__dropdown,
.nav__item--drop:focus-within .nav__dropdown { display: block; }
.nav__dropdown-self { display: none; }
.nav__dropdown a {
    display: block; padding: var(--s2) var(--s5);
    color: var(--ink-2); text-decoration: none; font-size: var(--fs-sm);
}
.nav__dropdown a:hover { background: var(--brand-wash); color: var(--brand-ink); }
/* The current page is inside this dropdown: mark the parent too, or nothing in
   the closed bar says where the reader is. */
.nav__item--drop.has-current > .nav__link,
.nav__dropdown a[aria-current="page"] { color: var(--brand); font-weight: 600; }

.nav__actions { display: flex; align-items: center; gap: var(--s2); flex-shrink: 0; }

.nav__theme {
    width: 40px; height: 40px; display: grid; place-items: center;
    background: transparent; border: 1px solid var(--line-strong);
    border-radius: var(--r-sm); color: var(--ink-2); cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav__theme:hover { border-color: var(--line-strong); color: var(--ink); }
.nav__theme .icon-moon { display: none; }
/* Biểu tượng trên nút chuyển theme phải khớp giao diện đang hiển thị.
   Sáng là mặc định nên mặt trời là trạng thái gốc; chỉ khi người dùng
   chọn tối mới đổi sang mặt trăng.

   Trước đây có thêm một khối @media (prefers-color-scheme: dark) ở đây. Đã
   bỏ cùng lúc với khối tương ứng trong tokens.css: giữ lại thì máy đặt chế
   độ tối sẽ thấy biểu tượng mặt trăng trong khi trang đang sáng — nút nói một
   đằng, màn hình một nẻo. */
.nav__theme .icon-sun  { display: block; }
.nav__theme .icon-moon { display: none; }
:root[data-theme="dark"] .nav__theme .icon-sun  { display: none; }
:root[data-theme="dark"] .nav__theme .icon-moon { display: block; }

.nav__toggle {
    display: none; width: 40px; height: 40px;
    background: transparent; border: 1px solid var(--line-strong);
    border-radius: var(--r-sm); cursor: pointer;
    flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.nav__toggle span { display: block; width: 18px; height: 1.5px; background: var(--ink); border-radius: 2px; }

@media (max-width: 860px) {
    .nav__toggle { display: flex; }
    .nav__menu {
        display: none; position: absolute; top: 100%; left: 0; right: 0;
        flex-direction: column; align-items: stretch; gap: 0; margin: 0;
        background: var(--surface); border-bottom: 1px solid var(--line);
        box-shadow: var(--shadow-2); padding: var(--s2) 0;
    }
    .nav__menu.is-open { display: flex; }
    .nav__link { padding: var(--s3) var(--gutter); border-radius: 0; }
    .nav__dropdown { position: static; display: none; box-shadow: none; border: 0; background: var(--surface-2); border-radius: 0; }
    .nav__item--drop.is-open .nav__dropdown { display: block; }
    .nav__item--drop:hover .nav__dropdown { display: none; }
    .nav__dropdown-self { display: block; }
    .nav__cta-text { display: none; }
}

/* ═══ Footer ═════════════════════════════════════════════════════════════ */
.foot {
    margin-top: auto;
    background: var(--surface);
    border-top: 1px solid var(--line);
    color: var(--ink-2); font-size: var(--fs-sm);
}
.foot__inner {
    max-width: var(--wrap); margin-inline: auto;
    padding: var(--s9) var(--gutter) var(--s7);
    display: grid; gap: var(--s8);
    grid-template-columns: minmax(220px, 1fr) 2fr;
}
.foot__brand-name {
    display: inline-flex; align-items: center; gap: var(--s3);
    font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600;
    color: var(--ink); text-decoration: none; margin-bottom: var(--s3);
}
.foot__brand-name img { height: 32px; width: auto; }
.foot__tagline { color: var(--ink-3); max-width: 34ch; }

.foot__cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s7); }
.foot__col-title {
    font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase;
    letter-spacing: var(--track-caps); color: var(--ink-3); margin-bottom: var(--s4);
}
.foot__col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.foot__col a { color: var(--ink-2); text-decoration: none; }
.foot__col a:hover { color: var(--brand); text-decoration: underline; }

.foot__band { display: grid; gap: var(--s2); }
.foot__band-row { display: flex; align-items: center; gap: var(--s3); font-size: var(--fs-xs); }
.foot__band-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.foot__band-num { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; min-width: 62px; }
.foot__band-lbl { color: var(--ink-3); }

.foot__bottom {
    border-top: 1px solid var(--line);
    max-width: var(--wrap); margin-inline: auto;
    padding: var(--s5) var(--gutter);
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--s3);
    font-size: var(--fs-xs); color: var(--ink-3);
}

/* Minimal footer for the test screen: no links, no exits. The top rule is
   there to separate the footer from the content block above it; there is no
   such block here, so it goes. */
.foot--minimal { background: transparent; border-top: 0; }
.foot--minimal .foot__bottom { border-top: 1px solid var(--line); }

@media (max-width: 760px) {
    .foot__inner { grid-template-columns: 1fr; gap: var(--s7); }
}

/* ── Item figures ───────────────────────────────────────────────────────────
   Item SVGs are generated with a fixed palette baked straight into the shape:
   #fff ground, #1f2937 ink, #e2e8f0 cell frame, #94a3b8 the answer cell.

   This used to be filter: invert(.9) for dark mode. That was wrong twice over:
   the white ground inverted to a neutral gray which, next to the teal-leaning
   --surface-2, showed as an obvious off-color rectangle; and it inverted every
   tone alike, so the hierarchy between ink and frame was lost.

   SVG presentation attributes rank below CSS, so retargeting each color is
   enough — no need to regenerate the item bank. check_figures.php guards this
   palette: change a color in generate_items.php and forget to change it here,
   and dark mode quietly goes white again. */
.tk-fig svg [fill="#fff"],
.tk-opt__fig svg [fill="#fff"],
.lp-specimen__fig svg [fill="#fff"],
.lp-try__fig svg [fill="#fff"],
.lp-opt__fig svg [fill="#fff"],
.rs-item__fig svg [fill="#fff"],
.rs-opt svg [fill="#fff"] { fill: var(--fig-bg); }

.tk-fig svg [fill="#1f2937"],
.tk-opt__fig svg [fill="#1f2937"],
.lp-specimen__fig svg [fill="#1f2937"],
.lp-try__fig svg [fill="#1f2937"],
.lp-opt__fig svg [fill="#1f2937"],
.rs-item__fig svg [fill="#1f2937"],
.rs-opt svg [fill="#1f2937"] { fill: var(--fig-ink); }

.tk-fig svg [stroke="#1f2937"],
.tk-opt__fig svg [stroke="#1f2937"],
.lp-specimen__fig svg [stroke="#1f2937"],
.lp-try__fig svg [stroke="#1f2937"],
.lp-opt__fig svg [stroke="#1f2937"],
.rs-item__fig svg [stroke="#1f2937"],
.rs-opt svg [stroke="#1f2937"] { stroke: var(--fig-ink); }

.tk-fig svg [stroke="#e2e8f0"],
.tk-opt__fig svg [stroke="#e2e8f0"],
.lp-specimen__fig svg [stroke="#e2e8f0"],
.lp-try__fig svg [stroke="#e2e8f0"],
.lp-opt__fig svg [stroke="#e2e8f0"],
.rs-item__fig svg [stroke="#e2e8f0"],
.rs-opt svg [stroke="#e2e8f0"] { stroke: var(--fig-line); }

.tk-fig svg [stroke="#cbd5e1"],
.tk-opt__fig svg [stroke="#cbd5e1"],
.lp-specimen__fig svg [stroke="#cbd5e1"],
.lp-try__fig svg [stroke="#cbd5e1"],
.lp-opt__fig svg [stroke="#cbd5e1"],
.rs-item__fig svg [stroke="#cbd5e1"],
.rs-opt svg [stroke="#cbd5e1"] { stroke: var(--fig-line-2); }

.tk-fig svg [fill="#94a3b8"],
.tk-opt__fig svg [fill="#94a3b8"],
.lp-specimen__fig svg [fill="#94a3b8"],
.lp-try__fig svg [fill="#94a3b8"],
.lp-opt__fig svg [fill="#94a3b8"],
.rs-item__fig svg [fill="#94a3b8"],
.rs-opt svg [fill="#94a3b8"] { fill: var(--fig-muted); }

.tk-fig svg [fill="#64748b"],
.tk-opt__fig svg [fill="#64748b"],
.lp-specimen__fig svg [fill="#64748b"],
.lp-try__fig svg [fill="#64748b"],
.lp-opt__fig svg [fill="#64748b"],
.rs-item__fig svg [fill="#64748b"],
.rs-opt svg [fill="#64748b"] { fill: var(--fig-notation); }

.tk-fig svg [stroke="#94a3b8"],
.tk-opt__fig svg [stroke="#94a3b8"],
.lp-specimen__fig svg [stroke="#94a3b8"],
.lp-try__fig svg [stroke="#94a3b8"],
.lp-opt__fig svg [stroke="#94a3b8"],
.rs-item__fig svg [stroke="#94a3b8"],
.rs-opt svg [stroke="#94a3b8"] { stroke: var(--fig-muted); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
    position: fixed; left: 50%; bottom: var(--s7); transform: translateX(-50%);
    background: var(--ink); color: var(--paper);
    padding: var(--s3) var(--s6); border-radius: var(--r-sm);
    font-size: var(--fs-sm); font-weight: 500;
    z-index: var(--z-toast); opacity: 0; pointer-events: none;
    transition: opacity var(--dur-med) var(--ease);
}
.toast.is-visible { opacity: 1; }
