:root {
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --primary: 221.2 83.2% 53.3%;
    --primary-foreground: 210 40% 98%;
    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;
    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 40% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 221.2 83.2% 53.3%;
    --radius: 0.5rem;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: hsl(var(--secondary));
    color: hsl(var(--foreground));
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background-color: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--border));
    padding: 1rem 1.5rem;
    text-align: center;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: hsl(var(--foreground));
    margin-bottom: 0.125rem;
}

.subtitle {
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
}

.main-content {
    display: grid;
    grid-template-columns: 1fr;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 5.5rem);
}

.config-panel,
.preview-panel {
    background-color: hsl(var(--background));
    height: 100%;
    display: flex;
    flex-direction: column;
}

.config-panel-right {
    border-left: 1px solid hsl(var(--border));
}

.config-panel-right .panel-scroll {
    padding: 0.625rem;
}

.config-panel-right .card {
    margin-bottom: 0;
}

.config-panel-right .card-content {
    padding: 0.625rem;
}

.config-panel-right .form-group {
    margin-bottom: 0.5rem;
}

.config-panel-right .card-header {
    padding: 0.375rem 0.625rem;
}

.panel-scroll {
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.config-content {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.card {
    background-color: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    margin-bottom: 0.625rem;
}

.card-header {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.card-header h2,
.card-header h3 {
    font-size: 0.6875rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.card-content {
    padding: 0.75rem;
}

.settings-card {
    display: none;
}

.settings-card.active {
    display: block;
}

.form-group {
    margin-bottom: 0.625rem;
}

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

.label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.6875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    margin-bottom: 0.25rem;
}

.label-value {
    font-size: 0.625rem;
    color: hsl(var(--muted-foreground));
    font-weight: 400;
}

.input,
.select {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    transition: all 0.2s;
}

.input:focus,
.select:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px hsla(var(--ring), 0.1);
}

.input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 10px;
    padding-right: 2rem;
}

.custom-resolution {
    display: none;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

.custom-resolution.active {
    display: flex;
}

.separator {
    font-weight: 500;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.color-input {
    width: 100%;
    height: 1.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    background-color: hsl(var(--background));
    padding: 0.1875rem;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: calc(var(--radius) - 4px);
}

.slider {
    width: 100%;
    height: 0.25rem;
    border-radius: 9999px;
    background: hsl(var(--secondary));
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
    cursor: pointer;
    border: 2px solid hsl(var(--background));
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    background: hsl(var(--primary) / 0.9);
}

.slider::-moz-range-thumb {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
    cursor: pointer;
    border: 2px solid hsl(var(--background));
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.slider::-moz-range-thumb:hover {
    background: hsl(var(--primary) / 0.9);
}

.btn-download-header {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--primary-foreground));
    background-color: hsl(var(--primary));
    border: none;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    white-space: nowrap;
}

.btn-download-header:hover {
    background-color: hsl(var(--primary) / 0.9);
}

.btn-download-header:active {
    transform: scale(0.98);
}

.file-input {
    display: none;
}

.file-upload-label {
    display: block;
    margin-bottom: 0.375rem;
}

.file-upload-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    background-color: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.2s;
}

.file-upload-button:hover {
    background-color: hsl(var(--accent));
}

.btn-clear {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: hsl(var(--destructive-foreground));
    background-color: hsl(var(--destructive));
    border: none;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.btn-clear:hover {
    background-color: hsl(var(--destructive) / 0.9);
}

.btn-clear:active {
    transform: scale(0.98);
}

.preview-card {
    margin: 1rem;
    height: calc(100% - 2rem);
    display: flex;
    flex-direction: column;
}

.preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
}

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

#previewCanvas {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid hsl(var(--border));
    border-radius: calc(var(--radius) - 2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    background-color: white;
}

.preview-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    flex: 1;
}

.preview-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.preview-info {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.toggle-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    display: inline-block;
    width: 2.25rem;
    height: 1.25rem;
    background-color: hsl(var(--input));
    border-radius: 9999px;
    transition: background-color 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 1rem;
    width: 1rem;
    left: 0.125rem;
    bottom: 0.125rem;
    background-color: hsl(var(--background));
    border-radius: 9999px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.toggle-input:checked + .toggle-slider {
    background-color: hsl(var(--primary));
}

.toggle-input:checked + .toggle-slider::before {
    transform: translateX(1rem);
}

.toggle-input:focus-visible + .toggle-slider {
    outline: 2px solid hsl(var(--ring));
    outline-offset: 2px;
}

.toggle-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: hsl(var(--foreground));
}

.toggle-wrapper-small {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.toggle-slider-small {
    position: relative;
    display: inline-block;
    width: 2rem;
    height: 1.125rem;
    background-color: hsl(var(--input));
    border-radius: 9999px;
    transition: background-color 0.2s;
}

.toggle-slider-small::before {
    content: '';
    position: absolute;
    height: 0.875rem;
    width: 0.875rem;
    left: 0.125rem;
    bottom: 0.125rem;
    background-color: hsl(var(--background));
    border-radius: 9999px;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.toggle-input:checked + .toggle-slider-small {
    background-color: hsl(var(--primary));
}

.toggle-input:checked + .toggle-slider-small::before {
    transform: translateX(0.875rem);
}

@media (min-width: 1024px) {
    .main-content {
        grid-template-columns: 300px 1fr 420px;
    }

    .config-panel-left {
        border-right: 1px solid hsl(var(--border));
        overflow: hidden;
    }

    .config-panel-right {
        overflow: hidden;
    }

    .preview-panel {
        overflow: hidden;
    }
}

@media (max-width: 1023px) {
    .config-panel-right {
        display: none;
    }

    .header {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .panel-scroll {
        padding: 1rem;
    }

    .card {
        margin-bottom: 0;
    }

    .card-header,
    .card-content {
        padding: 1rem;
    }

    .preview-card {
        margin: 1rem;
        height: auto;
        min-height: 400px;
    }

    .preview-content {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 0.75rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .panel-scroll {
        padding: 0.75rem;
    }

    .card-content {
        padding: 0.875rem;
    }

    .preview-card {
        margin: 0.75rem;
    }

    .btn-download-header {
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
        gap: 0.25rem;
    }

    .btn-download-header svg {
        width: 14px;
        height: 14px;
    }

    .preview-header-left {
        gap: 0.5rem;
    }

    .preview-header-right {
        gap: 0.5rem;
    }

    .toggle-slider {
        width: 2rem;
        height: 1.125rem;
    }

    .toggle-slider::before {
        height: 0.875rem;
        width: 0.875rem;
    }

    .toggle-input:checked + .toggle-slider::before {
        transform: translateX(0.875rem);
    }

    .toggle-label {
        font-size: 0.75rem;
    }
}
