/* STUDIO WORKSPACE (NẰM DƯỚI HEADER CHÍNH CỦA XẢ BUỒN) */
.studio {
    max-width: 1240px;
    margin: 0 auto;
    padding: 76px 16px 40px;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.studio * { box-sizing: border-box; }
.studio a { color: #1877f2; text-decoration: none; }
.studio a:hover { text-decoration: underline; }
.studio button, .studio input, .studio textarea, .studio select { font: inherit; }

/* BỐ CỤC 2 CỘT: TRÁI CANVAS, PHẢI ĐIỀU KHIỂN */
.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

/* KHUNG CANVAS XEM TRƯỚC (CỘT TRÁI) */
.preview-panel {
    background: #ffffff;
    border: 1px solid #e4e6eb;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    text-align: center;
}
.canvas-toolbar-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #65676b;
    padding: 6px 10px;
    background: #f0f2f5;
    border-radius: 8px;
}
.canvas-action-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}
.img-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    background: #ffffff;
    border: 1px solid #ccd0d5;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    color: #1c1e21;
    cursor: pointer;
    transition: all 0.15s ease;
}
.img-tool-btn:hover {
    background: #e4e6eb;
    border-color: #bec3c9;
    color: #050505;
}
.img-tool-btn svg {
    color: #1877f2;
}
.img-tool-reset {
    background: #fff0f0;
    border-color: #ffcdd2;
    color: #d32f2f;
}
.img-tool-reset:hover {
    background: #ffebee;
    border-color: #ef9a9a;
}
.canvas-hint-text {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: #65676b;
}
.canvas-size-info {
    font-weight: 600;
    color: #1877f2;
}

.canvas-container {
    position: relative;
    width: 100%;
    background: #1c1e21;
    border-radius: 10px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
}
#preview-empty {
    padding: 100px 20px;
    color: #b0b3b8;
}
#preview-empty strong {
    font-size: 18px;
    color: #ffffff;
    display: block;
    margin-bottom: 6px;
}
canvas#meme-canvas {
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 720px;
    display: block;
    cursor: crosshair;
    margin: 0 auto;
    object-fit: contain;
}
canvas#meme-canvas.dragging {
    cursor: grabbing !important;
}
canvas#meme-canvas[hidden] { display: none; }
.preview-note {
    font-size: 12px;
    color: #65676b;
    margin-top: 8px;
    margin-bottom: 0;
}

