/* CSS Variables */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-primary: #0ea5e9;
    --accent-secondary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 100%);
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-sm: 8px;
}

/* Reset & Base */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* App Layout */
.app {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.history-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.history-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Main Content */
.main {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Card */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

/* Step Header */
.step-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.step-number {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    color: white;
}

.step-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Step Content */
.step-content {
    padding-left: 52px;
}

.description {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

/* Input Group */
.input-group {
    display: flex;
    gap: 12px;
    max-width: 500px;
}

.input-group input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
}

.input-group input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

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

.input-group button {
    padding: 12px 28px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.input-group button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.error-message {
    margin-top: 12px;
    padding: 10px 16px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius-sm);
    color: var(--error);
    font-size: 0.9rem;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 100%;
    position: relative;
    background: var(--bg-primary);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-primary);
    background: rgba(14, 165, 233, 0.02);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

.upload-placeholder svg {
    opacity: 0.4;
    color: var(--accent-primary);
}

.upload-placeholder p {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.upload-placeholder span {
    font-size: 0.85rem;
}

.upload-preview {
    position: relative;
}

.upload-preview img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius-sm);
}

.remove-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 28px;
    height: 28px;
    background: var(--error);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

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

/* Buttons */
.primary-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 20px;
}

.primary-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.primary-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.primary-btn.loading {
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Progress */
.progress-container {
    max-width: 100%;
    margin-bottom: 30px;
}

.progress-bar {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#progress-percent {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Processing Animation */
.processing-animation {
    margin: 32px 0;
}

.emoji-loader {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 2rem;
}

.emoji-loader span {
    animation: bounce 1.5s ease-in-out infinite;
}

.emoji-loader span:nth-child(2) {
    animation-delay: 0.1s;
}

.emoji-loader span:nth-child(3) {
    animation-delay: 0.2s;
}

.emoji-loader span:nth-child(4) {
    animation-delay: 0.3s;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.processing-note {
    color: var(--text-secondary);
    font-size: 0.9rem;
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid var(--warning);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    max-width: 100%;
    margin-top: 24px;
}

.processing-note strong {
    color: var(--accent-primary);
    font-family: 'SF Mono', Monaco, monospace;
}

/* Step Timeline */
.step-timeline {
    margin: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.timeline-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 0;
    border-left: 2px solid var(--border-color);
    margin-left: 16px;
    padding-left: 24px;
    position: relative;
}

.timeline-item:first-child {
    padding-top: 0;
}

.timeline-item:last-child {
    border-left-color: transparent;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 16px;
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
}

.timeline-item:first-child::before {
    top: 0;
}

.timeline-item[data-status="active"]::before {
    background: var(--warning);
    border-color: var(--warning);
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
    animation: pulse 1.5s infinite;
}

.timeline-item[data-status="completed"]::before {
    background: var(--success);
    border-color: var(--success);
}

.timeline-item[data-status="completed"] {
    border-left-color: var(--success);
}

.timeline-item[data-status="failed"]::before {
    background: var(--error);
    border-color: var(--error);
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(245, 158, 11, 0.1);
    }
}

.timeline-icon {
    font-size: 1.5rem;
    min-width: 32px;
    text-align: center;
}

.timeline-content {
    flex: 1;
}

.timeline-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.timeline-item[data-status="pending"] .timeline-title {
    color: var(--text-secondary);
}

.timeline-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.timeline-status {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.timeline-item[data-status="active"] .timeline-status {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.timeline-item[data-status="active"] .timeline-status::before {
    content: '进行中';
}

.timeline-item[data-status="completed"] .timeline-status {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.timeline-item[data-status="completed"] .timeline-status::before {
    content: '✓ 完成';
}

.timeline-item[data-status="failed"] .timeline-status {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.timeline-item[data-status="failed"] .timeline-status::before {
    content: '✗ 失败';
}

/* Live Preview */
.live-preview {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.live-preview h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}

.preview-placeholder {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.preview-item {
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.preview-item img {
    width: 100%;
    height: auto;
    display: block;
}

.preview-item.emoji-grid-preview {
    grid-column: 1 / -1;
    max-width: 300px;
}

.preview-label {
    font-size: 0.7rem;
    padding: 4px 8px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    text-align: center;
}

/* Results */
.results-actions {
    margin-bottom: 24px;
}

.results-section {
    margin-bottom: 32px;
}

.results-section h3 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.result-grid.single {
    grid-template-columns: 1fr;
    max-width: 400px;
}

.result-item {
    position: relative;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: transform 0.2s;
}

.result-item:hover {
    transform: scale(1.02);
}

.result-item img {
    width: 100%;
    height: auto;
    display: block;
}

.download-single {
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.result-item:hover .download-single {
    opacity: 1;
}

.download-single:hover {
    background: var(--accent-primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.2rem;
    color: var(--text-primary);
}

.close-btn {
    width: 32px;
    height: 32px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.modal-body {
    overflow-y: auto;
}

/* History List */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.history-item:hover {
    background: var(--bg-secondary);
}

.history-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item-code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 1rem;
    color: var(--accent-primary);
    font-weight: 600;
}

.history-item-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.history-item-status {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.history-item-status.completed {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.history-item-status.processing {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.history-item-status.failed {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
}

.history-item-actions {
    display: flex;
    gap: 8px;
}

.history-item-actions button {
    padding: 8px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item-actions button:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .app {
        padding: 15px;
    }

    .header {
        margin-bottom: 24px;
    }

    .logo-text {
        font-size: 1.2rem;
    }

    .history-btn span {
        display: none;
    }

    .card {
        padding: 20px;
    }

    .step-content {
        padding-left: 0;
        margin-top: 16px;
    }

    .input-group {
        flex-direction: column;
    }

    .input-group button {
        width: 100%;
    }

    .upload-zone {
        padding: 32px 16px;
    }

    .result-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .emoji-loader {
        font-size: 1.6rem;
        gap: 12px;
    }

    .processing-layout {
        flex-direction: column;
    }

    .processing-left,
    .processing-right {
        min-width: 100%;
    }
}

/* Processing Left-Right Layout */
.processing-card {
    max-width: 1200px;
}

.processing-layout {
    display: flex;
    gap: 30px;
}

.processing-left {
    flex: 0 0 340px;
    min-width: 340px;
}

.processing-right {
    flex: 1;
    min-width: 0;
    max-height: 600px;
    overflow-y: auto;
}

.processing-right h4 {
    margin-bottom: 16px;
    font-size: 1.1rem;
    color: var(--text-primary);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 8px 0;
    z-index: 10;
}

/* Queue Status */
.queue-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.3);
    }

    50% {
        box-shadow: 0 0 20px 5px rgba(245, 158, 11, 0.3);
    }
}

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

.queue-text {
    font-weight: 500;
    color: #92400e;
}

.queue-text span {
    font-weight: 700;
    color: #b45309;
}

/* Preview Sections */
.preview-section {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.preview-section:last-child {
    border-bottom: none;
}

.preview-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-title span {
    font-weight: 400;
    color: var(--accent-primary);
}

.preview-placeholder {
    padding: 30px;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    border: 2px dashed var(--border-color);
}

/* Emoji Grid Preview */
.preview-emoji-grid img {
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

/* Split Images Grid */
.preview-split-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.preview-split-grid img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* Video Grid */
.preview-video-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.preview-video-grid video {
    width: 100%;
    border-radius: var(--radius-sm);
    background: #000;
}

/* GIF Grid */
.preview-gif-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.preview-gif-grid img {
    width: 100%;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}