/* ============================================================
   字帖网 · 手机端样式
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: #ffffff;
    color: #000000;
    text-align: center;
    font-family: "STHeiti", "Microsoft YaHei", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

img { border: 0; max-width: 100%; }
ul, li, dl, dt, dd { margin: 0; padding: 0; }
li { list-style: none; }

a:link, a:visited { color: #222222; text-decoration: none; }
a:hover { color: #222222; text-decoration: none; }

/* ===== 顶部 logo 条 ===== */
.ztop {
    width: 100%;
    padding: 0;
    background: #fff;
    color: #000;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,0.1);
    position: relative;
}
.writer-info {
    padding: 8px 12px;
    display: flex;
    height: 42px;
    position: relative;
    overflow: hidden;
}
.writer-info .leftLink {
    display: flex;
    height: 100%;
    flex: 1;
    align-items: center;
    vertical-align: middle;
}
.writer-info img { width: 24px; height: 24px; }

.leftLink .cmulu { margin-left: 10px; font-size: 15px; }
.leftLink .cmulu a {
    border: 1px solid #ccc;
    margin: 4px 0;
    padding: 2px 5px;
    text-align: center;
    border-radius: 5px;
}

.moreLink {
    vertical-align: middle;
    display: flex;
    align-items: center;
}
.czext {
    font-size: 15px;
    text-align: center;
    display: inline-block;
    color: #fff;
    padding: 0 10px;
}

