/* ============================================================
   EmojiCut — CapCut-style Editor UI
   3-column layout: Left tools | Center canvas+timeline | Right grid+preview
   ============================================================ */

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

:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    --bg-0: #09090f;
    --bg-1: #111118;
    --bg-2: #18181f;
    --bg-3: #222230;
    --bg-4: #2e2e3d;

    --surface: rgba(255,255,255,0.035);
    --surface-h: rgba(255,255,255,0.06);
    --surface-a: rgba(255,255,255,0.09);

    --border: rgba(255,255,255,0.07);
    --border-h: rgba(255,255,255,0.14);

    --text-1: #ededf0;
    --text-2: #9a9ab0;
    --text-3: #5c5c72;

    --accent: #2AABEE;
    --accent-d: rgba(42,171,238,0.12);
    --violet: #8B5CF6;
    --violet-d: rgba(139,92,246,0.12);
    --green: #34D399;
    --green-d: rgba(52,211,153,0.12);
    --red: #F87171;

    --grad: linear-gradient(135deg, var(--accent), var(--violet));

    --r-s: 6px;
    --r-m: 10px;
    --r-l: 14px;
    --r-xl: 18px;

    --ease: cubic-bezier(.16,1,.3,1);

    --topbar-h: 48px;
    --bottom-nav-h: 56px;
}

html {
    background: var(--bg-0);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

body { min-height: 100vh; min-height: 100dvh; }

.hidden { display: none !important; }

/* ===== TOP BAR ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: var(--topbar-h);
    background: rgba(9,9,15,0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.topbar-logo svg { display:block; }

.topbar-title {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.4px;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
    min-width: 0;
}

@media (min-width: 769px) {
    .topbar-center { display: none; }
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--r-m);
    border: none;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s var(--ease);
    text-decoration: none;
    white-space: nowrap;
    color: var(--text-1);
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity:.35; cursor:not-allowed; transform:none; }

.btn-accent {
    background: var(--grad);
    color: #fff;
    box-shadow: 0 2px 10px rgba(42,171,238,0.2);
}
.btn-accent:hover:not(:disabled) { box-shadow: 0 4px 20px rgba(42,171,238,0.3); }

.btn-secondary {
    background: var(--bg-3);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-4); border-color: var(--border-h); }

.btn-full { width: 100%; }

.btn-publish-top span { display: inline; }
.btn-publish-top { padding: 6px 14px; font-size: 12px; }

/* ===== CANVAS TOOLBAR (in topbar center) ===== */
.canvas-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0;
    background: transparent;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border-radius: var(--r-s);
    border: none;
    background: transparent;
    color: var(--text-2);
    font-family: var(--font);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
}

.toolbar-btn:hover { background: var(--surface-h); color: var(--text-1); }

.toolbar-btn.active {
    background: var(--accent-d);
    color: var(--accent);
}

.toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 2px;
}

.toolbar-zoom {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    min-width: 36px;
    text-align: center;
}

/* ===== EDITOR LAYOUT (3-column) ===== */
.editor {
    display: grid;
    grid-template-columns: 280px 1fr 340px;
    gap: 0;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
}

/* ===== LEFT PANEL ===== */
.editor-left {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* ===== CENTER (Canvas + Timelines) ===== */
.editor-center {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-0);
    overflow: hidden;
}

.canvas-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: grab;
    background:
        radial-gradient(circle at 50% 50%, rgba(42,171,238,0.03) 0%, transparent 60%),
        repeating-conic-gradient(var(--bg-1) 0% 25%, var(--bg-0) 0% 50%) 0 0 / 20px 20px;
}

.canvas-wrap:active { cursor: grabbing; }

#main-canvas {
    display: block;
    image-rendering: auto;
    border-radius: 4px;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.04);
}

/* Grid overlay on canvas */
.grid-overlay {
    position: absolute;
    pointer-events: none;
    border: 1.5px solid rgba(42,171,238,0.5);
    border-radius: 2px;
    display: grid;
    z-index: 3;
}

.grid-overlay-cell {
    border: 0.5px solid rgba(42,171,238,0.25);
}

/* Upload overlay */
.upload-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(9,9,15,0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
    transition: background .2s;
    z-index: 5;
}

.upload-overlay:hover { background: rgba(9,9,15,0.35); }
.upload-overlay.hidden { display: none; }

