/* 田字格字帖生成器 —— 站内样式 */
.tool-content {
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    padding: 1.2em;
    border-radius: .6em;
    position: relative;
}

.tz-app {
    --tz-theme: rgb(93 79 248 / 95%);
    --tz-theme-soft: rgb(93 79 248 / 10%);
    --tz-border: var(--border-color, #e5e7eb);
    --tz-muted: #6b7280;
    --tz-text: #1f2937;
    --tz-scale: 1;
    --tz-g: 18mm;
    --tz-gridline: #c8c0b2;
    --tz-charcolor: #2a2622;
    --tz-font: "KaiTi", "STKaiti", "楷体", serif;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    font-family: var(--font-simple, inherit);
    color: var(--tz-text);
}

/* 左侧预览 */
.tz-preview-panel {
    flex: 1;
    min-width: 0;
}

.tz-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 18px;
    border: 1px solid var(--tz-border);
    border-radius: 8px;
    background: #f3f4f6;
}

.tz-page-frame {
    position: relative;
    flex: none;
}

/* 右侧设置面板 */
.tz-panel {
    width: 320px;
    flex: none;
    box-sizing: border-box;
    padding: 16px;
    border: 1px solid var(--tz-border);
    border-radius: 8px;
    background: #fff;
}

.tz-group {
    margin-bottom: 18px;
}

.tz-group:last-child {
    margin-bottom: 0;
}

.tz-group-title {
    margin: 0 0 11px;
    padding-bottom: 7px;
    border-bottom: 1px dashed var(--tz-border);
    color: var(--tz-theme);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.tz-field {
    display: block;
    margin-bottom: 12px;
}

.tz-field > span {
    display: block;
    margin-bottom: 5px;
    color: var(--tz-muted);
    font-size: 12px;
}

.tz-field textarea,
.tz-field input[type="text"],
.tz-field input[type="number"],
.tz-field select {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--tz-border);
    border-radius: 6px;
    outline: none;
    background: #fff;
    color: var(--tz-text);
    font-family: inherit;
    font-size: 13px;
    transition: border-color .15s, box-shadow .15s;
}

.tz-field textarea:focus,
.tz-field input:focus,
.tz-field select:focus {
    border-color: var(--tz-theme);
    /*box-shadow: 0 0 0 3px var(--tz-theme-soft);*/
}

.tz-field textarea {
    min-height: 74px;
    resize: vertical;
    line-height: 1.7;
}

.tz-row2 {
    display: flex;
    gap: 10px;
}

.tz-row2 > * {
    flex: 1;
    min-width: 0;
}

.tz-seg {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tz-seg button {
    flex: 1;
    min-width: 62px;
    padding: 7px 4px;
    border: 1px solid var(--tz-border);
    border-radius: 6px;
    background: #fff;
    color: var(--tz-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    transition: .15s;
}

.tz-seg button:hover {
    border-color: var(--tz-theme);
    color: var(--tz-theme);
}

.tz-seg button.active {
    border-color: var(--tz-theme);
    background: var(--tz-theme-soft);
    color: var(--tz-theme);
    font-weight: 600;
}

.tz-range-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    color: var(--tz-muted);
    font-size: 12px;
}

.tz-range-head code {
    color: var(--tz-theme);
    font-size: 11px;
}

/* 滑块：完全自定义，避免被 reset.css 的 appearance:none 破坏 */
.tz-field input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    margin: 6px 0;
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    background: linear-gradient(rgb(93 79 248 / 95%), rgb(93 79 248 / 95%)) 0/30% 100% no-repeat #cbd5e1;
}

.tz-field input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: rgb(93 79 248 / 95%);
    cursor: pointer;
    box-shadow: 0 1px 3px rgb(0 0 0 / .2);
}

.tz-field input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: rgb(93 79 248 / 95%);
    cursor: pointer;
    box-shadow: 0 1px 3px rgb(0 0 0 / .2);
}

.tz-field input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 5px;
    background: #cbd5e1;
}

.tz-color-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tz-color-row input[type="color"] {
    width: 34px;
    height: 30px;
    padding: 2px;
    border: 1px solid var(--tz-border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
}

.tz-color-row code {
    color: var(--tz-muted);
    font-size: 10px;
}

.tz-check {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 12.5px;
}

/* 复选框：完全自定义，避免被 reset.css 的 appearance:none 破坏 */
.tz-check input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    flex: none;
    width: 16px;
    height: 16px;
    margin: 0;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    position: relative;
    transition: background .15s, border-color .15s;
}

.tz-check input[type="checkbox"]:checked {
    background: rgb(93 79 248 / 95%);
    border-color: rgb(93 79 248 / 95%);
}

