/**
 * modal.css - 设置弹窗样式
 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal.hidden {
    display: none;
}
.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: modalSlideIn 0.3s ease;
}
/* 设置弹窗不应用 UI/文字透明效果（文字背景透明度仍生效）：
   覆盖派生变量为 base 实色，保证设置页始终清晰可读 */
.modal-content,
.settings-modal-content,
.image-edit-modal-content {
    --bg-card: var(--bg-card-base);
    --surface-color: var(--surface-base);
    --border-color: var(--border-base);
    --text-color: var(--text-base);
    --text-light: var(--text-light-base);
    --text-muted: var(--text-muted-base);
}
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h2 {
    font-size: calc(18px * var(--font-scale));
    color: var(--text-color);
}
.close-btn {
    background: none;
    border: none;
    font-size: calc(24px * var(--font-scale));
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}
.close-btn:hover {
    background: var(--bg-color);
    color: var(--text-color);
}
.modal-body {
    padding: 24px;
}
.setting-group {
    margin-bottom: 24px;
}
.setting-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.setting-group-header .setting-label {
    margin-bottom: 0;
}
.setting-sub-group {
    margin-bottom: 16px;
}
.setting-sub-group:last-child {
    margin-bottom: 0;
}
.btn-reset-mini {
    padding: 4px 12px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: calc(12px * var(--font-scale));
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-reset-mini:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--bg-color);
}
.setting-label {
    display: block;
    font-size: calc(14px * var(--font-scale));
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 12px;
}
.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}
.color-picker {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    padding: 4px;
}
.color-value {
    font-family: monospace;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-light);
    background: var(--bg-color);
    padding: 6px 12px;
    border-radius: 6px;
}
.layout-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.layout-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.layout-option:hover {
    border-color: var(--primary-light);
}
.layout-option input[type="radio"] {
    accent-color: var(--primary-color);
}
.layout-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.05);
}
.setting-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}
.btn-primary {
    flex: 1;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: calc(15px * var(--font-scale));
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(30, 136, 229, 0.4);
}
.btn-secondary {
    padding: 12px 24px;
    background: var(--bg-color);
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: calc(15px * var(--font-scale));
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
/* 迷你按钮（字体上传等） */
.btn-mini {
    padding: 6px 14px;
    background: var(--bg-color);
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: calc(13px * var(--font-scale));
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn-mini:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
/* 透明度滑块样式 */
.opacity-value {
    color: var(--primary-color);
    font-weight: 600;
    margin-left: 8px;
}
.opacity-wrapper {
    display: flex;
    align-items: center;
    gap: 16px;
}
.opacity-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}
.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}
.opacity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}
.opacity-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}
.opacity-preview {
    width: 60px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(12px * var(--font-scale));
    color: #ffffff;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    /* JS 设置带透明度的 background-color；棋盘格放在 ::before 之后，
       透明部分可透出棋盘格，从而直观显示透明度 */
    position: relative;
    overflow: hidden;
    isolation: isolate;
    transition: background-color 0.1s ease;
}
.opacity-preview::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background-image:
        linear-gradient(45deg, #c8d2e0 25%, transparent 25%, transparent 75%, #c8d2e0 75%),
        linear-gradient(45deg, #c8d2e0 25%, transparent 25%, transparent 75%, #c8d2e0 75%);
    background-size: 12px 12px;
    background-position: 0 0, 6px 6px;
    background-color: #ffffff;
}

/* ============ 设置弹窗：左右两栏布局 ============ */
.settings-modal-content {
    width: 780px;
    max-width: 92vw;
    height: 520px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}
.settings-layout {
    display: flex;
    flex: 1;
    min-height: 0;
}
/* 左侧侧边栏 */
.settings-sidebar {
    width: 200px;
    background: var(--bg-color);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.settings-nav-group {
    display: flex;
    flex-direction: column;
}
/* 侧栏底部按钮区 */
.settings-sidebar-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.settings-sidebar-actions .btn-primary,
.settings-sidebar-actions .btn-secondary {
    flex: none;
    width: 100%;
    padding: 10px 16px;
    font-size: calc(14px * var(--font-scale));
}
.settings-nav-title {
    font-size: calc(11px * var(--font-scale));
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 8px 20px;
    margin-bottom: 4px;
}
.settings-nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 8px;
}
.settings-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-light);
    font-weight: 500;
    transition: all 0.15s ease;
    user-select: none;
}
.settings-nav-item:hover {
    background: rgba(30, 136, 229, 0.08);
    color: var(--text-color);
}
.settings-nav-item.active {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(30, 136, 229, 0.25);
}
.settings-nav-item.active .nav-item-icon {
    opacity: 1;
}
.nav-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    opacity: 0.8;
    flex-shrink: 0;
}
.nav-item-label {
    line-height: 1;
}
/* 右侧内容面板 */
.settings-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}
/* 美化设置面板滚动条（WebKit） */
.settings-content::-webkit-scrollbar {
    width: 8px;
}
.settings-content::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}
.settings-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
    transition: background 0.2s;
}
.settings-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
    background-clip: content-box;
}
.settings-content .modal-body {
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
}
.settings-panel {
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
    scroll-margin-top: 8px;
}
@keyframes panelFadeIn {
    from {
        opacity: 0;
        transform: translateX(6px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}
.panel-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}
.panel-title {
    font-size: calc(18px * var(--font-scale));
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}
.panel-desc {
    font-size: calc(13px * var(--font-scale));
    color: var(--text-muted);
    line-height: 1.5;
}
.panel-section {
    flex: 1;
}
/* 布局选项标题+描述 */
.layout-option-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.layout-option-title {
    font-size: calc(14px * var(--font-scale));
    font-weight: 600;
    color: var(--text-color);
}
.layout-option-desc {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
}

/* ============ 新增：主题模式切换 ============ */
.theme-mode-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.theme-mode-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 8px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.theme-mode-option:hover {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.04);
}
.theme-mode-option input[type="radio"] {
    position: absolute;
    top: 8px;
    right: 8px;
    accent-color: var(--primary-color);
}
.theme-mode-option input[type="radio"]:checked ~ .theme-mode-preview {
    transform: scale(1.1);
}
.theme-mode-option input[type="radio"]:checked ~ .theme-mode-name {
    color: var(--primary-color);
    font-weight: 600;
}
.theme-mode-option input[type="radio"]:checked ~ * {
    /* parent will be highlighted */
}
.theme-mode-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.08);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
}
.theme-mode-preview {
    width: 56px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(20px * var(--font-scale));
    transition: transform 0.2s ease;
}
.theme-mode-light {
    background: linear-gradient(135deg, #fffbe6 0%, #ffffff 100%);
    border: 1px solid #f0e6c8;
}
.theme-mode-dark {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid #2a2a4a;
}
.theme-mode-system {
    background: linear-gradient(135deg, #ffffff 0%, #1a1a2e 100%);
    border: 1px solid var(--border-color);
}
.theme-mode-name {
    font-size: calc(13px * var(--font-scale));
    color: var(--text-light);
    transition: color 0.2s ease;
}

/* ============ 新增：字体预览 ============ */
.font-preview {
    width: 80px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-color);
    font-weight: 500;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============ 新增：卡片间距选项 ============ */
.gap-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.gap-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: calc(13px * var(--font-scale));
    color: var(--text-light);
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
}
.gap-option input[type="radio"] {
    accent-color: var(--primary-color);
}
.gap-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.08);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
}

