:root {
    --primary: #4361ee;
    --primary-hover: #3a56d4;
    --bg-body: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-canvas: #eef1f5;
    --text-main: #2b2d42;
    --text-muted: #8d99ae;
    --border-color: #edf2f4;
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.04);
    --shadow-inner: inset 0 2px 4px rgba(0, 0, 0, 0.03);
    --shadow-panel: 0 4px 20px rgba(0, 0, 0, 0.03);
    --shadow-btn: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius-md: 10px;
    --radius-lg: 16px;
}

body { margin: 0; overflow: hidden; background-color: var(--bg-body); color: var(--text-main); font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }
#app-layout { display: flex; width: 100vw; height: 100vh; overflow: hidden; transition: all 0.3s ease; }
#canvas-wrapper { flex: 1; display: flex; align-items: center; justify-content: center; background-color: var(--bg-canvas); position: relative; transition: all 0.3s ease; }

#main-canvas { 
    width: min(90%, 80vh); 
    height: min(90%, 80vh); 
    aspect-ratio: 1 / 1; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.1); 
    border-radius: 4px; 
    transition: background 0.3s; 
    cursor: grab; 
}
#main-canvas:active { cursor: grabbing; }

.bg-checker {
    background-image: linear-gradient(45deg, #e9ecef 25%, transparent 25%), linear-gradient(135deg, #e9ecef 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e9ecef 75%), linear-gradient(135deg, transparent 75%, #e9ecef 75%);
    background-size: 20px 20px; background-position: 0 0, 10px 0, 10px -10px, 0px 10px; background-color: #ffffff;
}

#ui-panel {
    width: 440px; height: 100vh; background: var(--bg-panel); padding: 20px; box-sizing: border-box; overflow-y: auto; overflow-x: hidden; z-index: 10; box-shadow: -10px 0 30px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 16px; transition: transform 0.3s ease, opacity 0.3s ease;
}
#ui-panel::-webkit-scrollbar { width: 6px; }
#ui-panel::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
#ui-panel::-webkit-scrollbar-track { background: transparent; }

/* 탭 UI */
.tabs { 
    display: flex; 
    border-bottom: 2px solid var(--border-color); 
    flex-wrap: nowrap; 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch; 
    scrollbar-width: none; /* Firefox */
    flex-shrink: 0; 
}
.tabs::-webkit-scrollbar { display: none; } /* Chrome, Safari */

.tab-btn { 
    flex: auto;
    padding: 12px 16px; 
    border: none; background: transparent; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; box-shadow: none; border-radius: 0; white-space: nowrap; 
}
.tab-btn.active { color: var(--primary); border-bottom: 2px solid var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text-main); transform: none; box-shadow: none; }
.tab-content { display: none; flex-direction: column; gap: 16px; animation: fadeIn 0.3s ease; }
.tab-content.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.header-container { flex-shrink: 0; }

