* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    text-align: center;
    padding: 20px 10px;
    margin: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
}

h1 { color: #2c3e50; margin-top: 0; }
h3 { color: #2c3e50; }

.hidden { display: none !important; }

/* ========== 图片输入区 ========== */
.paste-area {
    border: 3px dashed #3498db;
    border-radius: 12px;
    padding: 50px 30px;
    background: #f8fbfd;
    color: #7f8c8d;
    transition: all 0.3s;
    cursor: pointer;
    margin: 20px 0;
}
.paste-area.highlight {
    background: #d6eaf8;
    border-color: #2980b9;
    transform: scale(1.01);
}
.paste-icon { font-size: 2.5em; margin-bottom: 10px; }
.paste-text { font-size: 1.2em; font-weight: bold; color: #34495e; }
.divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    color: #95a5a6;
    font-size: 0.9em;
}
.divider::before, .divider::after {
    content: '';
    height: 1px;
    width: 60px;
    background: #d5dbdb;
    margin: 0 12px;
}
.upload-btn {
    display: inline-block;
    padding: 12px 28px;
    background: #3498db;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
    font-size: 1.05em;
}
.upload-btn:hover { background: #2980b9; }
.hint { color: #95a5a6; font-size: 0.9em; margin-top: 12px; }

/* ========== 对齐区 ========== */
.align-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    align-items: center;
    margin: 15px 0;
}
.align-controls label { font-weight: bold; }
input[type="number"] {
    width: 70px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
}

.tip {
    color: #e67e22;
    font-size: 0.95em;
    background: #fef5e7;
    padding: 10px 16px;
    border-radius: 6px;
    display: inline-block;
    margin: 10px 0;
}

.align-canvas-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}
#alignCanvas {
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    max-width: 100%;
    height: auto;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    user-select: none;
}

/* ========== 结果区 - 桌面端左右分栏 ========== */
.split-view {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-top: 20px;
}

@media (min-width: 820px) {
    .split-view {
        flex-direction: row;
        align-items: flex-start;
    }
    .left-panel, .right-panel {
        flex: 1;
        min-width: 0;
    }
}

.panel-label {
    font-weight: bold;
    color: #2c3e50;
    margin: 0 0 10px 0;
    text-align: left;
}

#resultCanvas {
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    max-width: 100%;
    height: auto;
    display: block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ========== 字母网格 ========== */
#letterGridContainer {
    overflow-x: auto;
    padding: 4px 0;
}
.letter-grid {
    border-collapse: collapse;
    margin: 0 auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.4em;
    font-weight: bold;
}
.letter-grid td {
    width: 44px;
    height: 44px;
    text-align: center;
    vertical-align: middle;
    border: 2px solid #fff;
    border-radius: 4px;
    cursor: text;
    outline: none;
    transition: transform 0.1s, box-shadow 0.1s;
}
.letter-grid td:hover {
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5);
}
.letter-grid td:focus {
    border-color: #e74c3c;
    transform: scale(1.08);
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.6);
    z-index: 1;
    position: relative;
}

/* ========== 按钮 ========== */
button {
    padding: 10px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
}
button:hover { background-color: #2980b9; }
button:active { transform: scale(0.98); }
button:disabled { background-color: #95a5a6; cursor: not-allowed; }

.primary-btn {
    background-color: #27ae60;
}
.primary-btn:hover { background-color: #219a52; }

.small-btn {
    background-color: #95a5a6;
    padding: 8px 16px;
    font-size: 0.9em;
    margin-bottom: 10px;
}
.small-btn:hover { background-color: #7f8c8d; }

.solve-btn {
    width: 100%;
    margin-top: 16px;
    padding: 14px;
    background: #27ae60;
    font-size: 1.1em;
    font-weight: bold;
}
.solve-btn:hover { background: #219a52; }

/* ========== 状态提示 ========== */
#result {
    margin-top: 24px;
    font-size: 1.15em;
    font-weight: bold;
    color: #27ae60;
    min-height: 30px;
}
/* ========== 缩放微调条 ========== */
.zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 12px 0 4px 0;
    padding: 10px 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.zoom-label {
    font-weight: bold;
    color: #2c3e50;
    font-size: 0.95em;
}

.zoom-controls input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 260px;
    max-width: 55vw;
    height: 6px;
    border-radius: 3px;
    background: #d5dbdb;
    outline: none;
    cursor: pointer;
}

/* 滑块手柄 - Chrome/Safari */
.zoom-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3498db;
    cursor: grab;
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    transition: background 0.15s;
}
.zoom-controls input[type="range"]::-webkit-slider-thumb:hover {
    background: #2980b9;
}
.zoom-controls input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.05);
}

