/* ============================================================================
 * 檔案名稱：css/content.css（前台閱讀頁 ＋ 後台編輯器共用的內容排版樣式）
 * 對應腳本：content.js
 * 載入順序：CSS 第 2 順位
 * ----------------------------------------------------------------------------
 * 【包含內容（前台與編輯器所見即所得共用）】
 *   1. 文章基礎排版（.bk-doc 標題 H1~H3、段落、粗斜底刪、上下標、行內碼、引言、分隔線）
 *   2. 段落對齊、多層縮排（.bk-ind-1 ~ .bk-ind-8）與清單分層編號（.has-lv）
 *   3. 表格外觀（邊框、表頭、條紋、對齊）、圖片與圖說排版、圖片放大燈箱（.img-lightbox）
 *   4. HTML 沙盒容器、程式碼區塊語法高亮與行號、KaTeX 數學公式排版與編號
 *   5. 分頁線外觀與 @media print 列印換頁規則、連結預覽卡片（Link Card）
 * ============================================================================ */

.bk-doc {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    font-size: var(--ed-content-size, 16.5px);
    line-height: var(--ed-content-line, 1.8);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    color: var(--ed-text, #e2e8f0);
    word-break: break-word;
    overflow-wrap: anywhere;
    caret-color: var(--ed-accent, #38bdf8);
}

/* 區塊基本間距 */
.bk-doc > * {
    margin-top: 0;
    margin-bottom: 0.55em;
    box-sizing: border-box;
}

/* 標題字級與樣式 (H1–H6) */
.bk-doc h1 {
    font-size: 2.0em;
    font-weight: 700;
    line-height: 1.3;
    margin-top: 0.2em;
    margin-bottom: 0.6em;
    letter-spacing: -0.01em;
    color: var(--ed-text, #e2e8f0);
}

.bk-doc h2 {
    font-size: 1.6em;
    font-weight: 700;
    line-height: 1.35;
    margin-top: 1.4em;
    margin-bottom: 0.5em;
    border-bottom: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    padding-bottom: 0.3em;
    color: var(--ed-text, #e2e8f0);
}

.bk-doc h3 {
    font-size: 1.3em;
    font-weight: 650;
    line-height: 1.4;
    margin-top: 1.2em;
    margin-bottom: 0.4em;
    color: var(--ed-text, #e2e8f0);
}

.bk-doc h4 {
    font-size: 1.12em;
    font-weight: 650;
    line-height: 1.45;
    margin-top: 1.0em;
    margin-bottom: 0.35em;
    color: var(--ed-text, #e2e8f0);
}

.bk-doc h5 {
    font-size: 1.0em;
    font-weight: 650;
    line-height: 1.5;
    margin-top: 0.9em;
    margin-bottom: 0.3em;
    color: var(--ed-text, #e2e8f0);
}

.bk-doc h6 {
    font-size: 0.9em;
    font-weight: 600;
    line-height: 1.5;
    margin-top: 0.9em;
    margin-bottom: 0.3em;
    color: var(--ed-text-muted, #94a3b8);
    letter-spacing: 0.04em;
}

/* 段落與清單 */
.bk-doc p {
    margin-top: 0;
    margin-bottom: 0.55em;
    min-height: 1.8em;
}

.bk-doc ul,
.bk-doc ol {
    margin-top: 0.2em;
    margin-bottom: 0.55em;
    padding-left: 1.6em;
}

.bk-doc li {
    margin-bottom: 0.25em;
    line-height: 1.75;
}

/* ============================================================
   一、縮排（段落／標題／引言，每階 2em）
   用 margin 而不是 padding：有框樣式或引言左線時，整個框一起往右移
   ============================================================ */
:is(.bk-doc, .bk-editor-root) .bk-ind-1 { margin-left: 2em; }
:is(.bk-doc, .bk-editor-root) .bk-ind-2 { margin-left: 4em; }
:is(.bk-doc, .bk-editor-root) .bk-ind-3 { margin-left: 6em; }
:is(.bk-doc, .bk-editor-root) .bk-ind-4 { margin-left: 8em; }
:is(.bk-doc, .bk-editor-root) .bk-ind-5 { margin-left: 10em; }
:is(.bk-doc, .bk-editor-root) .bk-ind-6 { margin-left: 12em; }

@media (max-width: 640px) {
    /* 手機寬度有限，每階縮小為 1em */
    :is(.bk-doc, .bk-editor-root) .bk-ind-1 { margin-left: 1em; }
    :is(.bk-doc, .bk-editor-root) .bk-ind-2 { margin-left: 2em; }
    :is(.bk-doc, .bk-editor-root) .bk-ind-3 { margin-left: 3em; }
    :is(.bk-doc, .bk-editor-root) .bk-ind-4 { margin-left: 4em; }
    :is(.bk-doc, .bk-editor-root) .bk-ind-5 { margin-left: 5em; }
    :is(.bk-doc, .bk-editor-root) .bk-ind-6 { margin-left: 6em; }
}

/* ============================================================
   二、清單分層（最多 4 層）
   前台：巢狀 <ul>/<ol>，符號依層級 ● ○ ■、編號 1. a. i.
   ============================================================ */
.bk-doc li > ul,
.bk-doc li > ol {
    margin-top: 0.25em;
    margin-bottom: 0;
}

.bk-doc ul ul { list-style-type: circle; }
.bk-doc ul ul ul { list-style-type: square; }
.bk-doc ul ul ul ul { list-style-type: disc; }
.bk-doc ol ol { list-style-type: lower-alpha; }
.bk-doc ol ol ol { list-style-type: lower-roman; }
.bk-doc ol ol ol ol { list-style-type: decimal; }

/* 編輯器：項目維持同一層 <li data-lv="1～3">（Enter／Backspace 行為不變），符號與編號用 CSS 畫 */
.bk-editor-root :is(ul, ol).has-lv {
    list-style: none;
    counter-reset: bk-l0;
}

.bk-editor-root :is(ul, ol).has-lv > li {
    position: relative;
}

.bk-editor-root :is(ul, ol).has-lv > li[data-lv="1"] { margin-left: 1.6em; }
.bk-editor-root :is(ul, ol).has-lv > li[data-lv="2"] { margin-left: 3.2em; }
.bk-editor-root :is(ul, ol).has-lv > li[data-lv="3"] { margin-left: 4.8em; }

.bk-editor-root :is(ul, ol).has-lv > li::before {
    position: absolute;
    right: 100%;
    margin-right: 0.5em;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.bk-editor-root ul.has-lv > li::before { content: "●"; font-size: 0.5em; line-height: 3.5; }
.bk-editor-root ul.has-lv > li[data-lv="1"]::before { content: "○"; }
.bk-editor-root ul.has-lv > li[data-lv="2"]::before { content: "■"; }

.bk-editor-root ol.has-lv > li { counter-increment: bk-l0; counter-reset: bk-l1; }
.bk-editor-root ol.has-lv > li[data-lv="1"] { counter-increment: bk-l1; counter-reset: bk-l2; }
.bk-editor-root ol.has-lv > li[data-lv="2"] { counter-increment: bk-l2; counter-reset: bk-l3; }
.bk-editor-root ol.has-lv > li[data-lv="3"] { counter-increment: bk-l3; counter-reset: none; }
.bk-editor-root ol.has-lv > li::before { content: counter(bk-l0) "."; }
.bk-editor-root ol.has-lv > li[data-lv="1"]::before { content: counter(bk-l1, lower-alpha) "."; }
.bk-editor-root ol.has-lv > li[data-lv="2"]::before { content: counter(bk-l2, lower-roman) "."; }
.bk-editor-root ol.has-lv > li[data-lv="3"]::before { content: counter(bk-l3) "."; }

/* 引用區塊 */
.bk-doc blockquote {
    margin: 0.8em 0;
    padding: 0.6em 1.1em;
    border-left: 3px solid var(--ed-accent, #38bdf8);
    color: var(--ed-text-muted, #94a3b8);
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    border-radius: 0 var(--ed-radius-sm, 6px) var(--ed-radius-sm, 6px) 0;
    font-style: normal;
}

/* 分隔線 */
.bk-doc hr {
    border: none;
    border-top: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
    margin: 1.6em 0;
    height: 0;
}

/* 行內格式 */
.bk-doc strong {
    font-weight: 700;
    color: inherit;
}

.bk-doc em {
    font-style: italic;
}

.bk-doc u {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.bk-doc s {
    text-decoration: line-through;
    opacity: 0.75;
}

.bk-doc code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.88em;
    padding: 0.18em 0.4em;
    border-radius: var(--ed-radius-sm, 6px);
    background: var(--ed-border, rgba(255, 255, 255, 0.08));
    color: var(--ed-accent, #38bdf8);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.08));
}

/* 程式碼區塊、HTML 原始碼分頁的 <pre><code>：
   要蓋掉 legacy/tinymce_editor.css 全站 `pre > code {... !important}`（JetBrains Mono、line-height 1.6、padding 16px、overflow-x:auto），
   否則上色層與輸入層行高不同（游標逐行偏移）、行號被 code 的 overflow 裁掉 */
.cb-pre > code,
.hb-code-pre > code {
    display: inline !important;
    font: inherit !important;
    white-space: inherit !important;
    word-break: inherit !important;
    overflow-wrap: inherit !important;
    tab-size: inherit !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: none !important;
    color: inherit !important;
    overflow: visible !important;
}

/* 區塊內的 <pre><code> 不套行內程式碼樣式 */
.bk-doc pre code {
    font: inherit;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    color: inherit;
}

.bk-doc mark {
    background: rgba(250, 204, 21, 0.28);
    color: inherit;
    padding: 0.1em 0.25em;
    border-radius: 3px;
}

:is(.bk-doc, .bk-editor-root) a {
    color: var(--ed-accent, #38bdf8);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color var(--ed-transition, 0.15s cubic-bezier(0.4, 0, 0.2, 1));
}

:is(.bk-doc, .bk-editor-root) a:hover {
    color: var(--ed-accent-strong, #00d9ff);
}

:is(.bk-doc, .bk-editor-root) a[target="_blank"]::after,
:is(.bk-doc, .bk-editor-root) a[data-target="_blank"]::after {
    content: "↗";
    font-size: 0.75em;
    margin-left: 2px;
    text-decoration: none;
    display: inline-block;
    line-height: 1;
}

:is(.bk-doc, .bk-editor-root) a.on {
    background: var(--ed-accent-soft, rgba(56, 189, 248, 0.15));
    border-radius: 3px;
}

/* 響應式手機設定 */
@media (max-width: 768px) {
    .bk-doc {
        font-size: 15.5px;
        line-height: 1.75;
        overflow-x: hidden;
    }

    .bk-doc h1 { font-size: 1.75em; }
    .bk-doc h2 { font-size: 1.45em; }
    .bk-doc h3 { font-size: 1.22em; }
    .bk-doc h4 { font-size: 1.08em; }
}
/* ==========================================================================
   表格區塊樣式 (Table Block Styles - 前台與編輯器共用)
   對齊 table_demo.html 規範，支援 12 種配色與亮暗模式
   ========================================================================== */

/* 基礎表格變數 (暗色預設) */
:root, .ed-page, .bk-doc {
    --tb-c: #2f6db5;
    --tb-c-hi: #7cb3f0;
    --tb-c-lo: #23518a;
    --tb-cell: #1a1f29;
    --tb-line: rgba(148, 163, 184, .3);
    --tb-line-soft: rgba(148, 163, 184, .2);
    --tb-head-bg: #24344f;
    --tb-head-col-bg: #1f2b40;
    --tb-head-text: #ffffff;
    --tb-accent-line: rgba(56, 189, 248, .75);
    --tb-hover: #25314a;
    --tb-stripe: #1e2738;
    --tb-solid-head: #0369a1;
    --tb-solid-head-text: #ffffff;
    --tb-solid-head-line: #38bdf8;
    --tb-rule: #cbd5e1;
}

/* 亮色紙張主題 */
.ed-theme-light, .ed-theme-light .bk-doc, [data-theme="light"] .bk-doc, .bk-doc.theme-light {
    --tb-cell: #ffffff;
    --tb-line: rgba(15, 23, 42, .14);
    --tb-line-soft: rgba(15, 23, 42, .08);
    --tb-head-bg: #e2eef8;
    --tb-head-col-bg: #eef4f9;
    --tb-head-text: #0f2135;
    --tb-accent-line: rgba(2, 132, 199, .65);
    --tb-hover: #eaf3fb;
    --tb-stripe: #f3f7fb;
    --tb-solid-head: #0369a1;
    --tb-solid-head-text: #ffffff;
    --tb-solid-head-line: #075985;
    --tb-rule: #1e293b;
}

/* 12 種配色色票設定 */
.bk-table, .tb-block {
    --tb-solid-head: var(--tb-c);
    --tb-solid-head-text: var(--tb-c-text, #fff);
    --tb-solid-head-line: var(--tb-c-hi);
    --tb-accent-line: var(--tb-c-hi);
    --tb-head-col-bg: color-mix(in srgb, var(--tb-c) 16%, var(--tb-cell));
    --tb-stripe: color-mix(in srgb, var(--tb-c) 6%, var(--tb-cell));
    --tb-hover: color-mix(in srgb, var(--tb-c) 13%, var(--tb-cell));
    --ed-accent: var(--tb-c-hi);
    --ed-accent-soft: color-mix(in srgb, var(--tb-c-hi) 20%, transparent);
    --ed-border-strong: color-mix(in srgb, var(--tb-c-hi) 55%, transparent);
}

.ed-theme-light .bk-table, .ed-theme-light .tb-block,
[data-theme="light"] .bk-table, [data-theme="light"] .tb-block {
    --tb-solid-head: var(--tb-c);
    --tb-solid-head-text: var(--tb-c-text, #fff);
    --tb-solid-head-line: var(--tb-c-lo);
    --tb-accent-line: var(--tb-c);
    --tb-head-col-bg: color-mix(in srgb, var(--tb-c) 9%, #fff);
    --tb-stripe: color-mix(in srgb, var(--tb-c) 4%, #fff);
    --tb-hover: color-mix(in srgb, var(--tb-c) 10%, #fff);
    --ed-accent: var(--tb-c);
    --ed-accent-soft: color-mix(in srgb, var(--tb-c) 14%, transparent);
    --ed-border-strong: color-mix(in srgb, var(--tb-c) 50%, transparent);
}

.bk-table.tc-blue, .tb-block.tc-blue { --tb-c: #2f6db5; --tb-c-hi: #7cb3f0; --tb-c-lo: #23518a; }
.bk-table.tc-indigo, .tb-block.tc-indigo { --tb-c: #4f5bb5; --tb-c-hi: #9aa5f0; --tb-c-lo: #3a4490; }
.bk-table.tc-purple, .tb-block.tc-purple { --tb-c: #7559b8; --tb-c-hi: #b9a3f0; --tb-c-lo: #5a4296; }
.bk-table.tc-fuchsia, .tb-block.tc-fuchsia { --tb-c: #a8467c; --tb-c-hi: #e89cc4; --tb-c-lo: #85345f; }
.bk-table.tc-rose, .tb-block.tc-rose { --tb-c: #b84a5c; --tb-c-hi: #f09aa8; --tb-c-lo: #93384a; }
.bk-table.tc-orange, .tb-block.tc-orange { --tb-c: #d0663c; --tb-c-hi: #f5a582; --tb-c-lo: #a24a26; }
.bk-table.tc-amber, .tb-block.tc-amber { --tb-c: #e3a82b; --tb-c-hi: #f5cd6e; --tb-c-lo: #a8720c; --tb-c-text: #2a1c02; }
.bk-table.tc-olive, .tb-block.tc-olive { --tb-c: #5f9a32; --tb-c-hi: #a9dc7c; --tb-c-lo: #457524; }
.bk-table.tc-green, .tb-block.tc-green { --tb-c: #3f8a5a; --tb-c-hi: #8fd4a8; --tb-c-lo: #2f6b45; }
.bk-table.tc-teal, .tb-block.tc-teal { --tb-c: #2f8582; --tb-c-hi: #84d1cc; --tb-c-lo: #236663; }
.bk-table.tc-cyan, .tb-block.tc-cyan { --tb-c: #2f7fa3; --tb-c-hi: #86c9e6; --tb-c-lo: #23637f; }
.bk-table.tc-gray, .tb-block.tc-gray { --tb-c: #5b6678; --tb-c-hi: #b2bccb; --tb-c-lo: #444e5e; }

/* 表格本體容器 */
.bk-table, .tb-block {
    margin: 20px 0 26px;
    position: relative;
    max-width: 100%;
}

.bk-table-caption, .tb-caption {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--ed-text, #e2e8f0);
    margin: 0 0 10px;
    outline: none;
    line-height: 1.6;
}

.bk-table-caption:empty::before, .tb-caption:empty::before {
    content: "表名（選填，空白就不顯示）";
    color: var(--ed-text-muted, #94a3b8);
    opacity: .6;
    font-weight: 400;
}

.bk-table-caption.al-center, .tb-caption.al-center { text-align: center; }
.bk-table-caption.al-right, .tb-caption.al-right { text-align: right; }

.bk-table-frame, .tbx-frame {
    position: relative;
    max-width: 100%;
}

/* 捲動外框：高度永遠不出現捲軸 */
.bk-table-scroll, .tb-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, .35) transparent;
    border: 1px solid var(--tb-line);
    border-radius: 10px;
    transition: box-shadow .15s, border-color .15s;
}

.bk-table-scroll::-webkit-scrollbar, .tb-scroll::-webkit-scrollbar {
    height: 8px;
}

.bk-table-scroll::-webkit-scrollbar-thumb, .tb-scroll::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, .35);
    border-radius: 4px;
}

/* Table 樣式 */
.bk-tb {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    table-layout: fixed;
    font-size: 15px;
    line-height: 1.65;
    color: var(--ed-text, #e2e8f0);
}

.bk-tb td, .bk-tb th {
    border-right: 1px solid var(--tb-line-soft);
    border-bottom: 1px solid var(--tb-line-soft);
    padding: 10px 14px;
    vertical-align: middle;
    text-align: left;
    overflow-wrap: anywhere;
    word-break: break-word;
    outline: none;
    background-color: var(--tb-cell);
    font-weight: 400;
    transition: background-color .12s;
}

.bk-tb .e-r { border-right: 0; }
.bk-tb .e-b { border-bottom: 0; }

.bk-tb th {
    font-weight: 700;
    color: var(--tb-head-text);
}

/* 標題列與標題欄 */
.bk-tb th.h-row {
    background-color: var(--tb-solid-head);
    color: var(--tb-solid-head-text);
    border-bottom: 2px solid var(--tb-solid-head-line);
    border-right-color: rgba(255, 255, 255, .22);
}

.bk-tb th.h-row:empty::before {
    color: var(--tb-solid-head-text);
}

.bk-tb th.h-col {
    background-color: var(--tb-head-col-bg);
    border-right: 2px solid var(--tb-accent-line);
}

.bk-tb td {
    color: var(--ed-text, #e2e8f0);
}

.bk-tb th.h-row.e-b {
    border-bottom: 0;
}

.bk-tb td, .bk-tb th:not(.h-row) {
    border-bottom-color: var(--tb-line);
}

.bk-tb td, .bk-tb th.h-row {
    border-right-color: var(--tb-line);
}

/* 斑馬紋與懸停 */
.bk-tb tr:nth-child(even) > td {
    background-color: var(--tb-stripe);
}

.bk-tb tr:hover > td {
    background-color: var(--tb-hover);
}

.bk-tb th:empty::before {
    content: attr(data-ph);
    color: var(--ed-text-muted, #94a3b8);
    opacity: .55;
    font-weight: 400;
}

.bk-tb .al-center { text-align: center; }
.bk-tb .al-right { text-align: right; }

/* 釘選凍結欄 */
.bk-tb .is-sticky {
    position: sticky;
    left: 0;
    z-index: 1;
}

.bk-table-scroll.is-scrolled .is-sticky {
    box-shadow: 8px 0 12px -8px rgba(0, 0, 0, .45);
}
/* ==========================================================================
   圖片區塊 (Image Block - 前台與編輯器共用)
   ========================================================================== */
.bk-image {
    margin: 20px 0 24px;
    position: relative;
    max-width: 100%;
}

.bk-image.al-left {
    margin-right: auto;
}

.bk-image.al-center {
    margin-left: auto;
    margin-right: auto;
}

.bk-image.al-right {
    margin-left: auto;
}

.bk-image a {
    display: block;
    text-decoration: none;
    color: inherit;
    outline: none;
}

.bk-image-frame {
    position: relative;
    overflow: hidden;
    background: rgba(148, 163, 184, .08);
}

.bk-image-inner {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.bk-image-inner img {
    position: absolute;
    display: block;
    max-width: none;
    user-select: none;
    -webkit-user-drag: none;
}

.bk-image.st-round .bk-image-frame {
    border-radius: var(--ed-card-radius, 10px);
}

.bk-image.st-border .bk-image-frame {
    box-shadow: 0 0 0 1px var(--ed-border-strong, rgba(148, 163, 184, .4));
}

.bk-image.st-shadow .bk-image-frame {
    box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
}

.bk-image.st-border.st-shadow .bk-image-frame {
    box-shadow: 0 0 0 1px var(--ed-border-strong, rgba(148, 163, 184, .4)), 0 12px 32px rgba(0, 0, 0, .35);
}

.ed-theme-light .bk-image.st-shadow .bk-image-frame,
.light-mode .bk-image.st-shadow .bk-image-frame {
    box-shadow: 0 12px 30px rgba(15, 23, 42, .18);
}

.bk-image-caption {
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ed-text-muted, #94a3b8);
    outline: none;
}

.bk-image-caption.al-center { text-align: center; }
.bk-image-caption.al-right { text-align: right; }
.bk-image-caption:empty::before {
    content: "圖說（選填，空白就不顯示）";
    opacity: .6;
}

/* 前台未設連結之圖片框懸停縮放游標 */
.bk-doc .bk-image:not([data-has-link="true"]) .bk-image-frame {
    cursor: zoom-in;
}
/* ==========================================================================
   HTML 區塊樣式 (前台與編輯器共用 - TASK-026)
   ========================================================================== */
.bk-html {
    margin: 28px 0 22px;
    position: relative;
    box-sizing: border-box;
}

.hb-frame {
    position: relative;
    width: 100%;
    overflow: hidden;
    transition: height .15s ease;
    box-sizing: border-box;
}

.hb-frame iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: transparent;
}

.bk-html.st-round .hb-frame,
.bk-html.st-round .hb-code-pane {
    border-radius: var(--ed-radius-lg, 10px);
}

.bk-html.st-border .hb-frame,
.bk-html.st-border .hb-code-pane {
    box-shadow: 0 0 0 1px var(--ed-border-strong, rgba(56, 189, 248, .35));
}

.bk-html.bg-white .hb-frame {
    background: #ffffff;
}

.hb-cap {
    margin-top: 8px;
    text-align: center;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ed-text-muted, #94a3b8);
    outline: none;
    min-height: 1.4em;
}

.hb-cap:empty::before {
    content: "說明文字（選填，空白就不顯示）";
    opacity: .6;
}

.hb-fs {
    position: absolute;
    right: 8px;
    top: 8px;
    z-index: 2;
    width: 30px;
    height: 30px;
    border-radius: var(--ed-radius-md, 8px);
    border: 1px solid var(--ed-border, rgba(255, 255, 255, .15));
    background: var(--ed-bar-bg, rgba(15, 23, 42, .88));
    color: var(--ed-text, #e2e8f0);
    opacity: 0;
    transition: opacity .15s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.hb-block:hover .hb-fs,
.bk-html:hover .hb-fs {
    opacity: 1;
}

@media (hover: none) {
    .hb-fs { opacity: 1; }
}

/* 顯示方式分頁 (view: 'tabs') */
.hb-tabs-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* 結果／原始碼放右邊；左邊同一行放「HTML」標籤，中間放浮動工具列 */
    min-height: 44px;
    gap: 4px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--ed-border, rgba(255, 255, 255, .08));
    padding-bottom: 0;
}

.hb-tab-btn {
    appearance: none;
    background: transparent;
    border: none;
    color: var(--ed-text-muted, #94a3b8);
    font-size: 13px;
    padding: 4px 12px;
    border-radius: var(--ed-radius-sm, 6px);
    cursor: pointer;
    transition: all .15s;
}

.hb-tab-btn:hover {
    color: var(--ed-text, #ffffff);
    background: rgba(255, 255, 255, .05);
}

.hb-tab-btn.on {
    color: var(--ed-accent, #38bdf8);
    background: var(--ed-accent-soft, rgba(56, 189, 248, .15));
    font-weight: 600;
}

.hb-code-pane {
    position: relative;
    background: #070b14;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, .08));
    border-radius: 8px;
    overflow: hidden;
    min-height: 120px;
}

.hb-code-pre {
    margin: 0;
    padding: 14px 16px;
    max-height: 480px;
    overflow: auto;
    font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #e2e8f0;
    white-space: pre;
    tab-size: 2;
}

.hb-code-copy {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    padding: 4px 8px;
    font-size: 11.5px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, .15);
    background: rgba(15, 23, 42, .85);
    color: #e2e8f0;
    cursor: pointer;
    transition: all .15s;
}

.hb-code-copy:hover {
    color: var(--ed-accent, #38bdf8);
    border-color: var(--ed-accent, #38bdf8);
}

.hb-noscript {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 400px;
    background: rgba(15, 23, 42, .4);
    border: 1px dashed var(--ed-border, rgba(255, 255, 255, .15));
    border-radius: 8px;
    color: var(--ed-text-muted, #94a3b8);
    font-size: 13.5px;
}
/* ==========================================================================
   💻 程式碼區塊樣式 (Code Block - TASK-027)
   ========================================================================== */
:root {
    --t-kw: #ff7b72;
    --t-str: #a5d6ff;
    --t-num: #79c0ff;
    --t-com: #8b949e;
    --t-fn: #d2a8ff;
    --t-attr: #ffa657;
    --t-bi: #ffa657;
    --t-tag: #7ee787;
    --t-meta: #79c0ff;
}

.ed-theme-light, .theme-light {
    --t-kw: #cf222e;
    --t-str: #0a3069;
    --t-num: #0550ae;
    --t-com: #6e7781;
    --t-fn: #8250df;
    --t-attr: #953800;
    --t-bi: #953800;
    --t-tag: #116329;
    --t-meta: #0550ae;
}

.cb {
    --cb-bg: #0b1020;
    --cb-head: #111830;
    --cb-line: rgba(255, 255, 255, .07);
    --cb-text: #d6deeb;
    --cb-muted: #5f6b85;
    margin: 22px 0;
    border: 1px solid var(--cb-line);
    border-radius: 10px;
    background: var(--cb-bg);
    overflow: hidden;
    position: relative;
}

.ed-theme-light .cb, .theme-light .cb {
    --cb-bg: #f6f8fa;
    --cb-head: #eef1f5;
    --cb-line: rgba(15, 23, 42, .1);
    --cb-text: #1f2937;
    --cb-muted: #94a3b8;
}

.cb-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 4px 8px 4px 12px;
    background: var(--cb-head);
    border-bottom: 1px solid var(--cb-line);
    font-size: 12.5px;
    color: var(--cb-muted);
}

.cb-head .sp {
    flex: 1;
}

.cb-lang-l {
    color: var(--ed-accent, #38bdf8);
    font-weight: 600;
}

.cb-file-l {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    color: var(--cb-text);
    opacity: .8;
}

.cb-lang {
    background: transparent;
    border: 1px solid transparent;
    color: var(--ed-accent, #38bdf8);
    font: 600 12.5px inherit;
    font-family: inherit;
    border-radius: 6px;
    padding: 3px 4px;
    cursor: pointer;
    outline: none;
}

.cb-lang:hover, .cb-lang:focus {
    border-color: var(--cb-line);
}

.cb-lang option {
    background: var(--ed-panel-bg);
    color: var(--ed-text);
}

.cb-det {
    font-size: 11.5px;
    white-space: nowrap; /* 窄畫面不要被擠成直排 */
}

.cb-file {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--cb-text);
    font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace;
    padding: 3px 6px;
    width: 180px;
    outline: none;
}

.cb-file:hover, .cb-file:focus {
    border-color: var(--cb-line);
}

.cb-file::placeholder {
    color: var(--cb-muted);
}

.cb-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--cb-line);
    border-radius: 6px;
    background: var(--cb-bg);
    color: var(--cb-text);
    font: 12.5px inherit;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
}

.cb-btn .ic {
    width: 14px;
    height: 14px;
    flex: none;
}

.ed-theme-light .cb-btn, .theme-light .cb-btn {
    background: #fff;
    color: #334155;
    border-color: rgba(15, 23, 42, .18);
}

.cb-btn:hover {
    border-color: var(--ed-accent, #38bdf8);
    color: var(--ed-accent, #38bdf8);
}

.cb-btn.ok {
    border-color: #22c55e !important;
    color: #22c55e !important;
}

.cb-del:hover {
    border-color: #ef4444;
    color: #ef4444;
    background: rgba(239, 68, 68, .08);
}

.cb-head .cb-btn + .cb-btn {
    margin-left: 2px;
}

.cb-body {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
}

.cb-area {
    position: relative;
    min-width: 100%;
    width: max-content;
}

.cb.wrap .cb-area {
    width: 100%;
}

.cb-pre, .cb-ta {
    margin: 0;
    padding: 12px 16px 12px 3.6em;
    font: 13.5px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    tab-size: 2;
    white-space: pre;
    color: var(--cb-text);
    letter-spacing: 0;
    word-spacing: 0;
}

.cb.nolines .cb-pre, .cb.nolines .cb-ta {
    padding-left: 16px;
}

.cb.wrap .cb-pre, .cb.wrap .cb-ta {
    white-space: pre-wrap;
    word-break: break-word;
}

.cb-pre {
    counter-reset: ln;
    min-height: 1.7em;
}

.cb-pre .cl {
    display: block;
    position: relative;
    min-height: 1.7em;
}

.cb-pre .cl::before {
    counter-increment: ln;
    content: counter(ln);
    position: absolute;
    left: -3.6em;
    width: 2.6em;
    text-align: right;
    color: var(--cb-muted);
    opacity: .7;
    user-select: none;
}

.cb.nolines .cb-pre .cl::before {
    display: none;
}

.cb-ta {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    resize: none;
    border: 0;
    outline: none;
    background: transparent;
    color: transparent;
    caret-color: var(--ed-accent, #38bdf8);
    overflow: hidden;
}

.cb-ta::selection {
    background: rgba(56, 189, 248, .3);
}

.cb-ta::placeholder {
    color: var(--cb-muted);
}

.cb-cap {
    padding: 6px 14px 8px;
    font-size: 13px;
    color: var(--cb-muted);
    border-top: 1px solid var(--cb-line);
}

.cb-wrapfold {
    position: relative;
}

.cb.folded .cb-body {
    max-height: calc(20 * 23px + 24px);
}

.cb-more {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 72px;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    background: linear-gradient(transparent, var(--cb-bg) 70%);
    z-index: 1;
}

.cb.folded .cb-more {
    display: flex;
}

.cb-more button {
    border: 1px solid var(--cb-line);
    background: var(--cb-head);
    color: var(--cb-text);
    border-radius: 999px;
    padding: 5px 14px;
    font: 12.5px inherit;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
}

.cb-more button:hover {
    border-color: var(--ed-accent, #38bdf8);
    color: var(--ed-accent, #38bdf8);
}

/* highlight.js 語法上色色彩 */
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-type { color: var(--t-kw); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-template-string { color: var(--t-str); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--t-num); }
.hljs-comment, .hljs-quote { color: var(--t-com); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--t-fn); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property { color: var(--t-attr); }
.hljs-built_in, .hljs-title.class_, .hljs-params { color: var(--t-bi); }
.hljs-name, .hljs-tag, .hljs-selector-id, .hljs-selector-class, .hljs-deletion { color: var(--t-tag); }
.hljs-meta, .hljs-subst { color: var(--t-meta); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
/* =========================================================
   數學公式排版樣式（TASK-029: 行內公式 .mi 與公式區塊 .mb）
   ========================================================= */

/* 行內公式 */
.mi {
    display: inline-block;
    padding: 0 3px;
    margin: 0 1px;
    border-radius: 4px;
    cursor: pointer;
    vertical-align: baseline;
    color: inherit;
    transition: background .15s, outline .15s;
}

.mi:hover {
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
}

.mi.on {
    background: var(--ed-accent-soft, rgba(56,189,248,.15));
    outline: 1px solid var(--ed-border-strong, rgba(56,189,248,.35));
}

.mi.err {
    color: var(--ed-danger, #fe5461);
    font-family: monospace;
    font-size: .85em;
}

/* 前台預覽與閱讀器複製手勢 */
.preview .mi,
.preview .mb-out,
.reader-content .mi,
.reader-content .mb-out,
.note-view .mi,
.note-view .mb-out {
    cursor: copy;
}

/* 公式區塊 */
.mb {
    position: relative;
    margin: 14px 0;
    border-radius: var(--ed-radius, 8px);
    border: 1px solid transparent;
    user-select: none;
    transition: border-color .15s, background .15s;
}

.mb-out {
    padding: 10px 56px;
    overflow-x: auto;
    overflow-y: hidden;
    text-align: center;
    cursor: pointer;
    min-height: 48px;
    -webkit-overflow-scrolling: touch;
}

.mb-out .katex-display {
    margin: .3em 0;
}

.mb-view {
    position: relative;
}

.mb-num {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ed-muted, #94a3b8);
    font-size: .95em;
    font-family: inherit;
    pointer-events: none;
}

.mb-out.stale {
    opacity: .35;
}

.mb-empty {
    color: var(--ed-muted, #94a3b8);
    font-size: 14px;
    font-style: italic;
}

.mb-cap {
    text-align: center;
    color: var(--ed-muted, #94a3b8);
    font-size: .85em;
    margin-top: -4px;
    padding-bottom: 6px;
}

/* 手機版 RWD 邊距調整 */
@media (max-width: 600px) {
    .mb-out {
        padding: 10px 36px 10px 4px;
    }
}
/* ==========================================================================
   分頁線 (Pagebreak) 與列印樣式 (TASK-030)
   ========================================================================== */
.pb {
    display: none;
}

@media print {
    .pb {
        display: block !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        visibility: hidden !important;
        page-break-before: always !important;
        break-before: page !important;
    }

    [data-keep="true"],
    [data-keep="1"],
    .bk-table[data-keep="true"],
    .bk-image[data-keep="true"],
    .bk-html[data-keep="true"],
    .cb[data-keep="true"],
    .mb[data-keep="true"],
    .lc[data-keep="true"],
    .lc[data-keep="1"] {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    [data-keep="false"],
    [data-keep="0"] {
        page-break-inside: auto !important;
        break-inside: auto !important;
    }
}
/* ==========================================================================
   連結卡片樣式 (Link Card) (TASK-032)
   對接 design/pagebreak_link_demo.html
   ========================================================================== */
.lc {
    display: flex;
    gap: 14px;
    align-items: stretch;
    margin: 14px 0;
    border: 1px solid var(--ed-border, rgba(255, 255, 255, 0.1));
    border-radius: 10px;
    padding: 12px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    background: rgba(148, 163, 184, .04);
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
}
.lc:hover {
    border-color: var(--ed-border-strong, #38bdf8);
    background: rgba(148, 163, 184, .07);
}
.lc .th {
    width: 84px;
    min-height: 64px;
    flex: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 22px;
    user-select: none;
}
.lc .tx {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.lc .tt {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ed-text, #f1f5f9);
}
.lc .ds {
    color: var(--ed-muted, #94a3b8);
    font-size: 13px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.lc .dm {
    color: var(--ed-muted, #94a3b8);
    font-size: 12px;
    margin-top: auto;
    padding-top: 4px;
}
/* 亮色紙張適配 */
.paper-light .lc, body.paper-light .lc {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #1e293b;
}
.paper-light .lc .tt, body.paper-light .lc .tt {
    color: #0f172a;
}
.paper-light .lc .ds, body.paper-light .lc .ds,
.paper-light .lc .dm, body.paper-light .lc .dm {
    color: #64748b;
}
/* ==========================================================================
   文字區塊對齊與上下標 (TASK-033)
   ========================================================================== */
.bk-al-center,
:is(.bk-doc, .bk-editor-root) .bk-al-center {
    text-align: center;
}
.bk-al-right,
:is(.bk-doc, .bk-editor-root) .bk-al-right {
    text-align: right;
}

/* 上標與下標 */
:is(.bk-doc, .bk-editor-root) sup,
:is(.bk-doc, .bk-editor-root) sub,
sup, sub {
    font-size: 0.75em;
    line-height: 0;
    position: relative;
    vertical-align: baseline;
}
:is(.bk-doc, .bk-editor-root) sup,
sup {
    top: -0.5em;
}
:is(.bk-doc, .bk-editor-root) sub,
sub {
    bottom: -0.25em;
}
/* ==========================================================================
   全站共用燈箱 (Image Lightbox - 前台與編輯器共用)
   ========================================================================== */
.ed-lightbox, .lightbox {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(3, 6, 12, .94);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    user-select: none;
}

.ed-lightbox.show, .lightbox.show {
    display: flex;
}

.ed-lightbox .lb-stage, .lightbox .lb-stage {
    position: relative;
    touch-action: none;
}

.ed-lightbox .lb-frame, .lightbox .lb-frame {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
    transform-origin: 0 0;
    will-change: transform;
}

.ed-lightbox.can-pan .lb-frame, .lightbox.can-pan .lb-frame {
    cursor: grab;
}

.ed-lightbox.panning .lb-frame, .lightbox.panning .lb-frame {
    cursor: grabbing;
}

.ed-lightbox .lb-cap, .lightbox .lb-cap {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, .7);
    color: #cbd5e1;
    font-size: 14px;
    max-width: 80vw;
    text-align: center;
    padding: 4px 12px;
    border-radius: 6px;
    z-index: 2;
    pointer-events: none;
}

.ed-lightbox .lb-x, .lightbox .lb-x {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, .1);
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

.ed-lightbox .lb-x:hover, .lightbox .lb-x:hover {
    background: rgba(255, 255, 255, .2);
}

.ed-lightbox .lb-tools, .lightbox .lb-tools {
    position: absolute;
    bottom: 18px;
    display: flex;
    gap: 6px;
    align-items: center;
    background: rgba(15, 23, 42, .85);
    padding: 6px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .1);
    z-index: 2;
}

.ed-lightbox .lb-tools .sep, .lightbox .lb-tools .sep {
    width: 1px;
    height: 18px;
    background: rgba(255, 255, 255, .15);
    margin: 0 4px;
}

.ed-lightbox .lb-tools .pct, .lightbox .lb-tools .pct {
    min-width: 52px;
    text-align: center;
    color: var(--ed-text);
    font-size: 12.5px;
}

.ed-lightbox .lb-tools button, .lightbox .lb-tools button {
    background: rgba(255, 255, 255, .1);
    border: 0;
    color: var(--ed-text);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s ease;
}

.ed-lightbox .lb-tools button:hover, .lightbox .lb-tools button:hover {
    background: rgba(255, 255, 255, .18);
}

.ed-lightbox .lb-tools button.on, .lightbox .lb-tools button.on {
    background: rgba(56, 189, 248, .25);
    color: #7dd3fc;
}
