:root {
    --primary: #c0392b;
    /* 传统朱砂红 */
    --primary-hover: #a93226;
    --accent: #2980b9;
    --bg: #f6f4f0;
    /* 宣纸米白底色 */
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #e2ddd5;
    --grid-line: #e8b4b8;
    /* 田字格红线 */
    --radius: 12px;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 16px;
}

/* 顶部导航 */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--primary);
    color: #fff;
    font-size: 22px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-family: "KaiTi", "STKaiti", serif;
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* 卡片通用 */
.card,
.search-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-top: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px dashed var(--border);
}

.card-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
}

.badge {
    background: #fdecea;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.hint {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* 搜索框 */
.search-box {
    display: flex;
    gap: 10px;
}

.search-box input {
    flex: 1;
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--primary);
}

/* 按钮体系 */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #ecf0f1;
    color: var(--text);
}

.btn-secondary:hover {
    background: #dfe6e9;
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: #2471a3;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* 多字切换栏 & 快捷标签 */
.multi-char-bar,
.quick-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.hidden {
    display: none !important;
}

.label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.char-pills,
.quick-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag,
.char-pill {
    padding: 4px 12px;
    border: 1px solid var(--border);
    background: #faf8f5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.15s;
}

.tag:hover,
.char-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.char-pill.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* 双模式主布局 */
.result-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 20px;
    align-items: start;
}

/* 左侧田字格动画区 */
.canvas-wrapper {
    position: relative;
    width: 260px;
    height: 260px;
    margin: 0 auto 14px;
}

.tianzige {
    width: 100%;
    height: 100%;
    border: 2px solid var(--primary);
    background-color: #fffdfa;
    background-image:
        linear-gradient(to right, transparent 49.5%, var(--grid-line) 49.5%, var(--grid-line) 50.5%, transparent 50.5%),
        linear-gradient(to bottom, transparent 49.5%, var(--grid-line) 49.5%, var(--grid-line) 50.5%, transparent 50.5%),
        linear-gradient(45deg, transparent 49.6%, #f3d6d8 49.6%, #f3d6d8 50.4%, transparent 50.4%),
        linear-gradient(-45deg, transparent 49.6%, #f3d6d8 49.6%, #f3d6d8 50.4%, transparent 50.4%);
    border-radius: 6px;
    touch-action: none;
    /* 防止手机端描红时页面滚动 */
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: var(--primary);
    border-radius: 6px;
}

.feedback-text {
    text-align: center;
    font-size: 0.86rem;
    color: var(--text-muted);
    min-height: 24px;
    margin-bottom: 14px;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.speed-select {
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 0.9rem;
    color: var(--text);
}

/* 右侧分步拆解网格 */
.steps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
    gap: 10px;
    max-height: 440px;
    overflow-y: auto;
    padding-right: 4px;
}

.step-item {
    border: 1px solid #e5b8bc;
    background: #fffdfa;
    border-radius: 6px;
    aspect-ratio: 1 / 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image:
        linear-gradient(to right, transparent 49%, #f3d6d8 49%, #f3d6d8 51%, transparent 51%),
        linear-gradient(to bottom, transparent 49%, #f3d6d8 49%, #f3d6d8 51%, transparent 51%);
}

.step-num {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* 3500 字库浏览器 */
.dict-header {
    flex-wrap: wrap;
    gap: 12px;
}

.dict-filter input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 8px;
}

.dict-char-btn {
    aspect-ratio: 1 / 1;
    border: 1px solid var(--border);
    background: #faf8f5;
    border-radius: 6px;
    font-size: 1.25rem;
    font-family: "KaiTi", "STKaiti", serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.dict-char-btn:hover,
.dict-char-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    transform: translateY(-1px);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 18px;
}

.footer {
    text-align: center;
    padding: 28px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* 手机端深度适配 */
@media (max-width: 768px) {
    .result-grid {
        grid-template-columns: 1fr;
    }

    .canvas-wrapper {
        width: 230px;
        height: 230px;
    }

    .search-box {
        flex-direction: column;
    }

    .steps-grid {
        grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
        max-height: none;
    }

    .logo h1 {
        font-size: 1.05rem;
    }
}