.upload-overlay-content {
    text-align: center;
    padding: 30px;
}

.upload-o-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 14px;
    background: var(--accent-d);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-overlay-content p {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.upload-overlay-content span {
    font-size: 12px;
    color: var(--text-3);
}

/* ===== TRIMMING TIMELINE ===== */
.timeline-container {
    padding: 8px 14px 6px;
    background: var(--bg-1);
    border-top: 1px solid var(--border);
    display: none;
}

.timeline-container.active {
    display: block;
    animation: fadeIn .25s var(--ease);
}

.timeline-labels {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.timeline-range {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}

.timeline-selected {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    padding: 2px 8px;
    background: var(--accent-d);
    border-radius: 10px;
}

/* Timeline ticks */
.timeline-ticks {
    position: relative;
    height: 16px;
    margin-bottom: 2px;
}

.timeline-tick {
    position: absolute;
    font-size: 9px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    transform: translateX(-50%);
    white-space: nowrap;
}

.timeline-tick::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 50%;
    width: 1px;
    height: 4px;
    background: var(--text-3);
    opacity: 0.4;
}

.timeline-track {
    position: relative;
    height: 36px;
    background: var(--bg-3);
    border-radius: var(--r-s);
    cursor: pointer;
    overflow: visible;
}

.timeline-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(42,171,238,0.25), rgba(139,92,246,0.25));
    border-radius: var(--r-s);
    cursor: grab;
    transition: left .05s, width .05s;
}

.timeline-fill:active {
    cursor: grabbing;
}

.timeline-playhead {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: var(--text-1);
    border-radius: 1px;
    pointer-events: none;
    z-index: 3;
    box-shadow: 0 0 4px rgba(255,255,255,0.3);
    transition: left .05s linear;
}

.timeline-handle {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 14px;
    cursor: ew-resize;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timeline-handle-left { border-radius: 4px 0 0 4px; }
.timeline-handle-right { border-radius: 0 4px 4px 0; }

.timeline-handle-grip {
    width: 4px;
    height: 20px;
    background: var(--accent);
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(42,171,238,0.3);
    transition: background .15s, transform .15s;
}

.timeline-handle:hover .timeline-handle-grip {
    background: var(--violet);
    transform: scaleY(1.1);
}

.timeline-times {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* ===== LAYER TIMELINE (CapCut-style) ===== */
.layer-timeline {
    position: relative;
    background: var(--bg-1);
    border-top: 1px solid var(--border);
    min-height: 80px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    display: block;
}

.layer-timeline.active {
    display: block;
    animation: fadeIn .25s var(--ease);
}

.timeline-ruler {
    display: flex;
    justify-content: space-between;
    padding: 4px 12px 2px;
    font-size: 10px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-1);
    z-index: 5;
}

.timeline-ruler span {
    flex: 1;
    text-align: center;
}
.timeline-ruler span:first-child { text-align: left; }
.timeline-ruler span:last-child { text-align: right; }

.timeline-tracks {
    position: relative;
    padding: 6px 12px;
    min-height: 40px;
}

.timeline-track-row {
    display: flex;
    align-items: center;
    height: 32px;
    margin-bottom: 3px;
    position: relative;
}

.timeline-track-label {
    display: none;
}

.timeline-track-bar-wrap {
    flex: 1;
    position: relative;
    height: 28px;
}

.timeline-track-bar {
    position: absolute;
    height: 28px;
    border-radius: 6px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px;
    font-size: 10px;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    overflow: hidden;
    white-space: nowrap;
    user-select: none;
    transition: box-shadow .15s, border-color .15s;
}

.timeline-track-bar:hover {
    box-shadow: 0 0 0 1.5px var(--accent);
}

.timeline-track-bar:active {
    cursor: grabbing;
}

.timeline-track-bar.video-bar {
    background: linear-gradient(135deg, rgba(42,171,238,0.3), rgba(139,92,246,0.3));
    border: 1px solid rgba(42,171,238,0.3);
}

.timeline-track-bar.layer-bar {
    background: linear-gradient(135deg, rgba(139,92,246,0.35), rgba(248,113,113,0.25));
    border: 1px solid rgba(139,92,246,0.3);
}

.timeline-track-bar.text-bar {
    background: linear-gradient(135deg, rgba(139,92,246,0.35), rgba(139,92,246,0.2));
    border: 1px solid rgba(139,92,246,0.4);
}

.timeline-track-bar.image-bar {
    background: linear-gradient(135deg, rgba(52,211,153,0.35), rgba(52,211,153,0.2));
    border: 1px solid rgba(52,211,153,0.4);
}

.timeline-track-bar.selected-bar {
    box-shadow: 0 0 0 2px var(--accent), 0 0 16px rgba(42,171,238,0.35) !important;
    border-color: var(--accent) !important;
    z-index: 2;
}

/* Resize handles on layer track bars */
.track-bar-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
    cursor: ew-resize;
    z-index: 2;
}

