* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #0f0f1a;
    color: #e4e4e7;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    display: flex;
    min-height: 100vh;
}

/* Left Preview Area */
#preview-area {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: 100vh;
}

.site-logo {
    display: inline-block;
    margin-bottom: 8px;
}

.site-logo img {
    height: 40px;
    width: auto;
}

.preview-header h1 {
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 4px;
}

.preview-header .subtitle {
    font-size: 0.9rem;
    color: #71717a;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed #3d3d5c;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(99, 102, 241, 0.03);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.08);
}

.drop-zone-content svg {
    color: #6366f1;
    margin-bottom: 12px;
}

.drop-zone-content p {
    color: #a1a1aa;
    margin-bottom: 4px;
}

.drop-zone .hint {
    font-size: 0.85rem;
    color: #52525b;
}

.drop-zone input[type="file"] {
    display: none;
}

/* Tabs */
.tabs-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.tab-buttons {
    display: flex;
    gap: 4px;
    background: #1a1a2e;
    padding: 4px;
    border-radius: 8px;
    margin-bottom: 12px;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: #71717a;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: #a1a1aa;
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    background: #6366f1;
    color: #fff;
}

.tab-content {
    flex: 1;
    background: #1a1a2e;
    border-radius: 12px;
    overflow: hidden;
    min-height: 250px;
}

/* Texture Grid */
.texture-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.texture-grid-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #252540;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.texture-grid-item:hover {
    border-color: #6366f1;
}

.texture-grid-item.selected {
    border-color: #22c55e;
}

.texture-grid-item.excluded {
    opacity: 0.4;
}

.texture-grid-item img,
.texture-grid-item canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.texture-grid-item .texture-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.8);
    font-size: 0.7rem;
    color: #a1a1aa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.texture-grid-item .select-indicator {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #52525b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.texture-grid-item.selected .select-indicator {
    background: #22c55e;
    border-color: #22c55e;
}

.texture-grid-item.selected .select-indicator::after {
    content: '';
    width: 8px;
    height: 5px;
    border: 2px solid #fff;
    border-top: none;
    border-right: none;
    transform: rotate(-45deg);
    margin-top: -2px;
}

/* Atlas Preview */
.atlas-preview-container {
    width: 100%;
    height: 100%;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: auto;
}

.atlas-preview-container canvas {
    max-width: 100%;
    max-height: 100%;
    background: repeating-conic-gradient(#252540 0% 25%, #1a1a2e 0% 50%) 50% / 16px 16px;
    border: 1px solid #3d3d5c;
    border-radius: 4px;
}

.atlas-empty,
.model-empty {
    text-align: center;
    color: #52525b;
    padding: 40px;
}

/* 3D Viewport */
#viewport {
    width: 100%;
    height: 100%;
    min-height: 300px;
    position: relative;
}

#viewport canvas {
    width: 100%;
    height: 100%;
}

/* Stats Bar */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 20px;
    background: #1a1a2e;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 0.85rem;
    color: #71717a;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: #e4e4e7;
}

.stat-arrow {
    color: #52525b;
}

.reduction-badge {
    padding: 4px 10px;
    background: #22c55e;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 12px;
}

.reduction-badge.negative {
    background: #ef4444;
}

/* Right Options Panel */
#options-panel {
    width: 320px;
    background: #1a1a2e;
    border-left: 1px solid #252540;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 100vh;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid #252540;
}

.panel-section h3 {
    font-size: 0.9rem;
    color: #a1a1aa;
    margin-bottom: 12px;
    font-weight: 600;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    margin-bottom: 0;
}

.section-actions {
    display: flex;
    gap: 4px;
}

/* Loaded Files */
.loaded-files {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loaded-file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #252540;
    border-radius: 8px;
}

.file-icon {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.file-icon.dff {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
}

.file-icon.txd {
    background: rgba(168, 85, 247, 0.2);
    color: #c084fc;
}

.file-name {
    flex: 1;
    font-size: 0.85rem;
    color: #e4e4e7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.remove-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.2s;
}

.remove-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

.no-files-msg,
.empty-list-msg {
    font-size: 0.85rem;
    color: #52525b;
    text-align: center;
    padding: 12px;
}

/* Settings */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    font-size: 0.85rem;
    color: #a1a1aa;
}

