/* ========== 基础重置与全局样式 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Microsoft YaHei", "SimSun", serif;
    font-weight: 600;
    background-color: #fefaf0;
    color: #3c2f23;
    line-height: 1.6;
    /* 核心：全局竖排设置 */
    writing-mode: vertical-rl;
    -webkit-writing-mode: vertical-rl;
    text-orientation: mixed;
    -webkit-text-orientation: mixed;
    min-height: 100vh;
    overflow-x: auto;
    overflow-y: auto;
    /* 非均匀渐变纹理 */
    background-image:
        linear-gradient(120deg, rgba(0, 0, 0, 0.01) 0%, transparent 60%),
        linear-gradient(240deg, rgba(0, 0, 0, 0.012) 0%, transparent 70%),
        linear-gradient(45deg, rgba(0, 0, 0, 0.006) 0%, transparent 50%);
    /* 纸张轻微厚度感阴影 */
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.02);
    position: relative;
}

button,
input,
textarea,
select,
option,
label {
    font-family: inherit;
    font-weight: inherit;
}

/* 第一层大颗粒噪声 */
body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    background: rgba(0, 0, 0, 0.02);
    filter: url(#noise-filter-1);
    pointer-events: none;
}

/* 第二层小颗粒噪声 */
body::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    background: rgba(0, 0, 0, 0.015);
    filter: url(#noise-filter-2);
    pointer-events: none;
}

/* 噪声滤镜 */
svg {
    position: absolute;
    width: 0;
    height: 0;
    visibility: hidden;
}

/* ========== 布局容器 ========== */
.app-container {
    display: flex;
    flex-direction: row;
    width: fit-content;
    padding-right: 1em;
}

/* ========== 控制面板 ========== */
.control-panel {
    width: 60em;
    padding: 1em;
    z-index: 10;
    border-left: 1px solid #e0d6c2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5em;
    overflow-y: auto;
}

.control-panel h3 {
    font-weight: 600;
    text-align: center;
    margin: 0.5em 0;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e0d6c2;
    width: 100%;
}

.control-panel h4 {
    font-weight: 600;
    text-align: center;
    margin: 0.3em 0;
    font-size: 0.9em;
    color: #7a6c55;
}

/* ========== 字体设置面板 ========== */
.font-settings-panel,
.layout-settings,
.style-settings {
    width: 100%;
    background-color: #f8f5ee;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 0.5em;
    margin-bottom: 0.5em;
}

.font-tabs {
    display: flex;
    margin-bottom: 0.5em;
    border-bottom: 1px solid #e0d6c2;
}

.font-tab-btn {
    padding: 0.3em 0.5em;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    color: #3c2f23;
    font-size: 0.8em;
    flex: 1;
    text-align: center;
}

.font-tab-btn.active {
    border-bottom: 2px solid #b8a276;
    font-weight: bold;
}

.font-tab-content {
    display: none;
}

.font-tab-content.active {
    display: block;
}

.font-option {
    background-color: #fffef9;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 0.5em;
    margin-bottom: 0.5em;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.8em;
}

.font-option:hover {
    background-color: #f0ebdf;
    border-color: #c9b88a;
}

.font-option.selected {
    background-color: #e6dfc6;
    border-color: #b8a276;
    border-width: 2px;
}

.font-name {
    font-weight: bold;
    margin-bottom: 0.2em;
}

.font-description {
    font-size: 0.7em;
    color: #7a6c55;
}

.file-input-container {
    margin: 0.5em 0;
}

.file-input-label {
    display: inline-block;
    padding: 0.3em 0.5em;
    background-color: #e6dfc6;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.8em;
    text-align: center;
    width: 100%;
}

.file-input-label:hover {
    background-color: #d8ceaa;
}

.file-input {
    display: none;
}

.selected-file {
    margin-top: 0.3em;
    font-size: 0.7em;
    color: #7a6c55;
    word-break: break-all;
}

/* ========== 布局设置 ========== */
.option-group {
    margin-bottom: 0.5em;
}

.option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.3em;
    font-size: 0.8em;
}

.option-row span {
    flex: 1;
}

.option-input {
    width: 3em;
    padding: 0.2em;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    text-align: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.3em;
    cursor: pointer;
    flex: 1;
}

.checkbox-label input {
    margin: 0;
}

input[type="color"] {
    width: 1.5em;
    height: 1.5em;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    cursor: pointer;
}

/* ========== 按钮 ========== */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
    width: 100%;
    margin-top: 0.5em;
}