/* ĐỔI MẪU NHANH DƯỚI CANVAS */
.quick-template-section {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed #e4e6eb;
}
.quick-template-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
    margin-bottom: 8px;
    color: #050505;
}
.quick-template-header a {
    color: #1877f2;
    font-weight: 600;
}
.quick-template-carousel {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: thin;
}
.quick-template-carousel::-webkit-scrollbar { height: 5px; }
.quick-template-carousel::-webkit-scrollbar-thumb {
    background: #ccd0d5;
    border-radius: 4px;
}
.quick-template-btn {
    flex: 0 0 68px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
    background: #ffffff;
    border: 1px solid #e4e6eb;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}
.quick-template-btn:hover {
    border-color: #1877f2;
    transform: translateY(-2px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}
.quick-template-btn.active {
    border-color: #1877f2;
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.3);
    background: #f0f7ff;
}
.quick-template-btn img {
    width: 60px;
    height: 46px;
    object-fit: cover;
    border-radius: 5px;
    background: #f0f2f5;
}
.quick-template-btn span {
    font-size: 10.5px;
    font-weight: 600;
    color: #1c1e21;
    margin-top: 4px;
    max-width: 62px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* BẢNG ĐIỀU KHIỂN CHẾ ẢNH (CỘT PHẢI - THOÁNG ĐÃNG, ĐẦY ĐỦ CHIỀU DÀI) */
.editor-controls {
    background: #ffffff;
    border: 1px solid #e4e6eb;
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 13px;
}

.source-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
    color: #65676b;
    padding-bottom: 8px;
    border-bottom: 1px solid #e4e6eb;
}
.source-bar a {
    color: #1877f2;
    font-weight: 600;
}

.tool-label {
    font-size: 11.5px;
    font-weight: 700;
    color: #65676b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    display: block;
}

/* BỘ CÔNG CỤ LÀM ĐẸP & BỘ LỌC ẢNH */
.image-enhance-card {
    background: linear-gradient(135deg, #f5f0ff 0%, #fff0f6 100%);
    border: 1px solid #d8b4fe;
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 1px 4px rgba(147, 51, 234, 0.08);
}
.enhance-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.enhance-title {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    color: #6b21a8;
    font-weight: 700;
}
.enhance-quick-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-auto-enhance {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
    color: #ffffff;
    border: none;
    border-radius: 16px;
    padding: 5px 11px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
    transition: all 0.15s ease;
}
.btn-auto-enhance:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(124, 58, 237, 0.45);
}
.btn-reset-filters {
    background: #ffffff;
    border: 1px solid #d8b4fe;
    color: #6b21a8;
    border-radius: 14px;
    padding: 4px 9px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-reset-filters:hover {
    background: #f5f3ff;
}
.filter-preset-chips {
    display: flex;
    gap: 5px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 6px;
    scrollbar-width: thin;
}
.filter-preset-chips::-webkit-scrollbar { height: 3px; }
.filter-preset-chips::-webkit-scrollbar-thumb { background: #d8b4fe; border-radius: 3px; }
.filter-chip {
    flex-shrink: 0;
    padding: 3.5px 9px;
    background: #ffffff;
    border: 1px solid #d8b4fe;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 600;
    color: #581c87;
    cursor: pointer;
    transition: all 0.15s ease;
}
.filter-chip:hover {
    background: #f3e8ff;
    border-color: #a855f7;
}
.filter-chip.active {
    background: #7c3aed;
    color: #ffffff;
    border-color: #7c3aed;
    box-shadow: 0 1px 4px rgba(124, 58, 237, 0.3);
}
.enhance-details {
    font-size: 11.5px;
    margin-top: 4px;
    padding-top: 5px;
    border-top: 1px dashed #e9d5ff;
}
.enhance-details summary {
    cursor: pointer;
    color: #7c3aed;
    font-weight: 600;
    user-select: none;
    outline: none;
}
.enhance-sliders-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 8px;
}
.slider-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.slider-row label {
    font-size: 10.5px;
    font-weight: 600;
    color: #581c87;
    display: flex;
    justify-content: space-between;
}
.slider-row label span {
    color: #7c3aed;
    font-weight: 700;
}
.slider-row input[type="range"] {
    width: 100%;
    height: 4px;
    accent-color: #7c3aed;
    cursor: pointer;
}

/* 1. GỢI Ý CÂU ĐÙA SIÊU MẶN */
.smart-punchline-card {
    background: linear-gradient(135deg, #f0f7ff 0%, #fff7eb 100%);
    border: 1px solid #b8daff;
    border-radius: 10px;
    padding: 11px 13px;
    box-shadow: 0 1px 4px rgba(24, 119, 242, 0.08);
}
.smart-punchline-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.smart-punchline-title {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    color: #0d47a1;
    font-weight: 700;
}
.sparkle-icon { font-size: 14px; }
.btn-dice-joke {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #ff7043;
    color: #ffffff;
    border: none;
    border-radius: 16px;
    padding: 5px 12px;
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(255, 112, 67, 0.3);
    transition: all 0.15s ease;
}
.btn-dice-joke:hover {
    background: #f4511e;
    transform: translateY(-1px);
}
.dice-icon { display: inline-block; font-size: 13px; }

.punchline-category-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    margin-top: 8px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.punchline-category-chips::-webkit-scrollbar {
    height: 3px;
}
.punchline-category-chips::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 3px;
}
.punchline-category-chips::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.cat-chip {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 4px 10px;
    background: #ffffff;
    border: 1px solid #ccd0d5;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s ease;
}
.cat-chip:hover {
    border-color: #1877f2;
    color: #1877f2;
}
.cat-chip.active {
    background: #1877f2;
    border-color: #1877f2;
    color: #ffffff;
}

/* 2. BỐ CỤC PRESET LAYOUTS */
.layout-preset-container {
    margin-bottom: 2px;
}
.layout-preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 6px;
}
.layout-preset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 8px;
    background: #ffffff;
    border: 1.5px solid #ccd0d5;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.15s ease;
}
.layout-preset-btn:hover {
    border-color: #1877f2;
    background: #f8faff;
}
.layout-preset-btn.active {
    border-color: #1877f2;
    background: #e7f3ff;
    color: #1877f2;
    box-shadow: 0 0 0 1.5px rgba(24, 119, 242, 0.25);
}
.layout-icon { font-size: 15px; }