.setting-row select,
.setting-row input[type="text"] {
    width: 140px;
    padding: 8px 12px;
    background: #252540;
    border: 1px solid #3d3d5c;
    border-radius: 6px;
    color: #e4e4e7;
    font-size: 0.85rem;
}

.setting-row select:focus,
.setting-row input:focus {
    outline: none;
    border-color: #6366f1;
}

/* Texture List */
.texture-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.texture-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #252540;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.texture-list-item:hover {
    border-color: #3d3d5c;
}

.texture-list-item.excluded {
    opacity: 0.5;
}

.texture-list-item .tex-checkbox {
    width: 18px;
    height: 18px;
    accent-color: #22c55e;
    cursor: pointer;
}

.texture-list-item .tex-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: #1a1a2e;
    object-fit: contain;
    image-rendering: pixelated;
}

.texture-list-item .tex-info {
    flex: 1;
    min-width: 0;
}

.texture-list-item .tex-name {
    font-size: 0.8rem;
    color: #e4e4e7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.texture-list-item .tex-dims {
    font-size: 0.7rem;
    color: #52525b;
}

.texture-list-item .tex-options {
    display: flex;
    gap: 4px;
}

.texture-list-item select {
    padding: 4px 6px;
    font-size: 0.7rem;
    background: #1a1a2e;
    border: 1px solid #3d3d5c;
    border-radius: 4px;
    color: #a1a1aa;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    transform: translateY(-1px);
}

.btn-secondary {
    background: #252540;
    color: #a1a1aa;
    border: 1px solid #3d3d5c;
}

.btn-secondary:hover:not(:disabled) {
    background: #2d2d50;
    color: #e4e4e7;
}

.small-btn {
    padding: 4px 10px;
    background: #252540;
    border: 1px solid #3d3d5c;
    border-radius: 4px;
    color: #a1a1aa;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.small-btn:hover {
    background: #2d2d50;
    color: #e4e4e7;
}

/* Actions Section */
.actions-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.actions-section .btn {
    width: 100%;
}

/* Download Section */
.download-section {
    background: rgba(34, 197, 94, 0.05);
}

.download-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.download-btn {
    padding: 10px;
    font-size: 0.85rem;
}

.download-btn svg {
    width: 14px;
    height: 14px;
}

/* Credits */
.credits {
    padding: 16px;
    text-align: center;
    font-size: 0.8rem;
    color: #52525b;
    margin-top: auto;
}

.credits a {
    color: #6366f1;
    text-decoration: none;
}

.credits a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background: #1a1a2e;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #71717a;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #252540;
    color: #e4e4e7;
}

/* Progress Modal */
.progress-modal-content {
    text-align: center;
}

.progress-modal-content h3 {
    color: #fff;
    margin-bottom: 20px;
}

.progress-bar {
    height: 8px;
    background: #252540;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    color: #71717a;
}

/* Error Modal */
.error-modal-content {
    text-align: center;
}

.error-icon {
    color: #f87171;
    margin-bottom: 16px;
}

.error-modal-content h3 {
    color: #f87171;
    margin-bottom: 12px;
}

.error-modal-content p {
    color: #a1a1aa;
    margin-bottom: 20px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.error-modal-content .btn {
    min-width: 100px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
    background: #3d3d5c;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #52525b;
}

/* Responsive */
@media (max-width: 900px) {
    #app {
        flex-direction: column;
    }

    #preview-area {
        max-height: none;
    }

    #options-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #252540;
        max-height: none;
    }

    .tabs-container {
        min-height: 250px;
    }
}

@media (max-width: 600px) {
    #preview-area {
        padding: 16px;
    }

    .preview-header h1 {
        font-size: 1.25rem;
    }

    .drop-zone {
        padding: 30px 16px;
    }

    .texture-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }

    .stats-bar {
        flex-wrap: wrap;
        gap: 12px;
    }

    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .setting-row select,
    .setting-row input[type="text"] {
        width: 100%;
    }

    .download-buttons {
        grid-template-columns: 1fr;
    }
}
