:root {
    --primary: #9B6AF6;
    --primary-dark: #282B5D;
    --secondary: #E37DF7;
    --cta: #9B6AF6;
    --cta-hover: #E37DF7;
    --bg-dark: #0F0F23;
    --bg-card: rgba(22, 22, 45, 0.8);
    --text-light: #FFFFFF;
    --text-muted: rgba(255, 255, 255, 0.7);
    --border: #9B6AF6;
    --border-light: rgba(227, 125, 247, 0.3);
    --shadow-glow: 0 0 20px rgba(155, 106, 246, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --transition: 200ms ease-out;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 15px rgba(134, 51, 169, 0.3);
    }

    50% {
        box-shadow: 0 0 30px rgba(134, 51, 169, 0.6);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-8px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(8px);
    }
}

@keyframes confetti-fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

@keyframes confetti-explode {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% center;
    }

    100% {
        background-position: 200% center;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

body {
    font-family: 'Switzer', sans-serif;
    background: var(--bg-dark);
    background-image:
        radial-gradient(ellipse at top, rgba(155, 106, 246, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(227, 125, 247, 0.1) 0%, transparent 50%);
    min-height: 100vh;
    color: var(--text-light);
    line-height: 1.6;
}

.app {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    margin-bottom: 32px;
    position: relative;
}

.brand-logo {
    position: absolute;
    top: 0;
    left: 0;
    width: 48px;
    height: 48px;
    object-fit: contain;
    animation: float 3s ease-in-out infinite;
}

.logo {
    font-family: 'Lineca', 'Switzer', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    animation: fadeInUp 0.6s ease-out;
}

.brand-name {
    background: linear-gradient(135deg, #97FEDD, #BE95FF, #97FEDD);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 2s linear infinite;
    font-weight: 700;
    text-shadow: 0 0 30px rgba(151, 254, 221, 0.5);
}

.tagline {
    color: var(--text-muted);
    font-size: 1rem;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.section-title {
    font-family: 'Lineca', 'Switzer', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-light);
}

.frames-section {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.frames-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.frame-card {
    background: rgba(15, 15, 35, 0.6);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    animation: fadeInUp 0.5s ease-out backwards;
}

.frame-card:nth-child(1) {
    animation-delay: 0.1s;
}

.frame-card:nth-child(2) {
    animation-delay: 0.2s;
}

.frame-card:nth-child(3) {
    animation-delay: 0.3s;
}

.frame-card:nth-child(4) {
    animation-delay: 0.4s;
}

.frame-card:hover {
    border-color: var(--secondary);
    transform: translateY(-2px);
}

.frame-card.active {
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
}

.frame-preview {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
}

.frame-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.frame-card.active .frame-label {
    color: var(--secondary);
}

.editor-section {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    align-items: start;
}

.preview-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeInUp 0.5s ease-out 0.5s backwards;
}

.preview-area {
    width: 400px;
    height: 400px;
    position: relative;
    background: #1a1a2e;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: grab;
}

.preview-area:active {
    cursor: grabbing;
}

.user-image-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

.user-image-layer img {
    max-width: none;
    user-select: none;
    -webkit-user-drag: none;
}

.user-image-layer img[src=""] {
    display: none;
}

.frame-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    background-size: cover;
    background-position: center;
    pointer-events: none;
}

.circular-guide {
    position: absolute;
    inset: 10%;
    z-index: 3;
    border: 3px dashed rgba(167, 139, 250, 0.5);
    border-radius: 50%;
    pointer-events: none;
}

.upload-placeholder {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    background: rgba(15, 15, 35, 0.8);
    transition: all var(--transition);
    cursor: pointer;
    animation: pulse-glow 2s ease-in-out infinite;
}

.upload-placeholder:hover {
    background: rgba(15, 15, 35, 0.6);
    color: var(--secondary);
}

.upload-placeholder.hidden {
    opacity: 0;
    pointer-events: none;
}

.controls-panel {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: fadeInUp 0.5s ease-out 0.6s backwards;
}

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

.control-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-light);
}

.control-value {
    color: var(--secondary);
    font-family: 'Lineca', 'Switzer', sans-serif;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: 'Switzer', sans-serif;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

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

.upload-group {
    flex-direction: row;
    gap: 12px;
}

.clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    background: rgba(244, 63, 94, 0.2);
    border: 1px solid rgba(244, 63, 94, 0.4);
    border-radius: var(--radius-md);
    color: #F43F5E;
    font-family: 'Switzer', sans-serif;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.clear-btn:hover {
    background: rgba(244, 63, 94, 0.3);
    border-color: #F43F5E;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(15, 15, 35, 0.8);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
    box-shadow: 0 2px 8px rgba(134, 51, 169, 0.4);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(134, 51, 169, 0.4);
}

.flip-controls {
    flex-direction: row;
    gap: 12px;
}

.flip-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    background: rgba(15, 15, 35, 0.8);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-light);
    font-family: 'Switzer', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.flip-btn:hover {
    border-color: var(--secondary);
    background: rgba(155, 106, 246, 0.1);
}

.flip-btn.active {
    background: rgba(155, 106, 246, 0.3);
    border-color: var(--primary);
}

.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    background: linear-gradient(90deg, var(--cta) 0%, var(--cta-hover) 50%, var(--cta) 100%);
    background-size: 200% auto;
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: 'Lineca', 'Switzer', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    margin-top: 8px;
    animation: shimmer 3s linear infinite;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 20px rgba(244, 63, 94, 0.4);
}

.footer {
    text-align: center;
    padding: 24px 0 0;
    color: var(--text-muted);
    font-size: 1rem;
}

.copyright {
    margin-top: 8px;
}

.copyright a {
    color: var(--secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.copyright a:hover {
    color: var(--primary);
}

@media (max-width: 768px) {
    .header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    .brand-logo {
        position: static;
        margin: 0 auto;
    }

    .logo {
        font-size: 2rem;
    }

    .frames-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .editor-section {
        grid-template-columns: 1fr;
    }

    .preview-area {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

@media (min-width: 992px) {
    .app {
        max-width: 1200px;
    }

    .main-content {
        display: grid;
        grid-template-columns: 1fr 1.2fr;
        gap: 32px;
        align-items: start;
    }

    .frames-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .editor-section {
        display: flex;
        flex-direction: column;
        gap: 24px;
    }

    .preview-container,
    .controls-panel {
        width: 100%;
        max-width: 448px;
        margin: 0 auto;
    }
}

.crop-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 35, 0.95);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.crop-modal.active {
    display: flex;
}

.crop-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 600px;
    width: 100%;
    animation: scaleIn 0.3s ease-out;
}

.crop-title {
    font-family: 'Lineca', 'Switzer', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 16px;
    text-align: center;
}

.crop-area {
    width: 100%;
    max-height: 400px;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: #1a1a2e;
}

.crop-area img {
    display: block;
    max-width: 100%;
}

.crop-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.crop-cancel-btn {
    flex: 1;
    padding: 12px 20px;
    background: rgba(15, 15, 35, 0.8);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-light);
    font-family: 'Switzer', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.crop-cancel-btn:hover {
    border-color: var(--secondary);
}

.crop-apply-btn {
    flex: 1;
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: 'Switzer', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.crop-apply-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.download-btn.shaking {
    animation: shake 0.5s ease-in-out;
}

.confetti-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    transform: translate(-50%, -50%);
    animation: confetti-explode-radial 2s ease-out forwards;
}

@keyframes confetti-explode-radial {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.5) rotate(720deg);
        opacity: 0;
    }
}