/**
 * Qin_EasyAccess
 *
 * 两部分：
 *   A. 偏好效果 —— 由 <html> 上的 data-ea-* 属性驱动，作用于整站
 *   B. 工具条自身样式 —— 命名空间 .qin-ea，不影响主题
 *
 * 纯 CSS，不依赖主题 LESS，因此在 2.3.4 与 2.4.8、以及六个站的定制主题上
 * 行为一致。选择器保持低特异性，只在必须压过主题时才提高。
 */

/* ══ A. 偏好效果 ═══════════════════════════════════════════════ */

/* 文字间距 —— WCAG SC 1.4.12 的目标值 */
html[data-ea-spacing="on"] body,
html[data-ea-spacing="on"] p,
html[data-ea-spacing="on"] li,
html[data-ea-spacing="on"] dd,
html[data-ea-spacing="on"] dt,
html[data-ea-spacing="on"] td,
html[data-ea-spacing="on"] th,
html[data-ea-spacing="on"] label,
html[data-ea-spacing="on"] a {
    line-height: 1.6 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

html[data-ea-spacing="on"] p {
    margin-bottom: 2em !important;
}

/* 链接下划线 —— WCAG SC 1.4.1：不能只靠颜色区分链接 */
html[data-ea-links="on"] a:not([class*="button"]):not([class*="btn"]):not(.action) {
    text-decoration: underline !important;
    text-underline-offset: 2px;
}

/* 暂停动画 —— WCAG SC 2.2.2 */
html[data-ea-motion="on"] *,
html[data-ea-motion="on"] *::before,
html[data-ea-motion="on"] *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* 用户未做选择时跟随系统设置，不用工具条的默认值覆盖操作系统偏好 */
@media (prefers-reduced-motion: reduce) {
    html:not([data-ea-motion="off"]) *,
    html:not([data-ea-motion="off"]) *::before,
    html:not([data-ea-motion="off"]) *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* 增强焦点环 —— WCAG SC 2.4.13 */
html[data-ea-focus="on"] :focus {
    outline: 3px solid #1b44e8 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.9) !important;
}

html[data-ea-focus="on"] :focus:not(:focus-visible) {
    outline: none !important;
    box-shadow: none !important;
}

/*
 * 主导航例外：Luma 用 jQuery UI Menu，方向键移动时是脚本调用 .focus()
 * 程序化聚焦，浏览器不一定把它算作 focus-visible。上面那条重置会把
 * 键盘用户在导航里的焦点环整个清掉——WCAG 2.4.7 AA 失败。
 * 这里用更高的特异性顶回来。
 */
html[data-ea-focus="on"] .navigation a:focus:not(:focus-visible) {
    outline: 3px solid #1b44e8 !important;
    outline-offset: -3px !important;
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.95) !important;
}

html[data-ea-focus="on"] :focus-visible {
    outline: 3px solid #1b44e8 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.9) !important;
}

/*
 * 配色模式。
 *
 * dark 与 mono 用 filter 实现，是权衡后的选择：一行覆盖全站、不需要为
 * 六个定制主题各写一套色板。代价是图片会被反色，所以下面把媒体元素
 * 和工具条本身反回来。high 走真实颜色覆盖，因为对比度必须可控。
 */
html[data-ea-contrast="dark"] {
    filter: invert(1) hue-rotate(180deg);
    background: #fff;
}

html[data-ea-contrast="mono"] {
    filter: grayscale(1);
}

html[data-ea-contrast="dark"] img,
html[data-ea-contrast="dark"] video,
html[data-ea-contrast="dark"] iframe,
html[data-ea-contrast="dark"] picture,
html[data-ea-contrast="dark"] [style*="background-image"],
html[data-ea-contrast="dark"] .qin-ea {
    filter: invert(1) hue-rotate(180deg);
}

/*
 * high —— 高对比。
 *
 * 注意实现方式：白色只画在 body 这一层，内层元素一律 transparent，
 * 让 body 的底色透上来。
 *
 * 不要写成 `body * { background-color:#fff }`——那样每一层元素都会被
 * 独立刷白，页面所有分区、卡片、按钮的边界全部消失，看上去就是一张白纸，
 * 而且会把 img / svg 一起匹配进去。
 */
html[data-ea-contrast="high"] body {
    background: #fff !important;
    color: #000 !important;
}

html[data-ea-contrast="high"] body * {
    background-color: transparent !important;
    color: #000 !important;
    /* 覆盖渐变文字一类的写法：那种情况下 color 是无效的 */
    -webkit-text-fill-color: #000 !important;
    text-shadow: none !important;
}

/* 媒体元素完全不参与配色覆盖 */
html[data-ea-contrast="high"] img,
html[data-ea-contrast="high"] svg,
html[data-ea-contrast="high"] svg *,
html[data-ea-contrast="high"] video,
html[data-ea-contrast="high"] picture,
html[data-ea-contrast="high"] canvas,
html[data-ea-contrast="high"] iframe,
html[data-ea-contrast="high"] object,
html[data-ea-contrast="high"] embed {
    background-color: initial !important;
    color: initial !important;
    -webkit-text-fill-color: initial !important;
}

html[data-ea-contrast="high"] a,
html[data-ea-contrast="high"] a * {
    color: #00109f !important;
    -webkit-text-fill-color: #00109f !important;
    text-decoration: underline !important;
}

/*
 * 底色统一之后没有色块了，真正的按钮和表单控件靠边框区分。
 *
 * 千万不要在这里写裸的 `.action`。Luma 把这个 class 用得极其泛滥——
 * .action.showcart / .action.nav-toggle / .action.view / 分页的 .action.next /
 * .action.toggle / .action.tocart / .action.delete 等等，其中大量是
 * 普通的行内文字链接。给 .action 加边框的结果是满屏黑框。
 * 只匹配 button 元素和明确的 primary/secondary 按钮类。
 */
html[data-ea-contrast="high"] button,
html[data-ea-contrast="high"] .action.primary,
html[data-ea-contrast="high"] .action.secondary,
html[data-ea-contrast="high"] .action-primary,
html[data-ea-contrast="high"] .action-secondary,
html[data-ea-contrast="high"] input:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]),
html[data-ea-contrast="high"] select,
html[data-ea-contrast="high"] textarea {
    border: 2px solid #000 !important;
    background-color: #fff !important;
}

