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

:root {
    --bg: #4a5a3a;
    --bg-secondary: #3f4e32;
    --bg-hover: #566844;
    --bg-card: #faf8f5;
    --text: #2c2f27;
    --text-secondary: #6b6e5f;
    --text-tertiary: #9b9d8f;
    --border: #d5d1c8;
    --accent: #6b7c4e;
    --accent-hover: #5a6a40;
    --accent-light: #e8ecdf;
    --danger: #b54a3f;
    --danger-light: #f3e1de;
    --success: #5a7a4a;
    --success-light: #e2eddb;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(44, 47, 39, 0.04);
    --shadow: 0 1px 3px rgba(44, 47, 39, 0.06), 0 1px 2px rgba(44, 47, 39, 0.04);
    --shadow-md: 0 4px 12px rgba(44, 47, 39, 0.08);
    --transition: 120ms ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-secondary);
    min-height: 100vh;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Topbar ---- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 22px;
    height: 22px;
    color: var(--text);
}

.logo-text {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.topbar-hint {
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ---- Container ---- */

.container {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 24px;
    flex: 1;
}

/* ---- Drop Zone ---- */

.drop-zone {
    background: var(--bg-card);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 56px 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.drop-zone:hover {
    border-color: var(--accent);
    background: var(--bg-card);
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eae7e0;
    border-radius: 10px;
    color: var(--text-secondary);
}

.drop-zone-icon svg {
    width: 22px;
    height: 22px;
}

.drop-zone-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.drop-zone-sub {
    font-size: 13px;
    color: var(--text-secondary);
}

.drop-zone-link {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.drop-zone-types {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 12px;
}

/* ---- Workspace ---- */

.workspace {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.file-count {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: #eae7e0;
    padding: 1px 8px;
    border-radius: 10px;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
}

.files-section {
    padding: 24px;
    min-width: 0;
}

.preview-section {
    padding: 24px;
    border-left: 1px solid var(--border);
    min-width: 0;
    background: #f0ede6;
}

/* ---- File List ---- */

.files-container {
    max-height: 380px;
    overflow-y: auto;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius);
    transition: background var(--transition);
    cursor: grab;
    gap: 12px;
    user-select: none;
}

.file-item:active {
    cursor: grabbing;
}

.file-item.clickable:hover {
    cursor: pointer;
}

.file-item:hover {
    background: #f0ede6;
}

.file-item.selected {
    background: var(--accent-light);
}

.file-item.dragging {
    opacity: 0.4;
}

.file-item.drag-over {
    background: var(--accent-light);
}

.file-item.drag-over-top::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 8px;
    right: 8px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.file-item.drag-over-bottom::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 8px;
    right: 8px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.file-order {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: #eae7e0;
    flex-shrink: 0;
}

.file-item.selected .file-order {
    background: var(--accent);
    color: #fff;
}

.file-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 12px;
    color: var(--text-tertiary);
}

.file-remove {
    background: none;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: all var(--transition);
    flex-shrink: 0;
    opacity: 0;
}

.file-item:hover .file-remove {
    opacity: 1;
}

.file-remove:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* ---- Preview ---- */

.preview-container {
    max-height: 500px;
    overflow-y: auto;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-placeholder {
    text-align: center;
    color: var(--text-tertiary);
    padding: 40px 24px;
}

.preview-icon {
    width: 40px;
    height: 40px;
    margin: 0 auto 12px;
    color: var(--text-tertiary);
    opacity: 0.5;
}

.preview-placeholder p {
    font-size: 13px;
}

.preview-content {
    width: 100%;
    text-align: center;
    padding: 16px;
}

.preview-content img,
.preview-content canvas {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    box-shadow: var(--shadow);
    background: var(--bg-card);
}

.preview-info {
    margin-top: 12px;
    padding: 8px 12px;
    background: #e6e3db;
    border-radius: var(--radius);
    font-size: 12px;
    color: var(--text-secondary);
    text-align: left;
}

.preview-info strong {
    color: var(--text);
    font-weight: 500;
    display: block;
    margin-bottom: 2px;
}

.preview-loading {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 20px;
}

.preview-error {
    text-align: center;
    color: var(--danger);
    font-size: 13px;
    padding: 20px;
}

.preview-error p {
    margin: 0;
}

/* ---- Buttons ---- */

.actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    font-family: inherit;
    line-height: 1.4;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-ghost {
    background: none;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: #eae7e0;
    color: var(--text);
}

.btn-download {
    margin-top: 16px;
    padding: 10px 20px;
    font-size: 14px;
}

.btn-loader {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ---- Result ---- */

.result {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    text-align: center;
}

.success-message {
    color: var(--text);
}

.success-check {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--success-light);
    border-radius: 50%;
    color: var(--success);
}

.success-check svg {
    width: 24px;
    height: 24px;
}

.success-message h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.success-message p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ---- Scrollbar ---- */

.files-container::-webkit-scrollbar,
.preview-container::-webkit-scrollbar {
    width: 6px;
}

.files-container::-webkit-scrollbar-track,
.preview-container::-webkit-scrollbar-track {
    background: transparent;
}

.files-container::-webkit-scrollbar-thumb,
.preview-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.files-container::-webkit-scrollbar-thumb:hover,
.preview-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    .topbar-hint {
        display: none;
    }

    .container {
        padding: 24px 16px;
    }

    .drop-zone {
        padding: 40px 24px;
    }

    .main-content {
        grid-template-columns: 1fr;
    }

    .preview-section {
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .preview-container {
        min-height: 240px;
        max-height: 360px;
    }

    .actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .file-remove {
        opacity: 1;
    }
}