.action-btn {
    padding: 0.5em;
    background-color: #b8a276;
    border: 1px solid #9c8a62;
    border-radius: 4px;
    color: white;
    font-family: inherit;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.action-btn:hover {
    background-color: #9c8a62;
    transform: translateY(-1px);
}

.apply-font-btn {
    width: auto;
    padding: 0.3em;
    background-color: #8a6d46;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.8em;
    cursor: pointer;
    margin-top: 0.5em;
}

.apply-font-btn:hover {
    background-color: #6b5534;
}

/* ========== 主内容区域 ========== */
.main-content {
    flex: 1;
    min-width: 84em;
    padding: 1em;
    border-left: 1px solid #e0d6c2;
    margin-left: 1em;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ========== 头部样式 ========== */
header {
    text-align: center;
    margin-bottom: 1.5em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid #d4c29e;
}

h1 {
    font-size: 2em;
    font-weight: 600;
    letter-spacing: 0.1em;
    margin-bottom: 0.3em;
    color: #5d4a2e;
}

h2,
h3,
h4 {
    font-weight: 600;
    text-align: center;
    margin: 0.5em 0;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e0d6c2;
}

/* ========== 社交链接容器 ========== */
.social-links {
    width: 100%;
    order: 99;
    /* 放在控制面板最后 */
    margin-top: 0.5em;
    padding-top: 0.5em;
    border-top: 1px solid rgba(224, 214, 194, 0.5);
    display: flex;
    justify-content: center;
    gap: 0.5em;
}

/* 桌面端：社交链接垂直排列 */
.social-links {
    flex-direction: column;
    gap: 0.2em;
}

/* ========== 功能区样式 ========== */
.section {
    margin-bottom: 1.5em;
    padding: 0.8em;
    background-color: #fffef9;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
}

/* ========== 输入输出区域 ========== */
.input-area,
.output-area {
    min-height: 10em;
    min-width: 24em;
}

.vertical-textarea {
    width: 100%;
    min-width: 16em;
    min-height: 98%;
    padding: 0.8em;
    margin: 0.5em 0;
    background-color: #fff;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    font-family: inherit;
    font-size: 1em;
    resize: both;
    /* 允许用户调整大小 */

    /* 竖排输入优化 */
    writing-mode: vertical-rl;
    -webkit-writing-mode: vertical-rl;
    text-orientation: mixed;
    -webkit-text-orientation: mixed;
    overflow-y: auto;
    overflow-x: hidden;

    /* 字符保护 */
    word-break: keep-all;
    white-space: pre-wrap;
    unicode-bidi: plaintext;

    /* 关键：确保文本边界框正确 */
    box-sizing: border-box;
    display: block;
}

/* ========== 图片预览区域 ========== */
.preview-area {
    margin-bottom: 1em;
}

.image-preview {
    background-color: #fefaf0;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 1em;
    min-height: 20em;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.image-preview canvas {
    max-width: 100%;
    max-height: 500px;
    border: 1px solid #e0d6c2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.result-container {
    min-height: 98%;
    min-width: 16em;
    padding: 0.8em;
    background-color: #fff;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    /* 字符保护 */
    word-break: keep-all;
    white-space: pre-wrap;
    unicode-bidi: plaintext;
    line-height: 1.8;
    resize: both;
}

/* ========== 按钮样式 ========== */
.vertical-button {
    writing-mode: vertical-rl;
    -webkit-writing-mode: vertical-rl;
    text-orientation: mixed;
    -webkit-text-orientation: mixed;
    width: auto;
    height: auto;
    padding: 1.5em 0.8em;
    margin: 0.3em;
    background-color: #e6dfc6;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    color: #3c2f23;
    font-family: inherit;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    text-align: center;
}

.vertical-button:hover {
    background-color: #d8ceaa;
    transform: translateY(-1px);
}

.button-group {
    display: flex;
    justify-content: center;
    gap: 0.5em;
    margin-top: 0.5em;
}

#imageGeneratorBtn {
    background-color: #8a6d46;
    color: #fffef9;
}

#imageGeneratorBtn:hover {
    background-color: #6b5534;
}

/* ========== 特殊按钮样式 ========== */
#togglePanelBtn {
    background-color: #b8a276;
    color: #fffef9;
    font-weight: bold;
}

#fontSettingsBtn {
    background-color: #8a6d46;
    color: #fffef9;
    font-weight: bold;
}

#clearCacheBtn {
    background-color: #fccbdb;
    color: #140a2d;
    font-weight: bold;
}

#clearCacheBtn:hover {
    background-color: #a56e7f;
}