/*
 * 工具条自身要保持可辨识：上面的 body * 会把触发按钮也刷成透明底黑字，
 * 用户就找不到它了。这里逐项还原。
 */
html[data-ea-contrast="high"] .qin-ea__trigger {
    background: var(--qin-ea-accent) !important;
    color: #fff !important;
    -webkit-text-fill-color: #fff !important;
    border: 2px solid #000 !important;
}

html[data-ea-contrast="high"] .qin-ea__icon {
    fill: #fff !important;
}

html[data-ea-contrast="high"] .qin-ea__panel {
    background-color: #fff !important;
    border: 2px solid #000 !important;
}

html[data-ea-contrast="high"] .qin-ea__choice span,
html[data-ea-contrast="high"] .qin-ea__reset {
    background-color: #fff !important;
    border: 1px solid #000 !important;
}

/* 关闭按钮是 <button>，会被上面的通用规则套上 2px 黑框，还原成无边框图标 */
html[data-ea-contrast="high"] .qin-ea__close {
    border: 0 !important;
    background-color: transparent !important;
}

html[data-ea-contrast="high"] .qin-ea__choice input:checked + span {
    border-width: 2px !important;
    box-shadow: inset 0 0 0 1px #000 !important;
}

/* ══ B. 工具条自身 ═════════════════════════════════════════════ */

.qin-ea {
    --qin-ea-accent: #1b44e8;
    --qin-ea-ink: #16181f;
    --qin-ea-muted: #555b6e;
    --qin-ea-line: #d7dae4;
    --qin-ea-surface: #fff;

    position: fixed;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--qin-ea-ink);
}

.qin-ea[data-position="bottom_right"] { right: 20px; bottom: 20px; }
.qin-ea[data-position="bottom_left"]  { left: 20px;  bottom: 20px; }
.qin-ea[data-position="middle_right"] { right: 20px; top: 50%; transform: translateY(-50%); }
.qin-ea[data-position="middle_left"]  { left: 20px;  top: 50%; transform: translateY(-50%); }

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

