* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
header {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 20px;
}

header h1 {
    color: #2c3e50;
    font-size: 1.8rem;
    font-weight: 600;
}

/* 网站标题链接样式 */
.site-title-link {
    color: inherit;
    text-decoration: none;
    display: inline-block;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.site-title-link:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

.site-title-link:active {
    transform: translateY(0);
}

header nav {
    display: flex;
    gap: 1rem;
    align-items: center;
}

header nav a {
    text-decoration: none;
    color: #666;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
}

header nav a:hover {
    background: #f8f9fa;
    color: #2c3e50;
}

/* nav中的span标签样式 */
header nav span {
    color: #666;
    padding: 0.5rem 1rem;
    display: inline-flex;
    align-items: center;
}

/* Main Content */
main {
    min-height: calc(100vh - 140px);
    padding: 2rem 0;
}

/* Upload Section */
.upload-section {
    background: #fff;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden; /* 防止内容撑破容器 */
}

.upload-section h2 {
    margin-bottom: 1.5rem;
    color: #2c3e50;
    text-align: center;
}

.upload-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    box-sizing: border-box;
}

.upload-form > * {
    max-width: 100%;
    box-sizing: border-box;
}

/* File Previews */
.file-previews {
    display: grid;
    /* 每行最多4个，固定宽度150px */
    grid-template-columns: repeat(auto-fill, minmax(150px, 150px));
    gap: 1rem;
    margin: 1rem 0;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    /* 强制不超过容器宽度 */
    max-width: 100%;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
    /* 确保网格布局不会超出容器 */
    grid-auto-flow: dense;
    align-items: start;
    /* 确保每行最多4个 */
    justify-content: start;
}

/* 当没有图片时隐藏预览容器 */
.file-previews:empty {
    display: none;
}

.file-preview {
    position: relative;
    background: #fff;
    border-radius: 4px;
    padding: 0.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
    /* 固定宽度150px */
    width: 150px;
    max-width: 150px;
    box-sizing: border-box;
    /* 防止内容溢出 */
    overflow: hidden;
    /* 确保元素不超出容器 */
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    /* 强制限制 */
    min-width: 0;
    max-width: 150px;
}

.file-preview:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.preview-image {
    /* 初始由CSS控制 */
    width: 100%;
    height: 120px;
    object-fit: cover;
    object-position: center;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: block;
    box-sizing: border-box;
    /* 固定尺寸，严格限制 */
    max-width: 139px; /* 150px容器 - 11px左右padding */
    max-height: 120px;
    min-width: 0;
    min-height: 0;
}

.file-info {
    font-size: 0.875rem;
    color: #495057;
}

.file-name {
    font-weight: 600;
    color: #2c3e50;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 0.25rem;
    width: 100%;
    /* 固定宽度 */
    width: 139px;
}

.file-size {
    color: #6c757d;
    font-size: 0.8rem;
    /* 固定宽度 */
    width: 139px;
}

/* 确保预览容器内的所有元素都正确适配 */
.file-preview > * {
    max-width: 100%;
    box-sizing: border-box;
}

.remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease, transform 0.2s ease;
    z-index: 10;
    flex-shrink: 0;
}

.remove-btn:hover {
    background: #c82333;
    transform: scale(1.1);
}

/* Results Section */
.results-section {
    margin-top: 2rem;
    width: 100%;
    box-sizing: border-box;
    /* 桌面端最多显示2列，容器限制宽度 */
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
}

.results-section h3 {
    margin-bottom: 1rem;
    color: #2c3e50;
}

.results-section .image-result {
    display: inline-block;
    vertical-align: top;
    margin: 0.5rem;
    padding: 1rem;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    box-sizing: border-box;
    /* 桌面端每行显示2个，固定宽度 */
    width: calc(50% - 1rem);
    max-width: calc(50% - 1rem);
}

.results-section .image-result img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: block;
    box-sizing: border-box;
    width: auto;
    height: auto;
}

.results-section .image-info {
    text-align: left;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.results-section .image-name {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
}

.results-section .url-box {
    margin-top: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    gap: 0.5rem;
}

.results-section .url-box input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    min-width: 0;
    box-sizing: border-box;
}

.results-section .url-box button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Upload Actions */
.upload-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.upload-actions button {
    flex: 1;
}