/* ============ 新增：背景图片上传区 ============ */
.bg-upload-zone {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.bg-history-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.bg-history-title > span:first-child {
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    color: var(--text-color);
}
.bg-history-hint {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
}
.bg-history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 10px;
    padding: 12px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    min-height: 110px;
}
.bg-history-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px 0;
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
}
.bg-history-item {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--border-color);
    transition: all 0.2s ease;
}
.bg-history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.bg-history-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.15);
}
.bg-history-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.bg-history-item .bg-del {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(220, 53, 69, 0.95);
    color: #fff;
    border: none;
    font-size: calc(12px * var(--font-scale));
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.bg-history-item:hover .bg-del {
    opacity: 1;
}
.bg-history-item .bg-active-badge {
    position: absolute;
    bottom: 3px;
    left: 3px;
    background: var(--primary-color);
    color: #fff;
    font-size: calc(10px * var(--font-scale));
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}
.setting-hint {
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 8px;
}

/* ============ 新增：通用-最大保存数量 ============ */
.max-count-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.max-count-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.max-count-option {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    padding: 10px 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: calc(14px * var(--font-scale));
    font-weight: 600;
    color: var(--text-light);
    transition: all 0.2s ease;
    position: relative;
}
.max-count-option input[type="radio"] {
    accent-color: var(--primary-color);
    margin-right: 4px;
}
.max-count-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.08);
    color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
}

