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

:root {
    --bg-primary: #fafafa;
    --bg-card: #ffffff;
    --bg-input: #f5f5f5;
    --border-color: #e5e5e5;
    --text-primary: #1a1a1a;
    --text-secondary: #737373;
    --accent: #525252;
    --dot-color: #d4d4d4;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-card: #141414;
    --bg-input: #1a1a1a;
    --border-color: #262626;
    --text-primary: #ededed;
    --text-secondary: #a3a3a3;
    --accent: #d4d4d4;
    --dot-color: #262626;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    animation: slideIn 0.4s ease;
}

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

@media (max-width: 480px) {
    .container {
        padding: 1rem;
    }
}

header {
    margin-bottom: 2.5rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.4rem;
    }
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.8rem;
    font-weight: 600;
    position: relative;
    overflow: hidden;
}

.icon-btn:hover {
    border-color: var(--accent);
    background: var(--bg-input);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

.icon-btn svg {
    width: 20px;
    height: 20px;
    position: relative;
    z-index: 1;
}

[data-theme="dark"] .sun-icon {
    display: block;
}

[data-theme="dark"] .moon-icon {
    display: none;
}

[data-theme="light"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: block;
}

.upload-section {
    padding: 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
    animation: slideIn 0.4s ease 0.05s both;
}

@media (max-width: 480px) {
    .upload-section {
        padding: 1rem;
    }
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2.5rem 1.5rem;
    background: var(--bg-input);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 480px) {
    .upload-label {
        padding: 2rem 1rem;
    }
}

.upload-label:hover {
    border-color: var(--accent);
    background: var(--bg-card);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.upload-label:hover svg {
    color: var(--text-primary);
    transform: translateY(-3px);
}

.upload-label svg {
    color: var(--text-secondary);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#fileInput {
    display: none;
}

.settings-section {
    margin-top: 1.5rem;
    animation: slideIn 0.4s ease 0.1s both;
}

.preview-container {
    padding: 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@media (max-width: 480px) {
    .preview-container {
        padding: 0.75rem;
        border-radius: var(--radius-md);
    }
}

#previewCanvas {
    max-width: 100%;
    border-radius: var(--radius-md);
    background: repeating-conic-gradient(var(--border-color) 0% 25%, var(--bg-input) 0% 50%) 50% / 16px 16px;
    animation: canvasFadeIn 0.4s ease;
}

@keyframes canvasFadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.controls {
    margin-top: 1rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    align-items: end;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@media (max-width: 600px) {
    .controls {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 400px) {
    .controls {
        grid-template-columns: 1fr;
    }
}

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

.control-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

input[type="number"]:hover,
input[type="text"]:hover {
    border-color: var(--accent);
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(128, 128, 128, 0.1);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem 0;
    text-transform: none;
    letter-spacing: normal;
    transition: opacity 0.2s ease;
}

.checkbox-group label:hover {
    opacity: 0.8;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    cursor: pointer;
    accent-color: var(--text-primary);
}

button {
    padding: 0.875rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s ease;
}

button:hover::before {
    left: 100%;
}

button:hover {
    border-color: var(--accent);
    background: var(--bg-input);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

button:active {
    transform: translateY(0);
}

@media (max-width: 400px) {
    button {
        padding: 0.75rem 1rem;
    }
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-card);
    border-color: var(--text-primary);
}

.btn-primary:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-card);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}

.results-section {
    margin-top: 1.5rem;
    animation: slideIn 0.4s ease 0.15s both;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
}

@media (max-width: 480px) {
    .results-header {
        flex-wrap: wrap;
        padding: 0.875rem 1rem;
    }
}

.results-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

#imageCount {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    white-space: nowrap;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 480px) {
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 0.5rem;
    }
}

@media (max-width: 350px) {
    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.result-item {
    position: relative;
    aspect-ratio: 1;
    background: repeating-conic-gradient(var(--border-color) 0% 25%, var(--bg-input) 0% 50%) 50% / 12px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    animation: resultFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes resultFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.result-item:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1;
}

.result-item.empty {
    opacity: 0.3;
}

.result-item.empty:hover {
    opacity: 0.5;
}

.result-item canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.result-item .download-btn {
    position: absolute;
    bottom: 0.5rem;
    right: 0.5rem;
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(4px);
}

@media (hover: none) {
    .result-item .download-btn {
        opacity: 1;
    }
}

.result-item:hover .download-btn {
    opacity: 1;
    transform: translateY(0);
}

.result-item .download-btn:hover {
    background: var(--text-primary);
    color: var(--bg-card);
}

.results-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .results-actions {
        flex-direction: column;
    }

    .results-actions button {
        width: 100%;
    }
}
