:root {
    /* Panda/TinyPNG Inspired Palette */
    --bg-color: #f3f9ff;
    /* Very light sky blue */
    --surface-color: #ffffff;
    /* Pure white */

    /* Lively Accents */
    --primary-color: #16a34a;
    /* Vibrant Green */
    --primary-hover: #15803d;
    /* Darker Green */
    --accent-color: #0ea5e9;
    /* Sky Blue */

    /* Dark Bar for Success */
    --success-bar-bg: #1f2937;
    /* Dark Charcoal */
    --success-text: #f9fafb;
    /* Gray 50 */

    /* Text Colors */
    --text-primary: #374151;
    /* Gray 700 */
    --text-secondary: #6b7280;
    /* Gray 500 */
    --text-tertiary: #9ca3af;
    /* Gray 400 */

    /* Borders */
    --border-color: #e5e7eb;
    /* Gray 200 */
    --border-dashed: #cbd5e1;
    /* Slate 300 */

    /* Border Radius for Soft Look */
    --radius-sm: 8px;
    --radius-md: 20px;
    --radius-lg: 32px;

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --preview-max-width: min(860px, calc(100vw - 4rem));
    --preview-max-height: calc(100vh - 260px);
    --preview-padding: 1rem;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-y: scroll;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    background-image: radial-gradient(#e0f2fe 1px, transparent 1px);
    background-size: 24px 24px;
}

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

/* Header */
header {
    height: 72px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    /* Clean text logo, no emoji */
    font-family: 'Inter', sans-serif;
    letter-spacing: -0.02em;
}

.logo img {
    width: 34px;
    height: 34px;
    display: block;
    border-radius: 8px;
    box-shadow: 0 6px 14px rgba(92, 54, 23, 0.14);
}

.source-credit {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    padding: 0.35rem 0.55rem;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.06);
}

.source-credit:hover {
    color: var(--text-primary);
    border-color: rgba(14, 165, 233, 0.55);
}

.source-credit img {
    width: 22px;
    height: 22px;
    display: block;
    border-radius: 5px;
}

/* Removed ::before emoji content */

/* Main Area */
main {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column; /* Stack editor and button vertically */
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 2rem; /* Space between editor and button */
}

/* Editor Area - Main Card */
#editor-area {
    position: relative;
    width: 100%;
    max-width: 800px;
    /* Increased slightly */
    /* Flexible container to hold canvas top and bar bottom */
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    /* Clips the bottom bar corners */
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#editor-area:not(.empty-state) {
    width: min-content;
    min-width: min(100%, 520px);
    max-width: var(--preview-max-width);
    max-height: none;
    align-items: center;
}

/* Empty State */
#editor-area.empty-state {
    aspect-ratio: 16/9;
    /* Maintain nice landing shape */
    justify-content: center;
    /* Center content vertically in empty state */
    align-items: center;
    border: 4px dashed var(--border-dashed);
    box-shadow: none;
    background: white;
    cursor: pointer;
    min-height: 400px;
    /* Ensure enough breathing room */
    padding: 3rem;
}

#editor-area.empty-state:hover {
    border-color: var(--accent-color);
    background: #f0f9ff;
    transform: scale(1.005);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    pointer-events: none;
    /* Clicks pass through to parent */
    user-select: none;
    /* Prevent text selection */
    text-align: center;
}

.drop-zone-content svg {
    color: var(--border-dashed);
    width: 80px;
    height: 80px;
    transition: all 0.3s ease;
}

#editor-area:hover .drop-zone-content svg {
    color: var(--accent-color);
    transform: scale(1.1) rotate(10deg);
}

.drop-zone-content h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drop-zone-content p {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* Canvas Container to ensure it fills available space but doesn't overflow */
canvas {
    display: none;
    width: auto;
    height: auto;
    max-width: var(--preview-max-width);
    max-height: var(--preview-max-height);
    min-height: 0;
    object-fit: contain;
    /* Add padding so image doesn't touch edges uncomfortably */
    padding: var(--preview-padding);
    background: conic-gradient(#eee 25%, white 0 50%, #eee 0 75%, white 0) 0 0 / 20px 20px;
}

#imageCanvas {
    z-index: 10;
}

/* Steps - Hidden in active state to save space? Or keep top? */
.steps-guide {
    display: flex;
    gap: 1.5rem;
    margin-top: 2rem;
}

.step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: var(--bg-color);
    padding: 0.4rem 1rem;
    border-radius: 100px;
}

