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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2rem;
    font-weight: 600;
}

.main-content {
    padding: 30px;
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 30px;
    transition: grid-template-columns 0.3s ease;
}

.main-content.has-result {
    grid-template-columns: 1fr 2fr 1fr 1fr;
    max-width: 100%;
}

/* Upload Section */
.upload-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.upload-box {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
}

.upload-box h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1rem;
}

.upload-area {
    border: 3px dashed #cbd5e0;
    border-radius: 10px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.upload-area:hover {
    border-color: #667eea;
    background: #f7fafc;
}

.upload-area.drag-over {
    border-color: #667eea;
    background: #edf2f7;
    transform: scale(1.02);
}

.upload-placeholder span {
    font-size: 3rem;
    display: block;
    margin-bottom: 10px;
}

.upload-placeholder p {
    color: #718096;
    font-size: 0.9rem;
}

.file-info {
    margin-top: 10px;
    font-size: 0.85rem;
    color: #4a5568;
    padding: 8px;
    background: white;
    border-radius: 5px;
    display: none;
}

.file-info.show {
    display: block;
}

.pdf-controls {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pdf-controls label,
.opacity-controls label {
    font-weight: 600;
    color: #4a5568;
}

.pdf-controls input[type="range"],
.opacity-controls input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e8f0;
    outline: none;
    -webkit-appearance: none;
}

.pdf-controls input[type="range"]::-webkit-slider-thumb,
.opacity-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.pdf-controls input[type="range"]::-moz-range-thumb,
.opacity-controls input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

.pdf-controls span,
.opacity-controls span {
    font-weight: 600;
    color: #667eea;
    min-width: 60px;
    text-align: center;
}

.opacity-controls {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.clear-btn {
    margin-top: 10px;
    padding: 8px 16px;
    background: #e53e3e;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
    width: 100%;
}

.clear-btn:hover {
    background: #c53030;
}

/* Canvas Section */
.canvas-section {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
}

.canvas-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1rem;
}

.canvas-container {
    background: white;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
    position: relative;
}

#canvas {
    max-width: 100%;
    max-height: 600px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: default;
}

/* Form Section */
.form-section {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
}

.form-section h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1rem;
}

.input-mode {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
}

.input-mode label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
    color: #4a5568;
}

.input-mode input[type="radio"] {
    cursor: pointer;
}

.form-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

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

.form-group label {
    font-weight: 600;
    color: #4a5568;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    padding: 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.submit-btn {
    margin-top: 20px;
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.submit-btn:active {
    transform: translateY(0);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .upload-section {
        flex-direction: row;
        gap: 20px;
    }
    
    .upload-box {
        flex: 1;
    }
}

/* Result Preview (Sidebar) */
.result-preview {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    animation: slideIn 0.4s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.result-preview h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1rem;
    text-align: center;
}

.preview-container {
    background: white;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.preview-container:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.preview-thumbnail {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    transition: border-color 0.3s;
}

.preview-container:hover .preview-thumbnail {
    border-color: #667eea;
}

.preview-hint {
    margin-top: 10px;
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 500;
}

/* Modal (Fullscreen) */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    font-size: 40px;
    color: white;
    cursor: pointer;
    transition: color 0.2s;
    user-select: none;
}

.modal-close:hover {
    color: #667eea;
}

#modalImage {
    max-width: 90vw;
    max-height: 75vh;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.modal-download-btn,
.modal-new-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.modal-download-btn {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.modal-download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(72, 187, 120, 0.4);
}

.modal-new-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.modal-new-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(102, 126, 234, 0.4);
}

.modal-download-btn:active,
.modal-new-btn:active {
    transform: translateY(0);
}

@media (max-width: 1200px) {
    .main-content,
    .main-content.has-result {
        grid-template-columns: 1fr;
    }

    .upload-section {
        flex-direction: row;
        gap: 20px;
    }

    .upload-box {
        flex: 1;
    }
}

@media (max-width: 768px) {
    .upload-section {
        flex-direction: column;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .main-content {
        padding: 20px;
    }

    .result-preview {
        padding: 15px;
    }

    .modal-content {
        max-width: 95vw;
    }

    #modalImage {
        max-width: 95vw;
        max-height: 70vh;
    }

    .modal-actions {
        flex-direction: column;
        width: 100%;
    }

    .modal-download-btn,
    .modal-new-btn {
        width: 100%;
    }

    .modal-close {
        font-size: 30px;
        top: -35px;
    }
}