/* ============ 新增：图片编辑子弹窗 ============ */
.image-edit-modal-content {
    width: 520px;
    max-width: 92vw;
    height: 580px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}
.image-edit-modal-content .modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.image-preview-wrapper {
    width: 100%;
    margin-bottom: 20px;
}
.image-preview-box {
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    overflow: hidden;
    background:
        linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
        linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #fafafa;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    position: relative;
}
.image-preview-box.dragging {
    cursor: grabbing;
}
.image-preview-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transform-origin: center center;
    pointer-events: none;
}
/* 预览区工具栏 */
.image-preview-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    justify-content: center;
}
.preview-toolbar-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: pointer;
    font-size: calc(16px * var(--font-scale));
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.preview-toolbar-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: rgba(30, 136, 229, 0.06);
}
.preview-zoom-label {
    min-width: 52px;
    text-align: center;
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    color: var(--text-color);
}
.preview-hint {
    text-align: center;
    font-size: calc(12px * var(--font-scale));
    color: var(--text-muted);
    margin-top: 6px;
}

/* 图片大小模式图标 */
.bg-size-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.bg-size-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    font-size: calc(12px * var(--font-scale));
    color: var(--text-light);
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
}
.bg-size-option input[type="radio"] {
    position: absolute;
    top: 6px;
    right: 6px;
    accent-color: var(--primary-color);
    width: 14px;
    height: 14px;
}
.bg-size-option:has(input:checked) {
    border-color: var(--primary-color);
    background: rgba(30, 136, 229, 0.08);
    color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
}
.bg-size-icon {
    width: 44px;
    height: 32px;
    border: 1.5px solid var(--text-muted);
    border-radius: 4px;
    position: relative;
    background:
        linear-gradient(135deg, rgba(30, 136, 229, 0.25) 0%, rgba(30, 136, 229, 0.15) 100%);
}
.bg-size-icon.cover::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: rgba(30, 136, 229, 0.35);
    border-radius: 3px;
}
.bg-size-icon.contain::after {
    content: '';
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 6px;
    right: 6px;
    background: rgba(30, 136, 229, 0.4);
    border-radius: 2px;
}
.bg-size-icon.stretch::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(30, 136, 229, 0.4);
    border-radius: 2px;
}
.bg-size-icon.tile {
    background-image:
        linear-gradient(rgba(30,136,229,0.35) 50%, transparent 50%),
        linear-gradient(90deg, rgba(30,136,229,0.35) 50%, transparent 50%);
    background-size: 50% 50%;
}

/* 九宫格位置按钮 */
.bg-position-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 260px;
}
.pos-btn {
    aspect-ratio: 1 / 1;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    cursor: pointer;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-light);
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-weight: 600;
}
.pos-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary-color);
}
.pos-btn.active {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: #fff;
    box-shadow: 0 2px 8px rgba(30, 136, 229, 0.3);
}

/* 响应式：小屏时改为上下布局 */
@media (max-width: 560px) {
    .theme-mode-options {
        grid-template-columns: 1fr 1fr 1fr;
    }
    .bg-size-options {
        grid-template-columns: 1fr 1fr;
    }
    .settings-modal-content {
        max-width: 95%;
        min-height: auto;
    }
}

/* ============ 通用设置：搜索历史条数输入框 ============ */
.history-count-input {
    width: 90px;
    padding: 8px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-color);
    background: var(--bg-color);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.history-count-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.12);
}

/* ============ 通用设置：默认搜索引擎下拉 ============ */
.engine-select {
    min-width: 200px;
    padding: 8px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    font-size: calc(14px * var(--font-scale));
    color: var(--text-color);
    background: var(--bg-color);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.engine-select:hover {
    border-color: var(--primary-light);
}
.engine-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.12);
}
.engine-select option {
    background: var(--bg-card);
    color: var(--text-color);
}

