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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
    font-feature-settings: 'ss01', 'cv01';
    background: #c9c9c9;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    position: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.particle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    pointer-events: none;
    animation: float linear forwards;
    animation-duration: 1.5s;
    z-index: 0;
}

.particle.slow {
    animation-duration: 4s;
}

@keyframes float {
    0% {
        transform: translateY(0px) translateX(0px);
        opacity: 0;
    }
    5% {
        opacity: 0.8;
    }
    95% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(-110vh) translateX(var(--drift));
        opacity: 0;
    }
}

#app {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* Start Screen */
#start-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 30px;
    text-align: center;
    color: rgba(0, 0, 0, 0.75);
    position: relative;
    z-index: 1;
}

#start-screen .emoji {
    font-size: 120px;
    margin-bottom: 40px;
    display: block;
    animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

#start-btn {
    padding: 50px 90px;
    background: transparent;
    border: none;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 72px;
    font-weight: 900;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 8px;
    text-shadow:
        0 0 10px rgba(255, 255, 255, 0.8),
        0 0 20px rgba(255, 255, 255, 0.6),
        0 0 30px rgba(255, 255, 255, 0.4),
        3px 3px 0px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1) backwards, pulse 2s ease-in-out infinite;
    animation-delay: 0.2s, 0.8s;
}

#start-btn:hover {
    transform: scale(1.1);
    text-shadow:
        0 0 15px rgba(255, 255, 255, 1),
        0 0 30px rgba(255, 255, 255, 0.8),
        0 0 45px rgba(255, 255, 255, 0.6),
        4px 4px 0px rgba(0, 0, 0, 0.4);
}

#start-btn:active {
    transform: scale(1.05);
}

/* Main View */
#main-view {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 15px;
}

/* Upload Section */
#upload-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#upload-area {
    width: 100%;
    max-width: 600px;
    padding: 80px 40px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(1rem);
    -webkit-backdrop-filter: blur(1rem);
    border-radius: 1.2rem;
    border: 3px dashed rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.1));
    text-align: center;
}

#upload-area:hover {
    border-color: rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-4px);
    filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.15));
}

.upload-text {
    color: rgba(0, 0, 0, 0.75);
    font-size: 18px;
    font-weight: 600;
}

/* Editor Layout */
#editor-section {
    display: grid;
    grid-template-columns: 250px 1fr 300px;
    gap: 15px;
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
    animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2s, 1);
}

/* Panels */
.panel {
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(1rem);
    -webkit-backdrop-filter: blur(1rem);
    border-radius: 1.2rem;
    padding: 20px;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.1));
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

.panel h3 {
    color: rgba(0, 0, 0, 0.75);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.layer-count {
    font-size: 12px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.5);
}

/* Layers Panel */
#layers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
    margin-bottom: 10px;
}

.layer-item {
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.layer-item:hover {
    border-color: rgba(0, 0, 0, 0.3);
}

.layer-item.active {
    border-color: rgba(0, 0, 0, 0.75);
    background: rgba(0, 0, 0, 0.75);
    color: white;
}

.layer-text {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 5px;
}

.layer-actions {
    display: flex;
    gap: 5px;
}

.layer-btn {
    padding: 4px 8px;
    font-size: 11px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.1);
    cursor: pointer;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.75);
    transition: all 0.2s;
}

.layer-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.layer-item.active .layer-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.layer-item.active .layer-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.add-layer-btn {
    width: 100%;
    padding: 12px;
    border: 2px dashed rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.75);
    transition: all 0.2s;
}

.add-layer-btn:hover {
    border-color: rgba(0, 0, 0, 0.4);
    background: rgba(255, 255, 255, 0.4);
}

/* Canvas */
.canvas-panel {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#preview-canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0.8rem;
    cursor: crosshair;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.2));
}

/* Crop Overlay */
#crop-overlay {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    cursor: move;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid #000;
    border-radius: 50%;
}

.crop-handle.tl { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.tr { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.bl { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.br { bottom: -6px; right: -6px; cursor: se-resize; }

/* Controls Panel */
#controls-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    padding-right: 5px;
}

#controls-panel::-webkit-scrollbar {
    width: 6px;
}

#controls-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

#controls-panel::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

#controls-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

.control-section {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 15px;
}

.control-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: rgba(0, 0, 0, 0.75);
}

/* Inputs */
input[type="text"], textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    font-size: 14px;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.75);
    resize: vertical;
    font-family: inherit;
}

input[type="text"]:focus, textarea:focus {
    outline: none;
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.7);
}

.slider-group {
    margin-bottom: 12px;
}

.slider-group:last-child {
    margin-bottom: 0;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    color: rgba(0, 0, 0, 0.75);
}

input[type="range"] {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.1);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.75);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.75);
    cursor: pointer;
    border: none;
}

input[type="color"] {
    width: 100%;
    height: 40px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.5);
}

/* Style Grid */
.style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.style-btn {
    padding: 10px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: rgba(0, 0, 0, 0.75);
}

.style-btn:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.6);
}

.style-btn.active {
    border-color: rgba(0, 0, 0, 0.75);
    background: rgba(0, 0, 0, 0.75);
    color: white;
}

