/* ============================================
   主题变量 — 东方水墨美学
   ============================================ */
:root {
    /* 主色：朱砂红系 */
    --primary: #B5453A;
    --primary-light: #D4766C;
    --primary-dark: #8B2E23;
    --primary-bg: rgba(181, 69, 58, 0.06);
    --primary-bg-hover: rgba(181, 69, 58, 0.12);
    --gradient-primary: linear-gradient(135deg, #B5453A, #D4766C);

    /* 辅色：墨青/黛蓝 */
    --accent-cyan: #5B8C8D;
    --accent-blue: #4A6B8A;

    /* 背景：宣纸暖白 */
    --bg-body: #F7F4EF;
    --bg-card: #FFFEF9;
    --bg-header: rgba(255, 254, 249, 0.92);
    --bg-input: #F0EDE6;
    --bg-tag: #EDE9E0;

    /* 文字：墨色层次 */
    --text-primary: #2C2417;
    --text-secondary: #6B5E4F;
    --text-tertiary: #9E9282;
    --text-link: #B5453A;
    --border-color: #E2DDD3;
    --border-focus: #B5453A;

    /* 阴影：温润如墨 */
    --shadow-sm: 0 1px 3px rgba(44, 36, 23, 0.04);
    --shadow-md: 0 4px 12px rgba(44, 36, 23, 0.06);
    --shadow-lg: 0 8px 30px rgba(44, 36, 23, 0.08);
    --shadow-xl: 0 18px 40px rgba(44, 36, 23, 0.10);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;

    --sidebar-width: 420px;
}

/* ============================================
   基础重置
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'SimSun', 'PingFang SC', 'Microsoft YaHei', serif;
    background: var(--bg-body);
    background-image:
        radial-gradient(ellipse at 15% 50%, rgba(181, 69, 58, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 20%, rgba(91, 140, 141, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 90%, rgba(181, 69, 58, 0.02) 0%, transparent 40%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--text-link); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; display: block; }
input, button, textarea, select { font-family: inherit; font-size: inherit; border: none; outline: none; }
button { cursor: pointer; background: none; }

/* ============================================
   页头
   ============================================ */
.site-header {
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-header::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--primary) 20%,
        var(--primary-light) 50%,
        var(--primary) 80%,
        transparent 100%);
    opacity: 0.4;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 20px;
    color: var(--text-primary);
    text-decoration: none;
    flex-shrink: 0;
    letter-spacing: 2px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: var(--gradient-primary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #FFFEF9;
    box-shadow:
        0 2px 8px rgba(181, 69, 58, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    position: relative;
}

.logo-icon::before {
    content: "";
    position: absolute;
    inset: 2px;
    border: 1px solid rgba(255, 254, 249, 0.2);
    border-radius: 2px;
    pointer-events: none;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.5px;
    position: relative;
}

.nav-link:hover {
    color: var(--primary);
    background: var(--primary-bg);
}

.nav-link::after {
    content: "";
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 16px;
    height: 1.5px;
    background: var(--primary);
    border-radius: 1px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link:hover::after {
    transform: translateX(-50%) scaleX(1);
}

/* ============================================
   主容器
   ============================================ */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    flex: 1;
}

.tool-header {
    text-align: center;
    padding: 28px 0 20px;
    position: relative;
}

.tool-header h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: 2px;
}

.tool-header p {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.tool-header::after {
    content: "";
    display: block;
    width: 40px;
    height: 2px;
    background: var(--gradient-primary);
    border-radius: 1px;
    margin: 12px auto 0;
    opacity: 0.5;
}

/* ============================================
   模板选择区
   ============================================ */
.template-section {
    background: var(--bg-card);
    background-image:
        radial-gradient(ellipse at 10% 0%, rgba(181, 69, 58, 0.015) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 100%, rgba(91, 140, 141, 0.015) 0%, transparent 50%);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 20px 24px 24px;
    margin-bottom: 20px;
    position: relative;
}

.template-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0;
}

.tpl-tab {
    padding: 8px 20px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    letter-spacing: 1px;
    position: relative;
}

.tpl-tab:hover {
    color: var(--primary);
    background: var(--primary-bg);
}

