:root {
    --primary: #FBC02D;
    --primary-light: #FFF9C4;
    --text: #455A64;
    --bg: #FAFAFA;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', sans-serif; }
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background-color: var(--bg); color: var(--text); overflow: hidden; }

/* Navbar */
.navbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 25px; background: white; box-shadow: 0 2px 10px rgba(0,0,0,0.05); z-index: 100; }
.logo-container { display: flex; align-items: center; gap: 12px; }
.nav-logo { height: 40px; width: auto; }
.logo-text { font-weight: 800; color: var(--primary); font-size: 1.5rem; }

.btn { padding: 10px 22px; border: none; border-radius: 30px; cursor: pointer; font-weight: 700; transition: 0.3s; }
.btn-share { background: var(--primary); color: white; }

/* Workspace */
.workspace { flex: 1; display: flex; justify-content: center; align-items: center; padding: 20px; gap: 20px; overflow: hidden; flex-wrap: nowrap; }
.canvas-container { display: flex; flex-direction: row; align-items: stretch; height: 52vh; max-height: 500px; width: auto; gap: 20px; }

/* Toolbar Desktop */
.toolbar { display: grid; grid-template-columns: repeat(2, 1fr); align-content: flex-start; justify-items: center; align-items: center; gap: 15px 12px; background: white; padding: 20px 18px; border-radius: 30px; margin-bottom: 0; box-shadow: 0 4px 10px rgba(0,0,0,0.05); height: 100%; overflow-y: auto; }
.toolbar::-webkit-scrollbar { display: none; }
.toolbar { -ms-overflow-style: none; scrollbar-width: none; }
.toolbar button { 
    color: #8E8E8E !important; 
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: transparent;
    border: none;
    cursor: pointer;
}
.toolbar button:hover { color: #F0A3B0 !important; }
.toolbar button:disabled { opacity: 0.3 !important; }

.divider { grid-column: span 2; width: 70%; height: 1px; background: #eee; flex-shrink: 0; margin: 2px 0; }
.divider-vertical { width: 1px; height: 20px; background: #eee; }

.mobile-btn { display: none; }
.close-layers-btn { display: none; }

/* BINGKAI KANVAS */
.canvas-view { position: relative; height: 100%; width: auto; aspect-ratio: 4 / 5; flex-shrink: 0; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
.canvas-wrapper { height: 100%; width: 100%; background: transparent; position: relative; overflow: auto; display: flex; justify-content: flex-start; align-items: flex-start; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
.canvas-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-wrapper::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }

/* FLOATING ZOOM PANEL */
.floating-zoom-panel { position: absolute; bottom: 15px; right: 15px; background: white; border-radius: 30px; box-shadow: 0 4px 15px rgba(0,0,0,0.15); display: flex; align-items: center; padding: 8px 15px; gap: 12px; z-index: 50; }
.floating-zoom-panel button { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: #455A64; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.floating-zoom-panel button:hover { color: var(--primary); transform: scale(1.1); }
.floating-zoom-panel #zoom-text { font-weight: bold; font-size: 0.9rem; color: #455A64; min-width: 45px; text-align: center; user-select: none; }

/* KERTAS KANVAS */
.canvas-area { width: 100%; height: 100%; background: white; position: relative; overflow: hidden; border-radius: 12px; display: flex; justify-content: center; align-items: center; container-type: inline-size; transform-origin: center center; transition: transform 0.2s ease-out, margin 0.2s ease-out; flex-shrink: 0; }
.panduan { text-align: center; color: #CFD8DC; font-size: 4.5cqw; }

/* Items */
.draggable-item { position: absolute; width: 32cqw; transform-origin: center center; display: flex; align-items: center; justify-content: center; touch-action: none; }
.item-image { width: 100%; height: auto; pointer-events: none; }
.draggable-item.selected { border: 2px dashed var(--primary); border-radius: 8px; }
.draggable-item.locked { pointer-events: none; border: none !important; }

.control-handle { position: absolute; background: white; border: 2px solid var(--primary); border-radius: 50%; width: 4.5cqw; height: 4.5cqw; display: none; z-index: 10; }
.draggable-item.selected:not(.locked) .control-handle { display: block; }
.handle-resize { bottom: -2.25cqw; right: -2.25cqw; cursor: nwse-resize; }
.handle-rotate { top: -9cqw; left: 50%; transform: translateX(-50%); cursor: crosshair; }

.color-picker { grid-column: span 2; appearance: none; -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; border: 1px solid #ddd; cursor: pointer; overflow: hidden; padding: 0; flex-shrink: 0; margin-top: 5px; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 50%; }

/* Sidebar Layers */
.layers-panel { width: 300px; height: 52vh; max-height: 500px; background: white; border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); display: flex; flex-direction: column; flex-shrink: 0; }
.layers-header { padding: 15px; border-bottom: 1px solid #f5f5f5; display: flex; justify-content: space-between; align-items: center; }
.badge { background: var(--primary-light); color: var(--primary); padding: 2px 10px; border-radius: 20px; font-weight: bold; }
.layer-list { flex: 1; padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.layer-item { display: flex; align-items: center; padding: 10px; background: #fafafa; border-radius: 8px; cursor: pointer; }
.layer-item.active { background: var(--primary-light); border: 1px solid var(--primary); }
.layer-icon { width: 24px; height: 24px; object-fit: contain; margin-right: 10px; }

/* =========================================
   ASSET GALLERY (SUDAH DIPERBAIKI)
========================================= */
.asset-gallery { padding: 15px 20px; background: white; border-top: 1px solid #eee; display: flex; flex-direction: column; flex-shrink: 0; z-index: 10; position: relative; }
.category-tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 5px; scrollbar-width: none; position: relative; margin-bottom: 10px; }
.category-tabs::-webkit-scrollbar { display: none; }
.tab-btn { padding: 6px 18px; border: 1px solid transparent; background: transparent; color: #607D8B; font-weight: 600; border-radius: 20px; cursor: pointer; white-space: nowrap; transition: 0.3s; font-size: 0.9rem; }
.tab-btn:hover { color: #E91E63; }
.tab-btn.active { color: #E91E63; border: 1px solid #F8BBD0; background: #FCE4EC; }

/* KEMBALI KE PENGATURAN NORMAL TANPA MARGIN/PADDING HACK */
.items-container { 
    display: flex; gap: 18px; overflow-x: auto; 
    padding-bottom: 15px; 
    scrollbar-width: thin; align-items: flex-start; position: relative; 
}
.item { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 75px; position: relative; }

.item-img-box { width: 75px; height: 75px; background: #ffffff; border-radius: 18px; display: flex; align-items: center; justify-content: center; border: 1.5px solid #f0f0f0; box-shadow: 0 4px 10px rgba(0,0,0,0.03); transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); cursor: pointer; position: relative; }
.item-img-box:hover { transform: translateY(-5px); border-color: #F8BBD0; box-shadow: 0 8px 20px rgba(233,30,99,0.15); }
.item-img-box img { width: 75%; height: 75%; object-fit: contain; }
.item-label { font-size: 0.75rem; color: #455A64; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 80px; }

/* GLOBAL POPUP MELAYANG (ANTI KEPOTONG & ANTI Z-INDEX BUG) */
.color-popup-global {
    position: fixed; /* Rahasia agar popup bebas melayang menembus segalanya */
    background: white;
    padding: 8px;
    border-radius: 20px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    width: max-content;
    max-width: 130px;
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.color-popup-global::after { content: ''; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); border-width: 6px 6px 0; border-style: solid; border-color: white transparent transparent transparent; }
.color-popup-global.show { opacity: 1; pointer-events: auto; }

.color-dot { width: 22px; height: 22px; border-radius: 50%; cursor: pointer; box-shadow: inset 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.1); transition: transform 0.2s, box-shadow 0.2s; }
.color-dot:hover { transform: scale(1.2); box-shadow: 0 2px 8px rgba(0,0,0,0.3); }

/* BINGKAI POLAROID & CROPPER */
.item-content { width: 100%; display: flex; justify-content: center; align-items: center; }
.polaroid-style { background: #fff; padding: 5% 5% 25% 5%; box-shadow: 0 5px 15px rgba(0,0,0,0.2); border: 1px solid #eee; width: 100%; display: flex; flex-direction: column; }
.polaroid-style img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; pointer-events: none; border: 1px solid #f5f5f5; }

.crop-container { width: 100%; max-height: 50vh; background-color: #f0f0f0; border-radius: 10px; overflow: hidden; display: flex; justify-content: center; align-items: center; }
.crop-container img { display: block; max-width: 100%; max-height: 50vh; }

/* Modal & Form */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 10000; }
.modal.hidden { display: none; }
.modal-content { background: white; width: 90%; max-width: 500px; padding: 30px; border-radius: 15px; position: relative; }
.modal-title { color: var(--primary); margin-bottom: 25px; text-align: center; }
.close-btn { position: absolute; top: 15px; right: 20px; font-size: 1.8rem; cursor: pointer; color: #999; line-height: 1; }
.close-btn:hover { color: #E91E63; }
.hidden { display: none !important; }

.form-row { display: flex; gap: 15px; margin-bottom: 20px; }
.form-group { flex: 1; }
.form-group label, .form-section label { display: block; margin-bottom: 5px; font-weight: 600; color: #455A64; font-size: 0.9rem; }
.form-input { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px; outline: none; transition: 0.3s; }
.form-input:focus { border-color: var(--primary); }

.textarea-wrapper { position: relative; }
textarea { width: 100%; height: 100px; border: 1px solid #ddd; border-radius: 8px; padding: 12px; font-family: 'Caveat', cursive; font-size: 1.4rem; resize: none; outline: none; transition: 0.3s; }
textarea:focus { border-color: var(--primary); }
.char-count { position: absolute; bottom: 10px; right: 10px; font-size: 0.8rem; color: #999; }

.btn-primary { background: var(--primary); color: white; border: none; padding: 12px 25px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: 0.3s; }
.btn-primary:hover { background: #e6b02a; transform: translateY(-2px); }
.btn-secondary { background: white; border: 1px solid #ddd; padding: 12px 25px; border-radius: 8px; cursor: pointer; transition: 0.3s; }

/* =========================================
   RESPONSIF MOBILE (HP)
========================================= */
@media (max-width: 768px) {
    .workspace { flex-direction: column; justify-content: flex-start; align-items: center; padding: 15px 10px 40px 10px; overflow-y: auto; overflow-x: hidden; }
    .canvas-container { flex-direction: column; width: 100%; height: auto; min-height: min-content; max-height: none; align-items: center; justify-content: flex-start; gap: 15px; margin-top: auto; margin-bottom: auto; }
    
    .toolbar { display: flex; flex-direction: row; width: 100%; max-width: 360px; height: auto; flex-wrap: wrap; justify-content: center; padding: 10px; border-radius: 30px; }
    .color-picker { margin-top: 0; }
    .divider { width: 1px; height: 20px; margin: 0 5px; }

    div.mobile-btn { display: block; width: 1px; height: 20px; margin: 0 5px; background: #eee; }
    button.mobile-btn { display: block; background: none; border: none; font-size: 1.2rem; cursor: pointer; }
    .close-layers-btn { display: inline-block; background: none; border: none; font-size: 1.2rem; color: #999; margin-left: 15px; cursor: pointer; }

    .canvas-view { width: 100%; height: auto; max-width: 360px; aspect-ratio: 4 / 5; }
    .canvas-wrapper { width: 100%; height: 100%; aspect-ratio: auto; }
    .floating-zoom-panel { bottom: 10px; right: 10px; padding: 5px 10px; }
    .floating-zoom-panel button { font-size: 1rem; }

    .layers-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.9); opacity: 0; pointer-events: none; z-index: 1000; width: 90%; max-width: 340px; height: 60vh; transition: all 0.3s ease; box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
    .layers-panel.show { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }

    .asset-gallery { padding: 10px; gap: 0; }
    .category-tabs { margin-bottom: 5px; }
    
    .items-container { gap: 12px; padding-bottom: 10px; }
    .item { min-width: 55px; }
    .item-img-box { width: 55px; height: 55px; border-radius: 12px; }
    .item-label { font-size: 0.65rem; max-width: 60px; }
    
    .color-popup-global { max-width: 100px; padding: 6px; }
    .color-dot { width: 18px; height: 18px; }
    
    .form-row { flex-direction: column; gap: 10px; margin-bottom: 10px; }
}