/* Day/night switch and the hand-written part of night mode.
   Page-specific night overrides are generated into theme/dark/ by
   MACMINI/scripts/build-dark-theme.py and loaded by app/includes/document_head.php. */

button.theme-switch[data-theme-switch] {
    --theme-switch-width: 58px;
    box-sizing: border-box;
    min-height: 0;
    margin: 0;
    line-height: 1;
    --theme-switch-height: 32px;
    --theme-knob: 24px;
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    width: var(--theme-switch-width);
    height: var(--theme-switch-height);
    padding: 0;
    border: 1px solid rgba(116, 231, 255, 0.34);
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(125, 211, 252, 0.28), rgba(251, 191, 36, 0.22));
    box-shadow: inset 0 1px 3px rgba(2, 12, 27, 0.28);
    color: inherit;
    cursor: pointer;
    font: inherit;
    transition: background-color 240ms ease, border-color 240ms ease, box-shadow 240ms ease;
    -webkit-tap-highlight-color: transparent;
}

button.theme-switch[data-theme-switch]:hover {
    border-color: rgba(116, 231, 255, 0.6);
}

button.theme-switch[data-theme-switch]:focus-visible {
    outline: 3px solid rgba(56, 189, 248, 0.72);
    outline-offset: 2px;
}

.theme-switch-track-icon {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    transform: translateY(-50%);
    opacity: 0.75;
    pointer-events: none;
}

.theme-switch-track-icon.is-sun {
    left: 8px;
    color: #fde68a;
}

.theme-switch-track-icon.is-moon {
    right: 8px;
    color: #e0f2fe;
}

.theme-switch-knob {
    position: absolute;
    top: 50%;
    left: 3px;
    display: grid;
    place-items: center;
    width: var(--theme-knob);
    height: var(--theme-knob);
    border-radius: 50%;
    background: #fff7d6;
    box-shadow: 0 2px 8px rgba(2, 12, 27, 0.35), 0 0 0 1px rgba(251, 191, 36, 0.45);
    color: #d97706;
    transform: translateY(-50%);
    transition: transform 260ms cubic-bezier(0.34, 1.4, 0.64, 1), background-color 240ms ease, color 240ms ease, box-shadow 240ms ease;
}

.theme-switch-knob svg {
    width: 15px;
    height: 15px;
}

.theme-switch-knob .is-moon,
html[data-theme="dark"] .theme-switch-knob .is-sun {
    display: none;
}

html[data-theme="dark"] .theme-switch-knob .is-moon {
    display: block;
}

html[data-theme="dark"] button.theme-switch[data-theme-switch] {
    border-color: rgba(129, 140, 248, 0.45);
    background: linear-gradient(135deg, rgba(30, 41, 82, 0.92), rgba(15, 23, 42, 0.92));
}

html[data-theme="dark"] .theme-switch-knob {
    background: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(165, 180, 252, 0.5);
    color: #c7d2fe;
    transform: translate(calc(var(--theme-switch-width) - var(--theme-knob) - 8px), -50%);
}

/* Pages without the shared header get a small floating switch. */
button.theme-switch[data-theme-switch].is-floating {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 2147483000;
    border-color: rgba(116, 231, 255, 0.45);
    background: linear-gradient(135deg, rgba(6, 20, 39, 0.86), rgba(11, 47, 96, 0.86));
    box-shadow: 0 8px 24px rgba(2, 12, 27, 0.3);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

@media (max-width: 430px) {
    button.theme-switch[data-theme-switch] {
        --theme-switch-width: 50px;
        --theme-switch-height: 28px;
        --theme-knob: 21px;
    }

    .theme-switch-track-icon {
        width: 12px;
        height: 12px;
    }

    .theme-switch-track-icon.is-sun {
        left: 6px;
    }

    .theme-switch-track-icon.is-moon {
        right: 6px;
    }
}

@media print {
    button.theme-switch[data-theme-switch] {
        display: none !important;
    }
}

/* VI / EN language switch (assets/i18n/i18n.js). */
div.lang-switch[data-lang-switch] {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px;
    height: 32px;
    padding: 3px;
    border: 1px solid rgba(116, 231, 255, 0.34);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 3px rgba(2, 12, 27, 0.28);
    box-sizing: border-box;
}

div.lang-switch[data-lang-switch] > button[data-lang-option] {
    all: unset;
    box-sizing: border-box;
    display: inline-grid;
    place-items: center;
    min-width: 30px;
    height: 24px;
    padding: 0 7px;
    border-radius: 999px;
    color: #cbd5e1;
    font: 800 11px/1 var(--a-font);
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background-color 200ms ease, color 200ms ease, box-shadow 200ms ease;
    -webkit-tap-highlight-color: transparent;
}

div.lang-switch[data-lang-switch] > button[data-lang-option]:hover {
    color: #fff;
}

div.lang-switch[data-lang-switch] > button[data-lang-option]:focus-visible {
    outline: 3px solid rgba(56, 189, 248, 0.72);
    outline-offset: 1px;
}

div.lang-switch[data-lang-switch] > button[data-lang-option][aria-pressed="true"] {
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.45);
    cursor: default;
}