.track-bar-handle-left { left: 0; border-radius: 4px 0 0 4px; }
.track-bar-handle-right { right: 0; border-radius: 0 4px 4px 0; }

.track-bar-handle:hover {
    background: rgba(42,171,238,0.3);
}

/* Playhead line */
.timeline-playhead-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent);
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 0 6px rgba(42,171,238,0.4);
    transition: left .05s linear;
}

.timeline-playhead-line::before {
    content: '';
    position: absolute;
    top: 0;
    left: -4px;
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
}

/* ===== RIGHT PANEL ===== */
.editor-right {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--bg-1);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* ===== PANELS ===== */
.panel {
    padding: 14px;
    border-bottom: 1px solid var(--border);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-2);
}

.panel-header h3 svg { color: var(--text-3); }

.badge {
    padding: 3px 9px;
    border-radius: 20px;
    background: var(--accent-d);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

/* Grid mode toggle */
.grid-mode-toggle {
    display: flex;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
    padding: 3px;
    margin-bottom: 12px;
    gap: 2px;
}

.grid-mode-btn {
    flex: 1;
    padding: 5px 8px;
    border: none;
    background: transparent;
    color: var(--text-3);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    border-radius: 7px;
    cursor: pointer;
    transition: all .2s var(--ease);
}

.grid-mode-btn:hover { color: var(--text-2); }

.grid-mode-btn.active {
    background: var(--accent-d);
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(42,171,238,0.1);
}

/* Presets */
.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}

.preset {
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-family: var(--font);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}

.preset:hover { border-color: var(--border-h); background: var(--surface); }

.preset.active {
    background: var(--accent-d);
    border-color: rgba(42,171,238,0.3);
    color: var(--accent);
}

/* Steppers */
.stepper-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.stepper-row label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
}

.stepper {
    display: flex;
    align-items: center;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
}

.stepper-btn {
    width: 30px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 15px;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
}

.stepper-btn:hover { color: var(--text-1); background: var(--surface-h); }
.stepper-btn:first-child { border-radius: var(--r-m) 0 0 var(--r-m); }
.stepper-btn:last-child { border-radius: 0 var(--r-m) var(--r-m) 0; }

.stepper-val {
    width: 34px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    line-height: 28px;
}

/* Free grid rows */
.free-rows-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 8px;
    max-height: 240px;
    overflow-y: auto;
}

.free-row-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
    animation: fadeIn .2s var(--ease);
}

.free-row-item label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    min-width: 60px;
}

.free-row-item .stepper { margin: 0; }

.free-row-item .btn-remove-row {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-3);
    font-size: 14px;
    cursor: pointer;
    transition: all .15s;
    border-radius: var(--r-s);
    margin-left: 4px;
    font-family: var(--font);
}

.free-row-item .btn-remove-row:hover {
    background: rgba(248,113,113,0.12);
    color: var(--red);
}

.btn-add-row {
    width: 100%;
    padding: 6px 12px;
    font-size: 11px;
    margin-bottom: 6px;
}

/* Info bar */
.info-bar {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 10px;
    background: var(--surface);
    border-radius: var(--r-m);
    margin-top: 8px;
}

.info-bar svg { flex-shrink:0; color: var(--accent); margin-top: 1px; }

.info-bar span {
    font-size: 10px;
    color: var(--text-3);
    line-height: 1.5;
}

/* ===== TELEGRAM POST MOCKUP ===== */
.theme-switch {
    display: flex;
    background: var(--bg-2);
    border-radius: var(--r-s);
    padding: 2px;
}

.theme-btn {
    width: 24px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-3);
    border-radius: 4px;
    cursor: pointer;
    transition: all .15s;
}