/* 触发按钮：≥44×44px —— WCAG SC 2.5.8 */
.qin-ea__trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: var(--qin-ea-accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}

.qin-ea__trigger:hover {
    filter: brightness(1.12);
}

.qin-ea__trigger:focus-visible,
.qin-ea__close:focus-visible,
.qin-ea__reset:focus-visible {
    outline: 3px solid var(--qin-ea-accent);
    outline-offset: 3px;
}

.qin-ea__icon {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* 透明点击捕获层：维持 aria-modal 语义，但不遮暗页面,
   用户要能实时看到设置对页面的效果。 */
.qin-ea__backdrop {
    position: fixed;
    inset: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    background: transparent;
}

.qin-ea__panel {
    position: absolute;
    bottom: 64px;
    width: 320px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding: 0;
    border: 1px solid var(--qin-ea-line);
    border-radius: 10px;
    background: var(--qin-ea-surface);
    box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
}

.qin-ea[data-position$="_right"] .qin-ea__panel { right: 0; }
.qin-ea[data-position$="_left"]  .qin-ea__panel { left: 0; }
.qin-ea[data-position^="middle"] .qin-ea__panel { bottom: auto; top: 0; }

.qin-ea__panel[hidden] {
    display: none;
}

.qin-ea__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--qin-ea-line);
}

.qin-ea__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
}

.qin-ea__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: -10px -8px -10px 0;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--qin-ea-muted);
    cursor: pointer;
}

.qin-ea__close:hover {
    background: #f1f2f6;
    color: var(--qin-ea-ink);
}

.qin-ea__close svg {
    width: 15px;
    height: 15px;
}

.qin-ea__body {
    padding: 6px 16px 16px;
}

.qin-ea__group {
    margin: 14px 0 0;
    padding: 0;
    border: 0;
}

.qin-ea__legend {
    display: block;
    width: 100%;
    margin: 0 0 8px;
    padding: 0;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--qin-ea-muted);
}

.qin-ea__choices {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.qin-ea__choice {
    flex: 1 1 auto;
}

.qin-ea__choice input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.qin-ea__choice span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 62px;
    min-height: 44px;
    padding: 4px 10px;
    border: 1px solid var(--qin-ea-line);
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
}

.qin-ea__choice input:checked + span {
    border-color: var(--qin-ea-accent);
    box-shadow: inset 0 0 0 1px var(--qin-ea-accent);
    font-weight: 600;
}

/* 选中态不能只靠颜色 —— WCAG SC 1.4.1 */
.qin-ea__choice input:checked + span::before {
    content: "\2713\00a0";
}

.qin-ea__choice input:focus-visible + span {
    outline: 3px solid var(--qin-ea-accent);
    outline-offset: 2px;
}

.qin-ea__switches {
    display: flex;
    flex-direction: column;
}

.qin-ea__switch {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 4px 0;
    font-size: 14px;
    cursor: pointer;
}

.qin-ea__switch input {
    flex: none;
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--qin-ea-accent);
    cursor: pointer;
}

.qin-ea__reset {
    width: 100%;
    min-height: 44px;
    margin-top: 18px;
    padding: 10px 12px;
    border: 1px solid var(--qin-ea-line);
    border-radius: 6px;
    background: #f7f8fb;
    font-size: 14px;
    font-weight: 600;
    color: var(--qin-ea-ink);
    cursor: pointer;
}

.qin-ea__reset:hover {
    background: #eceef5;
}

.qin-ea__note {
    margin: 12px 0 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--qin-ea-muted);
}

.qin-ea__links {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0 0;
    font-size: 12.5px;
}

.qin-ea__links a {
    color: var(--qin-ea-accent);
}

@media (max-width: 480px) {
    .qin-ea[data-position] {
        right: 12px;
        left: auto;
        bottom: 12px;
        top: auto;
        transform: none;
    }

    .qin-ea__panel {
        right: 0;
        left: auto;
        width: calc(100vw - 24px);
    }
}