/* 3. QUẢN LÝ CÁC DÒNG CHỮ */
.text-tabs-section {
    margin-bottom: 2px;
}
.text-tabs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.text-tabs-header .tool-label { margin-bottom: 0; }
.btn-add-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    background: #e7f3ff;
    color: #1877f2;
    border: 1px solid #cfe2ff;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-add-text:hover { background: #d0e7ff; }

.text-chips-list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.text-chip {
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 16px;
    border: 1px solid #ccd0d5;
    background: #f0f2f5;
    color: #4b5563;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: all 0.15s ease;
}
.text-chip:hover { background: #e4e6eb; color: #050505; }
.text-chip.active {
    background: #1877f2;
    border-color: #1877f2;
    color: #ffffff;
    box-shadow: 0 1px 4px rgba(24, 119, 242, 0.3);
}

/* 4. HỘP ĐIỀU CHỈNH CHỮ ĐANG CHỌN */
.active-text-card {
    background: #f8f9fa;
    border: 1px solid #e4e6eb;
    border-radius: 10px;
    padding: 13px 15px;
}
.active-text-card textarea {
    width: 100%;
    min-height: 52px;
    font-size: 14px;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid #ccd0d5;
    border-radius: 8px;
    color: #1c1e21;
    background: #ffffff;
    margin-bottom: 8px;
    resize: vertical;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.active-text-card textarea:focus {
    border-color: #1877f2;
    outline: none;
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
}

.text-action-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #e4e6eb;
}
.btn-tool-sub {
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 600;
    background: #ffffff;
    border: 1px solid #ccd0d5;
    border-radius: 6px;
    cursor: pointer;
    color: #4b5563;
    transition: all 0.15s ease;
}
.btn-tool-sub:hover { background: #f0f2f5; color: #1877f2; border-color: #1877f2; }

.btn-del-text {
    padding: 4px 10px;
    font-size: 11.5px;
    font-weight: 600;
    background: #ffebee;
    border: 1px solid #ffccd0;
    color: #d93025;
    border-radius: 6px;
    cursor: pointer;
    margin-left: auto;
    transition: all 0.15s ease;
}
.btn-del-text:hover { background: #ffcdd2; }

.tool-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 11px;
}
.tool-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tool-col select {
    height: 36px;
    border: 1px solid #ccd0d5;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12.5px;
    font-weight: 600;
    background: #ffffff;
}

.size-slider-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
}
.size-slider-wrap button {
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #ccd0d5;
    background: #ffffff;
    cursor: pointer;
}
.size-slider-wrap input[type=range] {
    flex: 1;
    height: 5px;
    cursor: pointer;
    accent-color: #1877f2;
}
.size-badge {
    font-size: 11.5px;
    font-weight: 700;
    color: #1877f2;
    min-width: 34px;
    text-align: right;
}

.color-picker-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    min-height: 32px;
}
.color-swatch {
    width: 23px;
    height: 23px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px #ccd0d5;
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s ease;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active {
    box-shadow: 0 0 0 2px #1877f2;
    transform: scale(1.15);
}
.color-input-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid #ccd0d5;
    overflow: hidden;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}
.color-input-btn input[type=color] {
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* 5. DÁN STICKER & BIỂU CẢM (DẠNG SỔ RA TIẾT KIỆM DIỆN TÍCH) */
.sticker-dropdown-section {
    position: relative;
    margin-bottom: 2px;
}
.sticker-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-sticker-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #f0f2f5;
    border: 1px solid #ccd0d5;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: #1c1e21;
    cursor: pointer;
    transition: all 0.15s ease;
    flex: 1;
}
.btn-sticker-toggle:hover {
    background: #e4e6eb;
    border-color: #bec3c9;
}
.btn-sticker-toggle.active {
    background: #e7f3ff;
    border-color: #1877f2;
    color: #1877f2;
}
.sticker-toggle-icon {
    font-size: 16px;
    line-height: 1;
}
.sticker-toggle-text {
    flex: 1;
    text-align: left;
}
.sticker-toggle-arrow {
    font-size: 12px;
    color: #65676b;
    transition: transform 0.2s ease;
}
.btn-sticker-toggle.active .sticker-toggle-arrow {
    transform: rotate(180deg);
}

