/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 3rem 2rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.125rem;
    opacity: 0.95;
    font-weight: 400;
}

/* Main Content */
main {
    padding: 2rem;
}

section {
    margin-bottom: 3rem;
}

section h2 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

/* Upload Section */
.upload-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    margin-bottom: 3rem;
}

.upload-box {
    width: 100%;
    max-width: 600px;
    padding: 3rem 2rem;
    border: 3px dashed var(--border-color);
    border-radius: var(--border-radius);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--background);
}

.upload-box:hover {
    border-color: var(--primary-color);
    background: #f1f5f9;
    transform: translateY(-2px);
}

.upload-box.drag-over {
    border-color: var(--primary-color);
    background: #eef2ff;
    transform: scale(1.02);
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    color: var(--primary-color);
}

.upload-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.upload-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Transformation Section */
.transformation-section {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.categories-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.category {
    background: var(--background);
    padding: 0;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.category-header:hover {
    background: #f1f5f9;
}

.category-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.category-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0;
}

.collapse-indicator {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    min-width: 30px;
    text-align: center;
    transition: var(--transition);
}

.category-content {
    padding: 0 1.5rem 1.5rem 1.5rem;
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.category-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.transformations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.transform-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.transform-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.transform-card.selected {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    box-shadow: var(--shadow-md);
}

.transform-card h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.transform-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Parameters Panel */
.parameters-panel {
    background: var(--background);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 1000px;
    }
}

.parameters-panel h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

#parametersContainer {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.parameter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.parameter-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.parameter-value {
    color: var(--primary-color);
    font-weight: 700;
}

.parameter-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.parameter-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
}

.parameter-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.2);
}

.parameter-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.parameter-description {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-2px);
}

/* Results Section */
.results-section {
    animation: fadeIn 0.5s ease-in;
}

.images-comparison {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.image-container h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.image-wrapper {
    position: relative;
    background: var(--background);
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-wrapper img {
    width: 100%;
    height: auto;
    display: block;
}

/* Image Placeholder */
.image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.25rem;
    font-weight: 500;
}

.image-placeholder p {
    margin: 0;
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-spinner p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Actions */
.actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

/* Matrix Data Section */
.matrix-section {
    background: var(--background);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    background: var(--surface);
}

.matrix-header:hover {
    background: #f1f5f9;
}

.matrix-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.matrix-content {
    padding: 1.5rem;
    max-height: 3000px;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.matrix-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.matrix-controls {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.matrix-control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.matrix-control-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.matrix-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
}

.matrix-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.matrix-toggle span {
    font-weight: 600;
    color: var(--text-primary);
}

.matrix-control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.matrix-control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: var(--transition);
}

.matrix-control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-dark);
    transform: scale(1.2);
}

.matrix-control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.matrix-grids {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}

.matrix-container h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-align: center;
}

.matrix-grid {
    display: grid;
    gap: 0;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: auto;
    font-size: 0.75rem;
    line-height: 1.3;
    max-height: 1000px;
    max-width: 100%;
}

.matrix-cell {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: none;
    line-height: 1.2;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    border: none;
}

.matrix-cell.hide-numbers {
    font-size: 0;
    color: transparent;
}

.matrix-placeholder {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* Status Messages */
.status-message {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transform: translateY(150%);
    transition: transform 0.3s ease-out;
    z-index: 1000;
    max-width: 400px;
}

.status-message.show {
    transform: translateY(0);
}

.status-message.success {
    background: var(--success-color);
    color: white;
}

.status-message.error {
    background: var(--error-color);
    color: white;
}

.status-message.info {
    background: var(--primary-color);
    color: white;
}

/* Footer */
footer {
    background: var(--background);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-top: 1px solid var(--border-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.875rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    main {
        padding: 1.5rem;
    }

    .transformations-grid {
        grid-template-columns: 1fr;
    }

    .images-comparison {
        grid-template-columns: 1fr;
    }

    .status-message {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
    }

    .matrix-grids {
        grid-template-columns: 1fr;
    }

    .matrix-grid {
        max-height: 600px;
    }

    .matrix-controls {
        padding: 1rem;
    }
}