/* ============ 标签页快捷切换：Toggle 左右滑动开关 ============ */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
    margin: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: #d0d5dd;
    border-radius: 26px;
    transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25), 0 0 0 0 rgba(30, 136, 229, 0);
}
/* 开启状态 */
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary-color);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15), 0 0 8px rgba(30, 136, 229, 0.3);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
/* 禁用（置灰）状态 */
.toggle-switch.disabled {
    cursor: not-allowed;
}
.toggle-switch.disabled .toggle-slider {
    background: #e4e7ec;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}
.toggle-switch.disabled .toggle-slider::before {
    background: #f0f2f5;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.toggle-switch.disabled input:checked + .toggle-slider {
    background: #b4c5d6;
}
/* 深色模式 */
body[data-theme="dark"] .toggle-slider {
    background: #3a3f4b;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}
body[data-theme="dark"] .toggle-slider::before {
    background: #e0e0e0;
}
body[data-theme="dark"] .toggle-switch input:checked + .toggle-slider {
    background: var(--primary-color);
}
body[data-theme="dark"] .toggle-switch.disabled .toggle-slider {
    background: #2a2d35;
}
body[data-theme="dark"] .toggle-switch.disabled .toggle-slider::before {
    background: #555;
}
body[data-theme="dark"] .toggle-switch.disabled input:checked + .toggle-slider {
    background: #3d4a5a;
}

/* ============ 标签页快捷切换：布局容器 ============ */
.tab-switch-wrapper {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 0;
}
.tab-switch-row {
    display: flex;
    align-items: center;
    gap: 14px;
}
.tab-switch-status {
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    line-height: 1.4;
    transition: color 0.2s ease;
}
.tab-switch-status.status-ready {
    color: #1e8e48;
}
.tab-switch-status.status-offline {
    color: #98a2b3;
}
body[data-theme="dark"] .tab-switch-status.status-ready {
    color: #4ade80;
}
body[data-theme="dark"] .tab-switch-status.status-offline {
    color: #6b7280;
}
.tab-switch-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ============ 标签页快捷切换：下载扩展按钮 ============ */
.btn-load-extension {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: 1.5px solid var(--primary-color);
    background: linear-gradient(135deg, rgba(30, 136, 229, 0.06), rgba(0, 198, 255, 0.06));
    color: var(--primary-color);
    border-radius: 10px;
    font-size: calc(13px * var(--font-scale));
    font-weight: 600;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    transition: all 0.2s ease;
    align-self: flex-start;
    text-decoration: none;
    position: relative;
    overflow: hidden;
}
.btn-load-extension::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}
.btn-load-extension:hover {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 6px 16px rgba(30, 136, 229, 0.3);
    transform: translateY(-2px);
}
.btn-load-extension:hover::before {
    left: 100%;
}
.btn-load-extension:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(30, 136, 229, 0.2);
}
.btn-load-extension:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}
.btn-load-extension:disabled::before {
    display: none;
}
.btn-load-extension svg {
    flex-shrink: 0;
}
/* 深色模式 */
body[data-theme="dark"] .btn-load-extension {
    background: linear-gradient(135deg, rgba(30, 136, 229, 0.12), rgba(0, 198, 255, 0.1));
    border-color: var(--primary-color);
    color: var(--primary-light);
}
body[data-theme="dark"] .btn-load-extension:hover {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: #fff;
    box-shadow: 0 6px 16px rgba(30, 136, 229, 0.35);
}

/* ============ 深色模式：设置页全局适配 ============ */
/* 输入框/下拉框在深色下保证底色与文字对比 */
body[data-theme="dark"] .history-count-input,
body[data-theme="dark"] .engine-select,
body[data-theme="dark"] .engine-select option {
    background-color: var(--bg-card-base);
    color: var(--text-base);
}
/* 设置侧栏底色加深，避免与内容区混淆 */
body[data-theme="dark"] .settings-sidebar {
    background: var(--bg-color-base);
}
/* 棋盘格预览底色在深色下压暗，避免刺眼 */
body[data-theme="dark"] .opacity-preview::before {
    background-color: #2a3040;
    background-image:
        linear-gradient(45deg, #3a4050 25%, transparent 25%, transparent 75%, #3a4050 75%),
        linear-gradient(45deg, #3a4050 25%, transparent 25%, transparent 75%, #3a4050 75%);
}
/* 图片编辑棋盘格底色 */
body[data-theme="dark"] .image-preview-box {
    background-color: #1a1f2e;
    background-image:
        linear-gradient(45deg, #2a3040 25%, transparent 25%),
        linear-gradient(-45deg, #2a3040 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #2a3040 75%),
        linear-gradient(-45deg, transparent 75%, #2a3040 75%);
}
/* 主题预览块在深色下边框可见 */
body[data-theme="dark"] .theme-mode-light {
    border-color: #4a4a5a;
}