.theme-btn.active { background: var(--bg-4); color: var(--text-1); }

.tg-post {
    border-radius: var(--r-l);
    overflow: hidden;
    transition: background .25s, color .25s;
}

.tg-post.dark { background: #1e1e1e; color: #e8e8e8; }
.tg-post.light { background: #fff; color: #1a1a1a; }

.tg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px 5px;
}

.tg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}

.tg-meta { display: flex; flex-direction: column; }
.tg-name { font-size: 12px; font-weight: 600; }
.tg-time { font-size: 10px; opacity: .35; }

.tg-body { padding: 3px 10px 6px; }

/* Telegram grid — no gaps */
.tg-grid {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    margin-bottom: 4px;
}

.tg-grid-row {
    display: flex;
    gap: 0;
    justify-content: flex-start;
}

.tg-cell {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    max-width: 24px;
    max-height: 24px;
    border-radius: 0;
    position: relative;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    flex: 0 0 24px;
    margin: 0;
    border: none;
}

/* Placeholder cells — thin outline to show grid structure */
.tg-cell--placeholder {
    background: rgba(42, 171, 238, 0.2);
    outline: 1px solid rgba(42, 171, 238, 0.4);
    outline-offset: -1px;
}

.tg-cell--placeholder::before {
    content: '';
    position: absolute;
    inset: 0;
    background: none;
}

.tg-cell--placeholder::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.06) 45%, transparent 65%);
    animation: shimmer 2.2s ease-in-out infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(120%); }
}

.tg-cell--filled {
    background-color: var(--bg-3);
    background-size: cover;
    outline: none;
}

.tg-text { font-size: 12px; opacity: .45; line-height: 1.45; }

.tg-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 10px 8px;
    font-size: 10px;
    opacity: .3;
}

.tg-views { margin-left: auto; }

.tg-post.light .tg-cell--placeholder::before { opacity: .12; }

/* ===== PUBLISH PANEL ===== */
.panel-header-toggle { cursor: pointer; user-select: none; }

.chevron { transition: transform .25s var(--ease); }

.panel-publish.open .chevron { transform: rotate(180deg); }

.panel-body {
    display: none;
    padding-top: 4px;
}

.panel-publish.open .panel-body {
    display: block;
    animation: fadeIn .2s var(--ease);
}

@keyframes fadeIn { from { opacity:0; transform: translateY(-4px); } to { opacity:1; transform:none; } }

.input-group { margin-bottom: 10px; }

.input-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.input-group input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--r-m);
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: all .2s;
}

.input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-d);
}

.input-hint {
    display: block;
    font-size: 10px;
    color: var(--text-3);
    margin-top: 3px;
}

/* ===== MODALS ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn .2s;
}

.modal-backdrop.hidden { display: none; }

.modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 28px 24px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.modal-ring {
    width: 90px;
    height: 90px;
    margin: 0 auto 16px;
    position: relative;
}

.modal-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.modal-percent {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.modal-status { font-size: 12px; color: var(--text-3); }

/* Result modal */
.modal-result { text-align: center; }

.result-check {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--green-d);
    color: var(--green);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    animation: popIn .4s var(--ease);
}

@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

.result-link {
    display: inline-block;
    color: var(--accent);
    font-size: 12px;
    word-break: break-all;
    margin-bottom: 16px;
    text-decoration: none;
}
.result-link:hover { text-decoration: underline; }

.result-copy-section {
    background: var(--bg-3);
    border-radius: var(--r-l);
    padding: 12px;
    margin-bottom: 16px;
    text-align: left;
}

.result-copy-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.result-copy-header span { font-size: 11px; color: var(--text-3); font-weight: 600; }

.btn-copy {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-family: var(--font);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.btn-copy:hover { background: var(--surface-h); }
.btn-copy.copied { background: var(--green-d); border-color: var(--green); color: var(--green); }

.result-text {
    font-size: 18px;
    line-height: 1.2;
    word-break: break-all;
    padding: 6px;
    background: var(--bg-2);
    border-radius: var(--r-s);
    min-height: 36px;
}

.result-actions {
    display: flex;
    gap: 8px;
}
.result-actions .btn { flex:1; }

/* ===== LAYERS PANEL ===== */
.layers-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 7px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
    cursor: pointer;
    transition: all .2s var(--ease);
    animation: fadeIn .2s var(--ease);
}

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