.header-title { font-size: 20px; font-weight: 800; color: var(--text-main); margin: 0 0 4px 0; display: flex; align-items: center; justify-content: space-between;}
hr { border: none; border-top: 1px solid var(--border-color); margin: 8px 0; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-main); }
.text-muted { color: var(--text-muted); font-size: 11px; font-weight: 500; margin-top: 4px; display: block; line-height: 1.4; }
.text-warning { color: #f59e0b; }
.control-group { display: flex; flex-direction: column; }
input[type="range"] { width: 100%; accent-color: var(--primary); margin: 8px 0; cursor: pointer; }
input[type="number"] { width: 60px; padding: 4px; border: 1px solid var(--border-color); border-radius: 4px; font-size: 12px; text-align: center; }
select, input[type="file"] { width: 100%; padding: 10px; background: #fafbfc; border: 1px solid var(--border-color); color: var(--text-main); border-radius: var(--radius-md); box-shadow: var(--shadow-inner); font-size: 13px; outline: none; transition: all 0.2s; box-sizing: border-box; }
select:focus, input[type="file"]:focus { border-color: var(--primary); background: #ffffff; }
.panel-box { background: #ffffff; padding: 16px; border-radius: var(--radius-lg); box-shadow: var(--shadow-panel); border: 1px solid var(--border-color); }
.flex { display: flex; } .flex-col { flex-direction: column; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .items-center { align-items: center; } .flex-1 { flex: 1; } .flex-2 { flex: 2; }
.mb-2 { margin-bottom: 8px; } .mt-2 { margin-top: 8px; }
input[type="color"] { width: 36px; height: 36px; border: none; border-radius: 8px; cursor: pointer; padding: 0; background: none; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid var(--border-color); border-radius: 8px; box-shadow: var(--shadow-inner); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* 버튼 스타일 */
button { width: 100%; padding: 12px; font-size: 14px; background: var(--bg-panel); color: var(--text-main); border: 1px solid var(--border-color); border-radius: var(--radius-md); cursor: pointer; font-weight: 700; transition: all 0.2s; box-shadow: var(--shadow-btn); display: flex; align-items: center; justify-content: center; gap: 6px; }
button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(0,0,0,0.12); }
button:disabled { opacity: 0.6; cursor: not-allowed; box-shadow: none; transform: none; background: #e5e7eb; color: #9ca3af; border: none; }
.btn-primary { background: var(--primary); color: white; border: none; box-shadow: 0 4px 15px rgba(67, 97, 238, 0.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: #ef233c; color: white; border: none; padding: 8px 12px; width: auto; font-size: 12px; box-shadow: 0 4px 10px rgba(239, 35, 60, 0.2); }
.btn-danger:hover:not(:disabled) { background: #d90429; }
.btn-green { background: #10b981; color: white; border: none; box-shadow: 0 4px 15px rgba(16, 185, 129, 0.25); }
.btn-blue { background: #3b82f6; color: white; border: none; box-shadow: 0 4px 15px rgba(59, 130, 246, 0.25); }
.btn-purple { background: #8b5cf6; color: white; border: none; box-shadow: 0 4px 15px rgba(139, 92, 246, 0.25); }
.btn-yellow { background: #f59e0b; color: white; border: none; box-shadow: 0 4px 15px rgba(245, 158, 11, 0.25); }
.btn-gray { background: #f8f9fa; color: var(--text-main); border: 1px solid var(--border-color); box-shadow: 0 2px 8px rgba(0,0,0,0.04); }

/* 드래그 앤 드롭 정렬 관련 */
.draggable-item { background: #fff; transition: background 0.2s, box-shadow 0.2s; position: relative; }
.draggable-item.dragging { opacity: 0.5; box-shadow: 0 4px 12px rgba(0,0,0,0.1); z-index: 5; }
.drag-over { border-top: 3px solid var(--primary); margin-top: -3px; }
.drag-handle { cursor: grab; font-size: 16px; color: #cbd5e1; padding-right: 8px; user-select: none; }
.drag-handle:active { cursor: grabbing; color: var(--primary); }

#loading-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.75); backdrop-filter: blur(8px); display: none; justify-content: center; align-items: center; flex-direction: column; z-index: 50; }
.spinner { width: 46px; height: 46px; border: 4px solid var(--border-color); border-top: 4px solid var(--primary); border-radius: 50%; animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite; }
.loading-text { margin-top: 16px; font-size: 15px; font-weight: 700; color: var(--text-main); text-align: center; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.light-pad { width: 80px; height: 80px; border-radius: 50%; background: #f8f9fa; border: 1px solid var(--border-color); box-shadow: inset 0 2px 6px rgba(0,0,0,0.06); position: relative; cursor: crosshair; flex-shrink: 0; }
.light-handle { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); box-shadow: 0 2px 4px rgba(67, 97, 238, 0.4); pointer-events: none; }

/* 자이로스코프 복귀 버튼 */
#btnExitGyro {
    display: none;
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 32px;
    font-size: 16px;
    border-radius: 50px;
    z-index: 100;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: auto;
    white-space: nowrap;
}

/* 모바일 및 자이로스코프 모드 전용 UI 레이아웃 */
@media (max-width: 768px) {
    #app-layout { flex-direction: column; }
    #canvas-wrapper { flex: none; height: 45vh; min-height: 45vh; } /* 캔버스 영역 고정 */
    #ui-panel { width: 100%; flex: 1; height: 55vh; border-top: 1px solid var(--border-color); padding: 15px; } /* 패널 스크롤 영역 확보 */
    
    /* 모바일에서는 찌그러지지 않게 완벽한 비율 강제 (화면 너비나 높이 중 짧은 것에 맞춤) */
    #main-canvas { 
        width: min(90vw, 40vh); 
        height: min(90vw, 40vh); 
        aspect-ratio: 1 / 1;
        max-width: 100%; max-height: 100%;
    }
}

#app-layout.gyro-mode #ui-panel { display: none !important; }
#app-layout.gyro-mode #canvas-wrapper { height: 100vh !important; flex: 1; }
#app-layout.gyro-mode #main-canvas { max-width: 90vmin; max-height: 90vmin; }

/* 모달 및 라이선스 정보 스타일 */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); display: none; justify-content: center; align-items: center; z-index: 999; backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.3s ease; }
.modal-overlay.show { display: flex; opacity: 1; }
.modal-content { background: var(--bg-panel); width: 90%; max-width: 400px; border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,0.15); overflow: hidden; transform: translateY(20px); transition: transform 0.3s ease; }
.modal-overlay.show .modal-content { transform: translateY(0); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; background: #fafbfc; }
.btn-close { background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; box-shadow: none; padding: 0; width: auto; height: auto; line-height: 1; }
.btn-close:hover { color: var(--text-main); transform: none; background: none; box-shadow: none; }
.modal-body { padding: 20px; max-height: 60vh; overflow-y: auto; font-size: 13px; line-height: 1.5; color: var(--text-main); }
.license-item { background: #f8f9fa; padding: 12px; border-radius: 8px; margin-top: 12px; border: 1px solid var(--border-color); }
.btn-info { background: #eef1f5; color: var(--primary); border: none; border-radius: 50%; width: 24px; height: 24px; font-weight: bold; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-shadow: none; margin-left: 8px; padding: 0; transition: all 0.2s; }
.btn-info:hover { background: #e0e7ff; box-shadow: none; transform: translateY(-1px); }