/* ==========================================================
   字帖生成器 / 汉字字帖 - 专属样式
   仅包含本工具特有部件；通用按钮、卡片、提示等沿用 /style.css
   ========================================================== */

/* 画布类工具需要更宽的排版空间（沿用站内 bead-pattern-generator 等页的做法） */
.tool-page .tool-container {
    max-width: 1200px;
}

.zt-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
    margin-top: 1rem;
}

/* ---------------- 左侧控制面板 ---------------- */

.zt-panel {
    position: sticky;
    top: calc(var(--header-height) + 12px);
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: calc(100vh - var(--header-height) - 28px);
    overflow-y: auto;
}

.zt-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 由「字帖模式」决定显隐的分组：.zt-group 自身是 display:flex，
   作者样式会覆盖 [hidden] 的浏览器默认规则，这里必须显式声明 */
.zt-panel [hidden] {
    display: none !important;
}

/* ---------------- 字帖模式 ---------------- */

#ztMode .zt-chip {
    padding: 0.55rem 0.8rem;
}

.zt-mode-hint {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.55;
    color: var(--text-secondary);
    background: var(--primary-light);
    border-left: 3px solid var(--primary-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.65rem;
}

.zt-group-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    letter-spacing: 0.02em;
}

.zt-group-title i {
    color: var(--primary-color);
}

.zt-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.zt-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ---------------- 选项按钮（chips） ---------------- */

.zt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.zt-chip {
    border: 1px solid var(--border-color);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.zt-chip:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.zt-chip.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

/* 线条颜色：色块预览 */
#ztColor .zt-chip {
    position: relative;
    padding-left: 1.75rem;
}

#ztColor .zt-chip::before {
    content: '';
    position: absolute;
    left: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

#ztColor .zt-chip[data-value="red"]::before { background: #e8a6a6; }
#ztColor .zt-chip[data-value="gray"]::before { background: #c4c4c4; }
#ztColor .zt-chip[data-value="blue"]::before { background: #a8bcdd; }
#ztColor .zt-chip[data-value="green"]::before { background: #a9cba9; }
#ztColor .zt-chip[data-value="dark"]::before { background: #8c8c8c; }

/* 字体：按钮直接用对应字体渲染 */
#ztFont .zt-chip[data-value="kai"] { font-family: "KaiTi", "STKaiti", "Kaiti SC", "楷体", serif; }
#ztFont .zt-chip[data-value="song"] { font-family: "SimSun", "Songti SC", "宋体", serif; }
#ztFont .zt-chip[data-value="hei"] { font-family: "SimHei", "Microsoft YaHei", "黑体", sans-serif; }
#ztFont .zt-chip[data-value="li"] { font-family: "LiSu", "STLiti", "隶书", serif; }
#ztFont .zt-chip[data-value="yuan"] { font-family: "YouYuan", "Yuanti SC", "圆体", sans-serif; }

/* ---------------- 表单控件 ---------------- */

.zt-select,
.zt-input {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition-fast);
}

.zt-select:focus,
.zt-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.zt-textarea {
    width: 100%;
    min-height: 110px;
    padding: 0.65rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.7;
    font-family: inherit;
    resize: vertical;
    transition: var(--transition-fast);
}

.zt-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.zt-range-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.6rem;
}

.zt-range-row input[type="range"] {
    width: 100%;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.zt-range-val {
    font-size: 0.8rem;
    color: var(--primary-color);
    font-weight: 600;
    min-width: 3.6rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.zt-check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.zt-check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.zt-check input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* 内置范文 */
.zt-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.zt-preset-btn {
    border: 1px dashed var(--border-color);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-size: 0.78rem;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.zt-preset-btn:hover {
    border-color: var(--primary-color);
    border-style: solid;
    color: var(--primary-color);
    background: var(--primary-light);
}

/* ---------------- 右侧预览 ---------------- */

.zt-preview {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-width: 0;
}

.zt-stage {
    background: #eef1f5;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    max-height: 78vh;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 260px;
}

.zt-canvas {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
    border-radius: 2px;
}

.zt-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.zt-pager-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid var(--border-color);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.zt-pager-btn:hover:not(:disabled) {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.zt-pager-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.zt-page-info {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 6.5rem;
    text-align: center;
}

.zt-meta {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.zt-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
}

.zt-actions .btn {
    flex: 1 1 150px;
}

/* ---------------- 字表信息 ---------------- */

.zt-info-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 400;
}

.zt-table-wrap {
    overflow-x: auto;
}

.zt-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.zt-table th,
.zt-table td {
    border: 1px solid var(--border-color);
    padding: 0.45rem 0.6rem;
    text-align: center;
    color: var(--text-secondary);
    white-space: nowrap;
}

.zt-table th {
    background: var(--bg-light);
    color: var(--text-primary);
    font-weight: 600;
}

.zt-table tbody tr:nth-child(even) {
    background: #fcfcfd;
}

.zt-td-char {
    font-family: "KaiTi", "STKaiti", "楷体", serif;
    font-size: 1.15rem;
    color: var(--text-primary);
}

/* ---------------- 提示气泡配色（.toast 在 style.css 中只有默认色） ---------------- */

.toast.success { background-color: var(--success-color); }
.toast.error { background-color: var(--danger-color); }

/* ---------------- 打印 ---------------- */

#ztPrintRoot {
    display: none;
}

@media print {
    body > *:not(#ztPrintRoot) {
        display: none !important;
    }

    #ztPrintRoot {
        display: block !important;
    }

    #ztPrintRoot canvas {
        display: block;
        page-break-after: always;
        break-after: page;
    }

    #ztPrintRoot canvas:last-child {
        page-break-after: auto;
        break-after: auto;
    }
}

/* ---------------- 响应式 ---------------- */

@media (max-width: 1024px) {
    .tool-page .tool-container {
        max-width: 900px;
    }

    .zt-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .zt-panel {
        position: static;
        max-height: none;
        overflow: visible;
    }
}

@media (max-width: 768px) {
    .zt-stage {
        padding: 0.6rem;
        min-height: 200px;
        max-height: 66vh;
    }

    .zt-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .zt-actions .btn {
        flex: none;
        width: auto;
        min-width: 0;
        padding: 0.6rem 0.5rem;
        font-size: 0.88rem;
    }

    .zt-actions .btn:first-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 400px) {
    .zt-actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .zt-actions .btn:first-child {
        grid-column: auto;
    }

    .zt-chip {
        font-size: 0.8rem;
        padding: 0.45rem 0.6rem;
    }
}