.layer-item.selected {
    border-color: rgba(42,171,238,0.4);
    background: var(--accent-d);
}

.layer-vis-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    border-radius: 4px;
    transition: all .15s;
    flex-shrink: 0;
    font-size: 12px;
}

.layer-vis-btn:hover { background: var(--surface-h); }
.layer-vis-btn.hidden-layer { color: var(--text-3); opacity: 0.5; }

.layer-preview {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    background: var(--bg-3);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: var(--text-3);
}

.layer-preview img,
.layer-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.layer-name {
    flex: 1;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-item.selected .layer-name { color: var(--text-1); }

.layer-del-btn {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    border-radius: 4px;
    transition: all .15s;
    flex-shrink: 0;
    font-family: var(--font);
    font-size: 13px;
}

.layer-del-btn:hover {
    background: rgba(248,113,113,0.12);
    color: var(--red);
}

.layers-add-buttons {
    display: flex;
    gap: 5px;
}

.layers-add-btn {
    flex: 1;
    padding: 6px 8px;
    font-size: 11px;
}

/* Layer properties panel */
.layer-props {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    animation: fadeIn .2s var(--ease);
}

.layer-props.hidden { display: none; }

.layer-props-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}

.layer-props .input-group { margin-bottom: 8px; }

.layer-props .input-group label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    margin-bottom: 3px;
}

.layer-props textarea {
    width: 100%;
    padding: 7px 9px;
    border-radius: var(--r-s);
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 12px;
    outline: none;
    resize: vertical;
    transition: border-color .2s;
}

.layer-props textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-d);
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.slider {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    background: var(--bg-3);
    border-radius: 2px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 4px rgba(42,171,238,0.3);
}

.slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.slider-val {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    min-width: 28px;
    text-align: right;
}

.color-input {
    width: 36px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: var(--r-s);
    background: transparent;
    cursor: pointer;
    padding: 2px;
}

.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: none; border-radius: 3px; }

.toggle-btn {
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 800;
    font-family: var(--font);
}

.toggle-btn.active {
    background: var(--accent-d);
    border-color: rgba(42,171,238,0.3);
    color: var(--accent);
}

.select-input {
    width: 100%;
    padding: 7px 9px;
    border-radius: var(--r-s);
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 12px;
    outline: none;
    cursor: pointer;
    transition: border-color .2s;
}

.select-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-d);
}

.select-input option,
.select-input optgroup {
    background: var(--bg-2);
    color: var(--text-1);
}

/* ===== SUBSCRIPTION PANEL ===== */
.subscription-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface);
    border-radius: var(--r-m);
}

.sub-plan {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-1);
}

.sub-plan.pro {
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sub-info {
    font-size: 10px;
    color: var(--text-3);
    margin-left: auto;
}

/* Subscription modal */
.modal-subscription { text-align: center; }

.sub-modal-star {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(42,171,238,0.15), rgba(139,92,246,0.15));
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    animation: popIn .4s var(--ease);
}

.sub-features {
    list-style: none;
    margin: 12px 0;
    text-align: left;
    padding: 0;
}

.sub-features li {
    padding: 5px 0;
    font-size: 12px;
    color: var(--text-2);
    position: relative;
    padding-left: 20px;
}

.sub-features li::before {
    content: '\2713';
    position: absolute;
    left: 0;
    color: var(--green);
    font-weight: 700;
}

.sub-price {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 14px 0;
    flex-wrap: wrap;
}