.step-num {
    width: 20px;
    height: 20px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
}

/* Toolbar - Success Bar Style */
/* No longer absolute centered. It's a block at the bottom. */
.editor-toolbar {
    display: none;
    /* Hidden by default */
    width: 100%;
    background: var(--success-bar-bg);
    padding: 1rem 2rem;
    align-items: center;
    justify-content: space-between;
    color: white;
    z-index: 50;
    animation: slideUpBar 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpBar {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.editor-toolbar.visible {
    display: flex;
    /* Flex layout when visible */
}

/* Status Text in Toolbar (Inserted via JS or HTML) */
.toolbar-status {
    font-weight: 500;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-status svg {
    color: #4ade80;
    /* Green check */
}

/* Buttons */
.toolbar-btn {
    background: transparent;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 100px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.toolbar-btn.primary {
    background: var(--primary-color);
    color: white;
    /* Slight 3D feel */
    box-shadow: 0 4px 0 #15803d;
}

.toolbar-btn.primary:hover {
    background: #22c55e;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #15803d;
    /* Enhanced shadow on hover */
}

.toolbar-btn.primary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #15803d;
}

.toolbar-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.toolbar-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

/* Close Button */
.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
    z-index: 60;
}

.close-btn:hover {
    background: #fee2e2;
    color: #ef4444;
    border-color: #fecaca;
    transform: rotate(90deg);
}

.close-btn.hidden {
    display: none !important;
}

/* Footer Info */
.footer-info {
    position: absolute;
    bottom: 0.5rem;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    pointer-events: none;
}

.footer-info a {
    color: var(--text-secondary);
    text-decoration: none;
    pointer-events: auto;
}

/* Processing Overlay */
#processing-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideUp 0.3s ease-out;
    pointer-events: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chrome Extension Popup Adjustment */
body {
    /* min-width removed to allow side panel resizing */
    width: 100%;
    margin: 0;
}

/* Chrome Extension / Compact Mode Overrides */
/* Applied when width is small (like in the extension popup or side panel) */
@media (max-width: 650px) {
    :root {
        --preview-max-width: calc(100vw - 1rem);
        --preview-max-height: calc(100vh - 230px);
        --preview-padding: 0.5rem;
    }

    body {
        padding: 0;
        background: var(--surface-color);
        /* Remove border for side panel integration */
        border: none;
    }

    .app-container {
        padding: 0;
    }

    header {
        height: 56px;
        padding: 0 0.75rem;
        background: var(--bg-color);
    }

    .logo {
        font-size: 0.95rem;
    }

    .source-credit span {
        display: none;
    }

    /* Main Area: Side Panel Layout */
    main {
        padding: 0.75rem 0.5rem 1rem;
        min-height: calc(100vh - 56px);
        display: flex;
        flex-direction: column;
        overflow: visible;
        background: var(--bg-color);
        gap: 1rem;
    }

    /* Editor Area: Container */
    #editor-area {
        width: 100%;
        max-width: var(--preview-max-width);
        transition: all 0.3s ease;
        position: relative;
    }

    #editor-area.empty-state {
        min-height: 320px;
        padding: 2rem 1rem;
    }

    #editor-area:not(.empty-state) {
        width: min-content;
        min-width: min(100%, 360px);
        max-width: var(--preview-max-width);
        margin: 0 auto;
        border-radius: var(--radius-md);
        background: var(--surface-color);
        align-items: center;
    }

    .editor-toolbar {
        padding: 0.75rem;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .toolbar-actions {
        gap: 0.5rem !important;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .toolbar-btn {
        padding: 0.55rem 0.85rem;
        font-size: 0.85rem;
    }

}

/* Manual Trigger Container - Flow Layout Outside Card (Global) */
.trigger-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    /* No padding needed here as main handles gap */
    background: transparent;
    border: none;
    z-index: 40;
    pointer-events: auto;
}

.trigger-container.hidden {
    display: none;
}

.trigger-btn {
    pointer-events: auto;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 100px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 10px 25px rgba(22, 163, 74, 0.4);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: pulseButton 2s infinite;
    white-space: nowrap;
}

.trigger-btn svg {
    width: 24px;
    height: 24px;
}

.trigger-btn:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 15px 35px rgba(22, 163, 74, 0.5);
}

.trigger-btn:active {
    transform: scale(0.95);
}

@keyframes pulseButton {
    0% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.6);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(22, 163, 74, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
    }
}
