* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #8B7FD9;
    --color-primary-light: #A89FF0;
    --color-secondary: #6FB4E8;
    --color-accent: #FF8FA3;
    --color-bg: #FAFBFD;
    --color-surface: #FFFFFF;
    --color-border: #E5E9F5;
    --color-text: #2D3748;
    --color-text-muted: #718096;
    --shadow-sm: 0 2px 8px rgba(139, 127, 217, 0.08);
    --shadow-md: 0 4px 16px rgba(139, 127, 217, 0.12);
    --shadow-lg: 0 8px 24px rgba(139, 127, 217, 0.16);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --header-logo-size: 70px;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #FAFBFD 0%, #F3F4F8 100%);
    color: var(--color-text);
    min-height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, rgba(139, 127, 217, 0.05) 0%, rgba(111, 180, 232, 0.05) 100%);
    border-bottom: 1px solid var(--color-border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 100;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: var(--header-logo-size);
    height: var(--header-logo-size);
    background: linear-gradient(135deg, var(--color-primary-dark, #0f172a) 0%, var(--color-secondary-dark, #1e1b4b) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: var(--shadow-sm);
}

.logo-icon img{
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.logo-text {
    font-family: 'Unbounded', sans-serif;
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-subtitle {
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 500;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--color-border);
}
/* Make the H1 behave like your logo text visually */
.h1-logo {
  margin: 0;
  line-height: 1.1;
}

/* Keep subtitle aligned nicely with the H1 */
.h1-subtitle {
  margin-top: 4px;
}

/* Main Workspace */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Left Panel */
.left-panel {
    width: 320px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel-section {
    padding: 20px;
    border-bottom: 1px solid var(--color-border);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

/* Upload Button */
.upload-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.upload-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.upload-btn:hover::before {
    width: 300px;
    height: 300px;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.upload-icon {
    font-size: 18px;
}

input[type="file"] {
    display: none;
}

/* Mode Tabs */
.mode-tabs {
    display: flex;
    gap: 8px;
    background: var(--color-bg);
    padding: 4px;
    border-radius: var(--radius-md);
}

.mode-tab {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.mode-tab:hover {
    background: rgba(139, 127, 217, 0.1);
    color: var(--color-primary);
}

.mode-tab.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.mode-icon {
    font-size: 14px;
}

/* Controls */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group.full-width {
    grid-column: 1 / -1;
}

.control-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-muted);
}

.control-input {
    padding: 10px 12px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: 'DM Sans', sans-serif;
    color: var(--color-text);
    background: var(--color-surface);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.control-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(139, 127, 217, 0.1);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.upload-btn:focus-visible,
.mode-tab:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.region-delete:focus-visible,
.image-download:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1.5px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.btn-danger {
    background: linear-gradient(135deg, #FF8FA3 0%, #FF6B85 100%);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Freehand Instructions */
.freehand-hint {
    background: linear-gradient(135deg, rgba(255, 143, 163, 0.08) 0%, rgba(139, 127, 217, 0.08) 100%);
    border: 1.5px solid rgba(255, 143, 163, 0.2);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-top: 16px;
}

.hint-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--color-text);
    margin-bottom: 6px;
}

.hint-item:last-child {
    margin-bottom: 0;
}

.hint-icon {
    font-size: 14px;
}

/* Regions List */
.regions-panel {
    max-height: 280px;
    overflow-y: auto;
    margin-top: 16px;
}

.regions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.regions-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-primary);
    background: rgba(139, 127, 217, 0.1);
    padding: 4px 10px;
    border-radius: 12px;
}

.region-card {
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.region-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    transform: translateX(2px);
}

.region-info {
    font-size: 13px;
    color: var(--color-text);
    font-weight: 500;
}

.region-size {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.region-delete {
    background: none;
    border: none;
    color: var(--color-accent);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
    font-size: 16px;
}

.region-delete:hover {
    background: rgba(255, 143, 163, 0.1);
    transform: scale(1.1);
}

/* Right Panel - Canvas */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #FAFBFD 0%, #F7F8FC 100%);
    overflow: hidden;
}

.canvas-header {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
}

.canvas-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
}

.canvas-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 16px;
}

.icon-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-1px);
}

.canvas-workspace {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    overflow: auto;
    position: relative;
}

.canvas-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
}

#previewCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(139, 127, 217, 0.15);
    cursor: crosshair;
    transition: all 0.3s ease;
    touch-action: none; /* Prevent default touch behaviors */
    -webkit-user-select: none;
    user-select: none;
}

#previewCanvas:hover {
    box-shadow: 0 16px 48px rgba(139, 127, 217, 0.2);
}

.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: 60px 20px;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.empty-text {
    font-size: 14px;
}

/* Cropped Images Section */
.cropped-section {
    position: fixed;
    bottom: 0;
    left: 320px;
    right: 0;
    max-height: 50vh;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.cropped-section.visible {
    transform: translateY(0);
}

.cropped-header {
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

.cropped-title {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-count-badge {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.cropped-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
}

.image-card {
    background: var(--color-surface);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    cursor: pointer;
}

.image-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.image-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.4) 0%, transparent 50%, rgba(0,0,0,0.6) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
}

.image-card:hover .image-overlay {
    opacity: 1;
}

.image-name {
    font-size: 11px;
    font-weight: 600;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 6px;
    backdrop-filter: blur(8px);
    cursor: text;
}

.image-download {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.image-download:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(139, 127, 217, 0.4);
}

.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
    }

    .header {
        padding: 12px 16px;
    }

    .logo-icon {
        --header-logo-size: 40px;
        font-size: 16px;
    }

    .logo-text {
        font-size: 18px;
    }

    .logo-subtitle {
        display: none;
    }

    .workspace {
        flex-direction: column;
        height: auto;
    }

    .left-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        max-height: none;
    }

    .right-panel {
        min-height: 400px;
    }

    .canvas-workspace {
        padding: 20px;
        min-height: 300px;
    }

    .cropped-section {
        left: 0;
        max-height: 60vh;
    }

    .cropped-section.visible {
        position: relative;
        transform: none;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .canvas-header {
        padding: 12px 16px;
    }

    .panel-section {
        padding: 16px;
    }

    /* Mobile touch improvements */
    .mode-tab {
        padding: 12px 20px;
        font-size: 14px;
    }

    .btn {
        padding: 14px 18px;
        font-size: 14px;
    }

    .control-input {
        padding: 12px 14px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .region-card {
        padding: 14px;
    }

    .image-card {
        min-height: 140px;
    }

    /* Touch-friendly overlay */
    .image-overlay {
        opacity: 1;
        background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 40%, rgba(0,0,0,0.7) 100%);
    }
}
