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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    /* Account for iPhone safe areas */
    padding-top: env(safe-area-inset-top);
    /* Prevent zooming and text selection */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
}

.app-container {
    max-width: 100%;
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--background);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


/* Upload Section */
.upload-section {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.upload-area {
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: #f8f9ff;
}

.upload-area:active {
    transform: scale(0.98);
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--primary-color);
    margin: 0 auto 1rem;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Step Sections */
.step-section {
    margin-bottom: 2rem;
}

/* Media Preview */
.media-preview-section {
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.step-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 1rem;
}

.step-actions .btn {
    flex: 1;
}


.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
    flex: 1;
}

.media-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.media-item img,
.media-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}

/* Controls Section */
.controls-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.controls-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    color: var(--text-primary);
}

.controls-section h3:first-child {
    margin-top: 0;
}

.control-group {
    margin-bottom: 1rem;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
}

.control-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.control-group input[type="range"] {
    width: 100%;
    margin-top: 0.5rem;
    cursor: pointer;
}

.control-group input[type="color"] {
    width: 50px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.control-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
}

.text-input-group {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.text-input-group input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

.rotation-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

.rotation-item {
    background: var(--background);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid var(--border);
}

.rotation-preview {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border);
}

.rotation-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.rotation-value {
    min-width: 50px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Editing Section */
.editing-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    /* Account for iPhone safe areas */
    padding-bottom: env(safe-area-inset-bottom);
}

.canvas-container {
    width: 100%;
    background: #f5f5f5;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    flex: 1 1 0;
    align-items: center;
    position: relative;
    min-height: 0;
}

.canvas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-secondary);
    gap: 0.75rem;
    padding: 1rem;
}

.placeholder-icon {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.placeholder-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    opacity: 0.7;
    text-align: center;
}

#collageCanvas {
    display: none;
    image-rendering: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.editing-controls {
    background: var(--surface);
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    z-index: 10;
    position: relative;
    min-height: 60px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.btn-icon {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: relative;
    gap: 2px;
    padding: 0.25rem;
}

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

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

.btn-icon svg {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

.btn-label {
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}

.color-preview {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    margin-top: 2px;
}

.btn-add {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-add:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-add svg {
    stroke-width: 2.5;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.menu-content {
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 60vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.menu-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    text-align: center;
}

.format-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.format-option-btn {
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.format-option-btn:hover {
    border-color: var(--primary-color);
    background: #f8f9ff;
}

.format-option-btn span:first-child {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.format-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.color-presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.color-preset {
    aspect-ratio: 1;
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    background: none;
    position: relative;
}

.color-preset::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.color-preset[style*="border-color: var(--primary-color)"]::after {
    opacity: 1;
}

/* In-place text input */
.in-place-text-input {
    position: fixed;
    z-index: 100;
    border: none;
    border-radius: 8px;
    background: transparent;
    padding: 0.5rem;
    text-align: center;
    outline: none;
    box-shadow: none;
    pointer-events: auto;
}

.in-place-text-input:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

/* Text editing controls */
.text-editing-controls {
    background: var(--surface);
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    z-index: 10;
    position: relative;
    min-height: 60px;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

/* Font options */
.font-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 1rem;
}

.font-option {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.font-option:hover {
    border-color: var(--primary-color);
    background: #f8f9ff;
}

.font-option[data-font="classic"] {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
}

.font-option[data-font="modern"] {
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
}

.font-option[data-font="strong"] {
    font-family: 'Oswald', sans-serif;
    font-weight: 600;
}

.font-option[data-font="neon"] {
    font-family: 'Bebas Neue', cursive;
    font-weight: 400;
}

.font-option[data-font="typewriter"] {
    font-family: 'Courier Prime', monospace;
    font-weight: 400;
}

.font-option[data-font="caveat"] {
    font-family: 'Caveat', cursive;
    font-weight: 500;
}

.color-preset:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.color-preset:active {
    transform: scale(0.95);
}

.format-option:hover {
    border-color: var(--primary-color);
    background: #f8f9ff;
}

.format-option input[type="radio"] {
    margin: 0;
    cursor: pointer;
}

.format-option input[type="radio"]:checked + span {
    color: var(--primary-color);
    font-weight: 600;
}

.format-option input[type="radio"]:checked {
    accent-color: var(--primary-color);
}

.format-option input[type="radio"]:checked ~ span {
    color: var(--primary-color);
    font-weight: 600;
}

#downloadBtn {
    flex-shrink: 0;
    min-width: 90px;
}

#collageCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

/* Buttons */
.btn {
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
    text-align: center;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

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

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--background);
}

.download-buttons {
    display: flex;
    gap: 1rem;
    flex-direction: column;
}

/* Responsive Design */
@media (min-width: 768px) {
    .app-container {
        max-width: 1024px;
        margin: 0 auto;
    }

    .canvas-container {
        max-width: 1024px;
        margin: 0 auto;
    }

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

@media (min-width: 768px) {
    .app-container {
        max-width: 768px;
    }

    .rotation-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 1024px;
    }
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