.tpl-tab.active {
    color: var(--primary);
    background: var(--primary-bg);
    border-bottom-color: var(--primary);
}

.tpl-tab.active::after {
    content: "";
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.tpl-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-color);
    background: var(--bg-card);
    background-image:
        radial-gradient(ellipse at 30% 20%, rgba(181, 69, 58, 0.02) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(91, 140, 141, 0.02) 0%, transparent 60%);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.tpl-card::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 0%, rgba(181, 69, 58, 0.08) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.tpl-card:hover {
    border-color: var(--primary);
    background: var(--bg-card);
    transform: translateY(-2px);
    box-shadow:
        0 4px 12px rgba(181, 69, 58, 0.08),
        0 1px 3px rgba(44, 36, 23, 0.04);
}

.tpl-card:hover::before {
    opacity: 1;
}

.tpl-card.active {
    border-color: var(--primary);
    background: var(--bg-card);
    background-image:
        radial-gradient(ellipse at 50% 0%, rgba(181, 69, 58, 0.05) 0%, transparent 60%);
    box-shadow:
        0 0 0 2px rgba(181, 69, 58, 0.10),
        0 4px 12px rgba(181, 69, 58, 0.06);
}

.tpl-card.hidden {
    display: none;
}

.tpl-icon {
    font-size: 22px;
    line-height: 1;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tpl-card:hover .tpl-icon {
    transform: scale(1.1);
}

.tpl-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    letter-spacing: 0.5px;
    transition: color 0.3s ease;
}

.tpl-card.active .tpl-name {
    color: var(--primary);
}

/* ============================================
   双栏布局
   ============================================ */
.tool-body {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding-bottom: 40px;
}

/* 左侧设置面板 */
.settings-panel {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    position: sticky;
    top: 80px;
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-card);
    background-image:
        radial-gradient(ellipse at 0% 0%, rgba(181, 69, 58, 0.02) 0%, transparent 40%);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 4px 0;
}

/* 滚动条美化 */
.settings-panel::-webkit-scrollbar {
    width: 4px;
}
.settings-panel::-webkit-scrollbar-track {
    background: transparent;
}
.settings-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
.settings-panel::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
}

/* 设置分区 */
.setting-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.setting-section:last-child {
    border-bottom: none;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 14px;
    letter-spacing: 0.5px;
}

.section-title::before {
    content: "";
    width: 3px;
    height: 14px;
    background: var(--gradient-primary);
    border-radius: 2px;
    flex-shrink: 0;
}

.section-icon {
    font-size: 16px;
}

/* ============================================
   表单控件
   ============================================ */
.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.form-group {
    min-width: 0;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
}