.tz-check input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.tz-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.tz-btn {
    flex: 1;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--tz-border);
    border-radius: 6px;
    background: #fff;
    color: var(--tz-text);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: .15s;
}

.tz-btn:hover {
    border-color: var(--tz-theme);
    color: var(--tz-theme);
}

.tz-btn-primary {
    border-color: var(--tz-theme);
    background: var(--tz-theme);
    color: #fff;
}

.tz-btn-primary:hover {
    background: rgb(93 79 248 / 85%);
    color: #fff;
}

/* 字帖纸张 */
.tz-sheet {
    /* 格宽/格线色/字色/字体由 JS 设置在 .tz-app 上，此处不可再声明同名变量，
       否则会遮蔽动态值导致格子变长方形、颜色字体改不动 */
    --tz-edge-w: .6mm;
    --tz-inner-w: .15mm;
    width: 210mm;
    height: 297mm;
    box-sizing: border-box;
    padding: 12mm;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fffdf8;
    box-shadow: 0 6px 20px rgb(0 0 0 / .14);
    transform: scale(var(--tz-scale));
    transform-origin: top left;
}

.tz-sheet.tz-landscape {
    width: 297mm;
    height: 210mm;
}

.tz-page-head {
    flex: none;
    margin-bottom: 8mm;
}

.tz-title {
    margin: 0 0 2mm;
    color: #3a342c;
    font-family: "KaiTi", "STKaiti", "楷体", serif;
    font-size: 10mm;
    line-height: 1.2;
    letter-spacing: 2.5mm;
    text-align: center;
}

.tz-meta {
    display: flex;
    justify-content: center;
    gap: 18mm;
    color: #6b6459;
    font-size: 4mm;
    letter-spacing: .5mm;
}

.tz-meta i {
    display: inline-block;
    width: 34mm;
    border-bottom: .25mm solid #b9b1a3;
}

.tz-grid {
    display: grid;
    grid-template-columns: repeat(var(--tz-cols), minmax(0, 1fr));
    grid-auto-rows: var(--tz-g);
    align-content: start;
    flex: none;
    border: calc(var(--tz-edge-w) / 2) solid var(--tz-gridline);
}

.tz-cell {
    position: relative;
    width: 100%;
    height: var(--tz-g);
    box-sizing: border-box;
    border: calc(var(--tz-edge-w) / 2) solid var(--tz-gridline);
}

.tz-cell::before,
.tz-cell::after {
    content: "";
    position: absolute;
    background: var(--tz-gridline);
    opacity: .55;
}

.tz-cell::before {
    left: 50%;
    top: 0;
    bottom: 0;
    width: var(--tz-inner-w);
    transform: translateX(-50%);
}

.tz-cell::after {
    top: 50%;
    left: 0;
    right: 0;
    height: var(--tz-inner-w);
    transform: translateY(-50%);
}

.tz-diag {
    position: absolute;
    top: 0;
    left: 0;
    width: 141.421%;
    height: 0;
    border-top: var(--tz-inner-w) dashed var(--tz-gridline);
    opacity: .55;
    transform-origin: 0 0;
    pointer-events: none;
}

.tz-diag.d1 { transform: rotate(45deg); }
.tz-diag.d2 { left: 100%; transform: rotate(135deg); }

.tz-ch {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tz-charcolor);
    font-family: var(--tz-font);
    font-size: calc(var(--tz-g) * .74);
    line-height: 1;
}

.tz-cell.tz-trace .tz-ch {
    opacity: 1;
    color: color-mix(in srgb, var(--tz-charcolor) 26%, #fffdf8);
}

.tz-page-footer {
    flex: none;
    margin-top: auto;
    color: #6b6459;
    font-size: 3.5mm;
    text-align: center;
}

@media (max-width: 900px) {
    .tz-app { flex-direction: column-reverse; }
    .tz-panel { width: 100%; }
    .tz-preview { width: 100%; box-sizing: border-box; }
}

/* 打印：只显示字帖纸张 */
@media print {
    body > *:not(#tz-print-stage) { display: none !important; }
    #tz-print-stage { display: block !important; }
    #tz-print-stage .tz-sheet,
    #tz-print-stage .tz-sheet * { visibility: visible; }
    #tz-print-stage .tz-sheet {
        position: static;
        transform: none !important;
        box-shadow: none !important;
        margin: 0 !important;
        page-break-after: always;
        break-after: page;
    }
    #tz-print-stage .tz-sheet:last-child {
        page-break-after: auto;
        break-after: auto;
    }
    * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
