/* Fixed accessibility launcher: one blue circular surface, no rectangular decoration. */
#a11y-toggle-btn {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 100010;
  box-sizing: border-box;
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: #1958df;
  background-image: none;
  color: #fff;
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(13, 48, 116, 0.22);
  -webkit-appearance: none;
  appearance: none;
  transform: none;
  transition: background-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
#a11y-toggle-btn::before,
#a11y-toggle-btn::after { content: none !important; display: none !important; }
#a11y-toggle-btn .a11y-toggle-icon {
  width: 36px;
  height: 36px;
  display: block;
  flex: none;
  pointer-events: none;
}
@media (hover: hover) {
  #a11y-toggle-btn:hover {
    background: #1245b8;
    box-shadow: 0 6px 18px rgba(13, 48, 116, 0.3);
    transform: translateY(-2px);
  }
}
#a11y-toggle-btn:active { transform: translateY(0); }
#a11y-toggle-btn:focus-visible {
  outline: 3px solid #fbbf24;
  outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
  #a11y-toggle-btn { transition: none; }
}
@media (max-width: 480px) {
  #a11y-toggle-btn {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
  }
  #a11y-toggle-btn .a11y-toggle-icon { width: 33px; height: 33px; }
}

/* 主面板 */
#a11y-panel {
  position: fixed;
  right: 16px;
  bottom: 86px;
  width: 360px;
  max-height: 80vh;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.45);
  display: none;
  flex-direction: column;
  z-index: 999998;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#a11y-panel.a11y-panel-open {
  display: flex;
}

.a11y-panel-header {
  padding: 12px 16px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 16px 16px 0 0;
}

.a11y-panel-header-title {
  font-size: 15px;
  font-weight: 600;
}

.a11y-panel-header-shortcut {
  font-size: 11px;
  opacity: 0.9;
}

#a11y-close-btn {
  border: none;
  background: transparent;
  color: #e5e7eb;
  cursor: pointer;
  font-size: 18px;
}

.a11y-panel-body {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

/* 功能按钮通用样式 */
.a11y-btn {
  font-size: 12px;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.a11y-btn span {
  display: block;
}

.a11y-btn-label {
  font-weight: 500;
}

.a11y-btn-desc {
  font-size: 10px;
  color: #6b7280;
}

.a11y-btn-active {
  border-color: #2563eb;
  background: #eff6ff;
}

/* 下方的行控制（字体大小、行距等） */
.a11y-control-row {
  grid-column: span 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  font-size: 12px;
}

.a11y-control-row span {
  font-weight: 500;
}

.a11y-control-row .a11y-stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.a11y-stepper button {
  border-radius: 999px;
  width: 22px;
  height: 22px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.a11y-stepper-value {
  min-width: 36px;
  text-align: center;
  font-size: 11px;
  color: #6b7280;
}

/* Reset 一行独占 */
#a11y-reset {
  grid-column: span 3;
  margin-top: 4px;
  width: 100%;
  padding: 8px 0;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 12px;
  font-weight: 600;
}

/* ========== Reading Mask ========== */
#a11y-reading-mask {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999997;
  background: linear-gradient(
    to bottom,
    rgba(15, 23, 42, 0.7) 0,
    rgba(15, 23, 42, 0.7) var(--mask-top),
    transparent var(--mask-top),
    transparent calc(var(--mask-top) + var(--mask-height)),
    rgba(15, 23, 42, 0.7) calc(var(--mask-top) + var(--mask-height)),
    rgba(15, 23, 42, 0.7) 100%
  );
}

/* ========== Text Magnifier ========== */
#a11y-text-magnifier {
  position: fixed;
  max-width: 320px;
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1.4;
  background: #fefce8;
  border-radius: 10px;
  border: 1px solid #facc15;
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.3);
  z-index: 999999;
  pointer-events: none;
  color: #111827;
}

/* ========== 全局变量（字体/行距/字间距） ========== */
html {
  --a11y-font-scale: 1;
  --a11y-line-height: 1;
  --a11y-letter-spacing: 1;
}

body {
  font-size: calc(16px * var(--a11y-font-scale));
  line-height: calc(1.5 * var(--a11y-line-height));
  letter-spacing: calc(0em + (var(--a11y-letter-spacing) - 1) * 0.06em);
}

/* 高对比度 */
html.a11y-high-contrast {
  background-color: #000 !important;
  color: #fff !important;
}

html.a11y-high-contrast body,
html.a11y-high-contrast * {
  background-color: transparent !important;
  color: #fff !important;
  border-color: #9ca3af !important;
}

/* 暗色模式（比高对比度柔和一点） */
html.a11y-dark-mode {
  background-color: #020617;
  color: #e5e7eb;
}

html.a11y-dark-mode body {
  background-color: #020617;
  color: #e5e7eb;
}

/* 去色模式 */
html.a11y-desaturate {
  filter: grayscale(1);
}

/* 可读字体，比如统一无衬线 */
html.a11y-readable-font * {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif !important;
}

/* 链接高亮 */
html.a11y-highlight-links a {
  outline: 2px solid #f97316;
  background-color: rgba(251, 146, 60, 0.2);
}

/* 标题高亮 */
html.a11y-highlight-titles h1,
html.a11y-highlight-titles h2,
html.a11y-highlight-titles h3 {
  background-color: rgba(56, 189, 248, 0.25);
}

/* 隐藏图片 */
html.a11y-hide-images img {
  visibility: hidden !important;
}

/* Prevent hidden controls from receiving keyboard focus. */
#a11y-panel:not(.a11y-panel-open){visibility:hidden;pointer-events:none;}
#a11y-panel.a11y-panel-open{visibility:visible;}
#a11y-toggle-btn:focus-visible,#a11y-panel button:focus-visible{outline:3px solid #f59e0b;outline-offset:3px;}
#a11y-toggle-btn{z-index:100010;}
#a11y-panel{z-index:100011;}
@media(max-width:480px){#a11y-panel{max-width:calc(100vw - 22px);max-height:80vh;overflow-y:auto;}}

@media (max-width: 480px) {
  #a11y-panel { right: 12px; bottom: 76px; width: min(360px, calc(100vw - 24px)); }
}
/* Prevent launcher icon clipping and inherited square decoration. */
#a11y-toggle-btn { overflow: hidden; isolation: isolate; background-color: #2563eb; }
#a11y-toggle-btn .a11y-toggle-icon { width: 34px; height: 34px; max-width: 100%; max-height: 100%; fill: none; overflow: visible; flex-shrink: 0; transform: none; }
@media (max-width: 480px) { #a11y-toggle-btn .a11y-toggle-icon { width: 32px; height: 32px; } }