/* ===== 蓝色导航条 ===== */
.dhbar {
    margin: 2px auto;
    width: 100%;
    height: auto;
    color: #fff;
    padding: 4px 0 2px 0;
    overflow: hidden;
    background: #00539f;
    text-align: left;
    clear: both;
}
.dhbar ul { margin: 0; padding: 0; }
.dhbar li {
    margin: 1px 5px;
    float: left;
    list-style-type: none;
    width: 80px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: clip;
}
.dhbar a:link, .dhbar a:visited { color: #fff; text-decoration: none; }
.dhbar a:hover { color: #FFFF00; text-decoration: underline; }

:root { --m-nav-h: 56px; }

/* ====== 顶部 header ====== */
header {
    background: #fff;
    width: 100%;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 60;
}
header h1 {
    font-size: 14px;
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    text-align: left;
}
header .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;   /* 给 VIP 角标留空间 */
}
header .actions button,
header .actions .link-btn {
    flex: 1 1 auto;
    min-width: 88px;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: #0f172a;
    text-decoration: none;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    transition: background 0.15s;
}
header .actions button:hover,
header .actions .link-btn:hover { background: #f8fafc; color: #0f172a; }
header .actions .link-btn:visited { color: #0f172a; }
header .actions button.primary {
    background: #0f172a; color: #fff; border-color: #0f172a;
}
header .actions button.primary:hover { background: #1e293b; }
header .actions button:disabled { cursor: not-allowed; opacity: 0.6; }

#vip-status-text { max-width: 58vw; font-size: 11px; }

/* 隐藏 header 里的「＋文本 / ＋图片」——移动端从底部 Tab 栏触发，
   仅视觉隐藏，保证 #btn-add-text.click() 仍能正常执行 */
#btn-add-text,
#btn-add-image {
    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;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ====== 主区域 & 预览 ====== */
main {
    display: block;
    max-width: none;
    padding: 8px 0 calc(var(--m-nav-h) + env(safe-area-inset-bottom, 0px) + 12px);
}
.preview-wrap {
    display: block;
    padding: 8px 10px 0;
    overflow-x: hidden;
}
.page-info {
    font-size: 12px;
    color: #64748b;
    text-align: center;
    margin-bottom: 6px;
}
#pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    position: relative;
}
.zitie-page {
    background: #fff;
    box-shadow: 0 3px 12px rgba(0,0,0,.10);
    display: block;
    flex-shrink: 0;
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
}

/* ====== 多音字箭头 ====== */
.pinyin-arrow {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #cbd5e1;
    color: #475569;
    font-size: 10px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    z-index: 5;
    user-select: none;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.pinyin-arrow:hover { background: #f1f5f9; border-color: #94a3b8; }
.pinyin-arrow.open { background: #0f172a; color: #fff; border-color: #0f172a; }

/* ====== 多音字选择菜单 ====== */
#pinyin-menu {
    position: absolute;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.14);
    padding: 4px 0;
    min-width: 76px;
    z-index: 100;
    font-size: 14px;
    font-family: Arial, "Helvetica Neue", sans-serif;
}
#pinyin-menu.hidden { display: none; }
#pinyin-menu .pinyin-menu-item {
    padding: 6px 14px;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    color: #334155;
    transition: background 0.1s;
}
#pinyin-menu .pinyin-menu-item:hover { background: #f1f5f9; }
#pinyin-menu .pinyin-menu-item.active { background: #0f172a; color: #fff; }

/* ====== 底部设置面板 ====== */
.settings {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: calc(var(--m-nav-h) + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 45vh;
    margin: 0;
    padding: 0 0 14px;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 28px rgba(0,0,0,.16);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 940;
    display: block;
    transform: translateY(120%);
    visibility: hidden;
    transition: transform .26s ease, visibility 0s linear .26s;
}
.settings.m-open {
    transform: translateY(0);
    visibility: visible;
    transition: transform .26s ease, visibility 0s;
}

/* 面板内一次只显示一个设置块 */
.settings .settings-block {
    display: none;
    margin-left: 12px;
    margin-right: 12px;
}
.settings .settings-block.m-active { display: block !important; }

/* 移动端不折叠、隐藏标题 */
.settings-block > h3 { display: none !important; }
.settings-block.collapsed .block-body { display: block !important; }
.settings-block h3 .block-toggle { display: none !important; }

/* 设置块外观 */
.settings-block:not(.sub-block) {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    margin-bottom: 10px;
}
.settings-block.sub-block {
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

/* 依赖开关 / 条件项的隐藏 */
.settings-block.dep-hidden { display: none !important; }
.hidden-item { display: none !important; }

/* 内嵌小面板（页边距、外边框） */
#margin-settings,
#outer-border {
    padding: 10px;
    background: #f1f5f9;
    border-radius: 8px;
}

/* ====== 表单控件 ====== */
.setting-item { margin-bottom: 12px; }
.setting-item:last-child { margin-bottom: 0; }
.setting-item label {
    display: block;
    font-size: 13px;
    color: #334155;
    margin-bottom: 6px;
}
.setting-item input[type="text"],
.setting-item input[type="number"],
.setting-item textarea,
.setting-item select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 16px;           /* 避免 iOS 聚焦放大 */
    font-family: inherit;
    background: #fff;
    outline: none;
}
.setting-item input[type="text"]:focus,
.setting-item textarea:focus,
.setting-item select:focus { border-color: #0f172a; }
.setting-item textarea { resize: vertical; min-height: 80px; }
.setting-item input[type="range"] { width: 100%; accent-color: #0f172a; }
.setting-item input[type="color"] {
    width: 100%;
    height: 36px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
}
.setting-item .range-val {
    float: right;
    color: #64748b;
    font-size: 12px;
    font-weight: 400;
}

/* 左/中/右 对齐按钮组 */
.align-row { display: flex; gap: 6px; }
.align-row button {
    flex: 1;
    padding: 6px 0;
    font-size: 13px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    color: #334155;
    transition: all 0.15s;
}
.align-row button.active {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}

/* 开关 */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
    margin: 3px 0;
    border-bottom: 1px solid #f1f5f9;
}
.switch-row:last-child { border-bottom: none; padding-bottom: 0; }
.switch-row:first-child { padding-top: 0; }
.switch-row span:first-child { font-size: 13px; color: #334155; }
.switch {
    position: relative;
    width: 40px;
    height: 22px;
    background: #cbd5e1;
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}
.switch.on { background: #0f172a; }
.switch::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: left 0.2s;
}
.switch.on::after { left: 20px; }

/* 页边距设置标题行 + 按钮 */
.margin-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #edf2f7;
}
.margin-toggle-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #0f172a;
}
#btn-margin-toggle {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 12px;
    line-height: 1.2;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
    color: #475569;
    transition: background .15s, border-color .15s, color .15s;
}
#btn-margin-reset {
    width: 100%;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: #334155;
    transition: background .15s, border-color .15s;
}
#btn-margin-toggle:hover,
#btn-margin-reset:hover { background: #f8fafc; border-color: #94a3b8; }

/* 背景图方向按钮 */
.bg-move-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}
.bg-move-row { display: flex; gap: 4px; }
.bg-move-btn {
    width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #334155;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s;
}
.bg-move-btn:hover { background: #f8fafc; border-color: #94a3b8; }
.bg-page-mode-btn {
    padding: 6px 0;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    color: #334155;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
}
.bg-page-mode-btn.active {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}

/* ====== 面板头部 ====== */
.m-panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    position: sticky;
    top: 0;
    background: #0f172a;
    color: #fff;
    z-index: 2;
    border-radius: 16px 16px 0 0;
    border-bottom: 1px solid #1e293b;
}
.m-panel-title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}
.m-panel-close {
    border: none;
    background: #fff;
    color: #000;
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
.m-panel-close:active { opacity: .7; }

/* ====== 底部 Tab 栏 ====== */
.mobile-nav {
    display: flex;
    flex-direction: row;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(var(--m-nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 4px env(safe-area-inset-bottom, 0px);
    background: #fff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    z-index: 950;
}
.mobile-nav::-webkit-scrollbar { display: none; }

.m-tab {
    flex: 0 0 auto;
    min-width: 70px;
    height: var(--m-nav-h);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 0 10px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 12px;
    font-family: inherit;
    white-space: nowrap;
    cursor: pointer;
    position: relative;
    overflow: visible !important;
}
.m-tab::before {
    content: "";
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 3px;
    border-radius: 2px;
    background: transparent;
    transition: background .18s;
}
.m-tab.active { color: #0f172a; font-weight: 600; }
.m-tab.active::before { background: #0f172a; }
.m-tab sup {
    color: #dc2626;
    font-size: 10px;
    font-weight: 800;
    margin-left: 1px;
    line-height: 1;
    pointer-events: none;
}
.m-tab.m-action::before { display: none; }

/* ====== 字体选择弹窗 ====== */
.font-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.font-modal.hidden { display: none; }
.font-modal-mask {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,0.4);
}
.font-modal-panel {
    position: relative;
    width: 92vw;
    max-height: 78vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.font-modal-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
    font-size: 14px;
}
.font-modal-header button {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #64748b;
    padding: 0 4px;
}
.font-modal-search { padding: 10px 16px; border-bottom: 1px solid #f1f5f9; }
.font-modal-search input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    outline: none;
    font-size: 14px;
}
.font-modal-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.font-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    border-bottom: 1px solid #f8fafc;
    transition: background 0.1s;
}
.font-item:hover { background: #f1f5f9; }
.font-item.active { background: #eff6ff; color: #1d4ed8; }
.font-item .font-preview {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.font-item .font-name { font-size: 12px; color: #64748b; flex-shrink: 0; }
.font-modal-footer { padding: 8px 16px; border-top: 1px solid #e2e8f0; font-size: 12px; color: #64748b; }

/* ====== 轻量 toast（避开底部 Tab） ====== */
.font-toast {
    position: fixed;
    left: 50%;
    top: auto;
    bottom: calc(var(--m-nav-h) + 30px);
    transform: translateX(-50%);
    max-width: 80vw;
    background: rgba(15,23,42,0.92);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.font-toast.show { opacity: 1; }

/* ====== 文本图层 ====== */
#text-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 202;
}
#text-overlay .text-layer {
    position: absolute;
    padding: 0;
    margin: 0;
    line-height: 1.3;
    white-space: pre-wrap;
    word-break: break-word;
    cursor: move;
    pointer-events: auto;
    user-select: none;
    outline: 1px dashed transparent;
    outline-offset: 2px;
    transition: outline-color 0.12s;
    min-width: 16px;
    min-height: 1em;
    background: transparent;
}
#text-overlay .text-layer.empty {
    min-width: 3em;
    min-height: 1.3em;
    outline-color: #cbd5e1;
}
#text-overlay .text-layer:hover    { outline-color: #94a3b8; }
#text-overlay .text-layer.selected { outline-color: #0f172a; }
#text-overlay .text-layer.dragging { outline-color: #2563eb; cursor: grabbing; }

/* ====== 图片图层 ====== */
#image-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 201;
}
#image-overlay .image-layer {
    position: absolute;
    padding: 0;
    margin: 0;
    cursor: move;
    pointer-events: auto;
    user-select: none;
    box-sizing: border-box;
    transform-origin: center center;
    outline: 1px dashed transparent;
    outline-offset: 2px;
    transition: outline-color 0.12s;
    background: transparent;
}
#image-overlay .image-layer img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}
#image-overlay .image-layer:hover    { outline-color: #94a3b8; }
#image-overlay .image-layer.selected { outline-color: #0f172a; }
#image-overlay .image-layer.dragging { outline-color: #2563eb; cursor: grabbing; }

/* ====== 支付按钮（recharge.js 动态生成的支付表单使用） ====== */
.new-btn-pay {
    color: #ffffff;
    background-color: #1677ff;
    width: 180px;
    font-size: 20px;
    padding: 10px;
    border: none;
    cursor: pointer;
}

/* ====== 打印（保留基本 A4 排版；手机上通常不触发，保险） ====== */
@media print {
    header, .settings, .page-info, .dhbar,
    .pinyin-arrow, #pinyin-menu,
    #text-overlay, #image-overlay { display: none !important; }
    body { background: #fff; }
    main { padding: 0 !important; max-width: none; }
    .preview-wrap { padding: 0 !important; overflow: visible !important; }
    #pages-container { gap: 0 !important; }
    .zitie-page {
        width: 210mm !important;
        height: 297mm !important;
        box-shadow: none !important;
        page-break-after: always;
        break-after: page;
    }
    .zitie-page:last-of-type {
        page-break-after: auto;
        break-after: auto;
    }
    @page { size: A4; margin: 0; }
    html, body { width: 210mm; height: 297mm; }
}