.btn-del-sticker {
    padding: 6px 10px;
    font-size: 11.5px;
    font-weight: 600;
    background: #ffebee;
    border: 1px solid #ffcdd2;
    color: #c62828;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}
.btn-del-sticker:hover { background: #ffcdd2; }

/* BẢNG CHỌN STICKER SỔ RA (POPOVER) */
.sticker-popover {
    position: relative;
    margin-top: 8px;
    background: #ffffff;
    border: 1px solid #ccd0d5;
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    z-index: 50;
    animation: stickerSlideDown 0.18s ease-out;
}
.sticker-popover[hidden] {
    display: none !important;
}
@keyframes stickerSlideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.sticker-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    font-weight: 600;
    color: #65676b;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #e4e6eb;
}
.btn-close-popover {
    background: #f0f2f5;
    border: none;
    color: #65676b;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.btn-close-popover:hover {
    background: #e4e6eb;
    color: #050505;
}
.sticker-bar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    justify-items: center;
}
.sticker-btn {
    width: 100%;
    max-width: 36px;
    height: 36px;
    font-size: 18px;
    border-radius: 6px;
    border: 1px solid #e4e6eb;
    background: #f8f9fa;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    user-select: none;
}
.sticker-btn:hover {
    transform: scale(1.2);
    border-color: #1877f2;
    background: #e7f3ff;
}

/* 6. TIÊU ĐỀ BÀI VIẾT KHI ĐĂNG */
.meme-title-section {
    margin-bottom: 2px;
}
.meme-title-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.meme-title-header .tool-label { margin-bottom: 0; }
#meme-title {
    width: 100%;
    height: 40px;
    padding: 8px 12px;
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid #ccd0d5;
    border-radius: 8px;
    background: #ffffff;
    color: #1c1e21;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#meme-title:focus {
    border-color: #1877f2;
    outline: none;
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
}
.btn-theme-suggest {
    height: 28px;
    padding: 0 10px;
    font-size: 11.5px;
    font-weight: 600;
    background: #e7f3ff;
    color: #1877f2;
    border: 1px solid #cfe2ff;
    border-radius: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}
.btn-theme-suggest:hover {
    background: #1877f2;
    color: #ffffff;
}

.check-inline {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    color: #4b5563;
    cursor: pointer;
    margin: 2px 0 4px;
}
.check-inline input { margin: 0; }

@keyframes glowPulse {
    0% { box-shadow: 0 0 0 0 rgba(24, 119, 242, 0.4); border-color: #1877f2; }
    50% { box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.25); border-color: #1877f2; }
    100% { box-shadow: none; border-color: #ccd0d5; }
}
.highlight-glow {
    animation: glowPulse 1.2s ease-out;
}

/* 7. NÚT TẢI & ĐĂNG BÀI */
.editor-buttons {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}
.editor-buttons button {
    flex: 1;
    height: 44px;
    padding: 0 14px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 8px;
    border: 1px solid #ccd0d5;
    background: #ffffff;
    cursor: pointer;
    color: #1c1e21;
    transition: all 0.15s ease;
}
.editor-buttons button:hover { background: #f2f3f5; }
.editor-buttons button:disabled { opacity: 0.45; cursor: not-allowed; }
.editor-buttons .primary {
    background: #1877f2;
    color: #ffffff;
    border-color: #1877f2;
}
.editor-buttons .primary:hover { background: #166fe5; }

#editor-status {
    font-size: 12.5px;
    min-height: 18px;
    margin: 4px 0 0;
    font-weight: 600;
}
#editor-status.error { color: #d93025; }
#editor-status.success { color: #188038; }

#published {
    border-top: 1px solid #e4e6eb;
    margin-top: 10px;
    padding-top: 10px;
}
#published h2 { color: #188038; font-size: 16px; margin: 0 0 6px; }
#published-link {
    display: inline-block;
    font-weight: 700;
    margin-bottom: 8px;
    font-size: 13px;
}

/* CONFETTI CANVAS OVERLAY */
.confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999999;
}

