* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background-color: #f8fafc;
    color: #334155;
    min-height: 100vh;
    padding: 40px 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.02);
    overflow: hidden;
    border: 1px solid #f1f5f9;
}

/* 头部样式 */
.header {
    background: #ffffff;
    color: #0f172a;
    padding: 32px 40px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0;
}

.token-input-group {
    display: flex;
    gap: 12px;
    align-items: center;
    background: #f8fafc;
    padding: 8px 8px 8px 16px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;
}

.token-input-group:focus-within {
    border-color: #cbd5e1;
    box-shadow: 0 0 0 3px rgba(241, 245, 249, 0.5);
}

.token-input-group label {
    font-weight: 500;
    color: #64748b;
    font-size: 14px;
}

.token-input-group input {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    font-size: 14px;
    color: #0f172a;
    outline: none;
    min-width: 250px;
}

/* 主内容区 */
.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 32px;
    padding: 40px;
}

/* 画布区域 */
.canvas-section {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
}

.upload-area {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 480px;
    border: 2px dashed #cbd5e1;
    border-radius: 16px;
    background: #f8fafc;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: #94a3b8;
    background: #f1f5f9;
}

.upload-area.drag-over {
    border-color: #3b82f6;
    background: #eff6ff;
    transform: scale(1.01);
}

.upload-content {
    text-align: center;
}

.upload-icon {
    font-size: 56px;
    margin-bottom: 24px;
    color: #64748b;
    opacity: 0.8;
}

.upload-hint {
    margin-top: 16px;
    color: #475569;
    font-size: 15px;
    font-weight: 500;
}

.upload-hint-small {
    margin-top: 8px;
    color: #94a3b8;
    font-size: 13px;
}

.canvas-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.canvas-wrapper {
    position: relative;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: visible;
    background: #f8fafc;
    display: inline-block;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

/* 扩展边框容器 */
.expand-border-container {
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    pointer-events: none;
}

/* 扩展控制手柄 */
.expand-handle {
    position: absolute;
    background: white;
    border: 2px solid #3b82f6;
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.expand-handle:hover {
    background: #3b82f6;
    transform: scale(1.15);
}

/* 边缘手柄 */
.expand-handle-left,
.expand-handle-right {
    width: 10px;
    height: 60px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.expand-handle-left {
    left: 0;
    border-radius: 5px 0 0 5px;
}

.expand-handle-right {
    right: 0;
    border-radius: 0 5px 5px 0;
}

.expand-handle-top,
.expand-handle-bottom {
    height: 10px;
    width: 60px;
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.expand-handle-top {
    top: 0;
    border-radius: 5px 5px 0 0;
}

.expand-handle-bottom {
    bottom: 0;
    border-radius: 0 0 5px 5px;
}

/* 角落手柄 */
.expand-handle-top-left,
.expand-handle-top-right,
.expand-handle-bottom-left,
.expand-handle-bottom-right {
    width: 15px;
    height: 15px;
    border-radius: 50%;
}

.expand-handle-top-left {
    top: 0;
    left: 0;
    cursor: nwse-resize;
}

.expand-handle-top-right {
    top: 0;
    right: 0;
    cursor: nesw-resize;
}

.expand-handle-bottom-left {
    bottom: 0;
    left: 0;
    cursor: nesw-resize;
}

.expand-handle-bottom-right {
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
}

#mainCanvas, #maskCanvas {
    display: block;
    max-width: 100%;
    height: auto;
}

#maskCanvas {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
}

.canvas-controls {
    background: #ffffff;
    padding: 24px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.mode-selector {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.mode-selector label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: color 0.2s;
}

.mode-selector label:hover {
    color: #0f172a;
}

.mode-selector input[type="radio"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: #3b82f6;
}

.expand-controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.expand-hint {
    font-size: 14px;
    color: #3b82f6;
    font-weight: 500;
    margin: 0;
}

.expand-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    background: #f8fafc;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.expand-info-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}

.expand-info-item span:first-child {
    font-weight: 500;
    color: #64748b;
}

.expand-info-item span:last-child {
    font-weight: 600;
    color: #3b82f6;
}

.brush-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.brush-controls label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
}

.brush-controls input[type="range"] {
    width: 100%;
    margin-top: 8px;
    accent-color: #3b82f6;
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* 按钮样式 */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #f1f5f9;
    color: #475569;
}

.btn:hover {
    background: #e2e8f0;
    color: #0f172a;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: #0f172a;
    color: white;
}

.btn-primary:hover {
    background: #1e293b;
    color: white;
}

.btn-success {
    background: #3b82f6;
    color: white;
}

.btn-success:hover {
    background: #2563eb;
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-large {
    padding: 16px 32px;
    font-size: 16px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
    width: 100%;
    margin-top: 12px;
}

/* 加载动画 */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f1f5f9;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.loading-overlay p {
    color: #475569;
    font-weight: 500;
    font-size: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 侧边栏 */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.preview-section, .history-section {
    background: #ffffff;
    padding: 24px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.preview-section h2, .history-section h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #0f172a;
}

.preview-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.preview-item h3 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    color: #64748b;
}

.preview-image {
    width: 100%;
    height: 220px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f8fafc;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.preview-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.placeholder {
    color: #94a3b8;
    font-size: 14px;
}

/* 历史记录 */
.history-list {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.history-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-item:hover {
    border-color: #cbd5e1;
    background: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.history-item img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.history-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
}

.history-item-time {
    font-size: 12px;
    color: #64748b;
}

.history-item-mode {
    font-size: 12px;
    color: #3b82f6;
    font-weight: 600;
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
    align-self: flex-start;
}

.history-item-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.history-item-actions button {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        grid-template-columns: 1fr 1fr;
        display: grid;
    }
}

@media (max-width: 768px) {
    .sidebar {
        grid-template-columns: 1fr;
    }
    
    .token-input-group {
        flex-direction: column;
        align-items: stretch;
    }
}
