.th-tool-wrapper { --p-bg: #ffffff; --p-border: #e2e8f0; --p-primary: #3b82f6; --p-text: #0f172a; width: 100%; max-width: 1300px; margin: 0 auto; background: var(--p-bg); border-radius: 20px; padding: 24px; border: 1px solid var(--p-border); box-shadow: 0 10px 25px -5px rgba(0,0,0,0.05); box-sizing: border-box; }
.th-header-main { font-size: 1.6rem; font-weight: 800; color: var(--p-text); margin-bottom: 8px; text-align: center; }
.th-subtitle { color: #64748b; font-size: 0.95rem; padding-bottom: 20px; border-bottom: 1px solid var(--p-border); margin-bottom: 24px; text-align: center; max-width: 800px; margin-left: auto; margin-right: auto; line-height: 1.6; }

/* 布局与面板 */
.th-layout { display: flex; flex-direction: column; gap: 24px; }
.th-panel { display: flex; flex-direction: column; background: #f8fafc; border: 1px solid var(--p-border); border-radius: 16px; overflow: hidden; padding: 0; box-sizing: border-box; }
.th-preview-panel { background: #e2e8f0; padding: 24px; display: flex; align-items: center; justify-content: flex-start; flex-direction: column; box-sizing: border-box; }
.th-panel-title { font-size: 1.05rem; font-weight: 700; color: #334155; padding: 20px; border-bottom: 1px solid var(--p-border); background: #ffffff; margin: 0; }
.th-preview-panel .th-panel-title { background: transparent; border-bottom: none; }

/* 表单与网格 */
.th-config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; padding: 24px; box-sizing: border-box; }
.th-config-section { display: flex; flex-direction: column; }
.th-section-title { font-size: 0.95rem; font-weight: 700; color: #475569; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; border-bottom: 1px dashed #cbd5e1; padding-bottom: 10px; }

.th-form-group { display: flex; flex-direction: column; margin-bottom: 16px; }
.th-label { font-size: 0.85rem; font-weight: 600; color: #64748b; margin-bottom: 8px; }

.th-input, .th-select, .th-textarea { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid #cbd5e1; background: #ffffff; color: var(--p-text); font-size: 0.95rem; outline: none; transition: 0.2s; box-sizing: border-box; }
.th-textarea { resize: vertical; min-height: 200px; font-family: inherit; line-height: 1.6; }
.th-input:focus, .th-select:focus, .th-textarea:focus { border-color: var(--p-primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }

/* 滑块 Range 美化 */
.th-range { -webkit-appearance: none; width: 100%; height: 6px; background: #e2e8f0; border-radius: 3px; outline: none; margin: 10px 0; }
.th-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--p-primary); cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: 0.2s; }
.th-range::-webkit-slider-thumb:hover { transform: scale(1.1); }
.th-val-badge { background: #f1f5f9; border: 1px solid #cbd5e1; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-family: monospace; color: var(--p-primary); font-weight: bold; }

/* 悬浮工具栏 */
.th-theme-picker-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 20px; margin-top: 24px; padding: 16px 24px; background: #ffffff; border: 1px solid var(--p-border); border-radius: 16px; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.05); box-sizing: border-box; width: 100%; max-width: 600px; }
.th-theme-label { font-weight: 700; color: #475569; font-size: 0.95rem; white-space: nowrap; }
.th-theme-group { display: flex; gap: 12px; flex: 1; min-width: 250px; }
.th-select-sm { flex: 1; padding: 8px 10px; border-radius: 6px; border: 1px solid #cbd5e1; background: #f8fafc; color: #0f172a; font-size: 0.85rem; outline: none; font-weight: 600; cursor: pointer; }

/* 按钮 */
.th-btn-primary { background: var(--p-primary); color: white; border: none; padding: 10px 24px; border-radius: 20px; font-weight: 700; font-size: 0.95rem; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 6px; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.th-btn-primary:hover { background: #2563eb; transform: translateY(-1px); }

/* ================= 黑夜模式 (工具自身外壳适配) ================= */
[data-theme="dark"] .th-tool-wrapper { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .th-header-main, [data-theme="dark"] .th-panel-title { color: #f8fafc; }
[data-theme="dark"] .th-panel { background: #0f172a; border-color: #475569; }
[data-theme="dark"] .th-panel-title { background: #1e293b; border-bottom-color: #475569; }
[data-theme="dark"] .th-preview-panel { background: #020617; }
[data-theme="dark"] .th-section-title { border-bottom-color: #334155; }
[data-theme="dark"] .th-label { color: #cbd5e1; }
[data-theme="dark"] .th-input, [data-theme="dark"] .th-select, [data-theme="dark"] .th-textarea { background: #020617; border-color: #475569; color: #f8fafc; }
[data-theme="dark"] .th-range { background: #334155; }
[data-theme="dark"] .th-val-badge { background: #1e293b; border-color: #475569; }
[data-theme="dark"] .th-theme-picker-bar { background: #0f172a; border-color: #475569; }
[data-theme="dark"] .th-theme-label { color: #cbd5e1; }
[data-theme="dark"] .th-select-sm { background: #1e293b; border-color: #475569; color: #f8fafc; }


/* =======================================================
   独立封装的信纸与手写渲染引擎
   ======================================================= */
.th-preview-container { width: 100%; display: flex; justify-content: center; margin-top: 10px; overflow: hidden; box-sizing: border-box; }

.th-paper-wrapper {
    width: 100%;
    max-width: 600px;
    min-height: 848px; /* A4 比例 1:1.414 近似 */
    background-color: #ffffff;
    box-shadow: 0 20px 40px -10px rgba(0,0,0,0.2);
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    transition: background 0.3s ease;
}

/* 纸张材质与划线预设 */
/* 空白纸 */
.th-paper-wrapper[data-paper="blank"] { background: #ffffff; }

/* 泛黄复古纸 */
.th-paper-wrapper[data-paper="old"] { background: #fdf6e3; box-shadow: inset 0 0 100px rgba(139, 69, 19, 0.05), 0 20px 40px -10px rgba(0,0,0,0.2); }

/* 横线笔记本 (通过 JS 动态赋予 inline gradient 控制线高) */
.th-paper-wrapper[data-paper="ruled"] { background-color: #ffffff; }

/* 网格数学纸 (通过 JS 动态赋予 inline gradient) */
.th-paper-wrapper[data-paper="math"] { background-color: #ffffff; }

/* 左侧红线 (仅在 ruled 或 math 时显示) */
.th-paper-margin-line { position: absolute; left: 60px; top: 0; bottom: 0; width: 2px; background: rgba(239, 68, 68, 0.4); display: none; z-index: 1; pointer-events: none; }
.th-paper-wrapper[data-paper="ruled"] .th-paper-margin-line,
.th-paper-wrapper[data-paper="math"] .th-paper-margin-line { display: block; }

/* 文本容器 */
.th-text-content {
    position: relative;
    z-index: 2;
    padding-left: 80px; /* 避开左侧红线 */
    padding-right: 40px;
    padding-bottom: 60px;
    width: 100%;
    box-sizing: border-box;
    /* 基础设定，具体属性受 JS 控制 */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    color: #000080;
    font-family: 'Zhi Mang Xing', cursive;
    font-size: 28px;
    line-height: 40px;
    padding-top: 46px; /* JS 动态控制 */
}

/* 移动端适配 */
@media (max-width: 650px) {
    .th-tool-wrapper { padding: 16px; }
    .th-preview-panel { padding: 16px 0; }
    .th-config-grid { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
    .th-config-section[style] { grid-column: span 1 !important; }
    
    /* 缩小预览纸张 */
    .th-paper-wrapper { min-height: 600px; }
    .th-text-content { padding-left: 60px; padding-right: 20px; }
    .th-paper-margin-line { left: 45px; }
}