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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header p {
    opacity: 0.9;
    font-size: 1.2em;
}

.upload-zone {
    background: rgba(255, 255, 255, 0.95);
    border: 3px dashed #667eea;
    border-radius: 20px;
    padding: 60px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-zone:hover {
    border-color: #764ba2;
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.upload-zone.dragover {
    background: #f0f4ff;
    border-color: #764ba2;
}

.upload-content svg {
    color: #667eea;
    margin-bottom: 20px;
}

.upload-content p {
    margin: 10px 0;
    font-size: 1.2em;
    color: #555;
}

.upload-content button {
    background: none;
    border: none;
    color: #667eea;
    font-size: inherit;
    cursor: pointer;
    text-decoration: underline;
}

.hint {
    font-size: 0.9em !important;
    color: #888 !important;
}

.editor {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.editor-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    min-height: 500px;
}

.canvas-container {
    position: relative;
    border-radius: 10px;
    overflow: auto; /* allow scroll on mobile if image larger than viewport */
    background: #f5f5f5;
    touch-action: none; /* we will manage gestures for drag/resize */
}

#canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.text-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.text-box {
    position: absolute;
    padding: 10px;
    border-radius: 10px;
    cursor: move;
    user-select: none;
    pointer-events: all;
    transition: transform 0.2s;
    min-width: 20px;
    min-height: 20px;
    overflow: hidden;
}

.text-box:hover {
    transform: scale(1.02);
}

.text-box.selected {
    outline: 2px solid #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
}

/* Resize handle */
.resize-handle {
    width: 18px;
    height: 18px;
    background: rgba(0,0,0,0.6);
    position: absolute;
    right: 6px;
    bottom: 6px;
    border-radius: 4px;
    cursor: se-resize;
    z-index: 4;
    opacity: 0.95;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
    touch-action: none;
}

.controls {
    background: #f9f9f9;
    border-radius: 10px;
    padding: 20px;
}

.control-group {
    margin-bottom: 20px;
}

.btn {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.btn.primary {
    background: #667eea;
    color: white;
}

.btn.success {
    background: #48bb78;
    color: white;
}

.btn.info {
    background: #4a90e2;
    color: white;
}

.btn.danger {
    background: #f56565;
    color: white;
}

.btn.neutral { background: #e2e8f0; color: #1a202c; }
.btn.warning { background: #f6ad55; color: #1a202c; }

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toolbar-row {
    display: flex;
    gap: 10px;
    width: 100%;
}

.text-controls {
    margin-top: 30px;
}

.text-controls h3 {
    margin-bottom: 15px;
    color: #333;
}

.text-controls label {
    display: block;
    margin: 15px 0 5px;
    font-weight: 600;
    color: #555;
}

.text-controls input,
.text-controls select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.text-controls input[type="color"] {
    height: 40px;
    cursor: pointer;
}

.text-controls input[type="range"] {
    margin-bottom: 5px;
}

#font-size-value {
    font-size: 14px;
    color: #666;
}

.hidden {
    display: none !important;
}

/* Crop overlay styles */
.crop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 10;
    cursor: crosshair;
    pointer-events: all;
}

.crop-rect {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.35); /* darken outside */
    touch-action: none;
}

.crop-handle {
    position: absolute;
    width: 22px;
    height: 22px;
    background: #667eea;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    touch-action: none;
}
.crop-handle.tl { top: -12px; left: -12px; cursor: nwse-resize; }
.crop-handle.tr { top: -12px; right: -12px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -12px; left: -12px; cursor: nesw-resize; }
.crop-handle.br { bottom: -12px; right: -12px; cursor: nwse-resize; }

/* Improve responsive layout spacing */
@media (max-width: 768px) {
    #app { padding: 12px; }
    header h1 { font-size: 2em; }
    .controls { padding: 16px; }
    .editor-container {
        grid-template-columns: 1fr;
    }
    
    .controls {
        order: -1;
    }
}