.form-control {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    color: var(--text-primary);
    font-size: 13px;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-control:hover {
    border-color: var(--primary-light);
    background: var(--bg-card);
}

.form-control:focus {
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

select.form-control {
    appearance: none;
    cursor: pointer;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236B5E4F'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

input[type="color"].color-input {
    padding: 3px;
    height: 38px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

input[type="range"] {
    width: 100%;
    height: 6px;
    appearance: none;
    outline: none;
    border-radius: 10px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    margin-top: 4px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 3px solid #FFFEF9;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 1px 5px rgba(181, 69, 58, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

textarea.form-control {
    height: auto;
    padding: 8px 12px;
    resize: vertical;
    line-height: 1.5;
}

/* 类型特定参数显隐 */
.type-specific {
    display: none;
    animation: fadeSlideIn 0.25s ease both;
}

/* ============================================
   折叠面板
   ============================================ */
.collapsible-section {
    border-bottom: 1px solid var(--border-color);
}

.collapsible-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.collapsible-header:hover {
    background: var(--primary-bg);
    color: var(--primary);
    padding-left: 24px;
}

.collapsible-header span:first-child {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-icon {
    color: var(--text-tertiary);
    font-size: 12px;
    transition: transform var(--transition-normal);
}

.toggle-icon.rotated {
    transform: rotate(180deg);
}

.collapsible-content {
    display: none;
    padding: 4px 20px 16px;
    animation: fadeSlideIn 0.25s ease both;
}

/* ============================================
   水印开关
   ============================================ */
.watermark-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    display: none;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 30px;
    background: var(--border-color);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.slider:before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FFFEF9;
    box-shadow: 0 1px 3px rgba(44, 36, 23, 0.15);
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.switch input:checked + .slider {
    background: var(--primary);
    box-shadow: 0 0 8px rgba(181, 69, 58, 0.2);
}

.switch input:checked + .slider:before {
    transform: translateX(20px);
}

.watermark-options {
    display: none;
    padding-top: 12px;
    border-top: 1px dashed var(--border-color);
}

/* ============================================
   右侧预览区
   ============================================ */
.preview-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.preview-wrapper {
    background: var(--bg-card);
    background-image:
        radial-gradient(ellipse at 20% 30%, rgba(181, 69, 58, 0.02) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(91, 140, 141, 0.02) 0%, transparent 50%);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 40px 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
    overflow: auto;
    position: relative;
}

.preview-wrapper::before {
    content: "";
    position: absolute;
    top: 12px;
    right: 12px;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, rgba(181, 69, 58, 0.04) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

#paper-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    background: #fff;
    box-shadow:
        0 2px 8px rgba(44, 36, 23, 0.06),
        0 8px 30px rgba(44, 36, 23, 0.08);
    border-radius: 2px;
    animation: paperAppear 0.5s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* 导出按钮栏 */
.export-bar {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn {
    min-height: 42px;
    padding: 0 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 6px 16px rgba(181, 69, 58, 0.12),
        0 2px 6px rgba(44, 36, 23, 0.06);
}

.btn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-icon {
    font-size: 16px;
}

.btn-primary {
    background: var(--gradient-primary);
    color: #FFFEF9;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
    box-shadow:
        0 6px 20px rgba(181, 69, 58, 0.25),
        0 2px 6px rgba(44, 36, 23, 0.08);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--primary-bg);
    color: var(--primary);
    border-color: var(--primary-light);
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--primary-bg);
    color: var(--primary);
    border-color: var(--primary-light);
}

/* ============================================
   页脚
   ============================================ */
.site-footer {
    text-align: center;
    padding: 24px 20px;
    color: var(--text-tertiary);
    font-size: 13px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    position: relative;
    letter-spacing: 0.5px;
}

.site-footer::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--primary) 20%,
        var(--primary-light) 50%,
        var(--primary) 80%,
        transparent 100%);
    opacity: 0.3;
}

/* ============================================
   动画
   ============================================ */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes paperAppear {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(12px);
        box-shadow: 0 0 0 rgba(44, 36, 23, 0);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
        box-shadow:
            0 2px 8px rgba(44, 36, 23, 0.06),
            0 8px 30px rgba(44, 36, 23, 0.08);
    }
}

@keyframes inkSpread {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================
   响应式
   ============================================ */
@media (max-width: 1100px) {
    .tool-body {
        flex-direction: column;
    }

    .settings-panel {
        width: 100%;
        min-width: 0;
        max-height: none;
        position: static;
    }

    .preview-wrapper {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    .header-inner {
        padding: 0 16px;
        height: 52px;
    }

    .header-nav {
        display: none;
    }

    .logo-text {
        font-size: 17px;
    }

    .container {
        padding: 0 12px;
    }

    .tool-header h1 {
        font-size: 22px;
    }

    .tool-header p {
        font-size: 13px;
    }

    .template-section {
        padding: 14px 14px 18px;
    }

    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }

    .tpl-card {
        padding: 10px 6px;
    }

    .tpl-icon {
        font-size: 18px;
        min-height: 24px;
    }

    .tpl-name {
        font-size: 11px;
    }

    .form-grid.cols-2 {
        grid-template-columns: 1fr;
    }

    .form-grid.cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .setting-section {
        padding: 14px 16px;
    }

    .collapsible-header {
        padding: 12px 16px;
    }

    .collapsible-content {
        padding: 4px 16px 14px;
    }

    .preview-wrapper {
        padding: 20px 12px;
        min-height: 300px;
    }

    .export-bar {
        flex-wrap: wrap;
    }

    .btn {
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .template-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tpl-tab {
        padding: 6px 14px;
        font-size: 12px;
        white-space: nowrap;
    }

    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }
}