/* 1. CSS Variables */
:root {
    --primary-color: #2563eb;
    --bg-color: transparent;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --card-shadow: 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --canvas-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25), 0 8px 24px -4px rgb(0 0 0 / 0.15);
    --bg-gradient-light-1: #f8f9ff;
    --bg-gradient-light-2: #c7dbf5;
    --bg-gradient-1: #0f172a;
    --bg-gradient-2: #1e1b4b;
    /* interpolate-size: allow-keywords; */
--spring-easing: linear(0, 0.0027, 0.0105 0.69%, 0.0447 1.44%, 0.1055, 0.1867 3.1%, 0.3736 4.61%, 0.9115 8.46%, 1.0525 9.63%, 1.1581, 1.2435, 1.3071 12.73%, 1.3292 13.21%, 1.3488 13.76%, 1.3609 14.24%, 1.3694 14.79%, 1.3718, 1.3722 15.48%, 1.3671 16.17%, 1.3532, 1.3317 17.68%, 1.3012 18.51%, 1.2615 19.4%, 1.0477 23.53%, 0.9963 24.63%, 0.9571 25.59%, 0.9199, 0.8918, 0.873 28.9%, 0.867 29.45%, 0.8629 30.07%, 0.8614 30.75%, 0.8632, 0.8683 32.27%, 0.877 33.09%, 0.9033 34.81%, 0.9817 38.87%, 1.0146 40.87%, 1.0295 42.04%, 1.0401, 1.0472, 1.0509 45.34%, 1.051 46.85%, 1.0459 48.43%, 1.0362 50.15%, 1.007 54.21%, 0.9951 56.14%, 0.9856 58.34%, 0.9812 60.47%, 0.9809 62.06%, 0.9828 63.78%, 1.0016 71.41%, 1.0069 75.54%, 1.0064 79.19%, 0.9977 89.99%, 0.9995 99.96%);
--spring-duration: 1.705s;
}
* {
    box-sizing: border-box;
}

/* Custom Scrollbar Styles */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

/* 2. Base/Global Styles */
body {
    font-family: 'Inter', system-ui, sans-serif;
    color: var(--text-color);
    margin: 0;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh; /* Add this for modern browsers */
    box-sizing: border-box; /* Fix: was padding-box */
    background: linear-gradient(135deg,
        var(--bg-gradient-light-1) 0%,
        var(--bg-gradient-light-2) 100%);
    background: linear-gradient(135deg,
        var(--bg-gradient-1) 0%,
        var(--bg-gradient-2) 100%);
    background-attachment: fixed;
    overflow-x: hidden;
    overflow-y: scroll; /* Always show scrollbar to prevent jump */
    display:flex;
    align-items: center;

}

/* 3. Layout & Grid */
.app {
    display: none; /* Hidden by default until authentication */
    grid-template-columns: 380px auto 300px;
    grid-template-rows: 1fr max-content 1fr;
    grid-template-areas:
        "editor preview theme-selector"
        "editor preview info"
        "editor preview actions";
    gap: 24px;
    padding: 12px;
    /* max-width: 1160px; */
    width:100%;
    min-height:100dvh;
    margin: 0 auto;
    align-items: start;
    justify-content: space-between;

    @media(max-width: 1200px) {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        grid-template-areas:
            "editor"
            "preview"
            "theme-selector"
            "actions"
            "info";
        gap: 24px;
        padding: 20px;
        max-width: 540px;
    }

}

.editor {
    grid-area: editor;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index:10;
    align-self:center;
    transition: height 0.3s ease;
}

.preview {
    grid-area: preview;
    position: sticky;
    top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.actions {
    grid-area: actions;
    width: 100%;
    box-sizing:border-box;
    padding:0 24px 0 24px;
    /* padding-top:0px */
}

/* 5. Form Elements */
.input-group {
    position: relative;
    margin: 0;
}

.input-group label {
    display: block;
    font-size: 0.775rem;
    font-weight: 600;
    color: var(--text-color);
    /* text-transform: uppercase;
    letter-spacing: 0.5px; */
}

textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    box-sizing: border-box;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, height 0.15s ease;
    position: relative;
    resize: none;
    min-height: 44px;
    overflow: hidden;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

textarea::placeholder {
    color: #94a3b8;
    font-style: italic;
}

/* Unified Control Styles */
.control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    color: #475569;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.control-btn:active {
    transform: scale(0.98);
    background: #f1f5f9;
}

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