div.lang-switch[data-lang-switch].is-floating {
    position: fixed;
    left: 84px;
    bottom: 16px;
    z-index: 2147483000;
    background: linear-gradient(135deg, rgba(6, 20, 39, 0.86), rgba(11, 47, 96, 0.86));
    box-shadow: 0 8px 24px rgba(2, 12, 27, 0.3);
}

@media (max-width: 430px) {
    /* One button that names the language it switches to. */
    div.lang-switch[data-lang-switch] {
        height: 28px;
        padding: 2px;
    }

    div.lang-switch[data-lang-switch] > button[data-lang-option][aria-pressed="true"] {
        display: none;
    }

    div.lang-switch[data-lang-switch] > button[data-lang-option] {
        min-width: 26px;
        height: 22px;
        padding: 0 5px;
        font-size: var(--a-fs-2xs);
    }

    div.lang-switch[data-lang-switch].is-floating {
        left: 74px;
    }
}

@media print {
    div.lang-switch[data-lang-switch] {
        display: none !important;
    }
}

/* English is applied in the browser; hide the Vietnamese text until it is. */
html[data-lang="en"]:not(.i18n-ready) body {
    visibility: hidden;
}

/* Smooth colour change only while the user flips the switch. */
html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: background-color 260ms ease, border-color 260ms ease, color 260ms ease, fill 260ms ease, box-shadow 260ms ease !important;
}

@media (prefers-reduced-motion: reduce) {
    .theme-switch-knob,
    html.theme-switching,
    html.theme-switching *,
    html.theme-switching *::before,
    html.theme-switching *::after {
        transition: none !important;
    }
}

/* ------------------------------------------------------------ night mode */

html[data-theme="dark"] {
    color-scheme: dark;
}

