:root {
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --bg-hover: #334155;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --glass: rgba(30, 41, 59, 0.7);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    height: 60px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--primary);
}

.app-nav {
    display: flex;
    gap: 8px;
    background: var(--bg-dark);
    padding: 4px;
    border-radius: var(--radius-sm);
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn.active {
    background: var(--bg-panel);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.nav-btn:hover:not(.active) {
    color: var(--text-main);
}

/* Main Content */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    inset: 0;
    display: none;
    background: var(--bg-dark);
}

.view.active {
    display: flex;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Scroll internal */
}

.sidebar-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}

.right-sidebar {
    border-right: none;
    border-left: 1px solid var(--border);
}

.properties-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.prop-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.panel-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.tool-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Buttons & Inputs */
.custom-file-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--bg-hover);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px dashed var(--border);
    transition: all 0.2s;
}

.custom-file-upload:hover {
    border-color: var(--primary);
    color: var(--primary);
}

input[type="file"] {
    display: none;
}

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.tool-btn {
    background: var(--bg-hover);
    border: none;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--bg-dark);
    transform: translateY(-2px);
}

.tool-btn i {
    font-size: 1.2rem;
    color: var(--primary);
}

.shape-grid {
    display: flex;
    gap: 8px;
}

.shape-btn {
    flex: 1;
    background: var(--bg-hover);
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.shape-btn.active,
.shape-btn:hover {
    background: var(--bg-dark);
    border-color: var(--primary);
    color: var(--primary);
}

.preview-card {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-hover);
    transition: transform 0.2s;
}

.preview-card:hover {
    transform: scale(1.02);
}

.preview-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 0.8rem;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(4px);
    pointer-events: none;
    /* Let the click pass to the card */
}

.preview-info i {
    font-size: 1rem;
    color: var(--primary);
}

.action-btn {
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.action-btn.secondary {
    background: var(--bg-hover);
    color: var(--text-main);
}

.action-btn.primary {
    background: var(--primary);
    color: white;
}

.action-btn.danger {
    background: var(--danger);
    color: white;
}

.action-btn:hover {
    opacity: 0.9;
}

/* Layers List */
.layers-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layer-item {
    padding: 10px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.layer-item:hover {
    background: #2a384e;
}

.layer-item.active {
    border-color: var(--primary);
    background: #2a384e;
}

.layer-item i {
    color: var(--text-muted);
}

.layer-item.empty {
    background: transparent;
    color: var(--text-muted);
    font-style: italic;
    justify-content: center;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    background: #000;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-image: radial-gradient(#1e293b 1px, transparent 1px);
    background-size: 20px 20px;
}

.canvas-wrapper {
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s;
}

canvas {
    display: block;
    background: #fff;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: var(--bg-dark);
    z-index: 10;
    pointer-events: none;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Properties Panel */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 24px 24px 0 24px;
}

.panel-header span {
    font-size: 0.8rem;
    background: var(--primary);
    padding: 2px 8px;
    border-radius: 99px;
    font-weight: 600;
}

.prop-group {
    margin-bottom: 16px;
}

.prop-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.prop-input,
select.prop-input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: inherit;
}

.prop-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Range Slider */
.prop-range {
    width: 100%;
    height: 6px;
    background: var(--bg-dark);
    border-radius: 4px;
    outline: none;
    appearance: none;
}

.prop-range::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

/* Toggle Group */
.toggle-group {
    display: flex;
    gap: 4px;
    background: var(--bg-dark);
    padding: 2px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.toggle-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
}

.toggle-btn.active {
    background: var(--bg-hover);
    color: var(--text-main);
}

.hint-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    margin-top: 40px;
}

/* Generator View */
.generator-container {
    flex: 1;
    padding: 40px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    overflow-y: auto;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 60px;
    text-align: center;
    background: var(--bg-panel);
    transition: all 0.3s;
    cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.upload-zone i {
    font-size: 4rem;
    color: var(--primary);
    margin-bottom: 24px;
}

.upload-zone h3 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-muted);
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
}

.preview-card {
    background: var(--bg-panel);
    border-radius: var(--radius-md);
    padding: 12px;
    border: 1px solid var(--border);
}

.preview-image {
    width: 100%;
    aspect-ratio: 1;
    background: #000;
    border-radius: var(--radius-sm);
    object-fit: contain;
}

/* Generator V3 Setup Grid */
.generator-setup-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.setup-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    transition: transform 0.2s;
}

.setup-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
}

.card-icon {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 16px;
}

.setup-card h3 {
    margin-bottom: 8px;
}

.setup-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.badge {
    margin-top: 16px;
    font-size: 0.75rem;
    background: var(--bg-hover);
    padding: 4px 12px;
    border-radius: 99px;
    display: inline-block;
    color: var(--text-muted);
}

/* Progress Overlay */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-modal {
    background: var(--bg-panel);
    width: 450px;
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.modal-header h3 {
    text-align: center;
    margin-bottom: 24px;
    color: var(--text-main);
}

.progress-container {
    height: 12px;
    background: var(--bg-dark);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #818cf8);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--primary);
}

.progress-stats {
    margin-bottom: 24px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 12px;
}

.stat-details {
    background: var(--bg-dark);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

#current-file {
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
}

.time-stats {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
}

.modal-footer {
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

.success-msg {
    color: #10b981;
    font-weight: 600;
    margin-bottom: 16px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}