.control-btn.active:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.control-btn i {
    font-size: 16px;
}

.remove-btn {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}

.remove-btn:hover {
    background: #fee2e2;
    border-color: #dc2626;
    color: #b91c1c;
}

/* Image Controls */
.image-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

/* Logo Controls */
.logo-controls {
    display: flex;
    gap: 8px;
}

.logo-btn {
    flex: 1;
    min-width: 0;
}

/* Controls Row */
.controls-row {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease;
}

.controls-row:has(.input-group.visible) {
    grid-template-rows: 1fr;
}

.controls-row-inner {
    overflow: hidden;
    display: grid;
    grid-template-columns: auto auto;
    gap: 16px;
    align-items: flex-start;
}

.controls-row .input-group {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

.controls-row .input-group > * {
    overflow: hidden;
}

.controls-row .input-group.visible {
    grid-template-rows: 1fr;
    opacity: 1;
}

.controls-row .input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

@media (max-width: 400px) {
    .controls-row {
    }

    .controls-row .input-group {
        flex: 1 1 auto;
        min-width: 0;
    }
    .controls-row-inner {
        gap: 12px;
        grid-template-columns: auto;
    }
    .control-btn {
        padding: 12px 16px;
        min-height: 44px;
        font-size: 15px;
    }

    .control-btn i {
        font-size: 18px;
    }

    .control-group {
        gap: 10px;
    }

    .image-controls {
        gap: 14px;
    }

    .logo-controls {
        gap: 10px;
    }

    .info {
        margin-top: 16px;
    }

    .info-content {
        max-width: 100%;
        padding: 12px;
        gap: 10px;
    }

    .info-icon {
        font-size: 18px;
    }

    .info-text {
        font-size: 12px;
    }
}



/* 6. Theme & Color Controls */
.theme-selector {
    grid-area: theme-selector;
    align-self:flex-end;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 0 24px;
}

.theme-category-header {
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 8px;
}

.theme-category-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Update theme swatch styles */
.theme-swatch {
    width: 48px;
    height: 48px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
    flex:1;
    background: none;
    position: relative;
}

.theme-number {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    bottom: -1px;
    right: -1px;
    background: linear-gradient(135deg, #a9b7dfc9, #a5b3d9);
    color: #2563eb;
    font-size: 0.875rem;
    padding: 4px 8px;
    border-radius: 16px 0 3px 0;

}

.theme-swatch:hover .theme-number {
    background: linear-gradient(135deg, var(--primary-color), rgba(37, 99, 235, 0.9));
    color:#f1f5f9;
    transition: all 0.2s ease;
}

.theme-preview {
    width: 100%;
    height: 100%;
    display: block;
    filter: saturate(2);

}

.theme-swatch:hover {
    border-color: var(--primary-color);
    transform: scale(1.2);

}

.theme-swatch.active {
    border-color: var(--primary-color);
}

/* 7. Canvas & Preview */
.canvas-container {
    width: 100%;
    line-height: 0;
    position: relative;
}

canvas {
    width: auto;
    max-width: 100%;
    max-height: 540px;
    height: auto;
    border-radius: 12px;
    box-shadow: var(--canvas-shadow);
}

/* 8. Buttons & Actions */
button {
    color: white;
    border: none;
    padding: 10px 20px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s ease;

    &:hover {
    background: #1d4ed8;
}
}



.download-btn, .share-btn, .clear-btn {
    width: 100%;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.download-btn:hover {
    background: #1d4ed8;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2),
                0 2px 4px -2px rgba(37, 99, 235, 0.2);
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.share-btn, .clear-btn {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    height: 52px;
    padding: 0;
}

.share-btn .btn-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.share-btn .btn-content-original,
.share-btn .btn-content-copied {
    position: absolute;
    left: 0;
    right: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.share-btn .btn-content-original {
    transform: translateY(0);
    opacity: 1;
}

.share-btn .btn-content-copied {
    transform: translateY(-100%);
    opacity: 0;
}

.share-btn.copied .btn-content-original {
    transform: translateY(100%);
    opacity: 0;
}

.share-btn.copied .btn-content-copied {
    transform: translateY(0);
    opacity: 1;
}

.share-btn:hover {
    background: none;
    border: 1px solid #ffffff;
    color: #ffffff;
}



.clear-btn:hover {
    background: none;
    border: 1px solid #fa3b34;
    color: #fa3b34;
}

/* 8. Info Section */
.info {
    grid-area: info;
    display: flex;
    align-items: flex-start;
    place-self: flex-end;
    gap: 1rem;
}

.info-icon {
    color: rgba(59, 130, 246, 0.8);
    font-size: 20px;
    margin-top: 2px;
    flex-shrink: 0;
}

.info-text {
    color: hsl(218 40% 42% / 1);
    font-size: 13px;
    line-height: 1.5;
}

.info-text p {
    margin: 0 0 8px 0;
}

.info-text p:last-child {
    margin-bottom: 0;
}

.info-text a {
    color: rgba(59, 130, 246, 0.9);
    text-decoration: none;
    transition: color 0.2s ease;
}

.info-text a:hover {
    color: rgba(59, 130, 246, 1);
    text-decoration: underline;
}

/* 9. Animation & Effects */
.flash-overlay {
    position: absolute;
    inset: 0px;;
    /* background: #ffffff; */
    opacity: 1;
    border: 1px solid rgb(31, 74, 109);
    pointer-events: none;
    border-radius: 12px;
    z-index: -1;
    transform: scale(1);
}

.flash {
    animation: flashborder 1s ease-out;
}



.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    opacity: 0.8;
    transform: scale(0);
    animation: ripple 0.6s ease-out forwards;
    pointer-events: none;
    width: 100px;
    height: 100px;
    margin-left: -50px;
    margin-top: -50px;
    z-index: 10;
}

@keyframes flashborder {

    to{ opacity: 0; transform: scale(1.3);}
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.8;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* 10. Media Queries */
@media (max-width: 1024px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "editor"
            "preview"
            "theme-selector"
            "actions"
            "info";
        gap: 24px;
        padding: 20px;
        max-width: 540px;
    }

    .preview {
        position: static;
        width: 100%;
    }

    .canvas-container {
        width: 100%;
    }

    .theme-bar {
        padding: 8px;
        gap: 8px;
    }

}

@media (max-width: 580px) {
    canvas {
        width: 100%;
        height: auto;
    }
}

/* Password Modal Styles */
.password-modal {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg,
        var(--bg-gradient-1) 0%,
        var(--bg-gradient-2) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    interpolate-size: allow-keywords;

    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.password-modal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg,
        #7f1d1d 0%,
        #991b1b 50%,
        #7f1d1d 100%);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.password-modal.error::before {
    opacity: 1;
}

.password-modal.show {
    opacity: 1;
    visibility: visible;
}

.password-modal.fade-out {
    opacity: 0;
    visibility: hidden;
}

.password-modal-content {
    max-width: 400px;
    width: 90%;
    text-align: center;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.password-modal.show .password-modal-content {
    transform: translateY(0);
    opacity: 1;
}

.password-modal.fade-out .password-modal-content {
    transform: translateY(-10px);
    opacity: 0;
}

#password-input {
    width: 92%;
    padding: 20px 24px;
    border: none;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0;
    font-size: 20px;
    font-weight: 400;
    text-align: center;
    outline: none;
    background: transparent;
    color: white;
    letter-spacing: 0.5px;
    transition: border-color 0.3s ease, width 0.2s ease;
}

#password-input:focus {
    border-bottom-color: rgba(255, 255, 255, 0.8);
    width:100%;
}

#password-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
    font-weight: 300;
    letter-spacing: 0.5px;
}

.password-error {
    color: #fca5a5;
    font-size: 0.875rem;
    margin-top: 16px;
    font-weight: 400;
    opacity: 0;
    height: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease, height 0.3s ease;
    letter-spacing: 0.3px;
}

.password-error.show {
    opacity: 1;
    height: max-content;
    transform: translateY(0);
}