/* KHO MẪU PHÍA DƯỚI */
.template-section {
    margin-top: 36px;
    border-top: 1px solid #e4e6eb;
    padding-top: 20px;
}
.template-section > h2 { font-size: 18px; margin: 0 0 6px; }
.template-section > p { color: #65676b; font-size: 13.5px; margin: 0 0 14px; }
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}
.template {
    background: #ffffff;
    border: 1px solid #e4e6eb;
    border-radius: 8px;
    overflow: hidden;
    color: #1c1e21;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.template:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    text-decoration: none;
}
.template img { width: 100%; height: 130px; object-fit: contain; background: #e4e6eb; }
.template strong { display: block; padding: 6px 10px 2px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.template small { display: block; color: #65676b; font-size: 11px; padding: 0 10px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* STUDIO MODAL & CROP TOOL */
.studio-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.studio-modal[hidden] { display: none !important; }
.studio-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.studio-modal-dialog {
    position: relative;
    z-index: 1;
    background: #242526;
    border-radius: 14px;
    width: 100%;
    max-width: 760px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    color: #e4e6eb;
}
.studio-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid #3a3b3c;
}
.modal-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-title-group h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
}
.modal-close-btn {
    background: #3a3b3c;
    border: none;
    color: #b0b3b8;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.modal-close-btn:hover {
    background: #4e4f50;
    color: #ffffff;
}
.crop-workspace-wrap {
    padding: 16px;
    background: #18191a;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex: 1;
    min-height: 260px;
    max-height: 480px;
    user-select: none;
    -webkit-user-select: none;
}
.crop-workspace {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 440px;
    touch-action: none;
}
#crop-source-img {
    display: block;
    max-width: 100%;
    max-height: 440px;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}