/* ========== 篆书字符样式 ========== */
.seal-char {
    font-size: 1.2em;
    color: #8B4513;
    font-weight: bold;
    margin: 0.1em;
    display: inline-block;
}

.comparison {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0.3em 0;
}

.original-char {
    font-size: 1em;
    color: #3c2f23;
}

.converted-char {
    font-size: 1.3em;
    color: #8B4513;
    font-weight: bold;
}

.arrow {
    font-size: 1.1em;
    color: #b8a276;
    margin: 0.2em 0;
}

/* ========== 状态指示器 ========== */
.status-bar {
    font-size: 0.8em;
    color: #666;
    text-align: center;
    margin-top: 1em;
    padding-top: 0.5em;
    border-top: 1px solid #e0d6c2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #4CAF50;
}

.status-good {
    background-color: #4CAF50;
}

.status-warning {
    background-color: #FFC107;
}

.status-error {
    background-color: #F44336;
}

/* ========== 加载动画 ========== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #b8a276;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ========== 面板容器 ========== */
#conversionPanel,
#fontSettingsPanel {
    display: none;
    position: fixed;
    top: 5%;
    left: 20%;
    width: 75%;
    height: 50%;
    border: 2px solid #c9b88a;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    background-color: white;
}

/* 字体设置面板特殊样式 */
#fontSettingsPanel {
    background-color: #fffef9;
    padding: 1.5em;
    overflow-y: auto;
    z-index: 1001;
}

/* 遮罩层 */
.iframe-overlay,
.font-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0%;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.font-overlay {
    z-index: 998;
}

/* 从 seal-image-generator.css 添加的备用遮罩层样式 */
.iframe-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0%;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* 关闭按钮 */
.close-panel-btn {
    position: fixed;
    top: 14%;
    left: 24%;
    z-index: 1002;
    background-color: #b8a276;
    color: white;
    border: none;
    border-radius: 50%;
    width: 2em;
    height: 2em;
    font-size: 1.2em;
    cursor: pointer;
    display: none;
    justify-content: center;
    align-items: center;
}

.close-font-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1003;
    background-color: #b8a276;
    color: white;
    border: none;
    border-radius: 50%;
    width: 1.8em;
    height: 1.8em;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ========== 字体设置界面样式 ========== */
.font-tab {
    display: flex;
    margin-bottom: 1em;
    border-bottom: 1px solid #e0d6c2;
}

.font-tab button {
    padding: 0.5em 1em;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-family: inherit;
    color: #3c2f23;
}

.font-tab button.active {
    border-bottom: 2px solid #b8a276;
    font-weight: bold;
}

.font-preview {
    font-size: 1.2em;
    margin: 0.5em 0;
    text-align: center;
}

.url-input {
    width: 100%;
    padding: 0.5em;
    border: 1px solid #c9b88a;
    border-radius: 4px;
    margin-top: 0.5em;
    font-family: inherit;
}

.font-test-area {
    background-color: #f8f5ee;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 1em;
    margin-top: 1em;
    text-align: center;
}

.font-test-text {
    font-size: 1.1em;
    margin: 0.5em 0;
}

/* ========== 兼容模式样式 ========== */
.character-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 10px 0;
}

.char-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    vertical-align: middle;
   /* border: 1px solid #e0d6c2; */
    background-color: transparent;
    transition: transform 0.2s;
}

