/* style.css content here */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --background-light: #f4f7f9;
    --card-background: #ffffff;
    --text-color: #333;
    --border-radius: 8px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    --placeholder-color: #aaa;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-light);
    color: var(--text-color);
    line-height: 1.6;
    padding: 0;
}

/* --- Header & Branding --- */
header {
    background-color: var(--card-background);
    padding: 1rem 5%;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
}

header h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    font-weight: 600;
}

.anycoder-link {
    font-size: 0.85rem;
    color: var(--secondary-color);
    text-decoration: none;
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.anycoder-link:hover {
    color: var(--primary-color);
    background-color: #e9ecef;
}


/* --- Main Layout & Sections --- */
main {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

#app-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

section {
    background: var(--card-background);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

section h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.25rem;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 5px;
}

.instruction {
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 15px;
}

/* --- Controls Section --- */

input[type="file"] {
    display: block;
    width: 100%;
    padding: 15px 10px;
    border: 2px dashed #ccc;
    border-radius: var(--border-radius);
    background-color: #f9f9f9;
    cursor: pointer;
    font-size: 1rem;
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 15px;
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.3s, opacity 0.3s, transform 0.1s;
    flex-grow: 1;
}

button:active:not([disabled]) {
    transform: translateY(1px);
}

button:not([disabled]) {
    background-color: var(--primary-color);
    color: white;
}

button:hover:not([disabled]) {
    background-color: #0056b3;
}

button[disabled] {
    background-color: #e9ecef;
    color: var(--secondary-color);
    opacity: 0.7;
    cursor: not-allowed;
}

#download-btn {
    margin-top: 20px;
    background-color: var(--success-color);
    width: 100%;
}
#download-btn:hover:not([disabled]) {
    background-color: #1e7e34;
}

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

.preview-area {
    position: relative;
}

.image-outputs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.output-card {
    border: 1px solid #e0e0e0;
    padding: 15px;
    border-radius: var(--border-radius);
    background: #fafafa;
}

.output-card h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--secondary-color);
}

.image-container {
    min-height: 250px;
    max-height: 60vh; /* Limit height for massive images */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.image-container img,
.image-container canvas {
    max-width: 100%;
    /* Max height required for vertical shrinking in case of portrait images */
    max-height: 100%; 
    height: auto;
    display: block;
    object-fit: contain; 
}

.placeholder {
    color: var(--placeholder-color);
    font-style: italic;
    padding: 20px;
    text-align: center;
}

/* --- Loading & Error States --- */
.hidden {
    display: none !important;
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: var(--border-radius);
    border: 1px solid #f5c6cb;
    margin-top: 20px;
    text-align: center;
    font-weight: 500;
}

#image-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: var(--border-radius);
    backdrop-filter: blur(2px);
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

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

/* --- Responsive Design (Tablet/Desktop) --- */
@media (min-width: 768px) {
    header {
        padding: 1rem 30px;
    }
    
    #app-container {
        grid-template-columns: 250px 1fr;
        grid-template-areas: 
            "controls preview";
        display: grid;
    }

    .controls {
        grid-area: controls;
    }

    .preview-area {
        grid-area: preview;
    }

    .image-outputs {
        grid-template-columns: 1fr 1fr;
    }

    .output-card {
        padding: 20px;
    }

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