.crop-box {
    position: absolute;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
    border: 2px dashed #ffffff;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    cursor: move;
    box-sizing: border-box;
    touch-action: none;
}
.crop-grid-lines {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}
.crop-grid-lines::before, .crop-grid-lines::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.35);
}
.crop-grid-lines::before {
    top: 0; bottom: 0;
    left: 33.333%; right: 33.333%;
    border-left: 1px dashed rgba(255, 255, 255, 0.35);
    border-right: 1px dashed rgba(255, 255, 255, 0.35);
}
.crop-grid-lines::after {
    left: 0; right: 0;
    top: 33.333%; bottom: 33.333%;
    border-top: 1px dashed rgba(255, 255, 255, 0.35);
    border-bottom: 1px dashed rgba(255, 255, 255, 0.35);
}
.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #ffffff;
    border: 2px solid #1877f2;
    border-radius: 2px;
    box-sizing: border-box;
    z-index: 10;
}
.handle-tl { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-tr { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-br { bottom: -6px; right: -6px; cursor: nwse-resize; }

.crop-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 18px;
    background: #242526;
    border-top: 1px solid #3a3b3c;
}
.crop-ratios {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}
.crop-ratio-label {
    font-size: 12px;
    color: #b0b3b8;
    font-weight: 600;
    margin-right: 2px;
}
.ratio-btn {
    background: #3a3b3c;
    border: 1px solid #4e4f50;
    color: #e4e6eb;
    border-radius: 6px;
    padding: 4px 9px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.ratio-btn:hover {
    background: #4e4f50;
    color: #ffffff;
}
.ratio-btn.active {
    background: #1877f2;
    border-color: #1877f2;
    color: #ffffff;
}
.crop-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-crop-cancel {
    background: #3a3b3c;
    border: none;
    color: #e4e6eb;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}
.btn-crop-cancel:hover { background: #4e4f50; }
.btn-crop-apply {
    background: #1877f2;
    border: none;
    color: #ffffff;
    border-radius: 8px;
    padding: 7px 16px;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(24, 119, 242, 0.4);
    transition: all 0.15s ease;
}
.btn-crop-apply:hover { background: #166fe5; }

/* RESPONSIVE MOBILE - CÂN ĐỐI, GỌN GÀNG, CHUẨN GIAO DIỆN APP */
@media (max-width: 820px) {
    /* Khử khoảng trống đệm thừa khi tải trên mobile có thanh header sticky */
    .header-sticky-back ~ main.studio,
    #container .studio {
        padding: 10px 10px 40px !important;
    }

    /* Padding tổng thể trên màn hình hẹp */
    .studio {
        padding: 70px 10px 30px;
        max-width: 100%;
        overflow-x: hidden;
    }

    .editor-layout {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%;
        max-width: 100%;
    }

    /* 1. KHUNG PREVIEW VÀ CANVAS TRÊN MOBILE */
    .preview-panel {
        padding: 8px;
        border-radius: 12px;
        width: 100%;
        box-sizing: border-box;
    }

    .canvas-toolbar-wrap {
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 6px 8px;
        border-radius: 8px;
        margin-bottom: 6px;
    }

    .canvas-action-group {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
        width: 100%;
    }

    .img-tool-btn {
        justify-content: center;
        padding: 6px 2px;
        font-size: 11px;
        border-radius: 6px;
        white-space: nowrap;
    }

    .img-tool-reset {
        grid-column: span 4;
        margin-top: 2px;
        justify-content: center;
    }

    .canvas-hint-text {
        justify-content: space-between;
        font-size: 11px;
        padding: 0 4px;
        color: #8a8d91;
    }

    /* Giới hạn chiều cao canvas trên mobile để không chiếm hết màn hình */
    .canvas-container {
        min-height: 180px;
        max-height: 48vh;
        border-radius: 8px;
    }

    canvas#meme-canvas {
        max-height: 46vh !important;
        width: auto !important;
        max-width: 100% !important;
        object-fit: contain;
    }

    .preview-note {
        font-size: 11px;
        margin-top: 5px;
    }

    /* Đổi mẫu nhanh dưới canvas */
    .quick-template-section {
        margin-top: 8px;
        padding-top: 8px;
    }
    .quick-template-header {
        font-size: 12px;
        margin-bottom: 6px;
    }
    .quick-template-btn {
        flex: 0 0 62px;
        padding: 3px;
    }
    .quick-template-btn img {
        width: 56px;
        height: 42px;
    }
    .quick-template-btn span {
        font-size: 10px;
        max-width: 56px;
    }

    /* 2. BẢNG CÔNG CỤ ĐIỀU KHIỂN CỘT DƯỚI */
    .editor-controls {
        padding: 12px;
        border-radius: 12px;
        gap: 12px;
        width: 100%;
        box-sizing: border-box;
    }

    .source-bar {
        font-size: 12px;
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Card Làm đẹp ảnh & Bộ lọc */
    .image-enhance-card {
        padding: 10px;
        border-radius: 10px;
    }
    .enhance-head {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
    }
    .enhance-title {
        font-size: 12px;
    }
    .enhance-quick-actions {
        display: flex;
        gap: 4px;
    }
    .btn-auto-enhance {
        padding: 5px 9px;
        font-size: 10.5px;
        white-space: nowrap;
    }
    .btn-reset-filters {
        padding: 4px 7px;
        font-size: 10.5px;
    }
    .filter-preset-chips {
        gap: 4px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    .filter-chip {
        padding: 4px 10px;
        font-size: 11px;
    }
    .enhance-sliders-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .slider-row {
        gap: 2px;
    }

    /* Card Câu đùa siêu mặn */
    .smart-punchline-card {
        padding: 10px;
        border-radius: 10px;
    }
    .smart-punchline-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .smart-punchline-title {
        font-size: 12px;
    }
    .btn-dice-joke {
        padding: 4px 10px;
        font-size: 11px;
    }
    .punchline-category-chips {
        display: flex;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 4px;
        margin-top: 6px;
        padding-bottom: 3px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .punchline-category-chips::-webkit-scrollbar { display: none; }
    .cat-chip {
        flex-shrink: 0;
        padding: 3.5px 9px;
        font-size: 11px;
    }

    /* Bố cục meme preset */
    .layout-preset-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    .layout-preset-btn {
        flex-direction: column;
        height: auto;
        padding: 6px 2px;
        gap: 2px;
        font-size: 10.5px;
        text-align: center;
    }
    .layout-icon {
        font-size: 16px;
    }

    /* Các dòng chữ trên ảnh */
    .text-tabs-header {
        margin-bottom: 6px;
    }
    .text-chips-list {
        display: flex;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 5px;
        padding-bottom: 3px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .text-chips-list::-webkit-scrollbar { display: none; }
    .text-chip {
        flex-shrink: 0;
        padding: 4px 10px;
        font-size: 11.5px;
    }

    /* Hộp điều chỉnh chữ đang chọn */
    .active-text-card {
        padding: 10px 12px;
        border-radius: 10px;
    }
    .active-text-card textarea {
        font-size: 13.5px;
        min-height: 48px;
        padding: 6px 10px;
        margin-bottom: 6px;
    }
    .text-action-tools {
        margin-bottom: 8px;
        padding-bottom: 8px;
        gap: 4px;
    }
    .btn-tool-sub {
        padding: 4px 8px;
        font-size: 11px;
    }
    .btn-del-text {
        padding: 4px 8px;
        font-size: 11px;
    }

    /* Cân bằng 2 cột Font chữ và Cỡ chữ trên mobile */
    .tool-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 8px;
    }
    .tool-col select {
        height: 34px;
        padding: 4px 6px;
        font-size: 11.5px;
        width: 100%;
    }
    .size-slider-wrap {
        height: 34px;
        gap: 4px;
    }
    .size-slider-wrap button {
        height: 26px;
        padding: 2px 5px;
        font-size: 10px;
    }
    .size-slider-wrap input[type=range] {
        min-width: 0;
    }
    .size-badge {
        font-size: 10.5px;
        min-width: 28px;
    }

    /* Màu chữ & Viền chữ cân xứng */
    .color-picker-wrap {
        gap: 4px;
        min-height: 28px;
    }
    .color-swatch {
        width: 20px;
        height: 20px;
    }
    .color-input-btn {
        width: 20px;
        height: 20px;
    }

    /* Sticker Emoji: Lưới 7 cột cân xứng hoàn hảo (14 icon = 2 hàng x 7) */
    .sticker-section {
        padding: 10px 12px;
        border-radius: 10px;
    }
    .sticker-bar {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        gap: 4px;
        justify-items: center;
    }
    .sticker-btn {
        width: 100%;
        max-width: 38px;
        height: 36px;
        font-size: 18px;
        border-radius: 6px;
    }

    /* Tiêu đề bài viết */
    #meme-title {
        height: 38px;
        font-size: 13px;
        padding: 6px 10px;
    }

    /* Cặp nút tải về & đăng bài */
    .editor-buttons {
        gap: 8px;
        margin-top: 6px;
    }
    .editor-buttons button {
        height: 42px;
        font-size: 13px;
        padding: 0 8px;
        border-radius: 8px;
    }

    /* Cửa sổ Cắt ảnh trên mobile: Cân đối, không bị đẩy tràn màn hình */
    .studio-modal {
        padding: 8px;
    }
    .studio-modal-dialog {
        max-height: 92vh;
        width: 100%;
        border-radius: 12px;
    }
    .studio-modal-header {
        padding: 10px 14px;
    }
    .modal-title-group h3 {
        font-size: 14px;
    }
    .crop-workspace-wrap {
        min-height: 180px;
        max-height: 38vh;
        padding: 8px;
    }
    #crop-source-img {
        max-height: 36vh;
    }
    .crop-modal-footer {
        padding: 10px 12px;
        gap: 8px;
        flex-direction: column;
        align-items: stretch;
    }
    .crop-ratios {
        display: flex;
        overflow-x: auto;
        flex-wrap: nowrap;
        gap: 4px;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .crop-ratios::-webkit-scrollbar { display: none; }
    .ratio-btn {
        flex-shrink: 0;
        padding: 4px 8px;
        font-size: 11px;
    }
    .crop-actions {
        display: flex;
        gap: 8px;
        width: 100%;
    }
    .btn-crop-cancel,
    .btn-crop-apply {
        flex: 1;
        text-align: center;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Kho mẫu ảnh chế cộng đồng ở dưới */
    .template-section {
        margin-top: 20px;
        padding-top: 14px;
    }
    .template-section > h2 {
        font-size: 16px;
    }
    .template-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .template img {
        height: 110px;
    }
}
