:root {
    --bg-color: #0e0f14;
    --sidebar-bg: #181a20;
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary-color: #6366f1;
    /* Indigo */
    --primary-hover: #4f46e5;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --input-bg: #27272a;
    --input-border: #3f3f46;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --wrapper-padding: 40px;
    /* Mobile responsive padding */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 340px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    background: var(--sidebar-bg);
    z-index: 10;
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.35);
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-area h1::before {
    content: '';
    display: block;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    border-radius: 6px;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    /* Space for scrollbar */
}

/* Custom Scrollbar */
.controls::-webkit-scrollbar {
    width: 6px;
}

.controls::-webkit-scrollbar-track {
    background: transparent;
}

.controls::-webkit-scrollbar-thumb {
    background: var(--input-border);
    border-radius: 3px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.control-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="number"],
input[type="text"] {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    width: 100%;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Color Input */
.color-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--input-bg);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--input-border);
    cursor: pointer;
    transition: border-color 0.2s;
}

.color-input-wrapper:hover {
    border-color: var(--text-muted);
}

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 32px;
    height: 32px;
    cursor: pointer;
    background: none;
    padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.color-input-wrapper span {
    font-family: monospace;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Buttons */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.btn {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    font-size: 0.95rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), #4f46e5);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: translateY(0);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--input-border);
    color: var(--text-muted);
}

.secondary-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

.status-bar {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
    font-weight: 500;
}

.status-bar span {
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    line-height: 1.2;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.han-controls .inline-input {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.han-controls .hint-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

.hint-text.subtle {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.8rem;
}

.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 500;
    max-width: 320px;
    pointer-events: none;
}

.toast {
    background: rgba(20, 20, 24, 0.92);
    color: #f8fafc;
    padding: 12px 14px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.9rem;
    line-height: 1.4;
    transform: translateY(-8px);
    opacity: 0;
    animation: toast-in 140ms ease-out forwards;
}

@keyframes toast-in {
    from {
        transform: translateY(-8px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}

.modal-backdrop.active {
    display: flex;
}

.modal {
    background: #16161a;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    width: min(760px, 90vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.modal-header,
.modal-footer {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-footer {
    border-bottom: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    gap: 12px;
}

.modal-body {
    padding: 12px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: auto;
    max-height: 60vh;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.icon-btn.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.radio-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.radio {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-main);
    font-weight: 600;
}

.inline-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inline-input input[type="range"] {
    flex: 1;
}

.preview-list {
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.02);
}

.preview-list-header,
.preview-list-item {
    display: grid;
    grid-template-columns: 1fr 120px 120px;
    align-items: center;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.preview-list-header {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font-weight: 600;
}

.preview-list-item {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.preview-list-item .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-preview {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.btn.han-disabled {
    cursor: not-allowed;
    opacity: 0.6;
    filter: grayscale(0.2);
}

/* Main Area */
.main-area {
    flex: 1;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 90% 20%, rgba(168, 85, 247, 0.04) 0%, transparent 35%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.01) 0%, rgba(255, 255, 255, 0) 40%);
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.drop-zone {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: all 0.3s ease;
}

.drop-zone.drag-over::after {
    display: none; /* glow handled on drop-card */
}

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

.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 2;
}

.drop-card {
    width: 360px;
    max-width: 80%;
    padding: 28px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--input-border);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(6px);
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    position: relative;
    overflow: hidden;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

.drop-card.drag-over::after {
    content: '';
    position: absolute;
    inset: 12px;
    border: 2px dashed var(--primary-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.ghost-btn {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--text-main);
    margin-top: 6px;
    cursor: pointer;
}

.ghost-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

.drop-card {
    width: 360px;
    max-width: 80%;
    padding: 28px;
    border-radius: var(--radius-lg);
    border: 1px dashed var(--input-border);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(6px);
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.drop-card .icon {
    font-size: 2.75rem;
    line-height: 1;
}

.drop-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-main);
}

.drop-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.drop-card .hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}

.ghost-btn {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--text-main);
    margin-top: 6px;
}

.ghost-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

/* Preview Wrapper */
.preview-wrapper {
    width: 100%;
    height: 100%;
    padding: var(--wrapper-padding);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    cursor: default;
}

.preview-container {
    position: absolute;
    transform-origin: top left;
    transition: transform 0.22s ease, box-shadow 0.3s ease;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
}

.preview-hint {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--text-main);
    font-size: 12px;
    border-radius: 8px;
    pointer-events: none;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.insert-indicator {
    position: absolute;
    width: 3px;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.95));
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25), 0 8px 18px rgba(0, 0, 0, 0.4);
    border-radius: 999px;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
    opacity: 1;
}

