/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(139, 92, 246, 0.3);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent-primary: #8b5cf6;
    --accent-secondary: #a78bfa;
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #06b6d4);
    --success: #22c55e;
    --error: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.15);
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== App Container ===== */
.app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 3rem;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.github-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.625rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.github-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-secondary);
    transform: translateY(-2px);
}

.github-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== Main Content ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ===== Upload Section ===== */
.upload-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.upload-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    transition: var(--transition);
}

.upload-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
}

.upload-card h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Drop Zone ===== */
.drop-zone {
    position: relative;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.drop-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    transition: var(--transition);
}

.drop-zone:hover .drop-icon {
    color: var(--accent-primary);
    transform: scale(1.1);
}

.drop-zone p {
    font-weight: 500;
    color: var(--text-primary);
}

.drop-zone span {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.preview-image {
    display: none;
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

.drop-zone.has-image .drop-zone-content {
    display: none;
}

.drop-zone.has-image .preview-image {
    display: block;
}

/* ===== Overlay Checklist ===== */
.overlay-checklist {
    list-style: none;
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    font-size: 0.75rem;
}

.overlay-checklist li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: var(--transition);
}

.overlay-checklist li.loaded {
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.overlay-checklist li::before {
    content: '○';
    font-size: 0.625rem;
}

.overlay-checklist li.loaded::before {
    content: '●';
}

/* ===== Overlay Mode Toggle ===== */
.overlay-mode-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mode-btn {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.mode-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* ===== Image Controls ===== */
.image-editor-wrapper {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.image-editor-wrapper .preview-grid {
    flex: 1;
    display: grid;
    /* Center tracks if needed, but 1fr cols fill width */
    justify-content: center;
    align-content: center;
    max-width: 360px;
    margin: 0 auto;
    /* Center in flex space */
}

.controls-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-width: 280px;
}

.controls-container.visible {
    display: flex;
}

.control-group {
    flex: 1;
    min-width: 110px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.controls-container label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.controls-container label span {
    color: var(--accent-primary);
    font-weight: 600;
}

.controls-container input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.controls-container input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: grab;
    transition: transform 0.2s;
}

.controls-container input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.reset-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: rotate(90deg);
}

.reset-btn svg {
    width: 18px;
    height: 18px;
}

.hidden {
    display: none !important;
}

/* ===== Transparent Background Button ===== */
.transparent-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.transparent-btn svg {
    width: 18px;
    height: 18px;
}

.transparent-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
}

.transparent-btn.active {
    border-style: solid;
    border-color: var(--success);
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

/* ===== Options Section ===== */
.options-section {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.option-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.toggle-buttons {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn svg {
    width: 16px;
    height: 16px;
}

.toggle-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* ===== Generate Button ===== */
.generate-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-glow);
}

.generate-btn svg {
    width: 20px;
    height: 20px;
}

.generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 60px rgba(139, 92, 246, 0.3);
}

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

/* ===== Preview Section ===== */
.preview-section {
    display: none;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.preview-section.visible {
    display: flex;
}

.preview-section h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    max-width: 500px;
    margin: 0 auto;
}

/* Position 0 key in center of last row */
.preview-item[data-key="0"] {
    grid-column: 2;
}

.preview-item {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 300 / 287;
    border: 1px solid var(--border-color);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-item .label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
}

/* ===== Download Button ===== */
.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: var(--success);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    align-self: center;
}

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

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 40px rgba(34, 197, 94, 0.3);
}

.download-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.download-btn.passthm {
    background: var(--accent-primary);
}

.download-btn.passthm:hover {
    box-shadow: 0 0 40px rgba(139, 92, 246, 0.3);
}

/* ===== Filename Input ===== */
.filename-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filename-input label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.filename-input input {
    padding: 0.625rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    min-width: 200px;
    transition: var(--transition);
}

.filename-input input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding-top: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}


/* ===== Animations ===== */
@keyframes popIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.header,
.upload-card,
.options-section,
.footer {
    opacity: 0;
    animation: popIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.header {
    animation-delay: 0.1s;
}

.upload-card:nth-child(1) {
    animation-delay: 0.2s;
}

.upload-card:nth-child(2) {
    animation-delay: 0.3s;
}

.options-section {
    animation-delay: 0.4s;
}

.footer {
    animation-delay: 0.5s;
    text-align: center;
    margin-top: 3rem;
    padding-bottom: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Preview section pops in when it appears */
.preview-section {
    animation: popIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .app {
        padding: 1rem;
    }

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

    .options-section {
        flex-direction: column;
        gap: 1.5rem;
    }

    .overlay-checklist {
        grid-template-columns: 1fr;
    }

    .preview-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .image-editor-wrapper {
        flex-direction: column;
    }

    .image-editor-wrapper .preview-grid {
        margin: 0 auto;
        width: 100%;
    }

    .controls-container {
        width: 100%;
        min-width: auto;
    }
}