.sub-price-main {
    font-size: 18px;
    font-weight: 800;
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sub-price-or { font-size: 11px; color: var(--text-3); }

.sub-price-stars { font-size: 18px; font-weight: 800; color: var(--accent); }

.sub-actions { margin-top: 10px; }

/* ===== BOTTOM NAVIGATION (Mobile only) ===== */
.bottom-nav {
    display: none;
}

.bottom-drawer {
    display: none;
}

/* ===== RESPONSIVE ===== */

/* Tablet */
@media (max-width: 1100px) {
    .editor {
        grid-template-columns: 240px 1fr 300px;
    }
}

/* Narrower tablet */
@media (max-width: 920px) {
    .editor {
        grid-template-columns: 220px 1fr 280px;
    }
}

/* Mobile: <= 768px */
@media (max-width: 768px) {
    .topbar-center { display: none; }
    .btn-publish-top span { display: none; }

    .editor {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto auto;
        height: calc(100dvh - var(--topbar-h) - var(--bottom-nav-h));
    }

    .editor-left { display: none; }
    .editor-right { display: none; }

    .editor-center {
        min-height: 0;
    }

    .canvas-wrap {
        flex: 1;
        min-height: 200px;
    }

    /* Bottom navigation */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 90;
        height: var(--bottom-nav-h);
        background: rgba(17,17,24,0.92);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--border);
        padding: 0 4px;
        align-items: center;
        justify-content: space-around;
    }

    .bnav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        border: none;
        background: transparent;
        color: var(--text-3);
        font-family: var(--font);
        font-size: 9px;
        font-weight: 600;
        cursor: pointer;
        transition: color .2s;
        padding: 6px 8px;
        border-radius: 8px;
        min-width: 0;
        flex: 1;
    }

    .bnav-btn:hover { color: var(--text-2); }

    .bnav-btn.active {
        color: var(--accent);
    }

    .bnav-btn svg {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
    }

    /* Bottom drawer */
    .bottom-drawer {
        display: block;
        position: fixed;
        bottom: var(--bottom-nav-h);
        left: 0;
        right: 0;
        z-index: 85;
        background: rgba(17,17,24,0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--border);
        max-height: 50vh;
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateY(100%);
        transition: transform .3s var(--ease);
    }

    .bottom-drawer.open {
        transform: translateY(0);
    }

    .drawer-handle {
        width: 36px;
        height: 4px;
        background: var(--bg-4);
        border-radius: 2px;
        margin: 8px auto 4px;
    }

    .drawer-content {
        display: none;
        padding: 10px 14px 16px;
    }

    .drawer-content.active {
        display: block;
        animation: fadeIn .2s var(--ease);
    }

    /* Adjust timeline-container */
    .timeline-container {
        padding: 6px 10px 4px;
    }

    .timeline-track { height: 30px; }

    .layer-timeline { max-height: 120px; }

    /* Telegram cells smaller on mobile */
    .tg-cell {
        width: 20px;
        height: 20px;
        min-width: 20px;
        min-height: 20px;
        max-width: 20px;
        max-height: 20px;
        flex: 0 0 20px;
    }
}

@media (max-width: 380px) {
    .panel { padding: 10px; }
    .presets { gap: 3px; }
    .preset { padding: 3px 8px; font-size: 10px; }
    .topbar { padding: 0 8px; }

    .tg-cell {
        width: 18px;
        height: 18px;
        min-width: 18px;
        min-height: 18px;
        max-width: 18px;
        max-height: 18px;
        flex: 0 0 18px;
    }

    .bnav-btn {
        font-size: 8px;
        padding: 4px 4px;
    }

    .bnav-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* ===== CANVAS LAYER INTERACTION ===== */
.canvas-wrap.layer-mode { cursor: default; }
.canvas-wrap.layer-mode:active { cursor: default; }

/* ===== PROFILE BUTTON (topbar) ===== */
.btn-profile {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text-2);
    margin-left: 8px;
    flex-shrink: 0;
}
.btn-profile:hover { background: var(--bg-4); color: var(--text-1); }

/* ===== PUBLISH MODE TOGGLE ===== */
.publish-mode-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--bg-2);
    border-radius: var(--r-m);
    padding: 3px;
}
.publish-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 8px;
    border-radius: var(--r-s);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all .2s var(--ease);
    white-space: nowrap;
}
.publish-mode-btn.active {
    background: var(--bg-4);
    color: var(--text-1);
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.publish-mode-btn:hover:not(.active) { color: var(--text-1); }

/* ===== PACK INFO CARD ===== */
.pack-info-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
    padding: 10px 12px;
    margin: 8px 0;
}
.pack-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
}
.pack-info-label { color: var(--text-2); font-size: 12px; }
.pack-info-value { color: var(--text-1); font-size: 12px; font-weight: 600; }
.pack-info-link {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--accent);
    text-decoration: none;
}
.pack-info-link:hover { text-decoration: underline; }

.btn-refresh-packs { font-size: 11px; padding: 5px 10px; }

