:root {
    --apple-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --text-color-primary: #1d1d1f; /* Apple's primary text color (dark gray) */
    --text-color-secondary: #6e6e73; /* Apple's secondary text color (medium gray) */
    --background-color-page: #f5f5f7; /* Apple's light gray background */
    --background-color-card: #ffffff;
    --accent-color: #007aff; /* Apple's blue */
    --border-color: #d2d2d7;
    --border-radius-medium: 12px; /* Softer, more Apple-like corners */
    --border-radius-small: 8px;
    --box-shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body {
    font-family: var(--apple-font);
    margin: 0;
    padding: 40px 20px;
    background-color: var(--background-color-page);
    color: var(--text-color-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

.container {
    width: 100%;
    max-width: 700px; /* Limit content width for better readability */
    display: flex;
    flex-direction: column;
    gap: 30px; /* Space between major sections */
}

h1 {
    font-size: 2.5em; /* Larger, more impactful heading */
    font-weight: 600;
    color: var(--text-color-primary);
    text-align: center;
    margin-bottom: 10px; /* Reduced bottom margin as container has gap */
}

.controls,
.preview-area {
    background-color: var(--background-color-card);
    padding: 25px 30px; /* Increased padding */
    border-radius: var(--border-radius-medium);
    box-shadow: var(--box-shadow-soft);
    width: 100%;
    box-sizing: border-box;
}

.control-group { /* Replaces .controls > div for better semantics */
    margin-bottom: 20px;
}

.control-group:last-child {
    margin-bottom: 0;
}

label {
    display: block; /* Make labels block for better spacing */
    font-weight: 500;
    color: var(--text-color-secondary);
    margin-bottom: 8px;
}

input[type="file"] {
    display: block;
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-small);
    background-color: #f9f9f9;
    color: var(--text-color-primary);
    font-family: var(--apple-font);
    font-size: 0.95em;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="file"]::file-selector-button { /* Style the button part of file input */
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    margin-right: 10px;
    transition: background-color 0.2s ease;
}

input[type="file"]::file-selector-button:hover {
    background-color: #0056b3;
}


input[type="file"]:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
}

#selectedImagesPreviewContainer {
    margin-top: 15px; /* Add some space above the preview */
    /* Ensure the label for this section is styled if not already covered by general label styles */
}

#selectedImagesPreviewContainer label { /* Explicitly style the label for this section if needed */
    display: block;
    font-weight: 500;
    color: var(--text-color-secondary);
    margin-bottom: 8px;
}

#selectedImagesPreview {
    display: flex;
    flex-wrap: wrap; /* Allow thumbnails to wrap */
    gap: 10px; /* Space between thumbnails */
    padding: 10px;
    border: 1px dashed var(--border-color);
    border-radius: var(--border-radius-small);
    min-height: 80px; /* Minimum height for the preview area */
    background-color: #f9f9f9; /* Light background for the preview area */
    align-items: flex-start; /* Align items to the start if they don't fill the height */
    margin-top: 5px; /* Space between label and preview box */
}

#selectedImagesPreview img {
    max-width: 100px; /* Max width for thumbnails */
    max-height: 100px; /* Max height for thumbnails */
    height: auto; /* Maintain aspect ratio */
    border: 1px solid #ddd;
    border-radius: var(--border-radius-small);
    object-fit: cover; /* Ensure image covers the area, might crop */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.radio-group label {
    display: inline-flex; /* Align radio and text */
    align-items: center;
    margin-right: 20px;
    font-weight: normal; /* Normal weight for radio labels */
    color: var(--text-color-primary);
    cursor: pointer;
}

input[type="radio"] {
    margin-right: 8px;
    accent-color: var(--accent-color); /* Modern way to color radio/checkbox */
    transform: scale(1.1); /* Slightly larger radio */
}

.button-group {
    display: flex;
    gap: 15px; /* Space between buttons */
    margin-top: 25px;
}

button {
    flex-grow: 1; /* Make buttons share space */
    padding: 12px 20px;
    font-family: var(--apple-font);
    font-size: 1em;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    background-color: var(--accent-color);
    color: white;
}

button:hover {
    background-color: #0062cc; /* Darker blue on hover */
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
}

button:active {
    transform: translateY(1px);
}

button#downloadButton {
    background-color: #e9e9eb;
    color: var(--accent-color);
    flex-grow: 0; /* Prevent download button from taking full width in its new container */
    min-width: 220px; /* Ensure a good clickable width */
}

button#downloadButton:hover {
    background-color: #dcdce0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}


button:disabled {
    background-color: #e0e0e0; /* Lighter gray for disabled */
    color: #a0a0a0;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.output-area {
    background-color: var(--background-color-card);
    padding: 25px 30px;
    border-radius: var(--border-radius-medium);
    box-shadow: var(--box-shadow-soft);
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column; /* Stack canvas and button vertically */
    gap: 15px; /* Adjusted gap for tighter spacing between title, canvas, and button */
}

.output-area .control-group { /* Specifically target control-group within output-area */
    margin-bottom: 0; /* Remove bottom margin if it's the title container */
}

.output-area .section-title {
    font-size: 1.1em; /* Slightly larger than normal labels */
    font-weight: 600; /* Bolder */
    color: var(--text-color-primary); /* Primary text color for more emphasis */
    margin-bottom: 10px; /* Space below the title */
    text-align: left; /* Align to the left, or center if preferred */
}

.preview-area {
    min-height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--border-color);
    width: 100%; /* Ensure it takes full width of its parent .output-area */
    box-sizing: border-box;
    background-color: #fdfdfd; /* Slightly off-white for the direct canvas background */
    border-radius: var(--border-radius-small); /* Rounded corners for the canvas area itself */
    /* background-color, padding, outer border-radius, box-shadow are now on .output-area */
    /* padding is removed as canvas will fill this area */
}

.download-button-container {
    display: flex;
    justify-content: center; /* Center the download button */
    width: 100%;
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 500px; /* Max height for preview */
    background-color: transparent; /* Canvas itself transparent, relies on preview-area bg */
    border-radius: var(--border-radius-small); /* If canvas has its own border/bg */
}