/* ==========================================================================
           DESIGN TOKENS
        ========================================================================== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.15);
    --secondary: #ec4899;

    --bg-body: #090e17;
    --bg-panel: #111827;
    --bg-elevated: #1f2937;

    --text-main: #f3f4f6;
    --text-muted: #9ca3af;

    --border-color: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);

    --radius: 12px;
    --radius-sm: 8px;

    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}


/* ==========================================================================
           RESET & BASE
        ========================================================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


/* ==========================================================================
           ANIMATIONS
        ========================================================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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


/* ==========================================================================
           SVG FILTER HELPER (hidden)
        ========================================================================== */
#svg-filters {
    display: none;
}


/* ==========================================================================
           BUTTONS
        ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #374151;
}

.tool-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    transition: var(--transition);
}

.tool-btn:hover {
    background: #374151;
}

.tool-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}


/* ==========================================================================
           LAYOUT UTILITIES
        ========================================================================== */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}


/* ==========================================================================
           HEADER
        ========================================================================== */
.header {
    background: rgba(17, 24, 39, 0.8);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.8rem 1.5rem;
    z-index: 100;
}

.header-content {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, #818cf8, #e879f9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    user-select: none;
}

/* Desktop: show text, hide icon (icon is decorative) */
.logo span {
    display: inline;
}

.logo i {
    display: inline;
}

.nav-actions {
    display: flex;
    gap: 0.75rem;
}


/* ==========================================================================
           MAIN WORKSPACE CONTAINER
        ========================================================================== */
.container {
    flex: 1;
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
}


/* ==========================================================================
           UPLOAD SECTION
        ========================================================================== */
.upload-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    animation: fadeIn 0.4s ease;
}

.upload-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.upload-subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    max-width: 500px;
    line-height: 1.5;
}

.upload-zone {
    background: var(--bg-panel);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 4rem 2rem;
    cursor: pointer;
    width: 100%;
    max-width: 600px;
    transition: var(--transition);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-4px);
}

.upload-icon {
    font-size: 4rem;
    color: var(--primary);
    margin-bottom: 1.5rem;
    display: block;
}

.upload-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

#file-input {
    display: none;
}


/* ==========================================================================
           EDITOR LAYOUT
        ========================================================================== */
.editor-layout {
    display: none;
    grid-template-columns: 80px 320px 1fr;
    gap: 1.5rem;
    height: 100%;
    min-height: 0;
}

.editor-layout.active {
    display: grid;
    animation: fadeIn 0.4s ease;
}


/* ==========================================================================
           SIDEBAR NAVIGATION (icon rail)
        ========================================================================== */
.sidebar-nav {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0;
    gap: 0.25rem;
    overflow-y: auto;
}

.nav-btn {
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--text-muted);
    padding: 1rem 0.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    transition: var(--transition);
}

.nav-btn i {
    font-size: 1.25rem;
}

.nav-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
}

.nav-btn.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
}


/* ==========================================================================
           SETTINGS PANEL
        ========================================================================== */
.sidebar-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.2rem;
    overflow-y: auto;
}

.sidebar-panel::-webkit-scrollbar {
    width: 6px;
}

.sidebar-panel::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 3px;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

.tab-pane h3 {
    font-size: 1rem;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1.2rem;
}


/* ==========================================================================
           ACCORDIONS
        ========================================================================== */
.accordion {
    margin-bottom: 0.75rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    user-select: none;
}

.accordion-header i {
    transition: transform 0.3s ease;
}

.accordion.open .accordion-header i {
    transform: rotate(180deg);
}

.accordion-body {
    max-height: 0;
    overflow: hidden;
    padding: 0 1rem;
    transition: max-height 0.3s ease;
}

.accordion.open .accordion-body {
    max-height: 400px;
    padding: 0 1rem 1rem;
}


/* ==========================================================================
           FORM CONTROLS
        ========================================================================== */
.control-group {
    margin-bottom: 1rem;
}

.control-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.range-value {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--primary);
}

input[type=range] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #374151;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
    transition: transform 0.2s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.text-input {
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    margin-bottom: 1rem;
    resize: none;
    transition: var(--transition);
}

.text-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.color-picker-wrap {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border-color);
    overflow: hidden;
    display: inline-block;
    cursor: pointer;
}

.color-picker {
    width: 150%;
    height: 150%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    transform: translate(-15%, -15%);
}


/* ==========================================================================
           LAYERS
        ========================================================================== */
.layer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-elevated);
    border: 1px solid transparent;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.layer-item:hover {
    border-color: var(--border-color);
}

.layer-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.layer-item button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: 0.2s;
}

.layer-item button:hover {
    color: #f87171;
}


/* ==========================================================================
           EMOJI GRID
        ========================================================================== */
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 5px;
    margin-top: 10px;
}

.emoji-btn {
    font-size: 1.5rem;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s, transform 0.2s;
}