/* 滑块手柄 - Firefox */
.zoom-controls input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3498db;
    cursor: grab;
    border: 3px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.zoom-controls input[type="range"]::-moz-range-thumb:hover {
    background: #2980b9;
}

/* 加减按钮 */
.zoom-nudge {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    background: #ffffff;
    color: #2c3e50;
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    border: 2px solid #d5dbdb;
    display: flex;
    align-items: center;
    justify-content: center;
}
.zoom-nudge:hover {
    background: #ecf0f1;
    border-color: #3498db;
    color: #3498db;
}

/* 百分比显示 */
.zoom-value {
    min-width: 64px;
    padding: 4px 10px;
    background: #fff;
    border: 1px solid #d5dbdb;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95em;
    font-weight: bold;
    color: #2c3e50;
    text-align: center;
}
/* ========== Emoji 选择器 ========== */
.emoji-picker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 24px 0;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
}

.emoji-picker-label {
    font-weight: bold;
    color: #2c3e50;
    font-size: 0.95em;
    margin-right: 4px;
}

.emoji-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #ffffff;
    color: #2c3e50;
    border: 2px solid #e1e6ea;
    border-radius: 24px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.emoji-option .emoji-icon {
    font-size: 1.3em;
    line-height: 1;
}

.emoji-option:hover {
    border-color: #3498db;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(52, 152, 219, 0.15);
}

.emoji-option.active {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #ffffff;
    border-color: #2980b9;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.35);
}

/* 标题里 emoji 稍大一点 */
#titleEmoji {
    display: inline-block;
    margin-right: 6px;
    vertical-align: -2px;
}

/* ========== 自动对齐按钮 ========== */
.auto-btn {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    font-weight: bold;
}
.auto-btn:hover {
    background: linear-gradient(135deg, #e67e22, #d35400);
}

/* ========== 自动求解开关 ========== */
.auto-solve-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #fff;
    border: 2px solid #e1e6ea;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    color: #2c3e50;
    transition: all 0.2s;
    user-select: none;
}
.auto-solve-toggle:hover {
    border-color: #27ae60;
}
.auto-solve-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #27ae60;
    cursor: pointer;
    margin: 0;
}
.auto-solve-toggle:has(input:checked) {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: #fff;
    border-color: #27ae60;
    box-shadow: 0 3px 10px rgba(39, 174, 96, 0.3);
}
.auto-solve-toggle:has(input:checked) input[type="checkbox"] {
    accent-color: #fff;
}

/* ========== 对齐状态提示 ========== */
.align-status {
    margin: 10px 0;
    min-height: 22px;
    font-size: 0.95em;
    font-weight: 600;
    color: #2980b9;
}
.align-status.success { color: #27ae60; }
.align-status.error   { color: #e74c3c; }
.align-status.loading { color: #e67e22; }
/* ========== 预览区 ========== */
.preview-hint {
    color: #7f8c8d;
    font-size: 0.9em;
    margin: 6px 0 16px 0;
}

.preview-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    margin-top: 10px;
}

@media (min-width: 720px) {
    .preview-layout {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
    }
    .preview-canvas-box { flex: 0 1 auto; max-width: 60%; }
    .preview-controls { flex: 0 0 220px; }
}

#previewCanvas {
    max-width: 100%;
    height: auto;
    display: block;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    background: #fafafa;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.preview-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 1px solid #e9ecef;
    min-width: 220px;
}

.preview-n-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: bold;
    color: #2c3e50;
    font-size: 1em;
    gap: 8px;
}

.preview-n-label input[type="number"] {
    width: 80px;
    padding: 10px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    border: 2px solid #d5dbdb;
    border-radius: 8px;
}
.preview-n-label input[type="number"]:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.solve-big-btn {
    padding: 14px 20px;
    font-size: 1.15em;
    font-weight: bold;
    background: linear-gradient(135deg, #27ae60, #219a52);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}
.solve-big-btn:hover {
    background: linear-gradient(135deg, #219a52, #1e8449);
    box-shadow: 0 6px 16px rgba(39, 174, 96, 0.4);
    transform: translateY(-1px);
}
.solve-big-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(39, 174, 96, 0.3);
}

/* ========== 结果页头部按钮 ========== */
.result-header {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
    margin-bottom: 16px;
}
.result-header .small-btn {
    margin-bottom: 0;
}