.char-img:hover {
    transform: scale(1.2);
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.compatibility-result .char-container {
    display: inline-block;
    margin: 2px;
    position: relative;
    background-color: white;
}

.compatibility-result .char-container.compat-seal-char .char-img {
    filter: sepia(1) saturate(4.8) hue-rotate(344deg) brightness(0.74) contrast(1.08);
}

.compatibility-result .char-container.compat-seal-char .fallback-char {
    color: #8B4513;
    background-color: rgba(139, 69, 19, 0.08);
}

.compatibility-result {
    position: relative;
}

.compatibility-image-layer {
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.compatibility-select-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    color: transparent;
    background: transparent;
    user-select: text;
    -webkit-user-select: text;
    writing-mode: inherit;
    -webkit-writing-mode: inherit;
    text-orientation: inherit;
    -webkit-text-orientation: inherit;
    white-space: pre-wrap;
    cursor: text;
}

.compatibility-select-layer::selection {
    color: transparent;
    background: rgba(184, 162, 118, 0.35);
}

.compatibility-select-layer::-moz-selection {
    color: transparent;
    background: rgba(184, 162, 118, 0.35);
}

.compatibility-settings {
    background-color: #f8f5ee;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 1em;
    margin: 1em 0;
}

.compatibility-test-text {
    min-height: 60px;
    border: 1px dashed #c9b88a;
    border-radius: 4px;
    padding: 1em;
    background-color: #fffef9;
}

.img-loading {
    opacity: 0.6;
    filter: blur(1px);
}

.img-error {
    filter: grayscale(100%);
    opacity: 0.5;
    border-color: #ff6b6b !important;
}

.fallback-char {
    font-size: 1.2em;
    color: #666;
    background-color: #f0f0f0;
    padding: 2px 4px;
    border-radius: 3px;
}

/* ========== 统计信息样式 ========== */
.stats-container {
    background-color: #f8f5ee;
    border: 1px solid #e0d6c2;
    border-radius: 4px;
    padding: 0.8em;
    margin: 0.5em 0;
    text-align: center;
    display: block !important;
}

.stat-item {
    margin: 0.3em 0;
    font-size: 0.9em;
}

.stat-value {
    font-weight: bold;
    color: #8a6d46;
}

/* ========== 工具提示 ========== */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 8em;
    background-color: #3c2f23;
    color: #fff;
    text-align: center;
    border-radius: 3px;
    padding: 0.3em;
    position: absolute;
    z-index: 1;
    left: 120%;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.75em;
    writing-mode: horizontal-tb;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {

    /* 手机横排布局 */
    body {
        writing-mode: horizontal-tb;
        -webkit-writing-mode: horizontal-tb;
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
    }

    .app-container {
        flex-direction: column;
        padding-right: 0;
        height: auto;
    }

    .control-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e0d6c2;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 0.5em;
        order: 2;
        margin-top: 1em;
    }

    .font-settings-panel,
    .layout-settings,
    .style-settings {
        flex: 1;
        min-width: 45%;
        margin: 0.2em;
    }

    .action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .action-btn {
        flex: 1;
        min-width: 120px;
        margin: 0.2em;
    }

    .main-content {
        min-width: 0;
        border-left: none;
        border-top: 1px solid #e0d6c2;
        margin-left: 0;
        padding: 0.5em;
        order: 1;
    }

    .input-area,
    .output-area {
        min-width: 0;
    }

    .vertical-textarea {
        writing-mode: horizontal-tb;
        -webkit-writing-mode: horizontal-tb;
        min-width: 100%;
        height: 6em;
        min-height: 6em;
    }

    .result-container {
        min-width: 0;
    }

    .vertical-button {
        writing-mode: horizontal-tb;
        -webkit-writing-mode: horizontal-tb;
        padding: 0.8em 1.2em;
        margin: 0.2em;
    }

    #conversionPanel,
    #fontSettingsPanel {
        top: 5%;
        left: 5%;
        width: 90%;
        height: 90%;
    }

    .apply-font-btn {
        width: auto;
        min-width: 120px;
        max-width: 200px;
        padding: 1em 1.5em;
        font-size: 1em;
        margin: 1em auto;
    }

    .close-panel-btn {
        top: 4%;
        left: 4%;
    }

    h1 {
        font-size: 1.5em;
    }

    .tooltip .tooltiptext {
        left: 50%;
        top: 120%;
        transform: translateX(-50%);
    }

    .comparison {
        flex-direction: row;
    }

    .original-char,
    .converted-char,
    .arrow {
        margin: 0 0.3em;
    }

    /* 手机端：社交链接水平排列 */
    .social-links {
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* 两列等宽 */
        gap: 0.3em;
        padding: 0.3em;
    }

    .social-links a {
        width: 100%;
        padding: 0.3em 0;
        text-align: center;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .social-links a h4 {
        font-size: 1.4em;
        padding: 0.2em 0.4em;
        margin: 0;
    }

    /* 手机端：兼容模式调整 */
    .char-img {
        width: 20px;
        height: 20px;
    }
    
    /* 从 seal-image-generator.css 添加的图片预览响应式规则 */
    .image-preview {
        min-height: 15em;
    }
    
    .image-preview canvas {
        max-height: 300px;
    }
}

/* 平板设备优化 */
@media (min-width: 769px) and (max-width: 1024px) {
    .result-container {
        line-height: 1;
        padding: 0.6em;
        max-height: 18em;
    }

    .app-container {
        padding-right: 0.5em;
    }

    .main-content {
        padding: 0.8em;
    }

    .vertical-textarea {
        width: 5em;
        height: 18em;
    }

    .close-panel-btn {
        left: 19%;
    }
}

/* 竖排模式下的图片调整 */
@media (min-width: 769px) {
    .compatibility-result .char-container {
        margin: 0.2em 0;
    }

    .char-img {
        width: 1.2em;
        height: 1.2em;
    }
}