

/* ---------- 头部操作区（风格切换 + 主题切换） ---------- */
.tool-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.mode-switch {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 0.25rem;
}

.mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--primary-color);
    color: #fff;
}

/* ---------- 输入区 ---------- */
.px-input-section {
    margin-bottom: 1.25rem;
}

.px-input-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.px-input-area {
    width: 100%;
    min-height: 88px;
    padding: 0.875rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1.05rem;
    font-family: inherit;
    resize: vertical;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.px-input-area:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(45, 140, 240, 0.1);
}

.px-input-area::placeholder {
    color: var(--text-secondary);
}

.input-hint {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.input-hint i {
    color: var(--primary-color);
}

.example-text {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.px-example {
    background: var(--code-bg);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Courier New', monospace;
}

.px-example:hover {
    background: var(--primary-light);
}

/* ---------- 参数控件区 ---------- */
.px-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.px-controls .form-group {
    margin-bottom: 0;
}

.px-controls .form-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}

#blockSizeValue,
#thresholdValue {
    color: var(--primary-color);
    font-family: 'Courier New', monospace;
}

.px-range {
    width: 100%;
    margin-top: 0.5rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.px-color-input {
    width: 100%;
    height: 44px;
    margin-top: 0.25rem;
    padding: 0.25rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
}

.px-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.px-checkbox input {
    accent-color: var(--primary-color);
    cursor: pointer;
}

.px-checkbox-row {
    display: flex;
    align-items: flex-end;
}

/* ---------- 操作按钮 ---------- */
.px-action-buttons {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.px-action-buttons .btn {
    flex: 1 1 160px;
}

/* style.css 无 .btn-sm，本页自带小号按钮修饰类 */
.px-btn-sm {
    padding: 0.4rem 0.875rem;
    font-size: 0.85rem;
}

/* ---------- 预览区 ---------- */
.px-result-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 1rem;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.px-size-readout {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

.px-canvas-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    padding: 1rem;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    /* 棋盘格底衬，用于显示透明背景 */
    background-image:
        linear-gradient(45deg, rgba(0, 0, 0, 0.06) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.06) 75%),
        linear-gradient(45deg, rgba(0, 0, 0, 0.06) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.06) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

.px-canvas-wrap[data-empty="true"]::after {
    content: attr(data-hint);
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
}

.px-canvas-wrap[data-empty="true"] #pxCanvas {
    display: none;
}

#pxCanvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    /* 关键：预览缩放时保持像素块锐利，不被插值模糊 */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ---------- 速查表 ---------- */
.px-table-wrap {
    margin-top: 0.75rem;
    overflow-x: auto;
}

.px-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.px-table th,
.px-table td {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.px-table th {
    background: var(--primary-light);
    color: var(--text-primary);
    font-weight: 600;
}

.px-table td {
    color: var(--text-secondary);
}

.px-table tbody tr:nth-child(even) td {
    background: var(--bg-light);
}

/* ---------- 历史记录 ---------- */
.history-section {
    margin-top: 1.25rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.history-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-title i {
    color: var(--primary-color);
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.history-item {
    padding: 0.625rem 0.875rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.history-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-secondary);
    padding: 1rem;
    font-size: 0.9rem;
}

/* ---------- Toast 变体（.toast 本体在 style.css） ---------- */
.toast.success {
    background-color: var(--success-color);
    color: #fff;
}

.toast.error {
    background-color: var(--danger-color);
    color: #fff;
}

/* ---------- 动画 ---------- */
@keyframes pxFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .px-tool-wrapper {
        padding: 1rem;
    }

    .tool-header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .mode-switch {
        width: 100%;
    }

    .mode-btn {
        flex: 1;
        justify-content: center;
    }

    .px-action-buttons {
        flex-direction: column;
    }

    .px-action-buttons .btn {
        width: 100%;
    }

    .history-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .px-input-area {
        min-height: 70px;
    }
}
