/*!
 * fhc_theme 無障礙樣式
 * 所有工具都加上 .fhc-a11y-widget，高對比／灰階等模式不會套用到工具本身。
 */

/* ---------- 共用：僅供螢幕報讀器讀取 ---------- */
.fhc-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ---------- 略過連結（平時隱藏，取得焦點時出現在左上角） ---------- */
.fhc-skip {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2147483000;
}

.fhc-skip-link {
    position: absolute;
    left: -10000px;
    top: 0;
    padding: 0.75rem 1.25rem;
    background: #1a1a1a;
    color: #fff !important;
    font-size: 1rem;
    font-weight: bold;
    line-height: 1.5;
    text-decoration: underline;
    white-space: nowrap;
    border: 3px solid #fff;
    border-radius: 0 0 6px 0;
}

.fhc-skip-link:focus,
.fhc-skip-link:focus-visible {
    left: 0;
    outline: 3px solid var(--fhc-focus-color, #0b4f9c);
    outline-offset: 0;
}

/* ---------- 導盲磚 :::（平時隱藏，取得焦點時才顯示） ---------- */
.fhc-accesskey {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    color: #1a1a1a;
    background: #fff;
    text-decoration: none;
}

.fhc-accesskey:focus,
.fhc-accesskey:focus-visible {
    position: static;
    display: inline-block;
    width: auto;
    height: auto;
    clip: auto;
    padding: 0 0.5em;
    outline: 3px solid var(--fhc-focus-color, #0b4f9c);
}

.fhc-skip-target,
.fhc-no-outline:focus {
    outline: none;
}

/* ---------- 浮動工具列 ---------- */
.fhc-a11y-toolbar {
    position: fixed;
    z-index: 2147482000;
    font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    letter-spacing: normal;
    word-spacing: normal;
    text-align: left;
}

.fhc-a11y-toolbar.fhc-pos-bottom-right { right: 1rem; bottom: 1rem; }
.fhc-a11y-toolbar.fhc-pos-bottom-left { left: 1rem; bottom: 1rem; }
.fhc-a11y-toolbar.fhc-pos-middle-right { right: 0; top: 50%; transform: translateY(-50%); }
.fhc-a11y-toolbar.fhc-pos-middle-left { left: 0; top: 50%; transform: translateY(-50%); }

.fhc-a11y-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    min-width: 48px;
    min-height: 48px;
    padding: 0.4em 0.8em;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #0b4f9c;
    color: #fff;
    font: inherit;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.fhc-a11y-toggle:hover {
    background: #083a73;
}

.fhc-pos-middle-right .fhc-a11y-toggle { border-radius: 999px 0 0 999px; }
.fhc-pos-middle-left .fhc-a11y-toggle { border-radius: 0 999px 999px 0; }

.fhc-a11y-panel {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    width: 17rem;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 6rem);
    overflow: auto;
    background: #fff;
    color: #1a1a1a;
    border: 2px solid #1a1a1a;
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.fhc-a11y-panel[hidden] {
    display: none;
}

.fhc-pos-bottom-right .fhc-a11y-panel,
.fhc-pos-middle-right .fhc-a11y-panel { right: 0; }
.fhc-pos-bottom-left .fhc-a11y-panel,
.fhc-pos-middle-left .fhc-a11y-panel { left: 0; }
.fhc-pos-middle-right .fhc-a11y-panel,
.fhc-pos-middle-left .fhc-a11y-panel { bottom: auto; top: 50%; transform: translateY(-50%); }
.fhc-pos-middle-right .fhc-a11y-panel { right: calc(100% + 0.5rem); }
.fhc-pos-middle-left .fhc-a11y-panel { left: calc(100% + 0.5rem); }

.fhc-a11y-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: #0b4f9c;
    color: #fff;
}

.fhc-a11y-title {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 1.05rem !important;
    font-weight: bold;
    color: #fff !important;
    background: none !important;
    border: 0 !important;
}

.fhc-a11y-close {
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.fhc-a11y-body {
    display: grid;
    gap: 0.5rem;
    padding: 0.75rem;
}

.fhc-a11y-font {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.fhc-a11y-label {
    flex: 1 1 auto;
    font-weight: bold;
}

.fhc-a11y-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.4rem 0.75rem;
    border: 2px solid #555;
    border-radius: 6px;
    background: #fff;
    color: #1a1a1a;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.fhc-a11y-font .fhc-a11y-btn {
    justify-content: center;
    min-width: 44px;
    font-weight: bold;
}

.fhc-a11y-btn:hover {
    background: #eef3fa;
    border-color: #0b4f9c;
}

.fhc-a11y-switch-icon {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 1.25rem;
    border-radius: 999px;
    background: #767676;
    position: relative;
    transition: background-color 0.15s;
}

.fhc-a11y-switch-icon::after {
    content: "";
    position: absolute;
    top: 0.15rem;
    left: 0.15rem;
    width: 0.95rem;
    height: 0.95rem;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.15s;
}

.fhc-a11y-switch[aria-pressed="true"] {
    border-color: #0b4f9c;
    background: #eef3fa;
}

.fhc-a11y-switch[aria-pressed="true"] .fhc-a11y-switch-icon {
    background: #0b4f9c;
}

.fhc-a11y-switch[aria-pressed="true"] .fhc-a11y-switch-icon::after {
    transform: translateX(1rem);
}

.fhc-a11y-reset {
    justify-content: center;
    font-weight: bold;
}

.fhc-a11y-more {
    margin: 0.25rem 0 0;
    text-align: center;
}

.fhc-a11y-more a {
    color: #0b4f9c;
    text-decoration: underline;
}

.fhc-a11y-widget button:focus-visible,
.fhc-a11y-widget a:focus-visible {
    outline: 3px solid var(--fhc-focus-color, #0b4f9c) !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 5px #fff !important;
}

/* ---------- 回到頁首 ---------- */
.fhc-back-to-top {
    position: fixed;
    z-index: 2147481000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #1a1a1a;
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.fhc-back-to-top[hidden] {
    display: none;
}

.fhc-back-to-top.fhc-pos-bottom-right,
.fhc-back-to-top.fhc-pos-middle-right { right: 1rem; bottom: 5rem; }
.fhc-back-to-top.fhc-pos-bottom-left,
.fhc-back-to-top.fhc-pos-middle-left { left: 1rem; bottom: 5rem; }
.fhc-back-to-top.fhc-pos-middle-right,
.fhc-back-to-top.fhc-pos-middle-left { bottom: 1rem; }

/* ---------- 區塊中的工具按鈕 ---------- */
.fhc-a11y-block {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.fhc-a11y-block .fhc-a11y-btn {
    flex: 0 0 auto;
}

/* =================================================================
 * 使用者選擇的顯示模式（加在 <html> 上）
 * ================================================================= */

/* 連結底線與標示 */
html.fhc-underline a:not(.fhc-a11y-widget a):not(.btn) {
    text-decoration: underline !important;
    text-underline-offset: 0.15em;
}

html.fhc-underline a:not(.fhc-a11y-widget a):hover,
html.fhc-underline a:not(.fhc-a11y-widget a):focus {
    text-decoration-thickness: 0.15em !important;
}

/* 文字間距（WCAG 1.4.12：行高 1.5 倍、段落間距 2 倍、字距 0.12 倍、詞距 0.16 倍） */
html.fhc-spacing body *:where(:not(.fhc-a11y-widget, .fhc-a11y-widget *, i, [class*="fa-"])) {
    line-height: 1.5 !important;
    letter-spacing: 0.12em !important;
    word-spacing: 0.16em !important;
}

html.fhc-spacing body p:not(.fhc-a11y-widget *) {
    margin-bottom: 2em !important;
}

/* 停止動畫 */
html.fhc-motion *:not(.fhc-a11y-widget *),
html.fhc-motion *:not(.fhc-a11y-widget *)::before,
html.fhc-motion *:not(.fhc-a11y-widget *)::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* 大游標 */
html.fhc-cursor,
html.fhc-cursor * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M6 3l30 28H22l8 14-6 3-8-14-10 9z' fill='%23000' stroke='%23fff' stroke-width='2.5'/%3E%3C/svg%3E") 6 3, auto !important;
}

html.fhc-cursor a,
html.fhc-cursor button,
html.fhc-cursor [role="button"],
html.fhc-cursor label,
html.fhc-cursor select {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M18 4a4 4 0 0 1 4 4v12l12 2a5 5 0 0 1 4 6l-3 14H17L7 28a4 4 0 0 1 6-5l1 1V8a4 4 0 0 1 4-4z' fill='%23fff' stroke='%23000' stroke-width='2.5'/%3E%3C/svg%3E") 18 4, pointer !important;
}

/* 灰階（只套用到網頁內容，不影響固定位置的工具列） */
html.fhc-grayscale body > *:not(.fhc-a11y-widget) {
    filter: grayscale(100%);
}

/* 高對比：黑底白字、黃色連結 */
html.fhc-contrast,
html.fhc-contrast body {
    background: #000 !important;
}

/* :where() 讓這條規則的權重很低，下方的連結規則才能蓋過 */
html.fhc-contrast body *:where(:not(.fhc-a11y-widget, .fhc-a11y-widget *, img, svg, svg *, video, picture, canvas, iframe)) {
    background-color: #000 !important;
    background-image: none !important;
    color: #fff !important;
    border-color: #fff !important;
    text-shadow: none !important;
    box-shadow: none !important;
}

html.fhc-contrast body a:not(.fhc-a11y-widget a),
html.fhc-contrast body a:not(.fhc-a11y-widget a) * {
    color: #ff0 !important;
    text-decoration: underline !important;
}

html.fhc-contrast body a:not(.fhc-a11y-widget a):hover,
html.fhc-contrast body a:not(.fhc-a11y-widget a):focus {
    color: #000 !important;
    background-color: #ff0 !important;
}

html.fhc-contrast body button:not(.fhc-a11y-widget button),
html.fhc-contrast body input,
html.fhc-contrast body select,
html.fhc-contrast body textarea {
    border: 2px solid #fff !important;
}

html.fhc-contrast body ::placeholder {
    color: #ccc !important;
}

html.fhc-contrast.fhc-focus :focus-visible {
    outline-color: #ff0 !important;
}

/* =================================================================
 * 使用者在作業系統要求「減少動態效果」
 * ================================================================= */
@media (prefers-reduced-motion: reduce) {
    .fhc-a11y-switch-icon,
    .fhc-a11y-switch-icon::after {
        transition: none;
    }
}

/* Windows 高對比模式 */
@media (forced-colors: active) {
    .fhc-a11y-toggle,
    .fhc-a11y-btn,
    .fhc-back-to-top {
        border: 2px solid ButtonText;
    }

    .fhc-a11y-switch[aria-pressed="true"] .fhc-a11y-switch-icon {
        background: Highlight;
    }

    .fhc-skip-link:focus,
    .fhc-accesskey:focus {
        outline: 3px solid CanvasText;
    }
}

/* 列印時不輸出工具 */
@media print {
    .fhc-a11y-widget,
    .fhc-back-to-top {
        display: none !important;
    }
}

/* ===== WCAG 2.2 ===== */

/* 2.4.11 焦點不被遮住：用錨點或 Tab 捲動時，預留固定導覽列的高度（數值由 JS 量測） */
html.fhc-unobscured {
    scroll-padding-top: calc(var(--fhc-sticky-top, 0px) + 8px);
    scroll-padding-bottom: calc(var(--fhc-sticky-bottom, 0px) + 8px);
}

/* 2.5.8 目標尺寸（最小）：點擊範圍至少 24×24 CSS 像素 */
html.fhc-target .fhc-target-fix {
    min-width: 24px;
    min-height: 24px;
    box-sizing: border-box;
}
html.fhc-target a.fhc-target-fix,
html.fhc-target [role="button"].fhc-target-fix,
html.fhc-target summary.fhc-target-fix {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
html.fhc-target .fhc-target-check {
    width: 20px;
    height: 20px;
    margin: 2px;
    vertical-align: middle;
}