/* ===== MODAL: PROFILE ===== */
.modal-profile {
    max-width: 380px;
    text-align: center;
}
.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 16px;
}
.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--grad);
    color: #fff;
    font-size: 24px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    text-transform: uppercase;
}
.profile-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-1);
}
.profile-id {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
}
.profile-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 16px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.profile-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.profile-stat-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-1);
}
.profile-stat-label {
    font-size: 11px;
    color: var(--text-2);
    margin-top: 2px;
}
.profile-sub-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-m);
    padding: 10px 14px;
    margin-bottom: 16px;
    text-align: center;
}
.profile-sub-plan {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-1);
}
.profile-sub-plan.pro {
    background: var(--grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.profile-sub-expires {
    font-size: 11px;
    color: var(--text-2);
    margin-top: 4px;
}
.profile-actions { margin-top: 8px; }

/* ===== DRAG & DROP OVERLAY ===== */
.canvas-wrap.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
}
.canvas-wrap.drag-over .upload-overlay {
    pointer-events: none;
}

/* ===== HISTORY PANEL ===== */
.history-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 4px 0;
}
.history-loading, .history-empty {
    text-align: center;
    padding: 16px 8px;
    color: var(--text-3);
    font-size: 12px;
}
.history-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-s);
    padding: 8px 10px;
    margin-bottom: 6px;
}
.history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.history-pack-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}
.history-date {
    font-size: 10px;
    color: var(--text-3);
    flex-shrink: 0;
}
.history-card-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-2);
}
.history-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 11px;
}
.history-link:hover { text-decoration: underline; }

/* ===== PACK DETAIL MODAL ===== */
.modal-pack-detail {
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-pack-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.modal-pack-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-1);
}
.pack-detail-badge {
    font-size: 11px;
    color: var(--text-2);
    background: var(--bg-3);
    padding: 3px 8px;
    border-radius: var(--r-s);
}
.pack-stickers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 6px;
    margin-bottom: 8px;
}
.sticker-cell {
    position: relative;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-s);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.sticker-emoji {
    font-size: 24px;
}
.sticker-actions {
    position: absolute;
    top: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .2s;
}
.sticker-cell:hover .sticker-actions { opacity: 1; }

.sticker-action-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    padding: 0;
}
.sticker-delete-btn {
    background: rgba(248,113,113,0.85);
    color: #fff;
}
.sticker-delete-btn:hover { background: var(--red); }
.sticker-replace-btn {
    background: rgba(42,171,238,0.85);
    color: #fff;
}
.sticker-replace-btn:hover { background: var(--accent); }

/* ===== CANVAS TOOLS BAR (Desktop, below canvas) ===== */
.canvas-tools-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 12px;
    background: var(--bg-1);
    border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
    .canvas-tools-bar { display: none; }
}

/* ===== TEXT STYLE ROW ===== */
.text-style-row {
    display: flex;
    gap: 4px;
}

.text-style-row .toggle-btn {
    min-width: 32px;
    padding: 4px 8px;
}

/* ===== PROP ROW (side by side) ===== */
.prop-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== ADVANCED TOGGLE ===== */
.advanced-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    cursor: pointer;
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    transition: color .15s;
}

.advanced-toggle:hover { color: var(--text-2); }

.advanced-toggle .chevron-sm {
    transition: transform .2s var(--ease);
}

.advanced-toggle.open .chevron-sm {
    transform: rotate(180deg);
}

.advanced-section.hidden { display: none; }

.advanced-section {
    animation: fadeIn .2s var(--ease);
    padding-top: 8px;
}

/* ===== GRADIENT STOPS ===== */
.gradient-stop-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    padding: 4px 6px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-s);
}

/* ===== BACKGROUND LAYER BAR ===== */
.timeline-track-bar.bg-bar {
    background: linear-gradient(135deg, rgba(42,171,238,0.25), rgba(139,92,246,0.25));
    border: 1px solid rgba(42,171,238,0.3);
}

/* ===== BAR NAME & DURATION ===== */
.bar-name {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    font-size: 10px;
    pointer-events: none;
    opacity: 0.9;
}

.bar-duration {
    font-size: 9px;
    opacity: 0.5;
    flex-shrink: 0;
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

/* ===== ANIMATION INDICATOR ===== */
.timeline-track-bar.has-anim .bar-name::before {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--violet);
    margin-right: 4px;
    vertical-align: middle;
    box-shadow: 0 0 4px var(--violet);
}
