* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #0f0f1a;
    color: #e0e0e0;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: 360px;
    background: #1a1a2e;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid #2d2d44;
    display: flex;
    flex-direction: column;
}

#sidebar h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    color: #fff;
}

.subtitle {
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.site-logo {
    display: inline-block;
    margin-bottom: 12px;
}

.site-logo img {
    height: 24px;
    width: auto;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed #4a4a6a;
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
    position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone svg {
    color: #6366f1;
    margin-bottom: 12px;
}

.drop-zone p {
    margin-bottom: 4px;
}

.drop-zone .hint {
    font-size: 0.8rem;
    color: #666;
}

.drop-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* Info Panel */
.info-panel {
    background: #252540;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.info-panel h3 {
    font-size: 0.9rem;
    margin-bottom: 0;
    color: #fff;
}

/* Edit Mode Toggle */
.edit-mode-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #4a4a6a;
    border-radius: 4px;
    color: #888;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.edit-mode-toggle:hover {
    border-color: #6366f1;
    color: #ccc;
}

.edit-mode-toggle.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.edit-mode-toggle svg {
    flex-shrink: 0;
}

.info-row {
    font-size: 0.9rem;
    color: #fff;
    margin-bottom: 4px;
}

.info-row.secondary {
    font-size: 0.8rem;
    color: #888;
}

.type-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.type-stat {
    font-size: 0.75rem;
    background: #1a1a2e;
    padding: 4px 8px;
    border-radius: 4px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 4px;
}

.type-icon {
    font-size: 0.9rem;
}

/* Editor Controls */
.editor-controls {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #2d2d44;
}

.btn-editor {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
    background: #3d3d5c;
    color: #ccc;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-editor:hover:not(:disabled) {
    background: #4d4d6c;
    color: #fff;
}

.btn-editor:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-editor svg {
    flex-shrink: 0;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    color: #fff;
}

.btn-save {
    background: #059669;
}

.btn-save:hover:not(:disabled) {
    background: #10b981;
}

.btn-save.has-changes {
    animation: pulse-save 2s infinite;
}

@keyframes pulse-save {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* Search */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #252540;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.search-box svg {
    color: #666;
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
}

.search-box input::placeholder {
    color: #666;
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.filter-btn {
    padding: 6px 12px;
    background: #252540;
    border: none;
    border-radius: 6px;
    color: #888;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #2d2d50;
    color: #ccc;
}

.filter-btn.active {
    background: #6366f1;
    color: #fff;
}

/* Sort Bar */
.sort-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.75rem;
    color: #666;
}

.sort-buttons {
    display: flex;
    gap: 4px;
}

.sort-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid #3d3d5c;
    border-radius: 4px;
    color: #888;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sort-btn:hover {
    border-color: #6366f1;
    color: #ccc;
}

.sort-btn.active {
    background: #3d3d5c;
    color: #fff;
}

.sort-btn.desc::after {
    content: ' ↓';
}

.sort-btn.active:not(.desc)::after {
    content: ' ↑';
}

/* File List */
.file-list-container {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 12px;
    min-height: 200px;
    max-height: calc(100vh - 580px);
    border: 2px dashed transparent;
    border-radius: 8px;
    transition: all 0.2s;
}

.file-list-container.drag-over {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: #252540;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.file-item:hover {
    background: #2d2d50;
}

/* Active item (currently previewing) */
.file-item.active {
    background: #6366f1;
}

.file-item.active .file-size {
    color: rgba(255, 255, 255, 0.7);
}

/* Selected items (edit mode multi-select) */
.file-list-container.edit-mode .file-item.selected {
    background: #6366f1;
}

.file-list-container.edit-mode .file-item.selected .file-size {
    color: rgba(255, 255, 255, 0.7);
}

/* File state indicators (edit mode) */
.file-list-container.edit-mode .file-item.imported {
    border-left: 3px solid #10b981;
}

.file-list-container.edit-mode .file-item.modified {
    border-left: 3px solid #f59e0b;
}

/* Checkbox for multi-select */
.file-checkbox {
    width: 14px;
    height: 14px;
    accent-color: #6366f1;
    cursor: pointer;
    flex-shrink: 0;
}

/* Status indicators */
.status-icon {
    display: inline-block;
    margin-left: 4px;
    font-weight: bold;
    font-size: 0.7rem;
}

.status-icon.new {
    color: #10b981;
}

.status-icon.modified {
    color: #f59e0b;
}

/* Selection info */
#selection-info {
    color: #6366f1;
    font-weight: 500;
    margin-left: auto;
    margin-right: 8px;
}

/* Rename input */
.rename-input {
    flex: 1;
    background: #1a1a2e;
    border: 1px solid #6366f1;
    border-radius: 3px;
    color: #fff;
    font-size: 0.8rem;
    padding: 2px 4px;
    outline: none;
    min-width: 0;
}

.rename-ext {
    color: #888;
    font-size: 0.8rem;
}

.file-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.file-name {
    flex: 1;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    font-size: 0.7rem;
    color: #666;
    flex-shrink: 0;
}

.extract-btn {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.extract-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #6366f1;
}

.file-item.active .extract-btn {
    color: rgba(255, 255, 255, 0.6);
}

.file-item.active .extract-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* Extract Actions */
.extract-actions {
    display: flex;
    gap: 8px;
}

.btn {
    flex: 1;
    padding: 10px 16px;
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover {
    background: #5457e5;
}

.btn-secondary {
    background: #3d3d5c;
}

.btn-secondary:hover {
    background: #4d4d6c;
}

/* Main Area */
#main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #0f0f1a;
}

#empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #444;
    gap: 16px;
}