.insert-indicator.hidden {
    opacity: 0;
    transform: translateY(4px);
}


/* Image Item */
.image-item {
    position: absolute;
    overflow: hidden;
    cursor: grab;
    transition: transform 0.18s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.18s ease, border-color 0.2s ease;
    background: #2a2a2a;
    /* Placeholder while loading */
    border: none;
    user-select: none;
    -webkit-user-select: none;
}

.image-item:hover {
    z-index: 10;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    transform: translateY(-1px);
}

.image-item:active {
    cursor: grabbing;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    display: block;
    user-select: none;
    -webkit-user-select: none;
}

.image-item.dragging {
    opacity: 0.9;
    z-index: 100;
    transform: scale(1.02);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(99, 102, 241, 0.25);
}

.preview-shift {
    transition: transform 90ms ease-out;
    will-change: transform;
}

.filename-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #f8fafc;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    max-width: 70%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: 0.02em;
    user-select: none;
    -webkit-user-select: none;
}

.filename-badge.hidden {
    display: none;
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 14px;
    z-index: 20;
}


.preview-wrapper {
    width: 100%;
    height: 100%;
    padding: var(--wrapper-padding);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.preview-container {
    position: absolute;
    transform-origin: top left;
    transition: transform 0.22s ease, box-shadow 0.3s ease;
    will-change: transform;
}

.preview-hint {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--text-main);
    font-size: 12px;
    border-radius: 8px;
    pointer-events: none;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.insert-indicator {
    position: absolute;
    width: 3px;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.95));
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25), 0 8px 18px rgba(0, 0, 0, 0.4);
    border-radius: 999px;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
    opacity: 1;
}

.insert-indicator.hidden {
    opacity: 0;
    transform: translateY(4px);
}


/* Image Item */
.image-item {
    position: absolute;
    overflow: hidden;
    cursor: grab;
    transition: transform 0.18s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.18s ease, border-color 0.2s ease;
    background: #2a2a2a;
    /* Placeholder while loading */
    border: none;
}

.image-item:hover {
    z-index: 10;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    transform: translateY(-1px);
}

.image-item:active {
    cursor: grabbing;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    display: block;
}

.image-item.dragging {
    opacity: 0.9;
    z-index: 100;
    transform: scale(1.02);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(99, 102, 241, 0.25);
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 14px;
    z-index: 20;
}

.image-item:hover .delete-btn {
    opacity: 1;
    transform: scale(1);
}


.ghost-btn {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: var(--text-main);
    margin-top: 6px;
}

.ghost-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

/* Preview Wrapper */
.preview-wrapper {
    width: 100%;
    height: 100%;
    padding: var(--wrapper-padding);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.preview-container {
    position: absolute;
    transform-origin: top left;
    transition: transform 0.22s ease, box-shadow 0.3s ease;
    will-change: transform;
}

.preview-hint {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.45);
    color: var(--text-main);
    font-size: 12px;
    border-radius: 8px;
    pointer-events: none;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.insert-indicator {
    position: absolute;
    width: 3px;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.2), rgba(99, 102, 241, 0.95));
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.25), 0 8px 18px rgba(0, 0, 0, 0.4);
    border-radius: 999px;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
    opacity: 1;
}

.insert-indicator.hidden {
    opacity: 0;
    transform: translateY(4px);
}


/* Image Item */
.image-item {
    position: absolute;
    overflow: hidden;
    cursor: grab;
    transition: transform 0.18s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.18s ease, border-color 0.2s ease;
    background: #2a2a2a;
    /* Placeholder while loading */
    border: none;
}

.image-item:hover {
    z-index: 10;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    transform: translateY(-1px);
}

.image-item:active {
    cursor: grabbing;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    display: block;
}

.image-item.dragging {
    opacity: 0.9;
    z-index: 100;
    transform: scale(1.02);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(99, 102, 241, 0.25);
}

/* Delete Button */
.delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 14px;
    z-index: 20;
}

.image-item:hover .delete-btn {
    opacity: 1;
    transform: scale(1);
}

.delete-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    transform: scale(1.1);
}

/* Han Mode Separator */
.han-separator {
    position: absolute;
    pointer-events: none;
    background: var(--primary-color);
    /* Use theme color */
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.7), 0 0 24px rgba(99, 102, 241, 0.4);
    /* Glow effect */
    border-radius: 2px;
    /* Rounded edges */
    opacity: 1;
}

.export-canvas {
    display: none;
}