/* Slightly deeper navy frame so the dark cards do not look lighter than the sky. */
html[data-theme="dark"] body.site-standard-background {
    --site-background:
        radial-gradient(circle at 18% 24%, rgba(36, 144, 255, 0.26), transparent 28%),
        radial-gradient(circle at 82% 18%, rgba(42, 214, 255, 0.12), transparent 24%),
        linear-gradient(180deg, #030c19 0%, #08234a 52%, #0a3d80 100%);
}

/* Light backgrounds written straight into style attributes. */
html[data-theme="dark"] :is([style*="background:#fff"], [style*="background: #fff"], [style*="background-color:#fff"], [style*="background-color: #fff"], [style*="background:white"], [style*="background: white"], [style*="background-color: white"]):not(img, canvas, [class*="qr"], [id*="qr"]) {
    background-color: var(--a-surface) !important;
}

html[data-theme="dark"] :is([style*="background:#f8fafc"], [style*="background: #f8fafc"], [style*="background:#f9fafb"], [style*="background: #f9fafb"]) {
    background-color: var(--a-surface-2) !important;
}

html[data-theme="dark"] :is([style*="background:#f1f5f9"], [style*="background: #f1f5f9"], [style*="background:#f3f4f6"], [style*="background: #f3f4f6"]) {
    background-color: var(--a-surface-2) !important;
}

html[data-theme="dark"] :is([style*="color:#0f172a"], [style*="color: #0f172a"], [style*="color:#111827"], [style*="color: #111827"], [style*="color:#334155"], [style*="color: #334155"], [style*="color:#000"], [style*="color: #000"]) {
    color: var(--a-text) !important;
}

/* Images with transparent backgrounds inside lesson and problem statements
   (diagrams, formulas) were drawn for white paper. */
html[data-theme="dark"] :is(.problem-rich-text, .exam-description, .problem-text, .question-content) img {
    background: #fff;
    border-radius: 6px;
}

html[data-theme="dark"] ::selection {
    background: rgba(56, 189, 248, 0.35);
    color: #f8fafc;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
    color: #7c8aa0;
}

html[data-theme="dark"] select option {
    background-color: #17212f;
    color: #e2e8f0;
}

/* ---------- Thanh menu trang chủ/đầu trang (03/10/2026) ----------
   Hai công tắc cùng một kiểu trên nền đầu trang tối: cùng cao 30px, viền mảnh,
   mục đang chọn màu cam như "</>" của logo. Menu khổ vừa giữ một hàng. */
:is(.home-site-header, .ui-global-header) div.lang-switch[data-lang-switch],
:is(.home-site-header, .ui-global-header) button.theme-switch[data-theme-switch] {
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
}

:is(.home-site-header, .ui-global-header) div.lang-switch[data-lang-switch] {
    padding: 2px;
}

:is(.home-site-header, .ui-global-header) div.lang-switch[data-lang-switch] > button[data-lang-option] {
    min-width: 28px;
    height: 24px;
    color: #cbd5e1;
}

:is(.home-site-header, .ui-global-header) div.lang-switch[data-lang-switch] > button[data-lang-option][aria-pressed="true"] {
    background: #ea580c;
    color: #fff;
    box-shadow: none;
}

:is(.home-site-header, .ui-global-header) button.theme-switch[data-theme-switch] {
    --theme-switch-width: 54px;
    --theme-switch-height: 30px;
    --theme-knob: 24px;
}

:is(.home-site-header, .ui-global-header) .theme-switch-track-icon {
    color: #94a3b8;
    opacity: 0.8;
}

:is(.home-site-header, .ui-global-header) .theme-switch-knob {
    background: #ea580c;
    color: #fff;
    box-shadow: none;
}

html[data-theme="dark"] :is(.home-site-header, .ui-global-header) button.theme-switch[data-theme-switch] {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.18);
}

html[data-theme="dark"] :is(.home-site-header, .ui-global-header) .theme-switch-knob {
    background: #f1aa76;
    color: #172235;
}

@media (min-width: 781px) and (max-width: 1180px) {
    :is(.home-site-header, .ui-global-header) .header-actions {
        gap: 8px;
    }

    :is(.home-site-header, .ui-global-header) .nav {
        flex-wrap: nowrap;
        gap: 2px;
    }

    :is(.home-site-header, .ui-global-header) .nav > a,
    :is(.home-site-header, .ui-global-header) .nav .nav-drop-trigger {
        padding: 8px 9px;
        font-size: var(--a-fs-sm);
        white-space: nowrap;
    }
}

@media (min-width: 781px) and (max-width: 900px) {
    :is(.home-site-header, .ui-global-header) {
        padding-left: 14px;
        padding-right: 14px;
    }

    :is(.home-site-header, .ui-global-header) .brand {
        padding: 8px 4px;
        font-size: var(--a-fs-base);
    }

    :is(.home-site-header, .ui-global-header) .brand code {
        display: none;
    }

    :is(.home-site-header, .ui-global-header) .nav > a,
    :is(.home-site-header, .ui-global-header) .nav .nav-drop-trigger {
        padding: 7px 6px;
        font-size: var(--a-fs-sm);
    }

    :is(.home-site-header, .ui-global-header) .nav-drop-trigger::after {
        margin-left: 3px;
    }
}

/* ---------- Menu gập (☰) cho khổ 431–960px (03/10/2026, nới từ 780px ngày 07/10) ----------
   Sinh từ khối @media (max-width: 430px) của tracnghiem-nav.css và home-menu.css:
   trước đây ở khổ này menu ngang tràn đè lên logo. */