#empty-state svg {
    opacity: 0.5;
}

#empty-state h2 {
    font-size: 1.2rem;
    color: #666;
}

#empty-state p {
    font-size: 0.9rem;
}

/* Preview Panel */
#preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.preview-header {
    padding: 16px 20px;
    background: #1a1a2e;
    border-bottom: 1px solid #2d2d44;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-header h2 {
    font-size: 1rem;
    color: #fff;
}

.preview-header span {
    font-size: 0.8rem;
    color: #888;
}

.preview-content {
    flex: 1;
    position: relative;
    min-height: 0; /* Important for flex child to shrink */
}

#preview-3d {
    background: #1a1a2e;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#preview-texture {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px;
    overflow-y: auto;
}

#texture-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.texture-item {
    position: relative;
    aspect-ratio: 1;
    background: #252540;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.texture-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.texture-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.texture-item .texture-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    padding: 4px 6px;
    font-size: 0.65rem;
    color: #ccc;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.texture-item .texture-size {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    font-size: 0.6rem;
    color: #888;
    border-radius: 3px;
}

#preview-info {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20px;
    overflow-y: auto;
}

#file-info-content {
    font-size: 0.85rem;
    line-height: 1.8;
}

#file-info-content .info-row {
    margin-bottom: 8px;
}

#file-info-content .info-row span {
    color: #888;
    margin-right: 8px;
}

.hex-preview {
    margin-top: 16px;
    padding: 12px;
    background: #1a1a2e;
    border-radius: 6px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.7rem;
    line-height: 1.6;
    color: #888;
    overflow-x: auto;
    white-space: pre;
}

#no-preview {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666;
    gap: 12px;
}

#no-preview svg {
    opacity: 0.5;
}

/* Loading */
#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 26, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #2d2d44;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Credits */
.credits {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid #2d2d44;
    font-size: 0.75rem;
    color: #666;
    text-align: center;
}

.credits a {
    color: #888;
    text-decoration: none;
    transition: color 0.2s;
}

.credits a:hover {
    color: #6366f1;
}

.credits a.author {
    color: #6366f1;
    font-weight: 500;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
    background: #3d3d5c;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4d4d6c;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 0.85rem;
}

/* Mobile Toggle Button */
.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #6366f1;
    color: white;
    border: none;
    cursor: pointer;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    align-items: center;
    justify-content: center;
}

.mobile-toggle svg {
    width: 24px;
    height: 24px;
}

/* Responsive - Tablet */
@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    #app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    #sidebar {
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid #2d2d44;
        padding: 16px;
    }

    #sidebar h1 {
        font-size: 1.25rem;
    }

    .file-list-container {
        max-height: 250px;
        min-height: 150px;
    }

    #main-area {
        min-height: 400px;
    }

    .credits {
        display: none;
    }
}

/* Responsive - Mobile */
@media (max-width: 640px) {
    #sidebar {
        padding: 12px;
    }

    #sidebar h1 {
        font-size: 1.1rem;
    }

    .subtitle {
        font-size: 0.8rem;
        margin-bottom: 12px;
    }

    .drop-zone {
        padding: 20px 16px;
        margin-bottom: 12px;
    }

    .drop-zone svg {
        width: 36px;
        height: 36px;
    }

    .drop-zone p {
        font-size: 0.9rem;
    }

    .info-panel {
        padding: 12px;
        margin-bottom: 12px;
    }

    .editor-controls {
        flex-wrap: wrap;
        gap: 8px;
    }

    .btn-editor {
        padding: 10px 14px;
        font-size: 0.75rem;
    }

    .search-box {
        padding: 12px;
    }

    .search-box input {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .filters {
        gap: 8px;
    }

    .filter-btn {
        padding: 10px 14px;
        font-size: 0.75rem;
    }

    .file-list-container {
        max-height: 200px;
    }

    .file-item {
        padding: 12px;
        gap: 10px;
    }

    .file-checkbox {
        width: 20px;
        height: 20px;
    }

    .file-name {
        font-size: 0.85rem;
    }

    .file-size {
        font-size: 0.75rem;
    }

    .extract-btn {
        padding: 8px;
    }

    .extract-actions {
        flex-direction: column;
    }

    .btn {
        padding: 14px 16px;
        font-size: 0.85rem;
    }

    #main-area {
        min-height: 350px;
    }

    .preview-header {
        padding: 12px 16px;
    }

    .preview-header h2 {
        font-size: 0.9rem;
    }

    #preview-texture {
        padding: 12px;
    }

    #texture-preview-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
    }

    .texture-item:hover {
        transform: none; /* Disable on touch */
    }

    #preview-info {
        padding: 12px;
    }

    .hex-preview {
        font-size: 0.65rem;
    }

    .mobile-toggle {
        display: flex;
    }

    /* When sidebar is hidden on mobile */
    #app.preview-mode #sidebar {
        display: none;
    }

    #app.preview-mode #main-area {
        min-height: 100vh;
    }

    #app.preview-mode .mobile-toggle svg {
        transform: rotate(180deg);
    }
}

/* Very small phones */
@media (max-width: 380px) {
    #sidebar {
        padding: 10px;
    }

    .info-panel {
        padding: 10px;
    }

    .editor-controls {
        gap: 6px;
    }

    .btn-editor {
        padding: 8px 10px;
        font-size: 0.7rem;
        gap: 4px;
    }

    .btn-editor span {
        display: none; /* Hide text, keep icons */
    }

    .filter-btn {
        padding: 8px 10px;
    }

    .type-stats {
        gap: 4px;
    }

    .type-stat {
        font-size: 0.7rem;
        padding: 3px 6px;
    }
}