.upload-actions button[type="button"] {
    background: #6c757d;
}

.upload-actions button[type="button"]:hover {
    background: #545b62;
}

.upload-actions button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.file-input-wrapper input[type=file] {
    position: absolute;
    left: -9999px;
}

.file-input-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-input-label .label-icon {
    font-size: 2rem;
}

.file-input-label .label-text {
    font-size: 1rem;
}

.file-input-label:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.file-input-wrapper input[type=file]:valid + .file-input-label {
    border-color: #28a745;
    background: #d4edda;
    color: #155724;
}

/* Paste Area */
.paste-area {
    margin: 1rem 0;
    padding: 1.5rem;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.paste-area:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.paste-area.paste-hover {
    background: #e3f2fd;
    border-color: #2196f3;
    border-style: solid;
}

.paste-content {
    pointer-events: none;
}

.paste-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.paste-area p {
    margin: 0.5rem 0;
    color: #495057;
    font-weight: 500;
}

.paste-area small {
    color: #6c757d;
    font-size: 0.875rem;
}

.paste-preview {
    margin-top: 1rem;
    text-align: center;
}

.paste-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

button {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

button:hover {
    background: #0056b3;
}

button .btn-icon {
    font-size: 1.2rem;
}

button .btn-text {
    font-size: 1rem;
}

/* Auth Section */
.auth-section {
    background: #fff;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    max-width: 400px;
    margin: 2rem auto;
}

.auth-section h2 {
    margin-bottom: 1.5rem;
    color: #2c3e50;
    text-align: center;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #495057;
}

.form-group input,
.form-group textarea {
    padding: 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    color: #666;
}

.auth-link a {
    color: #007bff;
    text-decoration: none;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* Messages */
.error, .success {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* Image Result */
.image-result {
    margin-top: 1rem;
    text-align: center;
}

.url-box {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
}

.url-box input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    min-width: 0;
    box-sizing: border-box;
}

.url-box button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Footer */
footer {
    background: #2c3e50;
    color: #ecf0f1;
    text-align: center;
    padding: 1rem 0;
}

/* Responsive */
@media (max-width: 768px) {
    header .container {
        flex-direction: column;
        gap: 1rem;
    }
    
    header nav {
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
    }
    
    .upload-section,
    .auth-section {
        margin: 1rem;
        padding: 1.5rem;
    }
    
    .url-box {
        flex-direction: column;
    }

    /* 优化移动端文件预览网格 */
    .file-previews {
        grid-template-columns: repeat(auto-fill, minmax(100px, 100px));
        gap: 0.75rem;
        padding: 0.75rem;
        margin: 0.5rem auto 0.5rem auto;
        width: 100%;
        /* 移动端也限制最大宽度 */
        max-width: 100%;
    }

    .file-preview {
        padding: 0.4rem;
        margin: 0;
        /* 固定宽度100px */
        width: 100px;
        max-width: 100px;
        /* 强制限制 */
        min-width: 0;
        overflow: hidden;
    }

    .preview-image {
        height: 100px;
        min-height: 100px;
        /* 固定宽度 */
        width: 92px; /* 100px容器 - 8px左右padding */
        max-width: 92px;
        max-height: 100px;
        min-width: 0;
    }

    .file-name {
        font-size: 0.75rem;
        /* 固定宽度 */
        width: 92px;
    }

    .file-size {
        font-size: 0.7rem;
        /* 固定宽度 */
        width: 92px;
    }

    /* 优化移动端上传结果 */
    .results-section {
        margin-top: 1rem;
        max-width: 100%;
    }

    .results-section .image-result {
        max-width: 100%;
        margin: 0.5rem 0;
        padding: 0.75rem;
        box-sizing: border-box;
    }

    .results-section .image-result img {
        max-height: 150px;
        max-width: 100%;
    }

    .results-section .image-name {
        font-size: 0.9rem;
        margin-bottom: 0.4rem;
    }

    .results-section .url-box {
        flex-direction: column;
        gap: 0.5rem;
    }

    .results-section .url-box input {
        font-size: 0.85rem;
        padding: 0.4rem;
        width: 100%;
        box-sizing: border-box;
    }

    .results-section .url-box button {
        width: 100%;
        padding: 0.6rem;
    }

    /* 优化移动端按钮 */
    .upload-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .upload-actions button {
        padding: 1rem;
        font-size: 1.1rem;
        width: 100%;
        box-sizing: border-box;
    }

    .upload-actions button .btn-icon {
        font-size: 1.5rem;
    }

    /* 优化移动端文件输入标签 */
    .file-input-label {
        padding: 0.75rem;
    }

    .file-input-label .label-icon {
        font-size: 1.5rem;
    }

    .file-input-label .label-text {
        font-size: 0.9rem;
    }

    /* 优化移动端文件输入区域 */
    .paste-area {
        padding: 1rem;
    }

    .paste-icon {
        font-size: 1.5rem;
    }

    .paste-area p {
        font-size: 0.9rem;
    }

    .paste-area small {
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.4rem;
    }
    
    header nav {
        gap: 0.5rem;
    }
    
    header nav a {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }
    
    .container {
        padding: 0 10px;
    }
    
    .upload-section,
    .auth-section {
        margin: 0.5rem;
        padding: 0.75rem;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* 更紧凑的移动端预览网格 */
    .file-previews {
        grid-template-columns: repeat(auto-fill, minmax(80px, 80px));
        gap: 0.5rem;
        padding: 0.5rem;
        margin: 0.4rem auto 0.4rem auto;
        width: 100%;
        /* 强制不超出 */
        overflow: hidden;
    }

    .file-preview {
        padding: 0.3rem;
        /* 固定宽度80px */
        width: 80px;
        max-width: 80px;
        /* 强制限制 */
        min-width: 0;
        overflow: hidden;
    }

    .preview-image {
        height: 80px;
        min-height: 80px;
        /* 固定宽度 */
        width: 74px; /* 80px容器 - 6px左右padding */
        max-width: 74px;
        max-height: 80px;
        min-width: 0;
    }

    .file-info {
        display: none; /* 小屏幕隐藏文件信息，只保留预览图 */
    }

    /* 移动端移除按钮也需要调整 */
    .remove-btn {
        width: 20px;
        height: 20px;
        font-size: 1rem;
        top: 0.25rem;
        right: 0.25rem;
    }

    .upload-section h2 {
        font-size: 1.3rem;
    }

    /* 移动端优化文件输入标签 */
    .file-input-label {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    .paste-area {
        padding: 0.75rem;
    }

    .paste-icon {
        font-size: 1.2rem;
    }

    .paste-area p {
        font-size: 0.8rem;
        margin: 0.3rem 0;
    }

    /* 移动端结果优化 */
    .results-section h3 {
        font-size: 1.1rem;
    }

    .results-section .image-result {
        padding: 0.6rem;
        margin: 0.4rem 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .results-section .image-result img {
        max-height: 120px;
        max-width: 100%;
        width: auto;
    }

    .results-section .image-name {
        font-size: 0.85rem;
    }

    .url-box input {
        font-size: 0.8rem;
        padding: 0.4rem;
        width: 100%;
        box-sizing: border-box;
    }

    .url-box button {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    /* 优化小屏幕的按钮图标 */
    .upload-actions button .btn-icon {
        font-size: 1.3rem;
    }

    .file-input-label .label-icon {
        font-size: 1.2rem;
    }

    .file-input-label .label-text {
        font-size: 0.85rem;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .file-preview:hover {
        transform: none;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .file-preview:active {
        transform: scale(0.98);
        box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    }
    
    .preview-image {
        -webkit-tap-highlight-color: transparent;
    }
    
    .remove-btn {
        width: 32px;
        height: 32px;
        font-size: 1.3rem;
        -webkit-tap-highlight-color: rgba(255,255,255,0.2);
    }
    
    button {
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        user-select: none;
        -webkit-user-select: none;
    }
    
    .file-input-label:active {
        background: #e9ecef;
        border-color: #adb5bd;
        transform: scale(0.99);
    }
    
    .paste-area:active {
        background: #e9ecef;
        border-color: #adb5bd;
        transform: scale(0.99);
    }
    
    .url-box button:active {
        transform: scale(0.95);
    }
    
    /* 优化移动端滚动 */
    .file-previews {
        -webkit-overflow-scrolling: touch;
    }
}