:root {
    /* Light mode colors */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 6px;
    --padding-mobile: 0.75rem;
    --max-width: min(1200px, 100vw - 1rem);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark mode colors */
        --primary-color: #3b82f6;
        --primary-hover: #2563eb;
        --bg-color: #0f172a;
        --card-bg: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

.page-container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.5rem;
    width: 100%;
}

.preview-card,
.controls-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    width: 100%;
    overflow: hidden;
}

.preview-card {
    padding: 0.5rem;
}

.image-container {
    position: relative;
    background-color: var(--bg-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 4/3;
    display: flex;
    justify-content: center;
    align-items: center;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease;
}

canvas.loaded {
    opacity: 1;
}

.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-indicator::after {
    content: '';
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.controls-nav {
    display: flex;
    gap: 0.5rem;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 10;
    padding: 0.5rem;
}

.nav-btn {
    flex: 1;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    font-size: 0.9rem;
    min-width: max-content;
}

.nav-btn.active {
    background: var(--primary-color);
    color: white;
    font-weight: 500;
}

.nav-btn:hover:not(.active) {
    background: var(--bg-color);
}

.controls-content {
    display: none;
    padding: 0.5rem;
}

.controls-content.active {
    display: block;
}

.control-group {
    background: var(--bg-color);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: 2px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.adjust-btn {
    width: 24px;
    height: 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
}

.file-controls {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0 0;
    border-top: 1px solid var(--border-color);
    margin-top: 0.5rem;
}

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

input[type="file"] {
    display: none;
}

.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.download-btn {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.download-btn:hover,
.adjust-btn:hover,
.nav-btn.active:hover {
    background: var(--primary-hover);
}

@media (max-width: 1024px) {
    :root {
        --max-width: 100vw;
    }

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

@media (max-width: 768px) {
    .controls-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .controls-nav::-webkit-scrollbar {
        display: none;
    }
    
    .file-controls {
        flex-direction: column;
    }
}

@media (max-width: 360px) {
    :root {
        --padding-mobile: 0.25rem;
    }

    .page-container {
        padding: 0.25rem;
    }

    .nav-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.8125rem;
    }
}