/* Tool Buttons */
.tool-btns {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.tool-btn {
    padding: 12px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: rgba(0, 0, 0, 0.75);
}

.tool-btn:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.6);
}

.tool-btn.active {
    border-color: rgba(0, 0, 0, 0.75);
    background: rgba(0, 0, 0, 0.75);
    color: white;
}

/* Auto Design Button */
.auto-design-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    filter: drop-shadow(0 4px 12px rgba(102, 126, 234, 0.3));
}

.auto-design-btn:hover {
    transform: translateY(-2px);
    filter: drop-shadow(0 6px 16px rgba(102, 126, 234, 0.4));
}

/* Design Suggestions */
.design-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.suggestion-item {
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.2s;
}

.suggestion-item:hover {
    border-color: rgba(0, 0, 0, 0.3);
    transform: scale(1.05);
}

.suggestion-preview {
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    margin-bottom: 5px;
}

.suggestion-name {
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    color: rgba(0, 0, 0, 0.75);
}

/* Action Buttons */
.action-btns {
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    padding: 14px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.5);
    color: rgba(0, 0, 0, 0.75);
}

.action-btn:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px);
}

.action-btn.save-btn {
    background: rgba(0, 0, 0, 0.75);
    color: white;
    border-color: rgba(0, 0, 0, 0.75);
}

.action-btn.save-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    border-color: rgba(0, 0, 0, 0.85);
}

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

*::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

*::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Responsive */
@media (max-width: 1200px) {
    #editor-section {
        grid-template-columns: 1fr;
        gap: 12px;
        height: auto;
    }

    /* Make panels scrollable on tablet/mobile */
    .panel {
        max-height: 400px;
        overflow-y: auto;
    }

    .canvas-panel {
        max-height: 500px;
    }

    #start-btn {
        font-size: 48px;
        padding: 30px 50px;
    }

    #start-screen .emoji {
        font-size: 80px;
    }
}

@media (max-width: 768px) {
    #main-view {
        padding: 10px;
        gap: 10px;
    }

    #editor-section {
        gap: 10px;
    }

    .panel {
        padding: 12px;
        max-height: 300px;
    }

    .canvas-panel {
        max-height: 350px;
        min-height: 250px;
    }

    #preview-canvas {
        max-width: 95%;
        max-height: 95%;
    }

    .panel h3 {
        font-size: 14px;
        margin-bottom: 12px;
    }

    /* Make buttons more touch-friendly */
    .style-btn, .tool-btn {
        padding: 12px;
        font-size: 12px;
        touch-action: manipulation;
    }

    .action-btn {
        padding: 12px;
        font-size: 13px;
    }

    .add-layer-btn {
        padding: 10px;
        font-size: 13px;
    }

    /* Adjust text inputs */
    textarea {
        font-size: 14px;
        padding: 8px;
    }

    /* Make sliders easier to use */
    input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }

    .slider-group label {
        font-size: 11px;
    }

    /* Design suggestions */
    .design-suggestions {
        gap: 8px;
    }

    .suggestion-preview {
        height: 60px;
    }

    #start-btn {
        font-size: 36px;
        padding: 20px 40px;
        letter-spacing: 4px;
    }
}

@media (max-width: 480px) {
    #main-view {
        padding: 8px;
        gap: 8px;
    }

    #editor-section {
        gap: 8px;
    }

    .panel {
        padding: 10px;
        max-height: 250px;
    }

    .canvas-panel {
        max-height: 280px;
        min-height: 200px;
    }

    .panel h3 {
        font-size: 13px;
        margin-bottom: 10px;
    }

    /* Make controls more compact */
    .control-section {
        padding: 12px;
    }

    .control-section h4 {
        font-size: 12px;
        margin-bottom: 8px;
    }

    /* Single column layout for style buttons */
    .style-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .tool-btns {
        gap: 6px;
    }

    .style-btn, .tool-btn {
        padding: 10px;
        font-size: 11px;
    }

    /* Layer items */
    .layer-item {
        padding: 8px;
    }

    .layer-text {
        font-size: 11px;
    }

    .layer-btn {
        padding: 3px 6px;
        font-size: 10px;
    }

    /* Action buttons */
    .action-btns {
        flex-direction: column;
        gap: 8px;
    }

    .action-btn {
        width: 100%;
        padding: 10px;
        font-size: 12px;
    }

    /* Upload area */
    #upload-area {
        padding: 60px 30px;
    }

    .upload-text {
        font-size: 16px;
    }

    /* Auto design */
    .auto-design-btn {
        padding: 12px;
        font-size: 12px;
    }

    .design-suggestions {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .suggestion-preview {
        height: 50px;
    }

    .suggestion-name {
        font-size: 10px;
    }

    #start-btn {
        font-size: 28px;
        padding: 16px 32px;
        letter-spacing: 3px;
    }

    #start-screen .emoji {
        font-size: 70px;
        margin-bottom: 30px;
    }

    /* Improve input sizing */
    textarea {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 10px;
        min-height: 60px;
    }

    input[type="text"] {
        font-size: 16px; /* Prevent iOS zoom */
    }

    /* Make color picker easier to tap */
    input[type="color"] {
        height: 50px;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

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

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.02);
    }
}