.emoji-btn:hover {
    background: var(--bg-elevated);
    transform: scale(1.1);
}


/* ==========================================================================
           CANVAS AREA
        ========================================================================== */
.canvas-area {
    background-color: #0f141e;
    background-image:
        linear-gradient(45deg, #171f2e 25%, transparent 25%),
        linear-gradient(-45deg, #171f2e 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #171f2e 75%),
        linear-gradient(-45deg, transparent 75%, #171f2e 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.canvas-wrapper {
    position: relative;
    line-height: 0;
    box-shadow: var(--shadow-lg);
    transition: width 0.1s, height 0.1s;
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: 2px;
}


/* ==========================================================================
           OVERLAYS (text & crop)
        ========================================================================== */
#text-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

#crop-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    display: none;
}

#crop-overlay.active {
    pointer-events: auto;
    display: block;
}

.text-node {
    position: absolute;
    cursor: grab;
    pointer-events: auto;
    user-select: none;
    white-space: pre;
    line-height: 1.1;
    transform: translate(-50%, -50%);
    touch-action: none;
}

.text-node:active {
    cursor: grabbing;
}

.text-node.selected::after {
    content: '';
    position: absolute;
    inset: -6px;
    border: 2px dashed var(--primary);
    border-radius: 4px;
    pointer-events: none;
}

.crop-shade {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

#crop-box {
    position: absolute;
    border: 2px solid #fff;
    cursor: move;
    touch-action: none;
    pointer-events: auto;
}

#crop-box::before,
#crop-box::after {
    content: '';
    position: absolute;
    opacity: 0.3;
    pointer-events: none;
}

#crop-box::before {
    top: 33.3%;
    bottom: 33.3%;
    left: 0;
    right: 0;
    border-top: 1px solid #fff;
    border-bottom: 1px solid #fff;
}

#crop-box::after {
    left: 33.3%;
    right: 33.3%;
    top: 0;
    bottom: 0;
    border-left: 1px solid #fff;
    border-right: 1px solid #fff;
}

.crop-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border: 2px solid #fff;
    border-radius: 50%;
    pointer-events: auto;
    touch-action: none;
}

.crop-handle.tl {
    top: -8px;
    left: -8px;
    cursor: nwse-resize;
}

.crop-handle.tr {
    top: -8px;
    right: -8px;
    cursor: nesw-resize;
}

.crop-handle.bl {
    bottom: -8px;
    left: -8px;
    cursor: nesw-resize;
}

.crop-handle.br {
    bottom: -8px;
    right: -8px;
    cursor: nwse-resize;
}

.crop-handle.t {
    top: -8px;
    left: calc(50% - 8px);
    cursor: ns-resize;
}

.crop-handle.b {
    bottom: -8px;
    left: calc(50% - 8px);
    cursor: ns-resize;
}

.crop-handle.l {
    left: -8px;
    top: calc(50% - 8px);
    cursor: ew-resize;
}

.crop-handle.r {
    right: -8px;
    top: calc(50% - 8px);
    cursor: ew-resize;
}


/* ==========================================================================
           TOAST
        ========================================================================== */
.toast {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translate(-50%, 100px);
    background: #fff;
    color: #000;
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
    z-index: 1000;
    opacity: 0;
}

.toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}


/* ==========================================================================
           FOOTER
        ========================================================================== */
.footer {
    background: rgba(17, 24, 39, 0.9);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    z-index: 100;
}

.footer-content {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.footer-text a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: var(--transition);
}

.footer-text a:hover,
.footer-links a:hover {
    color: var(--text-main);
}


/* ==========================================================================
           RESPONSIVE — MOBILE (≤ 900px)
        ========================================================================== */
@media (max-width: 900px) {

    body {
        height: 100dvh;
    }

    .container {
        padding: 0.75rem;
    }

    .header {
        padding: 0.6rem 1rem;
    }

    .btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    /* Logo: hide text, keep icon */
    .logo i {
        display: inline;
    }

    .footer-content {
        flex-direction: row;
        gap: 1rem;
    }

    .hide-mobile {
        display: none;
    }

    /* Editor: single-column stack */
    .editor-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        gap: 0.75rem;
    }

    /* Canvas first */
    .canvas-area {
        height: 40vh;
        order: -1;
        border-radius: var(--radius-sm);
    }

    /* Horizontal nav rail */
    .sidebar-nav {
        height: 70px;
        flex-direction: row;
        align-items: center;
        padding: 0.25rem;
        border-radius: var(--radius-sm);
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-btn {
        flex: 1 0 auto;
        min-width: 70px;
        padding: 0.6rem 0.5rem;
        border-left: none;
        border-bottom: 3px solid transparent;
    }

    .nav-btn.active {
        border-left: none;
        border-bottom-color: var(--primary);
        background: transparent;
    }

    /* Settings panel */
    .sidebar-panel {
        height: 100%;
        max-height: none;
        min-height: 0;
        overflow-y: auto;
    }
}