@media (min-width: 431px) and (max-width: 960px) {
    .ui-global-header .header-actions { flex: 0 0 auto; min-width: auto; justify-content: flex-end; gap: 8px; margin-left: auto; }
    .ui-global-header .brand { font-size: var(--a-fs-md); }
    .ui-global-header .menu-toggle { display: inline-flex; }
    .ui-global-header .nav { position: absolute; top: calc(100% + 8px); left: 12px; right: 12px; z-index: 60; display: none; grid-template-columns: 1fr; gap: 4px; padding: 8px; border: 1px solid rgba(116, 231, 255, 0.28); border-radius: 12px; background: linear-gradient(180deg, #0a2344 0%, #061427 100%); box-shadow: 0 18px 45px rgba(6, 20, 39, 0.36); }
    .ui-global-header .nav.open { display: grid; }
    .ui-global-header .nav a, .ui-global-header .nav button { width: 100%; min-height: 42px; padding: 10px 12px; text-align: left; color: #dbeafe; }
    .ui-global-header .nav a:hover, .ui-global-header .nav a:focus-visible, .ui-global-header .nav a.active, .ui-global-header .nav button:hover, .ui-global-header .nav button:focus-visible { color: #fff; background: rgba(116, 231, 255, 0.1); text-shadow: 0 0 18px rgba(99, 230, 255, 0.28); transform: none; }
    .ui-global-header .nav-dropdown { width: 100%; }
    .ui-global-header .nav-drop-menu { position: static; min-width: 0; margin-top: 4px; border-color: rgba(116, 231, 255, 0.18); background: rgba(2, 12, 26, 0.72); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); }
    .home-site-header { position: sticky; }
    .home-site-header .header-actions { flex: 0 0 auto; min-width: auto; justify-content: flex-end; gap: 8px; margin-left: auto; }
    .home-site-header .brand { font-size: var(--a-fs-md); }
    .home-site-header .menu-toggle { display: inline-flex; }
    .home-site-header .nav { position: absolute; top: calc(100% + 8px); left: 12px; right: 12px; z-index: 40; display: none; grid-template-columns: 1fr; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
    .home-site-header .nav.open { display: grid; }
    .home-site-header .nav a, .home-site-header .nav button { width: 100%; min-height: 42px; padding: 10px 12px; text-align: left; }
    .home-site-header .nav > a, .home-site-header .nav-dropdown > button { color: var(--blue); text-shadow: none; }
    .home-site-header .nav > a:hover, .home-site-header .nav > a:focus-visible, .home-site-header .nav-dropdown > button:hover, .home-site-header .nav-dropdown > button:focus-visible { color: #082f69; background: #eef6ff; }
    .home-site-header .nav-dropdown { width: 100%; }
    .home-site-header .nav-drop-menu { position: static; min-width: 0; margin-top: 4px; box-shadow: none; }
}

@media (min-width: 431px) and (max-width: 960px) {
    html[data-theme="dark"] .ui-global-header .nav { border: 1px solid rgba(116, 231, 255, 0.28); background: linear-gradient(180deg, #0a2344 0%, #061427 100%); box-shadow: 0 18px 45px rgba(6, 20, 39, 0.36); }
    html[data-theme="dark"] .ui-global-header .nav a, html[data-theme="dark"] .ui-global-header .nav button { color: #dbeafe; }
    html[data-theme="dark"] .ui-global-header .nav a:hover, html[data-theme="dark"] .ui-global-header .nav a:focus-visible, html[data-theme="dark"] .ui-global-header .nav a.active, html[data-theme="dark"] .ui-global-header .nav button:hover, html[data-theme="dark"] .ui-global-header .nav button:focus-visible { color: #fff; background: rgba(116, 231, 255, 0.1); }
    html[data-theme="dark"] .ui-global-header .nav-drop-menu { border-color: rgba(116, 231, 255, 0.18); background: rgba(2, 12, 26, 0.72); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); }
    html[data-theme="dark"] .home-site-header .nav { background: var(--a-surface); }
    html[data-theme="dark"] .home-site-header .nav > a, html[data-theme="dark"] .home-site-header .nav-dropdown > button { color: #9dc1f9; }
    html[data-theme="dark"] .home-site-header .nav > a:hover, html[data-theme="dark"] .home-site-header .nav > a:focus-visible, html[data-theme="dark"] .home-site-header .nav-dropdown > button:hover, html[data-theme="dark"] .home-site-header .nav-dropdown > button:focus-visible { color: #a6c8fc; background: #122942; }
    html[data-theme="dark"] .home-site-header .nav-drop-menu { box-shadow: none; }
}
